@midnight-ntwrk/wallet-sdk-capabilities 4.0.0-beta.2 → 4.0.0-beta.4
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/README.md +27 -3
- package/dist/chainVersion/chainVersionProbe.d.ts +95 -0
- package/dist/chainVersion/chainVersionProbe.js +83 -0
- package/dist/chainVersion/index.d.ts +1 -0
- package/dist/chainVersion/index.js +13 -0
- package/dist/codecs/index.d.ts +1 -0
- package/dist/codecs/index.js +13 -0
- package/dist/codecs/ledgerParameters.d.ts +81 -0
- package/dist/codecs/ledgerParameters.js +63 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/pendingTransactions/pendingTransactions.d.ts +113 -9
- package/dist/pendingTransactions/pendingTransactions.js +147 -30
- package/dist/pendingTransactions/pendingTransactionsService.d.ts +25 -9
- package/dist/pendingTransactions/pendingTransactionsService.js +33 -21
- package/dist/proving/index.d.ts +2 -0
- package/dist/proving/index.js +2 -0
- package/dist/proving/provingService.d.ts +184 -15
- package/dist/proving/provingService.js +114 -12
- package/dist/proving/v8ProvingService.d.ts +53 -0
- package/dist/proving/v8ProvingService.js +71 -0
- package/dist/proving/versionedProving.d.ts +42 -0
- package/dist/proving/versionedProving.js +103 -0
- package/dist/signatures/index.d.ts +2 -0
- package/dist/signatures/index.js +14 -0
- package/dist/signatures/signing.d.ts +37 -0
- package/dist/signatures/signing.js +13 -0
- package/dist/signatures/v8Signatures.d.ts +54 -0
- package/dist/signatures/v8Signatures.js +62 -0
- package/dist/simulation/ForkSimulator.d.ts +114 -0
- package/dist/simulation/ForkSimulator.js +209 -0
- package/dist/simulation/LedgerTranslation.d.ts +53 -0
- package/dist/simulation/LedgerTranslation.js +56 -0
- package/dist/simulation/core/VersionTimeline.d.ts +54 -0
- package/dist/simulation/core/VersionTimeline.js +56 -0
- package/dist/simulation/core/blocks.d.ts +38 -0
- package/dist/simulation/core/blocks.js +52 -0
- package/dist/simulation/core/index.d.ts +13 -0
- package/dist/simulation/core/index.js +25 -0
- package/dist/simulation/core/strictness.d.ts +29 -0
- package/dist/simulation/core/strictness.js +39 -0
- package/dist/simulation/index.d.ts +22 -2
- package/dist/simulation/index.js +25 -14
- package/dist/simulation/v8/Simulator.d.ts +231 -0
- package/dist/simulation/v8/Simulator.js +503 -0
- package/dist/simulation/{SimulatorState.d.ts → v8/SimulatorState.d.ts} +31 -44
- package/dist/simulation/v8/SimulatorState.js +290 -0
- package/dist/simulation/v8/index.d.ts +2 -0
- package/dist/simulation/v8/index.js +26 -0
- package/dist/simulation/{Simulator.d.ts → v9/Simulator.d.ts} +57 -6
- package/dist/simulation/{Simulator.js → v9/Simulator.js} +68 -18
- package/dist/simulation/v9/SimulatorState.d.ts +336 -0
- package/dist/simulation/{SimulatorState.js → v9/SimulatorState.js} +34 -67
- package/dist/simulation/v9/index.d.ts +2 -0
- package/dist/simulation/v9/index.js +26 -0
- package/dist/submission/submissionService.d.ts +2 -1
- package/dist/submission/submissionService.js +1 -1
- package/dist/validation/blockData.d.ts +42 -2
- package/dist/validation/blockData.js +55 -8
- package/dist/validation/index.d.ts +2 -0
- package/dist/validation/index.js +2 -0
- package/dist/validation/v8ValidationService.d.ts +29 -0
- package/dist/validation/v8ValidationService.js +48 -0
- package/dist/validation/validationService.d.ts +132 -17
- package/dist/validation/validationService.js +88 -42
- package/dist/validation/versionedValidation.d.ts +46 -0
- package/dist/validation/versionedValidation.js +55 -0
- package/package.json +28 -14
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified Simulator for wallet testing.
|
|
3
|
+
*
|
|
4
|
+
* This module provides a simulated ledger environment for testing wallet functionality without requiring a real
|
|
5
|
+
* blockchain node. It supports:
|
|
6
|
+
*
|
|
7
|
+
* - Optional genesis mints for pre-funded accounts (shielded, unshielded, or Night tokens)
|
|
8
|
+
* - Transaction submission with configurable strictness
|
|
9
|
+
* - Night token rewards via rewardNight()
|
|
10
|
+
* - Time advancement for TTL and time-sensitive tests
|
|
11
|
+
*/
|
|
12
|
+
import { type Array as Arr, Effect, type Scope, Stream, SubscriptionRef } from 'effect';
|
|
13
|
+
import { type ProofErasedTransaction, type SignatureVerifyingKey } from '@midnight-ntwrk/ledger-v8';
|
|
14
|
+
import { LedgerOps } from '@midnight-ntwrk/wallet-sdk-utilities';
|
|
15
|
+
import { NetworkId, ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
16
|
+
import { type Block, type BlockProducer, type FullnessSpec, type GenesisMint, type SimulatorState, type StrictnessConfig } from './SimulatorState.js';
|
|
17
|
+
export type { SimulatorState, Block, BlockTransaction, PendingTransaction, BlockInfo, BlockProductionRequest, BlockProducer, FullnessSpec, GenesisMint, ScheduledFork, StrictnessConfig, } from './SimulatorState.js';
|
|
18
|
+
export { getLastBlock, getCurrentBlockNumber, getBlockByNumber, getLastBlockResults, getLastBlockEvents, hasPendingTransactions, getCurrentTime, getProtocolVersion, protocolVersionAt, applyTransaction, defaultStrictness, genesisStrictness, createStrictness, } from './SimulatorState.js';
|
|
19
|
+
/**
|
|
20
|
+
* Default block producer: produces a block for each state change with non-empty mempool.
|
|
21
|
+
*
|
|
22
|
+
* By default, uses post-genesis strictness (balancing, signatures, limits enforced). This ensures realistic simulation
|
|
23
|
+
* where transactions must be properly balanced (pay fees).
|
|
24
|
+
*
|
|
25
|
+
* @param fullness - Static fullness (0-1) or callback based on state
|
|
26
|
+
* @param strictness - Strictness config (defaults to defaultStrictness)
|
|
27
|
+
*/
|
|
28
|
+
export declare const immediateBlockProducer: (fullness?: FullnessSpec, strictness?: StrictnessConfig) => BlockProducer;
|
|
29
|
+
/** Simulator initialization configuration. */
|
|
30
|
+
export type SimulatorConfig = Readonly<{
|
|
31
|
+
/**
|
|
32
|
+
* Pre-funded accounts to create at genesis. When provided, creates a genesis block with transactions minting tokens
|
|
33
|
+
* to recipients. When omitted, the simulator starts with an empty ledger.
|
|
34
|
+
*/
|
|
35
|
+
genesisMints?: Arr.NonEmptyArray<GenesisMint>;
|
|
36
|
+
/** Network identifier. Defaults to Undeployed. */
|
|
37
|
+
networkId?: NetworkId.NetworkId;
|
|
38
|
+
/** Custom block producer. Defaults to immediateBlockProducer(). */
|
|
39
|
+
blockProducer?: BlockProducer;
|
|
40
|
+
/**
|
|
41
|
+
* Protocol version the chain starts on. Defaults to {@link ProtocolVersion.MinSupportedVersion}.
|
|
42
|
+
*
|
|
43
|
+
* The version a fork activates is never built in — schedule it with {@link Simulator.scheduleFork} or switch to it
|
|
44
|
+
* with {@link Simulator.setProtocolVersion}.
|
|
45
|
+
*/
|
|
46
|
+
protocolVersion?: ProtocolVersion.ProtocolVersion;
|
|
47
|
+
/**
|
|
48
|
+
* Height of the genesis block. Defaults to 0.
|
|
49
|
+
*
|
|
50
|
+
* Set this to continue an existing chain's numbering, as a ledger-v9 chain does from the fork height.
|
|
51
|
+
*/
|
|
52
|
+
genesisBlockNumber?: bigint;
|
|
53
|
+
/**
|
|
54
|
+
* Timestamp of the genesis block, from which simulator time advances. Defaults to the epoch.
|
|
55
|
+
*
|
|
56
|
+
* Set this to continue an existing chain's timeline, so that time-sensitive behaviour does not restart at the epoch.
|
|
57
|
+
*/
|
|
58
|
+
genesisTime?: Date;
|
|
59
|
+
}>;
|
|
60
|
+
/**
|
|
61
|
+
* Unified simulator for wallet testing.
|
|
62
|
+
*
|
|
63
|
+
* Provides a simulated ledger environment for testing wallet functionality without a real blockchain. Optionally
|
|
64
|
+
* pre-funds accounts via genesis mints.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* // Empty ledger (useful for dust/Night token testing via rewardNight)
|
|
69
|
+
* const simulator = yield* Simulator.init({});
|
|
70
|
+
*
|
|
71
|
+
* // Pre-funded accounts (useful for token transfer testing)
|
|
72
|
+
* const simulator = yield* Simulator.init({
|
|
73
|
+
* genesisMints: [{ amount: 1000n, tokenType, shieldedRecipient: secretKeys }],
|
|
74
|
+
* });
|
|
75
|
+
* ```;
|
|
76
|
+
*/
|
|
77
|
+
export declare class Simulator {
|
|
78
|
+
#private;
|
|
79
|
+
/**
|
|
80
|
+
* Initialize a new simulator.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* // Empty ledger - use rewardNight() for Night tokens
|
|
85
|
+
* const simulator = yield* Simulator.init({});
|
|
86
|
+
*
|
|
87
|
+
* // Pre-funded accounts for token transfer testing
|
|
88
|
+
* const simulator = yield* Simulator.init({
|
|
89
|
+
* genesisMints: [{ amount: 1000n, tokenType, shieldedRecipient: secretKeys }],
|
|
90
|
+
* });
|
|
91
|
+
*
|
|
92
|
+
* // With custom network ID
|
|
93
|
+
* const simulator = yield* Simulator.init({
|
|
94
|
+
* networkId: NetworkId.Preview,
|
|
95
|
+
* genesisMints: [...],
|
|
96
|
+
* });
|
|
97
|
+
* ```;
|
|
98
|
+
*
|
|
99
|
+
* @param config - Configuration options (all optional)
|
|
100
|
+
* @returns Effect that produces a Simulator instance
|
|
101
|
+
*/
|
|
102
|
+
static init(config?: SimulatorConfig): Effect.Effect<Simulator, never, Scope.Scope>;
|
|
103
|
+
/** Initialize simulator with blank ledger state. */
|
|
104
|
+
private static initBlank;
|
|
105
|
+
/**
|
|
106
|
+
* Initialize simulator with genesis mints (pre-funded accounts). Supports shielded and unshielded token mints. Night
|
|
107
|
+
* tokens are auto-detected by comparing tokenType with `Token.night`.
|
|
108
|
+
*/
|
|
109
|
+
private static initWithGenesis;
|
|
110
|
+
/**
|
|
111
|
+
* Create a Simulator from an initial state with proper stream setup.
|
|
112
|
+
*
|
|
113
|
+
* The low-level constructor behind {@link Simulator.init}. Use it when the initial state cannot be expressed as a
|
|
114
|
+
* config — most importantly a ledger-v9 chain, whose ledger is handed over from the chain before it.
|
|
115
|
+
*
|
|
116
|
+
* @param initialState - State the simulator starts from
|
|
117
|
+
* @param blockProducer - Custom block producer (defaults to immediateBlockProducer())
|
|
118
|
+
*/
|
|
119
|
+
static fromState(initialState: SimulatorState, blockProducer?: BlockProducer): Effect.Effect<Simulator, never, Scope.Scope>;
|
|
120
|
+
/** Observable stream of simulator state changes. */
|
|
121
|
+
readonly state$: Stream.Stream<SimulatorState>;
|
|
122
|
+
constructor(stateRef: SubscriptionRef.SubscriptionRef<SimulatorState>, state$: Stream.Stream<SimulatorState>);
|
|
123
|
+
/** Get the current simulator state. */
|
|
124
|
+
getLatestState(): Effect.Effect<SimulatorState>;
|
|
125
|
+
/**
|
|
126
|
+
* Distribute Night tokens to a recipient and submit claim transaction to mempool. Used for testing dust token
|
|
127
|
+
* generation.
|
|
128
|
+
*
|
|
129
|
+
* This method:
|
|
130
|
+
*
|
|
131
|
+
* 1. Modifies the ledger to make Night tokens claimable
|
|
132
|
+
* 2. Creates and submits a ClaimRewardsTransaction to the mempool
|
|
133
|
+
* 3. The block producer will process the transaction
|
|
134
|
+
*
|
|
135
|
+
* @param verifyingKey - Signature verifying key (recipient address is derived from it)
|
|
136
|
+
* @param amount - Amount of Night tokens to distribute
|
|
137
|
+
*/
|
|
138
|
+
rewardNight(verifyingKey: SignatureVerifyingKey, amount: bigint): Effect.Effect<Block, LedgerOps.LedgerError>;
|
|
139
|
+
/**
|
|
140
|
+
* Submit a transaction and wait for it to be included in a block.
|
|
141
|
+
*
|
|
142
|
+
* This method adds the transaction to the mempool and blocks until the block producer includes it in a block. Use
|
|
143
|
+
* this when you need confirmation that the transaction was processed.
|
|
144
|
+
*
|
|
145
|
+
* For fire-and-forget scenarios where you don't need to wait for block inclusion, use `submitAndForget` instead.
|
|
146
|
+
*
|
|
147
|
+
* @param tx - Transaction to submit (proofs erased)
|
|
148
|
+
* @param options - Optional submission options
|
|
149
|
+
* @param options.strictness - Override well-formedness strictness
|
|
150
|
+
* @returns The block containing the transaction
|
|
151
|
+
*/
|
|
152
|
+
submitTransaction(tx: ProofErasedTransaction, options?: {
|
|
153
|
+
strictness?: StrictnessConfig;
|
|
154
|
+
}): Effect.Effect<Block, LedgerOps.LedgerError>;
|
|
155
|
+
/**
|
|
156
|
+
* Submit a transaction without waiting for block inclusion.
|
|
157
|
+
*
|
|
158
|
+
* This method adds the transaction to the mempool and returns immediately. The block producer will process it
|
|
159
|
+
* asynchronously. Use this for fire-and-forget scenarios or when testing custom block producers with batched
|
|
160
|
+
* transactions.
|
|
161
|
+
*
|
|
162
|
+
* To wait for block inclusion, use `submitTransaction` instead.
|
|
163
|
+
*
|
|
164
|
+
* @param tx - Transaction to submit (proofs erased)
|
|
165
|
+
* @param options - Optional options
|
|
166
|
+
* @param options.strictness - Override well-formedness strictness
|
|
167
|
+
*/
|
|
168
|
+
submitAndForget(tx: ProofErasedTransaction, options?: {
|
|
169
|
+
strictness?: StrictnessConfig;
|
|
170
|
+
}): Effect.Effect<void>;
|
|
171
|
+
/**
|
|
172
|
+
* Produce a block with no transactions, advancing the chain by one height.
|
|
173
|
+
*
|
|
174
|
+
* Bypasses the configured block producer, which only produces when there is something in the mempool. Use it to reach
|
|
175
|
+
* a given height without traffic — a fork happens at a height whether or not transactions were submitted.
|
|
176
|
+
*
|
|
177
|
+
* @returns The produced block
|
|
178
|
+
*/
|
|
179
|
+
produceEmptyBlock(): Effect.Effect<Block, LedgerOps.LedgerError>;
|
|
180
|
+
/**
|
|
181
|
+
* Switch the chain to a protocol version, effective for blocks produced from now on. Already-produced blocks keep the
|
|
182
|
+
* version they were produced under.
|
|
183
|
+
*
|
|
184
|
+
* @param version - Version to switch the chain to
|
|
185
|
+
*/
|
|
186
|
+
setProtocolVersion(version: ProtocolVersion.ProtocolVersion): Effect.Effect<void>;
|
|
187
|
+
/**
|
|
188
|
+
* Schedule a protocol version to activate at a block height — a fork on the simulated chain. The block produced at
|
|
189
|
+
* that height, and every block after it, is stamped with `version`.
|
|
190
|
+
*
|
|
191
|
+
* @param atBlock - Height of the first block produced under `version`
|
|
192
|
+
* @param version - Version that activates at `atBlock`
|
|
193
|
+
*/
|
|
194
|
+
scheduleFork(atBlock: bigint, version: ProtocolVersion.ProtocolVersion): Effect.Effect<void>;
|
|
195
|
+
/**
|
|
196
|
+
* Fast-forward the simulator time by the given number of seconds. Does not produce a block - only advances the
|
|
197
|
+
* internal clock. Useful for testing time-sensitive functionality like TTL.
|
|
198
|
+
*
|
|
199
|
+
* @param seconds - Number of seconds to advance (must be positive)
|
|
200
|
+
*/
|
|
201
|
+
fastForward(seconds: bigint): Effect.Effect<void>;
|
|
202
|
+
/**
|
|
203
|
+
* Query the simulator state with a custom function. This is a generic query mechanism that allows extracting any
|
|
204
|
+
* information from the current state without modifying it.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* // Query fee prices
|
|
209
|
+
* const feePrices = yield* simulator.query(state => state.ledger.parameters.feePrices);
|
|
210
|
+
*
|
|
211
|
+
* // Use composable state accessors
|
|
212
|
+
* const blockNumber = yield* simulator.query(getCurrentBlockNumber);
|
|
213
|
+
* const lastBlock = yield* simulator.query(getLastBlock);
|
|
214
|
+
* const events = yield* simulator.query(getLastBlockEvents);
|
|
215
|
+
*
|
|
216
|
+
* // Query UTXOs for an address
|
|
217
|
+
* const utxos = yield* simulator.query(state => Array.from(state.ledger.utxo.filter(address)));
|
|
218
|
+
*
|
|
219
|
+
* // Complex query returning multiple values
|
|
220
|
+
* const info = yield* simulator.query(state => ({
|
|
221
|
+
* networkId: state.networkId,
|
|
222
|
+
* blockNumber: getCurrentBlockNumber(state),
|
|
223
|
+
* feePrices: state.ledger.parameters.feePrices,
|
|
224
|
+
* }));
|
|
225
|
+
* ```;
|
|
226
|
+
*
|
|
227
|
+
* @param fn - Function that receives the current state and returns a result
|
|
228
|
+
* @returns The result of applying the function to the current state
|
|
229
|
+
*/
|
|
230
|
+
query<T>(fn: (state: SimulatorState) => T): Effect.Effect<T>;
|
|
231
|
+
}
|