@@ -7,10 +7,9 @@ import Result "mo:base/Result";
77import Array "mo:base/Array" ;
88
99persistent actor class (keyName : Text ) {
10- let encryptedMapsState = IcVetkeys . EncryptedMaps . newEncryptedMapsState< Types . AccessRights > (
11- { curve = #bls12_381_g2; name = keyName },
12- "encrypted maps dapp" ,
13- );
10+ let encryptedMapsState = IcVetkeys . EncryptedMaps . newEncryptedMapsState< Types . AccessRights > ({ curve = #bls12_381_g2; name = "" }, "encrypted maps dapp" );
11+ encryptedMapsState. keyManager. vetKdKeyId := { curve = #bls12_381_g2; name = keyName };
12+ transient let encryptedMaps = IcVetkeys . EncryptedMaps . EncryptedMaps < Types . AccessRights > (encryptedMapsState, Types . accessRightsOperations());
1413
1514 // / In this canister, we use the `ByteBuf` type to represent blobs. The reason is that we want to be consistent with the Rust canister implementation.
1615 // / Unfortunately, the `Blob` type cannot be serialized/deserialized in the current Rust implementation efficiently without nesting it in another type.
@@ -35,7 +34,7 @@ persistent actor class (keyName : Text) {
3534
3635 public query (msg) func get_accessible_shared_map_names() : async [(Principal , ByteBuf )] {
3736 Array . map< (Principal , Blob ), (Principal , ByteBuf )> (
38- getEncryptedMaps() . getAccessibleSharedMapNames(msg. caller),
37+ encryptedMaps . getAccessibleSharedMapNames(msg. caller),
3938
4039 func ((principal, blob) : (Principal , Blob )) {
4140 (principal, { inner = blob });
@@ -47,14 +46,14 @@ persistent actor class (keyName : Text) {
4746 map_owner : Principal ,
4847 map_name : ByteBuf ,
4948 ) : async Result < [(Principal , Types . AccessRights )], Text > {
50- convertResult(getEncryptedMaps() . getSharedUserAccessForMap(msg. caller, (map_owner, map_name. inner)));
49+ convertResult(encryptedMaps . getSharedUserAccessForMap(msg. caller, (map_owner, map_name. inner)));
5150 };
5251
5352 public query (msg) func get_encrypted_values_for_map(
5453 map_owner : Principal ,
5554 map_name : ByteBuf ,
5655 ) : async Result < [(ByteBuf , ByteBuf )], Text > {
57- let result = getEncryptedMaps() . getEncryptedValuesForMap(msg. caller, (map_owner, map_name. inner));
56+ let result = encryptedMaps . getEncryptedValuesForMap(msg. caller, (map_owner, map_name. inner));
5857 switch (result) {
5958 case (#err(e)) { #Err (e) };
6059 case (#ok(values)) {
@@ -72,7 +71,7 @@ persistent actor class (keyName : Text) {
7271
7372 public query (msg) func get_all_accessible_encrypted_values() : async [((Principal , ByteBuf ), [(ByteBuf , ByteBuf )])] {
7473 Array . map< ((Principal , Blob ), [(Blob , Blob )]), ((Principal , ByteBuf ), [(ByteBuf , ByteBuf )])> (
75- getEncryptedMaps() . getAllAccessibleEncryptedValues(msg. caller),
74+ encryptedMaps . getAllAccessibleEncryptedValues(msg. caller),
7675 func (((owner, map_name), values) : ((Principal , Blob ), [(Blob , Blob )])) {
7776 (
7877 (owner, { inner = map_name }),
@@ -89,7 +88,7 @@ persistent actor class (keyName : Text) {
8988
9089 public query (msg) func get_all_accessible_encrypted_maps() : async [EncryptedMapData ] {
9190 Array . map< IcVetkeys . EncryptedMaps . EncryptedMapData < Types . AccessRights > , EncryptedMapData > (
92- getEncryptedMaps() . getAllAccessibleEncryptedMaps(msg. caller),
91+ encryptedMaps . getAllAccessibleEncryptedMaps(msg. caller),
9392 func (map : IcVetkeys . EncryptedMaps . EncryptedMapData < Types . AccessRights > ) : EncryptedMapData {
9493 {
9594 map_owner = map. map_owner;
@@ -111,7 +110,7 @@ persistent actor class (keyName : Text) {
111110 map_name : ByteBuf ,
112111 map_key : ByteBuf ,
113112 ) : async Result < ?ByteBuf , Text > {
114- let result = getEncryptedMaps() . getEncryptedValue(msg. caller, (map_owner, map_name. inner), map_key. inner);
113+ let result = encryptedMaps . getEncryptedValue(msg. caller, (map_owner, map_name. inner), map_key. inner);
115114 switch (result) {
116115 case (#err(e)) { #Err (e) };
117116 case (#ok(null )) { #Ok (null ) };
@@ -123,7 +122,7 @@ persistent actor class (keyName : Text) {
123122 map_owner : Principal ,
124123 map_name : ByteBuf ,
125124 ) : async Result < [ByteBuf ], Text > {
126- let result = getEncryptedMaps() . removeMapValues(msg. caller, (map_owner, map_name. inner));
125+ let result = encryptedMaps . removeMapValues(msg. caller, (map_owner, map_name. inner));
127126 switch (result) {
128127 case (#err(e)) { #Err (e) };
129128 case (#ok(values)) {
@@ -141,7 +140,7 @@ persistent actor class (keyName : Text) {
141140
142141 public query (msg) func get_owned_non_empty_map_names() : async [ByteBuf ] {
143142 Array . map< Blob , ByteBuf > (
144- getEncryptedMaps() . getOwnedNonEmptyMapNames(msg. caller),
143+ encryptedMaps . getOwnedNonEmptyMapNames(msg. caller),
145144 func (blob : Blob ) : ByteBuf {
146145 { inner = blob };
147146 },
@@ -154,7 +153,8 @@ persistent actor class (keyName : Text) {
154153 map_key : ByteBuf ,
155154 value : ByteBuf ,
156155 ) : async Result < ?ByteBuf , Text > {
157- let result = getEncryptedMaps(). insertEncryptedValue(msg. caller, (map_owner, map_name. inner), map_key. inner, value. inner);
156+ let result = encryptedMaps. insertEncryptedValue(msg. caller, (map_owner, map_name. inner), map_key. inner, value. inner);
157+
158158 switch (result) {
159159 case (#err(e)) { #Err (e) };
160160 case (#ok(null )) { #Ok (null ) };
@@ -167,7 +167,7 @@ persistent actor class (keyName : Text) {
167167 map_name : ByteBuf ,
168168 map_key : ByteBuf ,
169169 ) : async Result < ?ByteBuf , Text > {
170- let result = getEncryptedMaps() . removeEncryptedValue(msg. caller, (map_owner, map_name. inner), map_key. inner);
170+ let result = encryptedMaps . removeEncryptedValue(msg. caller, (map_owner, map_name. inner), map_key. inner);
171171 switch (result) {
172172 case (#err(e)) { #Err (e) };
173173 case (#ok(null )) { #Ok (null ) };
@@ -176,7 +176,7 @@ persistent actor class (keyName : Text) {
176176 };
177177
178178 public shared func get_vetkey_verification_key() : async ByteBuf {
179- let inner = await getEncryptedMaps() . getVetkeyVerificationKey();
179+ let inner = await encryptedMaps . getVetkeyVerificationKey();
180180 { inner };
181181 };
182182
@@ -185,7 +185,7 @@ persistent actor class (keyName : Text) {
185185 map_name : ByteBuf ,
186186 transport_key : ByteBuf ,
187187 ) : async Result < ByteBuf , Text > {
188- let result = await getEncryptedMaps() . getEncryptedVetkey(msg. caller, (map_owner, map_name. inner), transport_key. inner);
188+ let result = await encryptedMaps . getEncryptedVetkey(msg. caller, (map_owner, map_name. inner), transport_key. inner);
189189 switch (result) {
190190 case (#err(e)) { #Err (e) };
191191 case (#ok(vetkey)) { #Ok ({ inner = vetkey }) };
@@ -197,7 +197,7 @@ persistent actor class (keyName : Text) {
197197 map_name : ByteBuf ,
198198 user : Principal ,
199199 ) : async Result < ?Types . AccessRights , Text > {
200- convertResult(getEncryptedMaps() . getUserRights(msg. caller, (map_owner, map_name. inner), user));
200+ convertResult(encryptedMaps . getUserRights(msg. caller, (map_owner, map_name. inner), user));
201201 };
202202
203203 public shared (msg) func set_user_rights(
@@ -206,15 +206,15 @@ persistent actor class (keyName : Text) {
206206 user : Principal ,
207207 access_rights : Types . AccessRights ,
208208 ) : async Result < ?Types . AccessRights , Text > {
209- convertResult(getEncryptedMaps() . setUserRights(msg. caller, (map_owner, map_name. inner), user, access_rights));
209+ convertResult(encryptedMaps . setUserRights(msg. caller, (map_owner, map_name. inner), user, access_rights));
210210 };
211211
212212 public shared (msg) func remove_user(
213213 map_owner : Principal ,
214214 map_name : ByteBuf ,
215215 user : Principal ,
216216 ) : async Result < ?Types . AccessRights , Text > {
217- convertResult(getEncryptedMaps() . removeUser(msg. caller, (map_owner, map_name. inner), user));
217+ convertResult(encryptedMaps . removeUser(msg. caller, (map_owner, map_name. inner), user));
218218 };
219219
220220 // / Convert to the result type compatible with Rust's `Result`
0 commit comments