Skip to content

Commit 0e96ef8

Browse files
committed
nostr: rename contact module to nip02
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 4625793 commit 0e96ef8

File tree

10 files changed

+30
-21
lines changed

10 files changed

+30
-21
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
* nostr: change `Filter::custom_tag` value arg type ([Yuki Kishimoto])
4141
* nostr: rename `Filter::remove_custom_tag` to `Filter::remove_custom_tags` ([Yuki Kishimoto])
4242
* nostr: take a single filter per REQ and COUNT ([Yuki Kishimoto])
43+
* nostr: rename `contact` module to `nip02` ([Yuki Kishimoto])
4344
* pool: change `Relay::connect` method signature ([Yuki Kishimoto])
4445
* pool: change `Relay::disconnect` method signature ([Yuki Kishimoto])
4546
* pool: change `RelayPool::disconnect` method signature ([Yuki Kishimoto])

bindings/nostr-sdk-ffi/src/protocol/event/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::ops::Deref;
77
use std::sync::Arc;
88

99
use nostr::util::EventIdOrCoordinate;
10-
use nostr::{Contact as ContactSdk, RelayUrl, Url};
10+
use nostr::{RelayUrl, Url};
1111
use uniffi::Object;
1212

1313
use super::{Event, EventId, Kind};
@@ -196,7 +196,7 @@ impl EventBuilder {
196196
/// <https://github.com/nostr-protocol/nips/blob/master/02.md>
197197
#[uniffi::constructor]
198198
pub fn contact_list(contacts: Vec<Contact>) -> Result<Self> {
199-
let mut list: Vec<ContactSdk> = Vec::with_capacity(contacts.len());
199+
let mut list = Vec::with_capacity(contacts.len());
200200
for contact in contacts.into_iter() {
201201
list.push(contact.try_into()?);
202202
}

bindings/nostr-sdk-ffi/src/protocol/types/contact.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use std::sync::Arc;
66

7+
use nostr::nips::nip02;
78
use nostr::RelayUrl;
89
use uniffi::Record;
910

@@ -17,18 +18,18 @@ pub struct Contact {
1718
pub alias: Option<String>,
1819
}
1920

20-
impl TryFrom<Contact> for nostr::Contact {
21+
impl TryFrom<Contact> for nip02::Contact {
2122
type Error = NostrSdkError;
2223

2324
fn try_from(contact: Contact) -> Result<Self, Self::Error> {
2425
let relay_url = match contact.relay_url {
2526
Some(url) => Some(RelayUrl::parse(&url)?),
2627
None => None,
2728
};
28-
Ok(nostr::Contact::new(
29-
**contact.public_key,
29+
Ok(nip02::Contact {
30+
public_key: **contact.public_key,
3031
relay_url,
31-
contact.alias,
32-
))
32+
alias: contact.alias,
33+
})
3334
}
3435
}

bindings/nostr-sdk-js/src/protocol/types/contact.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ impl JsContact {
4848
None => None,
4949
};
5050
Ok(Self {
51-
inner: Contact::new(**public_key, relay_url, alias),
51+
inner: Contact {
52+
public_key: **public_key,
53+
relay_url,
54+
alias,
55+
},
5256
})
5357
}
5458

crates/nostr-sdk/src/client/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,11 @@ impl Client {
10291029
uppercase: false,
10301030
}) = tag.to_standardized()
10311031
{
1032-
contact_list.push(Contact::new(public_key, relay_url, alias))
1032+
contact_list.push(Contact {
1033+
public_key,
1034+
relay_url,
1035+
alias,
1036+
})
10331037
}
10341038
}
10351039
}

crates/nostr/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub use self::nips::nip19::{FromBech32, ToBech32};
7171
#[doc(hidden)]
7272
pub use self::signer::{NostrSigner, SignerError};
7373
#[doc(hidden)]
74-
pub use self::types::{Contact, ImageDimensions, RelayUrl, Timestamp, TryIntoUrl, Url};
74+
pub use self::types::{ImageDimensions, RelayUrl, Timestamp, TryIntoUrl, Url};
7575
#[doc(hidden)]
7676
pub use self::util::JsonUtil;
7777
#[doc(hidden)]

crates/nostr/src/nips/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! See all at <https://github.com/nostr-protocol/nips>
88
99
pub mod nip01;
10+
pub mod nip02;
1011
#[cfg(feature = "nip04")]
1112
pub mod nip04;
1213
#[cfg(all(feature = "std", feature = "nip05"))]

crates/nostr/src/types/contact.rs crates/nostr/src/nips/nip02.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
// Copyright (c) 2023-2024 Rust Nostr Developers
33
// Distributed under the MIT software license
44

5-
//! Contact
5+
//! NIP02: Follow List
6+
//!
7+
//! <https://github.com/nostr-protocol/nips/blob/master/02.md>
68
79
use alloc::string::String;
810

911
use crate::key::PublicKey;
1012
use crate::types::RelayUrl;
1113

1214
/// Contact
13-
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
15+
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
1416
pub struct Contact {
1517
/// Public key
1618
pub public_key: PublicKey,
@@ -21,16 +23,13 @@ pub struct Contact {
2123
}
2224

2325
impl Contact {
24-
/// Create new [`Contact`]
26+
/// Create new contact
2527
#[inline]
26-
pub fn new<S>(public_key: PublicKey, relay_url: Option<RelayUrl>, alias: Option<S>) -> Self
27-
where
28-
S: Into<String>,
29-
{
28+
pub fn new(public_key: PublicKey) -> Self {
3029
Self {
3130
public_key,
32-
relay_url,
33-
alias: alias.map(|a| a.into()),
31+
relay_url: None,
32+
alias: None,
3433
}
3534
}
3635
}

crates/nostr/src/prelude.rs

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub use crate::key::{self, *};
2929
pub use crate::message::{self, *};
3030
// NIPs
3131
pub use crate::nips::nip01::{self, *};
32+
pub use crate::nips::nip02::{self, *};
3233
#[cfg(feature = "nip04")]
3334
pub use crate::nips::nip04;
3435
#[cfg(all(feature = "std", feature = "nip05"))]

crates/nostr/src/types/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
#![allow(unknown_lints)]
88
#![allow(ambiguous_glob_reexports)]
99

10-
pub mod contact;
1110
pub mod image;
1211
pub mod time;
1312
pub mod url;
1413

15-
pub use self::contact::*;
1614
pub use self::image::*;
1715
pub use self::time::*;
1816
pub use self::url::*;

0 commit comments

Comments
 (0)