@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/lib/node.js
CHANGED
|
@@ -35,6 +35,9 @@ const bytesToBigInt = function (byteArray) {
|
|
|
35
35
|
.join('');
|
|
36
36
|
return BigInt(`0x${hex}`);
|
|
37
37
|
};
|
|
38
|
+
function ensure0x(s) {
|
|
39
|
+
return !s.startsWith('0x') ? `0x${s}` : s;
|
|
40
|
+
}
|
|
38
41
|
|
|
39
42
|
function setAuth(init, auth) {
|
|
40
43
|
if (auth) {
|
|
@@ -541,6 +544,17 @@ const NumEncryptedBits = {
|
|
|
541
544
|
7: 160, // eaddress
|
|
542
545
|
8: 256, // euint256
|
|
543
546
|
};
|
|
547
|
+
function getHandleType(handle) {
|
|
548
|
+
if (handle.length !== 66) {
|
|
549
|
+
throw new Error(`Handle ${handle} is not of valid length`);
|
|
550
|
+
}
|
|
551
|
+
const hexPair = handle.slice(-4, -2).toLowerCase();
|
|
552
|
+
const typeDiscriminant = parseInt(hexPair, 16);
|
|
553
|
+
if (!(typeDiscriminant in NumEncryptedBits)) {
|
|
554
|
+
throw new Error(`Handle ${handle} is not of valid type`);
|
|
555
|
+
}
|
|
556
|
+
return typeDiscriminant;
|
|
557
|
+
}
|
|
544
558
|
function checkEncryptedBits(handles) {
|
|
545
559
|
let total = 0;
|
|
546
560
|
for (const handle of handles) {
|
|
@@ -569,37 +583,30 @@ const aclABI$1 = [
|
|
|
569
583
|
];
|
|
570
584
|
const MAX_USER_DECRYPT_CONTRACT_ADDRESSES = 10;
|
|
571
585
|
const MAX_USER_DECRYPT_DURATION_DAYS = BigInt(365);
|
|
572
|
-
function formatAccordingToType(
|
|
586
|
+
function formatAccordingToType(clearValueAsBigInt, type) {
|
|
573
587
|
if (type === 0) {
|
|
574
588
|
// ebool
|
|
575
|
-
return
|
|
589
|
+
return clearValueAsBigInt === BigInt(1);
|
|
576
590
|
}
|
|
577
591
|
else if (type === 7) {
|
|
578
592
|
// eaddress
|
|
579
|
-
return getAddress$1('0x' +
|
|
580
|
-
}
|
|
581
|
-
else if (type === 9) {
|
|
582
|
-
// ebytes64
|
|
583
|
-
return '0x' + decryptedBigInt.toString(16).padStart(128, '0');
|
|
593
|
+
return getAddress$1('0x' + clearValueAsBigInt.toString(16).padStart(40, '0'));
|
|
584
594
|
}
|
|
585
|
-
else if (type
|
|
586
|
-
//
|
|
587
|
-
|
|
595
|
+
else if (type > 8 || type == 1) {
|
|
596
|
+
// type == 1 : euint4 (not supported)
|
|
597
|
+
throw new Error(`Unsupported handle type ${type}`);
|
|
588
598
|
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
return '0x' + decryptedBigInt.toString(16).padStart(512, '0');
|
|
592
|
-
} // euintXXX
|
|
593
|
-
return decryptedBigInt;
|
|
599
|
+
// euintXXX
|
|
600
|
+
return clearValueAsBigInt;
|
|
594
601
|
}
|
|
595
|
-
function
|
|
602
|
+
function buildUserDecryptResults(handles, listBigIntDecryptions) {
|
|
596
603
|
let typesList = [];
|
|
597
604
|
for (const handle of handles) {
|
|
598
605
|
const hexPair = handle.slice(-4, -2).toLowerCase();
|
|
599
606
|
const typeDiscriminant = parseInt(hexPair, 16);
|
|
600
607
|
typesList.push(typeDiscriminant);
|
|
601
608
|
}
|
|
602
|
-
|
|
609
|
+
const results = {};
|
|
603
610
|
handles.forEach((handle, idx) => (results[handle] = formatAccordingToType(listBigIntDecryptions[idx], typesList[idx])));
|
|
604
611
|
return results;
|
|
605
612
|
}
|
|
@@ -705,7 +712,7 @@ const userDecryptRequest = (kmsSigners, gatewayChainId, chainId, verifyingContra
|
|
|
705
712
|
};
|
|
706
713
|
const decryption = TKMS.process_user_decryption_resp_from_js(client, payloadForVerification, eip712Domain, json.response, pubKey, privKey, true);
|
|
707
714
|
const listBigIntDecryptions = decryption.map((d) => bytesToBigInt(d.bytes));
|
|
708
|
-
const results =
|
|
715
|
+
const results = buildUserDecryptResults(handles.map((h) => h.handle), listBigIntDecryptions);
|
|
709
716
|
return results;
|
|
710
717
|
}
|
|
711
718
|
catch (e) {
|
|
@@ -760,7 +767,7 @@ const createEncryptedInput = ({ aclContractAddress, chainId, tfheCompactPublicKe
|
|
|
760
767
|
checkEncryptedValue(Number(value), 1);
|
|
761
768
|
checkLimit(2);
|
|
762
769
|
builder.push_boolean(!!value);
|
|
763
|
-
bits.push(
|
|
770
|
+
bits.push(2); // ebool takes 2 encrypted bits
|
|
764
771
|
return this;
|
|
765
772
|
},
|
|
766
773
|
add8(value) {
|
|
@@ -814,36 +821,6 @@ const createEncryptedInput = ({ aclContractAddress, chainId, tfheCompactPublicKe
|
|
|
814
821
|
bits.push(256);
|
|
815
822
|
return this;
|
|
816
823
|
},
|
|
817
|
-
addBytes64(value) {
|
|
818
|
-
if (value.length !== 64)
|
|
819
|
-
throw Error('Uncorrect length of input Uint8Array, should be 64 for an ebytes64');
|
|
820
|
-
const bigIntValue = bytesToBigInt(value);
|
|
821
|
-
checkEncryptedValue(bigIntValue, 512);
|
|
822
|
-
checkLimit(512);
|
|
823
|
-
builder.push_u512(bigIntValue);
|
|
824
|
-
bits.push(512);
|
|
825
|
-
return this;
|
|
826
|
-
},
|
|
827
|
-
addBytes128(value) {
|
|
828
|
-
if (value.length !== 128)
|
|
829
|
-
throw Error('Uncorrect length of input Uint8Array, should be 128 for an ebytes128');
|
|
830
|
-
const bigIntValue = bytesToBigInt(value);
|
|
831
|
-
checkEncryptedValue(bigIntValue, 1024);
|
|
832
|
-
checkLimit(1024);
|
|
833
|
-
builder.push_u1024(bigIntValue);
|
|
834
|
-
bits.push(1024);
|
|
835
|
-
return this;
|
|
836
|
-
},
|
|
837
|
-
addBytes256(value) {
|
|
838
|
-
if (value.length !== 256)
|
|
839
|
-
throw Error('Uncorrect length of input Uint8Array, should be 256 for an ebytes256');
|
|
840
|
-
const bigIntValue = bytesToBigInt(value);
|
|
841
|
-
checkEncryptedValue(bigIntValue, 2048);
|
|
842
|
-
checkLimit(2048);
|
|
843
|
-
builder.push_u2048(bigIntValue);
|
|
844
|
-
bits.push(2048);
|
|
845
|
-
return this;
|
|
846
|
-
},
|
|
847
824
|
getBits() {
|
|
848
825
|
return bits;
|
|
849
826
|
},
|
|
@@ -876,18 +853,37 @@ const createEncryptedInput = ({ aclContractAddress, chainId, tfheCompactPublicKe
|
|
|
876
853
|
};
|
|
877
854
|
};
|
|
878
855
|
|
|
856
|
+
/**
|
|
857
|
+
* **FHE Type Mapping for Input Builders**
|
|
858
|
+
* * Maps the **number of encrypted bits** used by a FHEVM primary type
|
|
859
|
+
* to its corresponding **FheTypeId**. This constant is primarily used by
|
|
860
|
+
* `EncryptedInput` and `RelayerEncryptedInput` builders to determine the correct
|
|
861
|
+
* input type and calculate the total required bit-length.
|
|
862
|
+
*
|
|
863
|
+
* **Structure: \{ Encrypted Bit Length: FheTypeId \}**
|
|
864
|
+
*
|
|
865
|
+
* | Bits | FheTypeId | FHE Type Name | Note |
|
|
866
|
+
* | :--- | :-------- | :------------ | :--- |
|
|
867
|
+
* | 2 | 0 | `ebool` | The boolean type. |
|
|
868
|
+
* | (N/A)| 1 | `euint4` | **Deprecated** and omitted from this map. |
|
|
869
|
+
* | 8 | 2 | `euint8` | |
|
|
870
|
+
* | 16 | 3 | `euint16` | |
|
|
871
|
+
* | 32 | 4 | `euint32` | |
|
|
872
|
+
* | 64 | 5 | `euint64` | |
|
|
873
|
+
* | 128 | 6 | `euint128` | |
|
|
874
|
+
* | 160 | 7 | `eaddress` | Used for encrypted Ethereum addresses. |
|
|
875
|
+
* | 256 | 8 | `euint256` | The maximum supported integer size. |
|
|
876
|
+
*/
|
|
879
877
|
const ENCRYPTION_TYPES = {
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
1024: 10,
|
|
890
|
-
2048: 11,
|
|
878
|
+
2: 0, // ebool (FheTypeId=0) is using 2 encrypted bits
|
|
879
|
+
// euint4 (FheTypeId=1) is deprecated
|
|
880
|
+
8: 2, // euint8 (FheTypeId=2) is using 8 encrypted bits
|
|
881
|
+
16: 3, // euint16 (FheTypeId=3) is using 16 encrypted bits
|
|
882
|
+
32: 4, // euint32 (FheTypeId=4) is using 32 encrypted bits
|
|
883
|
+
64: 5, // euint64 (FheTypeId=5) is using 64 encrypted bits
|
|
884
|
+
128: 6, // euint128 (FheTypeId=128) is using 128 encrypted bits
|
|
885
|
+
160: 7, // eaddress (FheTypeId=7) is using 160 encrypted bits
|
|
886
|
+
256: 8, // euint256 (FheTypeId=8) is using 256 encrypted bits
|
|
891
887
|
};
|
|
892
888
|
|
|
893
889
|
const MAX_UINT64 = BigInt('18446744073709551615'); // 2^64 - 1
|
|
@@ -1116,6 +1112,74 @@ function isThresholdReached(kmsSigners, recoveredAddresses, threshold) {
|
|
|
1116
1112
|
}
|
|
1117
1113
|
return recoveredAddresses.length >= threshold;
|
|
1118
1114
|
}
|
|
1115
|
+
function abiEncodeClearValues(clearValues) {
|
|
1116
|
+
const handlesBytes32Hex = Object.keys(clearValues);
|
|
1117
|
+
const abiTypes = [];
|
|
1118
|
+
const abiValues = [];
|
|
1119
|
+
for (let i = 0; i < handlesBytes32Hex.length; ++i) {
|
|
1120
|
+
const handle = handlesBytes32Hex[i];
|
|
1121
|
+
const handleType = getHandleType(handle);
|
|
1122
|
+
let clearTextValue = clearValues[handle];
|
|
1123
|
+
if (typeof clearTextValue === 'boolean') {
|
|
1124
|
+
clearTextValue = clearTextValue ? '0x01' : '0x00';
|
|
1125
|
+
}
|
|
1126
|
+
const clearTextValueBigInt = BigInt(clearTextValue);
|
|
1127
|
+
//abiTypes.push(fhevmTypeInfo.solidityTypeName);
|
|
1128
|
+
abiTypes.push('uint256');
|
|
1129
|
+
switch (handleType) {
|
|
1130
|
+
// eaddress
|
|
1131
|
+
case 7: {
|
|
1132
|
+
// string
|
|
1133
|
+
abiValues.push(`0x${clearTextValueBigInt.toString(16).padStart(40, '0')}`);
|
|
1134
|
+
break;
|
|
1135
|
+
}
|
|
1136
|
+
// ebool
|
|
1137
|
+
case 0: {
|
|
1138
|
+
// bigint (0 or 1)
|
|
1139
|
+
if (clearTextValueBigInt !== BigInt(0) &&
|
|
1140
|
+
clearTextValueBigInt !== BigInt(1)) {
|
|
1141
|
+
throw new Error(`Invalid ebool clear text value ${clearTextValueBigInt}. Expecting 0 or 1.`);
|
|
1142
|
+
}
|
|
1143
|
+
abiValues.push(clearTextValueBigInt);
|
|
1144
|
+
break;
|
|
1145
|
+
}
|
|
1146
|
+
case 2: //euint8
|
|
1147
|
+
case 3: //euint16
|
|
1148
|
+
case 4: //euint32
|
|
1149
|
+
case 5: //euint64
|
|
1150
|
+
case 6: //euint128
|
|
1151
|
+
case 7: {
|
|
1152
|
+
//euint256
|
|
1153
|
+
// bigint
|
|
1154
|
+
abiValues.push(clearTextValueBigInt);
|
|
1155
|
+
break;
|
|
1156
|
+
}
|
|
1157
|
+
default: {
|
|
1158
|
+
throw new Error(`Unsupported Fhevm primitive type id: ${handleType}`);
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
const abiCoder = ethers.AbiCoder.defaultAbiCoder();
|
|
1163
|
+
// ABI encode the decryptedResult as done in the KMS, since all decrypted values
|
|
1164
|
+
// are native static types, thay have same abi-encoding as uint256:
|
|
1165
|
+
const abiEncodedClearValues = abiCoder.encode(abiTypes, abiValues);
|
|
1166
|
+
return {
|
|
1167
|
+
abiTypes,
|
|
1168
|
+
abiValues,
|
|
1169
|
+
abiEncodedClearValues,
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1172
|
+
function buildDecryptionProof(kmsSignatures, extraData) {
|
|
1173
|
+
// Build the decryptionProof as numSigners + KMS signatures + extraData
|
|
1174
|
+
const packedNumSigners = ethers.solidityPacked(['uint8'], [kmsSignatures.length]);
|
|
1175
|
+
const packedSignatures = ethers.solidityPacked(Array(kmsSignatures.length).fill('bytes'), kmsSignatures);
|
|
1176
|
+
const decryptionProof = ethers.concat([
|
|
1177
|
+
packedNumSigners,
|
|
1178
|
+
packedSignatures,
|
|
1179
|
+
extraData,
|
|
1180
|
+
]);
|
|
1181
|
+
return decryptionProof;
|
|
1182
|
+
}
|
|
1119
1183
|
const CiphertextType = {
|
|
1120
1184
|
0: 'bool',
|
|
1121
1185
|
2: 'uint256',
|
|
@@ -1126,7 +1190,7 @@ const CiphertextType = {
|
|
|
1126
1190
|
7: 'address',
|
|
1127
1191
|
8: 'uint256',
|
|
1128
1192
|
};
|
|
1129
|
-
function
|
|
1193
|
+
function deserializeClearValues(handles, decryptedResult) {
|
|
1130
1194
|
let typesList = [];
|
|
1131
1195
|
for (const handle of handles) {
|
|
1132
1196
|
const hexPair = handle.slice(-4, -2).toLowerCase();
|
|
@@ -1145,7 +1209,7 @@ function deserializeDecryptedResult(handles, decryptedResult) {
|
|
|
1145
1209
|
const decoded = coder.decode(['uint256', ...abiTypes, 'bytes[]'], restoredEncoded);
|
|
1146
1210
|
// strip dummy first/last element
|
|
1147
1211
|
const rawValues = decoded.slice(1, 1 + typesList.length);
|
|
1148
|
-
|
|
1212
|
+
const results = {};
|
|
1149
1213
|
handles.forEach((handle, idx) => (results[handle] = rawValues[idx]));
|
|
1150
1214
|
return results;
|
|
1151
1215
|
}
|
|
@@ -1190,22 +1254,26 @@ const publicDecryptRequest = (kmsSigners, thresholdSigners, gatewayChainId, veri
|
|
|
1190
1254
|
],
|
|
1191
1255
|
};
|
|
1192
1256
|
const result = json.response[0];
|
|
1193
|
-
const decryptedResult = result.decrypted_value
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
const signatures = result.signatures;
|
|
1257
|
+
const decryptedResult = ensure0x(result.decrypted_value);
|
|
1258
|
+
const kmsSignatures = result.signatures.map(ensure0x);
|
|
1259
|
+
// TODO result.extra_data (RelayerPublicDecryptJsonResponse)
|
|
1197
1260
|
const signedExtraData = '0x';
|
|
1198
|
-
const recoveredAddresses =
|
|
1199
|
-
const
|
|
1200
|
-
const recoveredAddress = ethers.verifyTypedData(domain, types, { ctHandles: handles, decryptedResult, extraData: signedExtraData }, sig);
|
|
1261
|
+
const recoveredAddresses = kmsSignatures.map((kmsSignature) => {
|
|
1262
|
+
const recoveredAddress = ethers.verifyTypedData(domain, types, { ctHandles: handles, decryptedResult, extraData: signedExtraData }, kmsSignature);
|
|
1201
1263
|
return recoveredAddress;
|
|
1202
1264
|
});
|
|
1203
1265
|
const thresholdReached = isThresholdReached(kmsSigners, recoveredAddresses, thresholdSigners);
|
|
1204
1266
|
if (!thresholdReached) {
|
|
1205
1267
|
throw Error('KMS signers threshold is not reached');
|
|
1206
1268
|
}
|
|
1207
|
-
const
|
|
1208
|
-
|
|
1269
|
+
const clearValues = deserializeClearValues(handles, decryptedResult);
|
|
1270
|
+
const abiEnc = abiEncodeClearValues(clearValues);
|
|
1271
|
+
const decryptionProof = buildDecryptionProof(kmsSignatures, signedExtraData);
|
|
1272
|
+
return {
|
|
1273
|
+
clearValues,
|
|
1274
|
+
abiEncodedClearValues: abiEnc.abiEncodedClearValues,
|
|
1275
|
+
decryptionProof,
|
|
1276
|
+
};
|
|
1209
1277
|
};
|
|
1210
1278
|
|
|
1211
1279
|
/**
|
|
@@ -1315,23 +1383,23 @@ const generateKeypair = () => {
|
|
|
1315
1383
|
global.fetch = fetchRetry(global.fetch, { retries: 5, retryDelay: 500 });
|
|
1316
1384
|
const SepoliaConfig = {
|
|
1317
1385
|
// ACL_CONTRACT_ADDRESS (FHEVM Host chain)
|
|
1318
|
-
aclContractAddress: '
|
|
1386
|
+
aclContractAddress: '0xf0Ffdc93b7E186bC2f8CB3dAA75D86d1930A433D',
|
|
1319
1387
|
// KMS_VERIFIER_CONTRACT_ADDRESS (FHEVM Host chain)
|
|
1320
|
-
kmsContractAddress: '
|
|
1388
|
+
kmsContractAddress: '0xbE0E383937d564D7FF0BC3b46c51f0bF8d5C311A',
|
|
1321
1389
|
// INPUT_VERIFIER_CONTRACT_ADDRESS (FHEVM Host chain)
|
|
1322
|
-
inputVerifierContractAddress: '
|
|
1390
|
+
inputVerifierContractAddress: '0xBBC1fFCdc7C316aAAd72E807D9b0272BE8F84DA0',
|
|
1323
1391
|
// DECRYPTION_ADDRESS (Gateway chain)
|
|
1324
|
-
verifyingContractAddressDecryption: '
|
|
1392
|
+
verifyingContractAddressDecryption: '0x5D8BD78e2ea6bbE41f26dFe9fdaEAa349e077478',
|
|
1325
1393
|
// INPUT_VERIFICATION_ADDRESS (Gateway chain)
|
|
1326
|
-
verifyingContractAddressInputVerification: '
|
|
1394
|
+
verifyingContractAddressInputVerification: '0x483b9dE06E4E4C7D35CCf5837A1668487406D955',
|
|
1327
1395
|
// FHEVM Host chain id
|
|
1328
1396
|
chainId: 11155111,
|
|
1329
1397
|
// Gateway chain id
|
|
1330
|
-
gatewayChainId:
|
|
1398
|
+
gatewayChainId: 10901,
|
|
1331
1399
|
// Optional RPC provider to host chain
|
|
1332
|
-
network: 'https://
|
|
1400
|
+
network: 'https://ethereum-sepolia-rpc.publicnode.com',
|
|
1333
1401
|
// Relayer URL
|
|
1334
|
-
relayerUrl: 'https://relayer.testnet.zama.
|
|
1402
|
+
relayerUrl: 'https://relayer.testnet.zama.org',
|
|
1335
1403
|
};
|
|
1336
1404
|
const createInstance = async (config) => {
|
|
1337
1405
|
const { verifyingContractAddressDecryption, verifyingContractAddressInputVerification, publicKey, kmsContractAddress, aclContractAddress, gatewayChainId, auth, } = config;
|
package/lib/web.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { InitInput as TFHEInput } from 'tfhe';
|
|
|
5
5
|
/**
|
|
6
6
|
* Custom cookie authentication
|
|
7
7
|
*/
|
|
8
|
-
declare type ApiKeyCookie = {
|
|
8
|
+
export declare type ApiKeyCookie = {
|
|
9
9
|
__type: 'ApiKeyCookie';
|
|
10
10
|
/**
|
|
11
11
|
* The cookie name. The default value is `x-api-key`.
|
|
@@ -20,7 +20,7 @@ declare type ApiKeyCookie = {
|
|
|
20
20
|
/**
|
|
21
21
|
* Custom header authentication
|
|
22
22
|
*/
|
|
23
|
-
declare type ApiKeyHeader = {
|
|
23
|
+
export declare type ApiKeyHeader = {
|
|
24
24
|
__type: 'ApiKeyHeader';
|
|
25
25
|
/**
|
|
26
26
|
* The header name. The default value is `x-api-key`.
|
|
@@ -39,12 +39,12 @@ declare type ApiKeyHeader = {
|
|
|
39
39
|
* - Custom header
|
|
40
40
|
* - Custom cookie
|
|
41
41
|
*/
|
|
42
|
-
declare type Auth = BearerToken | ApiKeyHeader | ApiKeyCookie;
|
|
42
|
+
export declare type Auth = BearerToken | ApiKeyHeader | ApiKeyCookie;
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* Bearer Token Authentication
|
|
46
46
|
*/
|
|
47
|
-
declare type BearerToken = {
|
|
47
|
+
export declare type BearerToken = {
|
|
48
48
|
__type: 'BearerToken';
|
|
49
49
|
/**
|
|
50
50
|
* The Bearer token.
|
|
@@ -52,6 +52,10 @@ declare type BearerToken = {
|
|
|
52
52
|
token: string;
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
+
export declare type ClearValues = Record<`0x${string}`, ClearValueType>;
|
|
56
|
+
|
|
57
|
+
export declare type ClearValueType = bigint | boolean | `0x${string}`;
|
|
58
|
+
|
|
55
59
|
/**
|
|
56
60
|
* Creates an EIP712 structure specifically for user decrypt requests
|
|
57
61
|
*
|
|
@@ -69,8 +73,6 @@ export declare const createEIP712: (verifyingContract: string, contractsChainId:
|
|
|
69
73
|
|
|
70
74
|
export declare const createInstance: (config: FhevmInstanceConfig) => Promise<FhevmInstance>;
|
|
71
75
|
|
|
72
|
-
export declare type DecryptedResults = Record<string, bigint | boolean | string>;
|
|
73
|
-
|
|
74
76
|
export declare type EIP712 = {
|
|
75
77
|
domain: {
|
|
76
78
|
chainId: number;
|
|
@@ -90,8 +92,29 @@ export declare type EIP712Type = {
|
|
|
90
92
|
type: string;
|
|
91
93
|
};
|
|
92
94
|
|
|
95
|
+
/**
|
|
96
|
+
* **FHE Type Mapping for Input Builders**
|
|
97
|
+
* * Maps the **number of encrypted bits** used by a FHEVM primary type
|
|
98
|
+
* to its corresponding **FheTypeId**. This constant is primarily used by
|
|
99
|
+
* `EncryptedInput` and `RelayerEncryptedInput` builders to determine the correct
|
|
100
|
+
* input type and calculate the total required bit-length.
|
|
101
|
+
*
|
|
102
|
+
* **Structure: \{ Encrypted Bit Length: FheTypeId \}**
|
|
103
|
+
*
|
|
104
|
+
* | Bits | FheTypeId | FHE Type Name | Note |
|
|
105
|
+
* | :--- | :-------- | :------------ | :--- |
|
|
106
|
+
* | 2 | 0 | `ebool` | The boolean type. |
|
|
107
|
+
* | (N/A)| 1 | `euint4` | **Deprecated** and omitted from this map. |
|
|
108
|
+
* | 8 | 2 | `euint8` | |
|
|
109
|
+
* | 16 | 3 | `euint16` | |
|
|
110
|
+
* | 32 | 4 | `euint32` | |
|
|
111
|
+
* | 64 | 5 | `euint64` | |
|
|
112
|
+
* | 128 | 6 | `euint128` | |
|
|
113
|
+
* | 160 | 7 | `eaddress` | Used for encrypted Ethereum addresses. |
|
|
114
|
+
* | 256 | 8 | `euint256` | The maximum supported integer size. |
|
|
115
|
+
*/
|
|
93
116
|
export declare const ENCRYPTION_TYPES: {
|
|
94
|
-
|
|
117
|
+
2: number;
|
|
95
118
|
8: number;
|
|
96
119
|
16: number;
|
|
97
120
|
32: number;
|
|
@@ -99,12 +122,9 @@ export declare const ENCRYPTION_TYPES: {
|
|
|
99
122
|
128: number;
|
|
100
123
|
160: number;
|
|
101
124
|
256: number;
|
|
102
|
-
512: number;
|
|
103
|
-
1024: number;
|
|
104
|
-
2048: number;
|
|
105
125
|
};
|
|
106
126
|
|
|
107
|
-
export declare type
|
|
127
|
+
export declare type EncryptionBits = keyof typeof ENCRYPTION_TYPES;
|
|
108
128
|
|
|
109
129
|
export declare type FhevmInstance = {
|
|
110
130
|
createEncryptedInput: (contractAddress: string, userAddress: string) => RelayerEncryptedInput;
|
|
@@ -113,8 +133,8 @@ export declare type FhevmInstance = {
|
|
|
113
133
|
privateKey: string;
|
|
114
134
|
};
|
|
115
135
|
createEIP712: (publicKey: string, contractAddresses: string[], startTimestamp: string | number, durationDays: string | number) => EIP712;
|
|
116
|
-
publicDecrypt: (handles: (string | Uint8Array)[]) => Promise<
|
|
117
|
-
userDecrypt: (handles: HandleContractPair[], privateKey: string, publicKey: string, signature: string, contractAddresses: string[], userAddress: string, startTimestamp: string | number, durationDays: string | number) => Promise<
|
|
136
|
+
publicDecrypt: (handles: (string | Uint8Array)[]) => Promise<PublicDecryptResults>;
|
|
137
|
+
userDecrypt: (handles: HandleContractPair[], privateKey: string, publicKey: string, signature: string, contractAddresses: string[], userAddress: string, startTimestamp: string | number, durationDays: string | number) => Promise<UserDecryptResults>;
|
|
118
138
|
getPublicKey: () => {
|
|
119
139
|
publicKeyId: string;
|
|
120
140
|
publicKey: Uint8Array;
|
|
@@ -165,8 +185,14 @@ export declare const initSDK: ({ tfheParams, kmsParams, thread, }?: {
|
|
|
165
185
|
|
|
166
186
|
export { KMSInput }
|
|
167
187
|
|
|
188
|
+
export declare type PublicDecryptResults = {
|
|
189
|
+
clearValues: ClearValues;
|
|
190
|
+
abiEncodedClearValues: `0x${string}`;
|
|
191
|
+
decryptionProof: `0x${string}`;
|
|
192
|
+
};
|
|
193
|
+
|
|
168
194
|
export declare type PublicParams<T = TFHEType['CompactPkeCrs']> = {
|
|
169
|
-
|
|
195
|
+
2048: {
|
|
170
196
|
publicParams: T;
|
|
171
197
|
publicParamsId: string;
|
|
172
198
|
};
|
|
@@ -181,7 +207,7 @@ export declare type RelayerEncryptedInput = {
|
|
|
181
207
|
add128: (value: number | bigint) => RelayerEncryptedInput;
|
|
182
208
|
add256: (value: number | bigint) => RelayerEncryptedInput;
|
|
183
209
|
addAddress: (value: string) => RelayerEncryptedInput;
|
|
184
|
-
getBits: () =>
|
|
210
|
+
getBits: () => EncryptionBits[];
|
|
185
211
|
encrypt: (options?: {
|
|
186
212
|
auth?: Auth;
|
|
187
213
|
}) => Promise<{
|
|
@@ -194,7 +220,7 @@ export declare const SepoliaConfig: FhevmInstanceConfig;
|
|
|
194
220
|
|
|
195
221
|
export { TFHEInput }
|
|
196
222
|
|
|
197
|
-
declare type TFHEType = {
|
|
223
|
+
export declare type TFHEType = {
|
|
198
224
|
default?: any;
|
|
199
225
|
TFHEInput?: any;
|
|
200
226
|
TfheCompactPublicKey: any;
|
|
@@ -205,4 +231,6 @@ declare type TFHEType = {
|
|
|
205
231
|
ZkComputeLoad: any;
|
|
206
232
|
};
|
|
207
233
|
|
|
234
|
+
export declare type UserDecryptResults = ClearValues;
|
|
235
|
+
|
|
208
236
|
export { }
|