@cofhe/sdk 0.7.0 → 0.8.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.
Files changed (79) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/acps/acp.ts +10 -1
  3. package/acps/index.ts +11 -0
  4. package/acps/onchain-utils.ts +188 -49
  5. package/acps/registry.ts +73 -0
  6. package/acps/test/onchainAccessStatus.test.ts +116 -0
  7. package/acps/types.ts +16 -0
  8. package/chains/chains/arbitrum.ts +14 -0
  9. package/chains/chains/ethereum.ts +14 -0
  10. package/chains/index.ts +5 -1
  11. package/chains/test/chains.test.ts +24 -3
  12. package/core/acps.ts +51 -143
  13. package/core/client.ts +13 -8
  14. package/core/clientTypes.ts +29 -4
  15. package/core/config.ts +25 -1
  16. package/core/consts.ts +14 -2
  17. package/core/decrypt/verifyDecryptResult.ts +4 -3
  18. package/core/encrypt/encryptInputsBuilder.ts +6 -0
  19. package/core/encrypt/zkPackProveVerify.ts +7 -1
  20. package/core/error.ts +1 -0
  21. package/core/fetchKeys.ts +2 -2
  22. package/core/index.ts +9 -1
  23. package/core/keyStore.ts +23 -10
  24. package/core/taskManager.ts +48 -0
  25. package/core/test/acps.test.ts +91 -1
  26. package/core/test/client.test.ts +41 -0
  27. package/core/test/config.test.ts +16 -0
  28. package/core/test/decrypt.test.ts +11 -4
  29. package/core/test/encryptInputsBuilder.test.ts +1 -1
  30. package/core/test/fetchKeys.test.ts +23 -2
  31. package/core/test/keyStore.test.ts +18 -6
  32. package/core/test/taskManager.test.ts +57 -0
  33. package/core/types.ts +8 -0
  34. package/dist/acps.cjs +314 -35
  35. package/dist/acps.d.cts +251 -4
  36. package/dist/acps.d.ts +251 -4
  37. package/dist/acps.js +2 -2
  38. package/dist/chains.cjs +26 -0
  39. package/dist/chains.d.cts +45 -1
  40. package/dist/chains.d.ts +45 -1
  41. package/dist/chains.js +1 -1
  42. package/dist/{chunk-43USWPEH.js → chunk-GGI7Y6AW.js} +59 -264
  43. package/dist/chunk-KSOV5B4B.js +50 -0
  44. package/dist/{chunk-ESMZCFJY.js → chunk-NMKMCAI3.js} +4 -2
  45. package/dist/{chunk-Q7CBWGQX.js → chunk-UJYOBHYA.js} +374 -37
  46. package/dist/{chunk-N6IDQRRU.js → chunk-UKQAJK4N.js} +25 -1
  47. package/dist/{clientTypes-BN3nbzYM.d.ts → clientTypes-5YPPR16m.d.ts} +77 -14
  48. package/dist/{clientTypes-CYZjFznO.d.cts → clientTypes-D3aIXmUp.d.cts} +77 -14
  49. package/dist/core.cjs +271 -136
  50. package/dist/core.d.cts +29 -8
  51. package/dist/core.d.ts +29 -8
  52. package/dist/core.js +4 -4
  53. package/dist/node.cjs +266 -136
  54. package/dist/node.d.cts +2 -2
  55. package/dist/node.d.ts +2 -2
  56. package/dist/node.js +5 -5
  57. package/dist/{acp-Wi6isVQI.d.cts → onchain-utils-CUAK8glx.d.cts} +31 -1
  58. package/dist/{acp-Wi6isVQI.d.ts → onchain-utils-CUAK8glx.d.ts} +31 -1
  59. package/dist/web.cjs +360 -150
  60. package/dist/web.d.cts +49 -3
  61. package/dist/web.d.ts +49 -3
  62. package/dist/web.js +51 -20
  63. package/dist/zkProve.worker.cjs +69 -15
  64. package/dist/zkProve.worker.js +23 -17
  65. package/node/storage.ts +2 -2
  66. package/node/test/inherited.test.ts +5 -1
  67. package/node/test/storage-memory-fallback.test.ts +47 -0
  68. package/package.json +5 -3
  69. package/web/index.ts +100 -26
  70. package/web/test/countingZkProveWorker.ts +31 -0
  71. package/web/test/inherited.web.test.ts +5 -1
  72. package/web/test/mainThreadPool.web.test.ts +174 -0
  73. package/web/test/threadPoolBenchHelper.ts +140 -0
  74. package/web/test/threadPoolOff.web.test.ts +17 -0
  75. package/web/test/threadPoolOn.web.test.ts +80 -0
  76. package/web/test/workerInitRace.web.test.ts +79 -0
  77. package/web/tfheThreadPool.ts +140 -0
  78. package/web/workerManager.ts +4 -2
  79. package/web/zkProve.worker.ts +42 -17
@@ -235,6 +235,13 @@ type SharedACP = Expand<Omit<ACPPublic, 'sealingKey' | 'recipientSignature'> & {
235
235
  name: string;
236
236
  type: 'sharing';
237
237
  }>;
238
+ /**
239
+ * An ACP on-chain status, as `client.acp.checkAccess` reports it instead of a revert.
240
+ * Without a handle: 'valid' or the reason it is not. With a handle, a valid ACP reports
241
+ * 'allowed', 'out-of-scope' (the ACP scope does not cover the handle) or
242
+ * 'issuer-not-allowed' (the issuer itself may not read the handle, so no ACP of theirs can).
243
+ */
244
+ type ACPAccessStatus = 'valid' | 'allowed' | 'out-of-scope' | 'issuer-not-allowed' | 'expired' | 'revoked' | 'invalid-issuer-signature' | 'invalid-recipient-signature';
238
245
  /**
239
246
  * A share read back from the on-chain ACPShareRegistry: the posted payload
240
247
  * (SharedACP minus the client-side name/type) plus its registry id.
@@ -402,6 +409,29 @@ declare const ACPUtils: {
402
409
  * Check if acp passes the on-chain validation
403
410
  */
404
411
  checkValidityOnChain: (acp: ACP, publicClient: PublicClient) => Promise<boolean>;
412
+ /**
413
+ * The acp on-chain status as a value instead of a revert: 'valid' or why not, and given a
414
+ * handle, whether the acp may read it (see `ACPAccessStatus`).
415
+ */
416
+ checkAccessOnChain: (acp: ACP, publicClient: PublicClient, handle?: bigint | Hex) => Promise<ACPAccessStatus>;
405
417
  };
406
418
 
407
- export { type ACP as A, type CreateSelfACPOptions as C, type EIP712Types as E, GenerateSealingKey as G, type ImportSharedACPOptions as I, type RecipientACP as R, type SerializedACP as S, type ValidationResult as V, type ACPPublic as a, type ACPSignaturePrimaryType as b, type EIP712Message as c, type CreateSharingACPOptions as d, type ACPMetadata as e, type SharedACP as f, type IncomingShare as g, type EIP712Domain as h, ACPUtils as i, type SealingKeyPair as j, type EthEncryptedData as k, type EIP712Type as l, type ACPPrivate as m, type ACPType as n, type ACPOf as o, type SelfACP as p, type SharingACP as q, ACPScope as r, seal as s, type ACPScopeOptions as t, unsealWithPrivateKey as u, type ACPHashFields as v, type Expand as w };
419
+ declare const getAclAddress: (publicClient: PublicClient) => Promise<Hex>;
420
+ interface AclServedAddresses {
421
+ defaultRevoker?: Hex;
422
+ shareRegistry?: Hex;
423
+ }
424
+ /** Test hook: forget resolved addresses (e.g. between redeployments on one chainId). */
425
+ declare const clearAclServedAddresses: () => void;
426
+ /**
427
+ * The ACP infrastructure addresses the chain's ACL serves (CoFHEAddressBook ->
428
+ * TaskManager -> acl() -> getters). Zero addresses and pre-upgrade ACLs (getters absent -> revert)
429
+ * resolve to `undefined` — callers fall back to `acp.*` config.
430
+ *
431
+ * Resolutions are cached per chainId. A failure to reach the TaskManager (network
432
+ * error, no CoFHE deployment) is NOT cached, so a transient outage does not pin
433
+ * an empty result for the whole session.
434
+ */
435
+ declare const getAclServedAddresses: (publicClient: PublicClient, chainId: number) => Promise<AclServedAddresses>;
436
+
437
+ export { type ACP as A, type ACPHashFields as B, type CreateSelfACPOptions as C, type Expand as D, type EIP712Types as E, GenerateSealingKey as G, type ImportSharedACPOptions as I, type RecipientACP as R, type SerializedACP as S, type ValidationResult as V, type ACPPublic as a, type ACPSignaturePrimaryType as b, type EIP712Message as c, type CreateSharingACPOptions as d, type ACPMetadata as e, type SharedACP as f, type IncomingShare as g, type EIP712Domain as h, ACPUtils as i, getAclAddress as j, getAclServedAddresses as k, clearAclServedAddresses as l, type AclServedAddresses as m, type SealingKeyPair as n, type EthEncryptedData as o, type EIP712Type as p, type ACPPrivate as q, type ACPType as r, seal as s, type ACPOf as t, unsealWithPrivateKey as u, type SelfACP as v, type SharingACP as w, ACPScope as x, type ACPScopeOptions as y, type ACPAccessStatus as z };
@@ -235,6 +235,13 @@ type SharedACP = Expand<Omit<ACPPublic, 'sealingKey' | 'recipientSignature'> & {
235
235
  name: string;
236
236
  type: 'sharing';
237
237
  }>;
238
+ /**
239
+ * An ACP on-chain status, as `client.acp.checkAccess` reports it instead of a revert.
240
+ * Without a handle: 'valid' or the reason it is not. With a handle, a valid ACP reports
241
+ * 'allowed', 'out-of-scope' (the ACP scope does not cover the handle) or
242
+ * 'issuer-not-allowed' (the issuer itself may not read the handle, so no ACP of theirs can).
243
+ */
244
+ type ACPAccessStatus = 'valid' | 'allowed' | 'out-of-scope' | 'issuer-not-allowed' | 'expired' | 'revoked' | 'invalid-issuer-signature' | 'invalid-recipient-signature';
238
245
  /**
239
246
  * A share read back from the on-chain ACPShareRegistry: the posted payload
240
247
  * (SharedACP minus the client-side name/type) plus its registry id.
@@ -402,6 +409,29 @@ declare const ACPUtils: {
402
409
  * Check if acp passes the on-chain validation
403
410
  */
404
411
  checkValidityOnChain: (acp: ACP, publicClient: PublicClient) => Promise<boolean>;
412
+ /**
413
+ * The acp on-chain status as a value instead of a revert: 'valid' or why not, and given a
414
+ * handle, whether the acp may read it (see `ACPAccessStatus`).
415
+ */
416
+ checkAccessOnChain: (acp: ACP, publicClient: PublicClient, handle?: bigint | Hex) => Promise<ACPAccessStatus>;
405
417
  };
406
418
 
407
- export { type ACP as A, type CreateSelfACPOptions as C, type EIP712Types as E, GenerateSealingKey as G, type ImportSharedACPOptions as I, type RecipientACP as R, type SerializedACP as S, type ValidationResult as V, type ACPPublic as a, type ACPSignaturePrimaryType as b, type EIP712Message as c, type CreateSharingACPOptions as d, type ACPMetadata as e, type SharedACP as f, type IncomingShare as g, type EIP712Domain as h, ACPUtils as i, type SealingKeyPair as j, type EthEncryptedData as k, type EIP712Type as l, type ACPPrivate as m, type ACPType as n, type ACPOf as o, type SelfACP as p, type SharingACP as q, ACPScope as r, seal as s, type ACPScopeOptions as t, unsealWithPrivateKey as u, type ACPHashFields as v, type Expand as w };
419
+ declare const getAclAddress: (publicClient: PublicClient) => Promise<Hex>;
420
+ interface AclServedAddresses {
421
+ defaultRevoker?: Hex;
422
+ shareRegistry?: Hex;
423
+ }
424
+ /** Test hook: forget resolved addresses (e.g. between redeployments on one chainId). */
425
+ declare const clearAclServedAddresses: () => void;
426
+ /**
427
+ * The ACP infrastructure addresses the chain's ACL serves (CoFHEAddressBook ->
428
+ * TaskManager -> acl() -> getters). Zero addresses and pre-upgrade ACLs (getters absent -> revert)
429
+ * resolve to `undefined` — callers fall back to `acp.*` config.
430
+ *
431
+ * Resolutions are cached per chainId. A failure to reach the TaskManager (network
432
+ * error, no CoFHE deployment) is NOT cached, so a transient outage does not pin
433
+ * an empty result for the whole session.
434
+ */
435
+ declare const getAclServedAddresses: (publicClient: PublicClient, chainId: number) => Promise<AclServedAddresses>;
436
+
437
+ export { type ACP as A, type ACPHashFields as B, type CreateSelfACPOptions as C, type Expand as D, type EIP712Types as E, GenerateSealingKey as G, type ImportSharedACPOptions as I, type RecipientACP as R, type SerializedACP as S, type ValidationResult as V, type ACPPublic as a, type ACPSignaturePrimaryType as b, type EIP712Message as c, type CreateSharingACPOptions as d, type ACPMetadata as e, type SharedACP as f, type IncomingShare as g, type EIP712Domain as h, ACPUtils as i, getAclAddress as j, getAclServedAddresses as k, clearAclServedAddresses as l, type AclServedAddresses as m, type SealingKeyPair as n, type EthEncryptedData as o, type EIP712Type as p, type ACPPrivate as q, type ACPType as r, seal as s, type ACPOf as t, unsealWithPrivateKey as u, type SelfACP as v, type SharingACP as w, ACPScope as x, type ACPScopeOptions as y, type ACPAccessStatus as z };