node-tkms 0.11.0-rc15 → 0.11.0-rc17

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,14 +1,21 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
+ export function ml_kem_pke_ct_pk_len(): number;
4
+ export function ml_kem_pke_sk_len(): number;
3
5
  export function public_sig_key_to_u8vec(pk: PublicSigKey): Uint8Array;
4
6
  export function u8vec_to_public_sig_key(v: Uint8Array): PublicSigKey;
5
7
  export function private_sig_key_to_u8vec(sk: PrivateSigKey): Uint8Array;
6
8
  export function u8vec_to_private_sig_key(v: Uint8Array): PrivateSigKey;
9
+ /**
10
+ * Create a new [ServerIdAddr] structure that holds an ID and an address
11
+ * which must be a valid EIP-55 address, notably prefixed with "0x".
12
+ */
13
+ export function new_server_id_addr(id: number, addr: string): ServerIdAddr;
7
14
  /**
8
15
  * Instantiate a new client.
9
16
  *
10
- * * `server_addrs` - a list of KMS server EIP-55 addresses,
11
- * must be prefixed with "0x".
17
+ * * `server_addrs` - a list of KMS server ID with EIP-55 addresses,
18
+ * the elements in the list can be created using [new_server_id_addr].
12
19
  *
13
20
  * * `client_address_hex` - the client (wallet) address in hex,
14
21
  * must be prefixed with "0x".
@@ -16,18 +23,18 @@ export function u8vec_to_private_sig_key(v: Uint8Array): PrivateSigKey;
16
23
  * * `fhe_parameter` - the parameter choice, which can be either `"test"` or `"default"`.
17
24
  * The "default" parameter choice is selected if no matching string is found.
18
25
  */
19
- export function new_client(server_addrs: string[], client_address_hex: string, fhe_parameter: string): Client;
20
- export function get_server_addrs(client: Client): string[];
26
+ export function new_client(server_addrs: ServerIdAddr[], client_address_hex: string, fhe_parameter: string): Client;
27
+ export function get_server_addrs(client: Client): ServerIdAddr[];
21
28
  export function get_client_secret_key(client: Client): PrivateSigKey | undefined;
22
29
  export function get_client_address(client: Client): string;
23
- export function cryptobox_keygen(): PrivateEncKey;
24
- export function cryptobox_get_pk(sk: PrivateEncKey): PublicEncKey;
25
- export function cryptobox_pk_to_u8vec(pk: PublicEncKey): Uint8Array;
26
- export function cryptobox_sk_to_u8vec(sk: PrivateEncKey): Uint8Array;
27
- export function u8vec_to_cryptobox_pk(v: Uint8Array): PublicEncKey;
28
- export function u8vec_to_cryptobox_sk(v: Uint8Array): PrivateEncKey;
29
- export function cryptobox_encrypt(msg: Uint8Array, their_pk: PublicEncKey, my_sk: PrivateEncKey): CryptoBoxCt;
30
- export function cryptobox_decrypt(ct: CryptoBoxCt, my_sk: PrivateEncKey, their_pk: PublicEncKey): Uint8Array;
30
+ export function ml_kem_pke_keygen(): PrivateEncKey;
31
+ export function ml_kem_pke_get_pk(sk: PrivateEncKey): PublicEncKey;
32
+ export function ml_kem_pke_pk_to_u8vec(pk: PublicEncKey): Uint8Array;
33
+ export function ml_kem_pke_sk_to_u8vec(sk: PrivateEncKey): Uint8Array;
34
+ export function u8vec_to_ml_kem_pke_pk(v: Uint8Array): PublicEncKey;
35
+ export function u8vec_to_ml_kem_pke_sk(v: Uint8Array): PrivateEncKey;
36
+ export function ml_kem_pke_encrypt(msg: Uint8Array, their_pk: PublicEncKey): CryptoBoxCt;
37
+ export function ml_kem_pke_decrypt(ct: CryptoBoxCt, my_sk: PrivateEncKey): Uint8Array;
31
38
  /**
32
39
  * Process the user_decryption response from JavaScript objects.
33
40
  * The returned result is a byte array representing a plaintext of any length,
@@ -179,6 +186,10 @@ export class RequestId {
179
186
  free(): void;
180
187
  request_id: string;
181
188
  }
189
+ export class ServerIdAddr {
190
+ private constructor();
191
+ free(): void;
192
+ }
182
193
  export class TypedCiphertext {
183
194
  private constructor();
184
195
  free(): void;
@@ -284,7 +295,7 @@ export class UserDecryptionResponse {
284
295
  signature: Uint8Array;
285
296
  /**
286
297
  * This is the external signature created from the Eip712 domain
287
- * on the structure, where userDecryptedShare is bincode::serialize(&payload)
298
+ * on the structure, where userDecryptedShare is bc2wrap::serialize(&payload)
288
299
  * struct UserDecryptResponseVerification {
289
300
  * bytes publicKey;
290
301
  * uint256\[\] ctHandles;
package/kms_lib.js CHANGED
@@ -170,6 +170,21 @@ function debugString(val) {
170
170
  // TODO we could test for more things here, like `Set`s and `Map`s.
171
171
  return className;
172
172
  }
173
+ /**
174
+ * @returns {number}
175
+ */
176
+ module.exports.ml_kem_pke_ct_pk_len = function() {
177
+ const ret = wasm.ml_kem_pke_ct_pk_len();
178
+ return ret >>> 0;
179
+ };
180
+
181
+ /**
182
+ * @returns {number}
183
+ */
184
+ module.exports.ml_kem_pke_sk_len = function() {
185
+ const ret = wasm.ml_kem_pke_sk_len();
186
+ return ret >>> 0;
187
+ };
173
188
 
174
189
  function _assertClass(instance, klass) {
175
190
  if (!(instance instanceof klass)) {
@@ -248,6 +263,23 @@ module.exports.u8vec_to_private_sig_key = function(v) {
248
263
  return PrivateSigKey.__wrap(ret[0]);
249
264
  };
250
265
 
266
+ /**
267
+ * Create a new [ServerIdAddr] structure that holds an ID and an address
268
+ * which must be a valid EIP-55 address, notably prefixed with "0x".
269
+ * @param {number} id
270
+ * @param {string} addr
271
+ * @returns {ServerIdAddr}
272
+ */
273
+ module.exports.new_server_id_addr = function(id, addr) {
274
+ const ptr0 = passStringToWasm0(addr, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
275
+ const len0 = WASM_VECTOR_LEN;
276
+ const ret = wasm.new_server_id_addr(id, ptr0, len0);
277
+ if (ret[2]) {
278
+ throw takeFromExternrefTable0(ret[1]);
279
+ }
280
+ return ServerIdAddr.__wrap(ret[0]);
281
+ };
282
+
251
283
  function passArrayJsValueToWasm0(array, malloc) {
252
284
  const ptr = malloc(array.length * 4, 4) >>> 0;
253
285
  for (let i = 0; i < array.length; i++) {
@@ -260,15 +292,15 @@ function passArrayJsValueToWasm0(array, malloc) {
260
292
  /**
261
293
  * Instantiate a new client.
262
294
  *
263
- * * `server_addrs` - a list of KMS server EIP-55 addresses,
264
- * must be prefixed with "0x".
295
+ * * `server_addrs` - a list of KMS server ID with EIP-55 addresses,
296
+ * the elements in the list can be created using [new_server_id_addr].
265
297
  *
266
298
  * * `client_address_hex` - the client (wallet) address in hex,
267
299
  * must be prefixed with "0x".
268
300
  *
269
301
  * * `fhe_parameter` - the parameter choice, which can be either `"test"` or `"default"`.
270
302
  * The "default" parameter choice is selected if no matching string is found.
271
- * @param {string[]} server_addrs
303
+ * @param {ServerIdAddr[]} server_addrs
272
304
  * @param {string} client_address_hex
273
305
  * @param {string} fhe_parameter
274
306
  * @returns {Client}
@@ -299,7 +331,7 @@ function getArrayJsValueFromWasm0(ptr, len) {
299
331
  }
300
332
  /**
301
333
  * @param {Client} client
302
- * @returns {string[]}
334
+ * @returns {ServerIdAddr[]}
303
335
  */
304
336
  module.exports.get_server_addrs = function(client) {
305
337
  _assertClass(client, Client);
@@ -340,8 +372,8 @@ module.exports.get_client_address = function(client) {
340
372
  /**
341
373
  * @returns {PrivateEncKey}
342
374
  */
343
- module.exports.cryptobox_keygen = function() {
344
- const ret = wasm.cryptobox_keygen();
375
+ module.exports.ml_kem_pke_keygen = function() {
376
+ const ret = wasm.ml_kem_pke_keygen();
345
377
  return PrivateEncKey.__wrap(ret);
346
378
  };
347
379
 
@@ -349,9 +381,9 @@ module.exports.cryptobox_keygen = function() {
349
381
  * @param {PrivateEncKey} sk
350
382
  * @returns {PublicEncKey}
351
383
  */
352
- module.exports.cryptobox_get_pk = function(sk) {
384
+ module.exports.ml_kem_pke_get_pk = function(sk) {
353
385
  _assertClass(sk, PrivateEncKey);
354
- const ret = wasm.cryptobox_get_pk(sk.__wbg_ptr);
386
+ const ret = wasm.ml_kem_pke_get_pk(sk.__wbg_ptr);
355
387
  return PublicEncKey.__wrap(ret);
356
388
  };
357
389
 
@@ -359,9 +391,9 @@ module.exports.cryptobox_get_pk = function(sk) {
359
391
  * @param {PublicEncKey} pk
360
392
  * @returns {Uint8Array}
361
393
  */
362
- module.exports.cryptobox_pk_to_u8vec = function(pk) {
394
+ module.exports.ml_kem_pke_pk_to_u8vec = function(pk) {
363
395
  _assertClass(pk, PublicEncKey);
364
- const ret = wasm.cryptobox_pk_to_u8vec(pk.__wbg_ptr);
396
+ const ret = wasm.ml_kem_pke_pk_to_u8vec(pk.__wbg_ptr);
365
397
  if (ret[3]) {
366
398
  throw takeFromExternrefTable0(ret[2]);
367
399
  }
@@ -374,9 +406,9 @@ module.exports.cryptobox_pk_to_u8vec = function(pk) {
374
406
  * @param {PrivateEncKey} sk
375
407
  * @returns {Uint8Array}
376
408
  */
377
- module.exports.cryptobox_sk_to_u8vec = function(sk) {
409
+ module.exports.ml_kem_pke_sk_to_u8vec = function(sk) {
378
410
  _assertClass(sk, PrivateEncKey);
379
- const ret = wasm.cryptobox_sk_to_u8vec(sk.__wbg_ptr);
411
+ const ret = wasm.ml_kem_pke_sk_to_u8vec(sk.__wbg_ptr);
380
412
  if (ret[3]) {
381
413
  throw takeFromExternrefTable0(ret[2]);
382
414
  }
@@ -389,10 +421,10 @@ module.exports.cryptobox_sk_to_u8vec = function(sk) {
389
421
  * @param {Uint8Array} v
390
422
  * @returns {PublicEncKey}
391
423
  */
392
- module.exports.u8vec_to_cryptobox_pk = function(v) {
424
+ module.exports.u8vec_to_ml_kem_pke_pk = function(v) {
393
425
  const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
394
426
  const len0 = WASM_VECTOR_LEN;
395
- const ret = wasm.u8vec_to_cryptobox_pk(ptr0, len0);
427
+ const ret = wasm.u8vec_to_ml_kem_pke_pk(ptr0, len0);
396
428
  if (ret[2]) {
397
429
  throw takeFromExternrefTable0(ret[1]);
398
430
  }
@@ -403,10 +435,10 @@ module.exports.u8vec_to_cryptobox_pk = function(v) {
403
435
  * @param {Uint8Array} v
404
436
  * @returns {PrivateEncKey}
405
437
  */
406
- module.exports.u8vec_to_cryptobox_sk = function(v) {
438
+ module.exports.u8vec_to_ml_kem_pke_sk = function(v) {
407
439
  const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
408
440
  const len0 = WASM_VECTOR_LEN;
409
- const ret = wasm.u8vec_to_cryptobox_sk(ptr0, len0);
441
+ const ret = wasm.u8vec_to_ml_kem_pke_sk(ptr0, len0);
410
442
  if (ret[2]) {
411
443
  throw takeFromExternrefTable0(ret[1]);
412
444
  }
@@ -416,29 +448,25 @@ module.exports.u8vec_to_cryptobox_sk = function(v) {
416
448
  /**
417
449
  * @param {Uint8Array} msg
418
450
  * @param {PublicEncKey} their_pk
419
- * @param {PrivateEncKey} my_sk
420
451
  * @returns {CryptoBoxCt}
421
452
  */
422
- module.exports.cryptobox_encrypt = function(msg, their_pk, my_sk) {
453
+ module.exports.ml_kem_pke_encrypt = function(msg, their_pk) {
423
454
  const ptr0 = passArray8ToWasm0(msg, wasm.__wbindgen_malloc);
424
455
  const len0 = WASM_VECTOR_LEN;
425
456
  _assertClass(their_pk, PublicEncKey);
426
- _assertClass(my_sk, PrivateEncKey);
427
- const ret = wasm.cryptobox_encrypt(ptr0, len0, their_pk.__wbg_ptr, my_sk.__wbg_ptr);
457
+ const ret = wasm.ml_kem_pke_encrypt(ptr0, len0, their_pk.__wbg_ptr);
428
458
  return CryptoBoxCt.__wrap(ret);
429
459
  };
430
460
 
431
461
  /**
432
462
  * @param {CryptoBoxCt} ct
433
463
  * @param {PrivateEncKey} my_sk
434
- * @param {PublicEncKey} their_pk
435
464
  * @returns {Uint8Array}
436
465
  */
437
- module.exports.cryptobox_decrypt = function(ct, my_sk, their_pk) {
466
+ module.exports.ml_kem_pke_decrypt = function(ct, my_sk) {
438
467
  _assertClass(ct, CryptoBoxCt);
439
468
  _assertClass(my_sk, PrivateEncKey);
440
- _assertClass(their_pk, PublicEncKey);
441
- const ret = wasm.cryptobox_decrypt(ct.__wbg_ptr, my_sk.__wbg_ptr, their_pk.__wbg_ptr);
469
+ const ret = wasm.ml_kem_pke_decrypt(ct.__wbg_ptr, my_sk.__wbg_ptr);
442
470
  var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
443
471
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
444
472
  return v1;
@@ -989,6 +1017,41 @@ class RequestId {
989
1017
  }
990
1018
  module.exports.RequestId = RequestId;
991
1019
 
1020
+ const ServerIdAddrFinalization = (typeof FinalizationRegistry === 'undefined')
1021
+ ? { register: () => {}, unregister: () => {} }
1022
+ : new FinalizationRegistry(ptr => wasm.__wbg_serveridaddr_free(ptr >>> 0, 1));
1023
+
1024
+ class ServerIdAddr {
1025
+
1026
+ static __wrap(ptr) {
1027
+ ptr = ptr >>> 0;
1028
+ const obj = Object.create(ServerIdAddr.prototype);
1029
+ obj.__wbg_ptr = ptr;
1030
+ ServerIdAddrFinalization.register(obj, obj.__wbg_ptr, obj);
1031
+ return obj;
1032
+ }
1033
+
1034
+ static __unwrap(jsValue) {
1035
+ if (!(jsValue instanceof ServerIdAddr)) {
1036
+ return 0;
1037
+ }
1038
+ return jsValue.__destroy_into_raw();
1039
+ }
1040
+
1041
+ __destroy_into_raw() {
1042
+ const ptr = this.__wbg_ptr;
1043
+ this.__wbg_ptr = 0;
1044
+ ServerIdAddrFinalization.unregister(this);
1045
+ return ptr;
1046
+ }
1047
+
1048
+ free() {
1049
+ const ptr = this.__destroy_into_raw();
1050
+ wasm.__wbg_serveridaddr_free(ptr, 0);
1051
+ }
1052
+ }
1053
+ module.exports.ServerIdAddr = ServerIdAddr;
1054
+
992
1055
  const TypedCiphertextFinalization = (typeof FinalizationRegistry === 'undefined')
993
1056
  ? { register: () => {}, unregister: () => {} }
994
1057
  : new FinalizationRegistry(ptr => wasm.__wbg_typedciphertext_free(ptr >>> 0, 1));
@@ -1463,7 +1526,7 @@ class UserDecryptionResponse {
1463
1526
  }
1464
1527
  /**
1465
1528
  * This is the external signature created from the Eip712 domain
1466
- * on the structure, where userDecryptedShare is bincode::serialize(&payload)
1529
+ * on the structure, where userDecryptedShare is bc2wrap::serialize(&payload)
1467
1530
  * struct UserDecryptResponseVerification {
1468
1531
  * bytes publicKey;
1469
1532
  * uint256\[\] ctHandles;
@@ -1479,7 +1542,7 @@ class UserDecryptionResponse {
1479
1542
  }
1480
1543
  /**
1481
1544
  * This is the external signature created from the Eip712 domain
1482
- * on the structure, where userDecryptedShare is bincode::serialize(&payload)
1545
+ * on the structure, where userDecryptedShare is bc2wrap::serialize(&payload)
1483
1546
  * struct UserDecryptResponseVerification {
1484
1547
  * bytes publicKey;
1485
1548
  * uint256\[\] ctHandles;
@@ -1814,6 +1877,16 @@ module.exports.__wbg_require_79b1e9274cde3c87 = function() { return handleError(
1814
1877
  return ret;
1815
1878
  }, arguments) };
1816
1879
 
1880
+ module.exports.__wbg_serveridaddr_new = function(arg0) {
1881
+ const ret = ServerIdAddr.__wrap(arg0);
1882
+ return ret;
1883
+ };
1884
+
1885
+ module.exports.__wbg_serveridaddr_unwrap = function(arg0) {
1886
+ const ret = ServerIdAddr.__unwrap(arg0);
1887
+ return ret;
1888
+ };
1889
+
1817
1890
  module.exports.__wbg_set_65595bdd868b3009 = function(arg0, arg1, arg2) {
1818
1891
  arg0.set(arg1, arg2 >>> 0);
1819
1892
  };
package/kms_lib_bg.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "collaborators": [
4
4
  "Zama"
5
5
  ],
6
- "version": "0.11.0-rc15",
6
+ "version": "0.11.0-rc17",
7
7
  "license": "BSD-3-Clause-Clear",
8
8
  "files": [
9
9
  "kms_lib_bg.wasm",