@cofhe/sdk 0.1.1 → 0.2.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 +22 -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/defineChain.ts +2 -2
- package/chains/index.ts +3 -1
- package/chains/types.ts +3 -3
- package/core/baseBuilder.ts +30 -49
- package/core/client.test.ts +200 -72
- package/core/client.ts +152 -148
- package/core/clientTypes.ts +114 -0
- package/core/config.test.ts +30 -11
- package/core/config.ts +26 -13
- package/core/consts.ts +18 -0
- package/core/decrypt/cofheMocksSealOutput.ts +2 -4
- 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 +15 -16
- 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 +37 -17
- package/core/keyStore.ts +65 -38
- package/core/permits.test.ts +255 -4
- package/core/permits.ts +83 -18
- 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 +18 -8
- package/dist/chains.d.cts +31 -9
- package/dist/chains.d.ts +31 -9
- package/dist/chains.js +1 -1
- package/dist/{chunk-KFGPTJ6X.js → chunk-I5WFEYXX.js} +1768 -1526
- package/dist/{chunk-LU7BMUUT.js → chunk-R3B5TMVX.js} +330 -197
- package/dist/{chunk-GZCQQYVI.js → chunk-TBLR7NNE.js} +18 -9
- package/dist/{types-PhwGgQvs.d.ts → clientTypes-RqkgkV2i.d.ts} +331 -429
- package/dist/{types-bB7wLj0q.d.cts → clientTypes-e4filDzK.d.cts} +331 -429
- package/dist/core.cjs +3000 -2625
- package/dist/core.d.cts +113 -7
- package/dist/core.d.ts +113 -7
- package/dist/core.js +3 -3
- package/dist/node.cjs +2851 -2526
- package/dist/node.d.cts +4 -4
- package/dist/node.d.ts +4 -4
- package/dist/node.js +4 -3
- package/dist/{permit-S9CnI6MF.d.cts → permit-MZ502UBl.d.cts} +54 -41
- package/dist/{permit-S9CnI6MF.d.ts → permit-MZ502UBl.d.ts} +54 -41
- package/dist/permits.cjs +328 -195
- package/dist/permits.d.cts +113 -825
- package/dist/permits.d.ts +113 -825
- package/dist/permits.js +1 -1
- package/dist/types-YiAC4gig.d.cts +33 -0
- package/dist/types-YiAC4gig.d.ts +33 -0
- package/dist/web.cjs +3067 -2527
- package/dist/web.d.cts +22 -6
- package/dist/web.d.ts +22 -6
- 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 +15 -15
- package/permits/index.ts +1 -0
- package/permits/localstorage.test.ts +9 -14
- package/permits/onchain-utils.ts +221 -0
- package/permits/permit.test.ts +76 -27
- package/permits/permit.ts +58 -95
- package/permits/sealing.test.ts +3 -3
- package/permits/sealing.ts +2 -2
- package/permits/store.test.ts +10 -50
- package/permits/store.ts +9 -21
- package/permits/test-utils.ts +11 -3
- package/permits/types.ts +39 -9
- package/permits/utils.ts +0 -5
- package/permits/validation.test.ts +29 -32
- package/permits/validation.ts +114 -176
- 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/types-KImPrEIe.d.cts +0 -48
- package/dist/types-KImPrEIe.d.ts +0 -48
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-e4filDzK.cjs';
|
|
4
2
|
import 'viem';
|
|
5
|
-
import './types-
|
|
3
|
+
import './types-YiAC4gig.cjs';
|
|
4
|
+
import 'zod';
|
|
5
|
+
import './permit-MZ502UBl.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-RqkgkV2i.js';
|
|
4
2
|
import 'viem';
|
|
5
|
-
import './types-
|
|
3
|
+
import './types-YiAC4gig.js';
|
|
4
|
+
import 'zod';
|
|
5
|
+
import './permit-MZ502UBl.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-I5WFEYXX.js';
|
|
2
|
+
import './chunk-TBLR7NNE.js';
|
|
3
|
+
import './chunk-R3B5TMVX.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
|
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { PublicClient, WalletClient } from 'viem';
|
|
1
|
+
import { Hex, PublicClient, WalletClient } from 'viem';
|
|
3
2
|
|
|
4
3
|
type EthEncryptedData = {
|
|
5
4
|
data: Uint8Array;
|
|
@@ -55,9 +54,9 @@ declare class SealingKey$1 {
|
|
|
55
54
|
* Asynchronously generates a new SealingKey.
|
|
56
55
|
* This function uses the 'nacl' library to create a new public/private key pair for sealing purposes.
|
|
57
56
|
* 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 {
|
|
57
|
+
* @returns {SealingKey} - A new SealingKey object containing the hexadecimal strings of the public and private keys.
|
|
59
58
|
*/
|
|
60
|
-
declare const GenerateSealingKey: () =>
|
|
59
|
+
declare const GenerateSealingKey: () => SealingKey$1;
|
|
61
60
|
|
|
62
61
|
/**
|
|
63
62
|
* EIP712 related types
|
|
@@ -71,7 +70,7 @@ type EIP712Message = Record<string, string>;
|
|
|
71
70
|
type EIP712Domain = {
|
|
72
71
|
chainId: number;
|
|
73
72
|
name: string;
|
|
74
|
-
verifyingContract:
|
|
73
|
+
verifyingContract: Hex;
|
|
75
74
|
version: string;
|
|
76
75
|
};
|
|
77
76
|
/**
|
|
@@ -83,6 +82,10 @@ type SealingKey = SealingKey$1;
|
|
|
83
82
|
* Core Permit interface - immutable design for React compatibility
|
|
84
83
|
*/
|
|
85
84
|
interface Permit {
|
|
85
|
+
/**
|
|
86
|
+
* Stable hash of relevant permit data, used as key in storage
|
|
87
|
+
*/
|
|
88
|
+
hash: string;
|
|
86
89
|
/**
|
|
87
90
|
* Name for this permit, for organization and UI usage, not included in signature.
|
|
88
91
|
*/
|
|
@@ -97,7 +100,7 @@ interface Permit {
|
|
|
97
100
|
/**
|
|
98
101
|
* (base) User that initially created the permission, target of data fetching
|
|
99
102
|
*/
|
|
100
|
-
issuer:
|
|
103
|
+
issuer: Hex;
|
|
101
104
|
/**
|
|
102
105
|
* (base) Expiration timestamp
|
|
103
106
|
*/
|
|
@@ -106,7 +109,7 @@ interface Permit {
|
|
|
106
109
|
* (sharing) The user that this permission will be shared with
|
|
107
110
|
* ** optional, use `address(0)` to disable **
|
|
108
111
|
*/
|
|
109
|
-
recipient:
|
|
112
|
+
recipient: Hex;
|
|
110
113
|
/**
|
|
111
114
|
* (issuer defined validation) An id used to query a contract to check this permissions validity
|
|
112
115
|
* ** optional, use `0` to disable **
|
|
@@ -116,7 +119,7 @@ interface Permit {
|
|
|
116
119
|
* (issuer defined validation) The contract to query to determine permission validity
|
|
117
120
|
* ** optional, user `address(0)` to disable **
|
|
118
121
|
*/
|
|
119
|
-
validatorContract:
|
|
122
|
+
validatorContract: Hex;
|
|
120
123
|
/**
|
|
121
124
|
* (base) The publicKey of a sealingPair used to re-encrypt `issuer`s confidential data
|
|
122
125
|
* (non-sharing) Populated by `issuer`
|
|
@@ -129,19 +132,35 @@ interface Permit {
|
|
|
129
132
|
* (non-sharing) < issuer, expiration, recipient, validatorId, validatorContract, sealingKey >
|
|
130
133
|
* (sharing) < issuer, expiration, recipient, validatorId, validatorContract >
|
|
131
134
|
*/
|
|
132
|
-
issuerSignature:
|
|
135
|
+
issuerSignature: Hex;
|
|
133
136
|
/**
|
|
134
137
|
* (sharing) `signTypedData` signature created by `recipient` with format:
|
|
135
138
|
* (sharing) < sealingKey, issuerSignature>
|
|
136
139
|
* ** required for shared permits **
|
|
137
140
|
*/
|
|
138
|
-
recipientSignature:
|
|
141
|
+
recipientSignature: Hex;
|
|
139
142
|
/**
|
|
140
143
|
* EIP712 domain used to sign this permit.
|
|
141
144
|
* Should not be set manually, included in metadata as part of serialization flows.
|
|
142
145
|
*/
|
|
143
146
|
_signedDomain?: EIP712Domain;
|
|
144
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Permit discriminant helpers
|
|
150
|
+
*/
|
|
151
|
+
type PermitType = Permit['type'];
|
|
152
|
+
/**
|
|
153
|
+
* Utility type to narrow a permit to a specific discriminant.
|
|
154
|
+
*
|
|
155
|
+
* Note: this only narrows the `type` field. Runtime/validation constraints
|
|
156
|
+
* (e.g. recipient == zeroAddress for self permits) are enforced elsewhere.
|
|
157
|
+
*/
|
|
158
|
+
type PermitOf<T extends PermitType> = Expand<Omit<Permit, 'type'> & {
|
|
159
|
+
type: T;
|
|
160
|
+
}>;
|
|
161
|
+
type SelfPermit = PermitOf<'self'>;
|
|
162
|
+
type SharingPermit = PermitOf<'sharing'>;
|
|
163
|
+
type RecipientPermit = PermitOf<'recipient'>;
|
|
145
164
|
/**
|
|
146
165
|
* Optional additional metadata of a Permit
|
|
147
166
|
* Can be passed into the constructor, but not necessary
|
|
@@ -180,7 +199,7 @@ type ImportSharedPermitOptions = {
|
|
|
180
199
|
recipient: string;
|
|
181
200
|
issuerSignature: string;
|
|
182
201
|
name?: string;
|
|
183
|
-
expiration
|
|
202
|
+
expiration: number;
|
|
184
203
|
validatorId?: number;
|
|
185
204
|
validatorContract?: string;
|
|
186
205
|
};
|
|
@@ -194,9 +213,13 @@ type SerializedPermit = Omit<Permit, 'sealingPair'> & {
|
|
|
194
213
|
/**
|
|
195
214
|
* A type representing the Permission struct that is passed to Permissioned.sol to grant encrypted data access.
|
|
196
215
|
*/
|
|
197
|
-
type Permission = Expand<Omit<Permit, 'name' | 'type' | 'sealingPair'> & {
|
|
198
|
-
sealingKey:
|
|
216
|
+
type Permission = Expand<Omit<Permit, 'name' | 'type' | 'sealingPair' | 'hash'> & {
|
|
217
|
+
sealingKey: Hex;
|
|
199
218
|
}>;
|
|
219
|
+
/**
|
|
220
|
+
* A type representing the permit fields that are used to generate the hash
|
|
221
|
+
*/
|
|
222
|
+
type PermitHashFields = Pick<Permit, 'type' | 'issuer' | 'expiration' | 'recipient' | 'validatorId' | 'validatorContract'>;
|
|
200
223
|
/**
|
|
201
224
|
* Validation result type
|
|
202
225
|
*/
|
|
@@ -219,31 +242,31 @@ declare const PermitUtils: {
|
|
|
219
242
|
/**
|
|
220
243
|
* Create a self permit for personal use
|
|
221
244
|
*/
|
|
222
|
-
createSelf: (options: CreateSelfPermitOptions) =>
|
|
245
|
+
createSelf: (options: CreateSelfPermitOptions) => SelfPermit;
|
|
223
246
|
/**
|
|
224
247
|
* Create a sharing permit to be shared with another user
|
|
225
248
|
*/
|
|
226
|
-
createSharing: (options: CreateSharingPermitOptions) =>
|
|
249
|
+
createSharing: (options: CreateSharingPermitOptions) => SharingPermit;
|
|
227
250
|
/**
|
|
228
251
|
* Import a shared permit from various input formats
|
|
229
252
|
*/
|
|
230
|
-
importShared: (options: ImportSharedPermitOptions |
|
|
253
|
+
importShared: (options: ImportSharedPermitOptions | string) => RecipientPermit;
|
|
231
254
|
/**
|
|
232
255
|
* Sign a permit with the provided wallet client
|
|
233
256
|
*/
|
|
234
|
-
sign: (permit:
|
|
257
|
+
sign: <T extends Permit>(permit: T, publicClient: PublicClient, walletClient: WalletClient) => Promise<T>;
|
|
235
258
|
/**
|
|
236
259
|
* Create and sign a self permit in one operation
|
|
237
260
|
*/
|
|
238
|
-
createSelfAndSign: (options: CreateSelfPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<
|
|
261
|
+
createSelfAndSign: (options: CreateSelfPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SelfPermit>;
|
|
239
262
|
/**
|
|
240
263
|
* Create and sign a sharing permit in one operation
|
|
241
264
|
*/
|
|
242
|
-
createSharingAndSign: (options: CreateSharingPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<
|
|
265
|
+
createSharingAndSign: (options: CreateSharingPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SharingPermit>;
|
|
243
266
|
/**
|
|
244
267
|
* Import and sign a shared permit in one operation from various input formats
|
|
245
268
|
*/
|
|
246
|
-
importSharedAndSign: (options: ImportSharedPermitOptions |
|
|
269
|
+
importSharedAndSign: (options: ImportSharedPermitOptions | string, publicClient: PublicClient, walletClient: WalletClient) => Promise<RecipientPermit>;
|
|
247
270
|
/**
|
|
248
271
|
* Deserialize a permit from serialized data
|
|
249
272
|
*/
|
|
@@ -255,35 +278,21 @@ declare const PermitUtils: {
|
|
|
255
278
|
/**
|
|
256
279
|
* Validate a permit
|
|
257
280
|
*/
|
|
258
|
-
validate: (permit: Permit) =>
|
|
259
|
-
type: "self" | "sharing" | "recipient";
|
|
260
|
-
issuer: string;
|
|
261
|
-
recipient?: string | undefined;
|
|
262
|
-
sealingPair?: {
|
|
263
|
-
privateKey: string;
|
|
264
|
-
publicKey: string;
|
|
265
|
-
} | undefined;
|
|
266
|
-
name?: string | undefined;
|
|
267
|
-
expiration?: number | undefined;
|
|
268
|
-
validatorId?: number | undefined;
|
|
269
|
-
validatorContract?: string | undefined;
|
|
270
|
-
issuerSignature?: string | undefined;
|
|
271
|
-
recipientSignature?: string | undefined;
|
|
272
|
-
}, {
|
|
273
|
-
recipient: `0x${string}`;
|
|
281
|
+
validate: (permit: Permit) => {
|
|
274
282
|
name: string;
|
|
275
283
|
type: "self" | "sharing" | "recipient";
|
|
276
284
|
issuer: `0x${string}`;
|
|
277
285
|
expiration: number;
|
|
286
|
+
recipient: `0x${string}`;
|
|
278
287
|
validatorId: number;
|
|
279
288
|
validatorContract: `0x${string}`;
|
|
280
|
-
issuerSignature: string
|
|
281
|
-
recipientSignature: string
|
|
289
|
+
issuerSignature: `0x${string}`;
|
|
290
|
+
recipientSignature: `0x${string}`;
|
|
282
291
|
sealingPair?: {
|
|
283
292
|
privateKey: string;
|
|
284
293
|
publicKey: string;
|
|
285
294
|
} | undefined;
|
|
286
|
-
}
|
|
295
|
+
};
|
|
287
296
|
/**
|
|
288
297
|
* Get the permission object from a permit (for use in contracts)
|
|
289
298
|
*/
|
|
@@ -291,7 +300,7 @@ declare const PermitUtils: {
|
|
|
291
300
|
/**
|
|
292
301
|
* Get a stable hash for the permit (used as key in storage)
|
|
293
302
|
*/
|
|
294
|
-
getHash: (permit:
|
|
303
|
+
getHash: (permit: PermitHashFields) => string;
|
|
295
304
|
/**
|
|
296
305
|
* Export permit data for sharing (removes sensitive fields)
|
|
297
306
|
*/
|
|
@@ -328,6 +337,10 @@ declare const PermitUtils: {
|
|
|
328
337
|
* Check if permit's signed domain is valid for the current chain
|
|
329
338
|
*/
|
|
330
339
|
checkSignedDomainValid: (permit: Permit, publicClient: PublicClient) => Promise<boolean>;
|
|
340
|
+
/**
|
|
341
|
+
* Check if permit passes the on-chain validation
|
|
342
|
+
*/
|
|
343
|
+
checkValidityOnChain: (permit: Permit, publicClient: PublicClient) => Promise<boolean>;
|
|
331
344
|
};
|
|
332
345
|
|
|
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
|
|
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 };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { PublicClient, WalletClient } from 'viem';
|
|
1
|
+
import { Hex, PublicClient, WalletClient } from 'viem';
|
|
3
2
|
|
|
4
3
|
type EthEncryptedData = {
|
|
5
4
|
data: Uint8Array;
|
|
@@ -55,9 +54,9 @@ declare class SealingKey$1 {
|
|
|
55
54
|
* Asynchronously generates a new SealingKey.
|
|
56
55
|
* This function uses the 'nacl' library to create a new public/private key pair for sealing purposes.
|
|
57
56
|
* 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 {
|
|
57
|
+
* @returns {SealingKey} - A new SealingKey object containing the hexadecimal strings of the public and private keys.
|
|
59
58
|
*/
|
|
60
|
-
declare const GenerateSealingKey: () =>
|
|
59
|
+
declare const GenerateSealingKey: () => SealingKey$1;
|
|
61
60
|
|
|
62
61
|
/**
|
|
63
62
|
* EIP712 related types
|
|
@@ -71,7 +70,7 @@ type EIP712Message = Record<string, string>;
|
|
|
71
70
|
type EIP712Domain = {
|
|
72
71
|
chainId: number;
|
|
73
72
|
name: string;
|
|
74
|
-
verifyingContract:
|
|
73
|
+
verifyingContract: Hex;
|
|
75
74
|
version: string;
|
|
76
75
|
};
|
|
77
76
|
/**
|
|
@@ -83,6 +82,10 @@ type SealingKey = SealingKey$1;
|
|
|
83
82
|
* Core Permit interface - immutable design for React compatibility
|
|
84
83
|
*/
|
|
85
84
|
interface Permit {
|
|
85
|
+
/**
|
|
86
|
+
* Stable hash of relevant permit data, used as key in storage
|
|
87
|
+
*/
|
|
88
|
+
hash: string;
|
|
86
89
|
/**
|
|
87
90
|
* Name for this permit, for organization and UI usage, not included in signature.
|
|
88
91
|
*/
|
|
@@ -97,7 +100,7 @@ interface Permit {
|
|
|
97
100
|
/**
|
|
98
101
|
* (base) User that initially created the permission, target of data fetching
|
|
99
102
|
*/
|
|
100
|
-
issuer:
|
|
103
|
+
issuer: Hex;
|
|
101
104
|
/**
|
|
102
105
|
* (base) Expiration timestamp
|
|
103
106
|
*/
|
|
@@ -106,7 +109,7 @@ interface Permit {
|
|
|
106
109
|
* (sharing) The user that this permission will be shared with
|
|
107
110
|
* ** optional, use `address(0)` to disable **
|
|
108
111
|
*/
|
|
109
|
-
recipient:
|
|
112
|
+
recipient: Hex;
|
|
110
113
|
/**
|
|
111
114
|
* (issuer defined validation) An id used to query a contract to check this permissions validity
|
|
112
115
|
* ** optional, use `0` to disable **
|
|
@@ -116,7 +119,7 @@ interface Permit {
|
|
|
116
119
|
* (issuer defined validation) The contract to query to determine permission validity
|
|
117
120
|
* ** optional, user `address(0)` to disable **
|
|
118
121
|
*/
|
|
119
|
-
validatorContract:
|
|
122
|
+
validatorContract: Hex;
|
|
120
123
|
/**
|
|
121
124
|
* (base) The publicKey of a sealingPair used to re-encrypt `issuer`s confidential data
|
|
122
125
|
* (non-sharing) Populated by `issuer`
|
|
@@ -129,19 +132,35 @@ interface Permit {
|
|
|
129
132
|
* (non-sharing) < issuer, expiration, recipient, validatorId, validatorContract, sealingKey >
|
|
130
133
|
* (sharing) < issuer, expiration, recipient, validatorId, validatorContract >
|
|
131
134
|
*/
|
|
132
|
-
issuerSignature:
|
|
135
|
+
issuerSignature: Hex;
|
|
133
136
|
/**
|
|
134
137
|
* (sharing) `signTypedData` signature created by `recipient` with format:
|
|
135
138
|
* (sharing) < sealingKey, issuerSignature>
|
|
136
139
|
* ** required for shared permits **
|
|
137
140
|
*/
|
|
138
|
-
recipientSignature:
|
|
141
|
+
recipientSignature: Hex;
|
|
139
142
|
/**
|
|
140
143
|
* EIP712 domain used to sign this permit.
|
|
141
144
|
* Should not be set manually, included in metadata as part of serialization flows.
|
|
142
145
|
*/
|
|
143
146
|
_signedDomain?: EIP712Domain;
|
|
144
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Permit discriminant helpers
|
|
150
|
+
*/
|
|
151
|
+
type PermitType = Permit['type'];
|
|
152
|
+
/**
|
|
153
|
+
* Utility type to narrow a permit to a specific discriminant.
|
|
154
|
+
*
|
|
155
|
+
* Note: this only narrows the `type` field. Runtime/validation constraints
|
|
156
|
+
* (e.g. recipient == zeroAddress for self permits) are enforced elsewhere.
|
|
157
|
+
*/
|
|
158
|
+
type PermitOf<T extends PermitType> = Expand<Omit<Permit, 'type'> & {
|
|
159
|
+
type: T;
|
|
160
|
+
}>;
|
|
161
|
+
type SelfPermit = PermitOf<'self'>;
|
|
162
|
+
type SharingPermit = PermitOf<'sharing'>;
|
|
163
|
+
type RecipientPermit = PermitOf<'recipient'>;
|
|
145
164
|
/**
|
|
146
165
|
* Optional additional metadata of a Permit
|
|
147
166
|
* Can be passed into the constructor, but not necessary
|
|
@@ -180,7 +199,7 @@ type ImportSharedPermitOptions = {
|
|
|
180
199
|
recipient: string;
|
|
181
200
|
issuerSignature: string;
|
|
182
201
|
name?: string;
|
|
183
|
-
expiration
|
|
202
|
+
expiration: number;
|
|
184
203
|
validatorId?: number;
|
|
185
204
|
validatorContract?: string;
|
|
186
205
|
};
|
|
@@ -194,9 +213,13 @@ type SerializedPermit = Omit<Permit, 'sealingPair'> & {
|
|
|
194
213
|
/**
|
|
195
214
|
* A type representing the Permission struct that is passed to Permissioned.sol to grant encrypted data access.
|
|
196
215
|
*/
|
|
197
|
-
type Permission = Expand<Omit<Permit, 'name' | 'type' | 'sealingPair'> & {
|
|
198
|
-
sealingKey:
|
|
216
|
+
type Permission = Expand<Omit<Permit, 'name' | 'type' | 'sealingPair' | 'hash'> & {
|
|
217
|
+
sealingKey: Hex;
|
|
199
218
|
}>;
|
|
219
|
+
/**
|
|
220
|
+
* A type representing the permit fields that are used to generate the hash
|
|
221
|
+
*/
|
|
222
|
+
type PermitHashFields = Pick<Permit, 'type' | 'issuer' | 'expiration' | 'recipient' | 'validatorId' | 'validatorContract'>;
|
|
200
223
|
/**
|
|
201
224
|
* Validation result type
|
|
202
225
|
*/
|
|
@@ -219,31 +242,31 @@ declare const PermitUtils: {
|
|
|
219
242
|
/**
|
|
220
243
|
* Create a self permit for personal use
|
|
221
244
|
*/
|
|
222
|
-
createSelf: (options: CreateSelfPermitOptions) =>
|
|
245
|
+
createSelf: (options: CreateSelfPermitOptions) => SelfPermit;
|
|
223
246
|
/**
|
|
224
247
|
* Create a sharing permit to be shared with another user
|
|
225
248
|
*/
|
|
226
|
-
createSharing: (options: CreateSharingPermitOptions) =>
|
|
249
|
+
createSharing: (options: CreateSharingPermitOptions) => SharingPermit;
|
|
227
250
|
/**
|
|
228
251
|
* Import a shared permit from various input formats
|
|
229
252
|
*/
|
|
230
|
-
importShared: (options: ImportSharedPermitOptions |
|
|
253
|
+
importShared: (options: ImportSharedPermitOptions | string) => RecipientPermit;
|
|
231
254
|
/**
|
|
232
255
|
* Sign a permit with the provided wallet client
|
|
233
256
|
*/
|
|
234
|
-
sign: (permit:
|
|
257
|
+
sign: <T extends Permit>(permit: T, publicClient: PublicClient, walletClient: WalletClient) => Promise<T>;
|
|
235
258
|
/**
|
|
236
259
|
* Create and sign a self permit in one operation
|
|
237
260
|
*/
|
|
238
|
-
createSelfAndSign: (options: CreateSelfPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<
|
|
261
|
+
createSelfAndSign: (options: CreateSelfPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SelfPermit>;
|
|
239
262
|
/**
|
|
240
263
|
* Create and sign a sharing permit in one operation
|
|
241
264
|
*/
|
|
242
|
-
createSharingAndSign: (options: CreateSharingPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<
|
|
265
|
+
createSharingAndSign: (options: CreateSharingPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SharingPermit>;
|
|
243
266
|
/**
|
|
244
267
|
* Import and sign a shared permit in one operation from various input formats
|
|
245
268
|
*/
|
|
246
|
-
importSharedAndSign: (options: ImportSharedPermitOptions |
|
|
269
|
+
importSharedAndSign: (options: ImportSharedPermitOptions | string, publicClient: PublicClient, walletClient: WalletClient) => Promise<RecipientPermit>;
|
|
247
270
|
/**
|
|
248
271
|
* Deserialize a permit from serialized data
|
|
249
272
|
*/
|
|
@@ -255,35 +278,21 @@ declare const PermitUtils: {
|
|
|
255
278
|
/**
|
|
256
279
|
* Validate a permit
|
|
257
280
|
*/
|
|
258
|
-
validate: (permit: Permit) =>
|
|
259
|
-
type: "self" | "sharing" | "recipient";
|
|
260
|
-
issuer: string;
|
|
261
|
-
recipient?: string | undefined;
|
|
262
|
-
sealingPair?: {
|
|
263
|
-
privateKey: string;
|
|
264
|
-
publicKey: string;
|
|
265
|
-
} | undefined;
|
|
266
|
-
name?: string | undefined;
|
|
267
|
-
expiration?: number | undefined;
|
|
268
|
-
validatorId?: number | undefined;
|
|
269
|
-
validatorContract?: string | undefined;
|
|
270
|
-
issuerSignature?: string | undefined;
|
|
271
|
-
recipientSignature?: string | undefined;
|
|
272
|
-
}, {
|
|
273
|
-
recipient: `0x${string}`;
|
|
281
|
+
validate: (permit: Permit) => {
|
|
274
282
|
name: string;
|
|
275
283
|
type: "self" | "sharing" | "recipient";
|
|
276
284
|
issuer: `0x${string}`;
|
|
277
285
|
expiration: number;
|
|
286
|
+
recipient: `0x${string}`;
|
|
278
287
|
validatorId: number;
|
|
279
288
|
validatorContract: `0x${string}`;
|
|
280
|
-
issuerSignature: string
|
|
281
|
-
recipientSignature: string
|
|
289
|
+
issuerSignature: `0x${string}`;
|
|
290
|
+
recipientSignature: `0x${string}`;
|
|
282
291
|
sealingPair?: {
|
|
283
292
|
privateKey: string;
|
|
284
293
|
publicKey: string;
|
|
285
294
|
} | undefined;
|
|
286
|
-
}
|
|
295
|
+
};
|
|
287
296
|
/**
|
|
288
297
|
* Get the permission object from a permit (for use in contracts)
|
|
289
298
|
*/
|
|
@@ -291,7 +300,7 @@ declare const PermitUtils: {
|
|
|
291
300
|
/**
|
|
292
301
|
* Get a stable hash for the permit (used as key in storage)
|
|
293
302
|
*/
|
|
294
|
-
getHash: (permit:
|
|
303
|
+
getHash: (permit: PermitHashFields) => string;
|
|
295
304
|
/**
|
|
296
305
|
* Export permit data for sharing (removes sensitive fields)
|
|
297
306
|
*/
|
|
@@ -328,6 +337,10 @@ declare const PermitUtils: {
|
|
|
328
337
|
* Check if permit's signed domain is valid for the current chain
|
|
329
338
|
*/
|
|
330
339
|
checkSignedDomainValid: (permit: Permit, publicClient: PublicClient) => Promise<boolean>;
|
|
340
|
+
/**
|
|
341
|
+
* Check if permit passes the on-chain validation
|
|
342
|
+
*/
|
|
343
|
+
checkValidityOnChain: (permit: Permit, publicClient: PublicClient) => Promise<boolean>;
|
|
331
344
|
};
|
|
332
345
|
|
|
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
|
|
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 };
|