#mint #wallet #kit #protocols #cashu #change #memory

cdk

Core Cashu Development Kit library implementing the Cashu protocol

8 releases (breaking)

new 0.6.0 Dec 17, 2024
0.5.0 Nov 19, 2024
0.4.0 Sep 8, 2024
0.3.0 Aug 31, 2024
0.0.0 Apr 6, 2024

#202 in Magic Beans

Download history 233/week @ 2024-08-26 154/week @ 2024-09-02 169/week @ 2024-09-09 47/week @ 2024-09-16 80/week @ 2024-09-23 37/week @ 2024-09-30 9/week @ 2024-10-07 42/week @ 2024-10-14 15/week @ 2024-10-21 13/week @ 2024-10-28 24/week @ 2024-11-04 2/week @ 2024-11-11 223/week @ 2024-11-18 41/week @ 2024-11-25 39/week @ 2024-12-02 33/week @ 2024-12-09

336 downloads per month
Used in 12 crates

MIT license

590KB
13K SLoC

Cashu Development Kit

ALPHA This library is in early development, the api will change and should be used with caution.

CDK is the core crate implementing the cashu protocol for both the Wallet and Mint.

Crate Feature Flags

The following crate feature flags are available:

Feature Default Description
wallet Yes Enable cashu wallet features
mint Yes Enable cashu mint wallet features

Implemented NUTs:

See https://github.com/cashubtc/cdk/blob/main/README.md

Examples

//! Wallet example with memory store

use std::sync::Arc;
use std::time::Duration;

use cdk::amount::SplitTarget;
use cdk::cdk_database::WalletMemoryDatabase;
use cdk::nuts::{CurrencyUnit, MintQuoteState};
use cdk::wallet::Wallet;
use cdk::Amount;
use rand::Rng;
use tokio::time::sleep;

#[tokio::main]
async fn main() {
    let seed = rand::thread_rng().gen::<[u8; 32]>();

    let mint_url = "https://testnut.cashu.space";
    let unit = CurrencyUnit::Sat;
    let amount = Amount::from(10);

    let localstore = WalletMemoryDatabase::default();

    let wallet = Wallet::new(mint_url, unit, Arc::new(localstore), &seed);

    let quote = wallet.mint_quote(amount).await.unwrap();

    println!("Pay request: {}", quote.request);

    loop {
        let status = wallet.mint_quote_state(&quote.id).await.unwrap();

        if status.state == MintQuoteState::Paid {
            break;
        }

        println!("Quote state: {}", status.state);

        sleep(Duration::from_secs(5)).await;
    }

    let receive_amount = wallet
        .mint(&quote.id, SplitTarget::default(), None)
        .await
        .unwrap();

    println!("Minted {}", receive_amount);

    let token = wallet
        .send(amount, None, None, &SplitTarget::None)
        .await
        .unwrap();

    println!("{}", token);
}

See more examples in the examples folder.

Minimum Supported Rust Version (MSRV)

The cdk library should always compile with any combination of features on Rust 1.63.0.

To build and test with the MSRV you will need to pin the below dependency versions:

cargo update -p half --precise 2.2.1
cargo update -p tokio --precise 1.38.1
cargo update -p reqwest --precise 0.12.4
cargo update -p serde_with --precise 3.1.0
cargo update -p regex --precise 1.9.6
cargo update -p backtrace --precise 0.3.58
# For wasm32-unknown-unknown target 
cargo update -p bumpalo --precise 3.12.0

License

This project is distributed under the MIT software license - see the LICENSE file for details

Dependencies

~20–36MB
~571K SLoC