@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
package/dist/acps.cjs CHANGED
@@ -398,15 +398,139 @@ var SignatureUtils = {
398
398
  };
399
399
 
400
400
  // core/consts.ts
401
- var TASK_MANAGER_ADDRESS = "0xeA30c4B8b44078Bbf8a6ef5b9f1eC1626C7848D9";
401
+ var COFHE_ADDRESS_BOOK_ADDRESS = "0xC0F4e00E531a2B086492Ae3DCC1515038307196b";
402
+ var TASK_MANAGER_ID = 1n;
402
403
  BigInt(1 << 30);
403
404
 
405
+ // core/error.ts
406
+ var CofheError = class _CofheError extends Error {
407
+ code;
408
+ cause;
409
+ hint;
410
+ context;
411
+ apiErrorCode;
412
+ constructor({ code, message, cause, hint, context, apiErrorCode }) {
413
+ const fullMessage = cause ? `${message} | Caused by: ${cause.message}` : message;
414
+ super(fullMessage);
415
+ this.name = "CofheError";
416
+ this.code = code;
417
+ this.cause = cause;
418
+ this.hint = hint;
419
+ this.context = context;
420
+ this.apiErrorCode = apiErrorCode;
421
+ if (Error.captureStackTrace) {
422
+ Error.captureStackTrace(this, _CofheError);
423
+ }
424
+ }
425
+ /**
426
+ * Creates a CofheError from an unknown error
427
+ * If the error is a CofheError, it is returned unchanged, else a new CofheError is created
428
+ * If a wrapperError is provided, it is used to create the new CofheError, else a default is used
429
+ */
430
+ static fromError(error, wrapperError) {
431
+ if (isCofheError(error))
432
+ return error;
433
+ const cause = error instanceof Error ? error : new Error(`${error}`);
434
+ return new _CofheError({
435
+ code: wrapperError?.code ?? "INTERNAL_ERROR" /* InternalError */,
436
+ message: wrapperError?.message ?? "An internal error occurred",
437
+ hint: wrapperError?.hint,
438
+ context: wrapperError?.context,
439
+ apiErrorCode: wrapperError?.apiErrorCode,
440
+ cause
441
+ });
442
+ }
443
+ /**
444
+ * Serializes the error to JSON string with proper handling of Error objects
445
+ */
446
+ serialize() {
447
+ return bigintSafeJsonStringify({
448
+ name: this.name,
449
+ code: this.code,
450
+ message: this.message,
451
+ hint: this.hint,
452
+ context: this.context,
453
+ apiErrorCode: this.apiErrorCode,
454
+ cause: this.cause ? {
455
+ name: this.cause.name,
456
+ message: this.cause.message,
457
+ stack: this.cause.stack
458
+ } : void 0,
459
+ stack: this.stack
460
+ });
461
+ }
462
+ /**
463
+ * Returns a human-readable string representation of the error
464
+ */
465
+ toString() {
466
+ const codeSuffix = this.apiErrorCode ? ` (api: ${this.apiErrorCode})` : "";
467
+ const parts = [`${this.name} [${this.code}]${codeSuffix}: ${this.message}`];
468
+ if (this.hint) {
469
+ parts.push(`Hint: ${this.hint}`);
470
+ }
471
+ if (this.context && Object.keys(this.context).length > 0) {
472
+ parts.push(`Context: ${bigintSafeJsonStringify(this.context)}`);
473
+ }
474
+ if (this.stack) {
475
+ parts.push(`
476
+ Stack trace:`);
477
+ parts.push(this.stack);
478
+ }
479
+ if (this.cause) {
480
+ parts.push(`
481
+ Caused by: ${this.cause.name}: ${this.cause.message}`);
482
+ if (this.cause.stack) {
483
+ parts.push(this.cause.stack);
484
+ }
485
+ }
486
+ return parts.join("\n");
487
+ }
488
+ };
489
+ var bigintSafeJsonStringify = (value) => {
490
+ return JSON.stringify(value, (key, value2) => {
491
+ if (typeof value2 === "bigint") {
492
+ return `${value2}n`;
493
+ }
494
+ return value2;
495
+ });
496
+ };
497
+ var isCofheError = (error) => error instanceof CofheError;
498
+
499
+ // core/taskManager.ts
500
+ var ADDRESS_BOOK_ABI = viem.parseAbi([
501
+ "function getTm(uint256 id) view returns (address)",
502
+ "error TaskManagerNotSet(uint256 id)"
503
+ ]);
504
+ var taskManagerAddressCache = /* @__PURE__ */ new Map();
505
+ var getTaskManagerAddress = async (publicClient, chainId) => {
506
+ const id = chainId ?? publicClient.chain?.id ?? await publicClient.getChainId();
507
+ const cached = taskManagerAddressCache.get(id);
508
+ if (cached != null)
509
+ return cached;
510
+ const pending = publicClient.readContract({
511
+ address: COFHE_ADDRESS_BOOK_ADDRESS,
512
+ abi: ADDRESS_BOOK_ABI,
513
+ functionName: "getTm",
514
+ args: [TASK_MANAGER_ID]
515
+ }).catch((error) => {
516
+ taskManagerAddressCache.delete(id);
517
+ throw CofheError.fromError(error, {
518
+ code: "TASK_MANAGER_UNRESOLVED" /* TaskManagerUnresolved */,
519
+ message: `Failed to resolve the Task Manager from the CoFHEAddressBook on chain ${id}`,
520
+ hint: "Ensure CoFHE is deployed on this chain. On a local hardhat / anvil chain, deploy the CoFHE mocks first.",
521
+ context: { chainId: id, addressBook: COFHE_ADDRESS_BOOK_ADDRESS, taskManagerId: TASK_MANAGER_ID }
522
+ });
523
+ });
524
+ taskManagerAddressCache.set(id, pending);
525
+ return pending;
526
+ };
527
+
404
528
  // acps/onchain-utils.ts
405
529
  var getAclAddress = async (publicClient) => {
406
530
  const ACL_IFACE = "function acl() view returns (address)";
407
531
  const aclAbi = viem.parseAbi([ACL_IFACE]);
408
532
  return await publicClient.readContract({
409
- address: TASK_MANAGER_ADDRESS,
533
+ address: await getTaskManagerAddress(publicClient),
410
534
  abi: aclAbi,
411
535
  functionName: "acl"
412
536
  });
@@ -433,6 +557,34 @@ var getAclEIP712Domain = async (publicClient) => {
433
557
  verifyingContract
434
558
  };
435
559
  };
560
+ var toACPTuple = (acp) => ({
561
+ issuer: acp.issuer,
562
+ expiration: BigInt(acp.expiration),
563
+ recipient: acp.recipient,
564
+ revokerData: BigInt(acp.revokerData),
565
+ revokerContract: acp.revokerContract,
566
+ scope: acp.scope,
567
+ contracts: acp.contracts,
568
+ handles: acp.handles,
569
+ sealingKey: acp.sealingKey,
570
+ issuerSignature: acp.issuerSignature,
571
+ recipientSignature: acp.recipientSignature
572
+ });
573
+ function revertErrorName(err, abi) {
574
+ const walk = err?.walk;
575
+ if (typeof walk === "function") {
576
+ const revertError = walk.call(err, (e) => e?.name === "ContractFunctionRevertedError");
577
+ if (revertError)
578
+ return revertError.data?.errorName ?? "";
579
+ }
580
+ const customErrorName = extractCustomErrorFromDetails(err, abi);
581
+ if (customErrorName)
582
+ return customErrorName;
583
+ const hhDetailsData = extractReturnData(err);
584
+ if (hhDetailsData != null)
585
+ return viem.decodeErrorResult({ abi, data: hhDetailsData }).errorName;
586
+ return void 0;
587
+ }
436
588
  var checkACPValidityOnChain = async (acp, publicClient) => {
437
589
  const aclAddress = await getAclAddress(publicClient);
438
590
  try {
@@ -440,43 +592,54 @@ var checkACPValidityOnChain = async (acp, publicClient) => {
440
592
  address: aclAddress,
441
593
  abi: checkACPValidityAbi,
442
594
  functionName: "checkPermissionValidity",
443
- args: [
444
- {
445
- issuer: acp.issuer,
446
- expiration: BigInt(acp.expiration),
447
- recipient: acp.recipient,
448
- revokerData: BigInt(acp.revokerData),
449
- revokerContract: acp.revokerContract,
450
- scope: acp.scope,
451
- contracts: acp.contracts,
452
- handles: acp.handles,
453
- sealingKey: acp.sealingKey,
454
- issuerSignature: acp.issuerSignature,
455
- recipientSignature: acp.recipientSignature
456
- }
457
- ]
595
+ args: [toACPTuple(acp)]
458
596
  });
459
597
  return true;
460
598
  } catch (err) {
461
- if (err instanceof viem.BaseError) {
462
- const revertError = err.walk((err2) => err2 instanceof viem.ContractFunctionRevertedError);
463
- if (revertError instanceof viem.ContractFunctionRevertedError) {
464
- const errorName = revertError.data?.errorName ?? "";
465
- throw new Error(errorName);
466
- }
467
- }
468
- const customErrorName = extractCustomErrorFromDetails(err, checkACPValidityAbi);
469
- if (customErrorName) {
470
- throw new Error(customErrorName);
471
- }
472
- const hhDetailsData = extractReturnData(err);
473
- if (hhDetailsData != null) {
474
- const decoded = viem.decodeErrorResult({
475
- abi: checkACPValidityAbi,
476
- data: hhDetailsData
599
+ const errorName = revertErrorName(err, checkACPValidityAbi);
600
+ if (errorName !== void 0)
601
+ throw new Error(errorName);
602
+ throw err;
603
+ }
604
+ };
605
+ var PERMISSION_ERROR_STATUS = {
606
+ PermissionInvalid_Expired: "expired",
607
+ PermissionInvalid_Disabled: "revoked",
608
+ PermissionInvalid_IssuerSignature: "invalid-issuer-signature",
609
+ PermissionInvalid_RecipientSignature: "invalid-recipient-signature"
610
+ };
611
+ var getACPAccessStatusOnChain = async (acp, publicClient, handle) => {
612
+ const aclAddress = await getAclAddress(publicClient);
613
+ try {
614
+ if (handle === void 0) {
615
+ await publicClient.simulateContract({
616
+ address: aclAddress,
617
+ abi: acpAccessAbi,
618
+ functionName: "checkPermissionValidity",
619
+ args: [toACPTuple(acp)]
477
620
  });
478
- throw new Error(decoded.errorName);
621
+ return "valid";
479
622
  }
623
+ const ctHash = BigInt(handle);
624
+ const allowed = await publicClient.readContract({
625
+ address: aclAddress,
626
+ abi: acpAccessAbi,
627
+ functionName: "isAllowedWithPermission",
628
+ args: [toACPTuple(acp), ctHash]
629
+ });
630
+ if (allowed)
631
+ return "allowed";
632
+ const issuerAllowed = await publicClient.readContract({
633
+ address: aclAddress,
634
+ abi: acpAccessAbi,
635
+ functionName: "isAllowed",
636
+ args: [ctHash, acp.issuer]
637
+ });
638
+ return issuerAllowed ? "out-of-scope" : "issuer-not-allowed";
639
+ } catch (err) {
640
+ const status = PERMISSION_ERROR_STATUS[revertErrorName(err, acpAccessAbi) ?? ""];
641
+ if (status)
642
+ return status;
480
643
  throw err;
481
644
  }
482
645
  };
@@ -498,7 +661,8 @@ function extractCustomErrorFromDetails(err, abi) {
498
661
  function extractReturnData(err) {
499
662
  const anyErr = err;
500
663
  const s = anyErr?.details ?? anyErr?.cause?.details ?? anyErr?.shortMessage ?? anyErr?.message ?? String(err);
501
- return s.match(/return data:\s*(0x[a-fA-F0-9]+)/)?.[1];
664
+ const match = s.match(/return data:\s*(0x[a-fA-F0-9]+)/) ?? s.match(/custom error (0x[a-fA-F0-9]{8,})/);
665
+ return match?.[1];
502
666
  }
503
667
  var checkACPValidityAbi = [
504
668
  {
@@ -598,6 +762,58 @@ var checkACPValidityAbi = [
598
762
  inputs: []
599
763
  }
600
764
  ];
765
+ var acpAccessAbi = [
766
+ ...checkACPValidityAbi,
767
+ {
768
+ type: "function",
769
+ name: "isAllowedWithPermission",
770
+ inputs: [checkACPValidityAbi[0].inputs[0], { name: "handle", type: "uint256", internalType: "uint256" }],
771
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
772
+ stateMutability: "view"
773
+ },
774
+ {
775
+ type: "function",
776
+ name: "isAllowed",
777
+ inputs: [
778
+ { name: "handle", type: "uint256", internalType: "uint256" },
779
+ { name: "account", type: "address", internalType: "address" }
780
+ ],
781
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
782
+ stateMutability: "view"
783
+ }
784
+ ];
785
+ var ACL_SERVED_ADDRESSES_ABI = viem.parseAbi([
786
+ "function acl() view returns (address)",
787
+ "function defaultRevokerContract() view returns (address)",
788
+ "function shareRegistry() view returns (address)"
789
+ ]);
790
+ var aclServedAddressesCache = /* @__PURE__ */ new Map();
791
+ var clearAclServedAddresses = () => aclServedAddressesCache.clear();
792
+ var getAclServedAddresses = async (publicClient, chainId) => {
793
+ const cached = aclServedAddressesCache.get(chainId);
794
+ if (cached != null)
795
+ return cached;
796
+ let aclAddress;
797
+ try {
798
+ aclAddress = await publicClient.readContract({
799
+ address: await getTaskManagerAddress(publicClient, chainId),
800
+ abi: ACL_SERVED_ADDRESSES_ABI,
801
+ functionName: "acl"
802
+ });
803
+ } catch {
804
+ return {};
805
+ }
806
+ const [defaultRevoker, shareRegistry] = await Promise.all([
807
+ publicClient.readContract({ address: aclAddress, abi: ACL_SERVED_ADDRESSES_ABI, functionName: "defaultRevokerContract" }).catch(() => void 0),
808
+ publicClient.readContract({ address: aclAddress, abi: ACL_SERVED_ADDRESSES_ABI, functionName: "shareRegistry" }).catch(() => void 0)
809
+ ]);
810
+ const resolved = {
811
+ defaultRevoker: defaultRevoker != null && defaultRevoker !== viem.zeroAddress ? defaultRevoker : void 0,
812
+ shareRegistry: shareRegistry != null && shareRegistry !== viem.zeroAddress ? shareRegistry : void 0
813
+ };
814
+ aclServedAddressesCache.set(chainId, resolved);
815
+ return resolved;
816
+ };
601
817
 
602
818
  // acps/acp.ts
603
819
  var ACPUtils = {
@@ -911,8 +1127,62 @@ var ACPUtils = {
911
1127
  checkValidityOnChain: async (acp, publicClient) => {
912
1128
  const publicAcp = ACPUtils.getPublic(acp);
913
1129
  return checkACPValidityOnChain(publicAcp, publicClient);
1130
+ },
1131
+ /**
1132
+ * The acp on-chain status as a value instead of a revert: 'valid' or why not, and given a
1133
+ * handle, whether the acp may read it (see `ACPAccessStatus`).
1134
+ */
1135
+ checkAccessOnChain: async (acp, publicClient, handle) => {
1136
+ return getACPAccessStatusOnChain(ACPUtils.getPublic(acp), publicClient, handle);
1137
+ }
1138
+ };
1139
+ var ACP_REVOKER_ABI = viem.parseAbi([
1140
+ "function revokeSingle(uint256 id)",
1141
+ "function revokeAllExisting()",
1142
+ "function disabled(address issuer, uint256 id) view returns (bool)"
1143
+ ]);
1144
+ var ACP_SHARE_REGISTRY_ABI = viem.parseAbi([
1145
+ "struct ACP { address issuer; uint64 expiration; address recipient; uint256 revokerData; address revokerContract; uint8 scope; address[] contracts; bytes32[] handles; bytes32 sealingKey; bytes issuerSignature; bytes recipientSignature; }",
1146
+ "function share(ACP calldata acp) external returns (bytes32)",
1147
+ "function removeShare(bytes32 shareId) external",
1148
+ "function sharesFor(address recipient) external view returns (ACP[] memory)",
1149
+ "function getShare(bytes32 shareId) external view returns (ACP memory)",
1150
+ "function isShareValid(bytes32 shareId) external view returns (bool)"
1151
+ ]);
1152
+ var ACP_SHARE_TUPLE_ABI = [
1153
+ {
1154
+ type: "tuple",
1155
+ components: [
1156
+ { name: "issuer", type: "address" },
1157
+ { name: "expiration", type: "uint64" },
1158
+ { name: "recipient", type: "address" },
1159
+ { name: "revokerData", type: "uint256" },
1160
+ { name: "revokerContract", type: "address" },
1161
+ { name: "scope", type: "uint8" },
1162
+ { name: "contracts", type: "address[]" },
1163
+ { name: "handles", type: "bytes32[]" },
1164
+ { name: "sealingKey", type: "bytes32" },
1165
+ { name: "issuerSignature", type: "bytes" },
1166
+ { name: "recipientSignature", type: "bytes" }
1167
+ ]
914
1168
  }
1169
+ ];
1170
+ var ZERO_BYTES32 = `0x${"0".repeat(64)}`;
1171
+ var toChainShare = (acp) => {
1172
+ const pub = ACPUtils.getPublic(acp, true);
1173
+ return {
1174
+ ...pub,
1175
+ expiration: BigInt(pub.expiration),
1176
+ revokerData: BigInt(pub.revokerData),
1177
+ sealingKey: ZERO_BYTES32,
1178
+ recipientSignature: "0x"
1179
+ };
1180
+ };
1181
+ var computeShareId = (acp) => {
1182
+ const p = toChainShare(acp);
1183
+ return viem.keccak256(viem.encodeAbiParameters(ACP_SHARE_TUPLE_ABI, [p]));
915
1184
  };
1185
+ var shareIdOfChainShare = (share) => viem.keccak256(viem.encodeAbiParameters(ACP_SHARE_TUPLE_ABI, [share]));
916
1186
  var ACP_STORE_DEFAULTS = {
917
1187
  acps: {},
918
1188
  activeACPHash: {}
@@ -1041,6 +1311,9 @@ var acpStore = {
1041
1311
 
1042
1312
  exports.ACPScope = ACPScope;
1043
1313
  exports.ACPUtils = ACPUtils;
1314
+ exports.ACP_REVOKER_ABI = ACP_REVOKER_ABI;
1315
+ exports.ACP_SHARE_REGISTRY_ABI = ACP_SHARE_REGISTRY_ABI;
1316
+ exports.ACP_SHARE_TUPLE_ABI = ACP_SHARE_TUPLE_ABI;
1044
1317
  exports.ACP_STORE_DEFAULTS = ACP_STORE_DEFAULTS;
1045
1318
  exports.GenerateSealingKey = GenerateSealingKey;
1046
1319
  exports.ImportACPOptionsValidator = ImportACPOptionsValidator;
@@ -1058,10 +1331,14 @@ exports.addressNotZeroSchema = addressNotZeroSchema;
1058
1331
  exports.addressSchema = addressSchema;
1059
1332
  exports.bytesNotEmptySchema = bytesNotEmptySchema;
1060
1333
  exports.bytesSchema = bytesSchema;
1334
+ exports.clearAclServedAddresses = clearAclServedAddresses;
1061
1335
  exports.clearStaleStore = clearStaleStore;
1336
+ exports.computeShareId = computeShareId;
1062
1337
  exports.contractsSchema = contractsSchema;
1063
1338
  exports.getACP = getACP;
1064
1339
  exports.getACPs = getACPs;
1340
+ exports.getAclAddress = getAclAddress;
1341
+ exports.getAclServedAddresses = getAclServedAddresses;
1065
1342
  exports.getActiveACP = getActiveACP;
1066
1343
  exports.getActiveACPHash = getActiveACPHash;
1067
1344
  exports.getSignatureTypesAndMessage = getSignatureTypesAndMessage;
@@ -1072,6 +1349,8 @@ exports.resetStore = resetStore;
1072
1349
  exports.seal = seal;
1073
1350
  exports.setACP = setACP;
1074
1351
  exports.setActiveACPHash = setActiveACPHash;
1352
+ exports.shareIdOfChainShare = shareIdOfChainShare;
1353
+ exports.toChainShare = toChainShare;
1075
1354
  exports.unsealWithPrivateKey = unsealWithPrivateKey;
1076
1355
  exports.validateImportACP = validateImportACP;
1077
1356
  exports.validateImportACPOptions = validateImportACPOptions;
package/dist/acps.d.cts CHANGED
@@ -1,9 +1,256 @@
1
- import { A as ACP, V as ValidationResult, a as ACPPublic, b as ACPSignaturePrimaryType, E as EIP712Types, c as EIP712Message, S as SerializedACP } from './acp-Wi6isVQI.cjs';
2
- export { v as ACPHashFields, e as ACPMetadata, o as ACPOf, m as ACPPrivate, r as ACPScope, t as ACPScopeOptions, n as ACPType, i as ACPUtils, C as CreateSelfACPOptions, d as CreateSharingACPOptions, h as EIP712Domain, l as EIP712Type, k as EthEncryptedData, w as Expand, G as GenerateSealingKey, I as ImportACPOptions, I as ImportSharedACPOptions, g as IncomingShare, R as RecipientACP, j as SealingKeyPair, p as SelfACP, C as SelfACPOptions, f as SharedACP, q as SharingACP, d as SharingACPOptions, s as seal, u as unsealWithPrivateKey } from './acp-Wi6isVQI.cjs';
1
+ import { A as ACP, V as ValidationResult, a as ACPPublic, b as ACPSignaturePrimaryType, E as EIP712Types, c as EIP712Message, S as SerializedACP } from './onchain-utils-CUAK8glx.cjs';
2
+ export { z as ACPAccessStatus, B as ACPHashFields, e as ACPMetadata, t as ACPOf, q as ACPPrivate, x as ACPScope, y as ACPScopeOptions, r as ACPType, i as ACPUtils, m as AclServedAddresses, C as CreateSelfACPOptions, d as CreateSharingACPOptions, h as EIP712Domain, p as EIP712Type, o as EthEncryptedData, D as Expand, G as GenerateSealingKey, I as ImportACPOptions, I as ImportSharedACPOptions, g as IncomingShare, R as RecipientACP, n as SealingKeyPair, v as SelfACP, C as SelfACPOptions, f as SharedACP, w as SharingACP, d as SharingACPOptions, l as clearAclServedAddresses, j as getAclAddress, k as getAclServedAddresses, s as seal, u as unsealWithPrivateKey } from './onchain-utils-CUAK8glx.cjs';
3
+ import { Hex, AbiParameterToPrimitiveType } from 'viem';
3
4
  import { z } from 'zod';
4
5
  import * as zustand_middleware from 'zustand/middleware';
5
6
  import * as zustand_vanilla from 'zustand/vanilla';
6
- import 'viem';
7
+
8
+ /**
9
+ * The on-chain sharing pieces: the share registry and revoker ABIs, the registry payload of a
10
+ * sharing ACP and its share id. Exported so an app can send these writes through its own
11
+ * transaction path and still agree with the registry on ids.
12
+ */
13
+ declare const ACP_REVOKER_ABI: readonly [{
14
+ readonly name: "revokeSingle";
15
+ readonly type: "function";
16
+ readonly stateMutability: "nonpayable";
17
+ readonly inputs: readonly [{
18
+ readonly type: "uint256";
19
+ readonly name: "id";
20
+ }];
21
+ readonly outputs: readonly [];
22
+ }, {
23
+ readonly name: "revokeAllExisting";
24
+ readonly type: "function";
25
+ readonly stateMutability: "nonpayable";
26
+ readonly inputs: readonly [];
27
+ readonly outputs: readonly [];
28
+ }, {
29
+ readonly name: "disabled";
30
+ readonly type: "function";
31
+ readonly stateMutability: "view";
32
+ readonly inputs: readonly [{
33
+ readonly type: "address";
34
+ readonly name: "issuer";
35
+ }, {
36
+ readonly type: "uint256";
37
+ readonly name: "id";
38
+ }];
39
+ readonly outputs: readonly [{
40
+ readonly type: "bool";
41
+ }];
42
+ }];
43
+ declare const ACP_SHARE_REGISTRY_ABI: readonly [{
44
+ readonly name: "share";
45
+ readonly type: "function";
46
+ readonly stateMutability: "nonpayable";
47
+ readonly inputs: readonly [{
48
+ readonly type: "tuple";
49
+ readonly components: readonly [{
50
+ readonly type: "address";
51
+ readonly name: "issuer";
52
+ }, {
53
+ readonly type: "uint64";
54
+ readonly name: "expiration";
55
+ }, {
56
+ readonly type: "address";
57
+ readonly name: "recipient";
58
+ }, {
59
+ readonly type: "uint256";
60
+ readonly name: "revokerData";
61
+ }, {
62
+ readonly type: "address";
63
+ readonly name: "revokerContract";
64
+ }, {
65
+ readonly type: "uint8";
66
+ readonly name: "scope";
67
+ }, {
68
+ readonly type: "address[]";
69
+ readonly name: "contracts";
70
+ }, {
71
+ readonly type: "bytes32[]";
72
+ readonly name: "handles";
73
+ }, {
74
+ readonly type: "bytes32";
75
+ readonly name: "sealingKey";
76
+ }, {
77
+ readonly type: "bytes";
78
+ readonly name: "issuerSignature";
79
+ }, {
80
+ readonly type: "bytes";
81
+ readonly name: "recipientSignature";
82
+ }];
83
+ readonly name: "acp";
84
+ }];
85
+ readonly outputs: readonly [{
86
+ readonly type: "bytes32";
87
+ }];
88
+ }, {
89
+ readonly name: "removeShare";
90
+ readonly type: "function";
91
+ readonly stateMutability: "nonpayable";
92
+ readonly inputs: readonly [{
93
+ readonly type: "bytes32";
94
+ readonly name: "shareId";
95
+ }];
96
+ readonly outputs: readonly [];
97
+ }, {
98
+ readonly name: "sharesFor";
99
+ readonly type: "function";
100
+ readonly stateMutability: "view";
101
+ readonly inputs: readonly [{
102
+ readonly type: "address";
103
+ readonly name: "recipient";
104
+ }];
105
+ readonly outputs: readonly [{
106
+ readonly type: "tuple[]";
107
+ readonly components: readonly [{
108
+ readonly type: "address";
109
+ readonly name: "issuer";
110
+ }, {
111
+ readonly type: "uint64";
112
+ readonly name: "expiration";
113
+ }, {
114
+ readonly type: "address";
115
+ readonly name: "recipient";
116
+ }, {
117
+ readonly type: "uint256";
118
+ readonly name: "revokerData";
119
+ }, {
120
+ readonly type: "address";
121
+ readonly name: "revokerContract";
122
+ }, {
123
+ readonly type: "uint8";
124
+ readonly name: "scope";
125
+ }, {
126
+ readonly type: "address[]";
127
+ readonly name: "contracts";
128
+ }, {
129
+ readonly type: "bytes32[]";
130
+ readonly name: "handles";
131
+ }, {
132
+ readonly type: "bytes32";
133
+ readonly name: "sealingKey";
134
+ }, {
135
+ readonly type: "bytes";
136
+ readonly name: "issuerSignature";
137
+ }, {
138
+ readonly type: "bytes";
139
+ readonly name: "recipientSignature";
140
+ }];
141
+ }];
142
+ }, {
143
+ readonly name: "getShare";
144
+ readonly type: "function";
145
+ readonly stateMutability: "view";
146
+ readonly inputs: readonly [{
147
+ readonly type: "bytes32";
148
+ readonly name: "shareId";
149
+ }];
150
+ readonly outputs: readonly [{
151
+ readonly type: "tuple";
152
+ readonly components: readonly [{
153
+ readonly type: "address";
154
+ readonly name: "issuer";
155
+ }, {
156
+ readonly type: "uint64";
157
+ readonly name: "expiration";
158
+ }, {
159
+ readonly type: "address";
160
+ readonly name: "recipient";
161
+ }, {
162
+ readonly type: "uint256";
163
+ readonly name: "revokerData";
164
+ }, {
165
+ readonly type: "address";
166
+ readonly name: "revokerContract";
167
+ }, {
168
+ readonly type: "uint8";
169
+ readonly name: "scope";
170
+ }, {
171
+ readonly type: "address[]";
172
+ readonly name: "contracts";
173
+ }, {
174
+ readonly type: "bytes32[]";
175
+ readonly name: "handles";
176
+ }, {
177
+ readonly type: "bytes32";
178
+ readonly name: "sealingKey";
179
+ }, {
180
+ readonly type: "bytes";
181
+ readonly name: "issuerSignature";
182
+ }, {
183
+ readonly type: "bytes";
184
+ readonly name: "recipientSignature";
185
+ }];
186
+ }];
187
+ }, {
188
+ readonly name: "isShareValid";
189
+ readonly type: "function";
190
+ readonly stateMutability: "view";
191
+ readonly inputs: readonly [{
192
+ readonly type: "bytes32";
193
+ readonly name: "shareId";
194
+ }];
195
+ readonly outputs: readonly [{
196
+ readonly type: "bool";
197
+ }];
198
+ }];
199
+ declare const ACP_SHARE_TUPLE_ABI: readonly [{
200
+ readonly type: "tuple";
201
+ readonly components: readonly [{
202
+ readonly name: "issuer";
203
+ readonly type: "address";
204
+ }, {
205
+ readonly name: "expiration";
206
+ readonly type: "uint64";
207
+ }, {
208
+ readonly name: "recipient";
209
+ readonly type: "address";
210
+ }, {
211
+ readonly name: "revokerData";
212
+ readonly type: "uint256";
213
+ }, {
214
+ readonly name: "revokerContract";
215
+ readonly type: "address";
216
+ }, {
217
+ readonly name: "scope";
218
+ readonly type: "uint8";
219
+ }, {
220
+ readonly name: "contracts";
221
+ readonly type: "address[]";
222
+ }, {
223
+ readonly name: "handles";
224
+ readonly type: "bytes32[]";
225
+ }, {
226
+ readonly name: "sealingKey";
227
+ readonly type: "bytes32";
228
+ }, {
229
+ readonly name: "issuerSignature";
230
+ readonly type: "bytes";
231
+ }, {
232
+ readonly name: "recipientSignature";
233
+ readonly type: "bytes";
234
+ }];
235
+ }];
236
+ /** The on-chain payload for a sharing ACP: recipient-side fields empty. */
237
+ declare const toChainShare: (acp: ACP) => {
238
+ expiration: bigint;
239
+ revokerData: bigint;
240
+ sealingKey: `0x${string}`;
241
+ recipientSignature: Hex;
242
+ issuer: Hex;
243
+ recipient: Hex;
244
+ revokerContract: Hex;
245
+ scope: number;
246
+ contracts: Hex[];
247
+ handles: Hex[];
248
+ issuerSignature: Hex;
249
+ };
250
+ /** Mirrors the registry's `keccak256(abi.encode(acp))` share id. */
251
+ declare const computeShareId: (acp: ACP) => Hex;
252
+ /** The share id of a registry payload as read back from `sharesFor` / `getShare`. */
253
+ declare const shareIdOfChainShare: (share: AbiParameterToPrimitiveType<(typeof ACP_SHARE_TUPLE_ABI)[0]>) => Hex;
7
254
 
8
255
  declare const addressSchema: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
9
256
  declare const addressNotZeroSchema: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
@@ -477,4 +724,4 @@ declare const acpStore: {
477
724
  resetStore: () => void;
478
725
  };
479
726
 
480
- export { ACP, ACPPublic, ACPSignaturePrimaryType, ACP_STORE_DEFAULTS, EIP712Message, EIP712Types, ImportACPOptionsValidator, ImportACPValidator, SelfACPOptionsValidator, SelfACPValidator, SerializedACP, SharingACPOptionsValidator, SharingACPValidator, SignatureTypes, SignatureUtils, ValidationResult, ValidationUtils, _acpStore, acpStore, addressNotZeroSchema, addressSchema, bytesNotEmptySchema, bytesSchema, clearStaleStore, contractsSchema, getACP, getACPs, getActiveACP, getActiveACPHash, getSignatureTypesAndMessage, handlesSchema, removeACP, removeActiveACPHash, resetStore, setACP, setActiveACPHash, validateImportACP, validateImportACPOptions, validateSelfACP, validateSelfACPOptions, validateSharingACP, validateSharingACPOptions };
727
+ export { ACP, ACPPublic, ACPSignaturePrimaryType, ACP_REVOKER_ABI, ACP_SHARE_REGISTRY_ABI, ACP_SHARE_TUPLE_ABI, ACP_STORE_DEFAULTS, EIP712Message, EIP712Types, ImportACPOptionsValidator, ImportACPValidator, SelfACPOptionsValidator, SelfACPValidator, SerializedACP, SharingACPOptionsValidator, SharingACPValidator, SignatureTypes, SignatureUtils, ValidationResult, ValidationUtils, _acpStore, acpStore, addressNotZeroSchema, addressSchema, bytesNotEmptySchema, bytesSchema, clearStaleStore, computeShareId, contractsSchema, getACP, getACPs, getActiveACP, getActiveACPHash, getSignatureTypesAndMessage, handlesSchema, removeACP, removeActiveACPHash, resetStore, setACP, setActiveACPHash, shareIdOfChainShare, toChainShare, validateImportACP, validateImportACPOptions, validateSelfACP, validateSelfACPOptions, validateSharingACP, validateSharingACPOptions };