@cofhe/sdk 0.7.1 → 1.0.0-alpha.0
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 +35 -0
- package/acps/acp.ts +35 -7
- package/acps/index.ts +28 -12
- package/acps/onchain-utils.ts +188 -49
- package/acps/registry.ts +231 -0
- package/acps/sealing.ts +9 -3
- package/acps/share-metadata/appKey.ts +8 -0
- package/acps/share-metadata/decode.ts +120 -0
- package/acps/share-metadata/describe.ts +198 -0
- package/acps/share-metadata/encode.ts +147 -0
- package/acps/share-metadata/erc7984.ts +26 -0
- package/acps/share-metadata/index.ts +9 -0
- package/acps/share-metadata/layout.ts +69 -0
- package/acps/share-metadata/presets.ts +116 -0
- package/acps/share-metadata/schema.ts +47 -0
- package/acps/share-metadata/test/codec.test.ts +140 -0
- package/acps/share-metadata/test/describe.test.ts +112 -0
- package/acps/share-metadata/test/fixtures.ts +157 -0
- package/acps/share-metadata/test/live.test.ts +56 -0
- package/acps/share-metadata/test/presets.test.ts +119 -0
- package/acps/share-metadata/test/verify.test.ts +144 -0
- package/acps/share-metadata/verify.ts +155 -0
- package/acps/store.ts +48 -18
- package/acps/test/acp.test.ts +102 -7
- package/acps/test/localstorage.test.ts +28 -1
- package/acps/test/onchainAccessStatus.test.ts +116 -0
- package/acps/test/registry.test.ts +144 -0
- package/acps/test/sealing.test.ts +23 -0
- package/acps/test/store.test.ts +71 -0
- package/acps/test/utils.test.ts +63 -0
- package/acps/test/validation.test.ts +0 -4
- package/acps/types.ts +59 -6
- package/acps/utils.ts +15 -2
- package/acps/validation.ts +3 -1
- package/chains/chains/arbitrum.ts +14 -0
- package/chains/chains/ethereum.ts +14 -0
- package/chains/index.ts +5 -1
- package/chains/test/chains.test.ts +24 -3
- package/core/acps.ts +164 -207
- package/core/client.ts +44 -13
- package/core/clientTypes.ts +50 -7
- package/core/config.ts +33 -1
- package/core/consts.ts +14 -2
- package/core/decrypt/apiError.ts +4 -1
- package/core/decrypt/verifyDecryptResult.ts +8 -4
- package/core/encrypt/cofheMocksZkVerifySign.ts +19 -2
- package/core/encrypt/encryptInputsBuilder.ts +6 -0
- package/core/encrypt/zkPackProveVerify.ts +7 -1
- package/core/error.ts +1 -0
- package/core/fetchKeys.ts +2 -2
- package/core/index.ts +9 -1
- package/core/keyStore.ts +23 -10
- package/core/taskManager.ts +48 -0
- package/core/test/acpDefaults.test.ts +108 -19
- package/core/test/acpStoreAccountCase.test.ts +80 -0
- package/core/test/acps.test.ts +128 -3
- package/core/test/apiError.test.ts +8 -0
- package/core/test/appKeyConfig.test.ts +94 -0
- package/core/test/client.test.ts +41 -0
- package/core/test/config.test.ts +24 -0
- package/core/test/decrypt.test.ts +11 -4
- package/core/test/decryptBuilders.test.ts +110 -2
- package/core/test/encryptInputsBuilder.test.ts +1 -1
- package/core/test/fetchKeys.test.ts +23 -2
- package/core/test/incomingShares.test.ts +84 -0
- package/core/test/keyStore.test.ts +18 -6
- package/core/test/mocksEncryptRange.test.ts +90 -0
- package/core/test/taskManager.test.ts +57 -0
- package/core/test/utils.test.ts +128 -0
- package/core/test/verifyDecryptResult.test.ts +51 -0
- package/core/types.ts +8 -0
- package/core/utils.ts +16 -9
- package/dist/acps.cjs +984 -64
- package/dist/acps.d.cts +589 -10
- package/dist/acps.d.ts +589 -10
- package/dist/acps.js +2 -2
- package/dist/chains.cjs +26 -0
- package/dist/chains.d.cts +45 -1
- package/dist/chains.d.ts +45 -1
- package/dist/chains.js +1 -1
- package/dist/chunk-6ZW76ZKB.js +228 -0
- package/dist/chunk-BQWHPIYU.js +1828 -0
- package/dist/chunk-KSOV5B4B.js +50 -0
- package/dist/{chunk-43USWPEH.js → chunk-OL3DZN7A.js} +159 -523
- package/dist/{chunk-N6IDQRRU.js → chunk-UKQAJK4N.js} +25 -1
- package/dist/chunk-XQ32JG3T.js +174 -0
- package/dist/{clientTypes-CYZjFznO.d.cts → clientTypes-C0A9ji5O.d.cts} +132 -29
- package/dist/{clientTypes-BN3nbzYM.d.ts → clientTypes-CcU5WvdV.d.ts} +132 -29
- package/dist/core.cjs +3269 -2626
- package/dist/core.d.cts +32 -8
- package/dist/core.d.ts +32 -8
- package/dist/core.js +5 -4
- package/dist/node.cjs +3074 -2436
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.js +20 -19
- package/dist/{acp-Wi6isVQI.d.cts → onchain-utils-D9Z33IP7.d.cts} +166 -12
- package/dist/{acp-Wi6isVQI.d.ts → onchain-utils-D9Z33IP7.d.ts} +166 -12
- package/dist/web.cjs +3204 -2493
- package/dist/web.d.cts +49 -3
- package/dist/web.d.ts +49 -3
- package/dist/web.js +52 -27
- package/dist/zkProve.worker.cjs +79 -18
- package/dist/zkProve.worker.js +24 -24
- package/node/index.ts +1 -10
- package/node/storage.ts +20 -9
- package/node/test/inherited.test.ts +5 -1
- package/node/test/storage-memory-fallback.test.ts +47 -0
- package/node/test/storage-permissions.test.ts +40 -0
- package/package.json +3 -1
- package/web/index.ts +101 -36
- package/web/test/countingZkProveWorker.ts +31 -0
- package/web/test/inherited.web.test.ts +5 -1
- package/web/test/mainThreadPool.web.test.ts +174 -0
- package/web/test/threadPoolBenchHelper.ts +134 -0
- package/web/test/threadPoolOff.web.test.ts +17 -0
- package/web/test/threadPoolOn.web.test.ts +80 -0
- package/web/test/workerInitRace.web.test.ts +79 -0
- package/web/tfheThreadPool.ts +140 -0
- package/web/workerManager.ts +4 -2
- package/web/zkProve.worker.ts +42 -26
- package/dist/chunk-ESMZCFJY.js +0 -12
- package/dist/chunk-Q7CBWGQX.js +0 -1029
package/dist/acps.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { ACPScope, ACPUtils, ACP_STORE_DEFAULTS, GenerateSealingKey, ImportACPOptionsValidator, ImportACPValidator, SelfACPOptionsValidator, SelfACPValidator, SharingACPOptionsValidator, SharingACPValidator, SignatureTypes, SignatureUtils, ValidationUtils, _acpStore, acpStore, addressNotZeroSchema, addressSchema, bytesNotEmptySchema, bytesSchema, clearStaleStore, contractsSchema, getACP, getACPs, getActiveACP, getActiveACPHash, getSignatureTypesAndMessage, handlesSchema, removeACP, removeActiveACPHash, resetStore, seal, setACP, setActiveACPHash, unsealWithPrivateKey, validateImportACP, validateImportACPOptions, validateSelfACP, validateSelfACPOptions, validateSharingACP, validateSharingACPOptions } from './chunk-
|
|
2
|
-
import './chunk-
|
|
1
|
+
export { ACPScope, ACPUtils, ACP_REVOKER_ABI, ACP_SHARE_REGISTRY_ABI, ACP_SHARE_TUPLE_ABI, ACP_STORE_DEFAULTS, ERC7984_ABI, GenerateSealingKey, ImportACPOptionsValidator, ImportACPValidator, LAYOUT_VERSION as SHARE_METADATA_VERSION, SelfACPOptionsValidator, SelfACPValidator, SharingACPOptionsValidator, SharingACPValidator, SignatureTypes, SignatureUtils, UNLABELLED, ValidationUtils, _acpStore, acpStore, addressNotZeroSchema, addressSchema, bytesNotEmptySchema, bytesSchema, clearAclServedAddresses, clearStaleStore, computeShareId, contractsSchema, decodeShareAppKey, decodeShareMetadata, decodeShareMetadataFull, describeShareLabels, describeShareMetadata, encodeShareMetadata, eventLogLabel, getACP, getACPs, getAclAddress, getAclServedAddresses, getActiveACP, getActiveACPHash, getSignatureTypesAndMessage, handlesSchema, readPostedShares, readShare, readSharesFor, removeACP, removeActiveACPHash, resetStore, seal, setACP, setActiveACPHash, shareAppKey, shareIdOfChainShare, toChainShare, unsealWithPrivateKey, validateImportACP, validateImportACPOptions, validateSelfACP, validateSelfACPOptions, validateSharingACP, validateSharingACPOptions, verifyShareLabel, verifyShareLabels, viewFunctionLabel } from './chunk-BQWHPIYU.js';
|
|
2
|
+
import './chunk-XQ32JG3T.js';
|
package/dist/chains.cjs
CHANGED
|
@@ -61,6 +61,28 @@ var baseSepolia = defineChain({
|
|
|
61
61
|
environment: "TESTNET"
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
+
// chains/chains/ethereum.ts
|
|
65
|
+
var ethereum = defineChain({
|
|
66
|
+
id: 1,
|
|
67
|
+
name: "Ethereum",
|
|
68
|
+
network: "ethereum",
|
|
69
|
+
coFheUrl: "https://cofhe.mainnet.fhenix.zone",
|
|
70
|
+
verifierUrl: "https://cofhe-vrf.mainnet.fhenix.zone",
|
|
71
|
+
thresholdNetworkUrl: "https://cofhe-tn.mainnet.fhenix.zone",
|
|
72
|
+
environment: "MAINNET"
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// chains/chains/arbitrum.ts
|
|
76
|
+
var arbitrum = defineChain({
|
|
77
|
+
id: 42161,
|
|
78
|
+
name: "Arbitrum One",
|
|
79
|
+
network: "arbitrum",
|
|
80
|
+
coFheUrl: "https://cofhe.mainnet.fhenix.zone",
|
|
81
|
+
verifierUrl: "https://cofhe-vrf.mainnet.fhenix.zone",
|
|
82
|
+
thresholdNetworkUrl: "https://cofhe-tn.mainnet.fhenix.zone",
|
|
83
|
+
environment: "MAINNET"
|
|
84
|
+
});
|
|
85
|
+
|
|
64
86
|
// chains/chains/hardhat.ts
|
|
65
87
|
var hardhat = defineChain({
|
|
66
88
|
id: 31337,
|
|
@@ -100,6 +122,8 @@ var chains = {
|
|
|
100
122
|
sepolia,
|
|
101
123
|
arbSepolia,
|
|
102
124
|
baseSepolia,
|
|
125
|
+
ethereum,
|
|
126
|
+
arbitrum,
|
|
103
127
|
hardhat,
|
|
104
128
|
localcofhe,
|
|
105
129
|
stagingCofhe
|
|
@@ -114,8 +138,10 @@ var getChainByName = (name) => {
|
|
|
114
138
|
};
|
|
115
139
|
|
|
116
140
|
exports.arbSepolia = arbSepolia;
|
|
141
|
+
exports.arbitrum = arbitrum;
|
|
117
142
|
exports.baseSepolia = baseSepolia;
|
|
118
143
|
exports.chains = chains;
|
|
144
|
+
exports.ethereum = ethereum;
|
|
119
145
|
exports.getChainById = getChainById;
|
|
120
146
|
exports.getChainByName = getChainByName;
|
|
121
147
|
exports.hardhat = hardhat;
|
package/dist/chains.d.cts
CHANGED
|
@@ -41,6 +41,32 @@ declare const baseSepolia: {
|
|
|
41
41
|
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Ethereum mainnet chain configuration
|
|
46
|
+
*/
|
|
47
|
+
declare const ethereum: {
|
|
48
|
+
id: number;
|
|
49
|
+
name: string;
|
|
50
|
+
network: string;
|
|
51
|
+
coFheUrl: string;
|
|
52
|
+
verifierUrl: string;
|
|
53
|
+
thresholdNetworkUrl: string;
|
|
54
|
+
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Arbitrum One mainnet chain configuration
|
|
59
|
+
*/
|
|
60
|
+
declare const arbitrum: {
|
|
61
|
+
id: number;
|
|
62
|
+
name: string;
|
|
63
|
+
network: string;
|
|
64
|
+
coFheUrl: string;
|
|
65
|
+
verifierUrl: string;
|
|
66
|
+
thresholdNetworkUrl: string;
|
|
67
|
+
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
68
|
+
};
|
|
69
|
+
|
|
44
70
|
/**
|
|
45
71
|
* Hardhat local development chain configuration
|
|
46
72
|
*/
|
|
@@ -115,6 +141,24 @@ declare const chains: {
|
|
|
115
141
|
thresholdNetworkUrl: string;
|
|
116
142
|
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
117
143
|
};
|
|
144
|
+
readonly ethereum: {
|
|
145
|
+
id: number;
|
|
146
|
+
name: string;
|
|
147
|
+
network: string;
|
|
148
|
+
coFheUrl: string;
|
|
149
|
+
verifierUrl: string;
|
|
150
|
+
thresholdNetworkUrl: string;
|
|
151
|
+
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
152
|
+
};
|
|
153
|
+
readonly arbitrum: {
|
|
154
|
+
id: number;
|
|
155
|
+
name: string;
|
|
156
|
+
network: string;
|
|
157
|
+
coFheUrl: string;
|
|
158
|
+
verifierUrl: string;
|
|
159
|
+
thresholdNetworkUrl: string;
|
|
160
|
+
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
161
|
+
};
|
|
118
162
|
readonly hardhat: {
|
|
119
163
|
id: number;
|
|
120
164
|
name: string;
|
|
@@ -147,4 +191,4 @@ declare const chains: {
|
|
|
147
191
|
declare const getChainById: (chainId: number) => CofheChain | undefined;
|
|
148
192
|
declare const getChainByName: (name: string) => CofheChain | undefined;
|
|
149
193
|
|
|
150
|
-
export { CofheChain, arbSepolia, baseSepolia, chains, getChainById, getChainByName, hardhat, localcofhe, sepolia, stagingCofhe };
|
|
194
|
+
export { CofheChain, arbSepolia, arbitrum, baseSepolia, chains, ethereum, getChainById, getChainByName, hardhat, localcofhe, sepolia, stagingCofhe };
|
package/dist/chains.d.ts
CHANGED
|
@@ -41,6 +41,32 @@ declare const baseSepolia: {
|
|
|
41
41
|
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Ethereum mainnet chain configuration
|
|
46
|
+
*/
|
|
47
|
+
declare const ethereum: {
|
|
48
|
+
id: number;
|
|
49
|
+
name: string;
|
|
50
|
+
network: string;
|
|
51
|
+
coFheUrl: string;
|
|
52
|
+
verifierUrl: string;
|
|
53
|
+
thresholdNetworkUrl: string;
|
|
54
|
+
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Arbitrum One mainnet chain configuration
|
|
59
|
+
*/
|
|
60
|
+
declare const arbitrum: {
|
|
61
|
+
id: number;
|
|
62
|
+
name: string;
|
|
63
|
+
network: string;
|
|
64
|
+
coFheUrl: string;
|
|
65
|
+
verifierUrl: string;
|
|
66
|
+
thresholdNetworkUrl: string;
|
|
67
|
+
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
68
|
+
};
|
|
69
|
+
|
|
44
70
|
/**
|
|
45
71
|
* Hardhat local development chain configuration
|
|
46
72
|
*/
|
|
@@ -115,6 +141,24 @@ declare const chains: {
|
|
|
115
141
|
thresholdNetworkUrl: string;
|
|
116
142
|
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
117
143
|
};
|
|
144
|
+
readonly ethereum: {
|
|
145
|
+
id: number;
|
|
146
|
+
name: string;
|
|
147
|
+
network: string;
|
|
148
|
+
coFheUrl: string;
|
|
149
|
+
verifierUrl: string;
|
|
150
|
+
thresholdNetworkUrl: string;
|
|
151
|
+
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
152
|
+
};
|
|
153
|
+
readonly arbitrum: {
|
|
154
|
+
id: number;
|
|
155
|
+
name: string;
|
|
156
|
+
network: string;
|
|
157
|
+
coFheUrl: string;
|
|
158
|
+
verifierUrl: string;
|
|
159
|
+
thresholdNetworkUrl: string;
|
|
160
|
+
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
161
|
+
};
|
|
118
162
|
readonly hardhat: {
|
|
119
163
|
id: number;
|
|
120
164
|
name: string;
|
|
@@ -147,4 +191,4 @@ declare const chains: {
|
|
|
147
191
|
declare const getChainById: (chainId: number) => CofheChain | undefined;
|
|
148
192
|
declare const getChainByName: (name: string) => CofheChain | undefined;
|
|
149
193
|
|
|
150
|
-
export { CofheChain, arbSepolia, baseSepolia, chains, getChainById, getChainByName, hardhat, localcofhe, sepolia, stagingCofhe };
|
|
194
|
+
export { CofheChain, arbSepolia, arbitrum, baseSepolia, chains, ethereum, getChainById, getChainByName, hardhat, localcofhe, sepolia, stagingCofhe };
|
package/dist/chains.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { arbSepolia, baseSepolia, chains, getChainById, getChainByName, hardhat, localcofhe, sepolia, stagingCofhe } from './chunk-
|
|
1
|
+
export { arbSepolia, arbitrum, baseSepolia, chains, ethereum, getChainById, getChainByName, hardhat, localcofhe, sepolia, stagingCofhe } from './chunk-UKQAJK4N.js';
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { CofheError } from './chunk-XQ32JG3T.js';
|
|
2
|
+
import 'viem';
|
|
3
|
+
|
|
4
|
+
// core/types.ts
|
|
5
|
+
var FheTypes = /* @__PURE__ */ ((FheTypes2) => {
|
|
6
|
+
FheTypes2[FheTypes2["Bool"] = 0] = "Bool";
|
|
7
|
+
FheTypes2[FheTypes2["Uint4"] = 1] = "Uint4";
|
|
8
|
+
FheTypes2[FheTypes2["Uint8"] = 2] = "Uint8";
|
|
9
|
+
FheTypes2[FheTypes2["Uint16"] = 3] = "Uint16";
|
|
10
|
+
FheTypes2[FheTypes2["Uint32"] = 4] = "Uint32";
|
|
11
|
+
FheTypes2[FheTypes2["Uint64"] = 5] = "Uint64";
|
|
12
|
+
FheTypes2[FheTypes2["Uint128"] = 6] = "Uint128";
|
|
13
|
+
FheTypes2[FheTypes2["Uint160"] = 7] = "Uint160";
|
|
14
|
+
FheTypes2[FheTypes2["Uint256"] = 8] = "Uint256";
|
|
15
|
+
FheTypes2[FheTypes2["Uint512"] = 9] = "Uint512";
|
|
16
|
+
FheTypes2[FheTypes2["Uint1024"] = 10] = "Uint1024";
|
|
17
|
+
FheTypes2[FheTypes2["Uint2048"] = 11] = "Uint2048";
|
|
18
|
+
FheTypes2[FheTypes2["Uint2"] = 12] = "Uint2";
|
|
19
|
+
FheTypes2[FheTypes2["Uint6"] = 13] = "Uint6";
|
|
20
|
+
FheTypes2[FheTypes2["Uint10"] = 14] = "Uint10";
|
|
21
|
+
FheTypes2[FheTypes2["Uint12"] = 15] = "Uint12";
|
|
22
|
+
FheTypes2[FheTypes2["Uint14"] = 16] = "Uint14";
|
|
23
|
+
FheTypes2[FheTypes2["Int2"] = 17] = "Int2";
|
|
24
|
+
FheTypes2[FheTypes2["Int4"] = 18] = "Int4";
|
|
25
|
+
FheTypes2[FheTypes2["Int6"] = 19] = "Int6";
|
|
26
|
+
FheTypes2[FheTypes2["Int8"] = 20] = "Int8";
|
|
27
|
+
FheTypes2[FheTypes2["Int10"] = 21] = "Int10";
|
|
28
|
+
FheTypes2[FheTypes2["Int12"] = 22] = "Int12";
|
|
29
|
+
FheTypes2[FheTypes2["Int14"] = 23] = "Int14";
|
|
30
|
+
FheTypes2[FheTypes2["Int16"] = 24] = "Int16";
|
|
31
|
+
FheTypes2[FheTypes2["Int32"] = 25] = "Int32";
|
|
32
|
+
FheTypes2[FheTypes2["Int64"] = 26] = "Int64";
|
|
33
|
+
FheTypes2[FheTypes2["Int128"] = 27] = "Int128";
|
|
34
|
+
FheTypes2[FheTypes2["Int160"] = 28] = "Int160";
|
|
35
|
+
FheTypes2[FheTypes2["Int256"] = 29] = "Int256";
|
|
36
|
+
return FheTypes2;
|
|
37
|
+
})(FheTypes || {});
|
|
38
|
+
var FheUintUTypes = [
|
|
39
|
+
2 /* Uint8 */,
|
|
40
|
+
3 /* Uint16 */,
|
|
41
|
+
4 /* Uint32 */,
|
|
42
|
+
5 /* Uint64 */,
|
|
43
|
+
6 /* Uint128 */
|
|
44
|
+
// [U256-DISABLED]
|
|
45
|
+
// FheTypes.Uint256,
|
|
46
|
+
];
|
|
47
|
+
var FheAllUTypes = [
|
|
48
|
+
0 /* Bool */,
|
|
49
|
+
2 /* Uint8 */,
|
|
50
|
+
3 /* Uint16 */,
|
|
51
|
+
4 /* Uint32 */,
|
|
52
|
+
5 /* Uint64 */,
|
|
53
|
+
6 /* Uint128 */,
|
|
54
|
+
// [U256-DISABLED]
|
|
55
|
+
// FheTypes.Uint256,
|
|
56
|
+
7 /* Uint160 */
|
|
57
|
+
];
|
|
58
|
+
var EncryptableFactoriesImpl = {
|
|
59
|
+
bool: (data, securityZone = 0) => ({ data, securityZone, utype: 0 /* Bool */ }),
|
|
60
|
+
address: (data, securityZone = 0) => ({ data, securityZone, utype: 7 /* Uint160 */ }),
|
|
61
|
+
uint8: (data, securityZone = 0) => ({ data, securityZone, utype: 2 /* Uint8 */ }),
|
|
62
|
+
uint16: (data, securityZone = 0) => ({ data, securityZone, utype: 3 /* Uint16 */ }),
|
|
63
|
+
uint32: (data, securityZone = 0) => ({ data, securityZone, utype: 4 /* Uint32 */ }),
|
|
64
|
+
uint64: (data, securityZone = 0) => ({ data, securityZone, utype: 5 /* Uint64 */ }),
|
|
65
|
+
uint128: (data, securityZone = 0) => ({ data, securityZone, utype: 6 /* Uint128 */ })
|
|
66
|
+
// [U256-DISABLED]
|
|
67
|
+
// uint256: (data: EncryptableUint256['data'], securityZone = 0) =>
|
|
68
|
+
// ({ data, securityZone, utype: FheTypes.Uint256 }) as EncryptableUint256,
|
|
69
|
+
};
|
|
70
|
+
function createEncryptableByLiteral(type, data, securityZone = 0) {
|
|
71
|
+
switch (type) {
|
|
72
|
+
case "bool": {
|
|
73
|
+
if (typeof data !== "boolean")
|
|
74
|
+
throw new Error("Bool encryptable data must be boolean");
|
|
75
|
+
return EncryptableFactoriesImpl.bool(data, securityZone);
|
|
76
|
+
}
|
|
77
|
+
case "address":
|
|
78
|
+
case "uint8":
|
|
79
|
+
case "uint16":
|
|
80
|
+
case "uint32":
|
|
81
|
+
case "uint64":
|
|
82
|
+
case "uint128": {
|
|
83
|
+
if (typeof data === "boolean")
|
|
84
|
+
throw new Error("Uint encryptable data must be string or bigint");
|
|
85
|
+
return EncryptableFactoriesImpl[type](data, securityZone);
|
|
86
|
+
}
|
|
87
|
+
default: {
|
|
88
|
+
const _exhaustive = type;
|
|
89
|
+
throw new Error(`Unsupported encryptable type: ${_exhaustive}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
var Encryptable = {
|
|
94
|
+
...EncryptableFactoriesImpl,
|
|
95
|
+
create: createEncryptableByLiteral
|
|
96
|
+
};
|
|
97
|
+
function isEncryptableItem(value) {
|
|
98
|
+
return (
|
|
99
|
+
// Is object and exists
|
|
100
|
+
typeof value === "object" && value !== null && // Has securityZone
|
|
101
|
+
"securityZone" in value && typeof value.securityZone === "number" && // Has utype
|
|
102
|
+
"utype" in value && FheAllUTypes.includes(value.utype) && // Has data
|
|
103
|
+
"data" in value && ["string", "number", "bigint", "boolean"].includes(typeof value.data)
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
var EncryptStep = /* @__PURE__ */ ((EncryptStep2) => {
|
|
107
|
+
EncryptStep2["InitTfhe"] = "initTfhe";
|
|
108
|
+
EncryptStep2["FetchKeys"] = "fetchKeys";
|
|
109
|
+
EncryptStep2["Pack"] = "pack";
|
|
110
|
+
EncryptStep2["Prove"] = "prove";
|
|
111
|
+
EncryptStep2["Verify"] = "verify";
|
|
112
|
+
return EncryptStep2;
|
|
113
|
+
})(EncryptStep || {});
|
|
114
|
+
function isLastEncryptionStep(step) {
|
|
115
|
+
return step === "verify" /* Verify */;
|
|
116
|
+
}
|
|
117
|
+
var toHexString = (bytes) => bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
|
|
118
|
+
var HEX_BODY_REGEX = /^[0-9a-fA-F]*$/;
|
|
119
|
+
var fromHexString = (hexString) => {
|
|
120
|
+
const body = hexString.replace(/^0x/, "");
|
|
121
|
+
if (!HEX_BODY_REGEX.test(body)) {
|
|
122
|
+
throw new Error("Invalid hex string: contains non-hexadecimal characters");
|
|
123
|
+
}
|
|
124
|
+
const padded = body.length % 2 === 1 ? `0${body}` : body;
|
|
125
|
+
const arr = padded.match(/.{1,2}/g);
|
|
126
|
+
if (!arr)
|
|
127
|
+
return new Uint8Array();
|
|
128
|
+
return new Uint8Array(arr.map((byte) => parseInt(byte, 16)));
|
|
129
|
+
};
|
|
130
|
+
var toBigIntOrThrow = (value) => {
|
|
131
|
+
if (typeof value === "bigint") {
|
|
132
|
+
return value;
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
return BigInt(value);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
throw new Error("Invalid input: Unable to convert to bigint");
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
var validateBigIntInRange = (value, max, min = 0n) => {
|
|
141
|
+
if (typeof value !== "bigint") {
|
|
142
|
+
throw new Error("Value must be of type bigint");
|
|
143
|
+
}
|
|
144
|
+
if (value > max || value < min) {
|
|
145
|
+
throw new Error(`Value out of range: ${max} - ${min}, try a different uint type`);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
var hexToBytes = (hex) => fromHexString(hex);
|
|
149
|
+
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
150
|
+
async function getPublicClientChainID(publicClient) {
|
|
151
|
+
let chainId = null;
|
|
152
|
+
try {
|
|
153
|
+
chainId = publicClient.chain?.id ?? await publicClient.getChainId();
|
|
154
|
+
} catch (e) {
|
|
155
|
+
throw new CofheError({
|
|
156
|
+
code: "PUBLIC_WALLET_GET_CHAIN_ID_FAILED" /* PublicWalletGetChainIdFailed */,
|
|
157
|
+
message: "getting chain ID from public client failed",
|
|
158
|
+
cause: e instanceof Error ? e : void 0
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
if (chainId === null) {
|
|
162
|
+
throw new CofheError({
|
|
163
|
+
code: "PUBLIC_WALLET_GET_CHAIN_ID_FAILED" /* PublicWalletGetChainIdFailed */,
|
|
164
|
+
message: "chain ID from public client is null"
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return chainId;
|
|
168
|
+
}
|
|
169
|
+
async function getWalletClientAccount(walletClient) {
|
|
170
|
+
let address;
|
|
171
|
+
try {
|
|
172
|
+
address = walletClient.account?.address;
|
|
173
|
+
if (!address) {
|
|
174
|
+
address = (await walletClient.getAddresses())?.[0];
|
|
175
|
+
}
|
|
176
|
+
} catch (e) {
|
|
177
|
+
throw new CofheError({
|
|
178
|
+
code: "PUBLIC_WALLET_GET_ADDRESSES_FAILED" /* PublicWalletGetAddressesFailed */,
|
|
179
|
+
message: "getting address from wallet client failed",
|
|
180
|
+
cause: e instanceof Error ? e : void 0
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
if (!address) {
|
|
184
|
+
throw new CofheError({
|
|
185
|
+
code: "PUBLIC_WALLET_GET_ADDRESSES_FAILED" /* PublicWalletGetAddressesFailed */,
|
|
186
|
+
message: "address from wallet client is null"
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
return address;
|
|
190
|
+
}
|
|
191
|
+
function fheTypeToString(utype) {
|
|
192
|
+
switch (utype) {
|
|
193
|
+
case 0 /* Bool */:
|
|
194
|
+
return "bool";
|
|
195
|
+
case 1 /* Uint4 */:
|
|
196
|
+
return "uint4";
|
|
197
|
+
case 2 /* Uint8 */:
|
|
198
|
+
return "uint8";
|
|
199
|
+
case 3 /* Uint16 */:
|
|
200
|
+
return "uint16";
|
|
201
|
+
case 4 /* Uint32 */:
|
|
202
|
+
return "uint32";
|
|
203
|
+
case 5 /* Uint64 */:
|
|
204
|
+
return "uint64";
|
|
205
|
+
case 6 /* Uint128 */:
|
|
206
|
+
return "uint128";
|
|
207
|
+
case 7 /* Uint160 */:
|
|
208
|
+
return "uint160";
|
|
209
|
+
case 8 /* Uint256 */:
|
|
210
|
+
return "uint256";
|
|
211
|
+
case 9 /* Uint512 */:
|
|
212
|
+
return "uint512";
|
|
213
|
+
case 10 /* Uint1024 */:
|
|
214
|
+
return "uint1024";
|
|
215
|
+
case 11 /* Uint2048 */:
|
|
216
|
+
return "uint2048";
|
|
217
|
+
case 12 /* Uint2 */:
|
|
218
|
+
return "uint2";
|
|
219
|
+
case 13 /* Uint6 */:
|
|
220
|
+
return "uint6";
|
|
221
|
+
case 14 /* Uint10 */:
|
|
222
|
+
return "uint10";
|
|
223
|
+
default:
|
|
224
|
+
throw new Error(`Unknown FheType: ${utype}`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export { EncryptStep, Encryptable, FheAllUTypes, FheTypes, FheUintUTypes, fheTypeToString, fromHexString, getPublicClientChainID, getWalletClientAccount, hexToBytes, isEncryptableItem, isLastEncryptionStep, sleep, toBigIntOrThrow, toHexString, validateBigIntInRange };
|