Skip to content

Commit

Permalink
connect: rename Nip46Signer to NostrConnect
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Oct 30, 2024
1 parent a054335 commit 9c2d7d7
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 47 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
* sdk: deprecate `Client::reconcile` and `Client::reconcile_with` ([Yuki Kishimoto])
* sdk: use by default tor for onion relays if `tor` feature is enabled on non-mobile targets ([Yuki Kishimoto])
* signer: auto enable `nip44` feature if `nip59` is enabled ([Yuki Kishimoto])
* connect: rename `Nip46Signer` to `NostrConnect` ([Yuki Kishimoto])
* database: improve `BTreeCappedSet` ([Yuki Kishimoto])
* database: not save invalid event deletion ([Yuki Kishimoto])
* lmdb: not save event deletion ([Yuki Kishimoto])
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bindings/nostr-sdk-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ndb = ["nostr-sdk/ndb"]
[dependencies]
async-trait.workspace = true
async-utility.workspace = true
nostr-connect.workspace = true
nostr-ffi = { path = "../nostr-ffi" }
nostr-relay-builder.workspace = true
nostr-sdk = { workspace = true, default-features = false, features = ["all-nips", "tor"] }
Expand Down
4 changes: 2 additions & 2 deletions bindings/nostr-sdk-ffi/bindings-python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pip install nostr-sdk
```python
import asyncio
from datetime import timedelta
from nostr_sdk import Keys, Client, NostrSigner, EventBuilder, Filter, Metadata, init_logger, LogLevel
from nostr_sdk import *


async def main():
Expand All @@ -36,7 +36,7 @@ async def main():
# Or, initialize with NIP46 signer
# app_keys = Keys.parse("..")
# uri = NostrConnectUri.parse("bunker://.. or nostrconnect://..")
# nip46 = Nip46Signer(uri, app_keys, timedelta(seconds=60), None)
# nip46 = NostrConnect(uri, app_keys, timedelta(seconds=60), None)
# signer = NostrSigner.nip46(nip46)

client = Client(signer)
Expand Down
4 changes: 2 additions & 2 deletions bindings/nostr-sdk-ffi/bindings-python/examples/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
from datetime import timedelta
from nostr_sdk import Keys, Client, NostrSigner, EventBuilder, Filter, Metadata, init_logger, LogLevel
from nostr_sdk import *


async def main():
Expand All @@ -17,7 +17,7 @@ async def main():
# Or, initialize with NIP46 signer
# app_keys = Keys.parse("..")
# uri = NostrConnectUri.parse("bunker://.. or nostrconnect://..")
# nip46 = Nip46Signer(uri, app_keys, timedelta(seconds=60), None)
# nip46 = NostrConnect(uri, app_keys, timedelta(seconds=60), None)
# signer = NostrSigner.nip46(nip46)

client = Client(signer)
Expand Down
4 changes: 2 additions & 2 deletions bindings/nostr-sdk-ffi/src/client/signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use uniffi::Object;

pub mod nip46;

use self::nip46::Nip46Signer;
use self::nip46::NostrConnect;
use crate::error::Result;

#[derive(Object)]
Expand Down Expand Up @@ -43,7 +43,7 @@ impl NostrSigner {
}

#[uniffi::constructor]
pub fn nip46(nip46: &Nip46Signer) -> Self {
pub fn nip46(nip46: &NostrConnect) -> Self {
Self {
inner: signer::NostrSigner::nip46(nip46.deref().clone()),
}
Expand Down
18 changes: 9 additions & 9 deletions bindings/nostr-sdk-ffi/src/client/signer/nip46.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,36 @@ use std::ops::Deref;
use std::sync::Arc;
use std::time::Duration;

use nostr_connect::{client, signer};
use nostr_ffi::nips::nip46::{Nip46Request, NostrConnectURI};
use nostr_ffi::{Keys, PublicKey, SecretKey};
use nostr_sdk::nostr::nips::nip46::Request;
use nostr_sdk::signer;
use uniffi::Object;

use crate::error::Result;
use crate::relay::RelayOptions;

#[derive(Object)]
pub struct Nip46Signer {
inner: signer::Nip46Signer,
pub struct NostrConnect {
inner: client::NostrConnect,
}

impl Deref for Nip46Signer {
type Target = signer::Nip46Signer;
impl Deref for NostrConnect {
type Target = client::NostrConnect;

fn deref(&self) -> &Self::Target {
&self.inner
}
}

impl From<signer::Nip46Signer> for Nip46Signer {
fn from(inner: signer::Nip46Signer) -> Self {
impl From<client::NostrConnect> for NostrConnect {
fn from(inner: client::NostrConnect) -> Self {
Self { inner }
}
}

#[uniffi::export(async_runtime = "tokio")]
impl Nip46Signer {
impl NostrConnect {
/// Construct Nostr Connect client
#[uniffi::constructor]
pub fn new(
Expand All @@ -45,7 +45,7 @@ impl Nip46Signer {
opts: Option<Arc<RelayOptions>>,
) -> Result<Self> {
Ok(Self {
inner: signer::Nip46Signer::new(
inner: client::NostrConnect::new(
uri.deref().clone(),
app_keys.deref().clone(),
timeout,
Expand Down
8 changes: 4 additions & 4 deletions bindings/nostr-sdk-ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ impl From<nostr_sdk::database::DatabaseError> for NostrSdkError {
}
}

impl From<nostr_sdk::signer::Error> for NostrSdkError {
fn from(e: nostr_sdk::signer::Error) -> NostrSdkError {
impl From<nostr_sdk::signer::SignerError> for NostrSdkError {
fn from(e: nostr_sdk::signer::SignerError) -> NostrSdkError {
Self::Generic(e.to_string())
}
}

impl From<nostr_sdk::signer::nip46::Error> for NostrSdkError {
fn from(e: nostr_sdk::signer::nip46::Error) -> NostrSdkError {
impl From<nostr_connect::error::Error> for NostrSdkError {
fn from(e: nostr_connect::error::Error) -> NostrSdkError {
Self::Generic(e.to_string())
}
}
Expand Down
1 change: 1 addition & 0 deletions bindings/nostr-sdk-js/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ crate-type = ["lib", "cdylib"]
[dependencies]
console_error_panic_hook = "0.1"
js-sys.workspace = true
nostr-connect.workspace = true
nostr-sdk = { workspace = true, default-features = false, features = ["all-nips", "indexeddb", "webln"] }
tracing.workspace = true
tracing-subscriber.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions bindings/nostr-sdk-js/examples/nostr-connect.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Keys, Client, NostrSigner, Nip46Signer, NostrConnectURI, loadWasmAsync, initLogger, LogLevel, Duration } = require("../");
const { Keys, Client, NostrSigner, NostrConnect, NostrConnectURI, loadWasmAsync, initLogger, LogLevel, Duration } = require("../");

async function main() {
await loadWasmAsync();
Expand All @@ -11,7 +11,7 @@ async function main() {
// Remote signer (NIP46)
let uri = NostrConnectURI.parse("bunker://..");
let timeout = Duration.fromSecs(60);
let nip46 = new Nip46Signer(uri, appKeys, timeout);
let nip46 = new NostrConnect(uri, appKeys, timeout);
let signer = NostrSigner.nip46(nip46);

// Compose client and add relays
Expand Down
4 changes: 2 additions & 2 deletions bindings/nostr-sdk-js/src/client/signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use wasm_bindgen::prelude::*;

pub mod nip46;

use self::nip46::JsNip46Signer;
use self::nip46::JsNostrConnect;
use crate::error::{into_err, Result};
use crate::protocol::event::{JsEvent, JsEventBuilder, JsUnsignedEvent};
use crate::protocol::key::{JsKeys, JsPublicKey};
Expand Down Expand Up @@ -52,7 +52,7 @@ impl JsNostrSigner {
}

/// NIP46
pub fn nip46(signer: &JsNip46Signer) -> Self {
pub fn nip46(signer: &JsNostrConnect) -> Self {
Self {
inner: NostrSigner::nip46(signer.deref().clone()),
}
Expand Down
24 changes: 12 additions & 12 deletions bindings/nostr-sdk-js/src/client/signer/nip46.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use core::ops::Deref;

use js_sys::Array;
use nostr_sdk::signer::Nip46Signer;
use nostr_connect::prelude::*;
use wasm_bindgen::prelude::*;

use crate::duration::JsDuration;
Expand All @@ -14,36 +14,36 @@ use crate::protocol::key::{JsKeys, JsPublicKey};
use crate::protocol::nips::nip46::JsNostrConnectURI;
use crate::JsStringArray;

#[wasm_bindgen(js_name = Nip46Signer)]
pub struct JsNip46Signer {
inner: Nip46Signer,
#[wasm_bindgen(js_name = NostrConnect)]
pub struct JsNostrConnect {
inner: NostrConnect,
}

impl Deref for JsNip46Signer {
type Target = Nip46Signer;
impl Deref for JsNostrConnect {
type Target = NostrConnect;

fn deref(&self) -> &Self::Target {
&self.inner
}
}

impl From<Nip46Signer> for JsNip46Signer {
fn from(inner: Nip46Signer) -> Self {
impl From<NostrConnect> for JsNostrConnect {
fn from(inner: NostrConnect) -> Self {
Self { inner }
}
}

#[wasm_bindgen(js_class = Nip46Signer)]
impl JsNip46Signer {
#[wasm_bindgen(js_class = NostrConnect)]
impl JsNostrConnect {
/// Construct Nostr Connect client
#[wasm_bindgen]
pub fn new(
uri: &JsNostrConnectURI,
app_keys: &JsKeys,
timeout: &JsDuration,
) -> Result<JsNip46Signer> {
) -> Result<JsNostrConnect> {
Ok(Self {
inner: Nip46Signer::new(
inner: NostrConnect::new(
uri.deref().clone(),
app_keys.deref().clone(),
**timeout,
Expand Down
12 changes: 8 additions & 4 deletions crates/nostr-connect/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ use nostr_relay_pool::{
use tokio::sync::broadcast::Receiver;
use tokio::sync::OnceCell;

use super::Error;
use crate::error::Error;

#[allow(missing_docs)]
#[deprecated(since = "0.36.0", note = "Use `NostrConnect` instead")]
pub type Nip46Signer = NostrConnect;

/// Nostr Connect Client
///
/// <https://github.com/nostr-protocol/nips/blob/master/46.md>
#[derive(Debug, Clone)]
pub struct Nip46Signer {
pub struct NostrConnect {
app_keys: Keys,
uri: NostrConnectURI,
signer_public_key: OnceCell<PublicKey>,
Expand All @@ -36,7 +40,7 @@ pub struct Nip46Signer {
bootstrapped: Arc<AtomicBool>,
}

impl Nip46Signer {
impl NostrConnect {
/// Construct Nostr Connect client
pub fn new(
uri: NostrConnectURI,
Expand Down Expand Up @@ -344,7 +348,7 @@ async fn get_signer_public_key(

#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
impl NostrSigner for Nip46Signer {
impl NostrSigner for NostrConnect {
async fn public_key(&self) -> Result<PublicKey, SignerError> {
// TODO: avoid copied?
self.signer_public_key()
Expand Down
4 changes: 0 additions & 4 deletions crates/nostr-connect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,3 @@ pub mod client;
pub mod error;
pub mod prelude;
pub mod signer;

pub use self::client::Nip46Signer;
pub use self::error::Error;
pub use self::signer::{NostrConnectRemoteSigner, NostrConnectSignerActions};
4 changes: 3 additions & 1 deletion crates/nostr-connect/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@

pub use nostr::prelude::*;

pub use crate::*;
pub use crate::client::*;
pub use crate::error::*;
pub use crate::signer::*;
2 changes: 1 addition & 1 deletion crates/nostr-connect/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use nostr_relay_pool::{
pool, RelayOptions, RelayPool, RelayPoolNotification, RelaySendOptions, SubscribeOptions,
};

use super::Error;
use crate::error::Error;

/// Nostr Connect Signer
///
Expand Down
4 changes: 2 additions & 2 deletions crates/nostr-sdk/examples/nostr-connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async fn main() -> Result<()> {

// Compose signer from bunker URI
let uri = NostrConnectURI::parse("bunker://79dff8f82963424e0bb02708a22e44b4980893e3a4be0fa3cb60a43b946764e3?relay=wss%3A%2F%2Frelay.nsec.app")?;
let signer = Nip46Signer::new(uri, app_keys, Duration::from_secs(60), None)?;
let signer = NostrConnect::new(uri, app_keys, Duration::from_secs(60), None)?;

// Compose signer
/* let uri = NostrConnectURI::client(
Expand All @@ -24,7 +24,7 @@ async fn main() -> Result<()> {
"Test app",
);
println!("\n{uri}\n");
let signer = Nip46Signer::new(uri, app_keys, Duration::from_secs(60), None).await?; */
let signer = NostrConnect::new(uri, app_keys, Duration::from_secs(60), None).await?; */

// Get bunker URI for future connections
let bunker_uri: NostrConnectURI = signer.bunker_uri().await?;
Expand Down

0 comments on commit 9c2d7d7

Please sign in to comment.