Skip to content

Commit 96a41c4

Browse files
committed
Implementing cashubtc/nuts#250
1 parent 47e6822 commit 96a41c4

File tree

15 files changed

+585
-482
lines changed

15 files changed

+585
-482
lines changed

crates/cdk-integration-tests/tests/integration_tests_pure.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ async fn test_swap_overpay_underpay_fee() {
513513
.expect("Failed to create test mint");
514514

515515
mint_bob
516-
.rotate_keyset(CurrencyUnit::Sat, 1, 32, 1)
516+
.rotate_keyset(CurrencyUnit::Sat, 32, 1)
517517
.await
518518
.unwrap();
519519

@@ -575,7 +575,7 @@ async fn test_mint_enforce_fee() {
575575
.expect("Failed to create test mint");
576576

577577
mint_bob
578-
.rotate_keyset(CurrencyUnit::Sat, 1, 32, 1)
578+
.rotate_keyset(CurrencyUnit::Sat, 32, 1)
579579
.await
580580
.unwrap();
581581

@@ -659,7 +659,7 @@ async fn test_mint_change_with_fee_melt() {
659659
.expect("Failed to create test mint");
660660

661661
mint_bob
662-
.rotate_keyset(CurrencyUnit::Sat, 1, 32, 1)
662+
.rotate_keyset(CurrencyUnit::Sat, 32, 1)
663663
.await
664664
.unwrap();
665665

crates/cdk-integration-tests/tests/mint.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,8 @@ async fn test_correct_keyset() {
5959
let quote_ttl = QuoteTTL::new(10000, 10000);
6060
localstore.set_quote_ttl(quote_ttl).await.unwrap();
6161

62-
mint.rotate_next_keyset(CurrencyUnit::Sat, 32, 0)
63-
.await
64-
.unwrap();
65-
mint.rotate_next_keyset(CurrencyUnit::Sat, 32, 0)
66-
.await
67-
.unwrap();
62+
mint.rotate_keyset(CurrencyUnit::Sat, 32, 0).await.unwrap();
63+
mint.rotate_keyset(CurrencyUnit::Sat, 32, 0).await.unwrap();
6864

6965
let active = mint.get_active_keysets();
7066

crates/cdk-mint-rpc/src/proto/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ impl CdkMint for MintRPCServer {
673673

674674
let keyset_info = self
675675
.mint
676-
.rotate_next_keyset(
676+
.rotate_keyset(
677677
unit,
678678
request.max_order.map(|a| a as u8).unwrap_or(32),
679679
request.input_fee_ppk.unwrap_or(0),

crates/cdk-signatory/proto/signatory.proto

Lines changed: 87 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,85 @@ syntax = "proto3";
22

33
package signatory;
44

5+
/// TODO: research about the stream, to notify when RotateKeyset is triggered.
56
service Signatory {
6-
rpc BlindSign(BlindedMessage) returns (BlindSignature);
7+
rpc BlindSign (BlindedMessages) returns (BlindSignResponse);
78

8-
rpc VerifyProof(Proof) returns (Empty);
9+
rpc VerifyProofs (Proofs) returns (BooleanResponse);
910

10-
rpc Keysets(Empty) returns (VecSignatoryKeySet);
11+
rpc Keysets (EmptyRequest) returns (KeysResponse);
1112

12-
rpc RotateKeyset(RotateKeyArguments) returns (MintKeySetInfo);
13+
rpc RotateKeyset (RotationRequest) returns (KeyRotationResponse);
1314
}
1415

15-
message Empty {}
16+
message BlindSignResponse {
17+
oneof result {
18+
BlindSignatures sigs = 1;
19+
Error error = 2;
20+
}
21+
}
1622

17-
message VecSignatoryKeySet {
18-
repeated SignatoryKeySet keysets = 1;
23+
message BlindedMessages {
24+
repeated BlindedMessage blinded_messages = 1;
25+
}
1926

20-
optional bool is_none = 2;
27+
// Represents a blinded message
28+
message BlindedMessage {
29+
uint64 amount = 1;
30+
string keyset_id = 2;
31+
bytes blinded_secret = 3;
2132
}
2233

23-
message SignatoryKeySet {
24-
KeySet key = 1;
25-
MintKeySetInfo info = 2;
34+
message BooleanResponse {
35+
oneof result {
36+
bool success = 1;
37+
Error error = 2;
38+
}
2639
}
2740

28-
message KeySet {
29-
Id id = 1;
30-
CurrencyUnit unit = 2;
31-
Keys keys = 3;
41+
message KeyRotationResponse {
42+
oneof result {
43+
KeySet keyset = 1;
44+
Error error = 2;
45+
}
3246
}
3347

34-
message Keys {
35-
map<uint64, bytes> keys = 1;
48+
message KeysResponse {
49+
oneof result {
50+
SignatoryKeysets keysets = 1;
51+
Error error = 2;
52+
}
3653
}
3754

55+
message SignatoryKeysets {
56+
bytes pubkey = 1;
57+
repeated KeySet keysets = 2;
58+
}
3859

39-
message RotateKeyArguments {
40-
CurrencyUnit unit = 1;
41-
optional uint32 derivation_path_index = 2;
42-
uint32 max_order = 3;
60+
message KeySet {
61+
string id = 1;
62+
CurrencyUnit unit = 2;
63+
bool active = 3;
4364
uint64 input_fee_ppk = 4;
65+
Keys keys = 5;
4466
}
4567

46-
message CustomDerivationPath {
47-
CurrencyUnit unit = 1;
48-
repeated DerivationPath derivation_path = 2;
68+
message Keys {
69+
map<uint64, bytes> keys = 1;
70+
}
71+
72+
message RotationRequest {
73+
CurrencyUnit unit = 1;
74+
uint64 input_fee_ppk = 2;
75+
uint64 max_order = 3;
4976
}
5077

5178
enum CurrencyUnitType {
52-
SAT = 0;
53-
MSAT = 1;
54-
USD = 2;
55-
EUR = 3;
79+
SAT = 0;
80+
MSAT = 1;
81+
USD = 2;
82+
EUR = 3;
83+
AUTH = 4;
5684
}
5785

5886
message CurrencyUnit {
@@ -62,13 +90,15 @@ message CurrencyUnit {
6290
}
6391
}
6492

93+
message Proofs {
94+
repeated Proof proof = 1;
95+
}
96+
6597
message Proof {
6698
uint64 amount = 1;
6799
string keyset_id = 2;
68-
string secret = 3;
100+
bytes secret = 3;
69101
bytes C = 4;
70-
optional Witness witness = 5;
71-
optional ProofDLEQ dleq = 6;
72102
}
73103

74104
message ProofDLEQ {
@@ -77,6 +107,16 @@ message ProofDLEQ {
77107
bytes r = 3;
78108
}
79109

110+
message SigningResponse {
111+
oneof result {
112+
BlindSignatures blind_signatures = 1;
113+
Error error = 2;
114+
}
115+
}
116+
message BlindSignatures {
117+
repeated BlindSignature blind_signatures = 1;
118+
}
119+
80120
message BlindSignature {
81121
uint64 amount = 1;
82122
string keyset_id = 2;
@@ -89,13 +129,6 @@ message BlindSignatureDLEQ {
89129
bytes s = 2;
90130
}
91131

92-
message KeySetInfo {
93-
Id id = 1;
94-
CurrencyUnit unit = 2;
95-
bool active = 3;
96-
uint64 input_fee_ppk = 4;
97-
}
98-
99132
// Witness type
100133
message Witness {
101134
oneof witness_type {
@@ -114,42 +147,27 @@ message P2PKWitness {
114147
message HTLCWitness {
115148
// Preimage
116149
string preimage = 1;
117-
118150
// List of signatures
119151
repeated string signatures = 2;
120152
}
121153

122-
message BlindedMessage {
123-
uint64 amount = 1;
124-
string keyset_id = 2;
125-
bytes blinded_secret = 3;
126-
optional Witness witness = 4; // This field is optional by default in proto3
127-
}
128-
129-
message KeysResponse {
130-
repeated KeySet keysets = 1;
131-
}
132-
133-
134-
message Id {
135-
bytes inner = 1;
154+
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;
136166
}
137167

138-
message DerivationPath {
139-
oneof child_number {
140-
uint32 normal = 1;
141-
uint32 hardened = 2;
142-
}
168+
message Error {
169+
ErrorCode code = 1;
170+
string detail = 2;
143171
}
144172

145-
message MintKeySetInfo {
146-
Id id = 1;
147-
CurrencyUnit unit = 2;
148-
bool active = 3;
149-
uint64 valid_from = 4;
150-
optional uint64 valid_to = 5;
151-
repeated DerivationPath derivation_path = 6;
152-
optional uint32 derivation_path_index = 7;
153-
uint32 max_order = 8;
154-
uint64 input_fee_ppk = 9;
155-
}
173+
message EmptyRequest {}

0 commit comments

Comments
 (0)