@cofhe/sdk 0.1.1 → 0.2.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 +22 -0
- package/adapters/ethers6.ts +28 -28
- package/adapters/hardhat.ts +0 -1
- package/adapters/index.test.ts +14 -19
- package/adapters/smartWallet.ts +81 -73
- package/adapters/test-utils.ts +45 -45
- package/adapters/types.ts +3 -3
- package/chains/chains/localcofhe.ts +14 -0
- package/chains/chains.test.ts +2 -1
- package/chains/defineChain.ts +2 -2
- package/chains/index.ts +3 -1
- package/chains/types.ts +3 -3
- package/core/baseBuilder.ts +30 -49
- package/core/client.test.ts +200 -72
- package/core/client.ts +152 -148
- package/core/clientTypes.ts +114 -0
- package/core/config.test.ts +30 -11
- package/core/config.ts +26 -13
- package/core/consts.ts +18 -0
- package/core/decrypt/cofheMocksSealOutput.ts +2 -4
- package/core/decrypt/decryptHandleBuilder.ts +51 -45
- package/core/decrypt/{tnSealOutput.ts → tnSealOutputV1.ts} +1 -1
- package/core/decrypt/tnSealOutputV2.ts +298 -0
- package/core/encrypt/cofheMocksZkVerifySign.ts +15 -16
- package/core/encrypt/encryptInputsBuilder.test.ts +132 -116
- package/core/encrypt/encryptInputsBuilder.ts +159 -111
- package/core/encrypt/encryptUtils.ts +6 -3
- package/core/encrypt/zkPackProveVerify.ts +70 -8
- package/core/error.ts +0 -2
- package/core/fetchKeys.test.ts +1 -18
- package/core/fetchKeys.ts +0 -26
- package/core/index.ts +37 -17
- package/core/keyStore.ts +65 -38
- package/core/permits.test.ts +255 -4
- package/core/permits.ts +83 -18
- package/core/types.ts +198 -152
- package/core/utils.ts +43 -1
- package/dist/adapters.d.cts +38 -20
- package/dist/adapters.d.ts +38 -20
- package/dist/chains.cjs +18 -8
- package/dist/chains.d.cts +31 -9
- package/dist/chains.d.ts +31 -9
- package/dist/chains.js +1 -1
- package/dist/{chunk-KFGPTJ6X.js → chunk-I5WFEYXX.js} +1768 -1526
- package/dist/{chunk-LU7BMUUT.js → chunk-R3B5TMVX.js} +330 -197
- package/dist/{chunk-GZCQQYVI.js → chunk-TBLR7NNE.js} +18 -9
- package/dist/{types-PhwGgQvs.d.ts → clientTypes-RqkgkV2i.d.ts} +331 -429
- package/dist/{types-bB7wLj0q.d.cts → clientTypes-e4filDzK.d.cts} +331 -429
- package/dist/core.cjs +3000 -2625
- package/dist/core.d.cts +113 -7
- package/dist/core.d.ts +113 -7
- package/dist/core.js +3 -3
- package/dist/node.cjs +2851 -2526
- package/dist/node.d.cts +4 -4
- package/dist/node.d.ts +4 -4
- package/dist/node.js +4 -3
- package/dist/{permit-S9CnI6MF.d.cts → permit-MZ502UBl.d.cts} +54 -41
- package/dist/{permit-S9CnI6MF.d.ts → permit-MZ502UBl.d.ts} +54 -41
- package/dist/permits.cjs +328 -195
- package/dist/permits.d.cts +113 -825
- package/dist/permits.d.ts +113 -825
- package/dist/permits.js +1 -1
- package/dist/types-YiAC4gig.d.cts +33 -0
- package/dist/types-YiAC4gig.d.ts +33 -0
- package/dist/web.cjs +3067 -2527
- package/dist/web.d.cts +22 -6
- package/dist/web.d.ts +22 -6
- package/dist/web.js +185 -9
- package/dist/zkProve.worker.cjs +93 -0
- package/dist/zkProve.worker.d.cts +2 -0
- package/dist/zkProve.worker.d.ts +2 -0
- package/dist/zkProve.worker.js +91 -0
- package/node/client.test.ts +20 -25
- package/node/encryptInputs.test.ts +18 -38
- package/node/index.ts +1 -0
- package/package.json +15 -15
- package/permits/index.ts +1 -0
- package/permits/localstorage.test.ts +9 -14
- package/permits/onchain-utils.ts +221 -0
- package/permits/permit.test.ts +76 -27
- package/permits/permit.ts +58 -95
- package/permits/sealing.test.ts +3 -3
- package/permits/sealing.ts +2 -2
- package/permits/store.test.ts +10 -50
- package/permits/store.ts +9 -21
- package/permits/test-utils.ts +11 -3
- package/permits/types.ts +39 -9
- package/permits/utils.ts +0 -5
- package/permits/validation.test.ts +29 -32
- package/permits/validation.ts +114 -176
- package/web/client.web.test.ts +20 -25
- package/web/config.web.test.ts +0 -2
- package/web/encryptInputs.web.test.ts +31 -54
- package/web/index.ts +65 -1
- package/web/storage.ts +19 -5
- package/web/worker.builder.web.test.ts +148 -0
- package/web/worker.config.web.test.ts +329 -0
- package/web/worker.output.web.test.ts +84 -0
- package/web/workerManager.test.ts +80 -0
- package/web/workerManager.ts +214 -0
- package/web/workerManager.web.test.ts +114 -0
- package/web/zkProve.worker.ts +133 -0
- package/core/result.test.ts +0 -180
- package/core/result.ts +0 -67
- package/core/test-utils.ts +0 -45
- package/dist/types-KImPrEIe.d.cts +0 -48
- package/dist/types-KImPrEIe.d.ts +0 -48
|
@@ -1,21 +1,180 @@
|
|
|
1
|
-
import { P as Permit, S as SerializedPermit, C as CreateSelfPermitOptions, d as CreateSharingPermitOptions, I as ImportSharedPermitOptions, g as PermitUtils } from './permit-S9CnI6MF.cjs';
|
|
2
1
|
import { WalletClient, PublicClient } from 'viem';
|
|
3
|
-
import { C as CofheChain } from './types-
|
|
2
|
+
import { C as CofheChain } from './types-YiAC4gig.cjs';
|
|
4
3
|
import { z } from 'zod';
|
|
4
|
+
import { P as Permit, S as SerializedPermit, C as CreateSelfPermitOptions, m as SelfPermit, d as CreateSharingPermitOptions, n as SharingPermit, I as ImportSharedPermitOptions, R as RecipientPermit, o as PermitHashFields, g as PermitUtils } from './permit-MZ502UBl.cjs';
|
|
5
5
|
import { StoreApi } from 'zustand/vanilla';
|
|
6
6
|
|
|
7
|
+
type TfheInitializer = () => Promise<boolean>;
|
|
8
|
+
interface IStorage {
|
|
9
|
+
getItem: (name: string) => Promise<any>;
|
|
10
|
+
setItem: (name: string, value: any) => Promise<void>;
|
|
11
|
+
removeItem: (name: string) => Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
14
|
+
type LiteralToPrimitive<T> = T extends number ? number : T extends bigint ? bigint : T extends string ? string : T extends boolean ? boolean : T extends symbol ? symbol : T extends null ? null : T extends undefined ? undefined : never;
|
|
15
|
+
declare const FheTypeValues: readonly ["bool", "uint8", "uint16", "uint32", "uint64", "uint128", "address"];
|
|
16
|
+
type FheTypeValue = (typeof FheTypeValues)[number];
|
|
17
|
+
declare enum FheTypes {
|
|
18
|
+
Bool = 0,
|
|
19
|
+
Uint4 = 1,
|
|
20
|
+
Uint8 = 2,
|
|
21
|
+
Uint16 = 3,
|
|
22
|
+
Uint32 = 4,
|
|
23
|
+
Uint64 = 5,
|
|
24
|
+
Uint128 = 6,
|
|
25
|
+
Uint160 = 7,
|
|
26
|
+
Uint256 = 8,
|
|
27
|
+
Uint512 = 9,
|
|
28
|
+
Uint1024 = 10,
|
|
29
|
+
Uint2048 = 11,
|
|
30
|
+
Uint2 = 12,
|
|
31
|
+
Uint6 = 13,
|
|
32
|
+
Uint10 = 14,
|
|
33
|
+
Uint12 = 15,
|
|
34
|
+
Uint14 = 16,
|
|
35
|
+
Int2 = 17,
|
|
36
|
+
Int4 = 18,
|
|
37
|
+
Int6 = 19,
|
|
38
|
+
Int8 = 20,
|
|
39
|
+
Int10 = 21,
|
|
40
|
+
Int12 = 22,
|
|
41
|
+
Int14 = 23,
|
|
42
|
+
Int16 = 24,
|
|
43
|
+
Int32 = 25,
|
|
44
|
+
Int64 = 26,
|
|
45
|
+
Int128 = 27,
|
|
46
|
+
Int160 = 28,
|
|
47
|
+
Int256 = 29
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* List of All FHE uint types (excludes bool and address)
|
|
51
|
+
*/
|
|
52
|
+
declare const FheUintUTypes: readonly [FheTypes.Uint8, FheTypes.Uint16, FheTypes.Uint32, FheTypes.Uint64, FheTypes.Uint128];
|
|
53
|
+
type FheUintUTypesType = (typeof FheUintUTypes)[number];
|
|
54
|
+
/**
|
|
55
|
+
* List of All FHE types (uints, bool, and address)
|
|
56
|
+
*/
|
|
57
|
+
declare const FheAllUTypes: readonly [FheTypes.Bool, FheTypes.Uint8, FheTypes.Uint16, FheTypes.Uint32, FheTypes.Uint64, FheTypes.Uint128, FheTypes.Uint160];
|
|
58
|
+
type EncryptedNumber = {
|
|
59
|
+
data: Uint8Array;
|
|
60
|
+
securityZone: number;
|
|
61
|
+
};
|
|
62
|
+
type EncryptedItemInput<TSignature = string> = {
|
|
63
|
+
ctHash: bigint;
|
|
64
|
+
securityZone: number;
|
|
65
|
+
utype: FheTypes;
|
|
66
|
+
signature: TSignature;
|
|
67
|
+
};
|
|
68
|
+
declare function assertCorrectEncryptedItemInput(input: EncryptedItemInput): asserts input is EncryptedItemInput<`0x${string}`>;
|
|
69
|
+
type EncryptedBoolInput = EncryptedItemInput & {
|
|
70
|
+
utype: FheTypes.Bool;
|
|
71
|
+
};
|
|
72
|
+
type EncryptedUint8Input = EncryptedItemInput & {
|
|
73
|
+
utype: FheTypes.Uint8;
|
|
74
|
+
};
|
|
75
|
+
type EncryptedUint16Input = EncryptedItemInput & {
|
|
76
|
+
utype: FheTypes.Uint16;
|
|
77
|
+
};
|
|
78
|
+
type EncryptedUint32Input = EncryptedItemInput & {
|
|
79
|
+
utype: FheTypes.Uint32;
|
|
80
|
+
};
|
|
81
|
+
type EncryptedUint64Input = EncryptedItemInput & {
|
|
82
|
+
utype: FheTypes.Uint64;
|
|
83
|
+
};
|
|
84
|
+
type EncryptedUint128Input = EncryptedItemInput & {
|
|
85
|
+
utype: FheTypes.Uint128;
|
|
86
|
+
};
|
|
87
|
+
type EncryptedAddressInput = EncryptedItemInput & {
|
|
88
|
+
utype: FheTypes.Uint160;
|
|
89
|
+
};
|
|
90
|
+
type EncryptableBase<U extends FheTypes, D> = {
|
|
91
|
+
data: D;
|
|
92
|
+
securityZone: number;
|
|
93
|
+
utype: U;
|
|
94
|
+
};
|
|
95
|
+
type EncryptableBool = EncryptableBase<FheTypes.Bool, boolean>;
|
|
96
|
+
type EncryptableUint8 = EncryptableBase<FheTypes.Uint8, string | bigint>;
|
|
97
|
+
type EncryptableUint16 = EncryptableBase<FheTypes.Uint16, string | bigint>;
|
|
98
|
+
type EncryptableUint32 = EncryptableBase<FheTypes.Uint32, string | bigint>;
|
|
99
|
+
type EncryptableUint64 = EncryptableBase<FheTypes.Uint64, string | bigint>;
|
|
100
|
+
type EncryptableUint128 = EncryptableBase<FheTypes.Uint128, string | bigint>;
|
|
101
|
+
type EncryptableAddress = EncryptableBase<FheTypes.Uint160, string | bigint>;
|
|
102
|
+
declare function createEncryptableByLiteral(type: 'bool', data: EncryptableBool['data'], securityZone?: number): EncryptableBool;
|
|
103
|
+
declare function createEncryptableByLiteral(type: 'address', data: EncryptableAddress['data'], securityZone?: number): EncryptableAddress;
|
|
104
|
+
declare function createEncryptableByLiteral(type: 'uint8', data: EncryptableUint8['data'], securityZone?: number): EncryptableUint8;
|
|
105
|
+
declare function createEncryptableByLiteral(type: 'uint16', data: EncryptableUint16['data'], securityZone?: number): EncryptableUint16;
|
|
106
|
+
declare function createEncryptableByLiteral(type: 'uint32', data: EncryptableUint32['data'], securityZone?: number): EncryptableUint32;
|
|
107
|
+
declare function createEncryptableByLiteral(type: 'uint64', data: EncryptableUint64['data'], securityZone?: number): EncryptableUint64;
|
|
108
|
+
declare function createEncryptableByLiteral(type: 'uint128', data: EncryptableUint128['data'], securityZone?: number): EncryptableUint128;
|
|
109
|
+
declare function createEncryptableByLiteral(type: FheTypeValue, data: EncryptableItem['data'], securityZone?: number): EncryptableItem;
|
|
110
|
+
declare const Encryptable: {
|
|
111
|
+
create: typeof createEncryptableByLiteral;
|
|
112
|
+
bool: (data: EncryptableBool["data"], securityZone?: number | undefined) => {
|
|
113
|
+
data: boolean;
|
|
114
|
+
securityZone: number;
|
|
115
|
+
utype: FheTypes.Bool;
|
|
116
|
+
};
|
|
117
|
+
address: (data: EncryptableAddress["data"], securityZone?: number | undefined) => {
|
|
118
|
+
data: string | bigint;
|
|
119
|
+
securityZone: number;
|
|
120
|
+
utype: FheTypes.Uint160;
|
|
121
|
+
};
|
|
122
|
+
uint8: (data: EncryptableUint8["data"], securityZone?: number | undefined) => {
|
|
123
|
+
data: string | bigint;
|
|
124
|
+
securityZone: number;
|
|
125
|
+
utype: FheTypes.Uint8;
|
|
126
|
+
};
|
|
127
|
+
uint16: (data: EncryptableUint16["data"], securityZone?: number | undefined) => {
|
|
128
|
+
data: string | bigint;
|
|
129
|
+
securityZone: number;
|
|
130
|
+
utype: FheTypes.Uint16;
|
|
131
|
+
};
|
|
132
|
+
uint32: (data: EncryptableUint32["data"], securityZone?: number | undefined) => {
|
|
133
|
+
data: string | bigint;
|
|
134
|
+
securityZone: number;
|
|
135
|
+
utype: FheTypes.Uint32;
|
|
136
|
+
};
|
|
137
|
+
uint64: (data: EncryptableUint64["data"], securityZone?: number | undefined) => {
|
|
138
|
+
data: string | bigint;
|
|
139
|
+
securityZone: number;
|
|
140
|
+
utype: FheTypes.Uint64;
|
|
141
|
+
};
|
|
142
|
+
uint128: (data: EncryptableUint128["data"], securityZone?: number | undefined) => {
|
|
143
|
+
data: string | bigint;
|
|
144
|
+
securityZone: number;
|
|
145
|
+
utype: FheTypes.Uint128;
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
type EncryptableItem = EncryptableBool | EncryptableUint8 | EncryptableUint16 | EncryptableUint32 | EncryptableUint64 | EncryptableUint128 | EncryptableAddress;
|
|
149
|
+
type EncryptableToEncryptedItemInputMap<E extends EncryptableItem> = E extends EncryptableBool ? EncryptedBoolInput : E extends EncryptableUint8 ? EncryptedUint8Input : E extends EncryptableUint16 ? EncryptedUint16Input : E extends EncryptableUint32 ? EncryptedUint32Input : E extends EncryptableUint64 ? EncryptedUint64Input : E extends EncryptableUint128 ? EncryptedUint128Input : E extends EncryptableAddress ? EncryptedAddressInput : never;
|
|
150
|
+
type EncryptedItemInputs<T> = T extends Primitive ? LiteralToPrimitive<T> : T extends EncryptableItem ? EncryptableToEncryptedItemInputMap<T> : {
|
|
151
|
+
[K in keyof T]: EncryptedItemInputs<T[K]>;
|
|
152
|
+
};
|
|
153
|
+
declare function isEncryptableItem(value: unknown): value is EncryptableItem;
|
|
154
|
+
declare enum EncryptStep {
|
|
155
|
+
InitTfhe = "initTfhe",
|
|
156
|
+
FetchKeys = "fetchKeys",
|
|
157
|
+
Pack = "pack",
|
|
158
|
+
Prove = "prove",
|
|
159
|
+
Verify = "verify"
|
|
160
|
+
}
|
|
161
|
+
declare function isLastEncryptionStep(step: EncryptStep): boolean;
|
|
162
|
+
type EncryptStepCallbackContext = Record<string, any> & {
|
|
163
|
+
isStart: boolean;
|
|
164
|
+
isEnd: boolean;
|
|
165
|
+
duration: number;
|
|
166
|
+
};
|
|
167
|
+
type EncryptStepCallbackFunction = (state: EncryptStep, context?: EncryptStepCallbackContext) => void;
|
|
168
|
+
type UnsealedItem<U extends FheTypes> = U extends FheTypes.Bool ? boolean : U extends FheTypes.Uint160 ? string : U extends FheUintUTypesType ? bigint : never;
|
|
169
|
+
|
|
7
170
|
/**
|
|
8
171
|
* Usable config type inferred from the schema
|
|
9
172
|
*/
|
|
10
173
|
type CofhesdkConfig = {
|
|
174
|
+
/** Environment that the SDK is running in */
|
|
175
|
+
environment: 'node' | 'hardhat' | 'web' | 'react';
|
|
176
|
+
/** List of supported chains */
|
|
11
177
|
supportedChains: CofheChain[];
|
|
12
|
-
/**
|
|
13
|
-
* Strategy for fetching FHE keys
|
|
14
|
-
* - CONNECTED_CHAIN: Fetch keys for the connected chain (provided by the publicClient)
|
|
15
|
-
* - SUPPORTED_CHAINS: Fetch keys for all supported chains (provided by the supportedChains config)
|
|
16
|
-
* - OFF: Do not fetch keys (fetching occurs during encryptInputs)
|
|
17
|
-
* */
|
|
18
|
-
fheKeysPrefetching: 'CONNECTED_CHAIN' | 'SUPPORTED_CHAINS' | 'OFF';
|
|
19
178
|
/**
|
|
20
179
|
* How permits are generated
|
|
21
180
|
* - ON_CONNECT: Generate a permit when client.connect() is called
|
|
@@ -31,6 +190,12 @@ type CofhesdkConfig = {
|
|
|
31
190
|
* (defaults to indexedDB on web, filesystem on node)
|
|
32
191
|
*/
|
|
33
192
|
fheKeyStorage: IStorage | null;
|
|
193
|
+
/**
|
|
194
|
+
* Whether to use Web Workers for ZK proof generation (web platform only)
|
|
195
|
+
* When enabled, heavy WASM computation is offloaded to prevent UI freezing
|
|
196
|
+
* Default: true
|
|
197
|
+
*/
|
|
198
|
+
useWorkers: boolean;
|
|
34
199
|
/** Mocks configs */
|
|
35
200
|
mocks: {
|
|
36
201
|
/**
|
|
@@ -49,109 +214,48 @@ type CofhesdkInternalConfig = {
|
|
|
49
214
|
* Zod schema for configuration validation
|
|
50
215
|
*/
|
|
51
216
|
declare const CofhesdkConfigSchema: z.ZodObject<{
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
217
|
+
environment: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
218
|
+
hardhat: "hardhat";
|
|
219
|
+
node: "node";
|
|
220
|
+
web: "web";
|
|
221
|
+
react: "react";
|
|
222
|
+
}>>>;
|
|
223
|
+
supportedChains: z.ZodArray<z.ZodCustom<{
|
|
55
224
|
id: number;
|
|
225
|
+
name: string;
|
|
56
226
|
network: string;
|
|
57
227
|
coFheUrl: string;
|
|
58
228
|
verifierUrl: string;
|
|
59
229
|
thresholdNetworkUrl: string;
|
|
60
230
|
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
61
|
-
},
|
|
62
|
-
name: string;
|
|
231
|
+
}, {
|
|
63
232
|
id: number;
|
|
233
|
+
name: string;
|
|
64
234
|
network: string;
|
|
65
235
|
coFheUrl: string;
|
|
66
236
|
verifierUrl: string;
|
|
67
237
|
thresholdNetworkUrl: string;
|
|
68
238
|
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
239
|
+
}>>;
|
|
240
|
+
permitGeneration: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
241
|
+
ON_CONNECT: "ON_CONNECT";
|
|
242
|
+
ON_DECRYPT_HANDLES: "ON_DECRYPT_HANDLES";
|
|
243
|
+
MANUAL: "MANUAL";
|
|
244
|
+
}>>>;
|
|
75
245
|
defaultPermitExpiration: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
76
|
-
/** Storage method for fhe keys (defaults to indexedDB on web, filesystem on node) */
|
|
77
246
|
fheKeyStorage: z.ZodDefault<z.ZodUnion<[z.ZodObject<{
|
|
78
|
-
getItem: z.
|
|
79
|
-
setItem: z.
|
|
80
|
-
removeItem: z.
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
setItem: (args_0: string, args_1: any, ...args_2: unknown[]) => Promise<void>;
|
|
84
|
-
removeItem: (args_0: string, ...args_1: unknown[]) => Promise<void>;
|
|
85
|
-
}, {
|
|
86
|
-
getItem: (args_0: string, ...args_1: unknown[]) => Promise<any>;
|
|
87
|
-
setItem: (args_0: string, args_1: any, ...args_2: unknown[]) => Promise<void>;
|
|
88
|
-
removeItem: (args_0: string, ...args_1: unknown[]) => Promise<void>;
|
|
89
|
-
}>, z.ZodNull]>>;
|
|
90
|
-
/** Mocks configs */
|
|
247
|
+
getItem: z.ZodCustom<(name: string) => Promise<any>, (name: string) => Promise<any>>;
|
|
248
|
+
setItem: z.ZodCustom<(name: string, value: any) => Promise<void>, (name: string, value: any) => Promise<void>>;
|
|
249
|
+
removeItem: z.ZodCustom<(name: string) => Promise<void>, (name: string) => Promise<void>>;
|
|
250
|
+
}, z.core.$strip>, z.ZodNull]>>;
|
|
251
|
+
useWorkers: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
91
252
|
mocks: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
92
253
|
sealOutputDelay: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
93
|
-
},
|
|
94
|
-
sealOutputDelay: number;
|
|
95
|
-
}, {
|
|
96
|
-
sealOutputDelay?: number | undefined;
|
|
97
|
-
}>>>;
|
|
98
|
-
/** Internal configuration */
|
|
254
|
+
}, z.core.$strip>>>;
|
|
99
255
|
_internal: z.ZodOptional<z.ZodObject<{
|
|
100
256
|
zkvWalletClient: z.ZodOptional<z.ZodAny>;
|
|
101
|
-
},
|
|
102
|
-
|
|
103
|
-
}, {
|
|
104
|
-
zkvWalletClient?: any;
|
|
105
|
-
}>>;
|
|
106
|
-
}, "strip", z.ZodTypeAny, {
|
|
107
|
-
supportedChains: {
|
|
108
|
-
name: string;
|
|
109
|
-
id: number;
|
|
110
|
-
network: string;
|
|
111
|
-
coFheUrl: string;
|
|
112
|
-
verifierUrl: string;
|
|
113
|
-
thresholdNetworkUrl: string;
|
|
114
|
-
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
115
|
-
}[];
|
|
116
|
-
fheKeysPrefetching: "CONNECTED_CHAIN" | "SUPPORTED_CHAINS" | "OFF";
|
|
117
|
-
permitGeneration: "ON_CONNECT" | "ON_DECRYPT_HANDLES" | "MANUAL";
|
|
118
|
-
defaultPermitExpiration: number;
|
|
119
|
-
fheKeyStorage: {
|
|
120
|
-
getItem: (args_0: string, ...args_1: unknown[]) => Promise<any>;
|
|
121
|
-
setItem: (args_0: string, args_1: any, ...args_2: unknown[]) => Promise<void>;
|
|
122
|
-
removeItem: (args_0: string, ...args_1: unknown[]) => Promise<void>;
|
|
123
|
-
} | null;
|
|
124
|
-
mocks: {
|
|
125
|
-
sealOutputDelay: number;
|
|
126
|
-
};
|
|
127
|
-
_internal?: {
|
|
128
|
-
zkvWalletClient?: any;
|
|
129
|
-
} | undefined;
|
|
130
|
-
}, {
|
|
131
|
-
supportedChains: {
|
|
132
|
-
name: string;
|
|
133
|
-
id: number;
|
|
134
|
-
network: string;
|
|
135
|
-
coFheUrl: string;
|
|
136
|
-
verifierUrl: string;
|
|
137
|
-
thresholdNetworkUrl: string;
|
|
138
|
-
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
139
|
-
}[];
|
|
140
|
-
fheKeysPrefetching?: "CONNECTED_CHAIN" | "SUPPORTED_CHAINS" | "OFF" | undefined;
|
|
141
|
-
permitGeneration?: "ON_CONNECT" | "ON_DECRYPT_HANDLES" | "MANUAL" | undefined;
|
|
142
|
-
defaultPermitExpiration?: number | undefined;
|
|
143
|
-
fheKeyStorage?: {
|
|
144
|
-
getItem: (args_0: string, ...args_1: unknown[]) => Promise<any>;
|
|
145
|
-
setItem: (args_0: string, args_1: any, ...args_2: unknown[]) => Promise<void>;
|
|
146
|
-
removeItem: (args_0: string, ...args_1: unknown[]) => Promise<void>;
|
|
147
|
-
} | null | undefined;
|
|
148
|
-
mocks?: {
|
|
149
|
-
sealOutputDelay?: number | undefined;
|
|
150
|
-
} | undefined;
|
|
151
|
-
_internal?: {
|
|
152
|
-
zkvWalletClient?: any;
|
|
153
|
-
} | undefined;
|
|
154
|
-
}>;
|
|
257
|
+
}, z.core.$strip>>;
|
|
258
|
+
}, z.core.$strip>;
|
|
155
259
|
/**
|
|
156
260
|
* Input config type inferred from the schema
|
|
157
261
|
*/
|
|
@@ -169,109 +273,6 @@ declare function createCofhesdkConfigBase(config: CofhesdkInputConfig): Cofhesdk
|
|
|
169
273
|
*/
|
|
170
274
|
declare const getCofhesdkConfigItem: <K extends keyof CofhesdkConfig>(config: CofhesdkConfig, key: K) => CofhesdkConfig[K];
|
|
171
275
|
|
|
172
|
-
declare enum CofhesdkErrorCode {
|
|
173
|
-
InternalError = "INTERNAL_ERROR",
|
|
174
|
-
UnknownEnvironment = "UNKNOWN_ENVIRONMENT",
|
|
175
|
-
InitTfheFailed = "INIT_TFHE_FAILED",
|
|
176
|
-
InitViemFailed = "INIT_VIEM_FAILED",
|
|
177
|
-
InitEthersFailed = "INIT_ETHERS_FAILED",
|
|
178
|
-
NotConnected = "NOT_CONNECTED",
|
|
179
|
-
MissingPublicClient = "MISSING_PUBLIC_CLIENT",
|
|
180
|
-
MissingWalletClient = "MISSING_WALLET_CLIENT",
|
|
181
|
-
MissingProviderParam = "MISSING_PROVIDER_PARAM",
|
|
182
|
-
EmptySecurityZonesParam = "EMPTY_SECURITY_ZONES_PARAM",
|
|
183
|
-
InvalidPermitData = "INVALID_PERMIT_DATA",
|
|
184
|
-
InvalidPermitDomain = "INVALID_PERMIT_DOMAIN",
|
|
185
|
-
PermitNotFound = "PERMIT_NOT_FOUND",
|
|
186
|
-
CannotRemoveLastPermit = "CANNOT_REMOVE_LAST_PERMIT",
|
|
187
|
-
AccountUninitialized = "ACCOUNT_UNINITIALIZED",
|
|
188
|
-
ChainIdUninitialized = "CHAIN_ID_UNINITIALIZED",
|
|
189
|
-
SealOutputFailed = "SEAL_OUTPUT_FAILED",
|
|
190
|
-
SealOutputReturnedNull = "SEAL_OUTPUT_RETURNED_NULL",
|
|
191
|
-
InvalidUtype = "INVALID_UTYPE",
|
|
192
|
-
DecryptFailed = "DECRYPT_FAILED",
|
|
193
|
-
DecryptReturnedNull = "DECRYPT_RETURNED_NULL",
|
|
194
|
-
ZkMocksInsertCtHashesFailed = "ZK_MOCKS_INSERT_CT_HASHES_FAILED",
|
|
195
|
-
ZkMocksCalcCtHashesFailed = "ZK_MOCKS_CALC_CT_HASHES_FAILED",
|
|
196
|
-
ZkMocksVerifySignFailed = "ZK_MOCKS_VERIFY_SIGN_FAILED",
|
|
197
|
-
ZkMocksCreateProofSignatureFailed = "ZK_MOCKS_CREATE_PROOF_SIGNATURE_FAILED",
|
|
198
|
-
ZkVerifyFailed = "ZK_VERIFY_FAILED",
|
|
199
|
-
ZkPackFailed = "ZK_PACK_FAILED",
|
|
200
|
-
ZkProveFailed = "ZK_PROVE_FAILED",
|
|
201
|
-
EncryptRemainingInItems = "ENCRYPT_REMAINING_IN_ITEMS",
|
|
202
|
-
ZkUninitialized = "ZK_UNINITIALIZED",
|
|
203
|
-
ZkVerifierUrlUninitialized = "ZK_VERIFIER_URL_UNINITIALIZED",
|
|
204
|
-
ThresholdNetworkUrlUninitialized = "THRESHOLD_NETWORK_URL_UNINITIALIZED",
|
|
205
|
-
MissingConfig = "MISSING_CONFIG",
|
|
206
|
-
UnsupportedChain = "UNSUPPORTED_CHAIN",
|
|
207
|
-
MissingZkBuilderAndCrsGenerator = "MISSING_ZK_BUILDER_AND_CRS_GENERATOR",
|
|
208
|
-
MissingTfhePublicKeyDeserializer = "MISSING_TFHE_PUBLIC_KEY_DESERIALIZER",
|
|
209
|
-
MissingCompactPkeCrsDeserializer = "MISSING_COMPACT_PKE_CRS_DESERIALIZER",
|
|
210
|
-
MissingFheKey = "MISSING_FHE_KEY",
|
|
211
|
-
MissingCrs = "MISSING_CRS",
|
|
212
|
-
FetchKeysFailed = "FETCH_KEYS_FAILED",
|
|
213
|
-
PublicWalletGetChainIdFailed = "PUBLIC_WALLET_GET_CHAIN_ID_FAILED",
|
|
214
|
-
PublicWalletGetAddressesFailed = "PUBLIC_WALLET_GET_ADDRESSES_FAILED",
|
|
215
|
-
RehydrateKeysStoreFailed = "REHYDRATE_KEYS_STORE_FAILED"
|
|
216
|
-
}
|
|
217
|
-
type CofhesdkErrorParams = {
|
|
218
|
-
code: CofhesdkErrorCode;
|
|
219
|
-
message: string;
|
|
220
|
-
cause?: Error;
|
|
221
|
-
hint?: string;
|
|
222
|
-
context?: Record<string, unknown>;
|
|
223
|
-
};
|
|
224
|
-
/**
|
|
225
|
-
* CofhesdkError class
|
|
226
|
-
* This class is used to create errors that are specific to the CoFHE SDK
|
|
227
|
-
* It extends the Error class and adds a code, cause, hint, and context
|
|
228
|
-
* The code is used to identify the type of error
|
|
229
|
-
* The cause is used to indicate the inner error that caused the CofhesdkError
|
|
230
|
-
* The hint is used to provide a hint about how to fix the error
|
|
231
|
-
* The context is used to provide additional context about the state that caused the error
|
|
232
|
-
* The serialize method is used to serialize the error to a JSON string
|
|
233
|
-
* The toString method is used to provide a human-readable string representation of the error
|
|
234
|
-
*/
|
|
235
|
-
declare class CofhesdkError extends Error {
|
|
236
|
-
readonly code: CofhesdkErrorCode;
|
|
237
|
-
readonly cause?: Error;
|
|
238
|
-
readonly hint?: string;
|
|
239
|
-
readonly context?: Record<string, unknown>;
|
|
240
|
-
constructor({ code, message, cause, hint, context }: CofhesdkErrorParams);
|
|
241
|
-
/**
|
|
242
|
-
* Creates a CofhesdkError from an unknown error
|
|
243
|
-
* If the error is a CofhesdkError, it is returned unchanged, else a new CofhesdkError is created
|
|
244
|
-
* If a wrapperError is provided, it is used to create the new CofhesdkError, else a default is used
|
|
245
|
-
*/
|
|
246
|
-
static fromError(error: unknown, wrapperError?: CofhesdkErrorParams): CofhesdkError;
|
|
247
|
-
/**
|
|
248
|
-
* Serializes the error to JSON string with proper handling of Error objects
|
|
249
|
-
*/
|
|
250
|
-
serialize(): string;
|
|
251
|
-
/**
|
|
252
|
-
* Returns a human-readable string representation of the error
|
|
253
|
-
*/
|
|
254
|
-
toString(): string;
|
|
255
|
-
}
|
|
256
|
-
declare const isCofhesdkError: (error: unknown) => error is CofhesdkError;
|
|
257
|
-
|
|
258
|
-
type Result<T> = {
|
|
259
|
-
success: true;
|
|
260
|
-
data: T;
|
|
261
|
-
error: null;
|
|
262
|
-
} | {
|
|
263
|
-
success: false;
|
|
264
|
-
data: null;
|
|
265
|
-
error: CofhesdkError;
|
|
266
|
-
};
|
|
267
|
-
declare const ResultErr: <T>(error: CofhesdkError) => Result<T>;
|
|
268
|
-
declare const ResultOk: <T>(data: T) => Result<T>;
|
|
269
|
-
declare const ResultErrOrInternal: <T>(error: unknown) => Result<T>;
|
|
270
|
-
declare const ResultHttpError: (error: unknown, url: string, status?: number) => CofhesdkError;
|
|
271
|
-
declare const ResultValidationError: (message: string) => CofhesdkError;
|
|
272
|
-
declare const resultWrapper: <T>(tryFn: () => Promise<T>, catchFn?: (error: CofhesdkError) => void, finallyFn?: () => void) => Promise<Result<T>>;
|
|
273
|
-
declare const resultWrapperSync: <T>(fn: () => T) => Result<T>;
|
|
274
|
-
|
|
275
276
|
/**
|
|
276
277
|
* Base parameters that all builders need
|
|
277
278
|
*/
|
|
@@ -288,48 +289,40 @@ type BaseBuilderParams = {
|
|
|
288
289
|
* for working with clients, config, and chain IDs
|
|
289
290
|
*/
|
|
290
291
|
declare abstract class BaseBuilder {
|
|
291
|
-
protected config: CofhesdkConfig
|
|
292
|
+
protected config: CofhesdkConfig;
|
|
292
293
|
protected publicClient: PublicClient | undefined;
|
|
293
294
|
protected walletClient: WalletClient | undefined;
|
|
294
295
|
protected chainId: number | undefined;
|
|
295
296
|
protected account: string | undefined;
|
|
296
|
-
protected requireConnected: (() => void) | undefined;
|
|
297
297
|
constructor(params: BaseBuilderParams);
|
|
298
298
|
/**
|
|
299
|
-
*
|
|
300
|
-
* @
|
|
301
|
-
* @throws {CofhesdkError} If chainId is not set and publicClient is not available
|
|
299
|
+
* Asserts that this.chainId is populated
|
|
300
|
+
* @throws {CofhesdkError} If chainId is not set
|
|
302
301
|
*/
|
|
303
|
-
protected
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
* @returns The account address
|
|
307
|
-
* @throws {CofhesdkError} If account is not set and walletClient is not available
|
|
308
|
-
*/
|
|
309
|
-
protected getAccountOrThrow(): Promise<string>;
|
|
302
|
+
protected assertChainId(): asserts this is this & {
|
|
303
|
+
chainId: number;
|
|
304
|
+
};
|
|
310
305
|
/**
|
|
311
|
-
*
|
|
312
|
-
* @
|
|
313
|
-
* @throws {CofhesdkError} If config is not set
|
|
306
|
+
* Asserts that this.account is populated
|
|
307
|
+
* @throws {CofhesdkError} If account is not set
|
|
314
308
|
*/
|
|
315
|
-
protected
|
|
309
|
+
protected assertAccount(): asserts this is this & {
|
|
310
|
+
account: string;
|
|
311
|
+
};
|
|
316
312
|
/**
|
|
317
|
-
*
|
|
318
|
-
* @returns The public client
|
|
313
|
+
* Asserts that this.publicClient is populated
|
|
319
314
|
* @throws {CofhesdkError} If publicClient is not set
|
|
320
315
|
*/
|
|
321
|
-
protected
|
|
316
|
+
protected assertPublicClient(): asserts this is this & {
|
|
317
|
+
publicClient: PublicClient;
|
|
318
|
+
};
|
|
322
319
|
/**
|
|
323
|
-
*
|
|
324
|
-
* @returns The wallet client
|
|
320
|
+
* Asserts that this.walletClient is populated
|
|
325
321
|
* @throws {CofhesdkError} If walletClient is not set
|
|
326
322
|
*/
|
|
327
|
-
protected
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
* @throws {CofhesdkError} If client is not connected
|
|
331
|
-
*/
|
|
332
|
-
protected requireConnectedOrThrow(): void;
|
|
323
|
+
protected assertWalletClient(): asserts this is this & {
|
|
324
|
+
walletClient: WalletClient;
|
|
325
|
+
};
|
|
333
326
|
}
|
|
334
327
|
|
|
335
328
|
/**
|
|
@@ -347,7 +340,7 @@ declare abstract class BaseBuilder {
|
|
|
347
340
|
* If permitHash not set, uses chainId and account to get active permit
|
|
348
341
|
* If permit is set, uses permit to decrypt regardless of chainId, account, or permitHash
|
|
349
342
|
*
|
|
350
|
-
* Returns
|
|
343
|
+
* Returns the unsealed item.
|
|
351
344
|
*/
|
|
352
345
|
type DecryptHandlesBuilderParams<U extends FheTypes> = BaseBuilderParams & {
|
|
353
346
|
ctHash: bigint;
|
|
@@ -457,9 +450,37 @@ declare class DecryptHandlesBuilder<U extends FheTypes> extends BaseBuilder {
|
|
|
457
450
|
*
|
|
458
451
|
* @returns The unsealed item.
|
|
459
452
|
*/
|
|
460
|
-
decrypt(): Promise<
|
|
453
|
+
decrypt(): Promise<UnsealedItem<U>>;
|
|
461
454
|
}
|
|
462
455
|
|
|
456
|
+
/**
|
|
457
|
+
* Worker function type for ZK proof generation
|
|
458
|
+
* Platform-specific implementations (web) can provide this to enable worker-based proofs
|
|
459
|
+
*/
|
|
460
|
+
type ZkProveWorkerFunction = (fheKeyHex: string, crsHex: string, items: EncryptableItem[], metadata: Uint8Array) => Promise<Uint8Array>;
|
|
461
|
+
/**
|
|
462
|
+
* Message sent from main thread to worker to request proof generation
|
|
463
|
+
*/
|
|
464
|
+
interface ZkProveWorkerRequest {
|
|
465
|
+
id: string;
|
|
466
|
+
type: 'zkProve';
|
|
467
|
+
fheKeyHex: string;
|
|
468
|
+
crsHex: string;
|
|
469
|
+
items: Array<{
|
|
470
|
+
utype: string;
|
|
471
|
+
data: any;
|
|
472
|
+
}>;
|
|
473
|
+
metadata: number[];
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Message sent from worker back to main thread with proof result
|
|
477
|
+
*/
|
|
478
|
+
interface ZkProveWorkerResponse {
|
|
479
|
+
id: string;
|
|
480
|
+
type: 'success' | 'error' | 'ready';
|
|
481
|
+
result?: number[];
|
|
482
|
+
error?: string;
|
|
483
|
+
}
|
|
463
484
|
type ZkProvenCiphertextList = {
|
|
464
485
|
serialize(): Uint8Array;
|
|
465
486
|
};
|
|
@@ -482,6 +503,17 @@ type ZkBuilderAndCrsGenerator = (fhe: string, crs: string) => {
|
|
|
482
503
|
zkBuilder: ZkCiphertextListBuilder;
|
|
483
504
|
zkCrs: ZkCompactPkeCrs;
|
|
484
505
|
};
|
|
506
|
+
/**
|
|
507
|
+
* Generates ZK proof using Web Worker (offloads heavy WASM computation)
|
|
508
|
+
* Serializes items and calls the platform-specific worker function
|
|
509
|
+
* @param workerFn - Platform-specific worker function (provided by web/index.ts)
|
|
510
|
+
* @param fheKeyHex - Hex-encoded FHE public key for worker deserialization
|
|
511
|
+
* @param crsHex - Hex-encoded CRS for worker deserialization
|
|
512
|
+
* @param items - Encryptable items to pack in the worker
|
|
513
|
+
* @param metadata - Pre-constructed ZK PoK metadata
|
|
514
|
+
* @returns The serialized proven ciphertext list
|
|
515
|
+
*/
|
|
516
|
+
declare const zkProveWithWorker: (workerFn: ZkProveWorkerFunction, fheKeyHex: string, crsHex: string, items: EncryptableItem[], metadata: Uint8Array) => Promise<Uint8Array>;
|
|
485
517
|
|
|
486
518
|
type ChainRecord<T> = Record<string, T>;
|
|
487
519
|
type SecurityZoneRecord<T> = Record<number, T>;
|
|
@@ -518,16 +550,6 @@ type FheKeyDeserializer = (buff: string) => void;
|
|
|
518
550
|
* @returns {Promise<[[string, boolean], [string, boolean]]>} - A promise that resolves to [[fheKey, fheKeyFetchedFromCoFHE], [crs, crsFetchedFromCoFHE]]
|
|
519
551
|
*/
|
|
520
552
|
declare const fetchKeys: (config: CofhesdkConfig, chainId: number, securityZone: number | undefined, tfhePublicKeyDeserializer: FheKeyDeserializer, compactPkeCrsDeserializer: FheKeyDeserializer, keysStorage?: KeysStorage | null) => Promise<[[string, boolean], [string, boolean]]>;
|
|
521
|
-
/**
|
|
522
|
-
* Fetches the FHE public key and the CRS for all chains in the config
|
|
523
|
-
* @param {CofhesdkConfig} config - The configuration object for the CoFHE SDK
|
|
524
|
-
* @param {number} securityZone - The security zone for which to retrieve the key (default 0).
|
|
525
|
-
* @param tfhePublicKeyDeserializer - The serializer for the FHE public key (used for validation).
|
|
526
|
-
* @param compactPkeCrsDeserializer - The serializer for the CRS (used for validation).
|
|
527
|
-
* @param keysStorage - The keys storage instance to use (optional)
|
|
528
|
-
* @returns {Promise<void>} - A promise that resolves when the keys are fetched and stored.
|
|
529
|
-
*/
|
|
530
|
-
declare const fetchMultichainKeys: (config: CofhesdkConfig, securityZone: number | undefined, tfhePublicKeyDeserializer: FheKeyDeserializer, compactPkeCrsDeserializer: FheKeyDeserializer, keysStorage?: KeysStorage | null) => Promise<void>;
|
|
531
553
|
|
|
532
554
|
type EncryptInputsBuilderParams<T extends EncryptableItem[]> = BaseBuilderParams & {
|
|
533
555
|
inputs: [...T];
|
|
@@ -537,15 +559,13 @@ type EncryptInputsBuilderParams<T extends EncryptableItem[]> = BaseBuilderParams
|
|
|
537
559
|
compactPkeCrsDeserializer: FheKeyDeserializer | undefined;
|
|
538
560
|
zkBuilderAndCrsGenerator: ZkBuilderAndCrsGenerator | undefined;
|
|
539
561
|
initTfhe: TfheInitializer | undefined;
|
|
562
|
+
zkProveWorkerFn: ZkProveWorkerFunction | undefined;
|
|
540
563
|
keysStorage: KeysStorage | undefined;
|
|
541
564
|
};
|
|
542
565
|
/**
|
|
543
566
|
* EncryptInputsBuilder exposes a builder pattern for encrypting inputs.
|
|
544
567
|
* account, securityZone, and chainId can be overridden in the builder.
|
|
545
568
|
* config, tfhePublicKeyDeserializer, compactPkeCrsDeserializer, and zkBuilderAndCrsGenerator are required to be set in the builder.
|
|
546
|
-
*
|
|
547
|
-
* @dev All errors must be throw in `encrypt`, which wraps them in a Result.
|
|
548
|
-
* Do not throw errors in the constructor or in the builder methods.
|
|
549
569
|
*/
|
|
550
570
|
declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuilder {
|
|
551
571
|
private securityZone;
|
|
@@ -556,7 +576,9 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
|
|
|
556
576
|
private compactPkeCrsDeserializer;
|
|
557
577
|
private zkBuilderAndCrsGenerator;
|
|
558
578
|
private initTfhe;
|
|
579
|
+
private zkProveWorkerFn;
|
|
559
580
|
private keysStorage;
|
|
581
|
+
private useWorker;
|
|
560
582
|
private stepTimestamps;
|
|
561
583
|
constructor(params: EncryptInputsBuilderParams<T>);
|
|
562
584
|
/**
|
|
@@ -607,6 +629,35 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
|
|
|
607
629
|
*/
|
|
608
630
|
setSecurityZone(securityZone: number): EncryptInputsBuilder<T>;
|
|
609
631
|
getSecurityZone(): number;
|
|
632
|
+
/**
|
|
633
|
+
* @param useWorker - Whether to use Web Workers for ZK proof generation.
|
|
634
|
+
*
|
|
635
|
+
* Overrides the config-level useWorkers setting for this specific encryption.
|
|
636
|
+
*
|
|
637
|
+
* Example:
|
|
638
|
+
* ```typescript
|
|
639
|
+
* const encrypted = await encryptInputs([Encryptable.uint128(10n)])
|
|
640
|
+
* .setUseWorker(false)
|
|
641
|
+
* .encrypt();
|
|
642
|
+
* ```
|
|
643
|
+
*
|
|
644
|
+
* @returns The chainable EncryptInputsBuilder instance.
|
|
645
|
+
*/
|
|
646
|
+
setUseWorker(useWorker: boolean): EncryptInputsBuilder<T>;
|
|
647
|
+
/**
|
|
648
|
+
* Gets the current worker configuration.
|
|
649
|
+
*
|
|
650
|
+
* @returns Whether Web Workers are enabled for this encryption.
|
|
651
|
+
*
|
|
652
|
+
* Example:
|
|
653
|
+
* ```typescript
|
|
654
|
+
* const builder = encryptInputs([Encryptable.uint128(10n)]);
|
|
655
|
+
* console.log(builder.getUseWorker()); // true (from config)
|
|
656
|
+
* builder.setUseWorker(false);
|
|
657
|
+
* console.log(builder.getUseWorker()); // false (overridden)
|
|
658
|
+
* ```
|
|
659
|
+
*/
|
|
660
|
+
getUseWorker(): boolean;
|
|
610
661
|
/**
|
|
611
662
|
* @param callback - Function to be called with the encryption step.
|
|
612
663
|
*
|
|
@@ -629,20 +680,6 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
|
|
|
629
680
|
*/
|
|
630
681
|
private fireStepStart;
|
|
631
682
|
private fireStepEnd;
|
|
632
|
-
/**
|
|
633
|
-
* tfhePublicKeyDeserializer is a platform-specific dependency injected into core/createCofhesdkClientBase by web/createCofhesdkClient and node/createCofhesdkClient
|
|
634
|
-
* web/ uses zama "tfhe"
|
|
635
|
-
* node/ uses zama "node-tfhe"
|
|
636
|
-
* Users should not set this manually.
|
|
637
|
-
*/
|
|
638
|
-
private getTfhePublicKeyDeserializerOrThrow;
|
|
639
|
-
/**
|
|
640
|
-
* compactPkeCrsDeserializer is a platform-specific dependency injected into core/createCofhesdkClientBase by web/createCofhesdkClient and node/createCofhesdkClient
|
|
641
|
-
* web/ uses zama "tfhe"
|
|
642
|
-
* node/ uses zama "node-tfhe"
|
|
643
|
-
* Users should not set this manually.
|
|
644
|
-
*/
|
|
645
|
-
private getCompactPkeCrsDeserializerOrThrow;
|
|
646
683
|
/**
|
|
647
684
|
* zkVerifierUrl is included in the chains exported from cofhesdk/chains for use in CofhesdkConfig.supportedChains
|
|
648
685
|
* Users should generally not set this manually.
|
|
@@ -660,15 +697,6 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
|
|
|
660
697
|
* If the key/crs already exists in the store it is returned, else it is fetched, stored, and returned
|
|
661
698
|
*/
|
|
662
699
|
private fetchFheKeyAndCrs;
|
|
663
|
-
/**
|
|
664
|
-
* zkBuilderAndCrsGenerator is a platform-specific dependency injected into core/createCofhesdkClientBase by web/createCofhesdkClient and node/createCofhesdkClient
|
|
665
|
-
* web/ uses zama "tfhe"
|
|
666
|
-
* node/ uses zama "node-tfhe"
|
|
667
|
-
* Users should not set this manually.
|
|
668
|
-
*
|
|
669
|
-
* Generates the zkBuilder and zkCrs from the fheKey and crs
|
|
670
|
-
*/
|
|
671
|
-
private generateZkBuilderAndCrs;
|
|
672
700
|
/**
|
|
673
701
|
* @dev Encrypt against the cofheMocks instead of CoFHE
|
|
674
702
|
*
|
|
@@ -700,7 +728,7 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
|
|
|
700
728
|
*
|
|
701
729
|
* @returns The encrypted inputs.
|
|
702
730
|
*/
|
|
703
|
-
encrypt(): Promise<
|
|
731
|
+
encrypt(): Promise<[...EncryptedItemInputs<T>]>;
|
|
704
732
|
}
|
|
705
733
|
|
|
706
734
|
declare const permits: {
|
|
@@ -745,33 +773,36 @@ declare const permits: {
|
|
|
745
773
|
};
|
|
746
774
|
};
|
|
747
775
|
}) => void) => () => void;
|
|
748
|
-
createSelf: (options: CreateSelfPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<
|
|
749
|
-
createSharing: (options: CreateSharingPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<
|
|
750
|
-
importShared: (options: ImportSharedPermitOptions |
|
|
751
|
-
|
|
776
|
+
createSelf: (options: CreateSelfPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SelfPermit>;
|
|
777
|
+
createSharing: (options: CreateSharingPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SharingPermit>;
|
|
778
|
+
importShared: (options: ImportSharedPermitOptions | string, publicClient: PublicClient, walletClient: WalletClient) => Promise<RecipientPermit>;
|
|
779
|
+
getOrCreateSelfPermit: (publicClient: PublicClient, walletClient: WalletClient, chainId?: number, account?: string, options?: CreateSelfPermitOptions) => Promise<Permit>;
|
|
780
|
+
getOrCreateSharingPermit: (publicClient: PublicClient, walletClient: WalletClient, options: CreateSharingPermitOptions, chainId?: number, account?: string) => Promise<Permit>;
|
|
781
|
+
getHash: (permit: PermitHashFields) => string;
|
|
752
782
|
serialize: (permit: Permit) => SerializedPermit;
|
|
753
783
|
deserialize: (serialized: SerializedPermit) => Permit;
|
|
754
784
|
getPermit: (chainId: number, account: string, hash: string) => Promise<Permit | undefined>;
|
|
755
785
|
getPermits: (chainId: number, account: string) => Promise<Record<string, Permit>>;
|
|
756
786
|
getActivePermit: (chainId: number, account: string) => Promise<Permit | undefined>;
|
|
757
|
-
getActivePermitHash: (chainId: number, account: string) =>
|
|
787
|
+
getActivePermitHash: (chainId: number, account: string) => string | undefined;
|
|
758
788
|
removePermit: (chainId: number, account: string, hash: string) => Promise<void>;
|
|
759
|
-
selectActivePermit: (chainId: number, account: string, hash: string) =>
|
|
789
|
+
selectActivePermit: (chainId: number, account: string, hash: string) => void;
|
|
760
790
|
removeActivePermit: (chainId: number, account: string) => Promise<void>;
|
|
761
791
|
};
|
|
762
792
|
|
|
763
|
-
type
|
|
764
|
-
type LiteralToPrimitive<T> = T extends number ? number : T extends bigint ? bigint : T extends string ? string : T extends boolean ? boolean : T extends symbol ? symbol : T extends null ? null : T extends undefined ? undefined : never;
|
|
765
|
-
type CofhesdkClient = {
|
|
793
|
+
type CofhesdkClient<TConfig extends CofhesdkConfig = CofhesdkConfig> = {
|
|
766
794
|
getSnapshot(): CofhesdkClientConnectionState;
|
|
767
795
|
subscribe(listener: Listener): () => void;
|
|
768
|
-
readonly initializationResults: {
|
|
769
|
-
keyFetchResult: Promise<Result<boolean>>;
|
|
770
|
-
};
|
|
771
796
|
readonly connected: boolean;
|
|
772
797
|
readonly connecting: boolean;
|
|
773
|
-
readonly config:
|
|
774
|
-
connect(publicClient: PublicClient, walletClient: WalletClient): Promise<
|
|
798
|
+
readonly config: TConfig;
|
|
799
|
+
connect(publicClient: PublicClient, walletClient: WalletClient): Promise<void>;
|
|
800
|
+
/**
|
|
801
|
+
* Clears the current connection state (account/chainId/clients) and marks the client as disconnected.
|
|
802
|
+
*
|
|
803
|
+
* This does not delete persisted permits or stored FHE keys; it only resets the in-memory connection.
|
|
804
|
+
*/
|
|
805
|
+
disconnect(): void;
|
|
775
806
|
/**
|
|
776
807
|
* Types docstring
|
|
777
808
|
*/
|
|
@@ -784,170 +815,41 @@ type CofhesdkClientConnectionState = {
|
|
|
784
815
|
connecting: boolean;
|
|
785
816
|
connectError: unknown | undefined;
|
|
786
817
|
chainId: number | undefined;
|
|
787
|
-
account: string | undefined;
|
|
818
|
+
account: `0x${string}` | undefined;
|
|
819
|
+
publicClient: PublicClient | undefined;
|
|
820
|
+
walletClient: WalletClient | undefined;
|
|
788
821
|
};
|
|
789
822
|
type Listener = (snapshot: CofhesdkClientConnectionState) => void;
|
|
823
|
+
type CofhesdkClientPermitsClients = {
|
|
824
|
+
publicClient: PublicClient;
|
|
825
|
+
walletClient: WalletClient;
|
|
826
|
+
};
|
|
790
827
|
type CofhesdkClientPermits = {
|
|
791
828
|
getSnapshot: typeof permits.getSnapshot;
|
|
792
829
|
subscribe: typeof permits.subscribe;
|
|
793
|
-
createSelf: (options: CreateSelfPermitOptions) => Promise<
|
|
794
|
-
createSharing: (options: CreateSharingPermitOptions) => Promise<
|
|
795
|
-
importShared: (options: ImportSharedPermitOptions |
|
|
796
|
-
getPermit: (hash: string, chainId?: number, account?: string) => Promise<
|
|
797
|
-
getPermits: (chainId?: number, account?: string) => Promise<
|
|
798
|
-
getActivePermit: (chainId?: number, account?: string) => Promise<
|
|
799
|
-
getActivePermitHash: (chainId?: number, account?: string) => Promise<
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
830
|
+
createSelf: (options: CreateSelfPermitOptions, clients?: CofhesdkClientPermitsClients) => Promise<SelfPermit>;
|
|
831
|
+
createSharing: (options: CreateSharingPermitOptions, clients?: CofhesdkClientPermitsClients) => Promise<SharingPermit>;
|
|
832
|
+
importShared: (options: ImportSharedPermitOptions | string, clients?: CofhesdkClientPermitsClients) => Promise<RecipientPermit>;
|
|
833
|
+
getPermit: (hash: string, chainId?: number, account?: string) => Promise<Permit | undefined>;
|
|
834
|
+
getPermits: (chainId?: number, account?: string) => Promise<Record<string, Permit>>;
|
|
835
|
+
getActivePermit: (chainId?: number, account?: string) => Promise<Permit | undefined>;
|
|
836
|
+
getActivePermitHash: (chainId?: number, account?: string) => Promise<string | undefined>;
|
|
837
|
+
getOrCreateSelfPermit: (chainId?: number, account?: string, options?: CreateSelfPermitOptions) => Promise<Permit>;
|
|
838
|
+
getOrCreateSharingPermit: (options: CreateSharingPermitOptions, chainId?: number, account?: string) => Promise<Permit>;
|
|
839
|
+
selectActivePermit: (hash: string, chainId?: number, account?: string) => void;
|
|
840
|
+
removePermit: (hash: string, chainId?: number, account?: string) => void;
|
|
841
|
+
removeActivePermit: (chainId?: number, account?: string) => void;
|
|
803
842
|
getHash: typeof PermitUtils.getHash;
|
|
804
843
|
serialize: typeof PermitUtils.serialize;
|
|
805
844
|
deserialize: typeof PermitUtils.deserialize;
|
|
806
845
|
};
|
|
807
|
-
type
|
|
808
|
-
|
|
809
|
-
config: CofhesdkConfig;
|
|
846
|
+
type CofhesdkClientParams<TConfig extends CofhesdkConfig> = {
|
|
847
|
+
config: TConfig;
|
|
810
848
|
zkBuilderAndCrsGenerator: ZkBuilderAndCrsGenerator;
|
|
811
849
|
tfhePublicKeyDeserializer: FheKeyDeserializer;
|
|
812
850
|
compactPkeCrsDeserializer: FheKeyDeserializer;
|
|
813
851
|
initTfhe: TfheInitializer;
|
|
852
|
+
zkProveWorkerFn?: ZkProveWorkerFunction;
|
|
814
853
|
};
|
|
815
|
-
interface IStorage {
|
|
816
|
-
getItem: (name: string) => Promise<any>;
|
|
817
|
-
setItem: (name: string, value: any) => Promise<void>;
|
|
818
|
-
removeItem: (name: string) => Promise<void>;
|
|
819
|
-
}
|
|
820
|
-
declare enum FheTypes {
|
|
821
|
-
Bool = 0,
|
|
822
|
-
Uint4 = 1,
|
|
823
|
-
Uint8 = 2,
|
|
824
|
-
Uint16 = 3,
|
|
825
|
-
Uint32 = 4,
|
|
826
|
-
Uint64 = 5,
|
|
827
|
-
Uint128 = 6,
|
|
828
|
-
Uint160 = 7,
|
|
829
|
-
Uint256 = 8,
|
|
830
|
-
Uint512 = 9,
|
|
831
|
-
Uint1024 = 10,
|
|
832
|
-
Uint2048 = 11,
|
|
833
|
-
Uint2 = 12,
|
|
834
|
-
Uint6 = 13,
|
|
835
|
-
Uint10 = 14,
|
|
836
|
-
Uint12 = 15,
|
|
837
|
-
Uint14 = 16,
|
|
838
|
-
Int2 = 17,
|
|
839
|
-
Int4 = 18,
|
|
840
|
-
Int6 = 19,
|
|
841
|
-
Int8 = 20,
|
|
842
|
-
Int10 = 21,
|
|
843
|
-
Int12 = 22,
|
|
844
|
-
Int14 = 23,
|
|
845
|
-
Int16 = 24,
|
|
846
|
-
Int32 = 25,
|
|
847
|
-
Int64 = 26,
|
|
848
|
-
Int128 = 27,
|
|
849
|
-
Int160 = 28,
|
|
850
|
-
Int256 = 29
|
|
851
|
-
}
|
|
852
|
-
/**
|
|
853
|
-
* List of All FHE uint types (excludes bool and address)
|
|
854
|
-
*/
|
|
855
|
-
declare const FheUintUTypes: readonly [FheTypes.Uint8, FheTypes.Uint16, FheTypes.Uint32, FheTypes.Uint64, FheTypes.Uint128];
|
|
856
|
-
type FheUintUTypesType = (typeof FheUintUTypes)[number];
|
|
857
|
-
/**
|
|
858
|
-
* List of All FHE types (uints, bool, and address)
|
|
859
|
-
*/
|
|
860
|
-
declare const FheAllUTypes: readonly [FheTypes.Bool, FheTypes.Uint8, FheTypes.Uint16, FheTypes.Uint32, FheTypes.Uint64, FheTypes.Uint128, FheTypes.Uint160];
|
|
861
|
-
type EncryptedNumber = {
|
|
862
|
-
data: Uint8Array;
|
|
863
|
-
securityZone: number;
|
|
864
|
-
};
|
|
865
|
-
type EncryptedItemInput = {
|
|
866
|
-
ctHash: bigint;
|
|
867
|
-
securityZone: number;
|
|
868
|
-
utype: FheTypes;
|
|
869
|
-
signature: string;
|
|
870
|
-
};
|
|
871
|
-
type EncryptedBoolInput = EncryptedItemInput & {
|
|
872
|
-
utype: FheTypes.Bool;
|
|
873
|
-
};
|
|
874
|
-
type EncryptedUint8Input = EncryptedItemInput & {
|
|
875
|
-
utype: FheTypes.Uint8;
|
|
876
|
-
};
|
|
877
|
-
type EncryptedUint16Input = EncryptedItemInput & {
|
|
878
|
-
utype: FheTypes.Uint16;
|
|
879
|
-
};
|
|
880
|
-
type EncryptedUint32Input = EncryptedItemInput & {
|
|
881
|
-
utype: FheTypes.Uint32;
|
|
882
|
-
};
|
|
883
|
-
type EncryptedUint64Input = EncryptedItemInput & {
|
|
884
|
-
utype: FheTypes.Uint64;
|
|
885
|
-
};
|
|
886
|
-
type EncryptedUint128Input = EncryptedItemInput & {
|
|
887
|
-
utype: FheTypes.Uint128;
|
|
888
|
-
};
|
|
889
|
-
type EncryptedUint256Input = EncryptedItemInput & {
|
|
890
|
-
utype: FheTypes.Uint256;
|
|
891
|
-
};
|
|
892
|
-
type EncryptedAddressInput = EncryptedItemInput & {
|
|
893
|
-
utype: FheTypes.Uint160;
|
|
894
|
-
};
|
|
895
|
-
type EncryptableBool = {
|
|
896
|
-
data: boolean;
|
|
897
|
-
utype: FheTypes.Bool;
|
|
898
|
-
};
|
|
899
|
-
type EncryptableUint8 = {
|
|
900
|
-
data: string | bigint;
|
|
901
|
-
utype: FheTypes.Uint8;
|
|
902
|
-
};
|
|
903
|
-
type EncryptableUint16 = {
|
|
904
|
-
data: string | bigint;
|
|
905
|
-
utype: FheTypes.Uint16;
|
|
906
|
-
};
|
|
907
|
-
type EncryptableUint32 = {
|
|
908
|
-
data: string | bigint;
|
|
909
|
-
utype: FheTypes.Uint32;
|
|
910
|
-
};
|
|
911
|
-
type EncryptableUint64 = {
|
|
912
|
-
data: string | bigint;
|
|
913
|
-
utype: FheTypes.Uint64;
|
|
914
|
-
};
|
|
915
|
-
type EncryptableUint128 = {
|
|
916
|
-
data: string | bigint;
|
|
917
|
-
utype: FheTypes.Uint128;
|
|
918
|
-
};
|
|
919
|
-
type EncryptableAddress = {
|
|
920
|
-
data: string | bigint;
|
|
921
|
-
utype: FheTypes.Uint160;
|
|
922
|
-
};
|
|
923
|
-
declare const Encryptable: {
|
|
924
|
-
readonly bool: (data: EncryptableBool["data"], securityZone?: number) => EncryptableBool;
|
|
925
|
-
readonly address: (data: EncryptableAddress["data"], securityZone?: number) => EncryptableAddress;
|
|
926
|
-
readonly uint8: (data: EncryptableUint8["data"], securityZone?: number) => EncryptableUint8;
|
|
927
|
-
readonly uint16: (data: EncryptableUint16["data"], securityZone?: number) => EncryptableUint16;
|
|
928
|
-
readonly uint32: (data: EncryptableUint32["data"], securityZone?: number) => EncryptableUint32;
|
|
929
|
-
readonly uint64: (data: EncryptableUint64["data"], securityZone?: number) => EncryptableUint64;
|
|
930
|
-
readonly uint128: (data: EncryptableUint128["data"], securityZone?: number) => EncryptableUint128;
|
|
931
|
-
};
|
|
932
|
-
type EncryptableItem = EncryptableBool | EncryptableUint8 | EncryptableUint16 | EncryptableUint32 | EncryptableUint64 | EncryptableUint128 | EncryptableAddress;
|
|
933
|
-
type EncryptableToEncryptedItemInputMap<E extends EncryptableItem> = E extends EncryptableBool ? EncryptedBoolInput : E extends EncryptableUint8 ? EncryptedUint8Input : E extends EncryptableUint16 ? EncryptedUint16Input : E extends EncryptableUint32 ? EncryptedUint32Input : E extends EncryptableUint64 ? EncryptedUint64Input : E extends EncryptableUint128 ? EncryptedUint128Input : E extends EncryptableAddress ? EncryptedAddressInput : never;
|
|
934
|
-
type EncryptedItemInputs<T> = T extends Primitive ? LiteralToPrimitive<T> : T extends EncryptableItem ? EncryptableToEncryptedItemInputMap<T> : {
|
|
935
|
-
[K in keyof T]: EncryptedItemInputs<T[K]>;
|
|
936
|
-
};
|
|
937
|
-
declare function isEncryptableItem(value: unknown): value is EncryptableItem;
|
|
938
|
-
declare enum EncryptStep {
|
|
939
|
-
InitTfhe = "initTfhe",
|
|
940
|
-
FetchKeys = "fetchKeys",
|
|
941
|
-
Pack = "pack",
|
|
942
|
-
Prove = "prove",
|
|
943
|
-
Verify = "verify"
|
|
944
|
-
}
|
|
945
|
-
type EncryptStepCallbackContext = Record<string, any> & {
|
|
946
|
-
isStart: boolean;
|
|
947
|
-
isEnd: boolean;
|
|
948
|
-
duration: number;
|
|
949
|
-
};
|
|
950
|
-
type EncryptStepCallbackFunction = (state: EncryptStep, context?: EncryptStepCallbackContext) => void;
|
|
951
|
-
type UnsealedItem<U extends FheTypes> = U extends FheTypes.Bool ? boolean : U extends FheTypes.Uint160 ? string : U extends FheUintUTypesType ? bigint : never;
|
|
952
854
|
|
|
953
|
-
export {
|
|
855
|
+
export { type ZkProveWorkerResponse as $, type FheTypeValue as A, type EncryptStepCallbackFunction as B, type CofhesdkInputConfig as C, type EncryptStepCallbackContext as D, type EncryptableItem as E, FheTypes as F, FheUintUTypes as G, FheAllUTypes as H, type IStorage as I, Encryptable as J, isEncryptableItem as K, type LiteralToPrimitive as L, EncryptStep as M, isLastEncryptionStep as N, assertCorrectEncryptedItemInput as O, type Primitive as P, fetchKeys as Q, type FheKeyDeserializer as R, createKeysStore as S, type KeysStorage as T, type UnsealedItem as U, type KeysStore as V, EncryptInputsBuilder as W, DecryptHandlesBuilder as X, type ZkProveWorkerFunction as Y, type ZkBuilderAndCrsGenerator as Z, type ZkProveWorkerRequest as _, type CofhesdkConfig as a, zkProveWithWorker as a0, type CofhesdkClient as b, type CofhesdkClientConnectionState as c, type CofhesdkClientParams as d, createCofhesdkConfigBase as e, type CofhesdkInternalConfig as f, getCofhesdkConfigItem as g, type CofhesdkClientPermits 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 };
|