Skip to content

Commit 5759cb8

Browse files
committed
chore: gates structs behind features
1 parent 928cd4a commit 5759cb8

File tree

10 files changed

+54
-14
lines changed

10 files changed

+54
-14
lines changed

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cashu/src/nuts/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub mod nut09;
1515
pub mod nut10;
1616
pub mod nut11;
1717
pub mod nut12;
18+
#[cfg(feature = "wallet")]
1819
pub mod nut13;
1920
pub mod nut14;
2021
pub mod nut15;
@@ -24,14 +25,18 @@ pub mod nut19;
2425
pub mod nut20;
2526

2627
pub use nut00::{
27-
BlindSignature, BlindedMessage, CurrencyUnit, PaymentMethod, PreMint, PreMintSecrets, Proof,
28-
Proofs, ProofsMethods, Token, TokenV3, TokenV4, Witness,
28+
BlindSignature, BlindedMessage, CurrencyUnit, PaymentMethod, Proof, Proofs, ProofsMethods,
29+
Token, TokenV3, TokenV4, Witness,
2930
};
31+
#[cfg(feature = "wallet")]
32+
pub use nut00::{PreMint, PreMintSecrets};
3033
pub use nut01::{Keys, KeysResponse, PublicKey, SecretKey};
3134
#[cfg(feature = "mint")]
3235
pub use nut02::MintKeySet;
3336
pub use nut02::{Id, KeySet, KeySetInfo, KeysetResponse};
34-
pub use nut03::{PreSwap, SwapRequest, SwapResponse};
37+
#[cfg(feature = "wallet")]
38+
pub use nut03::PreSwap;
39+
pub use nut03::{SwapRequest, SwapResponse};
3540
pub use nut04::{
3641
MintBolt11Request, MintBolt11Response, MintMethodSettings, MintQuoteBolt11Request,
3742
MintQuoteBolt11Response, QuoteState as MintQuoteState, Settings as NUT04Settings,

crates/cashu/src/nuts/nut00/mod.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,18 @@ use std::string::FromUtf8Error;
1111
use serde::{de, Deserialize, Deserializer, Serialize};
1212
use thiserror::Error;
1313

14+
#[cfg(feature = "wallet")]
1415
use super::nut10;
16+
#[cfg(feature = "wallet")]
1517
use super::nut11::SpendingConditions;
18+
#[cfg(feature = "wallet")]
1619
use crate::amount::SplitTarget;
17-
use crate::dhke::{blind_message, hash_to_curve};
18-
use crate::nuts::nut01::{PublicKey, SecretKey};
20+
#[cfg(feature = "wallet")]
21+
use crate::dhke::blind_message;
22+
use crate::dhke::hash_to_curve;
23+
use crate::nuts::nut01::PublicKey;
24+
#[cfg(feature = "wallet")]
25+
use crate::nuts::nut01::SecretKey;
1926
use crate::nuts::nut11::{serde_p2pk_witness, P2PKWitness};
2027
use crate::nuts::nut12::BlindSignatureDleq;
2128
use crate::nuts::nut14::{serde_htlc_witness, HTLCWitness};
@@ -491,6 +498,7 @@ impl<'de> Deserialize<'de> for PaymentMethod {
491498
}
492499

493500
/// PreMint
501+
#[cfg(feature = "wallet")]
494502
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
495503
pub struct PreMint {
496504
/// Blinded message
@@ -503,19 +511,22 @@ pub struct PreMint {
503511
pub amount: Amount,
504512
}
505513

514+
#[cfg(feature = "wallet")]
506515
impl Ord for PreMint {
507516
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
508517
self.amount.cmp(&other.amount)
509518
}
510519
}
511520

521+
#[cfg(feature = "wallet")]
512522
impl PartialOrd for PreMint {
513523
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
514524
Some(self.cmp(other))
515525
}
516526
}
517527

518528
/// Premint Secrets
529+
#[cfg(feature = "wallet")]
519530
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
520531
pub struct PreMintSecrets {
521532
/// Secrets
@@ -524,6 +535,7 @@ pub struct PreMintSecrets {
524535
pub keyset_id: Id,
525536
}
526537

538+
#[cfg(feature = "wallet")]
527539
impl PreMintSecrets {
528540
/// Create new [`PreMintSecrets`]
529541
pub fn new(keyset_id: Id) -> Self {
@@ -712,6 +724,7 @@ impl PreMintSecrets {
712724
}
713725

714726
// Implement Iterator for PreMintSecrets
727+
#[cfg(feature = "wallet")]
715728
impl Iterator for PreMintSecrets {
716729
type Item = PreMint;
717730

@@ -721,12 +734,14 @@ impl Iterator for PreMintSecrets {
721734
}
722735
}
723736

737+
#[cfg(feature = "wallet")]
724738
impl Ord for PreMintSecrets {
725739
fn cmp(&self, other: &Self) -> Ordering {
726740
self.secrets.cmp(&other.secrets)
727741
}
728742
}
729743

744+
#[cfg(feature = "wallet")]
730745
impl PartialOrd for PreMintSecrets {
731746
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
732747
Some(self.cmp(other))

crates/cashu/src/nuts/nut02.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,28 @@
55
use core::fmt;
66
use core::str::FromStr;
77
use std::array::TryFromSliceError;
8+
#[cfg(feature = "mint")]
89
use std::collections::BTreeMap;
910

11+
#[cfg(feature = "mint")]
1012
use bitcoin::bip32::{ChildNumber, DerivationPath, Xpriv};
1113
use bitcoin::hashes::sha256::Hash as Sha256;
1214
use bitcoin::hashes::Hash;
15+
#[cfg(feature = "mint")]
1316
use bitcoin::key::Secp256k1;
17+
#[cfg(feature = "mint")]
1418
use bitcoin::secp256k1;
1519
use serde::{Deserialize, Serialize};
1620
use serde_with::{serde_as, VecSkipError};
1721
use thiserror::Error;
1822

19-
use super::nut01::{Keys, MintKeyPair, MintKeys};
23+
use super::nut01::Keys;
24+
#[cfg(feature = "mint")]
25+
use super::nut01::{MintKeyPair, MintKeys};
2026
use crate::amount::AmountStr;
2127
use crate::nuts::nut00::CurrencyUnit;
2228
use crate::util::hex;
29+
#[cfg(feature = "mint")]
2330
use crate::Amount;
2431

2532
/// NUT02 Error
@@ -228,6 +235,7 @@ impl KeySet {
228235
}
229236
}
230237

238+
#[cfg(feature = "mint")]
231239
impl From<MintKeySet> for KeySet {
232240
fn from(keyset: MintKeySet) -> Self {
233241
Self {
@@ -258,6 +266,7 @@ fn default_input_fee_ppk() -> u64 {
258266
0
259267
}
260268

269+
#[cfg(feature = "mint")]
261270
/// MintKeyset
262271
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
263272
pub struct MintKeySet {
@@ -269,6 +278,7 @@ pub struct MintKeySet {
269278
pub keys: MintKeys,
270279
}
271280

281+
#[cfg(feature = "mint")]
272282
impl MintKeySet {
273283
/// Generate new [`MintKeySet`]
274284
pub fn generate<C: secp256k1::Signing>(
@@ -343,6 +353,7 @@ impl MintKeySet {
343353
}
344354
}
345355

356+
#[cfg(feature = "mint")]
346357
impl From<MintKeySet> for Id {
347358
fn from(keyset: MintKeySet) -> Id {
348359
let keys: super::KeySet = keyset.into();
@@ -351,6 +362,7 @@ impl From<MintKeySet> for Id {
351362
}
352363
}
353364

365+
#[cfg(feature = "mint")]
354366
impl From<&MintKeys> for Id {
355367
fn from(map: &MintKeys) -> Self {
356368
let keys: super::Keys = map.clone().into();

crates/cashu/src/nuts/nut03.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
use serde::{Deserialize, Serialize};
66
use thiserror::Error;
77

8-
use super::nut00::{BlindSignature, BlindedMessage, PreMintSecrets, Proofs};
8+
#[cfg(feature = "wallet")]
9+
use super::nut00::PreMintSecrets;
10+
use super::nut00::{BlindSignature, BlindedMessage, Proofs};
911
use crate::Amount;
1012

1113
/// NUT03 Error
@@ -20,6 +22,7 @@ pub enum Error {
2022
}
2123

2224
/// Preswap information
25+
#[cfg(feature = "wallet")]
2326
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
2427
pub struct PreSwap {
2528
/// Preswap mint secrets

crates/cdk-common/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ rust-version = "1.63.0" # MSRV
99
default = ["mint", "wallet"]
1010
swagger = ["dep:utoipa", "cashu/swagger"]
1111
bench = []
12-
wallet = ["cashu/wallet"]
12+
wallet = ["cashu/wallet", "dep:reqwest"]
1313
mint = ["cashu/mint", "dep:uuid"]
1414

1515
[dependencies]
@@ -23,7 +23,6 @@ bitcoin = { version = "0.32.2", features = [
2323
cashu = { path = "../cashu", default-features = false, version = "0.6.0" }
2424
cbor-diag = "0.1.12"
2525
ciborium = { version = "0.2.2", default-features = false, features = ["std"] }
26-
once_cell = "1.20.2"
2726
serde = { version = "1", features = ["derive"] }
2827
lightning-invoice = { version = "0.32.0", features = ["serde", "std"] }
2928
thiserror = "2"
@@ -42,7 +41,7 @@ reqwest = { version = "0.12", default-features = false, features = [
4241
"brotli",
4342
"gzip",
4443
"deflate",
45-
] }
44+
], optional = true }
4645
serde_json = "1"
4746
serde_with = "3"
4847

crates/cdk-common/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ pub enum Error {
199199
HexError(#[from] hex::Error),
200200
/// From hex error
201201
#[error(transparent)]
202+
#[cfg(feature = "wallet")]
202203
ReqwestError(#[from] reqwest::Error),
203204

204205
// Crate error conversions
@@ -237,6 +238,7 @@ pub enum Error {
237238
NUT12(#[from] crate::nuts::nut12::Error),
238239
/// NUT13 Error
239240
#[error(transparent)]
241+
#[cfg(feature = "wallet")]
240242
NUT13(#[from] crate::nuts::nut13::Error),
241243
/// NUT14 Error
242244
#[error(transparent)]

crates/cdk-common/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub mod subscription;
1717
pub mod ws;
1818

1919
// re-exporting external crates
20+
pub use bitcoin;
2021
pub use cashu::amount::{self, Amount};
2122
pub use cashu::lightning_invoice::{self, Bolt11Invoice};
2223
#[cfg(feature = "mint")]
@@ -25,4 +26,5 @@ pub use cashu::nuts::{self, *};
2526
#[cfg(feature = "wallet")]
2627
pub use cashu::wallet;
2728
pub use cashu::{dhke, mint_url, secret, util, SECP256K1};
28-
pub use {bitcoin, reqwest};
29+
#[cfg(feature = "wallet")]
30+
pub use reqwest;

crates/cdk-common/src/ws.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
//!
33
//! This module extends the `cashu` crate with types and functions for the CDK, using the correct
44
//! expected ID types.
5+
#[cfg(feature = "mint")]
56
use cashu::nut17::ws::JSON_RPC_VERSION;
67
use cashu::nut17::{self};
8+
#[cfg(feature = "mint")]
79
use cashu::NotificationPayload;
10+
#[cfg(feature = "mint")]
811
use uuid::Uuid;
912

1013
use crate::pub_sub::SubId;
@@ -21,6 +24,7 @@ pub type WsErrorBody = nut17::ws::WsErrorBody;
2124
pub type WsMessageOrResponse = nut17::ws::WsMessageOrResponse<SubId>;
2225
pub type NotificationInner<T> = nut17::ws::NotificationInner<T, SubId>;
2326

27+
#[cfg(feature = "mint")]
2428
pub fn notification_uuid_to_notification_string(
2529
notification: NotificationInner<Uuid>,
2630
) -> NotificationInner<String> {
@@ -38,6 +42,7 @@ pub fn notification_uuid_to_notification_string(
3842
}
3943
}
4044

45+
#[cfg(feature = "mint")]
4146
pub fn notification_to_ws_message(notification: NotificationInner<Uuid>) -> WsMessageOrResponse {
4247
nut17::ws::WsMessageOrResponse::Notification(nut17::ws::WsNotification {
4348
jsonrpc: JSON_RPC_VERSION.to_owned(),

crates/cdk/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ bitcoin = { version = "0.32.2", features = [
3434
] }
3535
ciborium = { version = "0.2.2", default-features = false, features = ["std"] }
3636
lightning-invoice = { version = "0.32.0", features = ["serde", "std"] }
37-
once_cell = "1.19"
3837
regex = "1"
3938
reqwest = { version = "0.12", default-features = false, features = [
4039
"json",

0 commit comments

Comments
 (0)