Skip to content

Commit

Permalink
nostr: use url in std and url-fork in no_std
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Jan 21, 2024
1 parent 7b604de commit ac198ac
Show file tree
Hide file tree
Showing 24 changed files with 45 additions and 47 deletions.
18 changes: 12 additions & 6 deletions Cargo.lock

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

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,13 @@ tokio = { version = "1", default-features = false }
tracing = { version = "0.1", default-features = false }
tracing-subscriber = "0.3"
uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "59c1e3ef15b1ea5143402e25264e933dbf8d1a1f" }
url-fork = { version = "3.0", default-features = false }
wasm-bindgen = { version = "0.2", default-features = false }
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", default-features = false }

# Pathces needed to reduce bindings size
[patch.crates-io]
bip39 = { git = "https://github.com/rust-bitcoin/rust-bip39", rev = "256a00e7c23c5b2ecc04df90894f60248c8d56d5" }
url = { git = "https://github.com/yukibtc/rust-url", rev = "233f5ceffcd053b93b7f98f4ec86cd9d68dcde2d" }
url-fork = { git = "https://github.com/yukibtc/rust-url", rev = "233f5ceffcd053b93b7f98f4ec86cd9d68dcde2d" }

[profile.release]
lto = true
Expand Down
4 changes: 2 additions & 2 deletions bindings/nostr-ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ impl From<nostr::secp256k1::Error> for NostrError {
}
}

impl From<nostr::url::ParseError> for NostrError {
fn from(e: nostr::url::ParseError) -> NostrError {
impl From<nostr::types::url::ParseError> for NostrError {
fn from(e: nostr::types::url::ParseError) -> NostrError {
Self::Generic { err: e.to_string() }
}
}
Expand Down
3 changes: 1 addition & 2 deletions bindings/nostr-ffi/src/event/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use std::collections::HashMap;
use std::ops::Deref;
use std::sync::Arc;

use nostr::url::Url;
use nostr::{Contact as ContactSdk, UncheckedUrl};
use nostr::{Contact as ContactSdk, UncheckedUrl, Url};
use uniffi::Object;

use super::{Event, EventId};
Expand Down
2 changes: 1 addition & 1 deletion bindings/nostr-ffi/src/nips/nip94.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::sync::Arc;

use nostr::hashes::sha256::Hash as Sha256Hash;
use nostr::nips::nip94;
use nostr::url::Url;
use nostr::Url;
use uniffi::Object;

use crate::error::Result;
Expand Down
4 changes: 2 additions & 2 deletions bindings/nostr-sdk-ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ impl From<AddrParseError> for NostrSdkError {
}
}

impl From<nostr_sdk::url::ParseError> for NostrSdkError {
fn from(e: nostr_sdk::url::ParseError) -> NostrSdkError {
impl From<nostr_sdk::types::url::ParseError> for NostrSdkError {
fn from(e: nostr_sdk::types::url::ParseError) -> NostrSdkError {
Self::Generic { err: e.to_string() }
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/nostr-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ nip57 = ["nostr/nip57", "dep:lnurl-pay"]

[dependencies]
async-utility.workspace = true
async-wsocket = "0.1"
async-wsocket = "0.2"
lnurl-pay = { version = "0.2", features = ["api"], optional = true }
nostr = { workspace = true, features = ["std"] }
nostr-database.workspace = true
Expand Down
3 changes: 1 addition & 2 deletions crates/nostr-sdk/src/client/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ use std::time::Duration;

use nostr::key::XOnlyPublicKey;
use nostr::nips::nip94::FileMetadata;
use nostr::url::Url;
use nostr::{
ClientMessage, Contact, Event, EventBuilder, EventId, Filter, Keys, Metadata, Result, Tag,
ClientMessage, Contact, Event, EventBuilder, EventId, Filter, Keys, Metadata, Result, Tag, Url,
};
use nostr_database::DynNostrDatabase;
use tokio::sync::broadcast;
Expand Down
5 changes: 2 additions & 3 deletions crates/nostr-sdk/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ use nostr::key::XOnlyPublicKey;
use nostr::nips::nip46::{Request, Response};
use nostr::nips::nip94::FileMetadata;
use nostr::types::metadata::Error as MetadataError;
use nostr::url::Url;
use nostr::util::EventIdOrCoordinate;
use nostr::{
ClientMessage, Contact, Event, EventBuilder, EventId, Filter, JsonUtil, Keys, Kind, Metadata,
Result, Tag, Timestamp,
Result, Tag, Timestamp, Url,
};
use nostr_database::DynNostrDatabase;
use tokio::sync::{broadcast, RwLock};
Expand Down Expand Up @@ -55,7 +54,7 @@ pub enum Error {
Keys(#[from] nostr::key::Error),
/// Url parse error
#[error("impossible to parse URL: {0}")]
Url(#[from] nostr::url::ParseError),
Url(#[from] nostr::types::url::ParseError),
/// [`RelayPool`] error
#[error("relay pool error: {0}")]
RelayPool(#[from] RelayPoolError),
Expand Down
2 changes: 1 addition & 1 deletion crates/nostr-sdk/src/relay/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use crate::util::TryIntoUrl;
pub enum Error {
/// Url parse error
#[error("impossible to parse URL: {0}")]
Url(#[from] nostr::url::ParseError),
Url(#[from] nostr::types::url::ParseError),
/// Relay error
#[error(transparent)]
Relay(#[from] RelayError),
Expand Down
2 changes: 1 addition & 1 deletion crates/nostr-sdk/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

//! Util
use nostr::url::{ParseError, Url};
use nostr::types::url::{ParseError, Url};

/// Try into [`Url`]
pub trait TryIntoUrl {
Expand Down
2 changes: 1 addition & 1 deletion crates/nostr-sqlite/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub enum Error {
Flatbuffers(#[from] flatbuffers::Error),
/// Url error
#[error(transparent)]
Url(#[from] nostr::url::ParseError),
Url(#[from] nostr::types::url::ParseError),
/// Not found
#[error("sqlite: {0} not found")]
NotFound(String),
Expand Down
6 changes: 4 additions & 2 deletions crates/nostr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ rustdoc-args = ["--cfg", "docsrs"]
default = ["std", "all-nips"]
std = [
"dep:once_cell",
"dep:url",
"cbc?/std",
"base64?/std",
"bitcoin/std",
Expand All @@ -30,10 +31,10 @@ std = [
"serde_json/std",
"serde_json/preserve_order",
"tracing/std",
"url-fork/std",
"wasm-bindgen?/std",
]
alloc = [
"dep:url-fork",
"cbc?/alloc",
"base64?/alloc",
"bitcoin/no-std",
Expand Down Expand Up @@ -67,7 +68,8 @@ reqwest = { version = "0.11", default-features = false, features = ["json", "rus
serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_json.workspace = true
tracing.workspace = true
url-fork = { workspace = true, features = ["serde"] }
url = { version = "2.5", default-features = false, features = ["serde"], optional = true } # Used in std
url-fork = { version = "3.0", default-features = false, features = ["serde"], optional = true } # Used for no_std

[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.2", features = ["js"] }
Expand Down
6 changes: 2 additions & 4 deletions crates/nostr/src/event/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use bitcoin::secp256k1::rand;
use bitcoin::secp256k1::rand::{CryptoRng, Rng};
use bitcoin::secp256k1::{self, Secp256k1, Signing, XOnlyPublicKey};
use serde_json::{json, Value};
use url_fork::Url;

use super::kind::{Kind, NIP90_JOB_REQUEST_RANGE, NIP90_JOB_RESULT_RANGE};
use super::tag::ImageDimensions;
Expand All @@ -40,7 +39,7 @@ use crate::types::{Contact, Metadata, Timestamp};
use crate::util::EventIdOrCoordinate;
#[cfg(feature = "std")]
use crate::SECP256K1;
use crate::{JsonUtil, RelayMetadata, UncheckedUrl};
use crate::{JsonUtil, RelayMetadata, UncheckedUrl, Url};

/// Wrong kind error
#[derive(Debug)]
Expand Down Expand Up @@ -335,8 +334,7 @@ impl EventBuilder {
///
/// # Example
/// ```rust,no_run
/// use nostr::url::Url;
/// use nostr::{EventBuilder, Metadata};
/// use nostr::{EventBuilder, Metadata, Url};
///
/// let metadata = Metadata::new()
/// .name("username")
Expand Down
2 changes: 1 addition & 1 deletion crates/nostr/src/event/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ use bitcoin::secp256k1::{self, XOnlyPublicKey};
use serde::de::Error as DeserializerError;
use serde::ser::SerializeSeq;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use url_fork::{ParseError, Url};

use super::id::{self, EventId};
use crate::nips::nip26::{Conditions, Error as Nip26Error};
use crate::nips::nip48::Protocol;
use crate::nips::nip53::{self, LiveEventMarker, LiveEventStatus};
use crate::nips::nip90::DataVendingMachineStatus;
use crate::types::url::{ParseError, Url};
use crate::{Event, JsonUtil, Kind, Timestamp, UncheckedUrl};

/// [`Tag`] error
Expand Down
3 changes: 1 addition & 2 deletions crates/nostr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ extern crate serde;
#[cfg(feature = "nip06")]
pub use bip39;
pub use bitcoin::{bech32, hashes, secp256k1};
pub use url_fork::{self as url, Url};
pub use {bitcoin, negentropy, serde_json};

pub mod event;
Expand All @@ -57,7 +56,7 @@ pub use self::message::{
Alphabet, ClientMessage, Filter, GenericTagValue, RawRelayMessage, RelayMessage, SubscriptionId,
};
pub use self::nips::nip19::{FromBech32, ToBech32};
pub use self::types::{Contact, Metadata, Timestamp, UncheckedUrl};
pub use self::types::{Contact, Metadata, Timestamp, UncheckedUrl, Url};
pub use self::util::JsonUtil;
#[cfg(feature = "std")]
pub use self::util::SECP256K1;
Expand Down
3 changes: 1 addition & 2 deletions crates/nostr/src/nips/nip11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ use std::net::SocketAddr;

#[cfg(not(target_arch = "wasm32"))]
use reqwest::Proxy;
use url_fork::Url;

use crate::types::time::Timestamp;
use crate::{Timestamp, Url};

/// `NIP11` error
#[derive(Debug)]
Expand Down
4 changes: 2 additions & 2 deletions crates/nostr/src/nips/nip46.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ use bitcoin::secp256k1::schnorr::Signature;
use bitcoin::secp256k1::{self, Message as Secp256k1Message, Secp256k1, Signing, XOnlyPublicKey};
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use url_fork::form_urlencoded::byte_serialize;
use url_fork::{ParseError, Url};

use super::nip04;
use super::nip26::{self, sign_delegation_with_ctx, Conditions};
use crate::event::unsigned::{self, UnsignedEvent};
use crate::key::{self, Keys};
use crate::types::url::form_urlencoded::byte_serialize;
use crate::types::url::{ParseError, Url};
#[cfg(feature = "std")]
use crate::SECP256K1;
use crate::{Event, JsonUtil};
Expand Down
4 changes: 2 additions & 2 deletions crates/nostr/src/nips/nip47.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ use core::str::FromStr;
use bitcoin::secp256k1::{self, SecretKey, XOnlyPublicKey};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_json::Value;
use url_fork::form_urlencoded::byte_serialize;
use url_fork::{ParseError, Url};

#[cfg(feature = "std")]
use super::nip04;
use crate::types::url::form_urlencoded::byte_serialize;
use crate::types::url::{ParseError, Url};
use crate::JsonUtil;
#[cfg(feature = "std")]
use crate::{Event, EventBuilder, Keys, Kind, Tag};
Expand Down
3 changes: 1 addition & 2 deletions crates/nostr/src/nips/nip94.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ use alloc::string::String;
use alloc::vec::Vec;

use bitcoin::hashes::sha256::Hash as Sha256Hash;
use url_fork::Url;

use crate::{ImageDimensions, Tag};
use crate::{ImageDimensions, Tag, Url};

/// Potential errors returned when parsing tags into a [FileMetadata] struct
#[derive(Debug, PartialEq, Eq)]
Expand Down
1 change: 0 additions & 1 deletion crates/nostr/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub use bitcoin::secp256k1::*;
pub use bitcoin::*;
pub use negentropy::*;
pub use serde_json::*;
pub use url_fork::*;

// Internal modules
pub use crate::event::builder::*;
Expand Down
3 changes: 1 addition & 2 deletions crates/nostr/src/types/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ use serde::de::{Deserializer, MapAccess, Visitor};
use serde::ser::{SerializeMap, Serializer};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use url_fork::Url;

use crate::JsonUtil;
use crate::{JsonUtil, Url};

/// [`Metadata`] error
#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion crates/nostr/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ pub mod url;
pub use self::contact::Contact;
pub use self::metadata::Metadata;
pub use self::time::Timestamp;
pub use self::url::UncheckedUrl;
pub use self::url::{UncheckedUrl, Url};
5 changes: 4 additions & 1 deletion crates/nostr/src/types/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use alloc::string::String;
use core::fmt;
use core::str::FromStr;

use url_fork::{ParseError, Url};
#[cfg(feature = "std")]
pub use url::*;
#[cfg(not(feature = "std"))]
pub use url_fork::*;

/// Unchecked Url
#[derive(Debug, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
Expand Down

0 comments on commit ac198ac

Please sign in to comment.