@@ -17,7 +17,6 @@ import {
1717import { AuthClient } from "@dfinity/auth-client" ;
1818import type { ActorSubclass } from "@dfinity/agent" ;
1919
20- // Store the IBE key in memory
2120let ibePrivateKey : VetKey | undefined = undefined ;
2221let ibePublicKey : DerivedPublicKey | undefined = undefined ;
2322let 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
7471async 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
10399async function sendMessage ( ) {
104100 const message = prompt ( "Enter your message:" ) ;
105101 if ( ! message ) throw Error ( "Message is required" ) ;
0 commit comments