@cofhe/sdk 0.8.0 → 1.0.0-alpha.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 (84) hide show
  1. package/acps/acp.ts +25 -6
  2. package/acps/index.ts +20 -15
  3. package/acps/registry.ts +166 -8
  4. package/acps/sealing.ts +9 -3
  5. package/acps/share-metadata/appKey.ts +8 -0
  6. package/acps/share-metadata/decode.ts +120 -0
  7. package/acps/share-metadata/describe.ts +198 -0
  8. package/acps/share-metadata/encode.ts +147 -0
  9. package/acps/share-metadata/erc7984.ts +26 -0
  10. package/acps/share-metadata/index.ts +9 -0
  11. package/acps/share-metadata/layout.ts +69 -0
  12. package/acps/share-metadata/presets.ts +116 -0
  13. package/acps/share-metadata/schema.ts +47 -0
  14. package/acps/share-metadata/test/codec.test.ts +140 -0
  15. package/acps/share-metadata/test/describe.test.ts +112 -0
  16. package/acps/share-metadata/test/fixtures.ts +157 -0
  17. package/acps/share-metadata/test/live.test.ts +56 -0
  18. package/acps/share-metadata/test/presets.test.ts +119 -0
  19. package/acps/share-metadata/test/verify.test.ts +144 -0
  20. package/acps/share-metadata/verify.ts +155 -0
  21. package/acps/store.ts +48 -18
  22. package/acps/test/acp.test.ts +102 -7
  23. package/acps/test/localstorage.test.ts +28 -1
  24. package/acps/test/registry.test.ts +144 -0
  25. package/acps/test/sealing.test.ts +23 -0
  26. package/acps/test/store.test.ts +71 -0
  27. package/acps/test/utils.test.ts +63 -0
  28. package/acps/test/validation.test.ts +0 -4
  29. package/acps/types.ts +43 -6
  30. package/acps/utils.ts +15 -2
  31. package/acps/validation.ts +3 -1
  32. package/core/acps.ts +123 -74
  33. package/core/client.ts +33 -7
  34. package/core/clientTypes.ts +25 -7
  35. package/core/config.ts +8 -0
  36. package/core/decrypt/apiError.ts +4 -1
  37. package/core/decrypt/verifyDecryptResult.ts +4 -1
  38. package/core/encrypt/cofheMocksZkVerifySign.ts +19 -2
  39. package/core/test/acpDefaults.test.ts +108 -19
  40. package/core/test/acpStoreAccountCase.test.ts +80 -0
  41. package/core/test/acps.test.ts +38 -3
  42. package/core/test/apiError.test.ts +8 -0
  43. package/core/test/appKeyConfig.test.ts +94 -0
  44. package/core/test/config.test.ts +8 -0
  45. package/core/test/decryptBuilders.test.ts +110 -2
  46. package/core/test/incomingShares.test.ts +84 -0
  47. package/core/test/mocksEncryptRange.test.ts +90 -0
  48. package/core/test/utils.test.ts +128 -0
  49. package/core/test/verifyDecryptResult.test.ts +51 -0
  50. package/core/utils.ts +16 -9
  51. package/dist/acps.cjs +674 -33
  52. package/dist/acps.d.cts +367 -35
  53. package/dist/acps.d.ts +367 -35
  54. package/dist/acps.js +2 -2
  55. package/dist/chunk-6ZW76ZKB.js +228 -0
  56. package/dist/{chunk-UJYOBHYA.js → chunk-BQWHPIYU.js} +660 -198
  57. package/dist/{chunk-GGI7Y6AW.js → chunk-OL3DZN7A.js} +110 -269
  58. package/dist/chunk-XQ32JG3T.js +174 -0
  59. package/dist/{clientTypes-D3aIXmUp.d.cts → clientTypes-C0A9ji5O.d.cts} +61 -21
  60. package/dist/{clientTypes-5YPPR16m.d.ts → clientTypes-CcU5WvdV.d.ts} +61 -21
  61. package/dist/core.cjs +3239 -2731
  62. package/dist/core.d.cts +6 -3
  63. package/dist/core.d.ts +6 -3
  64. package/dist/core.js +4 -3
  65. package/dist/node.cjs +3046 -2538
  66. package/dist/node.d.cts +2 -2
  67. package/dist/node.d.ts +2 -2
  68. package/dist/node.js +18 -17
  69. package/dist/{onchain-utils-CUAK8glx.d.cts → onchain-utils-D9Z33IP7.d.cts} +136 -12
  70. package/dist/{onchain-utils-CUAK8glx.d.ts → onchain-utils-D9Z33IP7.d.ts} +136 -12
  71. package/dist/web.cjs +3074 -2573
  72. package/dist/web.d.cts +2 -2
  73. package/dist/web.d.ts +2 -2
  74. package/dist/web.js +4 -10
  75. package/dist/zkProve.worker.cjs +14 -7
  76. package/dist/zkProve.worker.js +2 -8
  77. package/node/index.ts +1 -10
  78. package/node/storage.ts +18 -7
  79. package/node/test/storage-permissions.test.ts +40 -0
  80. package/package.json +4 -4
  81. package/web/index.ts +1 -10
  82. package/web/test/threadPoolBenchHelper.ts +1 -7
  83. package/web/zkProve.worker.ts +1 -10
  84. package/dist/chunk-NMKMCAI3.js +0 -14
@@ -0,0 +1,174 @@
1
+ // core/consts.ts
2
+ var COFHE_ADDRESS_BOOK_ADDRESS = "0xC0F4e00E531a2B086492Ae3DCC1515038307196b";
3
+ var TASK_MANAGER_ID = 1n;
4
+ var MOCKS_TASK_MANAGER_ADDRESS = "0x0000000000000000000000000000000000005000";
5
+ var MOCKS_ZK_VERIFIER_ADDRESS = "0x0000000000000000000000000000000000005001";
6
+ var MOCKS_THRESHOLD_NETWORK_ADDRESS = "0x0000000000000000000000000000000000005002";
7
+ var MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY = "0x6C8D7F768A6BB4AAFE85E8A2F5A9680355239C7E14646ED62B044E39DE154512";
8
+ var MOCKS_ZK_VERIFIER_SIGNER_ADDRESS = "0x6E12D8C87503D4287c294f2Fdef96ACd9DFf6bd2";
9
+ var MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY = "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d";
10
+ var TFHE_RS_ZK_MAX_BITS = 2048;
11
+ var TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT = BigInt(1 << 30);
12
+ var TFHE_RS_KEY_VERSION = 2;
13
+
14
+ // core/error.ts
15
+ var CofheErrorCode = /* @__PURE__ */ ((CofheErrorCode2) => {
16
+ CofheErrorCode2["InternalError"] = "INTERNAL_ERROR";
17
+ CofheErrorCode2["UnknownEnvironment"] = "UNKNOWN_ENVIRONMENT";
18
+ CofheErrorCode2["InitTfheFailed"] = "INIT_TFHE_FAILED";
19
+ CofheErrorCode2["InitViemFailed"] = "INIT_VIEM_FAILED";
20
+ CofheErrorCode2["InitEthersFailed"] = "INIT_ETHERS_FAILED";
21
+ CofheErrorCode2["NotConnected"] = "NOT_CONNECTED";
22
+ CofheErrorCode2["MissingPublicClient"] = "MISSING_PUBLIC_CLIENT";
23
+ CofheErrorCode2["MissingWalletClient"] = "MISSING_WALLET_CLIENT";
24
+ CofheErrorCode2["MissingProviderParam"] = "MISSING_PROVIDER_PARAM";
25
+ CofheErrorCode2["EmptySecurityZonesParam"] = "EMPTY_SECURITY_ZONES_PARAM";
26
+ CofheErrorCode2["InvalidACPData"] = "INVALID_ACP_DATA";
27
+ CofheErrorCode2["InvalidACPDomain"] = "INVALID_ACP_DOMAIN";
28
+ CofheErrorCode2["ACPNotFound"] = "ACP_NOT_FOUND";
29
+ CofheErrorCode2["CannotRemoveLastACP"] = "CANNOT_REMOVE_LAST_ACP";
30
+ CofheErrorCode2["AccountUninitialized"] = "ACCOUNT_UNINITIALIZED";
31
+ CofheErrorCode2["ChainIdUninitialized"] = "CHAIN_ID_UNINITIALIZED";
32
+ CofheErrorCode2["ConsumingContractUninitialized"] = "CONSUMING_CONTRACT_UNINITIALIZED";
33
+ CofheErrorCode2["SealOutputFailed"] = "SEAL_OUTPUT_FAILED";
34
+ CofheErrorCode2["SealOutputReturnedNull"] = "SEAL_OUTPUT_RETURNED_NULL";
35
+ CofheErrorCode2["InvalidUtype"] = "INVALID_UTYPE";
36
+ CofheErrorCode2["DecryptFailed"] = "DECRYPT_FAILED";
37
+ CofheErrorCode2["DecryptReturnedNull"] = "DECRYPT_RETURNED_NULL";
38
+ CofheErrorCode2["ZkMocksInsertCtHashesFailed"] = "ZK_MOCKS_INSERT_CT_HASHES_FAILED";
39
+ CofheErrorCode2["ZkMocksCalcCtHashesFailed"] = "ZK_MOCKS_CALC_CT_HASHES_FAILED";
40
+ CofheErrorCode2["ZkMocksVerifySignFailed"] = "ZK_MOCKS_VERIFY_SIGN_FAILED";
41
+ CofheErrorCode2["ZkMocksCreateProofSignatureFailed"] = "ZK_MOCKS_CREATE_PROOF_SIGNATURE_FAILED";
42
+ CofheErrorCode2["ZkVerifyFailed"] = "ZK_VERIFY_FAILED";
43
+ CofheErrorCode2["ZkPackFailed"] = "ZK_PACK_FAILED";
44
+ CofheErrorCode2["ZkProveFailed"] = "ZK_PROVE_FAILED";
45
+ CofheErrorCode2["EncryptRemainingInItems"] = "ENCRYPT_REMAINING_IN_ITEMS";
46
+ CofheErrorCode2["ZkUninitialized"] = "ZK_UNINITIALIZED";
47
+ CofheErrorCode2["ZkVerifierUrlUninitialized"] = "ZK_VERIFIER_URL_UNINITIALIZED";
48
+ CofheErrorCode2["ThresholdNetworkUrlUninitialized"] = "THRESHOLD_NETWORK_URL_UNINITIALIZED";
49
+ CofheErrorCode2["MissingConfig"] = "MISSING_CONFIG";
50
+ CofheErrorCode2["UnsupportedChain"] = "UNSUPPORTED_CHAIN";
51
+ CofheErrorCode2["MissingZkBuilderAndCrsGenerator"] = "MISSING_ZK_BUILDER_AND_CRS_GENERATOR";
52
+ CofheErrorCode2["MissingTfhePublicKeyDeserializer"] = "MISSING_TFHE_PUBLIC_KEY_DESERIALIZER";
53
+ CofheErrorCode2["MissingCompactPkeCrsDeserializer"] = "MISSING_COMPACT_PKE_CRS_DESERIALIZER";
54
+ CofheErrorCode2["MissingFheKey"] = "MISSING_FHE_KEY";
55
+ CofheErrorCode2["MissingCrs"] = "MISSING_CRS";
56
+ CofheErrorCode2["FetchKeysFailed"] = "FETCH_KEYS_FAILED";
57
+ CofheErrorCode2["PublicWalletGetChainIdFailed"] = "PUBLIC_WALLET_GET_CHAIN_ID_FAILED";
58
+ CofheErrorCode2["PublicWalletGetAddressesFailed"] = "PUBLIC_WALLET_GET_ADDRESSES_FAILED";
59
+ CofheErrorCode2["RehydrateKeysStoreFailed"] = "REHYDRATE_KEYS_STORE_FAILED";
60
+ CofheErrorCode2["TaskManagerUnresolved"] = "TASK_MANAGER_UNRESOLVED";
61
+ CofheErrorCode2["BadRequest"] = "BAD_REQUEST";
62
+ CofheErrorCode2["UnknownChain"] = "UNKNOWN_CHAIN";
63
+ CofheErrorCode2["ACPMalformed"] = "ACP_MALFORMED";
64
+ CofheErrorCode2["ACPDenied"] = "ACP_DENIED";
65
+ CofheErrorCode2["ACPExpired"] = "ACP_EXPIRED";
66
+ CofheErrorCode2["ACPInvalid"] = "ACP_INVALID";
67
+ CofheErrorCode2["ACPRevoked"] = "ACP_REVOKED";
68
+ CofheErrorCode2["NotPubliclyAllowed"] = "NOT_PUBLICLY_ALLOWED";
69
+ CofheErrorCode2["CtNotFound"] = "CT_NOT_FOUND";
70
+ CofheErrorCode2["UnsupportedSecurityZone"] = "UNSUPPORTED_SECURITY_ZONE";
71
+ CofheErrorCode2["UnsupportedType"] = "UNSUPPORTED_TYPE";
72
+ CofheErrorCode2["SigningFailed"] = "SIGNING_FAILED";
73
+ CofheErrorCode2["CtSourceError"] = "CT_SOURCE_ERROR";
74
+ CofheErrorCode2["ACPVerifierError"] = "ACP_VERIFIER_ERROR";
75
+ CofheErrorCode2["CtSourceTimeout"] = "CT_SOURCE_TIMEOUT";
76
+ CofheErrorCode2["ACPVerifierTimeout"] = "ACP_VERIFIER_TIMEOUT";
77
+ CofheErrorCode2["ACPRequired"] = "ACP_REQUIRED";
78
+ CofheErrorCode2["SealFailed"] = "SEAL_FAILED";
79
+ return CofheErrorCode2;
80
+ })(CofheErrorCode || {});
81
+ var CofheError = class _CofheError extends Error {
82
+ code;
83
+ cause;
84
+ hint;
85
+ context;
86
+ apiErrorCode;
87
+ constructor({ code, message, cause, hint, context, apiErrorCode }) {
88
+ const fullMessage = cause ? `${message} | Caused by: ${cause.message}` : message;
89
+ super(fullMessage);
90
+ this.name = "CofheError";
91
+ this.code = code;
92
+ this.cause = cause;
93
+ this.hint = hint;
94
+ this.context = context;
95
+ this.apiErrorCode = apiErrorCode;
96
+ if (Error.captureStackTrace) {
97
+ Error.captureStackTrace(this, _CofheError);
98
+ }
99
+ }
100
+ /**
101
+ * Creates a CofheError from an unknown error
102
+ * If the error is a CofheError, it is returned unchanged, else a new CofheError is created
103
+ * If a wrapperError is provided, it is used to create the new CofheError, else a default is used
104
+ */
105
+ static fromError(error, wrapperError) {
106
+ if (isCofheError(error))
107
+ return error;
108
+ const cause = error instanceof Error ? error : new Error(`${error}`);
109
+ return new _CofheError({
110
+ code: wrapperError?.code ?? "INTERNAL_ERROR" /* InternalError */,
111
+ message: wrapperError?.message ?? "An internal error occurred",
112
+ hint: wrapperError?.hint,
113
+ context: wrapperError?.context,
114
+ apiErrorCode: wrapperError?.apiErrorCode,
115
+ cause
116
+ });
117
+ }
118
+ /**
119
+ * Serializes the error to JSON string with proper handling of Error objects
120
+ */
121
+ serialize() {
122
+ return bigintSafeJsonStringify({
123
+ name: this.name,
124
+ code: this.code,
125
+ message: this.message,
126
+ hint: this.hint,
127
+ context: this.context,
128
+ apiErrorCode: this.apiErrorCode,
129
+ cause: this.cause ? {
130
+ name: this.cause.name,
131
+ message: this.cause.message,
132
+ stack: this.cause.stack
133
+ } : void 0,
134
+ stack: this.stack
135
+ });
136
+ }
137
+ /**
138
+ * Returns a human-readable string representation of the error
139
+ */
140
+ toString() {
141
+ const codeSuffix = this.apiErrorCode ? ` (api: ${this.apiErrorCode})` : "";
142
+ const parts = [`${this.name} [${this.code}]${codeSuffix}: ${this.message}`];
143
+ if (this.hint) {
144
+ parts.push(`Hint: ${this.hint}`);
145
+ }
146
+ if (this.context && Object.keys(this.context).length > 0) {
147
+ parts.push(`Context: ${bigintSafeJsonStringify(this.context)}`);
148
+ }
149
+ if (this.stack) {
150
+ parts.push(`
151
+ Stack trace:`);
152
+ parts.push(this.stack);
153
+ }
154
+ if (this.cause) {
155
+ parts.push(`
156
+ Caused by: ${this.cause.name}: ${this.cause.message}`);
157
+ if (this.cause.stack) {
158
+ parts.push(this.cause.stack);
159
+ }
160
+ }
161
+ return parts.join("\n");
162
+ }
163
+ };
164
+ var bigintSafeJsonStringify = (value) => {
165
+ return JSON.stringify(value, (key, value2) => {
166
+ if (typeof value2 === "bigint") {
167
+ return `${value2}n`;
168
+ }
169
+ return value2;
170
+ });
171
+ };
172
+ var isCofheError = (error) => error instanceof CofheError;
173
+
174
+ export { COFHE_ADDRESS_BOOK_ADDRESS, CofheError, CofheErrorCode, MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY, MOCKS_TASK_MANAGER_ADDRESS, MOCKS_THRESHOLD_NETWORK_ADDRESS, MOCKS_ZK_VERIFIER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY, TASK_MANAGER_ID, TFHE_RS_KEY_VERSION, TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT, TFHE_RS_ZK_MAX_BITS, isCofheError };
@@ -1,7 +1,7 @@
1
1
  import { WalletClient, PublicClient, Hex } from 'viem';
2
2
  import { C as CofheChain } from './types-C07FK-cL.cjs';
3
3
  import { z } from 'zod';
4
- import { A as ACP, h as EIP712Domain, C as CreateSelfACPOptions, v as SelfACP, d as CreateSharingACPOptions, w as SharingACP, I as ImportSharedACPOptions, R as RecipientACP, B as ACPHashFields, S as SerializedACP, z as ACPAccessStatus, g as IncomingShare, m as AclServedAddresses, i as ACPUtils } from './onchain-utils-CUAK8glx.cjs';
4
+ import { A as ACP, k as EIP712Domain, C as CreateSelfACPOptions, J as SelfACP, g as CreateSharingACPOptions, K as SharingACP, I as ImportSharedACPOptions, R as RecipientACP, P as ACPHashFields, f as SerializedACP, O as ACPAccessStatus, S as ShareLabel, j as IncomingShare, p as AclServedAddresses, L as LabelledShare, w as ShareLabelVerifyMode, x as ShareLabelCheck, l as ACPUtils } from './onchain-utils-D9Z33IP7.cjs';
5
5
  import { StoreApi } from 'zustand/vanilla';
6
6
 
7
7
  type TfheInitializer = () => Promise<boolean>;
@@ -280,6 +280,13 @@ type CofheConfig = {
280
280
  * names a registry.
281
281
  */
282
282
  sharingRegistry?: Record<number, `0x${string}`>;
283
+ /**
284
+ * The name of this app, e.g. 'explorer.fhenix.io'. Set, every share the client creates
285
+ * carries the app's key (`shareAppKey(app)`, kept in the share metadata), and
286
+ * `getIncomingShares` lists only the shares posted for this app. Unset, shares carry no
287
+ * key and every importable share is listed.
288
+ */
289
+ app?: string;
283
290
  };
284
291
  /** Mocks configs */
285
292
  mocks: {
@@ -341,6 +348,7 @@ declare const CofheConfigSchema: z.ZodObject<{
341
348
  defaultRevoker: z.ZodOptional<z.ZodCustom<Record<number, `0x${string}`>, Record<number, `0x${string}`>>>;
342
349
  defaultContractScopes: z.ZodOptional<z.ZodCustom<Record<number, `0x${string}`[]>, Record<number, `0x${string}`[]>>>;
343
350
  sharingRegistry: z.ZodOptional<z.ZodCustom<Record<number, `0x${string}`>, Record<number, `0x${string}`>>>;
351
+ app: z.ZodOptional<z.ZodString>;
344
352
  }, z.core.$strip>>>;
345
353
  mocks: z.ZodDefault<z.ZodOptional<z.ZodObject<{
346
354
  decryptDelay: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
@@ -1015,6 +1023,25 @@ type ImportActivationOptions = {
1015
1023
  */
1016
1024
  activate?: boolean;
1017
1025
  };
1026
+ /** Options for importing a shared acp: activation, and the recipient's own name for it. */
1027
+ type ImportSharedOptions = ImportActivationOptions & {
1028
+ /**
1029
+ * The name of the imported acp. Defaults to "Shared by 0x1234…abcd" (its issuer); the issuer's
1030
+ * own name for the share is not exported and is ignored if present.
1031
+ */
1032
+ name?: string;
1033
+ };
1034
+ /**
1035
+ * What `shareOnChain` posts with a share: the labels of its handles (one per handle, in order;
1036
+ * encoded with `encodeShareMetadata`), or an already encoded metadata blob. Written once, with the
1037
+ * share. Omitted, the labels the acp was created with are posted (`createSharing({ labels })`),
1038
+ * or none. `appKey` goes with given labels; a client configured with `acp: { app }` fills it in.
1039
+ */
1040
+ type ShareOnChainOptions = {
1041
+ labels?: readonly ShareLabel[];
1042
+ metadata?: Hex;
1043
+ appKey?: Hex;
1044
+ };
1018
1045
  declare const acps: {
1019
1046
  getSnapshot: () => {
1020
1047
  acps: {
@@ -1025,6 +1052,7 @@ declare const acps: {
1025
1052
  name: string;
1026
1053
  type: "self" | "sharing" | "recipient";
1027
1054
  sealingPrivateKey: Hex;
1055
+ metadata?: Hex | undefined;
1028
1056
  _signedDomain?: EIP712Domain | undefined;
1029
1057
  issuer: Hex;
1030
1058
  expiration: number;
@@ -1056,6 +1084,7 @@ declare const acps: {
1056
1084
  name: string;
1057
1085
  type: "self" | "sharing" | "recipient";
1058
1086
  sealingPrivateKey: Hex;
1087
+ metadata?: Hex | undefined;
1059
1088
  _signedDomain?: EIP712Domain | undefined;
1060
1089
  issuer: Hex;
1061
1090
  expiration: number;
@@ -1086,6 +1115,7 @@ declare const acps: {
1086
1115
  name: string;
1087
1116
  type: "self" | "sharing" | "recipient";
1088
1117
  sealingPrivateKey: Hex;
1118
+ metadata?: Hex | undefined;
1089
1119
  _signedDomain?: EIP712Domain | undefined;
1090
1120
  issuer: Hex;
1091
1121
  expiration: number;
@@ -1110,7 +1140,7 @@ declare const acps: {
1110
1140
  }) => void) => () => void;
1111
1141
  createSelf: (options: CreateSelfACPOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SelfACP>;
1112
1142
  createSharing: (options: CreateSharingACPOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SharingACP>;
1113
- importShared: (options: ImportSharedACPOptions | string, publicClient: PublicClient, walletClient: WalletClient, { activate }?: ImportActivationOptions) => Promise<RecipientACP>;
1143
+ importShared: (options: ImportSharedACPOptions | string, publicClient: PublicClient, walletClient: WalletClient, { activate, name }?: ImportSharedOptions) => Promise<RecipientACP>;
1114
1144
  getOrCreateSelfACP: (publicClient: PublicClient, walletClient: WalletClient, chainId?: number, account?: string, options?: CreateSelfACPOptions) => Promise<ACP>;
1115
1145
  getOrCreateSharingACP: (publicClient: PublicClient, walletClient: WalletClient, options: CreateSharingACPOptions, chainId?: number, account?: string) => Promise<ACP>;
1116
1146
  getHash: (acp: ACPHashFields) => string;
@@ -1120,6 +1150,7 @@ declare const acps: {
1120
1150
  name: string;
1121
1151
  type: "self" | "sharing" | "recipient";
1122
1152
  sealingPrivateKey: Hex;
1153
+ metadata?: Hex | undefined;
1123
1154
  _signedDomain?: EIP712Domain | undefined;
1124
1155
  issuer: Hex;
1125
1156
  expiration: number;
@@ -1138,6 +1169,7 @@ declare const acps: {
1138
1169
  name: string;
1139
1170
  type: "self" | "sharing" | "recipient";
1140
1171
  sealingPrivateKey: Hex;
1172
+ metadata?: Hex | undefined;
1141
1173
  _signedDomain?: EIP712Domain | undefined;
1142
1174
  issuer: Hex;
1143
1175
  expiration: number;
@@ -1162,24 +1194,17 @@ declare const acps: {
1162
1194
  revokeAllACPs: (walletClient: WalletClient, publicClient: PublicClient, revokerContract?: Hex) => Promise<Hex>;
1163
1195
  isACPRevoked: (acp: ACP, publicClient: PublicClient) => Promise<boolean>;
1164
1196
  checkAccess: (acp: ACP, publicClient: PublicClient, handle?: bigint | Hex) => Promise<ACPAccessStatus>;
1165
- shareOnChain: (acp: ACP, walletClient: WalletClient, registry: Hex) => Promise<{
1197
+ shareOnChain: (acp: ACP, walletClient: WalletClient, registry: Hex, options?: ShareOnChainOptions) => Promise<{
1166
1198
  txHash: Hex;
1167
1199
  shareId: Hex;
1168
1200
  }>;
1169
- getIncomingShares: (publicClient: PublicClient, registry: Hex, recipient: Hex) => Promise<IncomingShare[]>;
1170
- importFromChain: (share: IncomingShare, publicClient: PublicClient, walletClient: WalletClient, importOptions?: ImportActivationOptions) => Promise<RecipientACP>;
1201
+ getIncomingShares: (publicClient: PublicClient, registry: Hex, recipient: Hex, { appKey }?: {
1202
+ appKey?: Hex;
1203
+ }) => Promise<IncomingShare[]>;
1204
+ getShareFromChain: (publicClient: PublicClient, registry: Hex, shareId: Hex) => Promise<IncomingShare | null>;
1205
+ importFromChain: (share: IncomingShare, publicClient: PublicClient, walletClient: WalletClient, importOptions?: ImportSharedOptions) => Promise<RecipientACP>;
1171
1206
  removeShareOnChain: (shareId: Hex, walletClient: WalletClient, registry: Hex) => Promise<Hex>;
1172
1207
  computeShareId: (acp: ACP) => Hex;
1173
- applyACPDefaults: <T extends {
1174
- revokerData?: number;
1175
- revokerContract?: string;
1176
- scope?: number;
1177
- contracts?: string[];
1178
- handles?: (bigint | number | string)[];
1179
- }>(options: T, acpConfig: {
1180
- defaultRevoker?: Record<number, Hex>;
1181
- defaultContractScopes?: Record<number, Hex[]>;
1182
- } | undefined, chainId: number) => T;
1183
1208
  applyACPDefaultsFromChain: <T extends {
1184
1209
  revokerData?: number;
1185
1210
  revokerContract?: string;
@@ -1238,9 +1263,10 @@ type CofheClientACPsClients = {
1238
1263
  };
1239
1264
  /**
1240
1265
  * Options for `importShared`. `activate: false` stores the imported acp without making it the active
1241
- * one (default `true`). Clients default to the connected ones; pass both to override.
1266
+ * one (default `true`). `name` names it (default "Shared by 0x1234…abcd"). Clients default to the
1267
+ * connected ones; pass both to override.
1242
1268
  */
1243
- type CofheClientImportSharedOptions = ImportActivationOptions & (CofheClientACPsClients | {
1269
+ type CofheClientImportSharedOptions = ImportSharedOptions & (CofheClientACPsClients | {
1244
1270
  publicClient?: undefined;
1245
1271
  walletClient?: undefined;
1246
1272
  });
@@ -1269,15 +1295,29 @@ type CofheClientACPs = {
1269
1295
  * 'sharing', no recipient signature yet) the handle-less check covers expiry and revocation only.
1270
1296
  */
1271
1297
  checkAccess: (acp: ACP, handle?: bigint | `0x${string}`) => Promise<ACPAccessStatus>;
1272
- /** Post a signed sharing ACP to the on-chain share registry (ACL-served, or config `acp.sharingRegistry`). */
1273
- shareOnChain: (acp: ACP) => Promise<{
1298
+ /**
1299
+ * Post a signed sharing ACP to the on-chain share registry (ACL-served, or config `acp.sharingRegistry`),
1300
+ * optionally with the labels of its handles (`options.labels`, one per handle) or an encoded blob.
1301
+ */
1302
+ shareOnChain: (acp: ACP, options?: ShareOnChainOptions) => Promise<{
1274
1303
  txHash: `0x${string}`;
1275
1304
  shareId: `0x${string}`;
1276
1305
  }>;
1277
- /** Importable shares addressed to the connected account (unexpired, not revoked). */
1306
+ /** Importable shares addressed to the connected account (unexpired, not revoked), with their metadata. */
1278
1307
  getIncomingShares: () => Promise<IncomingShare[]>;
1308
+ /** One share by id, as posted; null when unknown or removed. */
1309
+ getShareFromChain: (shareId: `0x${string}`) => Promise<IncomingShare | null>;
1310
+ /**
1311
+ * Check a share's labels against the chain, index for index with its handles, as far as
1312
+ * `verify` says (default 'all'). Takes a share read from the registry or an acp imported from
1313
+ * exported JSON (or the issuer's sharing acp). Null for a share without metadata. Throws on a
1314
+ * malformed blob.
1315
+ */
1316
+ verifyShareLabels: (share: LabelledShare, options?: {
1317
+ verify?: ShareLabelVerifyMode;
1318
+ }) => Promise<ShareLabelCheck[] | null>;
1279
1319
  /** Import a share read from the registry: sign as recipient, store and (unless `activate: false`) activate. */
1280
- importFromChain: (share: IncomingShare, options?: ImportActivationOptions) => Promise<RecipientACP>;
1320
+ importFromChain: (share: IncomingShare, options?: ImportSharedOptions) => Promise<RecipientACP>;
1281
1321
  /** Recipient-side: remove a share from the registry (after import, or to decline). */
1282
1322
  dismissShare: (shareId: `0x${string}`) => Promise<`0x${string}`>;
1283
1323
  /** Issuer-side: retract a pending share from the registry. */
@@ -1,7 +1,7 @@
1
1
  import { WalletClient, PublicClient, Hex } from 'viem';
2
2
  import { C as CofheChain } from './types-C07FK-cL.js';
3
3
  import { z } from 'zod';
4
- import { A as ACP, h as EIP712Domain, C as CreateSelfACPOptions, v as SelfACP, d as CreateSharingACPOptions, w as SharingACP, I as ImportSharedACPOptions, R as RecipientACP, B as ACPHashFields, S as SerializedACP, z as ACPAccessStatus, g as IncomingShare, m as AclServedAddresses, i as ACPUtils } from './onchain-utils-CUAK8glx.js';
4
+ import { A as ACP, k as EIP712Domain, C as CreateSelfACPOptions, J as SelfACP, g as CreateSharingACPOptions, K as SharingACP, I as ImportSharedACPOptions, R as RecipientACP, P as ACPHashFields, f as SerializedACP, O as ACPAccessStatus, S as ShareLabel, j as IncomingShare, p as AclServedAddresses, L as LabelledShare, w as ShareLabelVerifyMode, x as ShareLabelCheck, l as ACPUtils } from './onchain-utils-D9Z33IP7.js';
5
5
  import { StoreApi } from 'zustand/vanilla';
6
6
 
7
7
  type TfheInitializer = () => Promise<boolean>;
@@ -280,6 +280,13 @@ type CofheConfig = {
280
280
  * names a registry.
281
281
  */
282
282
  sharingRegistry?: Record<number, `0x${string}`>;
283
+ /**
284
+ * The name of this app, e.g. 'explorer.fhenix.io'. Set, every share the client creates
285
+ * carries the app's key (`shareAppKey(app)`, kept in the share metadata), and
286
+ * `getIncomingShares` lists only the shares posted for this app. Unset, shares carry no
287
+ * key and every importable share is listed.
288
+ */
289
+ app?: string;
283
290
  };
284
291
  /** Mocks configs */
285
292
  mocks: {
@@ -341,6 +348,7 @@ declare const CofheConfigSchema: z.ZodObject<{
341
348
  defaultRevoker: z.ZodOptional<z.ZodCustom<Record<number, `0x${string}`>, Record<number, `0x${string}`>>>;
342
349
  defaultContractScopes: z.ZodOptional<z.ZodCustom<Record<number, `0x${string}`[]>, Record<number, `0x${string}`[]>>>;
343
350
  sharingRegistry: z.ZodOptional<z.ZodCustom<Record<number, `0x${string}`>, Record<number, `0x${string}`>>>;
351
+ app: z.ZodOptional<z.ZodString>;
344
352
  }, z.core.$strip>>>;
345
353
  mocks: z.ZodDefault<z.ZodOptional<z.ZodObject<{
346
354
  decryptDelay: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
@@ -1015,6 +1023,25 @@ type ImportActivationOptions = {
1015
1023
  */
1016
1024
  activate?: boolean;
1017
1025
  };
1026
+ /** Options for importing a shared acp: activation, and the recipient's own name for it. */
1027
+ type ImportSharedOptions = ImportActivationOptions & {
1028
+ /**
1029
+ * The name of the imported acp. Defaults to "Shared by 0x1234…abcd" (its issuer); the issuer's
1030
+ * own name for the share is not exported and is ignored if present.
1031
+ */
1032
+ name?: string;
1033
+ };
1034
+ /**
1035
+ * What `shareOnChain` posts with a share: the labels of its handles (one per handle, in order;
1036
+ * encoded with `encodeShareMetadata`), or an already encoded metadata blob. Written once, with the
1037
+ * share. Omitted, the labels the acp was created with are posted (`createSharing({ labels })`),
1038
+ * or none. `appKey` goes with given labels; a client configured with `acp: { app }` fills it in.
1039
+ */
1040
+ type ShareOnChainOptions = {
1041
+ labels?: readonly ShareLabel[];
1042
+ metadata?: Hex;
1043
+ appKey?: Hex;
1044
+ };
1018
1045
  declare const acps: {
1019
1046
  getSnapshot: () => {
1020
1047
  acps: {
@@ -1025,6 +1052,7 @@ declare const acps: {
1025
1052
  name: string;
1026
1053
  type: "self" | "sharing" | "recipient";
1027
1054
  sealingPrivateKey: Hex;
1055
+ metadata?: Hex | undefined;
1028
1056
  _signedDomain?: EIP712Domain | undefined;
1029
1057
  issuer: Hex;
1030
1058
  expiration: number;
@@ -1056,6 +1084,7 @@ declare const acps: {
1056
1084
  name: string;
1057
1085
  type: "self" | "sharing" | "recipient";
1058
1086
  sealingPrivateKey: Hex;
1087
+ metadata?: Hex | undefined;
1059
1088
  _signedDomain?: EIP712Domain | undefined;
1060
1089
  issuer: Hex;
1061
1090
  expiration: number;
@@ -1086,6 +1115,7 @@ declare const acps: {
1086
1115
  name: string;
1087
1116
  type: "self" | "sharing" | "recipient";
1088
1117
  sealingPrivateKey: Hex;
1118
+ metadata?: Hex | undefined;
1089
1119
  _signedDomain?: EIP712Domain | undefined;
1090
1120
  issuer: Hex;
1091
1121
  expiration: number;
@@ -1110,7 +1140,7 @@ declare const acps: {
1110
1140
  }) => void) => () => void;
1111
1141
  createSelf: (options: CreateSelfACPOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SelfACP>;
1112
1142
  createSharing: (options: CreateSharingACPOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SharingACP>;
1113
- importShared: (options: ImportSharedACPOptions | string, publicClient: PublicClient, walletClient: WalletClient, { activate }?: ImportActivationOptions) => Promise<RecipientACP>;
1143
+ importShared: (options: ImportSharedACPOptions | string, publicClient: PublicClient, walletClient: WalletClient, { activate, name }?: ImportSharedOptions) => Promise<RecipientACP>;
1114
1144
  getOrCreateSelfACP: (publicClient: PublicClient, walletClient: WalletClient, chainId?: number, account?: string, options?: CreateSelfACPOptions) => Promise<ACP>;
1115
1145
  getOrCreateSharingACP: (publicClient: PublicClient, walletClient: WalletClient, options: CreateSharingACPOptions, chainId?: number, account?: string) => Promise<ACP>;
1116
1146
  getHash: (acp: ACPHashFields) => string;
@@ -1120,6 +1150,7 @@ declare const acps: {
1120
1150
  name: string;
1121
1151
  type: "self" | "sharing" | "recipient";
1122
1152
  sealingPrivateKey: Hex;
1153
+ metadata?: Hex | undefined;
1123
1154
  _signedDomain?: EIP712Domain | undefined;
1124
1155
  issuer: Hex;
1125
1156
  expiration: number;
@@ -1138,6 +1169,7 @@ declare const acps: {
1138
1169
  name: string;
1139
1170
  type: "self" | "sharing" | "recipient";
1140
1171
  sealingPrivateKey: Hex;
1172
+ metadata?: Hex | undefined;
1141
1173
  _signedDomain?: EIP712Domain | undefined;
1142
1174
  issuer: Hex;
1143
1175
  expiration: number;
@@ -1162,24 +1194,17 @@ declare const acps: {
1162
1194
  revokeAllACPs: (walletClient: WalletClient, publicClient: PublicClient, revokerContract?: Hex) => Promise<Hex>;
1163
1195
  isACPRevoked: (acp: ACP, publicClient: PublicClient) => Promise<boolean>;
1164
1196
  checkAccess: (acp: ACP, publicClient: PublicClient, handle?: bigint | Hex) => Promise<ACPAccessStatus>;
1165
- shareOnChain: (acp: ACP, walletClient: WalletClient, registry: Hex) => Promise<{
1197
+ shareOnChain: (acp: ACP, walletClient: WalletClient, registry: Hex, options?: ShareOnChainOptions) => Promise<{
1166
1198
  txHash: Hex;
1167
1199
  shareId: Hex;
1168
1200
  }>;
1169
- getIncomingShares: (publicClient: PublicClient, registry: Hex, recipient: Hex) => Promise<IncomingShare[]>;
1170
- importFromChain: (share: IncomingShare, publicClient: PublicClient, walletClient: WalletClient, importOptions?: ImportActivationOptions) => Promise<RecipientACP>;
1201
+ getIncomingShares: (publicClient: PublicClient, registry: Hex, recipient: Hex, { appKey }?: {
1202
+ appKey?: Hex;
1203
+ }) => Promise<IncomingShare[]>;
1204
+ getShareFromChain: (publicClient: PublicClient, registry: Hex, shareId: Hex) => Promise<IncomingShare | null>;
1205
+ importFromChain: (share: IncomingShare, publicClient: PublicClient, walletClient: WalletClient, importOptions?: ImportSharedOptions) => Promise<RecipientACP>;
1171
1206
  removeShareOnChain: (shareId: Hex, walletClient: WalletClient, registry: Hex) => Promise<Hex>;
1172
1207
  computeShareId: (acp: ACP) => Hex;
1173
- applyACPDefaults: <T extends {
1174
- revokerData?: number;
1175
- revokerContract?: string;
1176
- scope?: number;
1177
- contracts?: string[];
1178
- handles?: (bigint | number | string)[];
1179
- }>(options: T, acpConfig: {
1180
- defaultRevoker?: Record<number, Hex>;
1181
- defaultContractScopes?: Record<number, Hex[]>;
1182
- } | undefined, chainId: number) => T;
1183
1208
  applyACPDefaultsFromChain: <T extends {
1184
1209
  revokerData?: number;
1185
1210
  revokerContract?: string;
@@ -1238,9 +1263,10 @@ type CofheClientACPsClients = {
1238
1263
  };
1239
1264
  /**
1240
1265
  * Options for `importShared`. `activate: false` stores the imported acp without making it the active
1241
- * one (default `true`). Clients default to the connected ones; pass both to override.
1266
+ * one (default `true`). `name` names it (default "Shared by 0x1234…abcd"). Clients default to the
1267
+ * connected ones; pass both to override.
1242
1268
  */
1243
- type CofheClientImportSharedOptions = ImportActivationOptions & (CofheClientACPsClients | {
1269
+ type CofheClientImportSharedOptions = ImportSharedOptions & (CofheClientACPsClients | {
1244
1270
  publicClient?: undefined;
1245
1271
  walletClient?: undefined;
1246
1272
  });
@@ -1269,15 +1295,29 @@ type CofheClientACPs = {
1269
1295
  * 'sharing', no recipient signature yet) the handle-less check covers expiry and revocation only.
1270
1296
  */
1271
1297
  checkAccess: (acp: ACP, handle?: bigint | `0x${string}`) => Promise<ACPAccessStatus>;
1272
- /** Post a signed sharing ACP to the on-chain share registry (ACL-served, or config `acp.sharingRegistry`). */
1273
- shareOnChain: (acp: ACP) => Promise<{
1298
+ /**
1299
+ * Post a signed sharing ACP to the on-chain share registry (ACL-served, or config `acp.sharingRegistry`),
1300
+ * optionally with the labels of its handles (`options.labels`, one per handle) or an encoded blob.
1301
+ */
1302
+ shareOnChain: (acp: ACP, options?: ShareOnChainOptions) => Promise<{
1274
1303
  txHash: `0x${string}`;
1275
1304
  shareId: `0x${string}`;
1276
1305
  }>;
1277
- /** Importable shares addressed to the connected account (unexpired, not revoked). */
1306
+ /** Importable shares addressed to the connected account (unexpired, not revoked), with their metadata. */
1278
1307
  getIncomingShares: () => Promise<IncomingShare[]>;
1308
+ /** One share by id, as posted; null when unknown or removed. */
1309
+ getShareFromChain: (shareId: `0x${string}`) => Promise<IncomingShare | null>;
1310
+ /**
1311
+ * Check a share's labels against the chain, index for index with its handles, as far as
1312
+ * `verify` says (default 'all'). Takes a share read from the registry or an acp imported from
1313
+ * exported JSON (or the issuer's sharing acp). Null for a share without metadata. Throws on a
1314
+ * malformed blob.
1315
+ */
1316
+ verifyShareLabels: (share: LabelledShare, options?: {
1317
+ verify?: ShareLabelVerifyMode;
1318
+ }) => Promise<ShareLabelCheck[] | null>;
1279
1319
  /** Import a share read from the registry: sign as recipient, store and (unless `activate: false`) activate. */
1280
- importFromChain: (share: IncomingShare, options?: ImportActivationOptions) => Promise<RecipientACP>;
1320
+ importFromChain: (share: IncomingShare, options?: ImportSharedOptions) => Promise<RecipientACP>;
1281
1321
  /** Recipient-side: remove a share from the registry (after import, or to decline). */
1282
1322
  dismissShare: (shareId: `0x${string}`) => Promise<`0x${string}`>;
1283
1323
  /** Issuer-side: retract a pending share from the registry. */