@cofhe/sdk 1.0.1 → 1.1.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +0 -8
  2. package/core/acps.ts +64 -23
  3. package/core/client.ts +32 -1
  4. package/core/clientTypes.ts +22 -1
  5. package/core/decrypt/decryptForTxBuilder.ts +16 -0
  6. package/core/decrypt/decryptForViewBuilder.ts +14 -0
  7. package/core/decrypt/submitRetry.ts +16 -0
  8. package/core/decrypt/tnDecryptV2.ts +19 -9
  9. package/core/decrypt/tnSealOutputV2.ts +19 -9
  10. package/core/encrypt/encryptInputsBuilder.ts +13 -31
  11. package/core/encrypt/zkPackProveVerify.ts +4 -16
  12. package/core/error.ts +0 -1
  13. package/core/test/acpsPrepare.test.ts +77 -0
  14. package/core/test/decryptBuilders.test.ts +51 -0
  15. package/core/test/encryptInputsBuilder.test.ts +4 -56
  16. package/dist/acps.d.cts +4 -358
  17. package/dist/acps.d.ts +4 -358
  18. package/dist/acps.js +2 -2
  19. package/dist/{chunk-WAA2U7CT.js → chunk-3L2IVPMI.js} +1 -1
  20. package/dist/{chunk-OC5TGQGG.js → chunk-J23FYAI2.js} +0 -1
  21. package/dist/{chunk-GKEJHZ52.js → chunk-VE7DKXSF.js} +132 -75
  22. package/dist/{chunk-3SD2UCRE.js → chunk-WJGTPW7K.js} +1 -1
  23. package/dist/{clientTypes-DEKYh0cw.d.ts → clientTypes-B-qOZCx0.d.ts} +55 -7
  24. package/dist/{clientTypes-C2b_qub5.d.cts → clientTypes-D2djRDoH.d.cts} +55 -7
  25. package/dist/core.cjs +128 -72
  26. package/dist/core.d.cts +3 -4
  27. package/dist/core.d.ts +3 -4
  28. package/dist/core.js +4 -4
  29. package/dist/node.cjs +128 -71
  30. package/dist/node.d.cts +2 -2
  31. package/dist/node.d.ts +2 -2
  32. package/dist/node.js +4 -4
  33. package/dist/{onchain-utils-CgOslubH.d.ts → onchain-utils-Ns56cBm0.d.cts} +356 -2
  34. package/dist/{onchain-utils-CgOslubH.d.cts → onchain-utils-Ns56cBm0.d.ts} +356 -2
  35. package/dist/web.cjs +128 -71
  36. package/dist/web.d.cts +2 -2
  37. package/dist/web.d.ts +2 -2
  38. package/dist/web.js +4 -4
  39. package/dist/zkProve.worker.js +2 -2
  40. package/package.json +1 -1
  41. package/core/test/zkPoKMetadata.test.ts +0 -27
@@ -239,24 +239,13 @@ export const zkProve = async (
239
239
  };
240
240
 
241
241
  /**
242
- * Constructs the ZK Proof of Knowledge metadata for the proof:
243
- * `securityZone (1) || account (20) || chainId (32, big-endian) || consumingContract (20)`.
244
- *
245
- * The verifier rebuilds the same bytes from the request fields before it checks the proof, so the
246
- * proof is bound to the consuming contract itself, not only to the signature the verifier returns.
242
+ * Constructs the ZK Proof of Knowledge metadata for the proof
247
243
  * @internal - Used internally within the encrypt module
248
244
  */
249
- export const constructZkPoKMetadata = (
250
- accountAddr: string,
251
- securityZone: number,
252
- chainId: number,
253
- consumingContract: string
254
- ): Uint8Array => {
255
- // Decode the account and contract addresses from hex
245
+ export const constructZkPoKMetadata = (accountAddr: string, securityZone: number, chainId: number): Uint8Array => {
246
+ // Decode the account address from hex
256
247
  const accountAddrNoPrefix = accountAddr.startsWith('0x') ? accountAddr.slice(2) : accountAddr;
257
248
  const accountBytes = hexToBytes(accountAddrNoPrefix);
258
- const contractNoPrefix = consumingContract.startsWith('0x') ? consumingContract.slice(2) : consumingContract;
259
- const contractBytes = hexToBytes(contractNoPrefix);
260
249
 
261
250
  // Encode chainId as 32 bytes (u256) in big-endian format
262
251
  const chainIdBytes = new Uint8Array(32);
@@ -270,11 +259,10 @@ export const constructZkPoKMetadata = (
270
259
  value = value >>> 8;
271
260
  }
272
261
 
273
- const metadata = new Uint8Array(1 + accountBytes.length + 32 + contractBytes.length);
262
+ const metadata = new Uint8Array(1 + accountBytes.length + 32);
274
263
  metadata[0] = securityZone;
275
264
  metadata.set(accountBytes, 1);
276
265
  metadata.set(chainIdBytes, 1 + accountBytes.length);
277
- metadata.set(contractBytes, 1 + accountBytes.length + 32);
278
266
 
279
267
  return metadata;
280
268
  };
package/core/error.ts CHANGED
@@ -16,7 +16,6 @@ export enum CofheErrorCode {
16
16
  AccountUninitialized = 'ACCOUNT_UNINITIALIZED',
17
17
  ChainIdUninitialized = 'CHAIN_ID_UNINITIALIZED',
18
18
  ConsumingContractUninitialized = 'CONSUMING_CONTRACT_UNINITIALIZED',
19
- ConsumingContractInvalid = 'CONSUMING_CONTRACT_INVALID',
20
19
  SealOutputFailed = 'SEAL_OUTPUT_FAILED',
21
20
  SealOutputReturnedNull = 'SEAL_OUTPUT_RETURNED_NULL',
22
21
  InvalidUtype = 'INVALID_UTYPE',
@@ -0,0 +1,77 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import type { Hex } from 'viem';
3
+ import { ACP_REVOKER_ABI, ACP_SHARE_REGISTRY_ABI, computeShareId, encodeShareMetadata, toChainShare } from '@/acps';
4
+ import { UNLABELLED } from '../../acps/share-metadata';
5
+ import { createMockACP } from '../../acps/test-utils';
6
+ import { acps } from '../acps';
7
+
8
+ /**
9
+ * The sharing writes built but not sent: what a caller that sends through its own path
10
+ * (simulation, transaction store) gets, and what the plain senders send. No chain involved.
11
+ */
12
+
13
+ const REGISTRY = '0x00000000000000000000000000000000000000A1';
14
+ const REVOKER = '0x00000000000000000000000000000000000000B2';
15
+ const ALICE = '0x70997970C51812dc3A010C7d01b50e0d17dc79C8';
16
+ const HANDLE: Hex = `0x${'1'.repeat(64)}`;
17
+
18
+ const signedSharing = (overrides: Parameters<typeof createMockACP>[0] = {}) =>
19
+ createMockACP({ type: 'sharing', recipient: ALICE, issuerSignature: '0x1234', ...overrides });
20
+
21
+ describe('prepareShareOnChain', () => {
22
+ it('a signed sharing acp: the registry share call with the acp and its metadata, and its share id', async () => {
23
+ const acp = await signedSharing();
24
+ const { write, shareId } = acps.prepareShareOnChain(acp, REGISTRY);
25
+ expect(write).toStrictEqual({
26
+ address: REGISTRY,
27
+ abi: ACP_SHARE_REGISTRY_ABI,
28
+ functionName: 'share',
29
+ args: [toChainShare(acp), '0x'],
30
+ });
31
+ expect(shareId).toBe(computeShareId(acp));
32
+ });
33
+
34
+ it('posts the labels it is given, else the metadata on the acp', async () => {
35
+ const acp = await signedSharing({ handles: [HANDLE] });
36
+ const labelled = acps.prepareShareOnChain(acp, REGISTRY, { labels: [UNLABELLED] });
37
+ expect(labelled.write.args[1]).toBe(encodeShareMetadata([UNLABELLED], { issuer: acp.issuer }));
38
+
39
+ const kept = acps.prepareShareOnChain({ ...acp, metadata: '0xdead' }, REGISTRY);
40
+ expect(kept.write.args[1]).toBe('0xdead');
41
+ });
42
+
43
+ it('refuses a self acp and an unsigned sharing acp', async () => {
44
+ const self = await createMockACP();
45
+ expect(() => acps.prepareShareOnChain(self, REGISTRY)).toThrow(/only 'sharing' ACPs/);
46
+ const unsigned = await createMockACP({ type: 'sharing', recipient: ALICE });
47
+ expect(() => acps.prepareShareOnChain(unsigned, REGISTRY)).toThrow(/sign it first/);
48
+ });
49
+ });
50
+
51
+ describe('prepareRemoveShare', () => {
52
+ it('the registry removeShare call for the share id', () => {
53
+ expect(acps.prepareRemoveShare(HANDLE, REGISTRY)).toStrictEqual({
54
+ address: REGISTRY,
55
+ abi: ACP_SHARE_REGISTRY_ABI,
56
+ functionName: 'removeShare',
57
+ args: [HANDLE],
58
+ });
59
+ });
60
+ });
61
+
62
+ describe('prepareRevokeACP', () => {
63
+ it('the revoker revokeSingle call for the acp revoker data', async () => {
64
+ const acp = await signedSharing({ revokerContract: REVOKER, revokerData: 42 });
65
+ expect(acps.prepareRevokeACP(acp)).toStrictEqual({
66
+ address: REVOKER,
67
+ abi: ACP_REVOKER_ABI,
68
+ functionName: 'revokeSingle',
69
+ args: [42n],
70
+ });
71
+ });
72
+
73
+ it('refuses an acp without a revoker', async () => {
74
+ const acp = await signedSharing();
75
+ expect(() => acps.prepareRevokeACP(acp)).toThrow(/not revocable/);
76
+ });
77
+ });
@@ -224,6 +224,21 @@ describe('DecryptForTxBuilder', () => {
224
224
 
225
225
  expect(() => builder.set404RetryTimeout(-1)).toThrow('set404RetryTimeout(timeoutMs) expects');
226
226
  });
227
+
228
+ it('should allow configuring the overall timeout', () => {
229
+ const builder = createTxBuilder();
230
+ const result = builder.setTimeout(20_000);
231
+
232
+ expect(result).toBe(builder);
233
+ expect((builder as any).timeoutMs).toBe(20_000);
234
+ });
235
+
236
+ it('should throw for an overall timeout that is not a positive number', () => {
237
+ const builder = createTxBuilder();
238
+
239
+ expect(() => builder.setTimeout(0)).toThrow('setTimeout(timeoutMs) expects');
240
+ expect(() => builder.setTimeout(Number.NaN)).toThrow('setTimeout(timeoutMs) expects');
241
+ });
227
242
  });
228
243
 
229
244
  // --- execute error paths ---
@@ -367,6 +382,21 @@ describe('DecryptForViewBuilder', () => {
367
382
 
368
383
  expect(() => builder.set404RetryTimeout(-1)).toThrow('set404RetryTimeout(timeoutMs) expects');
369
384
  });
385
+
386
+ it('should allow configuring the overall timeout', () => {
387
+ const builder = createViewBuilder(FheTypes.Uint32);
388
+ const result = builder.setTimeout(20_000);
389
+
390
+ expect(result).toBe(builder);
391
+ expect((builder as any).timeoutMs).toBe(20_000);
392
+ });
393
+
394
+ it('should throw for an overall timeout that is not a positive number', () => {
395
+ const builder = createViewBuilder(FheTypes.Uint32);
396
+
397
+ expect(() => builder.setTimeout(0)).toThrow('setTimeout(timeoutMs) expects');
398
+ expect(() => builder.setTimeout(-5)).toThrow('setTimeout(timeoutMs) expects');
399
+ });
370
400
  });
371
401
 
372
402
  // --- execute error paths ---
@@ -503,6 +533,16 @@ describe('execute – expired acp (regression, issue #272)', () => {
503
533
  expect(result.decryptedValue).toBe(7n);
504
534
  expect(tnDecryptV2).toHaveBeenCalledOnce();
505
535
  });
536
+
537
+ it('passes the overall timeout to the threshold network call', async () => {
538
+ vi.mocked(tnDecryptV2).mockResolvedValue({ decryptedValue: 7n, signature: '0x1234' });
539
+ const acp = createSignedSelfACP(now() + 3600);
540
+ seedACP(acp);
541
+
542
+ await selectTxACP('active acp', acp).setTimeout(20_000).execute();
543
+
544
+ expect(tnDecryptV2).toHaveBeenCalledWith(expect.objectContaining({ timeoutMs: 20_000 }));
545
+ });
506
546
  });
507
547
 
508
548
  describe('decryptForView', () => {
@@ -522,5 +562,16 @@ describe('execute – expired acp (regression, issue #272)', () => {
522
562
  await expect(selectViewACP('active acp', acp).execute()).rejects.toThrow('stubbed threshold network');
523
563
  expect(tnSealOutputV2).toHaveBeenCalledOnce();
524
564
  });
565
+
566
+ it('passes the overall timeout to the threshold network call', async () => {
567
+ vi.mocked(tnSealOutputV2).mockRejectedValue(new Error('stubbed threshold network'));
568
+ const acp = createSignedSelfACP(now() + 3600);
569
+ seedACP(acp);
570
+
571
+ await expect(selectViewACP('active acp', acp).setTimeout(20_000).execute()).rejects.toThrow(
572
+ 'stubbed threshold network'
573
+ );
574
+ expect(tnSealOutputV2).toHaveBeenCalledWith(expect.objectContaining({ timeoutMs: 20_000 }));
575
+ });
525
576
  });
526
577
  });
@@ -10,7 +10,7 @@ import {
10
10
  } from '../types.js';
11
11
  import { CofheError, CofheErrorCode } from '../error.js';
12
12
  import { fromHexString, toHexString } from '../utils.js';
13
- import { type PublicClient, createPublicClient, http, type WalletClient, createWalletClient, isAddress } from 'viem';
13
+ import { type PublicClient, createPublicClient, http, type WalletClient, createWalletClient } from 'viem';
14
14
  import { privateKeyToAccount } from 'viem/accounts';
15
15
  import { arbitrumSepolia } from 'viem/chains';
16
16
  import { type CofheConfig, createCofheConfigBase } from '../config.js';
@@ -53,9 +53,9 @@ const unpackMetadata = (metadata: string) => {
53
53
 
54
54
  export const deconstructZkPoKMetadata = (
55
55
  metadata: Uint8Array
56
- ): { accountAddr: string; securityZone: number; chainId: number; contractAddr: string } => {
57
- if (metadata.length < 73) {
58
- // 1 + 20 + 32 + 20 = 73 bytes minimum
56
+ ): { accountAddr: string; securityZone: number; chainId: number } => {
57
+ if (metadata.length < 53) {
58
+ // 1 + 20 + 32 = 53 bytes minimum
59
59
  throw new CofheError({
60
60
  code: CofheErrorCode.InternalError,
61
61
  message: 'Invalid metadata: insufficient length',
@@ -78,14 +78,10 @@ export const deconstructZkPoKMetadata = (
78
78
  chainId = (chainId << 8) | chainIdBytes[i];
79
79
  }
80
80
 
81
- // Extract the consuming contract (last 20 bytes)
82
- const contractAddr = '0x' + toHexString(metadata.slice(53, 73));
83
-
84
81
  return {
85
82
  accountAddr,
86
83
  securityZone,
87
84
  chainId,
88
- contractAddr,
89
85
  };
90
86
  };
91
87
 
@@ -449,38 +445,6 @@ describe('EncryptInputsBuilder', () => {
449
445
  expect((error as CofheError).code).toBe(CofheErrorCode.ConsumingContractUninitialized);
450
446
  }
451
447
  });
452
-
453
- it('accepts a mixed-case consuming contract whose checksum is wrong', async () => {
454
- // The verifier decodes the address case-insensitively and the chain compares
455
- // 20 bytes, so a 1.0.0 dApp with such an address must keep working.
456
- const wrongChecksum = '0xBEEFbeefBEEFbeefBEEFbeefBEEFbeefBEEFbeef';
457
- expect(isAddress(wrongChecksum)).toBe(false);
458
- expect(isAddress(wrongChecksum, { strict: false })).toBe(true);
459
-
460
- const result = await new EncryptInputsBuilder(createDefaultParams())
461
- .setConsumingContract(wrongChecksum)
462
- .execute();
463
-
464
- expect(Array.isArray(result)).toBe(true);
465
- });
466
-
467
- it('rejects a consuming contract that is not an address before any encrypt step runs', async () => {
468
- for (const notAnAddress of ['0x0', 'not-an-address', '0xbeefbeefbeefbeefbeefbeefbeefbeefbeefbee']) {
469
- const steps = vi.fn();
470
- const invalid = new EncryptInputsBuilder(createDefaultParams())
471
- .setConsumingContract(notAnAddress)
472
- .onStep(steps);
473
- try {
474
- await invalid.execute();
475
- expect.unreachable(`execute() should have thrown for ${notAnAddress}`);
476
- } catch (error) {
477
- expect(error, notAnAddress).toBeInstanceOf(CofheError);
478
- expect((error as CofheError).code, notAnAddress).toBe(CofheErrorCode.ConsumingContractInvalid);
479
- }
480
- // Rejected before initTfhe, so no step (and no proving) ever started.
481
- expect(steps, notAnAddress).not.toHaveBeenCalled();
482
- }
483
- });
484
448
  });
485
449
 
486
450
  describe('zkVerifierUrl', () => {
@@ -631,22 +595,6 @@ describe('EncryptInputsBuilder', () => {
631
595
  expect(encryptedMetadata.chainId).toBe(defaultChainId);
632
596
  });
633
597
 
634
- it('binds the consuming contract into the proof metadata', async () => {
635
- mockFetch.mockClear();
636
-
637
- await builder.execute();
638
-
639
- const verifyCall = mockFetch.mock.calls.find(([url]) => url === `${MockZkVerifierUrl}/verifyBatch`);
640
- expect(verifyCall).toBeDefined();
641
- const body = JSON.parse(verifyCall![1].body as string);
642
- const { metadata } = parseWithBigInt(new TextDecoder().decode(fromHexString(body.packed_list)));
643
- const embedded = deconstructZkPoKMetadata(Uint8Array.from(Object.values(metadata) as number[]));
644
- expect(embedded.accountAddr).toBe(defaultSender);
645
- expect(embedded.securityZone).toBe(0);
646
- expect(embedded.chainId).toBe(defaultChainId);
647
- expect(embedded.contractAddr).toBe(defaultConsumingContract);
648
- });
649
-
650
598
  it('should use overridden account when set', async () => {
651
599
  const overriddenSender = '0x5555555555555555555555555555555555555555';
652
600
  builder.setAccount(overriddenSender);
package/dist/acps.d.cts CHANGED
@@ -1,364 +1,10 @@
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-CgOslubH.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-CgOslubH.cjs';
3
- import { Hex, AbiParameterToPrimitiveType, Address, PublicClient, Abi, ContractFunctionName, ContractFunctionArgs, Log } from 'viem';
1
+ import { S as ShareLabel, a as StoredValueLabel, E as EventValueLabel, L as LabelledShare, A as ACP, V as ValidationResult, b as ACPPublic, c as ACPSignaturePrimaryType, d as EIP712Types, e as EIP712Message, f as SerializedACP } from './onchain-utils-Ns56cBm0.cjs';
2
+ export { a4 as ACPAccessStatus, a5 as ACPHashFields, h as ACPMetadata, _ as ACPOf, Y as ACPPrivate, a2 as ACPScope, a3 as ACPScopeOptions, Z as ACPType, l as ACPUtils, t as ACP_REVOKER_ABI, v as ACP_SHARE_REGISTRY_ABI, w as ACP_SHARE_TUPLE_ABI, p as AclServedAddresses, B as ChainShare, C as CreateSelfACPOptions, g as CreateSharingACPOptions, k as EIP712Domain, X as EIP712Type, r as EthEncryptedData, a6 as Expand, G as GenerateSealingKey, I as ImportACPOptions, I as ImportSharedACPOptions, j as IncomingShare, O as LabelVerification, P as PostedShare, F as PostedShares, a1 as RecipientACP, q as SealingKeyPair, $ as SelfACP, C as SelfACPOptions, D as ShareHeader, R as ShareLabelCheck, M as ShareLabelReadArg, Q as ShareLabelVerifyMode, i as SharedACP, a0 as SharingACP, g as SharingACPOptions, N as UnlabelledLabel, U as UnreadableShare, o as clearAclServedAddresses, y as computeShareId, m as getAclAddress, n as getAclServedAddresses, H as readPostedShares, K as readShare, J as readSharesFor, s as seal, z as shareIdOfChainShare, x as toChainShare, u as unsealWithPrivateKey, T as verifyShareLabel, W as verifyShareLabels } from './onchain-utils-Ns56cBm0.cjs';
3
+ import { Address, Hex, Abi, ContractFunctionName, ContractFunctionArgs, Log } from 'viem';
4
4
  import { z } from 'zod';
5
5
  import * as zustand_middleware from 'zustand/middleware';
6
6
  import * as zustand_vanilla from 'zustand/vanilla';
7
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
8
  /**
363
9
  * Byte layout of a share metadata blob, version 3. Integers are big-endian; sizes in bytes.
364
10
  *
@@ -1056,4 +702,4 @@ declare const acpStore: {
1056
702
  resetStore: () => void;
1057
703
  };
1058
704
 
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 };
705
+ export { ACP, ACPPublic, ACPSignaturePrimaryType, ACP_STORE_DEFAULTS, type DecodedShareMetadata, EIP712Message, EIP712Types, ERC7984_ABI, type EventValueDescription, EventValueLabel, ImportACPOptionsValidator, ImportACPValidator, LabelledShare, LAYOUT_VERSION as SHARE_METADATA_VERSION, SelfACPOptionsValidator, SelfACPValidator, SerializedACP, ShareLabel, type ShareLabelAbis, type ShareLabelArg, type ShareLabelDescription, type ShareLabelParam, SharingACPOptionsValidator, SharingACPValidator, SignatureTypes, SignatureUtils, type StoredValueDescription, StoredValueLabel, UNLABELLED, type UnlabelledDescription, ValidationResult, ValidationUtils, type ViewFunctionLabelOptions, _acpStore, acpStore, addressNotZeroSchema, addressSchema, bytesNotEmptySchema, bytesSchema, clearStaleStore, contractsSchema, decodeShareAppKey, decodeShareMetadata, decodeShareMetadataFull, describeShareLabels, describeShareMetadata, encodeShareMetadata, eventLogLabel, getACP, getACPs, getActiveACP, getActiveACPHash, getSignatureTypesAndMessage, handlesSchema, removeACP, removeActiveACPHash, resetStore, setACP, setActiveACPHash, shareAppKey, validateImportACP, validateImportACPOptions, validateSelfACP, validateSelfACPOptions, validateSharingACP, validateSharingACPOptions, viewFunctionLabel };