@cofhe/sdk 0.5.2 → 0.6.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/CHANGELOG.md +30 -0
- package/chains/chains/hardhat.ts +3 -3
- package/core/consts.ts +0 -3
- package/core/debug.ts +72 -0
- package/core/decrypt/tnDecryptV2.ts +20 -13
- package/core/decrypt/tnSealOutputV2.ts +20 -13
- package/core/encrypt/cofheMocksZkVerifySign.ts +2 -2
- package/core/encrypt/encryptInputsBuilder.ts +46 -11
- package/core/encrypt/zkPackProveVerify.ts +3 -3
- package/core/index.ts +23 -1
- package/core/permits.ts +17 -7
- package/core/test/encryptInputsBuilder.test.ts +35 -0
- package/core/test/permits.test.ts +62 -0
- package/core/types.ts +65 -5
- package/dist/chains.cjs +3 -3
- package/dist/chains.js +1 -1
- package/dist/{chunk-4FP4V35O.js → chunk-ESMZCFJY.js} +1 -2
- package/dist/{chunk-TBLR7NNE.js → chunk-MTRAXQXC.js} +3 -3
- package/dist/{chunk-YDOK4BDL.js → chunk-NOC3PYB7.js} +108 -33
- package/dist/{chunk-MRCKUMOS.js → chunk-VB62WYPL.js} +1 -1
- package/dist/{clientTypes-BJbFeeno.d.cts → clientTypes-BDy1qIBu.d.cts} +73 -11
- package/dist/{clientTypes-CEno_BEf.d.ts → clientTypes-CyUvRRzA.d.ts} +73 -11
- package/dist/core.cjs +110 -34
- package/dist/core.d.cts +26 -5
- package/dist/core.d.ts +26 -5
- package/dist/core.js +4 -4
- package/dist/node.cjs +100 -32
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +4 -4
- package/dist/permits.d.cts +10 -6
- package/dist/permits.d.ts +10 -6
- package/dist/permits.js +2 -2
- package/dist/web.cjs +100 -32
- package/dist/web.d.cts +1 -1
- package/dist/web.d.ts +1 -1
- package/dist/web.js +4 -4
- package/dist/zkProve.worker.js +1 -1
- package/package.json +2 -2
- package/permits/store.ts +1 -0
- package/web/test/ssr.test.ts +23 -0
- package/web/test/tfheinit.web.test.ts +81 -5
package/core/types.ts
CHANGED
|
@@ -111,16 +111,14 @@ export type EncryptedNumber = {
|
|
|
111
111
|
securityZone: number;
|
|
112
112
|
};
|
|
113
113
|
|
|
114
|
-
export type EncryptedItemInput
|
|
114
|
+
export type EncryptedItemInput = {
|
|
115
115
|
ctHash: bigint;
|
|
116
116
|
securityZone: number;
|
|
117
117
|
utype: FheTypes;
|
|
118
|
-
signature:
|
|
118
|
+
signature: `0x${string}`;
|
|
119
119
|
};
|
|
120
120
|
|
|
121
|
-
export function assertCorrectEncryptedItemInput(
|
|
122
|
-
input: EncryptedItemInput
|
|
123
|
-
): asserts input is EncryptedItemInput<`0x${string}`> {
|
|
121
|
+
export function assertCorrectEncryptedItemInput(input: EncryptedItemInput): asserts input is EncryptedItemInput {
|
|
124
122
|
if (!input.signature.startsWith('0x')) throw new Error('Signature must be a hex string starting with 0x');
|
|
125
123
|
}
|
|
126
124
|
|
|
@@ -387,6 +385,68 @@ export type EncryptStepCallbackContext = Record<string, any> & {
|
|
|
387
385
|
};
|
|
388
386
|
export type EncryptStepCallbackFunction = (state: EncryptStep, context?: EncryptStepCallbackContext) => void;
|
|
389
387
|
|
|
388
|
+
// HASH PLUS PROOF ENCRYPTED INPUTS
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Branded bytes32 types for external encrypted inputs (Solidity: externalEbool, externalEuint*, externalEaddress).
|
|
392
|
+
* The readonly `utype` field brands each hash so it can't be accidentally passed to the wrong asE* function.
|
|
393
|
+
*/
|
|
394
|
+
export type ExternalBoolHash = `0x${string}` & { readonly utype: FheTypes.Bool };
|
|
395
|
+
export type ExternalUint8Hash = `0x${string}` & { readonly utype: FheTypes.Uint8 };
|
|
396
|
+
export type ExternalUint16Hash = `0x${string}` & { readonly utype: FheTypes.Uint16 };
|
|
397
|
+
export type ExternalUint32Hash = `0x${string}` & { readonly utype: FheTypes.Uint32 };
|
|
398
|
+
export type ExternalUint64Hash = `0x${string}` & { readonly utype: FheTypes.Uint64 };
|
|
399
|
+
export type ExternalUint128Hash = `0x${string}` & { readonly utype: FheTypes.Uint128 };
|
|
400
|
+
export type ExternalAddressHash = `0x${string}` & { readonly utype: FheTypes.Uint160 };
|
|
401
|
+
|
|
402
|
+
/** Branded bytes proof blob (Solidity: bytes memory proof). */
|
|
403
|
+
export type ExternalHashProof = `0x${string}` & { readonly _kind: 'ExternalHashProof' };
|
|
404
|
+
|
|
405
|
+
/** Union of all External*Hash types — useful for utilities that operate on any hash without caring about the specific FHE type. */
|
|
406
|
+
export type AnyExternalHash =
|
|
407
|
+
| ExternalBoolHash
|
|
408
|
+
| ExternalUint8Hash
|
|
409
|
+
| ExternalUint16Hash
|
|
410
|
+
| ExternalUint32Hash
|
|
411
|
+
| ExternalUint64Hash
|
|
412
|
+
| ExternalUint128Hash
|
|
413
|
+
| ExternalAddressHash;
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Maps a single EncryptableItem to its corresponding External*Hash type.
|
|
417
|
+
* Mirrors EncryptableToEncryptedItemInputMap.
|
|
418
|
+
*/
|
|
419
|
+
export type EncryptableToExternalHashMap<E extends EncryptableItem> = E extends EncryptableBool
|
|
420
|
+
? ExternalBoolHash
|
|
421
|
+
: E extends EncryptableUint8
|
|
422
|
+
? ExternalUint8Hash
|
|
423
|
+
: E extends EncryptableUint16
|
|
424
|
+
? ExternalUint16Hash
|
|
425
|
+
: E extends EncryptableUint32
|
|
426
|
+
? ExternalUint32Hash
|
|
427
|
+
: E extends EncryptableUint64
|
|
428
|
+
? ExternalUint64Hash
|
|
429
|
+
: E extends EncryptableUint128
|
|
430
|
+
? ExternalUint128Hash
|
|
431
|
+
: E extends EncryptableAddress
|
|
432
|
+
? ExternalAddressHash
|
|
433
|
+
: never;
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Maps an EncryptableItem[] tuple to a tuple of corresponding External*Hash types,
|
|
437
|
+
* preserving index positions. e.g. [EncryptableBool, EncryptableUint32] → [ExternalBoolHash, ExternalUint32Hash]
|
|
438
|
+
*/
|
|
439
|
+
export type ExternalItemHashes<T extends EncryptableItem[]> = {
|
|
440
|
+
[K in keyof T]: T[K] extends EncryptableItem ? EncryptableToExternalHashMap<T[K]> : never;
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Return type of EncryptInputsBuilder.execute() when asHashPlusProof() is set.
|
|
445
|
+
* Tuple of per-input hashes in input order, followed by a single proof blob.
|
|
446
|
+
* e.g. [Encryptable.bool(true), Encryptable.uint32(5)] → [ExternalBoolHash, ExternalUint32Hash, ExternalHashProof]
|
|
447
|
+
*/
|
|
448
|
+
export type HashPlusProofResult<T extends EncryptableItem[]> = [...ExternalItemHashes<T>, ExternalHashProof];
|
|
449
|
+
|
|
390
450
|
// DECRYPT
|
|
391
451
|
|
|
392
452
|
export type DecryptEndpoint = 'decrypt' | 'sealoutput';
|
package/dist/chains.cjs
CHANGED
|
@@ -67,9 +67,9 @@ var hardhat = defineChain({
|
|
|
67
67
|
name: "Hardhat",
|
|
68
68
|
network: "localhost",
|
|
69
69
|
// These are unused in the mock environment
|
|
70
|
-
coFheUrl: "http://
|
|
71
|
-
verifierUrl: "http://
|
|
72
|
-
thresholdNetworkUrl: "http://
|
|
70
|
+
coFheUrl: "http://ignored-in-mock-environment",
|
|
71
|
+
verifierUrl: "http://ignored-in-mock-environment",
|
|
72
|
+
thresholdNetworkUrl: "http://ignored-in-mock-environment",
|
|
73
73
|
environment: "MOCK"
|
|
74
74
|
});
|
|
75
75
|
|
package/dist/chains.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { arbSepolia, baseSepolia, chains, getChainById, getChainByName, hardhat, localcofhe, sepolia } from './chunk-
|
|
1
|
+
export { arbSepolia, baseSepolia, chains, getChainById, getChainByName, hardhat, localcofhe, sepolia } from './chunk-MTRAXQXC.js';
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
var TASK_MANAGER_ADDRESS = "0xeA30c4B8b44078Bbf8a6ef5b9f1eC1626C7848D9";
|
|
3
3
|
var MOCKS_ZK_VERIFIER_ADDRESS = "0x0000000000000000000000000000000000005001";
|
|
4
4
|
var MOCKS_THRESHOLD_NETWORK_ADDRESS = "0x0000000000000000000000000000000000005002";
|
|
5
|
-
var TEST_BED_ADDRESS = "0x0000000000000000000000000000000000005003";
|
|
6
5
|
var MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY = "0x6C8D7F768A6BB4AAFE85E8A2F5A9680355239C7E14646ED62B044E39DE154512";
|
|
7
6
|
var MOCKS_ZK_VERIFIER_SIGNER_ADDRESS = "0x6E12D8C87503D4287c294f2Fdef96ACd9DFf6bd2";
|
|
8
7
|
var MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY = "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d";
|
|
@@ -10,4 +9,4 @@ var TFHE_RS_ZK_MAX_BITS = 2048;
|
|
|
10
9
|
var TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT = BigInt(1 << 30);
|
|
11
10
|
var TFHE_RS_KEY_VERSION = 2;
|
|
12
11
|
|
|
13
|
-
export { MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY, MOCKS_THRESHOLD_NETWORK_ADDRESS, MOCKS_ZK_VERIFIER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY, TASK_MANAGER_ADDRESS,
|
|
12
|
+
export { MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY, MOCKS_THRESHOLD_NETWORK_ADDRESS, MOCKS_ZK_VERIFIER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY, TASK_MANAGER_ADDRESS, TFHE_RS_KEY_VERSION, TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT, TFHE_RS_ZK_MAX_BITS };
|
|
@@ -65,9 +65,9 @@ var hardhat = defineChain({
|
|
|
65
65
|
name: "Hardhat",
|
|
66
66
|
network: "localhost",
|
|
67
67
|
// These are unused in the mock environment
|
|
68
|
-
coFheUrl: "http://
|
|
69
|
-
verifierUrl: "http://
|
|
70
|
-
thresholdNetworkUrl: "http://
|
|
68
|
+
coFheUrl: "http://ignored-in-mock-environment",
|
|
69
|
+
verifierUrl: "http://ignored-in-mock-environment",
|
|
70
|
+
thresholdNetworkUrl: "http://ignored-in-mock-environment",
|
|
71
71
|
environment: "MOCK"
|
|
72
72
|
});
|
|
73
73
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { hardhat as hardhat$1 } from './chunk-
|
|
2
|
-
import { permitStore, PermitUtils } from './chunk-
|
|
3
|
-
import { TFHE_RS_KEY_VERSION, TASK_MANAGER_ADDRESS, TFHE_RS_ZK_MAX_BITS, TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT, MOCKS_THRESHOLD_NETWORK_ADDRESS, MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY, MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY, MOCKS_ZK_VERIFIER_ADDRESS } from './chunk-
|
|
1
|
+
import { hardhat as hardhat$1 } from './chunk-MTRAXQXC.js';
|
|
2
|
+
import { permitStore, PermitUtils } from './chunk-VB62WYPL.js';
|
|
3
|
+
import { TFHE_RS_KEY_VERSION, TASK_MANAGER_ADDRESS, TFHE_RS_ZK_MAX_BITS, TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT, MOCKS_THRESHOLD_NETWORK_ADDRESS, MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY, MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY, MOCKS_ZK_VERIFIER_ADDRESS } from './chunk-ESMZCFJY.js';
|
|
4
4
|
import { createStore } from 'zustand/vanilla';
|
|
5
5
|
import { parseAbi, isAddressEqual, zeroAddress, recoverAddress, encodePacked, keccak256, createWalletClient, http, getAddress, parseSignature, serializeSignature } from 'viem';
|
|
6
6
|
import { hardhat } from 'viem/chains';
|
|
@@ -528,7 +528,7 @@ var zkVerify = async (verifierUrl, serializedBytes, address, securityZone, chain
|
|
|
528
528
|
}
|
|
529
529
|
};
|
|
530
530
|
var concatSigRecid = (signature, recid) => {
|
|
531
|
-
return signature
|
|
531
|
+
return `${signature}${(recid + 27).toString(16).padStart(2, "0")}`;
|
|
532
532
|
};
|
|
533
533
|
|
|
534
534
|
// core/encrypt/MockZkVerifierAbi.ts
|
|
@@ -1215,6 +1215,7 @@ var EncryptInputsBuilder = class extends BaseBuilder {
|
|
|
1215
1215
|
securityZone;
|
|
1216
1216
|
stepCallback;
|
|
1217
1217
|
inputItems;
|
|
1218
|
+
hpp = false;
|
|
1218
1219
|
zkvWalletClient;
|
|
1219
1220
|
tfhePublicKeyDeserializer;
|
|
1220
1221
|
compactPkeCrsDeserializer;
|
|
@@ -1344,6 +1345,20 @@ var EncryptInputsBuilder = class extends BaseBuilder {
|
|
|
1344
1345
|
getSecurityZone() {
|
|
1345
1346
|
return this.securityZone;
|
|
1346
1347
|
}
|
|
1348
|
+
/**
|
|
1349
|
+
* Example:
|
|
1350
|
+
* ```typescript
|
|
1351
|
+
* const encrypted = await encryptInputs([Encryptable.uint128(10n)])
|
|
1352
|
+
* .asHashPlusProof()
|
|
1353
|
+
* .execute();
|
|
1354
|
+
* ```
|
|
1355
|
+
*
|
|
1356
|
+
* @returns Chainable EncryptInputsBuilder instance that will return a HashPlusProofResult instead of an array of EncryptedItemInputs.
|
|
1357
|
+
*/
|
|
1358
|
+
asHashPlusProof() {
|
|
1359
|
+
this.hpp = true;
|
|
1360
|
+
return this;
|
|
1361
|
+
}
|
|
1347
1362
|
/**
|
|
1348
1363
|
* @param useWorker - Whether to use Web Workers for ZK proof generation.
|
|
1349
1364
|
*
|
|
@@ -1625,6 +1640,15 @@ var EncryptInputsBuilder = class extends BaseBuilder {
|
|
|
1625
1640
|
this.fireStepEnd("verify" /* Verify */);
|
|
1626
1641
|
return encryptedInputs;
|
|
1627
1642
|
}
|
|
1643
|
+
structsToHashPlusProof(inItems) {
|
|
1644
|
+
let hashes = [];
|
|
1645
|
+
let proof = "";
|
|
1646
|
+
for (const item of inItems) {
|
|
1647
|
+
hashes.push("0x" + item.ctHash.toString(16).padStart(64, "0"));
|
|
1648
|
+
proof += item.signature;
|
|
1649
|
+
}
|
|
1650
|
+
return [...hashes, proof];
|
|
1651
|
+
}
|
|
1628
1652
|
/**
|
|
1629
1653
|
* Final step of the encryption process. MUST BE CALLED LAST IN THE CHAIN.
|
|
1630
1654
|
*
|
|
@@ -1645,9 +1669,14 @@ var EncryptInputsBuilder = class extends BaseBuilder {
|
|
|
1645
1669
|
* @returns The encrypted inputs.
|
|
1646
1670
|
*/
|
|
1647
1671
|
async execute() {
|
|
1672
|
+
let items;
|
|
1648
1673
|
if (this.chainId === hardhat.id)
|
|
1649
|
-
|
|
1650
|
-
|
|
1674
|
+
items = await this.mocksExecute();
|
|
1675
|
+
else
|
|
1676
|
+
items = await this.productionExecute();
|
|
1677
|
+
if (this.hpp)
|
|
1678
|
+
return this.structsToHashPlusProof(items);
|
|
1679
|
+
return items;
|
|
1651
1680
|
}
|
|
1652
1681
|
};
|
|
1653
1682
|
var storeActivePermit = async (permit, publicClient, walletClient) => {
|
|
@@ -1701,7 +1730,7 @@ var getOrCreateSelfPermit = async (publicClient, walletClient, chainId, account,
|
|
|
1701
1730
|
const _chainId = chainId ?? await publicClient.getChainId();
|
|
1702
1731
|
const _account = account ?? walletClient.account.address;
|
|
1703
1732
|
const activePermit = await getActivePermit(_chainId, _account);
|
|
1704
|
-
if (activePermit && activePermit.type === "self") {
|
|
1733
|
+
if (activePermit && activePermit.type === "self" && PermitUtils.isValid(activePermit).valid) {
|
|
1705
1734
|
return activePermit;
|
|
1706
1735
|
}
|
|
1707
1736
|
return createSelf(options ?? { issuer: _account, name: "Autogenerated Self Permit" }, publicClient, walletClient);
|
|
@@ -1710,7 +1739,7 @@ var getOrCreateSharingPermit = async (publicClient, walletClient, options, chain
|
|
|
1710
1739
|
const _chainId = chainId ?? await publicClient.getChainId();
|
|
1711
1740
|
const _account = account ?? walletClient.account.address;
|
|
1712
1741
|
const activePermit = await getActivePermit(_chainId, _account);
|
|
1713
|
-
if (activePermit && activePermit.type === "sharing") {
|
|
1742
|
+
if (activePermit && activePermit.type === "sharing" && PermitUtils.isValid(activePermit).valid) {
|
|
1714
1743
|
return activePermit;
|
|
1715
1744
|
}
|
|
1716
1745
|
return createSharing(options, publicClient, walletClient);
|
|
@@ -1969,6 +1998,36 @@ async function cofheMocksDecryptForView(ctHash, utype, permit, publicClient) {
|
|
|
1969
1998
|
return unsealed;
|
|
1970
1999
|
}
|
|
1971
2000
|
|
|
2001
|
+
// core/debug.ts
|
|
2002
|
+
var interceptors = {};
|
|
2003
|
+
function setCofheDebugInterceptors(next) {
|
|
2004
|
+
interceptors.onRequest = next?.onRequest;
|
|
2005
|
+
interceptors.onResponse = next?.onResponse;
|
|
2006
|
+
}
|
|
2007
|
+
function getCofheDebugInterceptors() {
|
|
2008
|
+
return interceptors;
|
|
2009
|
+
}
|
|
2010
|
+
async function cofheFetch(url, init, ctx = { op: "request" }) {
|
|
2011
|
+
let finalUrl = url;
|
|
2012
|
+
let finalInit = init;
|
|
2013
|
+
if (interceptors.onRequest) {
|
|
2014
|
+
const override = await interceptors.onRequest(finalUrl, finalInit, ctx);
|
|
2015
|
+
if (override) {
|
|
2016
|
+
if (override.url !== void 0)
|
|
2017
|
+
finalUrl = override.url;
|
|
2018
|
+
if (override.init !== void 0)
|
|
2019
|
+
finalInit = override.init;
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2022
|
+
let response = await fetch(finalUrl, finalInit);
|
|
2023
|
+
if (interceptors.onResponse) {
|
|
2024
|
+
const replaced = await interceptors.onResponse(response, ctx);
|
|
2025
|
+
if (replaced)
|
|
2026
|
+
response = replaced;
|
|
2027
|
+
}
|
|
2028
|
+
return response;
|
|
2029
|
+
}
|
|
2030
|
+
|
|
1972
2031
|
// core/decrypt/polling.ts
|
|
1973
2032
|
function computeMinuteRampPollIntervalMs(elapsedMs, params) {
|
|
1974
2033
|
const elapsedSeconds = Math.floor(elapsedMs / 1e3);
|
|
@@ -2138,13 +2197,17 @@ async function submitSealOutputRequest(thresholdNetworkUrl, ctHash, chainId, per
|
|
|
2138
2197
|
for (; ; ) {
|
|
2139
2198
|
let response;
|
|
2140
2199
|
try {
|
|
2141
|
-
response = await
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2200
|
+
response = await cofheFetch(
|
|
2201
|
+
`${thresholdNetworkUrl}/v2/sealoutput`,
|
|
2202
|
+
/*op:sealoutput*/
|
|
2203
|
+
{
|
|
2204
|
+
method: "POST",
|
|
2205
|
+
headers: {
|
|
2206
|
+
"Content-Type": "application/json"
|
|
2207
|
+
},
|
|
2208
|
+
body: JSON.stringify(body)
|
|
2209
|
+
}
|
|
2210
|
+
);
|
|
2148
2211
|
} catch (e) {
|
|
2149
2212
|
throw new CofheError({
|
|
2150
2213
|
code: "SEAL_OUTPUT_FAILED" /* SealOutputFailed */,
|
|
@@ -2267,12 +2330,16 @@ async function pollSealOutputStatus(thresholdNetworkUrl, requestId, overallStart
|
|
|
2267
2330
|
}
|
|
2268
2331
|
let response;
|
|
2269
2332
|
try {
|
|
2270
|
-
response = await
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2333
|
+
response = await cofheFetch(
|
|
2334
|
+
`${thresholdNetworkUrl}/v2/sealoutput/${requestId}`,
|
|
2335
|
+
/*op:sealoutput-poll*/
|
|
2336
|
+
{
|
|
2337
|
+
method: "GET",
|
|
2338
|
+
headers: {
|
|
2339
|
+
"Content-Type": "application/json"
|
|
2340
|
+
}
|
|
2274
2341
|
}
|
|
2275
|
-
|
|
2342
|
+
);
|
|
2276
2343
|
} catch (e) {
|
|
2277
2344
|
throw new CofheError({
|
|
2278
2345
|
code: "SEAL_OUTPUT_FAILED" /* SealOutputFailed */,
|
|
@@ -2869,13 +2936,17 @@ async function submitDecryptRequestV2(thresholdNetworkUrl, ctHash, chainId, perm
|
|
|
2869
2936
|
for (; ; ) {
|
|
2870
2937
|
let response;
|
|
2871
2938
|
try {
|
|
2872
|
-
response = await
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2939
|
+
response = await cofheFetch(
|
|
2940
|
+
`${thresholdNetworkUrl}/v2/decrypt`,
|
|
2941
|
+
/*op:decrypt*/
|
|
2942
|
+
{
|
|
2943
|
+
method: "POST",
|
|
2944
|
+
headers: {
|
|
2945
|
+
"Content-Type": "application/json"
|
|
2946
|
+
},
|
|
2947
|
+
body: JSON.stringify(body)
|
|
2948
|
+
}
|
|
2949
|
+
);
|
|
2879
2950
|
} catch (e) {
|
|
2880
2951
|
throw new CofheError({
|
|
2881
2952
|
code: "DECRYPT_FAILED" /* DecryptFailed */,
|
|
@@ -3000,12 +3071,16 @@ async function pollDecryptStatusV2(thresholdNetworkUrl, requestId, overallStartT
|
|
|
3000
3071
|
}
|
|
3001
3072
|
let response;
|
|
3002
3073
|
try {
|
|
3003
|
-
response = await
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3074
|
+
response = await cofheFetch(
|
|
3075
|
+
`${thresholdNetworkUrl}/v2/decrypt/${requestId}`,
|
|
3076
|
+
/*op:decrypt-poll*/
|
|
3077
|
+
{
|
|
3078
|
+
method: "GET",
|
|
3079
|
+
headers: {
|
|
3080
|
+
"Content-Type": "application/json"
|
|
3081
|
+
}
|
|
3007
3082
|
}
|
|
3008
|
-
|
|
3083
|
+
);
|
|
3009
3084
|
} catch (e) {
|
|
3010
3085
|
throw new CofheError({
|
|
3011
3086
|
code: "DECRYPT_FAILED" /* DecryptFailed */,
|
|
@@ -3604,4 +3679,4 @@ function createCofheClientBase(opts) {
|
|
|
3604
3679
|
};
|
|
3605
3680
|
}
|
|
3606
3681
|
|
|
3607
|
-
export { CofheError, CofheErrorCode, DecryptForTxBuilder, DecryptForViewBuilder, EncryptInputsBuilder, EncryptStep, Encryptable, FheAllUTypes, FheTypes, FheUintUTypes, InitialConnectStore, assertCorrectEncryptedItemInput, createCofheClientBase, createCofheConfigBase, createKeysStore, fetchKeys, fheTypeToString, getCofheConfigItem, isCofheError, isEncryptableItem, isLastEncryptionStep, verifyDecryptResult, zkProveWithWorker };
|
|
3682
|
+
export { CofheError, CofheErrorCode, DecryptForTxBuilder, DecryptForViewBuilder, EncryptInputsBuilder, EncryptStep, Encryptable, FheAllUTypes, FheTypes, FheUintUTypes, InitialConnectStore, assertCorrectEncryptedItemInput, cofheFetch, createCofheClientBase, createCofheConfigBase, createKeysStore, fetchKeys, fheTypeToString, getCofheConfigItem, getCofheDebugInterceptors, isCofheError, isEncryptableItem, isLastEncryptionStep, setCofheDebugInterceptors, verifyDecryptResult, zkProveWithWorker };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TASK_MANAGER_ADDRESS } from './chunk-
|
|
1
|
+
import { TASK_MANAGER_ADDRESS } from './chunk-ESMZCFJY.js';
|
|
2
2
|
import { isAddress, getAddress, zeroAddress, isHex, keccak256, toHex, BaseError, ContractFunctionRevertedError, decodeErrorResult, parseAbi } from 'viem';
|
|
3
3
|
import nacl from 'tweetnacl';
|
|
4
4
|
import { z } from 'zod';
|
|
@@ -59,13 +59,13 @@ type EncryptedNumber = {
|
|
|
59
59
|
data: Uint8Array;
|
|
60
60
|
securityZone: number;
|
|
61
61
|
};
|
|
62
|
-
type EncryptedItemInput
|
|
62
|
+
type EncryptedItemInput = {
|
|
63
63
|
ctHash: bigint;
|
|
64
64
|
securityZone: number;
|
|
65
65
|
utype: FheTypes;
|
|
66
|
-
signature:
|
|
66
|
+
signature: `0x${string}`;
|
|
67
67
|
};
|
|
68
|
-
declare function assertCorrectEncryptedItemInput(input: EncryptedItemInput): asserts input is EncryptedItemInput
|
|
68
|
+
declare function assertCorrectEncryptedItemInput(input: EncryptedItemInput): asserts input is EncryptedItemInput;
|
|
69
69
|
type EncryptedBoolInput = EncryptedItemInput & {
|
|
70
70
|
utype: FheTypes.Bool;
|
|
71
71
|
};
|
|
@@ -165,6 +165,55 @@ type EncryptStepCallbackContext = Record<string, any> & {
|
|
|
165
165
|
duration: number;
|
|
166
166
|
};
|
|
167
167
|
type EncryptStepCallbackFunction = (state: EncryptStep, context?: EncryptStepCallbackContext) => void;
|
|
168
|
+
/**
|
|
169
|
+
* Branded bytes32 types for external encrypted inputs (Solidity: externalEbool, externalEuint*, externalEaddress).
|
|
170
|
+
* The readonly `utype` field brands each hash so it can't be accidentally passed to the wrong asE* function.
|
|
171
|
+
*/
|
|
172
|
+
type ExternalBoolHash = `0x${string}` & {
|
|
173
|
+
readonly utype: FheTypes.Bool;
|
|
174
|
+
};
|
|
175
|
+
type ExternalUint8Hash = `0x${string}` & {
|
|
176
|
+
readonly utype: FheTypes.Uint8;
|
|
177
|
+
};
|
|
178
|
+
type ExternalUint16Hash = `0x${string}` & {
|
|
179
|
+
readonly utype: FheTypes.Uint16;
|
|
180
|
+
};
|
|
181
|
+
type ExternalUint32Hash = `0x${string}` & {
|
|
182
|
+
readonly utype: FheTypes.Uint32;
|
|
183
|
+
};
|
|
184
|
+
type ExternalUint64Hash = `0x${string}` & {
|
|
185
|
+
readonly utype: FheTypes.Uint64;
|
|
186
|
+
};
|
|
187
|
+
type ExternalUint128Hash = `0x${string}` & {
|
|
188
|
+
readonly utype: FheTypes.Uint128;
|
|
189
|
+
};
|
|
190
|
+
type ExternalAddressHash = `0x${string}` & {
|
|
191
|
+
readonly utype: FheTypes.Uint160;
|
|
192
|
+
};
|
|
193
|
+
/** Branded bytes proof blob (Solidity: bytes memory proof). */
|
|
194
|
+
type ExternalHashProof = `0x${string}` & {
|
|
195
|
+
readonly _kind: 'ExternalHashProof';
|
|
196
|
+
};
|
|
197
|
+
/** Union of all External*Hash types — useful for utilities that operate on any hash without caring about the specific FHE type. */
|
|
198
|
+
type AnyExternalHash = ExternalBoolHash | ExternalUint8Hash | ExternalUint16Hash | ExternalUint32Hash | ExternalUint64Hash | ExternalUint128Hash | ExternalAddressHash;
|
|
199
|
+
/**
|
|
200
|
+
* Maps a single EncryptableItem to its corresponding External*Hash type.
|
|
201
|
+
* Mirrors EncryptableToEncryptedItemInputMap.
|
|
202
|
+
*/
|
|
203
|
+
type EncryptableToExternalHashMap<E extends EncryptableItem> = E extends EncryptableBool ? ExternalBoolHash : E extends EncryptableUint8 ? ExternalUint8Hash : E extends EncryptableUint16 ? ExternalUint16Hash : E extends EncryptableUint32 ? ExternalUint32Hash : E extends EncryptableUint64 ? ExternalUint64Hash : E extends EncryptableUint128 ? ExternalUint128Hash : E extends EncryptableAddress ? ExternalAddressHash : never;
|
|
204
|
+
/**
|
|
205
|
+
* Maps an EncryptableItem[] tuple to a tuple of corresponding External*Hash types,
|
|
206
|
+
* preserving index positions. e.g. [EncryptableBool, EncryptableUint32] → [ExternalBoolHash, ExternalUint32Hash]
|
|
207
|
+
*/
|
|
208
|
+
type ExternalItemHashes<T extends EncryptableItem[]> = {
|
|
209
|
+
[K in keyof T]: T[K] extends EncryptableItem ? EncryptableToExternalHashMap<T[K]> : never;
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* Return type of EncryptInputsBuilder.execute() when asHashPlusProof() is set.
|
|
213
|
+
* Tuple of per-input hashes in input order, followed by a single proof blob.
|
|
214
|
+
* e.g. [Encryptable.bool(true), Encryptable.uint32(5)] → [ExternalBoolHash, ExternalUint32Hash, ExternalHashProof]
|
|
215
|
+
*/
|
|
216
|
+
type HashPlusProofResult<T extends EncryptableItem[]> = [...ExternalItemHashes<T>, ExternalHashProof];
|
|
168
217
|
type DecryptEndpoint = 'decrypt' | 'sealoutput';
|
|
169
218
|
type DecryptPollCallbackContext = {
|
|
170
219
|
operation: DecryptEndpoint;
|
|
@@ -702,10 +751,11 @@ type EncryptInputsBuilderParams<T extends EncryptableItem[]> = BaseBuilderParams
|
|
|
702
751
|
* account, securityZone, and chainId can be overridden in the builder.
|
|
703
752
|
* config, tfhePublicKeyDeserializer, compactPkeCrsDeserializer, and zkBuilderAndCrsGenerator are required to be set in the builder.
|
|
704
753
|
*/
|
|
705
|
-
declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuilder {
|
|
754
|
+
declare class EncryptInputsBuilder<T extends EncryptableItem[], HPP extends boolean = false> extends BaseBuilder {
|
|
706
755
|
private securityZone;
|
|
707
756
|
private stepCallback?;
|
|
708
757
|
private inputItems;
|
|
758
|
+
private hpp;
|
|
709
759
|
private zkvWalletClient;
|
|
710
760
|
private tfhePublicKeyDeserializer;
|
|
711
761
|
private compactPkeCrsDeserializer;
|
|
@@ -730,7 +780,7 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
|
|
|
730
780
|
*
|
|
731
781
|
* @returns The chainable EncryptInputsBuilder instance.
|
|
732
782
|
*/
|
|
733
|
-
setAccount(account: string): EncryptInputsBuilder<T>;
|
|
783
|
+
setAccount(account: string): EncryptInputsBuilder<T, HPP>;
|
|
734
784
|
getAccount(): string | undefined;
|
|
735
785
|
/**
|
|
736
786
|
* @param chainId - Chain that will consume the encrypted inputs.
|
|
@@ -746,7 +796,7 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
|
|
|
746
796
|
*
|
|
747
797
|
* @returns The chainable EncryptInputsBuilder instance.
|
|
748
798
|
*/
|
|
749
|
-
setChainId(chainId: number): EncryptInputsBuilder<T>;
|
|
799
|
+
setChainId(chainId: number): EncryptInputsBuilder<T, HPP>;
|
|
750
800
|
getChainId(): number | undefined;
|
|
751
801
|
/**
|
|
752
802
|
* @param securityZone - Security zone to encrypt the inputs for.
|
|
@@ -762,8 +812,19 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
|
|
|
762
812
|
*
|
|
763
813
|
* @returns The chainable EncryptInputsBuilder instance.
|
|
764
814
|
*/
|
|
765
|
-
setSecurityZone(securityZone: number): EncryptInputsBuilder<T>;
|
|
815
|
+
setSecurityZone(securityZone: number): EncryptInputsBuilder<T, HPP>;
|
|
766
816
|
getSecurityZone(): number;
|
|
817
|
+
/**
|
|
818
|
+
* Example:
|
|
819
|
+
* ```typescript
|
|
820
|
+
* const encrypted = await encryptInputs([Encryptable.uint128(10n)])
|
|
821
|
+
* .asHashPlusProof()
|
|
822
|
+
* .execute();
|
|
823
|
+
* ```
|
|
824
|
+
*
|
|
825
|
+
* @returns Chainable EncryptInputsBuilder instance that will return a HashPlusProofResult instead of an array of EncryptedItemInputs.
|
|
826
|
+
*/
|
|
827
|
+
asHashPlusProof(): EncryptInputsBuilder<T, true>;
|
|
767
828
|
/**
|
|
768
829
|
* @param useWorker - Whether to use Web Workers for ZK proof generation.
|
|
769
830
|
*
|
|
@@ -778,7 +839,7 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
|
|
|
778
839
|
*
|
|
779
840
|
* @returns The chainable EncryptInputsBuilder instance.
|
|
780
841
|
*/
|
|
781
|
-
setUseWorker(useWorker: boolean): EncryptInputsBuilder<T>;
|
|
842
|
+
setUseWorker(useWorker: boolean): EncryptInputsBuilder<T, HPP>;
|
|
782
843
|
/**
|
|
783
844
|
* Gets the current worker configuration.
|
|
784
845
|
*
|
|
@@ -808,7 +869,7 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
|
|
|
808
869
|
*
|
|
809
870
|
* @returns The EncryptInputsBuilder instance.
|
|
810
871
|
*/
|
|
811
|
-
onStep(callback: EncryptStepCallbackFunction): EncryptInputsBuilder<T>;
|
|
872
|
+
onStep(callback: EncryptStepCallbackFunction): EncryptInputsBuilder<T, HPP>;
|
|
812
873
|
getStepCallback(): EncryptStepCallbackFunction | undefined;
|
|
813
874
|
/**
|
|
814
875
|
* Fires the step callback if set
|
|
@@ -849,6 +910,7 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
|
|
|
849
910
|
* In the production context, perform a true encryption with the CoFHE coprocessor.
|
|
850
911
|
*/
|
|
851
912
|
private productionExecute;
|
|
913
|
+
private structsToHashPlusProof;
|
|
852
914
|
/**
|
|
853
915
|
* Final step of the encryption process. MUST BE CALLED LAST IN THE CHAIN.
|
|
854
916
|
*
|
|
@@ -868,7 +930,7 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
|
|
|
868
930
|
*
|
|
869
931
|
* @returns The encrypted inputs.
|
|
870
932
|
*/
|
|
871
|
-
execute(): Promise<[...EncryptedItemInputs<T>]>;
|
|
933
|
+
execute(): Promise<HPP extends true ? HashPlusProofResult<T> : [...EncryptedItemInputs<T>]>;
|
|
872
934
|
}
|
|
873
935
|
|
|
874
936
|
declare const permits: {
|
|
@@ -1001,4 +1063,4 @@ type CofheClientParams<TConfig extends CofheConfig> = {
|
|
|
1001
1063
|
zkProveWorkerFn?: ZkProveWorkerFunction;
|
|
1002
1064
|
};
|
|
1003
1065
|
|
|
1004
|
-
export {
|
|
1066
|
+
export { Encryptable as $, type FheTypeValue as A, type ExternalBoolHash as B, type CofheInputConfig as C, type ExternalUint8Hash as D, type EncryptableItem as E, FheTypes as F, type ExternalUint16Hash as G, type ExternalUint32Hash as H, type IStorage as I, type ExternalUint64Hash as J, type ExternalUint128Hash as K, type LiteralToPrimitive as L, type ExternalAddressHash as M, type ExternalHashProof as N, type AnyExternalHash as O, type Primitive as P, type EncryptableToExternalHashMap as Q, type ExternalItemHashes as R, type HashPlusProofResult as S, type DecryptPollCallbackFunction as T, type UnsealedItem as U, type DecryptPollCallbackContext as V, type DecryptEndpoint as W, type EncryptStepCallbackFunction as X, type EncryptStepCallbackContext as Y, FheUintUTypes as Z, FheAllUTypes as _, type CofheConfig as a, isEncryptableItem as a0, EncryptStep as a1, isLastEncryptionStep as a2, assertCorrectEncryptedItemInput as a3, fetchKeys as a4, type FheKeyDeserializer as a5, createKeysStore as a6, type KeysStorage as a7, type KeysStore as a8, EncryptInputsBuilder as a9, DecryptForViewBuilder as aa, DecryptForTxBuilder as ab, type DecryptForTxResult as ac, type ZkBuilderAndCrsGenerator as ad, type ZkProveWorkerFunction as ae, type ZkProveWorkerRequest as af, type ZkProveWorkerResponse as ag, zkProveWithWorker as ah, type CofheClient as b, type CofheClientParams as c, type CofheClientConnectionState as d, createCofheConfigBase as e, type CofheInternalConfig as f, getCofheConfigItem as g, type CofheClientPermits as h, type EncryptableBool as i, type EncryptableUint8 as j, type EncryptableUint16 as k, type EncryptableUint32 as l, type EncryptableUint64 as m, type EncryptableUint128 as n, type EncryptableAddress as o, type EncryptedNumber as p, type EncryptedItemInput as q, type EncryptedBoolInput as r, type EncryptedUint8Input as s, type EncryptedUint16Input as t, type EncryptedUint32Input as u, type EncryptedUint64Input as v, type EncryptedUint128Input as w, type EncryptedAddressInput as x, type EncryptedItemInputs as y, type EncryptableToEncryptedItemInputMap as z };
|