crypto-aio 0.2.0 → 1.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/CHANGELOG.md +70 -2
- package/README.md +16 -10
- package/dist/adapters/avalanche/driver.d.ts +4 -0
- package/dist/adapters/avalanche/driver.js.map +1 -1
- package/dist/adapters/avalanche/sdk.d.ts +15 -0
- package/dist/adapters/avalanche/sdk.js.map +1 -1
- package/dist/adapters/evm/plugin.d.ts +1 -0
- package/dist/adapters/evm/plugin.js.map +1 -1
- package/dist/adapters/ton/network.d.ts +1 -0
- package/dist/adapters/ton/network.js +1 -0
- package/dist/adapters/ton/network.js.map +1 -1
- package/dist/adapters/ton/types.d.ts +1 -0
- package/dist/adapters/ton/types.js.map +1 -1
- package/dist/adapters/tron/decode.js +3 -2
- package/dist/adapters/tron/decode.js.map +1 -1
- package/dist/adapters/tron/http.d.ts +6 -0
- package/dist/adapters/tron/http.js +9 -0
- package/dist/adapters/tron/http.js.map +1 -1
- package/dist/adapters/tron/network.d.ts +4 -0
- package/dist/adapters/tron/network.js +4 -0
- package/dist/adapters/tron/network.js.map +1 -1
- package/dist/adapters/tron/proofs.js +6 -2
- package/dist/adapters/tron/proofs.js.map +1 -1
- package/dist/adapters/tron/reader.js +1 -1
- package/dist/adapters/tron/reader.js.map +1 -1
- package/dist/adapters/utxo/driver.d.ts +4 -0
- package/dist/adapters/utxo/driver.js.map +1 -1
- package/dist/adapters/utxo/esplora.d.ts +6 -0
- package/dist/adapters/utxo/esplora.js +20 -3
- package/dist/adapters/utxo/esplora.js.map +1 -1
- package/dist/adapters/utxo/types.d.ts +1 -0
- package/dist/adapters/utxo/types.js.map +1 -1
- package/dist/core/blockchain/handle.d.ts +6 -1
- package/dist/core/blockchain/handle.js +1 -1
- package/dist/core/blockchain/handle.js.map +1 -1
- package/dist/core/config/types.d.ts +64 -0
- package/dist/core/config/types.js.map +1 -1
- package/dist/core/container/container.d.ts +3 -0
- package/dist/core/container/container.js.map +1 -1
- package/dist/core/container/pool.js +12 -0
- package/dist/core/container/pool.js.map +1 -1
- package/dist/core/driver/types.d.ts +124 -7
- package/dist/core/driver/types.js.map +1 -1
- package/dist/core/errors/codes.d.ts +3 -0
- package/dist/core/errors/codes.js.map +1 -1
- package/dist/core/errors/error.d.ts +26 -0
- package/dist/core/errors/error.js +20 -0
- package/dist/core/errors/error.js.map +1 -1
- package/dist/core/events/logger.d.ts +17 -1
- package/dist/core/events/logger.js +5 -1
- package/dist/core/events/logger.js.map +1 -1
- package/dist/core/events/types.d.ts +26 -1
- package/dist/core/events/types.js.map +1 -1
- package/dist/core/lifecycle/engine.d.ts +5 -0
- package/dist/core/lifecycle/engine.js.map +1 -1
- package/dist/core/lifecycle/monitor.d.ts +6 -0
- package/dist/core/lifecycle/monitor.js.map +1 -1
- package/dist/core/lifecycle/views.d.ts +5 -0
- package/dist/core/lifecycle/views.js.map +1 -1
- package/dist/core/lifecycle/workers.d.ts +1 -0
- package/dist/core/lifecycle/workers.js.map +1 -1
- package/dist/core/model/address.d.ts +4 -0
- package/dist/core/model/address.js.map +1 -1
- package/dist/core/model/amount.d.ts +5 -0
- package/dist/core/model/amount.js.map +1 -1
- package/dist/core/model/asset.d.ts +11 -0
- package/dist/core/model/asset.js +2 -0
- package/dist/core/model/asset.js.map +1 -1
- package/dist/core/model/capability.d.ts +6 -0
- package/dist/core/model/capability.js +4 -0
- package/dist/core/model/capability.js.map +1 -1
- package/dist/core/model/chain.d.ts +19 -0
- package/dist/core/model/chain.js +1 -0
- package/dist/core/model/chain.js.map +1 -1
- package/dist/core/model/fee.d.ts +24 -1
- package/dist/core/model/fee.js.map +1 -1
- package/dist/core/model/ids.d.ts +10 -7
- package/dist/core/model/ids.js +1 -0
- package/dist/core/model/ids.js.map +1 -1
- package/dist/core/model/intent.d.ts +13 -0
- package/dist/core/model/intent.js.map +1 -1
- package/dist/core/model/ordering.d.ts +5 -0
- package/dist/core/model/ordering.js.map +1 -1
- package/dist/core/model/transaction.d.ts +39 -0
- package/dist/core/model/transaction.js.map +1 -1
- package/dist/core/observe/scanner.d.ts +10 -1
- package/dist/core/observe/scanner.js +6 -0
- package/dist/core/observe/scanner.js.map +1 -1
- package/dist/core/registry/assets.d.ts +5 -0
- package/dist/core/registry/assets.js.map +1 -1
- package/dist/core/registry/plugin.d.ts +6 -1
- package/dist/core/registry/plugin.js.map +1 -1
- package/dist/core/registry/providers.d.ts +5 -0
- package/dist/core/registry/providers.js.map +1 -1
- package/dist/core/registry/schemes.d.ts +7 -0
- package/dist/core/registry/schemes.js.map +1 -1
- package/dist/core/secret/redact.d.ts +9 -0
- package/dist/core/secret/redact.js +9 -0
- package/dist/core/secret/redact.js.map +1 -1
- package/dist/core/secret/secret.d.ts +4 -0
- package/dist/core/secret/secret.js +4 -0
- package/dist/core/secret/secret.js.map +1 -1
- package/dist/core/signing/callback.d.ts +5 -0
- package/dist/core/signing/callback.js.map +1 -1
- package/dist/core/signing/hd.d.ts +4 -0
- package/dist/core/signing/hd.js.map +1 -1
- package/dist/core/signing/local.d.ts +17 -0
- package/dist/core/signing/local.js +5 -0
- package/dist/core/signing/local.js.map +1 -1
- package/dist/core/signing/types.d.ts +35 -1
- package/dist/core/signing/types.js.map +1 -1
- package/dist/core/store/format.d.ts +3 -3
- package/dist/core/store/format.js +18 -8
- package/dist/core/store/format.js.map +1 -1
- package/dist/core/store/memory.d.ts +11 -0
- package/dist/core/store/memory.js +11 -0
- package/dist/core/store/memory.js.map +1 -1
- package/dist/core/store/types.d.ts +164 -3
- package/dist/core/store/types.js +4 -0
- package/dist/core/store/types.js.map +1 -1
- package/dist/core/transport/http-transport.js +33 -13
- package/dist/core/transport/http-transport.js.map +1 -1
- package/dist/core/transport/types.d.ts +70 -0
- package/dist/core/transport/types.js.map +1 -1
- package/dist/core/util/clock.d.ts +6 -0
- package/dist/core/util/clock.js.map +1 -1
- package/dist/core/util/json.d.ts +6 -0
- package/dist/core/util/json.js +21 -8
- package/dist/core/util/json.js.map +1 -1
- package/dist/testing/contracts/api.d.ts +1 -0
- package/dist/testing/contracts/api.js +1 -0
- package/dist/testing/contracts/api.js.map +1 -1
- package/dist/testing/contracts/cursors.d.ts +5 -0
- package/dist/testing/contracts/cursors.js +4 -0
- package/dist/testing/contracts/cursors.js.map +1 -1
- package/dist/testing/contracts/locks.d.ts +6 -0
- package/dist/testing/contracts/locks.js +5 -0
- package/dist/testing/contracts/locks.js.map +1 -1
- package/dist/testing/contracts/operations.d.ts +11 -0
- package/dist/testing/contracts/operations.js +10 -0
- package/dist/testing/contracts/operations.js.map +1 -1
- package/dist/testing/contracts/sequences.d.ts +5 -0
- package/dist/testing/contracts/sequences.js +4 -0
- package/dist/testing/contracts/sequences.js.map +1 -1
- package/dist/testing/env.d.ts +11 -0
- package/dist/testing/env.js +1 -0
- package/dist/testing/env.js.map +1 -1
- package/dist/testing/fake-chain.d.ts +32 -0
- package/dist/testing/fake-chain.js +11 -0
- package/dist/testing/fake-chain.js.map +1 -1
- package/dist/testing/fake-driver.d.ts +2 -0
- package/dist/testing/fake-driver.js.map +1 -1
- package/dist/testing/fake-fetch.d.ts +6 -0
- package/dist/testing/fake-fetch.js +2 -0
- package/dist/testing/fake-fetch.js.map +1 -1
- package/dist/testing/fake-plugin.d.ts +2 -0
- package/dist/testing/fake-plugin.js +2 -0
- package/dist/testing/fake-plugin.js.map +1 -1
- package/dist/testing/faulty-store.d.ts +2 -0
- package/dist/testing/faulty-store.js +1 -0
- package/dist/testing/faulty-store.js.map +1 -1
- package/package.json +5 -5
|
@@ -11,6 +11,10 @@ import type { KeyRef, Signer, SigningContext } from '../signing/types';
|
|
|
11
11
|
import type { Stores } from '../store/types';
|
|
12
12
|
import type { EndpointConfig, TransportOptions } from '../transport/types';
|
|
13
13
|
import type { Clock } from '../util/clock';
|
|
14
|
+
/**
|
|
15
|
+
* A provider: a preset by name with its API key (wrap it in `secret()`) and the preset's
|
|
16
|
+
* own options, or your own endpoints.
|
|
17
|
+
*/
|
|
14
18
|
export type ProviderConfig = {
|
|
15
19
|
readonly preset: string;
|
|
16
20
|
readonly apiKey?: string | Secret<string>;
|
|
@@ -18,34 +22,63 @@ export type ProviderConfig = {
|
|
|
18
22
|
} | {
|
|
19
23
|
readonly endpoints: readonly EndpointConfig[];
|
|
20
24
|
};
|
|
25
|
+
/** A provider by the name it has in `providers`, or given inline. */
|
|
21
26
|
export type ProviderRef = string | ProviderConfig;
|
|
27
|
+
/**
|
|
28
|
+
* A wallet: which key sends, through which signer. Without a signer it is watch-only: it
|
|
29
|
+
* reads, and with `publicKey` it prepares transactions for signing elsewhere.
|
|
30
|
+
*/
|
|
22
31
|
export interface WalletConfig {
|
|
32
|
+
/** The name of the signer (in `signers`) that holds the key. */
|
|
23
33
|
readonly signer?: string;
|
|
24
34
|
/** Routes requests to signers by `keyRef.id` (multi-party wallets). */
|
|
25
35
|
readonly signers?: Readonly<Record<string, string>>;
|
|
36
|
+
/** The address of a watch-only wallet. */
|
|
26
37
|
readonly address?: string;
|
|
27
38
|
/** Hex public key for watch-only wallets that still prepare transactions. */
|
|
28
39
|
readonly publicKey?: string;
|
|
40
|
+
/** An extended public key, for deposit addresses from `deriveAddress`. */
|
|
29
41
|
readonly xpub?: string;
|
|
42
|
+
/** The version bytes of a non-standard `xpub`. */
|
|
30
43
|
readonly xpubVersions?: ExtendedKeyVersions;
|
|
31
44
|
/** Child path template relative to the xpub; `{index}` is replaced. Default `0/{index}`. */
|
|
32
45
|
readonly xpubPath?: string;
|
|
46
|
+
/** Which key of the signer, such as a derivation path for a mnemonic signer. */
|
|
33
47
|
readonly keyRef?: KeyRef;
|
|
34
48
|
/** Metadata only (passed to signing context); no built-in behaviour. */
|
|
35
49
|
readonly tier?: string;
|
|
50
|
+
/** The chains this wallet may be used on. */
|
|
36
51
|
readonly chains?: readonly string[];
|
|
52
|
+
/**
|
|
53
|
+
* Bitcoin wallet settings (`UtxoWalletOptions` from `crypto-aio/utxo`). A plain record
|
|
54
|
+
* through 1.x; the family type names the shape it accepts.
|
|
55
|
+
*/
|
|
37
56
|
readonly utxo?: Readonly<Record<string, unknown>>;
|
|
57
|
+
/**
|
|
58
|
+
* TON wallet settings (`TonWalletIdentity` from `crypto-aio/ton`). A plain record
|
|
59
|
+
* through 1.x; the family type names the shape it accepts.
|
|
60
|
+
*/
|
|
38
61
|
readonly ton?: Readonly<Record<string, unknown>>;
|
|
62
|
+
/** Further family wallet options. */
|
|
39
63
|
readonly options?: Readonly<Record<string, unknown>>;
|
|
40
64
|
}
|
|
65
|
+
/** Per-chain defaults (`chains.<id>`); a handle can set the same fields but `maxLagBlocks`. */
|
|
41
66
|
export interface ChainDefaults {
|
|
67
|
+
/** Defaults to the chain's default network. */
|
|
42
68
|
readonly network?: string;
|
|
69
|
+
/** The SDK library, such as `ethers`; defaults to the chain's first. */
|
|
43
70
|
readonly library?: string;
|
|
71
|
+
/** Several providers fail over and cross-check proofs. */
|
|
44
72
|
readonly provider?: ProviderRef | readonly ProviderRef[];
|
|
73
|
+
/** The indexer providers, for the families that read one. */
|
|
45
74
|
readonly indexer?: ProviderRef | readonly ProviderRef[];
|
|
75
|
+
/** The wallet that sends. */
|
|
46
76
|
readonly wallet?: string;
|
|
77
|
+
/** Overrides the wallet's signer. */
|
|
47
78
|
readonly signer?: string;
|
|
79
|
+
/** The family's own options; a family refuses keys it does not know (`CONFIG_INVALID`). */
|
|
48
80
|
readonly options?: Readonly<Record<string, unknown>>;
|
|
81
|
+
/** The default target of `waitForConfirmation`. */
|
|
49
82
|
readonly confirmations?: number;
|
|
50
83
|
/**
|
|
51
84
|
* This chain's lag tolerance, in blocks. It wins over the root
|
|
@@ -55,10 +88,15 @@ export interface ChainDefaults {
|
|
|
55
88
|
*/
|
|
56
89
|
readonly maxLagBlocks?: number;
|
|
57
90
|
}
|
|
91
|
+
/** Timing and safety of transfers and workers. */
|
|
58
92
|
export interface LifecycleOptions {
|
|
93
|
+
/** How often waits and workers observe an Operation (default 5 000 ms). */
|
|
59
94
|
readonly pollIntervalMs?: number;
|
|
95
|
+
/** How long an unseen transaction waits before it counts as dropped and is resent (default 120 000 ms). */
|
|
60
96
|
readonly droppedGracePeriodMs?: number;
|
|
97
|
+
/** The least time between resends of one Attempt (default 60 000 ms). */
|
|
61
98
|
readonly rebroadcastIntervalMs?: number;
|
|
99
|
+
/** The time-to-live of a wallet's address lease, held while a slot is reserved and signed (default 30 000 ms). */
|
|
62
100
|
readonly leaseMs?: number;
|
|
63
101
|
/**
|
|
64
102
|
* How long a transfer waits for its wallet's address lease while another Operation of
|
|
@@ -67,9 +105,13 @@ export interface LifecycleOptions {
|
|
|
67
105
|
* to queue transfers behind a slow signer instead of failing them.
|
|
68
106
|
*/
|
|
69
107
|
readonly leaseWaitMs?: number;
|
|
108
|
+
/** How long a worker's claim on an Operation lasts (default 60 000 ms). */
|
|
70
109
|
readonly claimLeaseMs?: number;
|
|
110
|
+
/** The default timeout of `waitForConfirmation` (default 600 000 ms). */
|
|
71
111
|
readonly waitTimeoutMs?: number;
|
|
112
|
+
/** Whether a transfer without an idempotency key is an error (default `false`; set it in production). */
|
|
72
113
|
readonly requireIdempotencyKey?: boolean;
|
|
114
|
+
/** How many endpoints each broadcast goes to (default 1). */
|
|
73
115
|
readonly broadcastFanout?: number;
|
|
74
116
|
/**
|
|
75
117
|
* How long `transfer` and `submitSignatures` wait for the `beforeSign` hook and the
|
|
@@ -79,6 +121,7 @@ export interface LifecycleOptions {
|
|
|
79
121
|
*/
|
|
80
122
|
readonly signTimeoutMs?: number;
|
|
81
123
|
}
|
|
124
|
+
/** The container's hooks into the transfer lifecycle. */
|
|
82
125
|
export interface Hooks {
|
|
83
126
|
/**
|
|
84
127
|
* Throw to veto signing (policy engines, approvals). Runs before every signing request.
|
|
@@ -92,14 +135,20 @@ export interface Hooks {
|
|
|
92
135
|
*/
|
|
93
136
|
readonly beforeSign?: (ctx: SigningContext) => void | Promise<void>;
|
|
94
137
|
}
|
|
138
|
+
/** What `aio.scope(overrides)` can override, over its parent's options. */
|
|
95
139
|
export interface ScopeOptions {
|
|
140
|
+
/** Per-chain defaults, by chain id. */
|
|
96
141
|
readonly chains?: Readonly<Record<string, ChainDefaults>>;
|
|
142
|
+
/** Named providers. */
|
|
97
143
|
readonly providers?: Readonly<Record<string, ProviderConfig>>;
|
|
144
|
+
/** Named signers, from `localSigner` or `callbackSigner`. */
|
|
98
145
|
readonly signers?: Readonly<Record<string, Signer>>;
|
|
146
|
+
/** Named wallets. */
|
|
99
147
|
readonly wallets?: Readonly<Record<string, WalletConfig>>;
|
|
100
148
|
readonly hooks?: Hooks;
|
|
101
149
|
readonly lifecycle?: LifecycleOptions;
|
|
102
150
|
}
|
|
151
|
+
/** The options of `new CryptoAio(options)` and `configure(options)`. */
|
|
103
152
|
export interface AioOptions extends ScopeOptions {
|
|
104
153
|
/** Root-only: drivers and transports are shared by all scopes of a root container. */
|
|
105
154
|
readonly transport?: TransportOptions;
|
|
@@ -107,10 +156,18 @@ export interface AioOptions extends ScopeOptions {
|
|
|
107
156
|
readonly namespace?: string;
|
|
108
157
|
/** Environment source for routing config; `false` disables it. Default: `process.env`. */
|
|
109
158
|
readonly env?: Readonly<Record<string, string | undefined>> | false;
|
|
159
|
+
/** The environment profile to read (default: `CRYPTO_AIO_ENV`). */
|
|
110
160
|
readonly profile?: string;
|
|
161
|
+
/**
|
|
162
|
+
* The stores; each one left out is an in-memory store, which loses everything when the
|
|
163
|
+
* process ends. Production needs all four durable, shared by every process.
|
|
164
|
+
*/
|
|
111
165
|
readonly stores?: Partial<Stores>;
|
|
166
|
+
/** Where logs go (default: a `debug`-based logger). */
|
|
112
167
|
readonly logger?: Logger;
|
|
168
|
+
/** The time source (default: the system clock); `FakeClock` in tests. */
|
|
113
169
|
readonly clock?: Clock;
|
|
170
|
+
/** Root-only: extra chain families, networks, presets and tokens. */
|
|
114
171
|
readonly plugins?: readonly Plugin[];
|
|
115
172
|
/**
|
|
116
173
|
* Tokens to register on this root container, as a plugin's `assets` would: their decimals
|
|
@@ -120,6 +177,12 @@ export interface AioOptions extends ScopeOptions {
|
|
|
120
177
|
*/
|
|
121
178
|
readonly assets?: readonly AssetRegistration[];
|
|
122
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* What a handle is for (`aio.blockchain(options)`, `bc.with(overrides)`): a chain and, over
|
|
182
|
+
* its `chains.<id>` defaults, the same fields as `ChainDefaults` but `maxLagBlocks`.
|
|
183
|
+
* `options` stays a plain record through 1.x; each family's options are listed on its
|
|
184
|
+
* network page.
|
|
185
|
+
*/
|
|
123
186
|
export interface HandleOptions {
|
|
124
187
|
readonly chain: string;
|
|
125
188
|
readonly network?: string;
|
|
@@ -131,6 +194,7 @@ export interface HandleOptions {
|
|
|
131
194
|
readonly options?: Readonly<Record<string, unknown>>;
|
|
132
195
|
readonly confirmations?: number;
|
|
133
196
|
}
|
|
197
|
+
/** `HandleOptions` typed for chain `C`: its networks and libraries by name. */
|
|
134
198
|
export type HandleConfig<C extends ChainId> = Omit<HandleOptions, 'chain' | 'network' | 'library'> & {
|
|
135
199
|
readonly chain: C;
|
|
136
200
|
readonly network?: NetworkOf<C>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/config/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AdapterManifest } from '../driver/types';\nimport type { Logger } from '../events/logger';\nimport type { Capability } from '../model/capability';\nimport type { ChainInfo, NetworkInfo } from '../model/chain';\nimport type { ChainId, LibraryOf, NetworkOf } from '../model/ids';\nimport type { AssetRegistration } from '../registry/assets';\nimport type { Plugin } from '../registry/plugin';\nimport type { Secret } from '../secret/secret';\nimport type { ExtendedKeyVersions } from '../signing/hd';\nimport type { KeyRef, Signer, SigningContext } from '../signing/types';\nimport type { Stores } from '../store/types';\nimport type { EndpointConfig, TransportOptions } from '../transport/types';\nimport type { Clock } from '../util/clock';\n\nexport type ProviderConfig =\n | {\n readonly preset: string;\n readonly apiKey?: string | Secret<string>;\n readonly options?: Readonly<Record<string, unknown>>;\n }\n | { readonly endpoints: readonly EndpointConfig[] };\n\nexport type ProviderRef = string | ProviderConfig;\n\nexport interface WalletConfig {\n readonly signer?: string;\n /** Routes requests to signers by `keyRef.id` (multi-party wallets). */\n readonly signers?: Readonly<Record<string, string>>;\n readonly address?: string;\n /** Hex public key for watch-only wallets that still prepare transactions. */\n readonly publicKey?: string;\n readonly xpub?: string;\n readonly xpubVersions?: ExtendedKeyVersions;\n /** Child path template relative to the xpub; `{index}` is replaced. Default `0/{index}`. */\n readonly xpubPath?: string;\n readonly keyRef?: KeyRef;\n /** Metadata only (passed to signing context); no built-in behaviour. */\n readonly tier?: string;\n readonly chains?: readonly string[];\n readonly utxo?: Readonly<Record<string, unknown>>;\n readonly ton?: Readonly<Record<string, unknown>>;\n readonly options?: Readonly<Record<string, unknown>>;\n}\n\nexport interface ChainDefaults {\n readonly network?: string;\n readonly library?: string;\n readonly provider?: ProviderRef | readonly ProviderRef[];\n readonly indexer?: ProviderRef | readonly ProviderRef[];\n readonly wallet?: string;\n readonly signer?: string;\n readonly options?: Readonly<Record<string, unknown>>;\n readonly confirmations?: number;\n /**\n * This chain's lag tolerance, in blocks. It wins over the root\n * `transport.maxLagBlocks`, which wins over the plugin network's own, which wins over\n * the transport's built-in default. An endpoint further behind the best known height is\n * lagging, and a monitor or scanner view further behind is stale.\n */\n readonly maxLagBlocks?: number;\n}\n\nexport interface LifecycleOptions {\n readonly pollIntervalMs?: number;\n readonly droppedGracePeriodMs?: number;\n readonly rebroadcastIntervalMs?: number;\n readonly leaseMs?: number;\n /**\n * How long a transfer waits for its wallet's address lease while another Operation of\n * the wallet holds it, before it fails with `SEQUENCE_BUSY` (default: `leaseMs`). The\n * holder keeps the lease while its signer works, for up to `signTimeoutMs`, so raise this\n * to queue transfers behind a slow signer instead of failing them.\n */\n readonly leaseWaitMs?: number;\n readonly claimLeaseMs?: number;\n readonly waitTimeoutMs?: number;\n readonly requireIdempotencyKey?: boolean;\n readonly broadcastFanout?: number;\n /**\n * How long `transfer` and `submitSignatures` wait for the `beforeSign` hook and the\n * signer(s) (default 120 000 ms). The wallet's address lease is kept alive meanwhile. On\n * timeout nothing is written: the Operation stays `prepared` with its reservation, and a\n * repeat asks again. Signers that need longer should answer `pending` with a ticket.\n */\n readonly signTimeoutMs?: number;\n}\n\nexport interface Hooks {\n /**\n * Throw to veto signing (policy engines, approvals). Runs before every signing request.\n * It may run more than once per Operation: once per concurrent caller, and again when a\n * `prepared` Operation is repeated. Make it idempotent; `ctx.operationId` identifies the\n * Operation. It runs while the wallet's address lease is held, so keep it short. In\n * `transfer` and `submitSignatures` the lease is kept alive for up to\n * `lifecycle.signTimeoutMs`; in `prepareTransfer` a hook running longer than\n * `lifecycle.leaseMs` can lose the lease to another transfer. A veto after that writes\n * nothing; the Operation stays `prepared` and is vetoed again on its next repeat.\n */\n readonly beforeSign?: (ctx: SigningContext) => void | Promise<void>;\n}\n\nexport interface ScopeOptions {\n readonly chains?: Readonly<Record<string, ChainDefaults>>;\n readonly providers?: Readonly<Record<string, ProviderConfig>>;\n readonly signers?: Readonly<Record<string, Signer>>;\n readonly wallets?: Readonly<Record<string, WalletConfig>>;\n readonly hooks?: Hooks;\n readonly lifecycle?: LifecycleOptions;\n}\n\nexport interface AioOptions extends ScopeOptions {\n /** Root-only: drivers and transports are shared by all scopes of a root container. */\n readonly transport?: TransportOptions;\n /** Prefixes every store key; tenants sharing a database must use distinct namespaces. */\n readonly namespace?: string;\n /** Environment source for routing config; `false` disables it. Default: `process.env`. */\n readonly env?: Readonly<Record<string, string | undefined>> | false;\n readonly profile?: string;\n readonly stores?: Partial<Stores>;\n readonly logger?: Logger;\n readonly clock?: Clock;\n readonly plugins?: readonly Plugin[];\n /**\n * Tokens to register on this root container, as a plugin's `assets` would: their decimals\n * and symbol, and aliases such as `USDC`. A registered token's decimals scale its amounts\n * instead of what the chain says, so give each only from a source you trust; a token\n * whose chain gives no decimals can be sent only once they are registered.\n */\n readonly assets?: readonly AssetRegistration[];\n}\n\nexport interface HandleOptions {\n readonly chain: string;\n readonly network?: string;\n readonly library?: string;\n readonly provider?: ProviderRef | readonly ProviderRef[];\n readonly indexer?: ProviderRef | readonly ProviderRef[];\n readonly wallet?: string;\n readonly signer?: string;\n readonly options?: Readonly<Record<string, unknown>>;\n readonly confirmations?: number;\n}\n\nexport type HandleConfig<C extends ChainId> = Omit<\n HandleOptions,\n 'chain' | 'network' | 'library'\n> & {\n readonly chain: C;\n readonly network?: NetworkOf<C>;\n readonly library?: LibraryOf<C>;\n};\n\nexport interface EffectiveOptions {\n readonly chains: Readonly<Record<string, ChainDefaults>>;\n readonly providers: Readonly<Record<string, ProviderConfig>>;\n readonly signers: Readonly<Record<string, Signer>>;\n readonly wallets: Readonly<Record<string, WalletConfig>>;\n readonly hooks: Hooks;\n readonly lifecycle: LifecycleOptions;\n}\n\nexport interface ResolvedProvider {\n readonly name: string;\n readonly endpoints: readonly EndpointConfig[];\n readonly production: boolean;\n}\n\nexport interface ResolvedSelection {\n readonly chain: ChainInfo;\n readonly network: NetworkInfo;\n readonly library: string;\n readonly manifest: AdapterManifest;\n readonly providers: readonly ResolvedProvider[];\n readonly indexers: readonly ResolvedProvider[];\n readonly wallet?: { readonly name: string; readonly config: WalletConfig };\n readonly signer?: { readonly id: string; readonly instance: Signer };\n readonly options: Readonly<Record<string, unknown>>;\n readonly confirmations: number;\n /** The per-chain `maxLagBlocks` from the `chains` config, when set. */\n readonly maxLagBlocks?: number;\n readonly capabilities: ReadonlySet<Capability>;\n readonly providerNames: readonly string[];\n readonly indexerNames: readonly string[];\n /** Identity of the shared driver/transport (includes credential fingerprints). */\n readonly poolKey: string;\n /** Hash recorded in each Operation's ExecutionContext. */\n readonly configHash: string;\n /** The merged handle options, used by `with()`. */\n readonly handle: HandleOptions;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/config/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AdapterManifest } from '../driver/types';\nimport type { Logger } from '../events/logger';\nimport type { Capability } from '../model/capability';\nimport type { ChainInfo, NetworkInfo } from '../model/chain';\nimport type { ChainId, LibraryOf, NetworkOf } from '../model/ids';\nimport type { AssetRegistration } from '../registry/assets';\nimport type { Plugin } from '../registry/plugin';\nimport type { Secret } from '../secret/secret';\nimport type { ExtendedKeyVersions } from '../signing/hd';\nimport type { KeyRef, Signer, SigningContext } from '../signing/types';\nimport type { Stores } from '../store/types';\nimport type { EndpointConfig, TransportOptions } from '../transport/types';\nimport type { Clock } from '../util/clock';\n\n/**\n * A provider: a preset by name with its API key (wrap it in `secret()`) and the preset's\n * own options, or your own endpoints.\n */\nexport type ProviderConfig =\n | {\n readonly preset: string;\n readonly apiKey?: string | Secret<string>;\n readonly options?: Readonly<Record<string, unknown>>;\n }\n | { readonly endpoints: readonly EndpointConfig[] };\n\n/** A provider by the name it has in `providers`, or given inline. */\nexport type ProviderRef = string | ProviderConfig;\n\n/**\n * A wallet: which key sends, through which signer. Without a signer it is watch-only: it\n * reads, and with `publicKey` it prepares transactions for signing elsewhere.\n */\nexport interface WalletConfig {\n /** The name of the signer (in `signers`) that holds the key. */\n readonly signer?: string;\n /** Routes requests to signers by `keyRef.id` (multi-party wallets). */\n readonly signers?: Readonly<Record<string, string>>;\n /** The address of a watch-only wallet. */\n readonly address?: string;\n /** Hex public key for watch-only wallets that still prepare transactions. */\n readonly publicKey?: string;\n /** An extended public key, for deposit addresses from `deriveAddress`. */\n readonly xpub?: string;\n /** The version bytes of a non-standard `xpub`. */\n readonly xpubVersions?: ExtendedKeyVersions;\n /** Child path template relative to the xpub; `{index}` is replaced. Default `0/{index}`. */\n readonly xpubPath?: string;\n /** Which key of the signer, such as a derivation path for a mnemonic signer. */\n readonly keyRef?: KeyRef;\n /** Metadata only (passed to signing context); no built-in behaviour. */\n readonly tier?: string;\n /** The chains this wallet may be used on. */\n readonly chains?: readonly string[];\n /**\n * Bitcoin wallet settings (`UtxoWalletOptions` from `crypto-aio/utxo`). A plain record\n * through 1.x; the family type names the shape it accepts.\n */\n readonly utxo?: Readonly<Record<string, unknown>>;\n /**\n * TON wallet settings (`TonWalletIdentity` from `crypto-aio/ton`). A plain record\n * through 1.x; the family type names the shape it accepts.\n */\n readonly ton?: Readonly<Record<string, unknown>>;\n /** Further family wallet options. */\n readonly options?: Readonly<Record<string, unknown>>;\n}\n\n/** Per-chain defaults (`chains.<id>`); a handle can set the same fields but `maxLagBlocks`. */\nexport interface ChainDefaults {\n /** Defaults to the chain's default network. */\n readonly network?: string;\n /** The SDK library, such as `ethers`; defaults to the chain's first. */\n readonly library?: string;\n /** Several providers fail over and cross-check proofs. */\n readonly provider?: ProviderRef | readonly ProviderRef[];\n /** The indexer providers, for the families that read one. */\n readonly indexer?: ProviderRef | readonly ProviderRef[];\n /** The wallet that sends. */\n readonly wallet?: string;\n /** Overrides the wallet's signer. */\n readonly signer?: string;\n /** The family's own options; a family refuses keys it does not know (`CONFIG_INVALID`). */\n readonly options?: Readonly<Record<string, unknown>>;\n /** The default target of `waitForConfirmation`. */\n readonly confirmations?: number;\n /**\n * This chain's lag tolerance, in blocks. It wins over the root\n * `transport.maxLagBlocks`, which wins over the plugin network's own, which wins over\n * the transport's built-in default. An endpoint further behind the best known height is\n * lagging, and a monitor or scanner view further behind is stale.\n */\n readonly maxLagBlocks?: number;\n}\n\n/** Timing and safety of transfers and workers. */\nexport interface LifecycleOptions {\n /** How often waits and workers observe an Operation (default 5 000 ms). */\n readonly pollIntervalMs?: number;\n /** How long an unseen transaction waits before it counts as dropped and is resent (default 120 000 ms). */\n readonly droppedGracePeriodMs?: number;\n /** The least time between resends of one Attempt (default 60 000 ms). */\n readonly rebroadcastIntervalMs?: number;\n /** The time-to-live of a wallet's address lease, held while a slot is reserved and signed (default 30 000 ms). */\n readonly leaseMs?: number;\n /**\n * How long a transfer waits for its wallet's address lease while another Operation of\n * the wallet holds it, before it fails with `SEQUENCE_BUSY` (default: `leaseMs`). The\n * holder keeps the lease while its signer works, for up to `signTimeoutMs`, so raise this\n * to queue transfers behind a slow signer instead of failing them.\n */\n readonly leaseWaitMs?: number;\n /** How long a worker's claim on an Operation lasts (default 60 000 ms). */\n readonly claimLeaseMs?: number;\n /** The default timeout of `waitForConfirmation` (default 600 000 ms). */\n readonly waitTimeoutMs?: number;\n /** Whether a transfer without an idempotency key is an error (default `false`; set it in production). */\n readonly requireIdempotencyKey?: boolean;\n /** How many endpoints each broadcast goes to (default 1). */\n readonly broadcastFanout?: number;\n /**\n * How long `transfer` and `submitSignatures` wait for the `beforeSign` hook and the\n * signer(s) (default 120 000 ms). The wallet's address lease is kept alive meanwhile. On\n * timeout nothing is written: the Operation stays `prepared` with its reservation, and a\n * repeat asks again. Signers that need longer should answer `pending` with a ticket.\n */\n readonly signTimeoutMs?: number;\n}\n\n/** The container's hooks into the transfer lifecycle. */\nexport interface Hooks {\n /**\n * Throw to veto signing (policy engines, approvals). Runs before every signing request.\n * It may run more than once per Operation: once per concurrent caller, and again when a\n * `prepared` Operation is repeated. Make it idempotent; `ctx.operationId` identifies the\n * Operation. It runs while the wallet's address lease is held, so keep it short. In\n * `transfer` and `submitSignatures` the lease is kept alive for up to\n * `lifecycle.signTimeoutMs`; in `prepareTransfer` a hook running longer than\n * `lifecycle.leaseMs` can lose the lease to another transfer. A veto after that writes\n * nothing; the Operation stays `prepared` and is vetoed again on its next repeat.\n */\n readonly beforeSign?: (ctx: SigningContext) => void | Promise<void>;\n}\n\n/** What `aio.scope(overrides)` can override, over its parent's options. */\nexport interface ScopeOptions {\n /** Per-chain defaults, by chain id. */\n readonly chains?: Readonly<Record<string, ChainDefaults>>;\n /** Named providers. */\n readonly providers?: Readonly<Record<string, ProviderConfig>>;\n /** Named signers, from `localSigner` or `callbackSigner`. */\n readonly signers?: Readonly<Record<string, Signer>>;\n /** Named wallets. */\n readonly wallets?: Readonly<Record<string, WalletConfig>>;\n readonly hooks?: Hooks;\n readonly lifecycle?: LifecycleOptions;\n}\n\n/** The options of `new CryptoAio(options)` and `configure(options)`. */\nexport interface AioOptions extends ScopeOptions {\n /** Root-only: drivers and transports are shared by all scopes of a root container. */\n readonly transport?: TransportOptions;\n /** Prefixes every store key; tenants sharing a database must use distinct namespaces. */\n readonly namespace?: string;\n /** Environment source for routing config; `false` disables it. Default: `process.env`. */\n readonly env?: Readonly<Record<string, string | undefined>> | false;\n /** The environment profile to read (default: `CRYPTO_AIO_ENV`). */\n readonly profile?: string;\n /**\n * The stores; each one left out is an in-memory store, which loses everything when the\n * process ends. Production needs all four durable, shared by every process.\n */\n readonly stores?: Partial<Stores>;\n /** Where logs go (default: a `debug`-based logger). */\n readonly logger?: Logger;\n /** The time source (default: the system clock); `FakeClock` in tests. */\n readonly clock?: Clock;\n /** Root-only: extra chain families, networks, presets and tokens. */\n readonly plugins?: readonly Plugin[];\n /**\n * Tokens to register on this root container, as a plugin's `assets` would: their decimals\n * and symbol, and aliases such as `USDC`. A registered token's decimals scale its amounts\n * instead of what the chain says, so give each only from a source you trust; a token\n * whose chain gives no decimals can be sent only once they are registered.\n */\n readonly assets?: readonly AssetRegistration[];\n}\n\n/**\n * What a handle is for (`aio.blockchain(options)`, `bc.with(overrides)`): a chain and, over\n * its `chains.<id>` defaults, the same fields as `ChainDefaults` but `maxLagBlocks`.\n * `options` stays a plain record through 1.x; each family's options are listed on its\n * network page.\n */\nexport interface HandleOptions {\n readonly chain: string;\n readonly network?: string;\n readonly library?: string;\n readonly provider?: ProviderRef | readonly ProviderRef[];\n readonly indexer?: ProviderRef | readonly ProviderRef[];\n readonly wallet?: string;\n readonly signer?: string;\n readonly options?: Readonly<Record<string, unknown>>;\n readonly confirmations?: number;\n}\n\n/** `HandleOptions` typed for chain `C`: its networks and libraries by name. */\nexport type HandleConfig<C extends ChainId> = Omit<\n HandleOptions,\n 'chain' | 'network' | 'library'\n> & {\n readonly chain: C;\n readonly network?: NetworkOf<C>;\n readonly library?: LibraryOf<C>;\n};\n\nexport interface EffectiveOptions {\n readonly chains: Readonly<Record<string, ChainDefaults>>;\n readonly providers: Readonly<Record<string, ProviderConfig>>;\n readonly signers: Readonly<Record<string, Signer>>;\n readonly wallets: Readonly<Record<string, WalletConfig>>;\n readonly hooks: Hooks;\n readonly lifecycle: LifecycleOptions;\n}\n\nexport interface ResolvedProvider {\n readonly name: string;\n readonly endpoints: readonly EndpointConfig[];\n readonly production: boolean;\n}\n\nexport interface ResolvedSelection {\n readonly chain: ChainInfo;\n readonly network: NetworkInfo;\n readonly library: string;\n readonly manifest: AdapterManifest;\n readonly providers: readonly ResolvedProvider[];\n readonly indexers: readonly ResolvedProvider[];\n readonly wallet?: { readonly name: string; readonly config: WalletConfig };\n readonly signer?: { readonly id: string; readonly instance: Signer };\n readonly options: Readonly<Record<string, unknown>>;\n readonly confirmations: number;\n /** The per-chain `maxLagBlocks` from the `chains` config, when set. */\n readonly maxLagBlocks?: number;\n readonly capabilities: ReadonlySet<Capability>;\n readonly providerNames: readonly string[];\n readonly indexerNames: readonly string[];\n /** Identity of the shared driver/transport (includes credential fingerprints). */\n readonly poolKey: string;\n /** Hash recorded in each Operation's ExecutionContext. */\n readonly configHash: string;\n /** The merged handle options, used by `with()`. */\n readonly handle: HandleOptions;\n}\n"]}
|
|
@@ -8,12 +8,14 @@ import { type Plugin } from '../registry/plugin';
|
|
|
8
8
|
import type { OperationState } from '../store/types';
|
|
9
9
|
/** How long `close()` waits for one native client's `close` before moving on. */
|
|
10
10
|
export declare const NATIVE_CLOSE_TIMEOUT_MS = 5000;
|
|
11
|
+
/** Which Operations `aio.operations.list()` returns: every given field must match. */
|
|
11
12
|
export interface OperationsFilter {
|
|
12
13
|
readonly states?: readonly OperationState[];
|
|
13
14
|
readonly chain?: string;
|
|
14
15
|
readonly network?: string;
|
|
15
16
|
readonly limit?: number;
|
|
16
17
|
}
|
|
18
|
+
/** `aio.operations`: read this namespace's Operations and recover them at startup. */
|
|
17
19
|
export interface OperationsApi {
|
|
18
20
|
get(id: string): Promise<OperationView | null>;
|
|
19
21
|
/** In creation order. */
|
|
@@ -23,6 +25,7 @@ export interface OperationsApi {
|
|
|
23
25
|
readonly signal?: AbortSignal;
|
|
24
26
|
}): Promise<RecoveryReport>;
|
|
25
27
|
}
|
|
28
|
+
/** `aio.monitor`: the worker passes that check and finish every live Operation. */
|
|
26
29
|
export interface MonitorApi {
|
|
27
30
|
/** Runs worker passes until `signal` aborts; any number of workers may run. */
|
|
28
31
|
start(options?: WorkerOptions): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.js","sourceRoot":"","sources":["../../../src/core/container/container.ts"],"names":[],"mappings":";;;AAAA,+CAAiD;AACjD,iDAAyE;AACzE,qDAA2E;AAC3E,uCAA8C;AAC9C,2CAA4E;AAC5E,+CAAqD;AAUrD,2CAA8C;AAC9C,uCAAyC;AACzC,6CAAgD;AAEhD,gDAM6B;AAC7B,kDAAwF;AACxF,4DAA6D;AAC7D,8CAAgE;AAEhE,mDAA2D;AAC3D,+CAM4B;AAC5B,0DAA8D;AAC9D,8CAAuE;AACvE,4CAA8C;AAC9C,4CAAqD;AAErD,yCAAyC;AACzC,yCAAwD;AACxD,yCAA4C;AAC5C,2CAMqB;AACrB,iCAAuD;AAEvD,MAAM,SAAS,GAAG,wBAAwB,CAAC;AAE3C;;;;;GAKG;AACH,SAAS,YAAY,CACnB,OAAoB,EACpB,MAA+B;IAE/B,IAAI,OAAO,CAAC,MAAM;QAAE,MAAM,IAAA,uBAAW,GAAE,CAAC;IACxC,OAAO,MAAM;QACX,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACnD,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC;AAC7B,CAAC;AAED,iFAAiF;AACpE,QAAA,uBAAuB,GAAG,KAAK,CAAC;AAE7C,+FAA+F;AAC/F,KAAK,UAAU,WAAW,CACxB,KAAoB,EACpB,KAAY,EACZ,EAAU;IAEV,MAAM,KAAK,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AAE,CAAC,SAAS,CAAC;gBAC7D,WAAW,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC;gBACjD,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC;aAC3E,CAAC,CAAC;SACN,CAAC,CAAC;IACL,CAAC;CACF;AA7RD,8BA6RC","sourcesContent":["import { AssetService } from '../assets/service';\nimport { createBlockchain, type Blockchain } from '../blockchain/handle';\nimport { internalsOf, type HandleInternals } from '../blockchain/internal';\nimport { readEnvChains } from '../config/env';\nimport { assertNoCycle, isPlainObject, mergeScopes } from '../config/merge';\nimport { resolveSelection } from '../config/resolve';\nimport type {\n AioOptions,\n EffectiveOptions,\n HandleConfig,\n HandleOptions,\n ResolvedSelection,\n ScopeOptions,\n} from '../config/types';\nimport type { ChainDriver } from '../driver/types';\nimport { ConfigError } from '../errors/error';\nimport { EventBus } from '../events/bus';\nimport { createLogger } from '../events/logger';\nimport type { AioEvent, AioEventName } from '../events/types';\nimport {\n OperationEngine,\n errorCode,\n withLifecycleDefaults,\n type OperationTarget,\n type ReadTarget,\n} from '../lifecycle/engine';\nimport { Monitor, type RecoveryReport, type WorkerOptions } from '../lifecycle/monitor';\nimport { loadObservations } from '../lifecycle/observations';\nimport { toView, type OperationView } from '../lifecycle/views';\nimport type { ChainId } from '../model/ids';\nimport { SequenceCoordinator } from '../ordering/sequence';\nimport {\n applyPlugin,\n cloneCatalogs,\n createCatalogs,\n type Catalogs,\n type Plugin,\n} from '../registry/plugin';\nimport { SigningOrchestrator } from '../signing/orchestrator';\nimport { resolveWallet, type ResolvedWallet } from '../signing/wallet';\nimport { formatGuard } from '../store/format';\nimport { createMemoryStores } from '../store/memory';\nimport type { OperationRecord, OperationState, Stores } from '../store/types';\nimport { randomId } from '../util/bytes';\nimport { systemClock, type Clock } from '../util/clock';\nimport { builtinPlugins } from './builtins';\nimport {\n bindContainer,\n closedError,\n containerOf,\n type ContainerInternals,\n type RootRuntime,\n} from './internals';\nimport { DriverPool, type PooledDriver } from './pool';\n\nconst NAMESPACE = /^[A-Za-z0-9._-]{1,64}$/;\n\n/**\n * The signal a worker loop, pass or recovery runs under: the caller's, if any, and the\n * root's `closing`, which `close()` aborts. A closed container starts no new work: it\n * stops claiming Operations from a shared store (holding each for a lease) and no longer\n * keeps the process alive.\n */\nfunction workerSignal(\n runtime: RootRuntime,\n signal: AbortSignal | undefined,\n): AbortSignal {\n if (runtime.closed) throw closedError();\n return signal\n ? AbortSignal.any([signal, runtime.closing.signal])\n : runtime.closing.signal;\n}\n\n/** How long `close()` waits for one native client's `close` before moving on. */\nexport const NATIVE_CLOSE_TIMEOUT_MS = 5_000;\n\n/** Runs `close`, but gives up waiting after `ms` of `clock` time (the close keeps running). */\nasync function closeWithin(\n close: () => unknown,\n clock: Clock,\n ms: number,\n): Promise<'closed' | 'timeout'> {\n const timer = new AbortController();\n try {\n return await Promise.race([\n Promise.resolve()\n .then(close)\n .then(() => 'closed' as const),\n clock.sleep(ms, timer.signal).then(() => 'timeout' as const),\n ]);\n } finally {\n timer.abort();\n }\n}\n\ninterface ScopeInit {\n readonly parent: CryptoAio;\n readonly overrides: ScopeOptions;\n}\n\n/**\n * Set by `scope()` for the one synchronous constructor call it makes, so a child container\n * needs no constructor parameter in the public API.\n */\nlet pendingScope: ScopeInit | undefined;\n\n/**\n * Deep-clones plain objects/arrays into a frozen copy so a later mutation of the caller's\n * own input can never reach a layer already captured by a container. Class instances\n * (Signer, Secret, ...) are referenced, not cloned — they're already immutable.\n */\nfunction cloneFrozen<T>(value: T, ancestors: Set<object> = new Set()): T {\n if (!Array.isArray(value) && !isPlainObject(value)) return value;\n assertNoCycle(value, ancestors);\n ancestors.add(value);\n try {\n if (Array.isArray(value)) {\n return Object.freeze(\n value.map((item: unknown) => cloneFrozen(item, ancestors)),\n ) as T;\n }\n const out: Record<string, unknown> = {};\n for (const [key, v] of Object.entries(value)) out[key] = cloneFrozen(v, ancestors);\n return Object.freeze(out) as T;\n } finally {\n ancestors.delete(value);\n }\n}\n\n/** `chains`/`providers`/`wallets`/`signers`/`hooks`/`lifecycle` are all cloned and\n * deep-frozen at construction, so mutating the caller's options object afterwards never\n * affects handles already built from this layer. For `signers`, only the map OBJECT is\n * cloned (a fresh, frozen copy so adding/replacing a key on the caller's own map can't reach\n * an existing layer) — the `Signer` values it holds are opaque and always taken by reference,\n * never cloned or frozen, even a plain-object signer (`Signer` is an interface), so it keeps\n * its identity and its own mutable state. */\nfunction scopePart(options: ScopeOptions): ScopeOptions {\n const { chains, providers, signers, wallets, hooks, lifecycle } = options;\n return {\n ...(chains ? { chains: cloneFrozen(chains) } : {}),\n ...(providers ? { providers: cloneFrozen(providers) } : {}),\n ...(signers ? { signers: Object.freeze({ ...signers }) } : {}),\n ...(wallets ? { wallets: cloneFrozen(wallets) } : {}),\n ...(hooks ? { hooks: cloneFrozen(hooks) } : {}),\n ...(lifecycle ? { lifecycle: cloneFrozen(lifecycle) } : {}),\n };\n}\n\nconst checkedStores = new WeakMap<RootRuntime, Stores>();\n\n/**\n * The stores as the engine, the workers and `aio.operations` use them: Operation records\n * pass the format guard, so none is ever read in a format this version does not know.\n */\nfunction storesOf(runtime: RootRuntime): Stores {\n let stores = checkedStores.get(runtime);\n if (!stores) {\n stores = {\n ...runtime.stores,\n operations: formatGuard(runtime.stores.operations, runtime.log.child('store')),\n };\n checkedStores.set(runtime, stores);\n }\n return stores;\n}\n\nfunction createEngine(\n runtime: RootRuntime,\n effective: () => EffectiveOptions,\n): OperationEngine {\n const lifecycle = () => withLifecycleDefaults(effective().lifecycle);\n const { leaseMs, leaseWaitMs } = lifecycle();\n const log = runtime.log.child('lifecycle');\n return new OperationEngine({\n namespace: runtime.namespace,\n stores: storesOf(runtime),\n events: runtime.events,\n clock: runtime.clock,\n log,\n orchestrator: new SigningOrchestrator({\n schemes: () => runtime.catalogs.schemes,\n events: runtime.events,\n clock: runtime.clock,\n hooks: () => effective().hooks,\n }),\n sequences: new SequenceCoordinator({\n locks: runtime.stores.locks,\n sequences: runtime.stores.sequences,\n clock: runtime.clock,\n owner: runtime.owner,\n leaseMs,\n acquireTimeoutMs: leaseWaitMs,\n // The code only: a store's error message may carry detail that logs must not.\n onReleaseError: (error) =>\n log.warn('lease release failed', { code: errorCode(error) }),\n }),\n lifecycle,\n });\n}\n\n/**\n * The signer-free read target of a stored Operation, for every check,\n * worker pass and recovery read: its chain, network and library over its own named\n * providers first, then the current defaults when those no longer resolve (inline configs\n * are recorded by hash only and cannot be rebuilt). No wallet or signer is selected, not\n * even a chain default one, so a rotated signer, a removed wallet or a hung custody\n * backend never stops monitoring.\n */\nasync function readTarget(\n container: CryptoAio,\n record: OperationRecord,\n): Promise<ReadTarget> {\n const internals = containerOf(container);\n const { runtime } = internals;\n const { chain, network, library } = record.context;\n const effective = internals.effective();\n const { wallet: _wallet, signer: _signer, ...defaults } = effective.chains[chain] ?? {};\n const signerFree = { ...effective, chains: { ...effective.chains, [chain]: defaults } };\n const select = (provider?: readonly string[]) =>\n resolveSelection({\n handle: { chain, network, library, ...(provider ? { provider } : {}) },\n effective: signerFree,\n catalogs: runtime.catalogs,\n log: runtime.log,\n });\n const named = record.context.providers.filter((name) => !name.startsWith('inline:'));\n let selection: ResolvedSelection;\n try {\n selection = select(named.length > 0 ? named : undefined);\n } catch (error) {\n // Only a config that no longer resolves (e.g. a renamed provider) falls back.\n if (!(error instanceof ConfigError)) throw error;\n selection = select();\n }\n if (runtime.closed) throw closedError();\n return { selection, pooled: await runtime.pool.get(selection) };\n}\n\n/**\n * The wallets the monitor resolved for its writes, cached per container (one public-key\n * read per wallet selection, not one per pass) and bounded by `lifecycle.signTimeoutMs`. A\n * failed resolution is not kept. The cache is dropped when the config changes: a container's\n * layers are frozen, so only a plugin (`use()`, new catalogs and env layer) changes it.\n */\nfunction walletCache(\n runtime: RootRuntime,\n internals: () => ContainerInternals,\n): (selection: ResolvedSelection, driver: ChainDriver) => Promise<ResolvedWallet> {\n let catalogs: Catalogs = runtime.catalogs;\n const wallets = new Map<string, Promise<ResolvedWallet>>();\n return (selection, driver) => {\n if (runtime.catalogs !== catalogs) {\n catalogs = runtime.catalogs;\n wallets.clear();\n }\n const key = selection.configHash;\n const cached = wallets.get(key);\n if (cached) return cached;\n const { effective, signerDeadline } = internals();\n const resolving = resolveWallet(\n selection,\n driver,\n effective().signers,\n catalogs.schemes,\n signerDeadline(),\n ).catch((error: unknown) => {\n if (wallets.get(key) === resolving) wallets.delete(key);\n throw error;\n });\n wallets.set(key, resolving);\n return resolving;\n };\n}\n\n/**\n * The wallet-bound target of a stored Operation, resolved lazily and only for the\n * writes that need one: the all-rejected verdict, nonce reconciliation and recovery's\n * resend. None of them signs, and their address lease is keyed on the Operation itself.\n * Its frozen context (chain, network, library, wallet, signer) is rebuilt against the\n * container's current config with its own named providers first; when that no longer\n * resolves (a renamed provider, a rotated signer), the wallet alone over the current\n * defaults, with neither the recorded signer nor the providers: the wallet's current\n * signer, public key or address then stands for it (a watch-only wallet is enough). The\n * engine checks the resolved wallet still owns the Operation before using it.\n */\nasync function operationTarget(\n container: CryptoAio,\n runtime: RootRuntime,\n record: OperationRecord,\n wallets: (selection: ResolvedSelection, driver: ChainDriver) => Promise<ResolvedWallet>,\n): Promise<OperationTarget> {\n const { chain, network, library, wallet, signer, providers } = record.context;\n const base = { chain, network, library, wallet } as HandleConfig<ChainId>;\n const named = providers.filter((name) => !name.startsWith('inline:'));\n let handle: Blockchain<ChainId>;\n try {\n handle = container.blockchain({\n ...base,\n ...(signer !== undefined ? { signer } : {}),\n ...(named.length > 0 ? { provider: named } : {}),\n });\n } catch (error) {\n if (!(error instanceof ConfigError)) throw error;\n handle = container.blockchain(base);\n }\n const internals = internalsOf(handle);\n const pooled = await internals.pooled();\n return {\n selection: internals.selection,\n pooled,\n wallet: await wallets(internals.selection, pooled.driver),\n assets: runtime.assets,\n };\n}\n\nexport interface OperationsFilter {\n readonly states?: readonly OperationState[];\n readonly chain?: string;\n readonly network?: string;\n readonly limit?: number;\n}\n\nexport interface OperationsApi {\n get(id: string): Promise<OperationView | null>;\n /** In creation order. */\n list(filter?: OperationsFilter): Promise<OperationView[]>;\n /** Startup recovery for this namespace (see RecoveryReport); it never signs. */\n recover(options?: { readonly signal?: AbortSignal }): Promise<RecoveryReport>;\n}\n\nexport interface MonitorApi {\n /** Runs worker passes until `signal` aborts; any number of workers may run. */\n start(options?: WorkerOptions): Promise<void>;\n /** One worker pass; resolves to the number of Operations it claimed. */\n runOnce(options?: WorkerOptions): Promise<number>;\n}\n\n/**\n * Dependency container: stores, signers, wallets, hooks, plugins and a shared driver pool.\n * Separate `new CryptoAio()` instances are fully isolated (use one per tenant).\n */\nexport class CryptoAio {\n readonly namespace: string;\n\n constructor(options: AioOptions = {}) {\n const scope = pendingScope;\n pendingScope = undefined;\n if (scope) {\n const parent = containerOf(scope.parent);\n this.namespace = parent.runtime.namespace;\n this.#bind(parent.runtime, [...parent.layers, scopePart(scope.overrides)], false);\n return;\n }\n const namespace = options.namespace ?? 'default';\n if (!NAMESPACE.test(namespace))\n throw new ConfigError(\n 'CONFIG_INVALID',\n 'invalid namespace: use 1 to 64 letters, digits, dots, underscores or hyphens',\n );\n const clock = options.clock ?? systemClock;\n const log = options.logger ?? createLogger();\n const catalogs = createCatalogs();\n for (const plugin of [...builtinPlugins(), ...(options.plugins ?? [])])\n applyPlugin(catalogs, plugin);\n for (const asset of options.assets ?? []) {\n catalogs.chains.network(asset.chain, asset.network);\n catalogs.assets.register(asset);\n }\n const env = options.env === false ? {} : (options.env ?? process.env);\n const events = new EventBus(clock, log);\n // eslint-disable-next-line prefer-const -- closures below read it after assignment\n let runtime: RootRuntime;\n const pool = new DriverPool({\n catalogs: () => runtime.catalogs,\n clock,\n events,\n log,\n transport: () => runtime.transport,\n });\n runtime = {\n namespace,\n catalogs,\n envLayer: {\n chains: readEnvChains(\n env,\n catalogs.chains.list().map((c) => c.id),\n options.profile,\n ),\n },\n env,\n ...(options.profile !== undefined ? { profile: options.profile } : {}),\n clock,\n log,\n events,\n stores: {\n ...createMemoryStores(clock),\n ...(Object.fromEntries(\n Object.entries(options.stores ?? {}).filter(([, store]) => store !== undefined),\n ) as Partial<Stores>),\n },\n pool,\n assets: new AssetService(() => runtime.catalogs),\n transport: options.transport ?? {},\n owner: randomId('aio'),\n closed: false,\n closing: new AbortController(),\n natives: new Set(),\n };\n this.namespace = namespace;\n this.#bind(runtime, [scopePart(options)], true);\n }\n\n /**\n * Child container: inherits config, pool, stores and namespace; overrides merge on top.\n * Not a tenant boundary — a scope shares its root's pool and stores. Use a separate\n * `new CryptoAio({ namespace })` when isolation between tenants is required.\n */\n scope(overrides: ScopeOptions): CryptoAio {\n pendingScope = { parent: this, overrides };\n try {\n return new CryptoAio();\n } finally {\n pendingScope = undefined;\n }\n }\n\n blockchain<C extends ChainId>(config: HandleConfig<C>): Blockchain<C> {\n const internals = containerOf(this);\n const { runtime } = internals;\n const selection = resolveSelection({\n handle: config as HandleOptions,\n effective: internals.effective(),\n catalogs: runtime.catalogs,\n log: runtime.log,\n });\n let pooled: Promise<PooledDriver> | undefined;\n let wallet: Promise<ResolvedWallet> | undefined;\n const handle: HandleInternals = {\n container: this,\n selection,\n nativeClients: new Map(),\n assertOpen: () => {\n if (runtime.closed) throw closedError();\n },\n registerNative: (native) => {\n if (runtime.closed) throw closedError();\n if (native.close) runtime.natives.add(() => native.close?.());\n },\n // A closed root refuses work even through a pooled driver this handle holds.\n pooled: () => {\n if (runtime.closed) return Promise.reject(closedError());\n pooled ??= runtime.pool.get(selection).catch((error: unknown) => {\n pooled = undefined;\n throw error;\n });\n return pooled;\n },\n wallet: () => {\n if (runtime.closed) return Promise.reject(closedError());\n wallet ??= handle\n .pooled()\n .then(({ driver }) =>\n resolveWallet(\n selection,\n driver,\n internals.effective().signers,\n runtime.catalogs.schemes,\n internals.signerDeadline(),\n ),\n )\n .catch((error: unknown) => {\n wallet = undefined;\n throw error;\n });\n return wallet;\n },\n };\n return createBlockchain<C>(handle);\n }\n\n /** Registers a plugin on this root container (copy-on-write catalogs). */\n use(plugin: Plugin): this {\n const internals = containerOf(this);\n if (!internals.isRoot)\n throw new ConfigError(\n 'CONFIG_INVALID',\n 'plugins can only be added to a root container',\n );\n const { runtime } = internals;\n const next = cloneCatalogs(runtime.catalogs);\n applyPlugin(next, plugin);\n runtime.catalogs = next;\n runtime.envLayer = {\n chains: readEnvChains(\n runtime.env,\n next.chains.list().map((c) => c.id),\n runtime.profile,\n ),\n };\n return this;\n }\n\n on<E extends AioEventName>(type: E, handler: (event: AioEvent<E>) => void): () => void {\n return containerOf(this).runtime.events.on(type, handler);\n }\n\n onAny(handler: (event: AioEvent) => void): () => void {\n return containerOf(this).runtime.events.onAny(handler);\n }\n\n /** Stored Operations of this namespace, as views, and startup recovery. */\n get operations(): OperationsApi {\n const internals = containerOf(this);\n const store = storesOf(internals.runtime).operations;\n const namespace = internals.runtime.namespace;\n const view = async (record: OperationRecord) =>\n toView(record, await loadObservations(store, record));\n return {\n get: async (id) => {\n const record = await store.get(namespace, id);\n return record ? view(record) : null;\n },\n list: async (filter = {}) =>\n Promise.all(\n (\n await store.list({\n namespace,\n ...(filter.states ? { states: filter.states } : {}),\n ...(filter.chain ? { chain: filter.chain } : {}),\n ...(filter.network ? { network: filter.network } : {}),\n ...(filter.limit !== undefined ? { limit: filter.limit } : {}),\n })\n ).map(view),\n ),\n recover: async (options = {}) =>\n internals.monitor().recover({\n ...options,\n signal: workerSignal(internals.runtime, options.signal),\n }),\n };\n }\n\n /** Background workers that check due Operations without anyone waiting on them. */\n get monitor(): MonitorApi {\n const internals = containerOf(this);\n return {\n start: async (options = {}) =>\n internals.monitor().start({\n ...options,\n signal: workerSignal(internals.runtime, options.signal),\n }),\n runOnce: async (options = {}) =>\n internals.monitor().runOnce({\n workerId: options.workerId ?? internals.runtime.owner,\n ...(options.batch !== undefined ? { batch: options.batch } : {}),\n signal: workerSignal(internals.runtime, options.signal),\n }),\n };\n }\n\n /**\n * Closes the root container: runs the `close` of every native client that\n * `crypto-aio/native` handed out (a failing one is logged by code and skipped), then\n * closes the pooled drivers. Its handles and `native()` then fail with\n * `INVALID_TRANSITION`. A scope's `close()` does nothing; scopes share their root's pool.\n */\n async close(): Promise<void> {\n const internals = containerOf(this);\n if (!internals.isRoot) return;\n const { runtime } = internals;\n runtime.closed = true;\n // Every worker loop, pass and recovery stops at its next check, and its sleeps end.\n runtime.closing.abort();\n const natives = [...runtime.natives];\n runtime.natives.clear();\n await Promise.all(\n natives.map(async (close) => {\n try {\n const outcome = await closeWithin(\n close,\n runtime.clock,\n NATIVE_CLOSE_TIMEOUT_MS,\n );\n if (outcome === 'timeout') {\n runtime.log.warn('native client close timed out', {\n timeoutMs: NATIVE_CLOSE_TIMEOUT_MS,\n });\n }\n } catch (error) {\n runtime.log.warn('native client close failed', { code: errorCode(error) });\n }\n }),\n );\n await runtime.pool.close();\n }\n\n #bind(runtime: RootRuntime, layers: readonly ScopeOptions[], isRoot: boolean): void {\n const effective = () => mergeScopes([runtime.envLayer, ...layers]);\n let engine: OperationEngine | undefined;\n let monitor: Monitor | undefined;\n const getEngine = () => (engine ??= createEngine(runtime, effective));\n const wallets = walletCache(runtime, () => containerOf(this));\n bindContainer(this, {\n runtime,\n layers,\n isRoot,\n effective,\n signerDeadline: () => ({\n clock: runtime.clock,\n timeoutMs: withLifecycleDefaults(effective().lifecycle).signTimeoutMs,\n }),\n engine: getEngine,\n monitor: () =>\n (monitor ??= new Monitor({\n engine: getEngine(),\n stores: storesOf(runtime),\n events: runtime.events,\n clock: runtime.clock,\n log: runtime.log.child('monitor'),\n namespace: runtime.namespace,\n lifecycle: () => withLifecycleDefaults(effective().lifecycle),\n resolveRead: (record) => readTarget(this, record),\n resolveTarget: (record) => operationTarget(this, runtime, record, wallets),\n })),\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"container.js","sourceRoot":"","sources":["../../../src/core/container/container.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C,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,CAAC,MAAM,KAAK,YAAY,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;QACtE,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAA,uBAAW,EAAC,IAAI,CAAC,CAAC,CAAC;QAC9D,IAAA,yBAAa,EAAC,IAAI,EAAE;YAClB,OAAO;YACP,MAAM;YACN,MAAM;YACN,SAAS;YACT,cAAc,EAAE,GAAG,EAAE,CAAC,CAAC;gBACrB,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,SAAS,EAAE,IAAA,8BAAqB,EAAC,SAAS,EAAE,CAAC,SAAS,CAAC,CAAC,aAAa;aACtE,CAAC;YACF,MAAM,EAAE,SAAS;YACjB,OAAO,EAAE,GAAG,EAAE,CACZ,CAAC,OAAO,KAAK,IAAI,iBAAO,CAAC;gBACvB,MAAM,EAAE,SAAS,EAAE;gBACnB,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC;gBACzB,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC;gBACjC,SAAS,EAAE,OAAO,CAAC,SAAS;gBAC5B,SAAS,EAAE,GAAG,EAAE,CAAC,IAAA,8BAAqB,EAAC,SAAS,EAAE,CAAC,SAAS,CAAC;gBAC7D,WAAW,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC;gBACjD,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC;aAC3E,CAAC,CAAC;SACN,CAAC,CAAC;IACL,CAAC;CACF;AA7RD,8BA6RC","sourcesContent":["import { AssetService } from '../assets/service';\nimport { createBlockchain, type Blockchain } from '../blockchain/handle';\nimport { internalsOf, type HandleInternals } from '../blockchain/internal';\nimport { readEnvChains } from '../config/env';\nimport { assertNoCycle, isPlainObject, mergeScopes } from '../config/merge';\nimport { resolveSelection } from '../config/resolve';\nimport type {\n AioOptions,\n EffectiveOptions,\n HandleConfig,\n HandleOptions,\n ResolvedSelection,\n ScopeOptions,\n} from '../config/types';\nimport type { ChainDriver } from '../driver/types';\nimport { ConfigError } from '../errors/error';\nimport { EventBus } from '../events/bus';\nimport { createLogger } from '../events/logger';\nimport type { AioEvent, AioEventName } from '../events/types';\nimport {\n OperationEngine,\n errorCode,\n withLifecycleDefaults,\n type OperationTarget,\n type ReadTarget,\n} from '../lifecycle/engine';\nimport { Monitor, type RecoveryReport, type WorkerOptions } from '../lifecycle/monitor';\nimport { loadObservations } from '../lifecycle/observations';\nimport { toView, type OperationView } from '../lifecycle/views';\nimport type { ChainId } from '../model/ids';\nimport { SequenceCoordinator } from '../ordering/sequence';\nimport {\n applyPlugin,\n cloneCatalogs,\n createCatalogs,\n type Catalogs,\n type Plugin,\n} from '../registry/plugin';\nimport { SigningOrchestrator } from '../signing/orchestrator';\nimport { resolveWallet, type ResolvedWallet } from '../signing/wallet';\nimport { formatGuard } from '../store/format';\nimport { createMemoryStores } from '../store/memory';\nimport type { OperationRecord, OperationState, Stores } from '../store/types';\nimport { randomId } from '../util/bytes';\nimport { systemClock, type Clock } from '../util/clock';\nimport { builtinPlugins } from './builtins';\nimport {\n bindContainer,\n closedError,\n containerOf,\n type ContainerInternals,\n type RootRuntime,\n} from './internals';\nimport { DriverPool, type PooledDriver } from './pool';\n\nconst NAMESPACE = /^[A-Za-z0-9._-]{1,64}$/;\n\n/**\n * The signal a worker loop, pass or recovery runs under: the caller's, if any, and the\n * root's `closing`, which `close()` aborts. A closed container starts no new work: it\n * stops claiming Operations from a shared store (holding each for a lease) and no longer\n * keeps the process alive.\n */\nfunction workerSignal(\n runtime: RootRuntime,\n signal: AbortSignal | undefined,\n): AbortSignal {\n if (runtime.closed) throw closedError();\n return signal\n ? AbortSignal.any([signal, runtime.closing.signal])\n : runtime.closing.signal;\n}\n\n/** How long `close()` waits for one native client's `close` before moving on. */\nexport const NATIVE_CLOSE_TIMEOUT_MS = 5_000;\n\n/** Runs `close`, but gives up waiting after `ms` of `clock` time (the close keeps running). */\nasync function closeWithin(\n close: () => unknown,\n clock: Clock,\n ms: number,\n): Promise<'closed' | 'timeout'> {\n const timer = new AbortController();\n try {\n return await Promise.race([\n Promise.resolve()\n .then(close)\n .then(() => 'closed' as const),\n clock.sleep(ms, timer.signal).then(() => 'timeout' as const),\n ]);\n } finally {\n timer.abort();\n }\n}\n\ninterface ScopeInit {\n readonly parent: CryptoAio;\n readonly overrides: ScopeOptions;\n}\n\n/**\n * Set by `scope()` for the one synchronous constructor call it makes, so a child container\n * needs no constructor parameter in the public API.\n */\nlet pendingScope: ScopeInit | undefined;\n\n/**\n * Deep-clones plain objects/arrays into a frozen copy so a later mutation of the caller's\n * own input can never reach a layer already captured by a container. Class instances\n * (Signer, Secret, ...) are referenced, not cloned — they're already immutable.\n */\nfunction cloneFrozen<T>(value: T, ancestors: Set<object> = new Set()): T {\n if (!Array.isArray(value) && !isPlainObject(value)) return value;\n assertNoCycle(value, ancestors);\n ancestors.add(value);\n try {\n if (Array.isArray(value)) {\n return Object.freeze(\n value.map((item: unknown) => cloneFrozen(item, ancestors)),\n ) as T;\n }\n const out: Record<string, unknown> = {};\n for (const [key, v] of Object.entries(value)) out[key] = cloneFrozen(v, ancestors);\n return Object.freeze(out) as T;\n } finally {\n ancestors.delete(value);\n }\n}\n\n/** `chains`/`providers`/`wallets`/`signers`/`hooks`/`lifecycle` are all cloned and\n * deep-frozen at construction, so mutating the caller's options object afterwards never\n * affects handles already built from this layer. For `signers`, only the map OBJECT is\n * cloned (a fresh, frozen copy so adding/replacing a key on the caller's own map can't reach\n * an existing layer) — the `Signer` values it holds are opaque and always taken by reference,\n * never cloned or frozen, even a plain-object signer (`Signer` is an interface), so it keeps\n * its identity and its own mutable state. */\nfunction scopePart(options: ScopeOptions): ScopeOptions {\n const { chains, providers, signers, wallets, hooks, lifecycle } = options;\n return {\n ...(chains ? { chains: cloneFrozen(chains) } : {}),\n ...(providers ? { providers: cloneFrozen(providers) } : {}),\n ...(signers ? { signers: Object.freeze({ ...signers }) } : {}),\n ...(wallets ? { wallets: cloneFrozen(wallets) } : {}),\n ...(hooks ? { hooks: cloneFrozen(hooks) } : {}),\n ...(lifecycle ? { lifecycle: cloneFrozen(lifecycle) } : {}),\n };\n}\n\nconst checkedStores = new WeakMap<RootRuntime, Stores>();\n\n/**\n * The stores as the engine, the workers and `aio.operations` use them: Operation records\n * pass the format guard, so none is ever read in a format this version does not know.\n */\nfunction storesOf(runtime: RootRuntime): Stores {\n let stores = checkedStores.get(runtime);\n if (!stores) {\n stores = {\n ...runtime.stores,\n operations: formatGuard(runtime.stores.operations, runtime.log.child('store')),\n };\n checkedStores.set(runtime, stores);\n }\n return stores;\n}\n\nfunction createEngine(\n runtime: RootRuntime,\n effective: () => EffectiveOptions,\n): OperationEngine {\n const lifecycle = () => withLifecycleDefaults(effective().lifecycle);\n const { leaseMs, leaseWaitMs } = lifecycle();\n const log = runtime.log.child('lifecycle');\n return new OperationEngine({\n namespace: runtime.namespace,\n stores: storesOf(runtime),\n events: runtime.events,\n clock: runtime.clock,\n log,\n orchestrator: new SigningOrchestrator({\n schemes: () => runtime.catalogs.schemes,\n events: runtime.events,\n clock: runtime.clock,\n hooks: () => effective().hooks,\n }),\n sequences: new SequenceCoordinator({\n locks: runtime.stores.locks,\n sequences: runtime.stores.sequences,\n clock: runtime.clock,\n owner: runtime.owner,\n leaseMs,\n acquireTimeoutMs: leaseWaitMs,\n // The code only: a store's error message may carry detail that logs must not.\n onReleaseError: (error) =>\n log.warn('lease release failed', { code: errorCode(error) }),\n }),\n lifecycle,\n });\n}\n\n/**\n * The signer-free read target of a stored Operation, for every check,\n * worker pass and recovery read: its chain, network and library over its own named\n * providers first, then the current defaults when those no longer resolve (inline configs\n * are recorded by hash only and cannot be rebuilt). No wallet or signer is selected, not\n * even a chain default one, so a rotated signer, a removed wallet or a hung custody\n * backend never stops monitoring.\n */\nasync function readTarget(\n container: CryptoAio,\n record: OperationRecord,\n): Promise<ReadTarget> {\n const internals = containerOf(container);\n const { runtime } = internals;\n const { chain, network, library } = record.context;\n const effective = internals.effective();\n const { wallet: _wallet, signer: _signer, ...defaults } = effective.chains[chain] ?? {};\n const signerFree = { ...effective, chains: { ...effective.chains, [chain]: defaults } };\n const select = (provider?: readonly string[]) =>\n resolveSelection({\n handle: { chain, network, library, ...(provider ? { provider } : {}) },\n effective: signerFree,\n catalogs: runtime.catalogs,\n log: runtime.log,\n });\n const named = record.context.providers.filter((name) => !name.startsWith('inline:'));\n let selection: ResolvedSelection;\n try {\n selection = select(named.length > 0 ? named : undefined);\n } catch (error) {\n // Only a config that no longer resolves (e.g. a renamed provider) falls back.\n if (!(error instanceof ConfigError)) throw error;\n selection = select();\n }\n if (runtime.closed) throw closedError();\n return { selection, pooled: await runtime.pool.get(selection) };\n}\n\n/**\n * The wallets the monitor resolved for its writes, cached per container (one public-key\n * read per wallet selection, not one per pass) and bounded by `lifecycle.signTimeoutMs`. A\n * failed resolution is not kept. The cache is dropped when the config changes: a container's\n * layers are frozen, so only a plugin (`use()`, new catalogs and env layer) changes it.\n */\nfunction walletCache(\n runtime: RootRuntime,\n internals: () => ContainerInternals,\n): (selection: ResolvedSelection, driver: ChainDriver) => Promise<ResolvedWallet> {\n let catalogs: Catalogs = runtime.catalogs;\n const wallets = new Map<string, Promise<ResolvedWallet>>();\n return (selection, driver) => {\n if (runtime.catalogs !== catalogs) {\n catalogs = runtime.catalogs;\n wallets.clear();\n }\n const key = selection.configHash;\n const cached = wallets.get(key);\n if (cached) return cached;\n const { effective, signerDeadline } = internals();\n const resolving = resolveWallet(\n selection,\n driver,\n effective().signers,\n catalogs.schemes,\n signerDeadline(),\n ).catch((error: unknown) => {\n if (wallets.get(key) === resolving) wallets.delete(key);\n throw error;\n });\n wallets.set(key, resolving);\n return resolving;\n };\n}\n\n/**\n * The wallet-bound target of a stored Operation, resolved lazily and only for the\n * writes that need one: the all-rejected verdict, nonce reconciliation and recovery's\n * resend. None of them signs, and their address lease is keyed on the Operation itself.\n * Its frozen context (chain, network, library, wallet, signer) is rebuilt against the\n * container's current config with its own named providers first; when that no longer\n * resolves (a renamed provider, a rotated signer), the wallet alone over the current\n * defaults, with neither the recorded signer nor the providers: the wallet's current\n * signer, public key or address then stands for it (a watch-only wallet is enough). The\n * engine checks the resolved wallet still owns the Operation before using it.\n */\nasync function operationTarget(\n container: CryptoAio,\n runtime: RootRuntime,\n record: OperationRecord,\n wallets: (selection: ResolvedSelection, driver: ChainDriver) => Promise<ResolvedWallet>,\n): Promise<OperationTarget> {\n const { chain, network, library, wallet, signer, providers } = record.context;\n const base = { chain, network, library, wallet } as HandleConfig<ChainId>;\n const named = providers.filter((name) => !name.startsWith('inline:'));\n let handle: Blockchain<ChainId>;\n try {\n handle = container.blockchain({\n ...base,\n ...(signer !== undefined ? { signer } : {}),\n ...(named.length > 0 ? { provider: named } : {}),\n });\n } catch (error) {\n if (!(error instanceof ConfigError)) throw error;\n handle = container.blockchain(base);\n }\n const internals = internalsOf(handle);\n const pooled = await internals.pooled();\n return {\n selection: internals.selection,\n pooled,\n wallet: await wallets(internals.selection, pooled.driver),\n assets: runtime.assets,\n };\n}\n\n/** Which Operations `aio.operations.list()` returns: every given field must match. */\nexport interface OperationsFilter {\n readonly states?: readonly OperationState[];\n readonly chain?: string;\n readonly network?: string;\n readonly limit?: number;\n}\n\n/** `aio.operations`: read this namespace's Operations and recover them at startup. */\nexport interface OperationsApi {\n get(id: string): Promise<OperationView | null>;\n /** In creation order. */\n list(filter?: OperationsFilter): Promise<OperationView[]>;\n /** Startup recovery for this namespace (see RecoveryReport); it never signs. */\n recover(options?: { readonly signal?: AbortSignal }): Promise<RecoveryReport>;\n}\n\n/** `aio.monitor`: the worker passes that check and finish every live Operation. */\nexport interface MonitorApi {\n /** Runs worker passes until `signal` aborts; any number of workers may run. */\n start(options?: WorkerOptions): Promise<void>;\n /** One worker pass; resolves to the number of Operations it claimed. */\n runOnce(options?: WorkerOptions): Promise<number>;\n}\n\n/**\n * Dependency container: stores, signers, wallets, hooks, plugins and a shared driver pool.\n * Separate `new CryptoAio()` instances are fully isolated (use one per tenant).\n */\nexport class CryptoAio {\n readonly namespace: string;\n\n constructor(options: AioOptions = {}) {\n const scope = pendingScope;\n pendingScope = undefined;\n if (scope) {\n const parent = containerOf(scope.parent);\n this.namespace = parent.runtime.namespace;\n this.#bind(parent.runtime, [...parent.layers, scopePart(scope.overrides)], false);\n return;\n }\n const namespace = options.namespace ?? 'default';\n if (!NAMESPACE.test(namespace))\n throw new ConfigError(\n 'CONFIG_INVALID',\n 'invalid namespace: use 1 to 64 letters, digits, dots, underscores or hyphens',\n );\n const clock = options.clock ?? systemClock;\n const log = options.logger ?? createLogger();\n const catalogs = createCatalogs();\n for (const plugin of [...builtinPlugins(), ...(options.plugins ?? [])])\n applyPlugin(catalogs, plugin);\n for (const asset of options.assets ?? []) {\n catalogs.chains.network(asset.chain, asset.network);\n catalogs.assets.register(asset);\n }\n const env = options.env === false ? {} : (options.env ?? process.env);\n const events = new EventBus(clock, log);\n // eslint-disable-next-line prefer-const -- closures below read it after assignment\n let runtime: RootRuntime;\n const pool = new DriverPool({\n catalogs: () => runtime.catalogs,\n clock,\n events,\n log,\n transport: () => runtime.transport,\n });\n runtime = {\n namespace,\n catalogs,\n envLayer: {\n chains: readEnvChains(\n env,\n catalogs.chains.list().map((c) => c.id),\n options.profile,\n ),\n },\n env,\n ...(options.profile !== undefined ? { profile: options.profile } : {}),\n clock,\n log,\n events,\n stores: {\n ...createMemoryStores(clock),\n ...(Object.fromEntries(\n Object.entries(options.stores ?? {}).filter(([, store]) => store !== undefined),\n ) as Partial<Stores>),\n },\n pool,\n assets: new AssetService(() => runtime.catalogs),\n transport: options.transport ?? {},\n owner: randomId('aio'),\n closed: false,\n closing: new AbortController(),\n natives: new Set(),\n };\n this.namespace = namespace;\n this.#bind(runtime, [scopePart(options)], true);\n }\n\n /**\n * Child container: inherits config, pool, stores and namespace; overrides merge on top.\n * Not a tenant boundary — a scope shares its root's pool and stores. Use a separate\n * `new CryptoAio({ namespace })` when isolation between tenants is required.\n */\n scope(overrides: ScopeOptions): CryptoAio {\n pendingScope = { parent: this, overrides };\n try {\n return new CryptoAio();\n } finally {\n pendingScope = undefined;\n }\n }\n\n blockchain<C extends ChainId>(config: HandleConfig<C>): Blockchain<C> {\n const internals = containerOf(this);\n const { runtime } = internals;\n const selection = resolveSelection({\n handle: config as HandleOptions,\n effective: internals.effective(),\n catalogs: runtime.catalogs,\n log: runtime.log,\n });\n let pooled: Promise<PooledDriver> | undefined;\n let wallet: Promise<ResolvedWallet> | undefined;\n const handle: HandleInternals = {\n container: this,\n selection,\n nativeClients: new Map(),\n assertOpen: () => {\n if (runtime.closed) throw closedError();\n },\n registerNative: (native) => {\n if (runtime.closed) throw closedError();\n if (native.close) runtime.natives.add(() => native.close?.());\n },\n // A closed root refuses work even through a pooled driver this handle holds.\n pooled: () => {\n if (runtime.closed) return Promise.reject(closedError());\n pooled ??= runtime.pool.get(selection).catch((error: unknown) => {\n pooled = undefined;\n throw error;\n });\n return pooled;\n },\n wallet: () => {\n if (runtime.closed) return Promise.reject(closedError());\n wallet ??= handle\n .pooled()\n .then(({ driver }) =>\n resolveWallet(\n selection,\n driver,\n internals.effective().signers,\n runtime.catalogs.schemes,\n internals.signerDeadline(),\n ),\n )\n .catch((error: unknown) => {\n wallet = undefined;\n throw error;\n });\n return wallet;\n },\n };\n return createBlockchain<C>(handle);\n }\n\n /** Registers a plugin on this root container (copy-on-write catalogs). */\n use(plugin: Plugin): this {\n const internals = containerOf(this);\n if (!internals.isRoot)\n throw new ConfigError(\n 'CONFIG_INVALID',\n 'plugins can only be added to a root container',\n );\n const { runtime } = internals;\n const next = cloneCatalogs(runtime.catalogs);\n applyPlugin(next, plugin);\n runtime.catalogs = next;\n runtime.envLayer = {\n chains: readEnvChains(\n runtime.env,\n next.chains.list().map((c) => c.id),\n runtime.profile,\n ),\n };\n return this;\n }\n\n on<E extends AioEventName>(type: E, handler: (event: AioEvent<E>) => void): () => void {\n return containerOf(this).runtime.events.on(type, handler);\n }\n\n onAny(handler: (event: AioEvent) => void): () => void {\n return containerOf(this).runtime.events.onAny(handler);\n }\n\n /** Stored Operations of this namespace, as views, and startup recovery. */\n get operations(): OperationsApi {\n const internals = containerOf(this);\n const store = storesOf(internals.runtime).operations;\n const namespace = internals.runtime.namespace;\n const view = async (record: OperationRecord) =>\n toView(record, await loadObservations(store, record));\n return {\n get: async (id) => {\n const record = await store.get(namespace, id);\n return record ? view(record) : null;\n },\n list: async (filter = {}) =>\n Promise.all(\n (\n await store.list({\n namespace,\n ...(filter.states ? { states: filter.states } : {}),\n ...(filter.chain ? { chain: filter.chain } : {}),\n ...(filter.network ? { network: filter.network } : {}),\n ...(filter.limit !== undefined ? { limit: filter.limit } : {}),\n })\n ).map(view),\n ),\n recover: async (options = {}) =>\n internals.monitor().recover({\n ...options,\n signal: workerSignal(internals.runtime, options.signal),\n }),\n };\n }\n\n /** Background workers that check due Operations without anyone waiting on them. */\n get monitor(): MonitorApi {\n const internals = containerOf(this);\n return {\n start: async (options = {}) =>\n internals.monitor().start({\n ...options,\n signal: workerSignal(internals.runtime, options.signal),\n }),\n runOnce: async (options = {}) =>\n internals.monitor().runOnce({\n workerId: options.workerId ?? internals.runtime.owner,\n ...(options.batch !== undefined ? { batch: options.batch } : {}),\n signal: workerSignal(internals.runtime, options.signal),\n }),\n };\n }\n\n /**\n * Closes the root container: runs the `close` of every native client that\n * `crypto-aio/native` handed out (a failing one is logged by code and skipped), then\n * closes the pooled drivers. Its handles and `native()` then fail with\n * `INVALID_TRANSITION`. A scope's `close()` does nothing; scopes share their root's pool.\n */\n async close(): Promise<void> {\n const internals = containerOf(this);\n if (!internals.isRoot) return;\n const { runtime } = internals;\n runtime.closed = true;\n // Every worker loop, pass and recovery stops at its next check, and its sleeps end.\n runtime.closing.abort();\n const natives = [...runtime.natives];\n runtime.natives.clear();\n await Promise.all(\n natives.map(async (close) => {\n try {\n const outcome = await closeWithin(\n close,\n runtime.clock,\n NATIVE_CLOSE_TIMEOUT_MS,\n );\n if (outcome === 'timeout') {\n runtime.log.warn('native client close timed out', {\n timeoutMs: NATIVE_CLOSE_TIMEOUT_MS,\n });\n }\n } catch (error) {\n runtime.log.warn('native client close failed', { code: errorCode(error) });\n }\n }),\n );\n await runtime.pool.close();\n }\n\n #bind(runtime: RootRuntime, layers: readonly ScopeOptions[], isRoot: boolean): void {\n const effective = () => mergeScopes([runtime.envLayer, ...layers]);\n let engine: OperationEngine | undefined;\n let monitor: Monitor | undefined;\n const getEngine = () => (engine ??= createEngine(runtime, effective));\n const wallets = walletCache(runtime, () => containerOf(this));\n bindContainer(this, {\n runtime,\n layers,\n isRoot,\n effective,\n signerDeadline: () => ({\n clock: runtime.clock,\n timeoutMs: withLifecycleDefaults(effective().lifecycle).signTimeoutMs,\n }),\n engine: getEngine,\n monitor: () =>\n (monitor ??= new Monitor({\n engine: getEngine(),\n stores: storesOf(runtime),\n events: runtime.events,\n clock: runtime.clock,\n log: runtime.log.child('monitor'),\n namespace: runtime.namespace,\n lifecycle: () => withLifecycleDefaults(effective().lifecycle),\n resolveRead: (record) => readTarget(this, record),\n resolveTarget: (record) => operationTarget(this, runtime, record, wallets),\n })),\n });\n }\n}\n"]}
|
|
@@ -70,6 +70,18 @@ class DriverPool {
|
|
|
70
70
|
log: this.deps.log.child(selection.chain.id),
|
|
71
71
|
options: selection.options,
|
|
72
72
|
});
|
|
73
|
+
// The handle promises what its selection lists (`supports()`), so the driver must
|
|
74
|
+
// implement each capability the manifest and the network grant, and order Attempts
|
|
75
|
+
// as the chain says. A plugin whose declarations disagree is refused here, before any
|
|
76
|
+
// call, instead of failing later at a port the driver lacks.
|
|
77
|
+
const missing = [...selection.capabilities].filter((c) => !driver.capabilities.has(c));
|
|
78
|
+
if (missing.length > 0 || driver.ordering !== selection.chain.ordering) {
|
|
79
|
+
await driver.close?.();
|
|
80
|
+
const target = `${selection.chain.id}:${selection.network.id}`;
|
|
81
|
+
throw new error_1.ConfigError('CONFIG_INVALID', missing.length > 0
|
|
82
|
+
? `the ${selection.library} driver for ${target} does not implement ${missing.sort().join(', ')}, which its manifest and network declare`
|
|
83
|
+
: `the ${selection.library} driver for ${target} orders by '${driver.ordering}', but the chain says '${selection.chain.ordering}'`, { details: { missing: missing.sort(), ordering: driver.ordering } });
|
|
84
|
+
}
|
|
73
85
|
return { driver, transport, ...(indexer ? { indexer } : {}) };
|
|
74
86
|
}
|
|
75
87
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool.js","sourceRoot":"","sources":["../../../src/core/container/pool.ts"],"names":[],"mappings":";;;AAEA,
|
|
1
|
+
{"version":3,"file":"pool.js","sourceRoot":"","sources":["../../../src/core/container/pool.ts"],"names":[],"mappings":";;;AAEA,2CAA0D;AAI1D,gEAA4D;AAE5D,yCAAyC;AAiBzC,kGAAkG;AAClG,MAAa,UAAU;IAIQ;IAHpB,QAAQ,GAAG,IAAI,GAAG,EAAiC,CAAC;IAC7D,OAAO,GAAG,KAAK,CAAC;IAEhB,YAA6B,IAAoB;QAApB,SAAI,GAAJ,IAAI,CAAgB;IAAG,CAAC;IAErD,GAAG,CAAC,SAA4B;QAC9B,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,kBAAU,CAAC,oBAAoB,EAAE,uBAAuB,CAAC,CAC9D,CAAC;QACJ,CAAC;QACD,IAAI,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QACjD,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,C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AC,CAAC,EAAE,CAAC,EAAE,CAAC;IAChE,CAAC;CACF;AAlGD,gCAkGC","sourcesContent":["import type { ResolvedSelection } from '../config/types';\nimport type { ChainDriver } from '../driver/types';\nimport { ConfigError, StateError } from '../errors/error';\nimport type { EventBus } from '../events/bus';\nimport type { Logger } from '../events/logger';\nimport type { Catalogs } from '../registry/plugin';\nimport { HttpTransport } from '../transport/http-transport';\nimport type { Transport, TransportOptions } from '../transport/types';\nimport { randomId } from '../util/bytes';\nimport type { Clock } from '../util/clock';\n\nexport interface PooledDriver {\n readonly driver: ChainDriver;\n readonly transport: Transport;\n readonly indexer?: Transport;\n}\n\nexport interface DriverPoolDeps {\n readonly catalogs: () => Catalogs;\n readonly clock: Clock;\n readonly events: EventBus;\n readonly log: Logger;\n readonly transport: () => TransportOptions;\n}\n\n/** Shares one driver + transport per (chain, network, library, provider credentials, options). */\nexport class DriverPool {\n readonly #entries = new Map<string, Promise<PooledDriver>>();\n #closed = false;\n\n constructor(private readonly deps: DriverPoolDeps) {}\n\n get(selection: ResolvedSelection): Promise<PooledDriver> {\n if (this.#closed) {\n return Promise.reject(\n new StateError('INVALID_TRANSITION', 'driver pool is closed'),\n );\n }\n let entry = this.#entries.get(selection.poolKey);\n if (!entry) {\n entry = this.#create(selection);\n this.#entries.set(selection.poolKey, entry);\n entry.catch(() => {\n // Only evict THIS entry: a concurrent get() may already have replaced it (e.g. a\n // retry after this one failed), and that newer entry must survive.\n if (this.#entries.get(selection.poolKey) === entry) {\n this.#entries.delete(selection.poolKey);\n }\n });\n }\n return entry;\n }\n\n async close(): Promise<void> {\n this.#closed = true;\n const entries = [...this.#entries.values()];\n this.#entries.clear();\n await Promise.allSettled(\n entries.map(async (entry) => (await entry).driver.close?.()),\n );\n }\n\n async #create(selection: ResolvedSelection): Promise<PooledDriver> {\n const factory = await this.deps.catalogs().adapters.load(selection.manifest);\n const root = this.deps.transport();\n // First match wins: the user's per-chain config, the user's root transport option,\n // the plugin network's own, then (left unset) the transport's built-in default.\n const maxLagBlocks =\n selection.maxLagBlocks ?? root.maxLagBlocks ?? selection.network.maxLagBlocks;\n const options: TransportOptions = {\n ...root,\n ...(maxLagBlocks !== undefined ? { maxLagBlocks } : {}),\n };\n // `poolKey` fingerprints revealed provider URLs and must stay an in-memory map key\n // only (never persisted, emitted or logged); the transport's public id — which flows\n // into every rpc.*/provider.* event — is generated independently of it.\n const id = randomId('tr');\n const shared = {\n clock: this.deps.clock,\n events: this.deps.events,\n log: this.deps.log.child('transport'),\n options,\n };\n const transport = new HttpTransport(\n selection.providers.flatMap((p) => p.endpoints),\n { ...shared, id },\n );\n const indexer =\n selection.indexers.length > 0\n ? new HttpTransport(\n selection.indexers.flatMap((p) => p.endpoints),\n { ...shared, id: `${id}_idx` },\n )\n : undefined;\n const driver = await factory.create({\n chain: selection.chain,\n network: selection.network,\n library: selection.library,\n transport,\n ...(indexer ? { indexer } : {}),\n clock: this.deps.clock,\n log: this.deps.log.child(selection.chain.id),\n options: selection.options,\n });\n // The handle promises what its selection lists (`supports()`), so the driver must\n // implement each capability the manifest and the network grant, and order Attempts\n // as the chain says. A plugin whose declarations disagree is refused here, before any\n // call, instead of failing later at a port the driver lacks.\n const missing = [...selection.capabilities].filter(\n (c) => !driver.capabilities.has(c),\n );\n if (missing.length > 0 || driver.ordering !== selection.chain.ordering) {\n await driver.close?.();\n const target = `${selection.chain.id}:${selection.network.id}`;\n throw new ConfigError(\n 'CONFIG_INVALID',\n missing.length > 0\n ? `the ${selection.library} driver for ${target} does not implement ${missing.sort().join(', ')}, which its manifest and network declare`\n : `the ${selection.library} driver for ${target} orders by '${driver.ordering}', but the chain says '${selection.chain.ordering}'`,\n { details: { missing: missing.sort(), ordering: driver.ordering } },\n );\n }\n return { driver, transport, ...(indexer ? { indexer } : {}) };\n }\n}\n"]}
|