@midnight-ntwrk/ledger-v9 1.0.0-rc.3

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 (33) hide show
  1. package/ledger-v9.d.ts +3378 -0
  2. package/midnight_ledger_wasm_v9.js +7 -0
  3. package/midnight_ledger_wasm_v9_bg.js +10472 -0
  4. package/midnight_ledger_wasm_v9_bg.wasm +0 -0
  5. package/midnight_ledger_wasm_v9_fs.js +73 -0
  6. package/package-lock.json +12 -0
  7. package/package.json +34 -0
  8. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline0.js +1 -0
  9. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline1.js +1 -0
  10. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline10.js +1 -0
  11. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline11.js +1 -0
  12. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline12.js +1 -0
  13. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline13.js +1 -0
  14. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline14.js +1 -0
  15. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline15.js +1 -0
  16. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline16.js +1 -0
  17. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline17.js +1 -0
  18. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline18.js +1 -0
  19. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline19.js +1 -0
  20. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline2.js +1 -0
  21. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline20.js +1 -0
  22. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline21.js +1 -0
  23. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline22.js +1 -0
  24. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline23.js +1 -0
  25. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline24.js +1 -0
  26. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline25.js +1 -0
  27. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline3.js +1 -0
  28. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline4.js +1 -0
  29. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline5.js +1 -0
  30. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline6.js +1 -0
  31. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline7.js +1 -0
  32. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline8.js +1 -0
  33. package/snippets/midnight-ledger-wasm-v9-e238ef26b2371309/inline9.js +1 -0
package/ledger-v9.d.ts ADDED
@@ -0,0 +1,3378 @@
1
+ /**
2
+ * An onchain data value, in field-aligned binary format.
3
+ */
4
+ export type Value = Array<Uint8Array>;
5
+ /**
6
+ * The alignment of an onchain field-aligned binary data value.
7
+ */
8
+ export type Alignment = AlignmentSegment[];
9
+ /**
10
+ * A segment in a larger {@link Alignment}.
11
+ */
12
+ export type AlignmentSegment = { tag: 'option', value: Alignment[] } | { tag: 'atom', value: AlignmentAtom };
13
+ /**
14
+ * A atom in a larger {@link Alignment}.
15
+ */
16
+ export type AlignmentAtom = { tag: 'compress' } | { tag: 'field' } | { tag: 'bytes', length: number };
17
+ /**
18
+ * An onchain data value, in field-aligned binary format, annotated with its
19
+ * alignment.
20
+ */
21
+ export type AlignedValue = { value: Value, alignment: Alignment };
22
+ /**
23
+ * A Zswap nullifier, as a hex-encoded 256-bit bitstring
24
+ */
25
+ export type Nullifier = string;
26
+ /**
27
+ * A Zswap coin commitment, as a hex-encoded 256-bit bitstring
28
+ */
29
+ export type CoinCommitment = string;
30
+ /**
31
+ * A contract address, as a hex-encoded 32-byte string
32
+ */
33
+ export type ContractAddress = string;
34
+ /**
35
+ * A user public key address, as a hex-encoded 32-byte string
36
+ */
37
+ export type UserAddress = string;
38
+ /**
39
+ * The internal identifier attached to a {@link TokenType}, as a hex-encoded string.
40
+ */
41
+ export type RawTokenType = string;
42
+
43
+ /**
44
+ * Unshielded token type (or color), as a hex-encoded 32-byte string
45
+ */
46
+ export type UnshieldedTokenType = { tag: 'unshielded', raw: RawTokenType };
47
+ /**
48
+ * Shielded token type (or color), as a hex-encoded 32-byte string
49
+ */
50
+ export type ShieldedTokenType = { tag: 'shielded', raw: RawTokenType };
51
+ /**
52
+ * Dust token type
53
+ */
54
+ export type DustTokenType = { tag: 'dust' };
55
+ /**
56
+ * A token type (or color), as a hex-encoded 32-byte string, shielded, unshielded, or Dust
57
+ */
58
+ export type TokenType = UnshieldedTokenType | ShieldedTokenType | DustTokenType;
59
+ /**
60
+ * A token domain seperator, the pre-stage of `TokenType`, as 32-byte bytearray
61
+ */
62
+ export type DomainSeparator = Uint8Array;
63
+ /**
64
+ * A user public key capable of receiving Zswap coins, as a hex-encoded 32-byte
65
+ * string
66
+ */
67
+ export type CoinPublicKey = string;
68
+ /**
69
+ * A running tally of synthetic resource costs.
70
+ */
71
+ export type RunningCost = {
72
+ /**
73
+ * The amount of (modelled) time spent reading from disk, measured in picoseconds.
74
+ */
75
+ readTime: bigint,
76
+ /**
77
+ * The amount of (modelled) time spent in single-threaded compute, measured in picoseconds.
78
+ */
79
+ computeTime: bigint,
80
+ /**
81
+ * The number of (modelled) bytes written.
82
+ */
83
+ bytesWritten: bigint,
84
+ /**
85
+ * The number of (modelled) bytes deleted.
86
+ */
87
+ bytesDeleted: bigint,
88
+ };
89
+
90
+ /**
91
+ * The fee prices for transaction
92
+ */
93
+ export type FeePrices = {
94
+ /**
95
+ * The overall price of a full block in an average cost dimension.
96
+ */
97
+ overallPrice: number,
98
+ /**
99
+ * The price factor of time spent reading from disk.
100
+ */
101
+ readFactor: number,
102
+ /**
103
+ * The price factor of time spent in single-threaded compute.
104
+ */
105
+ computeFactor: number,
106
+ /**
107
+ * The price factor of block usage.
108
+ */
109
+ blockUsageFactor: number,
110
+ /**
111
+ * The price factor of time spent writing to disk.
112
+ */
113
+ writeFactor: number,
114
+ }
115
+
116
+ /**
117
+ * Holds the coin secret key of a user, serialized as a hex-encoded 32-byte string
118
+ */
119
+ export class CoinSecretKey {
120
+ private constructor();
121
+
122
+ /**
123
+ * Clears the coin secret key, so that it is no longer usable nor held in memory
124
+ */
125
+ clear(): void;
126
+
127
+ yesIKnowTheSecurityImplicationsOfThis_serialize(): Uint8Array;
128
+
129
+ static deserialize(raw: Uint8Array): CoinSecretKey
130
+ }
131
+
132
+ /**
133
+ * A Zswap nonce, as a hex-encoded 256-bit string
134
+ */
135
+ export type Nonce = string;
136
+ /**
137
+ * The algorithm used for a particular signature.
138
+ *
139
+ * - `schnorr` corresponds to BIP-340 Schnorr signatures
140
+ * - `ecdsa` corresponds to ECDSA signatures over secp256k1
141
+ */
142
+ export type SignatureKind = 'schnorr' | 'ecdsa';
143
+ /**
144
+ * A hex-encoded signature verifying key annotated with its kind
145
+ */
146
+ export type SignatureVerifyingKey = { tag: SignatureKind, value: string };
147
+ /**
148
+ * A hex-encoded signing key annotated with its kind
149
+ */
150
+ export type SigningKey = { tag: SignatureKind, value: string };
151
+ /**
152
+ * A hex-encoded signature annotated with its kind
153
+ */
154
+ export type Signature = { tag: SignatureKind, value: string };
155
+ /**
156
+ * An internal encoding of a value of the proof systems scalar field
157
+ */
158
+ export type Fr = Uint8Array;
159
+ /**
160
+ * Information required to create a new coin, alongside details about the
161
+ * recipient
162
+ */
163
+ export type ShieldedCoinInfo = {
164
+ /**
165
+ * The coin's type, identifying the currency it represents
166
+ */
167
+ type: RawTokenType,
168
+ /**
169
+ * The coin's randomness, preventing it from colliding with other coins
170
+ */
171
+ nonce: Nonce,
172
+ /**
173
+ * The coin's value, in atomic units dependent on the currency
174
+ *
175
+ * Bounded to be a non-negative 64-bit integer
176
+ */
177
+ value: bigint,
178
+ };
179
+ /**
180
+ * Information required to spend an existing coin, alongside authorization of
181
+ * the owner
182
+ */
183
+ export type QualifiedShieldedCoinInfo = {
184
+ /**
185
+ * The coin's type, identifying the currency it represents
186
+ */
187
+ type: RawTokenType,
188
+ /**
189
+ * The coin's randomness, preventing it from colliding with other coins
190
+ */
191
+ nonce: Nonce,
192
+ /**
193
+ * The coin's value, in atomic units dependent on the currency
194
+ *
195
+ * Bounded to be a non-negative 64-bit integer
196
+ */
197
+ value: bigint,
198
+ /**
199
+ * The coin's location in the chain's Merkle tree of coin commitments
200
+ *
201
+ * Bounded to be a non-negative 64-bit integer
202
+ */
203
+ mt_index: bigint,
204
+ };
205
+
206
+ /**
207
+ * A key used to index into an array or map in the onchain VM
208
+ */
209
+ export type Key = { tag: 'value', value: AlignedValue } | { tag: 'stack' };
210
+ /**
211
+ * An individual operation in the onchain VM
212
+ *
213
+ * @typeParam R - `null` or {@link AlignedValue}, for gathering and verifying
214
+ * mode respectively
215
+ */
216
+ export type Op<R> = { noop: { n: number } } |
217
+ 'lt' |
218
+ 'eq' |
219
+ 'type' |
220
+ 'size' |
221
+ 'new' |
222
+ 'and' |
223
+ 'or' |
224
+ 'neg' |
225
+ 'log' |
226
+ 'root' |
227
+ 'pop' |
228
+ { popeq: { cached: boolean, result: R } } |
229
+ { addi: { immediate: number } } |
230
+ { subi: { immediate: number } } |
231
+ { push: { storage: boolean, value: EncodedStateValue } } |
232
+ { branch: { skip: number } } |
233
+ { jmp: { skip: number } } |
234
+ 'add' |
235
+ 'sub' |
236
+ { concat: { cached: boolean, n: number } } |
237
+ 'member' |
238
+ { rem: { cached: boolean } } |
239
+ { dup: { n: number } } |
240
+ { swap: { n: number } } |
241
+ { idx: { cached: boolean, pushPath: boolean, path: Key[] } } |
242
+ { ins: { cached: boolean, n: number } } |
243
+ 'ckpt';
244
+ /**
245
+ * The type of a log event embedded in {@link GatherResult}.
246
+ */
247
+ export type LogEventType = 'shielded-spend' |
248
+ 'shielded-receive' |
249
+ 'shielded-mint' |
250
+ 'shielded-burn' |
251
+ 'unshielded-spend' |
252
+ 'unshielded-receive' |
253
+ 'unshielded-mint' |
254
+ 'unshielded-burn' |
255
+ 'paused' |
256
+ 'unpaused' |
257
+ 'misc';
258
+ /**
259
+ * An individual result of observing the results of a non-verifying VM program
260
+ * execution
261
+ */
262
+ export type GatherResult = { tag: 'read', content: AlignedValue } |
263
+ { tag: 'log', content: { version: number, eventType: LogEventType, data: EncodedStateValue} };
264
+ /**
265
+ * An alternative encoding of {@link StateValue} for use in {@link Op} for
266
+ * technical reasons
267
+ */
268
+ export type EncodedStateValue = { tag: 'null' } |
269
+ { tag: 'cell', content: AlignedValue } |
270
+ { tag: 'map', content: Map<AlignedValue, EncodedStateValue> } |
271
+ { tag: 'array', content: EncodedStateValue[] } |
272
+ { tag: 'boundedMerkleTree', content: [number, Map<bigint, [Uint8Array, undefined]>] };
273
+ /**
274
+ * A transcript of operations, to be recorded in a transaction
275
+ */
276
+ export type Transcript<R> = {
277
+ /**
278
+ * The execution budget for this transcript, which {@link program} must not
279
+ * exceed
280
+ */
281
+ gas: RunningCost,
282
+ /**
283
+ * The effects of the transcript, which are checked before execution, and
284
+ * must match those constructed by {@link program}
285
+ */
286
+ effects: Effects,
287
+ /**
288
+ * The sequence of operations that this transcript captured
289
+ */
290
+ program: Op<R>[],
291
+ };
292
+ /**
293
+ * A public address that an entity can be identified by
294
+ */
295
+ export type PublicAddress = { tag: 'user', address: UserAddress } | { tag: 'contract', address: ContractAddress }
296
+ /**
297
+ * The context information of a call provided to the VM.
298
+ */
299
+ export type CallContext = {
300
+ ownAddress: ContractAddress,
301
+ /**
302
+ * The commitment indices map accessible to the contract.
303
+ */
304
+ comIndices: Map<CoinCommitment, number>
305
+ /**
306
+ * The seconds since the UNIX epoch that have elapsed
307
+ */
308
+ secondsSinceEpoch: bigint,
309
+ /**
310
+ * The maximum error on {@link secondsSinceEpoch} that should occur, as a
311
+ * positive seconds value
312
+ */
313
+ secondsSinceEpochErr: number,
314
+ /**
315
+ * The hash of the block prior to this transaction, as a hex-encoded string
316
+ */
317
+ parentBlockHash: string,
318
+ /**
319
+ * The balances held by the called contract at the time it was called.
320
+ */
321
+ balance: Map<TokenType, bigint>,
322
+ /**
323
+ * A public address identifying an entity.
324
+ */
325
+ caller?: PublicAddress,
326
+ /**
327
+ * The {@link secondsSinceEpoch} of the previous block
328
+ */
329
+ lastBlockTime: bigint,
330
+ };
331
+ /**
332
+ * Context information about the block forwarded to {@link CallContext}.
333
+ */
334
+ export type BlockContext = {
335
+ /**
336
+ * The seconds since the UNIX epoch that have elapsed
337
+ */
338
+ secondsSinceEpoch: bigint,
339
+ /**
340
+ * The maximum error on {@link secondsSinceEpoch} that should occur, as a
341
+ * positive seconds value
342
+ */
343
+ secondsSinceEpochErr: number,
344
+ /**
345
+ * The hash of the block prior to this transaction, as a hex-encoded string
346
+ */
347
+ parentBlockHash: string,
348
+ /**
349
+ * The {@link secondsSinceEpoch} of the previous block
350
+ */
351
+ lastBlockTime: bigint,
352
+ };
353
+ /**
354
+ * The contract-external effects of a transcript.
355
+ */
356
+ export type Effects = {
357
+ /**
358
+ * The nullifiers (spends) this contract call requires
359
+ */
360
+ claimedNullifiers: Nullifier[],
361
+ /**
362
+ * The coin commitments (outputs) this contract call requires, as coins
363
+ * received
364
+ */
365
+ claimedShieldedReceives: CoinCommitment[],
366
+ /**
367
+ * The coin commitments (outputs) this contract call requires, as coins
368
+ * sent
369
+ */
370
+ claimedShieldedSpends: CoinCommitment[],
371
+ /**
372
+ * The contracts called from this contract. The values are, in order:
373
+ *
374
+ * - The sequence number of this call
375
+ * - The contract being called
376
+ * - The entry point being called
377
+ * - The communications commitment
378
+ */
379
+ claimedContractCalls: Array<[bigint, ContractAddress, string, Fr]>,
380
+ /**
381
+ * The shielded tokens minted in this call, as a map from hex-encoded 256-bit domain
382
+ * separators to unsigned 64-bit integers.
383
+ */
384
+ shieldedMints: Map<string, bigint>,
385
+ /**
386
+ * The unshielded tokens minted in this call, as a map from hex-encoded 256-bit domain
387
+ * separators to unsigned 64-bit integers.
388
+ */
389
+ unshieldedMints: Map<string, bigint>,
390
+ /**
391
+ * The unshielded inputs this contract expects.
392
+ */
393
+ unshieldedInputs: Map<TokenType, bigint>,
394
+ /**
395
+ * The unshielded outputs this contract authorizes.
396
+ */
397
+ unshieldedOutputs: Map<TokenType, bigint>,
398
+ /**
399
+ * The unshielded UTXO outputs this contract expects to be present.
400
+ */
401
+ claimedUnshieldedSpends: Map<[TokenType, PublicAddress], bigint>,
402
+ };
403
+
404
+ /**
405
+ * A hex-encoded commitment of data shared between two contracts in a call
406
+ */
407
+ export type CommunicationCommitment = string;
408
+ /**
409
+ * The hex-encoded randomness to {@link CommunicationCommitment}
410
+ */
411
+ export type CommunicationCommitmentRand = string;
412
+
413
+ /**
414
+ * Samples a new {@link CommunicationCommitmentRand} uniformly
415
+ */
416
+ export function communicationCommitmentRandomness(): CommunicationCommitmentRand;
417
+
418
+ /**
419
+ * Computes the communication commitment corresponding to an input/output pair and randomness.
420
+ */
421
+ export function communicationCommitment(input: AlignedValue, output: AlignedValue, rand: CommunicationCommitmentRand): CommunicationCommitment;
422
+
423
+ /**
424
+ * Computes the (hex-encoded) hash of a given contract entry point. Used in
425
+ * composable contracts to reference the called contract's entry point ID
426
+ * in-circuit.
427
+ */
428
+ export function entryPointHash(entryPoint: string | Uint8Array): string;
429
+
430
+ /**
431
+ * Randomly samples a {@link SigningKey}. If `kind` is not supplied, assumes
432
+ * `schnorr`.
433
+ */
434
+ export function sampleSigningKey(kind?: SignatureKind): SigningKey;
435
+
436
+ /**
437
+ * Creates a {@link SigningKey} from provided Bip340 private key.
438
+ */
439
+ export function signingKeyFromBip340(data: Uint8Array): SigningKey;
440
+
441
+ /**
442
+ * Signs arbitrary data with the given signing key.
443
+ *
444
+ * WARNING: Do not expose access to this function for valuable keys for data
445
+ * that is not strictly controlled!
446
+ */
447
+ export function signData(key: SigningKey, data: Uint8Array): Signature;
448
+
449
+ /**
450
+ * Returns the verifying key for a given signing key
451
+ */
452
+ export function signatureVerifyingKey(sk: SigningKey): SignatureVerifyingKey;
453
+
454
+ /**
455
+ * Verifies if a signature is correct
456
+ */
457
+ export function verifySignature(vk: SignatureVerifyingKey, data: Uint8Array, signature: Signature): boolean;
458
+
459
+ /**
460
+ * Encode a raw {@link RawTokenType} into a `Uint8Array` for use in Compact's
461
+ * `RawTokenType` type
462
+ */
463
+ export function encodeRawTokenType(tt: RawTokenType): Uint8Array;
464
+
465
+ /**
466
+ * Decode a raw {@link RawTokenType} from a `Uint8Array` originating from Compact's
467
+ * `RawTokenType` type
468
+ */
469
+ export function decodeRawTokenType(tt: Uint8Array): RawTokenType;
470
+
471
+ /**
472
+ * Encode a {@link ContractAddress} into a `Uint8Array` for use in Compact's
473
+ * `ContractAddress` type
474
+ */
475
+ export function encodeContractAddress(addr: ContractAddress): Uint8Array;
476
+
477
+ /**
478
+ * Decode a {@link ContractAddress} from a `Uint8Array` originating from
479
+ * Compact's `ContractAddress` type
480
+ */
481
+ export function decodeContractAddress(addr: Uint8Array): ContractAddress;
482
+
483
+ /**
484
+ * Encode a {@link UserAddress} into a `Uint8Array` for use in Compact's
485
+ * `UserAddress` type
486
+ */
487
+ export function encodeUserAddress(addr: UserAddress): Uint8Array;
488
+
489
+ /**
490
+ * Decode a {@link UserAddress} from a `Uint8Array` originating from
491
+ * Compact's `UserAddress` type
492
+ */
493
+ export function decodeUserAddress(addr: Uint8Array): UserAddress;
494
+
495
+ /**
496
+ * Encode a {@link CoinPublicKey} into a `Uint8Array` for use in Compact's
497
+ * `CoinPublicKey` type
498
+ */
499
+ export function encodeCoinPublicKey(pk: CoinPublicKey): Uint8Array;
500
+
501
+ /**
502
+ * Decode a {@link CoinPublicKey} from a `Uint8Array` originating from Compact's
503
+ * `CoinPublicKey` type
504
+ */
505
+ export function decodeCoinPublicKey(pk: Uint8Array): CoinPublicKey;
506
+
507
+ /**
508
+ * Encode a {@link ShieldedCoinInfo} into a Compact's `ShieldedCoinInfo` TypeScript
509
+ * representation
510
+ */
511
+ export function encodeShieldedCoinInfo(coin: ShieldedCoinInfo): { color: Uint8Array, nonce: Uint8Array, value: bigint };
512
+
513
+ /**
514
+ * Encode a {@link QualifiedShieldedCoinInfo} into a Compact's `QualifiedShieldedCoinInfo`
515
+ * TypeScript representation
516
+ */
517
+ export function encodeQualifiedShieldedCoinInfo(coin: QualifiedShieldedCoinInfo): {
518
+ color: Uint8Array,
519
+ nonce: Uint8Array,
520
+ value: bigint,
521
+ mt_index: bigint
522
+ };
523
+
524
+ /**
525
+ * Decode a {@link ShieldedCoinInfo} from Compact's `ShieldedCoinInfo` TypeScript representation
526
+ */
527
+ export function decodeShieldedCoinInfo(coin: { color: Uint8Array, nonce: Uint8Array, value: bigint }): ShieldedCoinInfo;
528
+
529
+ /**
530
+ * Decode a {@link QualifiedShieldedCoinInfo} from Compact's `QualifiedShieldedCoinInfo`
531
+ * TypeScript representation
532
+ */
533
+ export function decodeQualifiedShieldedCoinInfo(coin: {
534
+ color: Uint8Array,
535
+ nonce: Uint8Array,
536
+ value: bigint,
537
+ mt_index: bigint
538
+ }): QualifiedShieldedCoinInfo;
539
+
540
+ /**
541
+ * Derives the raw {@link RawTokenType} associated with a particular
542
+ * {@link DomainSeparator} and contract.
543
+ */
544
+ export function rawTokenType(domain_sep: DomainSeparator, contract: ContractAddress): RawTokenType;
545
+
546
+ /**
547
+ * Samples a uniform contract address, for use in testing
548
+ */
549
+ export function sampleContractAddress(): ContractAddress;
550
+
551
+ /**
552
+ * Samples a uniform user address, for use in testing
553
+ */
554
+ export function sampleUserAddress(): UserAddress;
555
+
556
+ /**
557
+ * Samples a uniform raw token type, for use in testing to construct
558
+ * both the shielded and unshielded token types.
559
+ */
560
+ export function sampleRawTokenType(): RawTokenType;
561
+
562
+ /**
563
+ * A sample contract address
564
+ */
565
+ export function dummyContractAddress(): ContractAddress;
566
+
567
+ /**
568
+ * A sample user address
569
+ */
570
+ export function dummyUserAddress(): UserAddress;
571
+
572
+ /**
573
+ * Internal implementation of the runtime's coin commitment primitive.
574
+ * @internal
575
+ */
576
+ export function runtimeCoinCommitment(coin: AlignedValue, recipient: AlignedValue): AlignedValue;
577
+
578
+ /**
579
+ * Internal implementation of the runtime's coin nullifier primitive.
580
+ * @internal
581
+ */
582
+ export function runtimeCoinNullifier(coin: AlignedValue, sender_evidence: AlignedValue): AlignedValue;
583
+
584
+ /**
585
+ * Internal implementation of the Merkle tree leaf hash primitive.
586
+ * @internal
587
+ */
588
+ export function leafHash(value: AlignedValue): AlignedValue;
589
+
590
+ /**
591
+ * Internal implementation of the max aligned size primitive.
592
+ * @internal
593
+ */
594
+ export function maxAlignedSize(alignment: Alignment): bigint;
595
+
596
+ /**
597
+ * Returns the maximum representable value in the proof systems scalar field
598
+ * (that is, 1 less than the prime modulus)
599
+ */
600
+ export function maxField(): bigint;
601
+
602
+ /**
603
+ * Converts input, output, and transcript information into a proof preimage
604
+ * suitable to pass to a `ProvingProvider`.
605
+ *
606
+ * The `key_location` parameter is a string used to identify the circuit by
607
+ * proving machinery, for backwards-compatibility, if unset it defaults to
608
+ * `'dummy'`.
609
+ */
610
+ export function proofDataIntoSerializedPreimage(
611
+ input: AlignedValue,
612
+ output: AlignedValue,
613
+ public_transcript: Op<AlignedValue>[],
614
+ private_transcript_outputs: AlignedValue[],
615
+ key_location?: string,
616
+ ): Uint8Array;
617
+
618
+ /**
619
+ * Takes a bigint modulus the proof systems scalar field
620
+ */
621
+ export function bigIntModFr(x: bigint): bigint;
622
+
623
+ /**
624
+ * Returns the largest representable JubJub scalar (i.e. the JubJub scalar field modulus minus one).
625
+ */
626
+ export function maxJubjubScalar(): bigint;
627
+
628
+ /**
629
+ * Samples a random JubJub scalar, returned as a native field element.
630
+ */
631
+ export function jubjubSampleScalar(): Value;
632
+
633
+ /**
634
+ * Converts a native field element (BLS12-381 scalar) to a JubJub scalar field
635
+ * element, reducing modulo the JubJub scalar field modulus.
636
+ */
637
+ export function jubjubScalarFromNative(native: Value): Value;
638
+
639
+ /**
640
+ * Converts a JubJub scalar field element to a native field element (BLS12-381 scalar).
641
+ */
642
+ export function nativeFromJubjubScalar(jubjub: Value): Value;
643
+
644
+ /**
645
+ * Internal conversion between field-aligned binary values and bigints within
646
+ * the scalar field
647
+ * @internal
648
+ * @throws If the value does not encode a field element
649
+ */
650
+ export function valueToBigInt(x: Value): bigint;
651
+
652
+ /**
653
+ * Internal conversion between bigints and their field-aligned binary
654
+ * representation
655
+ * @internal
656
+ */
657
+ export function bigIntToValue(x: bigint): Value;
658
+
659
+ /**
660
+ * Internal implementation of the transient hash primitive
661
+ * @internal
662
+ * @throws If {@link val} does not have alignment {@link align}
663
+ */
664
+ export function transientHash(align: Alignment, val: Value): Value;
665
+
666
+ /**
667
+ * Internal implementation of the transient commitment primitive
668
+ * @internal
669
+ * @throws If {@link val} does not have alignment {@link align}, or
670
+ * {@link opening} does not encode a field element
671
+ */
672
+ export function transientCommit(align: Alignment, val: Value, opening: Value): Value;
673
+
674
+ /**
675
+ * Internal implementation of the persistent hash primitive
676
+ * @internal
677
+ * @throws If {@link val} does not have alignment {@link align}, or any
678
+ * component has a compress alignment
679
+ */
680
+ export function persistentHash(align: Alignment, val: Value): Value;
681
+
682
+ /**
683
+ * Internal implementation of the persistent commitment primitive
684
+ * @internal
685
+ * @throws If {@link val} does not have alignment {@link align},
686
+ * {@link opening} does not encode a 32-byte bytestring, or any component has a
687
+ * compress alignment
688
+ */
689
+ export function persistentCommit(align: Alignment, val: Value, opening: Value): Value;
690
+
691
+ /**
692
+ * Internal implementation of the degrade to transient primitive
693
+ * @internal
694
+ * @throws If {@link persistent} does not encode a 32-byte bytestring
695
+ */
696
+ export function degradeToTransient(persistent: Value): Value;
697
+
698
+ /**
699
+ * Internal implementation of the upgrade from transient primitive
700
+ * @internal
701
+ * @throws If {@link transient} does not encode a field element
702
+ */
703
+ export function upgradeFromTransient(transient: Value): Value;
704
+
705
+ /**
706
+ * Internal implementation of the hash to curve primitive
707
+ * @internal
708
+ * @throws If {@link val} does not have alignment {@link align}
709
+ */
710
+ export function hashToCurve(align: Alignment, val: Value): Value;
711
+
712
+ /**
713
+ * Internal implementation of the elliptic curve addition primitive
714
+ * @internal
715
+ * @throws If either input does not encode an elliptic curve point
716
+ */
717
+ export function ecAdd(a: Value, b: Value): Value;
718
+
719
+ /**
720
+ * Internal implementation of the elliptic curve multiplication primitive
721
+ * @internal
722
+ * @throws If {@link a} does not encode an elliptic curve point or {@link b}
723
+ * does not encode a field element
724
+ */
725
+ export function ecMul(a: Value, b: Value): Value;
726
+
727
+ /**
728
+ * Internal implementation of the elliptic curve generator multiplication
729
+ * primitive
730
+ * @internal
731
+ * @throws if {@link val} does not encode a field element
732
+ */
733
+ export function ecMulGenerator(val: Value): Value;
734
+
735
+ /**
736
+ * Runs a VM program against an initial stack, with an optional gas limit
737
+ */
738
+ export function runProgram(initial: VmStack, ops: Op<null>[], cost_model: CostModel, gas_limit?: RunningCost): VmResults;
739
+
740
+ /**
741
+ * An individual operation, or entry point of a contract, consisting primarily
742
+ * of a ZK verifier keys, potentially for different versions of the proving
743
+ * system.
744
+ *
745
+ * Only the latest available version is exposed to this API.
746
+ *
747
+ * Note that the serialized form of the key is checked on initialization
748
+ */
749
+ export class ContractOperation {
750
+ constructor();
751
+
752
+ verifierKey: Uint8Array;
753
+
754
+ serialize(): Uint8Array;
755
+
756
+ static deserialize(raw: Uint8Array): ContractOperation;
757
+
758
+ toString(compact?: boolean): string;
759
+ }
760
+
761
+ /**
762
+ * A committee permitted to make changes to this contract. If a threshold of
763
+ * the public keys in this committee sign off, they can change the rules of
764
+ * this contract, or recompile it for a new version.
765
+ *
766
+ * If the threshold is greater than the number of committee members, it is
767
+ * impossible for them to sign anything.
768
+ */
769
+ export class ContractMaintenanceAuthority {
770
+ /**
771
+ * Constructs a new authority from its components
772
+ *
773
+ * If not supplied, `counter` will default to `0n`. Values should be
774
+ * non-negative, and at most 2^32 - 1.
775
+ *
776
+ * At deployment, `counter` must be `0n`, and any subsequent update should
777
+ * set counter to exactly one greater than the current value.
778
+ */
779
+ constructor(committee: Array<SignatureVerifyingKey>, threshold: number, counter?: bigint);
780
+
781
+ /**
782
+ * The committee public keys
783
+ */
784
+ readonly committee: Array<SignatureVerifyingKey>;
785
+ /**
786
+ * How many keys must sign rule changes
787
+ */
788
+ readonly threshold: number;
789
+ /**
790
+ * The replay protection counter
791
+ */
792
+ readonly counter: bigint;
793
+
794
+ serialize(): Uint8Array;
795
+
796
+ static deserialize(raw: Uint8Array): ContractMaintenanceAuthority;
797
+
798
+ toString(compact?: boolean): string;
799
+ }
800
+
801
+ /**
802
+ * The state of a contract, consisting primarily of the {@link data} accessible
803
+ * directly to the contract, and the map of {@link ContractOperation}s that can
804
+ * be called on it, the keys of which can be accessed with {@link operations},
805
+ * and the individual operations can be read with {@link operation} and written
806
+ * to with {@link setOperation}.
807
+ */
808
+ export class ContractState {
809
+ /**
810
+ * Creates a blank contract state
811
+ */
812
+ constructor();
813
+
814
+ /**
815
+ * Return a list of the entry points currently registered on this contract
816
+ */
817
+ operations(): Array<string | Uint8Array>
818
+
819
+ /**
820
+ * Get the operation at a specific entry point name
821
+ */
822
+ operation(operation: string | Uint8Array): ContractOperation | undefined;
823
+
824
+ /**
825
+ * Set a specific entry point name to contain a given operation
826
+ */
827
+ setOperation(operation: string | Uint8Array, value: ContractOperation): void;
828
+
829
+ /**
830
+ * Runs a series of operations against the current state, and returns the
831
+ * results
832
+ */
833
+ query(query: Op<null>[], cost_model: CostModel): GatherResult[];
834
+
835
+ serialize(): Uint8Array;
836
+
837
+ static deserialize(raw: Uint8Array): ContractState;
838
+
839
+ toString(compact?: boolean): string;
840
+
841
+ /**
842
+ * The current value of the primary state of the contract
843
+ */
844
+ data: ChargedState;
845
+ /**
846
+ * The maintenance authority associated with this contract
847
+ */
848
+ maintenanceAuthority: ContractMaintenanceAuthority;
849
+ /**
850
+ * The public balances held by this contract
851
+ */
852
+ balance: Map<TokenType, bigint>;
853
+ }
854
+
855
+ /**
856
+ * Provides the information needed to fully process a transaction, including
857
+ * information about the rest of the transaction, and the state of the chain at
858
+ * the time of execution.
859
+ */
860
+ export class QueryContext {
861
+ /**
862
+ * Construct a basic context from a contract's address and current state
863
+ * value
864
+ */
865
+ constructor(state: ChargedState, address: ContractAddress);
866
+
867
+ /**
868
+ * Register a given coin commitment as being accessible at a specific index,
869
+ * for use when receiving coins in-contract, and needing to record their
870
+ * index to later spend them
871
+ */
872
+ insertCommitment(comm: CoinCommitment, index: bigint): QueryContext;
873
+
874
+ /**
875
+ * Internal counterpart to {@link insertCommitment}; upgrades an encoded
876
+ * {@link ShieldedCoinInfo} to an encoded {@link QualifiedShieldedCoinInfo} using the
877
+ * inserted commitments
878
+ * @internal
879
+ */
880
+ qualify(coin: Value): Value | undefined;
881
+
882
+ /**
883
+ * Runs a transcript in verifying mode against the current query context,
884
+ * outputting a new query context, with the {@link state} and {@link effects}
885
+ * from after the execution.
886
+ */
887
+ runTranscript(transcript: Transcript<AlignedValue>, cost_model: CostModel): QueryContext;
888
+
889
+ /**
890
+ * Runs a sequence of operations in gather mode, returning the results of the
891
+ * gather.
892
+ */
893
+ query(ops: Op<null>[], cost_model: CostModel, gas_limit?: RunningCost): QueryResults;
894
+
895
+ /**
896
+ * Converts the QueryContext to {@link VmStack}.
897
+ */
898
+ toVmStack(): VmStack;
899
+
900
+ toString(compact?: boolean): string;
901
+
902
+ /**
903
+ * The address of the contract
904
+ */
905
+ readonly address: ContractAddress;
906
+ /**
907
+ * The block-level information accessible to the contract
908
+ */
909
+ block: CallContext;
910
+ /**
911
+ * The commitment indices map accessible to the contract, primarily via
912
+ * {@link qualify}
913
+ */
914
+ readonly comIndices: Map<CoinCommitment, bigint>;
915
+ /**
916
+ * The effects that occurred during execution against this context, should
917
+ * match those declared in a {@link Transcript}
918
+ */
919
+ effects: Effects;
920
+ /**
921
+ * The current contract state retained in the context
922
+ */
923
+ readonly state: ChargedState;
924
+ }
925
+
926
+ /**
927
+ * A cost model for calculating transaction fees
928
+ */
929
+ export class CostModel {
930
+ private constructor();
931
+
932
+ /**
933
+ * The initial cost model of Midnight
934
+ */
935
+ static initialCostModel(): CostModel;
936
+
937
+ toString(compact?: boolean): string;
938
+ }
939
+
940
+ /**
941
+ * The results of making a query against a specific state or context
942
+ */
943
+ export class QueryResults {
944
+ private constructor();
945
+
946
+ toString(compact?: boolean): string;
947
+
948
+ /**
949
+ * The context state after executing the query. This can be used to execute
950
+ * further queries
951
+ */
952
+ readonly context: QueryContext;
953
+ /**
954
+ * Any events/results that occurred during or from the query
955
+ */
956
+ readonly events: GatherResult[];
957
+ /**
958
+ * The measured cost of executing the query
959
+ */
960
+ readonly gasCost: RunningCost;
961
+ }
962
+
963
+ /**
964
+ * Represents a fixed-depth Merkle tree storing hashed data, whose preimages
965
+ * are unknown
966
+ */
967
+ export class StateBoundedMerkleTree {
968
+ /**
969
+ * Create a blank tree with the given height
970
+ */
971
+ constructor(height: number);
972
+
973
+ /**
974
+ * Internal implementation of the merkle tree root primitive.
975
+ * Returns undefined if the tree has not been fully hashed.
976
+ * @internal
977
+ */
978
+ root(): AlignedValue | undefined;
979
+
980
+ /**
981
+ * Internal implementation of the finding path primitive.
982
+ * Returns undefined if the leaf is not in the tree.
983
+ * @internal
984
+ */
985
+ findPathForLeaf(
986
+ leaf: AlignedValue,
987
+ indexStart?: bigint,
988
+ indexEnd?: bigint,
989
+ alreadyHashed?: boolean,
990
+ ): AlignedValue | undefined;
991
+
992
+ /**
993
+ * Internal implementation of the path construction primitive
994
+ * @internal
995
+ * @throws If the index is out-of-bounds for the tree
996
+ */
997
+ pathForLeaf(index: bigint, leaf: AlignedValue): AlignedValue;
998
+
999
+ /**
1000
+ * Inserts a value into the Merkle tree, returning the updated tree
1001
+ * @throws If the index is out-of-bounds for the tree
1002
+ */
1003
+ update(index: bigint, leaf: AlignedValue): StateBoundedMerkleTree;
1004
+
1005
+ /**
1006
+ * Rehashes the tree, updating all internal hashes and ensuring all
1007
+ * node hashes are present. Necessary because the onchain runtime does
1008
+ * not automatically rehash trees.
1009
+ */
1010
+ rehash(): StateBoundedMerkleTree;
1011
+
1012
+ /**
1013
+ * Erases all but necessary hashes between, and inclusive of, `start` and
1014
+ * `end` inidices @internal
1015
+ * @throws If the indices are out-of-bounds for the tree, or `end < start`
1016
+ */
1017
+ collapse(start: bigint, end: bigint): StateBoundedMerkleTree;
1018
+
1019
+ toString(compact?: boolean): string;
1020
+
1021
+ readonly height: number;
1022
+ }
1023
+
1024
+ /**
1025
+ * Represents a key-value map, where keys are {@link AlignedValue}s, and values
1026
+ * are {@link StateValue}s.
1027
+ */
1028
+ export class StateMap {
1029
+ constructor();
1030
+
1031
+ keys(): AlignedValue[];
1032
+
1033
+ get(key: AlignedValue): StateValue | undefined;
1034
+
1035
+ insert(key: AlignedValue, value: StateValue): StateMap;
1036
+
1037
+ remove(key: AlignedValue): StateMap;
1038
+
1039
+ toString(compact?: boolean): string;
1040
+ }
1041
+
1042
+ /**
1043
+ * Represents a {@link StateValue} with storage annotations.
1044
+ *
1045
+ * These track the state usage that has been charged for so far.
1046
+ */
1047
+ export class ChargedState {
1048
+ constructor(state: StateValue);
1049
+ readonly state: StateValue;
1050
+ toString(compact?: boolean): string;
1051
+ }
1052
+
1053
+ /**
1054
+ * Represents the core of a contract's state, and recursively represents each
1055
+ * of its components.
1056
+ *
1057
+ * There are different *classes* of state values:
1058
+ * - `null`
1059
+ * - Cells of {@link AlignedValue}s
1060
+ * - Maps from {@link AlignedValue}s to state values
1061
+ * - Bounded Merkle trees containing {@link AlignedValue} leaves
1062
+ * - Short (\<= 15 element) arrays of state values
1063
+ *
1064
+ * State values are *immutable*, any operations that mutate states will return
1065
+ * a new state instead.
1066
+ */
1067
+ export class StateValue {
1068
+ private constructor();
1069
+
1070
+ type(): 'null' | 'cell' | 'map' | 'array' | 'boundedMerkleTree';
1071
+
1072
+ static newNull(): StateValue;
1073
+
1074
+ static newCell(value: AlignedValue): StateValue;
1075
+
1076
+ static newMap(map: StateMap): StateValue;
1077
+
1078
+ static newBoundedMerkleTree(tree: StateBoundedMerkleTree): StateValue;
1079
+
1080
+ static newArray(): StateValue;
1081
+
1082
+ arrayPush(value: StateValue): StateValue;
1083
+
1084
+ asCell(): AlignedValue;
1085
+
1086
+ asMap(): StateMap | undefined;
1087
+
1088
+ asBoundedMerkleTree(): StateBoundedMerkleTree | undefined;
1089
+
1090
+ asArray(): StateValue[] | undefined;
1091
+
1092
+ logSize(): number;
1093
+
1094
+ toString(compact?: boolean): string;
1095
+
1096
+ /**
1097
+ * @internal
1098
+ */
1099
+ encode(): EncodedStateValue;
1100
+
1101
+ /**
1102
+ * @internal
1103
+ */
1104
+ static decode(value: EncodedStateValue): StateValue;
1105
+ }
1106
+
1107
+ /**
1108
+ * Represents the results of a VM call
1109
+ */
1110
+ export class VmResults {
1111
+ private constructor();
1112
+
1113
+ toString(compact?: boolean): string;
1114
+
1115
+ /**
1116
+ * The events that got emitted by this VM invocation
1117
+ */
1118
+ readonly events: GatherResult[];
1119
+ /**
1120
+ * The computed gas cost of running this VM invocation
1121
+ */
1122
+ readonly gasCost: RunningCost;
1123
+ /**
1124
+ * The VM stack at the end of the VM invocation
1125
+ */
1126
+ readonly stack: VmStack;
1127
+ }
1128
+
1129
+ /**
1130
+ * Represents the state of the VM's stack at a specific point. The stack is an
1131
+ * array of {@link StateValue}s, each of which is also annotated with whether
1132
+ * it is "strong" or "weak"; that is, whether it is permitted to be stored
1133
+ * on-chain or not.
1134
+ */
1135
+ export class VmStack {
1136
+ constructor();
1137
+
1138
+ push(value: StateValue, is_strong: boolean): void;
1139
+
1140
+ removeLast(): void;
1141
+
1142
+ length(): number;
1143
+
1144
+ get(idx: number): StateValue | undefined;
1145
+
1146
+ isStrong(idx: number): boolean | undefined;
1147
+
1148
+ toString(compact?: boolean): string;
1149
+ }
1150
+
1151
+
1152
+ /**
1153
+ * A zero-knowledge proof.
1154
+ */
1155
+ export class Proof {
1156
+ constructor(data: String);
1157
+ serialize(): Uint8Array;
1158
+ static deserialize(raw: Uint8Array): Proof;
1159
+ toString(compact?: boolean): string;
1160
+ instance: 'proof';
1161
+ private type_: 'proof';
1162
+ }
1163
+
1164
+ /**
1165
+ * The preimage, or data required to produce, a {@link Proof}.
1166
+ */
1167
+ export class PreProof {
1168
+ constructor(data: String);
1169
+ serialize(): Uint8Array;
1170
+ static deserialize(raw: Uint8Array): PreProof;
1171
+ toString(compact?: boolean): string;
1172
+ instance: 'pre-proof';
1173
+ private type_: 'pre-proof';
1174
+ }
1175
+
1176
+ /**
1177
+ * A unit type used to indicate the absence of proofs.
1178
+ */
1179
+ export class NoProof {
1180
+ constructor();
1181
+ toString(compact?: boolean): string;
1182
+ instance: 'no-proof';
1183
+ private type_: 'no-proof';
1184
+ }
1185
+
1186
+ /**
1187
+ * How proofs are currently being represented, between:
1188
+ * - Actual zero-knowledge proofs, as should be transmitted to the network
1189
+ * - The data required to *produce* proofs, for constructing and preparing
1190
+ * transactions.
1191
+ * - Proofs not being provided, largely for testing use or replaying already
1192
+ * validated transactions.
1193
+ */
1194
+ export type Proofish = Proof | PreProof | NoProof;
1195
+
1196
+ /**
1197
+ * A Fiat-Shamir proof of exponent binding (or ephemerally signing) an
1198
+ * {@link Intent}.
1199
+ */
1200
+ export class Binding {
1201
+ constructor(data: String);
1202
+ serialize(): Uint8Array;
1203
+ static deserialize(raw: Uint8Array): Binding;
1204
+ toString(compact?: boolean): string;
1205
+ instance: 'binding';
1206
+ private type_: 'binding';
1207
+ }
1208
+
1209
+ /**
1210
+ * Information that will be used to bind an {@link Intent} in the future, but
1211
+ * does not yet prevent modification of it.
1212
+ */
1213
+ export class PreBinding {
1214
+ constructor(data: String);
1215
+ serialize(): Uint8Array;
1216
+ static deserialize(raw: Uint8Array): PreBinding;
1217
+ toString(compact?: boolean): string;
1218
+ instance: 'pre-binding';
1219
+ private type_: 'pre-binding';
1220
+ }
1221
+
1222
+ export class NoBinding {
1223
+ constructor(data: String);
1224
+ serialize(): Uint8Array;
1225
+ static deserialize(raw: Uint8Array): NoBinding;
1226
+ toString(compact?: boolean): string;
1227
+ instance: 'no-binding';
1228
+ private type_: 'no-binding';
1229
+ }
1230
+
1231
+ /**
1232
+ * Whether an intent has binding cryptography applied or not. An intent's
1233
+ * content can no longer be modified after it is {@link Binding}.
1234
+ */
1235
+ export type Bindingish = Binding | PreBinding | NoBinding;
1236
+
1237
+ export class SignatureEnabled {
1238
+ constructor(data: Signature);
1239
+ serialize(): Uint8Array;
1240
+ static deserialize(raw: Uint8Array): SignatureEnabled;
1241
+ toString(compact?: boolean): string;
1242
+ readonly instance: 'signature';
1243
+ private type_: 'signature';
1244
+ readonly value: Signature;
1245
+ }
1246
+
1247
+ export class SignatureErased {
1248
+ constructor();
1249
+ toString(compact?: boolean): string;
1250
+ readonly instance: 'signature-erased';
1251
+ private type_: 'signature-erased';
1252
+ }
1253
+
1254
+ export type Signaturish = SignatureEnabled | SignatureErased;
1255
+
1256
+ /**
1257
+ * A type representing a transaction that has not been proven yet
1258
+ */
1259
+ export type UnprovenInput = ZswapInput<PreProof>;
1260
+
1261
+ /**
1262
+ * A type representing a transaction output that has not been proven yet.
1263
+ */
1264
+ export type UnprovenOutput = ZswapOutput<PreProof>;
1265
+
1266
+ /**
1267
+ * A type representing a transaction transient that has not been proven yet.
1268
+ */
1269
+ export type UnprovenTransient = ZswapTransient<PreProof>;
1270
+
1271
+ /**
1272
+ * A type representing an offer that has not been proven yet.
1273
+ */
1274
+ export type UnprovenOffer = ZswapOffer<PreProof>;
1275
+
1276
+ /**
1277
+ * A type representing an intent that has not been proven yet.
1278
+ */
1279
+ export type UnprovenIntent = Intent<SignatureEnabled, PreProof, PreBinding>;
1280
+
1281
+ /**
1282
+ * An interactions with a contract
1283
+ */
1284
+ export type ContractAction<P extends Proofish> = ContractCall<P> | ContractDeploy | MaintenanceUpdate;
1285
+
1286
+ /**
1287
+ * Strictness criteria for evaluating transaction well-formedness, used for
1288
+ * disabling parts of transaction validation for testing.
1289
+ */
1290
+ export class WellFormedStrictness {
1291
+ constructor();
1292
+
1293
+ /**
1294
+ * Whether to require the transaction to have a non-negative balance
1295
+ */
1296
+ enforceBalancing: boolean;
1297
+ /**
1298
+ * Whether to validate Midnight-native (non-contract) proofs in the transaction
1299
+ */
1300
+ verifyNativeProofs: boolean;
1301
+ /**
1302
+ * Whether to validate contract proofs in the transaction
1303
+ */
1304
+ verifyContractProofs: boolean;
1305
+ /**
1306
+ * Whether to enforce the transaction byte limit
1307
+ */
1308
+ enforceLimits: boolean;
1309
+ /**
1310
+ * Whether to enforce the signature verification
1311
+ */
1312
+ verifySignatures: boolean;
1313
+ }
1314
+
1315
+ /**
1316
+ * Contains the raw file contents required for proving
1317
+ */
1318
+ export type ProvingKeyMaterial = {
1319
+ proverKey: Uint8Array,
1320
+ verifierKey: Uint8Array,
1321
+ ir: Uint8Array,
1322
+ };
1323
+
1324
+ /**
1325
+ * A modelled cost of a transaction or block.
1326
+ */
1327
+ export type SyntheticCost = {
1328
+ /**
1329
+ * The amount of (modelled) time spent reading from disk, measured in picoseconds.
1330
+ */
1331
+ readTime: bigint,
1332
+ /**
1333
+ * The amount of (modelled) time spent in single-threaded compute, measured in picoseconds.
1334
+ */
1335
+ computeTime: bigint,
1336
+ /**
1337
+ * The number of bytes of blockspace used
1338
+ */
1339
+ blockUsage: bigint,
1340
+ /**
1341
+ * The net number of (modelled) bytes written, i.e. max(0, absolute written bytes less deleted bytes).
1342
+ */
1343
+ bytesWritten: bigint,
1344
+ /**
1345
+ * The number of (modelled) bytes written temporarily or overwritten.
1346
+ */
1347
+ bytesChurned: bigint,
1348
+ };
1349
+
1350
+ /**
1351
+ * A normalized form of {@link SyntheticCost}.
1352
+ */
1353
+ export type NormalizedCost = {
1354
+ /**
1355
+ * The amount of (modelled) time spent reading from disk, measured in picoseconds.
1356
+ */
1357
+ readTime: number,
1358
+ /**
1359
+ * The amount of (modelled) time spent in single-threaded compute, measured in picoseconds.
1360
+ */
1361
+ computeTime: number,
1362
+ /**
1363
+ * The number of bytes of blockspace used
1364
+ */
1365
+ blockUsage: number,
1366
+ /**
1367
+ * The net number of (modelled) bytes written, i.e. max(0, absolute written bytes less deleted bytes).
1368
+ */
1369
+ bytesWritten: number,
1370
+ /**
1371
+ * The number of (modelled) bytes written temporarily or overwritten.
1372
+ */
1373
+ bytesChurned: number,
1374
+ };
1375
+
1376
+ /**
1377
+ * An event emitted by the ledger
1378
+ */
1379
+ export class Event {
1380
+ private constructor();
1381
+ serialize(): Uint8Array;
1382
+ static deserialize(raw: Uint8Array): Event;
1383
+ toString(compact?: boolean): string;
1384
+ readonly source: EventSource;
1385
+ readonly content: EventDetails;
1386
+ }
1387
+
1388
+ /**
1389
+ * Where an event originated from
1390
+ */
1391
+ export type EventSource = {
1392
+ /**
1393
+ * The hash of the originating transaction.
1394
+ */
1395
+ transactionHash: TransactionHash,
1396
+ /**
1397
+ * The logical event segment, that is, during which segment's execution the
1398
+ * event was emitted.
1399
+ */
1400
+ logicalSegment: number,
1401
+ /**
1402
+ * The physical event segment, that is, the segment of the transaction this
1403
+ * event's trigger is contained in.
1404
+ */
1405
+ physicalSegment: number,
1406
+ };
1407
+
1408
+ /**
1409
+ * Details of the event emitted
1410
+ */
1411
+ export type EventDetails =
1412
+ {
1413
+ tag: 'zswapInput',
1414
+ nullifier: Nullifier,
1415
+ contract: ContractAddress | undefined,
1416
+ } | {
1417
+ tag: 'zswapOutput',
1418
+ commitment: CoinCommitment,
1419
+ contract: ContractAddress | undefined,
1420
+ mtIndex: bigint,
1421
+ } | {
1422
+ tag: 'dustInitialUtxo',
1423
+ generation: DustGenerationInfo,
1424
+ generationIndex: bigint,
1425
+ blockTime: Date,
1426
+ } | {
1427
+ tag: 'dustGenerationDtimeUpdate',
1428
+ update: TreeInsertionPath<DustGenerationInfo>,
1429
+ blockTime: Date,
1430
+ } | {
1431
+ tag: 'dustSpendProcessed',
1432
+ commitment: DustCommitment,
1433
+ commitmentIndex: bigint,
1434
+ nullifier: DustNullifier,
1435
+ vFee: bigint,
1436
+ declaredTime: Date,
1437
+ blockTime: Date,
1438
+ } | {
1439
+ tag: 'contractLog',
1440
+ address: ContractAddress,
1441
+ entryPoint: Uint8Array | string,
1442
+ loggedItem: {
1443
+ version: number,
1444
+ eventType: LogEventType,
1445
+ data: EncodedStateValue,
1446
+ },
1447
+ } |
1448
+ // Other variants may be added and some events are not yet supported in this API.
1449
+ { tag: string };
1450
+
1451
+ /**
1452
+ * A path evidencing how to insert an entry into a Merkle tree, even if it is
1453
+ * collapsed.
1454
+ */
1455
+ export type TreeInsertionPath<A> = {
1456
+ leafHash: string,
1457
+ annotation: A,
1458
+ path: TreeInsertionPathEntry[],
1459
+ };
1460
+
1461
+ /**
1462
+ * A single entry in a {@link TreeInsertionPath}.
1463
+ */
1464
+ export type TreeInsertionPathEntry = {
1465
+ hash: bigint | undefined,
1466
+ goesLeft: boolean,
1467
+ };
1468
+
1469
+ /**
1470
+ * A secret key for the Dust, used to derive Dust UTxO nonces and prove credentials to spend Dust UTxOs
1471
+ */
1472
+ export class DustSecretKey {
1473
+ private constructor();
1474
+
1475
+ /**
1476
+ * Temporary method to create an instance of {@link DustSecretKey} from a bigint (its natural representation)
1477
+ * @param bigint
1478
+ */
1479
+ static fromBigint(bigint: bigint): DustSecretKey;
1480
+
1481
+ /**
1482
+ * Create an instance of {@link DustSecretKey} from a seed.
1483
+ * @param seed
1484
+ */
1485
+ static fromSeed(seed: Uint8Array): DustSecretKey;
1486
+
1487
+ publicKey: DustPublicKey;
1488
+
1489
+ /**
1490
+ * Clears the dust secret key, so that it is no longer usable nor held in memory
1491
+ */
1492
+ clear(): void;
1493
+ }
1494
+
1495
+ // TODO: Doc comments
1496
+ export type DustPublicKey = bigint;
1497
+ export type DustInitialNonce = string;
1498
+ export type DustNonce = bigint;
1499
+ export type DustCommitment = bigint;
1500
+ export type DustNullifier = bigint;
1501
+
1502
+ export function sampleDustSecretKey(): DustSecretKey;
1503
+
1504
+ export function updatedValue(ctime: Date, initialValue: bigint, genInfo: DustGenerationInfo, now: Date, params: DustParameters): bigint;
1505
+
1506
+ export type DustOutput = {
1507
+ initialValue: bigint,
1508
+ owner: DustPublicKey,
1509
+ nonce: DustNonce,
1510
+ seq: number,
1511
+ ctime: Date,
1512
+ backingNight: DustInitialNonce,
1513
+ };
1514
+
1515
+ export type QualifiedDustOutput = {
1516
+ initialValue: bigint,
1517
+ owner: DustPublicKey,
1518
+ nonce: DustNonce,
1519
+ seq: number,
1520
+ ctime: Date,
1521
+ backingNight: DustInitialNonce,
1522
+ mtIndex: bigint,
1523
+ };
1524
+
1525
+ export type DustGenerationInfo = {
1526
+ value: bigint,
1527
+ owner: DustPublicKey,
1528
+ nonce: DustInitialNonce,
1529
+ dtime: Date | undefined,
1530
+ };
1531
+
1532
+ export type DustGenerationUniquenessInfo = {
1533
+ value: bigint,
1534
+ owner: DustPublicKey,
1535
+ nonce: DustInitialNonce,
1536
+ };
1537
+
1538
+ export class DustSpend<P extends Proofish> {
1539
+ private constructor();
1540
+ serialize(): Uint8Array;
1541
+ static deserialize<P extends Proofish>(markerP: P['instance'], raw: Uint8Array): DustSpend<P>;
1542
+ toString(compact?: boolean): string;
1543
+ readonly vFee: bigint;
1544
+ readonly oldNullifier: DustNullifier;
1545
+ readonly newCommitment: DustCommitment;
1546
+ readonly proof: P;
1547
+ }
1548
+
1549
+ export class DustRegistration<S extends Signaturish> {
1550
+ constructor(markerS: S['instance'], nightKey: SignatureVerifyingKey, dustAddress: DustPublicKey | undefined, allowFeePayment: bigint, signature?: S);
1551
+ serialize(): Uint8Array;
1552
+ static deserialize<S extends Signaturish>(markerS: S['instance'], raw: Uint8Array): DustRegistration<S>;
1553
+ toString(compact?: boolean): string;
1554
+ nightKey: SignatureVerifyingKey;
1555
+ dustAddress: DustPublicKey | undefined;
1556
+ allowFeePayment: bigint;
1557
+ signature: S;
1558
+ }
1559
+
1560
+ export class DustActions<S extends Signaturish, P extends Proofish> {
1561
+ constructor(markerS: S['instance'], markerP: P['instance'], ctime: Date, spends?: DustSpend<P>[], registrations?: DustRegistration<S>[]);
1562
+ serialize(): Uint8Array;
1563
+ static deserialize<S extends Signaturish, P extends Proofish>(markerS: S['instance'], markerP: P['instance'], raw: Uint8Array): DustActions<S, P>;
1564
+ toString(compact?: boolean): string;
1565
+ spends: DustSpend<P>[];
1566
+ registrations: DustRegistration<S>[];
1567
+ ctime: Date;
1568
+ }
1569
+
1570
+ export class DustParameters {
1571
+ constructor(nightDustRatio: bigint, generationDecayRate: bigint, dustGracePeriodSeconds: bigint);
1572
+ serialize(): Uint8Array;
1573
+ static deserialize(raw: Uint8Array): DustParameters;
1574
+ toString(compact?: boolean): string;
1575
+ nightDustRatio: bigint;
1576
+ generationDecayRate: bigint;
1577
+ dustGracePeriodSeconds: bigint;
1578
+ readonly timeToCapSeconds: bigint;
1579
+ }
1580
+
1581
+ export class DustUtxoState {
1582
+ constructor();
1583
+ serialize(): Uint8Array;
1584
+ static deserialize(raw: Uint8Array): DustUtxoState;
1585
+ toString(compact?: boolean): string;
1586
+ }
1587
+
1588
+ export class DustGenerationState {
1589
+ constructor();
1590
+ serialize(): Uint8Array;
1591
+ static deserialize(raw: Uint8Array): DustGenerationState;
1592
+ toString(compact?: boolean): string;
1593
+ }
1594
+
1595
+ export class DustGenerationTreeInsertionPath {
1596
+ constructor(state: DustGenerationState, index: bigint);
1597
+ serialize(): Uint8Array;
1598
+ static deserialize(raw: Uint8Array): DustGenerationTreeInsertionPath;
1599
+ toString(compact?: boolean): string;
1600
+ }
1601
+
1602
+ export class DustStateMerkleTreeCollapsedUpdate {
1603
+ private constructor();
1604
+ static newFromGenerationTree(state: DustGenerationState, start: bigint, end: bigint): DustStateMerkleTreeCollapsedUpdate;
1605
+ static newFromCommitmentTree(state: DustUtxoState, start: bigint, end: bigint): DustStateMerkleTreeCollapsedUpdate;
1606
+ serialize(): Uint8Array;
1607
+ static deserialize(raw: Uint8Array): DustStateMerkleTreeCollapsedUpdate;
1608
+ toString(compact?: boolean): string;
1609
+ }
1610
+
1611
+ export class DustState {
1612
+ constructor();
1613
+ serialize(): Uint8Array;
1614
+ static deserialize(raw: Uint8Array): DustState;
1615
+ toString(compact?: boolean): string;
1616
+ readonly utxo: DustUtxoState;
1617
+ readonly generation: DustGenerationState;
1618
+ }
1619
+
1620
+ export class DustStateChanges {
1621
+ constructor(source: TransactionHash, receivedUtxos: QualifiedDustOutput[], spentUtxos: QualifiedDustOutput[]);
1622
+ toString(compact?: boolean): string;
1623
+ /**
1624
+ * The source of the state change, as a hex-encoded string
1625
+ */
1626
+ readonly source: TransactionHash;
1627
+ /**
1628
+ * The UTXOs that were received in this state change
1629
+ */
1630
+ readonly receivedUtxos: QualifiedDustOutput[];
1631
+ /**
1632
+ * The UTXOs that were spent in this state change
1633
+ */
1634
+ readonly spentUtxos: QualifiedDustOutput[];
1635
+ }
1636
+
1637
+ export class DustLocalStateWithChanges {
1638
+ private constructor();
1639
+ /**
1640
+ * The updated local state after replaying events
1641
+ */
1642
+ readonly state: DustLocalState;
1643
+ /**
1644
+ * The state changes that occurred during the replay
1645
+ */
1646
+ readonly changes: DustStateChanges[];
1647
+ }
1648
+
1649
+ export class DustLocalState {
1650
+ constructor(params: DustParameters);
1651
+ walletBalance(time: Date): bigint;
1652
+ generationInfo(qdo: QualifiedDustOutput): DustGenerationInfo | undefined;
1653
+ insertGenerationInfo(generationIndex: bigint, generation: DustGenerationInfo, initialNonce?: DustInitialNonce): DustLocalState;
1654
+ removeGenerationInfo(generationIndex: bigint, generation: DustGenerationInfo): DustLocalState;
1655
+ collapseGenerationTree(generationIndexStart: bigint, generationIndexEnd: bigint): DustLocalState;
1656
+ applyGenerationCollapsedUpdate(update: DustStateMerkleTreeCollapsedUpdate): DustLocalState;
1657
+ updateGenerationTreeFromEvidence(evidence: DustGenerationTreeInsertionPath): DustLocalState;
1658
+ generatingTreeRoot(): bigint | undefined;
1659
+ insertCommitment(commitmentIndex: bigint, qdo: QualifiedDustOutput, own_qdo: boolean): DustLocalState;
1660
+ removeCommitment(commitmentIndex: bigint): DustLocalState;
1661
+ collapseCommitmentTree(commitmentIndexStart: bigint, commitmentIndexEnd: bigint): DustLocalState;
1662
+ applyCommitmentCollapsedUpdate(update: DustStateMerkleTreeCollapsedUpdate): DustLocalState;
1663
+ commitmentTreeRoot(): bigint | undefined;
1664
+ spend(sk: DustSecretKey, utxo: QualifiedDustOutput, vFee: bigint, ctime: Date): [DustLocalState, DustSpend<PreProof>];
1665
+ processTtls(time: Date): DustLocalState;
1666
+ replayEvents(sk: DustSecretKey, events: Event[]): DustLocalState;
1667
+ replayEventsWithChanges(sk: DustSecretKey, events: Event[]): DustLocalStateWithChanges;
1668
+ /**
1669
+ * Replays a direct concatenation of serialized ledger events. Otherwise, acts as `replayEventsWithChanges`.
1670
+ */
1671
+ replayRawEvents(sk: DustSecretKey, rawEvents: Uint8Array): DustLocalStateWithChanges;
1672
+ addUtxo(nullifier: DustNullifier, utxo: QualifiedDustOutput, pendingUntil?: Date): DustLocalState;
1673
+ findUtxoByNullifier(nullifier: DustNullifier): QualifiedDustOutput | undefined;
1674
+ removeUtxo(nullifier: DustNullifier): DustLocalState;
1675
+ serialize(): Uint8Array;
1676
+ static deserialize(raw: Uint8Array): DustLocalState;
1677
+ toString(compact?: boolean): string;
1678
+ readonly utxos: QualifiedDustOutput[];
1679
+ readonly nullifiers: Map<DustNullifier, QualifiedDustOutput>;
1680
+ readonly params: DustParameters;
1681
+ syncTime: Date;
1682
+ readonly generatingTreeFirstFree: bigint;
1683
+ readonly commitmentTreeFirstFree: bigint;
1684
+ }
1685
+
1686
+ /**
1687
+ * Creates a payload for proving a specific transaction through the proof server
1688
+ * @deprecated Use `Transaction.prove` instead.
1689
+ */
1690
+ export function createProvingTransactionPayload(
1691
+ transaction: UnprovenTransaction,
1692
+ proving_data: Map<string, ProvingKeyMaterial>,
1693
+ ): Uint8Array;
1694
+
1695
+ /**
1696
+ * Creates a payload for proving a specific proof through the proof server
1697
+ */
1698
+ export function createProvingPayload(
1699
+ serializedPreimage: Uint8Array,
1700
+ overwriteBindingInput: bigint | undefined,
1701
+ keyMaterial?: ProvingKeyMaterial,
1702
+ ): Uint8Array;
1703
+
1704
+ /**
1705
+ * Creates a payload for checking a specific proof through the proof server
1706
+ */
1707
+ export function createCheckPayload(
1708
+ serializedPreimage: Uint8Array,
1709
+ ir?: Uint8Array,
1710
+ ): Uint8Array;
1711
+
1712
+ /**
1713
+ * Parses the result of a proof-server check call
1714
+ */
1715
+ export function parseCheckResult(result: Uint8Array): (bigint | undefined)[]
1716
+
1717
+ /**
1718
+ * The state of the Midnight ledger
1719
+ */
1720
+ export class LedgerState {
1721
+ /**
1722
+ * Intializes from a Zswap state, with an empty contract set
1723
+ */
1724
+ constructor(network_id: string, zswap: ZswapChainState);
1725
+
1726
+ /**
1727
+ * A fully blank state
1728
+ */
1729
+ static blank(network_id: string): LedgerState;
1730
+
1731
+ /**
1732
+ * Applies a {@link Transaction}
1733
+ */
1734
+ apply(
1735
+ transaction: VerifiedTransaction,
1736
+ context: TransactionContext
1737
+ ): [LedgerState, TransactionResult];
1738
+
1739
+ /**
1740
+ * Applies a system transaction to this ledger state.
1741
+ */
1742
+ applySystemTx(transaction: SystemTransaction, tblock: Date): [LedgerState, Event[]];
1743
+
1744
+ /**
1745
+ * Indexes into the contract state map with a given contract address
1746
+ */
1747
+ index(address: ContractAddress): ContractState | undefined;
1748
+
1749
+ /**
1750
+ * Sets the state of a given contract address from a {@link ChargedState}
1751
+ */
1752
+ updateIndex(address: ContractAddress, state: ChargedState, balance: Map<TokenType, bigint>): LedgerState;
1753
+
1754
+ serialize(): Uint8Array;
1755
+
1756
+ static deserialize(raw: Uint8Array): LedgerState;
1757
+
1758
+ toString(compact?: boolean): string;
1759
+
1760
+ /**
1761
+ * Carries out a post-block update, which does amortized bookkeeping that
1762
+ * only needs to be done once per state change.
1763
+ *
1764
+ * Typically, `postBlockUpdate` should be run after any (sequence of)
1765
+ * (system)-transaction application(s).
1766
+ */
1767
+ postBlockUpdate(tblock: Date, detailedBlockFullness?: NormalizedCost, overallBlockFullness?: number): LedgerState;
1768
+
1769
+ /**
1770
+ * Retrieves the balance of the treasury for a specific token type.
1771
+ */
1772
+ treasuryBalance(token_type: TokenType): bigint;
1773
+
1774
+ /**
1775
+ * How much in block rewards a recipient is owed and can claim.
1776
+ */
1777
+ unclaimedBlockRewards(recipient: UserAddress): bigint;
1778
+
1779
+ /**
1780
+ * How much in bridged night a recipient is owed and can claim.
1781
+ */
1782
+ bridgeReceiving(recipient: UserAddress): bigint;
1783
+
1784
+ /**
1785
+ * Allows distributing the specified amount of Night to the recipient's address.
1786
+ * Use is for testing purposes only.
1787
+ */
1788
+ testingDistributeNight(recipient: UserAddress, amount: bigint, tblock: Date): LedgerState;
1789
+
1790
+ /**
1791
+ * Constructs a ledger state with the given genesis parameterisation, using
1792
+ * the default initial parameters. Allows seeding the locked, reserve, and
1793
+ * treasury NIGHT pools so that subsequent system transactions (e.g.
1794
+ * {@link testingUnlockToTreasury}) can be exercised
1795
+ *
1796
+ * Use is for testing purposes only.
1797
+ */
1798
+ static testingFromGenesis(network_id: string, lockedPool: bigint, reservePool: bigint, treasury: bigint): LedgerState;
1799
+
1800
+ /**
1801
+ * Applies an `UnlockToTreasury` system transaction, moving the given amount
1802
+ * of Night from the locked pool into the treasury.
1803
+ *
1804
+ * Use is for testing purposes only.
1805
+ */
1806
+ testingUnlockToTreasury(amount: bigint, tblock: Date): LedgerState;
1807
+
1808
+ /**
1809
+ * Applies an `UnlockToReserve` system transaction, moving the given amount
1810
+ * of Night from the locked pool into the reserve pool.
1811
+ *
1812
+ * Use is for testing purposes only.
1813
+ */
1814
+ testingUnlockToReserve(amount: bigint, tblock: Date): LedgerState;
1815
+
1816
+ /**
1817
+ * The remaining size of the locked Night pool.
1818
+ */
1819
+ readonly lockedPool: bigint;
1820
+
1821
+ /**
1822
+ * The size of the reserve Night pool
1823
+ */
1824
+ readonly reservePool: bigint;
1825
+
1826
+ /**
1827
+ * How much in bridged night a recipient is owed and can claim.
1828
+ */
1829
+ bridgeReceiving(recipient: UserAddress): bigint;
1830
+
1831
+ /**
1832
+ * The remaining unrewarded supply of native tokens.
1833
+ */
1834
+ readonly blockRewardPool: bigint;
1835
+ /**
1836
+ * The Zswap part of the ledger state
1837
+ */
1838
+ readonly zswap: ZswapChainState;
1839
+ /**
1840
+ * The unshielded utxos present
1841
+ */
1842
+ readonly utxo: UtxoState;
1843
+ /**
1844
+ * The dust subsystem state
1845
+ */
1846
+ readonly dust: DustState;
1847
+ /**
1848
+ * The parameters of the ledger
1849
+ */
1850
+ parameters: LedgerParameters;
1851
+ }
1852
+
1853
+ /**
1854
+ * An unspent transaction output
1855
+ */
1856
+ export type Utxo = {
1857
+ /**
1858
+ * The amount of tokens this UTXO represents
1859
+ */
1860
+ value: bigint,
1861
+ /**
1862
+ * The address owning these tokens.
1863
+ */
1864
+ owner: UserAddress,
1865
+ /**
1866
+ * The token type of this UTXO
1867
+ */
1868
+ type: RawTokenType,
1869
+ /**
1870
+ * The hash of the intent outputting this UTXO
1871
+ */
1872
+ intentHash: IntentHash,
1873
+ /**
1874
+ * The output number of this UTXO in its parent {@link Intent}.
1875
+ */
1876
+ outputNo: number,
1877
+ };
1878
+
1879
+ /**
1880
+ * An output appearing in an {@link Intent}.
1881
+ */
1882
+ export type UtxoOutput = {
1883
+ /**
1884
+ * The amount of tokens this UTXO represents
1885
+ */
1886
+ value: bigint,
1887
+ /**
1888
+ * The address owning these tokens.
1889
+ */
1890
+ owner: UserAddress,
1891
+ /**
1892
+ * The token type of this UTXO
1893
+ */
1894
+ type: RawTokenType,
1895
+ };
1896
+
1897
+ /**
1898
+ * Converts a bare signature public key to its corresponding address.
1899
+ */
1900
+ export function addressFromKey(key: SignatureVerifyingKey): UserAddress;
1901
+
1902
+ /**
1903
+ * An input appearing in an {@link Intent}, or a user's local book-keeping.
1904
+ */
1905
+ export type UtxoSpend = {
1906
+ /**
1907
+ * The amount of tokens this UTXO represents
1908
+ */
1909
+ value: bigint,
1910
+ /**
1911
+ * The signing key owning these tokens.
1912
+ */
1913
+ owner: SignatureVerifyingKey,
1914
+ /**
1915
+ * The token type of this UTXO
1916
+ */
1917
+ type: RawTokenType,
1918
+ /**
1919
+ * The hash of the intent outputting this UTXO
1920
+ */
1921
+ intentHash: IntentHash,
1922
+ /**
1923
+ * The output number of this UTXO in its parent {@link Intent}.
1924
+ */
1925
+ outputNo: number,
1926
+ };
1927
+
1928
+ /**
1929
+ * Metadata about a specific UTXO
1930
+ */
1931
+ export class UtxoMeta {
1932
+ constructor(ctime: Date);
1933
+ /**
1934
+ * The creation time of the UTXO, that is, when it was inserted into the state.
1935
+ */
1936
+ ctime: Date;
1937
+ }
1938
+ /**
1939
+ * The sub-state for unshielded UTXOs
1940
+ */
1941
+ export class UtxoState {
1942
+ static new(utxos: Map<Utxo, UtxoMeta>): UtxoState;
1943
+ /**
1944
+ * Lookup the metadata for a specific UTXO.
1945
+ */
1946
+ lookupMeta(utxo: Utxo): UtxoMeta | undefined;
1947
+
1948
+ /**
1949
+ * The set of valid UTXOs
1950
+ */
1951
+ readonly utxos: Set<Utxo>;
1952
+
1953
+ /**
1954
+ * Filters out the UTXOs owned by a specific user address
1955
+ */
1956
+ filter(addr: UserAddress): Set<Utxo>;
1957
+
1958
+ /**
1959
+ * Given a prior UTXO state, produce the set differences `this \ prior`, and
1960
+ * `prior \ this`, optionally filtered by a further condition.
1961
+ *
1962
+ * Note that this should be more efficient than iterating or manifesting the
1963
+ * {@link utxos} value, as the low-level implementation can avoid traversing
1964
+ * shared sub-structures.
1965
+ */
1966
+ delta(prior: UtxoState, filterBy?: (utxo: Utxo) => boolean): [Set<Utxo>, Set<Utxo>];
1967
+ }
1968
+
1969
+ /**
1970
+ * A single contract call segment
1971
+ */
1972
+ export class ContractCall<P extends Proofish> {
1973
+ private constructor();
1974
+
1975
+ toString(compact?: boolean): string;
1976
+
1977
+ /**
1978
+ * The address being called
1979
+ */
1980
+ readonly address: ContractAddress;
1981
+ /**
1982
+ * The communication commitment of this call
1983
+ */
1984
+ readonly communicationCommitment: CommunicationCommitment;
1985
+ /**
1986
+ * The entry point being called
1987
+ */
1988
+ readonly entryPoint: Uint8Array | string;
1989
+ /**
1990
+ * The fallible execution stage transcript
1991
+ */
1992
+ readonly fallibleTranscript: Transcript<AlignedValue> | undefined;
1993
+ /**
1994
+ * The guaranteed execution stage transcript
1995
+ */
1996
+ readonly guaranteedTranscript: Transcript<AlignedValue> | undefined;
1997
+ /**
1998
+ * The proof attached to this call
1999
+ */
2000
+ readonly proof: P;
2001
+ }
2002
+
2003
+ /**
2004
+ * A {@link ContractCall} prior to being partitioned into guarnateed and
2005
+ * fallible parts, for use with {@link Transaction.addCalls}.
2006
+ *
2007
+ * Note that this is similar, but not the same as {@link ContractCall}, which
2008
+ * assumes {@link partitionTranscripts} was already used. {@link
2009
+ * Transaction.addCalls} is a replacement for this that also handles
2010
+ * Zswap components, and creates relevant intents when needed.
2011
+ */
2012
+ export class PrePartitionContractCall {
2013
+ constructor(
2014
+ address: ContractAddress,
2015
+ entry_point: Uint8Array | string,
2016
+ op: ContractOperation,
2017
+ pre_transcript: PreTranscript,
2018
+ private_transcript_outputs: AlignedValue[],
2019
+ input: AlignedValue,
2020
+ output: AlignedValue,
2021
+ communication_commitment_rand: CommunicationCommitmentRand,
2022
+ key_location: string
2023
+ );
2024
+ toString(compact?: boolean): string;
2025
+ }
2026
+
2027
+ /**
2028
+ * A {@link ContractCall} still being assembled
2029
+ */
2030
+ export class ContractCallPrototype {
2031
+ /**
2032
+ * @param address - The address being called
2033
+ * @param entry_point - The entry point being called
2034
+ * @param op - The operation expected at this entry point
2035
+ * @param guaranteed_public_transcript - The guaranteed transcript computed
2036
+ * for this call
2037
+ * @param fallible_public_transcript - The fallible transcript computed for
2038
+ * this call
2039
+ * @param private_transcript_outputs - The private transcript recorded for
2040
+ * this call
2041
+ * @param input - The input(s) provided to this call
2042
+ * @param output - The output(s) computed from this call
2043
+ * @param communication_commitment_rand - The communication randomness used
2044
+ * for this call
2045
+ * @param key_location - An identifier for how the key for this call may be
2046
+ * looked up
2047
+ */
2048
+ constructor(
2049
+ address: ContractAddress,
2050
+ entry_point: Uint8Array | string,
2051
+ op: ContractOperation,
2052
+ guaranteed_public_transcript: Transcript<AlignedValue> | undefined,
2053
+ fallible_public_transcript: Transcript<AlignedValue> | undefined,
2054
+ private_transcript_outputs: AlignedValue[],
2055
+ input: AlignedValue,
2056
+ output: AlignedValue,
2057
+ communication_commitment_rand: CommunicationCommitmentRand,
2058
+ key_location: string
2059
+ );
2060
+
2061
+ toString(compact?: boolean): string;
2062
+
2063
+ intoCall(parentBinding: PreBinding): ContractCall<PreProof>;
2064
+ }
2065
+
2066
+ /**
2067
+ * An intent is a potentially unbalanced partial transaction, that may be
2068
+ * combined with other intents to form a whole.
2069
+ */
2070
+ export class Intent<S extends Signaturish, P extends Proofish, B extends Bindingish> {
2071
+ private constructor();
2072
+
2073
+ static new(ttl: Date): UnprovenIntent;
2074
+
2075
+ serialize(): Uint8Array;
2076
+
2077
+ static deserialize<S extends Signaturish, P extends Proofish, B extends Bindingish>(
2078
+ markerS: S['instance'],
2079
+ markerP: P['instance'],
2080
+ markerB: B['instance'],
2081
+ raw: Uint8Array,
2082
+
2083
+ ): Intent<S, P, B>;
2084
+
2085
+ toString(compact?: boolean): string;
2086
+
2087
+ /**
2088
+ * Returns the hash of this intent, for it's given segment ID.
2089
+ */
2090
+ intentHash(segmentId: number): IntentHash;
2091
+
2092
+ /**
2093
+ * Adds a contract call to this intent.
2094
+ */
2095
+ addCall(call: ContractCallPrototype): Intent<S, PreProof, PreBinding>;
2096
+
2097
+ /**
2098
+ * Adds a contract deploy to this intent.
2099
+ */
2100
+ addDeploy(deploy: ContractDeploy): Intent<S, PreProof, PreBinding>;
2101
+
2102
+ /**
2103
+ * Adds a maintenance update to this intent.
2104
+ */
2105
+ addMaintenanceUpdate(update: MaintenanceUpdate): Intent<S, PreProof, PreBinding>;
2106
+
2107
+ /**
2108
+ * Enforces binding for this intent. This is irreversible.
2109
+ * @throws If `segmentId` is not a valid segment ID.
2110
+ */
2111
+ bind(segmentId: number): Intent<S, P, Binding>;
2112
+
2113
+ /**
2114
+ * Removes proofs from this intent.
2115
+ */
2116
+ eraseProofs(): Intent<S, NoProof, NoBinding>;
2117
+
2118
+ /**
2119
+ * Removes signatures from this intent.
2120
+ */
2121
+ eraseSignatures(): Intent<SignatureErased, P, B>;
2122
+
2123
+ /**
2124
+ * The raw data that is signed for unshielded inputs in this intent.
2125
+ */
2126
+ signatureData(segmentId: number): Uint8Array;
2127
+
2128
+ /**
2129
+ * The UTXO inputs and outputs in the guaranteed section of this intent.
2130
+ * @throws Writing throws if `B` is {@link Binding}, unless the only change
2131
+ * is in the signature set.
2132
+ */
2133
+ guaranteedUnshieldedOffer: UnshieldedOffer<S> | undefined;
2134
+ /**
2135
+ * The UTXO inputs and outputs in the fallible section of this intent.
2136
+ * @throws Writing throws if `B` is {@link Binding}, unless the only change
2137
+ * is in the signature set.
2138
+ */
2139
+ fallibleUnshieldedOffer: UnshieldedOffer<S> | undefined;
2140
+ /**
2141
+ * The action sequence of this intent.
2142
+ * @throws Writing throws if `B` is {@link Binding}.
2143
+ */
2144
+ actions: ContractAction<P>[];
2145
+ /**
2146
+ * The DUST interactions made by this intent
2147
+ * @throws Writing throws if `B` is {@link Binding}.
2148
+ */
2149
+ dustActions: DustActions<S, P> | undefined;
2150
+ /**
2151
+ * The time this intent expires.
2152
+ * @throws Writing throws if `B` is {@link Binding}.
2153
+ */
2154
+ ttl: Date;
2155
+ readonly binding: B;
2156
+ }
2157
+
2158
+ /**
2159
+ * An unshielded offer consists of inputs, outputs, and signatures that
2160
+ * authorize the inputs. The data the signatures sign is provided by {@link
2161
+ * Intent.signatureData}.
2162
+ */
2163
+ export class UnshieldedOffer<S extends Signaturish> {
2164
+ private constructor();
2165
+
2166
+ static new(inputs: UtxoSpend[], outputs: UtxoOutput[], signatures: SignatureEnabled[]): UnshieldedOffer<SignatureEnabled>;
2167
+
2168
+ addSignatures(signatures: S[]): UnshieldedOffer<S>;
2169
+
2170
+ eraseSignatures(): UnshieldedOffer<SignatureErased>;
2171
+
2172
+ toString(compact?: boolean): string;
2173
+
2174
+ readonly inputs: UtxoSpend[];
2175
+ readonly outputs: UtxoOutput[];
2176
+ readonly signatures: S[];
2177
+ }
2178
+
2179
+ /**
2180
+ * The context against which a transaction is run.
2181
+ */
2182
+ export class TransactionContext {
2183
+ /**
2184
+ * @param ref_state - A past ledger state that is used as a reference point
2185
+ * for 'static' data.
2186
+ * @param block_context - Information about the block this transaction is, or
2187
+ * will be, contained in.
2188
+ * @param whitelist - A list of contracts that are being tracked, or
2189
+ * `undefined` to track all contracts.
2190
+ */
2191
+ constructor(ref_state: LedgerState, block_context: BlockContext, whitelist?: Set<ContractAddress>);
2192
+
2193
+ toString(compact?: boolean): string;
2194
+ }
2195
+
2196
+ /**
2197
+ * The result status of applying a transaction.
2198
+ * Includes an error message if the transaction failed, or partially failed.
2199
+ */
2200
+ export class TransactionResult {
2201
+ private constructor();
2202
+
2203
+ readonly type: 'success' | 'partialSuccess' | 'failure';
2204
+ readonly successfulSegments?: Map<number, boolean>;
2205
+ readonly error?: string;
2206
+ readonly events: Event[];
2207
+
2208
+ toString(compact?: boolean): string;
2209
+ }
2210
+
2211
+ /**
2212
+ * The result status of applying a transaction, without error message
2213
+ */
2214
+ export type ErasedTransactionResult = {
2215
+ type: 'success' | 'partialSuccess' | 'failure',
2216
+ successfulSegments?: Map<number, boolean>,
2217
+ };
2218
+
2219
+ /**
2220
+ * A single update instruction in a {@link MaintenanceUpdate}.
2221
+ */
2222
+ export type SingleUpdate = ReplaceAuthority | VerifierKeyRemove | VerifierKeyInsert | IrRemove | IrInsert;
2223
+
2224
+ /**
2225
+ * The version associated with a {@link ContractOperation}
2226
+ */
2227
+ export class ContractOperationVersion {
2228
+ constructor(version: 'v3' | 'v4');
2229
+
2230
+ readonly version: 'v3' | 'v4';
2231
+
2232
+ toString(compact?: boolean): string;
2233
+ }
2234
+
2235
+ /**
2236
+ * A versioned verifier key to be associated with a {@link ContractOperation}.
2237
+ */
2238
+ export class ContractOperationVersionedVerifierKey {
2239
+ constructor(version: 'v3' | 'v4', rawVk: Uint8Array);
2240
+
2241
+ readonly version: 'v3' | 'v4';
2242
+ readonly rawVk: Uint8Array;
2243
+
2244
+ toString(compact?: boolean): string;
2245
+ }
2246
+
2247
+ /**
2248
+ * An update instruction to replace the current contract maintenance authority
2249
+ * with a new one.
2250
+ */
2251
+ export class ReplaceAuthority {
2252
+ constructor(authority: ContractMaintenanceAuthority);
2253
+
2254
+ readonly authority: ContractMaintenanceAuthority;
2255
+
2256
+ toString(compact?: boolean): string;
2257
+ }
2258
+
2259
+ /**
2260
+ * An update instruction to remove a verifier key of a specific operation and
2261
+ * version.
2262
+ */
2263
+ export class VerifierKeyRemove {
2264
+ constructor(operation: string | Uint8Array, version: ContractOperationVersion);
2265
+
2266
+ readonly operation: string | Uint8Array;
2267
+ readonly version: ContractOperationVersion;
2268
+
2269
+ toString(compact?: boolean): string;
2270
+ }
2271
+
2272
+ /**
2273
+ * An update instruction to insert a verifier key at a specific operation and
2274
+ * version.
2275
+ */
2276
+ export class VerifierKeyInsert {
2277
+ constructor(operation: string | Uint8Array, vk: ContractOperationVersionedVerifierKey);
2278
+
2279
+ readonly operation: string | Uint8Array;
2280
+ readonly vk: ContractOperationVersionedVerifierKey;
2281
+
2282
+ toString(compact?: boolean): string;
2283
+ }
2284
+
2285
+ /**
2286
+ * An update instruction to remove IR metadata of a specific operation.
2287
+ */
2288
+ export class IrRemove {
2289
+ constructor(operation: string | Uint8Array);
2290
+
2291
+ readonly operation: string | Uint8Array;
2292
+
2293
+ toString(compact?: boolean): string;
2294
+ }
2295
+
2296
+ /**
2297
+ * An update instruction to insert IR metadata at a specific operation.
2298
+ */
2299
+ export class IrInsert {
2300
+ constructor(operation: string | Uint8Array, ir: Uint8Array);
2301
+
2302
+ readonly operation: string | Uint8Array;
2303
+ readonly ir: Uint8Array;
2304
+
2305
+ toString(compact?: boolean): string;
2306
+ }
2307
+
2308
+ /**
2309
+ * A contract maintenance update, updating associated operations, or
2310
+ * changing the maintenance authority.
2311
+ */
2312
+ export class MaintenanceUpdate {
2313
+ constructor(address: ContractAddress, updates: SingleUpdate[], counter: bigint);
2314
+
2315
+ /**
2316
+ * Adds a new signature to this update
2317
+ */
2318
+ addSignature(idx: bigint, signature: Signature): MaintenanceUpdate;
2319
+
2320
+ toString(compact?: boolean): string;
2321
+
2322
+ /**
2323
+ * The raw data any valid signature must be over to approve this update.
2324
+ */
2325
+ readonly dataToSign: Uint8Array;
2326
+ /**
2327
+ * The address this deployment will attempt to create
2328
+ */
2329
+ readonly address: ContractAddress;
2330
+ /**
2331
+ * The updates to carry out
2332
+ */
2333
+ readonly updates: SingleUpdate[];
2334
+ /**
2335
+ * The counter this update is valid against
2336
+ */
2337
+ readonly counter: bigint;
2338
+ /**
2339
+ * The signatures on this update
2340
+ */
2341
+ readonly signatures: [bigint, Signature][];
2342
+ }
2343
+
2344
+ /**
2345
+ * A contract deployment segment, instructing the creation of a new contract
2346
+ * address, if not already present
2347
+ */
2348
+ export class ContractDeploy {
2349
+ /**
2350
+ * Creates a deployment for an arbitrary contract state
2351
+ *
2352
+ * The deployment and its address are randomised.
2353
+ */
2354
+ constructor(initial_state: ContractState);
2355
+
2356
+ toString(compact?: boolean): string;
2357
+
2358
+ /**
2359
+ * The address this deployment will attempt to create
2360
+ */
2361
+ readonly address: ContractAddress;
2362
+ readonly initialState: ContractState;
2363
+ }
2364
+
2365
+ export type ProvingProvider = {
2366
+ check(
2367
+ serializedPreimage: Uint8Array,
2368
+ keyLocation: string,
2369
+ ): Promise<(bigint | undefined)[]>;
2370
+ prove(
2371
+ serializedPreimage: Uint8Array,
2372
+ keyLocation: string,
2373
+ overwriteBindingInput?: bigint,
2374
+ ): Promise<Uint8Array>;
2375
+ lookupKey(keyLocation: string): Promise<ProvingKeyMaterial | undefined>;
2376
+ };
2377
+
2378
+ /**
2379
+ * Specifies where something should execute in a transaction.
2380
+ *
2381
+ * Options are:
2382
+ * - As the first thing (alias for `{ tag: 'specific', value: 1 }`)
2383
+ * - In any physical segment, but only utilising the guaranteed logical segment
2384
+ * - In a random segment (ideal for merging with other intents)
2385
+ * - In a specific directly provided segment (in the range 1..65535)
2386
+ */
2387
+ export type SegmentSpecifier = { tag: 'first' } | { tag: 'guaranteedOnly' } | { tag: 'random' } | { tag: 'specific', value: number };
2388
+
2389
+ /**
2390
+ * A transaction that has been validated with `wellFormed`.
2391
+ **/
2392
+ export class VerifiedTransaction {
2393
+ private constructor();
2394
+
2395
+ /**
2396
+ * The actual underlying transaction
2397
+ **/
2398
+ readonly transaction: Transaction<SignatureErased, NoProof, NoBinding>;
2399
+ }
2400
+
2401
+ /**
2402
+ * A Midnight transaction, consisting a section of {@link
2403
+ * ContractAction}s, and a guaranteed and fallible {@link ZswapOffer}.
2404
+ *
2405
+ * The guaranteed section are run first, and fee payment is taken during this
2406
+ * part. If it succeeds, the fallible section is also run, and atomically
2407
+ * rolled back if it fails.
2408
+ */
2409
+ export class Transaction<S extends Signaturish, P extends Proofish, B extends Bindingish> {
2410
+ private constructor();
2411
+
2412
+ /**
2413
+ * Creates a transaction from its parts.
2414
+ */
2415
+ static fromParts(network_id: string, guaranteed?: UnprovenOffer, fallible?: UnprovenOffer, intent?: UnprovenIntent): UnprovenTransaction;
2416
+
2417
+ /**
2418
+ * Creates a transaction from its parts, randomizing the segment ID to better
2419
+ * allow merging.
2420
+ */
2421
+ static fromPartsRandomized(network_id: string, guaranteed?: UnprovenOffer, fallible?: UnprovenOffer, intent?: UnprovenIntent): UnprovenTransaction;
2422
+
2423
+ /**
2424
+ * Creates a rewards claim transaction, the funds claimed must have been
2425
+ * legitimately rewarded previously.
2426
+ */
2427
+ static fromRewards<S extends Signaturish>(rewards: ClaimRewardsTransaction<S>): Transaction<S, PreProof, Binding>;
2428
+
2429
+ /**
2430
+ * Mocks proving, producing a 'proven' transaction that, while it will
2431
+ * *not* verify, is accurate for fee computation purposes.
2432
+ *
2433
+ * Due to the variability in proof sizes, this *only* works for transactions
2434
+ * that do not contain unproven contract calls.
2435
+ *
2436
+ * @throws If called on bound, proven, or proof-erased transactions, or if the
2437
+ * transaction contains unproven contract calls.
2438
+ */
2439
+ mockProve(): Transaction<S, Proof, Binding>;
2440
+ /**
2441
+ * Proves the transaction, with access to a low-level proving provider.
2442
+ * This may *only* be called for `P = PreProof`.
2443
+ *
2444
+ * @throws If called on bound, proven, or proof-erased transactions.
2445
+ */
2446
+ prove(provider: ProvingProvider, cost_model: CostModel): Promise<Transaction<S, Proof, B>>;
2447
+
2448
+ /**
2449
+ * Adds a set of new calls to the transaction.
2450
+ *
2451
+ * In contrast to {@link Intent.addCall}, this takes calls *before*
2452
+ * transcript partitioning ({@link partitionTranscripts}), will create the
2453
+ * target intent where needed, and will ensure that relevant Zswap parts are
2454
+ * placed in the same section as contract interactions with them.
2455
+ *
2456
+ * @throws If called on bound, proven, or proof-erased transactions.
2457
+ */
2458
+ addCalls(
2459
+ segment: SegmentSpecifier,
2460
+ calls: PrePartitionContractCall[],
2461
+ params: LedgerParameters,
2462
+ ttl: Date,
2463
+ zswapInputs?: ZswapInput<PreProof>[],
2464
+ zswapOutputs?: ZswapOutput<PreProof>[],
2465
+ zswapTransient?: ZswapTransient<PreProof>[],
2466
+ ): Transaction<S, P, B>;
2467
+
2468
+ /**
2469
+ * Adds Zswap offer to the segment specified.
2470
+ *
2471
+ * @throws If called on bound transactions.
2472
+ */
2473
+ addZswapOffer(
2474
+ segment: SegmentSpecifier,
2475
+ offer: UnprovenOffer | undefined,
2476
+ ): Transaction<S, P, B>;
2477
+
2478
+ /**
2479
+ * Adds provided intent to the segment specified.
2480
+ *
2481
+ * @throws If called on bound transactions.
2482
+ */
2483
+ addIntent(
2484
+ segment: SegmentSpecifier,
2485
+ intent: Intent<S, P, B> | undefined,
2486
+ ): Transaction<S, P, B>;
2487
+
2488
+ /**
2489
+ * Erases the proofs contained in this transaction
2490
+ */
2491
+ eraseProofs(): Transaction<S, NoProof, NoBinding>;
2492
+
2493
+ /**
2494
+ * Removes signatures from this transaction.
2495
+ */
2496
+ eraseSignatures(): Transaction<SignatureErased, P, B>;
2497
+
2498
+ /**
2499
+ * Enforces binding for this transaction. This is irreversible.
2500
+ */
2501
+ bind(): Transaction<S, P, Binding>;
2502
+
2503
+ /**
2504
+ * Tests well-formedness criteria, optionally including transaction balancing
2505
+ *
2506
+ * @throws If the transaction is not well-formed for any reason
2507
+ */
2508
+ wellFormed(ref_state: LedgerState, strictness: WellFormedStrictness, tblock: Date): VerifiedTransaction;
2509
+
2510
+ /**
2511
+ * Returns the hash associated with this transaction. Due to the ability to
2512
+ * merge transactions, this should not be used to watch for a specific
2513
+ * transaction.
2514
+ */
2515
+ transactionHash(): TransactionHash;
2516
+
2517
+ /**
2518
+ * Returns the set of identifiers contained within this transaction. Any of
2519
+ * these *may* be used to watch for a specific transaction.
2520
+ */
2521
+ identifiers(): TransactionId[];
2522
+
2523
+ /**
2524
+ * Merges this transaction with another
2525
+ *
2526
+ * @throws If both transactions have contract interactions, or they spend the
2527
+ * same coins
2528
+ */
2529
+ merge(other: Transaction<S, P, B>): Transaction<S, P, B>;
2530
+
2531
+ serialize(): Uint8Array;
2532
+
2533
+ static deserialize<S extends Signaturish, P extends Proofish, B extends Bindingish>(
2534
+ markerS: S['instance'],
2535
+ markerP: P['instance'],
2536
+ markerB: B['instance'],
2537
+ raw: Uint8Array,
2538
+
2539
+ ): Transaction<S, P, B>;
2540
+
2541
+ /**
2542
+ * For given fees, and a given section (guaranteed/fallible), what the
2543
+ * surplus or deficit of this transaction in any token type is.
2544
+ *
2545
+ * @throws If `segment` is not a valid segment ID
2546
+ */
2547
+ imbalances(segment: number, fees?: bigint): Map<TokenType, bigint>;
2548
+
2549
+ /**
2550
+ * The underlying resource cost of this transaction.
2551
+ */
2552
+ cost(params: LedgerParameters, enforceTimeToDismiss?: boolean): SyntheticCost;
2553
+
2554
+ /**
2555
+ * The cost of this transaction, in SPECKs.
2556
+ *
2557
+ * Note that this is *only* accurate when called with proven transactions.
2558
+ */
2559
+ fees(params: LedgerParameters, enforceTimeToDismiss?: boolean): bigint;
2560
+
2561
+ /**
2562
+ * The cost of this transaction, in SPECKs, with a safety margin of `n` blocks applied.
2563
+ *
2564
+ * As with {@link fees}, this is only accurate for proven transactions.
2565
+ *
2566
+ * Warning: `n` must be a non-negative integer, and it is an exponent, it is
2567
+ * very easy to get a completely unreasonable margin here!
2568
+ */
2569
+ feesWithMargin(params: LedgerParameters, margin: number): bigint;
2570
+
2571
+ toString(compact?: boolean): string;
2572
+
2573
+ /**
2574
+ * The rewards this transaction represents, if applicable
2575
+ */
2576
+ readonly rewards: ClaimRewardsTransaction<S> | undefined;
2577
+ /**
2578
+ * The intents contained in this transaction
2579
+ *
2580
+ * Note that writing to this re-computes binding information if and only if
2581
+ * this transaction is unbound *and* unproven. If this is not the case,
2582
+ * creating or removing intents will lead to a binding error down the line,
2583
+ * but modifying existing intents will succeed.
2584
+ *
2585
+ * @throws On writing if `B` is {@link Binding} or this is not a standard
2586
+ * transaction
2587
+ */
2588
+ intents: Map<number, Intent<S, P, B>> | undefined;
2589
+ /**
2590
+ * The fallible Zswap offer
2591
+ *
2592
+ * Note that writing to this re-computes binding information if and only if
2593
+ * this transaction is unbound *and* unproven. If this is not the case,
2594
+ * creating or removing offer components will lead to a binding error down
2595
+ * the line.
2596
+ *
2597
+ * @throws On writing if `B` is {@link Binding} or this is not a standard
2598
+ * transaction
2599
+ */
2600
+ fallibleOffer: Map<number, ZswapOffer<P>> | undefined;
2601
+ /**
2602
+ * The guaranteed Zswap offer
2603
+ *
2604
+ * Note that writing to this re-computes binding information if and only if
2605
+ * this transaction is unbound *and* unproven. If this is not the case,
2606
+ * creating or removing offer components will lead to a binding error down
2607
+ * the line.
2608
+ *
2609
+ * @throws On writing if `B` is {@link Binding} or this is not a standard
2610
+ * transaction
2611
+ */
2612
+ guaranteedOffer: ZswapOffer<P> | undefined;
2613
+ /**
2614
+ * The binding randomness associated with this transaction
2615
+ */
2616
+ readonly bindingRandomness: bigint;
2617
+ }
2618
+
2619
+ /**
2620
+ * A transcript prior to partitioning, consisting of the context to run it in, the program that
2621
+ * will make up the transcript, and optionally a communication commitment to bind calls together.
2622
+ */
2623
+ export class PreTranscript {
2624
+ constructor(context: QueryContext, program: Op<AlignedValue>[], comm_comm?: CommunicationCommitment);
2625
+
2626
+ toString(compact?: boolean): string;
2627
+ }
2628
+
2629
+ export type PartitionedTranscript = [Transcript<AlignedValue> | undefined, Transcript<AlignedValue> | undefined];
2630
+
2631
+ /**
2632
+ * Computes the communication commitment corresponding to an input/output pair and randomness.
2633
+ */
2634
+ export function communicationCommitment(input: AlignedValue, output: AlignedValue, rand: CommunicationCommitmentRand): CommunicationCommitment;
2635
+
2636
+ /**
2637
+ * Finalizes a set of programs against their initial contexts,
2638
+ * resulting in guaranteed and fallible {@link Transcript}s, optimally
2639
+ * allocated, and heuristically covered for gas fees.
2640
+ */
2641
+ export function partitionTranscripts(calls: PreTranscript[], params: LedgerParameters): PartitionedTranscript[];
2642
+
2643
+ /**
2644
+ * The hash of a transaction, as a hex-encoded 256-bit bytestring
2645
+ */
2646
+ export type TransactionHash = string;
2647
+ /**
2648
+ * The hash of an intent, as a hex-encoded 256-bit bytestring
2649
+ */
2650
+ export type IntentHash = string;
2651
+ /**
2652
+ * A transaction identifier, used to index merged transactions
2653
+ */
2654
+ export type TransactionId = string;
2655
+ /**
2656
+ * An encryption public key, used to inform users of new coins sent to them
2657
+ */
2658
+ export type EncPublicKey = string;
2659
+
2660
+ /**
2661
+ * Samples a dummy user coin public key, for use in testing
2662
+ */
2663
+ export function sampleCoinPublicKey(): CoinPublicKey;
2664
+
2665
+ /**
2666
+ * Samples a dummy user encryption public key, for use in testing
2667
+ */
2668
+ export function sampleEncryptionPublicKey(): EncPublicKey;
2669
+
2670
+ /**
2671
+ * Samples a dummy user intent hash, for use in testing
2672
+ */
2673
+ export function sampleIntentHash(): IntentHash;
2674
+
2675
+ /**
2676
+ * Creates a new {@link ShieldedCoinInfo}, sampling a uniform nonce
2677
+ */
2678
+ export function createShieldedCoinInfo(type_: RawTokenType, value: bigint): ShieldedCoinInfo;
2679
+
2680
+ /**
2681
+ * The base/system token type
2682
+ */
2683
+ export function nativeToken(): UnshieldedTokenType;
2684
+
2685
+ /**
2686
+ * The system token type for fees
2687
+ */
2688
+ export function feeToken(): DustTokenType;
2689
+
2690
+ /**
2691
+ * Default shielded token type for testing
2692
+ */
2693
+ export function shieldedToken(): ShieldedTokenType;
2694
+
2695
+ /**
2696
+ * Default unshielded token type for testing
2697
+ */
2698
+ export function unshieldedToken(): UnshieldedTokenType;
2699
+
2700
+ /**
2701
+ * Calculate commitment of a coin owned by a user
2702
+ */
2703
+ export function coinCommitment(coin: ShieldedCoinInfo, coinPublicKey: CoinPublicKey): CoinCommitment;
2704
+
2705
+ /**
2706
+ * Calculate nullifier of a coin owned by a user
2707
+ */
2708
+ export function coinNullifier(coin: ShieldedCoinInfo, coinSecretKey: CoinSecretKey): Nullifier;
2709
+
2710
+ /**
2711
+ * Calculate commitment of Dust utxo owned by a user
2712
+ */
2713
+ export function dustCommitment(qdo: QualifiedDustOutput): DustCommitment;
2714
+
2715
+ /**
2716
+ * Calculate nullifier of Dust utxo owned by a user
2717
+ */
2718
+ export function dustNullifier(qdo: QualifiedDustOutput, sk: DustSecretKey): DustNullifier;
2719
+
2720
+ /**
2721
+ * Calculate Dust nonce
2722
+ */
2723
+ export function dustNonce(initialNonce: DustInitialNonce, seq: bigint, sk: DustSecretKey): DustNonce;
2724
+
2725
+ /**
2726
+ * Calculate Dust first nonce (when seq=0)
2727
+ */
2728
+ export function dustFirstNonce(backingNight: DustInitialNonce, dustAddress: DustPublicKey): DustNonce;
2729
+
2730
+ /**
2731
+ * Calculate Dust initial nonce (a backing night hash)
2732
+ */
2733
+ export function dustInitialNonce(outputNo: bigint, intentHash: IntentHash): DustInitialNonce;
2734
+
2735
+ /**
2736
+ * Returns a new Dust UTXO with a reduced value and the sequential nonce
2737
+ */
2738
+ export function successorDustUtxo(qdo: QualifiedDustOutput, now: Date, subtractFee: bigint, newCommitmentIndex: bigint, genInfo: DustGenerationInfo, sk: DustSecretKey, dustParams: DustParameters): QualifiedDustOutput;
2739
+
2740
+ /**
2741
+ * Parameters used by the Midnight ledger, including transaction fees and
2742
+ * bounds
2743
+ */
2744
+ export class LedgerParameters {
2745
+ private constructor();
2746
+
2747
+ /**
2748
+ * The initial parameters of Midnight
2749
+ */
2750
+ static initialParameters(): LedgerParameters;
2751
+
2752
+ /**
2753
+ * The cost model used for transaction fees contained in these parameters
2754
+ */
2755
+ readonly transactionCostModel: TransactionCostModel;
2756
+ /**
2757
+ * The parameters associated with DUST.
2758
+ */
2759
+ readonly dust: DustParameters;
2760
+
2761
+ /**
2762
+ * The maximum price adjustment per block with the current parameters, as a multiplicative
2763
+ * factor (that is: 1.1 would indicate a 10% adjustment). Will always return the positive (>1)
2764
+ * adjustment factor. Note that negative adjustments are the additive inverse (1.1 has a
2765
+ * corresponding 0.9 downward adjustment), *not* the multiplicative as might reasonably be
2766
+ * assumed.
2767
+ */
2768
+ maxPriceAdjustment(): number;
2769
+
2770
+ serialize(): Uint8Array;
2771
+
2772
+ static deserialize(raw: Uint8Array): LedgerParameters;
2773
+
2774
+ toString(compact?: boolean): string;
2775
+
2776
+ /**
2777
+ * Normalizes a detailed block fullness cost to the block limits.
2778
+ *
2779
+ * @throws if any of the block limits is exceeded
2780
+ */
2781
+ normalizeFullness(fullness: SyntheticCost): NormalizedCost;
2782
+
2783
+ /**
2784
+ * The fee prices for transaction
2785
+ */
2786
+ readonly feePrices: FeePrices;
2787
+ }
2788
+
2789
+ export class TransactionCostModel {
2790
+ private constructor();
2791
+
2792
+ /**
2793
+ * The initial cost model of Midnight
2794
+ */
2795
+ static initialTransactionCostModel(): TransactionCostModel;
2796
+
2797
+ /**
2798
+ * The increase in fees to expect from adding a new input to a transaction
2799
+ */
2800
+ readonly inputFeeOverhead: bigint;
2801
+ /**
2802
+ * The increase in fees to expect from adding a new output to a transaction
2803
+ */
2804
+ readonly outputFeeOverhead: bigint;
2805
+
2806
+ serialize(): Uint8Array;
2807
+
2808
+ static deserialize(raw: Uint8Array): TransactionCostModel;
2809
+
2810
+ toString(compact?: boolean): string;
2811
+
2812
+ /**
2813
+ * A cost model for calculating transaction fees
2814
+ */
2815
+ readonly runtimeCostModel: CostModel;
2816
+
2817
+ /**
2818
+ * A baseline cost to begin with
2819
+ */
2820
+ readonly baselineCost: RunningCost;
2821
+ }
2822
+
2823
+
2824
+ /**
2825
+ * A compact delta on the coin commitments Merkle tree, used to keep local
2826
+ * spending trees in sync with the global state without requiring receiving all
2827
+ * transactions.
2828
+ */
2829
+ export class MerkleTreeCollapsedUpdate {
2830
+ /**
2831
+ * Create a new compact update from a non-compact state, and inclusive
2832
+ * `start` and `end` indices
2833
+ *
2834
+ * @throws If the indices are out-of-bounds for the state, or `end < start`
2835
+ */
2836
+ constructor(state: ZswapChainState, start: bigint, end: bigint);
2837
+
2838
+ serialize(): Uint8Array;
2839
+
2840
+ static deserialize(raw: Uint8Array): MerkleTreeCollapsedUpdate;
2841
+
2842
+ toString(compact?: boolean): string;
2843
+ }
2844
+
2845
+ /**
2846
+ * Holds the encryption secret key of a user, which may be used to determine if
2847
+ * a given offer contains outputs addressed to this user
2848
+ */
2849
+ export class EncryptionSecretKey {
2850
+ private constructor();
2851
+
2852
+ /**
2853
+ * Clears the encryption secret key, so that it is no longer usable nor held in memory
2854
+ */
2855
+ clear(): void;
2856
+
2857
+ test<P extends Proofish>(offer: ZswapOffer<P>): boolean;
2858
+
2859
+ yesIKnowTheSecurityImplicationsOfThis_serialize(): Uint8Array;
2860
+ yesIKnowTheSecurityImplicationsOfThis_taggedSerialize(): Uint8Array;
2861
+
2862
+ static deserialize(raw: Uint8Array): EncryptionSecretKey
2863
+ static taggedDeserialize(raw: Uint8Array): EncryptionSecretKey
2864
+ }
2865
+
2866
+ export class ZswapSecretKeys {
2867
+ private constructor();
2868
+
2869
+ /**
2870
+ * Derives secret keys from a 32-byte seed
2871
+ */
2872
+ static fromSeed(seed: Uint8Array): ZswapSecretKeys;
2873
+
2874
+ /**
2875
+ * Derives secret keys from a 32-byte seed using deprecated implementation.
2876
+ * Use only for compatibility purposes
2877
+ */
2878
+ static fromSeedRng(seed: Uint8Array): ZswapSecretKeys;
2879
+
2880
+
2881
+ /**
2882
+ * Clears the secret keys, so that they are no longer usable nor held in memory
2883
+ * Note: it does not clear copies of the keys - which is particularly relevant for proof preimages
2884
+ * Note: this will cause all other operations to fail
2885
+ */
2886
+ clear(): void;
2887
+
2888
+ readonly coinPublicKey: CoinPublicKey;
2889
+ readonly coinSecretKey: CoinSecretKey;
2890
+ readonly encryptionPublicKey: EncPublicKey;
2891
+ readonly encryptionSecretKey: EncryptionSecretKey;
2892
+ }
2893
+
2894
+ /**
2895
+ * The on-chain state of Zswap, consisting of a Merkle tree of coin
2896
+ * commitments, a set of nullifiers, an index into the Merkle tree, and a set
2897
+ * of valid past Merkle tree roots
2898
+ */
2899
+ export class ZswapChainState {
2900
+ constructor();
2901
+
2902
+ serialize(): Uint8Array;
2903
+
2904
+ /**
2905
+ * The first free index in the coin commitment tree
2906
+ */
2907
+ readonly firstFree: bigint;
2908
+
2909
+ static deserialize(raw: Uint8Array): ZswapChainState;
2910
+
2911
+ /**
2912
+ * Given a whole ledger serialized state, deserialize only the Zswap portion
2913
+ */
2914
+ static deserializeFromLedgerState(raw: Uint8Array): ZswapChainState;
2915
+
2916
+ /**
2917
+ * Carries out a post-block update, which does amortized bookkeeping that
2918
+ * only needs to be done once per state change.
2919
+ *
2920
+ * Typically, `postBlockUpdate` should be run after any (sequence of)
2921
+ * (system)-transaction application(s).
2922
+ *
2923
+ * @param tblock - timestamp of a block last batch of updates was applied at
2924
+ * @param retentionDuration - number of seconds to retain past Merkle tree roots
2925
+ */
2926
+ postBlockUpdate(tblock: Date, retentionDuration: bigint): ZswapChainState;
2927
+
2928
+ /**
2929
+ * Try to apply an {@link ZswapOffer} to the state, returning the updated state
2930
+ * and a map on newly inserted coin commitments to their inserted indices.
2931
+ *
2932
+ * @param whitelist - A set of contract addresses that are of interest. If
2933
+ * set, *only* these addresses are tracked, and all other information is
2934
+ * discarded.
2935
+ */
2936
+ tryApply<P extends Proofish>(offer: ZswapOffer<P>, whitelist?: Set<ContractAddress>): [ZswapChainState, Map<CoinCommitment, bigint>];
2937
+
2938
+ toString(compact?: boolean): string;
2939
+
2940
+ /**
2941
+ * Filters the state to only include coins that are relevant to a given
2942
+ * contract address.
2943
+ *
2944
+ * @param contractAddress
2945
+ */
2946
+ filter(contractAddress: ContractAddress): ZswapChainState;
2947
+ }
2948
+
2949
+ export class ZswapStateChanges {
2950
+ constructor(source: TransactionHash, receivedCoins: QualifiedShieldedCoinInfo[], spentCoins: QualifiedShieldedCoinInfo[]);
2951
+ toString(compact?: boolean): string;
2952
+ /**
2953
+ * The source of the state change, as a hex-encoded string
2954
+ */
2955
+ readonly source: TransactionHash;
2956
+ /**
2957
+ * The coins that were received in this state change
2958
+ */
2959
+ readonly receivedCoins: QualifiedShieldedCoinInfo[];
2960
+ /**
2961
+ * The coins that were spent in this state change
2962
+ */
2963
+ readonly spentCoins: QualifiedShieldedCoinInfo[];
2964
+ }
2965
+
2966
+ export class ZswapLocalStateWithChanges {
2967
+ private constructor();
2968
+ /**
2969
+ * The updated local state after replaying events
2970
+ */
2971
+ readonly state: ZswapLocalState;
2972
+ /**
2973
+ * The state changes that occurred during the replay
2974
+ */
2975
+ readonly changes: ZswapStateChanges[];
2976
+ }
2977
+
2978
+ /**
2979
+ * The local state of a user/wallet, consisting of a set
2980
+ * of unspent coins
2981
+ *
2982
+ * It also keeps track of coins that are in-flight, either expecting to spend
2983
+ * or expecting to receive, and a local copy of the global coin commitment
2984
+ * Merkle tree to generate proofs against.
2985
+ *
2986
+ * It does not store keys internally, but accepts them as arguments to various operations.
2987
+ */
2988
+ export class ZswapLocalState {
2989
+ /**
2990
+ * Creates a new, empty state
2991
+ */
2992
+ constructor();
2993
+
2994
+ /**
2995
+ * Applies a collapsed Merkle tree update to the current local state, fast
2996
+ * forwarding through the indices included in it, if it is a correct update.
2997
+ *
2998
+ * The general flow for usage if Alice is in state A, and wants to ask Bob how to reach the new state B, is:
2999
+ * - Find where she left off – what's her firstFree?
3000
+ * - Find out where she's going – ask for Bob's firstFree.
3001
+ * - Find what contents she does care about – ask Bob for the filtered
3002
+ * entries she want to include proper in her tree.
3003
+ * - In order, of Merkle tree indices:
3004
+ * - Insert (with `apply` offers Alice cares about).
3005
+ * - Skip (with this method) sections Alice does not care about, obtaining
3006
+ * the collapsed update covering the gap from Bob.
3007
+ * Note that `firstFree` is not included in the tree itself, and both ends of
3008
+ * updates *are* included.
3009
+ */
3010
+ applyCollapsedUpdate(update: MerkleTreeCollapsedUpdate): ZswapLocalState;
3011
+
3012
+ /**
3013
+ * Directly inserts a coin owned by this wallet into the state at `this.first_free`.
3014
+ *
3015
+ * This function requires secret keys as coins are indexed by nullifier, and
3016
+ * secret keys are required to compute this.
3017
+ */
3018
+ insertCoin(secretKeys: ZswapSecretKeys, coin: ShieldedCoinInfo): ZswapLocalState;
3019
+
3020
+ /**
3021
+ * Removes a given coin from the tracked coins by its nullifier.
3022
+ */
3023
+ removeCoinByNullifier(nullifier: Nullifier): ZswapLocalState;
3024
+
3025
+ /**
3026
+ * Replays observed events against the current local state. These *must* be replayed
3027
+ * in the same order as emitted by the chain being followed.
3028
+ */
3029
+ replayEvents(secretKeys: ZswapSecretKeys, events: Event[]): ZswapLocalState;
3030
+ /**
3031
+ * Replays observed events against the current local state, returning both the updated state
3032
+ * and the state changes. These *must* be replayed in the same order as emitted by the chain being followed.
3033
+ */
3034
+ replayEventsWithChanges(secretKeys: ZswapSecretKeys, events: Event[]): ZswapLocalStateWithChanges;
3035
+ /**
3036
+ * Replays a direct concatenation of serialized ledger events. Otherwise acts as `replayEventsWithChanges`.
3037
+ */
3038
+ replayRawEvents(sk: ZswapSecretKeys, rawEvents: Uint8Array): ZswapLocalStateWithChanges;
3039
+ /**
3040
+ * Locally applies an offer to the current state, returning the updated state
3041
+ */
3042
+ apply<P extends Proofish>(secretKeys: ZswapSecretKeys, offer: ZswapOffer<P>): ZswapLocalState;
3043
+ /**
3044
+ * Locally applies an offer to the current state, returning both the updated state and the state changes.
3045
+ */
3046
+ applyWithChanges<P extends Proofish>(secretKeys: ZswapSecretKeys, offer: ZswapOffer<P>): ZswapLocalStateWithChanges;
3047
+ /**
3048
+ * Locally reverts pending outputs/spends from an offer known to have failed
3049
+ * or which has been discarded.
3050
+ */
3051
+ applyFailed<P extends Proofish>(offer: ZswapOffer<P>): ZswapLocalState;
3052
+ /**
3053
+ * Locally reverts all pending outputs/spends from a transaction which has been discarded.
3054
+ *
3055
+ * Behaves as {@link applyFailed} for the entire transaction.
3056
+ */
3057
+ revertTransaction<S extends Signaturish, P extends Proofish, B extends Bindingish>(transaction: Transaction<S, P, B>): ZswapLocalState;
3058
+ /**
3059
+ * Clears pending outputs / spends that have passed their TTL without being included in
3060
+ * a block.
3061
+ *
3062
+ * Note that as TTLs are *from a block perspective*, and there is some
3063
+ * latency between the block and the wallet, the time passed in here should
3064
+ * not be the current time, but incorporate a latency buffer.
3065
+ *
3066
+ * NOTE: This API endpoint is currently non-functional and works as a no-op.
3067
+ */
3068
+ clearPending(time: Date): ZswapLocalState;
3069
+
3070
+ /**
3071
+ * Initiates a new spend of a specific coin, outputting the corresponding
3072
+ * {@link ZswapInput}, and the updated state marking this coin as
3073
+ * in-flight.
3074
+ */
3075
+ spend(secretKeys: ZswapSecretKeys, coin: QualifiedShieldedCoinInfo, segment: number | undefined, ttl?: Date): [ZswapLocalState, UnprovenInput];
3076
+
3077
+ /**
3078
+ * Initiates a new spend of a new-yet-received output, outputting the
3079
+ * corresponding {@link ZswapTransient}, and the updated state marking
3080
+ * this coin as in-flight.
3081
+ */
3082
+ spendFromOutput(secretKeys: ZswapSecretKeys, coin: QualifiedShieldedCoinInfo, segment: number | undefined, output: UnprovenOutput, ttl?: Date): [ZswapLocalState, UnprovenTransient];
3083
+
3084
+ /**
3085
+ * Adds a coin to the list of coins that are expected to be received
3086
+ *
3087
+ * This should be used if an output is creating a coin for this wallet, which
3088
+ * does not contain a ciphertext to detect it. In this case, the wallet must
3089
+ * know the commitment ahead of time to notice the receipt.
3090
+ */
3091
+ watchFor(coinPublicKey: CoinPublicKey, coin: ShieldedCoinInfo): ZswapLocalState;
3092
+
3093
+ serialize(): Uint8Array;
3094
+
3095
+ static deserialize(raw: Uint8Array): ZswapLocalState;
3096
+
3097
+ toString(compact?: boolean): string;
3098
+
3099
+ /**
3100
+ * The set of *spendable* coins of this wallet
3101
+ */
3102
+ readonly coins: Set<QualifiedShieldedCoinInfo>;
3103
+ /**
3104
+ * The first free index in the internal coin commitments Merkle tree.
3105
+ * This may be used to identify which merkle tree updates are necessary.
3106
+ */
3107
+ readonly firstFree: bigint;
3108
+ /**
3109
+ * The outputs that this wallet is expecting to receive in the future, with
3110
+ * an optional TTL attached.
3111
+ */
3112
+ readonly pendingOutputs: Map<CoinCommitment, [ShieldedCoinInfo, Date | undefined]>;
3113
+ /**
3114
+ * The spends that this wallet is expecting to be finalized on-chain in the
3115
+ * future. Each has an optional TTL attached.
3116
+ */
3117
+ readonly pendingSpends: Map<Nullifier, [QualifiedShieldedCoinInfo, Date | undefined]>;
3118
+ /**
3119
+ * The root of the commitment Merkle tree.
3120
+ */
3121
+ readonly merkleTreeRoot: bigint | undefined;
3122
+ }
3123
+
3124
+ /**
3125
+ * A shielded transaction input
3126
+ */
3127
+ export class ZswapInput<P extends Proofish> {
3128
+ private constructor();
3129
+
3130
+ static newContractOwned(coin: QualifiedShieldedCoinInfo, segment: number | undefined, contract: ContractAddress, state: ZswapChainState): UnprovenInput;
3131
+
3132
+ serialize(): Uint8Array;
3133
+
3134
+ static deserialize<P extends Proofish>(markerP: P['instance'], raw: Uint8Array): ZswapInput<P>;
3135
+
3136
+ toString(compact?: boolean): string;
3137
+
3138
+ /**
3139
+ * The contract address receiving the input, if the sender is a contract
3140
+ */
3141
+ readonly contractAddress: ContractAddress | undefined;
3142
+ /**
3143
+ * The nullifier of the input
3144
+ */
3145
+ readonly nullifier: Nullifier;
3146
+ /**
3147
+ * The proof of this input
3148
+ */
3149
+ readonly proof: P;
3150
+ }
3151
+
3152
+ /**
3153
+ * A shielded transaction output
3154
+ */
3155
+ export class ZswapOutput<P extends Proofish> {
3156
+ private constructor();
3157
+
3158
+ /**
3159
+ * Creates a new output, targeted to a user's coin public key.
3160
+ *
3161
+ * Optionally the output contains a ciphertext encrypted to the user's
3162
+ * encryption public key, which may be omitted *only* if the {@link ShieldedCoinInfo}
3163
+ * is transferred to the recipient another way
3164
+ */
3165
+ static new(coin: ShieldedCoinInfo, segment: number | undefined, target_cpk: CoinPublicKey, target_epk: EncPublicKey): UnprovenOutput;
3166
+
3167
+ /**
3168
+ * Creates a new output, targeted to a smart contract
3169
+ *
3170
+ * A contract must *also* explicitly receive a coin created in this way for
3171
+ * the output to be valid
3172
+ */
3173
+ static newContractOwned(coin: ShieldedCoinInfo, segment: number | undefined, contract: ContractAddress): UnprovenOutput;
3174
+
3175
+ serialize(): Uint8Array;
3176
+
3177
+ static deserialize<P extends Proofish>(markerP: P['instance'], raw: Uint8Array): ZswapOutput<P>;
3178
+
3179
+ toString(compact?: boolean): string;
3180
+
3181
+ /**
3182
+ * The commitment of the output
3183
+ */
3184
+ readonly commitment: CoinCommitment;
3185
+ /**
3186
+ * The contract address receiving the output, if the recipient is a contract
3187
+ */
3188
+ readonly contractAddress: ContractAddress | undefined;
3189
+ /**
3190
+ * The proof of this output
3191
+ */
3192
+ readonly proof: P;
3193
+ }
3194
+
3195
+ /**
3196
+ * A shielded "transient"; an output that is immediately spent within the same
3197
+ * transaction
3198
+ */
3199
+ export class ZswapTransient<P extends Proofish> {
3200
+ private constructor();
3201
+
3202
+ /**
3203
+ * Creates a new contract-owned transient, from a given output and its coin.
3204
+ *
3205
+ * The {@link QualifiedShieldedCoinInfo} should have an `mt_index` of `0`
3206
+ */
3207
+ static newFromContractOwnedOutput(coin: QualifiedShieldedCoinInfo, segment: number | undefined, output: UnprovenOutput): UnprovenTransient;
3208
+
3209
+ serialize(): Uint8Array;
3210
+
3211
+ static deserialize<P extends Proofish>(markerP: P['instance'], raw: Uint8Array): ZswapTransient<P>;
3212
+
3213
+ toString(compact?: boolean): string;
3214
+
3215
+ /**
3216
+ * The commitment of the transient
3217
+ */
3218
+ readonly commitment: CoinCommitment;
3219
+ /**
3220
+ * The contract address creating the transient, if applicable
3221
+ */
3222
+ readonly contractAddress: ContractAddress | undefined;
3223
+ /**
3224
+ * The nullifier of the transient
3225
+ */
3226
+ readonly nullifier: Nullifier;
3227
+ /**
3228
+ * The input proof of this transient
3229
+ */
3230
+ readonly inputProof: P;
3231
+ /**
3232
+ * The output proof of this transient
3233
+ */
3234
+ readonly outputProof: P;
3235
+ }
3236
+
3237
+ export type ClaimKind = "Reward" | "CardanoBridge";
3238
+
3239
+ /**
3240
+ * A request to allocate rewards, authorized by the reward's recipient
3241
+ */
3242
+ export class ClaimRewardsTransaction<S extends Signaturish> {
3243
+ constructor(markerS: S['instance'], network_id: string, value: bigint, owner: SignatureVerifyingKey, nonce: Nonce, signature: S, kind?: ClaimKind);
3244
+
3245
+ static new(network_id: string, value: bigint, owner: SignatureVerifyingKey, nonce: Nonce, kind: ClaimKind): ClaimRewardsTransaction<SignatureErased>;
3246
+
3247
+ addSignature(signature: Signature): ClaimRewardsTransaction<SignatureEnabled>;
3248
+
3249
+ eraseSignatures(): ClaimRewardsTransaction<SignatureErased>;
3250
+
3251
+ serialize(): Uint8Array;
3252
+
3253
+ static deserialize<S extends Signaturish>(markerS: S['instance'], raw: Uint8Array): ClaimRewardsTransaction<S>;
3254
+
3255
+ toString(compact?: boolean): string;
3256
+
3257
+ /**
3258
+ * The raw data any valid signature must be over to approve this transaction.
3259
+ */
3260
+ readonly dataToSign: Uint8Array;
3261
+
3262
+ /**
3263
+ * The rewarded coin's value, in atomic units dependent on the currency
3264
+ *
3265
+ * Bounded to be a non-negative 64-bit integer
3266
+ */
3267
+ readonly value: bigint;
3268
+
3269
+ /**
3270
+ * The signing key owning this coin.
3271
+ */
3272
+ readonly owner: SignatureVerifyingKey;
3273
+
3274
+ /**
3275
+ * The rewarded coin's randomness, preventing it from colliding with other coins.
3276
+ */
3277
+ readonly nonce: Nonce;
3278
+
3279
+ /**
3280
+ * The signature on this request.
3281
+ */
3282
+ readonly signature: S;
3283
+
3284
+ /**
3285
+ * The kind of claim being made, either a `Reward` or a `CardanoBridge` claim.
3286
+ */
3287
+ readonly kind: ClaimKind
3288
+ }
3289
+
3290
+ /**
3291
+ * A full Zswap offer; the zswap part of a transaction
3292
+ *
3293
+ * Consists of sets of {@link ZswapInput}s, {@link ZswapOutput}s, and {@link ZswapTransient}s,
3294
+ * as well as a {@link deltas} vector of the transaction value
3295
+ */
3296
+ export class ZswapOffer<P extends Proofish> {
3297
+ private constructor();
3298
+
3299
+ /**
3300
+ * Creates a singleton offer, from an {@link ZswapInput} and its value
3301
+ * vector
3302
+ *
3303
+ * The `type_` and `value` parameters are deprecated and will be ignored.
3304
+ */
3305
+ static fromInput<P extends Proofish>(input: ZswapInput<P>, type_?: RawTokenType, value?: bigint): ZswapOffer<P>;
3306
+
3307
+ /**
3308
+ * Creates a singleton offer, from an {@link ZswapOutput} and its value
3309
+ * vector
3310
+ *
3311
+ * The `type_` and `value` parameters are deprecated and will be ignored.
3312
+ */
3313
+ static fromOutput<P extends Proofish>(output: ZswapOutput<P>, type_?: RawTokenType, value?: bigint): ZswapOffer<P>;
3314
+
3315
+ /**
3316
+ * Creates a singleton offer, from a {@link ZswapTransient}
3317
+ */
3318
+ static fromTransient<P extends Proofish>(transient: ZswapTransient<P>): ZswapOffer<P>;
3319
+
3320
+ /**
3321
+ * Combine this offer with another
3322
+ */
3323
+ merge(other: ZswapOffer<P>): ZswapOffer<P>;
3324
+
3325
+ serialize(): Uint8Array;
3326
+
3327
+ static deserialize<P extends Proofish>(markerP: P['instance'], raw: Uint8Array): ZswapOffer<P>;
3328
+
3329
+ toString(compact?: boolean): string;
3330
+
3331
+ /**
3332
+ * The value of this offer for each token type; note that this may be
3333
+ * negative
3334
+ *
3335
+ * This is input coin values - output coin values, for value vectors
3336
+ */
3337
+ readonly deltas: Map<RawTokenType, bigint>;
3338
+ /**
3339
+ * The inputs this offer is composed of
3340
+ */
3341
+ readonly inputs: ZswapInput<P>[];
3342
+ /**
3343
+ * The outputs this offer is composed of
3344
+ */
3345
+ readonly outputs: ZswapOutput<P>[];
3346
+ /**
3347
+ * The transients this offer is composed of
3348
+ */
3349
+ readonly transients: ZswapTransient<P>[];
3350
+ }
3351
+
3352
+ /**
3353
+ * A privileged transaction issued by the system.
3354
+ */
3355
+ export class SystemTransaction {
3356
+ private constructor();
3357
+
3358
+ serialize(): Uint8Array;
3359
+
3360
+ static deserialize(raw: Uint8Array): SystemTransaction;
3361
+
3362
+ toString(compact?: boolean): string;
3363
+ }
3364
+
3365
+ /**
3366
+ * A transaction that has not yet been proven.
3367
+ */
3368
+ export type UnprovenTransaction = Transaction<SignatureEnabled, PreProof, PreBinding>;
3369
+
3370
+ /**
3371
+ * A transaction that has been proven and finalized.
3372
+ */
3373
+ export type FinalizedTransaction = Transaction<SignatureEnabled, Proof, Binding>;
3374
+
3375
+ /**
3376
+ * A transaction with proofs erased.
3377
+ */
3378
+ export type ProofErasedTransaction = Transaction<Signaturish, NoProof, NoBinding>;