@midnightntwrk/onchain-runtime-v4 4.0.0-rc.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.
- package/midnight_onchain_runtime_wasm.js +5 -0
- package/midnight_onchain_runtime_wasm_bg.js +3034 -0
- package/midnight_onchain_runtime_wasm_bg.wasm +0 -0
- package/midnight_onchain_runtime_wasm_fs.js +22 -0
- package/onchain-runtime-v4.d.ts +1149 -0
- package/package-lock.json +12 -0
- package/package.json +34 -0
|
@@ -0,0 +1,1149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An onchain data value, in field-aligned binary format.
|
|
3
|
+
*/
|
|
4
|
+
export type Value = Array<Uint8Array>;
|
|
5
|
+
/**
|
|
6
|
+
* The alignment of an onchain field-aligned binary data value.
|
|
7
|
+
*/
|
|
8
|
+
export type Alignment = AlignmentSegment[];
|
|
9
|
+
/**
|
|
10
|
+
* A segment in a larger {@link Alignment}.
|
|
11
|
+
*/
|
|
12
|
+
export type AlignmentSegment = { tag: 'option', value: Alignment[] } | { tag: 'atom', value: AlignmentAtom };
|
|
13
|
+
/**
|
|
14
|
+
* A atom in a larger {@link Alignment}.
|
|
15
|
+
*/
|
|
16
|
+
export type AlignmentAtom = { tag: 'compress' } | { tag: 'field' } | { tag: 'bytes', length: number };
|
|
17
|
+
/**
|
|
18
|
+
* An onchain data value, in field-aligned binary format, annotated with its
|
|
19
|
+
* alignment.
|
|
20
|
+
*/
|
|
21
|
+
export type AlignedValue = { value: Value, alignment: Alignment };
|
|
22
|
+
/**
|
|
23
|
+
* A Zswap nullifier, as a hex-encoded 256-bit bitstring
|
|
24
|
+
*/
|
|
25
|
+
export type Nullifier = string;
|
|
26
|
+
/**
|
|
27
|
+
* A Zswap coin commitment, as a hex-encoded 256-bit bitstring
|
|
28
|
+
*/
|
|
29
|
+
export type CoinCommitment = string;
|
|
30
|
+
/**
|
|
31
|
+
* A contract address, as a hex-encoded 32-byte string
|
|
32
|
+
*/
|
|
33
|
+
export type ContractAddress = string;
|
|
34
|
+
/**
|
|
35
|
+
* A user public key address, as a hex-encoded 32-byte string
|
|
36
|
+
*/
|
|
37
|
+
export type UserAddress = string;
|
|
38
|
+
/**
|
|
39
|
+
* The internal identifier attached to a {@link TokenType}, as a hex-encoded string.
|
|
40
|
+
*/
|
|
41
|
+
export type RawTokenType = string;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Unshielded token type (or color), as a hex-encoded 32-byte string
|
|
45
|
+
*/
|
|
46
|
+
export type UnshieldedTokenType = { tag: 'unshielded', raw: RawTokenType };
|
|
47
|
+
/**
|
|
48
|
+
* Shielded token type (or color), as a hex-encoded 32-byte string
|
|
49
|
+
*/
|
|
50
|
+
export type ShieldedTokenType = { tag: 'shielded', raw: RawTokenType };
|
|
51
|
+
/**
|
|
52
|
+
* Dust token type
|
|
53
|
+
*/
|
|
54
|
+
export type DustTokenType = { tag: 'dust' };
|
|
55
|
+
/**
|
|
56
|
+
* A token type (or color), as a hex-encoded 32-byte string, shielded, unshielded, or Dust
|
|
57
|
+
*/
|
|
58
|
+
export type TokenType = UnshieldedTokenType | ShieldedTokenType | DustTokenType;
|
|
59
|
+
/**
|
|
60
|
+
* A token domain seperator, the pre-stage of `TokenType`, as 32-byte bytearray
|
|
61
|
+
*/
|
|
62
|
+
export type DomainSeparator = Uint8Array;
|
|
63
|
+
/**
|
|
64
|
+
* A user public key capable of receiving Zswap coins, as a hex-encoded 32-byte
|
|
65
|
+
* string
|
|
66
|
+
*/
|
|
67
|
+
export type CoinPublicKey = string;
|
|
68
|
+
/**
|
|
69
|
+
* A running tally of synthetic resource costs.
|
|
70
|
+
*/
|
|
71
|
+
export type RunningCost = {
|
|
72
|
+
/**
|
|
73
|
+
* The amount of (modelled) time spent reading from disk, measured in picoseconds.
|
|
74
|
+
*/
|
|
75
|
+
readTime: bigint,
|
|
76
|
+
/**
|
|
77
|
+
* The amount of (modelled) time spent in single-threaded compute, measured in picoseconds.
|
|
78
|
+
*/
|
|
79
|
+
computeTime: bigint,
|
|
80
|
+
/**
|
|
81
|
+
* The number of (modelled) bytes written.
|
|
82
|
+
*/
|
|
83
|
+
bytesWritten: bigint,
|
|
84
|
+
/**
|
|
85
|
+
* The number of (modelled) bytes deleted.
|
|
86
|
+
*/
|
|
87
|
+
bytesDeleted: bigint,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The fee prices for transaction
|
|
92
|
+
*/
|
|
93
|
+
export type FeePrices = {
|
|
94
|
+
/**
|
|
95
|
+
* The overall price of a full block in an average cost dimension.
|
|
96
|
+
*/
|
|
97
|
+
overallPrice: number,
|
|
98
|
+
/**
|
|
99
|
+
* The price factor of time spent reading from disk.
|
|
100
|
+
*/
|
|
101
|
+
readFactor: number,
|
|
102
|
+
/**
|
|
103
|
+
* The price factor of time spent in single-threaded compute.
|
|
104
|
+
*/
|
|
105
|
+
computeFactor: number,
|
|
106
|
+
/**
|
|
107
|
+
* The price factor of block usage.
|
|
108
|
+
*/
|
|
109
|
+
blockUsageFactor: number,
|
|
110
|
+
/**
|
|
111
|
+
* The price factor of time spent writing to disk.
|
|
112
|
+
*/
|
|
113
|
+
writeFactor: number,
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Holds the coin secret key of a user, serialized as a hex-encoded 32-byte string
|
|
118
|
+
*/
|
|
119
|
+
export class CoinSecretKey {
|
|
120
|
+
private constructor();
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Clears the coin secret key, so that it is no longer usable nor held in memory
|
|
124
|
+
*/
|
|
125
|
+
clear(): void;
|
|
126
|
+
|
|
127
|
+
yesIKnowTheSecurityImplicationsOfThis_serialize(): Uint8Array;
|
|
128
|
+
|
|
129
|
+
static deserialize(raw: Uint8Array): CoinSecretKey
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* A Zswap nonce, as a hex-encoded 256-bit string
|
|
134
|
+
*/
|
|
135
|
+
export type Nonce = string;
|
|
136
|
+
/**
|
|
137
|
+
* The algorithm used for a particular signature.
|
|
138
|
+
*
|
|
139
|
+
* - `schnorr` corresponds to BIP-340 Schnorr signatures
|
|
140
|
+
* - `ecdsa` corresponds to ECDSA signatures over secp256k1
|
|
141
|
+
*/
|
|
142
|
+
export type SignatureKind = 'schnorr' | 'ecdsa';
|
|
143
|
+
/**
|
|
144
|
+
* A hex-encoded signature verifying key annotated with its kind
|
|
145
|
+
*/
|
|
146
|
+
export type SignatureVerifyingKey = { tag: SignatureKind, value: string };
|
|
147
|
+
/**
|
|
148
|
+
* A hex-encoded signing key annotated with its kind
|
|
149
|
+
*/
|
|
150
|
+
export type SigningKey = { tag: SignatureKind, value: string };
|
|
151
|
+
/**
|
|
152
|
+
* A hex-encoded signature annotated with its kind
|
|
153
|
+
*/
|
|
154
|
+
export type Signature = { tag: SignatureKind, value: string };
|
|
155
|
+
/**
|
|
156
|
+
* An internal encoding of a value of the proof systems scalar field
|
|
157
|
+
*/
|
|
158
|
+
export type Fr = Uint8Array;
|
|
159
|
+
/**
|
|
160
|
+
* Information required to create a new coin, alongside details about the
|
|
161
|
+
* recipient
|
|
162
|
+
*/
|
|
163
|
+
export type ShieldedCoinInfo = {
|
|
164
|
+
/**
|
|
165
|
+
* The coin's type, identifying the currency it represents
|
|
166
|
+
*/
|
|
167
|
+
type: RawTokenType,
|
|
168
|
+
/**
|
|
169
|
+
* The coin's randomness, preventing it from colliding with other coins
|
|
170
|
+
*/
|
|
171
|
+
nonce: Nonce,
|
|
172
|
+
/**
|
|
173
|
+
* The coin's value, in atomic units dependent on the currency
|
|
174
|
+
*
|
|
175
|
+
* Bounded to be a non-negative 64-bit integer
|
|
176
|
+
*/
|
|
177
|
+
value: bigint,
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Information required to spend an existing coin, alongside authorization of
|
|
181
|
+
* the owner
|
|
182
|
+
*/
|
|
183
|
+
export type QualifiedShieldedCoinInfo = {
|
|
184
|
+
/**
|
|
185
|
+
* The coin's type, identifying the currency it represents
|
|
186
|
+
*/
|
|
187
|
+
type: RawTokenType,
|
|
188
|
+
/**
|
|
189
|
+
* The coin's randomness, preventing it from colliding with other coins
|
|
190
|
+
*/
|
|
191
|
+
nonce: Nonce,
|
|
192
|
+
/**
|
|
193
|
+
* The coin's value, in atomic units dependent on the currency
|
|
194
|
+
*
|
|
195
|
+
* Bounded to be a non-negative 64-bit integer
|
|
196
|
+
*/
|
|
197
|
+
value: bigint,
|
|
198
|
+
/**
|
|
199
|
+
* The coin's location in the chain's Merkle tree of coin commitments
|
|
200
|
+
*
|
|
201
|
+
* Bounded to be a non-negative 64-bit integer
|
|
202
|
+
*/
|
|
203
|
+
mt_index: bigint,
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* A key used to index into an array or map in the onchain VM
|
|
208
|
+
*/
|
|
209
|
+
export type Key = { tag: 'value', value: AlignedValue } | { tag: 'stack' };
|
|
210
|
+
/**
|
|
211
|
+
* An individual operation in the onchain VM
|
|
212
|
+
*
|
|
213
|
+
* @typeParam R - `null` or {@link AlignedValue}, for gathering and verifying
|
|
214
|
+
* mode respectively
|
|
215
|
+
*/
|
|
216
|
+
export type Op<R> = { noop: { n: number } } |
|
|
217
|
+
'lt' |
|
|
218
|
+
'eq' |
|
|
219
|
+
'type' |
|
|
220
|
+
'size' |
|
|
221
|
+
'new' |
|
|
222
|
+
'and' |
|
|
223
|
+
'or' |
|
|
224
|
+
'neg' |
|
|
225
|
+
'log' |
|
|
226
|
+
'root' |
|
|
227
|
+
'pop' |
|
|
228
|
+
{ popeq: { cached: boolean, result: R } } |
|
|
229
|
+
{ addi: { immediate: number } } |
|
|
230
|
+
{ subi: { immediate: number } } |
|
|
231
|
+
{ push: { storage: boolean, value: EncodedStateValue } } |
|
|
232
|
+
{ branch: { skip: number } } |
|
|
233
|
+
{ jmp: { skip: number } } |
|
|
234
|
+
'add' |
|
|
235
|
+
'sub' |
|
|
236
|
+
{ concat: { cached: boolean, n: number } } |
|
|
237
|
+
'member' |
|
|
238
|
+
{ rem: { cached: boolean } } |
|
|
239
|
+
{ dup: { n: number } } |
|
|
240
|
+
{ swap: { n: number } } |
|
|
241
|
+
{ idx: { cached: boolean, pushPath: boolean, path: Key[] } } |
|
|
242
|
+
{ ins: { cached: boolean, n: number } } |
|
|
243
|
+
'ckpt';
|
|
244
|
+
/**
|
|
245
|
+
* The type of a log event embedded in {@link GatherResult}.
|
|
246
|
+
*/
|
|
247
|
+
export type LogEventType = 'shielded-spend' |
|
|
248
|
+
'shielded-receive' |
|
|
249
|
+
'shielded-mint' |
|
|
250
|
+
'shielded-burn' |
|
|
251
|
+
'unshielded-spend' |
|
|
252
|
+
'unshielded-receive' |
|
|
253
|
+
'unshielded-mint' |
|
|
254
|
+
'unshielded-burn' |
|
|
255
|
+
'paused' |
|
|
256
|
+
'unpaused' |
|
|
257
|
+
'misc';
|
|
258
|
+
/**
|
|
259
|
+
* An individual result of observing the results of a non-verifying VM program
|
|
260
|
+
* execution
|
|
261
|
+
*/
|
|
262
|
+
export type GatherResult = { tag: 'read', content: AlignedValue } |
|
|
263
|
+
{ tag: 'log', content: { version: number, eventType: LogEventType, data: EncodedStateValue} };
|
|
264
|
+
/**
|
|
265
|
+
* An alternative encoding of {@link StateValue} for use in {@link Op} for
|
|
266
|
+
* technical reasons
|
|
267
|
+
*/
|
|
268
|
+
export type EncodedStateValue = { tag: 'null' } |
|
|
269
|
+
{ tag: 'cell', content: AlignedValue } |
|
|
270
|
+
{ tag: 'map', content: Map<AlignedValue, EncodedStateValue> } |
|
|
271
|
+
{ tag: 'array', content: EncodedStateValue[] } |
|
|
272
|
+
{ tag: 'boundedMerkleTree', content: [number, Map<bigint, [Uint8Array, undefined]>] };
|
|
273
|
+
/**
|
|
274
|
+
* A transcript of operations, to be recorded in a transaction
|
|
275
|
+
*/
|
|
276
|
+
export type Transcript<R> = {
|
|
277
|
+
/**
|
|
278
|
+
* The execution budget for this transcript, which {@link program} must not
|
|
279
|
+
* exceed
|
|
280
|
+
*/
|
|
281
|
+
gas: RunningCost,
|
|
282
|
+
/**
|
|
283
|
+
* The effects of the transcript, which are checked before execution, and
|
|
284
|
+
* must match those constructed by {@link program}
|
|
285
|
+
*/
|
|
286
|
+
effects: Effects,
|
|
287
|
+
/**
|
|
288
|
+
* The sequence of operations that this transcript captured
|
|
289
|
+
*/
|
|
290
|
+
program: Op<R>[],
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* A public address that an entity can be identified by
|
|
294
|
+
*/
|
|
295
|
+
export type PublicAddress = { tag: 'user', address: UserAddress } | { tag: 'contract', address: ContractAddress }
|
|
296
|
+
/**
|
|
297
|
+
* The context information of a call provided to the VM.
|
|
298
|
+
*/
|
|
299
|
+
export type CallContext = {
|
|
300
|
+
ownAddress: ContractAddress,
|
|
301
|
+
/**
|
|
302
|
+
* The commitment indices map accessible to the contract.
|
|
303
|
+
*/
|
|
304
|
+
comIndices: Map<CoinCommitment, number>
|
|
305
|
+
/**
|
|
306
|
+
* The seconds since the UNIX epoch that have elapsed
|
|
307
|
+
*/
|
|
308
|
+
secondsSinceEpoch: bigint,
|
|
309
|
+
/**
|
|
310
|
+
* The maximum error on {@link secondsSinceEpoch} that should occur, as a
|
|
311
|
+
* positive seconds value
|
|
312
|
+
*/
|
|
313
|
+
secondsSinceEpochErr: number,
|
|
314
|
+
/**
|
|
315
|
+
* The hash of the block prior to this transaction, as a hex-encoded string
|
|
316
|
+
*/
|
|
317
|
+
parentBlockHash: string,
|
|
318
|
+
/**
|
|
319
|
+
* The balances held by the called contract at the time it was called.
|
|
320
|
+
*/
|
|
321
|
+
balance: Map<TokenType, bigint>,
|
|
322
|
+
/**
|
|
323
|
+
* A public address identifying an entity.
|
|
324
|
+
*/
|
|
325
|
+
caller?: PublicAddress,
|
|
326
|
+
/**
|
|
327
|
+
* The {@link secondsSinceEpoch} of the previous block
|
|
328
|
+
*/
|
|
329
|
+
lastBlockTime: bigint,
|
|
330
|
+
};
|
|
331
|
+
/**
|
|
332
|
+
* Context information about the block forwarded to {@link CallContext}.
|
|
333
|
+
*/
|
|
334
|
+
export type BlockContext = {
|
|
335
|
+
/**
|
|
336
|
+
* The seconds since the UNIX epoch that have elapsed
|
|
337
|
+
*/
|
|
338
|
+
secondsSinceEpoch: bigint,
|
|
339
|
+
/**
|
|
340
|
+
* The maximum error on {@link secondsSinceEpoch} that should occur, as a
|
|
341
|
+
* positive seconds value
|
|
342
|
+
*/
|
|
343
|
+
secondsSinceEpochErr: number,
|
|
344
|
+
/**
|
|
345
|
+
* The hash of the block prior to this transaction, as a hex-encoded string
|
|
346
|
+
*/
|
|
347
|
+
parentBlockHash: string,
|
|
348
|
+
/**
|
|
349
|
+
* The {@link secondsSinceEpoch} of the previous block
|
|
350
|
+
*/
|
|
351
|
+
lastBlockTime: bigint,
|
|
352
|
+
};
|
|
353
|
+
/**
|
|
354
|
+
* The contract-external effects of a transcript.
|
|
355
|
+
*/
|
|
356
|
+
export type Effects = {
|
|
357
|
+
/**
|
|
358
|
+
* The nullifiers (spends) this contract call requires
|
|
359
|
+
*/
|
|
360
|
+
claimedNullifiers: Nullifier[],
|
|
361
|
+
/**
|
|
362
|
+
* The coin commitments (outputs) this contract call requires, as coins
|
|
363
|
+
* received
|
|
364
|
+
*/
|
|
365
|
+
claimedShieldedReceives: CoinCommitment[],
|
|
366
|
+
/**
|
|
367
|
+
* The coin commitments (outputs) this contract call requires, as coins
|
|
368
|
+
* sent
|
|
369
|
+
*/
|
|
370
|
+
claimedShieldedSpends: CoinCommitment[],
|
|
371
|
+
/**
|
|
372
|
+
* The contracts called from this contract. The values are, in order:
|
|
373
|
+
*
|
|
374
|
+
* - The sequence number of this call
|
|
375
|
+
* - The contract being called
|
|
376
|
+
* - The entry point being called
|
|
377
|
+
* - The communications commitment
|
|
378
|
+
*/
|
|
379
|
+
claimedContractCalls: Array<[bigint, ContractAddress, string, Fr]>,
|
|
380
|
+
/**
|
|
381
|
+
* The shielded tokens minted in this call, as a map from hex-encoded 256-bit domain
|
|
382
|
+
* separators to unsigned 64-bit integers.
|
|
383
|
+
*/
|
|
384
|
+
shieldedMints: Map<string, bigint>,
|
|
385
|
+
/**
|
|
386
|
+
* The unshielded tokens minted in this call, as a map from hex-encoded 256-bit domain
|
|
387
|
+
* separators to unsigned 64-bit integers.
|
|
388
|
+
*/
|
|
389
|
+
unshieldedMints: Map<string, bigint>,
|
|
390
|
+
/**
|
|
391
|
+
* The unshielded inputs this contract expects.
|
|
392
|
+
*/
|
|
393
|
+
unshieldedInputs: Map<TokenType, bigint>,
|
|
394
|
+
/**
|
|
395
|
+
* The unshielded outputs this contract authorizes.
|
|
396
|
+
*/
|
|
397
|
+
unshieldedOutputs: Map<TokenType, bigint>,
|
|
398
|
+
/**
|
|
399
|
+
* The unshielded UTXO outputs this contract expects to be present.
|
|
400
|
+
*/
|
|
401
|
+
claimedUnshieldedSpends: Map<[TokenType, PublicAddress], bigint>,
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* A hex-encoded commitment of data shared between two contracts in a call
|
|
406
|
+
*/
|
|
407
|
+
export type CommunicationCommitment = string;
|
|
408
|
+
/**
|
|
409
|
+
* The hex-encoded randomness to {@link CommunicationCommitment}
|
|
410
|
+
*/
|
|
411
|
+
export type CommunicationCommitmentRand = string;
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Samples a new {@link CommunicationCommitmentRand} uniformly
|
|
415
|
+
*/
|
|
416
|
+
export function communicationCommitmentRandomness(): CommunicationCommitmentRand;
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Computes the communication commitment corresponding to an input/output pair and randomness.
|
|
420
|
+
*/
|
|
421
|
+
export function communicationCommitment(input: AlignedValue, output: AlignedValue, rand: CommunicationCommitmentRand): CommunicationCommitment;
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Computes the (hex-encoded) hash of a given contract entry point. Used in
|
|
425
|
+
* composable contracts to reference the called contract's entry point ID
|
|
426
|
+
* in-circuit.
|
|
427
|
+
*/
|
|
428
|
+
export function entryPointHash(entryPoint: string | Uint8Array): string;
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Randomly samples a {@link SigningKey}. If `kind` is not supplied, assumes
|
|
432
|
+
* `schnorr`.
|
|
433
|
+
*/
|
|
434
|
+
export function sampleSigningKey(kind?: SignatureKind): SigningKey;
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Creates a {@link SigningKey} from provided Bip340 private key.
|
|
438
|
+
*/
|
|
439
|
+
export function signingKeyFromBip340(data: Uint8Array): SigningKey;
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Signs arbitrary data with the given signing key.
|
|
443
|
+
*
|
|
444
|
+
* WARNING: Do not expose access to this function for valuable keys for data
|
|
445
|
+
* that is not strictly controlled!
|
|
446
|
+
*/
|
|
447
|
+
export function signData(key: SigningKey, data: Uint8Array): Signature;
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Returns the verifying key for a given signing key
|
|
451
|
+
*/
|
|
452
|
+
export function signatureVerifyingKey(sk: SigningKey): SignatureVerifyingKey;
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Verifies if a signature is correct
|
|
456
|
+
*/
|
|
457
|
+
export function verifySignature(vk: SignatureVerifyingKey, data: Uint8Array, signature: Signature): boolean;
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Encode a raw {@link RawTokenType} into a `Uint8Array` for use in Compact's
|
|
461
|
+
* `RawTokenType` type
|
|
462
|
+
*/
|
|
463
|
+
export function encodeRawTokenType(tt: RawTokenType): Uint8Array;
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Decode a raw {@link RawTokenType} from a `Uint8Array` originating from Compact's
|
|
467
|
+
* `RawTokenType` type
|
|
468
|
+
*/
|
|
469
|
+
export function decodeRawTokenType(tt: Uint8Array): RawTokenType;
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* Encode a {@link ContractAddress} into a `Uint8Array` for use in Compact's
|
|
473
|
+
* `ContractAddress` type
|
|
474
|
+
*/
|
|
475
|
+
export function encodeContractAddress(addr: ContractAddress): Uint8Array;
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Decode a {@link ContractAddress} from a `Uint8Array` originating from
|
|
479
|
+
* Compact's `ContractAddress` type
|
|
480
|
+
*/
|
|
481
|
+
export function decodeContractAddress(addr: Uint8Array): ContractAddress;
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Encode a {@link UserAddress} into a `Uint8Array` for use in Compact's
|
|
485
|
+
* `UserAddress` type
|
|
486
|
+
*/
|
|
487
|
+
export function encodeUserAddress(addr: UserAddress): Uint8Array;
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Decode a {@link UserAddress} from a `Uint8Array` originating from
|
|
491
|
+
* Compact's `UserAddress` type
|
|
492
|
+
*/
|
|
493
|
+
export function decodeUserAddress(addr: Uint8Array): UserAddress;
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Encode a {@link CoinPublicKey} into a `Uint8Array` for use in Compact's
|
|
497
|
+
* `CoinPublicKey` type
|
|
498
|
+
*/
|
|
499
|
+
export function encodeCoinPublicKey(pk: CoinPublicKey): Uint8Array;
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Decode a {@link CoinPublicKey} from a `Uint8Array` originating from Compact's
|
|
503
|
+
* `CoinPublicKey` type
|
|
504
|
+
*/
|
|
505
|
+
export function decodeCoinPublicKey(pk: Uint8Array): CoinPublicKey;
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Encode a {@link ShieldedCoinInfo} into a Compact's `ShieldedCoinInfo` TypeScript
|
|
509
|
+
* representation
|
|
510
|
+
*/
|
|
511
|
+
export function encodeShieldedCoinInfo(coin: ShieldedCoinInfo): { color: Uint8Array, nonce: Uint8Array, value: bigint };
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Encode a {@link QualifiedShieldedCoinInfo} into a Compact's `QualifiedShieldedCoinInfo`
|
|
515
|
+
* TypeScript representation
|
|
516
|
+
*/
|
|
517
|
+
export function encodeQualifiedShieldedCoinInfo(coin: QualifiedShieldedCoinInfo): {
|
|
518
|
+
color: Uint8Array,
|
|
519
|
+
nonce: Uint8Array,
|
|
520
|
+
value: bigint,
|
|
521
|
+
mt_index: bigint
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Decode a {@link ShieldedCoinInfo} from Compact's `ShieldedCoinInfo` TypeScript representation
|
|
526
|
+
*/
|
|
527
|
+
export function decodeShieldedCoinInfo(coin: { color: Uint8Array, nonce: Uint8Array, value: bigint }): ShieldedCoinInfo;
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Decode a {@link QualifiedShieldedCoinInfo} from Compact's `QualifiedShieldedCoinInfo`
|
|
531
|
+
* TypeScript representation
|
|
532
|
+
*/
|
|
533
|
+
export function decodeQualifiedShieldedCoinInfo(coin: {
|
|
534
|
+
color: Uint8Array,
|
|
535
|
+
nonce: Uint8Array,
|
|
536
|
+
value: bigint,
|
|
537
|
+
mt_index: bigint
|
|
538
|
+
}): QualifiedShieldedCoinInfo;
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Derives the raw {@link RawTokenType} associated with a particular
|
|
542
|
+
* {@link DomainSeparator} and contract.
|
|
543
|
+
*/
|
|
544
|
+
export function rawTokenType(domain_sep: DomainSeparator, contract: ContractAddress): RawTokenType;
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Samples a uniform contract address, for use in testing
|
|
548
|
+
*/
|
|
549
|
+
export function sampleContractAddress(): ContractAddress;
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Samples a uniform user address, for use in testing
|
|
553
|
+
*/
|
|
554
|
+
export function sampleUserAddress(): UserAddress;
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Samples a uniform raw token type, for use in testing to construct
|
|
558
|
+
* both the shielded and unshielded token types.
|
|
559
|
+
*/
|
|
560
|
+
export function sampleRawTokenType(): RawTokenType;
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* A sample contract address
|
|
564
|
+
*/
|
|
565
|
+
export function dummyContractAddress(): ContractAddress;
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* A sample user address
|
|
569
|
+
*/
|
|
570
|
+
export function dummyUserAddress(): UserAddress;
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Internal implementation of the runtime's coin commitment primitive.
|
|
574
|
+
* @internal
|
|
575
|
+
*/
|
|
576
|
+
export function runtimeCoinCommitment(coin: AlignedValue, recipient: AlignedValue): AlignedValue;
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Internal implementation of the runtime's coin nullifier primitive.
|
|
580
|
+
* @internal
|
|
581
|
+
*/
|
|
582
|
+
export function runtimeCoinNullifier(coin: AlignedValue, sender_evidence: AlignedValue): AlignedValue;
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* Internal implementation of the Merkle tree leaf hash primitive.
|
|
586
|
+
* @internal
|
|
587
|
+
*/
|
|
588
|
+
export function leafHash(value: AlignedValue): AlignedValue;
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* Internal implementation of the max aligned size primitive.
|
|
592
|
+
* @internal
|
|
593
|
+
*/
|
|
594
|
+
export function maxAlignedSize(alignment: Alignment): bigint;
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Returns the maximum representable value in the proof systems scalar field
|
|
598
|
+
* (that is, 1 less than the prime modulus)
|
|
599
|
+
*/
|
|
600
|
+
export function maxField(): bigint;
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Converts input, output, and transcript information into a proof preimage
|
|
604
|
+
* suitable to pass to a `ProvingProvider`.
|
|
605
|
+
*
|
|
606
|
+
* The `key_location` parameter is a string used to identify the circuit by
|
|
607
|
+
* proving machinery, for backwards-compatibility, if unset it defaults to
|
|
608
|
+
* `'dummy'`.
|
|
609
|
+
*/
|
|
610
|
+
export function proofDataIntoSerializedPreimage(
|
|
611
|
+
input: AlignedValue,
|
|
612
|
+
output: AlignedValue,
|
|
613
|
+
public_transcript: Op<AlignedValue>[],
|
|
614
|
+
private_transcript_outputs: AlignedValue[],
|
|
615
|
+
key_location?: string,
|
|
616
|
+
): Uint8Array;
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Takes a bigint modulus the proof systems scalar field
|
|
620
|
+
*/
|
|
621
|
+
export function bigIntModFr(x: bigint): bigint;
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Returns the largest representable JubJub scalar (i.e. the JubJub scalar field modulus minus one).
|
|
625
|
+
*/
|
|
626
|
+
export function maxJubjubScalar(): bigint;
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* Samples a random JubJub scalar, returned as a native field element.
|
|
630
|
+
*/
|
|
631
|
+
export function jubjubSampleScalar(): Value;
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* Converts a native field element (BLS12-381 scalar) to a JubJub scalar field
|
|
635
|
+
* element, reducing modulo the JubJub scalar field modulus.
|
|
636
|
+
*/
|
|
637
|
+
export function jubjubScalarFromNative(native: Value): Value;
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* Converts a JubJub scalar field element to a native field element (BLS12-381 scalar).
|
|
641
|
+
*/
|
|
642
|
+
export function nativeFromJubjubScalar(jubjub: Value): Value;
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Internal conversion between field-aligned binary values and bigints within
|
|
646
|
+
* the scalar field
|
|
647
|
+
* @internal
|
|
648
|
+
* @throws If the value does not encode a field element
|
|
649
|
+
*/
|
|
650
|
+
export function valueToBigInt(x: Value): bigint;
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* Internal conversion between bigints and their field-aligned binary
|
|
654
|
+
* representation
|
|
655
|
+
* @internal
|
|
656
|
+
*/
|
|
657
|
+
export function bigIntToValue(x: bigint): Value;
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* Internal implementation of the transient hash primitive
|
|
661
|
+
* @internal
|
|
662
|
+
* @throws If {@link val} does not have alignment {@link align}
|
|
663
|
+
*/
|
|
664
|
+
export function transientHash(align: Alignment, val: Value): Value;
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* Internal implementation of the transient commitment primitive
|
|
668
|
+
* @internal
|
|
669
|
+
* @throws If {@link val} does not have alignment {@link align}, or
|
|
670
|
+
* {@link opening} does not encode a field element
|
|
671
|
+
*/
|
|
672
|
+
export function transientCommit(align: Alignment, val: Value, opening: Value): Value;
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* Internal implementation of the persistent hash primitive
|
|
676
|
+
* @internal
|
|
677
|
+
* @throws If {@link val} does not have alignment {@link align}, or any
|
|
678
|
+
* component has a compress alignment
|
|
679
|
+
*/
|
|
680
|
+
export function persistentHash(align: Alignment, val: Value): Value;
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* Internal implementation of the persistent commitment primitive
|
|
684
|
+
* @internal
|
|
685
|
+
* @throws If {@link val} does not have alignment {@link align},
|
|
686
|
+
* {@link opening} does not encode a 32-byte bytestring, or any component has a
|
|
687
|
+
* compress alignment
|
|
688
|
+
*/
|
|
689
|
+
export function persistentCommit(align: Alignment, val: Value, opening: Value): Value;
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* Internal implementation of the degrade to transient primitive
|
|
693
|
+
* @internal
|
|
694
|
+
* @throws If {@link persistent} does not encode a 32-byte bytestring
|
|
695
|
+
*/
|
|
696
|
+
export function degradeToTransient(persistent: Value): Value;
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* Internal implementation of the upgrade from transient primitive
|
|
700
|
+
* @internal
|
|
701
|
+
* @throws If {@link transient} does not encode a field element
|
|
702
|
+
*/
|
|
703
|
+
export function upgradeFromTransient(transient: Value): Value;
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* Internal implementation of the hash to curve primitive
|
|
707
|
+
* @internal
|
|
708
|
+
* @throws If {@link val} does not have alignment {@link align}
|
|
709
|
+
*/
|
|
710
|
+
export function hashToCurve(align: Alignment, val: Value): Value;
|
|
711
|
+
|
|
712
|
+
/**
|
|
713
|
+
* Internal implementation of the elliptic curve addition primitive
|
|
714
|
+
* @internal
|
|
715
|
+
* @throws If either input does not encode an elliptic curve point
|
|
716
|
+
*/
|
|
717
|
+
export function ecAdd(a: Value, b: Value): Value;
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* Internal implementation of the elliptic curve multiplication primitive
|
|
721
|
+
* @internal
|
|
722
|
+
* @throws If {@link a} does not encode an elliptic curve point or {@link b}
|
|
723
|
+
* does not encode a field element
|
|
724
|
+
*/
|
|
725
|
+
export function ecMul(a: Value, b: Value): Value;
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* Internal implementation of the elliptic curve generator multiplication
|
|
729
|
+
* primitive
|
|
730
|
+
* @internal
|
|
731
|
+
* @throws if {@link val} does not encode a field element
|
|
732
|
+
*/
|
|
733
|
+
export function ecMulGenerator(val: Value): Value;
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* Runs a VM program against an initial stack, with an optional gas limit
|
|
737
|
+
*/
|
|
738
|
+
export function runProgram(initial: VmStack, ops: Op<null>[], cost_model: CostModel, gas_limit?: RunningCost): VmResults;
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* An individual operation, or entry point of a contract, consisting primarily
|
|
742
|
+
* of a ZK verifier keys, potentially for different versions of the proving
|
|
743
|
+
* system.
|
|
744
|
+
*
|
|
745
|
+
* Only the latest available version is exposed to this API.
|
|
746
|
+
*
|
|
747
|
+
* Note that the serialized form of the key is checked on initialization
|
|
748
|
+
*/
|
|
749
|
+
export class ContractOperation {
|
|
750
|
+
constructor();
|
|
751
|
+
|
|
752
|
+
verifierKey: Uint8Array;
|
|
753
|
+
|
|
754
|
+
serialize(): Uint8Array;
|
|
755
|
+
|
|
756
|
+
static deserialize(raw: Uint8Array): ContractOperation;
|
|
757
|
+
|
|
758
|
+
toString(compact?: boolean): string;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* A committee permitted to make changes to this contract. If a threshold of
|
|
763
|
+
* the public keys in this committee sign off, they can change the rules of
|
|
764
|
+
* this contract, or recompile it for a new version.
|
|
765
|
+
*
|
|
766
|
+
* If the threshold is greater than the number of committee members, it is
|
|
767
|
+
* impossible for them to sign anything.
|
|
768
|
+
*/
|
|
769
|
+
export class ContractMaintenanceAuthority {
|
|
770
|
+
/**
|
|
771
|
+
* Constructs a new authority from its components
|
|
772
|
+
*
|
|
773
|
+
* If not supplied, `counter` will default to `0n`. Values should be
|
|
774
|
+
* non-negative, and at most 2^32 - 1.
|
|
775
|
+
*
|
|
776
|
+
* At deployment, `counter` must be `0n`, and any subsequent update should
|
|
777
|
+
* set counter to exactly one greater than the current value.
|
|
778
|
+
*/
|
|
779
|
+
constructor(committee: Array<SignatureVerifyingKey>, threshold: number, counter?: bigint);
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* The committee public keys
|
|
783
|
+
*/
|
|
784
|
+
readonly committee: Array<SignatureVerifyingKey>;
|
|
785
|
+
/**
|
|
786
|
+
* How many keys must sign rule changes
|
|
787
|
+
*/
|
|
788
|
+
readonly threshold: number;
|
|
789
|
+
/**
|
|
790
|
+
* The replay protection counter
|
|
791
|
+
*/
|
|
792
|
+
readonly counter: bigint;
|
|
793
|
+
|
|
794
|
+
serialize(): Uint8Array;
|
|
795
|
+
|
|
796
|
+
static deserialize(raw: Uint8Array): ContractMaintenanceAuthority;
|
|
797
|
+
|
|
798
|
+
toString(compact?: boolean): string;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* The state of a contract, consisting primarily of the {@link data} accessible
|
|
803
|
+
* directly to the contract, and the map of {@link ContractOperation}s that can
|
|
804
|
+
* be called on it, the keys of which can be accessed with {@link operations},
|
|
805
|
+
* and the individual operations can be read with {@link operation} and written
|
|
806
|
+
* to with {@link setOperation}.
|
|
807
|
+
*/
|
|
808
|
+
export class ContractState {
|
|
809
|
+
/**
|
|
810
|
+
* Creates a blank contract state
|
|
811
|
+
*/
|
|
812
|
+
constructor();
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* Return a list of the entry points currently registered on this contract
|
|
816
|
+
*/
|
|
817
|
+
operations(): Array<string | Uint8Array>
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* Get the operation at a specific entry point name
|
|
821
|
+
*/
|
|
822
|
+
operation(operation: string | Uint8Array): ContractOperation | undefined;
|
|
823
|
+
|
|
824
|
+
/**
|
|
825
|
+
* Set a specific entry point name to contain a given operation
|
|
826
|
+
*/
|
|
827
|
+
setOperation(operation: string | Uint8Array, value: ContractOperation): void;
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* Runs a series of operations against the current state, and returns the
|
|
831
|
+
* results
|
|
832
|
+
*/
|
|
833
|
+
query(query: Op<null>[], cost_model: CostModel): GatherResult[];
|
|
834
|
+
|
|
835
|
+
serialize(): Uint8Array;
|
|
836
|
+
|
|
837
|
+
static deserialize(raw: Uint8Array): ContractState;
|
|
838
|
+
|
|
839
|
+
toString(compact?: boolean): string;
|
|
840
|
+
|
|
841
|
+
/**
|
|
842
|
+
* The current value of the primary state of the contract
|
|
843
|
+
*/
|
|
844
|
+
data: ChargedState;
|
|
845
|
+
/**
|
|
846
|
+
* The maintenance authority associated with this contract
|
|
847
|
+
*/
|
|
848
|
+
maintenanceAuthority: ContractMaintenanceAuthority;
|
|
849
|
+
/**
|
|
850
|
+
* The public balances held by this contract
|
|
851
|
+
*/
|
|
852
|
+
balance: Map<TokenType, bigint>;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
/**
|
|
856
|
+
* Provides the information needed to fully process a transaction, including
|
|
857
|
+
* information about the rest of the transaction, and the state of the chain at
|
|
858
|
+
* the time of execution.
|
|
859
|
+
*/
|
|
860
|
+
export class QueryContext {
|
|
861
|
+
/**
|
|
862
|
+
* Construct a basic context from a contract's address and current state
|
|
863
|
+
* value
|
|
864
|
+
*/
|
|
865
|
+
constructor(state: ChargedState, address: ContractAddress);
|
|
866
|
+
|
|
867
|
+
/**
|
|
868
|
+
* Register a given coin commitment as being accessible at a specific index,
|
|
869
|
+
* for use when receiving coins in-contract, and needing to record their
|
|
870
|
+
* index to later spend them
|
|
871
|
+
*/
|
|
872
|
+
insertCommitment(comm: CoinCommitment, index: bigint): QueryContext;
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* Internal counterpart to {@link insertCommitment}; upgrades an encoded
|
|
876
|
+
* {@link ShieldedCoinInfo} to an encoded {@link QualifiedShieldedCoinInfo} using the
|
|
877
|
+
* inserted commitments
|
|
878
|
+
* @internal
|
|
879
|
+
*/
|
|
880
|
+
qualify(coin: Value): Value | undefined;
|
|
881
|
+
|
|
882
|
+
/**
|
|
883
|
+
* Runs a transcript in verifying mode against the current query context,
|
|
884
|
+
* outputting a new query context, with the {@link state} and {@link effects}
|
|
885
|
+
* from after the execution.
|
|
886
|
+
*/
|
|
887
|
+
runTranscript(transcript: Transcript<AlignedValue>, cost_model: CostModel): QueryContext;
|
|
888
|
+
|
|
889
|
+
/**
|
|
890
|
+
* Runs a sequence of operations in gather mode, returning the results of the
|
|
891
|
+
* gather.
|
|
892
|
+
*/
|
|
893
|
+
query(ops: Op<null>[], cost_model: CostModel, gas_limit?: RunningCost): QueryResults;
|
|
894
|
+
|
|
895
|
+
/**
|
|
896
|
+
* Converts the QueryContext to {@link VmStack}.
|
|
897
|
+
*/
|
|
898
|
+
toVmStack(): VmStack;
|
|
899
|
+
|
|
900
|
+
toString(compact?: boolean): string;
|
|
901
|
+
|
|
902
|
+
/**
|
|
903
|
+
* The address of the contract
|
|
904
|
+
*/
|
|
905
|
+
readonly address: ContractAddress;
|
|
906
|
+
/**
|
|
907
|
+
* The block-level information accessible to the contract
|
|
908
|
+
*/
|
|
909
|
+
block: CallContext;
|
|
910
|
+
/**
|
|
911
|
+
* The commitment indices map accessible to the contract, primarily via
|
|
912
|
+
* {@link qualify}
|
|
913
|
+
*/
|
|
914
|
+
readonly comIndices: Map<CoinCommitment, bigint>;
|
|
915
|
+
/**
|
|
916
|
+
* The effects that occurred during execution against this context, should
|
|
917
|
+
* match those declared in a {@link Transcript}
|
|
918
|
+
*/
|
|
919
|
+
effects: Effects;
|
|
920
|
+
/**
|
|
921
|
+
* The current contract state retained in the context
|
|
922
|
+
*/
|
|
923
|
+
readonly state: ChargedState;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
/**
|
|
927
|
+
* A cost model for calculating transaction fees
|
|
928
|
+
*/
|
|
929
|
+
export class CostModel {
|
|
930
|
+
private constructor();
|
|
931
|
+
|
|
932
|
+
/**
|
|
933
|
+
* The initial cost model of Midnight
|
|
934
|
+
*/
|
|
935
|
+
static initialCostModel(): CostModel;
|
|
936
|
+
|
|
937
|
+
toString(compact?: boolean): string;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
/**
|
|
941
|
+
* The results of making a query against a specific state or context
|
|
942
|
+
*/
|
|
943
|
+
export class QueryResults {
|
|
944
|
+
private constructor();
|
|
945
|
+
|
|
946
|
+
toString(compact?: boolean): string;
|
|
947
|
+
|
|
948
|
+
/**
|
|
949
|
+
* The context state after executing the query. This can be used to execute
|
|
950
|
+
* further queries
|
|
951
|
+
*/
|
|
952
|
+
readonly context: QueryContext;
|
|
953
|
+
/**
|
|
954
|
+
* Any events/results that occurred during or from the query
|
|
955
|
+
*/
|
|
956
|
+
readonly events: GatherResult[];
|
|
957
|
+
/**
|
|
958
|
+
* The measured cost of executing the query
|
|
959
|
+
*/
|
|
960
|
+
readonly gasCost: RunningCost;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
/**
|
|
964
|
+
* Represents a fixed-depth Merkle tree storing hashed data, whose preimages
|
|
965
|
+
* are unknown
|
|
966
|
+
*/
|
|
967
|
+
export class StateBoundedMerkleTree {
|
|
968
|
+
/**
|
|
969
|
+
* Create a blank tree with the given height
|
|
970
|
+
*/
|
|
971
|
+
constructor(height: number);
|
|
972
|
+
|
|
973
|
+
/**
|
|
974
|
+
* Internal implementation of the merkle tree root primitive.
|
|
975
|
+
* Returns undefined if the tree has not been fully hashed.
|
|
976
|
+
* @internal
|
|
977
|
+
*/
|
|
978
|
+
root(): AlignedValue | undefined;
|
|
979
|
+
|
|
980
|
+
/**
|
|
981
|
+
* Internal implementation of the finding path primitive.
|
|
982
|
+
* Returns undefined if the leaf is not in the tree.
|
|
983
|
+
* @internal
|
|
984
|
+
*/
|
|
985
|
+
findPathForLeaf(
|
|
986
|
+
leaf: AlignedValue,
|
|
987
|
+
indexStart?: bigint,
|
|
988
|
+
indexEnd?: bigint,
|
|
989
|
+
alreadyHashed?: boolean,
|
|
990
|
+
): AlignedValue | undefined;
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* Internal implementation of the path construction primitive
|
|
994
|
+
* @internal
|
|
995
|
+
* @throws If the index is out-of-bounds for the tree
|
|
996
|
+
*/
|
|
997
|
+
pathForLeaf(index: bigint, leaf: AlignedValue): AlignedValue;
|
|
998
|
+
|
|
999
|
+
/**
|
|
1000
|
+
* Inserts a value into the Merkle tree, returning the updated tree
|
|
1001
|
+
* @throws If the index is out-of-bounds for the tree
|
|
1002
|
+
*/
|
|
1003
|
+
update(index: bigint, leaf: AlignedValue): StateBoundedMerkleTree;
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* Rehashes the tree, updating all internal hashes and ensuring all
|
|
1007
|
+
* node hashes are present. Necessary because the onchain runtime does
|
|
1008
|
+
* not automatically rehash trees.
|
|
1009
|
+
*/
|
|
1010
|
+
rehash(): StateBoundedMerkleTree;
|
|
1011
|
+
|
|
1012
|
+
/**
|
|
1013
|
+
* Erases all but necessary hashes between, and inclusive of, `start` and
|
|
1014
|
+
* `end` inidices @internal
|
|
1015
|
+
* @throws If the indices are out-of-bounds for the tree, or `end < start`
|
|
1016
|
+
*/
|
|
1017
|
+
collapse(start: bigint, end: bigint): StateBoundedMerkleTree;
|
|
1018
|
+
|
|
1019
|
+
toString(compact?: boolean): string;
|
|
1020
|
+
|
|
1021
|
+
readonly height: number;
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
/**
|
|
1025
|
+
* Represents a key-value map, where keys are {@link AlignedValue}s, and values
|
|
1026
|
+
* are {@link StateValue}s.
|
|
1027
|
+
*/
|
|
1028
|
+
export class StateMap {
|
|
1029
|
+
constructor();
|
|
1030
|
+
|
|
1031
|
+
keys(): AlignedValue[];
|
|
1032
|
+
|
|
1033
|
+
get(key: AlignedValue): StateValue | undefined;
|
|
1034
|
+
|
|
1035
|
+
insert(key: AlignedValue, value: StateValue): StateMap;
|
|
1036
|
+
|
|
1037
|
+
remove(key: AlignedValue): StateMap;
|
|
1038
|
+
|
|
1039
|
+
toString(compact?: boolean): string;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
/**
|
|
1043
|
+
* Represents a {@link StateValue} with storage annotations.
|
|
1044
|
+
*
|
|
1045
|
+
* These track the state usage that has been charged for so far.
|
|
1046
|
+
*/
|
|
1047
|
+
export class ChargedState {
|
|
1048
|
+
constructor(state: StateValue);
|
|
1049
|
+
readonly state: StateValue;
|
|
1050
|
+
toString(compact?: boolean): string;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
/**
|
|
1054
|
+
* Represents the core of a contract's state, and recursively represents each
|
|
1055
|
+
* of its components.
|
|
1056
|
+
*
|
|
1057
|
+
* There are different *classes* of state values:
|
|
1058
|
+
* - `null`
|
|
1059
|
+
* - Cells of {@link AlignedValue}s
|
|
1060
|
+
* - Maps from {@link AlignedValue}s to state values
|
|
1061
|
+
* - Bounded Merkle trees containing {@link AlignedValue} leaves
|
|
1062
|
+
* - Short (\<= 15 element) arrays of state values
|
|
1063
|
+
*
|
|
1064
|
+
* State values are *immutable*, any operations that mutate states will return
|
|
1065
|
+
* a new state instead.
|
|
1066
|
+
*/
|
|
1067
|
+
export class StateValue {
|
|
1068
|
+
private constructor();
|
|
1069
|
+
|
|
1070
|
+
type(): 'null' | 'cell' | 'map' | 'array' | 'boundedMerkleTree';
|
|
1071
|
+
|
|
1072
|
+
static newNull(): StateValue;
|
|
1073
|
+
|
|
1074
|
+
static newCell(value: AlignedValue): StateValue;
|
|
1075
|
+
|
|
1076
|
+
static newMap(map: StateMap): StateValue;
|
|
1077
|
+
|
|
1078
|
+
static newBoundedMerkleTree(tree: StateBoundedMerkleTree): StateValue;
|
|
1079
|
+
|
|
1080
|
+
static newArray(): StateValue;
|
|
1081
|
+
|
|
1082
|
+
arrayPush(value: StateValue): StateValue;
|
|
1083
|
+
|
|
1084
|
+
asCell(): AlignedValue;
|
|
1085
|
+
|
|
1086
|
+
asMap(): StateMap | undefined;
|
|
1087
|
+
|
|
1088
|
+
asBoundedMerkleTree(): StateBoundedMerkleTree | undefined;
|
|
1089
|
+
|
|
1090
|
+
asArray(): StateValue[] | undefined;
|
|
1091
|
+
|
|
1092
|
+
logSize(): number;
|
|
1093
|
+
|
|
1094
|
+
toString(compact?: boolean): string;
|
|
1095
|
+
|
|
1096
|
+
/**
|
|
1097
|
+
* @internal
|
|
1098
|
+
*/
|
|
1099
|
+
encode(): EncodedStateValue;
|
|
1100
|
+
|
|
1101
|
+
/**
|
|
1102
|
+
* @internal
|
|
1103
|
+
*/
|
|
1104
|
+
static decode(value: EncodedStateValue): StateValue;
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
/**
|
|
1108
|
+
* Represents the results of a VM call
|
|
1109
|
+
*/
|
|
1110
|
+
export class VmResults {
|
|
1111
|
+
private constructor();
|
|
1112
|
+
|
|
1113
|
+
toString(compact?: boolean): string;
|
|
1114
|
+
|
|
1115
|
+
/**
|
|
1116
|
+
* The events that got emitted by this VM invocation
|
|
1117
|
+
*/
|
|
1118
|
+
readonly events: GatherResult[];
|
|
1119
|
+
/**
|
|
1120
|
+
* The computed gas cost of running this VM invocation
|
|
1121
|
+
*/
|
|
1122
|
+
readonly gasCost: RunningCost;
|
|
1123
|
+
/**
|
|
1124
|
+
* The VM stack at the end of the VM invocation
|
|
1125
|
+
*/
|
|
1126
|
+
readonly stack: VmStack;
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
/**
|
|
1130
|
+
* Represents the state of the VM's stack at a specific point. The stack is an
|
|
1131
|
+
* array of {@link StateValue}s, each of which is also annotated with whether
|
|
1132
|
+
* it is "strong" or "weak"; that is, whether it is permitted to be stored
|
|
1133
|
+
* on-chain or not.
|
|
1134
|
+
*/
|
|
1135
|
+
export class VmStack {
|
|
1136
|
+
constructor();
|
|
1137
|
+
|
|
1138
|
+
push(value: StateValue, is_strong: boolean): void;
|
|
1139
|
+
|
|
1140
|
+
removeLast(): void;
|
|
1141
|
+
|
|
1142
|
+
length(): number;
|
|
1143
|
+
|
|
1144
|
+
get(idx: number): StateValue | undefined;
|
|
1145
|
+
|
|
1146
|
+
isStrong(idx: number): boolean | undefined;
|
|
1147
|
+
|
|
1148
|
+
toString(compact?: boolean): string;
|
|
1149
|
+
}
|