@icp-sdk/vetkeys 0.5.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,466 @@
1
+ import { Principal } from '@icp-sdk/core/principal';
2
+ import { DerivedKeyMaterial } from '../utils/utils';
3
+ import { AccessRights, ByteBuf } from '../declarations/ic_vetkeys_manager_canister/ic_vetkeys_manager_canister.did.js';
4
+ export { DefaultEncryptedMapsClient } from './encrypted_maps_canister';
5
+ export type { AccessRights, ByteBuf, } from '../declarations/ic_vetkeys_manager_canister/ic_vetkeys_manager_canister.did.js';
6
+ /**
7
+ * The **EncryptedMaps** frontend library facilitates interaction with an [**EncryptedMaps-enabled canister**](https://docs.rs/ic-vetkeys/latest/ic_vetkeys/encrypted_maps/struct.EncryptedMaps.html) on the **Internet Computer (ICP)**.
8
+ * It allows web applications to securely store, retrieve, and manage encrypted key-value pairs within named maps while handling user access control and key sharing.
9
+ *
10
+ * ## Core Features
11
+ *
12
+ * - **Encrypted Key-Value Storage**: Store and retrieve encrypted key-value pairs within named maps.
13
+ * - **Retrieve Encrypted VetKeys**: Fetch encrypted VetKeys and decrypt them locally using a **transport secret key**.
14
+ * - **Shared Maps Access Information**: Query which maps a user has access to.
15
+ * - **Manage User Access**: Assign, modify, and revoke user rights on stored maps.
16
+ * - **Retrieve VetKey Verification Key**: Fetch the public verification key for validating VetKeys.
17
+ *
18
+ * ## Security Considerations
19
+ *
20
+ * - **Access Rights** should be carefully managed to prevent unauthorized access.
21
+ * - VetKeys should be decrypted **only in trusted environments** such as user browsers to prevent leaks.
22
+ *
23
+ */
24
+ export declare class EncryptedMaps {
25
+ /**
26
+ * The client instance for interacting with the EncryptedMaps canister.
27
+ */
28
+ canisterClient: EncryptedMapsClient;
29
+ /**
30
+ * The cached verification key for validating encrypted VetKeys.
31
+ */
32
+ verificationKey: Uint8Array | undefined;
33
+ /**
34
+ * Creates a new instance of the EncryptedMaps client.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * import { EncryptedMaps } from "@icp-sdk/vetkeys/encrypted_maps";
39
+ *
40
+ * const encryptedMaps = new EncryptedMaps(encryptedMapsClientInstance);
41
+ * ```
42
+ */
43
+ constructor(canisterClient: EncryptedMapsClient);
44
+ /**
45
+ * Retrieves a list of maps that were shared with the user and the user still has access to.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const sharedMaps = await encryptedMaps.getAccessibleSharedMapNames();
50
+ * console.log("Shared Maps:", sharedMaps);
51
+ * ```
52
+ *
53
+ * @returns Promise resolving to an array of `[Principal, Uint8Array]` pairs representing accessible map identifiers.
54
+ */
55
+ getAccessibleSharedMapNames(): Promise<[Principal, Uint8Array][]>;
56
+ /**
57
+ * Retrieves a list of non-empty maps owned by the caller.
58
+ *
59
+ * @returns Promise resolving to an array of map names
60
+ */
61
+ getOwnedNonEmptyMapNames(): Promise<Array<Uint8Array>>;
62
+ /**
63
+ * Retrieves all accessible values across all maps the user has access to.
64
+ *
65
+ * @returns Promise resolving to an array of map data with decrypted values
66
+ */
67
+ getAllAccessibleValues(): Promise<Array<[[Principal, Uint8Array], Array<[Uint8Array, Uint8Array]>]>>;
68
+ /**
69
+ * Retrieves all accessible maps with their decrypted values.
70
+ *
71
+ * @returns Promise resolving to an array of map data
72
+ */
73
+ getAllAccessibleMaps(): Promise<Array<MapData>>;
74
+ /**
75
+ * Retrieves and decrypts a stored value from a map.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * const mapOwner = Principal.fromText("aaaaa-aa");
80
+ * const mapName = "passwords";
81
+ * const mapKey = "email_account";
82
+ *
83
+ * const storedValue = await encryptedMaps.getValue(mapOwner, mapName, mapKey);
84
+ * console.log("Decrypted Value:", new TextDecoder().decode(storedValue));
85
+ * ```
86
+ *
87
+ * @param mapOwner - The principal of the map owner
88
+ * @param mapName - The name/identifier of the map
89
+ * @param mapKey - The key to retrieve
90
+ * @returns Promise resolving to the decrypted value
91
+ * @throws Error if the operation fails
92
+ */
93
+ getValue(mapOwner: Principal, mapName: Uint8Array, mapKey: Uint8Array): Promise<Uint8Array>;
94
+ /**
95
+ * Retrieves all values from a specific map.
96
+ *
97
+ * @param mapOwner - The principal of the map owner
98
+ * @param mapName - The name/identifier of the map
99
+ * @returns Promise resolving to an array of key-value pairs
100
+ * @throws Error if the operation fails
101
+ */
102
+ getValuesForMap(mapOwner: Principal, mapName: Uint8Array): Promise<Array<[Uint8Array, Uint8Array]>>;
103
+ /**
104
+ * Stores an encrypted value in a map.
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * const value = new TextEncoder().encode("my_secure_password");
109
+ * const result = await encryptedMaps.setValue(mapOwner, mapName, mapKey, value);
110
+ * console.log("Replaced Value:", result);
111
+ * ```
112
+ *
113
+ * @param mapOwner - The principal of the map owner
114
+ * @param mapName - The name/identifier of the map
115
+ * @param mapKey - The key to store
116
+ * @param data - The value to store
117
+ * @returns Promise resolving to the previous value if it existed
118
+ * @throws Error if the operation fails
119
+ */
120
+ setValue(mapOwner: Principal, mapName: Uint8Array, mapKey: Uint8Array, data: Uint8Array): Promise<Uint8Array | undefined>;
121
+ /**
122
+ * Removes a value from a map.
123
+ *
124
+ * @param mapOwner - The principal of the map owner
125
+ * @param mapName - The name/identifier of the map
126
+ * @param mapKey - The key to remove
127
+ * @returns Promise resolving to the removed value if it existed
128
+ * @throws Error if the operation fails
129
+ */
130
+ removeEncryptedValue(mapOwner: Principal, mapName: Uint8Array, mapKey: Uint8Array): Promise<Uint8Array | undefined>;
131
+ /**
132
+ * Removes all values from a map.
133
+ *
134
+ * @param mapOwner - The principal of the map owner
135
+ * @param mapName - The name/identifier of the map
136
+ * @returns Promise resolving to an array of removed keys
137
+ * @throws Error if the operation fails
138
+ */
139
+ removeMapValues(mapOwner: Principal, mapName: Uint8Array): Promise<Array<Uint8Array>>;
140
+ /**
141
+ * Retrieves the public verification key for validating encrypted VetKeys.
142
+ * The vetkeys obtained via `getVetkey` are verified using this key,
143
+ * and, therefore, this method is not needed for using `getVetkey`.
144
+ *
145
+ * @example
146
+ * ```ts
147
+ * const verificationKey = await encryptedMaps.getVetkeyVerificationKey();
148
+ * console.log("Verification Key:", verificationKey);
149
+ * ```
150
+ *
151
+ * @returns Promise resolving to the verification key bytes
152
+ */
153
+ getVetkeyVerificationKey(): Promise<Uint8Array>;
154
+ /**
155
+ * Grants or modifies access rights for a user.
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * const owner = Principal.fromText("aaaaa-aa");
160
+ * const user = Principal.fromText("bbbbbb-bb");
161
+ * const accessRights = { ReadWrite: null };
162
+ *
163
+ * const result = await encryptedMaps.setUserRights(
164
+ * owner,
165
+ * mapName,
166
+ * user,
167
+ * accessRights,
168
+ * );
169
+ * console.log("Access Rights Updated:", result);
170
+ * ```
171
+ *
172
+ * @param owner - The principal of the map owner
173
+ * @param mapName - The name/identifier of the map
174
+ * @param user - The principal of the user to grant/modify rights for
175
+ * @param userRights - The access rights to grant
176
+ * @returns Promise resolving to the previous access rights if they existed
177
+ * @throws Error if the operation fails
178
+ */
179
+ setUserRights(owner: Principal, mapName: Uint8Array, user: Principal, userRights: AccessRights): Promise<AccessRights | undefined>;
180
+ /**
181
+ * Checks a user's access rights.
182
+ *
183
+ * @example
184
+ * ```ts
185
+ * const userRights = await encryptedMaps.getUserRights(owner, mapName, user);
186
+ * console.log("User Access Rights:", userRights);
187
+ * ```
188
+ *
189
+ * @param owner - The principal of the map owner
190
+ * @param mapName - The name/identifier of the map
191
+ * @param user - The principal of the user to check rights for
192
+ * @returns Promise resolving to the user's access rights if they exist
193
+ * @throws Error if the operation fails
194
+ */
195
+ getUserRights(owner: Principal, mapName: Uint8Array, user: Principal): Promise<AccessRights | undefined>;
196
+ /**
197
+ * Gets all users that have access to a map and their access rights.
198
+ *
199
+ * @param owner - The principal of the map owner
200
+ * @param mapName - The name/identifier of the map
201
+ * @returns Promise resolving to an array of user-access rights pairs
202
+ * @throws Error if the operation fails
203
+ */
204
+ getSharedUserAccessForMap(owner: Principal, mapName: Uint8Array): Promise<Array<[Principal, AccessRights]>>;
205
+ /**
206
+ * Revokes a user's access.
207
+ *
208
+ * @example
209
+ * ```ts
210
+ * const removalResult = await encryptedMaps.removeUser(owner, mapName, user);
211
+ * console.log("User Removed:", removalResult);
212
+ * ```
213
+ *
214
+ * @param owner - The principal of the map owner
215
+ * @param mapName - The name/identifier of the map
216
+ * @param user - The principal of the user to remove
217
+ * @returns Promise resolving to the previous access rights if they existed
218
+ * @throws Error if the operation fails
219
+ */
220
+ removeUser(owner: Principal, mapName: Uint8Array, user: Principal): Promise<AccessRights | undefined>;
221
+ /**
222
+ * Derives a key material for a specific map.
223
+ *
224
+ * @param mapOwner - The principal of the map owner
225
+ * @param mapName - The name/identifier of the map
226
+ * @returns Promise resolving to the derived key material
227
+ * @throws Error if the operation fails
228
+ */
229
+ getDerivedKeyMaterial(mapOwner: Principal, mapName: Uint8Array): Promise<DerivedKeyMaterial>;
230
+ /**
231
+ * Encrypts a value for a specific map and key.
232
+ *
233
+ * @param mapOwner - The principal of the map owner
234
+ * @param mapName - The name/identifier of the map
235
+ * @param mapKey - The key to encrypt for
236
+ * @param cleartext - The value to encrypt
237
+ * @returns Promise resolving to the encrypted value
238
+ */
239
+ encryptFor(mapOwner: Principal, mapName: Uint8Array, mapKey: Uint8Array, cleartext: Uint8Array): Promise<Uint8Array>;
240
+ /**
241
+ * Decrypts a value for a specific map and key.
242
+ *
243
+ * @param mapOwner - The principal of the map owner
244
+ * @param mapName - The name/identifier of the map
245
+ * @param mapKey - The key to decrypt for
246
+ * @param encryptedValue - The value to decrypt
247
+ * @returns Promise resolving to the decrypted value
248
+ */
249
+ decryptFor(mapOwner: Principal, mapName: Uint8Array, mapKey: Uint8Array, encryptedValue: Uint8Array): Promise<Uint8Array>;
250
+ /**
251
+ * Gets or fetches the derived key material for a map.
252
+ *
253
+ * @param mapOwner - The principal of the map owner
254
+ * @param mapName - The name/identifier of the map
255
+ * @returns Promise resolving to the derived key material
256
+ */
257
+ getDerivedKeyMaterialOrFetchIfNeeded(mapOwner: Principal, mapName: Uint8Array): Promise<DerivedKeyMaterial>;
258
+ }
259
+ /**
260
+ * Interface for map data structure.
261
+ */
262
+ export interface MapData {
263
+ accessControl: Array<[Principal, AccessRights]>;
264
+ keyvals: Array<[Uint8Array, Uint8Array]>;
265
+ mapName: Uint8Array;
266
+ mapOwner: Principal;
267
+ }
268
+ /**
269
+ * An interface that maps `EncryptedMaps` calls to IC canister calls that will call the respective method of the backend `EncryptedMaps`.
270
+ * For example, `get_user_rights` will call the `get_user_rights` method of the backend `EncryptedMaps`.
271
+ */
272
+ export interface EncryptedMapsClient {
273
+ /**
274
+ * Retrieves a list of maps that were shared with the user and the user still has access to.
275
+ *
276
+ * @returns Promise resolving to an array of `[Principal, ByteBuf]` pairs representing accessible map identifiers.
277
+ */
278
+ get_accessible_shared_map_names(): Promise<[Principal, ByteBuf][]>;
279
+ /**
280
+ * Gets all users that have access to a map and their access rights.
281
+ *
282
+ * @param owner - The principal of the map owner
283
+ * @param mapName - The name/identifier of the map
284
+ * @returns Promise resolving to an array of user-access rights pairs, or an error if the operation fails
285
+ */
286
+ get_shared_user_access_for_map(owner: Principal, mapName: ByteBuf): Promise<{
287
+ Ok: Array<[Principal, AccessRights]>;
288
+ } | {
289
+ Err: string;
290
+ }>;
291
+ /**
292
+ * Retrieves a list of non-empty maps owned by the caller.
293
+ *
294
+ * @returns Promise resolving to an array of map names
295
+ */
296
+ get_owned_non_empty_map_names(): Promise<Array<ByteBuf>>;
297
+ /**
298
+ * Retrieves all accessible values across all maps the user has access to.
299
+ *
300
+ * @returns Promise resolving to an array of map data with encrypted values
301
+ */
302
+ get_all_accessible_encrypted_values(): Promise<[
303
+ [Principal, ByteBuf],
304
+ [ByteBuf, ByteBuf][]
305
+ ][]>;
306
+ /**
307
+ * Retrieves all accessible maps with their encrypted values.
308
+ *
309
+ * @returns Promise resolving to an array of encrypted map data
310
+ */
311
+ get_all_accessible_encrypted_maps(): Promise<Array<EncryptedMapData>>;
312
+ /**
313
+ * Retrieves an encrypted value from a map.
314
+ *
315
+ * @param mapOwner - The principal of the map owner
316
+ * @param mapName - The name/identifier of the map
317
+ * @param mapKey - The key to retrieve
318
+ * @returns Promise resolving to the encrypted value if it exists, or an error if the operation fails
319
+ */
320
+ get_encrypted_value(mapOwner: Principal, mapName: ByteBuf, mapKey: ByteBuf): Promise<{
321
+ Ok: [] | [ByteBuf];
322
+ } | {
323
+ Err: string;
324
+ }>;
325
+ /**
326
+ * Retrieves all encrypted values from a specific map.
327
+ *
328
+ * @param mapOwner - The principal of the map owner
329
+ * @param mapName - The name/identifier of the map
330
+ * @returns Promise resolving to an array of key-value pairs, or an error if the operation fails
331
+ */
332
+ get_encrypted_values_for_map(mapOwner: Principal, mapName: ByteBuf): Promise<{
333
+ Ok: Array<[ByteBuf, ByteBuf]>;
334
+ } | {
335
+ Err: string;
336
+ }>;
337
+ /**
338
+ * Stores an encrypted value in a map.
339
+ *
340
+ * @param mapOwner - The principal of the map owner
341
+ * @param mapName - The name/identifier of the map
342
+ * @param mapKey - The key to store
343
+ * @param data - The encrypted value to store
344
+ * @returns Promise resolving to the previous value if it existed, or an error if the operation fails
345
+ */
346
+ insert_encrypted_value(mapOwner: Principal, mapName: ByteBuf, mapKey: ByteBuf, data: ByteBuf): Promise<{
347
+ Ok: [] | [ByteBuf];
348
+ } | {
349
+ Err: string;
350
+ }>;
351
+ /**
352
+ * Removes a value from a map.
353
+ *
354
+ * @param mapOwner - The principal of the map owner
355
+ * @param mapName - The name/identifier of the map
356
+ * @param mapKey - The key to remove
357
+ * @returns Promise resolving to the removed value if it existed, or an error if the operation fails
358
+ */
359
+ remove_encrypted_value(mapOwner: Principal, mapName: ByteBuf, mapKey: ByteBuf): Promise<{
360
+ Ok: [] | [ByteBuf];
361
+ } | {
362
+ Err: string;
363
+ }>;
364
+ /**
365
+ * Removes all values from a map.
366
+ *
367
+ * @param mapOwner - The principal of the map owner
368
+ * @param mapName - The name/identifier of the map
369
+ * @returns Promise resolving to an array of removed keys, or an error if the operation fails
370
+ */
371
+ remove_map_values(mapOwner: Principal, mapName: ByteBuf): Promise<{
372
+ Ok: Array<ByteBuf>;
373
+ } | {
374
+ Err: string;
375
+ }>;
376
+ /**
377
+ * Grants or modifies access rights for a user.
378
+ *
379
+ * @param owner - The principal of the map owner
380
+ * @param mapName - The name/identifier of the map
381
+ * @param user - The principal of the user to grant/modify rights for
382
+ * @param userRights - The access rights to grant
383
+ * @returns Promise resolving to the previous access rights if they existed, or an error if the operation fails
384
+ */
385
+ set_user_rights(owner: Principal, mapName: ByteBuf, user: Principal, userRights: AccessRights): Promise<{
386
+ Ok: [] | [AccessRights];
387
+ } | {
388
+ Err: string;
389
+ }>;
390
+ /**
391
+ * Checks a user's access rights.
392
+ *
393
+ * @param owner - The principal of the map owner
394
+ * @param mapName - The name/identifier of the map
395
+ * @param user - The principal of the user to check rights for
396
+ * @returns Promise resolving to the user's access rights if they exist, or an error if the operation fails
397
+ */
398
+ get_user_rights(owner: Principal, mapName: ByteBuf, user: Principal): Promise<{
399
+ Ok: [] | [AccessRights];
400
+ } | {
401
+ Err: string;
402
+ }>;
403
+ /**
404
+ * Revokes a user's access.
405
+ *
406
+ * @param owner - The principal of the map owner
407
+ * @param mapName - The name/identifier of the map
408
+ * @param user - The principal of the user to remove
409
+ * @returns Promise resolving to the previous access rights if they existed, or an error if the operation fails
410
+ */
411
+ remove_user(owner: Principal, mapName: ByteBuf, user: Principal): Promise<{
412
+ Ok: [] | [AccessRights];
413
+ } | {
414
+ Err: string;
415
+ }>;
416
+ /**
417
+ * Fetches an encrypted VetKey.
418
+ *
419
+ * @param mapOwner - The principal of the map owner
420
+ * @param mapName - The name/identifier of the map
421
+ * @param transportKey - The public transport key to use for encryption
422
+ * @returns Promise resolving to the encrypted VetKey bytes, or an error if the operation fails
423
+ */
424
+ get_encrypted_vetkey(mapOwner: Principal, mapName: ByteBuf, transportKey: ByteBuf): Promise<{
425
+ Ok: ByteBuf;
426
+ } | {
427
+ Err: string;
428
+ }>;
429
+ /**
430
+ * Retrieves the public verification key for validating encrypted VetKeys.
431
+ *
432
+ * @returns Promise resolving to the verification key bytes
433
+ */
434
+ get_vetkey_verification_key(): Promise<ByteBuf>;
435
+ }
436
+ /**
437
+ * This interface represents the structure of an encrypted map as stored in the backend canister.
438
+ * It contains all the necessary information about a map, including its access control settings,
439
+ * encrypted key-value pairs, and metadata.
440
+ */
441
+ export interface EncryptedMapData {
442
+ /**
443
+ * Access control list for the map (excluding the map owner), specifying which users have what level of access.
444
+ * Each entry is a tuple of [Principal, AccessRights] where:
445
+ * - Principal: The user's identity
446
+ * - AccessRights: The level of access granted (Read, ReadWrite, or ReadWriteManage)
447
+ */
448
+ access_control: Array<[Principal, AccessRights]>;
449
+ /**
450
+ * The encrypted key-value pairs stored in the map.
451
+ * Each entry is a tuple of [ByteBuf, ByteBuf] where:
452
+ * - First ByteBuf: The encrypted key
453
+ * - Second ByteBuf: The encrypted value
454
+ */
455
+ keyvals: Array<[ByteBuf, ByteBuf]>;
456
+ /**
457
+ * The name/identifier of the map.
458
+ * This is used to uniquely identify the map within the system.
459
+ */
460
+ map_name: ByteBuf;
461
+ /**
462
+ * The principal of the map owner.
463
+ * This identifies who created and owns the map.
464
+ */
465
+ map_owner: Principal;
466
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @module @icp-sdk/vetkeys
3
+ *
4
+ * @description Provides frontend utilities for the low-level use of Verifiably Encrypted Threshold Keys (VetKeys) on the Internet Computer (IC) such as decryption of encrypted VetKeys, identity based encryption (IBE), and symmetric key derivation from a VetKey.
5
+ *
6
+ * ## Security Considerations
7
+ *
8
+ * - **Keep Transport Secret Keys Private:** Never expose the transport secret key as it is required for decrypting VetKeys.
9
+ * - **Unique Domain Separators:** Use unique domain separators for symmetric key derivation to prevent cross-context attacks.
10
+ * - **Authenticated Encryption:** Always verify ciphertext integrity when decrypting to prevent unauthorized modifications.
11
+ * - **Secure Key Storage:** If storing symmetric keys, ensure they are exposed only in authorized environments such as user's browser page.
12
+ */
13
+ export * from './utils/utils';
@@ -0,0 +1,216 @@
1
+ import { Principal } from '@icp-sdk/core/principal';
2
+ import { AccessRights, ByteBuf } from '../declarations/ic_vetkeys_manager_canister/ic_vetkeys_manager_canister.did.js';
3
+ export { DefaultKeyManagerClient } from './key_manager_canister';
4
+ export type { AccessRights, ByteBuf, } from '../declarations/ic_vetkeys_manager_canister/ic_vetkeys_manager_canister.did.js';
5
+ /**
6
+ * The **`KeyManager`** frontend library facilitates interaction with a [**`KeyManager`-enabled canister**](https://docs.rs/ic-vetkeys/latest/ic_vetkeys/key_manager/struct.KeyManager.html) on the **Internet Computer (ICP)**.
7
+ * It allows web applications to securely request, decrypt, and manage VetKeys while handling access control and key sharing.
8
+ *
9
+ * ## Core Features
10
+ *
11
+ * - **Retrieve And Decrypt VetKeys**: Fetch encrypted VetKeys and decrypt them locally using a **transport secret key**.
12
+ * - **Access Shared Keys Information**: Query which keys a user has access to.
13
+ * - **Manage Key Access**: Assign, modify, and revoke user rights on stored keys.
14
+ * - **Retrieve VetKey Verification Key**: Fetch the public verification key for validating encrypted VetKeys.
15
+ *
16
+ * ## Security Considerations
17
+ *
18
+ * - **Access Rights** should be carefully managed to prevent unauthorized access.
19
+ * - VetKeys should be decrypted **only in trusted environments** such as user browsers to prevent leaks.
20
+ *
21
+ */
22
+ export declare class KeyManager {
23
+ /**
24
+ * The client instance for interacting with the KeyManager canister.
25
+ */
26
+ canisterClient: KeyManagerClient;
27
+ /**
28
+ * Creates a new instance of the KeyManager.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import { KeyManager } from "@icp-sdk/vetkeys/key_manager";
33
+ *
34
+ * const keyManager = new KeyManager(keyManagerClientInstance);
35
+ * ```
36
+ */
37
+ constructor(canisterClient: KeyManagerClient);
38
+ /**
39
+ * Retrieves a list of keys that were shared with the user and the user still has access to.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * const sharedKeys = await keyManager.getAccessibleSharedKeyIds();
44
+ * console.log("Shared Keys:", sharedKeys);
45
+ * ```
46
+ *
47
+ * @returns Promise resolving to an array of `[Principal, Uint8Array]` pairs representing accessible key identifiers.
48
+ */
49
+ getAccessibleSharedKeyIds(): Promise<[Principal, Uint8Array][]>;
50
+ /**
51
+ * Fetches and decrypts an encrypted VetKey.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * const keyOwner = Principal.fromText("aaaaa-aa");
56
+ * const vetkeyName = "my_secure_key";
57
+ *
58
+ * const vetkey = await keyManager.getVetkey(
59
+ * keyOwner,
60
+ * vetkeyName,
61
+ * );
62
+ * console.log("Decrypted VetKey:", vetkey);
63
+ * ```
64
+ *
65
+ * @param keyOwner - The principal of the key owner
66
+ * @param vetkeyName - The name/identifier of the VetKey
67
+ * @returns Promise resolving to the decrypted VetKey bytes
68
+ * @throws Error if the key retrieval or decryption fails
69
+ */
70
+ getVetkey(keyOwner: Principal, vetkeyName: Uint8Array): Promise<Uint8Array>;
71
+ /**
72
+ * Retrieves the public verification key for validating encrypted VetKeys.
73
+ * The vetkeys obtained via `getVetkey` are verified using this key,
74
+ * and, therefore, this method is not needed for using `getVetkey`.
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * const verificationKey = await keyManager.getVetkeyVerificationKey();
79
+ * console.log("Verification Key:", verificationKey);
80
+ * ```
81
+ *
82
+ * @returns Promise resolving to the verification key bytes
83
+ */
84
+ getVetkeyVerificationKey(): Promise<Uint8Array>;
85
+ /**
86
+ * Grants or modifies access rights for a user.
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * const owner = Principal.fromText("aaaaa-aa");
91
+ * const keyName = "my_secure_key";
92
+ * const user = Principal.fromText("bbbbbb-bb");
93
+ * const accessRights = { ReadWrite: null };
94
+ *
95
+ * const result = await keyManager.setUserRights(
96
+ * owner,
97
+ * keyName,
98
+ * user,
99
+ * accessRights,
100
+ * );
101
+ * console.log("Replaced Access Rights:", result);
102
+ * ```
103
+ *
104
+ * @param owner - The principal of the key owner
105
+ * @param vetkeyName - The name/identifier of the VetKey
106
+ * @param user - The principal of the user to grant/modify rights for
107
+ * @param userRights - The access rights to grant
108
+ * @returns Promise resolving to the previous access rights if they existed
109
+ * @throws Error if the operation fails
110
+ */
111
+ setUserRights(owner: Principal, vetkeyName: Uint8Array, user: Principal, userRights: AccessRights): Promise<AccessRights | undefined>;
112
+ /**
113
+ * Checks a user's access rights.
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * const userRights = await keyManager.getUserRights(owner, keyName, user);
118
+ * console.log("User Access Rights:", userRights);
119
+ * ```
120
+ *
121
+ * @param owner - The principal of the key owner
122
+ * @param vetkeyName - The name/identifier of the VetKey
123
+ * @param user - The principal of the user to check rights for
124
+ * @returns Promise resolving to the user's access rights if they exist
125
+ * @throws Error if the operation fails
126
+ */
127
+ getUserRights(owner: Principal, vetkeyName: Uint8Array, user: Principal): Promise<AccessRights | undefined>;
128
+ /**
129
+ * Revokes a user's access.
130
+ *
131
+ * @example
132
+ * ```ts
133
+ * const removalResult = await keyManager.removeUser(owner, keyName, user);
134
+ * console.log("User Removed:", removalResult);
135
+ * ```
136
+ *
137
+ * @param owner - The principal of the key owner
138
+ * @param vetkeyName - The name/identifier of the VetKey
139
+ * @param user - The principal of the user to remove
140
+ * @returns Promise resolving to the previous access rights if they existed
141
+ * @throws Error if the operation fails
142
+ */
143
+ removeUser(owner: Principal, vetkeyName: Uint8Array, user: Principal): Promise<AccessRights | undefined>;
144
+ }
145
+ /**
146
+ * An interface that maps `KeyManager` calls to IC canister calls that will call the respective method of the backend `KeyManager`.
147
+ * For example, `get_user_rights` will call the `get_user_rights` method of the backend `KeyManager`.
148
+ * See the [Password Manager with Metadata Example]
149
+ */
150
+ export interface KeyManagerClient {
151
+ /**
152
+ * Retrieves a list of keys that were shared with the user and the user still has access to.
153
+ *
154
+ * @returns Promise resolving to an array of `[Principal, ByteBuf]` pairs representing accessible key identifiers.
155
+ */
156
+ get_accessible_shared_key_ids(): Promise<[Principal, ByteBuf][]>;
157
+ /**
158
+ * Grants or modifies access rights for a user.
159
+ *
160
+ * @param owner - The principal of the key owner
161
+ * @param vetkeyName - The name/identifier of the VetKey
162
+ * @param user - The principal of the user to grant/modify rights for
163
+ * @param userRights - The access rights to grant
164
+ * @returns Promise resolving to the previous access rights if they existed, or an error if the operation fails
165
+ */
166
+ set_user_rights(owner: Principal, vetkeyName: ByteBuf, user: Principal, userRights: AccessRights): Promise<{
167
+ Ok: [] | [AccessRights];
168
+ } | {
169
+ Err: string;
170
+ }>;
171
+ /**
172
+ * Checks a user's access rights.
173
+ *
174
+ * @param owner - The principal of the key owner
175
+ * @param vetkeyName - The name/identifier of the VetKey
176
+ * @param user - The principal of the user to check rights for
177
+ * @returns Promise resolving to the user's access rights if they exist, or an error if the operation fails
178
+ */
179
+ get_user_rights(owner: Principal, vetkeyName: ByteBuf, user: Principal): Promise<{
180
+ Ok: [] | [AccessRights];
181
+ } | {
182
+ Err: string;
183
+ }>;
184
+ /**
185
+ * Revokes a user's access.
186
+ *
187
+ * @param owner - The principal of the key owner
188
+ * @param vetkeyName - The name/identifier of the VetKey
189
+ * @param user - The principal of the user to remove
190
+ * @returns Promise resolving to the previous access rights if they existed, or an error if the operation fails
191
+ */
192
+ remove_user(owner: Principal, vetkeyName: ByteBuf, user: Principal): Promise<{
193
+ Ok: [] | [AccessRights];
194
+ } | {
195
+ Err: string;
196
+ }>;
197
+ /**
198
+ * Fetches an encrypted VetKey.
199
+ *
200
+ * @param keyOwner - The principal of the key owner
201
+ * @param vetkeyName - The name/identifier of the VetKey
202
+ * @param transportKey - The public transport key to use for encryption
203
+ * @returns Promise resolving to the encrypted VetKey bytes, or an error if the operation fails
204
+ */
205
+ get_encrypted_vetkey(keyOwner: Principal, vetkeyName: ByteBuf, transportKey: ByteBuf): Promise<{
206
+ Ok: ByteBuf;
207
+ } | {
208
+ Err: string;
209
+ }>;
210
+ /**
211
+ * Retrieves the public verification key for validating encrypted VetKeys.
212
+ *
213
+ * @returns Promise resolving to the verification key bytes
214
+ */
215
+ get_vetkey_verification_key(): Promise<ByteBuf>;
216
+ }