damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 29915aa8fe9f4d2baeab830317e87581fc079817
parent 2f0bf20845addeacce5bebdd821626dc109cac2f
Author: William Casarin <jb55@jb55.com>
Date:   Sun, 25 Dec 2022 20:27:04 -0800

ln: always make an lnurl link instead of lnaddr

Changelog-Fixed: Fix lightning tip button sometimes not working

Diffstat:
Mdamus/Nostr/Nostr.swift | 28+++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/damus/Nostr/Nostr.swift b/damus/Nostr/Nostr.swift @@ -57,13 +57,25 @@ struct Profile: Codable { set(s) { value["lud16"] = s } } + var lnurl: String? { + guard let addr = lud06 ?? lud16 else { + return nil; + } + + if addr.contains("@") { + return lnaddress_to_lnurl(addr); + } + + return addr; + } + var nip05: String? { get { return value["nip05"]; } set(s) { value["nip05"] = s } } var lightning_uri: URL? { - return make_ln_url(self.lud06) ?? make_ln_url(self.lud16) + return make_ln_url(self.lnurl) } init(from decoder: Decoder) throws { @@ -110,3 +122,17 @@ struct NostrSubscription { let sub_id: String let filter: NostrFilter } + +func lnaddress_to_lnurl(_ lnaddr: String) -> String? { + let parts = lnaddr.split(separator: "@") + guard parts.count == 2 else { + return nil + } + + let url = "https://\(parts[1])/.well-known/lnurlp/\(parts[0])"; + guard let dat = url.data(using: .utf8) else { + return nil + } + + return bech32_encode(hrp: "lnurl", Array(dat)) +}