@zama-fhe/relayer-sdk 0.4.0-alpha.0 → 0.4.0-alpha.1
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/relayer-sdk-js.js +4226 -4178
- package/bundle/relayer-sdk-js.umd.cjs +5 -5
- package/bundle.d.ts +1 -1
- package/lib/node.cjs +249 -212
- package/lib/node.d.ts +33 -114
- package/lib/node.js +250 -213
- package/lib/web.d.ts +33 -114
- package/lib/web.js +250 -213
- package/package.json +5 -2
package/lib/web.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonRpcProvider, BrowserProvider, Contract, getAddress as getAddress$2,
|
|
1
|
+
import { JsonRpcProvider, BrowserProvider, Contract, getAddress as getAddress$2, isAddress as isAddress$1, keccak256, ethers, AbiCoder } from 'ethers';
|
|
2
2
|
import { threads } from 'wasm-feature-detect';
|
|
3
3
|
|
|
4
4
|
var global$1 = (typeof global !== "undefined" ? global :
|
|
@@ -16254,31 +16254,9 @@ const SERIALIZED_SIZE_LIMIT_CIPHERTEXT = BigInt(1024 * 1024 * 512);
|
|
|
16254
16254
|
const SERIALIZED_SIZE_LIMIT_PK = BigInt(1024 * 1024 * 512);
|
|
16255
16255
|
const SERIALIZED_SIZE_LIMIT_CRS = BigInt(1024 * 1024 * 512);
|
|
16256
16256
|
|
|
16257
|
-
|
|
16258
|
-
|
|
16259
|
-
|
|
16260
|
-
case 'BearerToken':
|
|
16261
|
-
init.headers['Authorization'] =
|
|
16262
|
-
`Bearer ${auth.token}`;
|
|
16263
|
-
break;
|
|
16264
|
-
case 'ApiKeyHeader':
|
|
16265
|
-
init.headers[auth.header || 'x-api-key'] =
|
|
16266
|
-
auth.value;
|
|
16267
|
-
break;
|
|
16268
|
-
case 'ApiKeyCookie':
|
|
16269
|
-
if (typeof window !== 'undefined') {
|
|
16270
|
-
document.cookie = `${auth.cookie || 'x-api-key'}=${auth.value}; path=/; SameSite=Lax; Secure; HttpOnly;`;
|
|
16271
|
-
init.credentials = 'include';
|
|
16272
|
-
}
|
|
16273
|
-
else {
|
|
16274
|
-
let cookie = `${auth.cookie || 'x-api-key'}=${auth.value};`;
|
|
16275
|
-
init.headers['Cookie'] = cookie;
|
|
16276
|
-
}
|
|
16277
|
-
break;
|
|
16278
|
-
}
|
|
16279
|
-
}
|
|
16280
|
-
return init;
|
|
16281
|
-
}
|
|
16257
|
+
// This file is auto-generated
|
|
16258
|
+
const version = '0.4.0-alpha.1';
|
|
16259
|
+
const sdkName = '@zama-fhe/relayer-sdk';
|
|
16282
16260
|
|
|
16283
16261
|
function getErrorCause(e) {
|
|
16284
16262
|
if (e instanceof Error && typeof e.cause === 'object' && e.cause !== null) {
|
|
@@ -16460,7 +16438,39 @@ function throwRelayerUnknownError(operation, error, message) {
|
|
|
16460
16438
|
});
|
|
16461
16439
|
}
|
|
16462
16440
|
|
|
16463
|
-
|
|
16441
|
+
/**
|
|
16442
|
+
* Set the authentication method for the request. The default is no authentication.
|
|
16443
|
+
* It supports:
|
|
16444
|
+
* - Bearer Token
|
|
16445
|
+
* - Custom header
|
|
16446
|
+
* - Custom cookie
|
|
16447
|
+
*/
|
|
16448
|
+
function setAuth(init, auth) {
|
|
16449
|
+
if (auth) {
|
|
16450
|
+
switch (auth.__type) {
|
|
16451
|
+
case 'BearerToken':
|
|
16452
|
+
init.headers['Authorization'] =
|
|
16453
|
+
`Bearer ${auth.token}`;
|
|
16454
|
+
break;
|
|
16455
|
+
case 'ApiKeyHeader':
|
|
16456
|
+
init.headers[auth.header || 'x-api-key'] =
|
|
16457
|
+
auth.value;
|
|
16458
|
+
break;
|
|
16459
|
+
case 'ApiKeyCookie':
|
|
16460
|
+
if (typeof window !== 'undefined') {
|
|
16461
|
+
document.cookie = `${auth.cookie || 'x-api-key'}=${auth.value}; path=/; SameSite=Lax; Secure; HttpOnly;`;
|
|
16462
|
+
init.credentials = 'include';
|
|
16463
|
+
}
|
|
16464
|
+
else {
|
|
16465
|
+
let cookie = `${auth.cookie || 'x-api-key'}=${auth.value};`;
|
|
16466
|
+
init.headers['Cookie'] = cookie;
|
|
16467
|
+
}
|
|
16468
|
+
break;
|
|
16469
|
+
}
|
|
16470
|
+
}
|
|
16471
|
+
return init;
|
|
16472
|
+
}
|
|
16473
|
+
|
|
16464
16474
|
function assertIsRelayerV1FetchResponseJson(json) {
|
|
16465
16475
|
if (!json || typeof json !== 'object') {
|
|
16466
16476
|
throw new Error('Unexpected response JSON.');
|
|
@@ -16471,11 +16481,13 @@ function assertIsRelayerV1FetchResponseJson(json) {
|
|
|
16471
16481
|
throw new Error("Unexpected response JSON format: missing 'response' property.");
|
|
16472
16482
|
}
|
|
16473
16483
|
}
|
|
16474
|
-
async function
|
|
16484
|
+
async function fetchRelayerV1Post(relayerOperation, url, payload, options) {
|
|
16475
16485
|
const init = setAuth({
|
|
16476
16486
|
method: 'POST',
|
|
16477
16487
|
headers: {
|
|
16478
16488
|
'Content-Type': 'application/json',
|
|
16489
|
+
'ZAMA-SDK-VERSION': `${version}`,
|
|
16490
|
+
'ZAMA-SDK-NAME': `${sdkName}`,
|
|
16479
16491
|
},
|
|
16480
16492
|
body: JSON.stringify(payload),
|
|
16481
16493
|
}, options?.auth);
|
|
@@ -16506,14 +16518,20 @@ async function fetchRelayerJsonRpcPost(relayerOperation, url, payload, options)
|
|
|
16506
16518
|
}
|
|
16507
16519
|
return json;
|
|
16508
16520
|
}
|
|
16509
|
-
async function
|
|
16521
|
+
async function fetchRelayerV1Get(relayerOperation, url) {
|
|
16522
|
+
const init = {
|
|
16523
|
+
method: 'GET',
|
|
16524
|
+
headers: {
|
|
16525
|
+
'ZAMA-SDK-VERSION': `${version}`,
|
|
16526
|
+
'ZAMA-SDK-NAME': `${sdkName}`,
|
|
16527
|
+
},
|
|
16528
|
+
};
|
|
16510
16529
|
let response;
|
|
16511
16530
|
let json;
|
|
16512
16531
|
try {
|
|
16513
|
-
response = await fetch(url);
|
|
16532
|
+
response = await fetch(url, init);
|
|
16514
16533
|
}
|
|
16515
16534
|
catch (e) {
|
|
16516
|
-
console.log(e);
|
|
16517
16535
|
throwRelayerUnknownError(relayerOperation, e);
|
|
16518
16536
|
}
|
|
16519
16537
|
if (!response.ok) {
|
|
@@ -16541,7 +16559,7 @@ const getKeysFromRelayer = async (versionUrl, publicKeyId) => {
|
|
|
16541
16559
|
if (keyurlCache[versionUrl]) {
|
|
16542
16560
|
return keyurlCache[versionUrl];
|
|
16543
16561
|
}
|
|
16544
|
-
const data = await
|
|
16562
|
+
const data = await fetchRelayerV1Get('KEY_URL', `${versionUrl}/keyurl`);
|
|
16545
16563
|
try {
|
|
16546
16564
|
let pubKeyUrl;
|
|
16547
16565
|
// If no publicKeyId is provided, use the first one
|
|
@@ -16630,7 +16648,7 @@ class RelayerErrorBase extends Error {
|
|
|
16630
16648
|
_docsPath;
|
|
16631
16649
|
_docsUrl;
|
|
16632
16650
|
_version;
|
|
16633
|
-
static VERSION =
|
|
16651
|
+
static VERSION = version;
|
|
16634
16652
|
static DEFAULT_DOCS_BASE_URL = 'https//docs.zama.org';
|
|
16635
16653
|
static FULL_VERSION = `@zama-fhe/relayer-sdk@${RelayerErrorBase.VERSION}`;
|
|
16636
16654
|
constructor(params) {
|
|
@@ -17039,6 +17057,14 @@ function assertRecordStringArrayProperty(o, property, objName) {
|
|
|
17039
17057
|
}
|
|
17040
17058
|
}
|
|
17041
17059
|
}
|
|
17060
|
+
function safeJSONstringify(o) {
|
|
17061
|
+
try {
|
|
17062
|
+
return JSON.stringify(o, (_, v) => typeof v === 'bigint' ? v.toString() : v);
|
|
17063
|
+
}
|
|
17064
|
+
catch {
|
|
17065
|
+
return '';
|
|
17066
|
+
}
|
|
17067
|
+
}
|
|
17042
17068
|
|
|
17043
17069
|
const abiKmsVerifier = [
|
|
17044
17070
|
'function getKmsSigners() view returns (address[])',
|
|
@@ -17138,6 +17164,7 @@ const getCoprocessorSignersThreshold = async (provider, inputVerifierContractAdd
|
|
|
17138
17164
|
return Number(threshold); // threshold is always supposed to fit in a number
|
|
17139
17165
|
};
|
|
17140
17166
|
|
|
17167
|
+
// This file contains common utilities for both user and public decryption requests
|
|
17141
17168
|
const NumEncryptedBits = {
|
|
17142
17169
|
0: 2, // ebool
|
|
17143
17170
|
2: 8, // euint8
|
|
@@ -17148,17 +17175,6 @@ const NumEncryptedBits = {
|
|
|
17148
17175
|
7: 160, // eaddress
|
|
17149
17176
|
8: 256, // euint256
|
|
17150
17177
|
};
|
|
17151
|
-
function getHandleType(handle) {
|
|
17152
|
-
if (handle.length !== 66) {
|
|
17153
|
-
throw new Error(`Handle ${handle} is not of valid length`);
|
|
17154
|
-
}
|
|
17155
|
-
const hexPair = handle.slice(-4, -2).toLowerCase();
|
|
17156
|
-
const typeDiscriminant = parseInt(hexPair, 16);
|
|
17157
|
-
if (!(typeDiscriminant in NumEncryptedBits)) {
|
|
17158
|
-
throw new Error(`Handle ${handle} is not of valid type`);
|
|
17159
|
-
}
|
|
17160
|
-
return typeDiscriminant;
|
|
17161
|
-
}
|
|
17162
17178
|
function checkEncryptedBits(handles) {
|
|
17163
17179
|
let total = 0;
|
|
17164
17180
|
for (const handle of handles) {
|
|
@@ -17568,9 +17584,7 @@ function checkDeadlineValidity(startTimestamp, durationDays) {
|
|
|
17568
17584
|
throw Error('User decrypt request has expired');
|
|
17569
17585
|
}
|
|
17570
17586
|
}
|
|
17571
|
-
const userDecryptRequest = (kmsSigners, gatewayChainId, chainId, verifyingContractAddress, aclContractAddress,
|
|
17572
|
-
//relayerUrl: string,
|
|
17573
|
-
relayerProvider, provider, instanceOptions) => async (_handles, privateKey, publicKey, signature, contractAddresses, userAddress, startTimestamp, durationDays, options) => {
|
|
17587
|
+
const userDecryptRequest = (kmsSigners, gatewayChainId, chainId, verifyingContractAddress, aclContractAddress, relayerProvider, provider, defaultOptions) => async (_handles, privateKey, publicKey, signature, contractAddresses, userAddress, startTimestamp, durationDays, options) => {
|
|
17574
17588
|
const extraData = '0x00';
|
|
17575
17589
|
let pubKey;
|
|
17576
17590
|
let privKey;
|
|
@@ -17584,16 +17598,16 @@ relayerProvider, provider, instanceOptions) => async (_handles, privateKey, publ
|
|
|
17584
17598
|
// Casting handles if string
|
|
17585
17599
|
const signatureSanitized = signature.replace(/^(0x)/, '');
|
|
17586
17600
|
const publicKeySanitized = publicKey.replace(/^(0x)/, '');
|
|
17587
|
-
const
|
|
17601
|
+
const handleContractPairs = _handles.map((h) => ({
|
|
17588
17602
|
handle: typeof h.handle === 'string'
|
|
17589
17603
|
? toHexString(hexToBytes(h.handle), true)
|
|
17590
17604
|
: toHexString(h.handle, true),
|
|
17591
17605
|
contractAddress: getAddress$1(h.contractAddress),
|
|
17592
17606
|
}));
|
|
17593
|
-
checkEncryptedBits(
|
|
17607
|
+
checkEncryptedBits(handleContractPairs.map((h) => h.handle));
|
|
17594
17608
|
checkDeadlineValidity(BigInt(startTimestamp), BigInt(durationDays));
|
|
17595
|
-
const acl = new
|
|
17596
|
-
const verifications =
|
|
17609
|
+
const acl = new Contract(aclContractAddress, aclABI$1, provider);
|
|
17610
|
+
const verifications = handleContractPairs.map(async ({ handle, contractAddress }) => {
|
|
17597
17611
|
const userAllowed = await acl.persistAllowed(handle, userAddress);
|
|
17598
17612
|
const contractAllowed = await acl.persistAllowed(handle, contractAddress);
|
|
17599
17613
|
if (!userAllowed) {
|
|
@@ -17617,7 +17631,7 @@ relayerProvider, provider, instanceOptions) => async (_handles, privateKey, publ
|
|
|
17617
17631
|
throw e;
|
|
17618
17632
|
});
|
|
17619
17633
|
const payloadForRequest = {
|
|
17620
|
-
handleContractPairs
|
|
17634
|
+
handleContractPairs,
|
|
17621
17635
|
requestValidity: {
|
|
17622
17636
|
startTimestamp: startTimestamp.toString(), // Convert to string
|
|
17623
17637
|
durationDays: durationDays.toString(), // Convert to string
|
|
@@ -17629,13 +17643,10 @@ relayerProvider, provider, instanceOptions) => async (_handles, privateKey, publ
|
|
|
17629
17643
|
publicKey: publicKeySanitized,
|
|
17630
17644
|
extraData,
|
|
17631
17645
|
};
|
|
17632
|
-
const json = await relayerProvider.fetchPostUserDecrypt(payloadForRequest,
|
|
17633
|
-
|
|
17634
|
-
|
|
17635
|
-
|
|
17636
|
-
// payloadForRequest,
|
|
17637
|
-
// instanceOptions ?? options,
|
|
17638
|
-
// );
|
|
17646
|
+
const json = await relayerProvider.fetchPostUserDecrypt(payloadForRequest, {
|
|
17647
|
+
...defaultOptions,
|
|
17648
|
+
...options,
|
|
17649
|
+
});
|
|
17639
17650
|
// assume the KMS Signers have the correct order
|
|
17640
17651
|
let indexedKmsSigners = kmsSigners.map((signer, index) => {
|
|
17641
17652
|
return TKMS.new_server_id_addr(index + 1, signer);
|
|
@@ -17657,13 +17668,13 @@ relayerProvider, provider, instanceOptions) => async (_handles, privateKey, publ
|
|
|
17657
17668
|
signature: signatureSanitized,
|
|
17658
17669
|
client_address: userAddress,
|
|
17659
17670
|
enc_key: publicKeySanitized,
|
|
17660
|
-
ciphertext_handles:
|
|
17671
|
+
ciphertext_handles: handleContractPairs.map((h) => h.handle.replace(/^0x/, '')),
|
|
17661
17672
|
eip712_verifying_contract: verifyingContractAddress,
|
|
17662
17673
|
};
|
|
17663
17674
|
const decryption = TKMS.process_user_decryption_resp_from_js(client, payloadForVerification, eip712Domain, json, //json.response,
|
|
17664
17675
|
pubKey, privKey, true);
|
|
17665
17676
|
const listBigIntDecryptions = decryption.map((d) => bytesToBigInt(d.bytes));
|
|
17666
|
-
const results = buildUserDecryptResults(
|
|
17677
|
+
const results = buildUserDecryptResults(handleContractPairs.map((h) => h.handle), listBigIntDecryptions);
|
|
17667
17678
|
return results;
|
|
17668
17679
|
}
|
|
17669
17680
|
catch (e) {
|
|
@@ -17955,6 +17966,15 @@ function checksummedAddressToBytes20(address) {
|
|
|
17955
17966
|
return bytes;
|
|
17956
17967
|
}
|
|
17957
17968
|
|
|
17969
|
+
class FhevmHandleError extends RelayerErrorBase {
|
|
17970
|
+
constructor({ handle, message }) {
|
|
17971
|
+
super({
|
|
17972
|
+
message: message ?? `FHEVM Handle "${handle}" is invalid.`,
|
|
17973
|
+
name: 'FhevmHandleError',
|
|
17974
|
+
});
|
|
17975
|
+
}
|
|
17976
|
+
}
|
|
17977
|
+
|
|
17958
17978
|
////////////////////////////////////////////////////////////////////////////////
|
|
17959
17979
|
// FhevmHandle
|
|
17960
17980
|
////////////////////////////////////////////////////////////////////////////////
|
|
@@ -17987,6 +18007,16 @@ class FhevmHandle {
|
|
|
17987
18007
|
160: 7,
|
|
17988
18008
|
256: 8,
|
|
17989
18009
|
};
|
|
18010
|
+
static FheTypeIdToSolidityPrimitiveType = {
|
|
18011
|
+
0: 'bool',
|
|
18012
|
+
2: 'uint256',
|
|
18013
|
+
3: 'uint256',
|
|
18014
|
+
4: 'uint256',
|
|
18015
|
+
5: 'uint256',
|
|
18016
|
+
6: 'uint256',
|
|
18017
|
+
7: 'address',
|
|
18018
|
+
8: 'uint256',
|
|
18019
|
+
};
|
|
17990
18020
|
static {
|
|
17991
18021
|
Object.freeze(FhevmHandle.FheTypeIdToEncryptionBitwidths);
|
|
17992
18022
|
Object.freeze(FhevmHandle.FheTypeEncryptionBitwidthsToId);
|
|
@@ -18121,6 +18151,41 @@ class FhevmHandle {
|
|
|
18121
18151
|
toBytes32Hex() {
|
|
18122
18152
|
return bytesToHex(this.toBytes32());
|
|
18123
18153
|
}
|
|
18154
|
+
static checkHandleHex(handle) {
|
|
18155
|
+
if (!isBytes32Hex(handle)) {
|
|
18156
|
+
throw new FhevmHandleError({ handle });
|
|
18157
|
+
}
|
|
18158
|
+
}
|
|
18159
|
+
static isFheTypeId(value) {
|
|
18160
|
+
switch (value) {
|
|
18161
|
+
case 0:
|
|
18162
|
+
// 1: euint4 is deprecated
|
|
18163
|
+
case 2:
|
|
18164
|
+
case 3:
|
|
18165
|
+
case 4:
|
|
18166
|
+
case 5:
|
|
18167
|
+
case 6:
|
|
18168
|
+
case 7:
|
|
18169
|
+
case 8:
|
|
18170
|
+
return true;
|
|
18171
|
+
default:
|
|
18172
|
+
return false;
|
|
18173
|
+
}
|
|
18174
|
+
}
|
|
18175
|
+
static getFheTypeId(handle) {
|
|
18176
|
+
if (!isBytes32Hex(handle)) {
|
|
18177
|
+
throw new FhevmHandleError({ handle });
|
|
18178
|
+
}
|
|
18179
|
+
const hexPair = handle.slice(-4, -2).toLowerCase();
|
|
18180
|
+
const typeDiscriminant = parseInt(hexPair, 16);
|
|
18181
|
+
if (!FhevmHandle.isFheTypeId(typeDiscriminant)) {
|
|
18182
|
+
throw new FhevmHandleError({
|
|
18183
|
+
handle,
|
|
18184
|
+
message: `FHEVM Handle "${handle}" is invalid. Unknown FheType: ${typeDiscriminant}`,
|
|
18185
|
+
});
|
|
18186
|
+
}
|
|
18187
|
+
return typeDiscriminant;
|
|
18188
|
+
}
|
|
18124
18189
|
}
|
|
18125
18190
|
|
|
18126
18191
|
// Add type checking
|
|
@@ -18159,9 +18224,7 @@ function isFhevmRelayerInputProofResponse(json) {
|
|
|
18159
18224
|
return (response.signatures.every((s) => typeof s === 'string') &&
|
|
18160
18225
|
response.handles.every((h) => typeof h === 'string'));
|
|
18161
18226
|
}
|
|
18162
|
-
const createRelayerEncryptedInput = (aclContractAddress, verifyingContractAddressInputVerification, chainId, gatewayChainId,
|
|
18163
|
-
//relayerUrl: string,
|
|
18164
|
-
relayerProvider, tfheCompactPublicKey, publicParams, coprocessorSigners, thresholdCoprocessorSigners, instanceOptions) => (contractAddress, userAddress) => {
|
|
18227
|
+
const createRelayerEncryptedInput = (aclContractAddress, verifyingContractAddressInputVerification, chainId, gatewayChainId, relayerProvider, tfheCompactPublicKey, publicParams, coprocessorSigners, thresholdCoprocessorSigners, defaultOptions) => (contractAddress, userAddress) => {
|
|
18165
18228
|
if (!isAddress$1(contractAddress)) {
|
|
18166
18229
|
throw new Error('Contract address is not a valid address.');
|
|
18167
18230
|
}
|
|
@@ -18213,11 +18276,13 @@ relayerProvider, tfheCompactPublicKey, publicParams, coprocessorSigners, thresho
|
|
|
18213
18276
|
getBits() {
|
|
18214
18277
|
return input.getBits();
|
|
18215
18278
|
},
|
|
18279
|
+
getCiphertextWithInputVerification() {
|
|
18280
|
+
return input.encrypt();
|
|
18281
|
+
},
|
|
18216
18282
|
encrypt: async (options) => {
|
|
18217
18283
|
const extraData = '0x00';
|
|
18218
18284
|
const bits = input.getBits();
|
|
18219
18285
|
const ciphertext = input.encrypt();
|
|
18220
|
-
//console.log(`ciphertext=${toHexString(ciphertext)}`);
|
|
18221
18286
|
const payload = {
|
|
18222
18287
|
contractAddress: getAddress(contractAddress),
|
|
18223
18288
|
userAddress: getAddress(userAddress),
|
|
@@ -18225,13 +18290,10 @@ relayerProvider, tfheCompactPublicKey, publicParams, coprocessorSigners, thresho
|
|
|
18225
18290
|
contractChainId: ('0x' + chainId.toString(16)),
|
|
18226
18291
|
extraData,
|
|
18227
18292
|
};
|
|
18228
|
-
const json = await relayerProvider.fetchPostInputProof(payload,
|
|
18229
|
-
|
|
18230
|
-
|
|
18231
|
-
|
|
18232
|
-
// payload,
|
|
18233
|
-
// options ?? instanceOptions,
|
|
18234
|
-
// );
|
|
18293
|
+
const json = await relayerProvider.fetchPostInputProof(payload, {
|
|
18294
|
+
...defaultOptions,
|
|
18295
|
+
...options,
|
|
18296
|
+
});
|
|
18235
18297
|
if (!isFhevmRelayerInputProofResponse(json)) {
|
|
18236
18298
|
throwRelayerInternalError('INPUT_PROOF', json);
|
|
18237
18299
|
}
|
|
@@ -18243,7 +18305,6 @@ relayerProvider, tfheCompactPublicKey, publicParams, coprocessorSigners, thresho
|
|
|
18243
18305
|
fheTypeEncryptionBitwidths: bits,
|
|
18244
18306
|
});
|
|
18245
18307
|
const handles = fhevmHandles.map((h) => h.toBytes32());
|
|
18246
|
-
//const result = json.response;
|
|
18247
18308
|
const result = json;
|
|
18248
18309
|
// Note that the hex strings returned by the relayer do have have the 0x prefix
|
|
18249
18310
|
if (result.handles && result.handles.length > 0) {
|
|
@@ -18310,6 +18371,21 @@ relayerProvider, tfheCompactPublicKey, publicParams, coprocessorSigners, thresho
|
|
|
18310
18371
|
};
|
|
18311
18372
|
};
|
|
18312
18373
|
|
|
18374
|
+
function ensureError(e) {
|
|
18375
|
+
if (e instanceof Error) {
|
|
18376
|
+
return e;
|
|
18377
|
+
}
|
|
18378
|
+
const message = e.message ?? 'Non-Error value caught in exception handler';
|
|
18379
|
+
const name = e.name ?? 'ErrorWrapper';
|
|
18380
|
+
const cause = e.cause ?? e;
|
|
18381
|
+
const err = new Error(message, { cause });
|
|
18382
|
+
err.name = name;
|
|
18383
|
+
return err;
|
|
18384
|
+
}
|
|
18385
|
+
function assertNever(value, message) {
|
|
18386
|
+
throw new InternalError({ message });
|
|
18387
|
+
}
|
|
18388
|
+
|
|
18313
18389
|
const aclABI = [
|
|
18314
18390
|
'function isAllowedForDecryption(bytes32 handle) view returns (bool)',
|
|
18315
18391
|
];
|
|
@@ -18335,7 +18411,7 @@ function abiEncodeClearValues(clearValues) {
|
|
|
18335
18411
|
const abiValues = [];
|
|
18336
18412
|
for (let i = 0; i < handlesBytes32Hex.length; ++i) {
|
|
18337
18413
|
const handle = handlesBytes32Hex[i];
|
|
18338
|
-
const handleType =
|
|
18414
|
+
const handleType = FhevmHandle.getFheTypeId(handle);
|
|
18339
18415
|
let clearTextValue = clearValues[handle];
|
|
18340
18416
|
if (typeof clearTextValue === 'boolean') {
|
|
18341
18417
|
clearTextValue = clearTextValue ? '0x01' : '0x00';
|
|
@@ -18372,7 +18448,7 @@ function abiEncodeClearValues(clearValues) {
|
|
|
18372
18448
|
break;
|
|
18373
18449
|
}
|
|
18374
18450
|
default: {
|
|
18375
|
-
|
|
18451
|
+
assertNever(handleType, `Unsupported Fhevm primitive type id: ${handleType}`);
|
|
18376
18452
|
}
|
|
18377
18453
|
}
|
|
18378
18454
|
}
|
|
@@ -18397,21 +18473,11 @@ function buildDecryptionProof(kmsSignatures, extraData) {
|
|
|
18397
18473
|
]);
|
|
18398
18474
|
return decryptionProof;
|
|
18399
18475
|
}
|
|
18400
|
-
const CiphertextType = {
|
|
18401
|
-
0: 'bool',
|
|
18402
|
-
2: 'uint256',
|
|
18403
|
-
3: 'uint256',
|
|
18404
|
-
4: 'uint256',
|
|
18405
|
-
5: 'uint256',
|
|
18406
|
-
6: 'uint256',
|
|
18407
|
-
7: 'address',
|
|
18408
|
-
8: 'uint256',
|
|
18409
|
-
};
|
|
18410
18476
|
function deserializeClearValues(handles, decryptedResult) {
|
|
18411
18477
|
let typesList = [];
|
|
18412
18478
|
for (const handle of handles) {
|
|
18413
|
-
const
|
|
18414
|
-
|
|
18479
|
+
const typeDiscriminant = FhevmHandle.getFheTypeId(handle);
|
|
18480
|
+
assertRelayer(FhevmHandle.isFheTypeId(typeDiscriminant));
|
|
18415
18481
|
typesList.push(typeDiscriminant);
|
|
18416
18482
|
}
|
|
18417
18483
|
const restoredEncoded = '0x' +
|
|
@@ -18419,7 +18485,7 @@ function deserializeClearValues(handles, decryptedResult) {
|
|
|
18419
18485
|
decryptedResult.slice(2) +
|
|
18420
18486
|
'00'.repeat(32); // dummy empty bytes[] length (ignored)
|
|
18421
18487
|
const abiTypes = typesList.map((t) => {
|
|
18422
|
-
const abiType =
|
|
18488
|
+
const abiType = FhevmHandle.FheTypeIdToSolidityPrimitiveType[t]; // all types are valid because this was supposedly checked already inside the `checkEncryptedBits` function
|
|
18423
18489
|
return abiType;
|
|
18424
18490
|
});
|
|
18425
18491
|
const coder = new AbiCoder();
|
|
@@ -18430,9 +18496,7 @@ function deserializeClearValues(handles, decryptedResult) {
|
|
|
18430
18496
|
handles.forEach((handle, idx) => (results[handle] = rawValues[idx]));
|
|
18431
18497
|
return results;
|
|
18432
18498
|
}
|
|
18433
|
-
const publicDecryptRequest = (kmsSigners, thresholdSigners, gatewayChainId, verifyingContractAddress, aclContractAddress,
|
|
18434
|
-
//relayerUrl: string,
|
|
18435
|
-
relayerProvider, provider, instanceOptions) => async (_handles, options) => {
|
|
18499
|
+
const publicDecryptRequest = (kmsSigners, thresholdSigners, gatewayChainId, verifyingContractAddress, aclContractAddress, relayerProvider, provider, defaultOptions) => async (_handles, options) => {
|
|
18436
18500
|
const extraData = '0x00';
|
|
18437
18501
|
const acl = new ethers.Contract(aclContractAddress, aclABI, provider);
|
|
18438
18502
|
let handles;
|
|
@@ -18457,13 +18521,10 @@ relayerProvider, provider, instanceOptions) => async (_handles, options) => {
|
|
|
18457
18521
|
ciphertextHandles: handles,
|
|
18458
18522
|
extraData,
|
|
18459
18523
|
};
|
|
18460
|
-
const json = await relayerProvider.fetchPostPublicDecrypt(payloadForRequest,
|
|
18461
|
-
|
|
18462
|
-
|
|
18463
|
-
|
|
18464
|
-
// payloadForRequest,
|
|
18465
|
-
// options ?? instanceOptions,
|
|
18466
|
-
// );
|
|
18524
|
+
const json = await relayerProvider.fetchPostPublicDecrypt(payloadForRequest, {
|
|
18525
|
+
...defaultOptions,
|
|
18526
|
+
...options,
|
|
18527
|
+
});
|
|
18467
18528
|
// verify signatures on decryption:
|
|
18468
18529
|
const domain = {
|
|
18469
18530
|
name: 'Decryption',
|
|
@@ -18659,7 +18720,7 @@ class RelayerV1Provider extends AbstractRelayerProvider {
|
|
|
18659
18720
|
return 1;
|
|
18660
18721
|
}
|
|
18661
18722
|
async fetchGetKeyUrl() {
|
|
18662
|
-
const response = await
|
|
18723
|
+
const response = await fetchRelayerV1Get('KEY_URL', this.keyUrl);
|
|
18663
18724
|
return response;
|
|
18664
18725
|
}
|
|
18665
18726
|
async fetchPostInputProof(payload, options) {
|
|
@@ -18677,12 +18738,12 @@ class RelayerV1Provider extends AbstractRelayerProvider {
|
|
|
18677
18738
|
}
|
|
18678
18739
|
}
|
|
18679
18740
|
*/
|
|
18680
|
-
const json = await
|
|
18741
|
+
const json = await fetchRelayerV1Post('INPUT_PROOF', this.inputProof, payload, options);
|
|
18681
18742
|
assertIsRelayerInputProofResult(json.response, 'fetchPostInputProof()');
|
|
18682
18743
|
return json.response;
|
|
18683
18744
|
}
|
|
18684
18745
|
async fetchPostPublicDecrypt(payload, options) {
|
|
18685
|
-
const json = await
|
|
18746
|
+
const json = await fetchRelayerV1Post('PUBLIC_DECRYPT', this.publicDecrypt, payload, options);
|
|
18686
18747
|
const response = json.response[0];
|
|
18687
18748
|
const result = {
|
|
18688
18749
|
signatures: response.signatures,
|
|
@@ -18693,24 +18754,12 @@ class RelayerV1Provider extends AbstractRelayerProvider {
|
|
|
18693
18754
|
return result;
|
|
18694
18755
|
}
|
|
18695
18756
|
async fetchPostUserDecrypt(payload, options) {
|
|
18696
|
-
const json = await
|
|
18757
|
+
const json = await fetchRelayerV1Post('USER_DECRYPT', this.userDecrypt, payload, options);
|
|
18697
18758
|
assertIsRelayerUserDecryptResult(json.response, 'RelayerUserDecryptResult()');
|
|
18698
18759
|
return json.response;
|
|
18699
18760
|
}
|
|
18700
18761
|
}
|
|
18701
18762
|
|
|
18702
|
-
function ensureError(e) {
|
|
18703
|
-
if (e instanceof Error) {
|
|
18704
|
-
return e;
|
|
18705
|
-
}
|
|
18706
|
-
const message = e.message ?? 'Non-Error value caught in exception handler';
|
|
18707
|
-
const name = e.name ?? 'ErrorWrapper';
|
|
18708
|
-
const cause = e.cause ?? e;
|
|
18709
|
-
const err = new Error(message, { cause });
|
|
18710
|
-
err.name = name;
|
|
18711
|
-
return err;
|
|
18712
|
-
}
|
|
18713
|
-
|
|
18714
18763
|
class RelayerV2ProviderError extends RelayerErrorBase {
|
|
18715
18764
|
_operation;
|
|
18716
18765
|
constructor(params) {
|
|
@@ -19187,22 +19236,6 @@ class RelayerV2RequestInternalError extends RelayerV2RequestErrorBase {
|
|
|
19187
19236
|
}
|
|
19188
19237
|
}
|
|
19189
19238
|
|
|
19190
|
-
function assertIsRelayerV2ResultQueued(value, name) {
|
|
19191
|
-
assertRecordStringProperty(value, 'jobId', name);
|
|
19192
|
-
}
|
|
19193
|
-
|
|
19194
|
-
/*
|
|
19195
|
-
type RelayerV2ResponseQueued = {
|
|
19196
|
-
status: "queued";
|
|
19197
|
-
result: RelayerV2ResultQueued;
|
|
19198
|
-
}
|
|
19199
|
-
*/
|
|
19200
|
-
function assertIsRelayerV2ResponseQueued(value, name) {
|
|
19201
|
-
assertRecordStringProperty(value, 'status', name, 'queued');
|
|
19202
|
-
assertNonNullableRecordProperty(value, 'result', name);
|
|
19203
|
-
assertIsRelayerV2ResultQueued(value.result, `${name}.result`);
|
|
19204
|
-
}
|
|
19205
|
-
|
|
19206
19239
|
class RelayerV2ResponseApiError extends RelayerV2ResponseErrorBase {
|
|
19207
19240
|
constructor(params) {
|
|
19208
19241
|
super({
|
|
@@ -19264,6 +19297,36 @@ class RelayerV2MaxRetryError extends RelayerV2FetchErrorBase {
|
|
|
19264
19297
|
}
|
|
19265
19298
|
}
|
|
19266
19299
|
|
|
19300
|
+
function assertIsRelayerV2PostResultQueued(value, name) {
|
|
19301
|
+
assertRecordStringProperty(value, 'jobId', name);
|
|
19302
|
+
}
|
|
19303
|
+
|
|
19304
|
+
/*
|
|
19305
|
+
{
|
|
19306
|
+
status: 'queued';
|
|
19307
|
+
requestId: string;
|
|
19308
|
+
result: {
|
|
19309
|
+
jobId: string;
|
|
19310
|
+
};
|
|
19311
|
+
}
|
|
19312
|
+
*/
|
|
19313
|
+
function assertIsRelayerV2PostResponseQueued(value, name) {
|
|
19314
|
+
assertRecordStringProperty(value, 'status', name, 'queued');
|
|
19315
|
+
assertRecordStringProperty(value, 'requestId', name);
|
|
19316
|
+
assertNonNullableRecordProperty(value, 'result', name);
|
|
19317
|
+
assertIsRelayerV2PostResultQueued(value.result, `${name}.result`);
|
|
19318
|
+
}
|
|
19319
|
+
/*
|
|
19320
|
+
{
|
|
19321
|
+
status: 'queued';
|
|
19322
|
+
requestId: string;
|
|
19323
|
+
}
|
|
19324
|
+
*/
|
|
19325
|
+
function assertIsRelayerV2GetResponseQueued(value, name) {
|
|
19326
|
+
assertRecordStringProperty(value, 'status', name, 'queued');
|
|
19327
|
+
assertRecordStringProperty(value, 'requestId', name);
|
|
19328
|
+
}
|
|
19329
|
+
|
|
19267
19330
|
class RelayerV2AsyncRequest {
|
|
19268
19331
|
_jobId;
|
|
19269
19332
|
_jobIdTimestamp;
|
|
@@ -19508,14 +19571,15 @@ class RelayerV2AsyncRequest {
|
|
|
19508
19571
|
// - SyntaxError: Expected property name or '}' in JSON at position 1 (line 1 column 2) at JSON.parse (<anonymous>)
|
|
19509
19572
|
const bodyJson = await this._getResponseJson(response);
|
|
19510
19573
|
try {
|
|
19511
|
-
|
|
19574
|
+
assertIsRelayerV2PostResponseQueued(bodyJson, 'body');
|
|
19512
19575
|
}
|
|
19513
19576
|
catch (cause) {
|
|
19514
|
-
this.
|
|
19577
|
+
this._throwResponseInvalidBodyError({
|
|
19515
19578
|
fetchMethod: 'POST',
|
|
19516
19579
|
status: responseStatus,
|
|
19517
19580
|
cause: cause,
|
|
19518
19581
|
elapsed,
|
|
19582
|
+
bodyJson: safeJSONstringify(bodyJson),
|
|
19519
19583
|
});
|
|
19520
19584
|
}
|
|
19521
19585
|
let retry_after_sec = this._getRetryAfterHeaderValueInSecs(response);
|
|
@@ -19550,11 +19614,12 @@ class RelayerV2AsyncRequest {
|
|
|
19550
19614
|
assertIsRelayerV2ResponseFailedWithError400(bodyJson, 'body');
|
|
19551
19615
|
}
|
|
19552
19616
|
catch (cause) {
|
|
19553
|
-
this.
|
|
19617
|
+
this._throwResponseInvalidBodyError({
|
|
19554
19618
|
fetchMethod: 'POST',
|
|
19555
19619
|
status: responseStatus,
|
|
19556
19620
|
cause: cause,
|
|
19557
19621
|
elapsed,
|
|
19622
|
+
bodyJson: safeJSONstringify(bodyJson),
|
|
19558
19623
|
});
|
|
19559
19624
|
}
|
|
19560
19625
|
this._throwRelayerV2ResponseApiError({
|
|
@@ -19574,11 +19639,12 @@ class RelayerV2AsyncRequest {
|
|
|
19574
19639
|
assertIsRelayerV2ResponseFailedWithError429(bodyJson, 'body');
|
|
19575
19640
|
}
|
|
19576
19641
|
catch (cause) {
|
|
19577
|
-
this.
|
|
19642
|
+
this._throwResponseInvalidBodyError({
|
|
19578
19643
|
fetchMethod: 'POST',
|
|
19579
19644
|
status: responseStatus,
|
|
19580
19645
|
cause: cause,
|
|
19581
19646
|
elapsed,
|
|
19647
|
+
bodyJson: safeJSONstringify(bodyJson),
|
|
19582
19648
|
});
|
|
19583
19649
|
}
|
|
19584
19650
|
let retry_after_sec = this._getRetryAfterHeaderValueInSecs(response);
|
|
@@ -19609,11 +19675,12 @@ class RelayerV2AsyncRequest {
|
|
|
19609
19675
|
assertIsRelayerV2ResponseFailedWithError500(bodyJson, 'body');
|
|
19610
19676
|
}
|
|
19611
19677
|
catch (cause) {
|
|
19612
|
-
this.
|
|
19678
|
+
this._throwResponseInvalidBodyError({
|
|
19613
19679
|
fetchMethod: 'POST',
|
|
19614
19680
|
status: responseStatus,
|
|
19615
19681
|
cause: cause,
|
|
19616
19682
|
elapsed,
|
|
19683
|
+
bodyJson: safeJSONstringify(bodyJson),
|
|
19617
19684
|
});
|
|
19618
19685
|
}
|
|
19619
19686
|
this._throwRelayerV2ResponseApiError({
|
|
@@ -19633,11 +19700,12 @@ class RelayerV2AsyncRequest {
|
|
|
19633
19700
|
assertIsRelayerV2ResponseFailedWithError503(bodyJson, 'body');
|
|
19634
19701
|
}
|
|
19635
19702
|
catch (cause) {
|
|
19636
|
-
this.
|
|
19703
|
+
this._throwResponseInvalidBodyError({
|
|
19637
19704
|
fetchMethod: 'POST',
|
|
19638
19705
|
status: responseStatus,
|
|
19639
19706
|
cause: cause,
|
|
19640
19707
|
elapsed,
|
|
19708
|
+
bodyJson: safeJSONstringify(bodyJson),
|
|
19641
19709
|
});
|
|
19642
19710
|
}
|
|
19643
19711
|
this._throwRelayerV2ResponseApiError({
|
|
@@ -19761,6 +19829,7 @@ class RelayerV2AsyncRequest {
|
|
|
19761
19829
|
status: responseStatus,
|
|
19762
19830
|
elapsed,
|
|
19763
19831
|
cause: cause,
|
|
19832
|
+
bodyJson: safeJSONstringify(bodyJson),
|
|
19764
19833
|
});
|
|
19765
19834
|
}
|
|
19766
19835
|
// RelayerV2ResultPublicDecrypt
|
|
@@ -19772,7 +19841,7 @@ class RelayerV2AsyncRequest {
|
|
|
19772
19841
|
case 202: {
|
|
19773
19842
|
const bodyJson = await this._getResponseJson(response);
|
|
19774
19843
|
try {
|
|
19775
|
-
|
|
19844
|
+
assertIsRelayerV2GetResponseQueued(bodyJson, 'body');
|
|
19776
19845
|
}
|
|
19777
19846
|
catch (cause) {
|
|
19778
19847
|
this._throwResponseInvalidBodyError({
|
|
@@ -19780,6 +19849,7 @@ class RelayerV2AsyncRequest {
|
|
|
19780
19849
|
status: responseStatus,
|
|
19781
19850
|
elapsed,
|
|
19782
19851
|
cause: cause,
|
|
19852
|
+
bodyJson: safeJSONstringify(bodyJson),
|
|
19783
19853
|
});
|
|
19784
19854
|
}
|
|
19785
19855
|
let retry_after_sec = this._getRetryAfterHeaderValueInSecs(response);
|
|
@@ -19815,6 +19885,7 @@ class RelayerV2AsyncRequest {
|
|
|
19815
19885
|
status: responseStatus,
|
|
19816
19886
|
elapsed,
|
|
19817
19887
|
cause: cause,
|
|
19888
|
+
bodyJson: safeJSONstringify(bodyJson),
|
|
19818
19889
|
});
|
|
19819
19890
|
}
|
|
19820
19891
|
this._throwRelayerV2ResponseApiError({
|
|
@@ -19837,6 +19908,7 @@ class RelayerV2AsyncRequest {
|
|
|
19837
19908
|
status: responseStatus,
|
|
19838
19909
|
elapsed,
|
|
19839
19910
|
cause: cause,
|
|
19911
|
+
bodyJson: safeJSONstringify(bodyJson),
|
|
19840
19912
|
});
|
|
19841
19913
|
}
|
|
19842
19914
|
this._throwRelayerV2ResponseApiError({
|
|
@@ -19861,6 +19933,7 @@ class RelayerV2AsyncRequest {
|
|
|
19861
19933
|
status: responseStatus,
|
|
19862
19934
|
elapsed,
|
|
19863
19935
|
cause: cause,
|
|
19936
|
+
bodyJson: safeJSONstringify(bodyJson),
|
|
19864
19937
|
});
|
|
19865
19938
|
}
|
|
19866
19939
|
this._throwRelayerV2ResponseApiError({
|
|
@@ -19885,6 +19958,7 @@ class RelayerV2AsyncRequest {
|
|
|
19885
19958
|
status: responseStatus,
|
|
19886
19959
|
elapsed,
|
|
19887
19960
|
cause: cause,
|
|
19961
|
+
bodyJson: safeJSONstringify(bodyJson),
|
|
19888
19962
|
});
|
|
19889
19963
|
}
|
|
19890
19964
|
this._throwRelayerV2ResponseApiError({
|
|
@@ -19909,6 +19983,7 @@ class RelayerV2AsyncRequest {
|
|
|
19909
19983
|
status: responseStatus,
|
|
19910
19984
|
elapsed,
|
|
19911
19985
|
cause: cause,
|
|
19986
|
+
bodyJson: safeJSONstringify(bodyJson),
|
|
19912
19987
|
});
|
|
19913
19988
|
}
|
|
19914
19989
|
this._throwRelayerV2ResponseApiError({
|
|
@@ -20009,6 +20084,8 @@ class RelayerV2AsyncRequest {
|
|
|
20009
20084
|
method: 'POST',
|
|
20010
20085
|
headers: {
|
|
20011
20086
|
'Content-Type': 'application/json',
|
|
20087
|
+
'ZAMA-SDK-VERSION': `${version}`,
|
|
20088
|
+
'ZAMA-SDK-NAME': `${sdkName}`,
|
|
20012
20089
|
},
|
|
20013
20090
|
body: JSON.stringify(this._payload),
|
|
20014
20091
|
...(this._internalAbortSignal
|
|
@@ -20058,9 +20135,16 @@ class RelayerV2AsyncRequest {
|
|
|
20058
20135
|
this._assert(!this._state.terminated, '!this._state.terminated');
|
|
20059
20136
|
this._assert(!this._state.fetching, '!this._state.fetching');
|
|
20060
20137
|
this._trace('_fetchGet', `jobId=${this.jobId}`);
|
|
20061
|
-
const init =
|
|
20062
|
-
|
|
20063
|
-
:
|
|
20138
|
+
const init = {
|
|
20139
|
+
method: 'GET',
|
|
20140
|
+
headers: {
|
|
20141
|
+
'ZAMA-SDK-VERSION': `${version}`,
|
|
20142
|
+
'ZAMA-SDK-NAME': `${sdkName}`,
|
|
20143
|
+
},
|
|
20144
|
+
...(this._internalAbortSignal
|
|
20145
|
+
? { signal: this._internalAbortSignal }
|
|
20146
|
+
: {}),
|
|
20147
|
+
};
|
|
20064
20148
|
this._state.fetching = true;
|
|
20065
20149
|
let response;
|
|
20066
20150
|
try {
|
|
@@ -20313,20 +20397,11 @@ class RelayerV2AsyncRequest {
|
|
|
20313
20397
|
elapsed,
|
|
20314
20398
|
});
|
|
20315
20399
|
}
|
|
20316
|
-
_throwInvalidResponseError(params) {
|
|
20317
|
-
throw new RelayerV2ResponseInvalidBodyError({
|
|
20318
|
-
...params,
|
|
20319
|
-
url: this._url,
|
|
20320
|
-
operation: this._relayerOperation,
|
|
20321
|
-
state: { ...this._state },
|
|
20322
|
-
retryCount: this._retryCount,
|
|
20323
|
-
});
|
|
20324
|
-
}
|
|
20325
20400
|
_throwResponseInvalidBodyError(params) {
|
|
20326
20401
|
throw new RelayerV2ResponseInvalidBodyError({
|
|
20327
20402
|
...params,
|
|
20328
20403
|
url: this._url,
|
|
20329
|
-
jobId: this.
|
|
20404
|
+
jobId: this._jobId,
|
|
20330
20405
|
operation: this._relayerOperation,
|
|
20331
20406
|
state: { ...this._state },
|
|
20332
20407
|
retryCount: this._retryCount,
|
|
@@ -20397,7 +20472,7 @@ function assertIsRelayerV2KeyData(value, name) {
|
|
|
20397
20472
|
assertRecordStringProperty(value, 'dataId', name);
|
|
20398
20473
|
assertRecordStringArrayProperty(value, 'urls', name);
|
|
20399
20474
|
}
|
|
20400
|
-
function
|
|
20475
|
+
function toRelayerV1KeyUrlResponse(response) {
|
|
20401
20476
|
const fheKeyInfoV1 = response.response.fheKeyInfo.map((v2Info) => ({
|
|
20402
20477
|
fhe_public_key: {
|
|
20403
20478
|
data_id: v2Info.fhePublicKey.dataId,
|
|
@@ -20427,7 +20502,7 @@ class RelayerV2Provider extends AbstractRelayerProvider {
|
|
|
20427
20502
|
return 2;
|
|
20428
20503
|
}
|
|
20429
20504
|
async fetchGetKeyUrlV2() {
|
|
20430
|
-
const response = await
|
|
20505
|
+
const response = await fetchRelayerV1Get('KEY_URL', this.keyUrl);
|
|
20431
20506
|
// Relayer error
|
|
20432
20507
|
try {
|
|
20433
20508
|
assertIsRelayerV2GetResponseKeyUrl(response, 'fetchGetKeyUrl()');
|
|
@@ -20441,7 +20516,7 @@ class RelayerV2Provider extends AbstractRelayerProvider {
|
|
|
20441
20516
|
}
|
|
20442
20517
|
async fetchGetKeyUrl() {
|
|
20443
20518
|
const response = await this.fetchGetKeyUrlV2();
|
|
20444
|
-
return
|
|
20519
|
+
return toRelayerV1KeyUrlResponse(response);
|
|
20445
20520
|
}
|
|
20446
20521
|
async fetchPostInputProof(payload, instanceOptions, fetchOptions) {
|
|
20447
20522
|
const request = new RelayerV2AsyncRequest({
|
|
@@ -21131,60 +21206,39 @@ function _resolveRelayerUrl(value, defaultVersion) {
|
|
|
21131
21206
|
};
|
|
21132
21207
|
}
|
|
21133
21208
|
|
|
21134
|
-
|
|
21135
|
-
|
|
21136
|
-
|
|
21137
|
-
|
|
21138
|
-
|
|
21139
|
-
|
|
21140
|
-
|
|
21141
|
-
|
|
21142
|
-
|
|
21143
|
-
|
|
21144
|
-
|
|
21145
|
-
|
|
21146
|
-
|
|
21147
|
-
* | 8 | 2 | `euint8` | |
|
|
21148
|
-
* | 16 | 3 | `euint16` | |
|
|
21149
|
-
* | 32 | 4 | `euint32` | |
|
|
21150
|
-
* | 64 | 5 | `euint64` | |
|
|
21151
|
-
* | 128 | 6 | `euint128` | |
|
|
21152
|
-
* | 160 | 7 | `eaddress` | Used for encrypted Ethereum addresses. |
|
|
21153
|
-
* | 256 | 8 | `euint256` | The maximum supported integer size. |
|
|
21154
|
-
*/
|
|
21155
|
-
const ENCRYPTION_TYPES = {
|
|
21156
|
-
2: 0, // ebool (FheTypeId=0) is using 2 encrypted bits
|
|
21157
|
-
// euint4 (FheTypeId=1) is deprecated
|
|
21158
|
-
8: 2, // euint8 (FheTypeId=2) is using 8 encrypted bits
|
|
21159
|
-
16: 3, // euint16 (FheTypeId=3) is using 16 encrypted bits
|
|
21160
|
-
32: 4, // euint32 (FheTypeId=4) is using 32 encrypted bits
|
|
21161
|
-
64: 5, // euint64 (FheTypeId=5) is using 64 encrypted bits
|
|
21162
|
-
128: 6, // euint128 (FheTypeId=128) is using 128 encrypted bits
|
|
21163
|
-
160: 7, // eaddress (FheTypeId=7) is using 160 encrypted bits
|
|
21164
|
-
256: 8, // euint256 (FheTypeId=8) is using 256 encrypted bits
|
|
21209
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
21210
|
+
// MainnetConfig
|
|
21211
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
21212
|
+
const MainnetConfig = {
|
|
21213
|
+
aclContractAddress: '0xcA2E8f1F656CD25C01F05d0b243Ab1ecd4a8ffb6',
|
|
21214
|
+
kmsContractAddress: '0x77627828a55156b04Ac0DC0eb30467f1a552BB03',
|
|
21215
|
+
inputVerifierContractAddress: '0xCe0FC2e05CFff1B719EFF7169f7D80Af770c8EA2',
|
|
21216
|
+
verifyingContractAddressDecryption: '0x0f6024a97684f7d90ddb0fAAD79cB15F2C888D24',
|
|
21217
|
+
verifyingContractAddressInputVerification: '0xcB1bB072f38bdAF0F328CdEf1Fc6eDa1DF029287',
|
|
21218
|
+
chainId: 1,
|
|
21219
|
+
gatewayChainId: 261131,
|
|
21220
|
+
network: 'https://ethereum-rpc.publicnode.com',
|
|
21221
|
+
relayerUrl: 'https://relayer.mainnet.zama.org',
|
|
21165
21222
|
};
|
|
21166
|
-
|
|
21223
|
+
Object.freeze(MainnetConfig);
|
|
21224
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
21225
|
+
// SepoliaConfig
|
|
21226
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
21167
21227
|
const SepoliaConfig = {
|
|
21168
|
-
// ACL_CONTRACT_ADDRESS (FHEVM Host chain)
|
|
21169
21228
|
aclContractAddress: '0xf0Ffdc93b7E186bC2f8CB3dAA75D86d1930A433D',
|
|
21170
|
-
// KMS_VERIFIER_CONTRACT_ADDRESS (FHEVM Host chain)
|
|
21171
21229
|
kmsContractAddress: '0xbE0E383937d564D7FF0BC3b46c51f0bF8d5C311A',
|
|
21172
|
-
// INPUT_VERIFIER_CONTRACT_ADDRESS (FHEVM Host chain)
|
|
21173
21230
|
inputVerifierContractAddress: '0xBBC1fFCdc7C316aAAd72E807D9b0272BE8F84DA0',
|
|
21174
|
-
// DECRYPTION_ADDRESS (Gateway chain)
|
|
21175
21231
|
verifyingContractAddressDecryption: '0x5D8BD78e2ea6bbE41f26dFe9fdaEAa349e077478',
|
|
21176
|
-
// INPUT_VERIFICATION_ADDRESS (Gateway chain)
|
|
21177
21232
|
verifyingContractAddressInputVerification: '0x483b9dE06E4E4C7D35CCf5837A1668487406D955',
|
|
21178
|
-
// FHEVM Host chain id
|
|
21179
21233
|
chainId: 11155111,
|
|
21180
|
-
// Gateway chain id
|
|
21181
21234
|
gatewayChainId: 10901,
|
|
21182
|
-
// Optional RPC provider to host chain
|
|
21183
21235
|
network: 'https://ethereum-sepolia-rpc.publicnode.com',
|
|
21184
|
-
// Relayer URL
|
|
21185
21236
|
relayerUrl: 'https://relayer.testnet.zama.org',
|
|
21186
21237
|
};
|
|
21187
21238
|
Object.freeze(SepoliaConfig);
|
|
21239
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
21240
|
+
// createInstance
|
|
21241
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
21188
21242
|
const createInstance = async (config) => {
|
|
21189
21243
|
const { verifyingContractAddressDecryption, verifyingContractAddressInputVerification, publicKey, inputVerifierContractAddress, kmsContractAddress, aclContractAddress, gatewayChainId, auth, } = config;
|
|
21190
21244
|
if (!isChecksummedAddress(aclContractAddress)) {
|
|
@@ -21216,29 +21270,12 @@ const createInstance = async (config) => {
|
|
|
21216
21270
|
defaultRelayerVersion: 1,
|
|
21217
21271
|
});
|
|
21218
21272
|
const chainId = await getChainId(provider, config);
|
|
21219
|
-
// const relayerVersionUrl = `${config.relayerUrl!}/v1`;
|
|
21220
|
-
// const publicKeyData = await getTfheCompactPublicKey({
|
|
21221
|
-
// relayerVersionUrl: relayerFhevm.relayerVersionUrl,
|
|
21222
|
-
// publicKey: config.publicKey,
|
|
21223
|
-
// });
|
|
21224
|
-
//const aaa = relayerFhevm.getPublicKey();
|
|
21225
|
-
// const publicParamsData = await getPublicParams({
|
|
21226
|
-
// relayerVersionUrl,
|
|
21227
|
-
// publicParams: config.publicParams,
|
|
21228
|
-
// });
|
|
21229
21273
|
const kmsSigners = await getKMSSigners(provider, kmsContractAddress);
|
|
21230
21274
|
const thresholdKMSSigners = await getKMSSignersThreshold(provider, kmsContractAddress);
|
|
21231
21275
|
const coprocessorSigners = await getCoprocessorSigners(provider, inputVerifierContractAddress);
|
|
21232
21276
|
const thresholdCoprocessorSigners = await getCoprocessorSignersThreshold(provider, inputVerifierContractAddress);
|
|
21233
21277
|
return {
|
|
21234
|
-
createEncryptedInput: createRelayerEncryptedInput(aclContractAddress, verifyingContractAddressInputVerification, chainId, gatewayChainId,
|
|
21235
|
-
//cleanURL(config.relayerUrl),
|
|
21236
|
-
//relayerFhevm.relayerVersionUrl,
|
|
21237
|
-
relayerFhevm.relayerProvider,
|
|
21238
|
-
//publicKeyData.publicKey,
|
|
21239
|
-
relayerFhevm.getPublicKeyWasm().publicKey,
|
|
21240
|
-
//publicParamsData,
|
|
21241
|
-
{ 2048: relayerFhevm.getPublicParamsWasm(2048) }, coprocessorSigners, thresholdCoprocessorSigners),
|
|
21278
|
+
createEncryptedInput: createRelayerEncryptedInput(aclContractAddress, verifyingContractAddressInputVerification, chainId, gatewayChainId, relayerFhevm.relayerProvider, relayerFhevm.getPublicKeyWasm().publicKey, { 2048: relayerFhevm.getPublicParamsWasm(2048) }, coprocessorSigners, thresholdCoprocessorSigners, auth && { auth }),
|
|
21242
21279
|
generateKeypair,
|
|
21243
21280
|
createEIP712: createEIP712(verifyingContractAddressDecryption, chainId),
|
|
21244
21281
|
publicDecrypt: publicDecryptRequest(kmsSigners, thresholdKMSSigners, gatewayChainId, verifyingContractAddressDecryption, aclContractAddress,
|
|
@@ -21318,4 +21355,4 @@ window.TKMS = {
|
|
|
21318
21355
|
ml_kem_pke_get_pk,
|
|
21319
21356
|
};
|
|
21320
21357
|
|
|
21321
|
-
export {
|
|
21358
|
+
export { MainnetConfig, SepoliaConfig, createEIP712, createInstance, generateKeypair, getErrorCauseCode, getErrorCauseStatus, initSDK };
|