Skip to content

Commit dd255c8

Browse files
authored
chore: CRP-2823 minor refactoring for dev docs (#138)
- Omit root from root IBE public key. - Reorganize timelock example to show as less use case related info as possible for decryption.
1 parent b79f3e3 commit dd255c8

File tree

13 files changed

+160
-149
lines changed

13 files changed

+160
-149
lines changed

examples/basic_ibe/backend/backend.did

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ type SendMessageRequest = record {
1010
receiver : principal;
1111
};
1212
service : (text) -> {
13+
get_ibe_public_key : () -> (blob);
1314
get_my_encrypted_ibe_key : (blob) -> (blob);
1415
get_my_messages : () -> (Inbox) query;
15-
get_root_ibe_public_key : () -> (blob);
1616
remove_my_message_by_index : (nat64) -> (Result);
1717
send_message : (SendMessageRequest) -> (Result);
1818
}

examples/basic_ibe/backend/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn send_message(request: SendMessageRequest) -> Result<(), String> {
6868
}
6969

7070
#[update]
71-
async fn get_root_ibe_public_key() -> VetKeyPublicKey {
71+
async fn get_ibe_public_key() -> VetKeyPublicKey {
7272
let request = VetKDPublicKeyArgs {
7373
canister_id: None,
7474
context: DOMAIN_SEPARATOR.as_bytes().to_vec(),

examples/basic_ibe/frontend/src/main.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
import { AuthClient } from "@dfinity/auth-client";
1818
import type { ActorSubclass } from "@dfinity/agent";
1919

20-
// Store the IBE key in memory
2120
let ibePrivateKey: VetKey | undefined = undefined;
2221
let ibePublicKey: DerivedPublicKey | undefined = undefined;
2322
let myPrincipal: Principal | undefined = undefined;
@@ -47,11 +46,10 @@ function getBasicIbeCanister(): ActorSubclass<_SERVICE> {
4746
return basicIbeCanister;
4847
}
4948

50-
// Get the root IBE public key
51-
async function getRootIbePublicKey(): Promise<DerivedPublicKey> {
49+
async function getIbePublicKey(): Promise<DerivedPublicKey> {
5250
if (ibePublicKey) return ibePublicKey;
5351
ibePublicKey = DerivedPublicKey.deserialize(
54-
new Uint8Array(await getBasicIbeCanister().get_root_ibe_public_key()),
52+
new Uint8Array(await getBasicIbeCanister().get_ibe_public_key()),
5553
);
5654
return ibePublicKey;
5755
}
@@ -60,7 +58,7 @@ async function encrypt(
6058
cleartext: Uint8Array,
6159
receiver: Principal,
6260
): Promise<Uint8Array> {
63-
const publicKey = await getRootIbePublicKey();
61+
const publicKey = await getIbePublicKey();
6462
const ciphertext = IbeCiphertext.encrypt(
6563
publicKey,
6664
IbeIdentity.fromPrincipal(receiver),
@@ -70,7 +68,6 @@ async function encrypt(
7068
return ciphertext.serialize();
7169
}
7270

73-
// Get the user's encrypted IBE key
7471
async function getMyIbePrivateKey(): Promise<VetKey> {
7572
if (ibePrivateKey) return ibePrivateKey;
7673

@@ -85,7 +82,7 @@ async function getMyIbePrivateKey(): Promise<VetKey> {
8582
);
8683
ibePrivateKey = new EncryptedVetKey(encryptedKey).decryptAndVerify(
8784
transportSecretKey,
88-
await getRootIbePublicKey(),
85+
await getIbePublicKey(),
8986
new Uint8Array(myPrincipal.toUint8Array()),
9087
);
9188
return ibePrivateKey;
@@ -99,7 +96,6 @@ async function decryptMessage(encryptedMessage: Uint8Array): Promise<string> {
9996
return new TextDecoder().decode(plaintext);
10097
}
10198

102-
// Send a message
10399
async function sendMessage() {
104100
const message = prompt("Enter your message:");
105101
if (!message) throw Error("Message is required");

examples/basic_ibe/src/declarations/basic_ibe/basic_ibe.did

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ type SendMessageRequest = record {
1010
receiver : principal;
1111
};
1212
service : (text) -> {
13+
get_ibe_public_key : () -> (blob);
1314
get_my_encrypted_ibe_key : (blob) -> (blob);
1415
get_my_messages : () -> (Inbox) query;
15-
get_root_ibe_public_key : () -> (blob);
1616
remove_my_message_by_index : (nat64) -> (Result);
1717
send_message : (SendMessageRequest) -> (Result);
1818
}

examples/basic_ibe/src/declarations/basic_ibe/basic_ibe.did.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ export interface SendMessageRequest {
1515
'receiver' : Principal,
1616
}
1717
export interface _SERVICE {
18+
'get_ibe_public_key' : ActorMethod<[], Uint8Array | number[]>,
1819
'get_my_encrypted_ibe_key' : ActorMethod<
1920
[Uint8Array | number[]],
2021
Uint8Array | number[]
2122
>,
2223
'get_my_messages' : ActorMethod<[], Inbox>,
23-
'get_root_ibe_public_key' : ActorMethod<[], Uint8Array | number[]>,
2424
'remove_my_message_by_index' : ActorMethod<[bigint], Result>,
2525
'send_message' : ActorMethod<[SendMessageRequest], Result>,
2626
}

examples/basic_ibe/src/declarations/basic_ibe/basic_ibe.did.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ export const idlFactory = ({ IDL }) => {
1111
'receiver' : IDL.Principal,
1212
});
1313
return IDL.Service({
14+
'get_ibe_public_key' : IDL.Func([], [IDL.Vec(IDL.Nat8)], []),
1415
'get_my_encrypted_ibe_key' : IDL.Func(
1516
[IDL.Vec(IDL.Nat8)],
1617
[IDL.Vec(IDL.Nat8)],
1718
[],
1819
),
1920
'get_my_messages' : IDL.Func([], [Inbox], ['query']),
20-
'get_root_ibe_public_key' : IDL.Func([], [IDL.Vec(IDL.Nat8)], []),
2121
'remove_my_message_by_index' : IDL.Func([IDL.Nat64], [Result], []),
2222
'send_message' : IDL.Func([SendMessageRequest], [Result], []),
2323
});

examples/basic_timelock_ibe/backend/backend.did

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ type Result = variant { Ok : nat; Err : text };
2020
type Result_1 = variant { Ok; Err : text };
2121
service : (text) -> {
2222
create_lot : (text, text, nat16) -> (Result);
23+
get_ibe_public_key : () -> (blob);
2324
get_lots : () -> (OpenLotsResponse, ClosedLotsResponse) query;
24-
get_root_ibe_public_key : () -> (blob);
2525
place_bid : (nat, blob) -> (Result_1);
26-
start_with_interval_secs : (nat64) -> ();
26+
start_lot_closing_timer_job_with_interval_secs : (nat64) -> ();
2727
}

0 commit comments

Comments
 (0)