@cofhe/sdk 0.4.0 → 0.5.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 +38 -0
- package/adapters/{ethers5.test.ts → test/ethers5.test.ts} +2 -2
- package/adapters/{ethers6.test.ts → test/ethers6.test.ts} +2 -2
- package/adapters/{hardhat.hh2.test.ts → test/hardhat.hh2.test.ts} +2 -2
- package/adapters/{index.test.ts → test/index.test.ts} +1 -1
- package/adapters/{wagmi.test.ts → test/wagmi.test.ts} +1 -1
- package/chains/{chains.test.ts → test/chains.test.ts} +1 -1
- package/core/client.ts +11 -1
- package/core/clientTypes.ts +3 -1
- package/core/consts.ts +9 -0
- package/core/decrypt/cofheMocksDecryptForTx.ts +14 -3
- package/core/decrypt/decryptForTxBuilder.ts +16 -2
- package/core/decrypt/decryptForViewBuilder.ts +14 -7
- package/core/decrypt/polling.ts +14 -0
- package/core/decrypt/tnDecryptV2.ts +250 -110
- package/core/decrypt/tnSealOutputV2.ts +245 -104
- package/core/decrypt/verifyDecryptResult.ts +65 -0
- package/core/encrypt/cofheMocksZkVerifySign.ts +6 -6
- package/core/encrypt/zkPackProveVerify.ts +10 -19
- package/core/fetchKeys.ts +0 -2
- package/core/index.ts +9 -1
- package/core/keyStore.ts +5 -2
- package/core/permits.ts +5 -0
- package/core/{client.test.ts → test/client.test.ts} +7 -7
- package/core/{config.test.ts → test/config.test.ts} +1 -1
- package/core/test/decrypt.test.ts +252 -0
- package/core/test/decryptBuilders.test.ts +390 -0
- package/core/{encrypt → test}/encryptInputsBuilder.test.ts +61 -6
- package/core/{fetchKeys.test.ts → test/fetchKeys.test.ts} +3 -3
- package/core/{keyStore.test.ts → test/keyStore.test.ts} +5 -3
- package/core/{permits.test.ts → test/permits.test.ts} +42 -1
- package/core/test/pollCallbacks.test.ts +563 -0
- package/core/types.ts +13 -0
- package/dist/chains.d.cts +2 -2
- package/dist/chains.d.ts +2 -2
- package/dist/chunk-4FP4V35O.js +13 -0
- package/dist/{chunk-NWDKXBIP.js → chunk-MRCKUMOS.js} +62 -22
- package/dist/{chunk-MXND5SVN.js → chunk-S7OKGLFD.js} +485 -207
- package/dist/{clientTypes-kkrRdawm.d.ts → clientTypes-BSbwairE.d.cts} +23 -6
- package/dist/{clientTypes-ACVWbrXL.d.cts → clientTypes-DDmcgZ0a.d.ts} +23 -6
- package/dist/core.cjs +561 -244
- package/dist/core.d.cts +24 -6
- package/dist/core.d.ts +24 -6
- package/dist/core.js +3 -2
- package/dist/node.cjs +566 -246
- package/dist/node.d.cts +3 -3
- package/dist/node.d.ts +3 -3
- package/dist/node.js +14 -7
- package/dist/{permit-MZ502UBl.d.cts → permit-DnVMDT5h.d.cts} +34 -4
- package/dist/{permit-MZ502UBl.d.ts → permit-DnVMDT5h.d.ts} +34 -4
- package/dist/permits.cjs +66 -29
- package/dist/permits.d.cts +18 -13
- package/dist/permits.d.ts +18 -13
- package/dist/permits.js +2 -1
- package/dist/web.cjs +604 -256
- package/dist/web.d.cts +8 -4
- package/dist/web.d.ts +8 -4
- package/dist/web.js +49 -14
- package/dist/zkProve.worker.cjs +72 -64
- package/dist/zkProve.worker.js +71 -64
- package/node/index.ts +13 -4
- package/node/test/client.test.ts +25 -0
- package/node/test/config.test.ts +16 -0
- package/node/test/inherited.test.ts +244 -0
- package/node/test/tfheinit.test.ts +56 -0
- package/package.json +24 -22
- package/permits/permit.ts +31 -5
- package/permits/sealing.ts +1 -1
- package/permits/{localstorage.test.ts → test/localstorage.test.ts} +2 -2
- package/permits/{permit.test.ts → test/permit.test.ts} +35 -1
- package/permits/{sealing.test.ts → test/sealing.test.ts} +1 -1
- package/permits/{store.test.ts → test/store.test.ts} +2 -2
- package/permits/{validation.test.ts → test/validation.test.ts} +82 -6
- package/permits/types.ts +1 -1
- package/permits/validation.ts +42 -2
- package/web/const.ts +2 -0
- package/web/index.ts +40 -11
- package/web/storage.ts +18 -3
- package/web/{client.web.test.ts → test/client.web.test.ts} +13 -1
- package/web/test/config.web.test.ts +16 -0
- package/web/test/inherited.web.test.ts +245 -0
- package/web/test/tfheinit.web.test.ts +62 -0
- package/web/{worker.config.web.test.ts → test/worker.config.web.test.ts} +1 -1
- package/web/{worker.output.web.test.ts → test/worker.output.web.test.ts} +1 -1
- package/web/{workerManager.test.ts → test/workerManager.test.ts} +1 -1
- package/web/{workerManager.web.test.ts → test/workerManager.web.test.ts} +1 -1
- package/web/zkProve.worker.ts +94 -84
- package/node/client.test.ts +0 -147
- package/node/config.test.ts +0 -68
- package/node/encryptInputs.test.ts +0 -155
- package/web/config.web.test.ts +0 -69
- package/web/encryptInputs.web.test.ts +0 -172
- package/web/worker.builder.web.test.ts +0 -148
- /package/dist/{types-YiAC4gig.d.cts → types-C07FK-cL.d.cts} +0 -0
- /package/dist/{types-YiAC4gig.d.ts → types-C07FK-cL.d.ts} +0 -0
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { TASK_MANAGER_ADDRESS } from './chunk-4FP4V35O.js';
|
|
2
|
+
import { isAddress, getAddress, zeroAddress, isHex, keccak256, toHex, BaseError, ContractFunctionRevertedError, decodeErrorResult, parseAbi } from 'viem';
|
|
3
|
+
import nacl from 'tweetnacl';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
import { createStore } from 'zustand/vanilla';
|
|
5
6
|
import { persist } from 'zustand/middleware';
|
|
6
7
|
import { produce } from 'immer';
|
|
7
8
|
|
|
8
|
-
// permits/permit.ts
|
|
9
|
-
|
|
10
9
|
// permits/utils.ts
|
|
11
10
|
var fromHexString = (hexString) => {
|
|
12
11
|
const cleanString = hexString.length % 2 === 1 ? `0${hexString}` : hexString;
|
|
@@ -292,9 +291,9 @@ var ValidationUtils = {
|
|
|
292
291
|
return false;
|
|
293
292
|
},
|
|
294
293
|
/**
|
|
295
|
-
*
|
|
294
|
+
* Checks that a permit is signed and not expired.
|
|
296
295
|
*/
|
|
297
|
-
|
|
296
|
+
isSignedAndNotExpired: (permit) => {
|
|
298
297
|
if (ValidationUtils.isExpired(permit)) {
|
|
299
298
|
return { valid: false, error: "expired" };
|
|
300
299
|
}
|
|
@@ -302,6 +301,34 @@ var ValidationUtils = {
|
|
|
302
301
|
return { valid: false, error: "not-signed" };
|
|
303
302
|
}
|
|
304
303
|
return { valid: true, error: null };
|
|
304
|
+
},
|
|
305
|
+
/**
|
|
306
|
+
* Asserts that a permit is signed and not expired.
|
|
307
|
+
*
|
|
308
|
+
* Throws `Error` with message:
|
|
309
|
+
* - `Permit is expired`
|
|
310
|
+
* - `Permit is not signed`
|
|
311
|
+
*/
|
|
312
|
+
assertSignedAndNotExpired: (permit) => {
|
|
313
|
+
const result = ValidationUtils.isSignedAndNotExpired(permit);
|
|
314
|
+
if (result.valid)
|
|
315
|
+
return;
|
|
316
|
+
if (result.error === "expired") {
|
|
317
|
+
throw new Error("Permit is expired");
|
|
318
|
+
}
|
|
319
|
+
if (result.error === "not-signed") {
|
|
320
|
+
throw new Error("Permit is not signed");
|
|
321
|
+
}
|
|
322
|
+
throw new Error("Permit is invalid");
|
|
323
|
+
},
|
|
324
|
+
isValid: (permit) => {
|
|
325
|
+
const schema = permit.type === "self" ? SelfPermitValidator : permit.type === "sharing" ? SharingPermitValidator : permit.type === "recipient" ? ImportPermitValidator : null;
|
|
326
|
+
if (schema == null)
|
|
327
|
+
return { valid: false, error: "invalid-schema" };
|
|
328
|
+
const schemaResult = schema.safeParse(permit);
|
|
329
|
+
if (!schemaResult.success)
|
|
330
|
+
return { valid: false, error: "invalid-schema" };
|
|
331
|
+
return ValidationUtils.isSignedAndNotExpired(permit);
|
|
305
332
|
}
|
|
306
333
|
};
|
|
307
334
|
|
|
@@ -365,17 +392,6 @@ var SignatureUtils = {
|
|
|
365
392
|
throw new Error(`Unknown permit type: ${permitType}`);
|
|
366
393
|
}
|
|
367
394
|
};
|
|
368
|
-
|
|
369
|
-
// core/consts.ts
|
|
370
|
-
var TASK_MANAGER_ADDRESS = "0xeA30c4B8b44078Bbf8a6ef5b9f1eC1626C7848D9";
|
|
371
|
-
var MOCKS_ZK_VERIFIER_ADDRESS = "0x0000000000000000000000000000000000005001";
|
|
372
|
-
var MOCKS_THRESHOLD_NETWORK_ADDRESS = "0x0000000000000000000000000000000000005002";
|
|
373
|
-
var TEST_BED_ADDRESS = "0x0000000000000000000000000000000000005003";
|
|
374
|
-
var MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY = "0x6C8D7F768A6BB4AAFE85E8A2F5A9680355239C7E14646ED62B044E39DE154512";
|
|
375
|
-
var MOCKS_ZK_VERIFIER_SIGNER_ADDRESS = "0x6E12D8C87503D4287c294f2Fdef96ACd9DFf6bd2";
|
|
376
|
-
var MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY = "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d";
|
|
377
|
-
|
|
378
|
-
// permits/onchain-utils.ts
|
|
379
395
|
var getAclAddress = async (publicClient) => {
|
|
380
396
|
const ACL_IFACE = "function acl() view returns (address)";
|
|
381
397
|
const aclAbi = parseAbi([ACL_IFACE]);
|
|
@@ -694,9 +710,9 @@ var PermitUtils = {
|
|
|
694
710
|
};
|
|
695
711
|
},
|
|
696
712
|
/**
|
|
697
|
-
* Validate a permit
|
|
713
|
+
* Validate a permit (schema-level validation)
|
|
698
714
|
*/
|
|
699
|
-
|
|
715
|
+
validateSchema: (permit) => {
|
|
700
716
|
if (permit.type === "self") {
|
|
701
717
|
return validateSelfPermit(permit);
|
|
702
718
|
} else if (permit.type === "sharing") {
|
|
@@ -707,12 +723,27 @@ var PermitUtils = {
|
|
|
707
723
|
throw new Error("Invalid permit type");
|
|
708
724
|
}
|
|
709
725
|
},
|
|
726
|
+
/**
|
|
727
|
+
* Validate a permit (holistic validation).
|
|
728
|
+
*
|
|
729
|
+
* This validates:
|
|
730
|
+
* - Permit schema (shape + invariants)
|
|
731
|
+
* - Permit is signed
|
|
732
|
+
* - Permit is not expired
|
|
733
|
+
*
|
|
734
|
+
* For schema-only validation, use `validateSchema(permit)`.
|
|
735
|
+
*/
|
|
736
|
+
validate: (permit) => {
|
|
737
|
+
const validated = PermitUtils.validateSchema(permit);
|
|
738
|
+
ValidationUtils.assertSignedAndNotExpired(validated);
|
|
739
|
+
return validated;
|
|
740
|
+
},
|
|
710
741
|
/**
|
|
711
742
|
* Get the permission object from a permit (for use in contracts)
|
|
712
743
|
*/
|
|
713
744
|
getPermission: (permit, skipValidation = false) => {
|
|
714
745
|
if (!skipValidation) {
|
|
715
|
-
PermitUtils.
|
|
746
|
+
PermitUtils.validateSchema(permit);
|
|
716
747
|
}
|
|
717
748
|
return {
|
|
718
749
|
issuer: permit.issuer,
|
|
@@ -778,8 +809,17 @@ var PermitUtils = {
|
|
|
778
809
|
return ValidationUtils.isSigned(permit);
|
|
779
810
|
},
|
|
780
811
|
/**
|
|
781
|
-
* Check if permit is
|
|
812
|
+
* Check if permit is signed and not expired
|
|
782
813
|
*/
|
|
814
|
+
isSignedAndNotExpired: (permit) => {
|
|
815
|
+
return ValidationUtils.isSignedAndNotExpired(permit);
|
|
816
|
+
},
|
|
817
|
+
/**
|
|
818
|
+
* Assert that permit is signed and not expired
|
|
819
|
+
*/
|
|
820
|
+
assertSignedAndNotExpired: (permit) => {
|
|
821
|
+
return ValidationUtils.assertSignedAndNotExpired(permit);
|
|
822
|
+
},
|
|
783
823
|
isValid: (permit) => {
|
|
784
824
|
return ValidationUtils.isValid(permit);
|
|
785
825
|
},
|
|
@@ -935,4 +975,4 @@ var permitStore = {
|
|
|
935
975
|
resetStore
|
|
936
976
|
};
|
|
937
977
|
|
|
938
|
-
export { GenerateSealingKey, ImportPermitOptionsValidator, ImportPermitValidator,
|
|
978
|
+
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 };
|