Skip to content

Commit aa711ae

Browse files
committed
Update vetKD examples with latest API names
1 parent 9464f78 commit aa711ae

File tree

13 files changed

+72
-68
lines changed

13 files changed

+72
-68
lines changed

motoko/encrypted-notes-dapp-vetkd/src/encrypted_notes_motoko/main.mo

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,12 @@ shared ({ caller = initializer }) actor class () {
315315
vetkd_public_key : ({
316316
canister_id : ?Principal;
317317
derivation_path : [Blob];
318-
key_id : { curve : { #bls12_381 }; name : Text };
318+
key_id : { curve : { #bls12_381_g2 }; name : Text };
319319
}) -> async ({ public_key : Blob });
320-
vetkd_encrypted_key : ({
321-
public_key_derivation_path : [Blob];
320+
vetkd_derive_encrypted_key : ({
321+
derivation_path : [Blob];
322322
derivation_id : Blob;
323-
key_id : { curve : { #bls12_381 }; name : Text };
323+
key_id : { curve : { #bls12_381_g2 }; name : Text };
324324
encryption_public_key : Blob;
325325
}) -> async ({ encrypted_key : Blob });
326326
};
@@ -331,7 +331,7 @@ shared ({ caller = initializer }) actor class () {
331331
let { public_key } = await vetkd_system_api.vetkd_public_key({
332332
canister_id = null;
333333
derivation_path = Array.make(Text.encodeUtf8("note_symmetric_key"));
334-
key_id = { curve = #bls12_381; name = "test_key_1" };
334+
key_id = { curve = #bls12_381_g2; name = "test_key_1" };
335335
});
336336
Hex.encode(Blob.toArray(public_key));
337337
};
@@ -348,10 +348,10 @@ shared ({ caller = initializer }) actor class () {
348348
buf.append(Buffer.fromArray(Blob.toArray(Text.encodeUtf8(note.owner))));
349349
let derivation_id = Blob.fromArray(Buffer.toArray(buf)); // prefix-free
350350

351-
let { encrypted_key } = await vetkd_system_api.vetkd_encrypted_key({
351+
let { encrypted_key } = await vetkd_system_api.vetkd_derive_encrypted_key({
352352
derivation_id;
353-
public_key_derivation_path = Array.make(Text.encodeUtf8("note_symmetric_key"));
354-
key_id = { curve = #bls12_381; name = "test_key_1" };
353+
derivation_path = Array.make(Text.encodeUtf8("note_symmetric_key"));
354+
key_id = { curve = #bls12_381_g2; name = "test_key_1" };
355355
encryption_public_key;
356356
});
357357
Hex.encode(Blob.toArray(encrypted_key));

motoko/encrypted-notes-dapp-vetkd/src/encrypted_notes_rust/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ async fn symmetric_key_verification_key_for_note() -> String {
364364
let request = VetKDPublicKeyRequest {
365365
canister_id: None,
366366
derivation_path: vec![b"note_symmetric_key".to_vec()],
367-
key_id: bls12_381_test_key_1(),
367+
key_id: bls12_381_g2_test_key_1(),
368368
};
369369

370370
let (response,): (VetKDPublicKeyReply,) = ic_cdk::call(
@@ -396,8 +396,8 @@ async fn encrypted_symmetric_key_for_note(
396396
buf.extend_from_slice(note.owner.as_bytes());
397397
buf // prefix-free
398398
},
399-
public_key_derivation_path: vec![b"note_symmetric_key".to_vec()],
400-
key_id: bls12_381_test_key_1(),
399+
derivation_path: vec![b"note_symmetric_key".to_vec()],
400+
key_id: bls12_381_g2_test_key_1(),
401401
encryption_public_key,
402402
}
403403
} else {
@@ -407,18 +407,18 @@ async fn encrypted_symmetric_key_for_note(
407407

408408
let (response,): (VetKDEncryptedKeyReply,) = ic_cdk::call(
409409
vetkd_system_api_canister_id(),
410-
"vetkd_encrypted_key",
410+
"vetkd_derive_encrypted_key",
411411
(request,),
412412
)
413413
.await
414-
.expect("call to vetkd_encrypted_key failed");
414+
.expect("call to vetkd_derive_encrypted_key failed");
415415

416416
hex::encode(response.encrypted_key)
417417
}
418418

419-
fn bls12_381_test_key_1() -> VetKDKeyId {
419+
fn bls12_381_g2_test_key_1() -> VetKDKeyId {
420420
VetKDKeyId {
421-
curve: VetKDCurve::Bls12_381,
421+
curve: VetKDCurve::Bls12_381_G2,
422422
name: "test_key_1".to_string(),
423423
}
424424
}

motoko/encrypted-notes-dapp-vetkd/src/encrypted_notes_rust/src/vetkd_types.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ pub type CanisterId = Principal;
66

77
#[derive(CandidType, Deserialize)]
88
pub enum VetKDCurve {
9-
#[serde(rename = "bls12_381")]
10-
Bls12_381,
9+
#[serde(rename = "bls12_381_g2")]
10+
#[allow(non_camel_case_types)]
11+
Bls12_381_G2,
1112
}
1213

1314
#[derive(CandidType, Deserialize)]
@@ -30,7 +31,7 @@ pub struct VetKDPublicKeyReply {
3031

3132
#[derive(CandidType, Deserialize)]
3233
pub struct VetKDEncryptedKeyRequest {
33-
pub public_key_derivation_path: Vec<Vec<u8>>,
34+
pub derivation_path: Vec<Vec<u8>>,
3435
pub derivation_id: Vec<u8>,
3536
pub key_id: VetKDKeyId,
3637
pub encryption_public_key: Vec<u8>,

motoko/encrypted-notes-dapp-vetkd/vetkd_system_api.did

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
type canister_id = principal;
2-
type vetkd_curve = variant { bls12_381 };
2+
type vetkd_curve = variant { bls12_381_g2 };
33

44
service : {
55
vetkd_public_key : (
@@ -9,9 +9,9 @@ service : {
99
key_id : record { curve : vetkd_curve; name : text };
1010
}
1111
) -> (record { public_key : blob });
12-
vetkd_encrypted_key : (
12+
vetkd_derive_encrypted_key : (
1313
record {
14-
public_key_derivation_path : vec blob;
14+
derivation_path : vec blob;
1515
derivation_id : blob;
1616
key_id : record { curve : vetkd_curve; name : text };
1717
encryption_public_key : blob;
-128 KB
Binary file not shown.

motoko/vetkd/src/app_backend/Main.mo

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ actor {
1010
vetkd_public_key : ({
1111
canister_id : ?Principal;
1212
derivation_path : [Blob];
13-
key_id : { curve : { #bls12_381 }; name : Text };
13+
key_id : { curve : { #bls12_381_g2 }; name : Text };
1414
}) -> async ({ public_key : Blob });
15-
vetkd_encrypted_key : ({
16-
public_key_derivation_path : [Blob];
15+
vetkd_derive_encrypted_key : ({
16+
derivation_path : [Blob];
1717
derivation_id : Blob;
18-
key_id : { curve : { #bls12_381 }; name : Text };
18+
key_id : { curve : { #bls12_381_g2 }; name : Text };
1919
encryption_public_key : Blob;
2020
}) -> async ({ encrypted_key : Blob });
2121
};
@@ -26,7 +26,7 @@ actor {
2626
let { public_key } = await vetkd_system_api.vetkd_public_key({
2727
canister_id = null;
2828
derivation_path;
29-
key_id = { curve = #bls12_381; name = "test_key_1" };
29+
key_id = { curve = #bls12_381_g2; name = "test_key_1" };
3030
});
3131
Hex.encode(Blob.toArray(public_key));
3232
};
@@ -35,18 +35,18 @@ actor {
3535
let { public_key } = await vetkd_system_api.vetkd_public_key({
3636
canister_id = null;
3737
derivation_path = Array.make(Text.encodeUtf8("symmetric_key"));
38-
key_id = { curve = #bls12_381; name = "test_key_1" };
38+
key_id = { curve = #bls12_381_g2; name = "test_key_1" };
3939
});
4040
Hex.encode(Blob.toArray(public_key));
4141
};
4242

4343
public shared ({ caller }) func encrypted_symmetric_key_for_caller(encryption_public_key : Blob) : async Text {
4444
Debug.print("encrypted_symmetric_key_for_caller: caller: " # debug_show (caller));
4545

46-
let { encrypted_key } = await vetkd_system_api.vetkd_encrypted_key({
46+
let { encrypted_key } = await vetkd_system_api.vetkd_derive_encrypted_key({
4747
derivation_id = Principal.toBlob(caller);
48-
public_key_derivation_path = Array.make(Text.encodeUtf8("symmetric_key"));
49-
key_id = { curve = #bls12_381; name = "test_key_1" };
48+
derivation_path = Array.make(Text.encodeUtf8("symmetric_key"));
49+
key_id = { curve = #bls12_381_g2; name = "test_key_1" };
5050
encryption_public_key;
5151
});
5252
Hex.encode(Blob.toArray(encrypted_key));
@@ -56,18 +56,18 @@ actor {
5656
let { public_key } = await vetkd_system_api.vetkd_public_key({
5757
canister_id = null;
5858
derivation_path = Array.make(Text.encodeUtf8("ibe_encryption"));
59-
key_id = { curve = #bls12_381; name = "test_key_1" };
59+
key_id = { curve = #bls12_381_g2; name = "test_key_1" };
6060
});
6161
Hex.encode(Blob.toArray(public_key));
6262
};
6363

6464
public shared ({ caller }) func encrypted_ibe_decryption_key_for_caller(encryption_public_key : Blob) : async Text {
6565
Debug.print("encrypted_ibe_decryption_key_for_caller: caller: " # debug_show (caller));
6666

67-
let { encrypted_key } = await vetkd_system_api.vetkd_encrypted_key({
67+
let { encrypted_key } = await vetkd_system_api.vetkd_derive_encrypted_key({
6868
derivation_id = Principal.toBlob(caller);
69-
public_key_derivation_path = Array.make(Text.encodeUtf8("ibe_encryption"));
70-
key_id = { curve = #bls12_381; name = "test_key_1" };
69+
derivation_path = Array.make(Text.encodeUtf8("ibe_encryption"));
70+
key_id = { curve = #bls12_381_g2; name = "test_key_1" };
7171
encryption_public_key;
7272
});
7373
Hex.encode(Blob.toArray(encrypted_key));

motoko/vetkd/src/system_api/src/types.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ pub type CanisterId = Principal;
66

77
#[derive(CandidType, Deserialize, Eq, PartialEq)]
88
pub enum VetKDCurve {
9-
#[serde(rename = "bls12_381")]
10-
Bls12_381,
9+
#[serde(rename = "bls12_381_g2")]
10+
#[allow(non_camel_case_types)]
11+
Bls12_381_G2,
1112
}
1213

1314
#[derive(CandidType, Deserialize, Eq, PartialEq)]
@@ -30,7 +31,7 @@ pub struct VetKDPublicKeyReply {
3031

3132
#[derive(CandidType, Deserialize)]
3233
pub struct VetKDEncryptedKeyRequest {
33-
pub public_key_derivation_path: Vec<Vec<u8>>,
34+
pub derivation_path: Vec<Vec<u8>>,
3435
pub derivation_id: Vec<u8>,
3536
pub key_id: VetKDKeyId,
3637
pub encryption_public_key: Vec<u8>,

motoko/vetkd/src/system_api/vetkd_system_api.did

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
type canister_id = principal;
2-
type vetkd_curve = variant { bls12_381 };
2+
type vetkd_curve = variant { bls12_381_g2 };
33

44
service : {
55
vetkd_public_key : (
@@ -9,9 +9,9 @@ service : {
99
key_id : record { curve : vetkd_curve; name : text };
1010
}
1111
) -> (record { public_key : blob });
12-
vetkd_encrypted_key : (
12+
vetkd_derive_encrypted_key : (
1313
record {
14-
public_key_derivation_path : vec blob;
14+
derivation_path : vec blob;
1515
derivation_id : blob;
1616
key_id : record { curve : vetkd_curve; name : text };
1717
encryption_public_key : blob;

rust/vetkd/src/app_backend/src/lib.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ async fn symmetric_key_verification_key() -> String {
1414
let request = VetKDPublicKeyRequest {
1515
canister_id: None,
1616
derivation_path: vec![b"symmetric_key".to_vec()],
17-
key_id: bls12_381_test_key_1(),
17+
key_id: bls12_381_g2_test_key_1(),
1818
};
1919

2020
let (response,): (VetKDPublicKeyReply,) = ic_cdk::api::call::call(
@@ -34,18 +34,18 @@ async fn encrypted_symmetric_key_for_caller(encryption_public_key: Vec<u8>) -> S
3434

3535
let request = VetKDEncryptedKeyRequest {
3636
derivation_id: ic_cdk::caller().as_slice().to_vec(),
37-
public_key_derivation_path: vec![b"symmetric_key".to_vec()],
38-
key_id: bls12_381_test_key_1(),
37+
derivation_path: vec![b"symmetric_key".to_vec()],
38+
key_id: bls12_381_g2_test_key_1(),
3939
encryption_public_key,
4040
};
4141

4242
let (response,): (VetKDEncryptedKeyReply,) = ic_cdk::api::call::call(
4343
vetkd_system_api_canister_id(),
44-
"vetkd_encrypted_key",
44+
"vetkd_derive_encrypted_key",
4545
(request,),
4646
)
4747
.await
48-
.expect("call to vetkd_encrypted_key failed");
48+
.expect("call to vetkd_derive_encrypted_key failed");
4949

5050
hex::encode(response.encrypted_key)
5151
}
@@ -55,7 +55,7 @@ async fn ibe_encryption_key() -> String {
5555
let request = VetKDPublicKeyRequest {
5656
canister_id: None,
5757
derivation_path: vec![b"ibe_encryption".to_vec()],
58-
key_id: bls12_381_test_key_1(),
58+
key_id: bls12_381_g2_test_key_1(),
5959
};
6060

6161
let (response,): (VetKDPublicKeyReply,) = ic_cdk::api::call::call(
@@ -75,25 +75,25 @@ async fn encrypted_ibe_decryption_key_for_caller(encryption_public_key: Vec<u8>)
7575

7676
let request = VetKDEncryptedKeyRequest {
7777
derivation_id: ic_cdk::caller().as_slice().to_vec(),
78-
public_key_derivation_path: vec![b"ibe_encryption".to_vec()],
79-
key_id: bls12_381_test_key_1(),
78+
derivation_path: vec![b"ibe_encryption".to_vec()],
79+
key_id: bls12_381_g2_test_key_1(),
8080
encryption_public_key,
8181
};
8282

8383
let (response,): (VetKDEncryptedKeyReply,) = ic_cdk::api::call::call(
8484
vetkd_system_api_canister_id(),
85-
"vetkd_encrypted_key",
85+
"vetkd_derive_encrypted_key",
8686
(request,),
8787
)
8888
.await
89-
.expect("call to vetkd_encrypted_key failed");
89+
.expect("call to vetkd_derive_encrypted_key failed");
9090

9191
hex::encode(response.encrypted_key)
9292
}
9393

94-
fn bls12_381_test_key_1() -> VetKDKeyId {
94+
fn bls12_381_g2_test_key_1() -> VetKDKeyId {
9595
VetKDKeyId {
96-
curve: VetKDCurve::Bls12_381,
96+
curve: VetKDCurve::Bls12_381_G2,
9797
name: "test_key_1".to_string(),
9898
}
9999
}

rust/vetkd/src/app_backend/src/types.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ pub type CanisterId = Principal;
66

77
#[derive(CandidType, Deserialize)]
88
pub enum VetKDCurve {
9-
#[serde(rename = "bls12_381")]
10-
Bls12_381,
9+
#[serde(rename = "bls12_381_g2")]
10+
#[allow(non_camel_case_types)]
11+
Bls12_381_G2,
1112
}
1213

1314
#[derive(CandidType, Deserialize)]
@@ -30,7 +31,7 @@ pub struct VetKDPublicKeyReply {
3031

3132
#[derive(CandidType, Deserialize)]
3233
pub struct VetKDEncryptedKeyRequest {
33-
pub public_key_derivation_path: Vec<Vec<u8>>,
34+
pub derivation_path: Vec<Vec<u8>>,
3435
pub derivation_id: Vec<u8>,
3536
pub key_id: VetKDKeyId,
3637
pub encryption_public_key: Vec<u8>,

0 commit comments

Comments
 (0)