From 348dff287039e6ea3b7f725ffba4429627305f0d Mon Sep 17 00:00:00 2001 From: Yuki Kishimoto Date: Sat, 24 Aug 2024 19:55:37 -0400 Subject: [PATCH] nostr: add `NostrWalletConnectURI::parse` Signed-off-by: Yuki Kishimoto --- CHANGELOG.md | 1 + crates/nostr/src/nips/nip47.rs | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fd211e5c..557e01c24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ * nostr: impl `TryFrom>` for `LiveEvent` ([w3irdrobot]) * nostr: add `Tag::as_slice` ([Yuki Kishimoto]) +* nostr: add `NostrWalletConnectURI::parse` ([Yuki Kishimoto]) * bindings(nostr): expose `as_pretty_json` for some structs ([Yuki Kishimoto]) * bindings(sdk): expose `Client::fetch_metadata` ([Yuki Kishimoto]) * ffi(nostr): expose `Kind::is_*` methods ([Yuki Kishimoto]) diff --git a/crates/nostr/src/nips/nip47.rs b/crates/nostr/src/nips/nip47.rs index 815e03db9..8e785af26 100644 --- a/crates/nostr/src/nips/nip47.rs +++ b/crates/nostr/src/nips/nip47.rs @@ -912,13 +912,13 @@ impl NostrWalletConnectURI { lud16, } } -} - -impl FromStr for NostrWalletConnectURI { - type Err = Error; - fn from_str(uri: &str) -> Result { - let url = Url::parse(uri)?; + /// Parse NWC URI + pub fn parse(uri: S) -> Result + where + S: AsRef, + { + let url: Url = Url::parse(uri.as_ref())?; if url.scheme() != NOSTR_WALLET_CONNECT_URI_SCHEME { return Err(Error::InvalidURIScheme); @@ -960,6 +960,14 @@ impl FromStr for NostrWalletConnectURI { } } +impl FromStr for NostrWalletConnectURI { + type Err = Error; + + fn from_str(uri: &str) -> Result { + Self::parse(uri) + } +} + impl fmt::Display for NostrWalletConnectURI { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // trailing slash is removed, this breaks some clients