Browse Source

Merge remote-tracking branch 'origin/feature/cdk-common' into feature/cdk-common

Cesar Rodas 2 months ago
parent
commit
36c1d2a8e5

+ 13 - 4
.github/workflows/ci.yml

@@ -49,6 +49,16 @@ jobs:
       matrix:
         build-args:
           [
+            -p cashu,
+            -p cashu --no-default-features,
+            -p cashu --no-default-features --features wallet,
+            -p cashu --no-default-features --features mint,
+            -p cashu --no-default-features --features "mint swagger",
+            -p cdk-common,
+            -p cdk-common --no-default-features,
+            -p cdk-common --no-default-features --features wallet,
+            -p cdk-common --no-default-features --features mint,
+            -p cdk-common --no-default-features --features "mint swagger",
             -p cdk,
             -p cdk --no-default-features,
             -p cdk --no-default-features --features wallet,
@@ -154,10 +164,9 @@ jobs:
       matrix:
         build-args:
           [
-            -p cdk,
-            -p cdk --no-default-features,
-            -p cdk --no-default-features --features wallet,
-            -p cdk --no-default-features --features mint,
+            -p cashu --no-default-features --features "wallet mint",
+            -p cdk-common --no-default-features --features "wallet mint",
+            -p cdk --no-default-features --features "mint mint",
             -p cdk-axum,
             -p cdk-axum --no-default-features --features redis,
             -p cdk-strike,

+ 0 - 2
Cargo.lock

@@ -772,7 +772,6 @@ dependencies = [
  "futures",
  "getrandom",
  "lightning-invoice",
- "once_cell",
  "rand",
  "regex",
  "reqwest",
@@ -862,7 +861,6 @@ dependencies = [
  "futures",
  "instant",
  "lightning-invoice",
- "once_cell",
  "rand",
  "serde",
  "serde_json",

+ 1 - 0
crates/cashu/Cargo.toml

@@ -38,3 +38,4 @@ instant = { version = "0.1", features = ["wasm-bindgen", "inaccurate"] }
 [dev-dependencies]
 rand = "0.8.5"
 bip39 = "2.0"
+uuid = { version = "1", features = ["v4", "serde"] }

+ 8 - 3
crates/cashu/src/nuts/mod.rs

@@ -15,6 +15,7 @@ pub mod nut09;
 pub mod nut10;
 pub mod nut11;
 pub mod nut12;
+#[cfg(feature = "wallet")]
 pub mod nut13;
 pub mod nut14;
 pub mod nut15;
@@ -24,14 +25,18 @@ pub mod nut19;
 pub mod nut20;
 
 pub use nut00::{
-    BlindSignature, BlindedMessage, CurrencyUnit, PaymentMethod, PreMint, PreMintSecrets, Proof,
-    Proofs, ProofsMethods, Token, TokenV3, TokenV4, Witness,
+    BlindSignature, BlindedMessage, CurrencyUnit, PaymentMethod, Proof, Proofs, ProofsMethods,
+    Token, TokenV3, TokenV4, Witness,
 };
+#[cfg(feature = "wallet")]
+pub use nut00::{PreMint, PreMintSecrets};
 pub use nut01::{Keys, KeysResponse, PublicKey, SecretKey};
 #[cfg(feature = "mint")]
 pub use nut02::MintKeySet;
 pub use nut02::{Id, KeySet, KeySetInfo, KeysetResponse};
-pub use nut03::{PreSwap, SwapRequest, SwapResponse};
+#[cfg(feature = "wallet")]
+pub use nut03::PreSwap;
+pub use nut03::{SwapRequest, SwapResponse};
 pub use nut04::{
     MintBolt11Request, MintBolt11Response, MintMethodSettings, MintQuoteBolt11Request,
     MintQuoteBolt11Response, QuoteState as MintQuoteState, Settings as NUT04Settings,

+ 18 - 2
crates/cashu/src/nuts/nut00/mod.rs

@@ -11,11 +11,18 @@ use std::string::FromUtf8Error;
 use serde::{de, Deserialize, Deserializer, Serialize};
 use thiserror::Error;
 
+#[cfg(feature = "wallet")]
 use super::nut10;
+#[cfg(feature = "wallet")]
 use super::nut11::SpendingConditions;
+#[cfg(feature = "wallet")]
 use crate::amount::SplitTarget;
-use crate::dhke::{blind_message, hash_to_curve};
-use crate::nuts::nut01::{PublicKey, SecretKey};
+#[cfg(feature = "wallet")]
+use crate::dhke::blind_message;
+use crate::dhke::hash_to_curve;
+use crate::nuts::nut01::PublicKey;
+#[cfg(feature = "wallet")]
+use crate::nuts::nut01::SecretKey;
 use crate::nuts::nut11::{serde_p2pk_witness, P2PKWitness};
 use crate::nuts::nut12::BlindSignatureDleq;
 use crate::nuts::nut14::{serde_htlc_witness, HTLCWitness};
@@ -491,6 +498,7 @@ impl<'de> Deserialize<'de> for PaymentMethod {
 }
 
 /// PreMint
+#[cfg(feature = "wallet")]
 #[derive(Debug, Clone, PartialEq, Eq, Serialize)]
 pub struct PreMint {
     /// Blinded message
@@ -503,12 +511,14 @@ pub struct PreMint {
     pub amount: Amount,
 }
 
+#[cfg(feature = "wallet")]
 impl Ord for PreMint {
     fn cmp(&self, other: &Self) -> std::cmp::Ordering {
         self.amount.cmp(&other.amount)
     }
 }
 
+#[cfg(feature = "wallet")]
 impl PartialOrd for PreMint {
     fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
         Some(self.cmp(other))
@@ -516,6 +526,7 @@ impl PartialOrd for PreMint {
 }
 
 /// Premint Secrets
+#[cfg(feature = "wallet")]
 #[derive(Debug, Clone, PartialEq, Eq, Serialize)]
 pub struct PreMintSecrets {
     /// Secrets
@@ -524,6 +535,7 @@ pub struct PreMintSecrets {
     pub keyset_id: Id,
 }
 
+#[cfg(feature = "wallet")]
 impl PreMintSecrets {
     /// Create new [`PreMintSecrets`]
     pub fn new(keyset_id: Id) -> Self {
@@ -712,6 +724,7 @@ impl PreMintSecrets {
 }
 
 // Implement Iterator for PreMintSecrets
+#[cfg(feature = "wallet")]
 impl Iterator for PreMintSecrets {
     type Item = PreMint;
 
@@ -721,12 +734,14 @@ impl Iterator for PreMintSecrets {
     }
 }
 
+#[cfg(feature = "wallet")]
 impl Ord for PreMintSecrets {
     fn cmp(&self, other: &Self) -> Ordering {
         self.secrets.cmp(&other.secrets)
     }
 }
 
+#[cfg(feature = "wallet")]
 impl PartialOrd for PreMintSecrets {
     fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
         Some(self.cmp(other))
@@ -753,6 +768,7 @@ mod tests {
     }
 
     #[test]
+    #[cfg(feature = "wallet")]
     fn test_blank_blinded_messages() {
         let b = PreMintSecrets::blank(
             Id::from_str("009a1f293253e41e").unwrap(),

+ 13 - 1
crates/cashu/src/nuts/nut02.rs

@@ -5,21 +5,28 @@
 use core::fmt;
 use core::str::FromStr;
 use std::array::TryFromSliceError;
+#[cfg(feature = "mint")]
 use std::collections::BTreeMap;
 
+#[cfg(feature = "mint")]
 use bitcoin::bip32::{ChildNumber, DerivationPath, Xpriv};
 use bitcoin::hashes::sha256::Hash as Sha256;
 use bitcoin::hashes::Hash;
+#[cfg(feature = "mint")]
 use bitcoin::key::Secp256k1;
+#[cfg(feature = "mint")]
 use bitcoin::secp256k1;
 use serde::{Deserialize, Serialize};
 use serde_with::{serde_as, VecSkipError};
 use thiserror::Error;
 
-use super::nut01::{Keys, MintKeyPair, MintKeys};
+use super::nut01::Keys;
+#[cfg(feature = "mint")]
+use super::nut01::{MintKeyPair, MintKeys};
 use crate::amount::AmountStr;
 use crate::nuts::nut00::CurrencyUnit;
 use crate::util::hex;
+#[cfg(feature = "mint")]
 use crate::Amount;
 
 /// NUT02 Error
@@ -228,6 +235,7 @@ impl KeySet {
     }
 }
 
+#[cfg(feature = "mint")]
 impl From<MintKeySet> for KeySet {
     fn from(keyset: MintKeySet) -> Self {
         Self {
@@ -258,6 +266,7 @@ fn default_input_fee_ppk() -> u64 {
     0
 }
 
+#[cfg(feature = "mint")]
 /// MintKeyset
 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
 pub struct MintKeySet {
@@ -269,6 +278,7 @@ pub struct MintKeySet {
     pub keys: MintKeys,
 }
 
+#[cfg(feature = "mint")]
 impl MintKeySet {
     /// Generate new [`MintKeySet`]
     pub fn generate<C: secp256k1::Signing>(
@@ -343,6 +353,7 @@ impl MintKeySet {
     }
 }
 
+#[cfg(feature = "mint")]
 impl From<MintKeySet> for Id {
     fn from(keyset: MintKeySet) -> Id {
         let keys: super::KeySet = keyset.into();
@@ -351,6 +362,7 @@ impl From<MintKeySet> for Id {
     }
 }
 
+#[cfg(feature = "mint")]
 impl From<&MintKeys> for Id {
     fn from(map: &MintKeys) -> Self {
         let keys: super::Keys = map.clone().into();

+ 4 - 1
crates/cashu/src/nuts/nut03.rs

@@ -5,7 +5,9 @@
 use serde::{Deserialize, Serialize};
 use thiserror::Error;
 
-use super::nut00::{BlindSignature, BlindedMessage, PreMintSecrets, Proofs};
+#[cfg(feature = "wallet")]
+use super::nut00::PreMintSecrets;
+use super::nut00::{BlindSignature, BlindedMessage, Proofs};
 use crate::Amount;
 
 /// NUT03 Error
@@ -20,6 +22,7 @@ pub enum Error {
 }
 
 /// Preswap information
+#[cfg(feature = "wallet")]
 #[derive(Debug, Clone, PartialEq, Eq, Serialize)]
 pub struct PreSwap {
     /// Preswap mint secrets

+ 0 - 1
crates/cdk-common/Cargo.toml

@@ -23,7 +23,6 @@ bitcoin = { version = "0.32.2", features = [
 cashu = { path = "../cashu", default-features = false, version = "0.6.0" }
 cbor-diag = "0.1.12"
 ciborium = { version = "0.2.2", default-features = false, features = ["std"] }
-once_cell = "1.20.2"
 serde = { version = "1", features = ["derive"] }
 lightning-invoice = { version = "0.32.0", features = ["serde", "std"] }
 thiserror = "2"

+ 1 - 0
crates/cdk-common/src/error.rs

@@ -237,6 +237,7 @@ pub enum Error {
     NUT12(#[from] crate::nuts::nut12::Error),
     /// NUT13 Error
     #[error(transparent)]
+    #[cfg(feature = "wallet")]
     NUT13(#[from] crate::nuts::nut13::Error),
     /// NUT14 Error
     #[error(transparent)]

+ 5 - 0
crates/cdk-common/src/ws.rs

@@ -2,9 +2,12 @@
 //!
 //! This module extends the `cashu` crate with types and functions for the CDK, using the correct
 //! expected ID types.
+#[cfg(feature = "mint")]
 use cashu::nut17::ws::JSON_RPC_VERSION;
 use cashu::nut17::{self};
+#[cfg(feature = "mint")]
 use cashu::NotificationPayload;
+#[cfg(feature = "mint")]
 use uuid::Uuid;
 
 use crate::pub_sub::SubId;
@@ -21,6 +24,7 @@ pub type WsErrorBody = nut17::ws::WsErrorBody;
 pub type WsMessageOrResponse = nut17::ws::WsMessageOrResponse<SubId>;
 pub type NotificationInner<T> = nut17::ws::NotificationInner<T, SubId>;
 
+#[cfg(feature = "mint")]
 pub fn notification_uuid_to_notification_string(
     notification: NotificationInner<Uuid>,
 ) -> NotificationInner<String> {
@@ -38,6 +42,7 @@ pub fn notification_uuid_to_notification_string(
     }
 }
 
+#[cfg(feature = "mint")]
 pub fn notification_to_ws_message(notification: NotificationInner<Uuid>) -> WsMessageOrResponse {
     nut17::ws::WsMessageOrResponse::Notification(nut17::ws::WsNotification {
         jsonrpc: JSON_RPC_VERSION.to_owned(),

+ 0 - 1
crates/cdk/Cargo.toml

@@ -34,7 +34,6 @@ bitcoin = { version = "0.32.2", features = [
 ] }
 ciborium = { version = "0.2.2", default-features = false, features = ["std"] }
 lightning-invoice = { version = "0.32.0", features = ["serde", "std"] }
-once_cell = "1.19"
 regex = "1"
 reqwest = { version = "0.12", default-features = false, features = [
     "json",