node-tkms 0.13.1 → 0.13.3

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.
package/kms_lib.d.ts CHANGED
@@ -1,50 +1,10 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
- /**
4
- * Instantiate a new client.
5
- *
6
- * * `server_addrs` - a list of KMS server ID with EIP-55 addresses,
7
- * the elements in the list can be created using [new_server_id_addr].
8
- *
9
- * * `client_address_hex` - the client (wallet) address in hex,
10
- * must be prefixed with "0x".
11
- *
12
- * * `fhe_parameter` - the parameter choice, which can be either `"test"` or `"default"`.
13
- * The "default" parameter choice is selected if no matching string is found.
14
- */
15
- export function new_client(server_addrs: ServerIdAddr[], client_address_hex: string, fhe_parameter: string): Client;
16
3
  /**
17
4
  * Create a new [ServerIdAddr] structure that holds an ID and an address
18
5
  * which must be a valid EIP-55 address, notably prefixed with "0x".
19
6
  */
20
7
  export function new_server_id_addr(id: number, addr: string): ServerIdAddr;
21
- /**
22
- * Process the user_decryption response from Rust objects.
23
- * Consider using [process_user_decryption_resp_from_js]
24
- * when using the JS API.
25
- * The result is a byte array representing a plaintext of any length.
26
- *
27
- * * `client` - client that wants to perform user_decryption.
28
- *
29
- * * `request` - the initial user_decryption request.
30
- * Must be given if `verify` is true.
31
- *
32
- * * `eip712_domain` - the EIP-712 domain.
33
- * Must be given if `verify` is true.
34
- *
35
- * * `agg_resp` - the vector of user_decryption responses.
36
- *
37
- * * `enc_pk` - The ephemeral public key.
38
- *
39
- * * `enc_sk` - The ephemeral secret key.
40
- *
41
- * * `verify` - Whether to perform signature verification for the response.
42
- * It is insecure if `verify = false`!
43
- */
44
- export function process_user_decryption_resp(client: Client, request: ParsedUserDecryptionRequest | null | undefined, eip712_domain: Eip712DomainMsg | null | undefined, agg_resp: UserDecryptionResponse[], enc_pk: PublicEncKeyMlKem512, enc_sk: PrivateEncKeyMlKem512, verify: boolean): TypedPlaintext[];
45
- export function ml_kem_pke_keygen(): PrivateEncKeyMlKem512;
46
- export function ml_kem_pke_sk_len(): number;
47
- export function ml_kem_pke_pk_to_u8vec(pk: PublicEncKeyMlKem512): Uint8Array;
48
8
  /**
49
9
  * Process the user_decryption response from JavaScript objects.
50
10
  * The returned result is a byte array representing a plaintext of any length,
@@ -107,29 +67,69 @@ export function ml_kem_pke_pk_to_u8vec(pk: PublicEncKeyMlKem512): Uint8Array;
107
67
  * It is insecure if `verify = false`!
108
68
  */
109
69
  export function process_user_decryption_resp_from_js(client: Client, request: any, eip712_domain: any, agg_resp: any, enc_pk: PublicEncKeyMlKem512, enc_sk: PrivateEncKeyMlKem512, verify: boolean): TypedPlaintext[];
70
+ export function u8vec_to_ml_kem_pke_pk(v: Uint8Array): PublicEncKeyMlKem512;
71
+ /**
72
+ * Instantiate a new client.
73
+ *
74
+ * * `server_addrs` - a list of KMS server ID with EIP-55 addresses,
75
+ * the elements in the list can be created using [new_server_id_addr].
76
+ *
77
+ * * `client_address_hex` - the client (wallet) address in hex,
78
+ * must be prefixed with "0x".
79
+ *
80
+ * * `fhe_parameter` - the parameter choice, which can be either `"test"` or `"default"`.
81
+ * The "default" parameter choice is selected if no matching string is found.
82
+ */
83
+ export function new_client(server_addrs: ServerIdAddr[], client_address_hex: string, fhe_parameter: string): Client;
84
+ export function ml_kem_pke_get_pk(sk: PrivateEncKeyMlKem512): PublicEncKeyMlKem512;
85
+ export function u8vec_to_private_sig_key(v: Uint8Array): PrivateSigKey;
86
+ export function u8vec_to_ml_kem_pke_sk(v: Uint8Array): PrivateEncKeyMlKem512;
87
+ /**
88
+ * This function is *not* used by relayer-sdk because the encryption
89
+ * happens on the KMS side. It's just here for completeness and tests.
90
+ */
91
+ export function ml_kem_pke_encrypt(msg: Uint8Array, their_pk: PublicEncKeyMlKem512): Uint8Array;
110
92
  /**
111
93
  * This function is *not* used by relayer-sdk because the decryption
112
94
  * is handled by [process_user_decryption_resp].
113
95
  * It's just here for completeness and tests.
114
96
  */
115
97
  export function ml_kem_pke_decrypt(ct: Uint8Array, my_sk: PrivateEncKeyMlKem512): Uint8Array;
116
- export function get_client_secret_key(client: Client): PrivateSigKey | undefined;
98
+ export function ml_kem_pke_pk_len(): number;
117
99
  /**
118
- * This function is *not* used by relayer-sdk because the encryption
119
- * happens on the KMS side. It's just here for completeness and tests.
100
+ * Process the user_decryption response from Rust objects.
101
+ * Consider using [process_user_decryption_resp_from_js]
102
+ * when using the JS API.
103
+ * The result is a byte array representing a plaintext of any length.
104
+ *
105
+ * * `client` - client that wants to perform user_decryption.
106
+ *
107
+ * * `request` - the initial user_decryption request.
108
+ * Must be given if `verify` is true.
109
+ *
110
+ * * `eip712_domain` - the EIP-712 domain.
111
+ * Must be given if `verify` is true.
112
+ *
113
+ * * `agg_resp` - the vector of user_decryption responses.
114
+ *
115
+ * * `enc_pk` - The ephemeral public key.
116
+ *
117
+ * * `enc_sk` - The ephemeral secret key.
118
+ *
119
+ * * `verify` - Whether to perform signature verification for the response.
120
+ * It is insecure if `verify = false`!
120
121
  */
121
- export function ml_kem_pke_encrypt(msg: Uint8Array, their_pk: PublicEncKeyMlKem512): Uint8Array;
122
- export function u8vec_to_private_sig_key(v: Uint8Array): PrivateSigKey;
123
- export function public_sig_key_to_u8vec(pk: PublicSigKey): Uint8Array;
124
- export function u8vec_to_ml_kem_pke_sk(v: Uint8Array): PrivateEncKeyMlKem512;
125
- export function ml_kem_pke_get_pk(sk: PrivateEncKeyMlKem512): PublicEncKeyMlKem512;
122
+ export function process_user_decryption_resp(client: Client, request: ParsedUserDecryptionRequest | null | undefined, eip712_domain: Eip712DomainMsg | null | undefined, agg_resp: UserDecryptionResponse[], enc_pk: PublicEncKeyMlKem512, enc_sk: PrivateEncKeyMlKem512, verify: boolean): TypedPlaintext[];
123
+ export function ml_kem_pke_pk_to_u8vec(pk: PublicEncKeyMlKem512): Uint8Array;
126
124
  export function ml_kem_pke_sk_to_u8vec(sk: PrivateEncKeyMlKem512): Uint8Array;
127
- export function ml_kem_pke_pk_len(): number;
125
+ export function ml_kem_pke_sk_len(): number;
128
126
  export function get_client_address(client: Client): string;
127
+ export function private_sig_key_to_u8vec(sk: PrivateSigKey): Uint8Array;
128
+ export function get_client_secret_key(client: Client): PrivateSigKey | undefined;
129
+ export function public_sig_key_to_u8vec(pk: PublicSigKey): Uint8Array;
130
+ export function ml_kem_pke_keygen(): PrivateEncKeyMlKem512;
129
131
  export function u8vec_to_public_sig_key(v: Uint8Array): PublicSigKey;
130
- export function u8vec_to_ml_kem_pke_pk(v: Uint8Array): PublicEncKeyMlKem512;
131
132
  export function get_server_addrs(client: Client): ServerIdAddr[];
132
- export function private_sig_key_to_u8vec(sk: PrivateSigKey): Uint8Array;
133
133
  export class CiphertextHandle {
134
134
  private constructor();
135
135
  free(): void;
package/kms_lib.js CHANGED
@@ -171,51 +171,11 @@ function debugString(val) {
171
171
  return className;
172
172
  }
173
173
 
174
- function passArrayJsValueToWasm0(array, malloc) {
175
- const ptr = malloc(array.length * 4, 4) >>> 0;
176
- for (let i = 0; i < array.length; i++) {
177
- const add = addToExternrefTable0(array[i]);
178
- getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
179
- }
180
- WASM_VECTOR_LEN = array.length;
181
- return ptr;
182
- }
183
-
184
174
  function takeFromExternrefTable0(idx) {
185
175
  const value = wasm.__wbindgen_export_4.get(idx);
186
176
  wasm.__externref_table_dealloc(idx);
187
177
  return value;
188
178
  }
189
- /**
190
- * Instantiate a new client.
191
- *
192
- * * `server_addrs` - a list of KMS server ID with EIP-55 addresses,
193
- * the elements in the list can be created using [new_server_id_addr].
194
- *
195
- * * `client_address_hex` - the client (wallet) address in hex,
196
- * must be prefixed with "0x".
197
- *
198
- * * `fhe_parameter` - the parameter choice, which can be either `"test"` or `"default"`.
199
- * The "default" parameter choice is selected if no matching string is found.
200
- * @param {ServerIdAddr[]} server_addrs
201
- * @param {string} client_address_hex
202
- * @param {string} fhe_parameter
203
- * @returns {Client}
204
- */
205
- module.exports.new_client = function(server_addrs, client_address_hex, fhe_parameter) {
206
- const ptr0 = passArrayJsValueToWasm0(server_addrs, wasm.__wbindgen_malloc);
207
- const len0 = WASM_VECTOR_LEN;
208
- const ptr1 = passStringToWasm0(client_address_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
209
- const len1 = WASM_VECTOR_LEN;
210
- const ptr2 = passStringToWasm0(fhe_parameter, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
211
- const len2 = WASM_VECTOR_LEN;
212
- const ret = wasm.new_client(ptr0, len0, ptr1, len1, ptr2, len2);
213
- if (ret[2]) {
214
- throw takeFromExternrefTable0(ret[1]);
215
- }
216
- return Client.__wrap(ret[0]);
217
- };
218
-
219
179
  /**
220
180
  * Create a new [ServerIdAddr] structure that holds an ID and an address
221
181
  * which must be a valid EIP-55 address, notably prefixed with "0x".
@@ -249,97 +209,6 @@ function getArrayJsValueFromWasm0(ptr, len) {
249
209
  wasm.__externref_drop_slice(ptr, len);
250
210
  return result;
251
211
  }
252
- /**
253
- * Process the user_decryption response from Rust objects.
254
- * Consider using [process_user_decryption_resp_from_js]
255
- * when using the JS API.
256
- * The result is a byte array representing a plaintext of any length.
257
- *
258
- * * `client` - client that wants to perform user_decryption.
259
- *
260
- * * `request` - the initial user_decryption request.
261
- * Must be given if `verify` is true.
262
- *
263
- * * `eip712_domain` - the EIP-712 domain.
264
- * Must be given if `verify` is true.
265
- *
266
- * * `agg_resp` - the vector of user_decryption responses.
267
- *
268
- * * `enc_pk` - The ephemeral public key.
269
- *
270
- * * `enc_sk` - The ephemeral secret key.
271
- *
272
- * * `verify` - Whether to perform signature verification for the response.
273
- * It is insecure if `verify = false`!
274
- * @param {Client} client
275
- * @param {ParsedUserDecryptionRequest | null | undefined} request
276
- * @param {Eip712DomainMsg | null | undefined} eip712_domain
277
- * @param {UserDecryptionResponse[]} agg_resp
278
- * @param {PublicEncKeyMlKem512} enc_pk
279
- * @param {PrivateEncKeyMlKem512} enc_sk
280
- * @param {boolean} verify
281
- * @returns {TypedPlaintext[]}
282
- */
283
- module.exports.process_user_decryption_resp = function(client, request, eip712_domain, agg_resp, enc_pk, enc_sk, verify) {
284
- _assertClass(client, Client);
285
- let ptr0 = 0;
286
- if (!isLikeNone(request)) {
287
- _assertClass(request, ParsedUserDecryptionRequest);
288
- ptr0 = request.__destroy_into_raw();
289
- }
290
- let ptr1 = 0;
291
- if (!isLikeNone(eip712_domain)) {
292
- _assertClass(eip712_domain, Eip712DomainMsg);
293
- ptr1 = eip712_domain.__destroy_into_raw();
294
- }
295
- const ptr2 = passArrayJsValueToWasm0(agg_resp, wasm.__wbindgen_malloc);
296
- const len2 = WASM_VECTOR_LEN;
297
- _assertClass(enc_pk, PublicEncKeyMlKem512);
298
- _assertClass(enc_sk, PrivateEncKeyMlKem512);
299
- const ret = wasm.process_user_decryption_resp(client.__wbg_ptr, ptr0, ptr1, ptr2, len2, enc_pk.__wbg_ptr, enc_sk.__wbg_ptr, verify);
300
- if (ret[3]) {
301
- throw takeFromExternrefTable0(ret[2]);
302
- }
303
- var v4 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
304
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
305
- return v4;
306
- };
307
-
308
- /**
309
- * @returns {PrivateEncKeyMlKem512}
310
- */
311
- module.exports.ml_kem_pke_keygen = function() {
312
- const ret = wasm.ml_kem_pke_keygen();
313
- return PrivateEncKeyMlKem512.__wrap(ret);
314
- };
315
-
316
- /**
317
- * @returns {number}
318
- */
319
- module.exports.ml_kem_pke_sk_len = function() {
320
- const ret = wasm.ml_kem_pke_sk_len();
321
- return ret >>> 0;
322
- };
323
-
324
- function getArrayU8FromWasm0(ptr, len) {
325
- ptr = ptr >>> 0;
326
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
327
- }
328
- /**
329
- * @param {PublicEncKeyMlKem512} pk
330
- * @returns {Uint8Array}
331
- */
332
- module.exports.ml_kem_pke_pk_to_u8vec = function(pk) {
333
- _assertClass(pk, PublicEncKeyMlKem512);
334
- const ret = wasm.ml_kem_pke_pk_to_u8vec(pk.__wbg_ptr);
335
- if (ret[3]) {
336
- throw takeFromExternrefTable0(ret[2]);
337
- }
338
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
339
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
340
- return v1;
341
- };
342
-
343
212
  /**
344
213
  * Process the user_decryption response from JavaScript objects.
345
214
  * The returned result is a byte array representing a plaintext of any length,
@@ -429,48 +298,66 @@ function passArray8ToWasm0(arg, malloc) {
429
298
  return ptr;
430
299
  }
431
300
  /**
432
- * This function is *not* used by relayer-sdk because the decryption
433
- * is handled by [process_user_decryption_resp].
434
- * It's just here for completeness and tests.
435
- * @param {Uint8Array} ct
436
- * @param {PrivateEncKeyMlKem512} my_sk
437
- * @returns {Uint8Array}
301
+ * @param {Uint8Array} v
302
+ * @returns {PublicEncKeyMlKem512}
438
303
  */
439
- module.exports.ml_kem_pke_decrypt = function(ct, my_sk) {
440
- const ptr0 = passArray8ToWasm0(ct, wasm.__wbindgen_malloc);
304
+ module.exports.u8vec_to_ml_kem_pke_pk = function(v) {
305
+ const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
441
306
  const len0 = WASM_VECTOR_LEN;
442
- _assertClass(my_sk, PrivateEncKeyMlKem512);
443
- const ret = wasm.ml_kem_pke_decrypt(ptr0, len0, my_sk.__wbg_ptr);
444
- var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
445
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
446
- return v2;
307
+ const ret = wasm.u8vec_to_ml_kem_pke_pk(ptr0, len0);
308
+ if (ret[2]) {
309
+ throw takeFromExternrefTable0(ret[1]);
310
+ }
311
+ return PublicEncKeyMlKem512.__wrap(ret[0]);
447
312
  };
448
313
 
314
+ function passArrayJsValueToWasm0(array, malloc) {
315
+ const ptr = malloc(array.length * 4, 4) >>> 0;
316
+ for (let i = 0; i < array.length; i++) {
317
+ const add = addToExternrefTable0(array[i]);
318
+ getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
319
+ }
320
+ WASM_VECTOR_LEN = array.length;
321
+ return ptr;
322
+ }
449
323
  /**
450
- * @param {Client} client
451
- * @returns {PrivateSigKey | undefined}
324
+ * Instantiate a new client.
325
+ *
326
+ * * `server_addrs` - a list of KMS server ID with EIP-55 addresses,
327
+ * the elements in the list can be created using [new_server_id_addr].
328
+ *
329
+ * * `client_address_hex` - the client (wallet) address in hex,
330
+ * must be prefixed with "0x".
331
+ *
332
+ * * `fhe_parameter` - the parameter choice, which can be either `"test"` or `"default"`.
333
+ * The "default" parameter choice is selected if no matching string is found.
334
+ * @param {ServerIdAddr[]} server_addrs
335
+ * @param {string} client_address_hex
336
+ * @param {string} fhe_parameter
337
+ * @returns {Client}
452
338
  */
453
- module.exports.get_client_secret_key = function(client) {
454
- _assertClass(client, Client);
455
- const ret = wasm.get_client_secret_key(client.__wbg_ptr);
456
- return ret === 0 ? undefined : PrivateSigKey.__wrap(ret);
339
+ module.exports.new_client = function(server_addrs, client_address_hex, fhe_parameter) {
340
+ const ptr0 = passArrayJsValueToWasm0(server_addrs, wasm.__wbindgen_malloc);
341
+ const len0 = WASM_VECTOR_LEN;
342
+ const ptr1 = passStringToWasm0(client_address_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
343
+ const len1 = WASM_VECTOR_LEN;
344
+ const ptr2 = passStringToWasm0(fhe_parameter, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
345
+ const len2 = WASM_VECTOR_LEN;
346
+ const ret = wasm.new_client(ptr0, len0, ptr1, len1, ptr2, len2);
347
+ if (ret[2]) {
348
+ throw takeFromExternrefTable0(ret[1]);
349
+ }
350
+ return Client.__wrap(ret[0]);
457
351
  };
458
352
 
459
353
  /**
460
- * This function is *not* used by relayer-sdk because the encryption
461
- * happens on the KMS side. It's just here for completeness and tests.
462
- * @param {Uint8Array} msg
463
- * @param {PublicEncKeyMlKem512} their_pk
464
- * @returns {Uint8Array}
354
+ * @param {PrivateEncKeyMlKem512} sk
355
+ * @returns {PublicEncKeyMlKem512}
465
356
  */
466
- module.exports.ml_kem_pke_encrypt = function(msg, their_pk) {
467
- const ptr0 = passArray8ToWasm0(msg, wasm.__wbindgen_malloc);
468
- const len0 = WASM_VECTOR_LEN;
469
- _assertClass(their_pk, PublicEncKeyMlKem512);
470
- const ret = wasm.ml_kem_pke_encrypt(ptr0, len0, their_pk.__wbg_ptr);
471
- var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
472
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
473
- return v2;
357
+ module.exports.ml_kem_pke_get_pk = function(sk) {
358
+ _assertClass(sk, PrivateEncKeyMlKem512);
359
+ const ret = wasm.ml_kem_pke_get_pk(sk.__wbg_ptr);
360
+ return PublicEncKeyMlKem512.__wrap(ret);
474
361
  };
475
362
 
476
363
  /**
@@ -487,18 +374,6 @@ module.exports.u8vec_to_private_sig_key = function(v) {
487
374
  return PrivateSigKey.__wrap(ret[0]);
488
375
  };
489
376
 
490
- /**
491
- * @param {PublicSigKey} pk
492
- * @returns {Uint8Array}
493
- */
494
- module.exports.public_sig_key_to_u8vec = function(pk) {
495
- _assertClass(pk, PublicSigKey);
496
- const ret = wasm.public_sig_key_to_u8vec(pk.__wbg_ptr);
497
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
498
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
499
- return v1;
500
- };
501
-
502
377
  /**
503
378
  * @param {Uint8Array} v
504
379
  * @returns {PrivateEncKeyMlKem512}
@@ -513,14 +388,122 @@ module.exports.u8vec_to_ml_kem_pke_sk = function(v) {
513
388
  return PrivateEncKeyMlKem512.__wrap(ret[0]);
514
389
  };
515
390
 
391
+ function getArrayU8FromWasm0(ptr, len) {
392
+ ptr = ptr >>> 0;
393
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
394
+ }
516
395
  /**
517
- * @param {PrivateEncKeyMlKem512} sk
518
- * @returns {PublicEncKeyMlKem512}
396
+ * This function is *not* used by relayer-sdk because the encryption
397
+ * happens on the KMS side. It's just here for completeness and tests.
398
+ * @param {Uint8Array} msg
399
+ * @param {PublicEncKeyMlKem512} their_pk
400
+ * @returns {Uint8Array}
519
401
  */
520
- module.exports.ml_kem_pke_get_pk = function(sk) {
521
- _assertClass(sk, PrivateEncKeyMlKem512);
522
- const ret = wasm.ml_kem_pke_get_pk(sk.__wbg_ptr);
523
- return PublicEncKeyMlKem512.__wrap(ret);
402
+ module.exports.ml_kem_pke_encrypt = function(msg, their_pk) {
403
+ const ptr0 = passArray8ToWasm0(msg, wasm.__wbindgen_malloc);
404
+ const len0 = WASM_VECTOR_LEN;
405
+ _assertClass(their_pk, PublicEncKeyMlKem512);
406
+ const ret = wasm.ml_kem_pke_encrypt(ptr0, len0, their_pk.__wbg_ptr);
407
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
408
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
409
+ return v2;
410
+ };
411
+
412
+ /**
413
+ * This function is *not* used by relayer-sdk because the decryption
414
+ * is handled by [process_user_decryption_resp].
415
+ * It's just here for completeness and tests.
416
+ * @param {Uint8Array} ct
417
+ * @param {PrivateEncKeyMlKem512} my_sk
418
+ * @returns {Uint8Array}
419
+ */
420
+ module.exports.ml_kem_pke_decrypt = function(ct, my_sk) {
421
+ const ptr0 = passArray8ToWasm0(ct, wasm.__wbindgen_malloc);
422
+ const len0 = WASM_VECTOR_LEN;
423
+ _assertClass(my_sk, PrivateEncKeyMlKem512);
424
+ const ret = wasm.ml_kem_pke_decrypt(ptr0, len0, my_sk.__wbg_ptr);
425
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
426
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
427
+ return v2;
428
+ };
429
+
430
+ /**
431
+ * @returns {number}
432
+ */
433
+ module.exports.ml_kem_pke_pk_len = function() {
434
+ const ret = wasm.ml_kem_pke_pk_len();
435
+ return ret >>> 0;
436
+ };
437
+
438
+ /**
439
+ * Process the user_decryption response from Rust objects.
440
+ * Consider using [process_user_decryption_resp_from_js]
441
+ * when using the JS API.
442
+ * The result is a byte array representing a plaintext of any length.
443
+ *
444
+ * * `client` - client that wants to perform user_decryption.
445
+ *
446
+ * * `request` - the initial user_decryption request.
447
+ * Must be given if `verify` is true.
448
+ *
449
+ * * `eip712_domain` - the EIP-712 domain.
450
+ * Must be given if `verify` is true.
451
+ *
452
+ * * `agg_resp` - the vector of user_decryption responses.
453
+ *
454
+ * * `enc_pk` - The ephemeral public key.
455
+ *
456
+ * * `enc_sk` - The ephemeral secret key.
457
+ *
458
+ * * `verify` - Whether to perform signature verification for the response.
459
+ * It is insecure if `verify = false`!
460
+ * @param {Client} client
461
+ * @param {ParsedUserDecryptionRequest | null | undefined} request
462
+ * @param {Eip712DomainMsg | null | undefined} eip712_domain
463
+ * @param {UserDecryptionResponse[]} agg_resp
464
+ * @param {PublicEncKeyMlKem512} enc_pk
465
+ * @param {PrivateEncKeyMlKem512} enc_sk
466
+ * @param {boolean} verify
467
+ * @returns {TypedPlaintext[]}
468
+ */
469
+ module.exports.process_user_decryption_resp = function(client, request, eip712_domain, agg_resp, enc_pk, enc_sk, verify) {
470
+ _assertClass(client, Client);
471
+ let ptr0 = 0;
472
+ if (!isLikeNone(request)) {
473
+ _assertClass(request, ParsedUserDecryptionRequest);
474
+ ptr0 = request.__destroy_into_raw();
475
+ }
476
+ let ptr1 = 0;
477
+ if (!isLikeNone(eip712_domain)) {
478
+ _assertClass(eip712_domain, Eip712DomainMsg);
479
+ ptr1 = eip712_domain.__destroy_into_raw();
480
+ }
481
+ const ptr2 = passArrayJsValueToWasm0(agg_resp, wasm.__wbindgen_malloc);
482
+ const len2 = WASM_VECTOR_LEN;
483
+ _assertClass(enc_pk, PublicEncKeyMlKem512);
484
+ _assertClass(enc_sk, PrivateEncKeyMlKem512);
485
+ const ret = wasm.process_user_decryption_resp(client.__wbg_ptr, ptr0, ptr1, ptr2, len2, enc_pk.__wbg_ptr, enc_sk.__wbg_ptr, verify);
486
+ if (ret[3]) {
487
+ throw takeFromExternrefTable0(ret[2]);
488
+ }
489
+ var v4 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
490
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
491
+ return v4;
492
+ };
493
+
494
+ /**
495
+ * @param {PublicEncKeyMlKem512} pk
496
+ * @returns {Uint8Array}
497
+ */
498
+ module.exports.ml_kem_pke_pk_to_u8vec = function(pk) {
499
+ _assertClass(pk, PublicEncKeyMlKem512);
500
+ const ret = wasm.ml_kem_pke_pk_to_u8vec(pk.__wbg_ptr);
501
+ if (ret[3]) {
502
+ throw takeFromExternrefTable0(ret[2]);
503
+ }
504
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
505
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
506
+ return v1;
524
507
  };
525
508
 
526
509
  /**
@@ -541,8 +524,8 @@ module.exports.ml_kem_pke_sk_to_u8vec = function(sk) {
541
524
  /**
542
525
  * @returns {number}
543
526
  */
544
- module.exports.ml_kem_pke_pk_len = function() {
545
- const ret = wasm.ml_kem_pke_pk_len();
527
+ module.exports.ml_kem_pke_sk_len = function() {
528
+ const ret = wasm.ml_kem_pke_sk_len();
546
529
  return ret >>> 0;
547
530
  };
548
531
 
@@ -565,31 +548,62 @@ module.exports.get_client_address = function(client) {
565
548
  };
566
549
 
567
550
  /**
568
- * @param {Uint8Array} v
569
- * @returns {PublicSigKey}
551
+ * @param {PrivateSigKey} sk
552
+ * @returns {Uint8Array}
570
553
  */
571
- module.exports.u8vec_to_public_sig_key = function(v) {
572
- const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
573
- const len0 = WASM_VECTOR_LEN;
574
- const ret = wasm.u8vec_to_public_sig_key(ptr0, len0);
575
- if (ret[2]) {
576
- throw takeFromExternrefTable0(ret[1]);
554
+ module.exports.private_sig_key_to_u8vec = function(sk) {
555
+ _assertClass(sk, PrivateSigKey);
556
+ const ret = wasm.private_sig_key_to_u8vec(sk.__wbg_ptr);
557
+ if (ret[3]) {
558
+ throw takeFromExternrefTable0(ret[2]);
577
559
  }
578
- return PublicSigKey.__wrap(ret[0]);
560
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
561
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
562
+ return v1;
563
+ };
564
+
565
+ /**
566
+ * @param {Client} client
567
+ * @returns {PrivateSigKey | undefined}
568
+ */
569
+ module.exports.get_client_secret_key = function(client) {
570
+ _assertClass(client, Client);
571
+ const ret = wasm.get_client_secret_key(client.__wbg_ptr);
572
+ return ret === 0 ? undefined : PrivateSigKey.__wrap(ret);
573
+ };
574
+
575
+ /**
576
+ * @param {PublicSigKey} pk
577
+ * @returns {Uint8Array}
578
+ */
579
+ module.exports.public_sig_key_to_u8vec = function(pk) {
580
+ _assertClass(pk, PublicSigKey);
581
+ const ret = wasm.public_sig_key_to_u8vec(pk.__wbg_ptr);
582
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
583
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
584
+ return v1;
585
+ };
586
+
587
+ /**
588
+ * @returns {PrivateEncKeyMlKem512}
589
+ */
590
+ module.exports.ml_kem_pke_keygen = function() {
591
+ const ret = wasm.ml_kem_pke_keygen();
592
+ return PrivateEncKeyMlKem512.__wrap(ret);
579
593
  };
580
594
 
581
595
  /**
582
596
  * @param {Uint8Array} v
583
- * @returns {PublicEncKeyMlKem512}
597
+ * @returns {PublicSigKey}
584
598
  */
585
- module.exports.u8vec_to_ml_kem_pke_pk = function(v) {
599
+ module.exports.u8vec_to_public_sig_key = function(v) {
586
600
  const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
587
601
  const len0 = WASM_VECTOR_LEN;
588
- const ret = wasm.u8vec_to_ml_kem_pke_pk(ptr0, len0);
602
+ const ret = wasm.u8vec_to_public_sig_key(ptr0, len0);
589
603
  if (ret[2]) {
590
604
  throw takeFromExternrefTable0(ret[1]);
591
605
  }
592
- return PublicEncKeyMlKem512.__wrap(ret[0]);
606
+ return PublicSigKey.__wrap(ret[0]);
593
607
  };
594
608
 
595
609
  /**
@@ -604,21 +618,6 @@ module.exports.get_server_addrs = function(client) {
604
618
  return v1;
605
619
  };
606
620
 
607
- /**
608
- * @param {PrivateSigKey} sk
609
- * @returns {Uint8Array}
610
- */
611
- module.exports.private_sig_key_to_u8vec = function(sk) {
612
- _assertClass(sk, PrivateSigKey);
613
- const ret = wasm.private_sig_key_to_u8vec(sk.__wbg_ptr);
614
- if (ret[3]) {
615
- throw takeFromExternrefTable0(ret[2]);
616
- }
617
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
618
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
619
- return v1;
620
- };
621
-
622
621
  const CiphertextHandleFinalization = (typeof FinalizationRegistry === 'undefined')
623
622
  ? { register: () => {}, unregister: () => {} }
624
623
  : new FinalizationRegistry(ptr => wasm.__wbg_ciphertexthandle_free(ptr >>> 0, 1));
package/kms_lib_bg.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "Zama"
5
5
  ],
6
6
  "description": "Key Management System for the Zama Protocol.",
7
- "version": "v0.13.1",
7
+ "version": "v0.13.3",
8
8
  "license": "BSD-3-Clause-Clear",
9
9
  "repository": {
10
10
  "type": "git",