Harden Nostr validation and BLE announce tests (#1012)

Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
jack
2026-02-02 18:07:19 -10:00
committed by GitHub
co-authored by jack
parent 90a5e8ba9d
commit 8c7e3e7b9b
12 changed files with 283 additions and 103 deletions
+27
View File
@@ -213,6 +213,33 @@ struct NostrProtocolTests {
}
}
@Test func nostrEventSignatureVerification_roundTrip() throws {
let identity = try NostrIdentity.generate()
var event = NostrEvent(
pubkey: identity.publicKeyHex,
createdAt: Date(),
kind: .ephemeralEvent,
tags: [],
content: "Signed event"
)
let signed = try event.sign(with: identity.schnorrSigningKey())
#expect(signed.isValidSignature())
}
@Test func nostrEventSignatureVerification_detectsTamper() throws {
let identity = try NostrIdentity.generate()
var event = NostrEvent(
pubkey: identity.publicKeyHex,
createdAt: Date(),
kind: .ephemeralEvent,
tags: [],
content: "Original"
)
var signed = try event.sign(with: identity.schnorrSigningKey())
signed.id = "deadbeef"
#expect(!signed.isValidSignature())
}
// MARK: - Helpers
private static func base64URLDecode(_ s: String) -> Data? {
var str = s.replacingOccurrences(of: "-", with: "+").replacingOccurrences(of: "_", with: "/")