nip42: add initial relay auth support

Lightning-Invoice: lnbc1pjcpaakpp5gjs4f626hf8w6slx84xz3wwhlf309z503rjutckdxv6wwg5ldavsdqqcqzpgxqrrs0fppqjaxxw43p7em4g59vedv7pzl76kt0qyjfsp5qcp9de7a7t8h6zs5mcssfaqp4exrnkehqtg2hf0ary3z5cjnasvs9qyyssq55523e4h3cazhkv7f8jqf5qp0n8spykls49crsu5t3m636u3yj4qdqjkdl2nxf6jet5t2r2pfrxmm8rjpqjd3ylrzqq89m4gqt5l6ycqf92c7h
Closes: https://github.com/damus-io/damus/issues/940
Signed-off-by: Charlie Fish <contact@charlie.fish>
Signed-off-by: William Casarin <jb55@jb55.com>
Changelog-Added: Add NIP-42 relay auth support
This commit is contained in:
Charlie Fish
2023-12-24 14:22:25 -07:00
committed by William Casarin
parent 4c37bfc128
commit 84cfeb1604
29 changed files with 484 additions and 25 deletions
+14 -1
View File
@@ -23,7 +23,11 @@ enum NostrResponse {
case notice(String)
case eose(String)
case ok(CommandResult)
/// An [NIP-42](https://github.com/nostr-protocol/nips/blob/master/42.md) `auth` challenge.
///
/// The associated type of this case is the challenge string sent by the server.
case auth(String)
var subid: String? {
switch self {
case .ok:
@@ -34,6 +38,8 @@ enum NostrResponse {
return sub_id
case .notice:
return nil
case .auth(let challenge_string):
return challenge_string
}
}
@@ -94,6 +100,13 @@ enum NostrResponse {
case NDB_TCE_NOTICE:
free(data)
return .notice("")
case NDB_TCE_AUTH:
defer { free(data) }
guard let challenge_string = sized_cstr(cstr: tce.subid, len: tce.subid_len) else {
return nil
}
return .auth(challenge_string)
default:
free(data)
return nil