damus

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

commit a5726d4650de4f6a8cf2a9a84aeb7c5560537b45
parent 370a5feb4e4484f24a8f3f23794f29cb5e29c62b
Author: William Casarin <jb55@jb55.com>
Date:   Wed, 10 May 2023 11:10:43 -0700

nwc: add lud16 parameter

This will be used for auto-setting up the lightning wallet

See https://github.com/nostr-protocol/nips/pull/513

Diffstat:
Mdamus/Util/WalletConnect.swift | 22++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/damus/Util/WalletConnect.swift b/damus/Util/WalletConnect.swift @@ -17,10 +17,22 @@ struct WalletConnectURL: Equatable { let relay: RelayURL let keypair: FullKeypair let pubkey: String + let lud16: String? func to_url() -> URL { - let urlstr = "nostrwalletconnect://\(pubkey)?relay=\(relay.id)&secret=\(keypair.privkey)" - return URL(string: urlstr)! + var urlComponents = URLComponents() + urlComponents.scheme = "nostrwalletconnect" + urlComponents.host = pubkey + urlComponents.queryItems = [ + URLQueryItem(name: "relay", value: relay.id), + URLQueryItem(name: "secret", value: keypair.privkey) + ] + + if let lud16 { + urlComponents.queryItems?.append(URLQueryItem(name: "lud16", value: lud16)) + } + + return urlComponents.url! } init?(str: String) { @@ -37,14 +49,16 @@ struct WalletConnectURL: Equatable { return nil } + let lud16 = items.first(where: { qi in qi.name == "lud16" })?.value let keypair = FullKeypair(pubkey: our_pk, privkey: secret) - self = WalletConnectURL(pubkey: pk, relay: relay_url, keypair: keypair) + self = WalletConnectURL(pubkey: pk, relay: relay_url, keypair: keypair, lud16: lud16) } - init(pubkey: String, relay: RelayURL, keypair: FullKeypair) { + init(pubkey: String, relay: RelayURL, keypair: FullKeypair, lud16: String?) { self.pubkey = pubkey self.relay = relay self.keypair = keypair + self.lud16 = lud16 } }