@midnightntwrk/ledger-v10 1.0.0-alpha.1

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