-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce a SignatoryManager service. #509
Draft
crodas
wants to merge
3
commits into
cashubtc:main
Choose a base branch
from
crodas:proto/independent-signatory
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
//! Signatory mod | ||
//! | ||
//! This module abstract all the key related operations, defining an interface for the necessary | ||
//! operations, to be implemented by the different signatory implementations. | ||
//! | ||
//! There is an in memory implementation, when the keys are stored in memory, in the same process, | ||
//! but it is isolated from the rest of the application, and they communicate through a channel with | ||
//! the defined API. | ||
use std::collections::HashMap; | ||
|
||
use bitcoin::bip32::DerivationPath; | ||
use cashu::mint::MintKeySetInfo; | ||
use cashu::{ | ||
BlindSignature, BlindedMessage, CurrencyUnit, Id, KeySet, KeysResponse, KeysetResponse, Proof, | ||
}; | ||
|
||
use super::error::Error; | ||
|
||
/// Type alias to make the keyset info API more useful, queryable by unit and Id | ||
pub enum KeysetIdentifier { | ||
/// Mint Keyset by unit | ||
Unit(CurrencyUnit), | ||
/// Mint Keyset by Id | ||
Id(Id), | ||
} | ||
|
||
impl From<Id> for KeysetIdentifier { | ||
fn from(id: Id) -> Self { | ||
Self::Id(id) | ||
} | ||
} | ||
|
||
impl From<CurrencyUnit> for KeysetIdentifier { | ||
fn from(unit: CurrencyUnit) -> Self { | ||
Self::Unit(unit) | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
/// Signatory trait | ||
pub trait Signatory { | ||
/// Blind sign a message | ||
async fn blind_sign(&self, blinded_message: BlindedMessage) -> Result<BlindSignature, Error>; | ||
|
||
/// Verify [`Proof`] meets conditions and is signed | ||
async fn verify_proof(&self, proof: Proof) -> Result<(), Error>; | ||
|
||
/// Retrieve a keyset by id | ||
async fn keyset(&self, keyset_id: Id) -> Result<Option<KeySet>, Error>; | ||
|
||
/// Retrieve the public keys of a keyset | ||
async fn keyset_pubkeys(&self, keyset_id: Id) -> Result<KeysResponse, Error>; | ||
|
||
/// Retrieve the public keys of the active keyset for distribution to wallet | ||
/// clients | ||
async fn pubkeys(&self) -> Result<KeysResponse, Error>; | ||
|
||
/// Return a list of all supported keysets | ||
async fn keysets(&self) -> Result<KeysetResponse, Error>; | ||
|
||
/// Add current keyset to inactive keysets | ||
/// Generate new keyset | ||
async fn rotate_keyset( | ||
&self, | ||
unit: CurrencyUnit, | ||
derivation_path_index: u32, | ||
max_order: u8, | ||
input_fee_ppk: u64, | ||
custom_paths: HashMap<CurrencyUnit, DerivationPath>, | ||
) -> Result<MintKeySetInfo, Error>; | ||
|
||
/// Get Mint Keyset Info by Unit or Id | ||
async fn get_keyset_info(&self, keyset_id: KeysetIdentifier) -> Result<MintKeySetInfo, Error>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,14 +26,17 @@ cdk-redb = { path = "../cdk-redb", version = "0.7.1", default-features = false, | |
cdk-sqlite = { path = "../cdk-sqlite", version = "0.7.1", default-features = false, features = [ | ||
"mint", | ||
] } | ||
cdk-cln = { path = "../cdk-cln", version = "0.7.1", default-features = false } | ||
cdk-lnbits = { path = "../cdk-lnbits", version = "0.7.1", default-features = false } | ||
cdk-phoenixd = { path = "../cdk-phoenixd", version = "0.7.1", default-features = false } | ||
cdk-lnd = { path = "../cdk-lnd", version = "0.7.1", default-features = false } | ||
cdk-fake-wallet = { path = "../cdk-fake-wallet", version = "0.7.1", default-features = false } | ||
cdk-strike = { path = "../cdk-strike", version = "0.7.1" } | ||
cdk-axum = { path = "../cdk-axum", version = "0.7.1", default-features = false } | ||
cdk-mint-rpc = { path = "../cdk-mint-rpc", version = "0.7.1", default-features = false, optional = true } | ||
cdk-cln = { path = "../cdk-cln", version = "0.7.0", default-features = false } | ||
cdk-lnbits = { path = "../cdk-lnbits", version = "0.7.0", default-features = false } | ||
cdk-phoenixd = { path = "../cdk-phoenixd", version = "0.7.0", default-features = false } | ||
cdk-lnd = { path = "../cdk-lnd", version = "0.7.0", default-features = false } | ||
cdk-fake-wallet = { path = "../cdk-fake-wallet", version = "0.7.0", default-features = false } | ||
cdk-strike = { path = "../cdk-strike", version = "0.7.0" } | ||
cdk-axum = { path = "../cdk-axum", version = "0.7.0", default-features = false } | ||
cdk-mint-rpc = { path = "../cdk-mint-rpc", version = "0.7.0", default-features = false, optional = true } | ||
cdk-signatory = { path = "../cdk-signatory", default-features = false, features = [ | ||
"grpc", | ||
] } | ||
Comment on lines
+29
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these should all be version |
||
config = { version = "0.13.3", features = ["toml"] } | ||
clap = { version = "~4.0.32", features = ["derive"] } | ||
bitcoin = { version = "0.32.2", features = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use std::collections::HashMap; | ||
use std::env; | ||
use std::str::FromStr; | ||
|
||
use bip39::Mnemonic; | ||
use cdk::nuts::CurrencyUnit; | ||
use cdk_mintd::cli::CLIArgs; | ||
use cdk_mintd::env_vars::ENV_WORK_DIR; | ||
use cdk_mintd::{config, work_dir}; | ||
use cdk_signatory::proto::server::grpc_server; | ||
use cdk_signatory::MemorySignatory; | ||
use clap::Parser; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let args = CLIArgs::parse(); | ||
let work_dir = if let Some(work_dir) = args.work_dir { | ||
tracing::info!("Using work dir from cmd arg"); | ||
work_dir | ||
} else if let Ok(env_work_dir) = env::var(ENV_WORK_DIR) { | ||
tracing::info!("Using work dir from env var"); | ||
env_work_dir.into() | ||
} else { | ||
work_dir()? | ||
}; | ||
|
||
let config_file_arg = match args.config { | ||
Some(c) => c, | ||
None => work_dir.join("config.toml"), | ||
}; | ||
|
||
let settings = if config_file_arg.exists() { | ||
config::Settings::new(Some(config_file_arg)) | ||
} else { | ||
tracing::info!("Config file does not exist. Attempting to read env vars"); | ||
config::Settings::default() | ||
}; | ||
|
||
// This check for any settings defined in ENV VARs | ||
// ENV VARS will take **priority** over those in the config | ||
let mut settings = settings.from_env()?; | ||
let mnemonic = Mnemonic::from_str(&settings.info.mnemonic)?; | ||
|
||
let signatory = MemorySignatory::new( | ||
settings.database.engine.clone().mint(&work_dir).await?, | ||
&mnemonic.to_seed_normalized(""), | ||
settings | ||
.supported_units | ||
.take() | ||
.unwrap_or(vec![CurrencyUnit::default()]) | ||
.into_iter() | ||
.map(|u| (u, (0, 32))) | ||
.collect::<HashMap<_, _>>(), | ||
HashMap::new(), | ||
) | ||
.await?; | ||
|
||
grpc_server(signatory, "[::1]:50051".parse().unwrap()).await?; | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we week serde at 1? I know we changed uuid bc of the wasm build issue