Browse Source

Working on the database abstraction

Cesar Rodas 11 tháng trước cách đây
mục cha
commit
0813ee2c43
39 tập tin đã thay đổi với 640 bổ sung487 xóa
  1. 165 4
      Cargo.lock
  2. 1 1
      crates/cdk-cli/src/sub_commands/burn.rs
  3. 2 1
      crates/cdk-cli/src/sub_commands/melt.rs
  4. 1 1
      crates/cdk-cli/src/sub_commands/mint.rs
  5. 2 1
      crates/cdk-cli/src/sub_commands/receive.rs
  6. 1 1
      crates/cdk-cli/src/sub_commands/restore.rs
  7. 1 2
      crates/cdk-cli/src/sub_commands/send.rs
  8. 1 1
      crates/cdk-cli/src/sub_commands/update_mint_url.rs
  9. 3 0
      crates/cdk-common/Cargo.toml
  10. 0 0
      crates/cdk-common/src/common.rs
  11. 262 0
      crates/cdk-common/src/database.rs
  12. 3 8
      crates/cdk-common/src/error.rs
  13. 6 1
      crates/cdk-common/src/lib.rs
  14. 0 0
      crates/cdk-common/src/lightning.rs
  15. 44 1
      crates/cdk-common/src/mint.rs
  16. 24 0
      crates/cdk-common/src/wallet.rs
  17. 8 5
      crates/cdk-redb/Cargo.toml
  18. 7 7
      crates/cdk-redb/src/error.rs
  19. 2 3
      crates/cdk-redb/src/migrations.rs
  20. 3 4
      crates/cdk-redb/src/mint/migrations.rs
  21. 7 8
      crates/cdk-redb/src/mint/mod.rs
  22. 1 1
      crates/cdk-redb/src/wallet/migrations.rs
  23. 9 10
      crates/cdk-redb/src/wallet/mod.rs
  24. 15 10
      crates/cdk-sqlite/Cargo.toml
  25. 9 9
      crates/cdk-sqlite/src/mint/error.rs
  26. 11 12
      crates/cdk-sqlite/src/mint/mod.rs
  27. 9 9
      crates/cdk-sqlite/src/wallet/error.rs
  28. 11 12
      crates/cdk-sqlite/src/wallet/mod.rs
  29. 3 2
      crates/cdk/src/cdk_database/mint_memory.rs
  30. 2 281
      crates/cdk/src/cdk_database/mod.rs
  31. 1 2
      crates/cdk/src/cdk_database/wallet_memory.rs
  32. 1 2
      crates/cdk/src/fees.rs
  33. 4 7
      crates/cdk/src/lib.rs
  34. 3 3
      crates/cdk/src/mint/builder.rs
  35. 7 47
      crates/cdk/src/mint/mod.rs
  36. 3 3
      crates/cdk/src/mint/subscription/manager.rs
  37. 2 2
      crates/cdk/src/mint/subscription/on_subscription.rs
  38. 5 4
      crates/cdk/src/wallet/mod.rs
  39. 1 22
      crates/cdk/src/wallet/multi_mint_wallet.rs

+ 165 - 4
Cargo.lock

@@ -311,6 +311,12 @@ dependencies = [
 ]
 
 [[package]]
+name = "atomic-waker"
+version = "1.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
+
+[[package]]
 name = "autocfg"
 version = "1.4.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -825,14 +831,17 @@ dependencies = [
 name = "cdk-common"
 version = "0.6.0"
 dependencies = [
+ "anyhow",
  "async-trait",
  "bip39",
  "bitcoin 0.32.5",
  "cbor-diag",
  "ciborium",
+ "futures",
  "lightning-invoice",
  "once_cell",
  "rand",
+ "reqwest",
  "serde",
  "serde_json",
  "serde_with",
@@ -982,7 +991,7 @@ name = "cdk-redb"
 version = "0.6.0"
 dependencies = [
  "async-trait",
- "cdk",
+ "cdk-common",
  "lightning-invoice",
  "redb",
  "serde",
@@ -1013,7 +1022,7 @@ version = "0.6.0"
 dependencies = [
  "async-trait",
  "bitcoin 0.32.5",
- "cdk",
+ "cdk-common",
  "lightning-invoice",
  "serde_json",
  "sqlx",
@@ -1520,6 +1529,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
 
 [[package]]
+name = "encoding_rs"
+version = "0.8.35"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3"
+dependencies = [
+ "cfg-if",
+]
+
+[[package]]
 name = "equivalent"
 version = "1.0.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1626,6 +1644,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f"
 
 [[package]]
+name = "foreign-types"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
+dependencies = [
+ "foreign-types-shared",
+]
+
+[[package]]
+name = "foreign-types-shared"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
+
+[[package]]
 name = "form_urlencoded"
 version = "1.2.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1816,6 +1849,25 @@ dependencies = [
 ]
 
 [[package]]
+name = "h2"
+version = "0.4.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ccae279728d634d083c00f6099cb58f01cc99c145b84b8be2f6c74618d79922e"
+dependencies = [
+ "atomic-waker",
+ "bytes",
+ "fnv",
+ "futures-core",
+ "futures-sink",
+ "http 1.2.0",
+ "indexmap 2.7.0",
+ "slab",
+ "tokio",
+ "tokio-util",
+ "tracing",
+]
+
+[[package]]
 name = "half"
 version = "2.4.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2020,7 +2072,7 @@ dependencies = [
  "futures-channel",
  "futures-core",
  "futures-util",
- "h2",
+ "h2 0.3.26",
  "http 0.2.12",
  "http-body 0.4.6",
  "httparse",
@@ -2043,6 +2095,7 @@ dependencies = [
  "bytes",
  "futures-channel",
  "futures-util",
+ "h2 0.4.7",
  "http 1.2.0",
  "http-body 1.0.1",
  "httparse",
@@ -2099,6 +2152,22 @@ dependencies = [
 ]
 
 [[package]]
+name = "hyper-tls"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0"
+dependencies = [
+ "bytes",
+ "http-body-util",
+ "hyper 1.5.2",
+ "hyper-util",
+ "native-tls",
+ "tokio",
+ "tokio-native-tls",
+ "tower-service",
+]
+
+[[package]]
 name = "hyper-util"
 version = "0.1.10"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2698,6 +2767,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "defc4c55412d89136f966bbb339008b474350e5e6e78d2714439c386b3137a03"
 
 [[package]]
+name = "native-tls"
+version = "0.2.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466"
+dependencies = [
+ "libc",
+ "log",
+ "openssl",
+ "openssl-probe",
+ "openssl-sys",
+ "schannel",
+ "security-framework 2.11.1",
+ "security-framework-sys",
+ "tempfile",
+]
+
+[[package]]
 name = "negentropy"
 version = "0.3.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2890,12 +2976,50 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
 
 [[package]]
+name = "openssl"
+version = "0.10.68"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5"
+dependencies = [
+ "bitflags 2.6.0",
+ "cfg-if",
+ "foreign-types",
+ "libc",
+ "once_cell",
+ "openssl-macros",
+ "openssl-sys",
+]
+
+[[package]]
+name = "openssl-macros"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.94",
+]
+
+[[package]]
 name = "openssl-probe"
 version = "0.1.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
 
 [[package]]
+name = "openssl-sys"
+version = "0.9.104"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "45abf306cbf99debc8195b66b7346498d7b10c210de50418b5ccd7ceba08c741"
+dependencies = [
+ "cc",
+ "libc",
+ "pkg-config",
+ "vcpkg",
+]
+
+[[package]]
 name = "option-ext"
 version = "0.2.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3548,18 +3672,22 @@ dependencies = [
  "async-compression",
  "base64 0.22.1",
  "bytes",
+ "encoding_rs",
  "futures-core",
  "futures-util",
+ "h2 0.4.7",
  "http 1.2.0",
  "http-body 1.0.1",
  "http-body-util",
  "hyper 1.5.2",
  "hyper-rustls 0.27.5",
+ "hyper-tls",
  "hyper-util",
  "ipnet",
  "js-sys",
  "log",
  "mime",
+ "native-tls",
  "once_cell",
  "percent-encoding",
  "pin-project-lite",
@@ -3572,7 +3700,9 @@ dependencies = [
  "serde_json",
  "serde_urlencoded",
  "sync_wrapper 1.0.2",
+ "system-configuration",
  "tokio",
+ "tokio-native-tls",
  "tokio-rustls 0.26.1",
  "tokio-socks",
  "tokio-util",
@@ -4429,6 +4559,27 @@ dependencies = [
 ]
 
 [[package]]
+name = "system-configuration"
+version = "0.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b"
+dependencies = [
+ "bitflags 2.6.0",
+ "core-foundation 0.9.4",
+ "system-configuration-sys",
+]
+
+[[package]]
+name = "system-configuration-sys"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4"
+dependencies = [
+ "core-foundation-sys",
+ "libc",
+]
+
+[[package]]
 name = "tagptr"
 version = "0.2.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -4604,6 +4755,16 @@ dependencies = [
 ]
 
 [[package]]
+name = "tokio-native-tls"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2"
+dependencies = [
+ "native-tls",
+ "tokio",
+]
+
+[[package]]
 name = "tokio-rustls"
 version = "0.23.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -4733,7 +4894,7 @@ dependencies = [
  "axum",
  "base64 0.21.7",
  "bytes",
- "h2",
+ "h2 0.3.26",
  "http 0.2.12",
  "http-body 0.4.6",
  "hyper 0.14.32",

+ 1 - 1
crates/cdk-cli/src/sub_commands/burn.rs

@@ -3,7 +3,7 @@ use std::str::FromStr;
 use anyhow::Result;
 use cdk::mint_url::MintUrl;
 use cdk::nuts::CurrencyUnit;
-use cdk::wallet::multi_mint_wallet::WalletKey;
+use cdk::wallet::types::WalletKey;
 use cdk::wallet::MultiMintWallet;
 use cdk::Amount;
 use clap::Args;

+ 2 - 1
crates/cdk-cli/src/sub_commands/melt.rs

@@ -5,7 +5,8 @@ use std::str::FromStr;
 use anyhow::{bail, Result};
 use cdk::amount::MSAT_IN_SAT;
 use cdk::nuts::{CurrencyUnit, MeltOptions};
-use cdk::wallet::multi_mint_wallet::{MultiMintWallet, WalletKey};
+use cdk::wallet::multi_mint_wallet::MultiMintWallet;
+use cdk::wallet::types::WalletKey;
 use cdk::Bolt11Invoice;
 use clap::Args;
 

+ 1 - 1
crates/cdk-cli/src/sub_commands/mint.rs

@@ -7,7 +7,7 @@ use cdk::cdk_database::{Error, WalletDatabase};
 use cdk::mint_url::MintUrl;
 use cdk::nuts::nut00::ProofsMethods;
 use cdk::nuts::{CurrencyUnit, MintQuoteState, NotificationPayload};
-use cdk::wallet::multi_mint_wallet::WalletKey;
+use cdk::wallet::types::WalletKey;
 use cdk::wallet::{MultiMintWallet, Wallet, WalletSubscription};
 use cdk::Amount;
 use clap::Args;

+ 2 - 1
crates/cdk-cli/src/sub_commands/receive.rs

@@ -6,7 +6,8 @@ use anyhow::{anyhow, Result};
 use cdk::cdk_database::{self, WalletDatabase};
 use cdk::nuts::{SecretKey, Token};
 use cdk::util::unix_time;
-use cdk::wallet::multi_mint_wallet::{MultiMintWallet, WalletKey};
+use cdk::wallet::multi_mint_wallet::MultiMintWallet;
+use cdk::wallet::types::WalletKey;
 use cdk::wallet::Wallet;
 use cdk::Amount;
 use clap::Args;

+ 1 - 1
crates/cdk-cli/src/sub_commands/restore.rs

@@ -5,7 +5,7 @@ use anyhow::Result;
 use cdk::cdk_database::{Error, WalletDatabase};
 use cdk::mint_url::MintUrl;
 use cdk::nuts::CurrencyUnit;
-use cdk::wallet::multi_mint_wallet::WalletKey;
+use cdk::wallet::types::WalletKey;
 use cdk::wallet::{MultiMintWallet, Wallet};
 use clap::Args;
 

+ 1 - 2
crates/cdk-cli/src/sub_commands/send.rs

@@ -5,8 +5,7 @@ use std::str::FromStr;
 use anyhow::{bail, Result};
 use cdk::amount::SplitTarget;
 use cdk::nuts::{Conditions, CurrencyUnit, PublicKey, SpendingConditions};
-use cdk::wallet::multi_mint_wallet::WalletKey;
-use cdk::wallet::types::SendKind;
+use cdk::wallet::types::{SendKind, WalletKey};
 use cdk::wallet::MultiMintWallet;
 use cdk::Amount;
 use clap::Args;

+ 1 - 1
crates/cdk-cli/src/sub_commands/update_mint_url.rs

@@ -1,7 +1,7 @@
 use anyhow::{anyhow, Result};
 use cdk::mint_url::MintUrl;
 use cdk::nuts::CurrencyUnit;
-use cdk::wallet::multi_mint_wallet::WalletKey;
+use cdk::wallet::types::WalletKey;
 use cdk::wallet::MultiMintWallet;
 use clap::Args;
 

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

@@ -31,6 +31,9 @@ tracing = "0.1.41"
 url = "2.3"
 uuid = { version = "1", features = ["v4", "serde"] }
 utoipa = { version = "4", optional = true }
+futures = "0.3.31"
+anyhow = "1.0.95"
+reqwest = "0.12.11"
 
 [dev-dependencies]
 rand = "0.8.5"

+ 0 - 0
crates/cdk/src/types.rs → crates/cdk-common/src/common.rs


+ 262 - 0
crates/cdk-common/src/database.rs

@@ -0,0 +1,262 @@
+//! CDK Database
+
+use std::collections::HashMap;
+use std::fmt::Debug;
+
+use async_trait::async_trait;
+use thiserror::Error;
+use uuid::Uuid;
+
+use crate::common::{LnKey, ProofInfo};
+use crate::mint::{self, MintKeySetInfo, MintQuote as MintMintQuote};
+use crate::mint_url::MintUrl;
+use crate::nuts::{
+    BlindSignature, CurrencyUnit, Id, KeySetInfo, Keys, MeltBolt11Request, MeltQuoteState,
+    MintInfo, MintQuoteState, Proof, Proofs, PublicKey, SpendingConditions, State,
+};
+use crate::wallet;
+use crate::wallet::MintQuote as WalletMintQuote;
+
+/// CDK_database error
+#[derive(Debug, Error)]
+pub enum Error {
+    /// Database Error
+    #[error(transparent)]
+    Database(Box<dyn std::error::Error + Send + Sync>),
+    /// DHKE error
+    #[error(transparent)]
+    DHKE(#[from] crate::dhke::Error),
+    /// NUT00 Error
+    #[error(transparent)]
+    NUT00(#[from] crate::nuts::nut00::Error),
+    /// NUT02 Error
+    #[error(transparent)]
+    NUT02(#[from] crate::nuts::nut02::Error),
+    /// Serde Error
+    #[error(transparent)]
+    Serde(#[from] serde_json::Error),
+    /// Unknown Quote
+    #[error("Unknown Quote")]
+    UnknownQuote,
+}
+
+/// Wallet Database trait
+#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
+#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
+pub trait WalletDatabase: Debug {
+    /// Wallet Database Error
+    type Err: Into<Error> + From<Error>;
+
+    /// Add Mint to storage
+    async fn add_mint(
+        &self,
+        mint_url: MintUrl,
+        mint_info: Option<MintInfo>,
+    ) -> Result<(), Self::Err>;
+    /// Remove Mint from storage
+    async fn remove_mint(&self, mint_url: MintUrl) -> Result<(), Self::Err>;
+    /// Get mint from storage
+    async fn get_mint(&self, mint_url: MintUrl) -> Result<Option<MintInfo>, Self::Err>;
+    /// Get all mints from storage
+    async fn get_mints(&self) -> Result<HashMap<MintUrl, Option<MintInfo>>, Self::Err>;
+    /// Update mint url
+    async fn update_mint_url(
+        &self,
+        old_mint_url: MintUrl,
+        new_mint_url: MintUrl,
+    ) -> Result<(), Self::Err>;
+
+    /// Add mint keyset to storage
+    async fn add_mint_keysets(
+        &self,
+        mint_url: MintUrl,
+        keysets: Vec<KeySetInfo>,
+    ) -> Result<(), Self::Err>;
+    /// Get mint keysets for mint url
+    async fn get_mint_keysets(
+        &self,
+        mint_url: MintUrl,
+    ) -> Result<Option<Vec<KeySetInfo>>, Self::Err>;
+    /// Get mint keyset by id
+    async fn get_keyset_by_id(&self, keyset_id: &Id) -> Result<Option<KeySetInfo>, Self::Err>;
+
+    /// Add mint quote to storage
+    async fn add_mint_quote(&self, quote: WalletMintQuote) -> Result<(), Self::Err>;
+    /// Get mint quote from storage
+    async fn get_mint_quote(&self, quote_id: &str) -> Result<Option<WalletMintQuote>, Self::Err>;
+    /// Get mint quotes from storage
+    async fn get_mint_quotes(&self) -> Result<Vec<WalletMintQuote>, Self::Err>;
+    /// Remove mint quote from storage
+    async fn remove_mint_quote(&self, quote_id: &str) -> Result<(), Self::Err>;
+
+    /// Add melt quote to storage
+    async fn add_melt_quote(&self, quote: wallet::MeltQuote) -> Result<(), Self::Err>;
+    /// Get melt quote from storage
+    async fn get_melt_quote(&self, quote_id: &str) -> Result<Option<wallet::MeltQuote>, Self::Err>;
+    /// Remove melt quote from storage
+    async fn remove_melt_quote(&self, quote_id: &str) -> Result<(), Self::Err>;
+
+    /// Add [`Keys`] to storage
+    async fn add_keys(&self, keys: Keys) -> Result<(), Self::Err>;
+    /// Get [`Keys`] from storage
+    async fn get_keys(&self, id: &Id) -> Result<Option<Keys>, Self::Err>;
+    /// 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.
+    async fn update_proofs(
+        &self,
+        added: Vec<ProofInfo>,
+        removed_ys: Vec<PublicKey>,
+    ) -> Result<(), Self::Err>;
+    /// Set proofs as pending in storage. Proofs are identified by their Y
+    /// value.
+    async fn set_pending_proofs(&self, ys: Vec<PublicKey>) -> Result<(), Self::Err>;
+    /// Reserve proofs in storage. Proofs are identified by their Y value.
+    async fn reserve_proofs(&self, ys: Vec<PublicKey>) -> Result<(), Self::Err>;
+    /// Set proofs as unspent in storage. Proofs are identified by their Y
+    /// value.
+    async fn set_unspent_proofs(&self, ys: Vec<PublicKey>) -> Result<(), Self::Err>;
+    /// Get proofs from storage
+    async fn get_proofs(
+        &self,
+        mint_url: Option<MintUrl>,
+        unit: Option<CurrencyUnit>,
+        state: Option<Vec<State>>,
+        spending_conditions: Option<Vec<SpendingConditions>>,
+    ) -> Result<Vec<ProofInfo>, Self::Err>;
+
+    /// Increment Keyset counter
+    async fn increment_keyset_counter(&self, keyset_id: &Id, count: u32) -> Result<(), Self::Err>;
+    /// Get current Keyset counter
+    async fn get_keyset_counter(&self, keyset_id: &Id) -> Result<Option<u32>, Self::Err>;
+
+    /// Get when nostr key was last checked
+    async fn get_nostr_last_checked(
+        &self,
+        verifying_key: &PublicKey,
+    ) -> Result<Option<u32>, Self::Err>;
+    /// Update last checked time
+    async fn add_nostr_last_checked(
+        &self,
+        verifying_key: PublicKey,
+        last_checked: u32,
+    ) -> Result<(), Self::Err>;
+}
+
+/// Mint Database trait
+#[async_trait]
+pub trait MintDatabase {
+    /// Mint Database Error
+    type Err: Into<Error> + From<Error>;
+
+    /// Add Active Keyset
+    async fn set_active_keyset(&self, unit: CurrencyUnit, id: Id) -> Result<(), Self::Err>;
+    /// Get Active Keyset
+    async fn get_active_keyset_id(&self, unit: &CurrencyUnit) -> Result<Option<Id>, Self::Err>;
+    /// Get all Active Keyset
+    async fn get_active_keysets(&self) -> Result<HashMap<CurrencyUnit, Id>, Self::Err>;
+
+    /// Add [`MintMintQuote`]
+    async fn add_mint_quote(&self, quote: MintMintQuote) -> Result<(), Self::Err>;
+    /// Get [`MintMintQuote`]
+    async fn get_mint_quote(&self, quote_id: &Uuid) -> Result<Option<MintMintQuote>, Self::Err>;
+    /// Update state of [`MintMintQuote`]
+    async fn update_mint_quote_state(
+        &self,
+        quote_id: &Uuid,
+        state: MintQuoteState,
+    ) -> Result<MintQuoteState, Self::Err>;
+    /// Get all [`MintMintQuote`]s
+    async fn get_mint_quote_by_request(
+        &self,
+        request: &str,
+    ) -> Result<Option<MintMintQuote>, Self::Err>;
+    /// Get all [`MintMintQuote`]s
+    async fn get_mint_quote_by_request_lookup_id(
+        &self,
+        request_lookup_id: &str,
+    ) -> Result<Option<MintMintQuote>, Self::Err>;
+    /// Get Mint Quotes
+    async fn get_mint_quotes(&self) -> Result<Vec<MintMintQuote>, Self::Err>;
+    /// Remove [`MintMintQuote`]
+    async fn remove_mint_quote(&self, quote_id: &Uuid) -> Result<(), Self::Err>;
+
+    /// Add [`mint::MeltQuote`]
+    async fn add_melt_quote(&self, quote: mint::MeltQuote) -> Result<(), Self::Err>;
+    /// Get [`mint::MeltQuote`]
+    async fn get_melt_quote(&self, quote_id: &Uuid) -> Result<Option<mint::MeltQuote>, Self::Err>;
+    /// Update [`mint::MeltQuote`] state
+    async fn update_melt_quote_state(
+        &self,
+        quote_id: &Uuid,
+        state: MeltQuoteState,
+    ) -> Result<MeltQuoteState, Self::Err>;
+    /// Get all [`mint::MeltQuote`]s
+    async fn get_melt_quotes(&self) -> Result<Vec<mint::MeltQuote>, Self::Err>;
+    /// Remove [`mint::MeltQuote`]
+    async fn remove_melt_quote(&self, quote_id: &Uuid) -> Result<(), Self::Err>;
+
+    /// Add melt request
+    async fn add_melt_request(
+        &self,
+        melt_request: MeltBolt11Request<Uuid>,
+        ln_key: LnKey,
+    ) -> Result<(), Self::Err>;
+    /// Get melt request
+    async fn get_melt_request(
+        &self,
+        quote_id: &Uuid,
+    ) -> Result<Option<(MeltBolt11Request<Uuid>, LnKey)>, Self::Err>;
+
+    /// Add [`MintKeySetInfo`]
+    async fn add_keyset_info(&self, keyset: MintKeySetInfo) -> Result<(), Self::Err>;
+    /// Get [`MintKeySetInfo`]
+    async fn get_keyset_info(&self, id: &Id) -> Result<Option<MintKeySetInfo>, Self::Err>;
+    /// Get [`MintKeySetInfo`]s
+    async fn get_keyset_infos(&self) -> Result<Vec<MintKeySetInfo>, Self::Err>;
+
+    /// Add spent [`Proofs`]
+    async fn add_proofs(&self, proof: Proofs, quote_id: Option<Uuid>) -> Result<(), Self::Err>;
+    /// Get [`Proofs`] by ys
+    async fn get_proofs_by_ys(&self, ys: &[PublicKey]) -> Result<Vec<Option<Proof>>, Self::Err>;
+    /// Get ys by quote id
+    async fn get_proof_ys_by_quote_id(&self, quote_id: &Uuid) -> Result<Vec<PublicKey>, Self::Err>;
+    /// Get [`Proofs`] state
+    async fn get_proofs_states(&self, ys: &[PublicKey]) -> Result<Vec<Option<State>>, Self::Err>;
+    /// Get [`Proofs`] state
+    async fn update_proofs_states(
+        &self,
+        ys: &[PublicKey],
+        proofs_state: State,
+    ) -> Result<Vec<Option<State>>, Self::Err>;
+    /// Get [`Proofs`] by state
+    async fn get_proofs_by_keyset_id(
+        &self,
+        keyset_id: &Id,
+    ) -> Result<(Proofs, Vec<Option<State>>), Self::Err>;
+
+    /// Add [`BlindSignature`]
+    async fn add_blind_signatures(
+        &self,
+        blinded_messages: &[PublicKey],
+        blind_signatures: &[BlindSignature],
+        quote_id: Option<Uuid>,
+    ) -> Result<(), Self::Err>;
+    /// Get [`BlindSignature`]s
+    async fn get_blind_signatures(
+        &self,
+        blinded_messages: &[PublicKey],
+    ) -> Result<Vec<Option<BlindSignature>>, Self::Err>;
+    /// Get [`BlindSignature`]s for keyset_id
+    async fn get_blind_signatures_for_keyset(
+        &self,
+        keyset_id: &Id,
+    ) -> Result<Vec<BlindSignature>, Self::Err>;
+    /// Get [`BlindSignature`]s for quote
+    async fn get_blind_signatures_for_quote(
+        &self,
+        quote_id: &Uuid,
+    ) -> Result<Vec<BlindSignature>, Self::Err>;
+}

+ 3 - 8
crates/cdk/src/error.rs → crates/cdk-common/src/error.rs

@@ -8,8 +8,7 @@ use thiserror::Error;
 
 use crate::nuts::Id;
 use crate::util::hex;
-#[cfg(feature = "wallet")]
-use crate::wallet::multi_mint_wallet::WalletKey;
+use crate::wallet::WalletKey;
 use crate::Amount;
 
 /// CDK Error
@@ -128,7 +127,6 @@ pub enum Error {
     #[error("Incorrect wallet: `{0}`")]
     IncorrectWallet(String),
     /// Unknown Wallet
-    #[cfg(feature = "wallet")]
     #[error("Unknown wallet: `{0}`")]
     UnknownWallet(WalletKey),
     /// Max Fee Ecxeded
@@ -197,7 +195,6 @@ pub enum Error {
     /// From hex error
     #[error(transparent)]
     HexError(#[from] hex::Error),
-    #[cfg(feature = "wallet")]
     /// From hex error
     #[error(transparent)]
     ReqwestError(#[from] reqwest::Error),
@@ -249,13 +246,11 @@ pub enum Error {
     #[error(transparent)]
     NUT20(#[from] crate::nuts::nut20::Error),
     /// Database Error
-    #[cfg(any(feature = "wallet", feature = "mint"))]
     #[error(transparent)]
-    Database(#[from] crate::cdk_database::Error),
+    Database(#[from] crate::database::Error),
     /// Lightning Error
-    #[cfg(feature = "mint")]
     #[error(transparent)]
-    Lightning(#[from] crate::cdk_lightning::Error),
+    Lightning(#[from] crate::lightning::Error),
 }
 
 /// CDK Error Response

+ 6 - 1
crates/cdk-common/src/lib.rs

@@ -7,7 +7,11 @@
 //! internal crates.
 
 pub mod amount;
+pub mod common;
+pub mod database;
 pub mod dhke;
+pub mod error;
+pub mod lightning;
 pub mod mint;
 pub mod mint_url;
 pub mod nuts;
@@ -15,10 +19,11 @@ pub mod pub_sub;
 pub mod secret;
 pub mod signatory;
 pub mod util;
+pub mod wallet;
 
 // re-exporting external crates
-pub use bitcoin;
 pub use lightning_invoice::{self, Bolt11Invoice};
+pub use {bitcoin, reqwest};
 
 pub use self::amount::Amount;
 pub use self::nuts::*;

+ 0 - 0
crates/cdk/src/cdk_lightning/mod.rs → crates/cdk-common/src/lightning.rs


+ 44 - 1
crates/cdk-common/src/mint.rs

@@ -1,11 +1,12 @@
 //! Mint types
 
+use bitcoin::bip32::DerivationPath;
 use serde::{Deserialize, Serialize};
 use uuid::Uuid;
 
 use crate::mint_url::MintUrl;
 use crate::nuts::{MeltQuoteState, MintQuoteState};
-use crate::{Amount, CurrencyUnit, PublicKey};
+use crate::{Amount, CurrencyUnit, Id, KeySetInfo, PublicKey};
 
 /// Mint Quote Info
 #[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
@@ -111,3 +112,45 @@ impl MeltQuote {
         }
     }
 }
+
+/// Mint Keyset Info
+#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
+pub struct MintKeySetInfo {
+    /// Keyset [`Id`]
+    pub id: Id,
+    /// Keyset [`CurrencyUnit`]
+    pub unit: CurrencyUnit,
+    /// Keyset active or inactive
+    /// Mint will only issue new [`BlindSignature`] on active keysets
+    pub active: bool,
+    /// Starting unix time Keyset is valid from
+    pub valid_from: u64,
+    /// When the Keyset is valid to
+    /// This is not shown to the wallet and can only be used internally
+    pub valid_to: Option<u64>,
+    /// [`DerivationPath`] keyset
+    pub derivation_path: DerivationPath,
+    /// DerivationPath index of Keyset
+    pub derivation_path_index: Option<u32>,
+    /// Max order of keyset
+    pub max_order: u8,
+    /// Input Fee ppk
+    #[serde(default = "default_fee")]
+    pub input_fee_ppk: u64,
+}
+
+/// Default fee
+pub fn default_fee() -> u64 {
+    0
+}
+
+impl From<MintKeySetInfo> for KeySetInfo {
+    fn from(keyset_info: MintKeySetInfo) -> Self {
+        Self {
+            id: keyset_info.id,
+            unit: keyset_info.unit,
+            active: keyset_info.active,
+            input_fee_ppk: keyset_info.input_fee_ppk,
+        }
+    }
+}

+ 24 - 0
crates/cdk/src/wallet/types.rs → crates/cdk-common/src/wallet.rs

@@ -1,11 +1,35 @@
 //! Wallet Types
 
+use std::fmt;
+
 use serde::{Deserialize, Serialize};
 
 use crate::mint_url::MintUrl;
 use crate::nuts::{CurrencyUnit, MeltQuoteState, MintQuoteState, SecretKey};
 use crate::Amount;
 
+/// Wallet Key
+#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
+pub struct WalletKey {
+    /// Mint Url
+    pub mint_url: MintUrl,
+    /// Currency Unit
+    pub unit: CurrencyUnit,
+}
+
+impl fmt::Display for WalletKey {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        write!(f, "mint_url: {}, unit: {}", self.mint_url, self.unit,)
+    }
+}
+
+impl WalletKey {
+    /// Create new [`WalletKey`]
+    pub fn new(mint_url: MintUrl, unit: CurrencyUnit) -> Self {
+        Self { mint_url, unit }
+    }
+}
+
 /// Mint Quote Info
 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
 pub struct MintQuote {

+ 8 - 5
crates/cdk-redb/Cargo.toml

@@ -7,20 +7,23 @@ description = "Redb storage backend for CDK"
 license = "MIT"
 homepage = "https://github.com/cashubtc/cdk"
 repository = "https://github.com/cashubtc/cdk.git"
-rust-version = "1.66.0" # MSRV
+rust-version = "1.66.0"                            # MSRV
 
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 [features]
 default = ["mint", "wallet"]
-mint = ["cdk/mint"]
-wallet = ["cdk/wallet"]
+mint = []
+wallet = []
 
 [dependencies]
 async-trait = "0.1"
-cdk = { path = "../cdk", version = "0.6.0", default-features = false }
+cdk-common = { path = "../cdk-common", version = "0.6.0" }
 redb = "2.1.0"
 thiserror = "1"
-tracing = { version = "0.1", default-features = false, features = ["attributes", "log"] }
+tracing = { version = "0.1", default-features = false, features = [
+    "attributes",
+    "log",
+] }
 serde = { version = "1", default-features = false, features = ["derive"] }
 serde_json = "1"
 lightning-invoice = { version = "0.32.0", features = ["serde", "std"] }

+ 7 - 7
crates/cdk-redb/src/error.rs

@@ -33,22 +33,22 @@ pub enum Error {
     ParseInt(#[from] ParseIntError),
     /// CDK Database Error
     #[error(transparent)]
-    CDKDatabase(#[from] cdk::cdk_database::Error),
+    CDKDatabase(#[from] cdk_common::database::Error),
     /// CDK Mint Url Error
     #[error(transparent)]
-    CDKMintUrl(#[from] cdk::mint_url::Error),
+    CDKMintUrl(#[from] cdk_common::mint_url::Error),
     /// CDK Error
     #[error(transparent)]
-    CDK(#[from] cdk::error::Error),
+    CDK(#[from] cdk_common::error::Error),
     /// NUT00 Error
     #[error(transparent)]
-    CDKNUT00(#[from] cdk::nuts::nut00::Error),
+    CDKNUT00(#[from] cdk_common::nuts::nut00::Error),
     /// NUT02 Error
     #[error(transparent)]
-    CDKNUT02(#[from] cdk::nuts::nut02::Error),
+    CDKNUT02(#[from] cdk_common::nuts::nut02::Error),
     /// DHKE Error
     #[error(transparent)]
-    DHKE(#[from] cdk::dhke::Error),
+    DHKE(#[from] cdk_common::dhke::Error),
     /// Unknown Mint Info
     #[error("Unknown mint info")]
     UnknownMintInfo,
@@ -60,7 +60,7 @@ pub enum Error {
     UnknownDatabaseVersion,
 }
 
-impl From<Error> for cdk::cdk_database::Error {
+impl From<Error> for cdk_common::database::Error {
     fn from(e: Error) -> Self {
         Self::Database(Box::new(e))
     }

+ 2 - 3
crates/cdk-redb/src/migrations.rs

@@ -1,9 +1,8 @@
 use std::collections::HashMap;
 use std::sync::Arc;
 
-use cdk::mint_url::MintUrl;
-use cdk::nuts::{CurrencyUnit, MeltQuoteState, MintQuoteState};
-use cdk::Amount;
+use cdk_common::mint_url::MintUrl;
+use cdk_common::{Amount, CurrencyUnit, MeltQuoteState, MintQuoteState};
 use redb::{Database, ReadableTable, TableDefinition};
 use serde::{Deserialize, Serialize};
 

+ 3 - 4
crates/cdk-redb/src/mint/migrations.rs

@@ -3,10 +3,9 @@ use std::collections::HashMap;
 use std::str::FromStr;
 use std::sync::Arc;
 
-use cdk::mint::MintQuote;
-use cdk::mint_url::MintUrl;
-use cdk::nuts::{CurrencyUnit, MintQuoteState, Proof, State};
-use cdk::Amount;
+use cdk_common::mint::MintQuote;
+use cdk_common::mint_url::MintUrl;
+use cdk_common::{Amount, CurrencyUnit, MintQuoteState, Proof, State};
 use lightning_invoice::Bolt11Invoice;
 use redb::{
     Database, MultimapTableDefinition, ReadableMultimapTable, ReadableTable, TableDefinition,

+ 7 - 8
crates/cdk-redb/src/mint/mod.rs

@@ -7,16 +7,15 @@ use std::str::FromStr;
 use std::sync::Arc;
 
 use async_trait::async_trait;
-use cdk::cdk_database::MintDatabase;
-use cdk::dhke::hash_to_curve;
-use cdk::mint::{MintKeySetInfo, MintQuote};
-use cdk::nuts::nut00::ProofsMethods;
-use cdk::nuts::{
+use cdk_common::common::LnKey;
+use cdk_common::database::{self, MintDatabase};
+use cdk_common::dhke::hash_to_curve;
+use cdk_common::mint::{self, MintKeySetInfo, MintQuote};
+use cdk_common::nut00::ProofsMethods;
+use cdk_common::{
     BlindSignature, CurrencyUnit, Id, MeltBolt11Request, MeltQuoteState, MintQuoteState, Proof,
     Proofs, PublicKey, State,
 };
-use cdk::types::LnKey;
-use cdk::{cdk_database, mint};
 use migrations::{migrate_01_to_02, migrate_04_to_05};
 use redb::{Database, MultimapTableDefinition, ReadableTable, TableDefinition};
 use uuid::Uuid;
@@ -162,7 +161,7 @@ impl MintRedbDatabase {
 
 #[async_trait]
 impl MintDatabase for MintRedbDatabase {
-    type Err = cdk_database::Error;
+    type Err = database::Error;
 
     async fn set_active_keyset(&self, unit: CurrencyUnit, id: Id) -> Result<(), Self::Err> {
         let write_txn = self.db.begin_write().map_err(Error::from)?;

+ 1 - 1
crates/cdk-redb/src/wallet/migrations.rs

@@ -3,7 +3,7 @@ use std::ops::Deref;
 use std::str::FromStr;
 use std::sync::Arc;
 
-use cdk::mint_url::MintUrl;
+use cdk_common::mint_url::MintUrl;
 use redb::{
     Database, MultimapTableDefinition, ReadableMultimapTable, ReadableTable, TableDefinition,
 };

+ 9 - 10
crates/cdk-redb/src/wallet/mod.rs

@@ -7,15 +7,14 @@ use std::str::FromStr;
 use std::sync::Arc;
 
 use async_trait::async_trait;
-use cdk::cdk_database::WalletDatabase;
-use cdk::mint_url::MintUrl;
-use cdk::nuts::{
-    CurrencyUnit, Id, KeySetInfo, Keys, MintInfo, PublicKey, SpendingConditions, State,
+use cdk_common::common::ProofInfo;
+use cdk_common::database::WalletDatabase;
+use cdk_common::mint_url::MintUrl;
+use cdk_common::util::unix_time;
+use cdk_common::wallet::{self, MintQuote};
+use cdk_common::{
+    database, CurrencyUnit, Id, KeySetInfo, Keys, MintInfo, PublicKey, SpendingConditions, State,
 };
-use cdk::types::ProofInfo;
-use cdk::util::unix_time;
-use cdk::wallet::MintQuote;
-use cdk::{cdk_database, wallet};
 use redb::{Database, MultimapTableDefinition, ReadableTable, TableDefinition};
 use tracing::instrument;
 
@@ -153,7 +152,7 @@ impl WalletRedbDatabase {
         &self,
         ys: Vec<PublicKey>,
         state: State,
-    ) -> Result<(), cdk_database::Error> {
+    ) -> Result<(), database::Error> {
         let read_txn = self.db.begin_read().map_err(Error::from)?;
         let table = read_txn.open_table(PROOFS_TABLE).map_err(Error::from)?;
 
@@ -192,7 +191,7 @@ impl WalletRedbDatabase {
 
 #[async_trait]
 impl WalletDatabase for WalletRedbDatabase {
-    type Err = cdk_database::Error;
+    type Err = database::Error;
 
     #[instrument(skip(self))]
     async fn add_mint(

+ 15 - 10
crates/cdk-sqlite/Cargo.toml

@@ -7,26 +7,31 @@ description = "SQLite storage backend for CDK"
 license = "MIT"
 homepage = "https://github.com/cashubtc/cdk"
 repository = "https://github.com/cashubtc/cdk.git"
-rust-version = "1.66.0" # MSRV
+rust-version = "1.66.0"                            # MSRV
 
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 [features]
 default = ["mint", "wallet"]
-mint = ["cdk/mint"]
-wallet = ["cdk/wallet"]
+mint = []
+wallet = []
 
 [dependencies]
 async-trait = "0.1"
-cdk = { path = "../cdk", version = "0.6.0", default-features = false }
+cdk-common = { path = "../cdk-common", version = "0.6.0" }
 bitcoin = { version = "0.32.2", default-features = false }
-sqlx = { version = "0.6.3", default-features = false, features = ["runtime-tokio-rustls", "sqlite", "macros", "migrate", "uuid"] }
-thiserror = "1"
-tokio = { version = "1", features = [
-    "time",
+sqlx = { version = "0.6.3", default-features = false, features = [
+    "runtime-tokio-rustls",
+    "sqlite",
     "macros",
-    "sync",
+    "migrate",
+    "uuid",
+] }
+thiserror = "1"
+tokio = { version = "1", features = ["time", "macros", "sync"] }
+tracing = { version = "0.1", default-features = false, features = [
+    "attributes",
+    "log",
 ] }
-tracing = { version = "0.1", default-features = false, features = ["attributes", "log"] }
 serde_json = "1"
 lightning-invoice = { version = "0.32.0", features = ["serde", "std"] }
 uuid = { version = "1", features = ["v4", "serde"] }

+ 9 - 9
crates/cdk-sqlite/src/mint/error.rs

@@ -10,31 +10,31 @@ pub enum Error {
     SQLX(#[from] sqlx::Error),
     /// NUT00 Error
     #[error(transparent)]
-    CDKNUT00(#[from] cdk::nuts::nut00::Error),
+    CDKNUT00(#[from] cdk_common::nuts::nut00::Error),
     /// NUT01 Error
     #[error(transparent)]
-    CDKNUT01(#[from] cdk::nuts::nut01::Error),
+    CDKNUT01(#[from] cdk_common::nuts::nut01::Error),
     /// NUT02 Error
     #[error(transparent)]
-    CDKNUT02(#[from] cdk::nuts::nut02::Error),
+    CDKNUT02(#[from] cdk_common::nuts::nut02::Error),
     /// NUT04 Error
     #[error(transparent)]
-    CDKNUT04(#[from] cdk::nuts::nut04::Error),
+    CDKNUT04(#[from] cdk_common::nuts::nut04::Error),
     /// NUT05 Error
     #[error(transparent)]
-    CDKNUT05(#[from] cdk::nuts::nut05::Error),
+    CDKNUT05(#[from] cdk_common::nuts::nut05::Error),
     /// NUT07 Error
     #[error(transparent)]
-    CDKNUT07(#[from] cdk::nuts::nut07::Error),
+    CDKNUT07(#[from] cdk_common::nuts::nut07::Error),
     /// Secret Error
     #[error(transparent)]
-    CDKSECRET(#[from] cdk::secret::Error),
+    CDKSECRET(#[from] cdk_common::secret::Error),
     /// BIP32 Error
     #[error(transparent)]
     BIP32(#[from] bitcoin::bip32::Error),
     /// Mint Url Error
     #[error(transparent)]
-    MintUrl(#[from] cdk::mint_url::Error),
+    MintUrl(#[from] cdk_common::mint_url::Error),
     /// Could Not Initialize Database
     #[error("Could not initialize database")]
     CouldNotInitialize,
@@ -46,7 +46,7 @@ pub enum Error {
     Serde(#[from] serde_json::Error),
 }
 
-impl From<Error> for cdk::cdk_database::Error {
+impl From<Error> for cdk_common::database::Error {
     fn from(e: Error) -> Self {
         Self::Database(Box::new(e))
     }

+ 11 - 12
crates/cdk-sqlite/src/mint/mod.rs

@@ -7,18 +7,17 @@ use std::time::Duration;
 
 use async_trait::async_trait;
 use bitcoin::bip32::DerivationPath;
-use cdk::cdk_database::{self, MintDatabase};
-use cdk::mint::{MintKeySetInfo, MintQuote};
-use cdk::mint_url::MintUrl;
-use cdk::nuts::nut00::ProofsMethods;
-use cdk::nuts::nut05::QuoteState;
-use cdk::nuts::{
-    BlindSignature, BlindSignatureDleq, CurrencyUnit, Id, MeltBolt11Request, MeltQuoteState,
-    MintQuoteState, PaymentMethod, Proof, Proofs, PublicKey, SecretKey, State,
+use cdk_common::common::LnKey;
+use cdk_common::database::{self, MintDatabase};
+use cdk_common::mint::{self, MintKeySetInfo, MintQuote};
+use cdk_common::mint_url::MintUrl;
+use cdk_common::nut00::ProofsMethods;
+use cdk_common::nut05::QuoteState;
+use cdk_common::secret::Secret;
+use cdk_common::{
+    Amount, BlindSignature, BlindSignatureDleq, CurrencyUnit, Id, MeltBolt11Request,
+    MeltQuoteState, MintQuoteState, PaymentMethod, Proof, Proofs, PublicKey, SecretKey, State,
 };
-use cdk::secret::Secret;
-use cdk::types::LnKey;
-use cdk::{mint, Amount};
 use error::Error;
 use lightning_invoice::Bolt11Invoice;
 use sqlx::sqlite::{SqliteConnectOptions, SqlitePool, SqlitePoolOptions, SqliteRow};
@@ -63,7 +62,7 @@ impl MintSqliteDatabase {
 
 #[async_trait]
 impl MintDatabase for MintSqliteDatabase {
-    type Err = cdk_database::Error;
+    type Err = database::Error;
 
     async fn set_active_keyset(&self, unit: CurrencyUnit, id: Id) -> Result<(), Self::Err> {
         let mut transaction = self.pool.begin().await.map_err(Error::from)?;

+ 9 - 9
crates/cdk-sqlite/src/wallet/error.rs

@@ -13,28 +13,28 @@ pub enum Error {
     Serde(#[from] serde_json::Error),
     /// NUT00 Error
     #[error(transparent)]
-    CDKNUT00(#[from] cdk::nuts::nut00::Error),
+    CDKNUT00(#[from] cdk_common::nuts::nut00::Error),
     /// NUT01 Error
     #[error(transparent)]
-    CDKNUT01(#[from] cdk::nuts::nut01::Error),
+    CDKNUT01(#[from] cdk_common::nuts::nut01::Error),
     /// NUT02 Error
     #[error(transparent)]
-    CDKNUT02(#[from] cdk::nuts::nut02::Error),
+    CDKNUT02(#[from] cdk_common::nuts::nut02::Error),
     /// NUT04 Error
     #[error(transparent)]
-    CDKNUT04(#[from] cdk::nuts::nut04::Error),
+    CDKNUT04(#[from] cdk_common::nuts::nut04::Error),
     /// NUT05 Error
     #[error(transparent)]
-    CDKNUT05(#[from] cdk::nuts::nut05::Error),
+    CDKNUT05(#[from] cdk_common::nuts::nut05::Error),
     /// NUT07 Error
     #[error(transparent)]
-    CDKNUT07(#[from] cdk::nuts::nut07::Error),
+    CDKNUT07(#[from] cdk_common::nuts::nut07::Error),
     /// Secret Error
     #[error(transparent)]
-    CDKSECRET(#[from] cdk::secret::Error),
+    CDKSECRET(#[from] cdk_common::secret::Error),
     /// Mint Url
     #[error(transparent)]
-    MintUrl(#[from] cdk::mint_url::Error),
+    MintUrl(#[from] cdk_common::mint_url::Error),
     /// BIP32 Error
     #[error(transparent)]
     BIP32(#[from] bitcoin::bip32::Error),
@@ -46,7 +46,7 @@ pub enum Error {
     InvalidDbPath,
 }
 
-impl From<Error> for cdk::cdk_database::Error {
+impl From<Error> for cdk_common::database::Error {
     fn from(e: Error) -> Self {
         Self::Database(Box::new(e))
     }

+ 11 - 12
crates/cdk-sqlite/src/wallet/mod.rs

@@ -5,17 +5,16 @@ use std::path::Path;
 use std::str::FromStr;
 
 use async_trait::async_trait;
-use cdk::amount::Amount;
-use cdk::cdk_database::{self, WalletDatabase};
-use cdk::mint_url::MintUrl;
-use cdk::nuts::{
-    CurrencyUnit, Id, KeySetInfo, Keys, MeltQuoteState, MintInfo, MintQuoteState, Proof, PublicKey,
-    SecretKey, SpendingConditions, State,
+use cdk_common::common::ProofInfo;
+use cdk_common::database::WalletDatabase;
+use cdk_common::mint_url::MintUrl;
+use cdk_common::nuts::{MeltQuoteState, MintQuoteState};
+use cdk_common::secret::Secret;
+use cdk_common::wallet::{self, MintQuote};
+use cdk_common::{
+    database, Amount, CurrencyUnit, Id, KeySetInfo, Keys, MintInfo, Proof, PublicKey, SecretKey,
+    SpendingConditions, State,
 };
-use cdk::secret::Secret;
-use cdk::types::ProofInfo;
-use cdk::wallet;
-use cdk::wallet::MintQuote;
 use error::Error;
 use sqlx::sqlite::{SqliteConnectOptions, SqlitePool, SqliteRow};
 use sqlx::{ConnectOptions, Row};
@@ -54,7 +53,7 @@ impl WalletSqliteDatabase {
             .expect("Could not run migrations");
     }
 
-    async fn set_proof_state(&self, y: PublicKey, state: State) -> Result<(), cdk_database::Error> {
+    async fn set_proof_state(&self, y: PublicKey, state: State) -> Result<(), database::Error> {
         sqlx::query(
             r#"
     UPDATE proof
@@ -74,7 +73,7 @@ impl WalletSqliteDatabase {
 
 #[async_trait]
 impl WalletDatabase for WalletSqliteDatabase {
-    type Err = cdk_database::Error;
+    type Err = database::Error;
 
     #[instrument(skip(self, mint_info))]
     async fn add_mint(

+ 3 - 2
crates/cdk/src/cdk_database/mint_memory.rs

@@ -4,13 +4,14 @@ use std::collections::HashMap;
 use std::sync::Arc;
 
 use async_trait::async_trait;
+use cdk_common::database::{Error, MintDatabase};
+use cdk_common::mint::MintKeySetInfo;
 use cdk_common::nut00::ProofsMethods;
 use tokio::sync::{Mutex, RwLock};
 use uuid::Uuid;
 
-use super::{Error, MintDatabase};
 use crate::dhke::hash_to_curve;
-use crate::mint::{self, MintKeySetInfo, MintQuote};
+use crate::mint::{self, MintQuote};
 use crate::nuts::nut07::State;
 use crate::nuts::{
     nut07, BlindSignature, CurrencyUnit, Id, MeltBolt11Request, MeltQuoteState, MintQuoteState,

+ 2 - 281
crates/cdk/src/cdk_database/mod.rs

@@ -1,290 +1,11 @@
 //! CDK Database
 
-#[cfg(any(feature = "wallet", feature = "mint"))]
-use std::collections::HashMap;
-use std::fmt::Debug;
-
-#[cfg(any(feature = "wallet", feature = "mint"))]
-use async_trait::async_trait;
-use thiserror::Error;
-#[cfg(feature = "mint")]
-use uuid::Uuid;
-
-#[cfg(feature = "mint")]
-use crate::mint;
-#[cfg(feature = "mint")]
-use crate::mint::MintKeySetInfo;
-#[cfg(feature = "mint")]
-use crate::mint::MintQuote as MintMintQuote;
-#[cfg(feature = "wallet")]
-use crate::mint_url::MintUrl;
-#[cfg(feature = "mint")]
-use crate::nuts::MeltBolt11Request;
-#[cfg(feature = "mint")]
-use crate::nuts::{BlindSignature, MeltQuoteState, MintQuoteState, Proof, Proofs};
-#[cfg(any(feature = "wallet", feature = "mint"))]
-use crate::nuts::{CurrencyUnit, Id, PublicKey, State};
-#[cfg(feature = "wallet")]
-use crate::nuts::{KeySetInfo, Keys, MintInfo, SpendingConditions};
-#[cfg(feature = "mint")]
-use crate::types::LnKey;
-#[cfg(feature = "wallet")]
-use crate::types::ProofInfo;
-#[cfg(feature = "wallet")]
-use crate::wallet;
-#[cfg(feature = "wallet")]
-use crate::wallet::MintQuote as WalletMintQuote;
-
 #[cfg(feature = "mint")]
 pub mod mint_memory;
 #[cfg(feature = "wallet")]
 pub mod wallet_memory;
 
+/// re-export types
+pub use cdk_common::database::{Error, MintDatabase, WalletDatabase};
 #[cfg(feature = "wallet")]
 pub use wallet_memory::WalletMemoryDatabase;
-
-/// CDK_database error
-#[derive(Debug, Error)]
-pub enum Error {
-    /// Database Error
-    #[error(transparent)]
-    Database(Box<dyn std::error::Error + Send + Sync>),
-    /// DHKE error
-    #[error(transparent)]
-    DHKE(#[from] crate::dhke::Error),
-    /// NUT00 Error
-    #[error(transparent)]
-    NUT00(#[from] crate::nuts::nut00::Error),
-    /// NUT02 Error
-    #[error(transparent)]
-    NUT02(#[from] crate::nuts::nut02::Error),
-    /// Serde Error
-    #[error(transparent)]
-    Serde(#[from] serde_json::Error),
-    /// Unknown Quote
-    #[error("Unknown Quote")]
-    UnknownQuote,
-}
-
-/// Wallet Database trait
-#[cfg(feature = "wallet")]
-#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
-#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
-pub trait WalletDatabase: Debug {
-    /// Wallet Database Error
-    type Err: Into<Error> + From<Error>;
-
-    /// Add Mint to storage
-    async fn add_mint(
-        &self,
-        mint_url: MintUrl,
-        mint_info: Option<MintInfo>,
-    ) -> Result<(), Self::Err>;
-    /// Remove Mint from storage
-    async fn remove_mint(&self, mint_url: MintUrl) -> Result<(), Self::Err>;
-    /// Get mint from storage
-    async fn get_mint(&self, mint_url: MintUrl) -> Result<Option<MintInfo>, Self::Err>;
-    /// Get all mints from storage
-    async fn get_mints(&self) -> Result<HashMap<MintUrl, Option<MintInfo>>, Self::Err>;
-    /// Update mint url
-    async fn update_mint_url(
-        &self,
-        old_mint_url: MintUrl,
-        new_mint_url: MintUrl,
-    ) -> Result<(), Self::Err>;
-
-    /// Add mint keyset to storage
-    async fn add_mint_keysets(
-        &self,
-        mint_url: MintUrl,
-        keysets: Vec<KeySetInfo>,
-    ) -> Result<(), Self::Err>;
-    /// Get mint keysets for mint url
-    async fn get_mint_keysets(
-        &self,
-        mint_url: MintUrl,
-    ) -> Result<Option<Vec<KeySetInfo>>, Self::Err>;
-    /// Get mint keyset by id
-    async fn get_keyset_by_id(&self, keyset_id: &Id) -> Result<Option<KeySetInfo>, Self::Err>;
-
-    /// Add mint quote to storage
-    async fn add_mint_quote(&self, quote: WalletMintQuote) -> Result<(), Self::Err>;
-    /// Get mint quote from storage
-    async fn get_mint_quote(&self, quote_id: &str) -> Result<Option<WalletMintQuote>, Self::Err>;
-    /// Get mint quotes from storage
-    async fn get_mint_quotes(&self) -> Result<Vec<WalletMintQuote>, Self::Err>;
-    /// Remove mint quote from storage
-    async fn remove_mint_quote(&self, quote_id: &str) -> Result<(), Self::Err>;
-
-    /// Add melt quote to storage
-    async fn add_melt_quote(&self, quote: wallet::MeltQuote) -> Result<(), Self::Err>;
-    /// Get melt quote from storage
-    async fn get_melt_quote(&self, quote_id: &str) -> Result<Option<wallet::MeltQuote>, Self::Err>;
-    /// Remove melt quote from storage
-    async fn remove_melt_quote(&self, quote_id: &str) -> Result<(), Self::Err>;
-
-    /// Add [`Keys`] to storage
-    async fn add_keys(&self, keys: Keys) -> Result<(), Self::Err>;
-    /// Get [`Keys`] from storage
-    async fn get_keys(&self, id: &Id) -> Result<Option<Keys>, Self::Err>;
-    /// 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.
-    async fn update_proofs(
-        &self,
-        added: Vec<ProofInfo>,
-        removed_ys: Vec<PublicKey>,
-    ) -> Result<(), Self::Err>;
-    /// Set proofs as pending in storage. Proofs are identified by their Y
-    /// value.
-    async fn set_pending_proofs(&self, ys: Vec<PublicKey>) -> Result<(), Self::Err>;
-    /// Reserve proofs in storage. Proofs are identified by their Y value.
-    async fn reserve_proofs(&self, ys: Vec<PublicKey>) -> Result<(), Self::Err>;
-    /// Set proofs as unspent in storage. Proofs are identified by their Y
-    /// value.
-    async fn set_unspent_proofs(&self, ys: Vec<PublicKey>) -> Result<(), Self::Err>;
-    /// Get proofs from storage
-    async fn get_proofs(
-        &self,
-        mint_url: Option<MintUrl>,
-        unit: Option<CurrencyUnit>,
-        state: Option<Vec<State>>,
-        spending_conditions: Option<Vec<SpendingConditions>>,
-    ) -> Result<Vec<ProofInfo>, Self::Err>;
-
-    /// Increment Keyset counter
-    async fn increment_keyset_counter(&self, keyset_id: &Id, count: u32) -> Result<(), Self::Err>;
-    /// Get current Keyset counter
-    async fn get_keyset_counter(&self, keyset_id: &Id) -> Result<Option<u32>, Self::Err>;
-
-    /// Get when nostr key was last checked
-    async fn get_nostr_last_checked(
-        &self,
-        verifying_key: &PublicKey,
-    ) -> Result<Option<u32>, Self::Err>;
-    /// Update last checked time
-    async fn add_nostr_last_checked(
-        &self,
-        verifying_key: PublicKey,
-        last_checked: u32,
-    ) -> Result<(), Self::Err>;
-}
-
-/// Mint Database trait
-#[cfg(feature = "mint")]
-#[async_trait]
-pub trait MintDatabase {
-    /// Mint Database Error
-    type Err: Into<Error> + From<Error>;
-
-    /// Add Active Keyset
-    async fn set_active_keyset(&self, unit: CurrencyUnit, id: Id) -> Result<(), Self::Err>;
-    /// Get Active Keyset
-    async fn get_active_keyset_id(&self, unit: &CurrencyUnit) -> Result<Option<Id>, Self::Err>;
-    /// Get all Active Keyset
-    async fn get_active_keysets(&self) -> Result<HashMap<CurrencyUnit, Id>, Self::Err>;
-
-    /// Add [`MintMintQuote`]
-    async fn add_mint_quote(&self, quote: MintMintQuote) -> Result<(), Self::Err>;
-    /// Get [`MintMintQuote`]
-    async fn get_mint_quote(&self, quote_id: &Uuid) -> Result<Option<MintMintQuote>, Self::Err>;
-    /// Update state of [`MintMintQuote`]
-    async fn update_mint_quote_state(
-        &self,
-        quote_id: &Uuid,
-        state: MintQuoteState,
-    ) -> Result<MintQuoteState, Self::Err>;
-    /// Get all [`MintMintQuote`]s
-    async fn get_mint_quote_by_request(
-        &self,
-        request: &str,
-    ) -> Result<Option<MintMintQuote>, Self::Err>;
-    /// Get all [`MintMintQuote`]s
-    async fn get_mint_quote_by_request_lookup_id(
-        &self,
-        request_lookup_id: &str,
-    ) -> Result<Option<MintMintQuote>, Self::Err>;
-    /// Get Mint Quotes
-    async fn get_mint_quotes(&self) -> Result<Vec<MintMintQuote>, Self::Err>;
-    /// Remove [`MintMintQuote`]
-    async fn remove_mint_quote(&self, quote_id: &Uuid) -> Result<(), Self::Err>;
-
-    /// Add [`mint::MeltQuote`]
-    async fn add_melt_quote(&self, quote: mint::MeltQuote) -> Result<(), Self::Err>;
-    /// Get [`mint::MeltQuote`]
-    async fn get_melt_quote(&self, quote_id: &Uuid) -> Result<Option<mint::MeltQuote>, Self::Err>;
-    /// Update [`mint::MeltQuote`] state
-    async fn update_melt_quote_state(
-        &self,
-        quote_id: &Uuid,
-        state: MeltQuoteState,
-    ) -> Result<MeltQuoteState, Self::Err>;
-    /// Get all [`mint::MeltQuote`]s
-    async fn get_melt_quotes(&self) -> Result<Vec<mint::MeltQuote>, Self::Err>;
-    /// Remove [`mint::MeltQuote`]
-    async fn remove_melt_quote(&self, quote_id: &Uuid) -> Result<(), Self::Err>;
-
-    /// Add melt request
-    async fn add_melt_request(
-        &self,
-        melt_request: MeltBolt11Request<Uuid>,
-        ln_key: LnKey,
-    ) -> Result<(), Self::Err>;
-    /// Get melt request
-    async fn get_melt_request(
-        &self,
-        quote_id: &Uuid,
-    ) -> Result<Option<(MeltBolt11Request<Uuid>, LnKey)>, Self::Err>;
-
-    /// Add [`MintKeySetInfo`]
-    async fn add_keyset_info(&self, keyset: MintKeySetInfo) -> Result<(), Self::Err>;
-    /// Get [`MintKeySetInfo`]
-    async fn get_keyset_info(&self, id: &Id) -> Result<Option<MintKeySetInfo>, Self::Err>;
-    /// Get [`MintKeySetInfo`]s
-    async fn get_keyset_infos(&self) -> Result<Vec<MintKeySetInfo>, Self::Err>;
-
-    /// Add spent [`Proofs`]
-    async fn add_proofs(&self, proof: Proofs, quote_id: Option<Uuid>) -> Result<(), Self::Err>;
-    /// Get [`Proofs`] by ys
-    async fn get_proofs_by_ys(&self, ys: &[PublicKey]) -> Result<Vec<Option<Proof>>, Self::Err>;
-    /// Get ys by quote id
-    async fn get_proof_ys_by_quote_id(&self, quote_id: &Uuid) -> Result<Vec<PublicKey>, Self::Err>;
-    /// Get [`Proofs`] state
-    async fn get_proofs_states(&self, ys: &[PublicKey]) -> Result<Vec<Option<State>>, Self::Err>;
-    /// Get [`Proofs`] state
-    async fn update_proofs_states(
-        &self,
-        ys: &[PublicKey],
-        proofs_state: State,
-    ) -> Result<Vec<Option<State>>, Self::Err>;
-    /// Get [`Proofs`] by state
-    async fn get_proofs_by_keyset_id(
-        &self,
-        keyset_id: &Id,
-    ) -> Result<(Proofs, Vec<Option<State>>), Self::Err>;
-
-    /// Add [`BlindSignature`]
-    async fn add_blind_signatures(
-        &self,
-        blinded_messages: &[PublicKey],
-        blind_signatures: &[BlindSignature],
-        quote_id: Option<Uuid>,
-    ) -> Result<(), Self::Err>;
-    /// Get [`BlindSignature`]s
-    async fn get_blind_signatures(
-        &self,
-        blinded_messages: &[PublicKey],
-    ) -> Result<Vec<Option<BlindSignature>>, Self::Err>;
-    /// Get [`BlindSignature`]s for keyset_id
-    async fn get_blind_signatures_for_keyset(
-        &self,
-        keyset_id: &Id,
-    ) -> Result<Vec<BlindSignature>, Self::Err>;
-    /// Get [`BlindSignature`]s for quote
-    async fn get_blind_signatures_for_quote(
-        &self,
-        quote_id: &Uuid,
-    ) -> Result<Vec<BlindSignature>, Self::Err>;
-}

+ 1 - 2
crates/cdk/src/cdk_database/wallet_memory.rs

@@ -4,10 +4,9 @@ use std::collections::{HashMap, HashSet};
 use std::sync::Arc;
 
 use async_trait::async_trait;
+use cdk_common::database::{Error, WalletDatabase};
 use tokio::sync::RwLock;
 
-use super::WalletDatabase;
-use crate::cdk_database::Error;
 use crate::mint_url::MintUrl;
 use crate::nuts::{
     CurrencyUnit, Id, KeySetInfo, Keys, MintInfo, PublicKey, SpendingConditions, State,

+ 1 - 2
crates/cdk/src/fees.rs

@@ -6,9 +6,8 @@ use std::collections::HashMap;
 
 use tracing::instrument;
 
-use crate::error::Error;
 use crate::nuts::Id;
-use crate::Amount;
+use crate::{Amount, Error};
 
 /// Fee required for proof set
 #[instrument(skip_all)]

+ 4 - 7
crates/cdk/src/lib.rs

@@ -7,11 +7,7 @@
 pub mod cdk_database;
 
 #[cfg(feature = "mint")]
-pub mod cdk_lightning;
-pub mod error;
-#[cfg(feature = "mint")]
 pub mod mint;
-pub mod types;
 #[cfg(feature = "wallet")]
 pub mod wallet;
 
@@ -20,15 +16,16 @@ pub mod pub_sub;
 /// Re-export amount type
 #[doc(hidden)]
 pub use cdk_common::{
-    amount, dhke, lightning_invoice, mint_url, nuts, secret, util, Amount, Bolt11Invoice,
+    amount, common as types, dhke,
+    error::{self, Error},
+    lightning as cdk_lightning, lightning_invoice, mint_url, nuts, secret, util, Amount,
+    Bolt11Invoice,
 };
 
 pub mod fees;
 
 #[doc(hidden)]
 pub use bitcoin::secp256k1;
-#[doc(hidden)]
-pub use error::Error;
 #[cfg(feature = "mint")]
 #[doc(hidden)]
 pub use mint::Mint;

+ 3 - 3
crates/cdk/src/mint/builder.rs

@@ -4,12 +4,12 @@ use std::collections::HashMap;
 use std::sync::Arc;
 
 use anyhow::anyhow;
+use cdk_common::database::{self, MintDatabase};
 
 use super::nut17::SupportedMethods;
 use super::nut19::{self, CachedEndpoint};
 use super::Nuts;
 use crate::amount::Amount;
-use crate::cdk_database::{self, MintDatabase};
 use crate::cdk_lightning::{self, MintLightning};
 use crate::mint::Mint;
 use crate::nuts::{
@@ -26,7 +26,7 @@ pub struct MintBuilder {
     /// Mint Info
     mint_info: MintInfo,
     /// Mint Storage backend
-    localstore: Option<Arc<dyn MintDatabase<Err = cdk_database::Error> + Send + Sync>>,
+    localstore: Option<Arc<dyn MintDatabase<Err = database::Error> + Send + Sync>>,
     /// Ln backends for mint
     ln: Option<HashMap<LnKey, Arc<dyn MintLightning<Err = cdk_lightning::Error> + Send + Sync>>>,
     seed: Option<Vec<u8>>,
@@ -57,7 +57,7 @@ impl MintBuilder {
     /// Set localstore
     pub fn with_localstore(
         mut self,
-        localstore: Arc<dyn MintDatabase<Err = cdk_database::Error> + Send + Sync>,
+        localstore: Arc<dyn MintDatabase<Err = database::Error> + Send + Sync>,
     ) -> MintBuilder {
         self.localstore = Some(localstore);
         self

+ 7 - 47
crates/cdk/src/mint/mod.rs

@@ -6,6 +6,9 @@ use std::sync::Arc;
 
 use bitcoin::bip32::{ChildNumber, DerivationPath, Xpriv};
 use bitcoin::secp256k1::{self, Secp256k1};
+use cdk_common::common::{LnKey, QuoteTTL};
+use cdk_common::database::{self, MintDatabase};
+use cdk_common::mint::MintKeySetInfo;
 use config::SwappableConfig;
 use futures::StreamExt;
 use serde::{Deserialize, Serialize};
@@ -15,14 +18,12 @@ use tokio::task::JoinSet;
 use tracing::instrument;
 use uuid::Uuid;
 
-use crate::cdk_database::{self, MintDatabase};
 use crate::cdk_lightning::{self, MintLightning};
 use crate::dhke::{sign_message, verify_message};
 use crate::error::Error;
 use crate::fees::calculate_fee;
 use crate::mint_url::MintUrl;
 use crate::nuts::*;
-use crate::types::{LnKey, QuoteTTL};
 use crate::util::unix_time;
 use crate::Amount;
 
@@ -46,7 +47,7 @@ pub struct Mint {
     /// Mint Config
     pub config: SwappableConfig,
     /// Mint Storage backend
-    pub localstore: Arc<dyn MintDatabase<Err = cdk_database::Error> + Send + Sync>,
+    pub localstore: Arc<dyn MintDatabase<Err = database::Error> + Send + Sync>,
     /// Ln backends for mint
     pub ln: HashMap<LnKey, Arc<dyn MintLightning<Err = cdk_lightning::Error> + Send + Sync>>,
     /// Subscription manager
@@ -63,7 +64,7 @@ impl Mint {
         seed: &[u8],
         mint_info: MintInfo,
         quote_ttl: QuoteTTL,
-        localstore: Arc<dyn MintDatabase<Err = cdk_database::Error> + Send + Sync>,
+        localstore: Arc<dyn MintDatabase<Err = database::Error> + Send + Sync>,
         ln: HashMap<LnKey, Arc<dyn MintLightning<Err = cdk_lightning::Error> + Send + Sync>>,
         // Hashmap where the key is the unit and value is (input fee ppk, max_order)
         supported_units: HashMap<CurrencyUnit, (u64, u8)>,
@@ -517,47 +518,6 @@ pub struct FeeReserve {
     pub percent_fee_reserve: f32,
 }
 
-/// Mint Keyset Info
-#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
-pub struct MintKeySetInfo {
-    /// Keyset [`Id`]
-    pub id: Id,
-    /// Keyset [`CurrencyUnit`]
-    pub unit: CurrencyUnit,
-    /// Keyset active or inactive
-    /// Mint will only issue new [`BlindSignature`] on active keysets
-    pub active: bool,
-    /// Starting unix time Keyset is valid from
-    pub valid_from: u64,
-    /// When the Keyset is valid to
-    /// This is not shown to the wallet and can only be used internally
-    pub valid_to: Option<u64>,
-    /// [`DerivationPath`] keyset
-    pub derivation_path: DerivationPath,
-    /// DerivationPath index of Keyset
-    pub derivation_path_index: Option<u32>,
-    /// Max order of keyset
-    pub max_order: u8,
-    /// Input Fee ppk
-    #[serde(default = "default_fee")]
-    pub input_fee_ppk: u64,
-}
-
-fn default_fee() -> u64 {
-    0
-}
-
-impl From<MintKeySetInfo> for KeySetInfo {
-    fn from(keyset_info: MintKeySetInfo) -> Self {
-        Self {
-            id: keyset_info.id,
-            unit: keyset_info.unit,
-            active: keyset_info.active,
-            input_fee_ppk: keyset_info.input_fee_ppk,
-        }
-    }
-}
-
 /// Generate new [`MintKeySetInfo`] from path
 #[instrument(skip_all)]
 fn create_new_keyset<C: secp256k1::Signing>(
@@ -606,11 +566,11 @@ mod tests {
     use std::collections::HashSet;
 
     use bitcoin::Network;
+    use cdk_common::common::{LnKey, QuoteTTL};
     use secp256k1::Secp256k1;
     use uuid::Uuid;
 
     use super::*;
-    use crate::types::LnKey;
 
     #[test]
     fn mint_mod_generate_keyset_from_seed() {
@@ -698,7 +658,7 @@ mod tests {
         assert_eq!(amounts_and_pubkeys, expected_amounts_and_pubkeys);
     }
 
-    use cdk_database::mint_memory::MintMemoryDatabase;
+    use crate::cdk_database::mint_memory::MintMemoryDatabase;
 
     #[derive(Default)]
     struct MintConfig<'a> {

+ 3 - 3
crates/cdk/src/mint/subscription/manager.rs

@@ -2,12 +2,12 @@
 use std::ops::Deref;
 use std::sync::Arc;
 
+use cdk_common::database::{self, MintDatabase};
 use cdk_common::nut17::Notification;
 use cdk_common::NotificationPayload;
 use uuid::Uuid;
 
 use super::OnSubscription;
-use crate::cdk_database::{self, MintDatabase};
 use crate::nuts::{
     BlindSignature, MeltQuoteBolt11Response, MeltQuoteState, MintQuoteBolt11Response,
     MintQuoteState, ProofState,
@@ -28,8 +28,8 @@ impl Default for PubSubManager {
     }
 }
 
-impl From<Arc<dyn MintDatabase<Err = cdk_database::Error> + Send + Sync>> for PubSubManager {
-    fn from(val: Arc<dyn MintDatabase<Err = cdk_database::Error> + Send + Sync>) -> Self {
+impl From<Arc<dyn MintDatabase<Err = database::Error> + Send + Sync>> for PubSubManager {
+    fn from(val: Arc<dyn MintDatabase<Err = database::Error> + Send + Sync>) -> Self {
         PubSubManager(OnSubscription(Some(val)).into())
     }
 }

+ 2 - 2
crates/cdk/src/mint/subscription/on_subscription.rs

@@ -3,12 +3,12 @@
 //! This module contains the code that is triggered when a new subscription is created.
 use std::sync::Arc;
 
+use cdk_common::database::{self, MintDatabase};
 use cdk_common::nut17::Notification;
 use cdk_common::pub_sub::OnNewSubscription;
 use cdk_common::NotificationPayload;
 use uuid::Uuid;
 
-use crate::cdk_database::{self, MintDatabase};
 use crate::nuts::{MeltQuoteBolt11Response, MintQuoteBolt11Response, ProofState, PublicKey};
 
 #[derive(Default)]
@@ -18,7 +18,7 @@ use crate::nuts::{MeltQuoteBolt11Response, MintQuoteBolt11Response, ProofState,
 ///
 /// It is used to send the initial state of the subscription to the client.
 pub struct OnSubscription(
-    pub(crate) Option<Arc<dyn MintDatabase<Err = cdk_database::Error> + Send + Sync>>,
+    pub(crate) Option<Arc<dyn MintDatabase<Err = database::Error> + Send + Sync>>,
 );
 
 #[async_trait::async_trait]

+ 5 - 4
crates/cdk/src/wallet/mod.rs

@@ -6,6 +6,7 @@ use std::sync::Arc;
 
 use bitcoin::bip32::Xpriv;
 use bitcoin::Network;
+use cdk_common::database::{self, WalletDatabase};
 use client::MintConnector;
 use getrandom::getrandom;
 pub use multi_mint_wallet::MultiMintWallet;
@@ -14,7 +15,6 @@ use tracing::instrument;
 pub use types::{MeltQuote, MintQuote, SendKind};
 
 use crate::amount::SplitTarget;
-use crate::cdk_database::{self, WalletDatabase};
 use crate::dhke::construct_proofs;
 use crate::error::Error;
 use crate::fees::calculate_fee;
@@ -39,9 +39,10 @@ mod receive;
 mod send;
 pub mod subscription;
 mod swap;
-pub mod types;
 pub mod util;
 
+pub use cdk_common::wallet as types;
+
 use crate::nuts::nut00::ProofsMethods;
 
 /// CDK Wallet
@@ -56,7 +57,7 @@ pub struct Wallet {
     /// Unit
     pub unit: CurrencyUnit,
     /// Storage backend
-    pub localstore: Arc<dyn WalletDatabase<Err = cdk_database::Error> + Send + Sync>,
+    pub localstore: Arc<dyn WalletDatabase<Err = database::Error> + Send + Sync>,
     /// The targeted amount of proofs to have at each size
     pub target_proof_count: usize,
     xpriv: Xpriv,
@@ -132,7 +133,7 @@ impl Wallet {
     pub fn new(
         mint_url: &str,
         unit: CurrencyUnit,
-        localstore: Arc<dyn WalletDatabase<Err = cdk_database::Error> + Send + Sync>,
+        localstore: Arc<dyn WalletDatabase<Err = database::Error> + Send + Sync>,
         seed: &[u8],
         target_proof_count: Option<usize>,
     ) -> Result<Self, Error> {

+ 1 - 22
crates/cdk/src/wallet/multi_mint_wallet.rs

@@ -4,11 +4,10 @@
 //! pairs
 
 use std::collections::{BTreeMap, HashMap};
-use std::fmt;
 use std::str::FromStr;
 use std::sync::Arc;
 
-use serde::{Deserialize, Serialize};
+use cdk_common::wallet::WalletKey;
 use tokio::sync::Mutex;
 use tracing::instrument;
 
@@ -28,26 +27,6 @@ pub struct MultiMintWallet {
     pub wallets: Arc<Mutex<BTreeMap<WalletKey, Wallet>>>,
 }
 
-/// Wallet Key
-#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
-pub struct WalletKey {
-    mint_url: MintUrl,
-    unit: CurrencyUnit,
-}
-
-impl fmt::Display for WalletKey {
-    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        write!(f, "mint_url: {}, unit: {}", self.mint_url, self.unit,)
-    }
-}
-
-impl WalletKey {
-    /// Create new [`WalletKey`]
-    pub fn new(mint_url: MintUrl, unit: CurrencyUnit) -> Self {
-        Self { mint_url, unit }
-    }
-}
-
 impl MultiMintWallet {
     /// New Multimint wallet
     pub fn new(wallets: Vec<Wallet>) -> Self {