@cofhe/sdk 0.7.0 → 0.8.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 +37 -0
- package/acps/acp.ts +10 -1
- package/acps/index.ts +11 -0
- package/acps/onchain-utils.ts +188 -49
- package/acps/registry.ts +73 -0
- package/acps/test/onchainAccessStatus.test.ts +116 -0
- package/acps/types.ts +16 -0
- package/chains/chains/arbitrum.ts +14 -0
- package/chains/chains/ethereum.ts +14 -0
- package/chains/index.ts +5 -1
- package/chains/test/chains.test.ts +24 -3
- package/core/acps.ts +51 -143
- package/core/client.ts +13 -8
- package/core/clientTypes.ts +29 -4
- package/core/config.ts +25 -1
- package/core/consts.ts +14 -2
- package/core/decrypt/verifyDecryptResult.ts +4 -3
- package/core/encrypt/encryptInputsBuilder.ts +6 -0
- package/core/encrypt/zkPackProveVerify.ts +7 -1
- package/core/error.ts +1 -0
- package/core/fetchKeys.ts +2 -2
- package/core/index.ts +9 -1
- package/core/keyStore.ts +23 -10
- package/core/taskManager.ts +48 -0
- package/core/test/acps.test.ts +91 -1
- package/core/test/client.test.ts +41 -0
- package/core/test/config.test.ts +16 -0
- package/core/test/decrypt.test.ts +11 -4
- package/core/test/encryptInputsBuilder.test.ts +1 -1
- package/core/test/fetchKeys.test.ts +23 -2
- package/core/test/keyStore.test.ts +18 -6
- package/core/test/taskManager.test.ts +57 -0
- package/core/types.ts +8 -0
- package/dist/acps.cjs +314 -35
- package/dist/acps.d.cts +251 -4
- package/dist/acps.d.ts +251 -4
- package/dist/acps.js +2 -2
- package/dist/chains.cjs +26 -0
- package/dist/chains.d.cts +45 -1
- package/dist/chains.d.ts +45 -1
- package/dist/chains.js +1 -1
- package/dist/{chunk-43USWPEH.js → chunk-GGI7Y6AW.js} +59 -264
- package/dist/chunk-KSOV5B4B.js +50 -0
- package/dist/{chunk-ESMZCFJY.js → chunk-NMKMCAI3.js} +4 -2
- package/dist/{chunk-Q7CBWGQX.js → chunk-UJYOBHYA.js} +374 -37
- package/dist/{chunk-N6IDQRRU.js → chunk-UKQAJK4N.js} +25 -1
- package/dist/{clientTypes-BN3nbzYM.d.ts → clientTypes-5YPPR16m.d.ts} +77 -14
- package/dist/{clientTypes-CYZjFznO.d.cts → clientTypes-D3aIXmUp.d.cts} +77 -14
- package/dist/core.cjs +271 -136
- package/dist/core.d.cts +29 -8
- package/dist/core.d.ts +29 -8
- package/dist/core.js +4 -4
- package/dist/node.cjs +266 -136
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.js +5 -5
- package/dist/{acp-Wi6isVQI.d.cts → onchain-utils-CUAK8glx.d.cts} +31 -1
- package/dist/{acp-Wi6isVQI.d.ts → onchain-utils-CUAK8glx.d.ts} +31 -1
- package/dist/web.cjs +360 -150
- package/dist/web.d.cts +49 -3
- package/dist/web.d.ts +49 -3
- package/dist/web.js +51 -20
- package/dist/zkProve.worker.cjs +69 -15
- package/dist/zkProve.worker.js +23 -17
- package/node/storage.ts +2 -2
- package/node/test/inherited.test.ts +5 -1
- package/node/test/storage-memory-fallback.test.ts +47 -0
- package/package.json +5 -3
- package/web/index.ts +100 -26
- package/web/test/countingZkProveWorker.ts +31 -0
- package/web/test/inherited.web.test.ts +5 -1
- package/web/test/mainThreadPool.web.test.ts +174 -0
- package/web/test/threadPoolBenchHelper.ts +140 -0
- package/web/test/threadPoolOff.web.test.ts +17 -0
- package/web/test/threadPoolOn.web.test.ts +80 -0
- package/web/test/workerInitRace.web.test.ts +79 -0
- package/web/tfheThreadPool.ts +140 -0
- package/web/workerManager.ts +4 -2
- package/web/zkProve.worker.ts +42 -17
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { WalletClient, PublicClient, Hex } from 'viem';
|
|
2
2
|
import { C as CofheChain } from './types-C07FK-cL.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { A as ACP, h as EIP712Domain, C as CreateSelfACPOptions,
|
|
4
|
+
import { A as ACP, h as EIP712Domain, C as CreateSelfACPOptions, v as SelfACP, d as CreateSharingACPOptions, w as SharingACP, I as ImportSharedACPOptions, R as RecipientACP, B as ACPHashFields, S as SerializedACP, z as ACPAccessStatus, g as IncomingShare, m as AclServedAddresses, i as ACPUtils } from './onchain-utils-CUAK8glx.js';
|
|
5
5
|
import { StoreApi } from 'zustand/vanilla';
|
|
6
6
|
|
|
7
7
|
type TfheInitializer = () => Promise<boolean>;
|
|
8
|
+
/**
|
|
9
|
+
* How many threads tfhe's rayon pool may use for ZK proof generation (web only).
|
|
10
|
+
* - `'auto'` (default): derive from `navigator.hardwareConcurrency`, capped
|
|
11
|
+
* - a positive number: request exactly that many
|
|
12
|
+
* - `false`: stay single-threaded
|
|
13
|
+
*/
|
|
14
|
+
type TfheThreadsSetting = number | 'auto' | false;
|
|
8
15
|
interface IStorage {
|
|
9
16
|
getItem: (name: string) => Promise<any>;
|
|
10
17
|
setItem: (name: string, value: any) => Promise<void>;
|
|
@@ -229,6 +236,25 @@ type CofheConfig = {
|
|
|
229
236
|
* Default: true
|
|
230
237
|
*/
|
|
231
238
|
useWorkers: boolean;
|
|
239
|
+
/**
|
|
240
|
+
* How many threads tfhe's rayon pool may use for ZK proof generation
|
|
241
|
+
* (web platform only; ignored on node/hardhat).
|
|
242
|
+
*
|
|
243
|
+
* Proving dominates the cost of `encryptInputs`, and tfhe's wasm is built with
|
|
244
|
+
* rayon, so spreading it across threads is a large win — roughly 5x on an
|
|
245
|
+
* 8-thread pool.
|
|
246
|
+
*
|
|
247
|
+
* Requires a cross-origin-isolated page (`Cross-Origin-Opener-Policy: same-origin`
|
|
248
|
+
* plus `Cross-Origin-Embedder-Policy: require-corp` or `credentialless`). When the
|
|
249
|
+
* page isn't isolated the pool is skipped and proving stays single-threaded, so
|
|
250
|
+
* this is safe to leave on.
|
|
251
|
+
*
|
|
252
|
+
* `'auto'` derives the count from `navigator.hardwareConcurrency` (capped, since
|
|
253
|
+
* the speedup flattens out); a number requests exactly that many; `false` keeps
|
|
254
|
+
* tfhe single-threaded.
|
|
255
|
+
* Default: 'auto'
|
|
256
|
+
*/
|
|
257
|
+
tfheThreads: TfheThreadsSetting;
|
|
232
258
|
/** ACP acp defaults, applied when creating acps (user options always win) */
|
|
233
259
|
acp: {
|
|
234
260
|
/**
|
|
@@ -310,6 +336,7 @@ declare const CofheConfigSchema: z.ZodObject<{
|
|
|
310
336
|
removeItem: z.ZodCustom<(name: string) => Promise<void>, (name: string) => Promise<void>>;
|
|
311
337
|
}, z.core.$strip>, z.ZodNull]>>;
|
|
312
338
|
useWorkers: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
339
|
+
tfheThreads: z.ZodDefault<z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"auto">, z.ZodLiteral<false>]>>>;
|
|
313
340
|
acp: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
314
341
|
defaultRevoker: z.ZodOptional<z.ZodCustom<Record<number, `0x${string}`>, Record<number, `0x${string}`>>>;
|
|
315
342
|
defaultContractScopes: z.ZodOptional<z.ZodCustom<Record<number, `0x${string}`[]>, Record<number, `0x${string}`[]>>>;
|
|
@@ -665,6 +692,12 @@ interface ZkProveWorkerRequest {
|
|
|
665
692
|
data: any;
|
|
666
693
|
}>;
|
|
667
694
|
metadata: number[];
|
|
695
|
+
/**
|
|
696
|
+
* Forwarded from `config.tfheThreads`. The worker applies it the first time it
|
|
697
|
+
* initialises tfhe — `initThreadPool` can only run once per wasm instance, so
|
|
698
|
+
* later requests carrying a different value have no effect.
|
|
699
|
+
*/
|
|
700
|
+
tfheThreads?: TfheThreadsSetting;
|
|
668
701
|
}
|
|
669
702
|
/**
|
|
670
703
|
* Message sent from worker back to main thread with proof result
|
|
@@ -712,14 +745,14 @@ type ChainRecord<T> = Record<string, T>;
|
|
|
712
745
|
type SecurityZoneRecord<T> = Record<number, T>;
|
|
713
746
|
type KeysStore = {
|
|
714
747
|
fhe: ChainRecord<SecurityZoneRecord<string | undefined>>;
|
|
715
|
-
crs: ChainRecord<string | undefined
|
|
748
|
+
crs: ChainRecord<SecurityZoneRecord<string | undefined>>;
|
|
716
749
|
};
|
|
717
750
|
type KeysStorage = {
|
|
718
751
|
store: StoreApi<KeysStore>;
|
|
719
752
|
getFheKey: (chainId: number | undefined, securityZone?: number) => string | undefined;
|
|
720
|
-
getCrs: (chainId: number | undefined) => string | undefined;
|
|
753
|
+
getCrs: (chainId: number | undefined, securityZone?: number) => string | undefined;
|
|
721
754
|
setFheKey: (chainId: number, securityZone: number, key: string) => void;
|
|
722
|
-
setCrs: (chainId: number, crs: string) => void;
|
|
755
|
+
setCrs: (chainId: number, securityZone: number, crs: string) => void;
|
|
723
756
|
clearKeysStorage: () => Promise<void>;
|
|
724
757
|
rehydrateKeysStore: () => Promise<void>;
|
|
725
758
|
};
|
|
@@ -753,6 +786,7 @@ type EncryptInputsBuilderParams<T extends EncryptableItem[]> = BaseBuilderParams
|
|
|
753
786
|
zkBuilderAndCrsGenerator: ZkBuilderAndCrsGenerator | undefined;
|
|
754
787
|
initTfhe: TfheInitializer | undefined;
|
|
755
788
|
zkProveWorkerFn: ZkProveWorkerFunction | undefined;
|
|
789
|
+
beforeMainThreadProve?: (() => Promise<void>) | undefined;
|
|
756
790
|
keysStorage: KeysStorage | undefined;
|
|
757
791
|
};
|
|
758
792
|
/**
|
|
@@ -779,6 +813,7 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
|
|
|
779
813
|
private zkBuilderAndCrsGenerator;
|
|
780
814
|
private initTfhe;
|
|
781
815
|
private zkProveWorkerFn;
|
|
816
|
+
private beforeMainThreadProve;
|
|
782
817
|
private keysStorage;
|
|
783
818
|
private useWorker;
|
|
784
819
|
private stepTimestamps;
|
|
@@ -971,10 +1006,15 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
|
|
|
971
1006
|
execute(): Promise<HashPlusProofResult<T>>;
|
|
972
1007
|
}
|
|
973
1008
|
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
1009
|
+
/** Options for importing a shared acp. */
|
|
1010
|
+
type ImportActivationOptions = {
|
|
1011
|
+
/**
|
|
1012
|
+
* Make the imported acp the active one. Defaults to `true`.
|
|
1013
|
+
* With `false` the acp is only stored: decrypts that use the active acp keep using the current one,
|
|
1014
|
+
* and the imported acp is used only where it is passed explicitly (e.g. `.withACP(acp)`).
|
|
1015
|
+
*/
|
|
1016
|
+
activate?: boolean;
|
|
1017
|
+
};
|
|
978
1018
|
declare const acps: {
|
|
979
1019
|
getSnapshot: () => {
|
|
980
1020
|
acps: {
|
|
@@ -1070,7 +1110,7 @@ declare const acps: {
|
|
|
1070
1110
|
}) => void) => () => void;
|
|
1071
1111
|
createSelf: (options: CreateSelfACPOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SelfACP>;
|
|
1072
1112
|
createSharing: (options: CreateSharingACPOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SharingACP>;
|
|
1073
|
-
importShared: (options: ImportSharedACPOptions | string, publicClient: PublicClient, walletClient: WalletClient) => Promise<RecipientACP>;
|
|
1113
|
+
importShared: (options: ImportSharedACPOptions | string, publicClient: PublicClient, walletClient: WalletClient, { activate }?: ImportActivationOptions) => Promise<RecipientACP>;
|
|
1074
1114
|
getOrCreateSelfACP: (publicClient: PublicClient, walletClient: WalletClient, chainId?: number, account?: string, options?: CreateSelfACPOptions) => Promise<ACP>;
|
|
1075
1115
|
getOrCreateSharingACP: (publicClient: PublicClient, walletClient: WalletClient, options: CreateSharingACPOptions, chainId?: number, account?: string) => Promise<ACP>;
|
|
1076
1116
|
getHash: (acp: ACPHashFields) => string;
|
|
@@ -1121,12 +1161,13 @@ declare const acps: {
|
|
|
1121
1161
|
revokeACP: (acp: ACP, walletClient: WalletClient) => Promise<Hex>;
|
|
1122
1162
|
revokeAllACPs: (walletClient: WalletClient, publicClient: PublicClient, revokerContract?: Hex) => Promise<Hex>;
|
|
1123
1163
|
isACPRevoked: (acp: ACP, publicClient: PublicClient) => Promise<boolean>;
|
|
1164
|
+
checkAccess: (acp: ACP, publicClient: PublicClient, handle?: bigint | Hex) => Promise<ACPAccessStatus>;
|
|
1124
1165
|
shareOnChain: (acp: ACP, walletClient: WalletClient, registry: Hex) => Promise<{
|
|
1125
1166
|
txHash: Hex;
|
|
1126
1167
|
shareId: Hex;
|
|
1127
1168
|
}>;
|
|
1128
1169
|
getIncomingShares: (publicClient: PublicClient, registry: Hex, recipient: Hex) => Promise<IncomingShare[]>;
|
|
1129
|
-
importFromChain: (share: IncomingShare, publicClient: PublicClient, walletClient: WalletClient) => Promise<RecipientACP>;
|
|
1170
|
+
importFromChain: (share: IncomingShare, publicClient: PublicClient, walletClient: WalletClient, importOptions?: ImportActivationOptions) => Promise<RecipientACP>;
|
|
1130
1171
|
removeShareOnChain: (shareId: Hex, walletClient: WalletClient, registry: Hex) => Promise<Hex>;
|
|
1131
1172
|
computeShareId: (acp: ACP) => Hex;
|
|
1132
1173
|
applyACPDefaults: <T extends {
|
|
@@ -1195,12 +1236,20 @@ type CofheClientACPsClients = {
|
|
|
1195
1236
|
publicClient: PublicClient;
|
|
1196
1237
|
walletClient: WalletClient;
|
|
1197
1238
|
};
|
|
1239
|
+
/**
|
|
1240
|
+
* Options for `importShared`. `activate: false` stores the imported acp without making it the active
|
|
1241
|
+
* one (default `true`). Clients default to the connected ones; pass both to override.
|
|
1242
|
+
*/
|
|
1243
|
+
type CofheClientImportSharedOptions = ImportActivationOptions & (CofheClientACPsClients | {
|
|
1244
|
+
publicClient?: undefined;
|
|
1245
|
+
walletClient?: undefined;
|
|
1246
|
+
});
|
|
1198
1247
|
type CofheClientACPs = {
|
|
1199
1248
|
getSnapshot: typeof acps.getSnapshot;
|
|
1200
1249
|
subscribe: typeof acps.subscribe;
|
|
1201
1250
|
createSelf: (options: CreateSelfACPOptions, clients?: CofheClientACPsClients) => Promise<SelfACP>;
|
|
1202
1251
|
createSharing: (options: CreateSharingACPOptions, clients?: CofheClientACPsClients) => Promise<SharingACP>;
|
|
1203
|
-
importShared: (options: ImportSharedACPOptions | string,
|
|
1252
|
+
importShared: (options: ImportSharedACPOptions | string, importOptions?: CofheClientImportSharedOptions) => Promise<RecipientACP>;
|
|
1204
1253
|
getACP: (hash: string, chainId?: number, account?: string) => ACP | undefined;
|
|
1205
1254
|
getACPs: (chainId?: number, account?: string) => Record<string, ACP>;
|
|
1206
1255
|
getActiveACP: (chainId?: number, account?: string) => ACP | undefined;
|
|
@@ -1213,6 +1262,13 @@ type CofheClientACPs = {
|
|
|
1213
1262
|
revokeACP: (acp: ACP) => Promise<`0x${string}`>;
|
|
1214
1263
|
revokeAllACPs: (revokerContract?: `0x${string}`) => Promise<`0x${string}`>;
|
|
1215
1264
|
isACPRevoked: (acp: ACP) => Promise<boolean>;
|
|
1265
|
+
/**
|
|
1266
|
+
* The ACP on-chain status as a value instead of a revert. Without a handle: 'valid', or
|
|
1267
|
+
* 'expired' / 'revoked' / an invalid signature. With a handle, a valid ACP reports
|
|
1268
|
+
* 'allowed', 'out-of-scope' or 'issuer-not-allowed'. For the issuer copy of a share (type
|
|
1269
|
+
* 'sharing', no recipient signature yet) the handle-less check covers expiry and revocation only.
|
|
1270
|
+
*/
|
|
1271
|
+
checkAccess: (acp: ACP, handle?: bigint | `0x${string}`) => Promise<ACPAccessStatus>;
|
|
1216
1272
|
/** Post a signed sharing ACP to the on-chain share registry (ACL-served, or config `acp.sharingRegistry`). */
|
|
1217
1273
|
shareOnChain: (acp: ACP) => Promise<{
|
|
1218
1274
|
txHash: `0x${string}`;
|
|
@@ -1220,8 +1276,8 @@ type CofheClientACPs = {
|
|
|
1220
1276
|
}>;
|
|
1221
1277
|
/** Importable shares addressed to the connected account (unexpired, not revoked). */
|
|
1222
1278
|
getIncomingShares: () => Promise<IncomingShare[]>;
|
|
1223
|
-
/** Import a share read from the registry: sign as recipient, store and activate. */
|
|
1224
|
-
importFromChain: (share: IncomingShare) => Promise<RecipientACP>;
|
|
1279
|
+
/** Import a share read from the registry: sign as recipient, store and (unless `activate: false`) activate. */
|
|
1280
|
+
importFromChain: (share: IncomingShare, options?: ImportActivationOptions) => Promise<RecipientACP>;
|
|
1225
1281
|
/** Recipient-side: remove a share from the registry (after import, or to decline). */
|
|
1226
1282
|
dismissShare: (shareId: `0x${string}`) => Promise<`0x${string}`>;
|
|
1227
1283
|
/** Issuer-side: retract a pending share from the registry. */
|
|
@@ -1238,6 +1294,13 @@ type CofheClientParams<TConfig extends CofheConfig> = {
|
|
|
1238
1294
|
compactPkeCrsDeserializer: FheKeyDeserializer;
|
|
1239
1295
|
initTfhe: TfheInitializer;
|
|
1240
1296
|
zkProveWorkerFn?: ZkProveWorkerFunction;
|
|
1297
|
+
/**
|
|
1298
|
+
* Runs right before a ZK proof is generated on the calling thread, i.e. only
|
|
1299
|
+
* when the worker path is disabled, unavailable or has failed. Platforms use
|
|
1300
|
+
* it for setup that only pays off when that thread does the proving (web
|
|
1301
|
+
* starts tfhe's rayon thread pool here).
|
|
1302
|
+
*/
|
|
1303
|
+
beforeMainThreadProve?: () => Promise<void>;
|
|
1241
1304
|
};
|
|
1242
1305
|
|
|
1243
|
-
export {
|
|
1306
|
+
export { type KeysStorage as $, type AnyExternalHash as A, type EncryptableToExternalHashMap as B, type CofheInputConfig as C, type ExternalItemHashes as D, type EncryptableItem as E, FheTypes as F, type DecryptPollCallbackFunction as G, type HashPlusProofResult as H, type IStorage as I, type DecryptPollCallbackContext as J, type DecryptEndpoint as K, type LiteralToPrimitive as L, type EncryptStepCallbackFunction as M, type EncryptStepCallbackContext as N, type TfheThreadsSetting as O, type Primitive as P, FheUintUTypes as Q, FheAllUTypes as R, Encryptable as S, type TfheInitializer as T, type UnsealedItem as U, isEncryptableItem as V, EncryptStep as W, isLastEncryptionStep as X, fetchKeys as Y, type FheKeyDeserializer as Z, createKeysStore as _, type CofheConfig as a, type KeysStore as a0, EncryptInputsBuilder as a1, type EncryptInputsBuilderUnset as a2, DecryptForViewBuilder as a3, DecryptForTxBuilder as a4, type DecryptForTxResult as a5, type ZkBuilderAndCrsGenerator as a6, type ZkProveWorkerFunction as a7, type ZkProveWorkerRequest as a8, type ZkProveWorkerResponse as a9, zkProveWithWorker as aa, type CofheClient as b, type CofheClientParams as c, type CofheClientConnectionState as d, createCofheConfigBase as e, assertNoRenamedConfigKeys as f, getCofheConfigItem as g, type CofheInternalConfig as h, type CofheClientACPs as i, type EncryptableBool as j, type EncryptableUint8 as k, type EncryptableUint16 as l, type EncryptableUint32 as m, type EncryptableUint64 as n, type EncryptableUint128 as o, type EncryptableAddress as p, type EncryptedNumber as q, type FheTypeValue as r, type ExternalBoolHash as s, type ExternalUint8Hash as t, type ExternalUint16Hash as u, type ExternalUint32Hash as v, type ExternalUint64Hash as w, type ExternalUint128Hash as x, type ExternalAddressHash as y, type ExternalHashProof as z };
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { WalletClient, PublicClient, Hex } from 'viem';
|
|
2
2
|
import { C as CofheChain } from './types-C07FK-cL.cjs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { A as ACP, h as EIP712Domain, C as CreateSelfACPOptions,
|
|
4
|
+
import { A as ACP, h as EIP712Domain, C as CreateSelfACPOptions, v as SelfACP, d as CreateSharingACPOptions, w as SharingACP, I as ImportSharedACPOptions, R as RecipientACP, B as ACPHashFields, S as SerializedACP, z as ACPAccessStatus, g as IncomingShare, m as AclServedAddresses, i as ACPUtils } from './onchain-utils-CUAK8glx.cjs';
|
|
5
5
|
import { StoreApi } from 'zustand/vanilla';
|
|
6
6
|
|
|
7
7
|
type TfheInitializer = () => Promise<boolean>;
|
|
8
|
+
/**
|
|
9
|
+
* How many threads tfhe's rayon pool may use for ZK proof generation (web only).
|
|
10
|
+
* - `'auto'` (default): derive from `navigator.hardwareConcurrency`, capped
|
|
11
|
+
* - a positive number: request exactly that many
|
|
12
|
+
* - `false`: stay single-threaded
|
|
13
|
+
*/
|
|
14
|
+
type TfheThreadsSetting = number | 'auto' | false;
|
|
8
15
|
interface IStorage {
|
|
9
16
|
getItem: (name: string) => Promise<any>;
|
|
10
17
|
setItem: (name: string, value: any) => Promise<void>;
|
|
@@ -229,6 +236,25 @@ type CofheConfig = {
|
|
|
229
236
|
* Default: true
|
|
230
237
|
*/
|
|
231
238
|
useWorkers: boolean;
|
|
239
|
+
/**
|
|
240
|
+
* How many threads tfhe's rayon pool may use for ZK proof generation
|
|
241
|
+
* (web platform only; ignored on node/hardhat).
|
|
242
|
+
*
|
|
243
|
+
* Proving dominates the cost of `encryptInputs`, and tfhe's wasm is built with
|
|
244
|
+
* rayon, so spreading it across threads is a large win — roughly 5x on an
|
|
245
|
+
* 8-thread pool.
|
|
246
|
+
*
|
|
247
|
+
* Requires a cross-origin-isolated page (`Cross-Origin-Opener-Policy: same-origin`
|
|
248
|
+
* plus `Cross-Origin-Embedder-Policy: require-corp` or `credentialless`). When the
|
|
249
|
+
* page isn't isolated the pool is skipped and proving stays single-threaded, so
|
|
250
|
+
* this is safe to leave on.
|
|
251
|
+
*
|
|
252
|
+
* `'auto'` derives the count from `navigator.hardwareConcurrency` (capped, since
|
|
253
|
+
* the speedup flattens out); a number requests exactly that many; `false` keeps
|
|
254
|
+
* tfhe single-threaded.
|
|
255
|
+
* Default: 'auto'
|
|
256
|
+
*/
|
|
257
|
+
tfheThreads: TfheThreadsSetting;
|
|
232
258
|
/** ACP acp defaults, applied when creating acps (user options always win) */
|
|
233
259
|
acp: {
|
|
234
260
|
/**
|
|
@@ -310,6 +336,7 @@ declare const CofheConfigSchema: z.ZodObject<{
|
|
|
310
336
|
removeItem: z.ZodCustom<(name: string) => Promise<void>, (name: string) => Promise<void>>;
|
|
311
337
|
}, z.core.$strip>, z.ZodNull]>>;
|
|
312
338
|
useWorkers: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
339
|
+
tfheThreads: z.ZodDefault<z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"auto">, z.ZodLiteral<false>]>>>;
|
|
313
340
|
acp: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
314
341
|
defaultRevoker: z.ZodOptional<z.ZodCustom<Record<number, `0x${string}`>, Record<number, `0x${string}`>>>;
|
|
315
342
|
defaultContractScopes: z.ZodOptional<z.ZodCustom<Record<number, `0x${string}`[]>, Record<number, `0x${string}`[]>>>;
|
|
@@ -665,6 +692,12 @@ interface ZkProveWorkerRequest {
|
|
|
665
692
|
data: any;
|
|
666
693
|
}>;
|
|
667
694
|
metadata: number[];
|
|
695
|
+
/**
|
|
696
|
+
* Forwarded from `config.tfheThreads`. The worker applies it the first time it
|
|
697
|
+
* initialises tfhe — `initThreadPool` can only run once per wasm instance, so
|
|
698
|
+
* later requests carrying a different value have no effect.
|
|
699
|
+
*/
|
|
700
|
+
tfheThreads?: TfheThreadsSetting;
|
|
668
701
|
}
|
|
669
702
|
/**
|
|
670
703
|
* Message sent from worker back to main thread with proof result
|
|
@@ -712,14 +745,14 @@ type ChainRecord<T> = Record<string, T>;
|
|
|
712
745
|
type SecurityZoneRecord<T> = Record<number, T>;
|
|
713
746
|
type KeysStore = {
|
|
714
747
|
fhe: ChainRecord<SecurityZoneRecord<string | undefined>>;
|
|
715
|
-
crs: ChainRecord<string | undefined
|
|
748
|
+
crs: ChainRecord<SecurityZoneRecord<string | undefined>>;
|
|
716
749
|
};
|
|
717
750
|
type KeysStorage = {
|
|
718
751
|
store: StoreApi<KeysStore>;
|
|
719
752
|
getFheKey: (chainId: number | undefined, securityZone?: number) => string | undefined;
|
|
720
|
-
getCrs: (chainId: number | undefined) => string | undefined;
|
|
753
|
+
getCrs: (chainId: number | undefined, securityZone?: number) => string | undefined;
|
|
721
754
|
setFheKey: (chainId: number, securityZone: number, key: string) => void;
|
|
722
|
-
setCrs: (chainId: number, crs: string) => void;
|
|
755
|
+
setCrs: (chainId: number, securityZone: number, crs: string) => void;
|
|
723
756
|
clearKeysStorage: () => Promise<void>;
|
|
724
757
|
rehydrateKeysStore: () => Promise<void>;
|
|
725
758
|
};
|
|
@@ -753,6 +786,7 @@ type EncryptInputsBuilderParams<T extends EncryptableItem[]> = BaseBuilderParams
|
|
|
753
786
|
zkBuilderAndCrsGenerator: ZkBuilderAndCrsGenerator | undefined;
|
|
754
787
|
initTfhe: TfheInitializer | undefined;
|
|
755
788
|
zkProveWorkerFn: ZkProveWorkerFunction | undefined;
|
|
789
|
+
beforeMainThreadProve?: (() => Promise<void>) | undefined;
|
|
756
790
|
keysStorage: KeysStorage | undefined;
|
|
757
791
|
};
|
|
758
792
|
/**
|
|
@@ -779,6 +813,7 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
|
|
|
779
813
|
private zkBuilderAndCrsGenerator;
|
|
780
814
|
private initTfhe;
|
|
781
815
|
private zkProveWorkerFn;
|
|
816
|
+
private beforeMainThreadProve;
|
|
782
817
|
private keysStorage;
|
|
783
818
|
private useWorker;
|
|
784
819
|
private stepTimestamps;
|
|
@@ -971,10 +1006,15 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
|
|
|
971
1006
|
execute(): Promise<HashPlusProofResult<T>>;
|
|
972
1007
|
}
|
|
973
1008
|
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
1009
|
+
/** Options for importing a shared acp. */
|
|
1010
|
+
type ImportActivationOptions = {
|
|
1011
|
+
/**
|
|
1012
|
+
* Make the imported acp the active one. Defaults to `true`.
|
|
1013
|
+
* With `false` the acp is only stored: decrypts that use the active acp keep using the current one,
|
|
1014
|
+
* and the imported acp is used only where it is passed explicitly (e.g. `.withACP(acp)`).
|
|
1015
|
+
*/
|
|
1016
|
+
activate?: boolean;
|
|
1017
|
+
};
|
|
978
1018
|
declare const acps: {
|
|
979
1019
|
getSnapshot: () => {
|
|
980
1020
|
acps: {
|
|
@@ -1070,7 +1110,7 @@ declare const acps: {
|
|
|
1070
1110
|
}) => void) => () => void;
|
|
1071
1111
|
createSelf: (options: CreateSelfACPOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SelfACP>;
|
|
1072
1112
|
createSharing: (options: CreateSharingACPOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SharingACP>;
|
|
1073
|
-
importShared: (options: ImportSharedACPOptions | string, publicClient: PublicClient, walletClient: WalletClient) => Promise<RecipientACP>;
|
|
1113
|
+
importShared: (options: ImportSharedACPOptions | string, publicClient: PublicClient, walletClient: WalletClient, { activate }?: ImportActivationOptions) => Promise<RecipientACP>;
|
|
1074
1114
|
getOrCreateSelfACP: (publicClient: PublicClient, walletClient: WalletClient, chainId?: number, account?: string, options?: CreateSelfACPOptions) => Promise<ACP>;
|
|
1075
1115
|
getOrCreateSharingACP: (publicClient: PublicClient, walletClient: WalletClient, options: CreateSharingACPOptions, chainId?: number, account?: string) => Promise<ACP>;
|
|
1076
1116
|
getHash: (acp: ACPHashFields) => string;
|
|
@@ -1121,12 +1161,13 @@ declare const acps: {
|
|
|
1121
1161
|
revokeACP: (acp: ACP, walletClient: WalletClient) => Promise<Hex>;
|
|
1122
1162
|
revokeAllACPs: (walletClient: WalletClient, publicClient: PublicClient, revokerContract?: Hex) => Promise<Hex>;
|
|
1123
1163
|
isACPRevoked: (acp: ACP, publicClient: PublicClient) => Promise<boolean>;
|
|
1164
|
+
checkAccess: (acp: ACP, publicClient: PublicClient, handle?: bigint | Hex) => Promise<ACPAccessStatus>;
|
|
1124
1165
|
shareOnChain: (acp: ACP, walletClient: WalletClient, registry: Hex) => Promise<{
|
|
1125
1166
|
txHash: Hex;
|
|
1126
1167
|
shareId: Hex;
|
|
1127
1168
|
}>;
|
|
1128
1169
|
getIncomingShares: (publicClient: PublicClient, registry: Hex, recipient: Hex) => Promise<IncomingShare[]>;
|
|
1129
|
-
importFromChain: (share: IncomingShare, publicClient: PublicClient, walletClient: WalletClient) => Promise<RecipientACP>;
|
|
1170
|
+
importFromChain: (share: IncomingShare, publicClient: PublicClient, walletClient: WalletClient, importOptions?: ImportActivationOptions) => Promise<RecipientACP>;
|
|
1130
1171
|
removeShareOnChain: (shareId: Hex, walletClient: WalletClient, registry: Hex) => Promise<Hex>;
|
|
1131
1172
|
computeShareId: (acp: ACP) => Hex;
|
|
1132
1173
|
applyACPDefaults: <T extends {
|
|
@@ -1195,12 +1236,20 @@ type CofheClientACPsClients = {
|
|
|
1195
1236
|
publicClient: PublicClient;
|
|
1196
1237
|
walletClient: WalletClient;
|
|
1197
1238
|
};
|
|
1239
|
+
/**
|
|
1240
|
+
* Options for `importShared`. `activate: false` stores the imported acp without making it the active
|
|
1241
|
+
* one (default `true`). Clients default to the connected ones; pass both to override.
|
|
1242
|
+
*/
|
|
1243
|
+
type CofheClientImportSharedOptions = ImportActivationOptions & (CofheClientACPsClients | {
|
|
1244
|
+
publicClient?: undefined;
|
|
1245
|
+
walletClient?: undefined;
|
|
1246
|
+
});
|
|
1198
1247
|
type CofheClientACPs = {
|
|
1199
1248
|
getSnapshot: typeof acps.getSnapshot;
|
|
1200
1249
|
subscribe: typeof acps.subscribe;
|
|
1201
1250
|
createSelf: (options: CreateSelfACPOptions, clients?: CofheClientACPsClients) => Promise<SelfACP>;
|
|
1202
1251
|
createSharing: (options: CreateSharingACPOptions, clients?: CofheClientACPsClients) => Promise<SharingACP>;
|
|
1203
|
-
importShared: (options: ImportSharedACPOptions | string,
|
|
1252
|
+
importShared: (options: ImportSharedACPOptions | string, importOptions?: CofheClientImportSharedOptions) => Promise<RecipientACP>;
|
|
1204
1253
|
getACP: (hash: string, chainId?: number, account?: string) => ACP | undefined;
|
|
1205
1254
|
getACPs: (chainId?: number, account?: string) => Record<string, ACP>;
|
|
1206
1255
|
getActiveACP: (chainId?: number, account?: string) => ACP | undefined;
|
|
@@ -1213,6 +1262,13 @@ type CofheClientACPs = {
|
|
|
1213
1262
|
revokeACP: (acp: ACP) => Promise<`0x${string}`>;
|
|
1214
1263
|
revokeAllACPs: (revokerContract?: `0x${string}`) => Promise<`0x${string}`>;
|
|
1215
1264
|
isACPRevoked: (acp: ACP) => Promise<boolean>;
|
|
1265
|
+
/**
|
|
1266
|
+
* The ACP on-chain status as a value instead of a revert. Without a handle: 'valid', or
|
|
1267
|
+
* 'expired' / 'revoked' / an invalid signature. With a handle, a valid ACP reports
|
|
1268
|
+
* 'allowed', 'out-of-scope' or 'issuer-not-allowed'. For the issuer copy of a share (type
|
|
1269
|
+
* 'sharing', no recipient signature yet) the handle-less check covers expiry and revocation only.
|
|
1270
|
+
*/
|
|
1271
|
+
checkAccess: (acp: ACP, handle?: bigint | `0x${string}`) => Promise<ACPAccessStatus>;
|
|
1216
1272
|
/** Post a signed sharing ACP to the on-chain share registry (ACL-served, or config `acp.sharingRegistry`). */
|
|
1217
1273
|
shareOnChain: (acp: ACP) => Promise<{
|
|
1218
1274
|
txHash: `0x${string}`;
|
|
@@ -1220,8 +1276,8 @@ type CofheClientACPs = {
|
|
|
1220
1276
|
}>;
|
|
1221
1277
|
/** Importable shares addressed to the connected account (unexpired, not revoked). */
|
|
1222
1278
|
getIncomingShares: () => Promise<IncomingShare[]>;
|
|
1223
|
-
/** Import a share read from the registry: sign as recipient, store and activate. */
|
|
1224
|
-
importFromChain: (share: IncomingShare) => Promise<RecipientACP>;
|
|
1279
|
+
/** Import a share read from the registry: sign as recipient, store and (unless `activate: false`) activate. */
|
|
1280
|
+
importFromChain: (share: IncomingShare, options?: ImportActivationOptions) => Promise<RecipientACP>;
|
|
1225
1281
|
/** Recipient-side: remove a share from the registry (after import, or to decline). */
|
|
1226
1282
|
dismissShare: (shareId: `0x${string}`) => Promise<`0x${string}`>;
|
|
1227
1283
|
/** Issuer-side: retract a pending share from the registry. */
|
|
@@ -1238,6 +1294,13 @@ type CofheClientParams<TConfig extends CofheConfig> = {
|
|
|
1238
1294
|
compactPkeCrsDeserializer: FheKeyDeserializer;
|
|
1239
1295
|
initTfhe: TfheInitializer;
|
|
1240
1296
|
zkProveWorkerFn?: ZkProveWorkerFunction;
|
|
1297
|
+
/**
|
|
1298
|
+
* Runs right before a ZK proof is generated on the calling thread, i.e. only
|
|
1299
|
+
* when the worker path is disabled, unavailable or has failed. Platforms use
|
|
1300
|
+
* it for setup that only pays off when that thread does the proving (web
|
|
1301
|
+
* starts tfhe's rayon thread pool here).
|
|
1302
|
+
*/
|
|
1303
|
+
beforeMainThreadProve?: () => Promise<void>;
|
|
1241
1304
|
};
|
|
1242
1305
|
|
|
1243
|
-
export {
|
|
1306
|
+
export { type KeysStorage as $, type AnyExternalHash as A, type EncryptableToExternalHashMap as B, type CofheInputConfig as C, type ExternalItemHashes as D, type EncryptableItem as E, FheTypes as F, type DecryptPollCallbackFunction as G, type HashPlusProofResult as H, type IStorage as I, type DecryptPollCallbackContext as J, type DecryptEndpoint as K, type LiteralToPrimitive as L, type EncryptStepCallbackFunction as M, type EncryptStepCallbackContext as N, type TfheThreadsSetting as O, type Primitive as P, FheUintUTypes as Q, FheAllUTypes as R, Encryptable as S, type TfheInitializer as T, type UnsealedItem as U, isEncryptableItem as V, EncryptStep as W, isLastEncryptionStep as X, fetchKeys as Y, type FheKeyDeserializer as Z, createKeysStore as _, type CofheConfig as a, type KeysStore as a0, EncryptInputsBuilder as a1, type EncryptInputsBuilderUnset as a2, DecryptForViewBuilder as a3, DecryptForTxBuilder as a4, type DecryptForTxResult as a5, type ZkBuilderAndCrsGenerator as a6, type ZkProveWorkerFunction as a7, type ZkProveWorkerRequest as a8, type ZkProveWorkerResponse as a9, zkProveWithWorker as aa, type CofheClient as b, type CofheClientParams as c, type CofheClientConnectionState as d, createCofheConfigBase as e, assertNoRenamedConfigKeys as f, getCofheConfigItem as g, type CofheInternalConfig as h, type CofheClientACPs as i, type EncryptableBool as j, type EncryptableUint8 as k, type EncryptableUint16 as l, type EncryptableUint32 as m, type EncryptableUint64 as n, type EncryptableUint128 as o, type EncryptableAddress as p, type EncryptedNumber as q, type FheTypeValue as r, type ExternalBoolHash as s, type ExternalUint8Hash as t, type ExternalUint16Hash as u, type ExternalUint32Hash as v, type ExternalUint64Hash as w, type ExternalUint128Hash as x, type ExternalAddressHash as y, type ExternalHashProof as z };
|