@zama-fhe/relayer-sdk 0.1.0-3 → 0.1.0-5
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/bundle/fhevm.js +5350 -5318
- package/bundle/fhevm.umd.cjs +12 -12
- package/bundle/kms_lib_bg.wasm +0 -0
- package/lib/kms_lib_bg.wasm +0 -0
- package/lib/node.cjs +10 -6
- package/lib/node.js +11 -7
- package/lib/web.js +86 -23
- package/package.json +3 -3
package/bundle/kms_lib_bg.wasm
CHANGED
|
Binary file
|
package/lib/kms_lib_bg.wasm
CHANGED
|
Binary file
|
package/lib/node.cjs
CHANGED
|
@@ -368,8 +368,8 @@ const userDecryptRequest = (kmsSigners, gatewayChainId, chainId, verifyingContra
|
|
|
368
368
|
let pubKey;
|
|
369
369
|
let privKey;
|
|
370
370
|
try {
|
|
371
|
-
pubKey = nodeTkms.
|
|
372
|
-
privKey = nodeTkms.
|
|
371
|
+
pubKey = nodeTkms.u8vec_to_ml_kem_pke_pk(fromHexString(publicKey));
|
|
372
|
+
privKey = nodeTkms.u8vec_to_ml_kem_pke_sk(fromHexString(privateKey));
|
|
373
373
|
}
|
|
374
374
|
catch (e) {
|
|
375
375
|
throw new Error('Invalid public or private key', { cause: e });
|
|
@@ -398,7 +398,11 @@ const userDecryptRequest = (kmsSigners, gatewayChainId, chainId, verifyingContra
|
|
|
398
398
|
if (json.status === 'failure') {
|
|
399
399
|
throw new Error("User decrypt failed: the user decryption didn't succeed for an unknown reason", { cause: json });
|
|
400
400
|
}
|
|
401
|
-
|
|
401
|
+
// assume the KMS Signers have the correct order
|
|
402
|
+
let indexedKmsSigners = kmsSigners.map((signer, index) => {
|
|
403
|
+
return nodeTkms.new_server_id_addr(index + 1, signer);
|
|
404
|
+
});
|
|
405
|
+
const client = nodeTkms.new_client(indexedKmsSigners, userAddress, 'default');
|
|
402
406
|
try {
|
|
403
407
|
const buffer = new ArrayBuffer(32);
|
|
404
408
|
const view = new DataView(buffer);
|
|
@@ -1067,10 +1071,10 @@ const createEIP712 = (gatewayChainId, verifyingContract, contractsChainId) => (p
|
|
|
1067
1071
|
};
|
|
1068
1072
|
};
|
|
1069
1073
|
const generateKeypair = () => {
|
|
1070
|
-
const keypair = nodeTkms.
|
|
1074
|
+
const keypair = nodeTkms.ml_kem_pke_keygen();
|
|
1071
1075
|
return {
|
|
1072
|
-
publicKey: toHexString(nodeTkms.
|
|
1073
|
-
privateKey: toHexString(nodeTkms.
|
|
1076
|
+
publicKey: toHexString(nodeTkms.ml_kem_pke_pk_to_u8vec(nodeTkms.ml_kem_pke_get_pk(keypair))),
|
|
1077
|
+
privateKey: toHexString(nodeTkms.ml_kem_pke_sk_to_u8vec(keypair)),
|
|
1074
1078
|
};
|
|
1075
1079
|
};
|
|
1076
1080
|
|
package/lib/node.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JsonRpcProvider, BrowserProvider, Contract, ethers, getAddress, isAddress, AbiCoder } from 'ethers';
|
|
2
2
|
import { TfheCompactPublicKey, CompactPkeCrs, CompactCiphertextList, ZkComputeLoad, ShortintParameters, ShortintParametersName, ShortintCompactPublicKeyEncryptionParameters, ShortintCompactPublicKeyEncryptionParametersName, TfheConfigBuilder, TfheClientKey } from 'node-tfhe';
|
|
3
|
-
import {
|
|
3
|
+
import { u8vec_to_ml_kem_pke_pk, u8vec_to_ml_kem_pke_sk, new_server_id_addr, new_client, process_user_decryption_resp_from_js, ml_kem_pke_keygen, ml_kem_pke_pk_to_u8vec, ml_kem_pke_get_pk, ml_kem_pke_sk_to_u8vec } from 'node-tkms';
|
|
4
4
|
import createHash from 'keccak';
|
|
5
5
|
import fetchRetry from 'fetch-retry';
|
|
6
6
|
|
|
@@ -366,8 +366,8 @@ const userDecryptRequest = (kmsSigners, gatewayChainId, chainId, verifyingContra
|
|
|
366
366
|
let pubKey;
|
|
367
367
|
let privKey;
|
|
368
368
|
try {
|
|
369
|
-
pubKey =
|
|
370
|
-
privKey =
|
|
369
|
+
pubKey = u8vec_to_ml_kem_pke_pk(fromHexString(publicKey));
|
|
370
|
+
privKey = u8vec_to_ml_kem_pke_sk(fromHexString(privateKey));
|
|
371
371
|
}
|
|
372
372
|
catch (e) {
|
|
373
373
|
throw new Error('Invalid public or private key', { cause: e });
|
|
@@ -396,7 +396,11 @@ const userDecryptRequest = (kmsSigners, gatewayChainId, chainId, verifyingContra
|
|
|
396
396
|
if (json.status === 'failure') {
|
|
397
397
|
throw new Error("User decrypt failed: the user decryption didn't succeed for an unknown reason", { cause: json });
|
|
398
398
|
}
|
|
399
|
-
|
|
399
|
+
// assume the KMS Signers have the correct order
|
|
400
|
+
let indexedKmsSigners = kmsSigners.map((signer, index) => {
|
|
401
|
+
return new_server_id_addr(index + 1, signer);
|
|
402
|
+
});
|
|
403
|
+
const client = new_client(indexedKmsSigners, userAddress, 'default');
|
|
400
404
|
try {
|
|
401
405
|
const buffer = new ArrayBuffer(32);
|
|
402
406
|
const view = new DataView(buffer);
|
|
@@ -1065,10 +1069,10 @@ const createEIP712 = (gatewayChainId, verifyingContract, contractsChainId) => (p
|
|
|
1065
1069
|
};
|
|
1066
1070
|
};
|
|
1067
1071
|
const generateKeypair = () => {
|
|
1068
|
-
const keypair =
|
|
1072
|
+
const keypair = ml_kem_pke_keygen();
|
|
1069
1073
|
return {
|
|
1070
|
-
publicKey: toHexString(
|
|
1071
|
-
privateKey: toHexString(
|
|
1074
|
+
publicKey: toHexString(ml_kem_pke_pk_to_u8vec(ml_kem_pke_get_pk(keypair))),
|
|
1075
|
+
privateKey: toHexString(ml_kem_pke_sk_to_u8vec(keypair)),
|
|
1072
1076
|
};
|
|
1073
1077
|
};
|
|
1074
1078
|
|
package/lib/web.js
CHANGED
|
@@ -25189,6 +25189,23 @@ function takeFromExternrefTable0(idx) {
|
|
|
25189
25189
|
return value;
|
|
25190
25190
|
}
|
|
25191
25191
|
|
|
25192
|
+
/**
|
|
25193
|
+
* Create a new [ServerIdAddr] structure that holds an ID and an address
|
|
25194
|
+
* which must be a valid EIP-55 address, notably prefixed with "0x".
|
|
25195
|
+
* @param {number} id
|
|
25196
|
+
* @param {string} addr
|
|
25197
|
+
* @returns {ServerIdAddr}
|
|
25198
|
+
*/
|
|
25199
|
+
function new_server_id_addr(id, addr) {
|
|
25200
|
+
const ptr0 = passStringToWasm0(addr, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
25201
|
+
const len0 = WASM_VECTOR_LEN;
|
|
25202
|
+
const ret = wasm.new_server_id_addr(id, ptr0, len0);
|
|
25203
|
+
if (ret[2]) {
|
|
25204
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
25205
|
+
}
|
|
25206
|
+
return ServerIdAddr.__wrap(ret[0]);
|
|
25207
|
+
}
|
|
25208
|
+
|
|
25192
25209
|
function passArrayJsValueToWasm0(array, malloc) {
|
|
25193
25210
|
const ptr = malloc(array.length * 4, 4) >>> 0;
|
|
25194
25211
|
for (let i = 0; i < array.length; i++) {
|
|
@@ -25201,15 +25218,15 @@ function passArrayJsValueToWasm0(array, malloc) {
|
|
|
25201
25218
|
/**
|
|
25202
25219
|
* Instantiate a new client.
|
|
25203
25220
|
*
|
|
25204
|
-
* * `server_addrs` - a list of KMS server EIP-55 addresses,
|
|
25205
|
-
*
|
|
25221
|
+
* * `server_addrs` - a list of KMS server ID with EIP-55 addresses,
|
|
25222
|
+
* the elements in the list can be created using [new_server_id_addr].
|
|
25206
25223
|
*
|
|
25207
25224
|
* * `client_address_hex` - the client (wallet) address in hex,
|
|
25208
25225
|
* must be prefixed with "0x".
|
|
25209
25226
|
*
|
|
25210
25227
|
* * `fhe_parameter` - the parameter choice, which can be either `"test"` or `"default"`.
|
|
25211
25228
|
* The "default" parameter choice is selected if no matching string is found.
|
|
25212
|
-
* @param {
|
|
25229
|
+
* @param {ServerIdAddr[]} server_addrs
|
|
25213
25230
|
* @param {string} client_address_hex
|
|
25214
25231
|
* @param {string} fhe_parameter
|
|
25215
25232
|
* @returns {Client}
|
|
@@ -25242,8 +25259,8 @@ function getArrayJsValueFromWasm0(ptr, len) {
|
|
|
25242
25259
|
/**
|
|
25243
25260
|
* @returns {PrivateEncKey}
|
|
25244
25261
|
*/
|
|
25245
|
-
function
|
|
25246
|
-
const ret = wasm.
|
|
25262
|
+
function ml_kem_pke_keygen() {
|
|
25263
|
+
const ret = wasm.ml_kem_pke_keygen();
|
|
25247
25264
|
return PrivateEncKey.__wrap(ret);
|
|
25248
25265
|
}
|
|
25249
25266
|
|
|
@@ -25251,9 +25268,9 @@ function cryptobox_keygen() {
|
|
|
25251
25268
|
* @param {PrivateEncKey} sk
|
|
25252
25269
|
* @returns {PublicEncKey}
|
|
25253
25270
|
*/
|
|
25254
|
-
function
|
|
25271
|
+
function ml_kem_pke_get_pk(sk) {
|
|
25255
25272
|
_assertClass(sk, PrivateEncKey);
|
|
25256
|
-
const ret = wasm.
|
|
25273
|
+
const ret = wasm.ml_kem_pke_get_pk(sk.__wbg_ptr);
|
|
25257
25274
|
return PublicEncKey.__wrap(ret);
|
|
25258
25275
|
}
|
|
25259
25276
|
|
|
@@ -25261,9 +25278,9 @@ function cryptobox_get_pk(sk) {
|
|
|
25261
25278
|
* @param {PublicEncKey} pk
|
|
25262
25279
|
* @returns {Uint8Array}
|
|
25263
25280
|
*/
|
|
25264
|
-
function
|
|
25281
|
+
function ml_kem_pke_pk_to_u8vec(pk) {
|
|
25265
25282
|
_assertClass(pk, PublicEncKey);
|
|
25266
|
-
const ret = wasm.
|
|
25283
|
+
const ret = wasm.ml_kem_pke_pk_to_u8vec(pk.__wbg_ptr);
|
|
25267
25284
|
if (ret[3]) {
|
|
25268
25285
|
throw takeFromExternrefTable0(ret[2]);
|
|
25269
25286
|
}
|
|
@@ -25276,9 +25293,9 @@ function cryptobox_pk_to_u8vec(pk) {
|
|
|
25276
25293
|
* @param {PrivateEncKey} sk
|
|
25277
25294
|
* @returns {Uint8Array}
|
|
25278
25295
|
*/
|
|
25279
|
-
function
|
|
25296
|
+
function ml_kem_pke_sk_to_u8vec(sk) {
|
|
25280
25297
|
_assertClass(sk, PrivateEncKey);
|
|
25281
|
-
const ret = wasm.
|
|
25298
|
+
const ret = wasm.ml_kem_pke_sk_to_u8vec(sk.__wbg_ptr);
|
|
25282
25299
|
if (ret[3]) {
|
|
25283
25300
|
throw takeFromExternrefTable0(ret[2]);
|
|
25284
25301
|
}
|
|
@@ -25291,10 +25308,10 @@ function cryptobox_sk_to_u8vec(sk) {
|
|
|
25291
25308
|
* @param {Uint8Array} v
|
|
25292
25309
|
* @returns {PublicEncKey}
|
|
25293
25310
|
*/
|
|
25294
|
-
function
|
|
25311
|
+
function u8vec_to_ml_kem_pke_pk(v) {
|
|
25295
25312
|
const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
|
|
25296
25313
|
const len0 = WASM_VECTOR_LEN;
|
|
25297
|
-
const ret = wasm.
|
|
25314
|
+
const ret = wasm.u8vec_to_ml_kem_pke_pk(ptr0, len0);
|
|
25298
25315
|
if (ret[2]) {
|
|
25299
25316
|
throw takeFromExternrefTable0(ret[1]);
|
|
25300
25317
|
}
|
|
@@ -25305,10 +25322,10 @@ function u8vec_to_cryptobox_pk(v) {
|
|
|
25305
25322
|
* @param {Uint8Array} v
|
|
25306
25323
|
* @returns {PrivateEncKey}
|
|
25307
25324
|
*/
|
|
25308
|
-
function
|
|
25325
|
+
function u8vec_to_ml_kem_pke_sk(v) {
|
|
25309
25326
|
const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc);
|
|
25310
25327
|
const len0 = WASM_VECTOR_LEN;
|
|
25311
|
-
const ret = wasm.
|
|
25328
|
+
const ret = wasm.u8vec_to_ml_kem_pke_sk(ptr0, len0);
|
|
25312
25329
|
if (ret[2]) {
|
|
25313
25330
|
throw takeFromExternrefTable0(ret[1]);
|
|
25314
25331
|
}
|
|
@@ -25511,6 +25528,40 @@ class PublicEncKey {
|
|
|
25511
25528
|
? { register: () => {}, unregister: () => {} }
|
|
25512
25529
|
: new FinalizationRegistry(ptr => wasm.__wbg_requestid_free(ptr >>> 0, 1));
|
|
25513
25530
|
|
|
25531
|
+
const ServerIdAddrFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
25532
|
+
? { register: () => {}, unregister: () => {} }
|
|
25533
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_serveridaddr_free(ptr >>> 0, 1));
|
|
25534
|
+
|
|
25535
|
+
class ServerIdAddr {
|
|
25536
|
+
|
|
25537
|
+
static __wrap(ptr) {
|
|
25538
|
+
ptr = ptr >>> 0;
|
|
25539
|
+
const obj = Object.create(ServerIdAddr.prototype);
|
|
25540
|
+
obj.__wbg_ptr = ptr;
|
|
25541
|
+
ServerIdAddrFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
25542
|
+
return obj;
|
|
25543
|
+
}
|
|
25544
|
+
|
|
25545
|
+
static __unwrap(jsValue) {
|
|
25546
|
+
if (!(jsValue instanceof ServerIdAddr)) {
|
|
25547
|
+
return 0;
|
|
25548
|
+
}
|
|
25549
|
+
return jsValue.__destroy_into_raw();
|
|
25550
|
+
}
|
|
25551
|
+
|
|
25552
|
+
__destroy_into_raw() {
|
|
25553
|
+
const ptr = this.__wbg_ptr;
|
|
25554
|
+
this.__wbg_ptr = 0;
|
|
25555
|
+
ServerIdAddrFinalization.unregister(this);
|
|
25556
|
+
return ptr;
|
|
25557
|
+
}
|
|
25558
|
+
|
|
25559
|
+
free() {
|
|
25560
|
+
const ptr = this.__destroy_into_raw();
|
|
25561
|
+
wasm.__wbg_serveridaddr_free(ptr, 0);
|
|
25562
|
+
}
|
|
25563
|
+
}
|
|
25564
|
+
|
|
25514
25565
|
const TypedCiphertextFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
25515
25566
|
? { register: () => {}, unregister: () => {} }
|
|
25516
25567
|
: new FinalizationRegistry(ptr => wasm.__wbg_typedciphertext_free(ptr >>> 0, 1));
|
|
@@ -25835,7 +25886,7 @@ class UserDecryptionResponse {
|
|
|
25835
25886
|
}
|
|
25836
25887
|
/**
|
|
25837
25888
|
* This is the external signature created from the Eip712 domain
|
|
25838
|
-
* on the structure, where userDecryptedShare is
|
|
25889
|
+
* on the structure, where userDecryptedShare is bc2wrap::serialize(&payload)
|
|
25839
25890
|
* struct UserDecryptResponseVerification {
|
|
25840
25891
|
* bytes publicKey;
|
|
25841
25892
|
* uint256\[\] ctHandles;
|
|
@@ -25851,7 +25902,7 @@ class UserDecryptionResponse {
|
|
|
25851
25902
|
}
|
|
25852
25903
|
/**
|
|
25853
25904
|
* This is the external signature created from the Eip712 domain
|
|
25854
|
-
* on the structure, where userDecryptedShare is
|
|
25905
|
+
* on the structure, where userDecryptedShare is bc2wrap::serialize(&payload)
|
|
25855
25906
|
* struct UserDecryptResponseVerification {
|
|
25856
25907
|
* bytes publicKey;
|
|
25857
25908
|
* uint256\[\] ctHandles;
|
|
@@ -26188,6 +26239,14 @@ function __wbg_get_imports() {
|
|
|
26188
26239
|
const ret = module.require;
|
|
26189
26240
|
return ret;
|
|
26190
26241
|
}, arguments) };
|
|
26242
|
+
imports.wbg.__wbg_serveridaddr_new = function(arg0) {
|
|
26243
|
+
const ret = ServerIdAddr.__wrap(arg0);
|
|
26244
|
+
return ret;
|
|
26245
|
+
};
|
|
26246
|
+
imports.wbg.__wbg_serveridaddr_unwrap = function(arg0) {
|
|
26247
|
+
const ret = ServerIdAddr.__unwrap(arg0);
|
|
26248
|
+
return ret;
|
|
26249
|
+
};
|
|
26191
26250
|
imports.wbg.__wbg_set_65595bdd868b3009 = function(arg0, arg1, arg2) {
|
|
26192
26251
|
arg0.set(arg1, arg2 >>> 0);
|
|
26193
26252
|
};
|
|
@@ -26519,8 +26578,8 @@ const userDecryptRequest = (kmsSigners, gatewayChainId, chainId, verifyingContra
|
|
|
26519
26578
|
let pubKey;
|
|
26520
26579
|
let privKey;
|
|
26521
26580
|
try {
|
|
26522
|
-
pubKey =
|
|
26523
|
-
privKey =
|
|
26581
|
+
pubKey = u8vec_to_ml_kem_pke_pk(fromHexString(publicKey));
|
|
26582
|
+
privKey = u8vec_to_ml_kem_pke_sk(fromHexString(privateKey));
|
|
26524
26583
|
}
|
|
26525
26584
|
catch (e) {
|
|
26526
26585
|
throw new Error('Invalid public or private key', { cause: e });
|
|
@@ -26549,7 +26608,11 @@ const userDecryptRequest = (kmsSigners, gatewayChainId, chainId, verifyingContra
|
|
|
26549
26608
|
if (json.status === 'failure') {
|
|
26550
26609
|
throw new Error("User decrypt failed: the user decryption didn't succeed for an unknown reason", { cause: json });
|
|
26551
26610
|
}
|
|
26552
|
-
|
|
26611
|
+
// assume the KMS Signers have the correct order
|
|
26612
|
+
let indexedKmsSigners = kmsSigners.map((signer, index) => {
|
|
26613
|
+
return new_server_id_addr(index + 1, signer);
|
|
26614
|
+
});
|
|
26615
|
+
const client = new_client(indexedKmsSigners, userAddress, 'default');
|
|
26553
26616
|
try {
|
|
26554
26617
|
const buffer = new ArrayBuffer(32);
|
|
26555
26618
|
const view = new DataView(buffer);
|
|
@@ -27218,10 +27281,10 @@ const createEIP712 = (gatewayChainId, verifyingContract, contractsChainId) => (p
|
|
|
27218
27281
|
};
|
|
27219
27282
|
};
|
|
27220
27283
|
const generateKeypair = () => {
|
|
27221
|
-
const keypair =
|
|
27284
|
+
const keypair = ml_kem_pke_keygen();
|
|
27222
27285
|
return {
|
|
27223
|
-
publicKey: toHexString(
|
|
27224
|
-
privateKey: toHexString(
|
|
27286
|
+
publicKey: toHexString(ml_kem_pke_pk_to_u8vec(ml_kem_pke_get_pk(keypair))),
|
|
27287
|
+
privateKey: toHexString(ml_kem_pke_sk_to_u8vec(keypair)),
|
|
27225
27288
|
};
|
|
27226
27289
|
};
|
|
27227
27290
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zama-fhe/relayer-sdk",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-5",
|
|
4
4
|
"description": "fhevm Relayer SDK",
|
|
5
5
|
"main": "lib/node.js",
|
|
6
6
|
"types": "lib/node.d.ts",
|
|
@@ -63,9 +63,9 @@
|
|
|
63
63
|
"fetch-retry": "^6.0.0",
|
|
64
64
|
"keccak": "^3.0.4",
|
|
65
65
|
"node-tfhe": "^1.1.2",
|
|
66
|
-
"node-tkms": "0.11.0-
|
|
66
|
+
"node-tkms": "0.11.0-rc17",
|
|
67
67
|
"tfhe": "^1.1.2",
|
|
68
|
-
"tkms": "0.11.0-
|
|
68
|
+
"tkms": "0.11.0-rc17",
|
|
69
69
|
"wasm-feature-detect": "^1.8.0"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|