node-tkms 0.13.0 → 0.13.2

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,11 +1,22 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
- export function get_server_addrs(client: Client): ServerIdAddr[];
3
+ export function public_sig_key_to_u8vec(pk: PublicSigKey): Uint8Array;
4
+ /**
5
+ * Instantiate a new client.
6
+ *
7
+ * * `server_addrs` - a list of KMS server ID with EIP-55 addresses,
8
+ * the elements in the list can be created using [new_server_id_addr].
9
+ *
10
+ * * `client_address_hex` - the client (wallet) address in hex,
11
+ * must be prefixed with "0x".
12
+ *
13
+ * * `fhe_parameter` - the parameter choice, which can be either `"test"` or `"default"`.
14
+ * The "default" parameter choice is selected if no matching string is found.
15
+ */
16
+ export function new_client(server_addrs: ServerIdAddr[], client_address_hex: string, fhe_parameter: string): Client;
17
+ export function ml_kem_pke_get_pk(sk: PrivateEncKeyMlKem512): PublicEncKeyMlKem512;
18
+ export function ml_kem_pke_pk_to_u8vec(pk: PublicEncKeyMlKem512): Uint8Array;
4
19
  export function u8vec_to_ml_kem_pke_pk(v: Uint8Array): PublicEncKeyMlKem512;
5
- export function ml_kem_pke_sk_to_u8vec(sk: PrivateEncKeyMlKem512): Uint8Array;
6
- export function u8vec_to_private_sig_key(v: Uint8Array): PrivateSigKey;
7
- export function get_client_secret_key(client: Client): PrivateSigKey | undefined;
8
- export function u8vec_to_ml_kem_pke_sk(v: Uint8Array): PrivateEncKeyMlKem512;
9
20
  /**
10
21
  * Process the user_decryption response from Rust objects.
11
22
  * Consider using [process_user_decryption_resp_from_js]
@@ -30,44 +41,8 @@ export function u8vec_to_ml_kem_pke_sk(v: Uint8Array): PrivateEncKeyMlKem512;
30
41
  * It is insecure if `verify = false`!
31
42
  */
32
43
  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[];
33
- export function private_sig_key_to_u8vec(sk: PrivateSigKey): Uint8Array;
34
- /**
35
- * This function is *not* used by relayer-sdk because the encryption
36
- * happens on the KMS side. It's just here for completeness and tests.
37
- */
38
- export function ml_kem_pke_encrypt(msg: Uint8Array, their_pk: PublicEncKeyMlKem512): Uint8Array;
39
- export function u8vec_to_public_sig_key(v: Uint8Array): PublicSigKey;
40
- /**
41
- * Instantiate a new client.
42
- *
43
- * * `server_addrs` - a list of KMS server ID with EIP-55 addresses,
44
- * the elements in the list can be created using [new_server_id_addr].
45
- *
46
- * * `client_address_hex` - the client (wallet) address in hex,
47
- * must be prefixed with "0x".
48
- *
49
- * * `fhe_parameter` - the parameter choice, which can be either `"test"` or `"default"`.
50
- * The "default" parameter choice is selected if no matching string is found.
51
- */
52
- export function new_client(server_addrs: ServerIdAddr[], client_address_hex: string, fhe_parameter: string): Client;
53
- export function get_client_address(client: Client): string;
54
- export function ml_kem_pke_get_pk(sk: PrivateEncKeyMlKem512): PublicEncKeyMlKem512;
55
- /**
56
- * Create a new [ServerIdAddr] structure that holds an ID and an address
57
- * which must be a valid EIP-55 address, notably prefixed with "0x".
58
- */
59
- export function new_server_id_addr(id: number, addr: string): ServerIdAddr;
60
44
  export function ml_kem_pke_sk_len(): number;
61
- export function ml_kem_pke_keygen(): PrivateEncKeyMlKem512;
62
- export function public_sig_key_to_u8vec(pk: PublicSigKey): Uint8Array;
63
- export function ml_kem_pke_pk_len(): number;
64
- /**
65
- * This function is *not* used by relayer-sdk because the decryption
66
- * is handled by [process_user_decryption_resp].
67
- * It's just here for completeness and tests.
68
- */
69
- export function ml_kem_pke_decrypt(ct: Uint8Array, my_sk: PrivateEncKeyMlKem512): Uint8Array;
70
- export function ml_kem_pke_pk_to_u8vec(pk: PublicEncKeyMlKem512): Uint8Array;
45
+ export function u8vec_to_private_sig_key(v: Uint8Array): PrivateSigKey;
71
46
  /**
72
47
  * Process the user_decryption response from JavaScript objects.
73
48
  * The returned result is a byte array representing a plaintext of any length,
@@ -130,6 +105,31 @@ export function ml_kem_pke_pk_to_u8vec(pk: PublicEncKeyMlKem512): Uint8Array;
130
105
  * It is insecure if `verify = false`!
131
106
  */
132
107
  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[];
108
+ export function get_client_address(client: Client): string;
109
+ export function get_client_secret_key(client: Client): PrivateSigKey | undefined;
110
+ export function get_server_addrs(client: Client): ServerIdAddr[];
111
+ export function private_sig_key_to_u8vec(sk: PrivateSigKey): Uint8Array;
112
+ /**
113
+ * This function is *not* used by relayer-sdk because the decryption
114
+ * is handled by [process_user_decryption_resp].
115
+ * It's just here for completeness and tests.
116
+ */
117
+ export function ml_kem_pke_decrypt(ct: Uint8Array, my_sk: PrivateEncKeyMlKem512): Uint8Array;
118
+ /**
119
+ * Create a new [ServerIdAddr] structure that holds an ID and an address
120
+ * which must be a valid EIP-55 address, notably prefixed with "0x".
121
+ */
122
+ export function new_server_id_addr(id: number, addr: string): ServerIdAddr;
123
+ export function u8vec_to_ml_kem_pke_sk(v: Uint8Array): PrivateEncKeyMlKem512;
124
+ export function ml_kem_pke_keygen(): PrivateEncKeyMlKem512;
125
+ export function ml_kem_pke_sk_to_u8vec(sk: PrivateEncKeyMlKem512): Uint8Array;
126
+ /**
127
+ * This function is *not* used by relayer-sdk because the encryption
128
+ * happens on the KMS side. It's just here for completeness and tests.
129
+ */
130
+ export function ml_kem_pke_encrypt(msg: Uint8Array, their_pk: PublicEncKeyMlKem512): Uint8Array;
131
+ export function ml_kem_pke_pk_len(): number;
132
+ export function u8vec_to_public_sig_key(v: Uint8Array): PublicSigKey;
133
133
  export class CiphertextHandle {
134
134
  private constructor();
135
135
  free(): void;
package/kms_lib.js CHANGED
@@ -177,32 +177,29 @@ function _assertClass(instance, klass) {
177
177
  }
178
178
  }
179
179
 
180
- function getArrayJsValueFromWasm0(ptr, len) {
180
+ function getArrayU8FromWasm0(ptr, len) {
181
181
  ptr = ptr >>> 0;
182
- const mem = getDataViewMemory0();
183
- const result = [];
184
- for (let i = ptr; i < ptr + 4 * len; i += 4) {
185
- result.push(wasm.__wbindgen_export_4.get(mem.getUint32(i, true)));
186
- }
187
- wasm.__externref_drop_slice(ptr, len);
188
- return result;
182
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
189
183
  }
190
184
  /**
191
- * @param {Client} client
192
- * @returns {ServerIdAddr[]}
185
+ * @param {PublicSigKey} pk
186
+ * @returns {Uint8Array}
193
187
  */
194
- module.exports.get_server_addrs = function(client) {
195
- _assertClass(client, Client);
196
- const ret = wasm.get_server_addrs(client.__wbg_ptr);
197
- var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
198
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
188
+ module.exports.public_sig_key_to_u8vec = function(pk) {
189
+ _assertClass(pk, PublicSigKey);
190
+ const ret = wasm.public_sig_key_to_u8vec(pk.__wbg_ptr);
191
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
192
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
199
193
  return v1;
200
194
  };
201
195
 
202
- function passArray8ToWasm0(arg, malloc) {
203
- const ptr = malloc(arg.length * 1, 1) >>> 0;
204
- getUint8ArrayMemory0().set(arg, ptr / 1);
205
- WASM_VECTOR_LEN = arg.length;
196
+ function passArrayJsValueToWasm0(array, malloc) {
197
+ const ptr = malloc(array.length * 4, 4) >>> 0;
198
+ for (let i = 0; i < array.length; i++) {
199
+ const add = addToExternrefTable0(array[i]);
200
+ getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
201
+ }
202
+ WASM_VECTOR_LEN = array.length;
206
203
  return ptr;
207
204
  }
208
205
 
@@ -212,30 +209,52 @@ function takeFromExternrefTable0(idx) {
212
209
  return value;
213
210
  }
214
211
  /**
215
- * @param {Uint8Array} v
216
- * @returns {PublicEncKeyMlKem512}
212
+ * Instantiate a new client.
213
+ *
214
+ * * `server_addrs` - a list of KMS server ID with EIP-55 addresses,
215
+ * the elements in the list can be created using [new_server_id_addr].
216
+ *
217
+ * * `client_address_hex` - the client (wallet) address in hex,
218
+ * must be prefixed with "0x".
219
+ *
220
+ * * `fhe_parameter` - the parameter choice, which can be either `"test"` or `"default"`.
221
+ * The "default" parameter choice is selected if no matching string is found.
222
+ * @param {ServerIdAddr[]} server_addrs
223
+ * @param {string} client_address_hex
224
+ * @param {string} fhe_parameter
225
+ * @returns {Client}
217
226
  */
218
- module.exports.u8vec_to_ml_kem_pke_pk = function(v) {
219
- const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
227
+ module.exports.new_client = function(server_addrs, client_address_hex, fhe_parameter) {
228
+ const ptr0 = passArrayJsValueToWasm0(server_addrs, wasm.__wbindgen_malloc);
220
229
  const len0 = WASM_VECTOR_LEN;
221
- const ret = wasm.u8vec_to_ml_kem_pke_pk(ptr0, len0);
230
+ const ptr1 = passStringToWasm0(client_address_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
231
+ const len1 = WASM_VECTOR_LEN;
232
+ const ptr2 = passStringToWasm0(fhe_parameter, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
233
+ const len2 = WASM_VECTOR_LEN;
234
+ const ret = wasm.new_client(ptr0, len0, ptr1, len1, ptr2, len2);
222
235
  if (ret[2]) {
223
236
  throw takeFromExternrefTable0(ret[1]);
224
237
  }
225
- return PublicEncKeyMlKem512.__wrap(ret[0]);
238
+ return Client.__wrap(ret[0]);
226
239
  };
227
240
 
228
- function getArrayU8FromWasm0(ptr, len) {
229
- ptr = ptr >>> 0;
230
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
231
- }
232
241
  /**
233
242
  * @param {PrivateEncKeyMlKem512} sk
234
- * @returns {Uint8Array}
243
+ * @returns {PublicEncKeyMlKem512}
235
244
  */
236
- module.exports.ml_kem_pke_sk_to_u8vec = function(sk) {
245
+ module.exports.ml_kem_pke_get_pk = function(sk) {
237
246
  _assertClass(sk, PrivateEncKeyMlKem512);
238
- const ret = wasm.ml_kem_pke_sk_to_u8vec(sk.__wbg_ptr);
247
+ const ret = wasm.ml_kem_pke_get_pk(sk.__wbg_ptr);
248
+ return PublicEncKeyMlKem512.__wrap(ret);
249
+ };
250
+
251
+ /**
252
+ * @param {PublicEncKeyMlKem512} pk
253
+ * @returns {Uint8Array}
254
+ */
255
+ module.exports.ml_kem_pke_pk_to_u8vec = function(pk) {
256
+ _assertClass(pk, PublicEncKeyMlKem512);
257
+ const ret = wasm.ml_kem_pke_pk_to_u8vec(pk.__wbg_ptr);
239
258
  if (ret[3]) {
240
259
  throw takeFromExternrefTable0(ret[2]);
241
260
  }
@@ -244,52 +263,35 @@ module.exports.ml_kem_pke_sk_to_u8vec = function(sk) {
244
263
  return v1;
245
264
  };
246
265
 
266
+ function passArray8ToWasm0(arg, malloc) {
267
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
268
+ getUint8ArrayMemory0().set(arg, ptr / 1);
269
+ WASM_VECTOR_LEN = arg.length;
270
+ return ptr;
271
+ }
247
272
  /**
248
273
  * @param {Uint8Array} v
249
- * @returns {PrivateSigKey}
250
- */
251
- module.exports.u8vec_to_private_sig_key = function(v) {
252
- const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
253
- const len0 = WASM_VECTOR_LEN;
254
- const ret = wasm.u8vec_to_private_sig_key(ptr0, len0);
255
- if (ret[2]) {
256
- throw takeFromExternrefTable0(ret[1]);
257
- }
258
- return PrivateSigKey.__wrap(ret[0]);
259
- };
260
-
261
- /**
262
- * @param {Client} client
263
- * @returns {PrivateSigKey | undefined}
264
- */
265
- module.exports.get_client_secret_key = function(client) {
266
- _assertClass(client, Client);
267
- const ret = wasm.get_client_secret_key(client.__wbg_ptr);
268
- return ret === 0 ? undefined : PrivateSigKey.__wrap(ret);
269
- };
270
-
271
- /**
272
- * @param {Uint8Array} v
273
- * @returns {PrivateEncKeyMlKem512}
274
+ * @returns {PublicEncKeyMlKem512}
274
275
  */
275
- module.exports.u8vec_to_ml_kem_pke_sk = function(v) {
276
+ module.exports.u8vec_to_ml_kem_pke_pk = function(v) {
276
277
  const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
277
278
  const len0 = WASM_VECTOR_LEN;
278
- const ret = wasm.u8vec_to_ml_kem_pke_sk(ptr0, len0);
279
+ const ret = wasm.u8vec_to_ml_kem_pke_pk(ptr0, len0);
279
280
  if (ret[2]) {
280
281
  throw takeFromExternrefTable0(ret[1]);
281
282
  }
282
- return PrivateEncKeyMlKem512.__wrap(ret[0]);
283
+ return PublicEncKeyMlKem512.__wrap(ret[0]);
283
284
  };
284
285
 
285
- function passArrayJsValueToWasm0(array, malloc) {
286
- const ptr = malloc(array.length * 4, 4) >>> 0;
287
- for (let i = 0; i < array.length; i++) {
288
- const add = addToExternrefTable0(array[i]);
289
- getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
286
+ function getArrayJsValueFromWasm0(ptr, len) {
287
+ ptr = ptr >>> 0;
288
+ const mem = getDataViewMemory0();
289
+ const result = [];
290
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
291
+ result.push(wasm.__wbindgen_export_4.get(mem.getUint32(i, true)));
290
292
  }
291
- WASM_VECTOR_LEN = array.length;
292
- return ptr;
293
+ wasm.__externref_drop_slice(ptr, len);
294
+ return result;
293
295
  }
294
296
  /**
295
297
  * Process the user_decryption response from Rust objects.
@@ -348,79 +350,107 @@ module.exports.process_user_decryption_resp = function(client, request, eip712_d
348
350
  };
349
351
 
350
352
  /**
351
- * @param {PrivateSigKey} sk
352
- * @returns {Uint8Array}
353
- */
354
- module.exports.private_sig_key_to_u8vec = function(sk) {
355
- _assertClass(sk, PrivateSigKey);
356
- const ret = wasm.private_sig_key_to_u8vec(sk.__wbg_ptr);
357
- if (ret[3]) {
358
- throw takeFromExternrefTable0(ret[2]);
359
- }
360
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
361
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
362
- return v1;
363
- };
364
-
365
- /**
366
- * This function is *not* used by relayer-sdk because the encryption
367
- * happens on the KMS side. It's just here for completeness and tests.
368
- * @param {Uint8Array} msg
369
- * @param {PublicEncKeyMlKem512} their_pk
370
- * @returns {Uint8Array}
353
+ * @returns {number}
371
354
  */
372
- module.exports.ml_kem_pke_encrypt = function(msg, their_pk) {
373
- const ptr0 = passArray8ToWasm0(msg, wasm.__wbindgen_malloc);
374
- const len0 = WASM_VECTOR_LEN;
375
- _assertClass(their_pk, PublicEncKeyMlKem512);
376
- const ret = wasm.ml_kem_pke_encrypt(ptr0, len0, their_pk.__wbg_ptr);
377
- var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
378
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
379
- return v2;
355
+ module.exports.ml_kem_pke_sk_len = function() {
356
+ const ret = wasm.ml_kem_pke_sk_len();
357
+ return ret >>> 0;
380
358
  };
381
359
 
382
360
  /**
383
361
  * @param {Uint8Array} v
384
- * @returns {PublicSigKey}
362
+ * @returns {PrivateSigKey}
385
363
  */
386
- module.exports.u8vec_to_public_sig_key = function(v) {
364
+ module.exports.u8vec_to_private_sig_key = function(v) {
387
365
  const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
388
366
  const len0 = WASM_VECTOR_LEN;
389
- const ret = wasm.u8vec_to_public_sig_key(ptr0, len0);
367
+ const ret = wasm.u8vec_to_private_sig_key(ptr0, len0);
390
368
  if (ret[2]) {
391
369
  throw takeFromExternrefTable0(ret[1]);
392
370
  }
393
- return PublicSigKey.__wrap(ret[0]);
371
+ return PrivateSigKey.__wrap(ret[0]);
394
372
  };
395
373
 
396
374
  /**
397
- * Instantiate a new client.
375
+ * Process the user_decryption response from JavaScript objects.
376
+ * The returned result is a byte array representing a plaintext of any length,
377
+ * postprocessing is returned to turn it into an integer.
398
378
  *
399
- * * `server_addrs` - a list of KMS server ID with EIP-55 addresses,
400
- * the elements in the list can be created using [new_server_id_addr].
379
+ * * `client` - client that wants to perform user_decryption.
401
380
  *
402
- * * `client_address_hex` - the client (wallet) address in hex,
403
- * must be prefixed with "0x".
381
+ * * `request` - the initial user_decryption request JS object.
382
+ * It can be set to null if `verify` is false.
383
+ * Otherwise the caller needs to give the following JS object.
384
+ * Note that `client_address` and `eip712_verifying_contract` follow EIP-55.
385
+ * The signature field is not needed.
386
+ * ```
387
+ * {
388
+ * signature: undefined,
389
+ * client_address: '0x17853A630aAe15AED549B2B874de08B73C0F59c5',
390
+ * enc_key: '2000000000000000df2fcacb774f03187f3802a27259f45c06d33cefa68d9c53426b15ad531aa822',
391
+ * ciphertext_handles: [ '0748b542afe2353c86cb707e3d21044b0be1fd18efc7cbaa6a415af055bfb358' ]
392
+ * eip712_verifying_contract: '0x66f9664f97F2b50F62D13eA064982f936dE76657'
393
+ * }
394
+ * ```
404
395
  *
405
- * * `fhe_parameter` - the parameter choice, which can be either `"test"` or `"default"`.
406
- * The "default" parameter choice is selected if no matching string is found.
407
- * @param {ServerIdAddr[]} server_addrs
408
- * @param {string} client_address_hex
409
- * @param {string} fhe_parameter
410
- * @returns {Client}
396
+ * * `eip712_domain` - the EIP-712 domain JS object.
397
+ * It can be set to null if `verify` is false.
398
+ * Otherwise the caller needs to give the following JS object.
399
+ * Note that `salt` is optional and `verifying_contract` follows EIP-55,
400
+ * additionally, `chain_id` is an array of u8.
401
+ * ```
402
+ * {
403
+ * name: 'Authorization token',
404
+ * version: '1',
405
+ * chain_id: [
406
+ * 70, 31, 0, 0, 0, 0, 0, 0, 0,
407
+ * 0, 0, 0, 0, 0, 0, 0, 0, 0,
408
+ * 0, 0, 0, 0, 0, 0, 0, 0, 0,
409
+ * 0, 0, 0, 0, 0
410
+ * ],
411
+ * verifying_contract: '0x66f9664f97F2b50F62D13eA064982f936dE76657',
412
+ * salt: []
413
+ * }
414
+ * ```
415
+ *
416
+ * * `agg_resp` - the response JS object from the gateway.
417
+ * It has two fields like so, both are hex encoded byte arrays.
418
+ * ```
419
+ * [
420
+ * {
421
+ * signature: '69e7e040cab157aa819015b321c012dccb1545ffefd325b359b492653f0347517e28e66c572cdc299e259024329859ff9fcb0096e1ce072af0b6e1ca1fe25ec6',
422
+ * payload: '0100000029...',
423
+ * extra_data: '01234...',
424
+ * }
425
+ * ]
426
+ * ```
427
+ *
428
+ * * `enc_pk` - The ephemeral public key.
429
+ *
430
+ * * `enc_sk` - The ephemeral secret key.
431
+ *
432
+ * * `verify` - Whether to perform signature verification for the response.
433
+ * It is insecure if `verify = false`!
434
+ * @param {Client} client
435
+ * @param {any} request
436
+ * @param {any} eip712_domain
437
+ * @param {any} agg_resp
438
+ * @param {PublicEncKeyMlKem512} enc_pk
439
+ * @param {PrivateEncKeyMlKem512} enc_sk
440
+ * @param {boolean} verify
441
+ * @returns {TypedPlaintext[]}
411
442
  */
412
- module.exports.new_client = function(server_addrs, client_address_hex, fhe_parameter) {
413
- const ptr0 = passArrayJsValueToWasm0(server_addrs, wasm.__wbindgen_malloc);
414
- const len0 = WASM_VECTOR_LEN;
415
- const ptr1 = passStringToWasm0(client_address_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
416
- const len1 = WASM_VECTOR_LEN;
417
- const ptr2 = passStringToWasm0(fhe_parameter, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
418
- const len2 = WASM_VECTOR_LEN;
419
- const ret = wasm.new_client(ptr0, len0, ptr1, len1, ptr2, len2);
420
- if (ret[2]) {
421
- throw takeFromExternrefTable0(ret[1]);
443
+ module.exports.process_user_decryption_resp_from_js = function(client, request, eip712_domain, agg_resp, enc_pk, enc_sk, verify) {
444
+ _assertClass(client, Client);
445
+ _assertClass(enc_pk, PublicEncKeyMlKem512);
446
+ _assertClass(enc_sk, PrivateEncKeyMlKem512);
447
+ const ret = wasm.process_user_decryption_resp_from_js(client.__wbg_ptr, request, eip712_domain, agg_resp, enc_pk.__wbg_ptr, enc_sk.__wbg_ptr, verify);
448
+ if (ret[3]) {
449
+ throw takeFromExternrefTable0(ret[2]);
422
450
  }
423
- return Client.__wrap(ret[0]);
451
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
452
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
453
+ return v1;
424
454
  };
425
455
 
426
456
  /**
@@ -442,13 +472,58 @@ module.exports.get_client_address = function(client) {
442
472
  };
443
473
 
444
474
  /**
445
- * @param {PrivateEncKeyMlKem512} sk
446
- * @returns {PublicEncKeyMlKem512}
475
+ * @param {Client} client
476
+ * @returns {PrivateSigKey | undefined}
447
477
  */
448
- module.exports.ml_kem_pke_get_pk = function(sk) {
449
- _assertClass(sk, PrivateEncKeyMlKem512);
450
- const ret = wasm.ml_kem_pke_get_pk(sk.__wbg_ptr);
451
- return PublicEncKeyMlKem512.__wrap(ret);
478
+ module.exports.get_client_secret_key = function(client) {
479
+ _assertClass(client, Client);
480
+ const ret = wasm.get_client_secret_key(client.__wbg_ptr);
481
+ return ret === 0 ? undefined : PrivateSigKey.__wrap(ret);
482
+ };
483
+
484
+ /**
485
+ * @param {Client} client
486
+ * @returns {ServerIdAddr[]}
487
+ */
488
+ module.exports.get_server_addrs = function(client) {
489
+ _assertClass(client, Client);
490
+ const ret = wasm.get_server_addrs(client.__wbg_ptr);
491
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
492
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
493
+ return v1;
494
+ };
495
+
496
+ /**
497
+ * @param {PrivateSigKey} sk
498
+ * @returns {Uint8Array}
499
+ */
500
+ module.exports.private_sig_key_to_u8vec = function(sk) {
501
+ _assertClass(sk, PrivateSigKey);
502
+ const ret = wasm.private_sig_key_to_u8vec(sk.__wbg_ptr);
503
+ if (ret[3]) {
504
+ throw takeFromExternrefTable0(ret[2]);
505
+ }
506
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
507
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
508
+ return v1;
509
+ };
510
+
511
+ /**
512
+ * This function is *not* used by relayer-sdk because the decryption
513
+ * is handled by [process_user_decryption_resp].
514
+ * It's just here for completeness and tests.
515
+ * @param {Uint8Array} ct
516
+ * @param {PrivateEncKeyMlKem512} my_sk
517
+ * @returns {Uint8Array}
518
+ */
519
+ module.exports.ml_kem_pke_decrypt = function(ct, my_sk) {
520
+ const ptr0 = passArray8ToWasm0(ct, wasm.__wbindgen_malloc);
521
+ const len0 = WASM_VECTOR_LEN;
522
+ _assertClass(my_sk, PrivateEncKeyMlKem512);
523
+ const ret = wasm.ml_kem_pke_decrypt(ptr0, len0, my_sk.__wbg_ptr);
524
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
525
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
526
+ return v2;
452
527
  };
453
528
 
454
529
  /**
@@ -469,11 +544,17 @@ module.exports.new_server_id_addr = function(id, addr) {
469
544
  };
470
545
 
471
546
  /**
472
- * @returns {number}
547
+ * @param {Uint8Array} v
548
+ * @returns {PrivateEncKeyMlKem512}
473
549
  */
474
- module.exports.ml_kem_pke_sk_len = function() {
475
- const ret = wasm.ml_kem_pke_sk_len();
476
- return ret >>> 0;
550
+ module.exports.u8vec_to_ml_kem_pke_sk = function(v) {
551
+ const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
552
+ const len0 = WASM_VECTOR_LEN;
553
+ const ret = wasm.u8vec_to_ml_kem_pke_sk(ptr0, len0);
554
+ if (ret[2]) {
555
+ throw takeFromExternrefTable0(ret[1]);
556
+ }
557
+ return PrivateEncKeyMlKem512.__wrap(ret[0]);
477
558
  };
478
559
 
479
560
  /**
@@ -485,138 +566,57 @@ module.exports.ml_kem_pke_keygen = function() {
485
566
  };
486
567
 
487
568
  /**
488
- * @param {PublicSigKey} pk
569
+ * @param {PrivateEncKeyMlKem512} sk
489
570
  * @returns {Uint8Array}
490
571
  */
491
- module.exports.public_sig_key_to_u8vec = function(pk) {
492
- _assertClass(pk, PublicSigKey);
493
- const ret = wasm.public_sig_key_to_u8vec(pk.__wbg_ptr);
572
+ module.exports.ml_kem_pke_sk_to_u8vec = function(sk) {
573
+ _assertClass(sk, PrivateEncKeyMlKem512);
574
+ const ret = wasm.ml_kem_pke_sk_to_u8vec(sk.__wbg_ptr);
575
+ if (ret[3]) {
576
+ throw takeFromExternrefTable0(ret[2]);
577
+ }
494
578
  var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
495
579
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
496
580
  return v1;
497
581
  };
498
582
 
499
583
  /**
500
- * @returns {number}
501
- */
502
- module.exports.ml_kem_pke_pk_len = function() {
503
- const ret = wasm.ml_kem_pke_pk_len();
504
- return ret >>> 0;
505
- };
506
-
507
- /**
508
- * This function is *not* used by relayer-sdk because the decryption
509
- * is handled by [process_user_decryption_resp].
510
- * It's just here for completeness and tests.
511
- * @param {Uint8Array} ct
512
- * @param {PrivateEncKeyMlKem512} my_sk
584
+ * This function is *not* used by relayer-sdk because the encryption
585
+ * happens on the KMS side. It's just here for completeness and tests.
586
+ * @param {Uint8Array} msg
587
+ * @param {PublicEncKeyMlKem512} their_pk
513
588
  * @returns {Uint8Array}
514
589
  */
515
- module.exports.ml_kem_pke_decrypt = function(ct, my_sk) {
516
- const ptr0 = passArray8ToWasm0(ct, wasm.__wbindgen_malloc);
590
+ module.exports.ml_kem_pke_encrypt = function(msg, their_pk) {
591
+ const ptr0 = passArray8ToWasm0(msg, wasm.__wbindgen_malloc);
517
592
  const len0 = WASM_VECTOR_LEN;
518
- _assertClass(my_sk, PrivateEncKeyMlKem512);
519
- const ret = wasm.ml_kem_pke_decrypt(ptr0, len0, my_sk.__wbg_ptr);
593
+ _assertClass(their_pk, PublicEncKeyMlKem512);
594
+ const ret = wasm.ml_kem_pke_encrypt(ptr0, len0, their_pk.__wbg_ptr);
520
595
  var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
521
596
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
522
597
  return v2;
523
598
  };
524
599
 
525
600
  /**
526
- * @param {PublicEncKeyMlKem512} pk
527
- * @returns {Uint8Array}
601
+ * @returns {number}
528
602
  */
529
- module.exports.ml_kem_pke_pk_to_u8vec = function(pk) {
530
- _assertClass(pk, PublicEncKeyMlKem512);
531
- const ret = wasm.ml_kem_pke_pk_to_u8vec(pk.__wbg_ptr);
532
- if (ret[3]) {
533
- throw takeFromExternrefTable0(ret[2]);
534
- }
535
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
536
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
537
- return v1;
603
+ module.exports.ml_kem_pke_pk_len = function() {
604
+ const ret = wasm.ml_kem_pke_pk_len();
605
+ return ret >>> 0;
538
606
  };
539
607
 
540
608
  /**
541
- * Process the user_decryption response from JavaScript objects.
542
- * The returned result is a byte array representing a plaintext of any length,
543
- * postprocessing is returned to turn it into an integer.
544
- *
545
- * * `client` - client that wants to perform user_decryption.
546
- *
547
- * * `request` - the initial user_decryption request JS object.
548
- * It can be set to null if `verify` is false.
549
- * Otherwise the caller needs to give the following JS object.
550
- * Note that `client_address` and `eip712_verifying_contract` follow EIP-55.
551
- * The signature field is not needed.
552
- * ```
553
- * {
554
- * signature: undefined,
555
- * client_address: '0x17853A630aAe15AED549B2B874de08B73C0F59c5',
556
- * enc_key: '2000000000000000df2fcacb774f03187f3802a27259f45c06d33cefa68d9c53426b15ad531aa822',
557
- * ciphertext_handles: [ '0748b542afe2353c86cb707e3d21044b0be1fd18efc7cbaa6a415af055bfb358' ]
558
- * eip712_verifying_contract: '0x66f9664f97F2b50F62D13eA064982f936dE76657'
559
- * }
560
- * ```
561
- *
562
- * * `eip712_domain` - the EIP-712 domain JS object.
563
- * It can be set to null if `verify` is false.
564
- * Otherwise the caller needs to give the following JS object.
565
- * Note that `salt` is optional and `verifying_contract` follows EIP-55,
566
- * additionally, `chain_id` is an array of u8.
567
- * ```
568
- * {
569
- * name: 'Authorization token',
570
- * version: '1',
571
- * chain_id: [
572
- * 70, 31, 0, 0, 0, 0, 0, 0, 0,
573
- * 0, 0, 0, 0, 0, 0, 0, 0, 0,
574
- * 0, 0, 0, 0, 0, 0, 0, 0, 0,
575
- * 0, 0, 0, 0, 0
576
- * ],
577
- * verifying_contract: '0x66f9664f97F2b50F62D13eA064982f936dE76657',
578
- * salt: []
579
- * }
580
- * ```
581
- *
582
- * * `agg_resp` - the response JS object from the gateway.
583
- * It has two fields like so, both are hex encoded byte arrays.
584
- * ```
585
- * [
586
- * {
587
- * signature: '69e7e040cab157aa819015b321c012dccb1545ffefd325b359b492653f0347517e28e66c572cdc299e259024329859ff9fcb0096e1ce072af0b6e1ca1fe25ec6',
588
- * payload: '0100000029...',
589
- * extra_data: '01234...',
590
- * }
591
- * ]
592
- * ```
593
- *
594
- * * `enc_pk` - The ephemeral public key.
595
- *
596
- * * `enc_sk` - The ephemeral secret key.
597
- *
598
- * * `verify` - Whether to perform signature verification for the response.
599
- * It is insecure if `verify = false`!
600
- * @param {Client} client
601
- * @param {any} request
602
- * @param {any} eip712_domain
603
- * @param {any} agg_resp
604
- * @param {PublicEncKeyMlKem512} enc_pk
605
- * @param {PrivateEncKeyMlKem512} enc_sk
606
- * @param {boolean} verify
607
- * @returns {TypedPlaintext[]}
609
+ * @param {Uint8Array} v
610
+ * @returns {PublicSigKey}
608
611
  */
609
- module.exports.process_user_decryption_resp_from_js = function(client, request, eip712_domain, agg_resp, enc_pk, enc_sk, verify) {
610
- _assertClass(client, Client);
611
- _assertClass(enc_pk, PublicEncKeyMlKem512);
612
- _assertClass(enc_sk, PrivateEncKeyMlKem512);
613
- const ret = wasm.process_user_decryption_resp_from_js(client.__wbg_ptr, request, eip712_domain, agg_resp, enc_pk.__wbg_ptr, enc_sk.__wbg_ptr, verify);
614
- if (ret[3]) {
615
- throw takeFromExternrefTable0(ret[2]);
612
+ module.exports.u8vec_to_public_sig_key = function(v) {
613
+ const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
614
+ const len0 = WASM_VECTOR_LEN;
615
+ const ret = wasm.u8vec_to_public_sig_key(ptr0, len0);
616
+ if (ret[2]) {
617
+ throw takeFromExternrefTable0(ret[1]);
616
618
  }
617
- var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
618
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
619
- return v1;
619
+ return PublicSigKey.__wrap(ret[0]);
620
620
  };
621
621
 
622
622
  const CiphertextHandleFinalization = (typeof FinalizationRegistry === 'undefined')
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.0",
7
+ "version": "v0.13.2",
8
8
  "license": "BSD-3-Clause-Clear",
9
9
  "repository": {
10
10
  "type": "git",