@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
package/dist/node.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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-BSbwairE.cjs';
|
|
2
2
|
import 'viem';
|
|
3
|
-
import './types-
|
|
3
|
+
import './types-C07FK-cL.cjs';
|
|
4
4
|
import 'zod';
|
|
5
|
-
import './permit-
|
|
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-
|
|
1
|
+
import { C as CofheInputConfig, a as CofheConfig, b as CofheClient } from './clientTypes-DDmcgZ0a.js';
|
|
2
2
|
import 'viem';
|
|
3
|
-
import './types-
|
|
3
|
+
import './types-C07FK-cL.js';
|
|
4
4
|
import 'zod';
|
|
5
|
-
import './permit-
|
|
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-
|
|
1
|
+
import { createCofheConfigBase, createCofheClientBase } from './chunk-S7OKGLFD.js';
|
|
2
2
|
import './chunk-TBLR7NNE.js';
|
|
3
|
-
import './chunk-
|
|
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,
|
|
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
|
-
|
|
70
|
+
_deserializeTfhePublicKey(buff);
|
|
64
71
|
};
|
|
65
72
|
var compactPkeCrsDeserializer = (buff) => {
|
|
66
|
-
|
|
73
|
+
_deserializeCompactPkeCrs(buff);
|
|
67
74
|
};
|
|
68
75
|
var zkBuilderAndCrsGenerator = (fhe, crs) => {
|
|
69
|
-
const fhePublicKey =
|
|
76
|
+
const fhePublicKey = _deserializeTfhePublicKey(fhe);
|
|
70
77
|
const zkBuilder = ProvenCompactCiphertextList.builder(fhePublicKey);
|
|
71
|
-
const zkCrs =
|
|
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:
|
|
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
|
|
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
|
|
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:
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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 =
|
|
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 =
|
|
149
|
-
const nonce =
|
|
150
|
-
const encryptedMessage =
|
|
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 =
|
|
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
|
-
*
|
|
301
|
+
* Checks that a permit is signed and not expired.
|
|
318
302
|
*/
|
|
319
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
|
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
|
},
|
package/dist/permits.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as Permit, V as ValidationResult, a as
|
|
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-
|
|
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
|
-
*
|
|
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>, "
|
|
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
|
|
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
|
|
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>, "
|
|
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
|
|
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
|
|
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
|
|
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-
|
|
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
|
-
*
|
|
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>, "
|
|
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
|
|
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
|
|
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>, "
|
|
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
|
|
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
|
|
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-
|
|
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';
|