@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.
Files changed (95) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/adapters/{ethers5.test.ts → test/ethers5.test.ts} +2 -2
  3. package/adapters/{ethers6.test.ts → test/ethers6.test.ts} +2 -2
  4. package/adapters/{hardhat.hh2.test.ts → test/hardhat.hh2.test.ts} +2 -2
  5. package/adapters/{index.test.ts → test/index.test.ts} +1 -1
  6. package/adapters/{wagmi.test.ts → test/wagmi.test.ts} +1 -1
  7. package/chains/{chains.test.ts → test/chains.test.ts} +1 -1
  8. package/core/client.ts +11 -1
  9. package/core/clientTypes.ts +3 -1
  10. package/core/consts.ts +9 -0
  11. package/core/decrypt/cofheMocksDecryptForTx.ts +14 -3
  12. package/core/decrypt/decryptForTxBuilder.ts +16 -2
  13. package/core/decrypt/decryptForViewBuilder.ts +14 -7
  14. package/core/decrypt/polling.ts +14 -0
  15. package/core/decrypt/tnDecryptV2.ts +250 -110
  16. package/core/decrypt/tnSealOutputV2.ts +245 -104
  17. package/core/decrypt/verifyDecryptResult.ts +65 -0
  18. package/core/encrypt/cofheMocksZkVerifySign.ts +6 -6
  19. package/core/encrypt/zkPackProveVerify.ts +10 -19
  20. package/core/fetchKeys.ts +0 -2
  21. package/core/index.ts +9 -1
  22. package/core/keyStore.ts +5 -2
  23. package/core/permits.ts +5 -0
  24. package/core/{client.test.ts → test/client.test.ts} +7 -7
  25. package/core/{config.test.ts → test/config.test.ts} +1 -1
  26. package/core/test/decrypt.test.ts +252 -0
  27. package/core/test/decryptBuilders.test.ts +390 -0
  28. package/core/{encrypt → test}/encryptInputsBuilder.test.ts +61 -6
  29. package/core/{fetchKeys.test.ts → test/fetchKeys.test.ts} +3 -3
  30. package/core/{keyStore.test.ts → test/keyStore.test.ts} +5 -3
  31. package/core/{permits.test.ts → test/permits.test.ts} +42 -1
  32. package/core/test/pollCallbacks.test.ts +563 -0
  33. package/core/types.ts +13 -0
  34. package/dist/chains.d.cts +2 -2
  35. package/dist/chains.d.ts +2 -2
  36. package/dist/chunk-4FP4V35O.js +13 -0
  37. package/dist/{chunk-NWDKXBIP.js → chunk-MRCKUMOS.js} +62 -22
  38. package/dist/{chunk-MXND5SVN.js → chunk-S7OKGLFD.js} +485 -207
  39. package/dist/{clientTypes-kkrRdawm.d.ts → clientTypes-BSbwairE.d.cts} +23 -6
  40. package/dist/{clientTypes-ACVWbrXL.d.cts → clientTypes-DDmcgZ0a.d.ts} +23 -6
  41. package/dist/core.cjs +561 -244
  42. package/dist/core.d.cts +24 -6
  43. package/dist/core.d.ts +24 -6
  44. package/dist/core.js +3 -2
  45. package/dist/node.cjs +566 -246
  46. package/dist/node.d.cts +3 -3
  47. package/dist/node.d.ts +3 -3
  48. package/dist/node.js +14 -7
  49. package/dist/{permit-MZ502UBl.d.cts → permit-DnVMDT5h.d.cts} +34 -4
  50. package/dist/{permit-MZ502UBl.d.ts → permit-DnVMDT5h.d.ts} +34 -4
  51. package/dist/permits.cjs +66 -29
  52. package/dist/permits.d.cts +18 -13
  53. package/dist/permits.d.ts +18 -13
  54. package/dist/permits.js +2 -1
  55. package/dist/web.cjs +604 -256
  56. package/dist/web.d.cts +8 -4
  57. package/dist/web.d.ts +8 -4
  58. package/dist/web.js +49 -14
  59. package/dist/zkProve.worker.cjs +72 -64
  60. package/dist/zkProve.worker.js +71 -64
  61. package/node/index.ts +13 -4
  62. package/node/test/client.test.ts +25 -0
  63. package/node/test/config.test.ts +16 -0
  64. package/node/test/inherited.test.ts +244 -0
  65. package/node/test/tfheinit.test.ts +56 -0
  66. package/package.json +24 -22
  67. package/permits/permit.ts +31 -5
  68. package/permits/sealing.ts +1 -1
  69. package/permits/{localstorage.test.ts → test/localstorage.test.ts} +2 -2
  70. package/permits/{permit.test.ts → test/permit.test.ts} +35 -1
  71. package/permits/{sealing.test.ts → test/sealing.test.ts} +1 -1
  72. package/permits/{store.test.ts → test/store.test.ts} +2 -2
  73. package/permits/{validation.test.ts → test/validation.test.ts} +82 -6
  74. package/permits/types.ts +1 -1
  75. package/permits/validation.ts +42 -2
  76. package/web/const.ts +2 -0
  77. package/web/index.ts +40 -11
  78. package/web/storage.ts +18 -3
  79. package/web/{client.web.test.ts → test/client.web.test.ts} +13 -1
  80. package/web/test/config.web.test.ts +16 -0
  81. package/web/test/inherited.web.test.ts +245 -0
  82. package/web/test/tfheinit.web.test.ts +62 -0
  83. package/web/{worker.config.web.test.ts → test/worker.config.web.test.ts} +1 -1
  84. package/web/{worker.output.web.test.ts → test/worker.output.web.test.ts} +1 -1
  85. package/web/{workerManager.test.ts → test/workerManager.test.ts} +1 -1
  86. package/web/{workerManager.web.test.ts → test/workerManager.web.test.ts} +1 -1
  87. package/web/zkProve.worker.ts +94 -84
  88. package/node/client.test.ts +0 -147
  89. package/node/config.test.ts +0 -68
  90. package/node/encryptInputs.test.ts +0 -155
  91. package/web/config.web.test.ts +0 -69
  92. package/web/encryptInputs.web.test.ts +0 -172
  93. package/web/worker.builder.web.test.ts +0 -148
  94. /package/dist/{types-YiAC4gig.d.cts → types-C07FK-cL.d.cts} +0 -0
  95. /package/dist/{types-YiAC4gig.d.ts → types-C07FK-cL.d.ts} +0 -0
package/dist/node.d.cts CHANGED
@@ -1,8 +1,8 @@
1
- import { C as CofheInputConfig, a as CofheConfig, b as CofheClient } from './clientTypes-ACVWbrXL.cjs';
1
+ import { C as CofheInputConfig, a as CofheConfig, b as CofheClient } from './clientTypes-BSbwairE.cjs';
2
2
  import 'viem';
3
- import './types-YiAC4gig.cjs';
3
+ import './types-C07FK-cL.cjs';
4
4
  import 'zod';
5
- import './permit-MZ502UBl.cjs';
5
+ import './permit-DnVMDT5h.cjs';
6
6
  import 'zustand/vanilla';
7
7
 
8
8
  /**
package/dist/node.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { C as CofheInputConfig, a as CofheConfig, b as CofheClient } from './clientTypes-kkrRdawm.js';
1
+ import { C as CofheInputConfig, a as CofheConfig, b as CofheClient } from './clientTypes-DDmcgZ0a.js';
2
2
  import 'viem';
3
- import './types-YiAC4gig.js';
3
+ import './types-C07FK-cL.js';
4
4
  import 'zod';
5
- import './permit-MZ502UBl.js';
5
+ import './permit-DnVMDT5h.js';
6
6
  import 'zustand/vanilla';
7
7
 
8
8
  /**
package/dist/node.js CHANGED
@@ -1,9 +1,10 @@
1
- import { createCofheConfigBase, createCofheClientBase } from './chunk-MXND5SVN.js';
1
+ import { createCofheConfigBase, createCofheClientBase } from './chunk-S7OKGLFD.js';
2
2
  import './chunk-TBLR7NNE.js';
3
- import './chunk-NWDKXBIP.js';
3
+ import './chunk-MRCKUMOS.js';
4
+ import { TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT } from './chunk-4FP4V35O.js';
4
5
  import { promises } from 'fs';
5
6
  import { join } from 'path';
6
- import { init_panic_hook, TfheCompactPublicKey, CompactPkeCrs, ProvenCompactCiphertextList } from 'node-tfhe';
7
+ import { init_panic_hook, ProvenCompactCiphertextList, CompactPkeCrs, TfheCompactPublicKey } from 'node-tfhe';
7
8
 
8
9
  var memoryStorage = {};
9
10
  var createNodeStorage = () => {
@@ -59,16 +60,22 @@ var fromHexString = (hexString) => {
59
60
  return new Uint8Array();
60
61
  return new Uint8Array(arr.map((byte) => parseInt(byte, 16)));
61
62
  };
63
+ var _deserializeTfhePublicKey = (buff) => {
64
+ return TfheCompactPublicKey.safe_deserialize(fromHexString(buff), TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT);
65
+ };
66
+ var _deserializeCompactPkeCrs = (buff) => {
67
+ return CompactPkeCrs.safe_deserialize(fromHexString(buff), TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT);
68
+ };
62
69
  var tfhePublicKeyDeserializer = (buff) => {
63
- TfheCompactPublicKey.deserialize(fromHexString(buff));
70
+ _deserializeTfhePublicKey(buff);
64
71
  };
65
72
  var compactPkeCrsDeserializer = (buff) => {
66
- CompactPkeCrs.deserialize(fromHexString(buff));
73
+ _deserializeCompactPkeCrs(buff);
67
74
  };
68
75
  var zkBuilderAndCrsGenerator = (fhe, crs) => {
69
- const fhePublicKey = TfheCompactPublicKey.deserialize(fromHexString(fhe));
76
+ const fhePublicKey = _deserializeTfhePublicKey(fhe);
70
77
  const zkBuilder = ProvenCompactCiphertextList.builder(fhePublicKey);
71
- const zkCrs = CompactPkeCrs.deserialize(fromHexString(crs));
78
+ const zkCrs = _deserializeCompactPkeCrs(crs);
72
79
  return { zkBuilder, zkCrs };
73
80
  };
74
81
  function createCofheConfig(config) {
@@ -225,7 +225,7 @@ type PermitHashFields = Pick<Permit, 'type' | 'issuer' | 'expiration' | 'recipie
225
225
  */
226
226
  interface ValidationResult {
227
227
  valid: boolean;
228
- error: string | null;
228
+ error: 'invalid-schema' | 'expired' | 'not-signed' | null;
229
229
  }
230
230
  /**
231
231
  * Signature types for EIP712 signing
@@ -276,7 +276,32 @@ declare const PermitUtils: {
276
276
  */
277
277
  serialize: (permit: Permit) => SerializedPermit;
278
278
  /**
279
- * Validate a permit
279
+ * Validate a permit (schema-level validation)
280
+ */
281
+ validateSchema: (permit: Permit) => {
282
+ name: string;
283
+ type: "self" | "sharing" | "recipient";
284
+ issuer: `0x${string}`;
285
+ expiration: number;
286
+ recipient: `0x${string}`;
287
+ validatorId: number;
288
+ validatorContract: `0x${string}`;
289
+ issuerSignature: `0x${string}`;
290
+ recipientSignature: `0x${string}`;
291
+ sealingPair?: {
292
+ privateKey: string;
293
+ publicKey: string;
294
+ } | undefined;
295
+ };
296
+ /**
297
+ * Validate a permit (holistic validation).
298
+ *
299
+ * This validates:
300
+ * - Permit schema (shape + invariants)
301
+ * - Permit is signed
302
+ * - Permit is not expired
303
+ *
304
+ * For schema-only validation, use `validateSchema(permit)`.
280
305
  */
281
306
  validate: (permit: Permit) => {
282
307
  name: string;
@@ -318,8 +343,13 @@ declare const PermitUtils: {
318
343
  */
319
344
  isSigned: (permit: Permit) => boolean;
320
345
  /**
321
- * Check if permit is valid
346
+ * Check if permit is signed and not expired
347
+ */
348
+ isSignedAndNotExpired: (permit: Permit) => ValidationResult;
349
+ /**
350
+ * Assert that permit is signed and not expired
322
351
  */
352
+ assertSignedAndNotExpired: (permit: Permit) => void;
323
353
  isValid: (permit: Permit) => ValidationResult;
324
354
  /**
325
355
  * Update permit name (returns new permit instance)
@@ -343,4 +373,4 @@ declare const PermitUtils: {
343
373
  checkValidityOnChain: (permit: Permit, publicClient: PublicClient) => Promise<boolean>;
344
374
  };
345
375
 
346
- export { type CreateSelfPermitOptions as C, type EIP712Types as E, GenerateSealingKey as G, type ImportSharedPermitOptions as I, type Permit as P, type RecipientPermit as R, type SerializedPermit as S, type ValidationResult as V, type PermitSignaturePrimaryType as a, type Permission as b, type EIP712Message as c, type CreateSharingPermitOptions as d, type PermitMetadata as e, type EIP712Domain as f, PermitUtils as g, SealingKey$1 as h, type EthEncryptedData as i, type EIP712Type as j, type PermitType as k, type PermitOf as l, type SelfPermit as m, type SharingPermit as n, type PermitHashFields as o, type Expand as p };
376
+ export { type CreateSelfPermitOptions as C, type EIP712Types as E, GenerateSealingKey as G, type ImportSharedPermitOptions as I, type Permit as P, type RecipientPermit as R, type SerializedPermit as S, type ValidationResult as V, type Permission as a, type PermitSignaturePrimaryType as b, type EIP712Message as c, type CreateSharingPermitOptions as d, type PermitMetadata as e, type EIP712Domain as f, PermitUtils as g, SealingKey$1 as h, type EthEncryptedData as i, type EIP712Type as j, type PermitType as k, type PermitOf as l, type SelfPermit as m, type SharingPermit as n, type PermitHashFields as o, type Expand as p };
@@ -225,7 +225,7 @@ type PermitHashFields = Pick<Permit, 'type' | 'issuer' | 'expiration' | 'recipie
225
225
  */
226
226
  interface ValidationResult {
227
227
  valid: boolean;
228
- error: string | null;
228
+ error: 'invalid-schema' | 'expired' | 'not-signed' | null;
229
229
  }
230
230
  /**
231
231
  * Signature types for EIP712 signing
@@ -276,7 +276,32 @@ declare const PermitUtils: {
276
276
  */
277
277
  serialize: (permit: Permit) => SerializedPermit;
278
278
  /**
279
- * Validate a permit
279
+ * Validate a permit (schema-level validation)
280
+ */
281
+ validateSchema: (permit: Permit) => {
282
+ name: string;
283
+ type: "self" | "sharing" | "recipient";
284
+ issuer: `0x${string}`;
285
+ expiration: number;
286
+ recipient: `0x${string}`;
287
+ validatorId: number;
288
+ validatorContract: `0x${string}`;
289
+ issuerSignature: `0x${string}`;
290
+ recipientSignature: `0x${string}`;
291
+ sealingPair?: {
292
+ privateKey: string;
293
+ publicKey: string;
294
+ } | undefined;
295
+ };
296
+ /**
297
+ * Validate a permit (holistic validation).
298
+ *
299
+ * This validates:
300
+ * - Permit schema (shape + invariants)
301
+ * - Permit is signed
302
+ * - Permit is not expired
303
+ *
304
+ * For schema-only validation, use `validateSchema(permit)`.
280
305
  */
281
306
  validate: (permit: Permit) => {
282
307
  name: string;
@@ -318,8 +343,13 @@ declare const PermitUtils: {
318
343
  */
319
344
  isSigned: (permit: Permit) => boolean;
320
345
  /**
321
- * Check if permit is valid
346
+ * Check if permit is signed and not expired
347
+ */
348
+ isSignedAndNotExpired: (permit: Permit) => ValidationResult;
349
+ /**
350
+ * Assert that permit is signed and not expired
322
351
  */
352
+ assertSignedAndNotExpired: (permit: Permit) => void;
323
353
  isValid: (permit: Permit) => ValidationResult;
324
354
  /**
325
355
  * Update permit name (returns new permit instance)
@@ -343,4 +373,4 @@ declare const PermitUtils: {
343
373
  checkValidityOnChain: (permit: Permit, publicClient: PublicClient) => Promise<boolean>;
344
374
  };
345
375
 
346
- export { type CreateSelfPermitOptions as C, type EIP712Types as E, GenerateSealingKey as G, type ImportSharedPermitOptions as I, type Permit as P, type RecipientPermit as R, type SerializedPermit as S, type ValidationResult as V, type PermitSignaturePrimaryType as a, type Permission as b, type EIP712Message as c, type CreateSharingPermitOptions as d, type PermitMetadata as e, type EIP712Domain as f, PermitUtils as g, SealingKey$1 as h, type EthEncryptedData as i, type EIP712Type as j, type PermitType as k, type PermitOf as l, type SelfPermit as m, type SharingPermit as n, type PermitHashFields as o, type Expand as p };
376
+ export { type CreateSelfPermitOptions as C, type EIP712Types as E, GenerateSealingKey as G, type ImportSharedPermitOptions as I, type Permit as P, type RecipientPermit as R, type SerializedPermit as S, type ValidationResult as V, type Permission as a, type PermitSignaturePrimaryType as b, type EIP712Message as c, type CreateSharingPermitOptions as d, type PermitMetadata as e, type EIP712Domain as f, PermitUtils as g, SealingKey$1 as h, type EthEncryptedData as i, type EIP712Type as j, type PermitType as k, type PermitOf as l, type SelfPermit as m, type SharingPermit as n, type PermitHashFields as o, type Expand as p };
package/dist/permits.cjs CHANGED
@@ -7,25 +7,9 @@ var vanilla = require('zustand/vanilla');
7
7
  var middleware = require('zustand/middleware');
8
8
  var immer = require('immer');
9
9
 
10
- function _interopNamespace(e) {
11
- if (e && e.__esModule) return e;
12
- var n = Object.create(null);
13
- if (e) {
14
- Object.keys(e).forEach(function (k) {
15
- if (k !== 'default') {
16
- var d = Object.getOwnPropertyDescriptor(e, k);
17
- Object.defineProperty(n, k, d.get ? d : {
18
- enumerable: true,
19
- get: function () { return e[k]; }
20
- });
21
- }
22
- });
23
- }
24
- n.default = e;
25
- return Object.freeze(n);
26
- }
10
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
27
11
 
28
- var nacl__namespace = /*#__PURE__*/_interopNamespace(nacl);
12
+ var nacl__default = /*#__PURE__*/_interopDefault(nacl);
29
13
 
30
14
  // permits/permit.ts
31
15
 
@@ -112,7 +96,7 @@ var SealingKey = class _SealingKey {
112
96
  const ephemPublicKey = parsedData.public_key instanceof Uint8Array ? parsedData.public_key : new Uint8Array(parsedData.public_key);
113
97
  const dataToDecrypt = parsedData.data instanceof Uint8Array ? parsedData.data : new Uint8Array(parsedData.data);
114
98
  const privateKeyBytes = fromHexString(this.privateKey);
115
- const decryptedMessage = nacl__namespace.box.open(dataToDecrypt, nonce, ephemPublicKey, privateKeyBytes);
99
+ const decryptedMessage = nacl__default.default.box.open(dataToDecrypt, nonce, ephemPublicKey, privateKeyBytes);
116
100
  if (!decryptedMessage) {
117
101
  throw new Error("Failed to decrypt message");
118
102
  }
@@ -145,9 +129,9 @@ var SealingKey = class _SealingKey {
145
129
  static seal = (value, publicKey) => {
146
130
  isString(publicKey);
147
131
  isBigIntOrNumber(value);
148
- const ephemeralKeyPair = nacl__namespace.box.keyPair();
149
- const nonce = nacl__namespace.randomBytes(nacl__namespace.box.nonceLength);
150
- const encryptedMessage = nacl__namespace.box(toBeArray(value), nonce, fromHexString(publicKey), ephemeralKeyPair.secretKey);
132
+ const ephemeralKeyPair = nacl__default.default.box.keyPair();
133
+ const nonce = nacl__default.default.randomBytes(nacl__default.default.box.nonceLength);
134
+ const encryptedMessage = nacl__default.default.box(toBeArray(value), nonce, fromHexString(publicKey), ephemeralKeyPair.secretKey);
151
135
  return {
152
136
  data: encryptedMessage,
153
137
  public_key: ephemeralKeyPair.publicKey,
@@ -156,7 +140,7 @@ var SealingKey = class _SealingKey {
156
140
  };
157
141
  };
158
142
  var GenerateSealingKey = () => {
159
- const sodiumKeypair = nacl__namespace.box.keyPair();
143
+ const sodiumKeypair = nacl__default.default.box.keyPair();
160
144
  return new SealingKey(toHexString(sodiumKeypair.secretKey), toHexString(sodiumKeypair.publicKey));
161
145
  };
162
146
  var SerializedSealingPair = zod.z.object({
@@ -314,9 +298,9 @@ var ValidationUtils = {
314
298
  return false;
315
299
  },
316
300
  /**
317
- * Overall validity checker of a permit
301
+ * Checks that a permit is signed and not expired.
318
302
  */
319
- isValid: (permit) => {
303
+ isSignedAndNotExpired: (permit) => {
320
304
  if (ValidationUtils.isExpired(permit)) {
321
305
  return { valid: false, error: "expired" };
322
306
  }
@@ -324,6 +308,34 @@ var ValidationUtils = {
324
308
  return { valid: false, error: "not-signed" };
325
309
  }
326
310
  return { valid: true, error: null };
311
+ },
312
+ /**
313
+ * Asserts that a permit is signed and not expired.
314
+ *
315
+ * Throws `Error` with message:
316
+ * - `Permit is expired`
317
+ * - `Permit is not signed`
318
+ */
319
+ assertSignedAndNotExpired: (permit) => {
320
+ const result = ValidationUtils.isSignedAndNotExpired(permit);
321
+ if (result.valid)
322
+ return;
323
+ if (result.error === "expired") {
324
+ throw new Error("Permit is expired");
325
+ }
326
+ if (result.error === "not-signed") {
327
+ throw new Error("Permit is not signed");
328
+ }
329
+ throw new Error("Permit is invalid");
330
+ },
331
+ isValid: (permit) => {
332
+ const schema = permit.type === "self" ? SelfPermitValidator : permit.type === "sharing" ? SharingPermitValidator : permit.type === "recipient" ? ImportPermitValidator : null;
333
+ if (schema == null)
334
+ return { valid: false, error: "invalid-schema" };
335
+ const schemaResult = schema.safeParse(permit);
336
+ if (!schemaResult.success)
337
+ return { valid: false, error: "invalid-schema" };
338
+ return ValidationUtils.isSignedAndNotExpired(permit);
327
339
  }
328
340
  };
329
341
 
@@ -390,6 +402,7 @@ var SignatureUtils = {
390
402
 
391
403
  // core/consts.ts
392
404
  var TASK_MANAGER_ADDRESS = "0xeA30c4B8b44078Bbf8a6ef5b9f1eC1626C7848D9";
405
+ BigInt(1 << 30);
393
406
 
394
407
  // permits/onchain-utils.ts
395
408
  var getAclAddress = async (publicClient) => {
@@ -710,9 +723,9 @@ var PermitUtils = {
710
723
  };
711
724
  },
712
725
  /**
713
- * Validate a permit
726
+ * Validate a permit (schema-level validation)
714
727
  */
715
- validate: (permit) => {
728
+ validateSchema: (permit) => {
716
729
  if (permit.type === "self") {
717
730
  return validateSelfPermit(permit);
718
731
  } else if (permit.type === "sharing") {
@@ -723,12 +736,27 @@ var PermitUtils = {
723
736
  throw new Error("Invalid permit type");
724
737
  }
725
738
  },
739
+ /**
740
+ * Validate a permit (holistic validation).
741
+ *
742
+ * This validates:
743
+ * - Permit schema (shape + invariants)
744
+ * - Permit is signed
745
+ * - Permit is not expired
746
+ *
747
+ * For schema-only validation, use `validateSchema(permit)`.
748
+ */
749
+ validate: (permit) => {
750
+ const validated = PermitUtils.validateSchema(permit);
751
+ ValidationUtils.assertSignedAndNotExpired(validated);
752
+ return validated;
753
+ },
726
754
  /**
727
755
  * Get the permission object from a permit (for use in contracts)
728
756
  */
729
757
  getPermission: (permit, skipValidation = false) => {
730
758
  if (!skipValidation) {
731
- PermitUtils.validate(permit);
759
+ PermitUtils.validateSchema(permit);
732
760
  }
733
761
  return {
734
762
  issuer: permit.issuer,
@@ -794,8 +822,17 @@ var PermitUtils = {
794
822
  return ValidationUtils.isSigned(permit);
795
823
  },
796
824
  /**
797
- * Check if permit is valid
825
+ * Check if permit is signed and not expired
826
+ */
827
+ isSignedAndNotExpired: (permit) => {
828
+ return ValidationUtils.isSignedAndNotExpired(permit);
829
+ },
830
+ /**
831
+ * Assert that permit is signed and not expired
798
832
  */
833
+ assertSignedAndNotExpired: (permit) => {
834
+ return ValidationUtils.assertSignedAndNotExpired(permit);
835
+ },
799
836
  isValid: (permit) => {
800
837
  return ValidationUtils.isValid(permit);
801
838
  },
@@ -1,5 +1,5 @@
1
- import { P as Permit, V as ValidationResult, a as PermitSignaturePrimaryType, b as Permission, E as EIP712Types, c as EIP712Message, S as SerializedPermit } from './permit-MZ502UBl.cjs';
2
- export { C as CreateSelfPermitOptions, d as CreateSharingPermitOptions, f as EIP712Domain, j as EIP712Type, i as EthEncryptedData, p as Expand, G as GenerateSealingKey, I as ImportPermitOptions, I as ImportSharedPermitOptions, o as PermitHashFields, e as PermitMetadata, l as PermitOf, k as PermitType, g as PermitUtils, R as RecipientPermit, h as SealingKey, m as SelfPermit, C as SelfPermitOptions, n as SharingPermit, d as SharingPermitOptions } from './permit-MZ502UBl.cjs';
1
+ import { P as Permit, V as ValidationResult, a as Permission, b as PermitSignaturePrimaryType, E as EIP712Types, c as EIP712Message, S as SerializedPermit } from './permit-DnVMDT5h.cjs';
2
+ export { C as CreateSelfPermitOptions, d as CreateSharingPermitOptions, f as EIP712Domain, j as EIP712Type, i as EthEncryptedData, p as Expand, G as GenerateSealingKey, I as ImportPermitOptions, I as ImportSharedPermitOptions, o as PermitHashFields, e as PermitMetadata, l as PermitOf, k as PermitType, g as PermitUtils, R as RecipientPermit, h as SealingKey, m as SelfPermit, C as SelfPermitOptions, n as SharingPermit, d as SharingPermitOptions } from './permit-DnVMDT5h.cjs';
3
3
  import { z } from 'zod';
4
4
  import * as zustand_middleware from 'zustand/middleware';
5
5
  import * as zustand_vanilla from 'zustand/vanilla';
@@ -226,8 +226,17 @@ declare const ValidationUtils: {
226
226
  */
227
227
  isSigned: (permit: Permit) => boolean;
228
228
  /**
229
- * Overall validity checker of a permit
229
+ * Checks that a permit is signed and not expired.
230
230
  */
231
+ isSignedAndNotExpired: (permit: Permit) => ValidationResult;
232
+ /**
233
+ * Asserts that a permit is signed and not expired.
234
+ *
235
+ * Throws `Error` with message:
236
+ * - `Permit is expired`
237
+ * - `Permit is not signed`
238
+ */
239
+ assertSignedAndNotExpired: (permit: Permit) => void;
231
240
  isValid: (permit: Permit) => ValidationResult;
232
241
  };
233
242
 
@@ -293,17 +302,15 @@ type PermitsStore = {
293
302
  activePermitHash: ChainRecord<AccountRecord<string | undefined>>;
294
303
  };
295
304
  declare const PERMIT_STORE_DEFAULTS: PermitsStore;
296
- declare const _permitStore: Omit<zustand_vanilla.StoreApi<PermitsStore>, "setState" | "persist"> & {
297
- setState(partial: PermitsStore | Partial<PermitsStore> | ((state: PermitsStore) => PermitsStore | Partial<PermitsStore>), replace?: false | undefined): unknown;
298
- setState(state: PermitsStore | ((state: PermitsStore) => PermitsStore), replace: true): unknown;
305
+ declare const _permitStore: Omit<zustand_vanilla.StoreApi<PermitsStore>, "persist"> & {
299
306
  persist: {
300
- setOptions: (options: Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore, unknown>>) => void;
307
+ setOptions: (options: Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore>>) => void;
301
308
  clearStorage: () => void;
302
309
  rehydrate: () => Promise<void> | void;
303
310
  hasHydrated: () => boolean;
304
311
  onHydrate: (fn: (state: PermitsStore) => void) => () => void;
305
312
  onFinishHydration: (fn: (state: PermitsStore) => void) => () => void;
306
- getOptions: () => Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore, unknown>>;
313
+ getOptions: () => Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore>>;
307
314
  };
308
315
  };
309
316
  declare const clearStaleStore: () => void;
@@ -317,17 +324,15 @@ declare const setActivePermitHash: (chainId: number, account: string, hash: stri
317
324
  declare const removeActivePermitHash: (chainId: number, account: string) => void;
318
325
  declare const resetStore: () => void;
319
326
  declare const permitStore: {
320
- store: Omit<zustand_vanilla.StoreApi<PermitsStore>, "setState" | "persist"> & {
321
- setState(partial: PermitsStore | Partial<PermitsStore> | ((state: PermitsStore) => PermitsStore | Partial<PermitsStore>), replace?: false | undefined): unknown;
322
- setState(state: PermitsStore | ((state: PermitsStore) => PermitsStore), replace: true): unknown;
327
+ store: Omit<zustand_vanilla.StoreApi<PermitsStore>, "persist"> & {
323
328
  persist: {
324
- setOptions: (options: Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore, unknown>>) => void;
329
+ setOptions: (options: Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore>>) => void;
325
330
  clearStorage: () => void;
326
331
  rehydrate: () => Promise<void> | void;
327
332
  hasHydrated: () => boolean;
328
333
  onHydrate: (fn: (state: PermitsStore) => void) => () => void;
329
334
  onFinishHydration: (fn: (state: PermitsStore) => void) => () => void;
330
- getOptions: () => Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore, unknown>>;
335
+ getOptions: () => Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore>>;
331
336
  };
332
337
  };
333
338
  getPermit: (chainId: number | undefined, account: string | undefined, hash: string | undefined) => Permit | undefined;
package/dist/permits.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as Permit, V as ValidationResult, a as PermitSignaturePrimaryType, b as Permission, E as EIP712Types, c as EIP712Message, S as SerializedPermit } from './permit-MZ502UBl.js';
2
- export { C as CreateSelfPermitOptions, d as CreateSharingPermitOptions, f as EIP712Domain, j as EIP712Type, i as EthEncryptedData, p as Expand, G as GenerateSealingKey, I as ImportPermitOptions, I as ImportSharedPermitOptions, o as PermitHashFields, e as PermitMetadata, l as PermitOf, k as PermitType, g as PermitUtils, R as RecipientPermit, h as SealingKey, m as SelfPermit, C as SelfPermitOptions, n as SharingPermit, d as SharingPermitOptions } from './permit-MZ502UBl.js';
1
+ import { P as Permit, V as ValidationResult, a as Permission, b as PermitSignaturePrimaryType, E as EIP712Types, c as EIP712Message, S as SerializedPermit } from './permit-DnVMDT5h.js';
2
+ export { C as CreateSelfPermitOptions, d as CreateSharingPermitOptions, f as EIP712Domain, j as EIP712Type, i as EthEncryptedData, p as Expand, G as GenerateSealingKey, I as ImportPermitOptions, I as ImportSharedPermitOptions, o as PermitHashFields, e as PermitMetadata, l as PermitOf, k as PermitType, g as PermitUtils, R as RecipientPermit, h as SealingKey, m as SelfPermit, C as SelfPermitOptions, n as SharingPermit, d as SharingPermitOptions } from './permit-DnVMDT5h.js';
3
3
  import { z } from 'zod';
4
4
  import * as zustand_middleware from 'zustand/middleware';
5
5
  import * as zustand_vanilla from 'zustand/vanilla';
@@ -226,8 +226,17 @@ declare const ValidationUtils: {
226
226
  */
227
227
  isSigned: (permit: Permit) => boolean;
228
228
  /**
229
- * Overall validity checker of a permit
229
+ * Checks that a permit is signed and not expired.
230
230
  */
231
+ isSignedAndNotExpired: (permit: Permit) => ValidationResult;
232
+ /**
233
+ * Asserts that a permit is signed and not expired.
234
+ *
235
+ * Throws `Error` with message:
236
+ * - `Permit is expired`
237
+ * - `Permit is not signed`
238
+ */
239
+ assertSignedAndNotExpired: (permit: Permit) => void;
231
240
  isValid: (permit: Permit) => ValidationResult;
232
241
  };
233
242
 
@@ -293,17 +302,15 @@ type PermitsStore = {
293
302
  activePermitHash: ChainRecord<AccountRecord<string | undefined>>;
294
303
  };
295
304
  declare const PERMIT_STORE_DEFAULTS: PermitsStore;
296
- declare const _permitStore: Omit<zustand_vanilla.StoreApi<PermitsStore>, "setState" | "persist"> & {
297
- setState(partial: PermitsStore | Partial<PermitsStore> | ((state: PermitsStore) => PermitsStore | Partial<PermitsStore>), replace?: false | undefined): unknown;
298
- setState(state: PermitsStore | ((state: PermitsStore) => PermitsStore), replace: true): unknown;
305
+ declare const _permitStore: Omit<zustand_vanilla.StoreApi<PermitsStore>, "persist"> & {
299
306
  persist: {
300
- setOptions: (options: Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore, unknown>>) => void;
307
+ setOptions: (options: Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore>>) => void;
301
308
  clearStorage: () => void;
302
309
  rehydrate: () => Promise<void> | void;
303
310
  hasHydrated: () => boolean;
304
311
  onHydrate: (fn: (state: PermitsStore) => void) => () => void;
305
312
  onFinishHydration: (fn: (state: PermitsStore) => void) => () => void;
306
- getOptions: () => Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore, unknown>>;
313
+ getOptions: () => Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore>>;
307
314
  };
308
315
  };
309
316
  declare const clearStaleStore: () => void;
@@ -317,17 +324,15 @@ declare const setActivePermitHash: (chainId: number, account: string, hash: stri
317
324
  declare const removeActivePermitHash: (chainId: number, account: string) => void;
318
325
  declare const resetStore: () => void;
319
326
  declare const permitStore: {
320
- store: Omit<zustand_vanilla.StoreApi<PermitsStore>, "setState" | "persist"> & {
321
- setState(partial: PermitsStore | Partial<PermitsStore> | ((state: PermitsStore) => PermitsStore | Partial<PermitsStore>), replace?: false | undefined): unknown;
322
- setState(state: PermitsStore | ((state: PermitsStore) => PermitsStore), replace: true): unknown;
327
+ store: Omit<zustand_vanilla.StoreApi<PermitsStore>, "persist"> & {
323
328
  persist: {
324
- setOptions: (options: Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore, unknown>>) => void;
329
+ setOptions: (options: Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore>>) => void;
325
330
  clearStorage: () => void;
326
331
  rehydrate: () => Promise<void> | void;
327
332
  hasHydrated: () => boolean;
328
333
  onHydrate: (fn: (state: PermitsStore) => void) => () => void;
329
334
  onFinishHydration: (fn: (state: PermitsStore) => void) => () => void;
330
- getOptions: () => Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore, unknown>>;
335
+ getOptions: () => Partial<zustand_middleware.PersistOptions<PermitsStore, PermitsStore>>;
331
336
  };
332
337
  };
333
338
  getPermit: (chainId: number | undefined, account: string | undefined, hash: string | undefined) => Permit | undefined;
package/dist/permits.js CHANGED
@@ -1 +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-NWDKXBIP.js';
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-MRCKUMOS.js';
2
+ import './chunk-4FP4V35O.js';