nip19: added swift enums
Add enums to reflect Bech32 with TLV encoded data. Update parse method to call C library for generalized parsing of bech32 data. Lightning-url: LNURL1DP68GURN8GHJ7EM9W3SKCCNE9E3K7MF0D3H82UNVWQHKWUN9V4HXGCTHDC6RZVGR8SW3G Signed-off-by: kernelkind <kernelkind@gmail.com> Reviewed-by: William Casarin <jb55@jb55.com> Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
committed by
William Casarin
parent
97fc415b8c
commit
cb4adf06f1
@@ -60,20 +60,7 @@ func decode_universal_link(_ s: String) -> NostrLink? {
|
||||
uri = uri.replacingOccurrences(of: "https://damus.io/", with: "")
|
||||
uri = uri.replacingOccurrences(of: "/", with: "")
|
||||
|
||||
guard let decoded = try? bech32_decode(uri),
|
||||
decoded.data.count == 32
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
|
||||
if decoded.hrp == "note" {
|
||||
return .ref(.event(NoteId(decoded.data)))
|
||||
} else if decoded.hrp == "npub" {
|
||||
return .ref(.pubkey(Pubkey(decoded.data)))
|
||||
}
|
||||
// TODO: handle nprofile, etc
|
||||
|
||||
return nil
|
||||
return decode_nostr_bech32_uri(uri)
|
||||
}
|
||||
|
||||
func decode_nostr_bech32_uri(_ s: String) -> NostrLink? {
|
||||
@@ -82,16 +69,24 @@ func decode_nostr_bech32_uri(_ s: String) -> NostrLink? {
|
||||
}
|
||||
|
||||
switch obj {
|
||||
case .nsec(let privkey):
|
||||
guard let pubkey = privkey_to_pubkey(privkey: privkey) else { return nil }
|
||||
return .ref(.pubkey(pubkey))
|
||||
case .npub(let pubkey):
|
||||
return .ref(.pubkey(pubkey))
|
||||
case .note(let id):
|
||||
return .ref(.event(id))
|
||||
case .nscript(let data):
|
||||
return .script(data)
|
||||
}
|
||||
case .nsec(let privkey):
|
||||
guard let pubkey = privkey_to_pubkey(privkey: privkey) else { return nil }
|
||||
return .ref(.pubkey(pubkey))
|
||||
case .npub(let pubkey):
|
||||
return .ref(.pubkey(pubkey))
|
||||
case .note(let id):
|
||||
return .ref(.event(id))
|
||||
case .nscript(let data):
|
||||
return .script(data)
|
||||
case .naddr(let naddr):
|
||||
return .none // TODO: FIX
|
||||
case .nevent(let nevent):
|
||||
return .ref(.event(nevent.noteid))
|
||||
case .nprofile(let nprofile):
|
||||
return .ref(.pubkey(nprofile.author))
|
||||
case .nrelay(_):
|
||||
return .none
|
||||
}
|
||||
}
|
||||
|
||||
func decode_nostr_uri(_ s: String) -> NostrLink? {
|
||||
|
||||
Reference in New Issue
Block a user