diff --git a/crates/cdk-axum/src/lib.rs b/crates/cdk-axum/src/lib.rs index 8cc2300a..b082dc5b 100644 --- a/crates/cdk-axum/src/lib.rs +++ b/crates/cdk-axum/src/lib.rs @@ -64,7 +64,8 @@ struct MintState { quote_ttl: u64, } -/// Key used in hashmap of ln backends to identify what unit and payment method it is for +/// Key used in hashmap of ln backends to identify what unit and payment method +/// it is for #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub struct LnKey { /// Unit of Payment backend diff --git a/crates/cdk-axum/src/router_handlers.rs b/crates/cdk-axum/src/router_handlers.rs index 3704ffce..90c8d6d3 100644 --- a/crates/cdk-axum/src/router_handlers.rs +++ b/crates/cdk-axum/src/router_handlers.rs @@ -204,7 +204,8 @@ pub async fn post_melt_bolt11( }; // Check to see if there is a corresponding mint quote for a melt. - // In this case the mint can settle the payment internally and no ln payment is needed + // In this case the mint can settle the payment internally and no ln payment is + // needed let mint_quote = match state .mint .localstore @@ -273,12 +274,14 @@ pub async fn post_melt_bolt11( let mut partial_amount = None; - // If the quote unit is SAT or MSAT we can check that the expected fees are provided. - // We also check if the quote is less then the invoice amount in the case that it is a mmp - // However, if the quote id not of a bitcoin unit we cannot do these checks as the mint - // is unaware of a conversion rate. In this case it is assumed that the quote is correct - // and the mint should pay the full invoice amount if inputs > then quote.amount are included. - // This is checked in the verify_melt method. + // If the quote unit is SAT or MSAT we can check that the expected fees are + // provided. We also check if the quote is less then the invoice + // amount in the case that it is a mmp However, if the quote id not + // of a bitcoin unit we cannot do these checks as the mint + // is unaware of a conversion rate. In this case it is assumed that the quote is + // correct and the mint should pay the full invoice amount if inputs + // > then quote.amount are included. This is checked in the + // verify_melt method. if quote.unit == CurrencyUnit::Msat || quote.unit == CurrencyUnit::Sat { let quote_msats = to_unit(quote.amount, "e.unit, &CurrencyUnit::Msat) .expect("Quote unit is checked above that it can convert to msat"); diff --git a/crates/cdk-phoenixd/src/lib.rs b/crates/cdk-phoenixd/src/lib.rs index f131467e..6056b8bb 100644 --- a/crates/cdk-phoenixd/src/lib.rs +++ b/crates/cdk-phoenixd/src/lib.rs @@ -235,7 +235,8 @@ impl MintLightning for Phoenixd { impl Phoenixd { /// Check the status of an outgooing invoice - // TODO: This should likely bee added to the trait. Both CLN and PhD use a form of it + // TODO: This should likely bee added to the trait. Both CLN and PhD use a form + // of it async fn check_outgoing_invoice( &self, payment_hash: &str, diff --git a/crates/cdk/benches/dhke_benchmarks.rs b/crates/cdk/benches/dhke_benchmarks.rs index 092eee3c..f830142d 100644 --- a/crates/cdk/benches/dhke_benchmarks.rs +++ b/crates/cdk/benches/dhke_benchmarks.rs @@ -5,7 +5,7 @@ use criterion::{criterion_group, criterion_main, Criterion}; fn bench_dhke(c: &mut Criterion) { // ************************************************************* - // * PREPARE DATA FOR BENCHMARKS * + // * PREPARE DATA FOR BENCHMARKS * // ************************************************************* let message = hex::decode("d341ee4871f1f889041e63cf0d3823c713eea6aff01e80f1719f08f9e5be98f6").unwrap(); @@ -29,7 +29,7 @@ fn bench_dhke(c: &mut Criterion) { dhke::blind_message("test_message".as_bytes(), Some(bob_sec.clone())).unwrap(); // ************************************************************* - // * RUN INDIVIDUAL STEPS * + // * RUN INDIVIDUAL STEPS * // ************************************************************* c.bench_function("hash_to_curve", |b| { b.iter(|| { @@ -56,7 +56,7 @@ fn bench_dhke(c: &mut Criterion) { }); // ************************************************************* - // * RUN END TO END BDHKE * + // * RUN END TO END BDHKE * // ************************************************************* c.bench_function("End-to-End BDHKE", |b| { b.iter(|| { diff --git a/crates/cdk/src/cdk_database/mod.rs b/crates/cdk/src/cdk_database/mod.rs index 8c20ea84..33e3bd00 100644 --- a/crates/cdk/src/cdk_database/mod.rs +++ b/crates/cdk/src/cdk_database/mod.rs @@ -124,17 +124,20 @@ pub trait WalletDatabase: Debug { /// Remove [`Keys`] from storage async fn remove_keys(&self, id: &Id) -> Result<(), Self::Err>; - /// Update the proofs in storage by adding new proofs or removing proofs by their Y value. + /// Update the proofs in storage by adding new proofs or removing proofs by + /// their Y value. async fn update_proofs( &self, added: Vec, removed_ys: Vec, ) -> Result<(), Self::Err>; - /// Set proofs as pending in storage. Proofs are identified by their Y value. + /// Set proofs as pending in storage. Proofs are identified by their Y + /// value. async fn set_pending_proofs(&self, ys: Vec) -> Result<(), Self::Err>; /// Reserve proofs in storage. Proofs are identified by their Y value. async fn reserve_proofs(&self, ys: Vec) -> Result<(), Self::Err>; - /// Set proofs as unspent in storage. Proofs are identified by their Y value. + /// Set proofs as unspent in storage. Proofs are identified by their Y + /// value. async fn set_unspent_proofs(&self, ys: Vec) -> Result<(), Self::Err>; /// Get proofs from storage async fn get_proofs( diff --git a/crates/cdk/src/dhke.rs b/crates/cdk/src/dhke.rs index ada2388a..95009cd1 100644 --- a/crates/cdk/src/dhke.rs +++ b/crates/cdk/src/dhke.rs @@ -18,7 +18,8 @@ use crate::SECP256K1; const DOMAIN_SEPARATOR: &[u8; 28] = b"Secp256k1_HashToCurve_Cashu_"; -/// Deterministically maps a message to a public key point on the secp256k1 curve, utilizing a domain separator to ensure uniqueness. +/// Deterministically maps a message to a public key point on the secp256k1 +/// curve, utilizing a domain separator to ensure uniqueness. /// /// For definationn in NUT see [NUT-00](https://github.com/cashubtc/nuts/blob/main/00.md) pub fn hash_to_curve(message: &[u8]) -> Result { diff --git a/crates/cdk/src/mint/mod.rs b/crates/cdk/src/mint/mod.rs index 8e317712..f09d076e 100644 --- a/crates/cdk/src/mint/mod.rs +++ b/crates/cdk/src/mint/mod.rs @@ -253,8 +253,9 @@ impl Mint { let paid = quote.state == MintQuoteState::Paid; - // Since the pending state is not part of the NUT it should not be part of the response. - // In practice the wallet should not be checking the state of a quote while waiting for the mint response. + // Since the pending state is not part of the NUT it should not be part of the + // response. In practice the wallet should not be checking the state of + // a quote while waiting for the mint response. let state = match quote.state { MintQuoteState::Pending => MintQuoteState::Paid, s => s, @@ -459,7 +460,8 @@ impl Mint { Ok(()) } - /// Retrieve the public keys of the active keyset for distribution to wallet clients + /// Retrieve the public keys of the active keyset for distribution to wallet + /// clients #[instrument(skip(self))] pub async fn keyset_pubkeys(&self, keyset_id: &Id) -> Result { self.ensure_keyset_loaded(keyset_id).await?; @@ -470,7 +472,8 @@ impl Mint { }) } - /// Retrieve the public keys of the active keyset for distribution to wallet clients + /// Retrieve the public keys of the active keyset for distribution to wallet + /// clients #[instrument(skip_all)] pub async fn pubkeys(&self) -> Result { let keyset_infos = self.localstore.get_keyset_infos().await?; @@ -859,8 +862,9 @@ impl Mint { // Checks and verifes known secret kinds. // If it is an unknown secret kind it will be treated as a normal secret. // Spending conditions will **not** be check. It is up to the wallet to ensure - // only supported secret kinds are used as there is no way for the mint to enforce - // only signing supported secrets as they are blinded at that point. + // only supported secret kinds are used as there is no way for the mint to + // enforce only signing supported secrets as they are blinded at + // that point. match secret.kind { Kind::P2PK => { proof.verify_p2pk()?; @@ -1058,8 +1062,9 @@ impl Mint { } /// Process unpaid melt request - /// In the event that a melt request fails and the lighthing payment is not made - /// The [`Proofs`] should be returned to an unspent state and the quote should be unpaid + /// In the event that a melt request fails and the lighthing payment is not + /// made The [`Proofs`] should be returned to an unspent state and the + /// quote should be unpaid #[instrument(skip_all)] pub async fn process_unpaid_melt(&self, melt_request: &MeltBolt11Request) -> Result<(), Error> { let input_ys = melt_request @@ -1080,7 +1085,8 @@ impl Mint { } /// Process melt request marking [`Proofs`] as spent - /// The melt request must be verifyed using [`Self::verify_melt_request`] before calling [`Self::process_melt_request`] + /// The melt request must be verifyed using [`Self::verify_melt_request`] + /// before calling [`Self::process_melt_request`] #[instrument(skip_all)] pub async fn process_melt_request( &self, diff --git a/crates/cdk/src/nuts/nut04.rs b/crates/cdk/src/nuts/nut04.rs index 79216bec..f0e01e9e 100644 --- a/crates/cdk/src/nuts/nut04.rs +++ b/crates/cdk/src/nuts/nut04.rs @@ -40,7 +40,8 @@ pub enum QuoteState { /// Quote has been paid and wallet can mint Paid, /// Minting is in progress - /// **Note:** This state is to be used internally but is not part of the nut. + /// **Note:** This state is to be used internally but is not part of the + /// nut. Pending, /// ecash issued for quote Issued, diff --git a/crates/cdk/src/nuts/nut11/mod.rs b/crates/cdk/src/nuts/nut11/mod.rs index 8fd42667..28d466ec 100644 --- a/crates/cdk/src/nuts/nut11/mod.rs +++ b/crates/cdk/src/nuts/nut11/mod.rs @@ -588,7 +588,8 @@ where pub enum SigFlag { #[default] /// Requires valid signatures on all inputs. - /// It is the default signature flag and will be applied even if the `sigflag` tag is absent. + /// It is the default signature flag and will be applied even if the + /// `sigflag` tag is absent. SigInputs, /// Requires valid signatures on all inputs and on all outputs. SigAll, @@ -615,7 +616,8 @@ impl FromStr for SigFlag { } #[cfg(feature = "mint")] -/// Get the signature flag that should be enforced for a set of proofs and the public keys that signatures are valid for +/// Get the signature flag that should be enforced for a set of proofs and the +/// public keys that signatures are valid for pub(crate) fn enforce_sig_flag(proofs: Proofs) -> EnforceSigFlag { let mut sig_flag = SigFlag::SigInputs; let mut pubkeys = HashSet::new(); diff --git a/crates/cdk/src/nuts/nut13.rs b/crates/cdk/src/nuts/nut13.rs index 386a7523..5ad3ac83 100644 --- a/crates/cdk/src/nuts/nut13.rs +++ b/crates/cdk/src/nuts/nut13.rs @@ -117,7 +117,8 @@ impl PreMintSecrets { Ok(pre_mint_secrets) } - /// Generate blinded messages from predetermined secrets and blindings factor + /// Generate blinded messages from predetermined secrets and blindings + /// factor pub fn restore_batch( keyset_id: Id, xpriv: ExtendedPrivKey, diff --git a/crates/cdk/src/wallet/client.rs b/crates/cdk/src/wallet/client.rs index eb0ac81e..71731343 100644 --- a/crates/cdk/src/wallet/client.rs +++ b/crates/cdk/src/wallet/client.rs @@ -58,7 +58,8 @@ impl HttpClient { #[cfg(not(target_arch = "wasm32"))] /// Create new [`HttpClient`] with a proxy for specific TLDs. - /// Specifying `None` for `host_matcher` will use the proxy for all requests. + /// Specifying `None` for `host_matcher` will use the proxy for all + /// requests. pub fn with_proxy( proxy: Url, host_matcher: Option<&str>, diff --git a/crates/cdk/src/wallet/mod.rs b/crates/cdk/src/wallet/mod.rs index 49ccf854..36a90e9f 100644 --- a/crates/cdk/src/wallet/mod.rs +++ b/crates/cdk/src/wallet/mod.rs @@ -192,7 +192,8 @@ impl Wallet { Ok(balances) } - /// Update Mint information and related entries in the event a mint changes its URL + /// Update Mint information and related entries in the event a mint changes + /// its URL #[instrument(skip(self))] pub async fn update_mint_url(&mut self, new_mint_url: MintUrl) -> Result<(), Error> { self.mint_url = new_mint_url.clone(); @@ -327,7 +328,8 @@ impl Wallet { /// Get active keyset for mint /// - /// Quieries mint for current keysets then gets [`Keys`] for any unknown keysets + /// Quieries mint for current keysets then gets [`Keys`] for any unknown + /// keysets #[instrument(skip(self))] pub async fn get_active_mint_keyset(&self) -> Result { let keysets = self @@ -441,9 +443,10 @@ impl Wallet { .check_proofs_spent(proofs.clone().into_iter().map(|p| p.proof).collect()) .await?; - // Both `State::Pending` and `State::Unspent` should be included in the pending table. - // This is because a proof that has been crated to send will be stored in the pending table - // in order to avoid accidentally double spending but to allow it to be explicitly reclaimed + // Both `State::Pending` and `State::Unspent` should be included in the pending + // table. This is because a proof that has been crated to send will be + // stored in the pending table in order to avoid accidentally double + // spending but to allow it to be explicitly reclaimed let pending_states: HashSet = states .into_iter() .filter(|s| s.state.ne(&State::Spent)) @@ -561,27 +564,33 @@ impl Wallet { Ok(total_amount) } - /// Generates blinded secrets to send to the mint for signing. This function is - /// appropriate if the caller is providing their own network transport. Otherwise - /// use `mint`, which makes a network request to the mint. + /// Generates blinded secrets to send to the mint for signing. This function + /// is appropriate if the caller is providing their own network + /// transport. Otherwise use `mint`, which makes a network request to + /// the mint. /// /// # Parameters /// /// - `&self`: A reference to the current instance /// - `active_keyset_id`: The ID of the active keyset /// - `quote_info_amount`: The amount to be minted - /// - `amount_split_target`: Strategy for splitting amount into discrete tokens - /// - `spending_conditions`: Optional spending conditions to apply to the minted tokens - /// - `count`: How many tokens were previously generated from this keyset + 1 + /// - `amount_split_target`: Strategy for splitting amount into discrete + /// tokens + /// - `spending_conditions`: Optional spending conditions to apply to the + /// minted tokens + /// - `count`: How many tokens were previously generated from this keyset + + /// 1 /// - `xpriv`: The extended private key used for generating secrets /// /// # Returns /// - /// A `Result` containing `PreMintSecrets` if successful, or an `Error` otherwise. + /// A `Result` containing `PreMintSecrets` if successful, or an `Error` + /// otherwise. /// /// # Errors /// - /// This function will return an error if the creation of `PreMintSecrets` fails. + /// This function will return an error if the creation of `PreMintSecrets` + /// fails. /// /// ``` pub fn generate_premint_secrets( @@ -591,7 +600,7 @@ impl Wallet { amount_split_target: &SplitTarget, spending_conditions: Option<&SpendingConditions>, count: u32, - xpriv: ExtendedPrivKey + xpriv: ExtendedPrivKey, ) -> Result { // Move the match logic into this function. match spending_conditions { diff --git a/crates/cdk/src/wallet/multi_mint_wallet.rs b/crates/cdk/src/wallet/multi_mint_wallet.rs index 5f31c07d..051d0bf3 100644 --- a/crates/cdk/src/wallet/multi_mint_wallet.rs +++ b/crates/cdk/src/wallet/multi_mint_wallet.rs @@ -1,6 +1,7 @@ //! MultiMint Wallet //! -//! Wrapper around core [`Wallet`] that enables the use of multiple mint unit pairs +//! Wrapper around core [`Wallet`] that enables the use of multiple mint unit +//! pairs use std::collections::{BTreeMap, HashMap}; use std::fmt; diff --git a/crates/cdk/src/wallet/types.rs b/crates/cdk/src/wallet/types.rs index 4cae6417..301c63ee 100644 --- a/crates/cdk/src/wallet/types.rs +++ b/crates/cdk/src/wallet/types.rs @@ -54,7 +54,8 @@ pub enum SendKind { OnlineExact, /// Prefer offline send if difference is less then tolerance OnlineTolerance(Amount), - /// Wallet cannot do an online swap and selectedp proof must be exactly send amount + /// Wallet cannot do an online swap and selectedp proof must be exactly send + /// amount OfflineExact, /// Wallet must remain offline but can over pay if below tolerance OfflineTolerance(Amount), diff --git a/flake.nix b/flake.nix index ece16669..6b61aa73 100644 --- a/flake.nix +++ b/flake.nix @@ -45,12 +45,14 @@ pname = "flexbox-multibuild"; src = rustSrc; }).overrideArgs commonArgs; - in rec { + in + rec { workspaceDeps = craneLib.buildWorkspaceDepsOnly { }; workspaceBuild = craneLib.buildWorkspace { cargoArtifacts = workspaceDeps; }; }); - in { + in + { devShells = flakeboxLib.mkShells { toolchain = toolchainNative; packages = [ ];