@midnight-ntwrk/midnight-js-protocol 5.0.0-beta.7 → 5.0.0-beta.8

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/dist/index.d.ts CHANGED
@@ -1,10 +1,1286 @@
1
+ import * as ledgerV9 from '@midnightntwrk/ledger-v9';
2
+ import { EncodedStateValue, Op as Op$1, AlignedValue as AlignedValue$1, CallContext, Effects, CoinCommitment, Transcript, ContractCallPrototype } from '@midnightntwrk/ledger-v9';
3
+ export { ledgerV9 as ledger };
4
+ export { EncodedStateValue } from '@midnightntwrk/ledger-v9';
5
+ import * as ledgerV8 from '@midnightntwrk/ledger-v8';
6
+ import * as OnchainRuntimeV3 from '@midnight-ntwrk/onchain-runtime-v3';
7
+ import { EncodedZswapLocalState, ProofData, ZswapLocalState } from 'compact-runtime-ledger8';
1
8
  import * as compactJs from '@midnight-ntwrk/compact-js';
2
9
  export { compactJs };
3
10
  import * as compactRuntime from '@midnight-ntwrk/compact-runtime';
4
11
  export { compactRuntime };
5
12
  import * as platformJs from '@midnight-ntwrk/platform-js';
6
13
  export { platformJs as platform };
7
- import * as ledgerV9 from '@midnightntwrk/ledger-v9';
8
- export { ledgerV9 as ledger };
9
14
  import * as onchainRuntimeV4 from '@midnightntwrk/onchain-runtime-v4';
10
15
  export { onchainRuntimeV4 as onchainRuntime };
16
+
17
+ function _mergeNamespaces(n, m) {
18
+ m.forEach(function (e) {
19
+ e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
20
+ if (k !== 'default' && !(k in n)) {
21
+ var d = Object.getOwnPropertyDescriptor(e, k);
22
+ Object.defineProperty(n, k, d.get ? d : {
23
+ enumerable: true,
24
+ get: function () { return e[k]; }
25
+ });
26
+ }
27
+ });
28
+ });
29
+ return Object.freeze(n);
30
+ }
31
+
32
+ /**
33
+ * The two ledger runtimes midnight-js can talk to. `v8` backs the node 1.x
34
+ * line; `v9` backs the 2.x line. This is a closed, exhaustive set — see
35
+ * `protocolVersionToLedger` (`../version.ts`) for how a raw `protocolVersion`
36
+ * integer maps onto it.
37
+ *
38
+ * @see {@link SharedTableDiscipline} for why the array is frozen.
39
+ * @see {@link ModuleGraphAndLazyLoading} for why the constant is declared in
40
+ * this leaf module and re-exported by `../version.ts`.
41
+ */
42
+ declare const LEDGER_VERSIONS: readonly ["v8", "v9"];
43
+ type LedgerVersion = (typeof LEDGER_VERSIONS)[number];
44
+ /**
45
+ * The era whose objects this build hands out live, through `./ledger`.
46
+ *
47
+ * A protocol fact rather than a consumer's choice: it is decided by which
48
+ * ledger the package links eagerly, and every other era is reached lazily and
49
+ * crosses package boundaries as bytes. Declared here so that no package
50
+ * downstream restates "which era is now" as a literal of its own.
51
+ *
52
+ * The type is the single literal, not {@link LedgerVersion}, so a value typed
53
+ * by it DISCRIMINATES — the same discipline `CurrentPipelineEra` follows in
54
+ * `midnight-js-contracts`.
55
+ */
56
+ declare const CURRENT_LEDGER_VERSION: "v9";
57
+ type CurrentLedgerVersion = typeof CURRENT_LEDGER_VERSION;
58
+ /**
59
+ * Every era this build still speaks but does not run live — the eras that
60
+ * cross a package boundary as serialized bytes.
61
+ *
62
+ * Defined as the complement of {@link CURRENT_LEDGER_VERSION}, so a further
63
+ * era joins this set by being added to {@link LEDGER_VERSIONS} and nothing
64
+ * else. The value list below is checked against that complement at build time.
65
+ */
66
+ type RetainedLedgerVersion = Exclude<LedgerVersion, CurrentLedgerVersion>;
67
+ declare const RETAINED_LEDGER_VERSIONS: readonly ["v8"];
68
+
69
+ /**
70
+ * Stable error-code strings for this package. Every error class in this module
71
+ * carries one of these on its `code` field, which is the field a consumer
72
+ * switches on to tell one failure from another.
73
+ *
74
+ * @see {@link SharedTableDiscipline}
75
+ */
76
+ declare const PROTOCOL_ERROR_CODES: Readonly<{
77
+ readonly UNKNOWN_PROTOCOL_VERSION_READ: "MIDNIGHT_JS_P_UNKNOWN_PROTOCOL_VERSION_READ";
78
+ readonly UNKNOWN_PROTOCOL_VERSION_CONSTRUCT: "MIDNIGHT_JS_P_UNKNOWN_PROTOCOL_VERSION_CONSTRUCT";
79
+ readonly LEDGER8_INSTANCE_MISMATCH: "MIDNIGHT_JS_P_LEDGER8_INSTANCE_MISMATCH";
80
+ readonly LEDGER8_RUNTIME_MISSING: "MIDNIGHT_JS_P_LEDGER8_RUNTIME_MISSING";
81
+ readonly DOWN_CONVERT_FAILED: "MIDNIGHT_JS_P_DOWN_CONVERT_FAILED";
82
+ readonly MERKLE_NOT_REHASHED: "MIDNIGHT_JS_P_MERKLE_NOT_REHASHED";
83
+ readonly COMPOSE_FAILED: "MIDNIGHT_JS_P_COMPOSE_FAILED";
84
+ readonly COMPOSE_OPTION_INVALID: "MIDNIGHT_JS_P_COMPOSE_OPTION_INVALID";
85
+ readonly STATE_DECODE_FAILED: "MIDNIGHT_JS_P_STATE_DECODE_FAILED";
86
+ readonly UNKNOWN_LEDGER_VERSION: "MIDNIGHT_JS_P_UNKNOWN_LEDGER_VERSION";
87
+ readonly LEDGER8_RUNTIME_INVALID: "MIDNIGHT_JS_P_LEDGER8_RUNTIME_INVALID";
88
+ readonly UNKNOWN_LEDGER8_AXIS: "MIDNIGHT_JS_P_UNKNOWN_LEDGER8_AXIS";
89
+ readonly PAYLOAD_NOT_A_TRANSACTION: "MIDNIGHT_JS_P_PAYLOAD_NOT_A_TRANSACTION";
90
+ }>;
91
+ /** The union of every value in {@link PROTOCOL_ERROR_CODES}; the type of every error class's `code` field. */
92
+ type ProtocolErrorCode = (typeof PROTOCOL_ERROR_CODES)[keyof typeof PROTOCOL_ERROR_CODES];
93
+ /**
94
+ * Which call path asked for a ledger version:
95
+ * - `'read'` — the version was taken off an existing record.
96
+ * - `'construct'` — the version was chosen to build something new against the
97
+ * network's current head.
98
+ */
99
+ type VersionResolutionPath = 'read' | 'construct';
100
+ /**
101
+ * Why `protocolVersionToLedger` could not resolve a ledger version:
102
+ * - `'malformed'` — the input was not even a well-formed protocolVersion
103
+ * value (not a non-negative integer).
104
+ * - `'unknown'` — the input was a well-formed integer, but outside every
105
+ * range this framework version knows how to map.
106
+ */
107
+ type ProtocolVersionUnknownReason = 'unknown' | 'malformed';
108
+ /**
109
+ * Thrown by `protocolVersionToLedger` (and, transitively, `versionOfRecord` /
110
+ * `networkHeadVersion`) when a raw `protocolVersion` integer cannot be
111
+ * resolved to a `LedgerVersion`. Those live in `./version`, which imports this
112
+ * module -- the dependency stays one-way, so they are named here rather than
113
+ * linked.
114
+ *
115
+ * `code` is the field to switch on to tell all four cases apart: it splits
116
+ * `reason` by the `path` that produced it.
117
+ *
118
+ * @param protocolVersion The raw `protocolVersion` value that could not be
119
+ * resolved. Carried for programmatic use, and rendered in the message.
120
+ * @param path Which call path asked for the version — see
121
+ * {@link VersionResolutionPath}.
122
+ * @param reason A malformed input (wrong shape or type, not a
123
+ * protocol-version problem at all) or a well-formed but genuinely unknown
124
+ * version (a real protocol version this framework build does not support
125
+ * yet) — see {@link ProtocolVersionUnknownReason}.
126
+ */
127
+ declare class UnknownProtocolVersionError extends Error {
128
+ readonly protocolVersion: number;
129
+ readonly path: VersionResolutionPath;
130
+ readonly reason: ProtocolVersionUnknownReason;
131
+ readonly code: typeof PROTOCOL_ERROR_CODES.UNKNOWN_PROTOCOL_VERSION_READ | typeof PROTOCOL_ERROR_CODES.UNKNOWN_PROTOCOL_VERSION_CONSTRUCT;
132
+ constructor(protocolVersion: number, path: VersionResolutionPath, reason: ProtocolVersionUnknownReason);
133
+ }
134
+ /**
135
+ * Which lazily-loaded subpath export {@link Ledger8RuntimeMissingError} failed
136
+ * to acquire. Each chunk pulls a different set of retained-era dependencies, so
137
+ * naming the wrong one sends an operator to an entry point that loaded fine.
138
+ *
139
+ * @see {@link ModuleGraphAndLazyLoading}
140
+ */
141
+ type RetainedEraSubpath = '/v8' | '/engine';
142
+ /**
143
+ * Thrown when a lazily-loaded subpath export carrying the retained pre-fork
144
+ * runtime could not be acquired at all. Raised by `loadLedger8`
145
+ * (`lib/v8/load.ts`) and `loadLedger8Engine` (`lib/v8/load-engine.ts`), and
146
+ * surfaced through `createLedger8Engine` and `loadLedgerEra('v8')`.
147
+ *
148
+ * A failed acquisition is not memoised: the next call retries the import.
149
+ * Distinct from {@link Ledger8RuntimeInvalidError}, which reports a runtime
150
+ * that WAS acquired and then handed over incomplete.
151
+ *
152
+ * @param subpath Which chunk failed to load — see {@link RetainedEraSubpath}.
153
+ * @param cause The underlying module-resolution or initialisation failure,
154
+ * preserved unchanged. Read it for which module actually failed.
155
+ * @see {@link ModuleGraphAndLazyLoading}
156
+ * @see {@link EraSeam}
157
+ */
158
+ declare class Ledger8RuntimeMissingError extends Error {
159
+ readonly subpath: RetainedEraSubpath;
160
+ readonly code: "MIDNIGHT_JS_P_LEDGER8_RUNTIME_MISSING";
161
+ constructor(subpath: RetainedEraSubpath, cause: unknown);
162
+ }
163
+ /**
164
+ * Which physical-copy axis `assertSharedLedger8Instance`
165
+ * (`lib/v8/instance-guard.ts`) detected two distinct instances on.
166
+ *
167
+ * `'onchain-runtime-v3'` is the only member this framework version checks.
168
+ *
169
+ * @see {@link DualInstantiationGuard}
170
+ */
171
+ type Ledger8InstanceAxis = 'onchain-runtime-v3';
172
+ /**
173
+ * Thrown by `assertSharedLedger8Instance` (`lib/v8/instance-guard.ts`)
174
+ * when the same-named WASM package resolved to two physically distinct copies
175
+ * in this process (a dual-instantiation).
176
+ *
177
+ * Carries no `cause`: this is a direct reference-equality assertion failure,
178
+ * not a wrapped lower-level exception.
179
+ *
180
+ * @param axis Which physical-copy axis the check ran on — see
181
+ * {@link Ledger8InstanceAxis}. It also selects the package names the
182
+ * message tells the reader to trace.
183
+ * @see {@link DualInstantiationGuard}
184
+ */
185
+ declare class Ledger8InstanceMismatchError extends Error {
186
+ readonly axis: Ledger8InstanceAxis;
187
+ readonly code: "MIDNIGHT_JS_P_LEDGER8_INSTANCE_MISMATCH";
188
+ constructor(axis: Ledger8InstanceAxis);
189
+ }
190
+ /**
191
+ * Which step of the down-convert pipeline a {@link DownConvertFailedError}
192
+ * came from. A closed union, so a consumer can `switch` on `stage`
193
+ * exhaustively.
194
+ *
195
+ * @see {@link FailClosedDecoding}
196
+ */
197
+ type DownConvertStage = 'v8 envelope extraction' | 'v9 envelope extraction' | 'state down-convert';
198
+ /**
199
+ * Thrown by the down-convert engine (`lib/era/envelope.ts`,
200
+ * `lib/v8/down-convert.ts`) when it cannot turn a raw contract-state
201
+ * envelope, or an already-extracted `EncodedStateValue`, into an executable
202
+ * pre-fork state. Raised by `extractV9EncodedStateValue` (`lib/era/envelope.ts`)
203
+ * and `downConvertForExecution` (`lib/v8/down-convert.ts`).
204
+ *
205
+ * Renders no raw hex and no decoded state contents — only the stage name and
206
+ * the wrapped `cause`.
207
+ *
208
+ * @param stage Which step failed — see {@link DownConvertStage}.
209
+ * @param cause The runtime's own failure, preserved unchanged. It is what
210
+ * distinguishes a tag mismatch from truncated, trailing, or empty input.
211
+ * @see {@link FailClosedDecoding}
212
+ */
213
+ declare class DownConvertFailedError extends Error {
214
+ readonly stage: DownConvertStage;
215
+ readonly code: "MIDNIGHT_JS_P_DOWN_CONVERT_FAILED";
216
+ constructor(stage: DownConvertStage, cause: unknown);
217
+ }
218
+ /**
219
+ * Thrown by `checkRoot` (`lib/v8/down-convert.ts`) when a bounded Merkle
220
+ * tree's root is read before the tree has been rehashed. Reaches a caller
221
+ * through `assertMerkleTreesRehashed` and `downConvertForExecution`, which
222
+ * assert it on every tree they decode.
223
+ *
224
+ * The remediation is always the caller's: call `rehash()` on the tree before
225
+ * executing against it. Nothing here repairs the tree.
226
+ *
227
+ * @param cause The runtime's own failure, when reading the root threw. Absent
228
+ * when `root()` returned nothing instead of throwing.
229
+ * @see {@link FailClosedDecoding}
230
+ * @see {@link RetainedEraExecution}
231
+ */
232
+ declare class MerkleNotRehashedError extends Error {
233
+ readonly code: "MIDNIGHT_JS_P_MERKLE_NOT_REHASHED";
234
+ constructor(cause?: unknown);
235
+ }
236
+ /**
237
+ * What `circuitId` a {@link ComposeFailedError} names when the failure happened
238
+ * before any circuit was looked up — only `'call-empty'` reaches this today.
239
+ *
240
+ * Exported, and one literal rather than a per-module copy, so a consumer
241
+ * reading `circuitId` off a caught error can compare against it instead of
242
+ * matching a string this package could change, and so it can never be mistaken
243
+ * for a real entry point a caller might try to resolve.
244
+ *
245
+ * @see {@link ComposeRefusalOrder}
246
+ */
247
+ declare const NO_CIRCUIT = "(none)";
248
+ /**
249
+ * Which composition step {@link ComposeFailedError} failed at.
250
+ *
251
+ * Call stages:
252
+ * - `'call-empty'` — a call transaction was requested with no calls in it.
253
+ * The one stage that names no circuit: it is raised before any circuit is
254
+ * looked up, so it names {@link NO_CIRCUIT}.
255
+ * - `'call-operation'` — a call leg could not resolve a registered operation
256
+ * for the call's circuit on the given contract state.
257
+ * - `'call-verifier-key'` — a call leg resolved a registered operation for the
258
+ * call's circuit, but that operation carries no verifier key, so no ledger
259
+ * could verify a call against it.
260
+ * - `'call-contract-state'` — the call's pre-call state could not be bridged
261
+ * into the target era's own state algebra. Carries the decoder's failure on
262
+ * `cause`.
263
+ * - `'call-transcript-empty'` — a caller-supplied partitioned transcript
264
+ * carried neither a guaranteed nor a fallible half, so the call would record
265
+ * no operations at all.
266
+ * - `'call-partition-context'` — the era rejected the query-context state the
267
+ * call recorded (its block, its starting effects, or one of the commitment
268
+ * indices it registered for a coin received in-contract) while bridging it
269
+ * onto the context the transcript is partitioned against. Carries the
270
+ * runtime's own failure on `cause`.
271
+ * - `'call-partition'` — the ledger rejected the public transcript supplied
272
+ * for a call while splitting it into its guaranteed and fallible halves.
273
+ * Carries the runtime's own failure on `cause`.
274
+ * - `'call-prototype'` — the ledger rejected the call's own inputs while
275
+ * constructing the call prototype. Carries the runtime's failure on `cause`.
276
+ * - `'call-dust-payout'` — a transcript claimed an unshielded spend to a user
277
+ * address in DUST, which has no raw token type to be paid out in.
278
+ * - `'call-unsupported-payout'` — a transcript claimed an unshielded spend to
279
+ * a user address in a token type that cannot be paid out as an unshielded
280
+ * UTXO at all (a shielded token type today).
281
+ *
282
+ * Deploy stages:
283
+ * - `'deploy-verifier-key'` — a deploy leg was given no verifier key for a
284
+ * circuit the contract state declares.
285
+ * - `'deploy-unknown-circuit'` — the verifier-key map handed to a deploy leg
286
+ * names a circuit the contract state does not declare. Registering it would
287
+ * add an entry point the compiled contract never had, and silently change
288
+ * the deployed contract's address.
289
+ * - `'deploy-ambiguous-circuit'` — two entry points the contract state
290
+ * declares resolve to the same name, so the verifier-key map (keyed by
291
+ * name) cannot address them apart. Registering under the shared name would
292
+ * key one slot and leave the other blank.
293
+ * - `'deploy-verifier-key-blob'` — the ledger rejected the verifier-key bytes
294
+ * supplied for a circuit.
295
+ *
296
+ * Keep-state stage:
297
+ * - `'wrap-call'` — the keep-state leg could not resolve a registered
298
+ * operation for the transcript's circuit on the given contract state.
299
+ *
300
+ * Which ledger era the failure happened on is carried separately, on the
301
+ * error's `version` field. Every stage but `'wrap-call'` is reachable on both
302
+ * eras; `'wrap-call'` is only ever raised for `'v9'`.
303
+ *
304
+ * @see {@link ComposeRefusalOrder}
305
+ * @see {@link VerifierKeys}
306
+ */
307
+ type ComposeStage = 'wrap-call' | 'call-empty' | 'call-transcript-empty' | 'call-partition-context' | 'call-partition' | 'call-prototype' | 'call-dust-payout' | 'call-unsupported-payout' | 'call-operation' | 'call-contract-state' | 'call-verifier-key' | 'deploy-verifier-key' | 'deploy-unknown-circuit' | 'deploy-ambiguous-circuit' | 'deploy-verifier-key-blob';
308
+ /**
309
+ * Thrown when a transaction cannot be composed because a circuit's operation
310
+ * is missing, under-registered, or names a circuit the contract does not have.
311
+ * `stage` (see {@link ComposeStage}) names which composition step failed and is
312
+ * a closed union, so a consumer can `switch` on it exhaustively; `version`
313
+ * names the ledger era the composition was running against.
314
+ *
315
+ * Most stages are direct assertion failures (a missing lookup, not a wrapped
316
+ * lower-level exception) and carry no `cause`, like
317
+ * {@link Ledger8InstanceMismatchError}. The exceptions are the stages where
318
+ * the ledger itself rejected caller-supplied bytes — enumerated under `cause`
319
+ * below: that failure is preserved on `cause`, the same way
320
+ * {@link DownConvertFailedError} preserves its runtime's own message.
321
+ *
322
+ * `circuitId` names the entry point, never its raw contents: this class
323
+ * renders no hex and no byte-array dump. `'call-empty'` is the one stage with
324
+ * no circuit to name, and its message names none.
325
+ *
326
+ * @param version The ledger era the composition was running against.
327
+ * @param stage Which composition step failed — see {@link ComposeStage}. A
328
+ * closed union, so a consumer can `switch` on it exhaustively.
329
+ * @param circuitId The entry-point name, already decoded. {@link NO_CIRCUIT}
330
+ * for `'call-empty'`, the one stage raised before any circuit is looked up.
331
+ * @param cause The runtime's own failure, present only for the stages where
332
+ * the ledger itself rejected caller-supplied bytes: `'call-contract-state'`,
333
+ * `'call-partition-context'`, `'call-partition'`, `'call-prototype'` and
334
+ * `'deploy-verifier-key-blob'`.
335
+ * @see {@link ComposeRefusalOrder}
336
+ * @see {@link VerifierKeys}
337
+ */
338
+ declare class ComposeFailedError extends Error {
339
+ readonly version: LedgerVersion;
340
+ readonly stage: ComposeStage;
341
+ readonly circuitId: string;
342
+ readonly code: "MIDNIGHT_JS_P_COMPOSE_FAILED";
343
+ constructor(version: LedgerVersion, stage: ComposeStage, circuitId: string, cause?: unknown);
344
+ private static readonly MESSAGES;
345
+ }
346
+ /**
347
+ * Which option handed to a composition leg was unusable:
348
+ * - `'contractState'` — the state could not be bridged into the target
349
+ * ledger era (its serialized envelope was rejected by the era's decoder).
350
+ * - `'networkId'` — the network id was empty. The ledger accepts an empty
351
+ * string and bakes it into the transaction, so a caller that forgot to
352
+ * resolve one would only find out at submission.
353
+ * - `'ttl'` — the time-to-live was not a valid instant. `new Date('...')` on
354
+ * an unparseable value yields an Invalid Date, which the ledger silently
355
+ * records as the Unix epoch: a transaction that is already expired when it
356
+ * is composed.
357
+ * - `'calls'` — the call list is not one the target era can compose. The
358
+ * retained pre-fork era composes exactly one call: a cross-contract call is a
359
+ * ledger-9-only feature that a pre-fork contract cannot emit, so that era has
360
+ * no call tree to express.
361
+ * - `'verifierKeys'` — a deploy was requested with no verifier-key map, and the
362
+ * state it was given needs one. Raised on BOTH eras, for two different
363
+ * reasons: the retained era's deploy leg has to register the compiled
364
+ * contract's keys itself and so always needs the map, while the current era
365
+ * accepts its omission for a state that already carries its keys and refuses
366
+ * it only for a state still declaring a blank-keyed entry point.
367
+ * - `'zswapOffer'` — the supplied offer bytes were rejected by the target era's
368
+ * decoder. Raised on BOTH eras, for the same reason and with the same
369
+ * remediation: pass the bytes that era's own offer serialization produced.
370
+ *
371
+ * @see {@link ComposeRefusalOrder}
372
+ * @see {@link VerifierKeys}
373
+ */
374
+ type ComposeOption = 'calls' | 'contractState' | 'ledgerParameters' | 'networkId' | 'ttl' | 'verifierKeys' | 'zswapOffer';
375
+ /**
376
+ * Thrown by the composition legs when one of their options cannot be used at
377
+ * all, as opposed to {@link ComposeFailedError}, which reports a circuit whose
378
+ * operation is missing or under-registered.
379
+ *
380
+ * These are the well-formedness checks the ledger itself does not make.
381
+ *
382
+ * Like {@link DownConvertFailedError}, this class renders no input contents of
383
+ * its own.
384
+ *
385
+ * @param version The ledger era the option was being used against.
386
+ * @param option Which option was unusable — see {@link ComposeOption}. A
387
+ * closed union, so a consumer can `switch` on it exhaustively.
388
+ * @param cause The decoder's own failure, present only for `'contractState'`
389
+ * and `'zswapOffer'`, where caller-supplied bytes were rejected.
390
+ * @see {@link ComposeRefusalOrder}
391
+ * @see {@link VerifierKeys}
392
+ */
393
+ declare class ComposeOptionError extends Error {
394
+ readonly version: LedgerVersion;
395
+ readonly option: ComposeOption;
396
+ readonly code: "MIDNIGHT_JS_P_COMPOSE_OPTION_INVALID";
397
+ constructor(version: LedgerVersion, option: ComposeOption, cause?: unknown);
398
+ private static readonly MESSAGES;
399
+ }
400
+ /**
401
+ * Thrown when a raw, serialized contract-state envelope could not be read by
402
+ * the ledger era it was requested for. Raised by both of the facade's read
403
+ * paths, `extractState` and `decodeContractState`
404
+ * (`lib/shared/contract-state.ts`), so a caller writes one handler for both.
405
+ *
406
+ * Renders no hex and no byte dump of its own.
407
+ *
408
+ * @param version The era whose decoder rejected the envelope.
409
+ * @param cause The decoder's own diagnosis, preserved unchanged. It is what
410
+ * distinguishes a tag mismatch from truncated, trailing or empty input.
411
+ * @see {@link FailClosedDecoding}
412
+ */
413
+ declare class StateDecodeFailedError extends Error {
414
+ readonly version: LedgerVersion;
415
+ readonly code: "MIDNIGHT_JS_P_STATE_DECODE_FAILED";
416
+ constructor(version: LedgerVersion, cause: unknown);
417
+ }
418
+ /**
419
+ * Thrown by `extractEncodedStateValue` (`lib/era/envelope.ts`) when the
420
+ * injected pre-fork runtime cannot be used — it was not passed at all, or the
421
+ * binding the decoder needs is absent from it. Also raised by
422
+ * `downConvertForExecution` (`lib/v8/down-convert.ts`) and
423
+ * `assertSharedLedger8Instance` (`lib/v8/instance-guard.ts`), the latter for a
424
+ * nullish instance probe.
425
+ *
426
+ * Nothing is wrong with the caller's input here. Distinct from
427
+ * {@link Ledger8RuntimeMissingError}, which reports the v8 chunk failing to
428
+ * load at all, and from {@link DownConvertFailedError}, which reports an
429
+ * envelope or state that could not be turned into an executable pre-fork
430
+ * state.
431
+ *
432
+ * @param missingMember Which binding was absent. One of this module's own
433
+ * literals, never caller-supplied text, so it is safe to log.
434
+ * @see {@link FailClosedDecoding}
435
+ * @see {@link DualInstantiationGuard}
436
+ */
437
+ declare class Ledger8RuntimeInvalidError extends Error {
438
+ readonly missingMember: string;
439
+ readonly code: "MIDNIGHT_JS_P_LEDGER8_RUNTIME_INVALID";
440
+ constructor(missingMember: string);
441
+ }
442
+ /**
443
+ * Thrown by `assertSharedLedger8Instance` (`lib/v8/instance-guard.ts`)
444
+ * when the `axis` it was handed is not a member of {@link Ledger8InstanceAxis}.
445
+ *
446
+ * A TypeScript caller cannot produce this — `axis` is typed as
447
+ * {@link Ledger8InstanceAxis}. It exists for the untyped JavaScript consumers
448
+ * this package also serves.
449
+ *
450
+ * @param requestedAxis The offending value that was passed. Carried for
451
+ * programmatic use only; it is deliberately kept out of the message.
452
+ * @see {@link DualInstantiationGuard}
453
+ */
454
+ declare class UnknownLedger8AxisError extends Error {
455
+ readonly requestedAxis: string;
456
+ readonly code: "MIDNIGHT_JS_P_UNKNOWN_LEDGER8_AXIS";
457
+ constructor(requestedAxis: string);
458
+ }
459
+ /**
460
+ * Thrown when a ledger era was requested by a value that is not a member of
461
+ * `LEDGER_VERSIONS`. Raised by `loadLedgerEra` (`lib/era/load-era.ts`) and by
462
+ * `extractEncodedStateValue` (`lib/era/envelope.ts`).
463
+ *
464
+ * A TypeScript caller cannot produce this: `version` is typed as
465
+ * `LedgerVersion`. It exists for the untyped JavaScript consumers this package
466
+ * also serves.
467
+ *
468
+ * Carries no `version` field, unlike every other era-aware error here — there
469
+ * is no valid era to name.
470
+ *
471
+ * @param requestedVersion The offending value that was passed. Carried for
472
+ * programmatic use only; it is deliberately kept out of the message.
473
+ * @see {@link SharedTableDiscipline}
474
+ * @see {@link FailClosedDecoding}
475
+ */
476
+ declare class UnknownLedgerVersionError extends Error {
477
+ readonly requestedVersion: string;
478
+ readonly code: "MIDNIGHT_JS_P_UNKNOWN_LEDGER_VERSION";
479
+ constructor(requestedVersion: string);
480
+ }
481
+ /**
482
+ * The opening of the tag every serialized ledger transaction carries, on both
483
+ * eras.
484
+ *
485
+ * Stops before the bracketed version deliberately: a `[vN]` is the wire-schema
486
+ * version of the serialized OBJECT and never a ledger era — the retained era's
487
+ * transactions are tagged `transaction[v9]`.
488
+ *
489
+ * @see packages/contracts/docs/verification-path.md for the same rule stated
490
+ * about verifier-key tags.
491
+ */
492
+ declare const TRANSACTION_TAG_PREFIX = "midnight:transaction[";
493
+ /**
494
+ * Thrown when a payload handed to a proving seam is not a serialized
495
+ * transaction at all.
496
+ *
497
+ * Distinct from a decode failure inside the ledger runtime: this is raised
498
+ * before any runtime is asked to read the bytes, so it says the caller sent the
499
+ * wrong KIND of payload rather than a damaged one. It covers three ways that
500
+ * can happen — a `txBytes` field that is not a byte string, a byte string
501
+ * shorter than the tag prefix, and one that does not open with the prefix.
502
+ *
503
+ * @remarks Raised by `proveV8Transaction`, so it reaches application code as a
504
+ * `proveTx` rejection. Match it with `hasErrorCode` against
505
+ * `PROTOCOL_ERROR_CODES.PAYLOAD_NOT_A_TRANSACTION` rather than constructing it.
506
+ */
507
+ declare class PayloadNotATransactionError extends Error {
508
+ readonly code: "MIDNIGHT_JS_P_PAYLOAD_NOT_A_TRANSACTION";
509
+ private constructor();
510
+ /**
511
+ * The `txBytes` field of a `v8` payload was not a `Uint8Array`. Reachable
512
+ * from JavaScript, from a consumer built against a pre-5.0.0
513
+ * `midnight-js-types`, or across an untyped boundary — so it is refused with
514
+ * a code rather than left to become a bare `TypeError`.
515
+ */
516
+ static notBytes(received: unknown): PayloadNotATransactionError;
517
+ /** The payload is a byte string, but does not open with a transaction's tag. */
518
+ static wrongTag(byteLength: number): PayloadNotATransactionError;
519
+ }
520
+
521
+ /**
522
+ * The query-context state a call recorded while it ran, which its pre-call
523
+ * state bytes do not carry.
524
+ *
525
+ * `block` and `effects` are the PRE-call values; `comIndices` is the POST-call
526
+ * map. Plain data on every member.
527
+ *
528
+ * @see {@link ComposeRefusalOrder} for why partitioning needs the context the
529
+ * circuit actually ran on, and why `CallContext` and `Effects` are declared
530
+ * once against ledger-v9.
531
+ * @see {@link RetainedEraExecution} for why each member is read off the
532
+ * context it is.
533
+ * @see {@link EraSeam}
534
+ */
535
+ interface PartitionContext {
536
+ readonly block: CallContext;
537
+ readonly effects: Effects;
538
+ /** Commitment -> the index the runtime recorded it at. Empty for a call that received no coin. */
539
+ readonly comIndices: ReadonlyMap<CoinCommitment, bigint>;
540
+ }
541
+ /**
542
+ * Where a call's public transcript comes from. Two shapes, because neither
543
+ * production leg subsumes the other:
544
+ *
545
+ * - `'unpartitioned'` — the raw op sequence a circuit emitted on the retained
546
+ * pre-fork execution leg, the state it ran against, and the
547
+ * {@link PartitionContext} that leg recorded.
548
+ * - `'partitioned'` — a guaranteed/fallible pair already split by compact-js,
549
+ * which is the current production path.
550
+ *
551
+ * Every member is plain data in the ledger's own declared algebra — no live
552
+ * WASM handle.
553
+ *
554
+ * @see {@link RetainedEraExecution} for the leg that submits the unpartitioned
555
+ * shape.
556
+ * @see {@link ComposeRefusalOrder} for why an already-partitioned pair is
557
+ * passed through rather than re-derived.
558
+ * @see {@link EraSeam}
559
+ */
560
+ type CallTranscriptSource = {
561
+ readonly kind: 'unpartitioned';
562
+ readonly preState: EncodedStateValue;
563
+ readonly publicTranscript: Op$1<AlignedValue$1>[];
564
+ readonly partitionContext: PartitionContext;
565
+ } | {
566
+ readonly kind: 'partitioned';
567
+ readonly guaranteed?: Transcript<AlignedValue$1>;
568
+ readonly fallible?: Transcript<AlignedValue$1>;
569
+ };
570
+ /**
571
+ * The sentinel that asks for the ledger's own INITIAL cost model instead of the chain's.
572
+ *
573
+ * Spelled out as a value a caller has to name, because the thing it selects is wrong for any chain
574
+ * that has been running: the initial parameters are the model the chain started with, and prices
575
+ * adjust per block. Partitioning against them draws the guaranteed/fallible boundary in the wrong
576
+ * place and the node then refuses the guaranteed segment with `Transcript(Execution(OutOfGas))` --
577
+ * after the caller has already paid to prove it.
578
+ */
579
+ declare const INITIAL_LEDGER_PARAMETERS = "initial";
580
+ /**
581
+ * What a composer accepts for the block's ledger parameters: the chain's own serialized parameters,
582
+ * or {@link INITIAL_LEDGER_PARAMETERS}.
583
+ *
584
+ * There is deliberately no third option. This used to be optional, and omitting it fell back to the
585
+ * initial parameters silently -- so a caller that simply forgot got the wrong cost model with no
586
+ * signal, and a `PublicDataProvider` that does not serve `ledgerParameters` (the field is optional)
587
+ * degraded every call built through it. Requiring the option keeps the compatibility path reachable
588
+ * only as a decision, never as an oversight.
589
+ *
590
+ * A caller that reads the chain must pass the bytes from the SAME read as the contract state: the
591
+ * parameters are era-tagged and dated per block, so a second read could answer for another block.
592
+ *
593
+ * @see {@link EraSeam}
594
+ */
595
+ type LedgerParametersOption = Uint8Array | typeof INITIAL_LEDGER_PARAMETERS;
596
+ /**
597
+ * A call's guaranteed/fallible transcript pair, as the ledger's partitioner
598
+ * answers it. Either member is absent when that segment carries nothing.
599
+ */
600
+ type PartitionedCallTranscript = [
601
+ Transcript<AlignedValue$1> | undefined,
602
+ Transcript<AlignedValue$1> | undefined
603
+ ];
604
+ /**
605
+ * What an era needs to partition one call's transcript, which is strictly less
606
+ * than composing the call: no operation registry, no private outputs, no
607
+ * transaction envelope. The era supplies its own version.
608
+ */
609
+ interface EraPartitionCallOptions {
610
+ readonly circuitId: string;
611
+ readonly contractAddress: string;
612
+ readonly transcript: CallTranscriptSource;
613
+ /**
614
+ * The chain's own serialized ledger parameters at the block this call is
615
+ * built against, or {@link INITIAL_LEDGER_PARAMETERS} to partition against
616
+ * the era's initial cost model instead.
617
+ *
618
+ * Required, exactly as on `ComposeCallEntry`. The partitioner runs on this
619
+ * path too, so an optional field here would reopen the silent
620
+ * wrong-cost-model fallback that {@link LedgerParametersOption} exists to
621
+ * close.
622
+ */
623
+ readonly ledgerParameters: LedgerParametersOption;
624
+ }
625
+ /**
626
+ * One contract call in a call transaction.
627
+ *
628
+ * `contractState` is the raw, serialized state the call is dispatched against,
629
+ * as read from chain. It supplies the registered operation for `circuitId`,
630
+ * including its verifier key, which the call's key location hashes; a
631
+ * constructor-built state will not do, because it declares its entry points
632
+ * with blank keys.
633
+ *
634
+ * `communicationCommitmentRandomness` is the randomness the runtime bound a
635
+ * cross-contract callee to its caller with. The root call — being no one's
636
+ * callee — omits it and gets fresh randomness.
637
+ *
638
+ * @see {@link EraSeam}
639
+ */
640
+ interface ComposeCallEntry {
641
+ readonly contractAddress: string;
642
+ readonly circuitId: string;
643
+ readonly contractState: Uint8Array;
644
+ /**
645
+ * The ledger parameters the chain held at the block this call is built against, serialized —
646
+ * `RawContractState.ledgerParameters`, passed through untouched — or
647
+ * {@link INITIAL_LEDGER_PARAMETERS} to partition against the ledger's initial cost model instead.
648
+ *
649
+ * Required, and deliberately so. See {@link LedgerParametersOption}.
650
+ */
651
+ readonly ledgerParameters: LedgerParametersOption;
652
+ readonly transcript: CallTranscriptSource;
653
+ readonly privateTranscriptOutputs: AlignedValue$1[];
654
+ readonly input: AlignedValue$1;
655
+ readonly output: AlignedValue$1;
656
+ readonly communicationCommitmentRandomness?: string;
657
+ }
658
+ /**
659
+ * Everything a call transaction needs.
660
+ *
661
+ * `calls` is in execution-trace order: cross-contract callees first, the root
662
+ * call last. A circuit with no cross-contract calls has a single entry.
663
+ *
664
+ * The two Zswap offers are serialized offer bytes. `networkId` and `ttl` carry
665
+ * the caller's policy decisions — which network, how long the transaction
666
+ * lives.
667
+ *
668
+ * @see {@link ComposeRefusalOrder} for when the envelope options are checked.
669
+ * @see {@link EraSeam}
670
+ */
671
+ interface ComposeCallOptions {
672
+ readonly calls: readonly ComposeCallEntry[];
673
+ readonly networkId: string;
674
+ readonly ttl: Date;
675
+ readonly guaranteedZswapOffer?: Uint8Array;
676
+ readonly fallibleZswapOffer?: Uint8Array;
677
+ }
678
+ /**
679
+ * Everything a deploy transaction needs.
680
+ *
681
+ * `contractState` is the raw, serialized initial state the contract's
682
+ * constructor produced.
683
+ *
684
+ * `verifierKeys` maps entry-point name -> raw, tagged verifier key bytes
685
+ * (`keys/<id>.verifier`). When supplied, the map must name exactly the entry
686
+ * points the state declares — no more, no fewer. Omit it only for a state that
687
+ * ALREADY carries its keys.
688
+ *
689
+ * @see {@link VerifierKeys}
690
+ * @see {@link EraSeam}
691
+ */
692
+ interface ComposeDeployOptions {
693
+ readonly contractState: Uint8Array;
694
+ readonly verifierKeys?: ReadonlyMap<string, Uint8Array>;
695
+ readonly networkId: string;
696
+ readonly ttl: Date;
697
+ readonly guaranteedZswapOffer?: Uint8Array;
698
+ }
699
+ /**
700
+ * What a composed deploy hands back.
701
+ *
702
+ * `contractAddress` cannot be recomputed from the state a caller passed in, so
703
+ * it is handed back here rather than derived. `initialState` is the state that
704
+ * address was derived from — what a caller stores and later hands to a call.
705
+ *
706
+ * All three are plain data.
707
+ *
708
+ * @see {@link VerifierKeys} for why the address cannot be recomputed.
709
+ * @see {@link EraSeam}
710
+ */
711
+ interface DeployResultPojo {
712
+ readonly transaction: Uint8Array;
713
+ readonly contractAddress: string;
714
+ readonly initialState: Uint8Array;
715
+ }
716
+
717
+ /**
718
+ * One entry point a contract state declares, with the verifier key registered
719
+ * against it if there is one.
720
+ *
721
+ * `verifierKey` and `verifierKeyHash` are both absent for a blank slot — the
722
+ * shape a constructor-built state has before a deploy fills it in.
723
+ *
724
+ * @see {@link FailClosedDecoding} for why they are absent rather than
725
+ * zero-length or a hash of nothing.
726
+ */
727
+ interface ContractEntryPointPojo {
728
+ readonly circuitId: string;
729
+ readonly verifierKey: Uint8Array | undefined;
730
+ readonly verifierKeyHash: string | undefined;
731
+ }
732
+ /**
733
+ * A contract state as plain data: the primary state in its encoded form, and
734
+ * the entry points the state declares.
735
+ *
736
+ * `entryPoints` is an ARRAY, not a map keyed by circuit id: two distinct byte
737
+ * entry points can decode to the same name, and a caller has to reconcile
738
+ * them.
739
+ *
740
+ * @see {@link FailClosedDecoding}
741
+ */
742
+ interface ContractStatePojo {
743
+ readonly state: EncodedStateValue;
744
+ readonly entryPoints: readonly ContractEntryPointPojo[];
745
+ }
746
+
747
+ /**
748
+ * One ledger era, as a single object a caller holds and calls.
749
+ *
750
+ * Both eras expose the SAME methods with the same signatures. Which era an
751
+ * object is bound to is readable from {@link LedgerEra.version} and nowhere
752
+ * else — a caller that has resolved the era for a record (see
753
+ * `protocolVersionToLedger` in `../../version.ts`) hands that value to
754
+ * `loadLedgerEra` once and then writes era-agnostic code.
755
+ *
756
+ * Every value crossing this boundary is plain data: `Uint8Array`s and plain
757
+ * objects, never a live WASM handle, so a result outlives the module that
758
+ * produced it and survives a `structuredClone` or a worker boundary.
759
+ *
760
+ * The methods are synchronous. Asking for an era is the point at which its
761
+ * runtime is acquired, so by the time a caller holds one of these there is
762
+ * nothing left to await.
763
+ *
764
+ * @see {@link EraSeam}
765
+ */
766
+ interface LedgerEra {
767
+ /** The era this object is bound to — the value that was passed to `loadLedgerEra`. */
768
+ readonly version: LedgerVersion;
769
+ /**
770
+ * Reads the primary state out of a raw, serialized contract-state envelope
771
+ * written by this era.
772
+ *
773
+ * Fails closed on an envelope this era cannot read — including one written
774
+ * by the other era — rather than returning a partial or empty state. The
775
+ * failure is a `StateDecodeFailedError` naming this era, the same class
776
+ * {@link LedgerEra.decodeContractState} raises, with the decoder's own
777
+ * diagnosis on `cause`.
778
+ *
779
+ * @param raw The serialized contract-state envelope.
780
+ * @returns The primary state read out of the envelope.
781
+ * @throws StateDecodeFailedError if this era's decoder rejects `raw`.
782
+ * @see {@link FailClosedDecoding}
783
+ */
784
+ extractState(raw: Uint8Array): EncodedStateValue;
785
+ /**
786
+ * Reads a raw, serialized contract-state envelope written by this era into
787
+ * plain data: its primary state, and the entry points it declares with the
788
+ * verifier key registered against each.
789
+ *
790
+ * @param raw The serialized contract-state envelope.
791
+ * @returns The decoded state. A `verifierKey` absent on an entry point means
792
+ * that slot was never deployed, not that the key is empty.
793
+ * @throws StateDecodeFailedError if this era's decoder rejects `raw`, or if
794
+ * the state cannot resolve an entry point it declares itself.
795
+ * @see {@link FailClosedDecoding}
796
+ */
797
+ decodeContractState(raw: Uint8Array): ContractStatePojo;
798
+ /**
799
+ * Composes an UNPROVEN call transaction and serializes it.
800
+ *
801
+ * The returned bytes are what `Transaction.serialize()` produces before
802
+ * `.prove()` is ever called; proving needs a proving provider and a running
803
+ * proof server, neither of which this seam has.
804
+ *
805
+ * The two eras are not equivalent here, and the difference is deliberate
806
+ * rather than hidden: the retained pre-fork era composes exactly one call,
807
+ * because a cross-contract call is a ledger-9-only feature a pre-fork
808
+ * contract cannot emit. The refusal is raised, never worked around. A Zswap
809
+ * offer is NOT refused on either era.
810
+ *
811
+ * @param options The calls to compose and the transaction-wide envelope.
812
+ * @returns The serialized UNPROVEN transaction.
813
+ * @throws ComposeOptionError if an option is unusable on this era — an
814
+ * empty `networkId`, an invalid `ttl`, undecodable offer or state bytes, or
815
+ * a call tree with more than one entry on the retained pre-fork era.
816
+ * @throws ComposeFailedError if a call cannot be assembled; `stage` names
817
+ * which step refused it.
818
+ * @see {@link ComposeRefusalOrder}
819
+ * @see {@link EraSeam}
820
+ */
821
+ composeCallTx(options: ComposeCallOptions): Uint8Array;
822
+ /**
823
+ * Composes an UNPROVEN deploy transaction and returns it together with the
824
+ * address the deployment will have and the initial state that address was
825
+ * derived from.
826
+ *
827
+ * The address cannot be recomputed from the state a caller passed in — a
828
+ * deploy mints a fresh nonce — which is why it is returned rather than left
829
+ * to the caller to derive.
830
+ *
831
+ * @param options The initial state, its verifier keys, and the
832
+ * transaction-wide envelope.
833
+ * @returns The serialized UNPROVEN transaction, the address the deployment
834
+ * will have, and the initial state that address was derived from.
835
+ * @throws ComposeOptionError if an option is unusable on this era — an
836
+ * empty `networkId`, an invalid `ttl`, undecodable state bytes, or an
837
+ * omitted `verifierKeys` for a state that still declares a blank key.
838
+ * @throws ComposeFailedError if the supplied keys do not match the state's
839
+ * declared entry points, or if the ledger rejects a key blob; `stage` names
840
+ * which check refused it.
841
+ * @see {@link VerifierKeys}
842
+ * @see {@link ComposeRefusalOrder}
843
+ */
844
+ composeDeployTx(options: ComposeDeployOptions): DeployResultPojo;
845
+ /**
846
+ * Resolves one call's guaranteed/fallible transcript pair, without composing
847
+ * a transaction.
848
+ *
849
+ * PROTOTYPE SEAM. A caller that has to route a Zswap coin into the right
850
+ * segment needs the partition BEFORE it builds the offer, and `composeCallTx`
851
+ * computes the partition only after the offer has been handed to it as an
852
+ * option. Without this the retained-era pipeline places every coin movement
853
+ * in the guaranteed segment and the wallet cannot balance the result.
854
+ *
855
+ * @param options The call's transcript source, address, circuit and the
856
+ * chain's own serialized ledger parameters.
857
+ * @returns The `[guaranteed, fallible]` pair, either member possibly absent.
858
+ * @throws ComposeFailedError, ComposeOptionError as `composeCallTx` does for
859
+ * the same inputs.
860
+ */
861
+ partitionCallTranscript(options: EraPartitionCallOptions): PartitionedCallTranscript;
862
+ }
863
+
864
+ /**
865
+ * Resolves one ledger era to a {@link LedgerEra} bound to it.
866
+ *
867
+ * This is the only sanctioned way to reach either era's operations. Pass the
868
+ * version resolved from a record or from the network head (see
869
+ * `protocolVersionToLedger` in `../../version.ts`) rather than a string chosen
870
+ * by hand.
871
+ *
872
+ * Memoised per era, so the retained pre-fork WASM is instantiated at most once
873
+ * per process. A FAILED v8 acquisition is not memoised: the next call retries.
874
+ *
875
+ * @param version The era to resolve.
876
+ * @returns The era facade bound to `version`. The same object on every call
877
+ * for that era, and frozen.
878
+ * @throws UnknownLedgerVersionError — as a rejection — if `version` is not a
879
+ * member of `LEDGER_VERSIONS`.
880
+ * @throws Ledger8RuntimeMissingError — as a rejection — if the retained
881
+ * pre-fork runtime cannot be acquired. It propagates unchanged, carrying the
882
+ * underlying cause.
883
+ * @see {@link EraSeam}
884
+ * @see {@link SharedTableDiscipline}
885
+ */
886
+ declare const loadLedgerEra: (version: LedgerVersion) => Promise<LedgerEra>;
887
+
888
+ var V8 = /*#__PURE__*/_mergeNamespaces({
889
+ __proto__: null
890
+ }, [ledgerV8]);
891
+
892
+ type ProtocolV8 = typeof V8;
893
+ /**
894
+ * The only sanctioned runtime path to the v8 ledger era.
895
+ *
896
+ * The v8 WASM loads on the first call and not before.
897
+ *
898
+ * A failed load is not memoised: the rejection propagates as
899
+ * {@link Ledger8RuntimeMissingError} and the next call retries the import.
900
+ *
901
+ * @returns The v8 ledger module, memoised after the first successful load.
902
+ * @throws Ledger8RuntimeMissingError If the `./v8` chunk cannot be imported.
903
+ * The returned promise rejects with it, carrying the underlying failure on
904
+ * `cause`.
905
+ * @see {@link ModuleGraphAndLazyLoading}
906
+ * @see {@link EraSeam}
907
+ */
908
+ declare const loadLedger8: () => Promise<ProtocolV8>;
909
+
910
+ /**
911
+ * Anything that can report the network's current head protocol version —
912
+ * typically an indexer or node client. Consumed by {@link networkHeadVersion}.
913
+ */
914
+ interface ProtocolVersionSource {
915
+ /**
916
+ * @returns The network's current head `protocolVersion` integer.
917
+ */
918
+ queryLatestProtocolVersion(): Promise<number>;
919
+ }
920
+ /**
921
+ * Any record carrying a raw `protocolVersion` integer field, e.g. a
922
+ * transaction or block already read from the indexer. Consumed by
923
+ * {@link versionOfRecord}.
924
+ */
925
+ interface VersionedRecord {
926
+ readonly protocolVersion: number;
927
+ }
928
+ /**
929
+ * Maps a raw `protocolVersion` integer (as returned by the indexer or node)
930
+ * onto the ledger runtime it corresponds to.
931
+ *
932
+ * | protocolVersion range | node version | ledger |
933
+ * | --------------------- | ------------ | ------ |
934
+ * | 1_000_000 – 1_999_999 | 1.x | v8 |
935
+ * | 2_000_000 – 2_999_999 | 2.x | v9 |
936
+ *
937
+ * Most call sites should not call this directly. Prefer
938
+ * {@link versionOfRecord} for a `protocolVersion` read off an existing
939
+ * indexer/node record, or {@link networkHeadVersion} for the network's
940
+ * current head version — both tag the resulting error with the correct
941
+ * `path` automatically. Pass `path` explicitly here only when neither helper
942
+ * fits the call site.
943
+ *
944
+ * @param protocolVersion The raw integer read from an indexer or node record.
945
+ * @param path Which resolution path a failure is attributed to. Defaults to
946
+ * `'construct'`, and decides which of the two error codes a failure carries.
947
+ * @returns The {@link LedgerVersion} that `protocolVersion`'s node major maps
948
+ * onto.
949
+ * @throws {@link UnknownProtocolVersionError} with `reason: 'malformed'` when
950
+ * `protocolVersion` is not a non-negative integer, and with `reason: 'unknown'`
951
+ * when it is a well-formed integer outside every range above.
952
+ * @see {@link SharedTableDiscipline}
953
+ */
954
+ declare const protocolVersionToLedger: (protocolVersion: number, path?: VersionResolutionPath) => LedgerVersion;
955
+ /**
956
+ * Resolves the ledger version for a record's `protocolVersion` field (e.g. a
957
+ * transaction or block already read from the indexer).
958
+ *
959
+ * @param record Any object carrying a raw `protocolVersion` integer field.
960
+ * @returns The {@link LedgerVersion} that record was written under.
961
+ * @throws {@link UnknownProtocolVersionError} tagged with the `read` path, on
962
+ * the same two conditions as {@link protocolVersionToLedger}.
963
+ */
964
+ declare const versionOfRecord: (record: VersionedRecord) => LedgerVersion;
965
+ /**
966
+ * Queries `source` for the network's current head protocol version and
967
+ * resolves it to a {@link LedgerVersion}.
968
+ *
969
+ * The source is expected to read the network on every call. This is the
970
+ * construct path: the era being resolved is the one a transaction built now
971
+ * will land in, and a stale reading is wrong exactly at the fork boundary,
972
+ * where that question matters. `PublicDataProvider.queryLatestProtocolVersion`
973
+ * states the same prohibition as a requirement on its implementations; this
974
+ * parameter is a structural type, so nothing here can enforce it. See ADR 0007.
975
+ *
976
+ * @param source The indexer or node client to ask for the head version.
977
+ * @returns A promise for the {@link LedgerVersion} at the network head.
978
+ * @throws {@link UnknownProtocolVersionError} tagged with the `construct`
979
+ * path, on the same two conditions as {@link protocolVersionToLedger}. A
980
+ * rejection from `source.queryLatestProtocolVersion()` propagates unchanged.
981
+ */
982
+ declare const networkHeadVersion: (source: ProtocolVersionSource) => Promise<LedgerVersion>;
983
+
984
+ type ChargedState = OnchainRuntimeV3.ChargedState;
985
+ type StateValue = OnchainRuntimeV3.StateValue;
986
+ /**
987
+ * The retained runtime's state handle types, under names a consumer can write.
988
+ *
989
+ * `DownConvertedState.data` is an `onchain-runtime-v3` `ChargedState` and
990
+ * `.data.state` a `StateValue`, and neither was nameable outside this package:
991
+ * the aliases above are local, and the vendor package publishes no subpath to
992
+ * import them from. Published because results now carry these handles.
993
+ *
994
+ * TYPE-ONLY, deliberately. `import type` is erased at compile time, so nothing
995
+ * here puts a second copy of the retained runtime on any module graph — the
996
+ * loaders remain the only runtime path to it.
997
+ */
998
+ type Ledger8ChargedState = ChargedState;
999
+ /** See {@link Ledger8ChargedState}. */
1000
+ type Ledger8StateValue = StateValue;
1001
+
1002
+ /**
1003
+ * The result of a down-convert: only the primary state data a pre-fork
1004
+ * circuit reads during execution.
1005
+ *
1006
+ * Deliberately not a full pre-fork `ContractState`: it carries no
1007
+ * `.operations`, `.maintenanceAuthority` or `.balance`, which remain the
1008
+ * caller's to carry.
1009
+ *
1010
+ * @see {@link RetainedEraExecution}
1011
+ */
1012
+ interface DownConvertedState {
1013
+ readonly data: ChargedState;
1014
+ }
1015
+
1016
+ type AlignedValue = OnchainRuntimeV3.AlignedValue;
1017
+ type Op<T> = OnchainRuntimeV3.Op<T>;
1018
+
1019
+ /**
1020
+ * The `QueryContext` slice {@link executeCircuit} reads off a circuit's
1021
+ * context: the primary state, ready to be wrapped back into a
1022
+ * {@link DownConvertedState}, plus the three members a composition leg needs to
1023
+ * partition the call's public transcript against the context it really ran on
1024
+ * (see {@link PartitionContext}).
1025
+ *
1026
+ * A `Pick` of the vendor's own class, not a restatement of it: the member names
1027
+ * and their types come from onchain-runtime-v3, so a rename there fails this
1028
+ * build instead of leaving a mirror that describes a property the runtime no
1029
+ * longer has. It stays a narrowing rather than the whole class because
1030
+ * `QueryContext` is a WASM class with dozens of members, and this seam reads
1031
+ * four — the narrowing is what lets the execution tests hand `executeCircuit` a
1032
+ * plain object double instead of standing up real WASM.
1033
+ *
1034
+ * @see {@link RetainedEraExecution}
1035
+ */
1036
+ type Ledger8QueryContext = Pick<OnchainRuntimeV3.QueryContext, 'state' | 'block' | 'effects' | 'comIndices'>;
1037
+ /**
1038
+ * The circuit-context slice {@link executeCircuit} needs from a pre-fork
1039
+ * (`compact-runtime@0.16`) `createCircuitContext` call and a circuit's
1040
+ * updated context after it runs.
1041
+ *
1042
+ * Not the glue's `CircuitContext` itself: that one carries a real
1043
+ * `QueryContext`, a WASM class no test double can satisfy, and this seam reads
1044
+ * a handful of properties off it. The narrowing is the difference between
1045
+ * execution tests that check plumbing with a literal and tests that must stand
1046
+ * up WASM to do it — see {@link Ledger8QueryContext}, which derives those
1047
+ * properties from the vendor's class so the narrowing cannot drift from it.
1048
+ *
1049
+ * @see {@link RetainedEraExecution}
1050
+ */
1051
+ interface Ledger8CircuitContext {
1052
+ readonly currentQueryContext: Ledger8QueryContext;
1053
+ readonly currentPrivateState: unknown;
1054
+ readonly currentZswapLocalState: EncodedZswapLocalState;
1055
+ }
1056
+ /**
1057
+ * The proof-data slice of a pre-fork {@link Ledger8CircuitResult}.
1058
+ *
1059
+ * The vendor's own `ProofData`, not a copy of its four members: it is already
1060
+ * plain data with no WASM handle in it, so there was nothing for a mirror to
1061
+ * narrow — only a shape to drift out of sync. `Readonly` is this package's own
1062
+ * addition, and the only one.
1063
+ *
1064
+ * @see {@link EraSeam}
1065
+ */
1066
+ type Ledger8ProofData = Readonly<ProofData>;
1067
+ /**
1068
+ * What a pre-fork `impureCircuits[id](ctx, ...args)` call returns.
1069
+ *
1070
+ * Tracks the glue's `CircuitResults` but is not derived from it: `context` is
1071
+ * the narrowed {@link Ledger8CircuitContext} for the reason given there, and
1072
+ * `proofData` IS the vendor's own type — see {@link Ledger8ProofData}.
1073
+ *
1074
+ * @see {@link RetainedEraExecution}
1075
+ */
1076
+ interface Ledger8CircuitResult {
1077
+ readonly result: unknown;
1078
+ readonly proofData: Ledger8ProofData;
1079
+ readonly context: Ledger8CircuitContext;
1080
+ }
1081
+ /** One callable entry point on a compiled pre-fork contract's `impureCircuits` map. */
1082
+ type Ledger8ImpureCircuit = (ctx: Ledger8CircuitContext, ...args: readonly unknown[]) => Ledger8CircuitResult;
1083
+ /**
1084
+ * The subset of a compiled pre-fork (`compact-runtime@0.16`) contract module
1085
+ * {@link executeCircuit} needs: only `impureCircuits`, the map every
1086
+ * generated contract exposes its callable entry points under.
1087
+ *
1088
+ * @see {@link RetainedEraExecution}
1089
+ */
1090
+ interface Ledger8ContractLike {
1091
+ readonly impureCircuits: Readonly<Record<string, Ledger8ImpureCircuit>>;
1092
+ }
1093
+ /**
1094
+ * The result of one impure circuit's invocation on a pre-fork
1095
+ * (`compact-runtime@0.16`) contract instance: the primary result plus every
1096
+ * artifact {@link wrapKeepStateCall} (`../v9/wrap.ts`) needs to assemble a
1097
+ * v9-native `ContractCallPrototype`.
1098
+ *
1099
+ * `preContractState`/`postContractState` are {@link DownConvertedState}s, not
1100
+ * full pre-fork `ContractState`s: they carry only `.data`. They are also the
1101
+ * only members here that are LIVE HANDLES -- every other member of this type is
1102
+ * plain data. `postContractStateEncoded` is the post-state's encoded form,
1103
+ * carried beside the handle so a caller has a value that outlives the runtime
1104
+ * instance; the pre-state's encoded form is the caller's own input, which
1105
+ * `downConvertForExecution` already proves round-trips to it.
1106
+ *
1107
+ * `partitionContext` is the query-context state the call ran with, which the
1108
+ * carried state bytes do not hold — see {@link PartitionContext}. A composition
1109
+ * leg needs it to partition the call's transcript.
1110
+ *
1111
+ * `zswapLocalState` is the post-call Zswap local state, DECODED into the
1112
+ * runtime's public shape: the coins the circuit spent and produced. A caller
1113
+ * turns it into the transaction's segmented Zswap offer
1114
+ * (`zswapStateToSegmentedOffer`, `packages/contracts/src/internal/utils/zswap-utils.ts`)
1115
+ * and hands that offer to whichever composition leg it targets.
1116
+ *
1117
+ * @see {@link RetainedEraExecution}
1118
+ */
1119
+ interface TranscriptPojo {
1120
+ readonly circuitId: string;
1121
+ readonly result: unknown;
1122
+ readonly input: AlignedValue;
1123
+ readonly output: AlignedValue;
1124
+ readonly publicTranscript: Op<AlignedValue>[];
1125
+ readonly privateTranscriptOutputs: AlignedValue[];
1126
+ readonly preContractState: DownConvertedState;
1127
+ readonly postContractState: DownConvertedState;
1128
+ /**
1129
+ * The post-call state as an {@link EncodedStateValue}: the same value
1130
+ * {@link postContractState} holds, in the form that survives this process.
1131
+ *
1132
+ * `EncodedStateValue` is pinned identical across `onchain-runtime-v3`,
1133
+ * `ledger-v8` and `ledger-v9` -- see this package's README and the
1134
+ * cross-runtime assertions in `src/test/v8-down-convert.test.ts` -- so this is
1135
+ * the member era-agnostic code reads, and the one that can be persisted,
1136
+ * cloned or sent to a worker.
1137
+ */
1138
+ readonly postContractStateEncoded: EncodedStateValue;
1139
+ readonly privateStateAfter: unknown;
1140
+ readonly partitionContext: PartitionContext;
1141
+ readonly zswapLocalState: ZswapLocalState;
1142
+ }
1143
+ /** Everything {@link executeCircuit} needs to run one impure circuit call. */
1144
+ interface ExecuteCircuitOptions {
1145
+ readonly contract: Ledger8ContractLike;
1146
+ readonly circuitId: string;
1147
+ readonly args: readonly unknown[];
1148
+ readonly state: DownConvertedState;
1149
+ readonly address: string;
1150
+ readonly coinPk: string;
1151
+ readonly privateState: unknown;
1152
+ }
1153
+
1154
+ /**
1155
+ * Everything {@link wrapKeepStateCall} needs to wrap one keep-state call.
1156
+ * `contractState` is the migrated, post-fork v9 `ContractState` — read from
1157
+ * chain, or otherwise carrying the contract's real registered operations —
1158
+ * used only to look up the `ContractOperation` for `transcript.circuitId`
1159
+ * (mirrors `ComposeV8CallOptions`'s `contractState` parameter in
1160
+ * `../v8/compose.ts`).
1161
+ */
1162
+ interface WrapKeepStateCallOptions {
1163
+ readonly transcript: TranscriptPojo;
1164
+ readonly contractAddress: string;
1165
+ readonly contractState: ledgerV9.ContractState;
1166
+ /**
1167
+ * The ledger parameters of the block this call is built against, or
1168
+ * {@link INITIAL_LEDGER_PARAMETERS} to accept the initial cost model.
1169
+ *
1170
+ * Required rather than defaulted, and not hard-coded to the initial parameters here: the
1171
+ * transcript crosses as `'unpartitioned'`, so the partitioner DOES run and the cost model it uses
1172
+ * is whatever this supplies. Defaulting it would make this function the silent
1173
+ * wrong-cost-model path the option exists to close. See {@link LedgerParametersOption}.
1174
+ */
1175
+ readonly ledgerParameters: LedgerParametersOption;
1176
+ }
1177
+
1178
+ /**
1179
+ * The minimal shape a pre-fork (`compact-runtime@0.16`) `ContractState` is used
1180
+ * through here: just `.serialize()`. It is what {@link executeConstructor}
1181
+ * returns on its result, and `.serialize()` is how a caller turns that handle
1182
+ * into the bytes every deploy leg takes.
1183
+ *
1184
+ * Crosses the era boundary by bytes, not by handle.
1185
+ *
1186
+ * @see {@link DualInstantiationGuard} for why that crossing is the one a
1187
+ * duplicate install cannot affect
1188
+ * @see {@link EraSeam}
1189
+ */
1190
+ type Ledger8DeployableContractState = Pick<OnchainRuntimeV3.ContractState, 'serialize'>;
1191
+ /** What a pre-fork `contract.initialState(constructorContext, ...args)` call returns. */
1192
+ interface Ledger8ConstructorResult {
1193
+ readonly currentContractState: Ledger8DeployableContractState;
1194
+ readonly currentPrivateState: unknown;
1195
+ /**
1196
+ * The Zswap local state the constructor ended on, still ENCODED. A
1197
+ * constructor that mints a coin records it here, and a deploy that drops it
1198
+ * composes a transaction the ledger cannot balance.
1199
+ */
1200
+ readonly currentZswapLocalState: EncodedZswapLocalState;
1201
+ }
1202
+ /**
1203
+ * The subset of a compiled pre-fork (`compact-runtime@0.16`) contract module
1204
+ * {@link executeConstructor} needs: only `initialState`, the constructor
1205
+ * every generated contract exposes to build its initial ledger state.
1206
+ */
1207
+ interface Ledger8ConstructorContractLike {
1208
+ readonly initialState: (constructorContext: unknown, ...args: readonly unknown[]) => Ledger8ConstructorResult;
1209
+ }
1210
+ /** Everything {@link executeConstructor} needs to run one contract constructor. */
1211
+ interface ExecuteConstructorOptions {
1212
+ readonly contract: Ledger8ConstructorContractLike;
1213
+ readonly args: readonly unknown[];
1214
+ readonly privateState: unknown;
1215
+ readonly coinPk: string;
1216
+ }
1217
+ /**
1218
+ * The result of running a pre-fork constructor: the freshly built contract
1219
+ * state (still carrying blank verifier keys on every operation slot — see
1220
+ * {@link composeV8DeployTx}) and the resulting private state.
1221
+ */
1222
+ interface ConstructorResultPojo {
1223
+ readonly contractState: Ledger8DeployableContractState;
1224
+ readonly privateState: unknown;
1225
+ /**
1226
+ * The constructor's own Zswap local state, DECODED — plain data in both
1227
+ * runtimes. Empty for the ordinary constructor that mints nothing; carries
1228
+ * the outputs for one that does, which is what lets the deploy be balanced.
1229
+ */
1230
+ readonly zswapLocalState: ZswapLocalState;
1231
+ }
1232
+
1233
+ /**
1234
+ * The public surface {@link createLedger8Engine} builds: the retained pre-fork
1235
+ * EXECUTION capabilities, with the 0.16 runtime instance already captured in
1236
+ * closure — no method here takes a runtime or module parameter.
1237
+ *
1238
+ * Every method is synchronous: this object is handed over only after the
1239
+ * retained toolchain has been acquired.
1240
+ *
1241
+ * @see {@link EraSeam}
1242
+ */
1243
+ interface Ledger8Engine {
1244
+ downConvertForExecution(state: EncodedStateValue): DownConvertedState;
1245
+ executeCircuit(options: ExecuteCircuitOptions): TranscriptPojo;
1246
+ wrapKeepStateCall(options: WrapKeepStateCallOptions): ContractCallPrototype;
1247
+ executeConstructor(options: ExecuteConstructorOptions): ConstructorResultPojo;
1248
+ /**
1249
+ * Re-expresses a retained-era contract's entry points as a current-era contract state, so a
1250
+ * keep-state call has an operation registry the current composer can read.
1251
+ *
1252
+ * Fork-crossing work, which is why it sits here rather than on either era facade: the input is
1253
+ * what the retained decoder read off the chain, and the output is for the current ledger.
1254
+ */
1255
+ reexpressOperationsForCurrentEra(entryPoints: readonly ContractEntryPointPojo[]): Uint8Array;
1256
+ }
1257
+
1258
+ /**
1259
+ * The only sanctioned runtime path to the engine's public surface.
1260
+ *
1261
+ * The retained `compact-runtime@0.16` glue and
1262
+ * `@midnight-ntwrk/onchain-runtime-v3` WASM load only on the first call — never
1263
+ * as a side effect of importing the package root.
1264
+ *
1265
+ * A failed load is not memoised: the next call retries the import. Exactly two
1266
+ * rejections propagate unchanged — {@link Ledger8RuntimeMissingError} from the
1267
+ * retained-runtime acquisition, and {@link Ledger8InstanceMismatchError} from
1268
+ * the construction-time instance guard — keeping their class, code and
1269
+ * discriminants intact for callers. Every other failure is wrapped in
1270
+ * {@link Ledger8RuntimeMissingError}, including the coded
1271
+ * `Ledger8RuntimeInvalidError` that same guard raises for an incomplete
1272
+ * runtime, and a raw module-resolution error on the engine chunk itself.
1273
+ *
1274
+ * @returns The engine's public surface, memoised after the first successful
1275
+ * load.
1276
+ * @throws Ledger8RuntimeMissingError If the retained runtime, or the `./engine`
1277
+ * chunk itself, cannot be acquired.
1278
+ * @throws Ledger8InstanceMismatchError If the construction-time instance guard
1279
+ * found `onchain-runtime-v3` resolved to two physically distinct copies.
1280
+ * @see {@link ModuleGraphAndLazyLoading}
1281
+ * @see {@link EraSeam}
1282
+ */
1283
+ declare const loadLedger8Engine: () => Promise<Ledger8Engine>;
1284
+
1285
+ export { CURRENT_LEDGER_VERSION, ComposeFailedError, ComposeOptionError, DownConvertFailedError, INITIAL_LEDGER_PARAMETERS, LEDGER_VERSIONS, Ledger8InstanceMismatchError, Ledger8RuntimeInvalidError, Ledger8RuntimeMissingError, MerkleNotRehashedError, NO_CIRCUIT, PROTOCOL_ERROR_CODES, PayloadNotATransactionError, RETAINED_LEDGER_VERSIONS, StateDecodeFailedError, TRANSACTION_TAG_PREFIX, UnknownLedger8AxisError, UnknownLedgerVersionError, UnknownProtocolVersionError, loadLedger8, loadLedger8Engine, loadLedgerEra, networkHeadVersion, protocolVersionToLedger, versionOfRecord };
1286
+ export type { CallTranscriptSource, ComposeCallEntry, ComposeCallOptions, ComposeDeployOptions, ComposeOption, ComposeStage, ConstructorResultPojo, ContractEntryPointPojo, ContractStatePojo, CurrentLedgerVersion, DeployResultPojo, DownConvertStage, DownConvertedState, EraPartitionCallOptions, ExecuteCircuitOptions, ExecuteConstructorOptions, Ledger8ChargedState, Ledger8DeployableContractState, Ledger8Engine, Ledger8InstanceAxis, Ledger8StateValue, LedgerEra, LedgerParametersOption, LedgerVersion, PartitionContext, PartitionedCallTranscript, ProtocolErrorCode, ProtocolV8, ProtocolVersionSource, ProtocolVersionUnknownReason, RetainedEraSubpath, RetainedLedgerVersion, TranscriptPojo, VersionResolutionPath, VersionedRecord, WrapKeepStateCallOptions };