@cofhe/sdk 0.7.1 → 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 (123) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/acps/acp.ts +35 -7
  3. package/acps/index.ts +28 -12
  4. package/acps/onchain-utils.ts +188 -49
  5. package/acps/registry.ts +231 -0
  6. package/acps/sealing.ts +9 -3
  7. package/acps/share-metadata/appKey.ts +8 -0
  8. package/acps/share-metadata/decode.ts +120 -0
  9. package/acps/share-metadata/describe.ts +198 -0
  10. package/acps/share-metadata/encode.ts +147 -0
  11. package/acps/share-metadata/erc7984.ts +26 -0
  12. package/acps/share-metadata/index.ts +9 -0
  13. package/acps/share-metadata/layout.ts +69 -0
  14. package/acps/share-metadata/presets.ts +116 -0
  15. package/acps/share-metadata/schema.ts +47 -0
  16. package/acps/share-metadata/test/codec.test.ts +140 -0
  17. package/acps/share-metadata/test/describe.test.ts +112 -0
  18. package/acps/share-metadata/test/fixtures.ts +157 -0
  19. package/acps/share-metadata/test/live.test.ts +56 -0
  20. package/acps/share-metadata/test/presets.test.ts +119 -0
  21. package/acps/share-metadata/test/verify.test.ts +144 -0
  22. package/acps/share-metadata/verify.ts +155 -0
  23. package/acps/store.ts +48 -18
  24. package/acps/test/acp.test.ts +102 -7
  25. package/acps/test/localstorage.test.ts +28 -1
  26. package/acps/test/onchainAccessStatus.test.ts +116 -0
  27. package/acps/test/registry.test.ts +144 -0
  28. package/acps/test/sealing.test.ts +23 -0
  29. package/acps/test/store.test.ts +71 -0
  30. package/acps/test/utils.test.ts +63 -0
  31. package/acps/test/validation.test.ts +0 -4
  32. package/acps/types.ts +59 -6
  33. package/acps/utils.ts +15 -2
  34. package/acps/validation.ts +3 -1
  35. package/chains/chains/arbitrum.ts +14 -0
  36. package/chains/chains/ethereum.ts +14 -0
  37. package/chains/index.ts +5 -1
  38. package/chains/test/chains.test.ts +24 -3
  39. package/core/acps.ts +164 -207
  40. package/core/client.ts +44 -13
  41. package/core/clientTypes.ts +50 -7
  42. package/core/config.ts +33 -1
  43. package/core/consts.ts +14 -2
  44. package/core/decrypt/apiError.ts +4 -1
  45. package/core/decrypt/verifyDecryptResult.ts +8 -4
  46. package/core/encrypt/cofheMocksZkVerifySign.ts +19 -2
  47. package/core/encrypt/encryptInputsBuilder.ts +6 -0
  48. package/core/encrypt/zkPackProveVerify.ts +7 -1
  49. package/core/error.ts +1 -0
  50. package/core/fetchKeys.ts +2 -2
  51. package/core/index.ts +9 -1
  52. package/core/keyStore.ts +23 -10
  53. package/core/taskManager.ts +48 -0
  54. package/core/test/acpDefaults.test.ts +108 -19
  55. package/core/test/acpStoreAccountCase.test.ts +80 -0
  56. package/core/test/acps.test.ts +128 -3
  57. package/core/test/apiError.test.ts +8 -0
  58. package/core/test/appKeyConfig.test.ts +94 -0
  59. package/core/test/client.test.ts +41 -0
  60. package/core/test/config.test.ts +24 -0
  61. package/core/test/decrypt.test.ts +11 -4
  62. package/core/test/decryptBuilders.test.ts +110 -2
  63. package/core/test/encryptInputsBuilder.test.ts +1 -1
  64. package/core/test/fetchKeys.test.ts +23 -2
  65. package/core/test/incomingShares.test.ts +84 -0
  66. package/core/test/keyStore.test.ts +18 -6
  67. package/core/test/mocksEncryptRange.test.ts +90 -0
  68. package/core/test/taskManager.test.ts +57 -0
  69. package/core/test/utils.test.ts +128 -0
  70. package/core/test/verifyDecryptResult.test.ts +51 -0
  71. package/core/types.ts +8 -0
  72. package/core/utils.ts +16 -9
  73. package/dist/acps.cjs +984 -64
  74. package/dist/acps.d.cts +589 -10
  75. package/dist/acps.d.ts +589 -10
  76. package/dist/acps.js +2 -2
  77. package/dist/chains.cjs +26 -0
  78. package/dist/chains.d.cts +45 -1
  79. package/dist/chains.d.ts +45 -1
  80. package/dist/chains.js +1 -1
  81. package/dist/chunk-6ZW76ZKB.js +228 -0
  82. package/dist/chunk-BQWHPIYU.js +1828 -0
  83. package/dist/chunk-KSOV5B4B.js +50 -0
  84. package/dist/{chunk-43USWPEH.js → chunk-OL3DZN7A.js} +159 -523
  85. package/dist/{chunk-N6IDQRRU.js → chunk-UKQAJK4N.js} +25 -1
  86. package/dist/chunk-XQ32JG3T.js +174 -0
  87. package/dist/{clientTypes-CYZjFznO.d.cts → clientTypes-C0A9ji5O.d.cts} +132 -29
  88. package/dist/{clientTypes-BN3nbzYM.d.ts → clientTypes-CcU5WvdV.d.ts} +132 -29
  89. package/dist/core.cjs +3269 -2626
  90. package/dist/core.d.cts +32 -8
  91. package/dist/core.d.ts +32 -8
  92. package/dist/core.js +5 -4
  93. package/dist/node.cjs +3074 -2436
  94. package/dist/node.d.cts +2 -2
  95. package/dist/node.d.ts +2 -2
  96. package/dist/node.js +20 -19
  97. package/dist/{acp-Wi6isVQI.d.cts → onchain-utils-D9Z33IP7.d.cts} +166 -12
  98. package/dist/{acp-Wi6isVQI.d.ts → onchain-utils-D9Z33IP7.d.ts} +166 -12
  99. package/dist/web.cjs +3204 -2493
  100. package/dist/web.d.cts +49 -3
  101. package/dist/web.d.ts +49 -3
  102. package/dist/web.js +52 -27
  103. package/dist/zkProve.worker.cjs +79 -18
  104. package/dist/zkProve.worker.js +24 -24
  105. package/node/index.ts +1 -10
  106. package/node/storage.ts +20 -9
  107. package/node/test/inherited.test.ts +5 -1
  108. package/node/test/storage-memory-fallback.test.ts +47 -0
  109. package/node/test/storage-permissions.test.ts +40 -0
  110. package/package.json +3 -1
  111. package/web/index.ts +101 -36
  112. package/web/test/countingZkProveWorker.ts +31 -0
  113. package/web/test/inherited.web.test.ts +5 -1
  114. package/web/test/mainThreadPool.web.test.ts +174 -0
  115. package/web/test/threadPoolBenchHelper.ts +134 -0
  116. package/web/test/threadPoolOff.web.test.ts +17 -0
  117. package/web/test/threadPoolOn.web.test.ts +80 -0
  118. package/web/test/workerInitRace.web.test.ts +79 -0
  119. package/web/tfheThreadPool.ts +140 -0
  120. package/web/workerManager.ts +4 -2
  121. package/web/zkProve.worker.ts +42 -26
  122. package/dist/chunk-ESMZCFJY.js +0 -12
  123. package/dist/chunk-Q7CBWGQX.js +0 -1029
package/dist/acps.d.cts CHANGED
@@ -1,9 +1,582 @@
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, S as ShareLabel, a as StoredValueLabel, E as EventValueLabel, L as LabelledShare, V as ValidationResult, b as ACPPublic, c as ACPSignaturePrimaryType, d as EIP712Types, e as EIP712Message, f as SerializedACP } from './onchain-utils-D9Z33IP7.cjs';
2
+ export { O as ACPAccessStatus, P as ACPHashFields, h as ACPMetadata, H as ACPOf, D as ACPPrivate, M as ACPScope, N as ACPScopeOptions, F as ACPType, l as ACPUtils, p as AclServedAddresses, C as CreateSelfACPOptions, g as CreateSharingACPOptions, k as EIP712Domain, B as EIP712Type, r as EthEncryptedData, Q as Expand, G as GenerateSealingKey, I as ImportACPOptions, I as ImportSharedACPOptions, j as IncomingShare, v as LabelVerification, R as RecipientACP, q as SealingKeyPair, J as SelfACP, C as SelfACPOptions, x as ShareLabelCheck, t as ShareLabelReadArg, w as ShareLabelVerifyMode, i as SharedACP, K as SharingACP, g as SharingACPOptions, U as UnlabelledLabel, o as clearAclServedAddresses, m as getAclAddress, n as getAclServedAddresses, s as seal, u as unsealWithPrivateKey, y as verifyShareLabel, z as verifyShareLabels } from './onchain-utils-D9Z33IP7.cjs';
3
+ import { Hex, AbiParameterToPrimitiveType, Address, PublicClient, Abi, ContractFunctionName, ContractFunctionArgs, Log } 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, and the read of a share from its `Shared` event. Exported so an
11
+ * app can send these writes through its own transaction path and still agree with the registry
12
+ * on ids.
13
+ *
14
+ * The registry is pointer-based: storage keeps a share header (issuer, expiration, recipient,
15
+ * revoker, and the block of its `Shared` event); the full payload and the metadata blob travel in
16
+ * that event. A reader takes headers from `sharesFor` / `getShare` and fetches the events with one
17
+ * single-block `getLogs` per block.
18
+ */
19
+ declare const ACP_REVOKER_ABI: readonly [{
20
+ readonly name: "revokeSingle";
21
+ readonly type: "function";
22
+ readonly stateMutability: "nonpayable";
23
+ readonly inputs: readonly [{
24
+ readonly type: "uint256";
25
+ readonly name: "id";
26
+ }];
27
+ readonly outputs: readonly [];
28
+ }, {
29
+ readonly name: "revokeAllExisting";
30
+ readonly type: "function";
31
+ readonly stateMutability: "nonpayable";
32
+ readonly inputs: readonly [];
33
+ readonly outputs: readonly [];
34
+ }, {
35
+ readonly name: "disabled";
36
+ readonly type: "function";
37
+ readonly stateMutability: "view";
38
+ readonly inputs: readonly [{
39
+ readonly type: "address";
40
+ readonly name: "issuer";
41
+ }, {
42
+ readonly type: "uint256";
43
+ readonly name: "id";
44
+ }];
45
+ readonly outputs: readonly [{
46
+ readonly type: "bool";
47
+ }];
48
+ }];
49
+ declare const ACP_SHARE_REGISTRY_ABI: readonly [{
50
+ readonly name: "share";
51
+ readonly type: "function";
52
+ readonly stateMutability: "nonpayable";
53
+ readonly inputs: readonly [{
54
+ readonly type: "tuple";
55
+ readonly components: readonly [{
56
+ readonly type: "address";
57
+ readonly name: "issuer";
58
+ }, {
59
+ readonly type: "uint64";
60
+ readonly name: "expiration";
61
+ }, {
62
+ readonly type: "address";
63
+ readonly name: "recipient";
64
+ }, {
65
+ readonly type: "uint256";
66
+ readonly name: "revokerData";
67
+ }, {
68
+ readonly type: "address";
69
+ readonly name: "revokerContract";
70
+ }, {
71
+ readonly type: "uint8";
72
+ readonly name: "scope";
73
+ }, {
74
+ readonly type: "address[]";
75
+ readonly name: "contracts";
76
+ }, {
77
+ readonly type: "bytes32[]";
78
+ readonly name: "handles";
79
+ }, {
80
+ readonly type: "bytes32";
81
+ readonly name: "sealingKey";
82
+ }, {
83
+ readonly type: "bytes";
84
+ readonly name: "issuerSignature";
85
+ }, {
86
+ readonly type: "bytes";
87
+ readonly name: "recipientSignature";
88
+ }];
89
+ readonly name: "acp";
90
+ }, {
91
+ readonly type: "bytes";
92
+ readonly name: "metadata";
93
+ }];
94
+ readonly outputs: readonly [{
95
+ readonly type: "bytes32";
96
+ }];
97
+ }, {
98
+ readonly name: "removeShare";
99
+ readonly type: "function";
100
+ readonly stateMutability: "nonpayable";
101
+ readonly inputs: readonly [{
102
+ readonly type: "bytes32";
103
+ readonly name: "shareId";
104
+ }];
105
+ readonly outputs: readonly [];
106
+ }, {
107
+ readonly name: "sharesFor";
108
+ readonly type: "function";
109
+ readonly stateMutability: "view";
110
+ readonly inputs: readonly [{
111
+ readonly type: "address";
112
+ readonly name: "recipient";
113
+ }];
114
+ readonly outputs: readonly [{
115
+ readonly type: "bytes32[]";
116
+ readonly name: "shareIds";
117
+ }, {
118
+ readonly type: "tuple[]";
119
+ readonly components: readonly [{
120
+ readonly type: "address";
121
+ readonly name: "issuer";
122
+ }, {
123
+ readonly type: "uint64";
124
+ readonly name: "expiration";
125
+ }, {
126
+ readonly type: "address";
127
+ readonly name: "recipient";
128
+ }, {
129
+ readonly type: "uint64";
130
+ readonly name: "blockNumber";
131
+ }, {
132
+ readonly type: "address";
133
+ readonly name: "revokerContract";
134
+ }, {
135
+ readonly type: "uint256";
136
+ readonly name: "revokerData";
137
+ }];
138
+ readonly name: "headers";
139
+ }];
140
+ }, {
141
+ readonly name: "getShare";
142
+ readonly type: "function";
143
+ readonly stateMutability: "view";
144
+ readonly inputs: readonly [{
145
+ readonly type: "bytes32";
146
+ readonly name: "shareId";
147
+ }];
148
+ readonly outputs: readonly [{
149
+ readonly type: "tuple";
150
+ readonly components: readonly [{
151
+ readonly type: "address";
152
+ readonly name: "issuer";
153
+ }, {
154
+ readonly type: "uint64";
155
+ readonly name: "expiration";
156
+ }, {
157
+ readonly type: "address";
158
+ readonly name: "recipient";
159
+ }, {
160
+ readonly type: "uint64";
161
+ readonly name: "blockNumber";
162
+ }, {
163
+ readonly type: "address";
164
+ readonly name: "revokerContract";
165
+ }, {
166
+ readonly type: "uint256";
167
+ readonly name: "revokerData";
168
+ }];
169
+ }];
170
+ }, {
171
+ readonly name: "isShareValid";
172
+ readonly type: "function";
173
+ readonly stateMutability: "view";
174
+ readonly inputs: readonly [{
175
+ readonly type: "bytes32";
176
+ readonly name: "shareId";
177
+ }];
178
+ readonly outputs: readonly [{
179
+ readonly type: "bool";
180
+ }];
181
+ }, {
182
+ readonly name: "Shared";
183
+ readonly type: "event";
184
+ readonly inputs: readonly [{
185
+ readonly type: "address";
186
+ readonly name: "recipient";
187
+ readonly indexed: true;
188
+ }, {
189
+ readonly type: "address";
190
+ readonly name: "issuer";
191
+ readonly indexed: true;
192
+ }, {
193
+ readonly type: "bytes32";
194
+ readonly name: "shareId";
195
+ readonly indexed: true;
196
+ }, {
197
+ readonly type: "tuple";
198
+ readonly components: readonly [{
199
+ readonly type: "address";
200
+ readonly name: "issuer";
201
+ }, {
202
+ readonly type: "uint64";
203
+ readonly name: "expiration";
204
+ }, {
205
+ readonly type: "address";
206
+ readonly name: "recipient";
207
+ }, {
208
+ readonly type: "uint256";
209
+ readonly name: "revokerData";
210
+ }, {
211
+ readonly type: "address";
212
+ readonly name: "revokerContract";
213
+ }, {
214
+ readonly type: "uint8";
215
+ readonly name: "scope";
216
+ }, {
217
+ readonly type: "address[]";
218
+ readonly name: "contracts";
219
+ }, {
220
+ readonly type: "bytes32[]";
221
+ readonly name: "handles";
222
+ }, {
223
+ readonly type: "bytes32";
224
+ readonly name: "sealingKey";
225
+ }, {
226
+ readonly type: "bytes";
227
+ readonly name: "issuerSignature";
228
+ }, {
229
+ readonly type: "bytes";
230
+ readonly name: "recipientSignature";
231
+ }];
232
+ readonly name: "acp";
233
+ }, {
234
+ readonly type: "bytes";
235
+ readonly name: "metadata";
236
+ }];
237
+ }, {
238
+ readonly name: "ShareRemoved";
239
+ readonly type: "event";
240
+ readonly inputs: readonly [{
241
+ readonly type: "address";
242
+ readonly name: "recipient";
243
+ readonly indexed: true;
244
+ }, {
245
+ readonly type: "address";
246
+ readonly name: "issuer";
247
+ readonly indexed: true;
248
+ }, {
249
+ readonly type: "bytes32";
250
+ readonly name: "shareId";
251
+ readonly indexed: true;
252
+ }];
253
+ }];
254
+ declare const ACP_SHARE_TUPLE_ABI: readonly [{
255
+ readonly type: "tuple";
256
+ readonly components: readonly [{
257
+ readonly name: "issuer";
258
+ readonly type: "address";
259
+ }, {
260
+ readonly name: "expiration";
261
+ readonly type: "uint64";
262
+ }, {
263
+ readonly name: "recipient";
264
+ readonly type: "address";
265
+ }, {
266
+ readonly name: "revokerData";
267
+ readonly type: "uint256";
268
+ }, {
269
+ readonly name: "revokerContract";
270
+ readonly type: "address";
271
+ }, {
272
+ readonly name: "scope";
273
+ readonly type: "uint8";
274
+ }, {
275
+ readonly name: "contracts";
276
+ readonly type: "address[]";
277
+ }, {
278
+ readonly name: "handles";
279
+ readonly type: "bytes32[]";
280
+ }, {
281
+ readonly name: "sealingKey";
282
+ readonly type: "bytes32";
283
+ }, {
284
+ readonly name: "issuerSignature";
285
+ readonly type: "bytes";
286
+ }, {
287
+ readonly name: "recipientSignature";
288
+ readonly type: "bytes";
289
+ }];
290
+ }];
291
+ /** The on-chain payload for a sharing ACP: recipient-side fields empty. */
292
+ declare const toChainShare: (acp: ACP) => {
293
+ expiration: bigint;
294
+ revokerData: bigint;
295
+ sealingKey: `0x${string}`;
296
+ recipientSignature: Hex;
297
+ issuer: Hex;
298
+ recipient: Hex;
299
+ revokerContract: Hex;
300
+ scope: number;
301
+ contracts: Hex[];
302
+ handles: Hex[];
303
+ issuerSignature: Hex;
304
+ };
305
+ /** Mirrors the registry's `keccak256(abi.encode(acp))` share id. */
306
+ declare const computeShareId: (acp: ACP) => Hex;
307
+ /** The share id of a registry payload as read back from a `Shared` event. */
308
+ declare const shareIdOfChainShare: (share: ChainShare) => Hex;
309
+ /** A registry payload, as decoded from a `Shared` event (or passed to `share`). */
310
+ type ChainShare = AbiParameterToPrimitiveType<(typeof ACP_SHARE_TUPLE_ABI)[0]>;
311
+ /** What the registry stores of a share: the fields it checks, and the block of its `Shared` event. */
312
+ type ShareHeader = {
313
+ issuer: Address;
314
+ expiration: bigint;
315
+ recipient: Address;
316
+ /** Block of the `Shared` event (the L2 block on Arbitrum). */
317
+ blockNumber: bigint;
318
+ revokerContract: Address;
319
+ revokerData: bigint;
320
+ };
321
+ /** A share as posted: its payload and the metadata blob that came with it (`0x` when none). */
322
+ type PostedShare = {
323
+ shareId: Hex;
324
+ header: ShareHeader;
325
+ share: ChainShare;
326
+ metadata: Hex;
327
+ };
328
+ /** A share the registry lists but whose `Shared` event could not be read, and why. */
329
+ type UnreadableShare = {
330
+ shareId: Hex;
331
+ header: ShareHeader;
332
+ reason: string;
333
+ };
334
+ /** Shares read from their events, and those that could not be; each share is on its own. */
335
+ type PostedShares = {
336
+ posted: PostedShare[];
337
+ unreadable: UnreadableShare[];
338
+ };
339
+ /**
340
+ * Fetches the `Shared` events of shares from the blocks their headers name: one single-block
341
+ * `getLogs` per distinct block, filtered by registry and share ids, so any node answers it. Returns
342
+ * the shares in the order given; where a block holds several events for one share id, the last.
343
+ * Never fails as a whole: a share whose block the node cannot serve yet, whose event is missing
344
+ * from it, or whose event payload does not hash to its id is returned as `unreadable`, with the
345
+ * reason, and the rest are posted as usual.
346
+ */
347
+ declare const readPostedShares: (publicClient: PublicClient, registry: Address, headers: readonly {
348
+ shareId: Hex;
349
+ header: ShareHeader;
350
+ }[]) => Promise<PostedShares>;
351
+ /**
352
+ * The importable shares addressed to `recipient` (unexpired, not revoked), read from their events;
353
+ * those whose event could not be read are listed apart, so one of them never hides the rest.
354
+ */
355
+ declare const readSharesFor: (publicClient: PublicClient, registry: Address, recipient: Address) => Promise<PostedShares>;
356
+ /**
357
+ * One share by id, read from its event; null when the registry has no such share (unknown or
358
+ * removed). Throws, with the reason, when the registry lists it but its event could not be read.
359
+ */
360
+ declare const readShare: (publicClient: PublicClient, registry: Address, shareId: Hex) => Promise<PostedShare | null>;
361
+
362
+ /**
363
+ * Byte layout of a share metadata blob, version 3. Integers are big-endian; sizes in bytes.
364
+ *
365
+ * blob = version (1)
366
+ * | contract count (1) | contracts (20 each)
367
+ * | selector count (1) | selectors (4 each) function selectors, and event
368
+ * selectors (first 4 bytes of topic0)
369
+ * | transaction count (1) | transactions (6 each: block 4, tx index 2)
370
+ * | entries, one per ctHash, in the order of acp.handles
371
+ * | app key, optional: 0x01 | key (32) keccak256 of the name of the app the
372
+ * share is for; absent when the blob ends
373
+ *
374
+ * stored value = 0x00 | contract (1) | selector (1) | block (4) | args 8 bytes or more
375
+ * event value = 0x01 | contract (1) | transaction (1) | log index (2) | selector (1) 6 bytes
376
+ * unlabelled = 0xff 1 byte
377
+ *
378
+ * args = 0x00 no arguments, return word 0
379
+ * | 0x01 one argument, the share issuer, return word 0
380
+ * | 0xff | return word (1) | count (1) | argument, count times
381
+ * argument = 0x00 | word (32) a literal ABI word
382
+ * | 0x01 the share issuer
383
+ *
384
+ * Contracts, selectors and transactions are listed once; entries refer to them by position.
385
+ * The log index is block-wide, as RPC nodes return it.
386
+ */
387
+ declare const LAYOUT_VERSION = 3;
388
+
389
+ /**
390
+ * Encodes the labels of a share into a version 3 blob: one label per ctHash, in the order of
391
+ * `acp.handles`. The contracts, selectors and transactions the labels name are listed once each,
392
+ * in order of first use; function and event selectors share one list. Throws on a value that does
393
+ * not fit its field (more than 255 contracts, a block past uint32, ...). Given the share `issuer`, a
394
+ * stored-value argument equal to their address is stored as "the issuer" instead of the address.
395
+ * Given an `appKey` (`shareAppKey(app)`), it closes the blob, so the app can tell its shares apart.
396
+ */
397
+ declare const encodeShareMetadata: (labels: readonly ShareLabel[], { issuer, appKey }?: {
398
+ issuer?: Address;
399
+ appKey?: Hex;
400
+ }) => Hex;
401
+
402
+ /** The two things a blob holds: one label per ctHash, and the app key when the share names an app. */
403
+ type DecodedShareMetadata = {
404
+ labels: ShareLabel[];
405
+ appKey: Hex | undefined;
406
+ };
407
+ /**
408
+ * Decodes a version 3 blob: one label per ctHash, in the order of `acp.handles`, and the app key
409
+ * when there is one. The exact inverse of `encodeShareMetadata`. Throws on another version, an
410
+ * unknown kind, code or tag, a position outside its list, and unless the blob holds exactly one
411
+ * entry per ctHash.
412
+ */
413
+ declare const decodeShareMetadataFull: (blob: Hex, handles: readonly Hex[]) => DecodedShareMetadata;
414
+ /** The labels of a blob, one per ctHash in the order of `acp.handles` (see `decodeShareMetadataFull`). */
415
+ declare const decodeShareMetadata: (blob: Hex, handles: readonly Hex[]) => ShareLabel[];
416
+ /** The app key a share was posted with, or undefined: for a share without metadata, or without a key. */
417
+ declare const decodeShareAppKey: (metadata: Hex | undefined, handles: readonly Hex[]) => Hex | undefined;
418
+
419
+ /** A parameter as the ABI names it. `name` is absent when the ABI leaves it unnamed. */
420
+ type ShareLabelParam = {
421
+ name?: string;
422
+ type: string;
423
+ indexed?: boolean;
424
+ };
425
+ /** One argument of a stored-value read, decoded with the function's input type when the ABI has one. */
426
+ type ShareLabelArg = ShareLabelParam & {
427
+ /** The argument stands for the share issuer. */
428
+ isIssuer: boolean;
429
+ /** The 32-byte ABI word, or undefined for an issuer argument when no issuer was given. */
430
+ raw: Hex | undefined;
431
+ /** The decoded value (an address, a bigint, ...), or the raw word when there is no ABI type for it. */
432
+ value: unknown;
433
+ };
434
+ type DescriptionBase = {
435
+ /** Position of the ctHash in `acp.handles`. */
436
+ index: number;
437
+ handle: Hex;
438
+ };
439
+ type StoredValueDescription = DescriptionBase & {
440
+ kind: 'stored';
441
+ label: StoredValueLabel;
442
+ contract: Address;
443
+ block: bigint;
444
+ selector: Hex;
445
+ /** The view function, or null when the ABI of the contract is missing or has no function with this selector. */
446
+ function: {
447
+ name: string;
448
+ signature: string;
449
+ inputs: ShareLabelParam[];
450
+ } | null;
451
+ args: ShareLabelArg[];
452
+ /** The returned field that holds the ctHash, when the ABI names the outputs. */
453
+ output: ShareLabelParam | null;
454
+ };
455
+ type EventValueDescription = DescriptionBase & {
456
+ kind: 'event';
457
+ label: EventValueLabel;
458
+ contract: Address;
459
+ block: bigint;
460
+ txIndex: number;
461
+ logIndex: number;
462
+ selector: Hex;
463
+ /**
464
+ * The event, or null when the ABI of the contract is missing or has no event with this selector.
465
+ * Parameter values are not in the label; they come with the log fetched to verify it.
466
+ */
467
+ event: {
468
+ name: string;
469
+ signature: string;
470
+ inputs: ShareLabelParam[];
471
+ } | null;
472
+ };
473
+ type UnlabelledDescription = DescriptionBase & {
474
+ kind: 'unlabelled';
475
+ label: ShareLabel & {
476
+ kind: 'unlabelled';
477
+ };
478
+ };
479
+ type ShareLabelDescription = StoredValueDescription | EventValueDescription | UnlabelledDescription;
480
+ /** ABIs by contract address; addresses compare case-insensitively. */
481
+ type ShareLabelAbis = Readonly<Record<Address, Abi>>;
482
+ /**
483
+ * Turns decoded labels into structured, human-readable items, one per ctHash in the order of
484
+ * `handles`: the function name and decoded arguments of a stored value, the event name and
485
+ * parameters of an event value. A contract without an ABI, or a selector its ABI doesn't have,
486
+ * leaves the item in raw form (`function` / `event` null); this never throws. `issuer` (the share
487
+ * issuer) fills in the arguments that stand for it.
488
+ */
489
+ declare const describeShareLabels: (labels: readonly ShareLabel[], handles: readonly Hex[], abis?: ShareLabelAbis, options?: {
490
+ issuer?: Address;
491
+ }) => ShareLabelDescription[];
492
+ /**
493
+ * Decodes a share's metadata blob and describes it: `decodeShareMetadata` then
494
+ * `describeShareLabels`, with the share's issuer filling in the arguments that stand for it. The
495
+ * share is one read from the registry or an acp imported from exported JSON. Null for a share
496
+ * without labels (no metadata, or `0x`). Throws only when the blob itself is malformed; missing
497
+ * ABIs leave items in raw form.
498
+ */
499
+ declare const describeShareMetadata: (share: LabelledShare, abis?: ShareLabelAbis) => ShareLabelDescription[] | null;
500
+
501
+ /**
502
+ * Builders for labels. The format knows nothing about tokens: a balance is the value a view
503
+ * function returned, a transfer amount the value of one event.
504
+ */
505
+ type ViewFunctionLabelOptions<abi extends Abi, functionName extends ContractFunctionName<abi, 'pure' | 'view'>> = {
506
+ contract: Address;
507
+ abi: abi;
508
+ functionName: functionName;
509
+ /**
510
+ * The arguments of the call, static ABI types only. One equal to the share issuer's address
511
+ * (your own, when you share your balance) is stored as "the issuer" when the labels are encoded.
512
+ */
513
+ args?: ContractFunctionArgs<abi, 'pure' | 'view', functionName>;
514
+ /** Block the value was read at (on Arbitrum: the L2 block number). */
515
+ block: bigint;
516
+ /** Which 32-byte word of the return data is the ctHash; 0 (the default) for a single return value. */
517
+ returnWord?: number;
518
+ };
519
+ /**
520
+ * The label of a value a view function returned at a block, built from the contract's ABI: the
521
+ * function's selector, and each argument ABI-encoded to its word. Throws when the ABI has no such
522
+ * function, the arity is off, or an argument is not one static word.
523
+ */
524
+ declare const viewFunctionLabel: <const abi extends Abi, functionName extends ContractFunctionName<abi, "pure" | "view">>(options: ViewFunctionLabelOptions<abi, functionName>) => StoredValueLabel;
525
+ /**
526
+ * The label of a value carried by a log, as viem returns it from `getLogs` / `getContractEvents`:
527
+ * its contract, block, transaction and log index, and its event selector. Throws for a pending log.
528
+ */
529
+ declare const eventLogLabel: (log: Pick<Log, "address" | "blockNumber" | "transactionIndex" | "logIndex" | "topics">) => EventValueLabel;
530
+ /** The label of a ctHash the issuer chooses not to describe. */
531
+ declare const UNLABELLED: ShareLabel;
532
+
533
+ /**
534
+ * The parts of ERC-7984 (confidential tokens) that share labels most often point at: the balance
535
+ * read and the transfer event. One definition for the SDK's label presets and for apps, with
536
+ * `internalType` kept so `@cofhe/abi` recognises the encrypted values.
537
+ */
538
+ declare const ERC7984_ABI: readonly [{
539
+ readonly type: "function";
540
+ readonly name: "confidentialBalanceOf";
541
+ readonly stateMutability: "view";
542
+ readonly inputs: readonly [{
543
+ readonly name: "account";
544
+ readonly type: "address";
545
+ readonly internalType: "address";
546
+ }];
547
+ readonly outputs: readonly [{
548
+ readonly name: "";
549
+ readonly type: "bytes32";
550
+ readonly internalType: "euint64";
551
+ }];
552
+ }, {
553
+ readonly type: "event";
554
+ readonly name: "ConfidentialTransfer";
555
+ readonly anonymous: false;
556
+ readonly inputs: readonly [{
557
+ readonly name: "from";
558
+ readonly type: "address";
559
+ readonly indexed: true;
560
+ readonly internalType: "address";
561
+ }, {
562
+ readonly name: "to";
563
+ readonly type: "address";
564
+ readonly indexed: true;
565
+ readonly internalType: "address";
566
+ }, {
567
+ readonly name: "amount";
568
+ readonly type: "bytes32";
569
+ readonly indexed: true;
570
+ readonly internalType: "euint64";
571
+ }];
572
+ }];
573
+
574
+ /**
575
+ * The key an app marks its shares with: keccak256 of its name, e.g. `shareAppKey('explorer.fhenix.io')`.
576
+ * A client configured with `acp: { app }` puts it on every share it creates and lists only the
577
+ * shares that carry it; the name itself is never on-chain.
578
+ */
579
+ declare const shareAppKey: (app: string) => Hex;
7
580
 
8
581
  declare const addressSchema: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
9
582
  declare const addressNotZeroSchema: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
@@ -78,6 +651,7 @@ declare const SelfACPValidator: z.ZodObject<{
78
651
  handles: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>>>>;
79
652
  issuerSignature: z.ZodDefault<z.ZodOptional<z.ZodCustom<`0x${string}`, `0x${string}`>>>;
80
653
  recipientSignature: z.ZodDefault<z.ZodOptional<z.ZodCustom<`0x${string}`, `0x${string}`>>>;
654
+ metadata: z.ZodOptional<z.ZodCustom<`0x${string}`, `0x${string}`>>;
81
655
  sealingPrivateKey: z.ZodOptional<z.ZodString>;
82
656
  sealingKey: z.ZodOptional<z.ZodString>;
83
657
  }, z.core.$strip>;
@@ -146,6 +720,7 @@ declare const SharingACPValidator: z.ZodObject<{
146
720
  handles: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>>>>;
147
721
  issuerSignature: z.ZodDefault<z.ZodOptional<z.ZodCustom<`0x${string}`, `0x${string}`>>>;
148
722
  recipientSignature: z.ZodDefault<z.ZodOptional<z.ZodCustom<`0x${string}`, `0x${string}`>>>;
723
+ metadata: z.ZodOptional<z.ZodCustom<`0x${string}`, `0x${string}`>>;
149
724
  sealingPrivateKey: z.ZodOptional<z.ZodString>;
150
725
  sealingKey: z.ZodOptional<z.ZodString>;
151
726
  }, z.core.$strip>;
@@ -156,7 +731,6 @@ declare const ImportACPOptionsValidator: z.ZodPipe<z.ZodObject<{
156
731
  type: z.ZodDefault<z.ZodOptional<z.ZodLiteral<"recipient">>>;
157
732
  issuer: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
158
733
  recipient: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
159
- name: z.ZodDefault<z.ZodOptional<z.ZodString>>;
160
734
  expiration: z.ZodInt;
161
735
  revokerData: z.ZodDefault<z.ZodOptional<z.ZodInt>>;
162
736
  revokerContract: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>>>;
@@ -165,11 +739,11 @@ declare const ImportACPOptionsValidator: z.ZodPipe<z.ZodObject<{
165
739
  handles: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>>>>;
166
740
  issuerSignature: z.ZodCustom<`0x${string}`, `0x${string}`>;
167
741
  recipientSignature: z.ZodDefault<z.ZodOptional<z.ZodCustom<`0x${string}`, `0x${string}`>>>;
742
+ metadata: z.ZodPipe<z.ZodOptional<z.ZodCustom<`0x${string}`, `0x${string}`>>, z.ZodTransform<`0x${string}` | undefined, `0x${string}` | undefined>>;
168
743
  }, z.core.$strip>, z.ZodTransform<{
169
744
  type: "recipient";
170
745
  issuer: `0x${string}`;
171
746
  recipient: `0x${string}`;
172
- name: string;
173
747
  expiration: number;
174
748
  revokerData: number;
175
749
  revokerContract: `0x${string}`;
@@ -177,6 +751,7 @@ declare const ImportACPOptionsValidator: z.ZodPipe<z.ZodObject<{
177
751
  handles: `0x${string}`[];
178
752
  issuerSignature: `0x${string}`;
179
753
  recipientSignature: `0x${string}`;
754
+ metadata: `0x${string}` | undefined;
180
755
  scope?: number | undefined;
181
756
  } & {
182
757
  scope: number;
@@ -184,7 +759,6 @@ declare const ImportACPOptionsValidator: z.ZodPipe<z.ZodObject<{
184
759
  type: "recipient";
185
760
  issuer: `0x${string}`;
186
761
  recipient: `0x${string}`;
187
- name: string;
188
762
  expiration: number;
189
763
  revokerData: number;
190
764
  revokerContract: `0x${string}`;
@@ -192,6 +766,7 @@ declare const ImportACPOptionsValidator: z.ZodPipe<z.ZodObject<{
192
766
  handles: `0x${string}`[];
193
767
  issuerSignature: `0x${string}`;
194
768
  recipientSignature: `0x${string}`;
769
+ metadata: `0x${string}` | undefined;
195
770
  scope?: number | undefined;
196
771
  }>>;
197
772
  /**
@@ -214,6 +789,7 @@ declare const ImportACPValidator: z.ZodObject<{
214
789
  handles: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>>>>;
215
790
  issuerSignature: z.ZodDefault<z.ZodOptional<z.ZodCustom<`0x${string}`, `0x${string}`>>>;
216
791
  recipientSignature: z.ZodDefault<z.ZodOptional<z.ZodCustom<`0x${string}`, `0x${string}`>>>;
792
+ metadata: z.ZodOptional<z.ZodCustom<`0x${string}`, `0x${string}`>>;
217
793
  sealingPrivateKey: z.ZodOptional<z.ZodString>;
218
794
  sealingKey: z.ZodOptional<z.ZodString>;
219
795
  }, z.core.$strip>;
@@ -262,7 +838,6 @@ declare const validateImportACPOptions: (options: any) => {
262
838
  type: "recipient";
263
839
  issuer: `0x${string}`;
264
840
  recipient: `0x${string}`;
265
- name: string;
266
841
  expiration: number;
267
842
  revokerData: number;
268
843
  revokerContract: `0x${string}`;
@@ -270,6 +845,7 @@ declare const validateImportACPOptions: (options: any) => {
270
845
  handles: `0x${string}`[];
271
846
  issuerSignature: `0x${string}`;
272
847
  recipientSignature: `0x${string}`;
848
+ metadata: `0x${string}` | undefined;
273
849
  scope?: number | undefined;
274
850
  } & {
275
851
  scope: number;
@@ -290,6 +866,7 @@ declare const validateSelfACP: (acp: any) => {
290
866
  handles: `0x${string}`[];
291
867
  issuerSignature: `0x${string}`;
292
868
  recipientSignature: `0x${string}`;
869
+ metadata?: `0x${string}` | undefined;
293
870
  sealingPrivateKey?: string | undefined;
294
871
  sealingKey?: string | undefined;
295
872
  };
@@ -309,6 +886,7 @@ declare const validateSharingACP: (acp: any) => {
309
886
  handles: `0x${string}`[];
310
887
  issuerSignature: `0x${string}`;
311
888
  recipientSignature: `0x${string}`;
889
+ metadata?: `0x${string}` | undefined;
312
890
  sealingPrivateKey?: string | undefined;
313
891
  sealingKey?: string | undefined;
314
892
  };
@@ -328,6 +906,7 @@ declare const validateImportACP: (acp: any) => {
328
906
  handles: `0x${string}`[];
329
907
  issuerSignature: `0x${string}`;
330
908
  recipientSignature: `0x${string}`;
909
+ metadata?: `0x${string}` | undefined;
331
910
  sealingPrivateKey?: string | undefined;
332
911
  sealingKey?: string | undefined;
333
912
  };
@@ -391,8 +970,8 @@ declare const ACPSignatureAllFields: readonly [{
391
970
  }];
392
971
  type ACPSignatureFieldOption = (typeof ACPSignatureAllFields)[number]['name'];
393
972
  declare const SignatureTypes: {
394
- readonly ACPIssuerSelf: ("recipient" | "issuer" | "expiration" | "revokerData" | "revokerContract" | "scope" | "contracts" | "handles" | "sealingKey")[];
395
- readonly ACPIssuerShared: ("recipient" | "issuer" | "expiration" | "revokerData" | "revokerContract" | "scope" | "contracts" | "handles")[];
973
+ readonly ACPIssuerSelf: ("issuer" | "recipient" | "expiration" | "revokerData" | "revokerContract" | "scope" | "contracts" | "handles" | "sealingKey")[];
974
+ readonly ACPIssuerShared: ("issuer" | "recipient" | "expiration" | "revokerData" | "revokerContract" | "scope" | "contracts" | "handles")[];
396
975
  readonly ACPRecipient: ("sealingKey" | "issuerSignature")[];
397
976
  };
398
977
  /**
@@ -477,4 +1056,4 @@ declare const acpStore: {
477
1056
  resetStore: () => void;
478
1057
  };
479
1058
 
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 };
1059
+ export { ACP, ACPPublic, ACPSignaturePrimaryType, ACP_REVOKER_ABI, ACP_SHARE_REGISTRY_ABI, ACP_SHARE_TUPLE_ABI, ACP_STORE_DEFAULTS, type ChainShare, type DecodedShareMetadata, EIP712Message, EIP712Types, ERC7984_ABI, type EventValueDescription, EventValueLabel, ImportACPOptionsValidator, ImportACPValidator, LabelledShare, type PostedShare, type PostedShares, LAYOUT_VERSION as SHARE_METADATA_VERSION, SelfACPOptionsValidator, SelfACPValidator, SerializedACP, type ShareHeader, ShareLabel, type ShareLabelAbis, type ShareLabelArg, type ShareLabelDescription, type ShareLabelParam, SharingACPOptionsValidator, SharingACPValidator, SignatureTypes, SignatureUtils, type StoredValueDescription, StoredValueLabel, UNLABELLED, type UnlabelledDescription, type UnreadableShare, ValidationResult, ValidationUtils, type ViewFunctionLabelOptions, _acpStore, acpStore, addressNotZeroSchema, addressSchema, bytesNotEmptySchema, bytesSchema, clearStaleStore, computeShareId, contractsSchema, decodeShareAppKey, decodeShareMetadata, decodeShareMetadataFull, describeShareLabels, describeShareMetadata, encodeShareMetadata, eventLogLabel, getACP, getACPs, getActiveACP, getActiveACPHash, getSignatureTypesAndMessage, handlesSchema, readPostedShares, readShare, readSharesFor, removeACP, removeActiveACPHash, resetStore, setACP, setActiveACPHash, shareAppKey, shareIdOfChainShare, toChainShare, validateImportACP, validateImportACPOptions, validateSelfACP, validateSelfACPOptions, validateSharingACP, validateSharingACPOptions, viewFunctionLabel };