@cofhe/sdk 0.5.2 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/chains/chains/hardhat.ts +3 -3
- package/core/consts.ts +0 -3
- package/core/debug.ts +72 -0
- package/core/decrypt/tnDecryptV2.ts +20 -13
- package/core/decrypt/tnSealOutputV2.ts +20 -13
- package/core/encrypt/cofheMocksZkVerifySign.ts +2 -2
- package/core/encrypt/encryptInputsBuilder.ts +46 -11
- package/core/encrypt/zkPackProveVerify.ts +3 -3
- package/core/index.ts +23 -1
- package/core/permits.ts +17 -7
- package/core/test/encryptInputsBuilder.test.ts +35 -0
- package/core/test/permits.test.ts +62 -0
- package/core/types.ts +65 -5
- package/dist/chains.cjs +3 -3
- package/dist/chains.js +1 -1
- package/dist/{chunk-4FP4V35O.js → chunk-ESMZCFJY.js} +1 -2
- package/dist/{chunk-TBLR7NNE.js → chunk-MTRAXQXC.js} +3 -3
- package/dist/{chunk-YDOK4BDL.js → chunk-NOC3PYB7.js} +108 -33
- package/dist/{chunk-MRCKUMOS.js → chunk-VB62WYPL.js} +1 -1
- package/dist/{clientTypes-BJbFeeno.d.cts → clientTypes-BDy1qIBu.d.cts} +73 -11
- package/dist/{clientTypes-CEno_BEf.d.ts → clientTypes-CyUvRRzA.d.ts} +73 -11
- package/dist/core.cjs +110 -34
- package/dist/core.d.cts +26 -5
- package/dist/core.d.ts +26 -5
- package/dist/core.js +4 -4
- package/dist/node.cjs +100 -32
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +4 -4
- package/dist/permits.d.cts +10 -6
- package/dist/permits.d.ts +10 -6
- package/dist/permits.js +2 -2
- package/dist/web.cjs +100 -32
- package/dist/web.d.cts +1 -1
- package/dist/web.d.ts +1 -1
- package/dist/web.js +4 -4
- package/dist/zkProve.worker.js +1 -1
- package/package.json +2 -2
- package/permits/store.ts +1 -0
- package/web/test/ssr.test.ts +23 -0
- package/web/test/tfheinit.web.test.ts +81 -5
package/dist/node.cjs
CHANGED
|
@@ -358,7 +358,7 @@ var zkVerify = async (verifierUrl, serializedBytes, address, securityZone, chain
|
|
|
358
358
|
}
|
|
359
359
|
};
|
|
360
360
|
var concatSigRecid = (signature, recid) => {
|
|
361
|
-
return signature
|
|
361
|
+
return `${signature}${(recid + 27).toString(16).padStart(2, "0")}`;
|
|
362
362
|
};
|
|
363
363
|
|
|
364
364
|
// core/encrypt/MockZkVerifierAbi.ts
|
|
@@ -690,9 +690,9 @@ var hardhat2 = defineChain({
|
|
|
690
690
|
name: "Hardhat",
|
|
691
691
|
network: "localhost",
|
|
692
692
|
// These are unused in the mock environment
|
|
693
|
-
coFheUrl: "http://
|
|
694
|
-
verifierUrl: "http://
|
|
695
|
-
thresholdNetworkUrl: "http://
|
|
693
|
+
coFheUrl: "http://ignored-in-mock-environment",
|
|
694
|
+
verifierUrl: "http://ignored-in-mock-environment",
|
|
695
|
+
thresholdNetworkUrl: "http://ignored-in-mock-environment",
|
|
696
696
|
environment: "MOCK"
|
|
697
697
|
});
|
|
698
698
|
var CofheConfigSchema = zod.z.object({
|
|
@@ -1078,6 +1078,7 @@ var EncryptInputsBuilder = class extends BaseBuilder {
|
|
|
1078
1078
|
securityZone;
|
|
1079
1079
|
stepCallback;
|
|
1080
1080
|
inputItems;
|
|
1081
|
+
hpp = false;
|
|
1081
1082
|
zkvWalletClient;
|
|
1082
1083
|
tfhePublicKeyDeserializer;
|
|
1083
1084
|
compactPkeCrsDeserializer;
|
|
@@ -1207,6 +1208,20 @@ var EncryptInputsBuilder = class extends BaseBuilder {
|
|
|
1207
1208
|
getSecurityZone() {
|
|
1208
1209
|
return this.securityZone;
|
|
1209
1210
|
}
|
|
1211
|
+
/**
|
|
1212
|
+
* Example:
|
|
1213
|
+
* ```typescript
|
|
1214
|
+
* const encrypted = await encryptInputs([Encryptable.uint128(10n)])
|
|
1215
|
+
* .asHashPlusProof()
|
|
1216
|
+
* .execute();
|
|
1217
|
+
* ```
|
|
1218
|
+
*
|
|
1219
|
+
* @returns Chainable EncryptInputsBuilder instance that will return a HashPlusProofResult instead of an array of EncryptedItemInputs.
|
|
1220
|
+
*/
|
|
1221
|
+
asHashPlusProof() {
|
|
1222
|
+
this.hpp = true;
|
|
1223
|
+
return this;
|
|
1224
|
+
}
|
|
1210
1225
|
/**
|
|
1211
1226
|
* @param useWorker - Whether to use Web Workers for ZK proof generation.
|
|
1212
1227
|
*
|
|
@@ -1488,6 +1503,15 @@ var EncryptInputsBuilder = class extends BaseBuilder {
|
|
|
1488
1503
|
this.fireStepEnd("verify" /* Verify */);
|
|
1489
1504
|
return encryptedInputs;
|
|
1490
1505
|
}
|
|
1506
|
+
structsToHashPlusProof(inItems) {
|
|
1507
|
+
let hashes = [];
|
|
1508
|
+
let proof = "";
|
|
1509
|
+
for (const item of inItems) {
|
|
1510
|
+
hashes.push("0x" + item.ctHash.toString(16).padStart(64, "0"));
|
|
1511
|
+
proof += item.signature;
|
|
1512
|
+
}
|
|
1513
|
+
return [...hashes, proof];
|
|
1514
|
+
}
|
|
1491
1515
|
/**
|
|
1492
1516
|
* Final step of the encryption process. MUST BE CALLED LAST IN THE CHAIN.
|
|
1493
1517
|
*
|
|
@@ -1508,9 +1532,14 @@ var EncryptInputsBuilder = class extends BaseBuilder {
|
|
|
1508
1532
|
* @returns The encrypted inputs.
|
|
1509
1533
|
*/
|
|
1510
1534
|
async execute() {
|
|
1535
|
+
let items;
|
|
1511
1536
|
if (this.chainId === chains.hardhat.id)
|
|
1512
|
-
|
|
1513
|
-
|
|
1537
|
+
items = await this.mocksExecute();
|
|
1538
|
+
else
|
|
1539
|
+
items = await this.productionExecute();
|
|
1540
|
+
if (this.hpp)
|
|
1541
|
+
return this.structsToHashPlusProof(items);
|
|
1542
|
+
return items;
|
|
1514
1543
|
}
|
|
1515
1544
|
};
|
|
1516
1545
|
|
|
@@ -2533,7 +2562,7 @@ var getOrCreateSelfPermit = async (publicClient, walletClient, chainId, account,
|
|
|
2533
2562
|
const _chainId = chainId ?? await publicClient.getChainId();
|
|
2534
2563
|
const _account = account ?? walletClient.account.address;
|
|
2535
2564
|
const activePermit = await getActivePermit2(_chainId, _account);
|
|
2536
|
-
if (activePermit && activePermit.type === "self") {
|
|
2565
|
+
if (activePermit && activePermit.type === "self" && PermitUtils.isValid(activePermit).valid) {
|
|
2537
2566
|
return activePermit;
|
|
2538
2567
|
}
|
|
2539
2568
|
return createSelf(options ?? { issuer: _account, name: "Autogenerated Self Permit" }, publicClient, walletClient);
|
|
@@ -2542,7 +2571,7 @@ var getOrCreateSharingPermit = async (publicClient, walletClient, options, chain
|
|
|
2542
2571
|
const _chainId = chainId ?? await publicClient.getChainId();
|
|
2543
2572
|
const _account = account ?? walletClient.account.address;
|
|
2544
2573
|
const activePermit = await getActivePermit2(_chainId, _account);
|
|
2545
|
-
if (activePermit && activePermit.type === "sharing") {
|
|
2574
|
+
if (activePermit && activePermit.type === "sharing" && PermitUtils.isValid(activePermit).valid) {
|
|
2546
2575
|
return activePermit;
|
|
2547
2576
|
}
|
|
2548
2577
|
return createSharing(options, publicClient, walletClient);
|
|
@@ -2801,6 +2830,29 @@ async function cofheMocksDecryptForView(ctHash, utype, permit, publicClient) {
|
|
|
2801
2830
|
return unsealed;
|
|
2802
2831
|
}
|
|
2803
2832
|
|
|
2833
|
+
// core/debug.ts
|
|
2834
|
+
var interceptors = {};
|
|
2835
|
+
async function cofheFetch(url, init, ctx = { op: "request" }) {
|
|
2836
|
+
let finalUrl = url;
|
|
2837
|
+
let finalInit = init;
|
|
2838
|
+
if (interceptors.onRequest) {
|
|
2839
|
+
const override = await interceptors.onRequest(finalUrl, finalInit, ctx);
|
|
2840
|
+
if (override) {
|
|
2841
|
+
if (override.url !== void 0)
|
|
2842
|
+
finalUrl = override.url;
|
|
2843
|
+
if (override.init !== void 0)
|
|
2844
|
+
finalInit = override.init;
|
|
2845
|
+
}
|
|
2846
|
+
}
|
|
2847
|
+
let response = await fetch(finalUrl, finalInit);
|
|
2848
|
+
if (interceptors.onResponse) {
|
|
2849
|
+
const replaced = await interceptors.onResponse(response, ctx);
|
|
2850
|
+
if (replaced)
|
|
2851
|
+
response = replaced;
|
|
2852
|
+
}
|
|
2853
|
+
return response;
|
|
2854
|
+
}
|
|
2855
|
+
|
|
2804
2856
|
// core/decrypt/polling.ts
|
|
2805
2857
|
function computeMinuteRampPollIntervalMs(elapsedMs, params) {
|
|
2806
2858
|
const elapsedSeconds = Math.floor(elapsedMs / 1e3);
|
|
@@ -2970,13 +3022,17 @@ async function submitSealOutputRequest(thresholdNetworkUrl, ctHash, chainId, per
|
|
|
2970
3022
|
for (; ; ) {
|
|
2971
3023
|
let response;
|
|
2972
3024
|
try {
|
|
2973
|
-
response = await
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
3025
|
+
response = await cofheFetch(
|
|
3026
|
+
`${thresholdNetworkUrl}/v2/sealoutput`,
|
|
3027
|
+
/*op:sealoutput*/
|
|
3028
|
+
{
|
|
3029
|
+
method: "POST",
|
|
3030
|
+
headers: {
|
|
3031
|
+
"Content-Type": "application/json"
|
|
3032
|
+
},
|
|
3033
|
+
body: JSON.stringify(body)
|
|
3034
|
+
}
|
|
3035
|
+
);
|
|
2980
3036
|
} catch (e) {
|
|
2981
3037
|
throw new CofheError({
|
|
2982
3038
|
code: "SEAL_OUTPUT_FAILED" /* SealOutputFailed */,
|
|
@@ -3099,12 +3155,16 @@ async function pollSealOutputStatus(thresholdNetworkUrl, requestId, overallStart
|
|
|
3099
3155
|
}
|
|
3100
3156
|
let response;
|
|
3101
3157
|
try {
|
|
3102
|
-
response = await
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3158
|
+
response = await cofheFetch(
|
|
3159
|
+
`${thresholdNetworkUrl}/v2/sealoutput/${requestId}`,
|
|
3160
|
+
/*op:sealoutput-poll*/
|
|
3161
|
+
{
|
|
3162
|
+
method: "GET",
|
|
3163
|
+
headers: {
|
|
3164
|
+
"Content-Type": "application/json"
|
|
3165
|
+
}
|
|
3106
3166
|
}
|
|
3107
|
-
|
|
3167
|
+
);
|
|
3108
3168
|
} catch (e) {
|
|
3109
3169
|
throw new CofheError({
|
|
3110
3170
|
code: "SEAL_OUTPUT_FAILED" /* SealOutputFailed */,
|
|
@@ -3701,13 +3761,17 @@ async function submitDecryptRequestV2(thresholdNetworkUrl, ctHash, chainId, perm
|
|
|
3701
3761
|
for (; ; ) {
|
|
3702
3762
|
let response;
|
|
3703
3763
|
try {
|
|
3704
|
-
response = await
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3764
|
+
response = await cofheFetch(
|
|
3765
|
+
`${thresholdNetworkUrl}/v2/decrypt`,
|
|
3766
|
+
/*op:decrypt*/
|
|
3767
|
+
{
|
|
3768
|
+
method: "POST",
|
|
3769
|
+
headers: {
|
|
3770
|
+
"Content-Type": "application/json"
|
|
3771
|
+
},
|
|
3772
|
+
body: JSON.stringify(body)
|
|
3773
|
+
}
|
|
3774
|
+
);
|
|
3711
3775
|
} catch (e) {
|
|
3712
3776
|
throw new CofheError({
|
|
3713
3777
|
code: "DECRYPT_FAILED" /* DecryptFailed */,
|
|
@@ -3832,12 +3896,16 @@ async function pollDecryptStatusV2(thresholdNetworkUrl, requestId, overallStartT
|
|
|
3832
3896
|
}
|
|
3833
3897
|
let response;
|
|
3834
3898
|
try {
|
|
3835
|
-
response = await
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3899
|
+
response = await cofheFetch(
|
|
3900
|
+
`${thresholdNetworkUrl}/v2/decrypt/${requestId}`,
|
|
3901
|
+
/*op:decrypt-poll*/
|
|
3902
|
+
{
|
|
3903
|
+
method: "GET",
|
|
3904
|
+
headers: {
|
|
3905
|
+
"Content-Type": "application/json"
|
|
3906
|
+
}
|
|
3839
3907
|
}
|
|
3840
|
-
|
|
3908
|
+
);
|
|
3841
3909
|
} catch (e) {
|
|
3842
3910
|
throw new CofheError({
|
|
3843
3911
|
code: "DECRYPT_FAILED" /* DecryptFailed */,
|
package/dist/node.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as CofheInputConfig, a as CofheConfig, b as CofheClient } from './clientTypes-
|
|
1
|
+
import { C as CofheInputConfig, a as CofheConfig, b as CofheClient } from './clientTypes-BDy1qIBu.cjs';
|
|
2
2
|
import 'viem';
|
|
3
3
|
import './types-C07FK-cL.cjs';
|
|
4
4
|
import 'zod';
|
package/dist/node.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as CofheInputConfig, a as CofheConfig, b as CofheClient } from './clientTypes-
|
|
1
|
+
import { C as CofheInputConfig, a as CofheConfig, b as CofheClient } from './clientTypes-CyUvRRzA.js';
|
|
2
2
|
import 'viem';
|
|
3
3
|
import './types-C07FK-cL.js';
|
|
4
4
|
import 'zod';
|
package/dist/node.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { createCofheConfigBase, createCofheClientBase } from './chunk-
|
|
2
|
-
import './chunk-
|
|
3
|
-
import './chunk-
|
|
4
|
-
import { TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT } from './chunk-
|
|
1
|
+
import { createCofheConfigBase, createCofheClientBase } from './chunk-NOC3PYB7.js';
|
|
2
|
+
import './chunk-MTRAXQXC.js';
|
|
3
|
+
import './chunk-VB62WYPL.js';
|
|
4
|
+
import { TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT } from './chunk-ESMZCFJY.js';
|
|
5
5
|
import { promises } from 'fs';
|
|
6
6
|
import { join } from 'path';
|
|
7
7
|
import { init_panic_hook, ProvenCompactCiphertextList, CompactPkeCrs, TfheCompactPublicKey } from 'node-tfhe';
|
package/dist/permits.d.cts
CHANGED
|
@@ -302,15 +302,17 @@ type PermitsStore = {
|
|
|
302
302
|
activePermitHash: ChainRecord<AccountRecord<string | undefined>>;
|
|
303
303
|
};
|
|
304
304
|
declare const PERMIT_STORE_DEFAULTS: PermitsStore;
|
|
305
|
-
declare const _permitStore: Omit<zustand_vanilla.StoreApi<PermitsStore>, "persist"> & {
|
|
305
|
+
declare const _permitStore: Omit<zustand_vanilla.StoreApi<PermitsStore>, "setState" | "persist"> & {
|
|
306
|
+
setState(partial: PermitsStore | Partial<PermitsStore> | ((state: PermitsStore) => PermitsStore | Partial<PermitsStore>), replace?: false | undefined): unknown;
|
|
307
|
+
setState(state: PermitsStore | ((state: PermitsStore) => PermitsStore), replace: true): unknown;
|
|
306
308
|
persist: {
|
|
307
|
-
setOptions: (options: Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore>>) => void;
|
|
309
|
+
setOptions: (options: Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore, unknown>>) => void;
|
|
308
310
|
clearStorage: () => void;
|
|
309
311
|
rehydrate: () => Promise<void> | void;
|
|
310
312
|
hasHydrated: () => boolean;
|
|
311
313
|
onHydrate: (fn: (state: PermitsStore) => void) => () => void;
|
|
312
314
|
onFinishHydration: (fn: (state: PermitsStore) => void) => () => void;
|
|
313
|
-
getOptions: () => Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore>>;
|
|
315
|
+
getOptions: () => Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore, unknown>>;
|
|
314
316
|
};
|
|
315
317
|
};
|
|
316
318
|
declare const clearStaleStore: () => void;
|
|
@@ -324,15 +326,17 @@ declare const setActivePermitHash: (chainId: number, account: string, hash: stri
|
|
|
324
326
|
declare const removeActivePermitHash: (chainId: number, account: string) => void;
|
|
325
327
|
declare const resetStore: () => void;
|
|
326
328
|
declare const permitStore: {
|
|
327
|
-
store: Omit<zustand_vanilla.StoreApi<PermitsStore>, "persist"> & {
|
|
329
|
+
store: Omit<zustand_vanilla.StoreApi<PermitsStore>, "setState" | "persist"> & {
|
|
330
|
+
setState(partial: PermitsStore | Partial<PermitsStore> | ((state: PermitsStore) => PermitsStore | Partial<PermitsStore>), replace?: false | undefined): unknown;
|
|
331
|
+
setState(state: PermitsStore | ((state: PermitsStore) => PermitsStore), replace: true): unknown;
|
|
328
332
|
persist: {
|
|
329
|
-
setOptions: (options: Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore>>) => void;
|
|
333
|
+
setOptions: (options: Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore, unknown>>) => void;
|
|
330
334
|
clearStorage: () => void;
|
|
331
335
|
rehydrate: () => Promise<void> | void;
|
|
332
336
|
hasHydrated: () => boolean;
|
|
333
337
|
onHydrate: (fn: (state: PermitsStore) => void) => () => void;
|
|
334
338
|
onFinishHydration: (fn: (state: PermitsStore) => void) => () => void;
|
|
335
|
-
getOptions: () => Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore>>;
|
|
339
|
+
getOptions: () => Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore, unknown>>;
|
|
336
340
|
};
|
|
337
341
|
};
|
|
338
342
|
getPermit: (chainId: number | undefined, account: string | undefined, hash: string | undefined) => Permit | undefined;
|
package/dist/permits.d.ts
CHANGED
|
@@ -302,15 +302,17 @@ type PermitsStore = {
|
|
|
302
302
|
activePermitHash: ChainRecord<AccountRecord<string | undefined>>;
|
|
303
303
|
};
|
|
304
304
|
declare const PERMIT_STORE_DEFAULTS: PermitsStore;
|
|
305
|
-
declare const _permitStore: Omit<zustand_vanilla.StoreApi<PermitsStore>, "persist"> & {
|
|
305
|
+
declare const _permitStore: Omit<zustand_vanilla.StoreApi<PermitsStore>, "setState" | "persist"> & {
|
|
306
|
+
setState(partial: PermitsStore | Partial<PermitsStore> | ((state: PermitsStore) => PermitsStore | Partial<PermitsStore>), replace?: false | undefined): unknown;
|
|
307
|
+
setState(state: PermitsStore | ((state: PermitsStore) => PermitsStore), replace: true): unknown;
|
|
306
308
|
persist: {
|
|
307
|
-
setOptions: (options: Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore>>) => void;
|
|
309
|
+
setOptions: (options: Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore, unknown>>) => void;
|
|
308
310
|
clearStorage: () => void;
|
|
309
311
|
rehydrate: () => Promise<void> | void;
|
|
310
312
|
hasHydrated: () => boolean;
|
|
311
313
|
onHydrate: (fn: (state: PermitsStore) => void) => () => void;
|
|
312
314
|
onFinishHydration: (fn: (state: PermitsStore) => void) => () => void;
|
|
313
|
-
getOptions: () => Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore>>;
|
|
315
|
+
getOptions: () => Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore, unknown>>;
|
|
314
316
|
};
|
|
315
317
|
};
|
|
316
318
|
declare const clearStaleStore: () => void;
|
|
@@ -324,15 +326,17 @@ declare const setActivePermitHash: (chainId: number, account: string, hash: stri
|
|
|
324
326
|
declare const removeActivePermitHash: (chainId: number, account: string) => void;
|
|
325
327
|
declare const resetStore: () => void;
|
|
326
328
|
declare const permitStore: {
|
|
327
|
-
store: Omit<zustand_vanilla.StoreApi<PermitsStore>, "persist"> & {
|
|
329
|
+
store: Omit<zustand_vanilla.StoreApi<PermitsStore>, "setState" | "persist"> & {
|
|
330
|
+
setState(partial: PermitsStore | Partial<PermitsStore> | ((state: PermitsStore) => PermitsStore | Partial<PermitsStore>), replace?: false | undefined): unknown;
|
|
331
|
+
setState(state: PermitsStore | ((state: PermitsStore) => PermitsStore), replace: true): unknown;
|
|
328
332
|
persist: {
|
|
329
|
-
setOptions: (options: Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore>>) => void;
|
|
333
|
+
setOptions: (options: Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore, unknown>>) => void;
|
|
330
334
|
clearStorage: () => void;
|
|
331
335
|
rehydrate: () => Promise<void> | void;
|
|
332
336
|
hasHydrated: () => boolean;
|
|
333
337
|
onHydrate: (fn: (state: PermitsStore) => void) => () => void;
|
|
334
338
|
onFinishHydration: (fn: (state: PermitsStore) => void) => () => void;
|
|
335
|
-
getOptions: () => Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore>>;
|
|
339
|
+
getOptions: () => Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore, unknown>>;
|
|
336
340
|
};
|
|
337
341
|
};
|
|
338
342
|
getPermit: (chainId: number | undefined, account: string | undefined, hash: string | undefined) => Permit | undefined;
|
package/dist/permits.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { GenerateSealingKey, ImportPermitOptionsValidator, ImportPermitValidator, PERMIT_STORE_DEFAULTS, PermitUtils, SealingKey, SelfPermitOptionsValidator, SelfPermitValidator, SharingPermitOptionsValidator, SharingPermitValidator, SignatureTypes, SignatureUtils, ValidationUtils, _permitStore, addressNotZeroSchema, addressSchema, bytesNotEmptySchema, bytesSchema, clearStaleStore, getActivePermit, getActivePermitHash, getPermit, getPermits, getSignatureTypesAndMessage, permitStore, removeActivePermitHash, removePermit, resetStore, setActivePermitHash, setPermit, validateImportPermit, validateImportPermitOptions, validateSelfPermit, validateSelfPermitOptions, validateSharingPermit, validateSharingPermitOptions } from './chunk-
|
|
2
|
-
import './chunk-
|
|
1
|
+
export { GenerateSealingKey, ImportPermitOptionsValidator, ImportPermitValidator, PERMIT_STORE_DEFAULTS, PermitUtils, SealingKey, SelfPermitOptionsValidator, SelfPermitValidator, SharingPermitOptionsValidator, SharingPermitValidator, SignatureTypes, SignatureUtils, ValidationUtils, _permitStore, addressNotZeroSchema, addressSchema, bytesNotEmptySchema, bytesSchema, clearStaleStore, getActivePermit, getActivePermitHash, getPermit, getPermits, getSignatureTypesAndMessage, permitStore, removeActivePermitHash, removePermit, resetStore, setActivePermitHash, setPermit, validateImportPermit, validateImportPermitOptions, validateSelfPermit, validateSelfPermitOptions, validateSharingPermit, validateSharingPermitOptions } from './chunk-VB62WYPL.js';
|
|
2
|
+
import './chunk-ESMZCFJY.js';
|
package/dist/web.cjs
CHANGED
|
@@ -393,7 +393,7 @@ var zkVerify = async (verifierUrl, serializedBytes, address, securityZone, chain
|
|
|
393
393
|
}
|
|
394
394
|
};
|
|
395
395
|
var concatSigRecid = (signature, recid) => {
|
|
396
|
-
return signature
|
|
396
|
+
return `${signature}${(recid + 27).toString(16).padStart(2, "0")}`;
|
|
397
397
|
};
|
|
398
398
|
|
|
399
399
|
// core/encrypt/MockZkVerifierAbi.ts
|
|
@@ -725,9 +725,9 @@ var hardhat2 = defineChain({
|
|
|
725
725
|
name: "Hardhat",
|
|
726
726
|
network: "localhost",
|
|
727
727
|
// These are unused in the mock environment
|
|
728
|
-
coFheUrl: "http://
|
|
729
|
-
verifierUrl: "http://
|
|
730
|
-
thresholdNetworkUrl: "http://
|
|
728
|
+
coFheUrl: "http://ignored-in-mock-environment",
|
|
729
|
+
verifierUrl: "http://ignored-in-mock-environment",
|
|
730
|
+
thresholdNetworkUrl: "http://ignored-in-mock-environment",
|
|
731
731
|
environment: "MOCK"
|
|
732
732
|
});
|
|
733
733
|
var CofheConfigSchema = zod.z.object({
|
|
@@ -1113,6 +1113,7 @@ var EncryptInputsBuilder = class extends BaseBuilder {
|
|
|
1113
1113
|
securityZone;
|
|
1114
1114
|
stepCallback;
|
|
1115
1115
|
inputItems;
|
|
1116
|
+
hpp = false;
|
|
1116
1117
|
zkvWalletClient;
|
|
1117
1118
|
tfhePublicKeyDeserializer;
|
|
1118
1119
|
compactPkeCrsDeserializer;
|
|
@@ -1242,6 +1243,20 @@ var EncryptInputsBuilder = class extends BaseBuilder {
|
|
|
1242
1243
|
getSecurityZone() {
|
|
1243
1244
|
return this.securityZone;
|
|
1244
1245
|
}
|
|
1246
|
+
/**
|
|
1247
|
+
* Example:
|
|
1248
|
+
* ```typescript
|
|
1249
|
+
* const encrypted = await encryptInputs([Encryptable.uint128(10n)])
|
|
1250
|
+
* .asHashPlusProof()
|
|
1251
|
+
* .execute();
|
|
1252
|
+
* ```
|
|
1253
|
+
*
|
|
1254
|
+
* @returns Chainable EncryptInputsBuilder instance that will return a HashPlusProofResult instead of an array of EncryptedItemInputs.
|
|
1255
|
+
*/
|
|
1256
|
+
asHashPlusProof() {
|
|
1257
|
+
this.hpp = true;
|
|
1258
|
+
return this;
|
|
1259
|
+
}
|
|
1245
1260
|
/**
|
|
1246
1261
|
* @param useWorker - Whether to use Web Workers for ZK proof generation.
|
|
1247
1262
|
*
|
|
@@ -1523,6 +1538,15 @@ var EncryptInputsBuilder = class extends BaseBuilder {
|
|
|
1523
1538
|
this.fireStepEnd("verify" /* Verify */);
|
|
1524
1539
|
return encryptedInputs;
|
|
1525
1540
|
}
|
|
1541
|
+
structsToHashPlusProof(inItems) {
|
|
1542
|
+
let hashes = [];
|
|
1543
|
+
let proof = "";
|
|
1544
|
+
for (const item of inItems) {
|
|
1545
|
+
hashes.push("0x" + item.ctHash.toString(16).padStart(64, "0"));
|
|
1546
|
+
proof += item.signature;
|
|
1547
|
+
}
|
|
1548
|
+
return [...hashes, proof];
|
|
1549
|
+
}
|
|
1526
1550
|
/**
|
|
1527
1551
|
* Final step of the encryption process. MUST BE CALLED LAST IN THE CHAIN.
|
|
1528
1552
|
*
|
|
@@ -1543,9 +1567,14 @@ var EncryptInputsBuilder = class extends BaseBuilder {
|
|
|
1543
1567
|
* @returns The encrypted inputs.
|
|
1544
1568
|
*/
|
|
1545
1569
|
async execute() {
|
|
1570
|
+
let items;
|
|
1546
1571
|
if (this.chainId === chains.hardhat.id)
|
|
1547
|
-
|
|
1548
|
-
|
|
1572
|
+
items = await this.mocksExecute();
|
|
1573
|
+
else
|
|
1574
|
+
items = await this.productionExecute();
|
|
1575
|
+
if (this.hpp)
|
|
1576
|
+
return this.structsToHashPlusProof(items);
|
|
1577
|
+
return items;
|
|
1549
1578
|
}
|
|
1550
1579
|
};
|
|
1551
1580
|
|
|
@@ -2568,7 +2597,7 @@ var getOrCreateSelfPermit = async (publicClient, walletClient, chainId, account,
|
|
|
2568
2597
|
const _chainId = chainId ?? await publicClient.getChainId();
|
|
2569
2598
|
const _account = account ?? walletClient.account.address;
|
|
2570
2599
|
const activePermit = await getActivePermit2(_chainId, _account);
|
|
2571
|
-
if (activePermit && activePermit.type === "self") {
|
|
2600
|
+
if (activePermit && activePermit.type === "self" && PermitUtils.isValid(activePermit).valid) {
|
|
2572
2601
|
return activePermit;
|
|
2573
2602
|
}
|
|
2574
2603
|
return createSelf(options ?? { issuer: _account, name: "Autogenerated Self Permit" }, publicClient, walletClient);
|
|
@@ -2577,7 +2606,7 @@ var getOrCreateSharingPermit = async (publicClient, walletClient, options, chain
|
|
|
2577
2606
|
const _chainId = chainId ?? await publicClient.getChainId();
|
|
2578
2607
|
const _account = account ?? walletClient.account.address;
|
|
2579
2608
|
const activePermit = await getActivePermit2(_chainId, _account);
|
|
2580
|
-
if (activePermit && activePermit.type === "sharing") {
|
|
2609
|
+
if (activePermit && activePermit.type === "sharing" && PermitUtils.isValid(activePermit).valid) {
|
|
2581
2610
|
return activePermit;
|
|
2582
2611
|
}
|
|
2583
2612
|
return createSharing(options, publicClient, walletClient);
|
|
@@ -2836,6 +2865,29 @@ async function cofheMocksDecryptForView(ctHash, utype, permit, publicClient) {
|
|
|
2836
2865
|
return unsealed;
|
|
2837
2866
|
}
|
|
2838
2867
|
|
|
2868
|
+
// core/debug.ts
|
|
2869
|
+
var interceptors = {};
|
|
2870
|
+
async function cofheFetch(url, init, ctx = { op: "request" }) {
|
|
2871
|
+
let finalUrl = url;
|
|
2872
|
+
let finalInit = init;
|
|
2873
|
+
if (interceptors.onRequest) {
|
|
2874
|
+
const override = await interceptors.onRequest(finalUrl, finalInit, ctx);
|
|
2875
|
+
if (override) {
|
|
2876
|
+
if (override.url !== void 0)
|
|
2877
|
+
finalUrl = override.url;
|
|
2878
|
+
if (override.init !== void 0)
|
|
2879
|
+
finalInit = override.init;
|
|
2880
|
+
}
|
|
2881
|
+
}
|
|
2882
|
+
let response = await fetch(finalUrl, finalInit);
|
|
2883
|
+
if (interceptors.onResponse) {
|
|
2884
|
+
const replaced = await interceptors.onResponse(response, ctx);
|
|
2885
|
+
if (replaced)
|
|
2886
|
+
response = replaced;
|
|
2887
|
+
}
|
|
2888
|
+
return response;
|
|
2889
|
+
}
|
|
2890
|
+
|
|
2839
2891
|
// core/decrypt/polling.ts
|
|
2840
2892
|
function computeMinuteRampPollIntervalMs(elapsedMs, params) {
|
|
2841
2893
|
const elapsedSeconds = Math.floor(elapsedMs / 1e3);
|
|
@@ -3005,13 +3057,17 @@ async function submitSealOutputRequest(thresholdNetworkUrl, ctHash, chainId, per
|
|
|
3005
3057
|
for (; ; ) {
|
|
3006
3058
|
let response;
|
|
3007
3059
|
try {
|
|
3008
|
-
response = await
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3060
|
+
response = await cofheFetch(
|
|
3061
|
+
`${thresholdNetworkUrl}/v2/sealoutput`,
|
|
3062
|
+
/*op:sealoutput*/
|
|
3063
|
+
{
|
|
3064
|
+
method: "POST",
|
|
3065
|
+
headers: {
|
|
3066
|
+
"Content-Type": "application/json"
|
|
3067
|
+
},
|
|
3068
|
+
body: JSON.stringify(body)
|
|
3069
|
+
}
|
|
3070
|
+
);
|
|
3015
3071
|
} catch (e) {
|
|
3016
3072
|
throw new CofheError({
|
|
3017
3073
|
code: "SEAL_OUTPUT_FAILED" /* SealOutputFailed */,
|
|
@@ -3134,12 +3190,16 @@ async function pollSealOutputStatus(thresholdNetworkUrl, requestId, overallStart
|
|
|
3134
3190
|
}
|
|
3135
3191
|
let response;
|
|
3136
3192
|
try {
|
|
3137
|
-
response = await
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3193
|
+
response = await cofheFetch(
|
|
3194
|
+
`${thresholdNetworkUrl}/v2/sealoutput/${requestId}`,
|
|
3195
|
+
/*op:sealoutput-poll*/
|
|
3196
|
+
{
|
|
3197
|
+
method: "GET",
|
|
3198
|
+
headers: {
|
|
3199
|
+
"Content-Type": "application/json"
|
|
3200
|
+
}
|
|
3141
3201
|
}
|
|
3142
|
-
|
|
3202
|
+
);
|
|
3143
3203
|
} catch (e) {
|
|
3144
3204
|
throw new CofheError({
|
|
3145
3205
|
code: "SEAL_OUTPUT_FAILED" /* SealOutputFailed */,
|
|
@@ -3736,13 +3796,17 @@ async function submitDecryptRequestV2(thresholdNetworkUrl, ctHash, chainId, perm
|
|
|
3736
3796
|
for (; ; ) {
|
|
3737
3797
|
let response;
|
|
3738
3798
|
try {
|
|
3739
|
-
response = await
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3799
|
+
response = await cofheFetch(
|
|
3800
|
+
`${thresholdNetworkUrl}/v2/decrypt`,
|
|
3801
|
+
/*op:decrypt*/
|
|
3802
|
+
{
|
|
3803
|
+
method: "POST",
|
|
3804
|
+
headers: {
|
|
3805
|
+
"Content-Type": "application/json"
|
|
3806
|
+
},
|
|
3807
|
+
body: JSON.stringify(body)
|
|
3808
|
+
}
|
|
3809
|
+
);
|
|
3746
3810
|
} catch (e) {
|
|
3747
3811
|
throw new CofheError({
|
|
3748
3812
|
code: "DECRYPT_FAILED" /* DecryptFailed */,
|
|
@@ -3867,12 +3931,16 @@ async function pollDecryptStatusV2(thresholdNetworkUrl, requestId, overallStartT
|
|
|
3867
3931
|
}
|
|
3868
3932
|
let response;
|
|
3869
3933
|
try {
|
|
3870
|
-
response = await
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3934
|
+
response = await cofheFetch(
|
|
3935
|
+
`${thresholdNetworkUrl}/v2/decrypt/${requestId}`,
|
|
3936
|
+
/*op:decrypt-poll*/
|
|
3937
|
+
{
|
|
3938
|
+
method: "GET",
|
|
3939
|
+
headers: {
|
|
3940
|
+
"Content-Type": "application/json"
|
|
3941
|
+
}
|
|
3874
3942
|
}
|
|
3875
|
-
|
|
3943
|
+
);
|
|
3876
3944
|
} catch (e) {
|
|
3877
3945
|
throw new CofheError({
|
|
3878
3946
|
code: "DECRYPT_FAILED" /* DecryptFailed */,
|
package/dist/web.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as IStorage, C as CofheInputConfig, a as CofheConfig, b as CofheClient, E as EncryptableItem } from './clientTypes-
|
|
1
|
+
import { I as IStorage, C as CofheInputConfig, a as CofheConfig, b as CofheClient, E as EncryptableItem } from './clientTypes-BDy1qIBu.cjs';
|
|
2
2
|
import 'viem';
|
|
3
3
|
import './types-C07FK-cL.cjs';
|
|
4
4
|
import 'zod';
|
package/dist/web.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as IStorage, C as CofheInputConfig, a as CofheConfig, b as CofheClient, E as EncryptableItem } from './clientTypes-
|
|
1
|
+
import { I as IStorage, C as CofheInputConfig, a as CofheConfig, b as CofheClient, E as EncryptableItem } from './clientTypes-CyUvRRzA.js';
|
|
2
2
|
import 'viem';
|
|
3
3
|
import './types-C07FK-cL.js';
|
|
4
4
|
import 'zod';
|
package/dist/web.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { createCofheConfigBase, createCofheClientBase, fheTypeToString } from './chunk-
|
|
2
|
-
import './chunk-
|
|
3
|
-
import './chunk-
|
|
4
|
-
import { TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT } from './chunk-
|
|
1
|
+
import { createCofheConfigBase, createCofheClientBase, fheTypeToString } from './chunk-NOC3PYB7.js';
|
|
2
|
+
import './chunk-MTRAXQXC.js';
|
|
3
|
+
import './chunk-VB62WYPL.js';
|
|
4
|
+
import { TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT } from './chunk-ESMZCFJY.js';
|
|
5
5
|
import { constructClient } from 'iframe-shared-storage';
|
|
6
6
|
|
|
7
7
|
// web/const.ts
|
package/dist/zkProve.worker.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cofhe/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "SDK for Fhenix COFHE coprocessor interaction",
|
|
6
6
|
"main": "./dist/core.cjs",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"tweetnacl": "1.0.3",
|
|
65
65
|
"viem": "2.38.6",
|
|
66
66
|
"zod": "4.0.0",
|
|
67
|
-
"zustand": "5.0.
|
|
67
|
+
"zustand": "5.0.13"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
70
|
"@nomicfoundation/hardhat-ethers": "^3.0.0",
|
package/permits/store.ts
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { describe, expect, it, vi, afterEach } from 'vitest';
|
|
2
|
+
|
|
3
|
+
describe('@cofhe/sdk/web SSR smoke', () => {
|
|
4
|
+
afterEach(() => {
|
|
5
|
+
vi.restoreAllMocks();
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it('imports and creates config in a Node SSR environment', async () => {
|
|
9
|
+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
10
|
+
|
|
11
|
+
expect((globalThis as { window?: unknown }).window).toBeUndefined();
|
|
12
|
+
expect((globalThis as { document?: unknown }).document).toBeUndefined();
|
|
13
|
+
|
|
14
|
+
const web = await import('../index');
|
|
15
|
+
const config = web.createCofheConfig({ supportedChains: [] });
|
|
16
|
+
|
|
17
|
+
expect(web.hasDOM).toBe(false);
|
|
18
|
+
expect(config.environment).toBe('web');
|
|
19
|
+
expect(config.fheKeyStorage).not.toBeNull();
|
|
20
|
+
expect(() => web.createCofheClient(config)).not.toThrow();
|
|
21
|
+
expect(warnSpy).toHaveBeenCalledWith('using no-op server-side SSR storage');
|
|
22
|
+
});
|
|
23
|
+
});
|