Skip to content

Commit

Permalink
nostr: avoid PublicKey copy in NIP-05 module
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Aug 13, 2024
1 parent e318596 commit bd9fd8a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions crates/nostr/src/nips/nip05.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ fn get_key_from_json(json: &Value, name: &str) -> Option<PublicKey> {
}

#[inline]
fn get_relays_from_json(json: &Value, pk: PublicKey) -> Vec<Url> {
fn get_relays_from_json(json: &Value, pk: &PublicKey) -> Vec<Url> {
json.get("relays")
.and_then(|relays| relays.get(pk.to_hex()))
.and_then(|value| serde_json::from_value(value.clone()).ok())
.unwrap_or_default()
}

#[inline]
fn get_nip46_relays_from_json(json: &Value, pk: PublicKey) -> Vec<Url> {
fn get_nip46_relays_from_json(json: &Value, pk: &PublicKey) -> Vec<Url> {
json.get("nip46")
.and_then(|relays| relays.get(pk.to_hex()))
.and_then(|value| serde_json::from_value(value.clone()).ok())
Expand Down Expand Up @@ -178,8 +178,8 @@ where
let (json, name) = make_req(nip05.as_ref(), _proxy).await?;

let public_key: PublicKey = get_key_from_json(&json, name).ok_or(Error::ImpossibleToVerify)?;
let relays: Vec<Url> = get_relays_from_json(&json, public_key);
let nip46: Vec<Url> = get_nip46_relays_from_json(&json, public_key);
let relays: Vec<Url> = get_relays_from_json(&json, &public_key);
let nip46: Vec<Url> = get_nip46_relays_from_json(&json, &public_key);

Ok(Nip05Profile {
public_key,
Expand Down

0 comments on commit bd9fd8a

Please sign in to comment.