Skip to content

Commit

Permalink
nostr: add NostrWalletConnectURI::parse
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Aug 24, 2024
1 parent 2f230ce commit 348dff2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

* nostr: impl `TryFrom<Vec<Tag>>` 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])
Expand Down
20 changes: 14 additions & 6 deletions crates/nostr/src/nips/nip47.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,13 +912,13 @@ impl NostrWalletConnectURI {
lud16,
}
}
}

impl FromStr for NostrWalletConnectURI {
type Err = Error;

fn from_str(uri: &str) -> Result<Self, Self::Err> {
let url = Url::parse(uri)?;
/// Parse NWC URI
pub fn parse<S>(uri: S) -> Result<Self, Error>
where
S: AsRef<str>,
{
let url: Url = Url::parse(uri.as_ref())?;

if url.scheme() != NOSTR_WALLET_CONNECT_URI_SCHEME {
return Err(Error::InvalidURIScheme);
Expand Down Expand Up @@ -960,6 +960,14 @@ impl FromStr for NostrWalletConnectURI {
}
}

impl FromStr for NostrWalletConnectURI {
type Err = Error;

fn from_str(uri: &str) -> Result<Self, Self::Err> {
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
Expand Down

0 comments on commit 348dff2

Please sign in to comment.