@invisi-labs/protocol 1.1.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.
@@ -0,0 +1,948 @@
1
+ import * as _invisi_labs_core from '@invisi-labs/core';
2
+ import { Hex, Address, ReceivingKeyLookup, WalletAuthorizationRequest, Wallet, WalletAuthorizationProvider, Note, CreditDeliveryState, AuthorizedStatement } from '@invisi-labs/core';
3
+ import { ContractRunner, Provider } from 'ethers';
4
+ import { Prover, ProverOptions, ProofTarget, CircuitName, ProofStatement, ProvingRequest } from '@invisi-labs/prover';
5
+ import { DeploymentContext, CanonicalBlock, ProtocolDeployment, ProtocolRpcClient } from '@invisi-labs/rpc';
6
+ export { CanonicalBlock, DeploymentContext, Membership, ProtocolDataProvider, ProtocolDataStatus, ProtocolUpdateRange, ProtocolUpdates } from '@invisi-labs/rpc';
7
+ import { F as FundingParams, D as Delivery, I as InputSource, C as CreateCreditParams, a as CancelCreditParams, b as CreditDrawParams, T as TopUpCreditParams, c as TransactRequest, S as ShieldParams, d as ShieldOutput, e as CrossTreeTransactParams } from './types-RN45XzKc.js';
8
+
9
+ interface RegistryContext {
10
+ chainId: bigint;
11
+ registryAddress: Address;
12
+ /** Optional explicit wall-clock value in seconds. Equality with deadline is valid. */
13
+ now?: bigint;
14
+ }
15
+ interface RegistryReceivingKeys {
16
+ viewingPublicKey: Hex;
17
+ clueKey: Hex;
18
+ }
19
+ interface AddressRegistration {
20
+ /** Nonzero 20-byte EVM owner address. ABI calls zero-pad it to bytes32. */
21
+ walletIdentity: Hex;
22
+ keys: RegistryReceivingKeys;
23
+ /** The current registry nonce expected for this operation. */
24
+ nonce: bigint;
25
+ deadline: bigint;
26
+ }
27
+ interface RegistrationOptions {
28
+ update?: boolean;
29
+ /** Check a separately obtained current nonce before authorizing or encoding. */
30
+ expectedNonce?: bigint;
31
+ }
32
+ interface RegistrationCalldata {
33
+ to: Address;
34
+ callData: Hex;
35
+ value: 0n;
36
+ publicInputs: readonly [Hex, Hex, Hex];
37
+ }
38
+ /** Private-wallet authorization request; it contains only the public transcript. */
39
+ declare function registrationAuthorizationRequest(context: RegistryContext, registration: AddressRegistration, options?: RegistrationOptions): WalletAuthorizationRequest;
40
+ declare function registrationTypedData(context: RegistryContext, registration: AddressRegistration, options?: RegistrationOptions): {
41
+ domain: {
42
+ name: string;
43
+ version: string;
44
+ chainId: bigint;
45
+ verifyingContract: `0x${string}`;
46
+ };
47
+ types: {
48
+ readonly WalletAuthorization: readonly [{
49
+ readonly name: "operation";
50
+ readonly type: "bytes32";
51
+ }, {
52
+ readonly name: "statementHash";
53
+ readonly type: "bytes32";
54
+ }];
55
+ };
56
+ primaryType: "WalletAuthorization";
57
+ message: {
58
+ operation: `0x${string}`;
59
+ statementHash: `0x${string}`;
60
+ };
61
+ };
62
+ /** Exact wallet_registration public statement: WID, digest high128, digest low128. */
63
+ declare function registrationPublicInputs(context: RegistryContext, registration: AddressRegistration, options?: RegistrationOptions): readonly [Hex, Hex, Hex];
64
+ /** Encode a relayer-ready call after obtaining a proof; does not sign or broadcast. */
65
+ declare function buildRegistrationCalldata(context: RegistryContext, registration: AddressRegistration, proof: Hex, options?: RegistrationOptions): RegistrationCalldata;
66
+ /** Ethers runner used for registry contract reads. */
67
+ type RegistryReadClient = ContractRunner;
68
+ /** One receivingKeysOf query per short address; RPC failures propagate unchanged. */
69
+ declare function createRegistryReceivingKeyLookup(client: RegistryReadClient, registryAddress: Address): ReceivingKeyLookup;
70
+
71
+ interface TransactionContext extends DeploymentContext {
72
+ tokenAddress: Address;
73
+ now?: bigint;
74
+ }
75
+ declare const FIELD_MODULUS = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
76
+ declare const ZERO_ADDRESS: "0x0000000000000000000000000000000000000000";
77
+ declare const ZERO_WORD: Hex;
78
+ declare const EMPTY_PERMIT: {
79
+ readonly deadline: 0n;
80
+ readonly v: 0;
81
+ readonly r: `0x${string}`;
82
+ readonly s: `0x${string}`;
83
+ };
84
+ declare const EMPTY_FUNDING: FundingParams;
85
+ type FundingInput = Partial<Omit<FundingParams, "permit">> & {
86
+ permit?: FundingParams["permit"];
87
+ };
88
+ declare function uint(v: bigint | number | string, bits: number, name?: string): bigint;
89
+ declare function field(v: bigint | string, name?: string): bigint;
90
+ declare const word: (v: bigint | string) => Hex;
91
+ declare function dense<T>(v: readonly T[], name: string): readonly T[];
92
+ declare function known(v: object, keys: readonly string[], name?: string): void;
93
+ declare function notes(v: readonly Hex[], name: string): `0x${string}`[];
94
+ declare function envelope(v: Hex, length: number, version?: number): Hex;
95
+ declare function normalizeContext(c: TransactionContext): {
96
+ chainId: bigint;
97
+ protocolAddress: Hex;
98
+ tokenAddress: Hex;
99
+ now?: bigint;
100
+ };
101
+ declare function checkDeadline(c: TransactionContext, value: bigint): bigint;
102
+ declare function normalizeSources(sources: readonly InputSource[], inputCount: number, capacity: number): {
103
+ treeId: bigint;
104
+ merkleRoot: `0x${string}`;
105
+ }[];
106
+ declare const pad: (v: readonly bigint[], n: number) => bigint[];
107
+ declare function normalizeDelivery(value: Delivery, options?: {
108
+ credit?: boolean;
109
+ empty?: boolean;
110
+ }): Delivery;
111
+ declare const deliveriesHash: (v: readonly Delivery[]) => Hex;
112
+ declare function normalizeFunding(input?: FundingInput): FundingParams;
113
+ declare function validateFundingSubmission(f: FundingParams, caller?: Address, now?: bigint): void;
114
+ declare const getEIP712Domain: (c: TransactionContext) => {
115
+ name: string;
116
+ version: string;
117
+ chainId: bigint;
118
+ verifyingContract: Hex;
119
+ };
120
+ declare const fundingFields: readonly [{
121
+ readonly name: "requestHash";
122
+ readonly type: "bytes32";
123
+ }, {
124
+ readonly name: "payer";
125
+ readonly type: "address";
126
+ }, {
127
+ readonly name: "amount";
128
+ readonly type: "uint256";
129
+ }, {
130
+ readonly name: "sigNonce";
131
+ readonly type: "uint256";
132
+ }, {
133
+ readonly name: "deadline";
134
+ readonly type: "uint256";
135
+ }];
136
+
137
+ interface ProtocolLog {
138
+ address: Address;
139
+ data: Hex;
140
+ topics: readonly Hex[];
141
+ transactionHash: Hex;
142
+ logIndex: number;
143
+ }
144
+ interface CanonicalReceipt {
145
+ block: CanonicalBlock;
146
+ transactionHash: Hex;
147
+ logs: readonly ProtocolLog[];
148
+ status?: "success" | "reverted";
149
+ }
150
+ interface ChainReader {
151
+ getChainId(): Promise<bigint>;
152
+ getCode(address: Address): Promise<Hex>;
153
+ getBlock(number: bigint): Promise<CanonicalBlock>;
154
+ getLatestBlockNumber(): Promise<bigint>;
155
+ getFundingNonce(context: DeploymentContext, payer: Address, block: CanonicalBlock): Promise<bigint>;
156
+ isKnownRoot(context: DeploymentContext, treeId: bigint, root: Hex, block: CanonicalBlock): Promise<boolean>;
157
+ getTransaction(hash: Hex): Promise<(TransactionCall & {
158
+ transactionHash: Hex;
159
+ from: Address;
160
+ nonce: bigint;
161
+ }) | null>;
162
+ getReceipt(hash: Hex): Promise<CanonicalReceipt | null>;
163
+ isSpent(context: DeploymentContext, nullifiers: readonly Hex[], block: CanonicalBlock): Promise<readonly boolean[]>;
164
+ }
165
+ interface TransactionCall {
166
+ to: Address;
167
+ data: Hex;
168
+ value: bigint;
169
+ }
170
+ /** Optional deployment provenance queries, independent of token policy. */
171
+ interface FactoryReader {
172
+ getFactoryInstanceAddress(factory: Address, salt: Hex): Promise<Address>;
173
+ isFactoryInstance(factory: Address, instance: Address): Promise<boolean>;
174
+ getInstanceFactory(instance: Address): Promise<Address>;
175
+ }
176
+
177
+ interface RegistryReader extends Pick<ChainReader, "getChainId" | "getCode" | "getBlock" | "getLatestBlockNumber" | "getTransaction" | "getReceipt"> {
178
+ getRegistryNonce(context: RegistryContext, walletIdentity: Hex, block: CanonicalBlock): Promise<bigint>;
179
+ }
180
+ interface RegistrationPreparation {
181
+ wallet: Wallet;
182
+ reader: RegistryReader;
183
+ authorization?: WalletAuthorizationProvider;
184
+ prover?: Prover;
185
+ deadline?: bigint;
186
+ update?: boolean;
187
+ }
188
+ type RegistrationStatus = "prepared" | "authorized" | "ready" | "submitted" | "confirmed" | "uncertain" | "failed" | "expired" | "reorged";
189
+ declare class RegistrationOperation {
190
+ #private;
191
+ readonly status: RegistrationStatus;
192
+ private constructor();
193
+ static prepare(registry: AddressRegistry, options: RegistrationPreparation): Promise<RegistrationOperation>;
194
+ get id(): string;
195
+ preview(): {
196
+ update: boolean;
197
+ walletIdentity: Hex;
198
+ keys: RegistryReceivingKeys;
199
+ nonce: bigint;
200
+ deadline: bigint;
201
+ id: string;
202
+ status: RegistrationStatus;
203
+ chainId: bigint;
204
+ registryAddress: `0x${string}`;
205
+ };
206
+ authorize(options?: {
207
+ signal?: AbortSignal;
208
+ }): Promise<RegistrationOperation>;
209
+ prove(options?: ProverOptions): Promise<RegistrationOperation>;
210
+ private call;
211
+ exportTransaction(): Promise<TransactionCall>;
212
+ /** Associate a signed/broadcast transaction; ethers owns sending and receipt waiting. */
213
+ trackTransaction(transactionHash: string): RegistrationOperation;
214
+ reconcile(options?: {
215
+ transactionHash?: Hex;
216
+ signal?: AbortSignal;
217
+ }): Promise<RegistrationOperation>;
218
+ toJSON(): {
219
+ id: string;
220
+ kind: string;
221
+ status: RegistrationStatus;
222
+ };
223
+ }
224
+
225
+ interface AddressRegistryOptions {
226
+ lookup?: ReceivingKeyLookup;
227
+ expectedRuntimeCodeHash?: Hex;
228
+ }
229
+ /** Independent registry deployment and nonce domain, selected by the application. */
230
+ declare class AddressRegistry {
231
+ #private;
232
+ readonly context: Readonly<RegistryContext>;
233
+ readonly expectedRuntimeCodeHash: Hex | undefined;
234
+ constructor(context: RegistryContext, options?: AddressRegistryOptions);
235
+ validateDeployment(reader: Pick<RegistryReader, "getChainId" | "getCode">): Promise<void>;
236
+ prepareRegistration(options: RegistrationPreparation): Promise<RegistrationOperation>;
237
+ resolve(address: string): Promise<string>;
238
+ authorization(registration: AddressRegistration, options?: RegistrationOptions): _invisi_labs_core.WalletAuthorizationRequest;
239
+ publicInputs(registration: AddressRegistration, options?: RegistrationOptions): readonly [`0x${string}`, `0x${string}`, `0x${string}`];
240
+ buildCall(registration: AddressRegistration, proof: `0x${string}`, options?: RegistrationOptions): RegistrationCalldata;
241
+ }
242
+
243
+ declare const CREATE_CREDIT_FIELDS: readonly ["token", "sources", "nullifiers", "creditCommitment", "changeCommitment", "owner", "expiry", "deadline"];
244
+ /** Public checks cannot establish ownership or conservation: those are enforced by the proof. */
245
+ declare function validateCreateCreditRequest(c: TransactionContext, p: CreateCreditParams, cs: readonly Delivery[], funding?: FundingInput): {
246
+ sources: {
247
+ treeId: bigint;
248
+ merkleRoot: `0x${string}`;
249
+ }[];
250
+ nullifiers: `0x${string}`[];
251
+ actualCount: number;
252
+ sourceCount: number;
253
+ creditCommitment: `0x${string}`;
254
+ changeCommitment: `0x${string}`;
255
+ owner: `0x${string}`;
256
+ expiry: bigint;
257
+ deadline: bigint;
258
+ deliveries: Delivery[];
259
+ funding: FundingParams;
260
+ chainId: bigint;
261
+ protocolAddress: Hex;
262
+ tokenAddress: Hex;
263
+ now?: bigint;
264
+ };
265
+ declare function createCreditBaseInputs(c: TransactionContext, p: CreateCreditParams, cs: readonly Delivery[], f?: FundingInput): `0x${string}`[];
266
+ declare function createCreditPublicInputs(c: TransactionContext, p: CreateCreditParams, deliveries: readonly Delivery[], funding?: FundingInput): `0x${string}`[];
267
+ declare function createCreditRequestHash(p: CreateCreditParams, cs: readonly Delivery[], f?: FundingInput): Hex;
268
+ declare function encodeCreateCreditTypedData(c: TransactionContext, p: CreateCreditParams, deliveries: readonly Delivery[], funding?: FundingInput): {
269
+ domain: {
270
+ name: string;
271
+ version: string;
272
+ chainId: bigint;
273
+ verifyingContract: `0x${string}`;
274
+ };
275
+ types: {
276
+ readonly WalletAuthorization: readonly [{
277
+ readonly name: "operation";
278
+ readonly type: "bytes32";
279
+ }, {
280
+ readonly name: "statementHash";
281
+ readonly type: "bytes32";
282
+ }];
283
+ };
284
+ primaryType: "WalletAuthorization";
285
+ message: {
286
+ operation: `0x${string}`;
287
+ statementHash: `0x${string}`;
288
+ };
289
+ };
290
+ declare function encodeCreateCreditFundingTypedData(c: TransactionContext, p: CreateCreditParams, cs: readonly Delivery[], f: FundingInput): {
291
+ domain: {
292
+ name: string;
293
+ version: string;
294
+ chainId: bigint;
295
+ verifyingContract: Hex;
296
+ };
297
+ primaryType: "FundTransact";
298
+ types: {
299
+ FundTransact: readonly [{
300
+ readonly name: "requestHash";
301
+ readonly type: "bytes32";
302
+ }, {
303
+ readonly name: "payer";
304
+ readonly type: "address";
305
+ }, {
306
+ readonly name: "amount";
307
+ readonly type: "uint256";
308
+ }, {
309
+ readonly name: "sigNonce";
310
+ readonly type: "uint256";
311
+ }, {
312
+ readonly name: "deadline";
313
+ readonly type: "uint256";
314
+ }];
315
+ };
316
+ message: {
317
+ requestHash: `0x${string}`;
318
+ payer: `0x${string}`;
319
+ amount: bigint;
320
+ sigNonce: bigint;
321
+ deadline: bigint;
322
+ };
323
+ };
324
+ interface BuildCreateCreditCalldataParams {
325
+ context: TransactionContext;
326
+ proof: Hex;
327
+ params: CreateCreditParams;
328
+ deliveries: readonly Delivery[];
329
+ funding?: FundingInput;
330
+ caller?: Address;
331
+ }
332
+ declare function buildCreateCreditCalldata(p: BuildCreateCreditCalldataParams): {
333
+ data: Hex;
334
+ approveAmount: bigint;
335
+ };
336
+ /** Frame a raw direct proof from the proving backend for the Credit verifier adapter. */
337
+ declare function encodeCreditProof(proof: Hex): Hex;
338
+
339
+ declare const CREDIT_DRAW_CAPACITIES: readonly [1, 12, 50, 120];
340
+ declare function selectCreditDrawCircuit(count: number): {
341
+ name: string;
342
+ maxSize: 1 | 12 | 50 | 120;
343
+ publicInputCount: number;
344
+ totalBits: number;
345
+ };
346
+ declare function validateCreditDrawRequest(c: TransactionContext, p: CreditDrawParams, cs: readonly Delivery[]): {
347
+ sources: {
348
+ treeId: bigint;
349
+ merkleRoot: `0x${string}`;
350
+ }[];
351
+ nullifiers: `0x${string}`[];
352
+ remainderCommitments: `0x${string}`[];
353
+ recoveryAmounts: `0x${string}`[];
354
+ expiries: bigint[];
355
+ spender: `0x${string}`;
356
+ totalAmount: bigint;
357
+ deadline: bigint;
358
+ deliveries: Delivery[];
359
+ profile: {
360
+ name: string;
361
+ maxSize: 1 | 12 | 50 | 120;
362
+ publicInputCount: number;
363
+ totalBits: number;
364
+ };
365
+ chainId: bigint;
366
+ protocolAddress: Hex;
367
+ tokenAddress: Hex;
368
+ now?: bigint;
369
+ };
370
+ declare function creditDrawBaseInputs(c: TransactionContext, p: CreditDrawParams, cs: readonly Delivery[]): `0x${string}`[];
371
+ declare function validateCancelCreditRequest(c: TransactionContext, p: CancelCreditParams): {
372
+ source: {
373
+ treeId: bigint;
374
+ merkleRoot: `0x${string}`;
375
+ };
376
+ nullifier: `0x${string}`;
377
+ owner: `0x${string}`;
378
+ amount: bigint;
379
+ deadline: bigint;
380
+ chainId: bigint;
381
+ protocolAddress: Hex;
382
+ tokenAddress: Hex;
383
+ now?: bigint;
384
+ };
385
+ declare function cancelCreditBaseInputs(c: TransactionContext, p: CancelCreditParams): `0x${string}`[];
386
+ declare function validateTopUpCreditRequest(c: TransactionContext, p: TopUpCreditParams, cs: readonly Delivery[], funding?: FundingInput): {
387
+ creation: {
388
+ sources: {
389
+ treeId: bigint;
390
+ merkleRoot: `0x${string}`;
391
+ }[];
392
+ nullifiers: `0x${string}`[];
393
+ actualCount: number;
394
+ sourceCount: number;
395
+ creditCommitment: `0x${string}`;
396
+ changeCommitment: `0x${string}`;
397
+ owner: `0x${string}`;
398
+ expiry: bigint;
399
+ deadline: bigint;
400
+ deliveries: Delivery[];
401
+ funding: FundingParams;
402
+ chainId: bigint;
403
+ protocolAddress: Hex;
404
+ tokenAddress: Hex;
405
+ now?: bigint;
406
+ };
407
+ creditSource: {
408
+ treeId: bigint;
409
+ merkleRoot: `0x${string}`;
410
+ };
411
+ creditNullifier: `0x${string}`;
412
+ previousExpiry: bigint;
413
+ };
414
+ declare function topUpCreditBaseInputs(c: TransactionContext, p: TopUpCreditParams, cs: readonly Delivery[], f?: FundingInput): `0x${string}`[];
415
+ declare function cancelCreditRequestHash(p: CancelCreditParams): Hex;
416
+ declare function topUpCreditRequestHash(p: TopUpCreditParams, cs: readonly Delivery[], f?: FundingInput): Hex;
417
+ declare function encodeCancelCreditTypedData(c: TransactionContext, p: CancelCreditParams): {
418
+ domain: {
419
+ name: string;
420
+ version: string;
421
+ chainId: bigint;
422
+ verifyingContract: `0x${string}`;
423
+ };
424
+ types: {
425
+ readonly WalletAuthorization: readonly [{
426
+ readonly name: "operation";
427
+ readonly type: "bytes32";
428
+ }, {
429
+ readonly name: "statementHash";
430
+ readonly type: "bytes32";
431
+ }];
432
+ };
433
+ primaryType: "WalletAuthorization";
434
+ message: {
435
+ operation: `0x${string}`;
436
+ statementHash: `0x${string}`;
437
+ };
438
+ };
439
+ declare function encodeTopUpCreditTypedData(c: TransactionContext, p: TopUpCreditParams, deliveries: readonly Delivery[], funding?: FundingInput): {
440
+ domain: {
441
+ name: string;
442
+ version: string;
443
+ chainId: bigint;
444
+ verifyingContract: `0x${string}`;
445
+ };
446
+ types: {
447
+ readonly WalletAuthorization: readonly [{
448
+ readonly name: "operation";
449
+ readonly type: "bytes32";
450
+ }, {
451
+ readonly name: "statementHash";
452
+ readonly type: "bytes32";
453
+ }];
454
+ };
455
+ primaryType: "WalletAuthorization";
456
+ message: {
457
+ operation: `0x${string}`;
458
+ statementHash: `0x${string}`;
459
+ };
460
+ };
461
+ declare function encodeCreditDrawTypedData(c: TransactionContext, p: CreditDrawParams, deliveries: readonly Delivery[]): {
462
+ domain: {
463
+ name: string;
464
+ version: string;
465
+ chainId: bigint;
466
+ verifyingContract: `0x${string}`;
467
+ };
468
+ types: {
469
+ readonly WalletAuthorization: readonly [{
470
+ readonly name: "operation";
471
+ readonly type: "bytes32";
472
+ }, {
473
+ readonly name: "statementHash";
474
+ readonly type: "bytes32";
475
+ }];
476
+ };
477
+ primaryType: "WalletAuthorization";
478
+ message: {
479
+ operation: `0x${string}`;
480
+ statementHash: `0x${string}`;
481
+ };
482
+ };
483
+ declare function creditDrawPublicInputs(c: TransactionContext, p: CreditDrawParams, deliveries: readonly Delivery[]): `0x${string}`[];
484
+ declare function cancelCreditPublicInputs(c: TransactionContext, p: CancelCreditParams): `0x${string}`[];
485
+ declare function topUpCreditPublicInputs(c: TransactionContext, p: TopUpCreditParams, deliveries: readonly Delivery[], funding?: FundingInput): `0x${string}`[];
486
+ declare function encodeTopUpCreditFundingTypedData(c: TransactionContext, p: TopUpCreditParams, cs: readonly Delivery[], f: FundingInput): {
487
+ domain: {
488
+ name: string;
489
+ version: string;
490
+ chainId: bigint;
491
+ verifyingContract: Hex;
492
+ };
493
+ primaryType: "FundTransact";
494
+ types: {
495
+ FundTransact: readonly [{
496
+ readonly name: "requestHash";
497
+ readonly type: "bytes32";
498
+ }, {
499
+ readonly name: "payer";
500
+ readonly type: "address";
501
+ }, {
502
+ readonly name: "amount";
503
+ readonly type: "uint256";
504
+ }, {
505
+ readonly name: "sigNonce";
506
+ readonly type: "uint256";
507
+ }, {
508
+ readonly name: "deadline";
509
+ readonly type: "uint256";
510
+ }];
511
+ };
512
+ message: {
513
+ requestHash: `0x${string}`;
514
+ payer: `0x${string}`;
515
+ amount: bigint;
516
+ sigNonce: bigint;
517
+ deadline: bigint;
518
+ };
519
+ };
520
+ interface BuildCreditDrawCalldataParams {
521
+ context: TransactionContext;
522
+ proof: Hex;
523
+ params: CreditDrawParams;
524
+ deliveries: readonly Delivery[];
525
+ }
526
+ declare function buildCreditDrawCalldata(p: BuildCreditDrawCalldataParams): {
527
+ data: Hex;
528
+ nullifiers: readonly `0x${string}`[];
529
+ totalAmount: bigint;
530
+ };
531
+ interface BuildCancelCreditCalldataParams {
532
+ context: TransactionContext;
533
+ proof: Hex;
534
+ params: CancelCreditParams;
535
+ }
536
+ declare function buildCancelCreditCalldata(p: BuildCancelCreditCalldataParams): {
537
+ data: Hex;
538
+ };
539
+ interface BuildTopUpCreditCalldataParams {
540
+ context: TransactionContext;
541
+ proof: Hex;
542
+ params: TopUpCreditParams;
543
+ deliveries: readonly Delivery[];
544
+ funding?: FundingInput;
545
+ caller?: Address;
546
+ }
547
+ declare function buildTopUpCreditCalldata(p: BuildTopUpCreditCalldataParams): {
548
+ data: Hex;
549
+ approveAmount: bigint;
550
+ };
551
+
552
+ declare const TRANSACT_CAPACITIES: readonly [14, 56, 112, 168];
553
+ type TransactCapacity = (typeof TRANSACT_CAPACITIES)[number];
554
+ declare function selectTransactCapacity(inputs: number, outputs: number): TransactCapacity;
555
+ type TransactRequestParams = CrossTreeTransactParams;
556
+ declare function normalizeTransactRequest(c: TransactionContext, p: TransactRequestParams, cs: readonly Delivery[], funding?: FundingInput): {
557
+ capacity: 14 | 56 | 112 | 168;
558
+ sources: {
559
+ treeId: bigint;
560
+ merkleRoot: `0x${string}`;
561
+ }[];
562
+ nullifiers: `0x${string}`[];
563
+ outputCommitments: `0x${string}`[];
564
+ inputCount: number;
565
+ outputCount: number;
566
+ sourceCount: number;
567
+ inputTreeIds: bigint[];
568
+ merkleRoots: bigint[];
569
+ slotValues: bigint[];
570
+ deliveries: Delivery[];
571
+ deliveriesHash: `0x${string}`;
572
+ withdrawalAddress: `0x${string}`;
573
+ withdrawalAmount: bigint;
574
+ deadline: bigint;
575
+ depositAmount: bigint;
576
+ depositPayer: `0x${string}`;
577
+ funding: FundingParams;
578
+ chainId: bigint;
579
+ protocolAddress: Hex;
580
+ tokenAddress: Hex;
581
+ now?: bigint;
582
+ };
583
+ declare function transactPublicInputs(c: TransactionContext, p: TransactRequestParams, cs: readonly Delivery[], f?: FundingInput): `0x${string}`[];
584
+ declare function encodeTransactTypedData(c: TransactionContext, p: TransactRequestParams, deliveries: readonly Delivery[], f?: FundingInput): {
585
+ domain: {
586
+ name: string;
587
+ version: string;
588
+ chainId: bigint;
589
+ verifyingContract: `0x${string}`;
590
+ };
591
+ types: {
592
+ readonly WalletAuthorization: readonly [{
593
+ readonly name: "operation";
594
+ readonly type: "bytes32";
595
+ }, {
596
+ readonly name: "statementHash";
597
+ readonly type: "bytes32";
598
+ }];
599
+ };
600
+ primaryType: "WalletAuthorization";
601
+ message: {
602
+ operation: `0x${string}`;
603
+ statementHash: `0x${string}`;
604
+ };
605
+ };
606
+ declare function transactFundingRequestHash(proof: Hex, p: TransactRequestParams, cs: readonly Delivery[]): `0x${string}`;
607
+ declare function encodeTransactFundingTypedData(c: TransactionContext, proof: Hex, p: TransactRequestParams, cs: readonly Delivery[], funding: FundingInput): {
608
+ domain: {
609
+ name: string;
610
+ version: string;
611
+ chainId: bigint;
612
+ verifyingContract: Hex;
613
+ };
614
+ primaryType: "FundTransact";
615
+ types: {
616
+ FundTransact: readonly [{
617
+ readonly name: "requestHash";
618
+ readonly type: "bytes32";
619
+ }, {
620
+ readonly name: "payer";
621
+ readonly type: "address";
622
+ }, {
623
+ readonly name: "amount";
624
+ readonly type: "uint256";
625
+ }, {
626
+ readonly name: "sigNonce";
627
+ readonly type: "uint256";
628
+ }, {
629
+ readonly name: "deadline";
630
+ readonly type: "uint256";
631
+ }];
632
+ };
633
+ message: {
634
+ requestHash: `0x${string}`;
635
+ payer: `0x${string}`;
636
+ amount: bigint;
637
+ sigNonce: bigint;
638
+ deadline: bigint;
639
+ };
640
+ };
641
+ interface BuildTransactCalldataParams {
642
+ context: TransactionContext;
643
+ proof: Hex;
644
+ params: TransactRequestParams;
645
+ deliveries: readonly Delivery[];
646
+ funding?: FundingInput;
647
+ caller?: Address;
648
+ }
649
+ declare function buildTransactCalldata(p: BuildTransactCalldataParams): {
650
+ data: `0x${string}`;
651
+ capacity: 14 | 56 | 112 | 168;
652
+ approveAmount: bigint;
653
+ };
654
+ interface BuildTransactAggregateCalldataParams {
655
+ context: DeploymentContext & {
656
+ now?: bigint;
657
+ };
658
+ proof: Hex;
659
+ requests: readonly TransactRequest[];
660
+ caller?: Address;
661
+ }
662
+ declare function buildTransactAggregateCalldata(p: BuildTransactAggregateCalldataParams): {
663
+ data: Hex;
664
+ capacity: 14;
665
+ };
666
+ interface BuildShieldCalldataParams {
667
+ context: TransactionContext;
668
+ params: ShieldParams;
669
+ outputs: readonly ShieldOutput[];
670
+ deliveries: readonly Delivery[];
671
+ funding: FundingInput;
672
+ caller?: Address;
673
+ }
674
+ declare function validateShieldRequest(p: BuildShieldCalldataParams): Promise<FundingParams>;
675
+ declare function shieldFundingRequestHash(params: ShieldParams, outputs: readonly ShieldOutput[], cs: readonly Delivery[]): Hex;
676
+ declare function encodeShieldFundingTypedData(p: BuildShieldCalldataParams): Promise<{
677
+ domain: {
678
+ name: string;
679
+ version: string;
680
+ chainId: bigint;
681
+ verifyingContract: Hex;
682
+ };
683
+ primaryType: "FundShield";
684
+ types: {
685
+ FundShield: readonly [{
686
+ readonly name: "requestHash";
687
+ readonly type: "bytes32";
688
+ }, {
689
+ readonly name: "payer";
690
+ readonly type: "address";
691
+ }, {
692
+ readonly name: "amount";
693
+ readonly type: "uint256";
694
+ }, {
695
+ readonly name: "sigNonce";
696
+ readonly type: "uint256";
697
+ }, {
698
+ readonly name: "deadline";
699
+ readonly type: "uint256";
700
+ }];
701
+ };
702
+ message: {
703
+ requestHash: `0x${string}`;
704
+ payer: `0x${string}`;
705
+ amount: bigint;
706
+ sigNonce: bigint;
707
+ deadline: bigint;
708
+ };
709
+ }>;
710
+ declare function buildShieldCalldata(p: BuildShieldCalldataParams): Promise<{
711
+ data: Hex;
712
+ approveAmount: bigint;
713
+ }>;
714
+ /** Full active user-circuit public inputs: business statement followed by EIP-712 digest limbs. */
715
+ declare function transactUserPublicInputs(c: TransactionContext, p: TransactRequestParams, cs: readonly Delivery[], f?: FundingInput): `0x${string}`[];
716
+ type AggregateMemberInput = Pick<TransactRequest, "params" | "deliveries"> & {
717
+ funding?: FundingInput;
718
+ };
719
+ /** Atomic aggregate funding binds the member statement rather than the aggregate proof bytes. */
720
+ declare function aggregateMemberRequestHash(c: TransactionContext, r: AggregateMemberInput): Hex;
721
+ /** Router adapter business words (56 per member), not the aggregate circuit statement. */
722
+ declare function aggregatePublicInputs(c: TransactionContext, requests: readonly AggregateMemberInput[]): `0x${string}`[];
723
+ declare function encodeAggregateFundingTypedData(c: TransactionContext, r: AggregateMemberInput): {
724
+ domain: {
725
+ name: string;
726
+ version: string;
727
+ chainId: bigint;
728
+ verifyingContract: Hex;
729
+ };
730
+ primaryType: "FundTransact";
731
+ types: {
732
+ FundTransact: readonly [{
733
+ readonly name: "requestHash";
734
+ readonly type: "bytes32";
735
+ }, {
736
+ readonly name: "payer";
737
+ readonly type: "address";
738
+ }, {
739
+ readonly name: "amount";
740
+ readonly type: "uint256";
741
+ }, {
742
+ readonly name: "sigNonce";
743
+ readonly type: "uint256";
744
+ }, {
745
+ readonly name: "deadline";
746
+ readonly type: "uint256";
747
+ }];
748
+ };
749
+ message: {
750
+ requestHash: `0x${string}`;
751
+ payer: `0x${string}`;
752
+ amount: bigint;
753
+ sigNonce: bigint;
754
+ deadline: bigint;
755
+ };
756
+ };
757
+
758
+ interface TokenProtocolOptions {
759
+ expectedRuntimeCodeHash?: Hex;
760
+ }
761
+ /** A token-specific operation binding within a multi-token deployment. Pure builders never sign or submit. */
762
+ declare class TokenProtocol {
763
+ readonly context: Readonly<TransactionContext>;
764
+ readonly expectedRuntimeCodeHash: Hex | undefined;
765
+ constructor(context: TransactionContext, options?: TokenProtocolOptions);
766
+ validateDeployment(reader: Pick<ChainReader, "getChainId" | "getCode">, options?: {
767
+ requireRuntimeProfile?: boolean;
768
+ }): Promise<void>;
769
+ transact(request: Omit<BuildTransactCalldataParams, "context">): {
770
+ data: `0x${string}`;
771
+ capacity: 14 | 56 | 112 | 168;
772
+ approveAmount: bigint;
773
+ to: `0x${string}`;
774
+ value: bigint;
775
+ };
776
+ aggregate(request: Omit<BuildTransactAggregateCalldataParams, "context">): {
777
+ data: Hex;
778
+ capacity: 14;
779
+ to: `0x${string}`;
780
+ value: bigint;
781
+ };
782
+ shield(request: Omit<BuildShieldCalldataParams, "context">): Promise<{
783
+ data: Hex;
784
+ approveAmount: bigint;
785
+ to: `0x${string}`;
786
+ value: bigint;
787
+ }>;
788
+ createCredit(request: Omit<BuildCreateCreditCalldataParams, "context">): {
789
+ data: Hex;
790
+ approveAmount: bigint;
791
+ to: `0x${string}`;
792
+ value: bigint;
793
+ };
794
+ drawCredit(request: Omit<BuildCreditDrawCalldataParams, "context">): {
795
+ data: Hex;
796
+ nullifiers: readonly `0x${string}`[];
797
+ totalAmount: bigint;
798
+ to: `0x${string}`;
799
+ value: bigint;
800
+ };
801
+ cancelCredit(request: Omit<BuildCancelCreditCalldataParams, "context">): {
802
+ data: Hex;
803
+ to: `0x${string}`;
804
+ value: bigint;
805
+ };
806
+ topUpCredit(request: Omit<BuildTopUpCreditCalldataParams, "context">): {
807
+ data: Hex;
808
+ approveAmount: bigint;
809
+ to: `0x${string}`;
810
+ value: bigint;
811
+ };
812
+ }
813
+
814
+ interface ProtocolOptions {
815
+ deployment: ProtocolDeployment;
816
+ }
817
+ /** A multi-token deployment. Asset support is always read from the chain. */
818
+ declare class Protocol {
819
+ readonly deployment: Readonly<ProtocolDeployment>;
820
+ readonly context: Readonly<DeploymentContext>;
821
+ constructor(options: ProtocolOptions);
822
+ /** Load the selected deployment and verify its contract against Chain RPC before returning. */
823
+ static fromRpc(rpc: Pick<ProtocolRpcClient, "getDeployment">, provider: Provider, options?: {
824
+ signal?: AbortSignal;
825
+ }): Promise<Protocol>;
826
+ validateDeployment(connection: Provider | (Pick<ChainReader, "getChainId" | "getCode"> & {
827
+ getProtocolVersion?(address: Address): Promise<bigint>;
828
+ })): Promise<void>;
829
+ aggregate(request: Omit<BuildTransactAggregateCalldataParams, "context">): {
830
+ data: Hex;
831
+ capacity: 14;
832
+ to: `0x${string}`;
833
+ value: bigint;
834
+ };
835
+ /** Build an operation context for one asset within this same deployment. */
836
+ forToken(tokenAddress: Address): TokenProtocol;
837
+ }
838
+
839
+ interface VerifyNoteCommitmentParams {
840
+ walletIdentity: `0x${string}`;
841
+ tokenAddress: `0x${string}`;
842
+ amount: bigint;
843
+ nonce: `0x${string}`;
844
+ noteCommitment: `0x${string}`;
845
+ chainId: bigint;
846
+ }
847
+ declare function verifyNoteCommitment(params: VerifyNoteCommitmentParams): Promise<boolean>;
848
+ interface VerifyCreditCommitmentParams {
849
+ chainId: bigint;
850
+ spenderWalletIdentity: `0x${string}`;
851
+ ownerWalletIdentity: `0x${string}`;
852
+ spenderPayout: `0x${string}`;
853
+ ownerPayout: `0x${string}`;
854
+ tokenAddress: `0x${string}`;
855
+ amount: bigint;
856
+ nonce: bigint;
857
+ expiry: bigint;
858
+ creditSharedKey: bigint;
859
+ /** Server-returned value to verify against the locally recomputed commitment. */
860
+ creditCommitment: `0x${string}`;
861
+ }
862
+ /**
863
+ * Hashes the received shared key locally, recomputes the Credit leaf and compares it to the
864
+ * server-returned value. A mismatch means the server folded a wrong nonce
865
+ * (or other parameter) — the caller MUST abort and not create a Credit.
866
+ */
867
+ declare function verifyCreditCommitment(params: VerifyCreditCommitmentParams): Promise<boolean>;
868
+
869
+ interface BuildWithdrawalCalldataParams extends Omit<BuildTransactCalldataParams, "deliveries"> {
870
+ sourceNotes: readonly Note[];
871
+ }
872
+ /** Prepare a full public withdrawal whose spending authority is already proven in the supplied proof. */
873
+ declare function buildWithdrawalCalldata(p: BuildWithdrawalCalldataParams): Promise<{
874
+ data: `0x${string}`;
875
+ capacity: 14 | 56 | 112 | 168;
876
+ approveAmount: bigint;
877
+ }>;
878
+
879
+ interface NoteMembership {
880
+ note: Note;
881
+ treeId: bigint;
882
+ leafIndex: number;
883
+ path: readonly bigint[];
884
+ }
885
+ interface CreditMembership {
886
+ state: CreditDeliveryState;
887
+ treeId: bigint;
888
+ leafIndex: number;
889
+ path: readonly bigint[];
890
+ }
891
+ interface TransactWitnessParams extends Omit<BuildTransactCalldataParams, "proof" | "context"> {
892
+ inputs: readonly NoteMembership[];
893
+ outputs: readonly Note[];
894
+ authorization?: AuthorizedStatement;
895
+ target?: ProofTarget;
896
+ }
897
+ interface CreateCreditWitnessParams {
898
+ params: CreateCreditParams;
899
+ deliveries: readonly Delivery[];
900
+ funding?: FundingInput;
901
+ inputs: readonly NoteMembership[];
902
+ state: CreditDeliveryState;
903
+ change?: Note;
904
+ authorization: AuthorizedStatement;
905
+ }
906
+ interface DrawCreditWitnessParams {
907
+ params: CreditDrawParams;
908
+ deliveries: readonly Delivery[];
909
+ inputs: readonly CreditMembership[];
910
+ amounts: readonly bigint[];
911
+ authorization: AuthorizedStatement;
912
+ }
913
+ interface CancelCreditWitnessParams {
914
+ params: CancelCreditParams;
915
+ input: CreditMembership;
916
+ authorization: AuthorizedStatement;
917
+ }
918
+ interface TopUpCreditWitnessParams extends Omit<CreateCreditWitnessParams, "params"> {
919
+ params: TopUpCreditParams;
920
+ previous: CreditMembership;
921
+ }
922
+ /** Local typed assembly for authenticated circuit releases; no network or backend selection. */
923
+ declare class WitnessBuilder {
924
+ #private;
925
+ constructor(protocol: TokenProtocol);
926
+ static statement(circuitName: CircuitName, expectedPublicInputs: readonly Hex[], target?: ProofTarget): ProofStatement;
927
+ private context;
928
+ private authority;
929
+ private membership;
930
+ private noteLeaf;
931
+ private creditLeaf;
932
+ private noteInputs;
933
+ transact(p: TransactWitnessParams): Promise<ProvingRequest>;
934
+ private creation;
935
+ createCredit(p: CreateCreditWitnessParams): Promise<ProvingRequest>;
936
+ cancelCredit(p: CancelCreditWitnessParams): Promise<ProvingRequest>;
937
+ drawCredit(p: DrawCreditWitnessParams): Promise<ProvingRequest>;
938
+ topUpCredit(p: TopUpCreditWitnessParams): Promise<ProvingRequest>;
939
+ static registration(context: RegistryContext, registration: AddressRegistration, authorization: AuthorizedStatement, options?: RegistrationOptions): Promise<ProvingRequest>;
940
+ }
941
+
942
+ /**
943
+ * Query the selected factory. The caller still verifies the returned deployment profile.
944
+ * Calls `factory.getInstanceAddress(salt)` on-chain.
945
+ */
946
+ declare function resolveInstanceAddress(client: ContractRunner, factoryAddress: `0x${string}`, salt: `0x${string}`): Promise<`0x${string}`>;
947
+
948
+ export { type AddressRegistration, AddressRegistry, type AddressRegistryOptions, type AggregateMemberInput, type BuildCancelCreditCalldataParams, type BuildCreateCreditCalldataParams, type BuildCreditDrawCalldataParams, type BuildShieldCalldataParams, type BuildTopUpCreditCalldataParams, type BuildTransactAggregateCalldataParams, type BuildTransactCalldataParams, type BuildWithdrawalCalldataParams, CREATE_CREDIT_FIELDS, CREDIT_DRAW_CAPACITIES, type CancelCreditWitnessParams, type CanonicalReceipt, type ChainReader, type CreateCreditWitnessParams, type CreditMembership, type DrawCreditWitnessParams, EMPTY_FUNDING, EMPTY_PERMIT, FIELD_MODULUS, type FactoryReader, type FundingInput, type NoteMembership, Protocol, type ProtocolLog, type ProtocolOptions, type RegistrationCalldata, RegistrationOperation, type RegistrationOptions, type RegistrationPreparation, type RegistrationStatus, type RegistryContext, type RegistryReadClient, type RegistryReader, type RegistryReceivingKeys, TRANSACT_CAPACITIES, TokenProtocol, type TokenProtocolOptions, type TopUpCreditWitnessParams, type TransactCapacity, type TransactRequestParams, type TransactWitnessParams, type TransactionCall, type TransactionContext, type VerifyCreditCommitmentParams, type VerifyNoteCommitmentParams, WitnessBuilder, ZERO_ADDRESS, ZERO_WORD, aggregateMemberRequestHash, aggregatePublicInputs, buildCancelCreditCalldata, buildCreateCreditCalldata, buildCreditDrawCalldata, buildRegistrationCalldata, buildShieldCalldata, buildTopUpCreditCalldata, buildTransactAggregateCalldata, buildTransactCalldata, buildWithdrawalCalldata, cancelCreditBaseInputs, cancelCreditPublicInputs, cancelCreditRequestHash, checkDeadline, createCreditBaseInputs, createCreditPublicInputs, createCreditRequestHash, createRegistryReceivingKeyLookup, creditDrawBaseInputs, creditDrawPublicInputs, deliveriesHash, dense, encodeAggregateFundingTypedData, encodeCancelCreditTypedData, encodeCreateCreditFundingTypedData, encodeCreateCreditTypedData, encodeCreditDrawTypedData, encodeCreditProof, encodeShieldFundingTypedData, encodeTopUpCreditFundingTypedData, encodeTopUpCreditTypedData, encodeTransactFundingTypedData, encodeTransactTypedData, envelope, field, fundingFields, getEIP712Domain, known, normalizeContext, normalizeDelivery, normalizeFunding, normalizeSources, normalizeTransactRequest, notes, pad, registrationAuthorizationRequest, registrationPublicInputs, registrationTypedData, resolveInstanceAddress, selectCreditDrawCircuit, selectTransactCapacity, shieldFundingRequestHash, topUpCreditBaseInputs, topUpCreditPublicInputs, topUpCreditRequestHash, transactFundingRequestHash, transactPublicInputs, transactUserPublicInputs, uint, validateCancelCreditRequest, validateCreateCreditRequest, validateCreditDrawRequest, validateFundingSubmission, validateShieldRequest, validateTopUpCreditRequest, verifyCreditCommitment, verifyNoteCommitment, word };