Skip to content

Commit

Permalink
nostr: rename contact module to nip02
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Jan 30, 2025
1 parent 4625793 commit 0e96ef8
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
* nostr: change `Filter::custom_tag` value arg type ([Yuki Kishimoto])
* nostr: rename `Filter::remove_custom_tag` to `Filter::remove_custom_tags` ([Yuki Kishimoto])
* nostr: take a single filter per REQ and COUNT ([Yuki Kishimoto])
* nostr: rename `contact` module to `nip02` ([Yuki Kishimoto])
* pool: change `Relay::connect` method signature ([Yuki Kishimoto])
* pool: change `Relay::disconnect` method signature ([Yuki Kishimoto])
* pool: change `RelayPool::disconnect` method signature ([Yuki Kishimoto])
Expand Down
4 changes: 2 additions & 2 deletions bindings/nostr-sdk-ffi/src/protocol/event/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::ops::Deref;
use std::sync::Arc;

use nostr::util::EventIdOrCoordinate;
use nostr::{Contact as ContactSdk, RelayUrl, Url};
use nostr::{RelayUrl, Url};
use uniffi::Object;

use super::{Event, EventId, Kind};
Expand Down Expand Up @@ -196,7 +196,7 @@ impl EventBuilder {
/// <https://github.com/nostr-protocol/nips/blob/master/02.md>
#[uniffi::constructor]
pub fn contact_list(contacts: Vec<Contact>) -> Result<Self> {
let mut list: Vec<ContactSdk> = Vec::with_capacity(contacts.len());
let mut list = Vec::with_capacity(contacts.len());
for contact in contacts.into_iter() {
list.push(contact.try_into()?);
}
Expand Down
11 changes: 6 additions & 5 deletions bindings/nostr-sdk-ffi/src/protocol/types/contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use std::sync::Arc;

use nostr::nips::nip02;
use nostr::RelayUrl;
use uniffi::Record;

Expand All @@ -17,18 +18,18 @@ pub struct Contact {
pub alias: Option<String>,
}

impl TryFrom<Contact> for nostr::Contact {
impl TryFrom<Contact> for nip02::Contact {
type Error = NostrSdkError;

fn try_from(contact: Contact) -> Result<Self, Self::Error> {
let relay_url = match contact.relay_url {
Some(url) => Some(RelayUrl::parse(&url)?),
None => None,
};
Ok(nostr::Contact::new(
**contact.public_key,
Ok(nip02::Contact {
public_key: **contact.public_key,
relay_url,
contact.alias,
))
alias: contact.alias,
})
}
}
6 changes: 5 additions & 1 deletion bindings/nostr-sdk-js/src/protocol/types/contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ impl JsContact {
None => None,
};
Ok(Self {
inner: Contact::new(**public_key, relay_url, alias),
inner: Contact {
public_key: **public_key,
relay_url,
alias,
},
})
}

Expand Down
6 changes: 5 additions & 1 deletion crates/nostr-sdk/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,11 @@ impl Client {
uppercase: false,
}) = tag.to_standardized()
{
contact_list.push(Contact::new(public_key, relay_url, alias))
contact_list.push(Contact {
public_key,
relay_url,
alias,
})
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/nostr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub use self::nips::nip19::{FromBech32, ToBech32};
#[doc(hidden)]
pub use self::signer::{NostrSigner, SignerError};
#[doc(hidden)]
pub use self::types::{Contact, ImageDimensions, RelayUrl, Timestamp, TryIntoUrl, Url};
pub use self::types::{ImageDimensions, RelayUrl, Timestamp, TryIntoUrl, Url};
#[doc(hidden)]
pub use self::util::JsonUtil;
#[doc(hidden)]
Expand Down
1 change: 1 addition & 0 deletions crates/nostr/src/nips/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//! See all at <https://github.com/nostr-protocol/nips>
pub mod nip01;
pub mod nip02;
#[cfg(feature = "nip04")]
pub mod nip04;
#[cfg(all(feature = "std", feature = "nip05"))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
// Copyright (c) 2023-2024 Rust Nostr Developers
// Distributed under the MIT software license

//! Contact
//! NIP02: Follow List
//!
//! <https://github.com/nostr-protocol/nips/blob/master/02.md>
use alloc::string::String;

use crate::key::PublicKey;
use crate::types::RelayUrl;

/// Contact
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct Contact {
/// Public key
pub public_key: PublicKey,
Expand All @@ -21,16 +23,13 @@ pub struct Contact {
}

impl Contact {
/// Create new [`Contact`]
/// Create new contact
#[inline]
pub fn new<S>(public_key: PublicKey, relay_url: Option<RelayUrl>, alias: Option<S>) -> Self
where
S: Into<String>,
{
pub fn new(public_key: PublicKey) -> Self {
Self {
public_key,
relay_url,
alias: alias.map(|a| a.into()),
relay_url: None,
alias: None,
}
}
}
1 change: 1 addition & 0 deletions crates/nostr/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub use crate::key::{self, *};
pub use crate::message::{self, *};
// NIPs
pub use crate::nips::nip01::{self, *};
pub use crate::nips::nip02::{self, *};
#[cfg(feature = "nip04")]
pub use crate::nips::nip04;
#[cfg(all(feature = "std", feature = "nip05"))]
Expand Down
2 changes: 0 additions & 2 deletions crates/nostr/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
#![allow(unknown_lints)]
#![allow(ambiguous_glob_reexports)]

pub mod contact;
pub mod image;
pub mod time;
pub mod url;

pub use self::contact::*;
pub use self::image::*;
pub use self::time::*;
pub use self::url::*;

0 comments on commit 0e96ef8

Please sign in to comment.