@cofhe/sdk 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/adapters/ethers6.ts +28 -28
- package/adapters/hardhat.ts +0 -1
- package/adapters/index.test.ts +14 -19
- package/adapters/smartWallet.ts +81 -73
- package/adapters/test-utils.ts +45 -45
- package/adapters/types.ts +3 -3
- package/chains/chains/localcofhe.ts +14 -0
- package/chains/chains.test.ts +2 -1
- package/chains/index.ts +3 -1
- package/core/baseBuilder.ts +30 -49
- package/core/client.test.ts +94 -77
- package/core/client.ts +133 -149
- package/core/clientTypes.ts +108 -0
- package/core/config.test.ts +22 -11
- package/core/config.ts +16 -9
- package/core/decrypt/decryptHandleBuilder.ts +51 -45
- package/core/decrypt/{tnSealOutput.ts → tnSealOutputV1.ts} +1 -1
- package/core/decrypt/tnSealOutputV2.ts +298 -0
- package/core/encrypt/cofheMocksZkVerifySign.ts +16 -10
- package/core/encrypt/encryptInputsBuilder.test.ts +132 -116
- package/core/encrypt/encryptInputsBuilder.ts +159 -111
- package/core/encrypt/encryptUtils.ts +6 -3
- package/core/encrypt/zkPackProveVerify.ts +70 -8
- package/core/error.ts +0 -2
- package/core/fetchKeys.test.ts +1 -18
- package/core/fetchKeys.ts +0 -26
- package/core/index.ts +29 -17
- package/core/keyStore.ts +65 -38
- package/core/permits.test.ts +253 -1
- package/core/permits.ts +80 -16
- package/core/types.ts +198 -152
- package/core/utils.ts +43 -1
- package/dist/adapters.d.cts +38 -20
- package/dist/adapters.d.ts +38 -20
- package/dist/chains.cjs +14 -1
- package/dist/chains.d.cts +23 -1
- package/dist/chains.d.ts +23 -1
- package/dist/chains.js +1 -1
- package/dist/{chunk-LU7BMUUT.js → chunk-UGBVZNRT.js} +39 -25
- package/dist/{chunk-GZCQQYVI.js → chunk-WEAZ25JO.js} +14 -2
- package/dist/{chunk-KFGPTJ6X.js → chunk-WGCRJCBR.js} +1920 -1692
- package/dist/{types-bB7wLj0q.d.cts → clientTypes-5_1nwtUe.d.cts} +308 -347
- package/dist/{types-PhwGgQvs.d.ts → clientTypes-Es7fyi65.d.ts} +308 -347
- package/dist/core.cjs +2872 -2632
- package/dist/core.d.cts +101 -6
- package/dist/core.d.ts +101 -6
- package/dist/core.js +3 -3
- package/dist/node.cjs +2716 -2520
- package/dist/node.d.cts +3 -3
- package/dist/node.d.ts +3 -3
- package/dist/node.js +4 -3
- package/dist/{permit-S9CnI6MF.d.cts → permit-fUSe6KKq.d.cts} +31 -15
- package/dist/{permit-S9CnI6MF.d.ts → permit-fUSe6KKq.d.ts} +31 -15
- package/dist/permits.cjs +39 -24
- package/dist/permits.d.cts +137 -148
- package/dist/permits.d.ts +137 -148
- package/dist/permits.js +1 -1
- package/dist/web.cjs +2929 -2518
- package/dist/web.d.cts +21 -5
- package/dist/web.d.ts +21 -5
- package/dist/web.js +185 -9
- package/dist/zkProve.worker.cjs +93 -0
- package/dist/zkProve.worker.d.cts +2 -0
- package/dist/zkProve.worker.d.ts +2 -0
- package/dist/zkProve.worker.js +91 -0
- package/node/client.test.ts +20 -25
- package/node/encryptInputs.test.ts +18 -38
- package/node/index.ts +1 -0
- package/package.json +14 -14
- package/permits/index.ts +1 -0
- package/permits/localstorage.test.ts +0 -1
- package/permits/permit.test.ts +25 -22
- package/permits/permit.ts +30 -21
- package/permits/sealing.test.ts +3 -3
- package/permits/sealing.ts +2 -2
- package/permits/store.ts +5 -7
- package/permits/test-utils.ts +1 -1
- package/permits/types.ts +17 -0
- package/permits/utils.ts +0 -1
- package/permits/validation.ts +24 -4
- package/web/client.web.test.ts +20 -25
- package/web/config.web.test.ts +0 -2
- package/web/encryptInputs.web.test.ts +31 -54
- package/web/index.ts +65 -1
- package/web/storage.ts +19 -5
- package/web/worker.builder.web.test.ts +148 -0
- package/web/worker.config.web.test.ts +329 -0
- package/web/worker.output.web.test.ts +84 -0
- package/web/workerManager.test.ts +80 -0
- package/web/workerManager.ts +214 -0
- package/web/workerManager.web.test.ts +114 -0
- package/web/zkProve.worker.ts +133 -0
- package/core/result.test.ts +0 -180
- package/core/result.ts +0 -67
- package/core/test-utils.ts +0 -45
package/dist/node.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import './permit-S9CnI6MF.cjs';
|
|
3
|
-
import 'zod';
|
|
1
|
+
import { C as CofhesdkInputConfig, a as CofhesdkConfig, b as CofhesdkClient } from './clientTypes-5_1nwtUe.cjs';
|
|
4
2
|
import 'viem';
|
|
5
3
|
import './types-KImPrEIe.cjs';
|
|
4
|
+
import 'zod';
|
|
5
|
+
import './permit-fUSe6KKq.cjs';
|
|
6
6
|
import 'zustand/vanilla';
|
|
7
7
|
|
|
8
8
|
/**
|
package/dist/node.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import './permit-S9CnI6MF.js';
|
|
3
|
-
import 'zod';
|
|
1
|
+
import { C as CofhesdkInputConfig, a as CofhesdkConfig, b as CofhesdkClient } from './clientTypes-Es7fyi65.js';
|
|
4
2
|
import 'viem';
|
|
5
3
|
import './types-KImPrEIe.js';
|
|
4
|
+
import 'zod';
|
|
5
|
+
import './permit-fUSe6KKq.js';
|
|
6
6
|
import 'zustand/vanilla';
|
|
7
7
|
|
|
8
8
|
/**
|
package/dist/node.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createCofhesdkConfigBase, createCofhesdkClientBase } from './chunk-
|
|
2
|
-
import './chunk-
|
|
3
|
-
import './chunk-
|
|
1
|
+
import { createCofhesdkConfigBase, createCofhesdkClientBase } from './chunk-WGCRJCBR.js';
|
|
2
|
+
import './chunk-WEAZ25JO.js';
|
|
3
|
+
import './chunk-UGBVZNRT.js';
|
|
4
4
|
import { promises } from 'fs';
|
|
5
5
|
import { join } from 'path';
|
|
6
6
|
import { init_panic_hook, TfheCompactPublicKey, CompactPkeCrs, ProvenCompactCiphertextList } from 'node-tfhe';
|
|
@@ -73,6 +73,7 @@ var zkBuilderAndCrsGenerator = (fhe, crs) => {
|
|
|
73
73
|
};
|
|
74
74
|
function createCofhesdkConfig(config) {
|
|
75
75
|
return createCofhesdkConfigBase({
|
|
76
|
+
environment: "node",
|
|
76
77
|
...config,
|
|
77
78
|
fheKeyStorage: config.fheKeyStorage === null ? null : config.fheKeyStorage ?? createNodeStorage()
|
|
78
79
|
});
|
|
@@ -55,9 +55,9 @@ declare class SealingKey$1 {
|
|
|
55
55
|
* Asynchronously generates a new SealingKey.
|
|
56
56
|
* This function uses the 'nacl' library to create a new public/private key pair for sealing purposes.
|
|
57
57
|
* A sealing key is used to encrypt data such that it can only be unsealed (decrypted) by the owner of the corresponding private key.
|
|
58
|
-
* @returns {
|
|
58
|
+
* @returns {SealingKey} - A new SealingKey object containing the hexadecimal strings of the public and private keys.
|
|
59
59
|
*/
|
|
60
|
-
declare const GenerateSealingKey: () =>
|
|
60
|
+
declare const GenerateSealingKey: () => SealingKey$1;
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* EIP712 related types
|
|
@@ -142,6 +142,22 @@ interface Permit {
|
|
|
142
142
|
*/
|
|
143
143
|
_signedDomain?: EIP712Domain;
|
|
144
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Permit discriminant helpers
|
|
147
|
+
*/
|
|
148
|
+
type PermitType = Permit['type'];
|
|
149
|
+
/**
|
|
150
|
+
* Utility type to narrow a permit to a specific discriminant.
|
|
151
|
+
*
|
|
152
|
+
* Note: this only narrows the `type` field. Runtime/validation constraints
|
|
153
|
+
* (e.g. recipient == zeroAddress for self permits) are enforced elsewhere.
|
|
154
|
+
*/
|
|
155
|
+
type PermitOf<T extends PermitType> = Expand<Omit<Permit, 'type'> & {
|
|
156
|
+
type: T;
|
|
157
|
+
}>;
|
|
158
|
+
type SelfPermit = PermitOf<'self'>;
|
|
159
|
+
type SharingPermit = PermitOf<'sharing'>;
|
|
160
|
+
type RecipientPermit = PermitOf<'recipient'>;
|
|
145
161
|
/**
|
|
146
162
|
* Optional additional metadata of a Permit
|
|
147
163
|
* Can be passed into the constructor, but not necessary
|
|
@@ -219,31 +235,31 @@ declare const PermitUtils: {
|
|
|
219
235
|
/**
|
|
220
236
|
* Create a self permit for personal use
|
|
221
237
|
*/
|
|
222
|
-
createSelf: (options: CreateSelfPermitOptions) =>
|
|
238
|
+
createSelf: (options: CreateSelfPermitOptions) => SelfPermit;
|
|
223
239
|
/**
|
|
224
240
|
* Create a sharing permit to be shared with another user
|
|
225
241
|
*/
|
|
226
|
-
createSharing: (options: CreateSharingPermitOptions) =>
|
|
242
|
+
createSharing: (options: CreateSharingPermitOptions) => SharingPermit;
|
|
227
243
|
/**
|
|
228
244
|
* Import a shared permit from various input formats
|
|
229
245
|
*/
|
|
230
|
-
importShared: (options: ImportSharedPermitOptions |
|
|
246
|
+
importShared: (options: ImportSharedPermitOptions | string) => RecipientPermit;
|
|
231
247
|
/**
|
|
232
248
|
* Sign a permit with the provided wallet client
|
|
233
249
|
*/
|
|
234
|
-
sign: (permit:
|
|
250
|
+
sign: <T extends Permit>(permit: T, publicClient: PublicClient, walletClient: WalletClient) => Promise<T>;
|
|
235
251
|
/**
|
|
236
252
|
* Create and sign a self permit in one operation
|
|
237
253
|
*/
|
|
238
|
-
createSelfAndSign: (options: CreateSelfPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<
|
|
254
|
+
createSelfAndSign: (options: CreateSelfPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SelfPermit>;
|
|
239
255
|
/**
|
|
240
256
|
* Create and sign a sharing permit in one operation
|
|
241
257
|
*/
|
|
242
|
-
createSharingAndSign: (options: CreateSharingPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<
|
|
258
|
+
createSharingAndSign: (options: CreateSharingPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SharingPermit>;
|
|
243
259
|
/**
|
|
244
260
|
* Import and sign a shared permit in one operation from various input formats
|
|
245
261
|
*/
|
|
246
|
-
importSharedAndSign: (options: ImportSharedPermitOptions |
|
|
262
|
+
importSharedAndSign: (options: ImportSharedPermitOptions | string, publicClient: PublicClient, walletClient: WalletClient) => Promise<RecipientPermit>;
|
|
247
263
|
/**
|
|
248
264
|
* Deserialize a permit from serialized data
|
|
249
265
|
*/
|
|
@@ -259,20 +275,20 @@ declare const PermitUtils: {
|
|
|
259
275
|
type: "self" | "sharing" | "recipient";
|
|
260
276
|
issuer: string;
|
|
261
277
|
recipient?: string | undefined;
|
|
262
|
-
sealingPair?: {
|
|
263
|
-
privateKey: string;
|
|
264
|
-
publicKey: string;
|
|
265
|
-
} | undefined;
|
|
266
278
|
name?: string | undefined;
|
|
267
279
|
expiration?: number | undefined;
|
|
268
280
|
validatorId?: number | undefined;
|
|
269
281
|
validatorContract?: string | undefined;
|
|
282
|
+
sealingPair?: {
|
|
283
|
+
privateKey: string;
|
|
284
|
+
publicKey: string;
|
|
285
|
+
} | undefined;
|
|
270
286
|
issuerSignature?: string | undefined;
|
|
271
287
|
recipientSignature?: string | undefined;
|
|
272
288
|
}, {
|
|
273
289
|
recipient: `0x${string}`;
|
|
274
|
-
name: string;
|
|
275
290
|
type: "self" | "sharing" | "recipient";
|
|
291
|
+
name: string;
|
|
276
292
|
issuer: `0x${string}`;
|
|
277
293
|
expiration: number;
|
|
278
294
|
validatorId: number;
|
|
@@ -330,4 +346,4 @@ declare const PermitUtils: {
|
|
|
330
346
|
checkSignedDomainValid: (permit: Permit, publicClient: PublicClient) => Promise<boolean>;
|
|
331
347
|
};
|
|
332
348
|
|
|
333
|
-
export { type CreateSelfPermitOptions as C, type EIP712Types as E, GenerateSealingKey as G, type ImportSharedPermitOptions as I, type Permit as P, 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
|
|
349
|
+
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 Expand as o };
|
|
@@ -55,9 +55,9 @@ declare class SealingKey$1 {
|
|
|
55
55
|
* Asynchronously generates a new SealingKey.
|
|
56
56
|
* This function uses the 'nacl' library to create a new public/private key pair for sealing purposes.
|
|
57
57
|
* A sealing key is used to encrypt data such that it can only be unsealed (decrypted) by the owner of the corresponding private key.
|
|
58
|
-
* @returns {
|
|
58
|
+
* @returns {SealingKey} - A new SealingKey object containing the hexadecimal strings of the public and private keys.
|
|
59
59
|
*/
|
|
60
|
-
declare const GenerateSealingKey: () =>
|
|
60
|
+
declare const GenerateSealingKey: () => SealingKey$1;
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* EIP712 related types
|
|
@@ -142,6 +142,22 @@ interface Permit {
|
|
|
142
142
|
*/
|
|
143
143
|
_signedDomain?: EIP712Domain;
|
|
144
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Permit discriminant helpers
|
|
147
|
+
*/
|
|
148
|
+
type PermitType = Permit['type'];
|
|
149
|
+
/**
|
|
150
|
+
* Utility type to narrow a permit to a specific discriminant.
|
|
151
|
+
*
|
|
152
|
+
* Note: this only narrows the `type` field. Runtime/validation constraints
|
|
153
|
+
* (e.g. recipient == zeroAddress for self permits) are enforced elsewhere.
|
|
154
|
+
*/
|
|
155
|
+
type PermitOf<T extends PermitType> = Expand<Omit<Permit, 'type'> & {
|
|
156
|
+
type: T;
|
|
157
|
+
}>;
|
|
158
|
+
type SelfPermit = PermitOf<'self'>;
|
|
159
|
+
type SharingPermit = PermitOf<'sharing'>;
|
|
160
|
+
type RecipientPermit = PermitOf<'recipient'>;
|
|
145
161
|
/**
|
|
146
162
|
* Optional additional metadata of a Permit
|
|
147
163
|
* Can be passed into the constructor, but not necessary
|
|
@@ -219,31 +235,31 @@ declare const PermitUtils: {
|
|
|
219
235
|
/**
|
|
220
236
|
* Create a self permit for personal use
|
|
221
237
|
*/
|
|
222
|
-
createSelf: (options: CreateSelfPermitOptions) =>
|
|
238
|
+
createSelf: (options: CreateSelfPermitOptions) => SelfPermit;
|
|
223
239
|
/**
|
|
224
240
|
* Create a sharing permit to be shared with another user
|
|
225
241
|
*/
|
|
226
|
-
createSharing: (options: CreateSharingPermitOptions) =>
|
|
242
|
+
createSharing: (options: CreateSharingPermitOptions) => SharingPermit;
|
|
227
243
|
/**
|
|
228
244
|
* Import a shared permit from various input formats
|
|
229
245
|
*/
|
|
230
|
-
importShared: (options: ImportSharedPermitOptions |
|
|
246
|
+
importShared: (options: ImportSharedPermitOptions | string) => RecipientPermit;
|
|
231
247
|
/**
|
|
232
248
|
* Sign a permit with the provided wallet client
|
|
233
249
|
*/
|
|
234
|
-
sign: (permit:
|
|
250
|
+
sign: <T extends Permit>(permit: T, publicClient: PublicClient, walletClient: WalletClient) => Promise<T>;
|
|
235
251
|
/**
|
|
236
252
|
* Create and sign a self permit in one operation
|
|
237
253
|
*/
|
|
238
|
-
createSelfAndSign: (options: CreateSelfPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<
|
|
254
|
+
createSelfAndSign: (options: CreateSelfPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SelfPermit>;
|
|
239
255
|
/**
|
|
240
256
|
* Create and sign a sharing permit in one operation
|
|
241
257
|
*/
|
|
242
|
-
createSharingAndSign: (options: CreateSharingPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<
|
|
258
|
+
createSharingAndSign: (options: CreateSharingPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SharingPermit>;
|
|
243
259
|
/**
|
|
244
260
|
* Import and sign a shared permit in one operation from various input formats
|
|
245
261
|
*/
|
|
246
|
-
importSharedAndSign: (options: ImportSharedPermitOptions |
|
|
262
|
+
importSharedAndSign: (options: ImportSharedPermitOptions | string, publicClient: PublicClient, walletClient: WalletClient) => Promise<RecipientPermit>;
|
|
247
263
|
/**
|
|
248
264
|
* Deserialize a permit from serialized data
|
|
249
265
|
*/
|
|
@@ -259,20 +275,20 @@ declare const PermitUtils: {
|
|
|
259
275
|
type: "self" | "sharing" | "recipient";
|
|
260
276
|
issuer: string;
|
|
261
277
|
recipient?: string | undefined;
|
|
262
|
-
sealingPair?: {
|
|
263
|
-
privateKey: string;
|
|
264
|
-
publicKey: string;
|
|
265
|
-
} | undefined;
|
|
266
278
|
name?: string | undefined;
|
|
267
279
|
expiration?: number | undefined;
|
|
268
280
|
validatorId?: number | undefined;
|
|
269
281
|
validatorContract?: string | undefined;
|
|
282
|
+
sealingPair?: {
|
|
283
|
+
privateKey: string;
|
|
284
|
+
publicKey: string;
|
|
285
|
+
} | undefined;
|
|
270
286
|
issuerSignature?: string | undefined;
|
|
271
287
|
recipientSignature?: string | undefined;
|
|
272
288
|
}, {
|
|
273
289
|
recipient: `0x${string}`;
|
|
274
|
-
name: string;
|
|
275
290
|
type: "self" | "sharing" | "recipient";
|
|
291
|
+
name: string;
|
|
276
292
|
issuer: `0x${string}`;
|
|
277
293
|
expiration: number;
|
|
278
294
|
validatorId: number;
|
|
@@ -330,4 +346,4 @@ declare const PermitUtils: {
|
|
|
330
346
|
checkSignedDomainValid: (permit: Permit, publicClient: PublicClient) => Promise<boolean>;
|
|
331
347
|
};
|
|
332
348
|
|
|
333
|
-
export { type CreateSelfPermitOptions as C, type EIP712Types as E, GenerateSealingKey as G, type ImportSharedPermitOptions as I, type Permit as P, 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
|
|
349
|
+
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 Expand as o };
|
package/dist/permits.cjs
CHANGED
|
@@ -158,7 +158,7 @@ var SealingKey = class _SealingKey {
|
|
|
158
158
|
};
|
|
159
159
|
};
|
|
160
160
|
};
|
|
161
|
-
var GenerateSealingKey =
|
|
161
|
+
var GenerateSealingKey = () => {
|
|
162
162
|
const sodiumKeypair = nacl__namespace.box.keyPair();
|
|
163
163
|
return new SealingKey(toHexString(sodiumKeypair.secretKey), toHexString(sodiumKeypair.publicKey));
|
|
164
164
|
};
|
|
@@ -166,6 +166,7 @@ var SerializedSealingPair = zod.z.object({
|
|
|
166
166
|
privateKey: zod.z.string(),
|
|
167
167
|
publicKey: zod.z.string()
|
|
168
168
|
});
|
|
169
|
+
var DEFAULT_EXPIRATION_FN = () => Math.round(Date.now() / 1e3) + 7 * 24 * 60 * 60;
|
|
169
170
|
var zPermitWithDefaults = zod.z.object({
|
|
170
171
|
name: zod.z.string().optional().default("Unnamed Permit"),
|
|
171
172
|
type: zod.z.enum(["self", "sharing", "recipient"]),
|
|
@@ -174,7 +175,7 @@ var zPermitWithDefaults = zod.z.object({
|
|
|
174
175
|
}).refine((val) => val !== viem.zeroAddress, {
|
|
175
176
|
message: "Permit issuer :: must not be zeroAddress"
|
|
176
177
|
}),
|
|
177
|
-
expiration: zod.z.number().optional().default(
|
|
178
|
+
expiration: zod.z.number().optional().default(DEFAULT_EXPIRATION_FN),
|
|
178
179
|
recipient: zod.z.string().optional().default(viem.zeroAddress).refine((val) => viem.isAddress(val), {
|
|
179
180
|
message: "Permit recipient :: invalid address"
|
|
180
181
|
}),
|
|
@@ -199,13 +200,17 @@ var SelfPermitOptionsValidator = zod.z.object({
|
|
|
199
200
|
type: zod.z.literal("self").optional().default("self"),
|
|
200
201
|
issuer: zod.z.string().refine((val) => viem.isAddress(val), {
|
|
201
202
|
message: "Self permit issuer :: invalid address"
|
|
203
|
+
}).refine((val) => is0xPrefixed(val), {
|
|
204
|
+
message: "Self permit issuer :: must be 0x prefixed"
|
|
202
205
|
}).refine((val) => val !== viem.zeroAddress, {
|
|
203
206
|
message: "Self permit issuer :: must not be zeroAddress"
|
|
204
207
|
}),
|
|
205
208
|
name: zod.z.string().optional().default("Unnamed Permit"),
|
|
206
|
-
expiration: zod.z.number().optional().default(
|
|
209
|
+
expiration: zod.z.number().optional().default(DEFAULT_EXPIRATION_FN),
|
|
207
210
|
recipient: zod.z.string().optional().default(viem.zeroAddress).refine((val) => viem.isAddress(val), {
|
|
208
211
|
message: "Self permit recipient :: invalid address"
|
|
212
|
+
}).refine((val) => is0xPrefixed(val), {
|
|
213
|
+
message: "Self permit recipient :: must be 0x prefixed"
|
|
209
214
|
}).refine((val) => val === viem.zeroAddress, {
|
|
210
215
|
message: "Self permit recipient :: must be zeroAddress"
|
|
211
216
|
}),
|
|
@@ -233,16 +238,20 @@ var SharingPermitOptionsValidator = zod.z.object({
|
|
|
233
238
|
type: zod.z.literal("sharing").optional().default("sharing"),
|
|
234
239
|
issuer: zod.z.string().refine((val) => viem.isAddress(val), {
|
|
235
240
|
message: "Sharing permit issuer :: invalid address"
|
|
241
|
+
}).refine((val) => is0xPrefixed(val), {
|
|
242
|
+
message: "Sharing permit issuer :: must be 0x prefixed"
|
|
236
243
|
}).refine((val) => val !== viem.zeroAddress, {
|
|
237
244
|
message: "Sharing permit issuer :: must not be zeroAddress"
|
|
238
245
|
}),
|
|
239
246
|
recipient: zod.z.string().refine((val) => viem.isAddress(val), {
|
|
240
247
|
message: "Sharing permit recipient :: invalid address"
|
|
248
|
+
}).refine((val) => is0xPrefixed(val), {
|
|
249
|
+
message: "Sharing permit recipient :: must be 0x prefixed"
|
|
241
250
|
}).refine((val) => val !== viem.zeroAddress, {
|
|
242
251
|
message: "Sharing permit recipient :: must not be zeroAddress"
|
|
243
252
|
}),
|
|
244
253
|
name: zod.z.string().optional().default("Unnamed Permit"),
|
|
245
|
-
expiration: zod.z.number().optional().default(
|
|
254
|
+
expiration: zod.z.number().optional().default(DEFAULT_EXPIRATION_FN),
|
|
246
255
|
validatorId: zod.z.number().optional().default(0),
|
|
247
256
|
validatorContract: zod.z.string().optional().default(viem.zeroAddress).refine((val) => viem.isAddress(val), {
|
|
248
257
|
message: "Sharing permit validatorContract :: invalid address"
|
|
@@ -267,11 +276,15 @@ var ImportPermitOptionsValidator = zod.z.object({
|
|
|
267
276
|
type: zod.z.literal("recipient").optional().default("recipient"),
|
|
268
277
|
issuer: zod.z.string().refine((val) => viem.isAddress(val), {
|
|
269
278
|
message: "Import permit issuer :: invalid address"
|
|
279
|
+
}).refine((val) => is0xPrefixed(val), {
|
|
280
|
+
message: "Import permit issuer :: must be 0x prefixed"
|
|
270
281
|
}).refine((val) => val !== viem.zeroAddress, {
|
|
271
282
|
message: "Import permit issuer :: must not be zeroAddress"
|
|
272
283
|
}),
|
|
273
284
|
recipient: zod.z.string().refine((val) => viem.isAddress(val), {
|
|
274
285
|
message: "Import permit recipient :: invalid address"
|
|
286
|
+
}).refine((val) => is0xPrefixed(val), {
|
|
287
|
+
message: "Import permit recipient :: must be 0x prefixed"
|
|
275
288
|
}).refine((val) => val !== viem.zeroAddress, {
|
|
276
289
|
message: "Import permit recipient :: must not be zeroAddress"
|
|
277
290
|
}),
|
|
@@ -281,7 +294,7 @@ var ImportPermitOptionsValidator = zod.z.object({
|
|
|
281
294
|
message: "Import permit :: issuerSignature must be provided"
|
|
282
295
|
}),
|
|
283
296
|
name: zod.z.string().optional().default("Unnamed Permit"),
|
|
284
|
-
expiration: zod.z.number().optional().default(
|
|
297
|
+
expiration: zod.z.number().optional().default(DEFAULT_EXPIRATION_FN),
|
|
285
298
|
validatorId: zod.z.number().optional().default(0),
|
|
286
299
|
validatorContract: zod.z.string().optional().default(viem.zeroAddress).refine((val) => viem.isAddress(val), {
|
|
287
300
|
message: "Import permit validatorContract :: invalid address"
|
|
@@ -404,41 +417,43 @@ var PermitUtils = {
|
|
|
404
417
|
/**
|
|
405
418
|
* Create a self permit for personal use
|
|
406
419
|
*/
|
|
407
|
-
createSelf:
|
|
420
|
+
createSelf: (options) => {
|
|
408
421
|
const validation = validateSelfPermitOptions(options);
|
|
409
422
|
if (!validation.success) {
|
|
410
423
|
throw new Error(
|
|
411
424
|
"PermitUtils :: createSelf :: Parsing SelfPermitOptions failed " + JSON.stringify(validation.error, null, 2)
|
|
412
425
|
);
|
|
413
426
|
}
|
|
414
|
-
const sealingPair =
|
|
415
|
-
|
|
427
|
+
const sealingPair = GenerateSealingKey();
|
|
428
|
+
const permit = {
|
|
416
429
|
...validation.data,
|
|
417
430
|
sealingPair,
|
|
418
431
|
_signedDomain: void 0
|
|
419
432
|
};
|
|
433
|
+
return permit;
|
|
420
434
|
},
|
|
421
435
|
/**
|
|
422
436
|
* Create a sharing permit to be shared with another user
|
|
423
437
|
*/
|
|
424
|
-
createSharing:
|
|
438
|
+
createSharing: (options) => {
|
|
425
439
|
const validation = validateSharingPermitOptions(options);
|
|
426
440
|
if (!validation.success) {
|
|
427
441
|
throw new Error(
|
|
428
442
|
"PermitUtils :: createSharing :: Parsing SharingPermitOptions failed " + JSON.stringify(validation.error, null, 2)
|
|
429
443
|
);
|
|
430
444
|
}
|
|
431
|
-
const sealingPair =
|
|
432
|
-
|
|
445
|
+
const sealingPair = GenerateSealingKey();
|
|
446
|
+
const permit = {
|
|
433
447
|
...validation.data,
|
|
434
448
|
sealingPair,
|
|
435
449
|
_signedDomain: void 0
|
|
436
450
|
};
|
|
451
|
+
return permit;
|
|
437
452
|
},
|
|
438
453
|
/**
|
|
439
454
|
* Import a shared permit from various input formats
|
|
440
455
|
*/
|
|
441
|
-
importShared:
|
|
456
|
+
importShared: (options) => {
|
|
442
457
|
let parsedOptions;
|
|
443
458
|
if (typeof options === "string") {
|
|
444
459
|
try {
|
|
@@ -462,12 +477,13 @@ var PermitUtils = {
|
|
|
462
477
|
"PermitUtils :: importShared :: Parsing ImportPermitOptions failed " + JSON.stringify(validation.error, null, 2)
|
|
463
478
|
);
|
|
464
479
|
}
|
|
465
|
-
const sealingPair =
|
|
466
|
-
|
|
480
|
+
const sealingPair = GenerateSealingKey();
|
|
481
|
+
const permit = {
|
|
467
482
|
...validation.data,
|
|
468
483
|
sealingPair,
|
|
469
484
|
_signedDomain: void 0
|
|
470
485
|
};
|
|
486
|
+
return permit;
|
|
471
487
|
},
|
|
472
488
|
/**
|
|
473
489
|
* Sign a permit with the provided wallet client
|
|
@@ -508,21 +524,21 @@ var PermitUtils = {
|
|
|
508
524
|
* Create and sign a self permit in one operation
|
|
509
525
|
*/
|
|
510
526
|
createSelfAndSign: async (options, publicClient, walletClient) => {
|
|
511
|
-
const permit =
|
|
527
|
+
const permit = PermitUtils.createSelf(options);
|
|
512
528
|
return PermitUtils.sign(permit, publicClient, walletClient);
|
|
513
529
|
},
|
|
514
530
|
/**
|
|
515
531
|
* Create and sign a sharing permit in one operation
|
|
516
532
|
*/
|
|
517
533
|
createSharingAndSign: async (options, publicClient, walletClient) => {
|
|
518
|
-
const permit =
|
|
534
|
+
const permit = PermitUtils.createSharing(options);
|
|
519
535
|
return PermitUtils.sign(permit, publicClient, walletClient);
|
|
520
536
|
},
|
|
521
537
|
/**
|
|
522
538
|
* Import and sign a shared permit in one operation from various input formats
|
|
523
539
|
*/
|
|
524
540
|
importSharedAndSign: async (options, publicClient, walletClient) => {
|
|
525
|
-
const permit =
|
|
541
|
+
const permit = PermitUtils.importShared(options);
|
|
526
542
|
return PermitUtils.sign(permit, publicClient, walletClient);
|
|
527
543
|
},
|
|
528
544
|
/**
|
|
@@ -696,14 +712,12 @@ var PermitUtils = {
|
|
|
696
712
|
return PermitUtils.matchesDomain(permit, domain);
|
|
697
713
|
}
|
|
698
714
|
};
|
|
715
|
+
var PERMIT_STORE_DEFAULTS = {
|
|
716
|
+
permits: {},
|
|
717
|
+
activePermitHash: {}
|
|
718
|
+
};
|
|
699
719
|
var _permitStore = vanilla.createStore()(
|
|
700
|
-
middleware.persist(
|
|
701
|
-
() => ({
|
|
702
|
-
permits: {},
|
|
703
|
-
activePermitHash: {}
|
|
704
|
-
}),
|
|
705
|
-
{ name: "cofhesdk-permits" }
|
|
706
|
-
)
|
|
720
|
+
middleware.persist(() => PERMIT_STORE_DEFAULTS, { name: "cofhesdk-permits" })
|
|
707
721
|
);
|
|
708
722
|
var clearStaleStore = () => {
|
|
709
723
|
const state = _permitStore.getState();
|
|
@@ -826,6 +840,7 @@ var permitStore = {
|
|
|
826
840
|
exports.GenerateSealingKey = GenerateSealingKey;
|
|
827
841
|
exports.ImportPermitOptionsValidator = ImportPermitOptionsValidator;
|
|
828
842
|
exports.ImportPermitValidator = ImportPermitValidator;
|
|
843
|
+
exports.PERMIT_STORE_DEFAULTS = PERMIT_STORE_DEFAULTS;
|
|
829
844
|
exports.PermitUtils = PermitUtils;
|
|
830
845
|
exports.SealingKey = SealingKey;
|
|
831
846
|
exports.SelfPermitOptionsValidator = SelfPermitOptionsValidator;
|