@zama-fhe/relayer-sdk 0.3.0-3 → 0.3.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/relayer-sdk-js.js +4800 -4704
- package/bundle/relayer-sdk-js.umd.cjs +9 -9
- package/bundle.d.ts +9 -2
- package/lib/node.cjs +147 -79
- package/lib/node.d.ts +43 -15
- package/lib/node.js +147 -79
- package/lib/web.d.ts +44 -16
- package/lib/web.js +147 -79
- package/package.json +7 -7
package/bundle.d.ts
CHANGED
|
@@ -10,9 +10,16 @@ export {
|
|
|
10
10
|
FhevmInstance,
|
|
11
11
|
FhevmInstanceConfig,
|
|
12
12
|
createInstance,
|
|
13
|
-
|
|
13
|
+
EncryptionBits,
|
|
14
14
|
ENCRYPTION_TYPES,
|
|
15
|
-
|
|
15
|
+
UserDecryptResults,
|
|
16
|
+
PublicDecryptResults,
|
|
17
|
+
ClearValueType,
|
|
18
|
+
ClearValues,
|
|
16
19
|
initSDK,
|
|
17
20
|
SepoliaConfig,
|
|
21
|
+
Auth,
|
|
22
|
+
BearerToken,
|
|
23
|
+
ApiKeyCookie,
|
|
24
|
+
ApiKeyHeader,
|
|
18
25
|
} from './lib/web';
|
package/lib/node.cjs
CHANGED
|
@@ -56,6 +56,9 @@ const bytesToBigInt = function (byteArray) {
|
|
|
56
56
|
.join('');
|
|
57
57
|
return BigInt(`0x${hex}`);
|
|
58
58
|
};
|
|
59
|
+
function ensure0x(s) {
|
|
60
|
+
return !s.startsWith('0x') ? `0x${s}` : s;
|
|
61
|
+
}
|
|
59
62
|
|
|
60
63
|
function setAuth(init, auth) {
|
|
61
64
|
if (auth) {
|
|
@@ -562,6 +565,17 @@ const NumEncryptedBits = {
|
|
|
562
565
|
7: 160, // eaddress
|
|
563
566
|
8: 256, // euint256
|
|
564
567
|
};
|
|
568
|
+
function getHandleType(handle) {
|
|
569
|
+
if (handle.length !== 66) {
|
|
570
|
+
throw new Error(`Handle ${handle} is not of valid length`);
|
|
571
|
+
}
|
|
572
|
+
const hexPair = handle.slice(-4, -2).toLowerCase();
|
|
573
|
+
const typeDiscriminant = parseInt(hexPair, 16);
|
|
574
|
+
if (!(typeDiscriminant in NumEncryptedBits)) {
|
|
575
|
+
throw new Error(`Handle ${handle} is not of valid type`);
|
|
576
|
+
}
|
|
577
|
+
return typeDiscriminant;
|
|
578
|
+
}
|
|
565
579
|
function checkEncryptedBits(handles) {
|
|
566
580
|
let total = 0;
|
|
567
581
|
for (const handle of handles) {
|
|
@@ -590,37 +604,30 @@ const aclABI$1 = [
|
|
|
590
604
|
];
|
|
591
605
|
const MAX_USER_DECRYPT_CONTRACT_ADDRESSES = 10;
|
|
592
606
|
const MAX_USER_DECRYPT_DURATION_DAYS = BigInt(365);
|
|
593
|
-
function formatAccordingToType(
|
|
607
|
+
function formatAccordingToType(clearValueAsBigInt, type) {
|
|
594
608
|
if (type === 0) {
|
|
595
609
|
// ebool
|
|
596
|
-
return
|
|
610
|
+
return clearValueAsBigInt === BigInt(1);
|
|
597
611
|
}
|
|
598
612
|
else if (type === 7) {
|
|
599
613
|
// eaddress
|
|
600
|
-
return getAddress$1('0x' +
|
|
601
|
-
}
|
|
602
|
-
else if (type === 9) {
|
|
603
|
-
// ebytes64
|
|
604
|
-
return '0x' + decryptedBigInt.toString(16).padStart(128, '0');
|
|
614
|
+
return getAddress$1('0x' + clearValueAsBigInt.toString(16).padStart(40, '0'));
|
|
605
615
|
}
|
|
606
|
-
else if (type
|
|
607
|
-
//
|
|
608
|
-
|
|
616
|
+
else if (type > 8 || type == 1) {
|
|
617
|
+
// type == 1 : euint4 (not supported)
|
|
618
|
+
throw new Error(`Unsupported handle type ${type}`);
|
|
609
619
|
}
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
return '0x' + decryptedBigInt.toString(16).padStart(512, '0');
|
|
613
|
-
} // euintXXX
|
|
614
|
-
return decryptedBigInt;
|
|
620
|
+
// euintXXX
|
|
621
|
+
return clearValueAsBigInt;
|
|
615
622
|
}
|
|
616
|
-
function
|
|
623
|
+
function buildUserDecryptResults(handles, listBigIntDecryptions) {
|
|
617
624
|
let typesList = [];
|
|
618
625
|
for (const handle of handles) {
|
|
619
626
|
const hexPair = handle.slice(-4, -2).toLowerCase();
|
|
620
627
|
const typeDiscriminant = parseInt(hexPair, 16);
|
|
621
628
|
typesList.push(typeDiscriminant);
|
|
622
629
|
}
|
|
623
|
-
|
|
630
|
+
const results = {};
|
|
624
631
|
handles.forEach((handle, idx) => (results[handle] = formatAccordingToType(listBigIntDecryptions[idx], typesList[idx])));
|
|
625
632
|
return results;
|
|
626
633
|
}
|
|
@@ -726,7 +733,7 @@ const userDecryptRequest = (kmsSigners, gatewayChainId, chainId, verifyingContra
|
|
|
726
733
|
};
|
|
727
734
|
const decryption = TKMS.process_user_decryption_resp_from_js(client, payloadForVerification, eip712Domain, json.response, pubKey, privKey, true);
|
|
728
735
|
const listBigIntDecryptions = decryption.map((d) => bytesToBigInt(d.bytes));
|
|
729
|
-
const results =
|
|
736
|
+
const results = buildUserDecryptResults(handles.map((h) => h.handle), listBigIntDecryptions);
|
|
730
737
|
return results;
|
|
731
738
|
}
|
|
732
739
|
catch (e) {
|
|
@@ -781,7 +788,7 @@ const createEncryptedInput = ({ aclContractAddress, chainId, tfheCompactPublicKe
|
|
|
781
788
|
checkEncryptedValue(Number(value), 1);
|
|
782
789
|
checkLimit(2);
|
|
783
790
|
builder.push_boolean(!!value);
|
|
784
|
-
bits.push(
|
|
791
|
+
bits.push(2); // ebool takes 2 encrypted bits
|
|
785
792
|
return this;
|
|
786
793
|
},
|
|
787
794
|
add8(value) {
|
|
@@ -835,36 +842,6 @@ const createEncryptedInput = ({ aclContractAddress, chainId, tfheCompactPublicKe
|
|
|
835
842
|
bits.push(256);
|
|
836
843
|
return this;
|
|
837
844
|
},
|
|
838
|
-
addBytes64(value) {
|
|
839
|
-
if (value.length !== 64)
|
|
840
|
-
throw Error('Uncorrect length of input Uint8Array, should be 64 for an ebytes64');
|
|
841
|
-
const bigIntValue = bytesToBigInt(value);
|
|
842
|
-
checkEncryptedValue(bigIntValue, 512);
|
|
843
|
-
checkLimit(512);
|
|
844
|
-
builder.push_u512(bigIntValue);
|
|
845
|
-
bits.push(512);
|
|
846
|
-
return this;
|
|
847
|
-
},
|
|
848
|
-
addBytes128(value) {
|
|
849
|
-
if (value.length !== 128)
|
|
850
|
-
throw Error('Uncorrect length of input Uint8Array, should be 128 for an ebytes128');
|
|
851
|
-
const bigIntValue = bytesToBigInt(value);
|
|
852
|
-
checkEncryptedValue(bigIntValue, 1024);
|
|
853
|
-
checkLimit(1024);
|
|
854
|
-
builder.push_u1024(bigIntValue);
|
|
855
|
-
bits.push(1024);
|
|
856
|
-
return this;
|
|
857
|
-
},
|
|
858
|
-
addBytes256(value) {
|
|
859
|
-
if (value.length !== 256)
|
|
860
|
-
throw Error('Uncorrect length of input Uint8Array, should be 256 for an ebytes256');
|
|
861
|
-
const bigIntValue = bytesToBigInt(value);
|
|
862
|
-
checkEncryptedValue(bigIntValue, 2048);
|
|
863
|
-
checkLimit(2048);
|
|
864
|
-
builder.push_u2048(bigIntValue);
|
|
865
|
-
bits.push(2048);
|
|
866
|
-
return this;
|
|
867
|
-
},
|
|
868
845
|
getBits() {
|
|
869
846
|
return bits;
|
|
870
847
|
},
|
|
@@ -897,18 +874,37 @@ const createEncryptedInput = ({ aclContractAddress, chainId, tfheCompactPublicKe
|
|
|
897
874
|
};
|
|
898
875
|
};
|
|
899
876
|
|
|
877
|
+
/**
|
|
878
|
+
* **FHE Type Mapping for Input Builders**
|
|
879
|
+
* * Maps the **number of encrypted bits** used by a FHEVM primary type
|
|
880
|
+
* to its corresponding **FheTypeId**. This constant is primarily used by
|
|
881
|
+
* `EncryptedInput` and `RelayerEncryptedInput` builders to determine the correct
|
|
882
|
+
* input type and calculate the total required bit-length.
|
|
883
|
+
*
|
|
884
|
+
* **Structure: \{ Encrypted Bit Length: FheTypeId \}**
|
|
885
|
+
*
|
|
886
|
+
* | Bits | FheTypeId | FHE Type Name | Note |
|
|
887
|
+
* | :--- | :-------- | :------------ | :--- |
|
|
888
|
+
* | 2 | 0 | `ebool` | The boolean type. |
|
|
889
|
+
* | (N/A)| 1 | `euint4` | **Deprecated** and omitted from this map. |
|
|
890
|
+
* | 8 | 2 | `euint8` | |
|
|
891
|
+
* | 16 | 3 | `euint16` | |
|
|
892
|
+
* | 32 | 4 | `euint32` | |
|
|
893
|
+
* | 64 | 5 | `euint64` | |
|
|
894
|
+
* | 128 | 6 | `euint128` | |
|
|
895
|
+
* | 160 | 7 | `eaddress` | Used for encrypted Ethereum addresses. |
|
|
896
|
+
* | 256 | 8 | `euint256` | The maximum supported integer size. |
|
|
897
|
+
*/
|
|
900
898
|
const ENCRYPTION_TYPES = {
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
1024: 10,
|
|
911
|
-
2048: 11,
|
|
899
|
+
2: 0, // ebool (FheTypeId=0) is using 2 encrypted bits
|
|
900
|
+
// euint4 (FheTypeId=1) is deprecated
|
|
901
|
+
8: 2, // euint8 (FheTypeId=2) is using 8 encrypted bits
|
|
902
|
+
16: 3, // euint16 (FheTypeId=3) is using 16 encrypted bits
|
|
903
|
+
32: 4, // euint32 (FheTypeId=4) is using 32 encrypted bits
|
|
904
|
+
64: 5, // euint64 (FheTypeId=5) is using 64 encrypted bits
|
|
905
|
+
128: 6, // euint128 (FheTypeId=128) is using 128 encrypted bits
|
|
906
|
+
160: 7, // eaddress (FheTypeId=7) is using 160 encrypted bits
|
|
907
|
+
256: 8, // euint256 (FheTypeId=8) is using 256 encrypted bits
|
|
912
908
|
};
|
|
913
909
|
|
|
914
910
|
const MAX_UINT64 = BigInt('18446744073709551615'); // 2^64 - 1
|
|
@@ -1137,6 +1133,74 @@ function isThresholdReached(kmsSigners, recoveredAddresses, threshold) {
|
|
|
1137
1133
|
}
|
|
1138
1134
|
return recoveredAddresses.length >= threshold;
|
|
1139
1135
|
}
|
|
1136
|
+
function abiEncodeClearValues(clearValues) {
|
|
1137
|
+
const handlesBytes32Hex = Object.keys(clearValues);
|
|
1138
|
+
const abiTypes = [];
|
|
1139
|
+
const abiValues = [];
|
|
1140
|
+
for (let i = 0; i < handlesBytes32Hex.length; ++i) {
|
|
1141
|
+
const handle = handlesBytes32Hex[i];
|
|
1142
|
+
const handleType = getHandleType(handle);
|
|
1143
|
+
let clearTextValue = clearValues[handle];
|
|
1144
|
+
if (typeof clearTextValue === 'boolean') {
|
|
1145
|
+
clearTextValue = clearTextValue ? '0x01' : '0x00';
|
|
1146
|
+
}
|
|
1147
|
+
const clearTextValueBigInt = BigInt(clearTextValue);
|
|
1148
|
+
//abiTypes.push(fhevmTypeInfo.solidityTypeName);
|
|
1149
|
+
abiTypes.push('uint256');
|
|
1150
|
+
switch (handleType) {
|
|
1151
|
+
// eaddress
|
|
1152
|
+
case 7: {
|
|
1153
|
+
// string
|
|
1154
|
+
abiValues.push(`0x${clearTextValueBigInt.toString(16).padStart(40, '0')}`);
|
|
1155
|
+
break;
|
|
1156
|
+
}
|
|
1157
|
+
// ebool
|
|
1158
|
+
case 0: {
|
|
1159
|
+
// bigint (0 or 1)
|
|
1160
|
+
if (clearTextValueBigInt !== BigInt(0) &&
|
|
1161
|
+
clearTextValueBigInt !== BigInt(1)) {
|
|
1162
|
+
throw new Error(`Invalid ebool clear text value ${clearTextValueBigInt}. Expecting 0 or 1.`);
|
|
1163
|
+
}
|
|
1164
|
+
abiValues.push(clearTextValueBigInt);
|
|
1165
|
+
break;
|
|
1166
|
+
}
|
|
1167
|
+
case 2: //euint8
|
|
1168
|
+
case 3: //euint16
|
|
1169
|
+
case 4: //euint32
|
|
1170
|
+
case 5: //euint64
|
|
1171
|
+
case 6: //euint128
|
|
1172
|
+
case 7: {
|
|
1173
|
+
//euint256
|
|
1174
|
+
// bigint
|
|
1175
|
+
abiValues.push(clearTextValueBigInt);
|
|
1176
|
+
break;
|
|
1177
|
+
}
|
|
1178
|
+
default: {
|
|
1179
|
+
throw new Error(`Unsupported Fhevm primitive type id: ${handleType}`);
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
const abiCoder = ethers.ethers.AbiCoder.defaultAbiCoder();
|
|
1184
|
+
// ABI encode the decryptedResult as done in the KMS, since all decrypted values
|
|
1185
|
+
// are native static types, thay have same abi-encoding as uint256:
|
|
1186
|
+
const abiEncodedClearValues = abiCoder.encode(abiTypes, abiValues);
|
|
1187
|
+
return {
|
|
1188
|
+
abiTypes,
|
|
1189
|
+
abiValues,
|
|
1190
|
+
abiEncodedClearValues,
|
|
1191
|
+
};
|
|
1192
|
+
}
|
|
1193
|
+
function buildDecryptionProof(kmsSignatures, extraData) {
|
|
1194
|
+
// Build the decryptionProof as numSigners + KMS signatures + extraData
|
|
1195
|
+
const packedNumSigners = ethers.ethers.solidityPacked(['uint8'], [kmsSignatures.length]);
|
|
1196
|
+
const packedSignatures = ethers.ethers.solidityPacked(Array(kmsSignatures.length).fill('bytes'), kmsSignatures);
|
|
1197
|
+
const decryptionProof = ethers.ethers.concat([
|
|
1198
|
+
packedNumSigners,
|
|
1199
|
+
packedSignatures,
|
|
1200
|
+
extraData,
|
|
1201
|
+
]);
|
|
1202
|
+
return decryptionProof;
|
|
1203
|
+
}
|
|
1140
1204
|
const CiphertextType = {
|
|
1141
1205
|
0: 'bool',
|
|
1142
1206
|
2: 'uint256',
|
|
@@ -1147,7 +1211,7 @@ const CiphertextType = {
|
|
|
1147
1211
|
7: 'address',
|
|
1148
1212
|
8: 'uint256',
|
|
1149
1213
|
};
|
|
1150
|
-
function
|
|
1214
|
+
function deserializeClearValues(handles, decryptedResult) {
|
|
1151
1215
|
let typesList = [];
|
|
1152
1216
|
for (const handle of handles) {
|
|
1153
1217
|
const hexPair = handle.slice(-4, -2).toLowerCase();
|
|
@@ -1166,7 +1230,7 @@ function deserializeDecryptedResult(handles, decryptedResult) {
|
|
|
1166
1230
|
const decoded = coder.decode(['uint256', ...abiTypes, 'bytes[]'], restoredEncoded);
|
|
1167
1231
|
// strip dummy first/last element
|
|
1168
1232
|
const rawValues = decoded.slice(1, 1 + typesList.length);
|
|
1169
|
-
|
|
1233
|
+
const results = {};
|
|
1170
1234
|
handles.forEach((handle, idx) => (results[handle] = rawValues[idx]));
|
|
1171
1235
|
return results;
|
|
1172
1236
|
}
|
|
@@ -1211,22 +1275,26 @@ const publicDecryptRequest = (kmsSigners, thresholdSigners, gatewayChainId, veri
|
|
|
1211
1275
|
],
|
|
1212
1276
|
};
|
|
1213
1277
|
const result = json.response[0];
|
|
1214
|
-
const decryptedResult = result.decrypted_value
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
const signatures = result.signatures;
|
|
1278
|
+
const decryptedResult = ensure0x(result.decrypted_value);
|
|
1279
|
+
const kmsSignatures = result.signatures.map(ensure0x);
|
|
1280
|
+
// TODO result.extra_data (RelayerPublicDecryptJsonResponse)
|
|
1218
1281
|
const signedExtraData = '0x';
|
|
1219
|
-
const recoveredAddresses =
|
|
1220
|
-
const
|
|
1221
|
-
const recoveredAddress = ethers.ethers.verifyTypedData(domain, types, { ctHandles: handles, decryptedResult, extraData: signedExtraData }, sig);
|
|
1282
|
+
const recoveredAddresses = kmsSignatures.map((kmsSignature) => {
|
|
1283
|
+
const recoveredAddress = ethers.ethers.verifyTypedData(domain, types, { ctHandles: handles, decryptedResult, extraData: signedExtraData }, kmsSignature);
|
|
1222
1284
|
return recoveredAddress;
|
|
1223
1285
|
});
|
|
1224
1286
|
const thresholdReached = isThresholdReached(kmsSigners, recoveredAddresses, thresholdSigners);
|
|
1225
1287
|
if (!thresholdReached) {
|
|
1226
1288
|
throw Error('KMS signers threshold is not reached');
|
|
1227
1289
|
}
|
|
1228
|
-
const
|
|
1229
|
-
|
|
1290
|
+
const clearValues = deserializeClearValues(handles, decryptedResult);
|
|
1291
|
+
const abiEnc = abiEncodeClearValues(clearValues);
|
|
1292
|
+
const decryptionProof = buildDecryptionProof(kmsSignatures, signedExtraData);
|
|
1293
|
+
return {
|
|
1294
|
+
clearValues,
|
|
1295
|
+
abiEncodedClearValues: abiEnc.abiEncodedClearValues,
|
|
1296
|
+
decryptionProof,
|
|
1297
|
+
};
|
|
1230
1298
|
};
|
|
1231
1299
|
|
|
1232
1300
|
/**
|
|
@@ -1336,23 +1404,23 @@ const generateKeypair = () => {
|
|
|
1336
1404
|
global.fetch = fetchRetry(global.fetch, { retries: 5, retryDelay: 500 });
|
|
1337
1405
|
const SepoliaConfig = {
|
|
1338
1406
|
// ACL_CONTRACT_ADDRESS (FHEVM Host chain)
|
|
1339
|
-
aclContractAddress: '
|
|
1407
|
+
aclContractAddress: '0xf0Ffdc93b7E186bC2f8CB3dAA75D86d1930A433D',
|
|
1340
1408
|
// KMS_VERIFIER_CONTRACT_ADDRESS (FHEVM Host chain)
|
|
1341
|
-
kmsContractAddress: '
|
|
1409
|
+
kmsContractAddress: '0xbE0E383937d564D7FF0BC3b46c51f0bF8d5C311A',
|
|
1342
1410
|
// INPUT_VERIFIER_CONTRACT_ADDRESS (FHEVM Host chain)
|
|
1343
|
-
inputVerifierContractAddress: '
|
|
1411
|
+
inputVerifierContractAddress: '0xBBC1fFCdc7C316aAAd72E807D9b0272BE8F84DA0',
|
|
1344
1412
|
// DECRYPTION_ADDRESS (Gateway chain)
|
|
1345
|
-
verifyingContractAddressDecryption: '
|
|
1413
|
+
verifyingContractAddressDecryption: '0x5D8BD78e2ea6bbE41f26dFe9fdaEAa349e077478',
|
|
1346
1414
|
// INPUT_VERIFICATION_ADDRESS (Gateway chain)
|
|
1347
|
-
verifyingContractAddressInputVerification: '
|
|
1415
|
+
verifyingContractAddressInputVerification: '0x483b9dE06E4E4C7D35CCf5837A1668487406D955',
|
|
1348
1416
|
// FHEVM Host chain id
|
|
1349
1417
|
chainId: 11155111,
|
|
1350
1418
|
// Gateway chain id
|
|
1351
|
-
gatewayChainId:
|
|
1419
|
+
gatewayChainId: 10901,
|
|
1352
1420
|
// Optional RPC provider to host chain
|
|
1353
|
-
network: 'https://
|
|
1421
|
+
network: 'https://ethereum-sepolia-rpc.publicnode.com',
|
|
1354
1422
|
// Relayer URL
|
|
1355
|
-
relayerUrl: 'https://relayer.testnet.zama.
|
|
1423
|
+
relayerUrl: 'https://relayer.testnet.zama.org',
|
|
1356
1424
|
};
|
|
1357
1425
|
const createInstance = async (config) => {
|
|
1358
1426
|
const { verifyingContractAddressDecryption, verifyingContractAddressInputVerification, publicKey, kmsContractAddress, aclContractAddress, gatewayChainId, auth, } = config;
|
package/lib/node.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { TfheCompactPublicKey } from 'node-tfhe';
|
|
|
6
6
|
/**
|
|
7
7
|
* Custom cookie authentication
|
|
8
8
|
*/
|
|
9
|
-
declare type ApiKeyCookie = {
|
|
9
|
+
export declare type ApiKeyCookie = {
|
|
10
10
|
__type: 'ApiKeyCookie';
|
|
11
11
|
/**
|
|
12
12
|
* The cookie name. The default value is `x-api-key`.
|
|
@@ -21,7 +21,7 @@ declare type ApiKeyCookie = {
|
|
|
21
21
|
/**
|
|
22
22
|
* Custom header authentication
|
|
23
23
|
*/
|
|
24
|
-
declare type ApiKeyHeader = {
|
|
24
|
+
export declare type ApiKeyHeader = {
|
|
25
25
|
__type: 'ApiKeyHeader';
|
|
26
26
|
/**
|
|
27
27
|
* The header name. The default value is `x-api-key`.
|
|
@@ -40,12 +40,12 @@ declare type ApiKeyHeader = {
|
|
|
40
40
|
* - Custom header
|
|
41
41
|
* - Custom cookie
|
|
42
42
|
*/
|
|
43
|
-
declare type Auth = BearerToken | ApiKeyHeader | ApiKeyCookie;
|
|
43
|
+
export declare type Auth = BearerToken | ApiKeyHeader | ApiKeyCookie;
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* Bearer Token Authentication
|
|
47
47
|
*/
|
|
48
|
-
declare type BearerToken = {
|
|
48
|
+
export declare type BearerToken = {
|
|
49
49
|
__type: 'BearerToken';
|
|
50
50
|
/**
|
|
51
51
|
* The Bearer token.
|
|
@@ -53,6 +53,10 @@ declare type BearerToken = {
|
|
|
53
53
|
token: string;
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
+
export declare type ClearValues = Record<`0x${string}`, ClearValueType>;
|
|
57
|
+
|
|
58
|
+
export declare type ClearValueType = bigint | boolean | `0x${string}`;
|
|
59
|
+
|
|
56
60
|
/**
|
|
57
61
|
* Creates an EIP712 structure specifically for user decrypt requests
|
|
58
62
|
*
|
|
@@ -78,8 +82,6 @@ export declare const createTfheKeypair: () => {
|
|
|
78
82
|
|
|
79
83
|
export declare const createTfhePublicKey: () => string;
|
|
80
84
|
|
|
81
|
-
export declare type DecryptedResults = Record<string, bigint | boolean | string>;
|
|
82
|
-
|
|
83
85
|
export declare type EIP712 = {
|
|
84
86
|
domain: {
|
|
85
87
|
chainId: number;
|
|
@@ -99,8 +101,29 @@ export declare type EIP712Type = {
|
|
|
99
101
|
type: string;
|
|
100
102
|
};
|
|
101
103
|
|
|
104
|
+
/**
|
|
105
|
+
* **FHE Type Mapping for Input Builders**
|
|
106
|
+
* * Maps the **number of encrypted bits** used by a FHEVM primary type
|
|
107
|
+
* to its corresponding **FheTypeId**. This constant is primarily used by
|
|
108
|
+
* `EncryptedInput` and `RelayerEncryptedInput` builders to determine the correct
|
|
109
|
+
* input type and calculate the total required bit-length.
|
|
110
|
+
*
|
|
111
|
+
* **Structure: \{ Encrypted Bit Length: FheTypeId \}**
|
|
112
|
+
*
|
|
113
|
+
* | Bits | FheTypeId | FHE Type Name | Note |
|
|
114
|
+
* | :--- | :-------- | :------------ | :--- |
|
|
115
|
+
* | 2 | 0 | `ebool` | The boolean type. |
|
|
116
|
+
* | (N/A)| 1 | `euint4` | **Deprecated** and omitted from this map. |
|
|
117
|
+
* | 8 | 2 | `euint8` | |
|
|
118
|
+
* | 16 | 3 | `euint16` | |
|
|
119
|
+
* | 32 | 4 | `euint32` | |
|
|
120
|
+
* | 64 | 5 | `euint64` | |
|
|
121
|
+
* | 128 | 6 | `euint128` | |
|
|
122
|
+
* | 160 | 7 | `eaddress` | Used for encrypted Ethereum addresses. |
|
|
123
|
+
* | 256 | 8 | `euint256` | The maximum supported integer size. |
|
|
124
|
+
*/
|
|
102
125
|
export declare const ENCRYPTION_TYPES: {
|
|
103
|
-
|
|
126
|
+
2: number;
|
|
104
127
|
8: number;
|
|
105
128
|
16: number;
|
|
106
129
|
32: number;
|
|
@@ -108,12 +131,9 @@ export declare const ENCRYPTION_TYPES: {
|
|
|
108
131
|
128: number;
|
|
109
132
|
160: number;
|
|
110
133
|
256: number;
|
|
111
|
-
512: number;
|
|
112
|
-
1024: number;
|
|
113
|
-
2048: number;
|
|
114
134
|
};
|
|
115
135
|
|
|
116
|
-
export declare type
|
|
136
|
+
export declare type EncryptionBits = keyof typeof ENCRYPTION_TYPES;
|
|
117
137
|
|
|
118
138
|
export declare type FhevmInstance = {
|
|
119
139
|
createEncryptedInput: (contractAddress: string, userAddress: string) => RelayerEncryptedInput;
|
|
@@ -122,8 +142,8 @@ export declare type FhevmInstance = {
|
|
|
122
142
|
privateKey: string;
|
|
123
143
|
};
|
|
124
144
|
createEIP712: (publicKey: string, contractAddresses: string[], startTimestamp: string | number, durationDays: string | number) => EIP712;
|
|
125
|
-
publicDecrypt: (handles: (string | Uint8Array)[]) => Promise<
|
|
126
|
-
userDecrypt: (handles: HandleContractPair[], privateKey: string, publicKey: string, signature: string, contractAddresses: string[], userAddress: string, startTimestamp: string | number, durationDays: string | number) => Promise<
|
|
145
|
+
publicDecrypt: (handles: (string | Uint8Array)[]) => Promise<PublicDecryptResults>;
|
|
146
|
+
userDecrypt: (handles: HandleContractPair[], privateKey: string, publicKey: string, signature: string, contractAddresses: string[], userAddress: string, startTimestamp: string | number, durationDays: string | number) => Promise<UserDecryptResults>;
|
|
127
147
|
getPublicKey: () => {
|
|
128
148
|
publicKeyId: string;
|
|
129
149
|
publicKey: Uint8Array;
|
|
@@ -166,8 +186,14 @@ export declare type HandleContractPair = {
|
|
|
166
186
|
contractAddress: string;
|
|
167
187
|
};
|
|
168
188
|
|
|
189
|
+
export declare type PublicDecryptResults = {
|
|
190
|
+
clearValues: ClearValues;
|
|
191
|
+
abiEncodedClearValues: `0x${string}`;
|
|
192
|
+
decryptionProof: `0x${string}`;
|
|
193
|
+
};
|
|
194
|
+
|
|
169
195
|
export declare type PublicParams<T = TFHEType['CompactPkeCrs']> = {
|
|
170
|
-
|
|
196
|
+
2048: {
|
|
171
197
|
publicParams: T;
|
|
172
198
|
publicParamsId: string;
|
|
173
199
|
};
|
|
@@ -182,7 +208,7 @@ export declare type RelayerEncryptedInput = {
|
|
|
182
208
|
add128: (value: number | bigint) => RelayerEncryptedInput;
|
|
183
209
|
add256: (value: number | bigint) => RelayerEncryptedInput;
|
|
184
210
|
addAddress: (value: string) => RelayerEncryptedInput;
|
|
185
|
-
getBits: () =>
|
|
211
|
+
getBits: () => EncryptionBits[];
|
|
186
212
|
encrypt: (options?: {
|
|
187
213
|
auth?: Auth;
|
|
188
214
|
}) => Promise<{
|
|
@@ -204,4 +230,6 @@ export declare type TFHEType = {
|
|
|
204
230
|
ZkComputeLoad: any;
|
|
205
231
|
};
|
|
206
232
|
|
|
233
|
+
export declare type UserDecryptResults = ClearValues;
|
|
234
|
+
|
|
207
235
|
export { }
|