Kaynağa Gözat

cdk: adj. code according to `CODE_STYLE` and remove `serde_utils` mod

* Remove `wallet` and `mint` features from `nuts` module
* Sort dependencies in ASC order
* Fix `check-docks.sh` script

Closes https://github.com/cashubtc/cdk/issues/88
Closes https://github.com/cashubtc/cdk/issues/87

Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
Yuki Kishimoto 11 ay önce
ebeveyn
işleme
61c80606f6

+ 9 - 9
crates/cdk/Cargo.toml

@@ -19,29 +19,29 @@ redb = ["dep:redb"]
 
 
 [dependencies]
+async-trait = "0.1"
 base64 = "0.21" # bitcoin uses v0.21 (optional dep)
 bip39 = { version = "2.0", optional = true }
 bitcoin = { version = "0.30", features = ["serde", "rand", "rand-std"] } # lightning-invoice uses v0.30
+http = "1.0"
 lightning-invoice = { version = "0.29", features = ["serde"] }
 once_cell = "1.19"
-serde = { version = "1.0.160", default-features = false, features = ["derive"]}
-serde_json = "1.0.96"
+reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls", "socks"], optional = true }
+serde = { version = "1.0", default-features = false, features = ["derive"]}
+serde_json = "1.0"
 serde_with = "3.4"
-url = "2.3.1"
 tracing = { version = "0.1", default-features = false }
-thiserror = "1.0.50"
-async-trait = "0.1.74"
-http = "1.0.0"
+thiserror = "1.0"
+url = "2.3"
 uuid = { version = "1.6", features = ["v4"] }
-reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls", "socks"], optional = true }
 
 [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
 tokio = { workspace = true, features = ["rt-multi-thread", "time", "macros", "sync"] }
-redb = { version = "2.0.0", optional = true }
+redb = { version = "2.0", optional = true }
 
 [target.'cfg(target_arch = "wasm32")'.dependencies]
 tokio = { workspace = true, features = ["rt", "macros", "sync", "time"] }
-getrandom = { version = "0.2.14", features = ["js"] }
+getrandom = { version = "0.2", features = ["js"] }
 instant = { version = "0.1", features = [ "wasm-bindgen", "inaccurate" ] }
 
 

+ 0 - 1
crates/cdk/src/amount.rs

@@ -1,6 +1,5 @@
 use std::fmt;
 
-// https://github.com/clarkmoody/cashu-rs
 use serde::{Deserialize, Serialize};
 
 /// Number of satoshis

+ 0 - 0
crates/cdk/src/error/mod.rs → crates/cdk/src/error.rs


+ 0 - 1
crates/cdk/src/lib.rs

@@ -15,7 +15,6 @@ pub mod error;
 pub mod mint;
 pub mod nuts;
 pub mod secret;
-pub mod serde_utils;
 pub mod types;
 pub mod url;
 pub mod util;

+ 6 - 6
crates/cdk/src/mint/localstore/memory.rs

@@ -6,7 +6,7 @@ use tokio::sync::Mutex;
 
 use super::{Error, LocalStore};
 use crate::dhke::hash_to_curve;
-use crate::nuts::nut02::mint::KeySet;
+use crate::nuts::nut02::MintKeySet;
 use crate::nuts::{BlindSignature, CurrencyUnit, Id, MintInfo, Proof, Proofs, PublicKey};
 use crate::secret::Secret;
 use crate::types::{MeltQuote, MintQuote};
@@ -15,7 +15,7 @@ use crate::types::{MeltQuote, MintQuote};
 pub struct MemoryLocalStore {
     mint_info: Arc<Mutex<MintInfo>>,
     active_keysets: Arc<Mutex<HashMap<CurrencyUnit, Id>>>,
-    keysets: Arc<Mutex<HashMap<Id, KeySet>>>,
+    keysets: Arc<Mutex<HashMap<Id, MintKeySet>>>,
     mint_quotes: Arc<Mutex<HashMap<String, MintQuote>>>,
     melt_quotes: Arc<Mutex<HashMap<String, MeltQuote>>>,
     pending_proofs: Arc<Mutex<HashMap<[u8; 33], Proof>>>,
@@ -28,7 +28,7 @@ impl MemoryLocalStore {
     pub fn new(
         mint_info: MintInfo,
         active_keysets: HashMap<CurrencyUnit, Id>,
-        keysets: Vec<KeySet>,
+        keysets: Vec<MintKeySet>,
         mint_quotes: Vec<MintQuote>,
         melt_quotes: Vec<MeltQuote>,
         pending_proofs: Proofs,
@@ -85,16 +85,16 @@ impl LocalStore for MemoryLocalStore {
         Ok(self.active_keysets.lock().await.clone())
     }
 
-    async fn add_keyset(&self, keyset: KeySet) -> Result<(), Error> {
+    async fn add_keyset(&self, keyset: MintKeySet) -> Result<(), Error> {
         self.keysets.lock().await.insert(keyset.id, keyset);
         Ok(())
     }
 
-    async fn get_keyset(&self, keyset_id: &Id) -> Result<Option<KeySet>, Error> {
+    async fn get_keyset(&self, keyset_id: &Id) -> Result<Option<MintKeySet>, Error> {
         Ok(self.keysets.lock().await.get(keyset_id).cloned())
     }
 
-    async fn get_keysets(&self) -> Result<Vec<KeySet>, Error> {
+    async fn get_keysets(&self) -> Result<Vec<MintKeySet>, Error> {
         Ok(self.keysets.lock().await.values().cloned().collect())
     }
 

+ 11 - 11
crates/cdk/src/mint/localstore/mod.rs

@@ -1,17 +1,17 @@
-pub mod memory;
-#[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
-pub mod redb_store;
-
 use std::collections::HashMap;
 use std::num::ParseIntError;
 
 use async_trait::async_trait;
-pub use memory::MemoryLocalStore;
-#[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
-pub use redb_store::RedbLocalStore;
 use thiserror::Error;
 
-use crate::nuts::nut02::mint::KeySet;
+pub mod memory;
+#[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
+pub mod redb_store;
+
+pub use self::memory::MemoryLocalStore;
+#[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
+pub use self::redb_store::RedbLocalStore;
+use crate::nuts::nut02::MintKeySet;
 use crate::nuts::{BlindSignature, CurrencyUnit, Id, MintInfo, Proof, PublicKey};
 use crate::secret::Secret;
 use crate::types::{MeltQuote, MintQuote};
@@ -72,9 +72,9 @@ pub trait LocalStore {
     async fn get_melt_quotes(&self) -> Result<Vec<MeltQuote>, Error>;
     async fn remove_melt_quote(&self, quote_id: &str) -> Result<(), Error>;
 
-    async fn add_keyset(&self, keyset: KeySet) -> Result<(), Error>;
-    async fn get_keyset(&self, id: &Id) -> Result<Option<KeySet>, Error>;
-    async fn get_keysets(&self) -> Result<Vec<KeySet>, Error>;
+    async fn add_keyset(&self, keyset: MintKeySet) -> Result<(), Error>;
+    async fn get_keyset(&self, id: &Id) -> Result<Option<MintKeySet>, Error>;
+    async fn get_keysets(&self) -> Result<Vec<MintKeySet>, Error>;
 
     async fn add_spent_proof(&self, proof: Proof) -> Result<(), Error>;
     async fn get_spent_proof_by_secret(&self, secret: &Secret) -> Result<Option<Proof>, Error>;

+ 1 - 1
crates/cdk/src/mint/localstore/redb_store.rs

@@ -137,7 +137,7 @@ impl LocalStore for RedbLocalStore {
         let mut active_keysets = HashMap::new();
 
         for (unit, id) in (table.iter()?).flatten() {
-            let unit = CurrencyUnit::from_str(unit.value())?;
+            let unit = CurrencyUnit::from(unit.value());
             let id = Id::from_str(id.value())?;
 
             active_keysets.insert(unit, id);

+ 37 - 28
crates/cdk/src/mint/mod.rs

@@ -7,17 +7,17 @@ use serde::{Deserialize, Serialize};
 use thiserror::Error;
 use tracing::{debug, error, info};
 
+pub mod localstore;
+
+#[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
+pub use self::localstore::RedbLocalStore;
+pub use self::localstore::{LocalStore, MemoryLocalStore};
 use crate::dhke::{hash_to_curve, sign_message, verify_message};
 use crate::error::ErrorResponse;
 use crate::nuts::*;
 use crate::types::{MeltQuote, MintQuote};
 use crate::Amount;
 
-pub mod localstore;
-#[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
-pub use localstore::RedbLocalStore;
-pub use localstore::{LocalStore, MemoryLocalStore};
-
 #[derive(Debug, Error)]
 pub enum Error {
     /// Unknown Keyset
@@ -97,12 +97,8 @@ impl Mint {
         let mut active_units: HashSet<CurrencyUnit> = HashSet::default();
 
         if keysets_info.is_empty() {
-            let keyset = nut02::mint::KeySet::generate(
-                &mnemonic.to_seed_normalized(""),
-                CurrencyUnit::Sat,
-                "",
-                64,
-            );
+            let keyset =
+                MintKeySet::generate(&mnemonic.to_seed_normalized(""), CurrencyUnit::Sat, "", 64);
 
             localstore
                 .add_active_keyset(CurrencyUnit::Sat, keyset.id)
@@ -116,7 +112,7 @@ impl Mint {
                     todo!()
                 }
 
-                let keyset = nut02::mint::KeySet::generate(
+                let keyset = MintKeySet::generate(
                     &mnemonic.to_seed_normalized(""),
                     keyset_info.unit.clone(),
                     &keyset_info.derivation_path.clone(),
@@ -284,11 +280,14 @@ impl Mint {
         for blinded_message in &mint_request.outputs {
             if self
                 .localstore
-                .get_blinded_signature(&blinded_message.b)
+                .get_blinded_signature(&blinded_message.blinded_secret)
                 .await?
                 .is_some()
             {
-                error!("Output has already been signed: {}", blinded_message.b);
+                error!(
+                    "Output has already been signed: {}",
+                    blinded_message.blinded_secret
+                );
                 return Err(Error::BlindedMessageAlreadySigned);
             }
         }
@@ -305,10 +304,10 @@ impl Mint {
 
         let mut blind_signatures = Vec::with_capacity(mint_request.outputs.len());
 
-        for blinded_message in mint_request.outputs {
+        for blinded_message in mint_request.outputs.into_iter() {
             let blinded_signature = self.blind_sign(&blinded_message).await?;
             self.localstore
-                .add_blinded_signature(blinded_message.b, blinded_signature.clone())
+                .add_blinded_signature(blinded_message.blinded_secret, blinded_signature.clone())
                 .await?;
             blind_signatures.push(blinded_signature);
         }
@@ -321,7 +320,7 @@ impl Mint {
     async fn blind_sign(&self, blinded_message: &BlindedMessage) -> Result<BlindSignature, Error> {
         let BlindedMessage {
             amount,
-            b,
+            blinded_secret,
             keyset_id,
             ..
         } = blinded_message;
@@ -343,18 +342,18 @@ impl Mint {
             return Err(Error::InactiveKeyset);
         }
 
-        let Some(key_pair) = keyset.keys.0.get(amount) else {
+        let Some(key_pair) = keyset.keys.get(amount) else {
             // No key for amount
             return Err(Error::AmountKey);
         };
 
-        let c = sign_message(&key_pair.secret_key, b)?;
+        let c = sign_message(&key_pair.secret_key, blinded_secret)?;
 
         let blinded_signature = BlindSignature::new(
             *amount,
             c,
             keyset.id,
-            &blinded_message.b,
+            &blinded_message.blinded_secret,
             key_pair.secret_key.clone(),
         )?;
 
@@ -368,11 +367,14 @@ impl Mint {
         for blinded_message in &swap_request.outputs {
             if self
                 .localstore
-                .get_blinded_signature(&blinded_message.b)
+                .get_blinded_signature(&blinded_message.blinded_secret)
                 .await?
                 .is_some()
             {
-                error!("Output has already been signed: {}", blinded_message.b);
+                error!(
+                    "Output has already been signed: {}",
+                    blinded_message.blinded_secret
+                );
                 return Err(Error::BlindedMessageAlreadySigned);
             }
         }
@@ -447,7 +449,7 @@ impl Mint {
         for blinded_message in swap_request.outputs {
             let blinded_signature = self.blind_sign(&blinded_message).await?;
             self.localstore
-                .add_blinded_signature(blinded_message.b, blinded_signature.clone())
+                .add_blinded_signature(blinded_message.blinded_secret, blinded_signature.clone())
                 .await?;
             promises.push(blinded_signature);
         }
@@ -484,7 +486,7 @@ impl Mint {
             .await?
             .ok_or(Error::UnknownKeySet)?;
 
-        let Some(keypair) = keyset.keys.0.get(&proof.amount) else {
+        let Some(keypair) = keyset.keys.get(&proof.amount) else {
             return Err(Error::AmountKey);
         };
 
@@ -613,11 +615,14 @@ impl Mint {
             for blinded_message in outputs {
                 if self
                     .localstore
-                    .get_blinded_signature(&blinded_message.b)
+                    .get_blinded_signature(&blinded_message.blinded_secret)
                     .await?
                     .is_some()
                 {
-                    error!("Output has already been signed: {}", blinded_message.b);
+                    error!(
+                        "Output has already been signed: {}",
+                        blinded_message.blinded_secret
+                    );
                     return Err(Error::BlindedMessageAlreadySigned);
                 }
             }
@@ -653,7 +658,10 @@ impl Mint {
 
                 let blinded_signature = self.blind_sign(&blinded_message).await?;
                 self.localstore
-                    .add_blinded_signature(blinded_message.b, blinded_signature.clone())
+                    .add_blinded_signature(
+                        blinded_message.blinded_secret,
+                        blinded_signature.clone(),
+                    )
                     .await?;
                 change_sigs.push(blinded_signature)
             }
@@ -699,7 +707,8 @@ impl Mint {
         let mut outputs = Vec::with_capacity(output_len);
         let mut signatures = Vec::with_capacity(output_len);
 
-        let blinded_message: Vec<PublicKey> = request.outputs.iter().map(|b| b.b).collect();
+        let blinded_message: Vec<PublicKey> =
+            request.outputs.iter().map(|b| b.blinded_secret).collect();
 
         let blinded_signatures = self
             .localstore

+ 5 - 7
crates/cdk/src/nuts/mod.rs

@@ -14,12 +14,12 @@ pub mod nut12;
 #[cfg(feature = "nut13")]
 pub mod nut13;
 
-#[cfg(feature = "wallet")]
-pub use nut00::wallet::{PreMint, PreMintSecrets, Token};
-pub use nut00::{BlindSignature, BlindedMessage, CurrencyUnit, PaymentMethod, Proof};
+pub use nut00::{
+    BlindSignature, BlindedMessage, CurrencyUnit, PaymentMethod, PreMint, PreMintSecrets, Proof,
+    Proofs, Token,
+};
 pub use nut01::{Keys, KeysResponse, PublicKey, SecretKey};
-pub use nut02::mint::KeySet as MintKeySet;
-pub use nut02::{Id, KeySet, KeySetInfo, KeysetResponse};
+pub use nut02::{Id, KeySet, KeySetInfo, KeysetResponse, MintKeySet};
 #[cfg(feature = "wallet")]
 pub use nut03::PreSwap;
 pub use nut03::{SwapRequest, SwapResponse};
@@ -35,5 +35,3 @@ pub use nut09::{RestoreRequest, RestoreResponse};
 pub use nut10::{Kind, Secret as Nut10Secret, SecretData};
 pub use nut11::{P2PKConditions, SigFlag, Signatures, SigningKey, VerifyingKey};
 pub use nut12::{BlindSignatureDleq, ProofDleq};
-
-pub type Proofs = Vec<Proof>;

+ 374 - 323
crates/cdk/src/nuts/nut00.rs

@@ -1,20 +1,31 @@
-//! Notation and Models
-// https://github.com/cashubtc/nuts/blob/main/00.md
+//! NUT-00: Notation and Models
+//!
+//! <https://github.com/cashubtc/nuts/blob/main/00.md>
 
+use std::cmp::Ordering;
 use std::fmt;
-use std::hash::{self, Hasher};
+use std::hash::{Hash, Hasher};
 use std::str::FromStr;
 use std::string::FromUtf8Error;
 
-use serde::{Deserialize, Serialize};
+use base64::engine::{general_purpose, GeneralPurpose};
+use base64::{alphabet, Engine as _};
+use serde::{Deserialize, Deserializer, Serialize};
 use thiserror::Error;
+use url::Url;
 
-use super::{BlindSignatureDleq, Id, ProofDleq, Proofs, PublicKey, Signatures};
-use crate::nuts::nut11::{witness_deserialize, witness_serialize};
+use crate::dhke::blind_message;
+use crate::nuts::nut01::{PublicKey, SecretKey};
+use crate::nuts::nut11::{witness_deserialize, witness_serialize, Signatures};
+use crate::nuts::nut12::BlindSignatureDleq;
+use crate::nuts::{Id, P2PKConditions, ProofDleq};
 use crate::secret::Secret;
 use crate::url::UncheckedUrl;
 use crate::Amount;
 
+/// List of [Proof]
+pub type Proofs = Vec<Proof>;
+
 #[derive(Debug, Error)]
 pub enum Error {
     /// Proofs required
@@ -46,18 +57,26 @@ pub enum Error {
     NUT11(#[from] crate::nuts::nut11::Error),
 }
 
-/// Blinded Message [NUT-00]
-#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+/// Blinded Message (also called `output`)
+#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
 pub struct BlindedMessage {
     /// Amount
+    ///
+    /// The value for the requested [BlindSignature]
     pub amount: Amount,
-    /// Keyset Id
+    /// Keyset ID
+    ///
+    /// ID from which we expect a signature.
     #[serde(rename = "id")]
     pub keyset_id: Id,
     /// Blinded secret message (B_)
+    ///
+    /// The blinded secret message generated by the sender.
     #[serde(rename = "B_")]
-    pub b: PublicKey,
+    pub blinded_secret: PublicKey,
     /// Witness
+    ///
+    /// <https://github.com/cashubtc/nuts/blob/main/11.md>
     #[serde(default)]
     #[serde(skip_serializing_if = "Option::is_none")]
     //#[serde(serialize_with = "witness_serialize")]
@@ -66,18 +85,104 @@ pub struct BlindedMessage {
 }
 
 impl BlindedMessage {
-    pub fn new(amount: Amount, keyset_id: Id, b: PublicKey) -> Self {
+    /// Compose new blinded message
+    #[inline]
+    pub fn new(amount: Amount, keyset_id: Id, blinded_secret: PublicKey) -> Self {
         Self {
             amount,
             keyset_id,
-            b,
+            blinded_secret,
             witness: None,
         }
     }
+
+    /// Add witness
+    pub fn witness(mut self, witness: Signatures) -> Self {
+        self.witness = Some(witness);
+        self
+    }
+}
+
+/// Blind Signature (also called `promise`)
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct BlindSignature {
+    /// Amount
+    ///
+    /// The value of the blinded token.
+    pub amount: Amount,
+    /// Keyset ID
+    ///
+    /// ID of the mint keys that signed the token.
+    #[serde(rename = "id")]
+    pub keyset_id: Id,
+    /// Blinded signature (C_)
+    ///
+    /// The blinded signature on the secret message `B_` of [BlindedMessage].
+    #[serde(rename = "C_")]
+    pub c: PublicKey,
+    /// DLEQ Proof
+    ///
+    /// <https://github.com/cashubtc/nuts/blob/main/12.md>
+    #[serde(default)]
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub dleq: Option<BlindSignatureDleq>,
+}
+
+/// Proofs
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct Proof {
+    /// Amount
+    pub amount: Amount,
+    /// `Keyset id`
+    #[serde(rename = "id")]
+    pub keyset_id: Id,
+    /// Secret message
+    pub secret: Secret,
+    /// Unblinded signature
+    #[serde(rename = "C")]
+    pub c: PublicKey,
+    /// Witness
+    #[serde(default)]
+    #[serde(skip_serializing_if = "Option::is_none")]
+    #[serde(serialize_with = "witness_serialize")]
+    #[serde(deserialize_with = "witness_deserialize")]
+    pub witness: Option<Signatures>,
+    /// DLEQ Proof
+    pub dleq: Option<ProofDleq>,
+}
+
+impl Proof {
+    pub fn new(amount: Amount, keyset_id: Id, secret: Secret, c: PublicKey) -> Self {
+        Proof {
+            amount,
+            keyset_id,
+            secret,
+            c,
+            witness: None,
+            dleq: None,
+        }
+    }
+}
+
+impl Hash for Proof {
+    fn hash<H: Hasher>(&self, state: &mut H) {
+        self.secret.hash(state);
+    }
+}
+
+impl Ord for Proof {
+    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
+        self.amount.cmp(&other.amount)
+    }
+}
+
+impl PartialOrd for Proof {
+    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
+        Some(self.cmp(other))
+    }
 }
 
-#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, hash::Hash)]
-#[serde(rename_all = "lowercase")]
+#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
 pub enum CurrencyUnit {
     #[default]
     Sat,
@@ -85,14 +190,15 @@ pub enum CurrencyUnit {
     Custom(String),
 }
 
-impl FromStr for CurrencyUnit {
-    type Err = Error;
-
-    fn from_str(s: &str) -> Result<Self, Self::Err> {
-        match s {
-            "sat" => Ok(Self::Sat),
-            "usd" => Ok(Self::Usd),
-            _ => Ok(Self::Custom(s.to_string())),
+impl<S> From<S> for CurrencyUnit
+where
+    S: AsRef<str>,
+{
+    fn from(currency: S) -> Self {
+        match currency.as_ref() {
+            "sat" => Self::Sat,
+            "usd" => Self::Usd,
+            o => Self::Custom(o.to_string()),
         }
     }
 }
@@ -102,26 +208,45 @@ impl fmt::Display for CurrencyUnit {
         match self {
             CurrencyUnit::Sat => write!(f, "sat"),
             CurrencyUnit::Usd => write!(f, "usd"),
-            CurrencyUnit::Custom(unit) => write!(f, "{}", unit),
+            CurrencyUnit::Custom(unit) => write!(f, "{unit}"),
         }
     }
 }
 
-#[derive(Default, Deserialize, Serialize, Debug, PartialEq, Eq, Clone, Hash)]
-#[serde(rename_all = "lowercase")]
+impl Serialize for CurrencyUnit {
+    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+    where
+        S: serde::Serializer,
+    {
+        serializer.serialize_str(&self.to_string())
+    }
+}
+
+impl<'de> Deserialize<'de> for CurrencyUnit {
+    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+    where
+        D: Deserializer<'de>,
+    {
+        let currency: String = String::deserialize(deserializer)?;
+        Ok(Self::from(currency))
+    }
+}
+
+#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
 pub enum PaymentMethod {
     #[default]
     Bolt11,
     Custom(String),
 }
 
-impl FromStr for PaymentMethod {
-    type Err = Error;
-
-    fn from_str(s: &str) -> Result<Self, Self::Err> {
-        match s {
-            "bolt11" => Ok(Self::Bolt11),
-            _ => Ok(Self::Custom(s.to_string())),
+impl<S> From<S> for PaymentMethod
+where
+    S: AsRef<str>,
+{
+    fn from(method: S) -> Self {
+        match method.as_ref() {
+            "bolt11" => Self::Bolt11,
+            o => Self::Custom(o.to_string()),
         }
     }
 }
@@ -135,285 +260,285 @@ impl fmt::Display for PaymentMethod {
     }
 }
 
-#[cfg(feature = "wallet")]
-pub mod wallet {
-    use std::cmp::Ordering;
-    use std::fmt;
-    use std::str::FromStr;
+impl Serialize for PaymentMethod {
+    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+    where
+        S: serde::Serializer,
+    {
+        serializer.serialize_str(&self.to_string())
+    }
+}
 
-    use base64::engine::{general_purpose, GeneralPurpose};
-    use base64::{alphabet, Engine as _};
-    use serde::{Deserialize, Serialize};
-    use url::Url;
-
-    use super::{CurrencyUnit, MintProofs, *};
-    use crate::dhke::blind_message;
-    use crate::nuts::{BlindedMessage, Id, P2PKConditions, Proofs, SecretKey};
-    use crate::secret::Secret;
-    use crate::url::UncheckedUrl;
-    use crate::Amount;
-
-    #[derive(Debug, Clone, PartialEq, Eq, Serialize)]
-    pub struct PreMint {
-        /// Blinded message
-        pub blinded_message: BlindedMessage,
-        /// Secret
-        pub secret: Secret,
-        /// R
-        pub r: SecretKey,
-        /// Amount
-        pub amount: Amount,
-    }
-
-    impl Ord for PreMint {
-        fn cmp(&self, other: &Self) -> std::cmp::Ordering {
-            self.amount.cmp(&other.amount)
-        }
+impl<'de> Deserialize<'de> for PaymentMethod {
+    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+    where
+        D: Deserializer<'de>,
+    {
+        let payment_method: String = String::deserialize(deserializer)?;
+        Ok(Self::from(payment_method))
     }
+}
 
-    impl PartialOrd for PreMint {
-        fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
-            Some(self.cmp(other))
-        }
+#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
+pub struct PreMint {
+    /// Blinded message
+    pub blinded_message: BlindedMessage,
+    /// Secret
+    pub secret: Secret,
+    /// R
+    pub r: SecretKey,
+    /// Amount
+    pub amount: Amount,
+}
+
+impl Ord for PreMint {
+    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
+        self.amount.cmp(&other.amount)
     }
+}
 
-    #[derive(Debug, Default, Clone, PartialEq, Eq, Serialize)]
-    pub struct PreMintSecrets {
-        pub secrets: Vec<PreMint>,
+impl PartialOrd for PreMint {
+    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
+        Some(self.cmp(other))
     }
+}
 
-    impl PreMintSecrets {
-        /// Outputs for speceifed amount with random secret
-        pub fn random(keyset_id: Id, amount: Amount) -> Result<Self, Error> {
-            let amount_split = amount.split();
+#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize)]
+pub struct PreMintSecrets {
+    pub secrets: Vec<PreMint>,
+}
 
-            let mut output = Vec::with_capacity(amount_split.len());
+impl PreMintSecrets {
+    /// Outputs for speceifed amount with random secret
+    pub fn random(keyset_id: Id, amount: Amount) -> Result<Self, Error> {
+        let amount_split = amount.split();
 
-            for amount in amount_split {
-                let secret = Secret::generate();
-                let (blinded, r) = blind_message(&secret.to_bytes(), None)?;
+        let mut output = Vec::with_capacity(amount_split.len());
 
-                let blinded_message = BlindedMessage::new(amount, keyset_id, blinded);
+        for amount in amount_split {
+            let secret = Secret::generate();
+            let (blinded, r) = blind_message(&secret.to_bytes(), None)?;
 
-                output.push(PreMint {
-                    secret,
-                    blinded_message,
-                    r,
-                    amount,
-                });
-            }
+            let blinded_message = BlindedMessage::new(amount, keyset_id, blinded);
 
-            Ok(PreMintSecrets { secrets: output })
+            output.push(PreMint {
+                secret,
+                blinded_message,
+                r,
+                amount,
+            });
         }
 
-        pub fn from_secrets(
-            keyset_id: Id,
-            amounts: Vec<Amount>,
-            secrets: Vec<Secret>,
-        ) -> Result<Self, wallet::Error> {
-            let mut output = Vec::with_capacity(secrets.len());
+        Ok(PreMintSecrets { secrets: output })
+    }
 
-            for (secret, amount) in secrets.into_iter().zip(amounts) {
-                let (blinded, r) = blind_message(&secret.to_bytes(), None)?;
+    pub fn from_secrets(
+        keyset_id: Id,
+        amounts: Vec<Amount>,
+        secrets: Vec<Secret>,
+    ) -> Result<Self, Error> {
+        let mut output = Vec::with_capacity(secrets.len());
 
-                let blinded_message = BlindedMessage::new(amount, keyset_id, blinded);
+        for (secret, amount) in secrets.into_iter().zip(amounts) {
+            let (blinded, r) = blind_message(&secret.to_bytes(), None)?;
 
-                output.push(PreMint {
-                    secret,
-                    blinded_message,
-                    r,
-                    amount,
-                });
-            }
+            let blinded_message = BlindedMessage::new(amount, keyset_id, blinded);
 
-            Ok(PreMintSecrets { secrets: output })
+            output.push(PreMint {
+                secret,
+                blinded_message,
+                r,
+                amount,
+            });
         }
 
-        /// Blank Outputs used for NUT-08 change
-        pub fn blank(keyset_id: Id, fee_reserve: Amount) -> Result<Self, wallet::Error> {
-            let count = ((u64::from(fee_reserve) as f64).log2().ceil() as u64).max(1);
+        Ok(PreMintSecrets { secrets: output })
+    }
 
-            let mut output = Vec::with_capacity(count as usize);
+    /// Blank Outputs used for NUT-08 change
+    pub fn blank(keyset_id: Id, fee_reserve: Amount) -> Result<Self, Error> {
+        let count = ((u64::from(fee_reserve) as f64).log2().ceil() as u64).max(1);
 
-            for _i in 0..count {
-                let secret = Secret::generate();
-                let (blinded, r) = blind_message(&secret.to_bytes(), None)?;
+        let mut output = Vec::with_capacity(count as usize);
 
-                let blinded_message = BlindedMessage::new(Amount::ZERO, keyset_id, blinded);
+        for _i in 0..count {
+            let secret = Secret::generate();
+            let (blinded, r) = blind_message(&secret.to_bytes(), None)?;
 
-                output.push(PreMint {
-                    secret,
-                    blinded_message,
-                    r,
-                    amount: Amount::ZERO,
-                })
-            }
+            let blinded_message = BlindedMessage::new(Amount::ZERO, keyset_id, blinded);
 
-            Ok(PreMintSecrets { secrets: output })
+            output.push(PreMint {
+                secret,
+                blinded_message,
+                r,
+                amount: Amount::ZERO,
+            })
         }
 
-        pub fn with_p2pk_conditions(
-            keyset_id: Id,
-            amount: Amount,
-            conditions: P2PKConditions,
-        ) -> Result<Self, wallet::Error> {
-            let amount_split = amount.split();
-
-            let mut output = Vec::with_capacity(amount_split.len());
+        Ok(PreMintSecrets { secrets: output })
+    }
 
-            for amount in amount_split {
-                let secret: Secret = conditions.clone().try_into()?;
-                let (blinded, r) = blind_message(&secret.to_bytes(), None)?;
+    pub fn with_p2pk_conditions(
+        keyset_id: Id,
+        amount: Amount,
+        conditions: P2PKConditions,
+    ) -> Result<Self, Error> {
+        let amount_split = amount.split();
 
-                let blinded_message = BlindedMessage::new(amount, keyset_id, blinded);
+        let mut output = Vec::with_capacity(amount_split.len());
 
-                output.push(PreMint {
-                    secret,
-                    blinded_message,
-                    r,
-                    amount,
-                });
-            }
+        for amount in amount_split {
+            let secret: Secret = conditions.clone().try_into()?;
+            let (blinded, r) = blind_message(&secret.to_bytes(), None)?;
 
-            Ok(PreMintSecrets { secrets: output })
-        }
+            let blinded_message = BlindedMessage::new(amount, keyset_id, blinded);
 
-        pub fn iter(&self) -> impl Iterator<Item = &PreMint> {
-            self.secrets.iter()
+            output.push(PreMint {
+                secret,
+                blinded_message,
+                r,
+                amount,
+            });
         }
 
-        pub fn len(&self) -> usize {
-            self.secrets.len()
-        }
+        Ok(PreMintSecrets { secrets: output })
+    }
 
-        pub fn is_empty(&self) -> bool {
-            self.secrets.is_empty()
-        }
+    pub fn iter(&self) -> impl Iterator<Item = &PreMint> {
+        self.secrets.iter()
+    }
 
-        pub fn total_amount(&self) -> Amount {
-            self.secrets
-                .iter()
-                .map(|PreMint { amount, .. }| *amount)
-                .sum()
-        }
+    pub fn len(&self) -> usize {
+        self.secrets.len()
+    }
 
-        pub fn blinded_messages(&self) -> Vec<BlindedMessage> {
-            self.iter().map(|pm| pm.blinded_message.clone()).collect()
-        }
+    pub fn is_empty(&self) -> bool {
+        self.secrets.is_empty()
+    }
 
-        pub fn secrets(&self) -> Vec<Secret> {
-            self.iter().map(|pm| pm.secret.clone()).collect()
-        }
+    pub fn total_amount(&self) -> Amount {
+        self.secrets
+            .iter()
+            .map(|PreMint { amount, .. }| *amount)
+            .sum()
+    }
 
-        pub fn rs(&self) -> Vec<SecretKey> {
-            self.iter().map(|pm| pm.r.clone()).collect()
-        }
+    pub fn blinded_messages(&self) -> Vec<BlindedMessage> {
+        self.iter().map(|pm| pm.blinded_message.clone()).collect()
+    }
 
-        pub fn amounts(&self) -> Vec<Amount> {
-            self.iter().map(|pm| pm.amount).collect()
-        }
+    pub fn secrets(&self) -> Vec<Secret> {
+        self.iter().map(|pm| pm.secret.clone()).collect()
+    }
 
-        pub fn combine(&mut self, mut other: Self) {
-            self.secrets.append(&mut other.secrets)
-        }
+    pub fn rs(&self) -> Vec<SecretKey> {
+        self.iter().map(|pm| pm.r.clone()).collect()
+    }
 
-        pub fn sort_secrets(&mut self) {
-            self.secrets.sort();
-        }
+    pub fn amounts(&self) -> Vec<Amount> {
+        self.iter().map(|pm| pm.amount).collect()
     }
 
-    // Implement Iterator for PreMintSecrets
-    impl Iterator for PreMintSecrets {
-        type Item = PreMint;
+    pub fn combine(&mut self, mut other: Self) {
+        self.secrets.append(&mut other.secrets)
+    }
 
-        fn next(&mut self) -> Option<Self::Item> {
-            // Use the iterator of the vector
-            self.secrets.pop()
-        }
+    pub fn sort_secrets(&mut self) {
+        self.secrets.sort();
     }
+}
 
-    impl Ord for PreMintSecrets {
-        fn cmp(&self, other: &Self) -> Ordering {
-            self.secrets.cmp(&other.secrets)
-        }
+// Implement Iterator for PreMintSecrets
+impl Iterator for PreMintSecrets {
+    type Item = PreMint;
+
+    fn next(&mut self) -> Option<Self::Item> {
+        // Use the iterator of the vector
+        self.secrets.pop()
     }
+}
 
-    impl PartialOrd for PreMintSecrets {
-        fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
-            Some(self.cmp(other))
-        }
+impl Ord for PreMintSecrets {
+    fn cmp(&self, other: &Self) -> Ordering {
+        self.secrets.cmp(&other.secrets)
     }
+}
 
-    #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
-    pub struct Token {
-        pub token: Vec<MintProofs>,
-        /// Memo for token
-        #[serde(skip_serializing_if = "Option::is_none")]
-        pub memo: Option<String>,
-        /// Token Unit
-        #[serde(skip_serializing_if = "Option::is_none")]
-        pub unit: Option<CurrencyUnit>,
-    }
-
-    impl Token {
-        pub fn new(
-            mint_url: UncheckedUrl,
-            proofs: Proofs,
-            memo: Option<String>,
-            unit: Option<CurrencyUnit>,
-        ) -> Result<Self, Error> {
-            if proofs.is_empty() {
-                return Err(Error::ProofsRequired);
-            }
+impl PartialOrd for PreMintSecrets {
+    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+        Some(self.cmp(other))
+    }
+}
 
-            // Check Url is valid
-            let _: Url = (&mint_url).try_into().map_err(|_| Error::InvalidUrl)?;
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct Token {
+    pub token: Vec<MintProofs>,
+    /// Memo for token
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub memo: Option<String>,
+    /// Token Unit
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub unit: Option<CurrencyUnit>,
+}
 
-            Ok(Self {
-                token: vec![MintProofs::new(mint_url, proofs)],
-                memo,
-                unit,
-            })
+impl Token {
+    pub fn new(
+        mint_url: UncheckedUrl,
+        proofs: Proofs,
+        memo: Option<String>,
+        unit: Option<CurrencyUnit>,
+    ) -> Result<Self, Error> {
+        if proofs.is_empty() {
+            return Err(Error::ProofsRequired);
         }
 
-        pub fn token_info(&self) -> (u64, String) {
-            let mut amount = Amount::ZERO;
+        // Check Url is valid
+        let _: Url = (&mint_url).try_into().map_err(|_| Error::InvalidUrl)?;
 
-            for proofs in &self.token {
-                for proof in &proofs.proofs {
-                    amount += proof.amount;
-                }
-            }
+        Ok(Self {
+            token: vec![MintProofs::new(mint_url, proofs)],
+            memo,
+            unit,
+        })
+    }
+
+    pub fn token_info(&self) -> (u64, String) {
+        let mut amount = Amount::ZERO;
 
-            (amount.into(), self.token[0].mint.to_string())
+        for proofs in &self.token {
+            for proof in &proofs.proofs {
+                amount += proof.amount;
+            }
         }
-    }
 
-    impl FromStr for Token {
-        type Err = Error;
+        (amount.into(), self.token[0].mint.to_string())
+    }
+}
 
-        fn from_str(s: &str) -> Result<Self, Self::Err> {
-            let s = if s.starts_with("cashuA") {
-                s.replace("cashuA", "")
-            } else {
-                return Err(Error::UnsupportedToken);
-            };
+impl FromStr for Token {
+    type Err = Error;
 
-            let decode_config = general_purpose::GeneralPurposeConfig::new()
-                .with_decode_padding_mode(base64::engine::DecodePaddingMode::Indifferent);
-            let decoded = GeneralPurpose::new(&alphabet::STANDARD, decode_config).decode(s)?;
-            let decoded_str = String::from_utf8(decoded)?;
-            let token: Token = serde_json::from_str(&decoded_str)?;
-            Ok(token)
-        }
+    fn from_str(s: &str) -> Result<Self, Self::Err> {
+        let s = if s.starts_with("cashuA") {
+            s.replace("cashuA", "")
+        } else {
+            return Err(Error::UnsupportedToken);
+        };
+
+        let decode_config = general_purpose::GeneralPurposeConfig::new()
+            .with_decode_padding_mode(base64::engine::DecodePaddingMode::Indifferent);
+        let decoded = GeneralPurpose::new(&alphabet::STANDARD, decode_config).decode(s)?;
+        let decoded_str = String::from_utf8(decoded)?;
+        let token: Token = serde_json::from_str(&decoded_str)?;
+        Ok(token)
     }
+}
 
-    impl fmt::Display for Token {
-        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-            let json_string = serde_json::to_string(self).map_err(|_| fmt::Error)?;
-            let encoded = general_purpose::STANDARD.encode(json_string);
-            write!(f, "cashuA{}", encoded)
-        }
+impl fmt::Display for Token {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        let json_string = serde_json::to_string(self).map_err(|_| fmt::Error)?;
+        let encoded = general_purpose::STANDARD.encode(json_string);
+        write!(f, "cashuA{}", encoded)
     }
 }
 
@@ -423,9 +548,8 @@ pub struct MintProofs {
     pub proofs: Proofs,
 }
 
-#[cfg(feature = "wallet")]
 impl MintProofs {
-    fn new(mint_url: UncheckedUrl, proofs: Proofs) -> Self {
+    pub fn new(mint_url: UncheckedUrl, proofs: Proofs) -> Self {
         Self {
             mint: mint_url,
             proofs,
@@ -433,80 +557,10 @@ impl MintProofs {
     }
 }
 
-/// Promise (BlindSignature) [NUT-00]
-#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
-pub struct BlindSignature {
-    pub amount: Amount,
-    /// Keyset Id
-    #[serde(rename = "id")]
-    pub keyset_id: Id,
-    /// blinded signature (C_) on the secret message `B_` of [BlindedMessage]
-    #[serde(rename = "C_")]
-    pub c: PublicKey,
-    /// DLEQ Proof
-    pub dleq: Option<BlindSignatureDleq>,
-}
-
-/// Proofs [NUT-00]
-#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
-pub struct Proof {
-    /// Amount in satoshi
-    pub amount: Amount,
-    /// `Keyset id`
-    #[serde(rename = "id")]
-    pub keyset_id: Id,
-    /// Secret message
-    pub secret: Secret,
-    /// Unblinded signature
-    #[serde(rename = "C")]
-    pub c: PublicKey,
-    /// Witness
-    #[serde(default)]
-    #[serde(skip_serializing_if = "Option::is_none")]
-    #[serde(serialize_with = "witness_serialize")]
-    #[serde(deserialize_with = "witness_deserialize")]
-    pub witness: Option<Signatures>,
-    /// DLEQ Proof
-    pub dleq: Option<ProofDleq>,
-}
-
-impl Proof {
-    pub fn new(amount: Amount, keyset_id: Id, secret: Secret, c: PublicKey) -> Self {
-        Proof {
-            amount,
-            keyset_id,
-            secret,
-            c,
-            witness: None,
-            dleq: None,
-        }
-    }
-}
-
-impl hash::Hash for Proof {
-    fn hash<H: Hasher>(&self, state: &mut H) {
-        self.secret.hash(state);
-    }
-}
-
-impl Ord for Proof {
-    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
-        self.amount.cmp(&other.amount)
-    }
-}
-
-impl PartialOrd for Proof {
-    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
-        Some(self.cmp(other))
-    }
-}
-
 #[cfg(test)]
 mod tests {
     use std::str::FromStr;
 
-    #[cfg(feature = "wallet")]
-    use super::wallet::*;
     use super::*;
 
     #[test]
@@ -523,7 +577,6 @@ mod tests {
     }
 
     #[test]
-    #[cfg(feature = "wallet")]
     fn test_token_str_round_trip() {
         let token_str = "cashuAeyJ0b2tlbiI6W3sibWludCI6Imh0dHBzOi8vODMzMy5zcGFjZTozMzM4IiwicHJvb2ZzIjpbeyJhbW91bnQiOjIsImlkIjoiMDA5YTFmMjkzMjUzZTQxZSIsInNlY3JldCI6IjQwNzkxNWJjMjEyYmU2MWE3N2UzZTZkMmFlYjRjNzI3OTgwYmRhNTFjZDA2YTZhZmMyOWUyODYxNzY4YTc4MzciLCJDIjoiMDJiYzkwOTc5OTdkODFhZmIyY2M3MzQ2YjVlNDM0NWE5MzQ2YmQyYTUwNmViNzk1ODU5OGE3MmYwY2Y4NTE2M2VhIn0seyJhbW91bnQiOjgsImlkIjoiMDA5YTFmMjkzMjUzZTQxZSIsInNlY3JldCI6ImZlMTUxMDkzMTRlNjFkNzc1NmIwZjhlZTBmMjNhNjI0YWNhYTNmNGUwNDJmNjE0MzNjNzI4YzcwNTdiOTMxYmUiLCJDIjoiMDI5ZThlNTA1MGI4OTBhN2Q2YzA5NjhkYjE2YmMxZDVkNWZhMDQwZWExZGUyODRmNmVjNjlkNjEyOTlmNjcxMDU5In1dfV0sInVuaXQiOiJzYXQiLCJtZW1vIjoiVGhhbmsgeW91LiJ9";
 
@@ -547,7 +600,6 @@ mod tests {
     }
 
     #[test]
-    #[cfg(feature = "wallet")]
     fn test_blank_blinded_messages() {
         // TODO: Need to update id to new type in proof
         let b = PreMintSecrets::blank(
@@ -564,7 +616,6 @@ mod tests {
     }
 
     #[test]
-    #[cfg(feature = "wallet")]
     fn incorrect_tokens() {
         let incorrect_prefix = "casshuAeyJ0b2tlbiI6W3sibWludCI6Imh0dHBzOi8vODMzMy5zcGFjZTozMzM4IiwicHJvb2ZzIjpbeyJhbW91bnQiOjIsImlkIjoiMDA5YTFmMjkzMjUzZTQxZSIsInNlY3JldCI6IjQwNzkxNWJjMjEyYmU2MWE3N2UzZTZkMmFlYjRjNzI3OTgwYmRhNTFjZDA2YTZhZmMyOWUyODYxNzY4YTc4MzciLCJDIjoiMDJiYzkwOTc5OTdkODFhZmIyY2M3MzQ2YjVlNDM0NWE5MzQ2YmQyYTUwNmViNzk1ODU5OGE3MmYwY2Y4NTE2M2VhIn0seyJhbW91bnQiOjgsImlkIjoiMDA5YTFmMjkzMjUzZTQxZSIsInNlY3JldCI6ImZlMTUxMDkzMTRlNjFkNzc1NmIwZjhlZTBmMjNhNjI0YWNhYTNmNGUwNDJmNjE0MzNjNzI4YzcwNTdiOTMxYmUiLCJDIjoiMDI5ZThlNTA1MGI4OTBhN2Q2YzA5NjhkYjE2YmMxZDVkNWZhMDQwZWExZGUyODRmNmVjNjlkNjEyOTlmNjcxMDU5In1dfV0sInVuaXQiOiJzYXQiLCJtZW1vIjoiVGhhbmsgeW91LiJ9";
 

+ 33 - 60
crates/cdk/src/nuts/nut01/mod.rs

@@ -3,6 +3,7 @@
 //! <https://github.com/cashubtc/nuts/blob/main/01.md>
 
 use std::collections::BTreeMap;
+use std::ops::{Deref, DerefMut};
 
 use bitcoin::secp256k1;
 use serde::{Deserialize, Serialize};
@@ -30,8 +31,8 @@ pub enum Error {
 #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
 pub struct Keys(BTreeMap<Amount, PublicKey>);
 
-impl From<mint::Keys> for Keys {
-    fn from(keys: mint::Keys) -> Self {
+impl From<MintKeys> for Keys {
+    fn from(keys: MintKeys) -> Self {
         Self(
             keys.0
                 .iter()
@@ -70,71 +71,43 @@ pub struct KeysResponse {
     pub keysets: Vec<KeySet>,
 }
 
-/*
-impl<'de> serde::de::Deserialize<'de> for KeysResponse {
-    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
-    where
-        D: serde::Deserializer<'de>,
-    {
-        struct KeysVisitor;
-
-        impl<'de> serde::de::Visitor<'de> for KeysVisitor {
-            type Value = KeysResponse;
-
-            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
-                formatter.write_str("")
-            }
-
-            fn visit_map<M>(self, mut m: M) -> Result<Self::Value, M::Error>
-            where
-                M: serde::de::MapAccess<'de>,
-            {
-                let mut keys: BTreeMap<Amount, PublicKey> = BTreeMap::new();
-
-                while let Some((a, k)) = m.next_entry::<String, String>()? {
-                    let amount = a.parse::<u64>();
-                    let pub_key = PublicKey::from_hex(k);
-
-                    if let (Ok(amount), Ok(pubkey)) = (amount, pub_key) {
-                        let amount = Amount::from(amount);
-
-                        keys.insert(amount, pubkey);
-                    }
-                    // TODO: Should return an error if an amount or key is
-                    // invalid and not continue
-                }
-
-                Ok(KeysResponse { keys: Keys(keys) })
-            }
-        }
+/// Mint keys
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct MintKeys(BTreeMap<Amount, MintKeyPair>);
 
-        deserializer.deserialize_map(KeysVisitor)
+impl Deref for MintKeys {
+    type Target = BTreeMap<Amount, MintKeyPair>;
+
+    fn deref(&self) -> &Self::Target {
+        &self.0
     }
 }
-*/
-pub mod mint {
-    use std::collections::BTreeMap;
 
-    use serde::{Deserialize, Serialize};
-
-    use super::{PublicKey, SecretKey};
-    use crate::Amount;
-
-    #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
-    pub struct Keys(pub BTreeMap<Amount, KeyPair>);
+impl DerefMut for MintKeys {
+    fn deref_mut(&mut self) -> &mut Self::Target {
+        &mut self.0
+    }
+}
 
-    #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
-    pub struct KeyPair {
-        pub public_key: PublicKey,
-        pub secret_key: SecretKey,
+impl MintKeys {
+    #[inline]
+    pub fn new(map: BTreeMap<Amount, MintKeyPair>) -> Self {
+        Self(map)
     }
+}
 
-    impl KeyPair {
-        pub fn from_secret_key(secret_key: SecretKey) -> Self {
-            Self {
-                public_key: secret_key.public_key(),
-                secret_key,
-            }
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct MintKeyPair {
+    pub public_key: PublicKey,
+    pub secret_key: SecretKey,
+}
+
+impl MintKeyPair {
+    #[inline]
+    pub fn from_secret_key(secret_key: SecretKey) -> Self {
+        Self {
+            public_key: secret_key.public_key(),
+            secret_key,
         }
     }
 }

+ 63 - 74
crates/cdk/src/nuts/nut02.rs

@@ -4,15 +4,18 @@
 
 use core::fmt;
 use core::str::FromStr;
+use std::collections::BTreeMap;
 
-use bitcoin::hashes::{sha256, Hash};
-use serde::{Deserialize, Serialize};
+use bitcoin::hashes::sha256::Hash as Sha256;
+use bitcoin::hashes::{Hash, HashEngine};
+use serde::{Deserialize, Deserializer, Serialize};
 use serde_with::{serde_as, VecSkipError};
 use thiserror::Error;
 
-use super::nut01::Keys;
-use super::CurrencyUnit;
+use super::nut01::{Keys, MintKeyPair, MintKeys, SecretKey};
+use crate::nuts::nut00::CurrencyUnit;
 use crate::util::hex;
+use crate::Amount;
 
 #[derive(Debug, Error, PartialEq)]
 pub enum Error {
@@ -88,7 +91,7 @@ impl FromStr for Id {
     }
 }
 
-impl serde::ser::Serialize for Id {
+impl Serialize for Id {
     fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
     where
         S: serde::Serializer,
@@ -97,10 +100,10 @@ impl serde::ser::Serialize for Id {
     }
 }
 
-impl<'de> serde::de::Deserialize<'de> for Id {
+impl<'de> Deserialize<'de> for Id {
     fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
     where
-        D: serde::Deserializer<'de>,
+        D: Deserializer<'de>,
     {
         struct IdVisitor;
 
@@ -151,7 +154,7 @@ impl From<&Keys> for Id {
             .collect::<Vec<[u8; 33]>>()
             .concat();
 
-        let hash = sha256::Hash::hash(&pubkeys_concat);
+        let hash = Sha256::hash(&pubkeys_concat);
         let hex_of_hash = hex::encode(hash.to_byte_array());
         // First 9 bytes of hash will encode as the first 12 Base64 characters later
         Self {
@@ -190,8 +193,8 @@ pub struct KeySet {
     pub keys: Keys,
 }
 
-impl From<mint::KeySet> for KeySet {
-    fn from(keyset: mint::KeySet) -> Self {
+impl From<MintKeySet> for KeySet {
+    fn from(keyset: MintKeySet) -> Self {
         Self {
             id: keyset.id,
             unit: keyset.unit,
@@ -217,83 +220,69 @@ impl From<KeySet> for KeySetInfo {
     }
 }
 
-pub mod mint {
-    use std::collections::BTreeMap;
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct MintKeySet {
+    pub id: Id,
+    pub unit: CurrencyUnit,
+    pub keys: MintKeys,
+}
 
-    use bitcoin::hashes::sha256::Hash as Sha256;
-    use bitcoin::hashes::{Hash, HashEngine};
-    use serde::{Deserialize, Serialize};
+impl MintKeySet {
+    pub fn generate(
+        secret: &[u8],
+        unit: CurrencyUnit,
+        derivation_path: &str,
+        max_order: u8,
+    ) -> Self {
+        // Elliptic curve math context
+
+        /* NUT-02 § 2.1
+            for i in range(MAX_ORDER):
+                k_i = HASH_SHA256(s + D + i)[:32]
+        */
 
-    use super::Id;
-    use crate::nuts::nut01::mint::{KeyPair, Keys};
-    use crate::nuts::nut01::SecretKey;
-    use crate::nuts::CurrencyUnit;
-    use crate::Amount;
+        let mut map = BTreeMap::new();
 
-    #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
-    pub struct KeySet {
-        pub id: Id,
-        pub unit: CurrencyUnit,
-        pub keys: Keys,
-    }
+        // SHA-256 midstate, for quicker hashing
+        let mut engine = Sha256::engine();
+        engine.input(secret);
+        engine.input(derivation_path.as_bytes());
 
-    impl KeySet {
-        pub fn generate(
-            secret: &[u8],
-            unit: CurrencyUnit,
-            derivation_path: &str,
-            max_order: u8,
-        ) -> Self {
-            // Elliptic curve math context
-
-            /* NUT-02 § 2.1
-                for i in range(MAX_ORDER):
-                    k_i = HASH_SHA256(s + D + i)[:32]
-            */
-
-            let mut map = BTreeMap::new();
-
-            // SHA-256 midstate, for quicker hashing
-            let mut engine = Sha256::engine();
-            engine.input(secret);
-            engine.input(derivation_path.as_bytes());
-
-            for i in 0..max_order {
-                let amount = Amount::from(2_u64.pow(i as u32));
-
-                // Reuse midstate
-                let mut e = engine.clone();
-                e.input(i.to_string().as_bytes());
-                let hash = Sha256::from_engine(e);
-                let secret_key = SecretKey::from_slice(&hash.to_byte_array()).unwrap(); // TODO: remove unwrap
-                let keypair = KeyPair::from_secret_key(secret_key);
-                map.insert(amount, keypair);
-            }
+        for i in 0..max_order {
+            let amount = Amount::from(2_u64.pow(i as u32));
 
-            let keys = Keys(map);
+            // Reuse midstate
+            let mut e = engine.clone();
+            e.input(i.to_string().as_bytes());
+            let hash = Sha256::from_engine(e);
+            let secret_key = SecretKey::from_slice(&hash.to_byte_array()).unwrap(); // TODO: remove unwrap
+            let keypair = MintKeyPair::from_secret_key(secret_key);
+            map.insert(amount, keypair);
+        }
 
-            Self {
-                id: (&keys).into(),
-                unit,
-                keys,
-            }
+        let keys = MintKeys::new(map);
+
+        Self {
+            id: (&keys).into(),
+            unit,
+            keys,
         }
     }
+}
 
-    impl From<KeySet> for Id {
-        fn from(keyset: KeySet) -> Id {
-            let keys: super::KeySet = keyset.into();
+impl From<MintKeySet> for Id {
+    fn from(keyset: MintKeySet) -> Id {
+        let keys: super::KeySet = keyset.into();
 
-            Id::from(&keys.keys)
-        }
+        Id::from(&keys.keys)
     }
+}
 
-    impl From<&Keys> for Id {
-        fn from(map: &Keys) -> Self {
-            let keys: super::Keys = map.clone().into();
+impl From<&MintKeys> for Id {
+    fn from(map: &MintKeys) -> Self {
+        let keys: super::Keys = map.clone().into();
 
-            Id::from(&keys)
-        }
+        Id::from(&keys)
     }
 }
 

+ 1 - 6
crates/cdk/src/nuts/nut03.rs

@@ -4,14 +4,9 @@
 
 use serde::{Deserialize, Serialize};
 
-use super::nut00::BlindSignature;
-#[cfg(feature = "wallet")]
-use crate::nuts::PreMintSecrets;
-use crate::nuts::{BlindedMessage, Proofs};
+use super::nut00::{BlindSignature, BlindedMessage, PreMintSecrets, Proofs};
 use crate::Amount;
-pub use crate::Bolt11Invoice;
 
-#[cfg(feature = "wallet")]
 #[derive(Debug, Clone, PartialEq, Eq, Serialize)]
 pub struct PreSwap {
     pub pre_mint_secrets: PreMintSecrets,

+ 1 - 1
crates/cdk/src/nuts/nut04.rs

@@ -4,7 +4,7 @@
 
 use serde::{Deserialize, Serialize};
 
-use super::{BlindSignature, BlindedMessage, CurrencyUnit, PaymentMethod};
+use super::nut00::{BlindSignature, BlindedMessage, CurrencyUnit, PaymentMethod};
 use crate::types::MintQuote;
 use crate::Amount;
 

+ 1 - 2
crates/cdk/src/nuts/nut05.rs

@@ -4,8 +4,7 @@
 
 use serde::{Deserialize, Serialize};
 
-use super::{BlindSignature, BlindedMessage, CurrencyUnit, PaymentMethod};
-use crate::nuts::Proofs;
+use super::nut00::{BlindSignature, BlindedMessage, CurrencyUnit, PaymentMethod, Proofs};
 use crate::types::MeltQuote;
 use crate::{Amount, Bolt11Invoice};
 

+ 1 - 1
crates/cdk/src/nuts/nut07.rs

@@ -4,7 +4,7 @@
 
 use serde::{Deserialize, Serialize};
 
-use super::PublicKey;
+use super::nut01::PublicKey;
 
 #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
 #[serde(rename_all = "UPPERCASE")]

+ 1 - 1
crates/cdk/src/nuts/nut08.rs

@@ -4,7 +4,7 @@
 
 use serde::{Deserialize, Serialize};
 
-use super::{MeltBolt11Request, MeltBolt11Response};
+use super::nut05::{MeltBolt11Request, MeltBolt11Response};
 use crate::Amount;
 
 impl MeltBolt11Request {

+ 1 - 1
crates/cdk/src/nuts/nut09.rs

@@ -4,7 +4,7 @@
 
 use serde::{Deserialize, Serialize};
 
-use super::{BlindSignature, BlindedMessage};
+use super::nut00::{BlindSignature, BlindedMessage};
 
 /// Restore Request [NUT-09]
 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]

+ 11 - 5
crates/cdk/src/nuts/nut11.rs

@@ -70,7 +70,7 @@ pub enum Error {
     Secret(#[from] crate::secret::Error),
 }
 
-#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+#[derive(Default, Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
 pub struct Signatures {
     #[serde(default)]
     #[serde(skip_serializing_if = "Vec::is_empty")]
@@ -78,11 +78,13 @@ pub struct Signatures {
 }
 
 impl Signatures {
+    #[inline]
     pub fn is_empty(&self) -> bool {
         self.signatures.is_empty()
     }
 }
 
+/// Serialize [Signatures] as stringified JSON
 pub fn witness_serialize<S>(x: &Option<Signatures>, s: S) -> Result<S::Ok, S::Error>
 where
     S: Serializer,
@@ -90,9 +92,10 @@ where
     s.serialize_str(&serde_json::to_string(&x).map_err(ser::Error::custom)?)
 }
 
+/// Serialize [Signatures] from stringified JSON
 pub fn witness_deserialize<'de, D>(deserializer: D) -> Result<Option<Signatures>, D::Error>
 where
-    D: de::Deserializer<'de>,
+    D: Deserializer<'de>,
 {
     let s: String = String::deserialize(deserializer)?;
     serde_json::from_str(&s).map_err(de::Error::custom)
@@ -176,7 +179,7 @@ impl Proof {
 
 impl BlindedMessage {
     pub fn sign_p2pk(&mut self, secret_key: SigningKey) -> Result<(), Error> {
-        let msg: [u8; 33] = self.b.to_bytes();
+        let msg: [u8; 33] = self.blinded_secret.to_bytes();
         let signature: Signature = secret_key.sign(&msg)?;
 
         self.witness
@@ -197,13 +200,16 @@ impl BlindedMessage {
         if let Some(witness) = &self.witness {
             for signature in &witness.signatures {
                 for v in pubkeys {
-                    let msg = &self.b.to_bytes();
+                    let msg = &self.blinded_secret.to_bytes();
                     let sig = Signature::from_str(signature)?;
 
                     if v.verify(msg, &sig).is_ok() {
                         valid_sigs += 1;
                     } else {
-                        tracing::debug!("Could not verify signature: {sig} on message: {}", self.b)
+                        tracing::debug!(
+                            "Could not verify signature: {sig} on message: {}",
+                            self.blinded_secret
+                        )
                     }
                 }
             }

+ 3 - 2
crates/cdk/src/nuts/nut12.rs

@@ -8,7 +8,9 @@ use bitcoin::secp256k1::{self, Scalar};
 use serde::{Deserialize, Serialize};
 use thiserror::Error;
 
-use super::{BlindSignature, Id, Proof, PublicKey, SecretKey};
+use super::nut00::{BlindSignature, Proof};
+use super::nut01::{PublicKey, SecretKey};
+use super::nut02::Id;
 use crate::dhke::{hash_e, hash_to_curve};
 use crate::{Amount, SECP256K1};
 
@@ -182,7 +184,6 @@ impl BlindSignature {
     e = hash(R1,R2,A,C')
     s = r + e*a
     */
-    #[cfg(feature = "mint")]
     pub fn add_dleq_proof(
         &mut self,
         blinded_message: &PublicKey,

+ 56 - 65
crates/cdk/src/nuts/nut13.rs

@@ -8,11 +8,14 @@ use bip39::Mnemonic;
 use bitcoin::bip32::{DerivationPath, ExtendedPrivKey};
 use bitcoin::Network;
 
-use super::{Id, SecretKey};
+use super::nut00::{BlindedMessage, PreMint, PreMintSecrets};
+use super::nut01::SecretKey;
+use super::nut02::Id;
+use crate::dhke::blind_message;
 use crate::error::Error;
 use crate::secret::Secret;
 use crate::util::hex;
-use crate::SECP256K1;
+use crate::{Amount, SECP256K1};
 
 impl Secret {
     pub fn from_seed(mnemonic: &Mnemonic, keyset_id: Id, counter: u64) -> Result<Self, Error> {
@@ -58,90 +61,78 @@ impl SecretKey {
     }
 }
 
-#[cfg(feature = "wallet")]
-mod wallet {
-    use bip39::Mnemonic;
+impl PreMintSecrets {
+    /// Generate blinded messages from predetermined secrets and blindings
+    /// factor
+    pub fn from_seed(
+        keyset_id: Id,
+        counter: u64,
+        mnemonic: &Mnemonic,
+        amount: Amount,
+        zero_amount: bool,
+    ) -> Result<Self, Error> {
+        let mut pre_mint_secrets = PreMintSecrets::default();
 
-    use crate::dhke::blind_message;
-    use crate::error::Error;
-    use crate::nuts::{BlindedMessage, Id, PreMint, PreMintSecrets, SecretKey};
-    use crate::secret::Secret;
-    use crate::Amount;
+        let mut counter = counter;
 
-    impl PreMintSecrets {
-        /// Generate blinded messages from predetermined secrets and blindings
-        /// factor
-        pub fn from_seed(
-            keyset_id: Id,
-            counter: u64,
-            mnemonic: &Mnemonic,
-            amount: Amount,
-            zero_amount: bool,
-        ) -> Result<Self, Error> {
-            let mut pre_mint_secrets = PreMintSecrets::default();
+        for amount in amount.split() {
+            let secret = Secret::from_seed(mnemonic, keyset_id, counter)?;
+            let blinding_factor = SecretKey::from_seed(mnemonic, keyset_id, counter)?;
 
-            let mut counter = counter;
+            let (blinded, r) = blind_message(&secret.to_bytes(), Some(blinding_factor))?;
 
-            for amount in amount.split() {
-                let secret = Secret::from_seed(mnemonic, keyset_id, counter)?;
-                let blinding_factor = SecretKey::from_seed(mnemonic, keyset_id, counter)?;
+            let amount = if zero_amount { Amount::ZERO } else { amount };
 
-                let (blinded, r) = blind_message(&secret.to_bytes(), Some(blinding_factor))?;
+            let blinded_message = BlindedMessage::new(amount, keyset_id, blinded);
 
-                let amount = if zero_amount { Amount::ZERO } else { amount };
+            let pre_mint = PreMint {
+                blinded_message,
+                secret: secret.clone(),
+                r,
+                amount,
+            };
 
-                let blinded_message = BlindedMessage::new(amount, keyset_id, blinded);
-
-                let pre_mint = PreMint {
-                    blinded_message,
-                    secret: secret.clone(),
-                    r,
-                    amount,
-                };
-
-                pre_mint_secrets.secrets.push(pre_mint);
-                counter += 1;
-            }
-
-            Ok(pre_mint_secrets)
+            pre_mint_secrets.secrets.push(pre_mint);
+            counter += 1;
         }
 
-        /// Generate blinded messages from predetermined secrets and blindings
-        /// factor
-        pub fn restore_batch(
-            keyset_id: Id,
-            mnemonic: &Mnemonic,
-            start_count: u64,
-            end_count: u64,
-        ) -> Result<Self, Error> {
-            let mut pre_mint_secrets = PreMintSecrets::default();
+        Ok(pre_mint_secrets)
+    }
 
-            for i in start_count..=end_count {
-                let secret = Secret::from_seed(mnemonic, keyset_id, i)?;
-                let blinding_factor = SecretKey::from_seed(mnemonic, keyset_id, i)?;
+    /// Generate blinded messages from predetermined secrets and blindings
+    /// factor
+    pub fn restore_batch(
+        keyset_id: Id,
+        mnemonic: &Mnemonic,
+        start_count: u64,
+        end_count: u64,
+    ) -> Result<Self, Error> {
+        let mut pre_mint_secrets = PreMintSecrets::default();
 
-                let (blinded, r) = blind_message(&secret.to_bytes(), Some(blinding_factor))?;
+        for i in start_count..=end_count {
+            let secret = Secret::from_seed(mnemonic, keyset_id, i)?;
+            let blinding_factor = SecretKey::from_seed(mnemonic, keyset_id, i)?;
 
-                let blinded_message = BlindedMessage::new(Amount::ZERO, keyset_id, blinded);
+            let (blinded, r) = blind_message(&secret.to_bytes(), Some(blinding_factor))?;
 
-                let pre_mint = PreMint {
-                    blinded_message,
-                    secret: secret.clone(),
-                    r,
-                    amount: Amount::ZERO,
-                };
+            let blinded_message = BlindedMessage::new(Amount::ZERO, keyset_id, blinded);
 
-                pre_mint_secrets.secrets.push(pre_mint);
-            }
+            let pre_mint = PreMint {
+                blinded_message,
+                secret: secret.clone(),
+                r,
+                amount: Amount::ZERO,
+            };
 
-            Ok(pre_mint_secrets)
+            pre_mint_secrets.secrets.push(pre_mint);
         }
+
+        Ok(pre_mint_secrets)
     }
 }
 
 #[cfg(test)]
 mod tests {
-
     use super::*;
 
     #[test]

+ 0 - 48
crates/cdk/src/serde_utils.rs

@@ -1,48 +0,0 @@
-//! Utilities for serde
-
-// TODO: remove this module
-
-pub mod serde_url {
-    use serde::Deserialize;
-    use url::Url;
-
-    pub fn serialize<S>(url: &Url, serializer: S) -> Result<S::Ok, S::Error>
-    where
-        S: serde::Serializer,
-    {
-        serializer.serialize_str(url.to_string().trim_end_matches('/'))
-    }
-
-    pub fn deserialize<'de, D>(deserializer: D) -> Result<Url, D::Error>
-    where
-        D: serde::Deserializer<'de>,
-    {
-        let url_string = String::deserialize(deserializer)?;
-        Url::parse(&url_string).map_err(serde::de::Error::custom)
-    }
-}
-
-pub mod bytes_base64 {
-    use base64::engine::general_purpose;
-    use base64::Engine as _;
-    use serde::Deserialize;
-
-    pub fn serialize<S>(my_bytes: &Vec<u8>, serializer: S) -> Result<S::Ok, S::Error>
-    where
-        S: serde::Serializer,
-    {
-        let encoded = general_purpose::STANDARD.encode(my_bytes);
-        serializer.serialize_str(&encoded)
-    }
-
-    pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error>
-    where
-        D: serde::Deserializer<'de>,
-    {
-        let encoded = String::deserialize(deserializer)?;
-        let decoded = general_purpose::STANDARD
-            .decode(encoded)
-            .map_err(serde::de::Error::custom)?;
-        Ok(decoded)
-    }
-}

+ 1 - 1
crates/cdk/src/types.rs

@@ -1,4 +1,4 @@
-//! Types for `cashu-crab`
+//! Types
 
 use serde::{Deserialize, Serialize};
 use uuid::Uuid;

+ 7 - 8
crates/cdk/src/wallet/localstore/mod.rs

@@ -1,17 +1,16 @@
-mod memory;
-
-#[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
-mod redb_store;
-
 use std::collections::HashMap;
 use std::num::ParseIntError;
 
 use async_trait::async_trait;
-pub use memory::MemoryLocalStore;
-#[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
-pub use redb_store::RedbLocalStore;
 use thiserror::Error;
 
+mod memory;
+#[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
+mod redb_store;
+
+pub use self::memory::MemoryLocalStore;
+#[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
+pub use self::redb_store::RedbLocalStore;
 use crate::nuts::{Id, KeySetInfo, Keys, MintInfo, Proofs};
 use crate::types::{MeltQuote, MintQuote};
 use crate::url::UncheckedUrl;

+ 8 - 10
crates/cdk/src/wallet/mod.rs

@@ -1,4 +1,5 @@
 //! Cashu Wallet
+
 use std::collections::{HashMap, HashSet};
 use std::num::ParseIntError;
 use std::str::FromStr;
@@ -12,7 +13,7 @@ use tracing::{debug, warn};
 use crate::client::HttpClient;
 use crate::dhke::{construct_proofs, hash_to_curve, unblind_message};
 use crate::nuts::{
-    BlindSignature, CurrencyUnit, Id, KeySet, KeySetInfo, Keys, MintInfo, P2PKConditions,
+    nut12, BlindSignature, CurrencyUnit, Id, KeySet, KeySetInfo, Keys, MintInfo, P2PKConditions,
     PreMintSecrets, PreSwap, Proof, ProofState, Proofs, PublicKey, RestoreRequest, SigFlag,
     SigningKey, State, SwapRequest, Token,
 };
@@ -360,9 +361,8 @@ impl Wallet {
             for (sig, premint) in mint_res.signatures.iter().zip(&premint_secrets.secrets) {
                 let keys = self.get_keyset_keys(&mint_url, sig.keyset_id).await?;
                 let key = keys.amount_key(sig.amount).ok_or(Error::UnknownKey)?;
-                match sig.verify_dleq(key, premint.blinded_message.b) {
-                    Ok(_) => (),
-                    Err(crate::nuts::nut12::Error::MissingDleqProof) => (),
+                match sig.verify_dleq(key, premint.blinded_message.blinded_secret) {
+                    Ok(_) | Err(nut12::Error::MissingDleqProof) => (),
                     Err(_) => return Err(Error::CouldNotVerifyDleq),
                 }
             }
@@ -401,7 +401,7 @@ impl Wallet {
         let unit = token_data.unit.unwrap_or_default();
 
         // Verify the signature DLEQ is valid
-        // Verify that all proofs in the token have a vlid DLEQ proof if one is supplied
+        // Verify that all proofs in the token have a valid DLEQ proof if one is supplied
         {
             for mint_proof in &token_data.token {
                 let mint_url = &mint_proof.mint;
@@ -411,8 +411,7 @@ impl Wallet {
                     let keys = self.get_keyset_keys(mint_url, proof.keyset_id).await?;
                     let key = keys.amount_key(proof.amount).ok_or(Error::UnknownKey)?;
                     match proof.verify_dleq(key) {
-                        Ok(_) => continue,
-                        Err(crate::nuts::nut12::Error::MissingDleqProof) => continue,
+                        Ok(_) | Err(nut12::Error::MissingDleqProof) => continue,
                         Err(_) => return Err(Error::CouldNotVerifyDleq),
                     }
                 }
@@ -570,9 +569,8 @@ impl Wallet {
                     .await?
                     .ok_or(Error::UnknownKey)?;
                 let key = keys.amount_key(promise.amount).ok_or(Error::UnknownKey)?;
-                match promise.verify_dleq(key, premint.blinded_message.b) {
-                    Ok(_) => (),
-                    Err(crate::nuts::nut12::Error::MissingDleqProof) => (),
+                match promise.verify_dleq(key, premint.blinded_message.blinded_secret) {
+                    Ok(_) | Err(nut12::Error::MissingDleqProof) => (),
                     Err(_) => return Err(Error::CouldNotVerifyDleq),
                 }
             }

+ 1 - 2
misc/scripts/check-docs.sh

@@ -3,8 +3,7 @@
 set -euo pipefail
 
 buildargs=(
-    "-p cashu"
-    "-p cashu-sdk"
+    "-p cdk"
 )
 
 for arg in "${buildargs[@]}"; do