@cofhe/sdk 0.1.1 → 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 +14 -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/index.ts +3 -1
- package/core/baseBuilder.ts +30 -49
- package/core/client.test.ts +94 -77
- package/core/client.ts +133 -149
- package/core/clientTypes.ts +108 -0
- package/core/config.test.ts +22 -11
- package/core/config.ts +16 -9
- 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 +16 -10
- 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 +29 -17
- package/core/keyStore.ts +65 -38
- package/core/permits.test.ts +253 -1
- package/core/permits.ts +80 -16
- 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 +14 -1
- package/dist/chains.d.cts +23 -1
- package/dist/chains.d.ts +23 -1
- package/dist/chains.js +1 -1
- package/dist/{chunk-LU7BMUUT.js → chunk-UGBVZNRT.js} +39 -25
- package/dist/{chunk-GZCQQYVI.js → chunk-WEAZ25JO.js} +14 -2
- package/dist/{chunk-KFGPTJ6X.js → chunk-WGCRJCBR.js} +1920 -1692
- package/dist/{types-bB7wLj0q.d.cts → clientTypes-5_1nwtUe.d.cts} +308 -347
- package/dist/{types-PhwGgQvs.d.ts → clientTypes-Es7fyi65.d.ts} +308 -347
- package/dist/core.cjs +2872 -2632
- package/dist/core.d.cts +101 -6
- package/dist/core.d.ts +101 -6
- package/dist/core.js +3 -3
- package/dist/node.cjs +2716 -2520
- package/dist/node.d.cts +3 -3
- package/dist/node.d.ts +3 -3
- package/dist/node.js +4 -3
- package/dist/{permit-S9CnI6MF.d.cts → permit-fUSe6KKq.d.cts} +31 -15
- package/dist/{permit-S9CnI6MF.d.ts → permit-fUSe6KKq.d.ts} +31 -15
- package/dist/permits.cjs +39 -24
- package/dist/permits.d.cts +137 -148
- package/dist/permits.d.ts +137 -148
- package/dist/permits.js +1 -1
- package/dist/web.cjs +2929 -2518
- package/dist/web.d.cts +21 -5
- package/dist/web.d.ts +21 -5
- 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 +14 -14
- package/permits/index.ts +1 -0
- package/permits/localstorage.test.ts +0 -1
- package/permits/permit.test.ts +25 -22
- package/permits/permit.ts +30 -21
- package/permits/sealing.test.ts +3 -3
- package/permits/sealing.ts +2 -2
- package/permits/store.ts +5 -7
- package/permits/test-utils.ts +1 -1
- package/permits/types.ts +17 -0
- package/permits/utils.ts +0 -1
- package/permits/validation.ts +24 -4
- 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
|
@@ -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.js';
|
|
2
1
|
import { WalletClient, PublicClient } from 'viem';
|
|
3
2
|
import { C as CofheChain } from './types-KImPrEIe.js';
|
|
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, g as PermitUtils } from './permit-fUSe6KKq.js';
|
|
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,6 +214,8 @@ type CofhesdkInternalConfig = {
|
|
|
49
214
|
* Zod schema for configuration validation
|
|
50
215
|
*/
|
|
51
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"]>>>;
|
|
52
219
|
/** List of supported chain configurations */
|
|
53
220
|
supportedChains: z.ZodArray<z.ZodType<{
|
|
54
221
|
name: string;
|
|
@@ -67,8 +234,6 @@ declare const CofhesdkConfigSchema: z.ZodObject<{
|
|
|
67
234
|
thresholdNetworkUrl: string;
|
|
68
235
|
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
69
236
|
}>, "many">;
|
|
70
|
-
/** Strategy for fetching FHE keys */
|
|
71
|
-
fheKeysPrefetching: z.ZodDefault<z.ZodOptional<z.ZodEnum<["CONNECTED_CHAIN", "SUPPORTED_CHAINS", "OFF"]>>>;
|
|
72
237
|
/** How permits are generated */
|
|
73
238
|
permitGeneration: z.ZodDefault<z.ZodOptional<z.ZodEnum<["ON_CONNECT", "ON_DECRYPT_HANDLES", "MANUAL"]>>>;
|
|
74
239
|
/** Default permit expiration in seconds, default is 30 days */
|
|
@@ -87,6 +252,8 @@ declare const CofhesdkConfigSchema: z.ZodObject<{
|
|
|
87
252
|
setItem: (args_0: string, args_1: any, ...args_2: unknown[]) => Promise<void>;
|
|
88
253
|
removeItem: (args_0: string, ...args_1: unknown[]) => Promise<void>;
|
|
89
254
|
}>, z.ZodNull]>>;
|
|
255
|
+
/** Whether to use Web Workers for ZK proof generation (web platform only) */
|
|
256
|
+
useWorkers: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
90
257
|
/** Mocks configs */
|
|
91
258
|
mocks: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
92
259
|
sealOutputDelay: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
@@ -104,6 +271,7 @@ declare const CofhesdkConfigSchema: z.ZodObject<{
|
|
|
104
271
|
zkvWalletClient?: any;
|
|
105
272
|
}>>;
|
|
106
273
|
}, "strip", z.ZodTypeAny, {
|
|
274
|
+
environment: "hardhat" | "node" | "web" | "react";
|
|
107
275
|
supportedChains: {
|
|
108
276
|
name: string;
|
|
109
277
|
id: number;
|
|
@@ -113,7 +281,6 @@ declare const CofhesdkConfigSchema: z.ZodObject<{
|
|
|
113
281
|
thresholdNetworkUrl: string;
|
|
114
282
|
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
115
283
|
}[];
|
|
116
|
-
fheKeysPrefetching: "CONNECTED_CHAIN" | "SUPPORTED_CHAINS" | "OFF";
|
|
117
284
|
permitGeneration: "ON_CONNECT" | "ON_DECRYPT_HANDLES" | "MANUAL";
|
|
118
285
|
defaultPermitExpiration: number;
|
|
119
286
|
fheKeyStorage: {
|
|
@@ -121,6 +288,7 @@ declare const CofhesdkConfigSchema: z.ZodObject<{
|
|
|
121
288
|
setItem: (args_0: string, args_1: any, ...args_2: unknown[]) => Promise<void>;
|
|
122
289
|
removeItem: (args_0: string, ...args_1: unknown[]) => Promise<void>;
|
|
123
290
|
} | null;
|
|
291
|
+
useWorkers: boolean;
|
|
124
292
|
mocks: {
|
|
125
293
|
sealOutputDelay: number;
|
|
126
294
|
};
|
|
@@ -137,7 +305,7 @@ declare const CofhesdkConfigSchema: z.ZodObject<{
|
|
|
137
305
|
thresholdNetworkUrl: string;
|
|
138
306
|
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
139
307
|
}[];
|
|
140
|
-
|
|
308
|
+
environment?: "hardhat" | "node" | "web" | "react" | undefined;
|
|
141
309
|
permitGeneration?: "ON_CONNECT" | "ON_DECRYPT_HANDLES" | "MANUAL" | undefined;
|
|
142
310
|
defaultPermitExpiration?: number | undefined;
|
|
143
311
|
fheKeyStorage?: {
|
|
@@ -145,6 +313,7 @@ declare const CofhesdkConfigSchema: z.ZodObject<{
|
|
|
145
313
|
setItem: (args_0: string, args_1: any, ...args_2: unknown[]) => Promise<void>;
|
|
146
314
|
removeItem: (args_0: string, ...args_1: unknown[]) => Promise<void>;
|
|
147
315
|
} | null | undefined;
|
|
316
|
+
useWorkers?: boolean | undefined;
|
|
148
317
|
mocks?: {
|
|
149
318
|
sealOutputDelay?: number | undefined;
|
|
150
319
|
} | undefined;
|
|
@@ -169,109 +338,6 @@ declare function createCofhesdkConfigBase(config: CofhesdkInputConfig): Cofhesdk
|
|
|
169
338
|
*/
|
|
170
339
|
declare const getCofhesdkConfigItem: <K extends keyof CofhesdkConfig>(config: CofhesdkConfig, key: K) => CofhesdkConfig[K];
|
|
171
340
|
|
|
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
341
|
/**
|
|
276
342
|
* Base parameters that all builders need
|
|
277
343
|
*/
|
|
@@ -288,48 +354,40 @@ type BaseBuilderParams = {
|
|
|
288
354
|
* for working with clients, config, and chain IDs
|
|
289
355
|
*/
|
|
290
356
|
declare abstract class BaseBuilder {
|
|
291
|
-
protected config: CofhesdkConfig
|
|
357
|
+
protected config: CofhesdkConfig;
|
|
292
358
|
protected publicClient: PublicClient | undefined;
|
|
293
359
|
protected walletClient: WalletClient | undefined;
|
|
294
360
|
protected chainId: number | undefined;
|
|
295
361
|
protected account: string | undefined;
|
|
296
|
-
protected requireConnected: (() => void) | undefined;
|
|
297
362
|
constructor(params: BaseBuilderParams);
|
|
298
363
|
/**
|
|
299
|
-
*
|
|
300
|
-
* @
|
|
301
|
-
* @throws {CofhesdkError} If chainId is not set and publicClient is not available
|
|
364
|
+
* Asserts that this.chainId is populated
|
|
365
|
+
* @throws {CofhesdkError} If chainId is not set
|
|
302
366
|
*/
|
|
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>;
|
|
367
|
+
protected assertChainId(): asserts this is this & {
|
|
368
|
+
chainId: number;
|
|
369
|
+
};
|
|
310
370
|
/**
|
|
311
|
-
*
|
|
312
|
-
* @
|
|
313
|
-
* @throws {CofhesdkError} If config is not set
|
|
371
|
+
* Asserts that this.account is populated
|
|
372
|
+
* @throws {CofhesdkError} If account is not set
|
|
314
373
|
*/
|
|
315
|
-
protected
|
|
374
|
+
protected assertAccount(): asserts this is this & {
|
|
375
|
+
account: string;
|
|
376
|
+
};
|
|
316
377
|
/**
|
|
317
|
-
*
|
|
318
|
-
* @returns The public client
|
|
378
|
+
* Asserts that this.publicClient is populated
|
|
319
379
|
* @throws {CofhesdkError} If publicClient is not set
|
|
320
380
|
*/
|
|
321
|
-
protected
|
|
381
|
+
protected assertPublicClient(): asserts this is this & {
|
|
382
|
+
publicClient: PublicClient;
|
|
383
|
+
};
|
|
322
384
|
/**
|
|
323
|
-
*
|
|
324
|
-
* @returns The wallet client
|
|
385
|
+
* Asserts that this.walletClient is populated
|
|
325
386
|
* @throws {CofhesdkError} If walletClient is not set
|
|
326
387
|
*/
|
|
327
|
-
protected
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
* @throws {CofhesdkError} If client is not connected
|
|
331
|
-
*/
|
|
332
|
-
protected requireConnectedOrThrow(): void;
|
|
388
|
+
protected assertWalletClient(): asserts this is this & {
|
|
389
|
+
walletClient: WalletClient;
|
|
390
|
+
};
|
|
333
391
|
}
|
|
334
392
|
|
|
335
393
|
/**
|
|
@@ -347,7 +405,7 @@ declare abstract class BaseBuilder {
|
|
|
347
405
|
* If permitHash not set, uses chainId and account to get active permit
|
|
348
406
|
* If permit is set, uses permit to decrypt regardless of chainId, account, or permitHash
|
|
349
407
|
*
|
|
350
|
-
* Returns
|
|
408
|
+
* Returns the unsealed item.
|
|
351
409
|
*/
|
|
352
410
|
type DecryptHandlesBuilderParams<U extends FheTypes> = BaseBuilderParams & {
|
|
353
411
|
ctHash: bigint;
|
|
@@ -457,9 +515,37 @@ declare class DecryptHandlesBuilder<U extends FheTypes> extends BaseBuilder {
|
|
|
457
515
|
*
|
|
458
516
|
* @returns The unsealed item.
|
|
459
517
|
*/
|
|
460
|
-
decrypt(): Promise<
|
|
518
|
+
decrypt(): Promise<UnsealedItem<U>>;
|
|
461
519
|
}
|
|
462
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
|
+
}
|
|
463
549
|
type ZkProvenCiphertextList = {
|
|
464
550
|
serialize(): Uint8Array;
|
|
465
551
|
};
|
|
@@ -482,6 +568,17 @@ type ZkBuilderAndCrsGenerator = (fhe: string, crs: string) => {
|
|
|
482
568
|
zkBuilder: ZkCiphertextListBuilder;
|
|
483
569
|
zkCrs: ZkCompactPkeCrs;
|
|
484
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>;
|
|
485
582
|
|
|
486
583
|
type ChainRecord<T> = Record<string, T>;
|
|
487
584
|
type SecurityZoneRecord<T> = Record<number, T>;
|
|
@@ -518,16 +615,6 @@ type FheKeyDeserializer = (buff: string) => void;
|
|
|
518
615
|
* @returns {Promise<[[string, boolean], [string, boolean]]>} - A promise that resolves to [[fheKey, fheKeyFetchedFromCoFHE], [crs, crsFetchedFromCoFHE]]
|
|
519
616
|
*/
|
|
520
617
|
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
618
|
|
|
532
619
|
type EncryptInputsBuilderParams<T extends EncryptableItem[]> = BaseBuilderParams & {
|
|
533
620
|
inputs: [...T];
|
|
@@ -537,15 +624,13 @@ type EncryptInputsBuilderParams<T extends EncryptableItem[]> = BaseBuilderParams
|
|
|
537
624
|
compactPkeCrsDeserializer: FheKeyDeserializer | undefined;
|
|
538
625
|
zkBuilderAndCrsGenerator: ZkBuilderAndCrsGenerator | undefined;
|
|
539
626
|
initTfhe: TfheInitializer | undefined;
|
|
627
|
+
zkProveWorkerFn: ZkProveWorkerFunction | undefined;
|
|
540
628
|
keysStorage: KeysStorage | undefined;
|
|
541
629
|
};
|
|
542
630
|
/**
|
|
543
631
|
* EncryptInputsBuilder exposes a builder pattern for encrypting inputs.
|
|
544
632
|
* account, securityZone, and chainId can be overridden in the builder.
|
|
545
633
|
* 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
634
|
*/
|
|
550
635
|
declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuilder {
|
|
551
636
|
private securityZone;
|
|
@@ -556,7 +641,9 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
|
|
|
556
641
|
private compactPkeCrsDeserializer;
|
|
557
642
|
private zkBuilderAndCrsGenerator;
|
|
558
643
|
private initTfhe;
|
|
644
|
+
private zkProveWorkerFn;
|
|
559
645
|
private keysStorage;
|
|
646
|
+
private useWorker;
|
|
560
647
|
private stepTimestamps;
|
|
561
648
|
constructor(params: EncryptInputsBuilderParams<T>);
|
|
562
649
|
/**
|
|
@@ -607,6 +694,35 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
|
|
|
607
694
|
*/
|
|
608
695
|
setSecurityZone(securityZone: number): EncryptInputsBuilder<T>;
|
|
609
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;
|
|
610
726
|
/**
|
|
611
727
|
* @param callback - Function to be called with the encryption step.
|
|
612
728
|
*
|
|
@@ -629,20 +745,6 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
|
|
|
629
745
|
*/
|
|
630
746
|
private fireStepStart;
|
|
631
747
|
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
748
|
/**
|
|
647
749
|
* zkVerifierUrl is included in the chains exported from cofhesdk/chains for use in CofhesdkConfig.supportedChains
|
|
648
750
|
* Users should generally not set this manually.
|
|
@@ -660,15 +762,6 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
|
|
|
660
762
|
* If the key/crs already exists in the store it is returned, else it is fetched, stored, and returned
|
|
661
763
|
*/
|
|
662
764
|
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
765
|
/**
|
|
673
766
|
* @dev Encrypt against the cofheMocks instead of CoFHE
|
|
674
767
|
*
|
|
@@ -700,7 +793,7 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
|
|
|
700
793
|
*
|
|
701
794
|
* @returns The encrypted inputs.
|
|
702
795
|
*/
|
|
703
|
-
encrypt(): Promise<
|
|
796
|
+
encrypt(): Promise<[...EncryptedItemInputs<T>]>;
|
|
704
797
|
}
|
|
705
798
|
|
|
706
799
|
declare const permits: {
|
|
@@ -745,33 +838,30 @@ declare const permits: {
|
|
|
745
838
|
};
|
|
746
839
|
};
|
|
747
840
|
}) => void) => () => void;
|
|
748
|
-
createSelf: (options: CreateSelfPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<
|
|
749
|
-
createSharing: (options: CreateSharingPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<
|
|
750
|
-
importShared: (options: ImportSharedPermitOptions |
|
|
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>;
|
|
751
846
|
getHash: (permit: Permit) => string;
|
|
752
847
|
serialize: (permit: Permit) => SerializedPermit;
|
|
753
848
|
deserialize: (serialized: SerializedPermit) => Permit;
|
|
754
849
|
getPermit: (chainId: number, account: string, hash: string) => Promise<Permit | undefined>;
|
|
755
850
|
getPermits: (chainId: number, account: string) => Promise<Record<string, Permit>>;
|
|
756
851
|
getActivePermit: (chainId: number, account: string) => Promise<Permit | undefined>;
|
|
757
|
-
getActivePermitHash: (chainId: number, account: string) =>
|
|
758
|
-
removePermit: (chainId: number, account: string, hash: string) => Promise<void>;
|
|
759
|
-
selectActivePermit: (chainId: number, account: string, hash: string) =>
|
|
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;
|
|
760
855
|
removeActivePermit: (chainId: number, account: string) => Promise<void>;
|
|
761
856
|
};
|
|
762
857
|
|
|
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 = {
|
|
858
|
+
type CofhesdkClient<TConfig extends CofhesdkConfig = CofhesdkConfig> = {
|
|
766
859
|
getSnapshot(): CofhesdkClientConnectionState;
|
|
767
860
|
subscribe(listener: Listener): () => void;
|
|
768
|
-
readonly initializationResults: {
|
|
769
|
-
keyFetchResult: Promise<Result<boolean>>;
|
|
770
|
-
};
|
|
771
861
|
readonly connected: boolean;
|
|
772
862
|
readonly connecting: boolean;
|
|
773
|
-
readonly config:
|
|
774
|
-
connect(publicClient: PublicClient, walletClient: WalletClient): Promise<
|
|
863
|
+
readonly config: TConfig;
|
|
864
|
+
connect(publicClient: PublicClient, walletClient: WalletClient): Promise<void>;
|
|
775
865
|
/**
|
|
776
866
|
* Types docstring
|
|
777
867
|
*/
|
|
@@ -784,170 +874,41 @@ type CofhesdkClientConnectionState = {
|
|
|
784
874
|
connecting: boolean;
|
|
785
875
|
connectError: unknown | undefined;
|
|
786
876
|
chainId: number | undefined;
|
|
787
|
-
account: string | undefined;
|
|
877
|
+
account: `0x${string}` | undefined;
|
|
878
|
+
publicClient: PublicClient | undefined;
|
|
879
|
+
walletClient: WalletClient | undefined;
|
|
788
880
|
};
|
|
789
881
|
type Listener = (snapshot: CofhesdkClientConnectionState) => void;
|
|
882
|
+
type CofhesdkClientPermitsClients = {
|
|
883
|
+
publicClient: PublicClient;
|
|
884
|
+
walletClient: WalletClient;
|
|
885
|
+
};
|
|
790
886
|
type CofhesdkClientPermits = {
|
|
791
887
|
getSnapshot: typeof permits.getSnapshot;
|
|
792
888
|
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
|
-
|
|
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;
|
|
803
901
|
getHash: typeof PermitUtils.getHash;
|
|
804
902
|
serialize: typeof PermitUtils.serialize;
|
|
805
903
|
deserialize: typeof PermitUtils.deserialize;
|
|
806
904
|
};
|
|
807
|
-
type
|
|
808
|
-
|
|
809
|
-
config: CofhesdkConfig;
|
|
905
|
+
type CofhesdkClientParams<TConfig extends CofhesdkConfig> = {
|
|
906
|
+
config: TConfig;
|
|
810
907
|
zkBuilderAndCrsGenerator: ZkBuilderAndCrsGenerator;
|
|
811
908
|
tfhePublicKeyDeserializer: FheKeyDeserializer;
|
|
812
909
|
compactPkeCrsDeserializer: FheKeyDeserializer;
|
|
813
910
|
initTfhe: TfheInitializer;
|
|
911
|
+
zkProveWorkerFn?: ZkProveWorkerFunction;
|
|
814
912
|
};
|
|
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
913
|
|
|
953
|
-
export {
|
|
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 };
|