Skip to content

Commit eba30f5

Browse files
committed
Update proto buf to use the newest format
1 parent 0ebd265 commit eba30f5

File tree

8 files changed

+180
-176
lines changed

8 files changed

+180
-176
lines changed

crates/cdk-mintd/src/config.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ impl std::fmt::Debug for Info {
3030
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3131
// Use a fallback approach that won't panic
3232
let mnemonic_display = {
33-
let hash = sha256::Hash::hash(self.mnemonic.clone().into_bytes().as_ref());
34-
format!("<hashed: {hash}>")
33+
if let Some(mnemonic) = self.mnemonic.as_ref() {
34+
let hash = sha256::Hash::hash(mnemonic.as_bytes());
35+
format!("<hashed: {hash}>")
36+
} else {
37+
format!("<url: {}>", self.signatory_url.clone().unwrap_or_default())
38+
}
3539
};
3640

3741
f.debug_struct("Info")

crates/cdk-signatory/proto/signatory.proto

Lines changed: 76 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -2,167 +2,155 @@ syntax = "proto3";
22

33
package signatory;
44

5-
/// TODO: research about the stream, to notify when RotateKeyset is triggered.
65
service Signatory {
7-
rpc BlindSign (BlindedMessages) returns (BlindSignResponse);
8-
9-
rpc VerifyProofs (Proofs) returns (BooleanResponse);
10-
11-
rpc Keysets (EmptyRequest) returns (KeysResponse);
12-
13-
rpc RotateKeyset (RotationRequest) returns (KeyRotationResponse);
6+
rpc BlindSign(BlindedMessages) returns (BlindSignResponse);
7+
rpc VerifyProofs(Proofs) returns (BooleanResponse);
8+
// returns all the keysets for the mint
9+
rpc Keysets(EmptyRequest) returns (KeysResponse);
10+
// rotates the keysets
11+
rpc RotateKeyset(RotationRequest) returns (KeyRotationResponse);
1412
}
1513

1614
message BlindSignResponse {
17-
oneof result {
18-
BlindSignatures sigs = 1;
19-
Error error = 2;
20-
}
15+
Error error = 1;
16+
BlindSignatures sigs = 2;
2117
}
2218

2319
message BlindedMessages {
24-
repeated BlindedMessage blinded_messages = 1;
20+
repeated BlindedMessage blinded_messages = 1;
2521
}
2622

2723
// Represents a blinded message
2824
message BlindedMessage {
29-
uint64 amount = 1;
30-
string keyset_id = 2;
31-
bytes blinded_secret = 3;
25+
uint64 amount = 1;
26+
string keyset_id = 2;
27+
bytes blinded_secret = 3;
3228
}
3329

3430
message BooleanResponse {
35-
oneof result {
36-
bool success = 1;
37-
Error error = 2;
38-
}
31+
Error error = 1;
32+
bool success = 2;
3933
}
4034

4135
message KeyRotationResponse {
42-
oneof result {
43-
KeySet keyset = 1;
44-
Error error = 2;
45-
}
36+
Error error = 1;
37+
KeySet keyset = 2;
4638
}
4739

4840
message KeysResponse {
49-
oneof result {
50-
SignatoryKeysets keysets = 1;
51-
Error error = 2;
52-
}
41+
Error error = 1;
42+
SignatoryKeysets keysets = 2;
5343
}
5444

5545
message SignatoryKeysets {
56-
bytes pubkey = 1;
57-
repeated KeySet keysets = 2;
46+
bytes pubkey = 1;
47+
repeated KeySet keysets = 2;
5848
}
5949

6050
message KeySet {
61-
string id = 1;
62-
CurrencyUnit unit = 2;
63-
bool active = 3;
64-
uint64 input_fee_ppk = 4;
65-
Keys keys = 5;
51+
string id = 1;
52+
CurrencyUnit unit = 2;
53+
bool active = 3;
54+
uint64 input_fee_ppk = 4;
55+
Keys keys = 5;
6656
}
6757

6858
message Keys {
69-
map<uint64, bytes> keys = 1;
59+
map<uint64, bytes> keys = 1;
7060
}
7161

7262
message RotationRequest {
73-
CurrencyUnit unit = 1;
74-
uint64 input_fee_ppk = 2;
75-
uint64 max_order = 3;
63+
CurrencyUnit unit = 1;
64+
uint64 input_fee_ppk = 2;
65+
uint64 max_order = 3;
7666
}
7767

7868
enum CurrencyUnitType {
79-
SAT = 0;
80-
MSAT = 1;
81-
USD = 2;
82-
EUR = 3;
83-
AUTH = 4;
69+
SAT = 0;
70+
MSAT = 1;
71+
USD = 2;
72+
EUR = 3;
73+
AUTH = 4;
8474
}
8575

8676
message CurrencyUnit {
87-
oneof currency_unit {
88-
CurrencyUnitType unit = 1;
89-
string custom_unit = 2;
90-
}
77+
oneof currency_unit {
78+
CurrencyUnitType unit = 1;
79+
string custom_unit = 2;
80+
}
9181
}
9282

9383
message Proofs {
94-
repeated Proof proof = 1;
84+
repeated Proof proof = 1;
9585
}
9686

9787
message Proof {
98-
uint64 amount = 1;
99-
string keyset_id = 2;
100-
bytes secret = 3;
101-
bytes C = 4;
88+
uint64 amount = 1;
89+
string keyset_id = 2;
90+
bytes secret = 3;
91+
bytes C = 4;
10292
}
10393

10494
message ProofDLEQ {
105-
bytes e = 1;
106-
bytes s = 2;
107-
bytes r = 3;
95+
bytes e = 1;
96+
bytes s = 2;
97+
bytes r = 3;
10898
}
10999

110100
message SigningResponse {
111-
oneof result {
112-
BlindSignatures blind_signatures = 1;
113-
Error error = 2;
114-
}
101+
Error error = 1;
102+
BlindSignatures blind_signatures = 2;
115103
}
116104
message BlindSignatures {
117-
repeated BlindSignature blind_signatures = 1;
105+
repeated BlindSignature blind_signatures = 1;
118106
}
119107

120108
message BlindSignature {
121-
uint64 amount = 1;
122-
string keyset_id = 2;
123-
bytes blinded_secret = 3;
124-
optional BlindSignatureDLEQ dleq = 4;
109+
uint64 amount = 1;
110+
string keyset_id = 2;
111+
bytes blinded_secret = 3;
112+
optional BlindSignatureDLEQ dleq = 4;
125113
}
126114

127115
message BlindSignatureDLEQ {
128-
bytes e = 1;
129-
bytes s = 2;
116+
bytes e = 1;
117+
bytes s = 2;
130118
}
131119

132120
// Witness type
133121
message Witness {
134-
oneof witness_type {
135-
P2PKWitness p2pk_witness = 1;
136-
HTLCWitness htlc_witness = 2;
137-
}
122+
oneof witness_type {
123+
P2PKWitness p2pk_witness = 1;
124+
HTLCWitness htlc_witness = 2;
125+
}
138126
}
139127

140128
// P2PKWitness type
141129
message P2PKWitness {
142-
// List of signatures
143-
repeated string signatures = 1;
130+
// List of signatures
131+
repeated string signatures = 1;
144132
}
145133

146134
// HTLCWitness type
147135
message HTLCWitness {
148-
// Preimage
149-
string preimage = 1;
150-
// List of signatures
151-
repeated string signatures = 2;
136+
// Preimage
137+
string preimage = 1;
138+
// List of signatures
139+
repeated string signatures = 2;
152140
}
153141

154142
enum ErrorCode {
155-
UNKNOWN = 0;
156-
AMOUNT_OUTSIDE_LIMIT = 1;
157-
DUPLICATE_INPUTS_PROVIDED = 2;
158-
DUPLICATE_OUTPUTS_PROVIDED = 3;
159-
KEYSET_NOT_KNOWN = 4;
160-
KEYSET_INACTIVE = 5;
161-
MINTING_DISABLED = 6;
162-
COULD_NOT_ROTATE_KEYSET = 7;
163-
INVALID_PROOF = 8;
164-
INVALID_BLIND_MESSAGE = 9;
165-
UNIT_NOT_SUPPORTED = 10;
143+
UNKNOWN = 0;
144+
AMOUNT_OUTSIDE_LIMIT = 1;
145+
DUPLICATE_INPUTS_PROVIDED = 2;
146+
DUPLICATE_OUTPUTS_PROVIDED = 3;
147+
KEYSET_NOT_KNOWN = 4;
148+
KEYSET_INACTIVE = 5;
149+
MINTING_DISABLED = 6;
150+
COULD_NOT_ROTATE_KEYSET = 7;
151+
INVALID_PROOF = 8;
152+
INVALID_BLIND_MESSAGE = 9;
153+
UNIT_NOT_SUPPORTED = 10;
166154
}
167155

168156
message Error {

crates/cdk-signatory/src/db_signatory.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::signatory::{RotateKeyArguments, Signatory, SignatoryKeySet, Signatory
2222
pub struct DbSignatory {
2323
keysets: RwLock<HashMap<Id, (MintKeySetInfo, MintKeySet)>>,
2424
active_keysets: RwLock<HashMap<CurrencyUnit, Id>>,
25+
/// TODO: Merge localstore with auth_localstore (use the same db). It makes sense in CDK but not here.
2526
localstore: Arc<dyn database::MintKeysDatabase<Err = database::Error> + Send + Sync>,
2627
auth_localstore:
2728
Option<Arc<dyn database::MintAuthDatabase<Err = database::Error> + Send + Sync>>,

crates/cdk-signatory/src/main.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#[cfg(not(target_arch = "wasm32"))]
22
mod cli {
33
use std::collections::HashMap;
4-
use std::fs;
54
use std::net::SocketAddr;
65
use std::path::PathBuf;
76
use std::str::FromStr;
87
use std::sync::Arc;
8+
use std::{env, fs};
99

1010
use anyhow::{bail, Result};
1111
use bip39::rand::{thread_rng, Rng};
@@ -22,6 +22,7 @@ mod cli {
2222
use tracing_subscriber::EnvFilter;
2323

2424
const DEFAULT_WORK_DIR: &str = ".cdk-signatory";
25+
const ENV_MNEMONIC: &str = "CDK_MINTD_MNEMONIC";
2526

2627
/// Simple CLI application to interact with cashu
2728
#[derive(Parser)]
@@ -48,6 +49,7 @@ mod cli {
4849
listen_port: u32,
4950
#[arg(long, short)]
5051
certs: Option<String>,
52+
/// Supported units with the format of name,fee and max_order
5153
#[arg(long, short, default_value = "sat,0,32")]
5254
units: Vec<String>,
5355
}
@@ -74,7 +76,7 @@ mod cli {
7476

7577
let sqlx_filter = "sqlx=warn,hyper_util=warn,reqwest=warn";
7678

77-
let env_filter = EnvFilter::new(format!("{},{}", default_filter, sqlx_filter));
79+
let env_filter = EnvFilter::new(format!("{default_filter},{sqlx_filter}"));
7880

7981
// Parse input
8082
tracing_subscriber::fmt().with_env_filter(env_filter).init();
@@ -136,21 +138,25 @@ mod cli {
136138

137139
let seed_path = work_dir.join("seed");
138140

139-
let mnemonic = match fs::metadata(seed_path.clone()) {
140-
Ok(_) => {
141-
let contents = fs::read_to_string(seed_path.clone())?;
142-
Mnemonic::from_str(&contents)?
143-
}
144-
Err(_e) => {
145-
let mut rng = thread_rng();
146-
let random_bytes: [u8; 32] = rng.gen();
141+
let mnemonic = if let Ok(mnemonic) = env::var(ENV_MNEMONIC) {
142+
Mnemonic::from_str(&mnemonic)?
143+
} else {
144+
match fs::metadata(seed_path.clone()) {
145+
Ok(_) => {
146+
let contents = fs::read_to_string(seed_path.clone())?;
147+
Mnemonic::from_str(&contents)?
148+
}
149+
Err(_e) => {
150+
let mut rng = thread_rng();
151+
let random_bytes: [u8; 32] = rng.gen();
147152

148-
let mnemonic = Mnemonic::from_entropy(&random_bytes)?;
149-
tracing::info!("Creating new seed");
153+
let mnemonic = Mnemonic::from_entropy(&random_bytes)?;
154+
tracing::info!("Creating new seed");
150155

151-
fs::write(seed_path, mnemonic.to_string())?;
156+
fs::write(seed_path, mnemonic.to_string())?;
152157

153-
mnemonic
158+
mnemonic
159+
}
154160
}
155161
};
156162
let seed = mnemonic.to_seed_normalized("");

0 commit comments

Comments
 (0)