node-tkms 0.13.2 → 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,48 +1,10 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
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;
19
- export function u8vec_to_ml_kem_pke_pk(v: Uint8Array): PublicEncKeyMlKem512;
20
3
  /**
21
- * Process the user_decryption response from Rust objects.
22
- * Consider using [process_user_decryption_resp_from_js]
23
- * when using the JS API.
24
- * The result is a byte array representing a plaintext of any length.
25
- *
26
- * * `client` - client that wants to perform user_decryption.
27
- *
28
- * * `request` - the initial user_decryption request.
29
- * Must be given if `verify` is true.
30
- *
31
- * * `eip712_domain` - the EIP-712 domain.
32
- * Must be given if `verify` is true.
33
- *
34
- * * `agg_resp` - the vector of user_decryption responses.
35
- *
36
- * * `enc_pk` - The ephemeral public key.
37
- *
38
- * * `enc_sk` - The ephemeral secret key.
39
- *
40
- * * `verify` - Whether to perform signature verification for the response.
41
- * It is insecure if `verify = false`!
4
+ * Create a new [ServerIdAddr] structure that holds an ID and an address
5
+ * which must be a valid EIP-55 address, notably prefixed with "0x".
42
6
  */
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[];
44
- export function ml_kem_pke_sk_len(): number;
45
- export function u8vec_to_private_sig_key(v: Uint8Array): PrivateSigKey;
7
+ export function new_server_id_addr(id: number, addr: string): ServerIdAddr;
46
8
  /**
47
9
  * Process the user_decryption response from JavaScript objects.
48
10
  * The returned result is a byte array representing a plaintext of any length,
@@ -105,31 +67,69 @@ export function u8vec_to_private_sig_key(v: Uint8Array): PrivateSigKey;
105
67
  * It is insecure if `verify = false`!
106
68
  */
107
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[];
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;
70
+ export function u8vec_to_ml_kem_pke_pk(v: Uint8Array): PublicEncKeyMlKem512;
118
71
  /**
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".
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.
121
82
  */
122
- export function new_server_id_addr(id: number, addr: string): ServerIdAddr;
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;
123
86
  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
87
  /**
127
88
  * This function is *not* used by relayer-sdk because the encryption
128
89
  * happens on the KMS side. It's just here for completeness and tests.
129
90
  */
130
91
  export function ml_kem_pke_encrypt(msg: Uint8Array, their_pk: PublicEncKeyMlKem512): Uint8Array;
92
+ /**
93
+ * This function is *not* used by relayer-sdk because the decryption
94
+ * is handled by [process_user_decryption_resp].
95
+ * It's just here for completeness and tests.
96
+ */
97
+ export function ml_kem_pke_decrypt(ct: Uint8Array, my_sk: PrivateEncKeyMlKem512): Uint8Array;
131
98
  export function ml_kem_pke_pk_len(): number;
99
+ /**
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`!
121
+ */
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;
124
+ export function ml_kem_pke_sk_to_u8vec(sk: PrivateEncKeyMlKem512): Uint8Array;
125
+ export function ml_kem_pke_sk_len(): number;
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;
132
131
  export function u8vec_to_public_sig_key(v: Uint8Array): PublicSigKey;
132
+ export function get_server_addrs(client: Client): ServerIdAddr[];
133
133
  export class CiphertextHandle {
134
134
  private constructor();
135
135
  free(): void;
package/kms_lib.js CHANGED
@@ -171,28 +171,146 @@ function debugString(val) {
171
171
  return className;
172
172
  }
173
173
 
174
+ function takeFromExternrefTable0(idx) {
175
+ const value = wasm.__wbindgen_export_4.get(idx);
176
+ wasm.__externref_table_dealloc(idx);
177
+ return value;
178
+ }
179
+ /**
180
+ * Create a new [ServerIdAddr] structure that holds an ID and an address
181
+ * which must be a valid EIP-55 address, notably prefixed with "0x".
182
+ * @param {number} id
183
+ * @param {string} addr
184
+ * @returns {ServerIdAddr}
185
+ */
186
+ module.exports.new_server_id_addr = function(id, addr) {
187
+ const ptr0 = passStringToWasm0(addr, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
188
+ const len0 = WASM_VECTOR_LEN;
189
+ const ret = wasm.new_server_id_addr(id, ptr0, len0);
190
+ if (ret[2]) {
191
+ throw takeFromExternrefTable0(ret[1]);
192
+ }
193
+ return ServerIdAddr.__wrap(ret[0]);
194
+ };
195
+
174
196
  function _assertClass(instance, klass) {
175
197
  if (!(instance instanceof klass)) {
176
198
  throw new Error(`expected instance of ${klass.name}`);
177
199
  }
178
200
  }
179
201
 
180
- function getArrayU8FromWasm0(ptr, len) {
202
+ function getArrayJsValueFromWasm0(ptr, len) {
181
203
  ptr = ptr >>> 0;
182
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
204
+ const mem = getDataViewMemory0();
205
+ const result = [];
206
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
207
+ result.push(wasm.__wbindgen_export_4.get(mem.getUint32(i, true)));
208
+ }
209
+ wasm.__externref_drop_slice(ptr, len);
210
+ return result;
183
211
  }
184
212
  /**
185
- * @param {PublicSigKey} pk
186
- * @returns {Uint8Array}
213
+ * Process the user_decryption response from JavaScript objects.
214
+ * The returned result is a byte array representing a plaintext of any length,
215
+ * postprocessing is returned to turn it into an integer.
216
+ *
217
+ * * `client` - client that wants to perform user_decryption.
218
+ *
219
+ * * `request` - the initial user_decryption request JS object.
220
+ * It can be set to null if `verify` is false.
221
+ * Otherwise the caller needs to give the following JS object.
222
+ * Note that `client_address` and `eip712_verifying_contract` follow EIP-55.
223
+ * The signature field is not needed.
224
+ * ```
225
+ * {
226
+ * signature: undefined,
227
+ * client_address: '0x17853A630aAe15AED549B2B874de08B73C0F59c5',
228
+ * enc_key: '2000000000000000df2fcacb774f03187f3802a27259f45c06d33cefa68d9c53426b15ad531aa822',
229
+ * ciphertext_handles: [ '0748b542afe2353c86cb707e3d21044b0be1fd18efc7cbaa6a415af055bfb358' ]
230
+ * eip712_verifying_contract: '0x66f9664f97F2b50F62D13eA064982f936dE76657'
231
+ * }
232
+ * ```
233
+ *
234
+ * * `eip712_domain` - the EIP-712 domain JS object.
235
+ * It can be set to null if `verify` is false.
236
+ * Otherwise the caller needs to give the following JS object.
237
+ * Note that `salt` is optional and `verifying_contract` follows EIP-55,
238
+ * additionally, `chain_id` is an array of u8.
239
+ * ```
240
+ * {
241
+ * name: 'Authorization token',
242
+ * version: '1',
243
+ * chain_id: [
244
+ * 70, 31, 0, 0, 0, 0, 0, 0, 0,
245
+ * 0, 0, 0, 0, 0, 0, 0, 0, 0,
246
+ * 0, 0, 0, 0, 0, 0, 0, 0, 0,
247
+ * 0, 0, 0, 0, 0
248
+ * ],
249
+ * verifying_contract: '0x66f9664f97F2b50F62D13eA064982f936dE76657',
250
+ * salt: []
251
+ * }
252
+ * ```
253
+ *
254
+ * * `agg_resp` - the response JS object from the gateway.
255
+ * It has two fields like so, both are hex encoded byte arrays.
256
+ * ```
257
+ * [
258
+ * {
259
+ * signature: '69e7e040cab157aa819015b321c012dccb1545ffefd325b359b492653f0347517e28e66c572cdc299e259024329859ff9fcb0096e1ce072af0b6e1ca1fe25ec6',
260
+ * payload: '0100000029...',
261
+ * extra_data: '01234...',
262
+ * }
263
+ * ]
264
+ * ```
265
+ *
266
+ * * `enc_pk` - The ephemeral public key.
267
+ *
268
+ * * `enc_sk` - The ephemeral secret key.
269
+ *
270
+ * * `verify` - Whether to perform signature verification for the response.
271
+ * It is insecure if `verify = false`!
272
+ * @param {Client} client
273
+ * @param {any} request
274
+ * @param {any} eip712_domain
275
+ * @param {any} agg_resp
276
+ * @param {PublicEncKeyMlKem512} enc_pk
277
+ * @param {PrivateEncKeyMlKem512} enc_sk
278
+ * @param {boolean} verify
279
+ * @returns {TypedPlaintext[]}
187
280
  */
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);
281
+ module.exports.process_user_decryption_resp_from_js = function(client, request, eip712_domain, agg_resp, enc_pk, enc_sk, verify) {
282
+ _assertClass(client, Client);
283
+ _assertClass(enc_pk, PublicEncKeyMlKem512);
284
+ _assertClass(enc_sk, PrivateEncKeyMlKem512);
285
+ 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);
286
+ if (ret[3]) {
287
+ throw takeFromExternrefTable0(ret[2]);
288
+ }
289
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
290
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
193
291
  return v1;
194
292
  };
195
293
 
294
+ function passArray8ToWasm0(arg, malloc) {
295
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
296
+ getUint8ArrayMemory0().set(arg, ptr / 1);
297
+ WASM_VECTOR_LEN = arg.length;
298
+ return ptr;
299
+ }
300
+ /**
301
+ * @param {Uint8Array} v
302
+ * @returns {PublicEncKeyMlKem512}
303
+ */
304
+ module.exports.u8vec_to_ml_kem_pke_pk = function(v) {
305
+ const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
306
+ const len0 = WASM_VECTOR_LEN;
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]);
312
+ };
313
+
196
314
  function passArrayJsValueToWasm0(array, malloc) {
197
315
  const ptr = malloc(array.length * 4, 4) >>> 0;
198
316
  for (let i = 0; i < array.length; i++) {
@@ -202,12 +320,6 @@ function passArrayJsValueToWasm0(array, malloc) {
202
320
  WASM_VECTOR_LEN = array.length;
203
321
  return ptr;
204
322
  }
205
-
206
- function takeFromExternrefTable0(idx) {
207
- const value = wasm.__wbindgen_export_4.get(idx);
208
- wasm.__externref_table_dealloc(idx);
209
- return value;
210
- }
211
323
  /**
212
324
  * Instantiate a new client.
213
325
  *
@@ -249,50 +361,80 @@ module.exports.ml_kem_pke_get_pk = function(sk) {
249
361
  };
250
362
 
251
363
  /**
252
- * @param {PublicEncKeyMlKem512} pk
253
- * @returns {Uint8Array}
364
+ * @param {Uint8Array} v
365
+ * @returns {PrivateSigKey}
254
366
  */
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);
258
- if (ret[3]) {
259
- throw takeFromExternrefTable0(ret[2]);
367
+ module.exports.u8vec_to_private_sig_key = function(v) {
368
+ const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
369
+ const len0 = WASM_VECTOR_LEN;
370
+ const ret = wasm.u8vec_to_private_sig_key(ptr0, len0);
371
+ if (ret[2]) {
372
+ throw takeFromExternrefTable0(ret[1]);
260
373
  }
261
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
262
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
263
- return v1;
374
+ return PrivateSigKey.__wrap(ret[0]);
264
375
  };
265
376
 
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
- }
272
377
  /**
273
378
  * @param {Uint8Array} v
274
- * @returns {PublicEncKeyMlKem512}
379
+ * @returns {PrivateEncKeyMlKem512}
275
380
  */
276
- module.exports.u8vec_to_ml_kem_pke_pk = function(v) {
381
+ module.exports.u8vec_to_ml_kem_pke_sk = function(v) {
277
382
  const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
278
383
  const len0 = WASM_VECTOR_LEN;
279
- const ret = wasm.u8vec_to_ml_kem_pke_pk(ptr0, len0);
384
+ const ret = wasm.u8vec_to_ml_kem_pke_sk(ptr0, len0);
280
385
  if (ret[2]) {
281
386
  throw takeFromExternrefTable0(ret[1]);
282
387
  }
283
- return PublicEncKeyMlKem512.__wrap(ret[0]);
388
+ return PrivateEncKeyMlKem512.__wrap(ret[0]);
284
389
  };
285
390
 
286
- function getArrayJsValueFromWasm0(ptr, len) {
391
+ function getArrayU8FromWasm0(ptr, len) {
287
392
  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)));
292
- }
293
- wasm.__externref_drop_slice(ptr, len);
294
- return result;
393
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
295
394
  }
395
+ /**
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}
401
+ */
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
+
296
438
  /**
297
439
  * Process the user_decryption response from Rust objects.
298
440
  * Consider using [process_user_decryption_resp_from_js]
@@ -350,109 +492,43 @@ module.exports.process_user_decryption_resp = function(client, request, eip712_d
350
492
  };
351
493
 
352
494
  /**
353
- * @returns {number}
354
- */
355
- module.exports.ml_kem_pke_sk_len = function() {
356
- const ret = wasm.ml_kem_pke_sk_len();
357
- return ret >>> 0;
358
- };
359
-
360
- /**
361
- * @param {Uint8Array} v
362
- * @returns {PrivateSigKey}
495
+ * @param {PublicEncKeyMlKem512} pk
496
+ * @returns {Uint8Array}
363
497
  */
364
- module.exports.u8vec_to_private_sig_key = function(v) {
365
- const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
366
- const len0 = WASM_VECTOR_LEN;
367
- const ret = wasm.u8vec_to_private_sig_key(ptr0, len0);
368
- if (ret[2]) {
369
- throw takeFromExternrefTable0(ret[1]);
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]);
370
503
  }
371
- return PrivateSigKey.__wrap(ret[0]);
504
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
505
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
506
+ return v1;
372
507
  };
373
508
 
374
509
  /**
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.
378
- *
379
- * * `client` - client that wants to perform user_decryption.
380
- *
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
- * ```
395
- *
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[]}
510
+ * @param {PrivateEncKeyMlKem512} sk
511
+ * @returns {Uint8Array}
442
512
  */
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);
513
+ module.exports.ml_kem_pke_sk_to_u8vec = function(sk) {
514
+ _assertClass(sk, PrivateEncKeyMlKem512);
515
+ const ret = wasm.ml_kem_pke_sk_to_u8vec(sk.__wbg_ptr);
448
516
  if (ret[3]) {
449
517
  throw takeFromExternrefTable0(ret[2]);
450
518
  }
451
- var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
452
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
519
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
520
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
453
521
  return v1;
454
522
  };
455
523
 
524
+ /**
525
+ * @returns {number}
526
+ */
527
+ module.exports.ml_kem_pke_sk_len = function() {
528
+ const ret = wasm.ml_kem_pke_sk_len();
529
+ return ret >>> 0;
530
+ };
531
+
456
532
  /**
457
533
  * @param {Client} client
458
534
  * @returns {string}
@@ -471,28 +547,6 @@ module.exports.get_client_address = function(client) {
471
547
  }
472
548
  };
473
549
 
474
- /**
475
- * @param {Client} client
476
- * @returns {PrivateSigKey | undefined}
477
- */
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
550
  /**
497
551
  * @param {PrivateSigKey} sk
498
552
  * @returns {Uint8Array}
@@ -509,100 +563,33 @@ module.exports.private_sig_key_to_u8vec = function(sk) {
509
563
  };
510
564
 
511
565
  /**
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;
527
- };
528
-
529
- /**
530
- * Create a new [ServerIdAddr] structure that holds an ID and an address
531
- * which must be a valid EIP-55 address, notably prefixed with "0x".
532
- * @param {number} id
533
- * @param {string} addr
534
- * @returns {ServerIdAddr}
535
- */
536
- module.exports.new_server_id_addr = function(id, addr) {
537
- const ptr0 = passStringToWasm0(addr, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
538
- const len0 = WASM_VECTOR_LEN;
539
- const ret = wasm.new_server_id_addr(id, ptr0, len0);
540
- if (ret[2]) {
541
- throw takeFromExternrefTable0(ret[1]);
542
- }
543
- return ServerIdAddr.__wrap(ret[0]);
544
- };
545
-
546
- /**
547
- * @param {Uint8Array} v
548
- * @returns {PrivateEncKeyMlKem512}
549
- */
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]);
558
- };
559
-
560
- /**
561
- * @returns {PrivateEncKeyMlKem512}
566
+ * @param {Client} client
567
+ * @returns {PrivateSigKey | undefined}
562
568
  */
563
- module.exports.ml_kem_pke_keygen = function() {
564
- const ret = wasm.ml_kem_pke_keygen();
565
- return PrivateEncKeyMlKem512.__wrap(ret);
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);
566
573
  };
567
574
 
568
575
  /**
569
- * @param {PrivateEncKeyMlKem512} sk
576
+ * @param {PublicSigKey} pk
570
577
  * @returns {Uint8Array}
571
578
  */
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
- }
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);
578
582
  var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
579
583
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
580
584
  return v1;
581
585
  };
582
586
 
583
587
  /**
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
588
- * @returns {Uint8Array}
589
- */
590
- module.exports.ml_kem_pke_encrypt = function(msg, their_pk) {
591
- const ptr0 = passArray8ToWasm0(msg, wasm.__wbindgen_malloc);
592
- const len0 = WASM_VECTOR_LEN;
593
- _assertClass(their_pk, PublicEncKeyMlKem512);
594
- const ret = wasm.ml_kem_pke_encrypt(ptr0, len0, their_pk.__wbg_ptr);
595
- var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
596
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
597
- return v2;
598
- };
599
-
600
- /**
601
- * @returns {number}
588
+ * @returns {PrivateEncKeyMlKem512}
602
589
  */
603
- module.exports.ml_kem_pke_pk_len = function() {
604
- const ret = wasm.ml_kem_pke_pk_len();
605
- return ret >>> 0;
590
+ module.exports.ml_kem_pke_keygen = function() {
591
+ const ret = wasm.ml_kem_pke_keygen();
592
+ return PrivateEncKeyMlKem512.__wrap(ret);
606
593
  };
607
594
 
608
595
  /**
@@ -619,6 +606,18 @@ module.exports.u8vec_to_public_sig_key = function(v) {
619
606
  return PublicSigKey.__wrap(ret[0]);
620
607
  };
621
608
 
609
+ /**
610
+ * @param {Client} client
611
+ * @returns {ServerIdAddr[]}
612
+ */
613
+ module.exports.get_server_addrs = function(client) {
614
+ _assertClass(client, Client);
615
+ const ret = wasm.get_server_addrs(client.__wbg_ptr);
616
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
617
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
618
+ return v1;
619
+ };
620
+
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.2",
7
+ "version": "v0.13.3",
8
8
  "license": "BSD-3-Clause-Clear",
9
9
  "repository": {
10
10
  "type": "git",