mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-21 14:44:46 +01:00
* WIP: Introduce a SignatoryManager service. The SignatoryManager manager provides an API to interact with keysets, private keys, and all key-related operations, offering segregation between the mint and the most sensible part of the mind: the private keys. Although the default signatory runs in memory, it is completely isolated from the rest of the system and can only be communicated through the interface offered by the signatory manager. Only messages can be sent from the mintd to the Signatory trait through the Signatory Manager. This pull request sets the foundation for eventually being able to run the Signatory and all the key-related operations in a separate service, possibly in a foreign service, to offload risks, as described in #476. The Signatory manager is concurrent and deferred any mechanism needed to handle concurrency to the Signatory trait. * Fixed missing default feature for signatory * Do not read keys from the DB * Removed KeysDatabase Trait from MintDatabase All Keys operations should be done through the signatory * Make sure signatory has all the keys in memory Drop also foreign constraints on sqlite * Fix race condition * Adding debug info to failing test * Add `sleep` in test * Fixed issue with active auth keyset * Fixed dependency * Move all keys and keysets to an ArcSwap. Since the keys and keysets exist in RAM, most wrapping functions are infallible and synchronous, improving performance and adding breaking API changes. The signatory will provide this information on the boot and update when the `rotate_keyset` is executed. Todo: Implement a subscription key to reload the keys when the GRPC server changes the keys. For the embedded mode, that makes no sense since there is a single way to rotate keys, and that bit is already covered. * Implementing https://github.com/cashubtc/nuts/pull/250 * Add CLI for cdk-signatory to spawn an external signatory Add to the pipeline the external signatory * Update tests * Apply suggestions from code review Co-authored-by: ok300 <106775972+ok300@users.noreply.github.com> Co-authored-by: thesimplekid <tsk@thesimplekid.com> * Minor change * Update proto buf to use the newest format * Rename binary * Add instrumentations * Add more comments * Use a single database for the signatory Store all keys, even auth keys, in a single database. Leave the MintAuthDatabse trait implementation for the CDK but not the signagtory This commit also moves the cli mod to its own file * Update dep * Add `test_mint_keyset_gen` test --------- Co-authored-by: ok300 <106775972+ok300@users.noreply.github.com> Co-authored-by: thesimplekid <tsk@thesimplekid.com>
94 lines
2.9 KiB
Rust
94 lines
2.9 KiB
Rust
//! Mint tests
|
|
//!
|
|
//! This file contains tests that focus on the mint's internal functionality without client interaction.
|
|
//! These tests verify the mint's behavior in isolation, such as keyset management, database operations,
|
|
//! and other mint-specific functionality that doesn't require wallet clients.
|
|
|
|
use std::collections::{HashMap, HashSet};
|
|
use std::sync::Arc;
|
|
|
|
use bip39::Mnemonic;
|
|
use cdk::cdk_database::MintDatabase;
|
|
use cdk::mint::{MintBuilder, MintMeltLimits};
|
|
use cdk::nuts::{CurrencyUnit, PaymentMethod};
|
|
use cdk::types::{FeeReserve, QuoteTTL};
|
|
use cdk_fake_wallet::FakeWallet;
|
|
use cdk_sqlite::mint::memory;
|
|
|
|
pub const MINT_URL: &str = "http://127.0.0.1:8088";
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
|
|
async fn test_correct_keyset() {
|
|
let mnemonic = Mnemonic::generate(12).unwrap();
|
|
let fee_reserve = FeeReserve {
|
|
min_fee_reserve: 1.into(),
|
|
percent_fee_reserve: 1.0,
|
|
};
|
|
|
|
let database = memory::empty().await.expect("valid db instance");
|
|
|
|
let fake_wallet = FakeWallet::new(fee_reserve, HashMap::default(), HashSet::default(), 0);
|
|
|
|
let mut mint_builder = MintBuilder::new();
|
|
let localstore = Arc::new(database);
|
|
mint_builder = mint_builder
|
|
.with_localstore(localstore.clone())
|
|
.with_keystore(localstore.clone());
|
|
|
|
mint_builder = mint_builder
|
|
.add_ln_backend(
|
|
CurrencyUnit::Sat,
|
|
PaymentMethod::Bolt11,
|
|
MintMeltLimits::new(1, 5_000),
|
|
Arc::new(fake_wallet),
|
|
)
|
|
.await
|
|
.unwrap();
|
|
|
|
mint_builder = mint_builder
|
|
.with_name("regtest mint".to_string())
|
|
.with_description("regtest mint".to_string())
|
|
.with_seed(mnemonic.to_seed_normalized("").to_vec());
|
|
|
|
let mint = mint_builder.build().await.unwrap();
|
|
|
|
localstore
|
|
.set_mint_info(mint_builder.mint_info.clone())
|
|
.await
|
|
.unwrap();
|
|
let quote_ttl = QuoteTTL::new(10000, 10000);
|
|
localstore.set_quote_ttl(quote_ttl).await.unwrap();
|
|
|
|
let active = mint.get_active_keysets();
|
|
|
|
let active = active
|
|
.get(&CurrencyUnit::Sat)
|
|
.expect("There is a keyset for unit");
|
|
let old_keyset_info = mint.get_keyset_info(active).expect("There is keyset");
|
|
|
|
mint.rotate_keyset(CurrencyUnit::Sat, 32, 0).await.unwrap();
|
|
|
|
let active = mint.get_active_keysets();
|
|
|
|
let active = active
|
|
.get(&CurrencyUnit::Sat)
|
|
.expect("There is a keyset for unit");
|
|
|
|
let keyset_info = mint.get_keyset_info(active).expect("There is keyset");
|
|
|
|
assert_ne!(keyset_info.id, old_keyset_info.id);
|
|
|
|
mint.rotate_keyset(CurrencyUnit::Sat, 32, 0).await.unwrap();
|
|
let mint = mint_builder.build().await.unwrap();
|
|
|
|
let active = mint.get_active_keysets();
|
|
|
|
let active = active
|
|
.get(&CurrencyUnit::Sat)
|
|
.expect("There is a keyset for unit");
|
|
|
|
let new_keyset_info = mint.get_keyset_info(active).expect("There is keyset");
|
|
|
|
assert_ne!(new_keyset_info.id, keyset_info.id);
|
|
}
|