@cofhe/sdk 0.1.0 → 0.2.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 +62 -0
- package/adapters/ethers5.test.ts +174 -0
- package/adapters/ethers5.ts +36 -0
- package/adapters/ethers6.test.ts +169 -0
- package/adapters/ethers6.ts +36 -0
- package/adapters/hardhat-node.ts +167 -0
- package/adapters/hardhat.hh2.test.ts +159 -0
- package/adapters/hardhat.ts +36 -0
- package/adapters/index.test.ts +20 -0
- package/adapters/index.ts +5 -0
- package/adapters/smartWallet.ts +99 -0
- package/adapters/test-utils.ts +53 -0
- package/adapters/types.ts +6 -0
- package/adapters/wagmi.test.ts +156 -0
- package/adapters/wagmi.ts +17 -0
- package/chains/chains/arbSepolia.ts +14 -0
- package/chains/chains/baseSepolia.ts +14 -0
- package/chains/chains/hardhat.ts +15 -0
- package/chains/chains/localcofhe.ts +14 -0
- package/chains/chains/sepolia.ts +14 -0
- package/chains/chains.test.ts +50 -0
- package/chains/defineChain.ts +18 -0
- package/chains/index.ts +35 -0
- package/chains/types.ts +32 -0
- package/core/baseBuilder.ts +119 -0
- package/core/client.test.ts +315 -0
- package/core/client.ts +292 -0
- package/core/clientTypes.ts +108 -0
- package/core/config.test.ts +235 -0
- package/core/config.ts +220 -0
- package/core/decrypt/MockQueryDecrypterAbi.ts +129 -0
- package/core/decrypt/cofheMocksSealOutput.ts +57 -0
- package/core/decrypt/decryptHandleBuilder.ts +287 -0
- package/core/decrypt/decryptUtils.ts +28 -0
- package/core/decrypt/tnSealOutputV1.ts +59 -0
- package/core/decrypt/tnSealOutputV2.ts +298 -0
- package/core/encrypt/MockZkVerifierAbi.ts +106 -0
- package/core/encrypt/cofheMocksZkVerifySign.ts +284 -0
- package/core/encrypt/encryptInputsBuilder.test.ts +751 -0
- package/core/encrypt/encryptInputsBuilder.ts +560 -0
- package/core/encrypt/encryptUtils.ts +67 -0
- package/core/encrypt/zkPackProveVerify.ts +335 -0
- package/core/error.ts +168 -0
- package/core/fetchKeys.test.ts +195 -0
- package/core/fetchKeys.ts +144 -0
- package/core/index.ts +89 -0
- package/core/keyStore.test.ts +226 -0
- package/core/keyStore.ts +154 -0
- package/core/permits.test.ts +494 -0
- package/core/permits.ts +200 -0
- package/core/types.ts +398 -0
- package/core/utils.ts +130 -0
- package/dist/adapters.cjs +88 -0
- package/dist/adapters.d.cts +14576 -0
- package/dist/adapters.d.ts +14576 -0
- package/dist/adapters.js +83 -0
- package/dist/chains.cjs +114 -0
- package/dist/chains.d.cts +121 -0
- package/dist/chains.d.ts +121 -0
- package/dist/chains.js +1 -0
- package/dist/chunk-UGBVZNRT.js +818 -0
- package/dist/chunk-WEAZ25JO.js +105 -0
- package/dist/chunk-WGCRJCBR.js +2523 -0
- package/dist/clientTypes-5_1nwtUe.d.cts +914 -0
- package/dist/clientTypes-Es7fyi65.d.ts +914 -0
- package/dist/core.cjs +3414 -0
- package/dist/core.d.cts +111 -0
- package/dist/core.d.ts +111 -0
- package/dist/core.js +3 -0
- package/dist/node.cjs +3286 -0
- package/dist/node.d.cts +22 -0
- package/dist/node.d.ts +22 -0
- package/dist/node.js +91 -0
- package/dist/permit-fUSe6KKq.d.cts +349 -0
- package/dist/permit-fUSe6KKq.d.ts +349 -0
- package/dist/permits.cjs +871 -0
- package/dist/permits.d.cts +1045 -0
- package/dist/permits.d.ts +1045 -0
- package/dist/permits.js +1 -0
- package/dist/types-KImPrEIe.d.cts +48 -0
- package/dist/types-KImPrEIe.d.ts +48 -0
- package/dist/web.cjs +3478 -0
- package/dist/web.d.cts +38 -0
- package/dist/web.d.ts +38 -0
- package/dist/web.js +240 -0
- 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 +147 -0
- package/node/config.test.ts +68 -0
- package/node/encryptInputs.test.ts +155 -0
- package/node/index.ts +97 -0
- package/node/storage.ts +51 -0
- package/package.json +27 -15
- package/permits/index.ts +68 -0
- package/permits/localstorage.test.ts +117 -0
- package/permits/permit.test.ts +477 -0
- package/permits/permit.ts +405 -0
- package/permits/sealing.test.ts +84 -0
- package/permits/sealing.ts +131 -0
- package/permits/signature.ts +79 -0
- package/permits/store.test.ts +128 -0
- package/permits/store.ts +166 -0
- package/permits/test-utils.ts +20 -0
- package/permits/types.ts +191 -0
- package/permits/utils.ts +62 -0
- package/permits/validation.test.ts +288 -0
- package/permits/validation.ts +369 -0
- package/web/client.web.test.ts +147 -0
- package/web/config.web.test.ts +69 -0
- package/web/encryptInputs.web.test.ts +172 -0
- package/web/index.ts +161 -0
- package/web/storage.ts +34 -0
- 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
|
@@ -0,0 +1,914 @@
|
|
|
1
|
+
import { WalletClient, PublicClient } from 'viem';
|
|
2
|
+
import { C as CofheChain } from './types-KImPrEIe.js';
|
|
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, g as PermitUtils } from './permit-fUSe6KKq.js';
|
|
5
|
+
import { StoreApi } from 'zustand/vanilla';
|
|
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
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Usable config type inferred from the schema
|
|
172
|
+
*/
|
|
173
|
+
type CofhesdkConfig = {
|
|
174
|
+
/** Environment that the SDK is running in */
|
|
175
|
+
environment: 'node' | 'hardhat' | 'web' | 'react';
|
|
176
|
+
/** List of supported chains */
|
|
177
|
+
supportedChains: CofheChain[];
|
|
178
|
+
/**
|
|
179
|
+
* How permits are generated
|
|
180
|
+
* - ON_CONNECT: Generate a permit when client.connect() is called
|
|
181
|
+
* - ON_DECRYPT_HANDLES: Generate a permit when client.decryptHandles() is called
|
|
182
|
+
* - MANUAL: Generate a permit manually using client.generatePermit()
|
|
183
|
+
*/
|
|
184
|
+
permitGeneration: 'ON_CONNECT' | 'ON_DECRYPT_HANDLES' | 'MANUAL';
|
|
185
|
+
/** Default permit expiration in seconds, default is 30 days */
|
|
186
|
+
defaultPermitExpiration: number;
|
|
187
|
+
/**
|
|
188
|
+
* Storage scheme for the fetched fhe keys
|
|
189
|
+
* FHE keys are large, and caching prevents re-fetching them on each encryptInputs call
|
|
190
|
+
* (defaults to indexedDB on web, filesystem on node)
|
|
191
|
+
*/
|
|
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;
|
|
199
|
+
/** Mocks configs */
|
|
200
|
+
mocks: {
|
|
201
|
+
/**
|
|
202
|
+
* Length of the simulated seal output delay in milliseconds
|
|
203
|
+
* Default 1000ms on web
|
|
204
|
+
* Default 0ms on hardhat (will be called during tests no need for fake delay)
|
|
205
|
+
*/
|
|
206
|
+
sealOutputDelay: number;
|
|
207
|
+
};
|
|
208
|
+
_internal?: CofhesdkInternalConfig;
|
|
209
|
+
};
|
|
210
|
+
type CofhesdkInternalConfig = {
|
|
211
|
+
zkvWalletClient?: WalletClient;
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Zod schema for configuration validation
|
|
215
|
+
*/
|
|
216
|
+
declare const CofhesdkConfigSchema: z.ZodObject<{
|
|
217
|
+
/** Environment that the SDK is running in */
|
|
218
|
+
environment: z.ZodDefault<z.ZodOptional<z.ZodEnum<["node", "hardhat", "web", "react"]>>>;
|
|
219
|
+
/** List of supported chain configurations */
|
|
220
|
+
supportedChains: z.ZodArray<z.ZodType<{
|
|
221
|
+
name: string;
|
|
222
|
+
id: number;
|
|
223
|
+
network: string;
|
|
224
|
+
coFheUrl: string;
|
|
225
|
+
verifierUrl: string;
|
|
226
|
+
thresholdNetworkUrl: string;
|
|
227
|
+
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
228
|
+
}, z.ZodTypeDef, {
|
|
229
|
+
name: string;
|
|
230
|
+
id: number;
|
|
231
|
+
network: string;
|
|
232
|
+
coFheUrl: string;
|
|
233
|
+
verifierUrl: string;
|
|
234
|
+
thresholdNetworkUrl: string;
|
|
235
|
+
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
236
|
+
}>, "many">;
|
|
237
|
+
/** How permits are generated */
|
|
238
|
+
permitGeneration: z.ZodDefault<z.ZodOptional<z.ZodEnum<["ON_CONNECT", "ON_DECRYPT_HANDLES", "MANUAL"]>>>;
|
|
239
|
+
/** Default permit expiration in seconds, default is 30 days */
|
|
240
|
+
defaultPermitExpiration: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
241
|
+
/** Storage method for fhe keys (defaults to indexedDB on web, filesystem on node) */
|
|
242
|
+
fheKeyStorage: z.ZodDefault<z.ZodUnion<[z.ZodObject<{
|
|
243
|
+
getItem: z.ZodFunction<z.ZodTuple<[z.ZodString], z.ZodUnknown>, z.ZodPromise<z.ZodAny>>;
|
|
244
|
+
setItem: z.ZodFunction<z.ZodTuple<[z.ZodString, z.ZodAny], z.ZodUnknown>, z.ZodPromise<z.ZodVoid>>;
|
|
245
|
+
removeItem: z.ZodFunction<z.ZodTuple<[z.ZodString], z.ZodUnknown>, z.ZodPromise<z.ZodVoid>>;
|
|
246
|
+
}, "strip", z.ZodTypeAny, {
|
|
247
|
+
getItem: (args_0: string, ...args_1: unknown[]) => Promise<any>;
|
|
248
|
+
setItem: (args_0: string, args_1: any, ...args_2: unknown[]) => Promise<void>;
|
|
249
|
+
removeItem: (args_0: string, ...args_1: unknown[]) => Promise<void>;
|
|
250
|
+
}, {
|
|
251
|
+
getItem: (args_0: string, ...args_1: unknown[]) => Promise<any>;
|
|
252
|
+
setItem: (args_0: string, args_1: any, ...args_2: unknown[]) => Promise<void>;
|
|
253
|
+
removeItem: (args_0: string, ...args_1: unknown[]) => Promise<void>;
|
|
254
|
+
}>, z.ZodNull]>>;
|
|
255
|
+
/** Whether to use Web Workers for ZK proof generation (web platform only) */
|
|
256
|
+
useWorkers: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
257
|
+
/** Mocks configs */
|
|
258
|
+
mocks: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
259
|
+
sealOutputDelay: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
260
|
+
}, "strip", z.ZodTypeAny, {
|
|
261
|
+
sealOutputDelay: number;
|
|
262
|
+
}, {
|
|
263
|
+
sealOutputDelay?: number | undefined;
|
|
264
|
+
}>>>;
|
|
265
|
+
/** Internal configuration */
|
|
266
|
+
_internal: z.ZodOptional<z.ZodObject<{
|
|
267
|
+
zkvWalletClient: z.ZodOptional<z.ZodAny>;
|
|
268
|
+
}, "strip", z.ZodTypeAny, {
|
|
269
|
+
zkvWalletClient?: any;
|
|
270
|
+
}, {
|
|
271
|
+
zkvWalletClient?: any;
|
|
272
|
+
}>>;
|
|
273
|
+
}, "strip", z.ZodTypeAny, {
|
|
274
|
+
environment: "hardhat" | "node" | "web" | "react";
|
|
275
|
+
supportedChains: {
|
|
276
|
+
name: string;
|
|
277
|
+
id: number;
|
|
278
|
+
network: string;
|
|
279
|
+
coFheUrl: string;
|
|
280
|
+
verifierUrl: string;
|
|
281
|
+
thresholdNetworkUrl: string;
|
|
282
|
+
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
283
|
+
}[];
|
|
284
|
+
permitGeneration: "ON_CONNECT" | "ON_DECRYPT_HANDLES" | "MANUAL";
|
|
285
|
+
defaultPermitExpiration: number;
|
|
286
|
+
fheKeyStorage: {
|
|
287
|
+
getItem: (args_0: string, ...args_1: unknown[]) => Promise<any>;
|
|
288
|
+
setItem: (args_0: string, args_1: any, ...args_2: unknown[]) => Promise<void>;
|
|
289
|
+
removeItem: (args_0: string, ...args_1: unknown[]) => Promise<void>;
|
|
290
|
+
} | null;
|
|
291
|
+
useWorkers: boolean;
|
|
292
|
+
mocks: {
|
|
293
|
+
sealOutputDelay: number;
|
|
294
|
+
};
|
|
295
|
+
_internal?: {
|
|
296
|
+
zkvWalletClient?: any;
|
|
297
|
+
} | undefined;
|
|
298
|
+
}, {
|
|
299
|
+
supportedChains: {
|
|
300
|
+
name: string;
|
|
301
|
+
id: number;
|
|
302
|
+
network: string;
|
|
303
|
+
coFheUrl: string;
|
|
304
|
+
verifierUrl: string;
|
|
305
|
+
thresholdNetworkUrl: string;
|
|
306
|
+
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
307
|
+
}[];
|
|
308
|
+
environment?: "hardhat" | "node" | "web" | "react" | undefined;
|
|
309
|
+
permitGeneration?: "ON_CONNECT" | "ON_DECRYPT_HANDLES" | "MANUAL" | undefined;
|
|
310
|
+
defaultPermitExpiration?: number | undefined;
|
|
311
|
+
fheKeyStorage?: {
|
|
312
|
+
getItem: (args_0: string, ...args_1: unknown[]) => Promise<any>;
|
|
313
|
+
setItem: (args_0: string, args_1: any, ...args_2: unknown[]) => Promise<void>;
|
|
314
|
+
removeItem: (args_0: string, ...args_1: unknown[]) => Promise<void>;
|
|
315
|
+
} | null | undefined;
|
|
316
|
+
useWorkers?: boolean | undefined;
|
|
317
|
+
mocks?: {
|
|
318
|
+
sealOutputDelay?: number | undefined;
|
|
319
|
+
} | undefined;
|
|
320
|
+
_internal?: {
|
|
321
|
+
zkvWalletClient?: any;
|
|
322
|
+
} | undefined;
|
|
323
|
+
}>;
|
|
324
|
+
/**
|
|
325
|
+
* Input config type inferred from the schema
|
|
326
|
+
*/
|
|
327
|
+
type CofhesdkInputConfig = z.input<typeof CofhesdkConfigSchema>;
|
|
328
|
+
/**
|
|
329
|
+
* Creates and validates a cofhesdk configuration (base implementation)
|
|
330
|
+
* @param config - The configuration object to validate
|
|
331
|
+
* @returns The validated configuration
|
|
332
|
+
* @throws {Error} If the configuration is invalid
|
|
333
|
+
*/
|
|
334
|
+
declare function createCofhesdkConfigBase(config: CofhesdkInputConfig): CofhesdkConfig;
|
|
335
|
+
/**
|
|
336
|
+
* Access the CofhesdkConfig object directly by providing the key.
|
|
337
|
+
* This is powerful when you use OnchainKit utilities outside of the React context.
|
|
338
|
+
*/
|
|
339
|
+
declare const getCofhesdkConfigItem: <K extends keyof CofhesdkConfig>(config: CofhesdkConfig, key: K) => CofhesdkConfig[K];
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Base parameters that all builders need
|
|
343
|
+
*/
|
|
344
|
+
type BaseBuilderParams = {
|
|
345
|
+
config: CofhesdkConfig | undefined;
|
|
346
|
+
publicClient: PublicClient | undefined;
|
|
347
|
+
walletClient: WalletClient | undefined;
|
|
348
|
+
chainId: number | undefined;
|
|
349
|
+
account: string | undefined;
|
|
350
|
+
requireConnected: (() => void) | undefined;
|
|
351
|
+
};
|
|
352
|
+
/**
|
|
353
|
+
* Abstract base class for builders that provides common functionality
|
|
354
|
+
* for working with clients, config, and chain IDs
|
|
355
|
+
*/
|
|
356
|
+
declare abstract class BaseBuilder {
|
|
357
|
+
protected config: CofhesdkConfig;
|
|
358
|
+
protected publicClient: PublicClient | undefined;
|
|
359
|
+
protected walletClient: WalletClient | undefined;
|
|
360
|
+
protected chainId: number | undefined;
|
|
361
|
+
protected account: string | undefined;
|
|
362
|
+
constructor(params: BaseBuilderParams);
|
|
363
|
+
/**
|
|
364
|
+
* Asserts that this.chainId is populated
|
|
365
|
+
* @throws {CofhesdkError} If chainId is not set
|
|
366
|
+
*/
|
|
367
|
+
protected assertChainId(): asserts this is this & {
|
|
368
|
+
chainId: number;
|
|
369
|
+
};
|
|
370
|
+
/**
|
|
371
|
+
* Asserts that this.account is populated
|
|
372
|
+
* @throws {CofhesdkError} If account is not set
|
|
373
|
+
*/
|
|
374
|
+
protected assertAccount(): asserts this is this & {
|
|
375
|
+
account: string;
|
|
376
|
+
};
|
|
377
|
+
/**
|
|
378
|
+
* Asserts that this.publicClient is populated
|
|
379
|
+
* @throws {CofhesdkError} If publicClient is not set
|
|
380
|
+
*/
|
|
381
|
+
protected assertPublicClient(): asserts this is this & {
|
|
382
|
+
publicClient: PublicClient;
|
|
383
|
+
};
|
|
384
|
+
/**
|
|
385
|
+
* Asserts that this.walletClient is populated
|
|
386
|
+
* @throws {CofhesdkError} If walletClient is not set
|
|
387
|
+
*/
|
|
388
|
+
protected assertWalletClient(): asserts this is this & {
|
|
389
|
+
walletClient: WalletClient;
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* API
|
|
395
|
+
*
|
|
396
|
+
* await client.decryptHandle(ctHash, utype)
|
|
397
|
+
* .setChainId(chainId)
|
|
398
|
+
* .setAccount(account)
|
|
399
|
+
* .setPermitHash(permitHash)
|
|
400
|
+
* .setPermit(permit)
|
|
401
|
+
* .decrypt()
|
|
402
|
+
*
|
|
403
|
+
* If chainId not set, uses client's chainId
|
|
404
|
+
* If account not set, uses client's account
|
|
405
|
+
* If permitHash not set, uses chainId and account to get active permit
|
|
406
|
+
* If permit is set, uses permit to decrypt regardless of chainId, account, or permitHash
|
|
407
|
+
*
|
|
408
|
+
* Returns the unsealed item.
|
|
409
|
+
*/
|
|
410
|
+
type DecryptHandlesBuilderParams<U extends FheTypes> = BaseBuilderParams & {
|
|
411
|
+
ctHash: bigint;
|
|
412
|
+
utype: U;
|
|
413
|
+
permitHash?: string;
|
|
414
|
+
permit?: Permit;
|
|
415
|
+
};
|
|
416
|
+
declare class DecryptHandlesBuilder<U extends FheTypes> extends BaseBuilder {
|
|
417
|
+
private ctHash;
|
|
418
|
+
private utype;
|
|
419
|
+
private permitHash?;
|
|
420
|
+
private permit?;
|
|
421
|
+
constructor(params: DecryptHandlesBuilderParams<U>);
|
|
422
|
+
/**
|
|
423
|
+
* @param chainId - Chain to decrypt values from. Used to fetch the threshold network URL and use the correct permit.
|
|
424
|
+
*
|
|
425
|
+
* If not provided, the chainId will be fetched from the connected publicClient.
|
|
426
|
+
*
|
|
427
|
+
* Example:
|
|
428
|
+
* ```typescript
|
|
429
|
+
* const unsealed = await decryptHandle(ctHash, utype)
|
|
430
|
+
* .setChainId(11155111)
|
|
431
|
+
* .decrypt();
|
|
432
|
+
* ```
|
|
433
|
+
*
|
|
434
|
+
* @returns The chainable DecryptHandlesBuilder instance.
|
|
435
|
+
*/
|
|
436
|
+
setChainId(chainId: number): DecryptHandlesBuilder<U>;
|
|
437
|
+
getChainId(): number | undefined;
|
|
438
|
+
/**
|
|
439
|
+
* @param account - Account to decrypt values from. Used to fetch the correct permit.
|
|
440
|
+
*
|
|
441
|
+
* If not provided, the account will be fetched from the connected walletClient.
|
|
442
|
+
*
|
|
443
|
+
* Example:
|
|
444
|
+
* ```typescript
|
|
445
|
+
* const unsealed = await decryptHandle(ctHash, utype)
|
|
446
|
+
* .setAccount('0x1234567890123456789012345678901234567890')
|
|
447
|
+
* .decrypt();
|
|
448
|
+
* ```
|
|
449
|
+
*
|
|
450
|
+
* @returns The chainable DecryptHandlesBuilder instance.
|
|
451
|
+
*/
|
|
452
|
+
setAccount(account: string): DecryptHandlesBuilder<U>;
|
|
453
|
+
getAccount(): string | undefined;
|
|
454
|
+
/**
|
|
455
|
+
* @param permitHash - Permit hash to decrypt values from. Used to fetch the correct permit.
|
|
456
|
+
*
|
|
457
|
+
* If not provided, the active permit for the chainId and account will be used.
|
|
458
|
+
* If `setPermit()` is called, it will be used regardless of chainId, account, or permitHash.
|
|
459
|
+
*
|
|
460
|
+
* Example:
|
|
461
|
+
* ```typescript
|
|
462
|
+
* const unsealed = await decryptHandle(ctHash, utype)
|
|
463
|
+
* .setPermitHash('0x1234567890123456789012345678901234567890')
|
|
464
|
+
* .decrypt();
|
|
465
|
+
* ```
|
|
466
|
+
*
|
|
467
|
+
* @returns The chainable DecryptHandlesBuilder instance.
|
|
468
|
+
*/
|
|
469
|
+
setPermitHash(permitHash: string): DecryptHandlesBuilder<U>;
|
|
470
|
+
getPermitHash(): string | undefined;
|
|
471
|
+
/**
|
|
472
|
+
* @param permit - Permit to decrypt values with. If provided, it will be used regardless of chainId, account, or permitHash.
|
|
473
|
+
*
|
|
474
|
+
* If not provided, the permit will be determined by chainId, account, and permitHash.
|
|
475
|
+
*
|
|
476
|
+
* Example:
|
|
477
|
+
* ```typescript
|
|
478
|
+
* const unsealed = await decryptHandle(ctHash, utype)
|
|
479
|
+
* .setPermit(permit)
|
|
480
|
+
* .decrypt();
|
|
481
|
+
* ```
|
|
482
|
+
*
|
|
483
|
+
* @returns The chainable DecryptHandlesBuilder instance.
|
|
484
|
+
*/
|
|
485
|
+
setPermit(permit: Permit): DecryptHandlesBuilder<U>;
|
|
486
|
+
getPermit(): Permit | undefined;
|
|
487
|
+
private getThresholdNetworkUrl;
|
|
488
|
+
private validateUtypeOrThrow;
|
|
489
|
+
private getResolvedPermit;
|
|
490
|
+
/**
|
|
491
|
+
* On hardhat, interact with MockZkVerifier contract instead of CoFHE
|
|
492
|
+
*/
|
|
493
|
+
private mocksSealOutput;
|
|
494
|
+
/**
|
|
495
|
+
* In the production context, perform a true decryption with the CoFHE coprocessor.
|
|
496
|
+
*/
|
|
497
|
+
private productionSealOutput;
|
|
498
|
+
/**
|
|
499
|
+
* Final step of the decryption process. MUST BE CALLED LAST IN THE CHAIN.
|
|
500
|
+
*
|
|
501
|
+
* This will:
|
|
502
|
+
* - Use a permit based on provided permit OR chainId + account + permitHash
|
|
503
|
+
* - Check permit validity
|
|
504
|
+
* - Call CoFHE `/sealoutput` with the permit, which returns a sealed (encrypted) item
|
|
505
|
+
* - Unseal the sealed item with the permit
|
|
506
|
+
* - Return the unsealed item
|
|
507
|
+
*
|
|
508
|
+
* Example:
|
|
509
|
+
* ```typescript
|
|
510
|
+
* const unsealed = await decryptHandle(ctHash, utype)
|
|
511
|
+
* .setChainId(11155111) // optional
|
|
512
|
+
* .setAccount('0x123...890') // optional
|
|
513
|
+
* .decrypt(); // execute
|
|
514
|
+
* ```
|
|
515
|
+
*
|
|
516
|
+
* @returns The unsealed item.
|
|
517
|
+
*/
|
|
518
|
+
decrypt(): Promise<UnsealedItem<U>>;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Worker function type for ZK proof generation
|
|
523
|
+
* Platform-specific implementations (web) can provide this to enable worker-based proofs
|
|
524
|
+
*/
|
|
525
|
+
type ZkProveWorkerFunction = (fheKeyHex: string, crsHex: string, items: EncryptableItem[], metadata: Uint8Array) => Promise<Uint8Array>;
|
|
526
|
+
/**
|
|
527
|
+
* Message sent from main thread to worker to request proof generation
|
|
528
|
+
*/
|
|
529
|
+
interface ZkProveWorkerRequest {
|
|
530
|
+
id: string;
|
|
531
|
+
type: 'zkProve';
|
|
532
|
+
fheKeyHex: string;
|
|
533
|
+
crsHex: string;
|
|
534
|
+
items: Array<{
|
|
535
|
+
utype: string;
|
|
536
|
+
data: any;
|
|
537
|
+
}>;
|
|
538
|
+
metadata: number[];
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Message sent from worker back to main thread with proof result
|
|
542
|
+
*/
|
|
543
|
+
interface ZkProveWorkerResponse {
|
|
544
|
+
id: string;
|
|
545
|
+
type: 'success' | 'error' | 'ready';
|
|
546
|
+
result?: number[];
|
|
547
|
+
error?: string;
|
|
548
|
+
}
|
|
549
|
+
type ZkProvenCiphertextList = {
|
|
550
|
+
serialize(): Uint8Array;
|
|
551
|
+
};
|
|
552
|
+
type ZkCompactPkeCrs = {
|
|
553
|
+
free(): void;
|
|
554
|
+
serialize(compress: boolean): Uint8Array;
|
|
555
|
+
safe_serialize(serialized_size_limit: bigint): Uint8Array;
|
|
556
|
+
};
|
|
557
|
+
type ZkCiphertextListBuilder = {
|
|
558
|
+
push_boolean(data: boolean): void;
|
|
559
|
+
push_u8(data: number): void;
|
|
560
|
+
push_u16(data: number): void;
|
|
561
|
+
push_u32(data: number): void;
|
|
562
|
+
push_u64(data: bigint): void;
|
|
563
|
+
push_u128(data: bigint): void;
|
|
564
|
+
push_u160(data: bigint): void;
|
|
565
|
+
build_with_proof_packed(crs: ZkCompactPkeCrs, metadata: Uint8Array, computeLoad: 1): ZkProvenCiphertextList;
|
|
566
|
+
};
|
|
567
|
+
type ZkBuilderAndCrsGenerator = (fhe: string, crs: string) => {
|
|
568
|
+
zkBuilder: ZkCiphertextListBuilder;
|
|
569
|
+
zkCrs: ZkCompactPkeCrs;
|
|
570
|
+
};
|
|
571
|
+
/**
|
|
572
|
+
* Generates ZK proof using Web Worker (offloads heavy WASM computation)
|
|
573
|
+
* Serializes items and calls the platform-specific worker function
|
|
574
|
+
* @param workerFn - Platform-specific worker function (provided by web/index.ts)
|
|
575
|
+
* @param fheKeyHex - Hex-encoded FHE public key for worker deserialization
|
|
576
|
+
* @param crsHex - Hex-encoded CRS for worker deserialization
|
|
577
|
+
* @param items - Encryptable items to pack in the worker
|
|
578
|
+
* @param metadata - Pre-constructed ZK PoK metadata
|
|
579
|
+
* @returns The serialized proven ciphertext list
|
|
580
|
+
*/
|
|
581
|
+
declare const zkProveWithWorker: (workerFn: ZkProveWorkerFunction, fheKeyHex: string, crsHex: string, items: EncryptableItem[], metadata: Uint8Array) => Promise<Uint8Array>;
|
|
582
|
+
|
|
583
|
+
type ChainRecord<T> = Record<string, T>;
|
|
584
|
+
type SecurityZoneRecord<T> = Record<number, T>;
|
|
585
|
+
type KeysStore = {
|
|
586
|
+
fhe: ChainRecord<SecurityZoneRecord<string | undefined>>;
|
|
587
|
+
crs: ChainRecord<string | undefined>;
|
|
588
|
+
};
|
|
589
|
+
type KeysStorage = {
|
|
590
|
+
store: StoreApi<KeysStore>;
|
|
591
|
+
getFheKey: (chainId: number | undefined, securityZone?: number) => string | undefined;
|
|
592
|
+
getCrs: (chainId: number | undefined) => string | undefined;
|
|
593
|
+
setFheKey: (chainId: number, securityZone: number, key: string) => void;
|
|
594
|
+
setCrs: (chainId: number, crs: string) => void;
|
|
595
|
+
clearKeysStorage: () => Promise<void>;
|
|
596
|
+
rehydrateKeysStore: () => Promise<void>;
|
|
597
|
+
};
|
|
598
|
+
/**
|
|
599
|
+
* Creates a keys storage instance using the provided storage implementation
|
|
600
|
+
* @param storage - The storage implementation to use (IStorage interface), or null for non-persisted store
|
|
601
|
+
* @returns A KeysStorage instance with all utility methods
|
|
602
|
+
*/
|
|
603
|
+
declare function createKeysStore(storage: IStorage | null): KeysStorage;
|
|
604
|
+
|
|
605
|
+
type FheKeyDeserializer = (buff: string) => void;
|
|
606
|
+
/**
|
|
607
|
+
* Retrieves the FHE public key and the CRS from the provider.
|
|
608
|
+
* If the key/crs already exists in the store it is returned, else it is fetched, stored, and returned
|
|
609
|
+
* @param {CofhesdkConfig} config - The configuration object for the CoFHE SDK
|
|
610
|
+
* @param {number} chainId - The chain to fetch the FHE key for, if no chainId provided, undefined is returned
|
|
611
|
+
* @param securityZone - The security zone for which to retrieve the key (default 0).
|
|
612
|
+
* @param tfhePublicKeyDeserializer - The serializer for the FHE public key (used for validation).
|
|
613
|
+
* @param compactPkeCrsDeserializer - The serializer for the CRS (used for validation).
|
|
614
|
+
* @param keysStorage - The keys storage instance to use (optional)
|
|
615
|
+
* @returns {Promise<[[string, boolean], [string, boolean]]>} - A promise that resolves to [[fheKey, fheKeyFetchedFromCoFHE], [crs, crsFetchedFromCoFHE]]
|
|
616
|
+
*/
|
|
617
|
+
declare const fetchKeys: (config: CofhesdkConfig, chainId: number, securityZone: number | undefined, tfhePublicKeyDeserializer: FheKeyDeserializer, compactPkeCrsDeserializer: FheKeyDeserializer, keysStorage?: KeysStorage | null) => Promise<[[string, boolean], [string, boolean]]>;
|
|
618
|
+
|
|
619
|
+
type EncryptInputsBuilderParams<T extends EncryptableItem[]> = BaseBuilderParams & {
|
|
620
|
+
inputs: [...T];
|
|
621
|
+
securityZone?: number;
|
|
622
|
+
zkvWalletClient?: WalletClient | undefined;
|
|
623
|
+
tfhePublicKeyDeserializer: FheKeyDeserializer | undefined;
|
|
624
|
+
compactPkeCrsDeserializer: FheKeyDeserializer | undefined;
|
|
625
|
+
zkBuilderAndCrsGenerator: ZkBuilderAndCrsGenerator | undefined;
|
|
626
|
+
initTfhe: TfheInitializer | undefined;
|
|
627
|
+
zkProveWorkerFn: ZkProveWorkerFunction | undefined;
|
|
628
|
+
keysStorage: KeysStorage | undefined;
|
|
629
|
+
};
|
|
630
|
+
/**
|
|
631
|
+
* EncryptInputsBuilder exposes a builder pattern for encrypting inputs.
|
|
632
|
+
* account, securityZone, and chainId can be overridden in the builder.
|
|
633
|
+
* config, tfhePublicKeyDeserializer, compactPkeCrsDeserializer, and zkBuilderAndCrsGenerator are required to be set in the builder.
|
|
634
|
+
*/
|
|
635
|
+
declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuilder {
|
|
636
|
+
private securityZone;
|
|
637
|
+
private stepCallback?;
|
|
638
|
+
private inputItems;
|
|
639
|
+
private zkvWalletClient;
|
|
640
|
+
private tfhePublicKeyDeserializer;
|
|
641
|
+
private compactPkeCrsDeserializer;
|
|
642
|
+
private zkBuilderAndCrsGenerator;
|
|
643
|
+
private initTfhe;
|
|
644
|
+
private zkProveWorkerFn;
|
|
645
|
+
private keysStorage;
|
|
646
|
+
private useWorker;
|
|
647
|
+
private stepTimestamps;
|
|
648
|
+
constructor(params: EncryptInputsBuilderParams<T>);
|
|
649
|
+
/**
|
|
650
|
+
* @param account - Account that will create the tx using the encrypted inputs.
|
|
651
|
+
*
|
|
652
|
+
* If not provided, the account will be fetched from the connected walletClient.
|
|
653
|
+
*
|
|
654
|
+
* Example:
|
|
655
|
+
* ```typescript
|
|
656
|
+
* const encrypted = await encryptInputs([Encryptable.uint128(10n)])
|
|
657
|
+
* .setAccount("0x123")
|
|
658
|
+
* .encrypt();
|
|
659
|
+
* ```
|
|
660
|
+
*
|
|
661
|
+
* @returns The chainable EncryptInputsBuilder instance.
|
|
662
|
+
*/
|
|
663
|
+
setAccount(account: string): EncryptInputsBuilder<T>;
|
|
664
|
+
getAccount(): string | undefined;
|
|
665
|
+
/**
|
|
666
|
+
* @param chainId - Chain that will consume the encrypted inputs.
|
|
667
|
+
*
|
|
668
|
+
* If not provided, the chainId will be fetched from the connected publicClient.
|
|
669
|
+
*
|
|
670
|
+
* Example:
|
|
671
|
+
* ```typescript
|
|
672
|
+
* const encrypted = await encryptInputs([Encryptable.uint128(10n)])
|
|
673
|
+
* .setChainId(11155111)
|
|
674
|
+
* .encrypt();
|
|
675
|
+
* ```
|
|
676
|
+
*
|
|
677
|
+
* @returns The chainable EncryptInputsBuilder instance.
|
|
678
|
+
*/
|
|
679
|
+
setChainId(chainId: number): EncryptInputsBuilder<T>;
|
|
680
|
+
getChainId(): number | undefined;
|
|
681
|
+
/**
|
|
682
|
+
* @param securityZone - Security zone to encrypt the inputs for.
|
|
683
|
+
*
|
|
684
|
+
* If not provided, the default securityZone 0 will be used.
|
|
685
|
+
*
|
|
686
|
+
* Example:
|
|
687
|
+
* ```typescript
|
|
688
|
+
* const encrypted = await encryptInputs([Encryptable.uint128(10n)])
|
|
689
|
+
* .setSecurityZone(1)
|
|
690
|
+
* .encrypt();
|
|
691
|
+
* ```
|
|
692
|
+
*
|
|
693
|
+
* @returns The chainable EncryptInputsBuilder instance.
|
|
694
|
+
*/
|
|
695
|
+
setSecurityZone(securityZone: number): EncryptInputsBuilder<T>;
|
|
696
|
+
getSecurityZone(): number;
|
|
697
|
+
/**
|
|
698
|
+
* @param useWorker - Whether to use Web Workers for ZK proof generation.
|
|
699
|
+
*
|
|
700
|
+
* Overrides the config-level useWorkers setting for this specific encryption.
|
|
701
|
+
*
|
|
702
|
+
* Example:
|
|
703
|
+
* ```typescript
|
|
704
|
+
* const encrypted = await encryptInputs([Encryptable.uint128(10n)])
|
|
705
|
+
* .setUseWorker(false)
|
|
706
|
+
* .encrypt();
|
|
707
|
+
* ```
|
|
708
|
+
*
|
|
709
|
+
* @returns The chainable EncryptInputsBuilder instance.
|
|
710
|
+
*/
|
|
711
|
+
setUseWorker(useWorker: boolean): EncryptInputsBuilder<T>;
|
|
712
|
+
/**
|
|
713
|
+
* Gets the current worker configuration.
|
|
714
|
+
*
|
|
715
|
+
* @returns Whether Web Workers are enabled for this encryption.
|
|
716
|
+
*
|
|
717
|
+
* Example:
|
|
718
|
+
* ```typescript
|
|
719
|
+
* const builder = encryptInputs([Encryptable.uint128(10n)]);
|
|
720
|
+
* console.log(builder.getUseWorker()); // true (from config)
|
|
721
|
+
* builder.setUseWorker(false);
|
|
722
|
+
* console.log(builder.getUseWorker()); // false (overridden)
|
|
723
|
+
* ```
|
|
724
|
+
*/
|
|
725
|
+
getUseWorker(): boolean;
|
|
726
|
+
/**
|
|
727
|
+
* @param callback - Function to be called with the encryption step.
|
|
728
|
+
*
|
|
729
|
+
* Useful for debugging and tracking the progress of the encryption process.
|
|
730
|
+
* Useful for a UI element that shows the progress of the encryption process.
|
|
731
|
+
*
|
|
732
|
+
* Example:
|
|
733
|
+
* ```typescript
|
|
734
|
+
* const encrypted = await encryptInputs([Encryptable.uint128(10n)])
|
|
735
|
+
* .setStepCallback((step: EncryptStep) => console.log(step))
|
|
736
|
+
* .encrypt();
|
|
737
|
+
* ```
|
|
738
|
+
*
|
|
739
|
+
* @returns The EncryptInputsBuilder instance.
|
|
740
|
+
*/
|
|
741
|
+
setStepCallback(callback: EncryptStepCallbackFunction): EncryptInputsBuilder<T>;
|
|
742
|
+
getStepCallback(): EncryptStepCallbackFunction | undefined;
|
|
743
|
+
/**
|
|
744
|
+
* Fires the step callback if set
|
|
745
|
+
*/
|
|
746
|
+
private fireStepStart;
|
|
747
|
+
private fireStepEnd;
|
|
748
|
+
/**
|
|
749
|
+
* zkVerifierUrl is included in the chains exported from cofhesdk/chains for use in CofhesdkConfig.supportedChains
|
|
750
|
+
* Users should generally not set this manually.
|
|
751
|
+
*/
|
|
752
|
+
private getZkVerifierUrl;
|
|
753
|
+
/**
|
|
754
|
+
* initTfhe is a platform-specific dependency injected into core/createCofhesdkClientBase by web/createCofhesdkClient and node/createCofhesdkClient
|
|
755
|
+
* web/ uses zama "tfhe"
|
|
756
|
+
* node/ uses zama "node-tfhe"
|
|
757
|
+
* Users should not set this manually.
|
|
758
|
+
*/
|
|
759
|
+
private initTfheOrThrow;
|
|
760
|
+
/**
|
|
761
|
+
* Fetches the FHE key and CRS from the CoFHE API
|
|
762
|
+
* If the key/crs already exists in the store it is returned, else it is fetched, stored, and returned
|
|
763
|
+
*/
|
|
764
|
+
private fetchFheKeyAndCrs;
|
|
765
|
+
/**
|
|
766
|
+
* @dev Encrypt against the cofheMocks instead of CoFHE
|
|
767
|
+
*
|
|
768
|
+
* In the cofheMocks, the MockZkVerifier contract is deployed on hardhat to a fixed address, this contract handles mocking the zk verifying.
|
|
769
|
+
* cofheMocksInsertPackedHashes - stores the ctHashes and their plaintext values for on-chain mocking of FHE operations.
|
|
770
|
+
* cofheMocksZkCreateProofSignatures - creates signatures to be included in the encrypted inputs. The signers address is known and verified in the mock contracts.
|
|
771
|
+
*/
|
|
772
|
+
private mocksEncrypt;
|
|
773
|
+
/**
|
|
774
|
+
* In the production context, perform a true encryption with the CoFHE coprocessor.
|
|
775
|
+
*/
|
|
776
|
+
private productionEncrypt;
|
|
777
|
+
/**
|
|
778
|
+
* Final step of the encryption process. MUST BE CALLED LAST IN THE CHAIN.
|
|
779
|
+
*
|
|
780
|
+
* This will:
|
|
781
|
+
* - Pack the encryptable items into a zk proof
|
|
782
|
+
* - Prove the zk proof
|
|
783
|
+
* - Verify the zk proof with CoFHE
|
|
784
|
+
* - Package and return the encrypted inputs
|
|
785
|
+
*
|
|
786
|
+
* Example:
|
|
787
|
+
* ```typescript
|
|
788
|
+
* const encrypted = await encryptInputs([Encryptable.uint128(10n)])
|
|
789
|
+
* .setAccount('0x123...890') // optional
|
|
790
|
+
* .setChainId(11155111) // optional
|
|
791
|
+
* .encrypt(); // execute
|
|
792
|
+
* ```
|
|
793
|
+
*
|
|
794
|
+
* @returns The encrypted inputs.
|
|
795
|
+
*/
|
|
796
|
+
encrypt(): Promise<[...EncryptedItemInputs<T>]>;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
declare const permits: {
|
|
800
|
+
getSnapshot: () => {
|
|
801
|
+
permits: {
|
|
802
|
+
[x: number]: {
|
|
803
|
+
[x: string]: {
|
|
804
|
+
[x: string]: SerializedPermit | undefined;
|
|
805
|
+
};
|
|
806
|
+
};
|
|
807
|
+
};
|
|
808
|
+
activePermitHash: {
|
|
809
|
+
[x: number]: {
|
|
810
|
+
[x: string]: string | undefined;
|
|
811
|
+
};
|
|
812
|
+
};
|
|
813
|
+
};
|
|
814
|
+
subscribe: (listener: (state: {
|
|
815
|
+
permits: {
|
|
816
|
+
[x: number]: {
|
|
817
|
+
[x: string]: {
|
|
818
|
+
[x: string]: SerializedPermit | undefined;
|
|
819
|
+
};
|
|
820
|
+
};
|
|
821
|
+
};
|
|
822
|
+
activePermitHash: {
|
|
823
|
+
[x: number]: {
|
|
824
|
+
[x: string]: string | undefined;
|
|
825
|
+
};
|
|
826
|
+
};
|
|
827
|
+
}, prevState: {
|
|
828
|
+
permits: {
|
|
829
|
+
[x: number]: {
|
|
830
|
+
[x: string]: {
|
|
831
|
+
[x: string]: SerializedPermit | undefined;
|
|
832
|
+
};
|
|
833
|
+
};
|
|
834
|
+
};
|
|
835
|
+
activePermitHash: {
|
|
836
|
+
[x: number]: {
|
|
837
|
+
[x: string]: string | undefined;
|
|
838
|
+
};
|
|
839
|
+
};
|
|
840
|
+
}) => void) => () => void;
|
|
841
|
+
createSelf: (options: CreateSelfPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SelfPermit>;
|
|
842
|
+
createSharing: (options: CreateSharingPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SharingPermit>;
|
|
843
|
+
importShared: (options: ImportSharedPermitOptions | string, publicClient: PublicClient, walletClient: WalletClient) => Promise<RecipientPermit>;
|
|
844
|
+
getOrCreateSelfPermit: (publicClient: PublicClient, walletClient: WalletClient, chainId?: number, account?: string, options?: CreateSelfPermitOptions) => Promise<Permit>;
|
|
845
|
+
getOrCreateSharingPermit: (publicClient: PublicClient, walletClient: WalletClient, options: CreateSharingPermitOptions, chainId?: number, account?: string) => Promise<Permit>;
|
|
846
|
+
getHash: (permit: Permit) => string;
|
|
847
|
+
serialize: (permit: Permit) => SerializedPermit;
|
|
848
|
+
deserialize: (serialized: SerializedPermit) => Permit;
|
|
849
|
+
getPermit: (chainId: number, account: string, hash: string) => Promise<Permit | undefined>;
|
|
850
|
+
getPermits: (chainId: number, account: string) => Promise<Record<string, Permit>>;
|
|
851
|
+
getActivePermit: (chainId: number, account: string) => Promise<Permit | undefined>;
|
|
852
|
+
getActivePermitHash: (chainId: number, account: string) => string | undefined;
|
|
853
|
+
removePermit: (chainId: number, account: string, hash: string, force?: boolean) => Promise<void>;
|
|
854
|
+
selectActivePermit: (chainId: number, account: string, hash: string) => void;
|
|
855
|
+
removeActivePermit: (chainId: number, account: string) => Promise<void>;
|
|
856
|
+
};
|
|
857
|
+
|
|
858
|
+
type CofhesdkClient<TConfig extends CofhesdkConfig = CofhesdkConfig> = {
|
|
859
|
+
getSnapshot(): CofhesdkClientConnectionState;
|
|
860
|
+
subscribe(listener: Listener): () => void;
|
|
861
|
+
readonly connected: boolean;
|
|
862
|
+
readonly connecting: boolean;
|
|
863
|
+
readonly config: TConfig;
|
|
864
|
+
connect(publicClient: PublicClient, walletClient: WalletClient): Promise<void>;
|
|
865
|
+
/**
|
|
866
|
+
* Types docstring
|
|
867
|
+
*/
|
|
868
|
+
encryptInputs<T extends EncryptableItem[]>(inputs: [...T]): EncryptInputsBuilder<[...T]>;
|
|
869
|
+
decryptHandle<U extends FheTypes>(ctHash: bigint, utype: U): DecryptHandlesBuilder<U>;
|
|
870
|
+
permits: CofhesdkClientPermits;
|
|
871
|
+
};
|
|
872
|
+
type CofhesdkClientConnectionState = {
|
|
873
|
+
connected: boolean;
|
|
874
|
+
connecting: boolean;
|
|
875
|
+
connectError: unknown | undefined;
|
|
876
|
+
chainId: number | undefined;
|
|
877
|
+
account: `0x${string}` | undefined;
|
|
878
|
+
publicClient: PublicClient | undefined;
|
|
879
|
+
walletClient: WalletClient | undefined;
|
|
880
|
+
};
|
|
881
|
+
type Listener = (snapshot: CofhesdkClientConnectionState) => void;
|
|
882
|
+
type CofhesdkClientPermitsClients = {
|
|
883
|
+
publicClient: PublicClient;
|
|
884
|
+
walletClient: WalletClient;
|
|
885
|
+
};
|
|
886
|
+
type CofhesdkClientPermits = {
|
|
887
|
+
getSnapshot: typeof permits.getSnapshot;
|
|
888
|
+
subscribe: typeof permits.subscribe;
|
|
889
|
+
createSelf: (options: CreateSelfPermitOptions, clients?: CofhesdkClientPermitsClients) => Promise<SelfPermit>;
|
|
890
|
+
createSharing: (options: CreateSharingPermitOptions, clients?: CofhesdkClientPermitsClients) => Promise<SharingPermit>;
|
|
891
|
+
importShared: (options: ImportSharedPermitOptions | string, clients?: CofhesdkClientPermitsClients) => Promise<RecipientPermit>;
|
|
892
|
+
getPermit: (hash: string, chainId?: number, account?: string) => Promise<Permit | undefined>;
|
|
893
|
+
getPermits: (chainId?: number, account?: string) => Promise<Record<string, Permit>>;
|
|
894
|
+
getActivePermit: (chainId?: number, account?: string) => Promise<Permit | undefined>;
|
|
895
|
+
getActivePermitHash: (chainId?: number, account?: string) => Promise<string | undefined>;
|
|
896
|
+
getOrCreateSelfPermit: (chainId?: number, account?: string, options?: CreateSelfPermitOptions) => Promise<Permit>;
|
|
897
|
+
getOrCreateSharingPermit: (options: CreateSharingPermitOptions, chainId?: number, account?: string) => Promise<Permit>;
|
|
898
|
+
selectActivePermit: (hash: string, chainId?: number, account?: string) => void;
|
|
899
|
+
removePermit: (hash: string, chainId?: number, account?: string, force?: boolean) => void;
|
|
900
|
+
removeActivePermit: (chainId?: number, account?: string) => void;
|
|
901
|
+
getHash: typeof PermitUtils.getHash;
|
|
902
|
+
serialize: typeof PermitUtils.serialize;
|
|
903
|
+
deserialize: typeof PermitUtils.deserialize;
|
|
904
|
+
};
|
|
905
|
+
type CofhesdkClientParams<TConfig extends CofhesdkConfig> = {
|
|
906
|
+
config: TConfig;
|
|
907
|
+
zkBuilderAndCrsGenerator: ZkBuilderAndCrsGenerator;
|
|
908
|
+
tfhePublicKeyDeserializer: FheKeyDeserializer;
|
|
909
|
+
compactPkeCrsDeserializer: FheKeyDeserializer;
|
|
910
|
+
initTfhe: TfheInitializer;
|
|
911
|
+
zkProveWorkerFn?: ZkProveWorkerFunction;
|
|
912
|
+
};
|
|
913
|
+
|
|
914
|
+
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 };
|