@cofhe/sdk 0.2.0 → 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.
Files changed (57) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/chains/defineChain.ts +2 -2
  3. package/chains/types.ts +3 -3
  4. package/core/client.test.ts +111 -0
  5. package/core/client.ts +22 -2
  6. package/core/clientTypes.ts +7 -1
  7. package/core/config.test.ts +8 -0
  8. package/core/config.ts +10 -4
  9. package/core/consts.ts +18 -0
  10. package/core/decrypt/cofheMocksSealOutput.ts +2 -4
  11. package/core/encrypt/cofheMocksZkVerifySign.ts +4 -11
  12. package/core/index.ts +9 -1
  13. package/core/permits.test.ts +5 -6
  14. package/core/permits.ts +5 -4
  15. package/dist/chains.cjs +4 -7
  16. package/dist/chains.d.cts +12 -12
  17. package/dist/chains.d.ts +12 -12
  18. package/dist/chains.js +1 -1
  19. package/dist/{chunk-WGCRJCBR.js → chunk-I5WFEYXX.js} +33 -19
  20. package/dist/{chunk-UGBVZNRT.js → chunk-R3B5TMVX.js} +308 -189
  21. package/dist/{chunk-WEAZ25JO.js → chunk-TBLR7NNE.js} +4 -7
  22. package/dist/{clientTypes-Es7fyi65.d.ts → clientTypes-RqkgkV2i.d.ts} +34 -93
  23. package/dist/{clientTypes-5_1nwtUe.d.cts → clientTypes-e4filDzK.d.cts} +34 -93
  24. package/dist/core.cjs +343 -208
  25. package/dist/core.d.cts +17 -6
  26. package/dist/core.d.ts +17 -6
  27. package/dist/core.js +3 -3
  28. package/dist/node.cjs +337 -208
  29. package/dist/node.d.cts +3 -3
  30. package/dist/node.d.ts +3 -3
  31. package/dist/node.js +3 -3
  32. package/dist/{permit-fUSe6KKq.d.cts → permit-MZ502UBl.d.cts} +30 -33
  33. package/dist/{permit-fUSe6KKq.d.ts → permit-MZ502UBl.d.ts} +30 -33
  34. package/dist/permits.cjs +305 -187
  35. package/dist/permits.d.cts +111 -812
  36. package/dist/permits.d.ts +111 -812
  37. package/dist/permits.js +1 -1
  38. package/dist/types-YiAC4gig.d.cts +33 -0
  39. package/dist/types-YiAC4gig.d.ts +33 -0
  40. package/dist/web.cjs +337 -208
  41. package/dist/web.d.cts +3 -3
  42. package/dist/web.d.ts +3 -3
  43. package/dist/web.js +3 -3
  44. package/package.json +3 -3
  45. package/permits/localstorage.test.ts +9 -13
  46. package/permits/onchain-utils.ts +221 -0
  47. package/permits/permit.test.ts +51 -5
  48. package/permits/permit.ts +28 -74
  49. package/permits/store.test.ts +10 -50
  50. package/permits/store.ts +4 -14
  51. package/permits/test-utils.ts +10 -2
  52. package/permits/types.ts +22 -9
  53. package/permits/utils.ts +0 -4
  54. package/permits/validation.test.ts +29 -32
  55. package/permits/validation.ts +112 -194
  56. package/dist/types-KImPrEIe.d.cts +0 -48
  57. package/dist/types-KImPrEIe.d.ts +0 -48
package/dist/node.d.cts CHANGED
@@ -1,8 +1,8 @@
1
- import { C as CofhesdkInputConfig, a as CofhesdkConfig, b as CofhesdkClient } from './clientTypes-5_1nwtUe.cjs';
1
+ import { C as CofhesdkInputConfig, a as CofhesdkConfig, b as CofhesdkClient } from './clientTypes-e4filDzK.cjs';
2
2
  import 'viem';
3
- import './types-KImPrEIe.cjs';
3
+ import './types-YiAC4gig.cjs';
4
4
  import 'zod';
5
- import './permit-fUSe6KKq.cjs';
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 { C as CofhesdkInputConfig, a as CofhesdkConfig, b as CofhesdkClient } from './clientTypes-Es7fyi65.js';
1
+ import { C as CofhesdkInputConfig, a as CofhesdkConfig, b as CofhesdkClient } from './clientTypes-RqkgkV2i.js';
2
2
  import 'viem';
3
- import './types-KImPrEIe.js';
3
+ import './types-YiAC4gig.js';
4
4
  import 'zod';
5
- import './permit-fUSe6KKq.js';
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-WGCRJCBR.js';
2
- import './chunk-WEAZ25JO.js';
3
- import './chunk-UGBVZNRT.js';
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';
@@ -1,5 +1,4 @@
1
- import * as zod from 'zod';
2
- import { PublicClient, WalletClient } from 'viem';
1
+ import { Hex, PublicClient, WalletClient } from 'viem';
3
2
 
4
3
  type EthEncryptedData = {
5
4
  data: Uint8Array;
@@ -71,7 +70,7 @@ type EIP712Message = Record<string, string>;
71
70
  type EIP712Domain = {
72
71
  chainId: number;
73
72
  name: string;
74
- verifyingContract: `0x${string}`;
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: `0x${string}`;
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: `0x${string}`;
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: `0x${string}`;
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,13 +132,13 @@ interface Permit {
129
132
  * (non-sharing) < issuer, expiration, recipient, validatorId, validatorContract, sealingKey >
130
133
  * (sharing) < issuer, expiration, recipient, validatorId, validatorContract >
131
134
  */
132
- issuerSignature: `0x${string}`;
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: `0x${string}`;
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.
@@ -196,7 +199,7 @@ type ImportSharedPermitOptions = {
196
199
  recipient: string;
197
200
  issuerSignature: string;
198
201
  name?: string;
199
- expiration?: number;
202
+ expiration: number;
200
203
  validatorId?: number;
201
204
  validatorContract?: string;
202
205
  };
@@ -210,9 +213,13 @@ type SerializedPermit = Omit<Permit, 'sealingPair'> & {
210
213
  /**
211
214
  * A type representing the Permission struct that is passed to Permissioned.sol to grant encrypted data access.
212
215
  */
213
- type Permission = Expand<Omit<Permit, 'name' | 'type' | 'sealingPair'> & {
214
- sealingKey: `0x${string}`;
216
+ type Permission = Expand<Omit<Permit, 'name' | 'type' | 'sealingPair' | 'hash'> & {
217
+ sealingKey: Hex;
215
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'>;
216
223
  /**
217
224
  * Validation result type
218
225
  */
@@ -271,35 +278,21 @@ declare const PermitUtils: {
271
278
  /**
272
279
  * Validate a permit
273
280
  */
274
- validate: (permit: Permit) => zod.SafeParseReturnType<{
275
- type: "self" | "sharing" | "recipient";
276
- issuer: string;
277
- recipient?: string | undefined;
278
- name?: string | undefined;
279
- expiration?: number | undefined;
280
- validatorId?: number | undefined;
281
- validatorContract?: string | undefined;
282
- sealingPair?: {
283
- privateKey: string;
284
- publicKey: string;
285
- } | undefined;
286
- issuerSignature?: string | undefined;
287
- recipientSignature?: string | undefined;
288
- }, {
289
- recipient: `0x${string}`;
290
- type: "self" | "sharing" | "recipient";
281
+ validate: (permit: Permit) => {
291
282
  name: string;
283
+ type: "self" | "sharing" | "recipient";
292
284
  issuer: `0x${string}`;
293
285
  expiration: number;
286
+ recipient: `0x${string}`;
294
287
  validatorId: number;
295
288
  validatorContract: `0x${string}`;
296
- issuerSignature: string;
297
- recipientSignature: string;
289
+ issuerSignature: `0x${string}`;
290
+ recipientSignature: `0x${string}`;
298
291
  sealingPair?: {
299
292
  privateKey: string;
300
293
  publicKey: string;
301
294
  } | undefined;
302
- }>;
295
+ };
303
296
  /**
304
297
  * Get the permission object from a permit (for use in contracts)
305
298
  */
@@ -307,7 +300,7 @@ declare const PermitUtils: {
307
300
  /**
308
301
  * Get a stable hash for the permit (used as key in storage)
309
302
  */
310
- getHash: (permit: Permit) => string;
303
+ getHash: (permit: PermitHashFields) => string;
311
304
  /**
312
305
  * Export permit data for sharing (removes sensitive fields)
313
306
  */
@@ -344,6 +337,10 @@ declare const PermitUtils: {
344
337
  * Check if permit's signed domain is valid for the current chain
345
338
  */
346
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>;
347
344
  };
348
345
 
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 };
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 * as zod from 'zod';
2
- import { PublicClient, WalletClient } from 'viem';
1
+ import { Hex, PublicClient, WalletClient } from 'viem';
3
2
 
4
3
  type EthEncryptedData = {
5
4
  data: Uint8Array;
@@ -71,7 +70,7 @@ type EIP712Message = Record<string, string>;
71
70
  type EIP712Domain = {
72
71
  chainId: number;
73
72
  name: string;
74
- verifyingContract: `0x${string}`;
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: `0x${string}`;
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: `0x${string}`;
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: `0x${string}`;
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,13 +132,13 @@ interface Permit {
129
132
  * (non-sharing) < issuer, expiration, recipient, validatorId, validatorContract, sealingKey >
130
133
  * (sharing) < issuer, expiration, recipient, validatorId, validatorContract >
131
134
  */
132
- issuerSignature: `0x${string}`;
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: `0x${string}`;
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.
@@ -196,7 +199,7 @@ type ImportSharedPermitOptions = {
196
199
  recipient: string;
197
200
  issuerSignature: string;
198
201
  name?: string;
199
- expiration?: number;
202
+ expiration: number;
200
203
  validatorId?: number;
201
204
  validatorContract?: string;
202
205
  };
@@ -210,9 +213,13 @@ type SerializedPermit = Omit<Permit, 'sealingPair'> & {
210
213
  /**
211
214
  * A type representing the Permission struct that is passed to Permissioned.sol to grant encrypted data access.
212
215
  */
213
- type Permission = Expand<Omit<Permit, 'name' | 'type' | 'sealingPair'> & {
214
- sealingKey: `0x${string}`;
216
+ type Permission = Expand<Omit<Permit, 'name' | 'type' | 'sealingPair' | 'hash'> & {
217
+ sealingKey: Hex;
215
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'>;
216
223
  /**
217
224
  * Validation result type
218
225
  */
@@ -271,35 +278,21 @@ declare const PermitUtils: {
271
278
  /**
272
279
  * Validate a permit
273
280
  */
274
- validate: (permit: Permit) => zod.SafeParseReturnType<{
275
- type: "self" | "sharing" | "recipient";
276
- issuer: string;
277
- recipient?: string | undefined;
278
- name?: string | undefined;
279
- expiration?: number | undefined;
280
- validatorId?: number | undefined;
281
- validatorContract?: string | undefined;
282
- sealingPair?: {
283
- privateKey: string;
284
- publicKey: string;
285
- } | undefined;
286
- issuerSignature?: string | undefined;
287
- recipientSignature?: string | undefined;
288
- }, {
289
- recipient: `0x${string}`;
290
- type: "self" | "sharing" | "recipient";
281
+ validate: (permit: Permit) => {
291
282
  name: string;
283
+ type: "self" | "sharing" | "recipient";
292
284
  issuer: `0x${string}`;
293
285
  expiration: number;
286
+ recipient: `0x${string}`;
294
287
  validatorId: number;
295
288
  validatorContract: `0x${string}`;
296
- issuerSignature: string;
297
- recipientSignature: string;
289
+ issuerSignature: `0x${string}`;
290
+ recipientSignature: `0x${string}`;
298
291
  sealingPair?: {
299
292
  privateKey: string;
300
293
  publicKey: string;
301
294
  } | undefined;
302
- }>;
295
+ };
303
296
  /**
304
297
  * Get the permission object from a permit (for use in contracts)
305
298
  */
@@ -307,7 +300,7 @@ declare const PermitUtils: {
307
300
  /**
308
301
  * Get a stable hash for the permit (used as key in storage)
309
302
  */
310
- getHash: (permit: Permit) => string;
303
+ getHash: (permit: PermitHashFields) => string;
311
304
  /**
312
305
  * Export permit data for sharing (removes sensitive fields)
313
306
  */
@@ -344,6 +337,10 @@ declare const PermitUtils: {
344
337
  * Check if permit's signed domain is valid for the current chain
345
338
  */
346
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>;
347
344
  };
348
345
 
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 };
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 };