@arkade-os/sdk 0.5.4 → 0.5.6
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 +103 -17
- package/dist/adapters/expo.cjs +7 -6
- package/dist/adapters/expo.d.cts +4 -3
- package/dist/adapters/expo.d.ts +4 -3
- package/dist/adapters/expo.js +4 -3
- package/dist/{asyncStorageTaskQueue-DTBa8EH7.d.cts → asyncStorageTaskQueue-Bh2n0msM.d.cts} +2 -2
- package/dist/{asyncStorageTaskQueue-DHMIxY04.d.ts → asyncStorageTaskQueue-CpkstKZ5.d.ts} +2 -2
- package/dist/base-C-Y5t_0F.d.cts +359 -0
- package/dist/base-C-Y5t_0F.d.ts +359 -0
- package/dist/{chunk-6CUP6ZIF.js → chunk-47Z4LEIW.js} +17 -841
- package/dist/chunk-47Z4LEIW.js.map +1 -0
- package/dist/{chunk-DNITZVNG.cjs → chunk-4X67IB2V.cjs} +18 -17
- package/dist/chunk-4X67IB2V.cjs.map +1 -0
- package/dist/{chunk-BTRCN4JJ.js → chunk-C7NY6WSA.js} +64 -4
- package/dist/chunk-C7NY6WSA.js.map +1 -0
- package/dist/{chunk-TUOLZBNC.js → chunk-DJYX73W2.js} +5 -4
- package/dist/chunk-DJYX73W2.js.map +1 -0
- package/dist/chunk-DNFTHG73.js +829 -0
- package/dist/chunk-DNFTHG73.js.map +1 -0
- package/dist/chunk-FDJ734CH.js +882 -0
- package/dist/chunk-FDJ734CH.js.map +1 -0
- package/dist/chunk-FLPWNMX3.cjs +930 -0
- package/dist/chunk-FLPWNMX3.cjs.map +1 -0
- package/dist/{chunk-WXNSISXK.cjs → chunk-HKEPJBTY.cjs} +79 -18
- package/dist/chunk-HKEPJBTY.cjs.map +1 -0
- package/dist/chunk-JFJNB7ZH.cjs +884 -0
- package/dist/chunk-JFJNB7ZH.cjs.map +1 -0
- package/dist/{chunk-GHUUT54D.cjs → chunk-LZAINCGU.cjs} +89 -933
- package/dist/chunk-LZAINCGU.cjs.map +1 -0
- package/dist/{chunk-E6OOJEHL.cjs → chunk-NDQ4LB4X.cjs} +60 -934
- package/dist/chunk-NDQ4LB4X.cjs.map +1 -0
- package/dist/{chunk-AG4TFD6F.js → chunk-QTMK34TP.js} +79 -884
- package/dist/chunk-QTMK34TP.js.map +1 -0
- package/dist/chunk-V3ZLL5VY.js +380 -0
- package/dist/chunk-V3ZLL5VY.js.map +1 -0
- package/dist/{chunk-MWVAWFX6.js → chunk-VWW2ZBPI.js} +4 -4
- package/dist/{chunk-MWVAWFX6.js.map → chunk-VWW2ZBPI.js.map} +1 -1
- package/dist/chunk-X6ZI53DZ.cjs +383 -0
- package/dist/chunk-X6ZI53DZ.cjs.map +1 -0
- package/dist/{chunk-F3FAE7VJ.cjs → chunk-Y3CDDPWI.cjs} +3138 -1764
- package/dist/chunk-Y3CDDPWI.cjs.map +1 -0
- package/dist/{chunk-ZJHLLDBP.js → chunk-YKT4NAQG.js} +2653 -1295
- package/dist/chunk-YKT4NAQG.js.map +1 -0
- package/dist/{chunk-B6VNKGIH.cjs → chunk-YS76JSGP.cjs} +10 -10
- package/dist/{chunk-B6VNKGIH.cjs.map → chunk-YS76JSGP.cjs.map} +1 -1
- package/dist/compiler.cjs +50 -0
- package/dist/compiler.cjs.map +1 -0
- package/dist/compiler.d.cts +38 -0
- package/dist/compiler.d.ts +38 -0
- package/dist/compiler.js +47 -0
- package/dist/compiler.js.map +1 -0
- package/dist/contracts/handlers/index.cjs +11 -9
- package/dist/contracts/handlers/index.d.cts +6 -4
- package/dist/contracts/handlers/index.d.ts +6 -4
- package/dist/contracts/handlers/index.js +4 -2
- package/dist/{delegate-xrSBNybC.d.ts → delegate-gGkUnYpi.d.cts} +1 -1
- package/dist/{delegate-f4_t864Z.d.cts → delegate-iyDum4fw.d.ts} +1 -1
- package/dist/{index-BJDz15ms.d.ts → index-2wKMrT0a.d.ts} +5 -270
- package/dist/{index-BjiVGtp8.d.cts → index-46g577Ka.d.cts} +5 -270
- package/dist/{index-DRwe0UDN.d.cts → index-C66rjxz2.d.ts} +1603 -1721
- package/dist/{index-DRwe0UDN.d.ts → index-Dqk07NwJ.d.cts} +1603 -1721
- package/dist/index.cjs +457 -378
- package/dist/index.d.cts +640 -385
- package/dist/index.d.ts +640 -385
- package/dist/index.js +7 -4
- package/dist/{wallet-jVBDQl6R.d.cts → keyringDescriptorProvider-DiBM4GmB.d.ts} +417 -366
- package/dist/{wallet-Oc3Wd5gv.d.ts → keyringDescriptorProvider-DnaLUC7v.d.cts} +417 -366
- package/dist/program-BARSNg3X.d.ts +286 -0
- package/dist/program-znrWkxE4.d.cts +286 -0
- package/dist/repositories/realm/index.cjs +71 -51
- package/dist/repositories/realm/index.cjs.map +1 -1
- package/dist/repositories/realm/index.d.cts +20 -9
- package/dist/repositories/realm/index.d.ts +20 -9
- package/dist/repositories/realm/index.js +42 -23
- package/dist/repositories/realm/index.js.map +1 -1
- package/dist/repositories/sqlite/index.cjs +81 -56
- package/dist/repositories/sqlite/index.cjs.map +1 -1
- package/dist/repositories/sqlite/index.d.cts +17 -8
- package/dist/repositories/sqlite/index.d.ts +17 -8
- package/dist/repositories/sqlite/index.js +55 -31
- package/dist/repositories/sqlite/index.js.map +1 -1
- package/dist/{taskRunner-CDlNeth0.d.ts → taskRunner-BM6IAKlS.d.ts} +2 -2
- package/dist/{taskRunner-BPPU-YHG.d.cts → taskRunner-BmDIZiSl.d.cts} +2 -2
- package/dist/wallet/expo/background.cjs +17 -14
- package/dist/wallet/expo/background.cjs.map +1 -1
- package/dist/wallet/expo/background.d.cts +5 -4
- package/dist/wallet/expo/background.d.ts +5 -4
- package/dist/wallet/expo/background.js +9 -6
- package/dist/wallet/expo/background.js.map +1 -1
- package/dist/wallet/expo/index.cjs +29 -16
- package/dist/wallet/expo/index.cjs.map +1 -1
- package/dist/wallet/expo/index.d.cts +12 -7
- package/dist/wallet/expo/index.d.ts +12 -7
- package/dist/wallet/expo/index.js +19 -6
- package/dist/wallet/expo/index.js.map +1 -1
- package/dist/worker/expo/index.cjs +12 -9
- package/dist/worker/expo/index.cjs.map +1 -1
- package/dist/worker/expo/index.d.cts +6 -5
- package/dist/worker/expo/index.d.ts +6 -5
- package/dist/worker/expo/index.js +8 -5
- package/dist/worker/expo/index.js.map +1 -1
- package/package.json +16 -1
- package/dist/chunk-6CUP6ZIF.js.map +0 -1
- package/dist/chunk-AG4TFD6F.js.map +0 -1
- package/dist/chunk-BTRCN4JJ.js.map +0 -1
- package/dist/chunk-DNITZVNG.cjs.map +0 -1
- package/dist/chunk-E6OOJEHL.cjs.map +0 -1
- package/dist/chunk-F3FAE7VJ.cjs.map +0 -1
- package/dist/chunk-GHUUT54D.cjs.map +0 -1
- package/dist/chunk-TUOLZBNC.js.map +0 -1
- package/dist/chunk-WXNSISXK.cjs.map +0 -1
- package/dist/chunk-ZJHLLDBP.js.map +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Bytes } from '@scure/btc-signer/utils.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { Transaction as Transaction$1 } from '@scure/btc-signer';
|
|
3
|
+
import { TransactionInput, TransactionOutput } from '@scure/btc-signer/psbt.js';
|
|
4
|
+
import { A as ArkAddress, T as TapLeafScript, E as EncodedVtxoScript, R as RelativeTimelock, V as VtxoScript } from './base-C-Y5t_0F.js';
|
|
4
5
|
import { TxOpts } from '@scure/btc-signer/transaction.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -159,6 +160,248 @@ interface DescriptorProvider {
|
|
|
159
160
|
signMessageWithDescriptor(descriptor: string, message: Uint8Array, type?: "schnorr" | "ecdsa"): Promise<Uint8Array>;
|
|
160
161
|
}
|
|
161
162
|
|
|
163
|
+
/**
|
|
164
|
+
* Off-chain source of previous transactions: ark, tree and checkpoint txs, as
|
|
165
|
+
* base64 PSBTs keyed by txid. Structurally satisfied by `IndexerProvider`.
|
|
166
|
+
*/
|
|
167
|
+
interface PrevTxSource {
|
|
168
|
+
getVirtualTxs(txids: string[]): Promise<{
|
|
169
|
+
txs: string[];
|
|
170
|
+
}>;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* On-chain source of previous transactions — boarding and commitment txs, which
|
|
174
|
+
* `getVirtualTxs` does not serve. Structurally satisfied by `OnchainProvider`.
|
|
175
|
+
*/
|
|
176
|
+
interface RawTxSource {
|
|
177
|
+
getRawTransaction(txid: string): Promise<Uint8Array>;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* A previous transaction could not be resolved, so the emulator would reject the
|
|
181
|
+
* submission with `missing prevout tx for input N`. Distinguishes "no source is
|
|
182
|
+
* wired up" from "the source did not have it" — the remedies differ.
|
|
183
|
+
*/
|
|
184
|
+
declare class PrevTxUnavailableError extends Error {
|
|
185
|
+
readonly txids: string[];
|
|
186
|
+
constructor(message: string, txids?: string[]);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Resolve raw wire-format bytes for each txid, batched and de-duplicated.
|
|
190
|
+
*
|
|
191
|
+
* Emulator v0.0.7+ requires the raw tx behind every input of a submitted ark tx
|
|
192
|
+
* or proof (`PrevArkTxField`) and of an onchain tx (`PrevoutTxField`).
|
|
193
|
+
* The value is a serialized `wire.MsgTx`, *not* a PSBT — `Transaction.toBytes()`
|
|
194
|
+
* with the default `(withScriptSig=false, withWitness=false)` is exactly the
|
|
195
|
+
* preimage the emulator hashes to check the tx against the outpoint.
|
|
196
|
+
*
|
|
197
|
+
* Off-chain txs are fetched in one batched call; anything the indexer does not
|
|
198
|
+
* serve (a commitment or boarding tx) falls through to `onchain` when supplied.
|
|
199
|
+
*/
|
|
200
|
+
declare function resolvePrevTxs(txids: string[], source: PrevTxSource, onchain?: RawTxSource): Promise<Map<string, Uint8Array>>;
|
|
201
|
+
/**
|
|
202
|
+
* Attach `PrevArkTxField` to every input of `tx` that does not already carry
|
|
203
|
+
* one, resolving the bytes for `txids[i]` — the coin input `i` ultimately
|
|
204
|
+
* spends.
|
|
205
|
+
*
|
|
206
|
+
* Inputs already carrying the field are skipped rather than overwritten: the
|
|
207
|
+
* emulator rejects an input with more than one field of the same type, so a
|
|
208
|
+
* caller-supplied value (`Utxo.sourceTx`) must win outright. Nothing is fetched
|
|
209
|
+
* when every input is already covered.
|
|
210
|
+
*/
|
|
211
|
+
declare function attachPrevArkTxs(tx: Transaction, txids: string[], source: PrevTxSource, onchain?: RawTxSource): Promise<void>;
|
|
212
|
+
/**
|
|
213
|
+
* Attach `PrevoutTxField` to every input of an onchain PSBT, reading each
|
|
214
|
+
* input's own outpoint — unlike an ark tx, an onchain tx spends its prevout
|
|
215
|
+
* directly, so the txid is in the PSBT already.
|
|
216
|
+
*/
|
|
217
|
+
declare function attachPrevoutTxs(tx: Transaction, source: RawTxSource): Promise<void>;
|
|
218
|
+
/**
|
|
219
|
+
* A coin a proof spends, carrying the raw previous tx the emulator needs
|
|
220
|
+
* to resolve its prevout pkScript.
|
|
221
|
+
*/
|
|
222
|
+
type WithPrevTx<T> = T & {
|
|
223
|
+
prevTx?: Uint8Array;
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Fill in `prevTx` on every coin a proof will spend, in one batched
|
|
227
|
+
* lookup. The proof's synthetic input 0 needs nothing — the emulator synthesises
|
|
228
|
+
* a one-output tx for it — so this covers exactly the coins, which land on proof
|
|
229
|
+
* inputs `1..n`.
|
|
230
|
+
*/
|
|
231
|
+
declare function withPrevTxs<T extends {
|
|
232
|
+
txid: string;
|
|
233
|
+
prevTx?: Uint8Array;
|
|
234
|
+
}>(coins: T[], source: PrevTxSource, onchain?: RawTxSource): Promise<T[]>;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* An input of a {@link Proof}: an output it proves ownership of. `prevTx` carries the raw wire
|
|
238
|
+
* bytes of the transaction that created it — required by emulator v0.0.7+ on
|
|
239
|
+
* every real input of a submitted proof. {@link Proof.create} is synchronous,
|
|
240
|
+
* so the bytes are supplied rather than fetched; `withPrevTxs` fills them in.
|
|
241
|
+
*/
|
|
242
|
+
type ProofInput = WithPrevTx<ExtendedCoin>;
|
|
243
|
+
/**
|
|
244
|
+
* A signed BIP322-style PSBT carrying a message. Its inputs are Bitcoin outputs,
|
|
245
|
+
* its signature proves the user controls them, and its message says what to do
|
|
246
|
+
* with them.
|
|
247
|
+
*
|
|
248
|
+
* A proof is a deliberately invalid PSBT, so it can never be broadcast. Signing
|
|
249
|
+
* a proof means signing the PSBT as a regular transaction.
|
|
250
|
+
*/
|
|
251
|
+
type Proof = Transaction;
|
|
252
|
+
/**
|
|
253
|
+
* Utilities for creating and inspecting {@link Proof}s.
|
|
254
|
+
*
|
|
255
|
+
* @see https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```typescript
|
|
259
|
+
* // Create an unsigned proof
|
|
260
|
+
* const proof = Proof.create(
|
|
261
|
+
* "Hello Bitcoin!",
|
|
262
|
+
* [input],
|
|
263
|
+
* [output]
|
|
264
|
+
* );
|
|
265
|
+
*
|
|
266
|
+
* // Sign the proof
|
|
267
|
+
* const signedProof = await identity.sign(proof);
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
declare namespace Proof {
|
|
271
|
+
/**
|
|
272
|
+
* Creates an unsigned {@link Proof}.
|
|
273
|
+
*
|
|
274
|
+
* This function constructs a special transaction that can be signed to prove
|
|
275
|
+
* ownership of onchain and virtual outputs. The proof includes the message to be
|
|
276
|
+
* signed and the inputs/outputs that demonstrate ownership.
|
|
277
|
+
*
|
|
278
|
+
* @param message - The message to be signed, either a raw string or a Message object
|
|
279
|
+
* @param ins - Array of transaction inputs to prove ownership of
|
|
280
|
+
* @param outputs - Optional array of transaction outputs
|
|
281
|
+
* @returns An unsigned proof
|
|
282
|
+
*/
|
|
283
|
+
function create(message: string | Message, ins: (TransactionInput | ProofInput)[], outputs?: TransactionOutput[]): Proof;
|
|
284
|
+
/**
|
|
285
|
+
* Compute the fee paid by a proof.
|
|
286
|
+
*
|
|
287
|
+
* @param proof - The proof
|
|
288
|
+
* @returns The fee in satoshis
|
|
289
|
+
*/
|
|
290
|
+
function fee(proof: Proof): number;
|
|
291
|
+
type RegisterMessage = {
|
|
292
|
+
type: "register";
|
|
293
|
+
onchain_output_indexes: number[];
|
|
294
|
+
valid_at: number;
|
|
295
|
+
expire_at: number;
|
|
296
|
+
cosigners_public_keys: string[];
|
|
297
|
+
};
|
|
298
|
+
type DeleteMessage = {
|
|
299
|
+
type: "delete";
|
|
300
|
+
expire_at: number;
|
|
301
|
+
};
|
|
302
|
+
type GetPendingTxMessage = {
|
|
303
|
+
type: "get-pending-tx";
|
|
304
|
+
expire_at: number;
|
|
305
|
+
};
|
|
306
|
+
type Message = RegisterMessage | DeleteMessage | GetPendingTxMessage;
|
|
307
|
+
/**
|
|
308
|
+
* Serialize a proof message to the canonical JSON string used for signing.
|
|
309
|
+
*
|
|
310
|
+
* @param message - Proof message payload
|
|
311
|
+
* @returns Canonical string form of the message
|
|
312
|
+
*/
|
|
313
|
+
function encodeMessage(message: Message): string;
|
|
314
|
+
}
|
|
315
|
+
/** @deprecated Use {@link ProofInput}. */
|
|
316
|
+
type IntentCoin = ProofInput;
|
|
317
|
+
/** @deprecated Use {@link Proof}. */
|
|
318
|
+
declare const Intent: typeof Proof;
|
|
319
|
+
/** @deprecated Use {@link Proof}. */
|
|
320
|
+
declare namespace Intent {
|
|
321
|
+
type Proof = Transaction;
|
|
322
|
+
type RegisterMessage = Proof.RegisterMessage;
|
|
323
|
+
type DeleteMessage = Proof.DeleteMessage;
|
|
324
|
+
type GetPendingTxMessage = Proof.GetPendingTxMessage;
|
|
325
|
+
type Message = Proof.Message;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Emulator REST client.
|
|
330
|
+
*
|
|
331
|
+
* The emulator is a signing service that executes Arkade scripts
|
|
332
|
+
* and co-signs transactions when the scripts pass validation.
|
|
333
|
+
*
|
|
334
|
+
* The read here goes through `baseFetch`, the SDK's shared fetch boundary, so
|
|
335
|
+
* it picks up whatever policy that boundary carries. The four submit calls
|
|
336
|
+
* deliberately do not: aborting a submit would not tell the caller whether the
|
|
337
|
+
* emulator signed, and none of them has a way to find out, so they stay on the
|
|
338
|
+
* global `fetch` with their transport-error type unchanged.
|
|
339
|
+
*/
|
|
340
|
+
|
|
341
|
+
interface EmulatorInfo {
|
|
342
|
+
signerPubkey: string;
|
|
343
|
+
}
|
|
344
|
+
interface EmulatorProvider {
|
|
345
|
+
getInfo(): Promise<EmulatorInfo>;
|
|
346
|
+
submitTx(arkTx: string, checkpointTxs: string[]): Promise<{
|
|
347
|
+
signedArkTx: string;
|
|
348
|
+
signedCheckpointTxs: string[];
|
|
349
|
+
}>;
|
|
350
|
+
/** Signs an intent proof whose covenants pass: a registration, or the delete withdrawing it. */
|
|
351
|
+
submitIntent(intent: {
|
|
352
|
+
proof: string;
|
|
353
|
+
message: Intent.RegisterMessage | Intent.DeleteMessage;
|
|
354
|
+
}): Promise<string>;
|
|
355
|
+
submitFinalization(intent: {
|
|
356
|
+
proof: string;
|
|
357
|
+
message: Proof.RegisterMessage;
|
|
358
|
+
}, forfeits: string[], connectorTree: ConnectorTreeNode[] | null, commitmentTx: string): Promise<{
|
|
359
|
+
signedForfeits: string[];
|
|
360
|
+
signedCommitmentTx?: string;
|
|
361
|
+
}>;
|
|
362
|
+
submitOnchainTx(tx: string): Promise<{
|
|
363
|
+
signedTx: string;
|
|
364
|
+
}>;
|
|
365
|
+
}
|
|
366
|
+
interface ConnectorTreeNode {
|
|
367
|
+
txid: string;
|
|
368
|
+
tx: string;
|
|
369
|
+
children: Record<string, string>;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* REST-based emulator client.
|
|
373
|
+
*
|
|
374
|
+
* @example
|
|
375
|
+
* ```typescript
|
|
376
|
+
* const client = new RestEmulatorProvider('http://localhost:7073');
|
|
377
|
+
* const info = await client.getInfo();
|
|
378
|
+
* console.log('Emulator pubkey:', info.signerPubkey);
|
|
379
|
+
* ```
|
|
380
|
+
*/
|
|
381
|
+
declare class RestEmulatorProvider implements EmulatorProvider {
|
|
382
|
+
serverUrl: string;
|
|
383
|
+
constructor(serverUrl: string);
|
|
384
|
+
getInfo(): Promise<EmulatorInfo>;
|
|
385
|
+
submitTx(arkTx: string, checkpointTxs: string[]): Promise<{
|
|
386
|
+
signedArkTx: string;
|
|
387
|
+
signedCheckpointTxs: string[];
|
|
388
|
+
}>;
|
|
389
|
+
submitIntent(intent: {
|
|
390
|
+
proof: string;
|
|
391
|
+
message: Intent.RegisterMessage | Intent.DeleteMessage;
|
|
392
|
+
}): Promise<string>;
|
|
393
|
+
submitFinalization(intent: {
|
|
394
|
+
proof: string;
|
|
395
|
+
message: Proof.RegisterMessage;
|
|
396
|
+
}, forfeits: string[], connectorTree: ConnectorTreeNode[] | null, commitmentTx: string): Promise<{
|
|
397
|
+
signedForfeits: string[];
|
|
398
|
+
signedCommitmentTx?: string;
|
|
399
|
+
}>;
|
|
400
|
+
submitOnchainTx(tx: string): Promise<{
|
|
401
|
+
signedTx: string;
|
|
402
|
+
}>;
|
|
403
|
+
}
|
|
404
|
+
|
|
162
405
|
/**
|
|
163
406
|
* Where the SDK gets its `EventSource`. Node exposes the global only behind
|
|
164
407
|
* `--experimental-eventsource` (24.x), so it must be injectable.
|
|
@@ -363,6 +606,30 @@ type GetVtxosOptions = PaginationOptions & {
|
|
|
363
606
|
outpoints: Outpoint[];
|
|
364
607
|
scripts?: never;
|
|
365
608
|
});
|
|
609
|
+
/** Filters of {@link IndexerProvider.getUtxos}: scripts or outpoints, not both. */
|
|
610
|
+
type GetUtxosOptions = PaginationOptions & ({
|
|
611
|
+
scripts: string[];
|
|
612
|
+
outpoints?: never;
|
|
613
|
+
} | {
|
|
614
|
+
outpoints: Outpoint[];
|
|
615
|
+
scripts?: never;
|
|
616
|
+
});
|
|
617
|
+
/** An onchain coin whose spend the operator signed or watched, and that spend. */
|
|
618
|
+
interface IndexerUtxo extends Outpoint {
|
|
619
|
+
value: number;
|
|
620
|
+
script: string;
|
|
621
|
+
/** Txid of the spend: a batch commitment, a cosigned onchain tx or an unrolled VTXO's spend. */
|
|
622
|
+
spentBy: string;
|
|
623
|
+
/** Set once the spending tx confirms. */
|
|
624
|
+
spendConfirmation?: {
|
|
625
|
+
height: number;
|
|
626
|
+
time: number;
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
/** The Arkade server predates `GetUtxos` (arkd v0.9.22). */
|
|
630
|
+
declare class IndexerUtxosUnsupportedError extends Error {
|
|
631
|
+
constructor();
|
|
632
|
+
}
|
|
366
633
|
interface IndexerProvider {
|
|
367
634
|
/**
|
|
368
635
|
* Fetch the virtual output tree for a batch outpoint.
|
|
@@ -475,8 +742,17 @@ interface IndexerProvider {
|
|
|
475
742
|
page?: PageResponse;
|
|
476
743
|
}>;
|
|
477
744
|
/**
|
|
478
|
-
* Fetch
|
|
479
|
-
*
|
|
745
|
+
* Fetch onchain coins whose spend the operator signed or watched: boarding inputs of a
|
|
746
|
+
* batch, inputs of a cosigned onchain tx, and spent unrolled VTXOs. Optional; a server
|
|
747
|
+
* without it throws {@link IndexerUtxosUnsupportedError}.
|
|
748
|
+
*/
|
|
749
|
+
getUtxos?(opts: GetUtxosOptions): Promise<{
|
|
750
|
+
utxos: IndexerUtxo[];
|
|
751
|
+
page?: PageResponse;
|
|
752
|
+
}>;
|
|
753
|
+
/**
|
|
754
|
+
* Fetch metadata for a specific asset id.
|
|
755
|
+
*
|
|
480
756
|
* @param assetId - Asset identifier
|
|
481
757
|
* @returns Asset details
|
|
482
758
|
*/
|
|
@@ -511,6 +787,8 @@ declare class RestIndexerProvider implements IndexerProvider {
|
|
|
511
787
|
serverUrl: string;
|
|
512
788
|
/** Overrides {@link configureEventSource} for this provider's subscription. */
|
|
513
789
|
protected readonly eventSource?: EventSourceFactory;
|
|
790
|
+
/** Set by a 404 for this provider's lifetime: a server upgraded meanwhile needs a new one. */
|
|
791
|
+
private utxosUnsupported;
|
|
514
792
|
/** @see fetchVtxosJson */
|
|
515
793
|
private readonly inFlightVtxoReads;
|
|
516
794
|
constructor(serverUrl?: string, options?: EventSourceCapable);
|
|
@@ -564,6 +842,10 @@ declare class RestIndexerProvider implements IndexerProvider {
|
|
|
564
842
|
* delta-syncs that contract on both arms.
|
|
565
843
|
*/
|
|
566
844
|
private fetchVtxosJson;
|
|
845
|
+
getUtxos(opts: GetUtxosOptions): Promise<{
|
|
846
|
+
utxos: IndexerUtxo[];
|
|
847
|
+
page?: PageResponse;
|
|
848
|
+
}>;
|
|
567
849
|
getAssetDetails(assetId: string): Promise<AssetDetails>;
|
|
568
850
|
subscribeForScripts(scripts: string[], subscriptionId?: string, signal?: AbortSignal): Promise<string>;
|
|
569
851
|
unsubscribeForScripts(subscriptionId: string, scripts?: string[]): Promise<void>;
|
|
@@ -608,171 +890,6 @@ interface FeeOutput {
|
|
|
608
890
|
script: string;
|
|
609
891
|
}
|
|
610
892
|
|
|
611
|
-
/**
|
|
612
|
-
* Off-chain source of previous transactions: ark, tree and checkpoint txs, as
|
|
613
|
-
* base64 PSBTs keyed by txid. Structurally satisfied by `IndexerProvider`.
|
|
614
|
-
*/
|
|
615
|
-
interface PrevTxSource {
|
|
616
|
-
getVirtualTxs(txids: string[]): Promise<{
|
|
617
|
-
txs: string[];
|
|
618
|
-
}>;
|
|
619
|
-
}
|
|
620
|
-
/**
|
|
621
|
-
* On-chain source of previous transactions — boarding and commitment txs, which
|
|
622
|
-
* `getVirtualTxs` does not serve. Structurally satisfied by `OnchainProvider`.
|
|
623
|
-
*/
|
|
624
|
-
interface RawTxSource {
|
|
625
|
-
getRawTransaction(txid: string): Promise<Uint8Array>;
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
* A previous transaction could not be resolved, so the emulator would reject the
|
|
629
|
-
* submission with `missing prevout tx for input N`. Distinguishes "no source is
|
|
630
|
-
* wired up" from "the source did not have it" — the remedies differ.
|
|
631
|
-
*/
|
|
632
|
-
declare class PrevTxUnavailableError extends Error {
|
|
633
|
-
readonly txids: string[];
|
|
634
|
-
constructor(message: string, txids?: string[]);
|
|
635
|
-
}
|
|
636
|
-
/**
|
|
637
|
-
* Resolve raw wire-format bytes for each txid, batched and de-duplicated.
|
|
638
|
-
*
|
|
639
|
-
* Emulator v0.0.7+ requires the raw tx behind every input of a submitted ark tx
|
|
640
|
-
* or proof (`PrevArkTxField`) and of an onchain tx (`PrevoutTxField`).
|
|
641
|
-
* The value is a serialized `wire.MsgTx`, *not* a PSBT — `Transaction.toBytes()`
|
|
642
|
-
* with the default `(withScriptSig=false, withWitness=false)` is exactly the
|
|
643
|
-
* preimage the emulator hashes to check the tx against the outpoint.
|
|
644
|
-
*
|
|
645
|
-
* Off-chain txs are fetched in one batched call; anything the indexer does not
|
|
646
|
-
* serve (a commitment or boarding tx) falls through to `onchain` when supplied.
|
|
647
|
-
*/
|
|
648
|
-
declare function resolvePrevTxs(txids: string[], source: PrevTxSource, onchain?: RawTxSource): Promise<Map<string, Uint8Array>>;
|
|
649
|
-
/**
|
|
650
|
-
* Attach `PrevArkTxField` to every input of `tx` that does not already carry
|
|
651
|
-
* one, resolving the bytes for `txids[i]` — the coin input `i` ultimately
|
|
652
|
-
* spends.
|
|
653
|
-
*
|
|
654
|
-
* Inputs already carrying the field are skipped rather than overwritten: the
|
|
655
|
-
* emulator rejects an input with more than one field of the same type, so a
|
|
656
|
-
* caller-supplied value (`Utxo.sourceTx`) must win outright. Nothing is fetched
|
|
657
|
-
* when every input is already covered.
|
|
658
|
-
*/
|
|
659
|
-
declare function attachPrevArkTxs(tx: Transaction, txids: string[], source: PrevTxSource, onchain?: RawTxSource): Promise<void>;
|
|
660
|
-
/**
|
|
661
|
-
* Attach `PrevoutTxField` to every input of an onchain PSBT, reading each
|
|
662
|
-
* input's own outpoint — unlike an ark tx, an onchain tx spends its prevout
|
|
663
|
-
* directly, so the txid is in the PSBT already.
|
|
664
|
-
*/
|
|
665
|
-
declare function attachPrevoutTxs(tx: Transaction, source: RawTxSource): Promise<void>;
|
|
666
|
-
/**
|
|
667
|
-
* A coin a proof spends, carrying the raw previous tx the emulator needs
|
|
668
|
-
* to resolve its prevout pkScript.
|
|
669
|
-
*/
|
|
670
|
-
type WithPrevTx<T> = T & {
|
|
671
|
-
prevTx?: Uint8Array;
|
|
672
|
-
};
|
|
673
|
-
/**
|
|
674
|
-
* Fill in `prevTx` on every coin a proof will spend, in one batched
|
|
675
|
-
* lookup. The proof's synthetic input 0 needs nothing — the emulator synthesises
|
|
676
|
-
* a one-output tx for it — so this covers exactly the coins, which land on proof
|
|
677
|
-
* inputs `1..n`.
|
|
678
|
-
*/
|
|
679
|
-
declare function withPrevTxs<T extends {
|
|
680
|
-
txid: string;
|
|
681
|
-
prevTx?: Uint8Array;
|
|
682
|
-
}>(coins: T[], source: PrevTxSource, onchain?: RawTxSource): Promise<T[]>;
|
|
683
|
-
|
|
684
|
-
/**
|
|
685
|
-
* An input of a {@link Proof}: an output it proves ownership of. `prevTx` carries the raw wire
|
|
686
|
-
* bytes of the transaction that created it — required by emulator v0.0.7+ on
|
|
687
|
-
* every real input of a submitted proof. {@link Proof.create} is synchronous,
|
|
688
|
-
* so the bytes are supplied rather than fetched; `withPrevTxs` fills them in.
|
|
689
|
-
*/
|
|
690
|
-
type ProofInput = WithPrevTx<ExtendedCoin>;
|
|
691
|
-
/**
|
|
692
|
-
* A signed BIP322-style PSBT carrying a message. Its inputs are Bitcoin outputs,
|
|
693
|
-
* its signature proves the user controls them, and its message says what to do
|
|
694
|
-
* with them.
|
|
695
|
-
*
|
|
696
|
-
* A proof is a deliberately invalid PSBT, so it can never be broadcast. Signing
|
|
697
|
-
* a proof means signing the PSBT as a regular transaction.
|
|
698
|
-
*/
|
|
699
|
-
type Proof = Transaction;
|
|
700
|
-
/**
|
|
701
|
-
* Utilities for creating and inspecting {@link Proof}s.
|
|
702
|
-
*
|
|
703
|
-
* @see https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki
|
|
704
|
-
*
|
|
705
|
-
* @example
|
|
706
|
-
* ```typescript
|
|
707
|
-
* // Create an unsigned proof
|
|
708
|
-
* const proof = Proof.create(
|
|
709
|
-
* "Hello Bitcoin!",
|
|
710
|
-
* [input],
|
|
711
|
-
* [output]
|
|
712
|
-
* );
|
|
713
|
-
*
|
|
714
|
-
* // Sign the proof
|
|
715
|
-
* const signedProof = await identity.sign(proof);
|
|
716
|
-
* ```
|
|
717
|
-
*/
|
|
718
|
-
declare namespace Proof {
|
|
719
|
-
/**
|
|
720
|
-
* Creates an unsigned {@link Proof}.
|
|
721
|
-
*
|
|
722
|
-
* This function constructs a special transaction that can be signed to prove
|
|
723
|
-
* ownership of onchain and virtual outputs. The proof includes the message to be
|
|
724
|
-
* signed and the inputs/outputs that demonstrate ownership.
|
|
725
|
-
*
|
|
726
|
-
* @param message - The message to be signed, either a raw string or a Message object
|
|
727
|
-
* @param ins - Array of transaction inputs to prove ownership of
|
|
728
|
-
* @param outputs - Optional array of transaction outputs
|
|
729
|
-
* @returns An unsigned proof
|
|
730
|
-
*/
|
|
731
|
-
function create(message: string | Message, ins: (TransactionInput | ProofInput)[], outputs?: TransactionOutput[]): Proof;
|
|
732
|
-
/**
|
|
733
|
-
* Compute the fee paid by a proof.
|
|
734
|
-
*
|
|
735
|
-
* @param proof - The proof
|
|
736
|
-
* @returns The fee in satoshis
|
|
737
|
-
*/
|
|
738
|
-
function fee(proof: Proof): number;
|
|
739
|
-
type RegisterMessage = {
|
|
740
|
-
type: "register";
|
|
741
|
-
onchain_output_indexes: number[];
|
|
742
|
-
valid_at: number;
|
|
743
|
-
expire_at: number;
|
|
744
|
-
cosigners_public_keys: string[];
|
|
745
|
-
};
|
|
746
|
-
type DeleteMessage = {
|
|
747
|
-
type: "delete";
|
|
748
|
-
expire_at: number;
|
|
749
|
-
};
|
|
750
|
-
type GetPendingTxMessage = {
|
|
751
|
-
type: "get-pending-tx";
|
|
752
|
-
expire_at: number;
|
|
753
|
-
};
|
|
754
|
-
type Message = RegisterMessage | DeleteMessage | GetPendingTxMessage;
|
|
755
|
-
/**
|
|
756
|
-
* Serialize a proof message to the canonical JSON string used for signing.
|
|
757
|
-
*
|
|
758
|
-
* @param message - Proof message payload
|
|
759
|
-
* @returns Canonical string form of the message
|
|
760
|
-
*/
|
|
761
|
-
function encodeMessage(message: Message): string;
|
|
762
|
-
}
|
|
763
|
-
/** @deprecated Use {@link ProofInput}. */
|
|
764
|
-
type IntentCoin = ProofInput;
|
|
765
|
-
/** @deprecated Use {@link Proof}. */
|
|
766
|
-
declare const Intent: typeof Proof;
|
|
767
|
-
/** @deprecated Use {@link Proof}. */
|
|
768
|
-
declare namespace Intent {
|
|
769
|
-
type Proof = Transaction;
|
|
770
|
-
type RegisterMessage = Proof.RegisterMessage;
|
|
771
|
-
type DeleteMessage = Proof.DeleteMessage;
|
|
772
|
-
type GetPendingTxMessage = Proof.GetPendingTxMessage;
|
|
773
|
-
type Message = Proof.Message;
|
|
774
|
-
}
|
|
775
|
-
|
|
776
893
|
/**
|
|
777
894
|
* Thrown by {@link RestOperatorProvider} when arkd rejects a request with
|
|
778
895
|
* `DIGEST_MISMATCH` — the client's cached operator info was stale (e.g. an
|
|
@@ -784,6 +901,22 @@ declare namespace Intent {
|
|
|
784
901
|
declare class DigestMismatchError extends Error {
|
|
785
902
|
constructor(message: string);
|
|
786
903
|
}
|
|
904
|
+
declare class OnchainCosignUnsupportedError extends Error {
|
|
905
|
+
constructor();
|
|
906
|
+
}
|
|
907
|
+
/** arkd's structured error name is carried in the message as `[NAME] ` so it survives structured clone. */
|
|
908
|
+
declare class OnchainCosignRejectedError extends Error {
|
|
909
|
+
readonly serverMessage: string;
|
|
910
|
+
readonly arkErrorName?: string | undefined;
|
|
911
|
+
constructor(serverMessage: string, arkErrorName?: string | undefined);
|
|
912
|
+
}
|
|
913
|
+
/** The cosign request may have broadcast the tx: never retry the payment with other coins. */
|
|
914
|
+
declare class OnchainCosignAmbiguousError extends Error {
|
|
915
|
+
readonly detail: string;
|
|
916
|
+
constructor(detail: string, options?: {
|
|
917
|
+
cause?: unknown;
|
|
918
|
+
});
|
|
919
|
+
}
|
|
787
920
|
/** Output requested during settlement or transaction submission. */
|
|
788
921
|
type Output = {
|
|
789
922
|
/** Destination address, either onchain or Arkade (offchain). */
|
|
@@ -1008,6 +1141,8 @@ interface TxNotificationEvent {
|
|
|
1008
1141
|
interface OperatorProvider {
|
|
1009
1142
|
/** Fetch the operator's configuration and fee settings. */
|
|
1010
1143
|
getInfo(): Promise<OperatorInfo>;
|
|
1144
|
+
/** Cosign and broadcast an onchain tx spending server-cosigned UTXOs; returns the txid. */
|
|
1145
|
+
cosignOnchainTx?(psbtB64: string): Promise<string>;
|
|
1011
1146
|
/** Submit a signed Arkade transaction and its checkpoint transactions. */
|
|
1012
1147
|
submitTx(signedArkTx: string, checkpointTxs: string[]): Promise<{
|
|
1013
1148
|
arkTxid: string;
|
|
@@ -1017,9 +1152,9 @@ interface OperatorProvider {
|
|
|
1017
1152
|
/** Finalize a previously submitted Arkade transaction. */
|
|
1018
1153
|
finalizeTx(arkTxid: string, finalCheckpointTxs: string[]): Promise<void>;
|
|
1019
1154
|
/** Register a signed intent with the operator. */
|
|
1020
|
-
registerIntent(intent:
|
|
1155
|
+
registerIntent(intent: SignedProof<Proof.RegisterMessage>): Promise<string>;
|
|
1021
1156
|
/** Delete a previously registered intent. */
|
|
1022
|
-
deleteIntent(intent:
|
|
1157
|
+
deleteIntent(intent: SignedProof<Proof.DeleteMessage>): Promise<void>;
|
|
1023
1158
|
/** Confirm an already registered intent id. */
|
|
1024
1159
|
confirmRegistration(intentId: string): Promise<void>;
|
|
1025
1160
|
/** Submit musig2 tree nonces for a batch signing session. */
|
|
@@ -1056,6 +1191,7 @@ declare class RestOperatorProvider implements OperatorProvider {
|
|
|
1056
1191
|
* stale. Empty until the first {@link getInfo}.
|
|
1057
1192
|
*/
|
|
1058
1193
|
private _digest;
|
|
1194
|
+
private _onchainCosignUnsupported;
|
|
1059
1195
|
private _hasServerInfo;
|
|
1060
1196
|
private _suppressNextGetInfoChangeEmit;
|
|
1061
1197
|
private _serverInfoListeners;
|
|
@@ -1064,7 +1200,7 @@ declare class RestOperatorProvider implements OperatorProvider {
|
|
|
1064
1200
|
* `DIGEST_MISMATCH` refresh or when {@link getInfo} observes a changed digest.
|
|
1065
1201
|
* Returns an unsubscribe function.
|
|
1066
1202
|
*/
|
|
1067
|
-
onServerInfoChanged(listener: (info:
|
|
1203
|
+
onServerInfoChanged(listener: (info: OperatorInfo) => void): () => void;
|
|
1068
1204
|
private emitServerInfoChanged;
|
|
1069
1205
|
/**
|
|
1070
1206
|
* `fetch` wrapper for arkd requests that participates in operator info digest
|
|
@@ -1084,9 +1220,10 @@ declare class RestOperatorProvider implements OperatorProvider {
|
|
|
1084
1220
|
finalArkTx: string;
|
|
1085
1221
|
signedCheckpointTxs: string[];
|
|
1086
1222
|
}>;
|
|
1223
|
+
cosignOnchainTx(psbtB64: string): Promise<string>;
|
|
1087
1224
|
finalizeTx(arkTxid: string, finalCheckpointTxs: string[]): Promise<void>;
|
|
1088
|
-
registerIntent(intent:
|
|
1089
|
-
deleteIntent(intent:
|
|
1225
|
+
registerIntent(intent: SignedProof<Proof.RegisterMessage>): Promise<string>;
|
|
1226
|
+
deleteIntent(intent: SignedProof<Proof.DeleteMessage>): Promise<void>;
|
|
1090
1227
|
confirmRegistration(intentId: string): Promise<void>;
|
|
1091
1228
|
submitTreeNonces(batchId: string, pubkey: string, nonces: TreeNonces): Promise<void>;
|
|
1092
1229
|
submitTreeSignatures(batchId: string, pubkey: string, signatures: TreePartialSigs): Promise<void>;
|
|
@@ -1210,434 +1347,80 @@ declare const RestArkProvider: typeof RestOperatorProvider;
|
|
|
1210
1347
|
/** @deprecated Use {@link RestOperatorProvider}. */
|
|
1211
1348
|
type RestArkProvider = RestOperatorProvider;
|
|
1212
1349
|
|
|
1350
|
+
type NetworkName = "bitcoin" | "testnet" | "signet" | "mutinynet" | "regtest";
|
|
1351
|
+
interface Network {
|
|
1352
|
+
hrp: string;
|
|
1353
|
+
bech32: string;
|
|
1354
|
+
pubKeyHash: number;
|
|
1355
|
+
scriptHash: number;
|
|
1356
|
+
wif: number;
|
|
1357
|
+
/**
|
|
1358
|
+
* Canonical name this network was resolved from, when known: the only way to tell the
|
|
1359
|
+
* tb-family apart (testnet, signet and mutinynet share every field above). Optional because a
|
|
1360
|
+
* hand-built `Network` has none — read a missing one as "unknown" and take the strictest branch.
|
|
1361
|
+
*/
|
|
1362
|
+
name?: NetworkName;
|
|
1363
|
+
}
|
|
1364
|
+
declare const getNetwork: (network: NetworkName) => Network;
|
|
1213
1365
|
/**
|
|
1214
|
-
*
|
|
1215
|
-
*
|
|
1216
|
-
*
|
|
1217
|
-
* ```typescript
|
|
1218
|
-
* const timelock = { value: 144n, type: "blocks" }; // 1 day in blocks
|
|
1219
|
-
* const timelock = { value: 512n, type: "seconds" }; // 8 minutes in seconds
|
|
1220
|
-
* ```
|
|
1366
|
+
* The {@link Network} the operator's info names. {@link getNetwork} fails closed, so an
|
|
1367
|
+
* unrecognized network throws here rather than resolving to mainnet parameters downstream.
|
|
1368
|
+
* Structurally typed so the network table doesn't depend on the provider layer.
|
|
1221
1369
|
*/
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1370
|
+
declare const networkFromOperatorInfo: (info: {
|
|
1371
|
+
network: string;
|
|
1372
|
+
}) => Network;
|
|
1373
|
+
/** @deprecated Use {@link networkFromOperatorInfo}. */
|
|
1374
|
+
declare const networkFromArkadeInfo: (info: {
|
|
1375
|
+
network: string;
|
|
1376
|
+
}) => Network;
|
|
1377
|
+
declare const networks: {
|
|
1378
|
+
bitcoin: Network;
|
|
1379
|
+
testnet: Network;
|
|
1380
|
+
signet: Network;
|
|
1381
|
+
mutinynet: Network;
|
|
1382
|
+
regtest: Network;
|
|
1225
1383
|
};
|
|
1226
|
-
declare enum TapscriptType {
|
|
1227
|
-
Multisig = "multisig",
|
|
1228
|
-
CSVMultisig = "csv-multisig",
|
|
1229
|
-
ConditionCSVMultisig = "condition-csv-multisig",
|
|
1230
|
-
ConditionMultisig = "condition-multisig",
|
|
1231
|
-
CLTVMultisig = "cltv-multisig"
|
|
1232
|
-
}
|
|
1233
1384
|
/**
|
|
1234
|
-
*
|
|
1235
|
-
*
|
|
1385
|
+
* The operator's cosigner that emulates Arkade Script on mainnet, resolved by the
|
|
1386
|
+
* `{ network: "bitcoin" }` service. No trailing slash: `RestEmulatorProvider` appends its paths
|
|
1387
|
+
* verbatim. The URL only selects where to ask for a signature; the key covenants commit to is
|
|
1388
|
+
* {@link BITCOIN_EMULATOR_PUBKEY}.
|
|
1236
1389
|
*/
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1390
|
+
declare const DEFAULT_ARKADE_EMULATOR_URL: "https://emulator.arkade.computer";
|
|
1391
|
+
/** Key of the operator's cosigner that emulates Arkade Script on mainnet. */
|
|
1392
|
+
declare const BITCOIN_EMULATOR_PUBKEY: "0239c196415da47b26456a101daaa12ba9e445bfe153197f1e2b750bf40e52092e";
|
|
1393
|
+
/** Key of the operator's cosigner that emulates Arkade Script on mutinynet. */
|
|
1394
|
+
declare const MUTINYNET_EMULATOR_PUBKEY: "03f823b9b2febc81f4af967e77aed2f541cbd3397c6d8f5a72e32eb7b471af889a";
|
|
1395
|
+
/** Key of the operator's cosigner that emulates Arkade Script in the `arkade-regtest` stack. */
|
|
1396
|
+
declare const REGTEST_EMULATOR_PUBKEY: "02999413c46fa10ada5cbc4bcc79a1d09160c2ba3cfc812705d7a13e5e545fb2a9";
|
|
1242
1397
|
/**
|
|
1243
|
-
*
|
|
1398
|
+
* The pinned co-signer key for `network`, as 33-byte compressed lowercase hex.
|
|
1244
1399
|
*
|
|
1245
|
-
* @throws
|
|
1246
|
-
*
|
|
1247
|
-
*
|
|
1248
|
-
*
|
|
1249
|
-
*
|
|
1250
|
-
*
|
|
1400
|
+
* @throws if the network carries no name, or names one with no deployed emulator. Fail closed:
|
|
1401
|
+
* the key ends up in a covenant leaf deciding who can move the funds. Guessing a tb-family
|
|
1402
|
+
* neighbour's key locks funds to a co-signer that never signs; an empty string only moves the
|
|
1403
|
+
* failure. Deliberately NOT falling back to the emulator's self-reported key — that is the
|
|
1404
|
+
* trust this pin removes, and a silent fallback on an unnamed `Network` (which may carry
|
|
1405
|
+
* mainnet-equivalent parameters) would lapse it exactly where it matters most. Callers who mean
|
|
1406
|
+
* it pass {@link resolveEmulatorPubkey}'s override, which the thrown message names.
|
|
1251
1407
|
*/
|
|
1252
|
-
declare function
|
|
1408
|
+
declare function defaultEmulatorPubkey(network: Network): string;
|
|
1253
1409
|
/**
|
|
1254
|
-
*
|
|
1410
|
+
* Resolve the co-signer key for `network`, letting a caller substitute its own, for:
|
|
1255
1411
|
*
|
|
1256
|
-
*
|
|
1412
|
+
* 1. **A network rotated its emulator key before this SDK shipped the new constant.**
|
|
1413
|
+
* `Arkade.connect` no longer asks the service, so covenants would keep building against the
|
|
1414
|
+
* retired key and fail only at claim time; the override makes rotation a config change.
|
|
1415
|
+
* 2. A private or self-hosted emulator, including on unpinned networks.
|
|
1416
|
+
* 3. Tests and local stacks.
|
|
1257
1417
|
*
|
|
1258
|
-
*
|
|
1259
|
-
*
|
|
1260
|
-
*
|
|
1261
|
-
* ```
|
|
1418
|
+
* Supplying it means trusting that operator in place of the network's: covenants built from the
|
|
1419
|
+
* key can be completed by its holder and no one else. A malformed override throws rather than
|
|
1420
|
+
* surfacing later as an unspendable contract.
|
|
1262
1421
|
*/
|
|
1263
|
-
declare
|
|
1264
|
-
|
|
1265
|
-
enum MultisigType {
|
|
1266
|
-
CHECKSIG = 0,
|
|
1267
|
-
CHECKSIGADD = 1
|
|
1268
|
-
}
|
|
1269
|
-
type Params = {
|
|
1270
|
-
pubkeys: Bytes[];
|
|
1271
|
-
type?: MultisigType;
|
|
1272
|
-
};
|
|
1273
|
-
/** Encode a plain multisig tapscript. */
|
|
1274
|
-
function encode(params: Params): Type;
|
|
1275
|
-
/** Decode a plain multisig tapscript from raw script bytes. */
|
|
1276
|
-
function decode(script: Uint8Array): Type;
|
|
1277
|
-
/** Return true when the tapscript is a plain multisig tapscript. */
|
|
1278
|
-
function is(tapscript: ArkTapscript<any, any>): tapscript is Type;
|
|
1279
|
-
}
|
|
1280
|
-
/**
|
|
1281
|
-
* Implements a relative timelock script that requires all specified pubkeys to sign
|
|
1282
|
-
* after the relative timelock has expired. The timelock can be specified in blocks or seconds.
|
|
1283
|
-
*
|
|
1284
|
-
* This is the standard exit closure and it is also used for the sweep closure in vtxo trees.
|
|
1285
|
-
*
|
|
1286
|
-
* <sequence> CHECKSEQUENCEVERIFY DROP <pubkey> CHECKSIG
|
|
1287
|
-
*
|
|
1288
|
-
* @example
|
|
1289
|
-
* ```typescript
|
|
1290
|
-
* const csvMultisigTapscript = CSVMultisigTapscript.encode({ timelock: { type: "blocks", value: 144 }, pubkeys: [new Uint8Array(32), new Uint8Array(32)] });
|
|
1291
|
-
* ```
|
|
1292
|
-
*/
|
|
1293
|
-
declare namespace CSVMultisigTapscript {
|
|
1294
|
-
type Type = ArkTapscript<TapscriptType.CSVMultisig, Params>;
|
|
1295
|
-
type Params = {
|
|
1296
|
-
timelock: RelativeTimelock;
|
|
1297
|
-
} & MultisigTapscript.Params;
|
|
1298
|
-
/** Encode a CSV multisig tapscript. */
|
|
1299
|
-
function encode(params: Params): Type;
|
|
1300
|
-
/** Decode a CSV multisig tapscript from raw script bytes. */
|
|
1301
|
-
function decode(script: Uint8Array): Type;
|
|
1302
|
-
/** Return true when the tapscript is a CSV multisig tapscript. */
|
|
1303
|
-
function is(tapscript: ArkTapscript<any, any>): tapscript is Type;
|
|
1304
|
-
function isScriptValid(script: Uint8Array): true | Error;
|
|
1305
|
-
}
|
|
1306
|
-
/**
|
|
1307
|
-
* Combines a condition script with an exit closure. The resulting script requires
|
|
1308
|
-
* the condition to be met, followed by the standard exit closure requirements
|
|
1309
|
-
* (timelock and signatures).
|
|
1310
|
-
*
|
|
1311
|
-
* <conditionScript> VERIFY <sequence> CHECKSEQUENCEVERIFY DROP <pubkey> CHECKSIGVERIFY <pubkey> CHECKSIG
|
|
1312
|
-
*
|
|
1313
|
-
* @example
|
|
1314
|
-
* ```typescript
|
|
1315
|
-
* const conditionCSVMultisigTapscript = ConditionCSVMultisigTapscript.encode({ conditionScript: new Uint8Array(32), pubkeys: [new Uint8Array(32), new Uint8Array(32)] });
|
|
1316
|
-
* ```
|
|
1317
|
-
*/
|
|
1318
|
-
declare namespace ConditionCSVMultisigTapscript {
|
|
1319
|
-
type Type = ArkTapscript<TapscriptType.ConditionCSVMultisig, Params>;
|
|
1320
|
-
type Params = {
|
|
1321
|
-
conditionScript: Bytes;
|
|
1322
|
-
} & CSVMultisigTapscript.Params;
|
|
1323
|
-
/** Encode a condition + CSV multisig tapscript. */
|
|
1324
|
-
function encode(params: Params): Type;
|
|
1325
|
-
/** Decode a condition + CSV multisig tapscript from raw script bytes. */
|
|
1326
|
-
function decode(script: Uint8Array): Type;
|
|
1327
|
-
/** Return true when the tapscript is a condition + CSV multisig tapscript. */
|
|
1328
|
-
function is(tapscript: ArkTapscript<any, any>): tapscript is Type;
|
|
1329
|
-
function isScriptValid(script: Uint8Array): true | Error;
|
|
1330
|
-
}
|
|
1331
|
-
/**
|
|
1332
|
-
* Combines a condition script with a forfeit closure. The resulting script requires
|
|
1333
|
-
* the condition to be met, followed by the standard forfeit closure requirements
|
|
1334
|
-
* (multi-signature).
|
|
1335
|
-
*
|
|
1336
|
-
* <conditionScript> VERIFY <pubkey> CHECKSIGVERIFY <pubkey> CHECKSIG
|
|
1337
|
-
*
|
|
1338
|
-
* @example
|
|
1339
|
-
* ```typescript
|
|
1340
|
-
* const conditionMultisigTapscript = ConditionMultisigTapscript.encode({ conditionScript: new Uint8Array(32), pubkeys: [new Uint8Array(32), new Uint8Array(32)] });
|
|
1341
|
-
* ```
|
|
1342
|
-
*/
|
|
1343
|
-
declare namespace ConditionMultisigTapscript {
|
|
1344
|
-
type Type = ArkTapscript<TapscriptType.ConditionMultisig, Params>;
|
|
1345
|
-
type Params = {
|
|
1346
|
-
conditionScript: Bytes;
|
|
1347
|
-
} & MultisigTapscript.Params;
|
|
1348
|
-
/** Encode a condition + multisig tapscript. */
|
|
1349
|
-
function encode(params: Params): Type;
|
|
1350
|
-
/** Decode a condition + multisig tapscript from raw script bytes. */
|
|
1351
|
-
function decode(script: Uint8Array): Type;
|
|
1352
|
-
/** Return true when the tapscript is a condition + multisig tapscript. */
|
|
1353
|
-
function is(tapscript: ArkTapscript<any, any>): tapscript is Type;
|
|
1354
|
-
function isScriptValid(script: Uint8Array): true | Error;
|
|
1355
|
-
}
|
|
1356
|
-
/**
|
|
1357
|
-
* Implements an absolute timelock (CLTV) script combined with a forfeit closure.
|
|
1358
|
-
* The script requires waiting until a specific block height/timestamp before the
|
|
1359
|
-
* forfeit closure conditions can be met.
|
|
1360
|
-
*
|
|
1361
|
-
* <locktime> CHECKLOCKTIMEVERIFY DROP <pubkey> CHECKSIGVERIFY <pubkey> CHECKSIG
|
|
1362
|
-
*
|
|
1363
|
-
* @example
|
|
1364
|
-
* ```typescript
|
|
1365
|
-
* const cltvMultisigTapscript = CLTVMultisigTapscript.encode({ absoluteTimelock: 144, pubkeys: [new Uint8Array(32), new Uint8Array(32)] });
|
|
1366
|
-
* ```
|
|
1367
|
-
*/
|
|
1368
|
-
declare namespace CLTVMultisigTapscript {
|
|
1369
|
-
type Type = ArkTapscript<TapscriptType.CLTVMultisig, Params>;
|
|
1370
|
-
type Params = {
|
|
1371
|
-
absoluteTimelock: bigint;
|
|
1372
|
-
} & MultisigTapscript.Params;
|
|
1373
|
-
/** Encode a CLTV multisig tapscript. */
|
|
1374
|
-
function encode(params: Params): Type;
|
|
1375
|
-
/** Decode a CLTV multisig tapscript from raw script bytes. */
|
|
1376
|
-
function decode(script: Uint8Array): Type;
|
|
1377
|
-
/** Return true when the tapscript is a CLTV multisig tapscript. */
|
|
1378
|
-
function is(tapscript: ArkTapscript<any, any>): tapscript is Type;
|
|
1379
|
-
function isScriptValid(script: Uint8Array): true | Error;
|
|
1380
|
-
}
|
|
1381
|
-
|
|
1382
|
-
/**
|
|
1383
|
-
* ArkAddress allows creating and decoding bech32m-encoded Arkade addresses: an hrp plus a
|
|
1384
|
-
* 65-byte payload of version byte ‖ 32-byte server pubkey ‖ 32-byte VTXO taproot key.
|
|
1385
|
-
*
|
|
1386
|
-
* @remarks
|
|
1387
|
-
* This is an Arkade-specific address format.
|
|
1388
|
-
* It is distinct from the Taproot onchain address returned by `VtxoScript.onchainAddress`.
|
|
1389
|
-
*
|
|
1390
|
-
* @see VtxoScript
|
|
1391
|
-
*
|
|
1392
|
-
* @example
|
|
1393
|
-
* ```typescript
|
|
1394
|
-
* const address = new ArkAddress(
|
|
1395
|
-
* new Uint8Array(32), // server public key
|
|
1396
|
-
* new Uint8Array(32), // vtxo taproot public key
|
|
1397
|
-
* "ark"
|
|
1398
|
-
* );
|
|
1399
|
-
*
|
|
1400
|
-
* const encoded = address.encode();
|
|
1401
|
-
* console.log("address: ", encoded);
|
|
1402
|
-
*
|
|
1403
|
-
* const decoded = ArkAddress.decode(encoded);
|
|
1404
|
-
* ```
|
|
1405
|
-
*/
|
|
1406
|
-
declare class ArkAddress {
|
|
1407
|
-
readonly serverPubKey: Bytes;
|
|
1408
|
-
readonly vtxoTaprootKey: Bytes;
|
|
1409
|
-
readonly hrp: string;
|
|
1410
|
-
readonly version: number;
|
|
1411
|
-
/**
|
|
1412
|
-
* Create an Arkade address from its server public key, Taproot output key, and prefix.
|
|
1413
|
-
*
|
|
1414
|
-
* @param serverPubKey - 32-byte Arkade server public key
|
|
1415
|
-
* @param vtxoTaprootKey - 32-byte Taproot output key (a.k.a. tweaked public key)
|
|
1416
|
-
* @param hrp - Bech32 human-readable prefix
|
|
1417
|
-
* @param version - Address version byte
|
|
1418
|
-
* @defaultValue `version = 0`
|
|
1419
|
-
* @throws Error if either public key is not 32 bytes long
|
|
1420
|
-
*/
|
|
1421
|
-
constructor(serverPubKey: Bytes, vtxoTaprootKey: Bytes, hrp?: string, version?: number);
|
|
1422
|
-
/**
|
|
1423
|
-
* Decode an Arkade address from its bech32m string form.
|
|
1424
|
-
*
|
|
1425
|
-
* @param address - Bech32m-encoded Arkade address
|
|
1426
|
-
* @returns Decoded Arkade address
|
|
1427
|
-
* @throws Error if the address is malformed or has an invalid payload length
|
|
1428
|
-
* @see encode
|
|
1429
|
-
*/
|
|
1430
|
-
static decode(address: string): ArkAddress;
|
|
1431
|
-
/**
|
|
1432
|
-
* Encode the address to its bech32m string form.
|
|
1433
|
-
*
|
|
1434
|
-
* @returns Bech32m-encoded Arkade address
|
|
1435
|
-
* @see decode
|
|
1436
|
-
*/
|
|
1437
|
-
encode(): string;
|
|
1438
|
-
/** ScriptPubKey used to send non-dust funds to the address. */
|
|
1439
|
-
get pkScript(): Bytes;
|
|
1440
|
-
/** ScriptPubKey used to send sub-dust funds to the address. */
|
|
1441
|
-
get subdustPkScript(): Bytes;
|
|
1442
|
-
}
|
|
1443
|
-
|
|
1444
|
-
type TapLeafScript = [
|
|
1445
|
-
{
|
|
1446
|
-
version: number;
|
|
1447
|
-
internalKey: Bytes;
|
|
1448
|
-
merklePath: Bytes[];
|
|
1449
|
-
},
|
|
1450
|
-
Bytes
|
|
1451
|
-
];
|
|
1452
|
-
declare const TapTreeCoder: (typeof PSBTOutput.tapTree)[2];
|
|
1453
|
-
declare function scriptFromTapLeafScript(leaf: TapLeafScript): Bytes;
|
|
1454
|
-
/**
|
|
1455
|
-
* VtxoScript is a script that contains a list of tapleaf scripts.
|
|
1456
|
-
* It is used to create virtual output scripts.
|
|
1457
|
-
*
|
|
1458
|
-
* @see ArkAddress
|
|
1459
|
-
*
|
|
1460
|
-
* @example
|
|
1461
|
-
* ```typescript
|
|
1462
|
-
* const vtxoScript = new VtxoScript([new Uint8Array(32), new Uint8Array(32)]);
|
|
1463
|
-
* ```
|
|
1464
|
-
*/
|
|
1465
|
-
declare class VtxoScript {
|
|
1466
|
-
readonly scripts: Bytes[];
|
|
1467
|
-
readonly leaves: TapLeafScript[];
|
|
1468
|
-
readonly tweakedPublicKey: Bytes;
|
|
1469
|
-
readonly pkScript: Bytes;
|
|
1470
|
-
/**
|
|
1471
|
-
* Decode a virtual output script from an encoded TapTree.
|
|
1472
|
-
*
|
|
1473
|
-
* Leaves are normally read in construction order and their depths
|
|
1474
|
-
* ignored: that covers the {@link encode} form (every depth 1) and the
|
|
1475
|
-
* placeholder depths other writers use, such as arkd's. The exception is
|
|
1476
|
-
* the BIP-371 form {@link toBIP371TapTree} writes, whose leaves are in the
|
|
1477
|
-
* tree's DFS order: for some leaf counts (6, 7, 10, ...) that differs from
|
|
1478
|
-
* construction order. A tree whose depths are exactly the shape
|
|
1479
|
-
* `assembleBtcdTaprootTree` builds is that form, so its leaves are mapped
|
|
1480
|
-
* back to construction order first. No construction-order writer produces
|
|
1481
|
-
* that depth sequence when the two orders differ, so this never reorders
|
|
1482
|
-
* a tree that decoded correctly before.
|
|
1483
|
-
*
|
|
1484
|
-
* Every leaf must carry the base tapscript version: the tree is rebuilt
|
|
1485
|
-
* with {@link TAP_LEAF_VERSION} leaves, so any other version would
|
|
1486
|
-
* silently derive a different taproot key.
|
|
1487
|
-
*
|
|
1488
|
-
* @param tapTree - Encoded TapTree bytes
|
|
1489
|
-
* @returns Decoded virtual output script
|
|
1490
|
-
* @throws Error if the TapTree cannot be decoded into a valid script set
|
|
1491
|
-
* or a leaf carries a version other than {@link TAP_LEAF_VERSION}
|
|
1492
|
-
* @see encode
|
|
1493
|
-
*/
|
|
1494
|
-
static decode(tapTree: Bytes): VtxoScript;
|
|
1495
|
-
/**
|
|
1496
|
-
* Create a virtual output script from its tapleaf scripts.
|
|
1497
|
-
*
|
|
1498
|
-
* The Taproot script tree is assembled using btcd's algorithm
|
|
1499
|
-
* (`txscript.AssembleTaprootScriptTree`) so the derived taproot output
|
|
1500
|
-
* key agrees with arkd for any leaf count. `@scure/btc-signer`'s
|
|
1501
|
-
* default `taprootListToTree` is a Huffman builder that only agrees
|
|
1502
|
-
* with arkd for power-of-2 leaf counts.
|
|
1503
|
-
*
|
|
1504
|
-
* @param scripts - Raw tapscript bytes for each leaf
|
|
1505
|
-
* @throws Error if the provided leaves cannot produce a valid Taproot tree
|
|
1506
|
-
*/
|
|
1507
|
-
constructor(scripts: Bytes[]);
|
|
1508
|
-
/**
|
|
1509
|
-
* Encode the virtual output script to a TapTree byte representation.
|
|
1510
|
-
*
|
|
1511
|
-
* @returns Encoded TapTree bytes
|
|
1512
|
-
* @see decode
|
|
1513
|
-
*/
|
|
1514
|
-
encode(): Bytes;
|
|
1515
|
-
/**
|
|
1516
|
-
* Build the Arkade address corresponding to this virtual output script.
|
|
1517
|
-
*
|
|
1518
|
-
* @param prefix - Bech32 human-readable prefix
|
|
1519
|
-
* @param serverPubKey - 32-byte Arkade server public key
|
|
1520
|
-
* @returns Arkade address for this script
|
|
1521
|
-
* @see ArkAddress
|
|
1522
|
-
*/
|
|
1523
|
-
address(prefix: string | undefined, serverPubKey: Bytes): ArkAddress;
|
|
1524
|
-
/**
|
|
1525
|
-
* Build the Taproot onchain address corresponding to this virtual output script.
|
|
1526
|
-
*
|
|
1527
|
-
* @param network - Bitcoin network descriptor
|
|
1528
|
-
* @returns Taproot onchain address
|
|
1529
|
-
* @see address
|
|
1530
|
-
*/
|
|
1531
|
-
onchainAddress(network?: typeof NETWORK): string;
|
|
1532
|
-
/**
|
|
1533
|
-
* Look up a tapleaf script by its hex-encoded tapscript body.
|
|
1534
|
-
*
|
|
1535
|
-
* @param scriptHex - Hex-encoded tapscript body without the leaf version byte
|
|
1536
|
-
* @returns Matching tapleaf script
|
|
1537
|
-
* @throws Error if no matching leaf exists
|
|
1538
|
-
*/
|
|
1539
|
-
findLeaf(scriptHex: string): TapLeafScript;
|
|
1540
|
-
/**
|
|
1541
|
-
* Return all unilateral exit paths embedded in the virtual output script.
|
|
1542
|
-
*
|
|
1543
|
-
* @returns CSV-based exit paths found in the leaves
|
|
1544
|
-
* @see getSequence
|
|
1545
|
-
*/
|
|
1546
|
-
exitPaths(): Array<CSVMultisigTapscript.Type | ConditionCSVMultisigTapscript.Type>;
|
|
1547
|
-
}
|
|
1548
|
-
type EncodedVtxoScript = {
|
|
1549
|
-
tapTree: Bytes;
|
|
1550
|
-
};
|
|
1551
|
-
/**
|
|
1552
|
-
* Extract the timelock value encoded in a timelocked tapleaf, if any.
|
|
1553
|
-
*
|
|
1554
|
-
* The return value is unit-ambiguous: for a CSV leaf it is a BIP-68
|
|
1555
|
-
* nSequence (relative timelock); for a CLTV leaf it is an absolute
|
|
1556
|
-
* nLockTime. Callers must know which leaf shape they are inspecting to
|
|
1557
|
-
* interpret the number correctly, and must not copy a CSV result into
|
|
1558
|
-
* `Transaction.lockTime` (or vice versa).
|
|
1559
|
-
*
|
|
1560
|
-
* @param tapLeafScript - Tapleaf script to inspect
|
|
1561
|
-
* @returns The encoded timelock value, or `undefined` when neither a CSV
|
|
1562
|
-
* nor CLTV path is present
|
|
1563
|
-
* @see VtxoScript.exitPaths
|
|
1564
|
-
*/
|
|
1565
|
-
declare function getSequence(tapLeafScript: TapLeafScript): number | undefined;
|
|
1566
|
-
|
|
1567
|
-
type NetworkName = "bitcoin" | "testnet" | "signet" | "mutinynet" | "regtest";
|
|
1568
|
-
interface Network {
|
|
1569
|
-
hrp: string;
|
|
1570
|
-
bech32: string;
|
|
1571
|
-
pubKeyHash: number;
|
|
1572
|
-
scriptHash: number;
|
|
1573
|
-
wif: number;
|
|
1574
|
-
/**
|
|
1575
|
-
* Canonical name this network was resolved from, when known: the only way to tell the
|
|
1576
|
-
* tb-family apart (testnet, signet and mutinynet share every field above). Optional because a
|
|
1577
|
-
* hand-built `Network` has none — read a missing one as "unknown" and take the strictest branch.
|
|
1578
|
-
*/
|
|
1579
|
-
name?: NetworkName;
|
|
1580
|
-
}
|
|
1581
|
-
declare const getNetwork: (network: NetworkName) => Network;
|
|
1582
|
-
/**
|
|
1583
|
-
* The {@link Network} the operator's info names. {@link getNetwork} fails closed, so an
|
|
1584
|
-
* unrecognized network throws here rather than resolving to mainnet parameters downstream.
|
|
1585
|
-
* Structurally typed so the network table doesn't depend on the provider layer.
|
|
1586
|
-
*/
|
|
1587
|
-
declare const networkFromOperatorInfo: (info: {
|
|
1588
|
-
network: string;
|
|
1589
|
-
}) => Network;
|
|
1590
|
-
/** @deprecated Use {@link networkFromOperatorInfo}. */
|
|
1591
|
-
declare const networkFromArkadeInfo: (info: {
|
|
1592
|
-
network: string;
|
|
1593
|
-
}) => Network;
|
|
1594
|
-
declare const networks: {
|
|
1595
|
-
bitcoin: Network;
|
|
1596
|
-
testnet: Network;
|
|
1597
|
-
signet: Network;
|
|
1598
|
-
mutinynet: Network;
|
|
1599
|
-
regtest: Network;
|
|
1600
|
-
};
|
|
1601
|
-
/**
|
|
1602
|
-
* The operator's cosigner that emulates Arkade Script on mainnet, resolved by the
|
|
1603
|
-
* `{ network: "bitcoin" }` service. No trailing slash: `RestEmulatorProvider` appends its paths
|
|
1604
|
-
* verbatim. The URL only selects where to ask for a signature; the key covenants commit to is
|
|
1605
|
-
* {@link BITCOIN_EMULATOR_PUBKEY}.
|
|
1606
|
-
*/
|
|
1607
|
-
declare const DEFAULT_ARKADE_EMULATOR_URL: "https://emulator.arkade.computer";
|
|
1608
|
-
/** Key of the operator's cosigner that emulates Arkade Script on mainnet. */
|
|
1609
|
-
declare const BITCOIN_EMULATOR_PUBKEY: "0239c196415da47b26456a101daaa12ba9e445bfe153197f1e2b750bf40e52092e";
|
|
1610
|
-
/** Key of the operator's cosigner that emulates Arkade Script on mutinynet. */
|
|
1611
|
-
declare const MUTINYNET_EMULATOR_PUBKEY: "03f823b9b2febc81f4af967e77aed2f541cbd3397c6d8f5a72e32eb7b471af889a";
|
|
1612
|
-
/** Key of the operator's cosigner that emulates Arkade Script in the `arkade-regtest` stack. */
|
|
1613
|
-
declare const REGTEST_EMULATOR_PUBKEY: "02999413c46fa10ada5cbc4bcc79a1d09160c2ba3cfc812705d7a13e5e545fb2a9";
|
|
1614
|
-
/**
|
|
1615
|
-
* The pinned co-signer key for `network`, as 33-byte compressed lowercase hex.
|
|
1616
|
-
*
|
|
1617
|
-
* @throws if the network carries no name, or names one with no deployed emulator. Fail closed:
|
|
1618
|
-
* the key ends up in a covenant leaf deciding who can move the funds. Guessing a tb-family
|
|
1619
|
-
* neighbour's key locks funds to a co-signer that never signs; an empty string only moves the
|
|
1620
|
-
* failure. Deliberately NOT falling back to the emulator's self-reported key — that is the
|
|
1621
|
-
* trust this pin removes, and a silent fallback on an unnamed `Network` (which may carry
|
|
1622
|
-
* mainnet-equivalent parameters) would lapse it exactly where it matters most. Callers who mean
|
|
1623
|
-
* it pass {@link resolveEmulatorPubkey}'s override, which the thrown message names.
|
|
1624
|
-
*/
|
|
1625
|
-
declare function defaultEmulatorPubkey(network: Network): string;
|
|
1626
|
-
/**
|
|
1627
|
-
* Resolve the co-signer key for `network`, letting a caller substitute its own, for:
|
|
1628
|
-
*
|
|
1629
|
-
* 1. **A network rotated its emulator key before this SDK shipped the new constant.**
|
|
1630
|
-
* `Arkade.connect` no longer asks the service, so covenants would keep building against the
|
|
1631
|
-
* retired key and fail only at claim time; the override makes rotation a config change.
|
|
1632
|
-
* 2. A private or self-hosted emulator, including on unpinned networks.
|
|
1633
|
-
* 3. Tests and local stacks.
|
|
1634
|
-
*
|
|
1635
|
-
* Supplying it means trusting that operator in place of the network's: covenants built from the
|
|
1636
|
-
* key can be completed by its holder and no one else. A malformed override throws rather than
|
|
1637
|
-
* surfacing later as an unspendable contract.
|
|
1638
|
-
*/
|
|
1639
|
-
declare function resolveEmulatorPubkey(network: Network, override?: string): string;
|
|
1640
|
-
|
|
1422
|
+
declare function resolveEmulatorPubkey(network: Network, override?: string): string;
|
|
1423
|
+
|
|
1641
1424
|
/**
|
|
1642
1425
|
* The default base URLs for esplora API providers: Ark Labs–operated mempool deployments, except
|
|
1643
1426
|
* testnet (public mempool.space; Ark doesn't host it) and regtest (a local arkade-regtest stack).
|
|
@@ -1646,16 +1429,24 @@ declare const ESPLORA_URL: Record<NetworkName, string>;
|
|
|
1646
1429
|
type ExplorerTransaction = {
|
|
1647
1430
|
txid: string;
|
|
1648
1431
|
/**
|
|
1649
|
-
* Spent outpoints, as returned by Esplora's `/address/:addr/txs
|
|
1650
|
-
*
|
|
1432
|
+
* Spent outpoints, as returned by Esplora's `/address/:addr/txs` and built from the raw tx by
|
|
1433
|
+
* the electrum provider. `getBoardingTxs` reads a boarding output's spender (commitment tx)
|
|
1434
|
+
* from them and asks `getTxOutspend(s)` only when no listed tx spends it, so a provider that
|
|
1435
|
+
* sets this saves one outspend request per settled boarding output. Leave it unset when
|
|
1436
|
+
* unknown: the outspend request then runs as before.
|
|
1651
1437
|
*/
|
|
1652
1438
|
vin?: {
|
|
1653
1439
|
txid: string;
|
|
1654
1440
|
vout: number;
|
|
1441
|
+
/** Set by Esplora; the electrum provider omits it. */
|
|
1442
|
+
prevout?: {
|
|
1443
|
+
scriptpubkey_address?: string;
|
|
1444
|
+
};
|
|
1655
1445
|
}[];
|
|
1656
1446
|
vout: {
|
|
1657
1447
|
scriptpubkey_address: string;
|
|
1658
|
-
|
|
1448
|
+
/** Output amount in satoshis, matching Esplora's numeric JSON field. */
|
|
1449
|
+
value: number;
|
|
1659
1450
|
}[];
|
|
1660
1451
|
status: {
|
|
1661
1452
|
confirmed: boolean;
|
|
@@ -1758,6 +1549,11 @@ interface OnchainProvider {
|
|
|
1758
1549
|
time: number;
|
|
1759
1550
|
hash: string;
|
|
1760
1551
|
}>;
|
|
1552
|
+
/**
|
|
1553
|
+
* Fetch consensus median-time-past for a block at the given height. Providers that do not
|
|
1554
|
+
* implement this cannot determine seconds-based relative-lock expiry from chain data.
|
|
1555
|
+
*/
|
|
1556
|
+
getMedianTimePast?(height: number): Promise<number>;
|
|
1761
1557
|
/**
|
|
1762
1558
|
* Watch a set of addresses and invoke the callback when transactions are observed.
|
|
1763
1559
|
*
|
|
@@ -1837,6 +1633,7 @@ declare class EsploraProvider implements OnchainProvider {
|
|
|
1837
1633
|
time: number;
|
|
1838
1634
|
hash: string;
|
|
1839
1635
|
}>;
|
|
1636
|
+
getMedianTimePast(height: number): Promise<number>;
|
|
1840
1637
|
private broadcastPackage;
|
|
1841
1638
|
private broadcastTx;
|
|
1842
1639
|
}
|
|
@@ -2185,7 +1982,7 @@ interface MigrationVtxoRef {
|
|
|
2185
1982
|
}
|
|
2186
1983
|
/**
|
|
2187
1984
|
* Machine-readable status for a single deprecated signer the wallet holds funds under. Derived at
|
|
2188
|
-
* read time from contract params plus a fresh {@link
|
|
1985
|
+
* read time from contract params plus a fresh {@link OperatorInfo} snapshot — never persisted.
|
|
2189
1986
|
*/
|
|
2190
1987
|
interface DeprecatedSignerReport {
|
|
2191
1988
|
/** Deprecated signer key (x-only hex). */
|
|
@@ -2347,7 +2144,17 @@ interface IVtxoManager {
|
|
|
2347
2144
|
}>;
|
|
2348
2145
|
getExpiringVtxos(thresholdMs?: number): Promise<ExtendedVirtualCoin[]>;
|
|
2349
2146
|
renewVtxos(eventCallback?: (event: SettlementEvent) => void, options?: RenewVtxosOptions): Promise<string>;
|
|
2147
|
+
/**
|
|
2148
|
+
* Boarding inputs whose own timelock has elapsed, at every boarding address the wallet shows,
|
|
2149
|
+
* including those under a deprecated signer.
|
|
2150
|
+
*/
|
|
2350
2151
|
getExpiredBoardingUtxos(): Promise<ExtendedCoin[]>;
|
|
2152
|
+
/**
|
|
2153
|
+
* Sweep the expired boarding inputs from {@link getExpiredBoardingUtxos} back to the current
|
|
2154
|
+
* boarding address via the unilateral exit path, which needs no operator.
|
|
2155
|
+
*
|
|
2156
|
+
* @returns The broadcast transaction ID
|
|
2157
|
+
*/
|
|
2351
2158
|
sweepExpiredBoardingUtxos(): Promise<string>;
|
|
2352
2159
|
/**
|
|
2353
2160
|
* Cooperatively migrate VTXOs minted under a now-deprecated server signer to the wallet's
|
|
@@ -2567,6 +2374,8 @@ declare class VtxoManager implements AsyncDisposable, IVtxoManager {
|
|
|
2567
2374
|
/**
|
|
2568
2375
|
* Get boarding inputs whose timelock has expired: they can no longer be onboarded via
|
|
2569
2376
|
* `settle()` and must be swept back to a fresh boarding address via the unilateral exit path.
|
|
2377
|
+
* Covers every boarding address the wallet shows, including those under a deprecated signer,
|
|
2378
|
+
* and judges each input by the timelock of its own address.
|
|
2570
2379
|
*
|
|
2571
2380
|
* @returns Array of expired boarding inputs
|
|
2572
2381
|
*
|
|
@@ -2580,11 +2389,18 @@ declare class VtxoManager implements AsyncDisposable, IVtxoManager {
|
|
|
2580
2389
|
* ```
|
|
2581
2390
|
*/
|
|
2582
2391
|
getExpiredBoardingUtxos(prefetchedUtxos?: ExtendedCoin[]): Promise<ExtendedCoin[]>;
|
|
2392
|
+
/**
|
|
2393
|
+
* Renew the boarding coins nearing cosign cut-off through an arkd
|
|
2394
|
+
* cosignature; unrolled outputs are never swept here. Returns the txid, or
|
|
2395
|
+
* undefined when nothing qualified or the cosign path is unavailable.
|
|
2396
|
+
*/
|
|
2397
|
+
sweepOnchainCoins(): Promise<string | undefined>;
|
|
2583
2398
|
/**
|
|
2584
2399
|
* Sweep expired boarding inputs back to a fresh boarding address via the unilateral exit path:
|
|
2585
2400
|
* one pure onchain tx (no Arkade server) spending every expired input via the CSV exit script
|
|
2586
2401
|
* into a single boarding-address output, which restarts the timelock. Skipped if the output
|
|
2587
|
-
* after fees would be below dust.
|
|
2402
|
+
* after fees would be below dust. Covers boarding inputs under a deprecated signer too: the
|
|
2403
|
+
* exit leaf is the user's key plus a CSV, so it never needs the operator.
|
|
2588
2404
|
*
|
|
2589
2405
|
* @returns The broadcast transaction ID
|
|
2590
2406
|
* @throws Error if no expired boarding inputs are found
|
|
@@ -2620,8 +2436,9 @@ declare class VtxoManager implements AsyncDisposable, IVtxoManager {
|
|
|
2620
2436
|
* Status of every deprecated server signer the wallet holds funds under (VTXO and boarding,
|
|
2621
2437
|
* merged per signer), without migrating.
|
|
2622
2438
|
*
|
|
2623
|
-
* @remarks
|
|
2624
|
-
* (`getCoins` round trips) and
|
|
2439
|
+
* @remarks This is no longer a pure repository/info read: surfacing boarding
|
|
2440
|
+
* holdings fans out per boarding address (`getCoins` round trips) and
|
|
2441
|
+
* syncs those coins into the contract manager's store.
|
|
2625
2442
|
*/
|
|
2626
2443
|
getDeprecatedSignerStatus(): Promise<DeprecatedSignerReport[]>;
|
|
2627
2444
|
/**
|
|
@@ -2680,7 +2497,9 @@ declare class VtxoManager implements AsyncDisposable, IVtxoManager {
|
|
|
2680
2497
|
*/
|
|
2681
2498
|
private anyInputUnderDeprecatedSigner;
|
|
2682
2499
|
private getSweepWallet;
|
|
2683
|
-
|
|
2500
|
+
/** The signer `settle` can cooperate with: the one the wallet's boarding address is built on. */
|
|
2501
|
+
private getCurrentSigner;
|
|
2502
|
+
private boardingExpiry;
|
|
2684
2503
|
private getOnchainProvider;
|
|
2685
2504
|
private getOperatorProvider;
|
|
2686
2505
|
/**
|
|
@@ -2758,14 +2577,20 @@ interface ContractFilter {
|
|
|
2758
2577
|
* @see ContractWatchState
|
|
2759
2578
|
*/
|
|
2760
2579
|
watch?: ContractWatchState | ContractWatchState[];
|
|
2580
|
+
/**
|
|
2581
|
+
* Filter by scope(s). Rows without a stored scope resolve via
|
|
2582
|
+
* `scopeOf`.
|
|
2583
|
+
*/
|
|
2584
|
+
scope?: ContractScope | ContractScope[];
|
|
2761
2585
|
}
|
|
2762
2586
|
interface ContractRepository extends AsyncDisposable {
|
|
2763
2587
|
/**
|
|
2764
2588
|
* 2 — {@link Contract.watch}. An implementation must persist and
|
|
2765
2589
|
* round-trip it, and treat a row without one as `"watched"`.
|
|
2766
2590
|
* 3 — the unpaged `getContracts` is gone; implement `getContractsPage`.
|
|
2591
|
+
* 4 — persist contract scope; absent scope resolves via its handler.
|
|
2767
2592
|
*/
|
|
2768
|
-
readonly version:
|
|
2593
|
+
readonly version: 4;
|
|
2769
2594
|
/**
|
|
2770
2595
|
* Clear all data from storage.
|
|
2771
2596
|
*/
|
|
@@ -2783,19 +2608,24 @@ interface ContractRepository extends AsyncDisposable {
|
|
|
2783
2608
|
}
|
|
2784
2609
|
declare const collectContracts: (repository: Pick<ContractRepository, "getContractsPage">, filter?: ContractFilter) => Promise<Contract[]>;
|
|
2785
2610
|
|
|
2786
|
-
type
|
|
2787
|
-
declare const
|
|
2788
|
-
declare function
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2611
|
+
type BatchRegistrationState = "waiting_to_submit" | "waiting_for_batch" | "batch_in_progress" | "batch_failed" | "batch_succeeded" | "cancelled";
|
|
2612
|
+
declare const BATCH_REGISTRATION_TERMINAL_STATES: ReadonlySet<BatchRegistrationState>;
|
|
2613
|
+
declare function isTerminalBatchRegistrationState(s: BatchRegistrationState): boolean;
|
|
2614
|
+
/**
|
|
2615
|
+
* A wallet's request to join a batch, tracked from signing to its terminal state.
|
|
2616
|
+
* Backends keep their older column and key names on disk and map them here. No data
|
|
2617
|
+
* migration runs, so an in-flight lock survives an upgrade or a rollback.
|
|
2618
|
+
*/
|
|
2619
|
+
interface BatchRegistration {
|
|
2620
|
+
/** Register proof tx id. Primary key. */
|
|
2621
|
+
proofTxId: string;
|
|
2622
|
+
/**
|
|
2623
|
+
* Operator-assigned registration id. Unique when present: saving a *different*
|
|
2624
|
+
* proofTxId that reuses a live registrationId is rejected (NArk parity). Absent
|
|
2625
|
+
* until the proof is registered with the operator.
|
|
2626
|
+
*/
|
|
2627
|
+
registrationId?: string;
|
|
2628
|
+
state: BatchRegistrationState;
|
|
2799
2629
|
validFrom?: number;
|
|
2800
2630
|
validUntil?: number;
|
|
2801
2631
|
createdAt: number;
|
|
@@ -2812,30 +2642,40 @@ interface ArkIntent {
|
|
|
2812
2642
|
cancellationReason?: string;
|
|
2813
2643
|
partialForfeits: string[];
|
|
2814
2644
|
signerDescriptor?: string;
|
|
2815
|
-
/**
|
|
2816
|
-
|
|
2645
|
+
/** Inputs locked by this registration. */
|
|
2646
|
+
proofInputs: Outpoint[];
|
|
2817
2647
|
}
|
|
2818
|
-
interface
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
/**
|
|
2648
|
+
interface BatchRegistrationFilter {
|
|
2649
|
+
proofTxIds?: string[];
|
|
2650
|
+
registrationIds?: string[];
|
|
2651
|
+
/** Registrations whose `proofInputs` intersect any of these outpoints. */
|
|
2822
2652
|
containingInputs?: Outpoint[];
|
|
2823
|
-
states?:
|
|
2653
|
+
states?: BatchRegistrationState[];
|
|
2824
2654
|
/** Intents valid at this ms-epoch instant (null bounds = open). */
|
|
2825
2655
|
validAt?: number;
|
|
2826
|
-
/** Substring match over
|
|
2656
|
+
/** Substring match over registrationId, batchId, commitmentTransactionId. */
|
|
2827
2657
|
searchText?: string;
|
|
2828
2658
|
}
|
|
2829
|
-
type
|
|
2830
|
-
|
|
2659
|
+
type BatchRegistrationPageFilter = BatchRegistrationFilter;
|
|
2660
|
+
/** @deprecated Use {@link BatchRegistration}. */
|
|
2661
|
+
type ArkIntent = BatchRegistration;
|
|
2662
|
+
/** @deprecated Use {@link BatchRegistrationFilter}. */
|
|
2663
|
+
type IntentFilter = BatchRegistrationFilter;
|
|
2664
|
+
/** @deprecated Use {@link BatchRegistrationPageFilter}. */
|
|
2665
|
+
type IntentPageFilter = BatchRegistrationPageFilter;
|
|
2666
|
+
interface BatchRegistrationRepository extends AsyncDisposable {
|
|
2831
2667
|
readonly version: 1;
|
|
2832
2668
|
clear(): Promise<void>;
|
|
2833
|
-
/** Upsert by
|
|
2834
|
-
|
|
2835
|
-
/**
|
|
2836
|
-
|
|
2837
|
-
/**
|
|
2838
|
-
|
|
2669
|
+
/** Upsert by primary key; implementation sets `updatedAt = Date.now()`. */
|
|
2670
|
+
saveBatchRegistration(intent: BatchRegistration): Promise<void>;
|
|
2671
|
+
/** @deprecated Use {@link saveBatchRegistration}. */
|
|
2672
|
+
saveIntent: BatchRegistrationRepository["saveBatchRegistration"];
|
|
2673
|
+
/** Bounded registrations in primary key order, not chronological order; `after` is exclusive. */
|
|
2674
|
+
getBatchRegistrationsPage(filter: BatchRegistrationPageFilter | undefined, page: PageRequest): Promise<PageResult<BatchRegistration>>;
|
|
2675
|
+
/** @deprecated Use {@link getBatchRegistrationsPage}. */
|
|
2676
|
+
getIntentsPage: BatchRegistrationRepository["getBatchRegistrationsPage"];
|
|
2677
|
+
/**
|
|
2678
|
+
* Outpoints held by NON-terminal registrations — `waiting_to_submit`,
|
|
2839
2679
|
* `waiting_for_batch`, and `batch_in_progress` — to exclude from spendable
|
|
2840
2680
|
* balance. Terminal states never lock.
|
|
2841
2681
|
*
|
|
@@ -2844,12 +2684,22 @@ interface IntentRepository extends AsyncDisposable {
|
|
|
2844
2684
|
* offline-first and reads this set as its single source of coin locking, so
|
|
2845
2685
|
* it must also hold inputs already committed to an in-progress batch. NArk
|
|
2846
2686
|
* excludes `BatchInProgress` here but protects those inputs through its
|
|
2847
|
-
*
|
|
2687
|
+
* own services instead.
|
|
2848
2688
|
*/
|
|
2849
2689
|
getLockedVtxoOutpoints(): Promise<Outpoint[]>;
|
|
2850
2690
|
}
|
|
2851
|
-
/** Collects in
|
|
2852
|
-
declare const
|
|
2691
|
+
/** Collects in primary key order; sort by `createdAt` for chronological display. */
|
|
2692
|
+
declare const collectBatchRegistrations: (repository: Pick<BatchRegistrationRepository, "getBatchRegistrationsPage">, filter?: BatchRegistrationPageFilter) => Promise<BatchRegistration[]>;
|
|
2693
|
+
/** @deprecated Use {@link BatchRegistrationState}. */
|
|
2694
|
+
type ArkIntentState = BatchRegistrationState;
|
|
2695
|
+
/** @deprecated Use {@link BatchRegistrationRepository}. */
|
|
2696
|
+
type IntentRepository = BatchRegistrationRepository;
|
|
2697
|
+
/** @deprecated Use {@link isTerminalBatchRegistrationState}. */
|
|
2698
|
+
declare const isTerminalIntentState: typeof isTerminalBatchRegistrationState;
|
|
2699
|
+
/** @deprecated Use {@link BATCH_REGISTRATION_TERMINAL_STATES}. */
|
|
2700
|
+
declare const INTENT_TERMINAL_STATES: ReadonlySet<BatchRegistrationState>;
|
|
2701
|
+
/** @deprecated Use {@link collectBatchRegistrations}. */
|
|
2702
|
+
declare const collectIntents: (repository: Pick<BatchRegistrationRepository, "getBatchRegistrationsPage">, filter?: BatchRegistrationPageFilter) => Promise<BatchRegistration[]>;
|
|
2853
2703
|
|
|
2854
2704
|
/**
|
|
2855
2705
|
* Type of a tx inside a VTXO's chain (commitment → leaf), as reported by
|
|
@@ -2899,191 +2749,432 @@ interface VirtualTxRepository extends AsyncDisposable {
|
|
|
2899
2749
|
pruneForSpentVtxo(vtxo: Outpoint): Promise<void>;
|
|
2900
2750
|
}
|
|
2901
2751
|
|
|
2902
|
-
/**
|
|
2903
|
-
|
|
2904
|
-
* for every VTXO locked to the same contract, so they can be memoized per
|
|
2905
|
-
* contract (see {@link ContractTapscriptCache}).
|
|
2906
|
-
*/
|
|
2907
|
-
type ContractTapscripts = Pick<ExtendedVirtualCoin, "forfeitTapLeafScript" | "intentTapLeafScript" | "tapTree">;
|
|
2908
|
-
/**
|
|
2909
|
-
* Cache of per-contract tapscript data, keyed by `contract.script`. Building
|
|
2910
|
-
* the taproot tree via `handler.createScript(contract.params)` is the dominant
|
|
2911
|
-
* cost when annotating large VTXO sets; passing a shared cache across an
|
|
2912
|
-
* annotation batch rebuilds it once per distinct contract instead of once per
|
|
2913
|
-
* VTXO (see #521).
|
|
2914
|
-
*/
|
|
2915
|
-
type ContractTapscriptCache = Map<string, ContractTapscripts>;
|
|
2916
|
-
declare function getRandomId(): string;
|
|
2917
|
-
/**
|
|
2918
|
-
* What a recipient Arkade address must match. An address failing either check
|
|
2919
|
-
* belongs to another network or operator, so this wallet's operator cannot
|
|
2920
|
-
* create the VTXO where the recipient's wallet expects it.
|
|
2921
|
-
*/
|
|
2922
|
-
type RecipientArkadeAddressContext = {
|
|
2923
|
-
hrp: string;
|
|
2924
|
-
signerSet: SignerSet;
|
|
2925
|
-
};
|
|
2926
|
-
/**
|
|
2927
|
-
* The embedded server key may be the current signer or a deprecated signer
|
|
2928
|
-
* whose rotation cutoff has not passed.
|
|
2929
|
-
*/
|
|
2930
|
-
declare function assertRecipientArkadeAddress(encoded: string, address: ArkAddress, context: RecipientArkadeAddressContext): void;
|
|
2931
|
-
|
|
2932
|
-
/** Minimal indexer surface the reconciler needs. */
|
|
2933
|
-
type IntentReconcilerIndexer = Pick<IndexerProvider, "getVtxos">;
|
|
2934
|
-
interface IntentReconciliationDeps {
|
|
2935
|
-
intentRepository: IntentRepository;
|
|
2936
|
-
indexerProvider: IntentReconcilerIndexer;
|
|
2752
|
+
/** One transaction's participation in one logical action. */
|
|
2753
|
+
interface GroupMembership {
|
|
2937
2754
|
/**
|
|
2938
|
-
*
|
|
2939
|
-
*
|
|
2755
|
+
* Stable id of the action; txs sharing it group together. Third-party
|
|
2756
|
+
* resolvers should namespace it (`"vendor:thing"`) to avoid colliding with
|
|
2757
|
+
* other resolvers' groups. SDK built-ins use namespaced ids such as `boarding:`.
|
|
2758
|
+
* A membership with an empty groupId is dropped.
|
|
2759
|
+
*/
|
|
2760
|
+
groupId: string;
|
|
2761
|
+
/** Human label for the action, e.g. "Dice game". */
|
|
2762
|
+
label?: string;
|
|
2763
|
+
/** App category for icon/filtering, e.g. "game". */
|
|
2764
|
+
kind?: string;
|
|
2765
|
+
/**
|
|
2766
|
+
* Outcome of the action this membership belongs to, e.g. "failed",
|
|
2767
|
+
* "refunded" — an opaque machine token for the app to map to its own
|
|
2768
|
+
* copy or icon, not display text. Merged first-writer-wins across
|
|
2769
|
+
* resolvers sharing a `groupId`, like `label` and `kind`.
|
|
2940
2770
|
*/
|
|
2941
|
-
|
|
2771
|
+
outcome?: string;
|
|
2942
2772
|
/**
|
|
2943
|
-
*
|
|
2944
|
-
*
|
|
2773
|
+
* Free-form row data. Same-group metadata is shallow-merged with
|
|
2774
|
+
* earlier-resolver keys winning.
|
|
2945
2775
|
*/
|
|
2946
|
-
|
|
2947
|
-
/**
|
|
2948
|
-
|
|
2776
|
+
metadata?: Record<string, unknown>;
|
|
2777
|
+
/**
|
|
2778
|
+
* This tx's unsigned sat contribution to this group. Defaults to the tx's
|
|
2779
|
+
* full amount; the builder applies direction. Use it to split a batched tx
|
|
2780
|
+
* across groups. Same-key receive rows paired with a sent row are treated
|
|
2781
|
+
* as change and excluded from `Activity.amount`. A membership with a
|
|
2782
|
+
* non-finite amount (NaN/Infinity) is dropped.
|
|
2783
|
+
*/
|
|
2784
|
+
amount?: number;
|
|
2949
2785
|
}
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
* An input for {@link IContractManager.assertSpendableNow}.
|
|
2953
|
-
*
|
|
2954
|
-
* Prefer passing a full {@link VirtualCoin}: a relative (CSV) timelock is measured from the
|
|
2955
|
-
* coin's own confirmation (`status.block_height` / `status.block_time`). The bare shape still
|
|
2956
|
-
* answers every absolute (CLTV) question.
|
|
2957
|
-
*/
|
|
2958
|
-
type AssertSpendableInput = {
|
|
2959
|
-
txid: string;
|
|
2960
|
-
vout: number;
|
|
2961
|
-
script: string;
|
|
2962
|
-
};
|
|
2963
|
-
type RefreshVtxosOptions = {
|
|
2964
|
-
/** Narrow the refresh to these scripts. A subset query, so the sync cursor does not advance. */
|
|
2965
|
-
scripts?: string[];
|
|
2966
|
-
/** Time window overriding the cursor-derived one. The cursor never advances on a window. */
|
|
2967
|
-
after?: number;
|
|
2968
|
-
/** @see after */
|
|
2969
|
-
before?: number;
|
|
2970
|
-
/**
|
|
2971
|
-
* When true and `scripts` is not set, refresh every repository contract rather than the
|
|
2972
|
-
* watcher's watched set. A superset, so the cursor still advances (absent `after`/`before`).
|
|
2973
|
-
*
|
|
2974
|
-
* @defaultValue `false`
|
|
2975
|
-
*/
|
|
2976
|
-
includeInactive?: boolean;
|
|
2977
|
-
};
|
|
2978
|
-
/**
|
|
2979
|
-
* A single `Discoverable` handler's discovery failure, captured during a
|
|
2980
|
-
* {@link IContractManager.scanContracts} run instead of aborting the loop.
|
|
2981
|
-
*/
|
|
2982
|
-
interface HandlerError {
|
|
2983
|
-
handler: string;
|
|
2984
|
-
/** The failed index, or the first index of a failed `discoverRange` window. */
|
|
2985
|
-
fromIndex: number;
|
|
2986
|
-
/** Inclusive end of a failed `discoverRange` window; absent for a single index. */
|
|
2987
|
-
toIndex?: number;
|
|
2988
|
-
error: unknown;
|
|
2989
|
-
}
|
|
2990
|
-
/** Outcome of a {@link IContractManager.scanContracts} run. */
|
|
2991
|
-
interface ScanResult {
|
|
2786
|
+
/** A pluggable resolver keyed by `id`. */
|
|
2787
|
+
interface ActivityResolver {
|
|
2992
2788
|
/**
|
|
2993
|
-
*
|
|
2994
|
-
*
|
|
2995
|
-
*
|
|
2789
|
+
* Registry key — override or remove by it. Namespace it (`"vendor:games"`)
|
|
2790
|
+
* so independent libraries don't clobber each other; `use()` overwrites
|
|
2791
|
+
* silently on a duplicate id.
|
|
2996
2792
|
*/
|
|
2997
|
-
|
|
2793
|
+
id: string;
|
|
2998
2794
|
/**
|
|
2999
|
-
*
|
|
3000
|
-
*
|
|
3001
|
-
* scan closed a genuine gap.
|
|
2795
|
+
* Load correlation data before `resolve` runs. If it rejects, this resolver
|
|
2796
|
+
* contributes no memberships.
|
|
3002
2797
|
*/
|
|
3003
|
-
|
|
3004
|
-
/**
|
|
3005
|
-
|
|
2798
|
+
prepare?(): Promise<void>;
|
|
2799
|
+
/** Pure and synchronous. The groups this tx belongs to, or undefined to leave it plain. */
|
|
2800
|
+
resolve(tx: ArkTransaction): GroupMembership[] | undefined;
|
|
3006
2801
|
}
|
|
3007
|
-
/**
|
|
3008
|
-
interface
|
|
3009
|
-
/**
|
|
3010
|
-
|
|
2802
|
+
/** The non-id, non-amount part of a {@link GroupMembership}. */
|
|
2803
|
+
interface ActivityIntent {
|
|
2804
|
+
/** Human label for the action, e.g. "Dice game". */
|
|
2805
|
+
label?: string;
|
|
2806
|
+
/** App category for icon/filtering, e.g. "game". */
|
|
2807
|
+
kind?: string;
|
|
3011
2808
|
/**
|
|
3012
|
-
*
|
|
3013
|
-
*
|
|
3014
|
-
*
|
|
2809
|
+
* Resolver-declared outcome for the group, e.g. "failed", "refunded" — an
|
|
2810
|
+
* opaque machine token for the app to map to its own copy or icon, not
|
|
2811
|
+
* display text.
|
|
3015
2812
|
*/
|
|
3016
|
-
|
|
3017
|
-
/**
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
2813
|
+
outcome?: string;
|
|
2814
|
+
/** Free-form row data, shallow-merged across the group's resolvers (first-writer-wins). */
|
|
2815
|
+
metadata?: Record<string, unknown>;
|
|
2816
|
+
}
|
|
2817
|
+
/** One logical activity. */
|
|
2818
|
+
interface Activity {
|
|
2819
|
+
/** The groupId, or the natural tx key for untagged rows. */
|
|
2820
|
+
id: string;
|
|
2821
|
+
/** Merged intent for the group, if any resolver tagged it. */
|
|
2822
|
+
intent?: ActivityIntent;
|
|
2823
|
+
/** Member txs, oldest-first. */
|
|
2824
|
+
txs: ArkTransaction[];
|
|
2825
|
+
/** Signed net sats: positive received, negative sent; same-key change rows are excluded. */
|
|
2826
|
+
amount: number;
|
|
2827
|
+
/** Earliest member createdAt (ms since epoch). */
|
|
2828
|
+
createdAt: number;
|
|
2829
|
+
/** True once every member tx is settled. */
|
|
2830
|
+
settled: boolean;
|
|
2831
|
+
}
|
|
2832
|
+
/** Resolver registry keyed by id. */
|
|
2833
|
+
declare class ActivityRegistry {
|
|
2834
|
+
private readonly resolvers;
|
|
2835
|
+
/** Add a resolver, or override an existing one with the same id (kept in place). */
|
|
2836
|
+
use(resolver: ActivityResolver): void;
|
|
2837
|
+
/** Remove a resolver (built-in or custom) by id. */
|
|
2838
|
+
remove(id: string): void;
|
|
2839
|
+
/** The registered resolver ids, in registration order. */
|
|
2840
|
+
list(): string[];
|
|
2841
|
+
/** All registered resolvers, in registration (priority) order. */
|
|
2842
|
+
all(): ActivityResolver[];
|
|
3023
2843
|
}
|
|
2844
|
+
/** Built-in resolver: labels on-chain boarding (deposit) transactions. */
|
|
2845
|
+
declare function boardingResolver(): ActivityResolver;
|
|
2846
|
+
/** Built-in resolver: labels collaborative exits (VTXOs forfeited to chain in a batch). */
|
|
2847
|
+
declare function collabExitResolver(): ActivityResolver;
|
|
3024
2848
|
/**
|
|
3025
|
-
*
|
|
3026
|
-
*
|
|
3027
|
-
*
|
|
2849
|
+
* Built-in resolver: labels the genesis transaction of a minted asset — "Asset
|
|
2850
|
+
* mint" on the issuer's sent tx, "Asset receive" when the fresh supply arrives
|
|
2851
|
+
* in the genesis tx itself. An asset id encodes its genesis txid; reissues and
|
|
2852
|
+
* transfers carry the asset under a different `arkTxid`, so they are left plain.
|
|
3028
2853
|
*
|
|
3029
|
-
* `
|
|
3030
|
-
*
|
|
3031
|
-
*
|
|
2854
|
+
* `metadata.amount` is the decimal string of the asset's `bigint` amount, kept
|
|
2855
|
+
* as a string so large supplies survive JSON round-trips without truncation.
|
|
2856
|
+
* Recover the value with `BigInt(metadata.amount as string)` — using it
|
|
2857
|
+
* directly in arithmetic coerces (`"10" + 1` is `"101"`, not `11`) and loses
|
|
2858
|
+
* precision past `Number.MAX_SAFE_INTEGER`.
|
|
3032
2859
|
*/
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
2860
|
+
declare function assetMintResolver(): ActivityResolver;
|
|
2861
|
+
/**
|
|
2862
|
+
* A registry pre-populated with the SDK's built-in resolvers: `boarding`,
|
|
2863
|
+
* `collab-exit`, and `asset-mint`.
|
|
2864
|
+
*/
|
|
2865
|
+
declare function createDefaultActivityRegistry(): ActivityRegistry;
|
|
2866
|
+
|
|
2867
|
+
/**
|
|
2868
|
+
* A source of unilateral-exit chain data for a set of VTXOs. Sources are tried
|
|
2869
|
+
* in order by the resolver; a source returns `null` (chain) or omits keys (psbts)
|
|
2870
|
+
* for data it cannot supply — a "miss" — and the resolver falls through.
|
|
2871
|
+
*/
|
|
2872
|
+
interface ExitDataSource {
|
|
2873
|
+
readonly name: string;
|
|
2874
|
+
/** Full ancestry chain for a vtxo (all pages merged), or null on a miss. */
|
|
2875
|
+
getVtxoChain(vtxo: Outpoint): Promise<ChainTx[] | null>;
|
|
2876
|
+
/** Base64 PSBTs this source has, keyed by (unsigned) txid. Absent key = miss. */
|
|
2877
|
+
getVirtualTxs(txids: string[]): Promise<Map<string, string>>;
|
|
2878
|
+
}
|
|
2879
|
+
/** Reads exit chain data through an ordered chain of sources. */
|
|
2880
|
+
interface ExitChainResolver {
|
|
2881
|
+
getVtxoChain(vtxo: Outpoint): Promise<ChainTx[]>;
|
|
2882
|
+
getVirtualTxs(txids: string[]): Promise<string[]>;
|
|
2883
|
+
}
|
|
2884
|
+
/**
|
|
2885
|
+
* Assemble the standard exit-data resolver: local repo (if configured) → any
|
|
2886
|
+
* extra sources (e.g. a future provider) → indexer. Read-through persists to the
|
|
2887
|
+
* repository. With no repository this is exactly the indexer path (a no-op seam).
|
|
2888
|
+
*/
|
|
2889
|
+
declare function createExitChainResolver(params: {
|
|
2890
|
+
indexer: IndexerProvider;
|
|
2891
|
+
repository?: VirtualTxRepository;
|
|
2892
|
+
extraSources?: ExitDataSource[];
|
|
2893
|
+
}): ExitChainResolver;
|
|
2894
|
+
|
|
2895
|
+
type ExitCaptureMode = "lite" | "full";
|
|
2896
|
+
|
|
2897
|
+
/** Delegate identity and fee information returned by `getDelegateInfo`. */
|
|
2898
|
+
interface DelegateInfo {
|
|
2899
|
+
/** Delegate public key. */
|
|
2900
|
+
pubkey: string;
|
|
2901
|
+
/** Delegate fee amount or expression returned by the delegate. */
|
|
2902
|
+
fee: string;
|
|
2903
|
+
/** Address for delegate fee collection. */
|
|
2904
|
+
delegateAddress: string;
|
|
2905
|
+
}
|
|
2906
|
+
/** Optional delegate behavior flags. */
|
|
2907
|
+
interface DelegateOptions {
|
|
3044
2908
|
/**
|
|
3045
|
-
*
|
|
3046
|
-
*
|
|
2909
|
+
* Tell the delegate not to replace an existing delegation (signed register intent + its
|
|
2910
|
+
* forfeits) that already includes at least one virtual output from this request.
|
|
2911
|
+
*
|
|
2912
|
+
* @defaultValue `false`
|
|
3047
2913
|
*/
|
|
3048
|
-
|
|
2914
|
+
rejectReplace?: boolean;
|
|
2915
|
+
}
|
|
2916
|
+
/** Provider interface for a remote delegation service. */
|
|
2917
|
+
interface DelegateProvider {
|
|
3049
2918
|
/**
|
|
3050
|
-
*
|
|
3051
|
-
*
|
|
2919
|
+
* Request delegation for a signed register intent and its forfeit transactions.
|
|
2920
|
+
*
|
|
2921
|
+
* @param forfeitTxs - Forfeit transactions associated with the delegation request
|
|
3052
2922
|
*/
|
|
3053
|
-
|
|
2923
|
+
delegate(intent: SignedProof<Proof.RegisterMessage>, forfeitTxs: string[], options?: DelegateOptions): Promise<void>;
|
|
2924
|
+
/** Fetch delegate metadata: pubkey, fee, and delegate address. */
|
|
2925
|
+
getDelegateInfo(): Promise<DelegateInfo>;
|
|
2926
|
+
}
|
|
2927
|
+
/**
|
|
2928
|
+
* REST-based delegate provider implementation.
|
|
2929
|
+
* @example
|
|
2930
|
+
* ```typescript
|
|
2931
|
+
* const provider = new RestDelegateProvider('https://delegate.example.com');
|
|
2932
|
+
* const info = await provider.getDelegateInfo();
|
|
2933
|
+
* await provider.delegate(intent, forfeitTxs);
|
|
2934
|
+
* ```
|
|
2935
|
+
*/
|
|
2936
|
+
declare class RestDelegateProvider implements DelegateProvider {
|
|
2937
|
+
url: string;
|
|
2938
|
+
/** @param url - Base URL of the remote delegation service. */
|
|
2939
|
+
constructor(url: string);
|
|
3054
2940
|
/**
|
|
3055
|
-
*
|
|
2941
|
+
* Submit a delegation request to the remote delegation service.
|
|
3056
2942
|
*
|
|
3057
|
-
* @
|
|
3058
|
-
* ```typescript
|
|
3059
|
-
* const vhtlcs = await manager.getContracts({ type: "vhtlc" });
|
|
3060
|
-
* const active = await manager.getContracts({ state: "active" });
|
|
3061
|
-
* ```
|
|
2943
|
+
* @throws Error if the remote service rejects the request
|
|
3062
2944
|
*/
|
|
3063
|
-
|
|
3064
|
-
/** List contracts (all when no filter) with their current virtual outputs. `unspentOnly`
|
|
3065
|
-
* omits spent VTXOs from the repository result; it does not narrow the provider sync. */
|
|
3066
|
-
getContractsWithVtxos(filter?: GetContractsFilter, pageSize?: number, options?: {
|
|
3067
|
-
maxSyncAgeMs?: number;
|
|
3068
|
-
unspentOnly?: boolean;
|
|
3069
|
-
requireSynced?: boolean;
|
|
3070
|
-
}): Promise<ContractWithVtxos[]>;
|
|
3071
|
-
/** Latest provider-sync health. See {@link ContractSyncState}. */
|
|
3072
|
-
getSyncState(): ContractSyncState;
|
|
2945
|
+
delegate(intent: SignedProof<Proof.RegisterMessage>, forfeitTxs: string[], options?: DelegateOptions): Promise<void>;
|
|
3073
2946
|
/**
|
|
3074
|
-
*
|
|
3075
|
-
* older than `vtxoSyncMaxAgeMs` is requested in the background (skipped while the lazy boot
|
|
3076
|
-
* runs); check {@link getSyncState} before trusting the result. For display, never coin
|
|
3077
|
-
* selection.
|
|
2947
|
+
* Fetch delegate metadata exposed by the remote delegation service.
|
|
3078
2948
|
*
|
|
3079
|
-
*
|
|
3080
|
-
* its construction runs the boot sync, and a read racing it (a worker still handling
|
|
3081
|
-
* `INIT_WALLET`) waits for that. Through the service worker, {@link getSyncState} is cached
|
|
3082
|
-
* right after the read, so it usually reports `syncing` until the next proxy call refreshes it.
|
|
2949
|
+
* @throws Error if the remote service returns invalid data
|
|
3083
2950
|
*/
|
|
3084
|
-
|
|
2951
|
+
getDelegateInfo(): Promise<DelegateInfo>;
|
|
2952
|
+
}
|
|
2953
|
+
|
|
2954
|
+
interface IDelegateManager {
|
|
3085
2955
|
/**
|
|
3086
|
-
*
|
|
2956
|
+
* Delegate virtual outputs to the remote delegation service.
|
|
2957
|
+
*
|
|
2958
|
+
* Vtxos that are not locked to a delegate-type contract (no tap leaf
|
|
2959
|
+
* matches the delegate's pubkey) are filtered out silently, since they
|
|
2960
|
+
* cannot be co-signed by the delegate.
|
|
2961
|
+
*
|
|
2962
|
+
* @param vtxos - Virtual outputs to delegate
|
|
2963
|
+
* @param destination - Arkade address that should receive renewed funds
|
|
2964
|
+
* @param delegateAt - Optional timestamp to force a specific delegation time
|
|
2965
|
+
* @returns Successfully delegated and failed outpoint groups
|
|
2966
|
+
*/
|
|
2967
|
+
delegate(vtxos: ContractVtxo[], destination: string, delegateAt?: Date): Promise<{
|
|
2968
|
+
delegated: Outpoint[];
|
|
2969
|
+
failed: {
|
|
2970
|
+
outpoints: Outpoint[];
|
|
2971
|
+
error: unknown;
|
|
2972
|
+
}[];
|
|
2973
|
+
}>;
|
|
2974
|
+
/** Fetch delegate metadata such as pubkey, fee, and delegate address. */
|
|
2975
|
+
getDelegateInfo(): Promise<DelegateInfo>;
|
|
2976
|
+
}
|
|
2977
|
+
declare class DelegateManagerImpl implements IDelegateManager {
|
|
2978
|
+
readonly delegateProvider: DelegateProvider;
|
|
2979
|
+
readonly arkInfoProvider: Pick<OperatorProvider, "getInfo">;
|
|
2980
|
+
readonly identity: Identity;
|
|
2981
|
+
/** Create a delegate manager from the configured provider, Arkade info source, and wallet identity. */
|
|
2982
|
+
constructor(delegateProvider: DelegateProvider, arkInfoProvider: Pick<OperatorProvider, "getInfo">, identity: Identity);
|
|
2983
|
+
getDelegateInfo(): Promise<DelegateInfo>;
|
|
2984
|
+
delegate(vtxos: ContractVtxo[], destination: string, delegateAt?: Date): Promise<{
|
|
2985
|
+
delegated: Outpoint[];
|
|
2986
|
+
failed: {
|
|
2987
|
+
outpoints: Outpoint[];
|
|
2988
|
+
error: unknown;
|
|
2989
|
+
}[];
|
|
2990
|
+
}>;
|
|
2991
|
+
}
|
|
2992
|
+
|
|
2993
|
+
/**
|
|
2994
|
+
* Tapscript fields derived purely from a contract's params. They are identical
|
|
2995
|
+
* for every VTXO locked to the same contract, so they can be memoized per
|
|
2996
|
+
* contract (see {@link ContractTapscriptCache}).
|
|
2997
|
+
*/
|
|
2998
|
+
type ContractTapscripts = Pick<ExtendedVirtualCoin, "forfeitTapLeafScript" | "proofTapLeafScript" | "tapTree">;
|
|
2999
|
+
/**
|
|
3000
|
+
* Cache of per-contract tapscript data, keyed by `contract.script`. Building
|
|
3001
|
+
* the taproot tree via `handler.createScript(contract.params)` is the dominant
|
|
3002
|
+
* cost when annotating large VTXO sets; passing a shared cache across an
|
|
3003
|
+
* annotation batch rebuilds it once per distinct contract instead of once per
|
|
3004
|
+
* VTXO (see #521).
|
|
3005
|
+
*/
|
|
3006
|
+
type ContractTapscriptCache = Map<string, ContractTapscripts>;
|
|
3007
|
+
declare function getRandomId(): string;
|
|
3008
|
+
/**
|
|
3009
|
+
* What a recipient Arkade address must match. An address failing either check
|
|
3010
|
+
* belongs to another network or operator, so this wallet's operator cannot
|
|
3011
|
+
* create the VTXO where the recipient's wallet expects it.
|
|
3012
|
+
*/
|
|
3013
|
+
type RecipientArkadeAddressContext = {
|
|
3014
|
+
hrp: string;
|
|
3015
|
+
signerSet: SignerSet;
|
|
3016
|
+
};
|
|
3017
|
+
/**
|
|
3018
|
+
* The embedded server key may be the current signer or a deprecated signer
|
|
3019
|
+
* whose rotation cutoff has not passed.
|
|
3020
|
+
*/
|
|
3021
|
+
declare function assertRecipientArkadeAddress(encoded: string, address: ArkAddress, context: RecipientArkadeAddressContext): void;
|
|
3022
|
+
|
|
3023
|
+
/** Minimal indexer surface the reconciler needs. */
|
|
3024
|
+
type IntentReconcilerIndexer = Pick<IndexerProvider, "getVtxos">;
|
|
3025
|
+
interface IntentReconciliationDeps {
|
|
3026
|
+
intentRepository: BatchRegistrationRepository;
|
|
3027
|
+
indexerProvider: IntentReconcilerIndexer;
|
|
3028
|
+
/**
|
|
3029
|
+
* Replays an intent's stored delete proof against arkd. Absent ⇒ an unresolved, unexpired
|
|
3030
|
+
* intent stays locked, since arkd never expires a queued intent on its own.
|
|
3031
|
+
*/
|
|
3032
|
+
deleteIntent?: (intent: SignedProof<Proof.DeleteMessage>) => Promise<void>;
|
|
3033
|
+
/**
|
|
3034
|
+
* Whether a live settlement in this wallet is spending the outpoint. An intent with an
|
|
3035
|
+
* in-flight input belongs to that settlement and is skipped.
|
|
3036
|
+
*/
|
|
3037
|
+
isOutpointInFlight?: (outpoint: Outpoint) => boolean;
|
|
3038
|
+
/** Injectable clock (tests). Defaults to `Date.now`. */
|
|
3039
|
+
now?: () => number;
|
|
3040
|
+
}
|
|
3041
|
+
|
|
3042
|
+
/**
|
|
3043
|
+
* An input for {@link IContractManager.assertSpendableNow}.
|
|
3044
|
+
*
|
|
3045
|
+
* Prefer passing a full {@link VirtualCoin}: a relative (CSV) timelock is measured from the
|
|
3046
|
+
* coin's own confirmation (`status.block_height` / `status.block_time`). The bare shape still
|
|
3047
|
+
* answers every absolute (CLTV) question.
|
|
3048
|
+
*/
|
|
3049
|
+
type AssertSpendableInput = {
|
|
3050
|
+
txid: string;
|
|
3051
|
+
vout: number;
|
|
3052
|
+
script: string;
|
|
3053
|
+
};
|
|
3054
|
+
type RefreshVtxosOptions = {
|
|
3055
|
+
/** Narrow the refresh to these scripts. A subset query, so the sync cursor does not advance. */
|
|
3056
|
+
scripts?: string[];
|
|
3057
|
+
/** Time window overriding the cursor-derived one. The cursor never advances on a window. */
|
|
3058
|
+
after?: number;
|
|
3059
|
+
/** @see after */
|
|
3060
|
+
before?: number;
|
|
3061
|
+
/**
|
|
3062
|
+
* When true and `scripts` is not set, refresh every repository contract rather than the
|
|
3063
|
+
* watcher's watched set. A superset, so the cursor still advances (absent `after`/`before`).
|
|
3064
|
+
*
|
|
3065
|
+
* @defaultValue `false`
|
|
3066
|
+
*/
|
|
3067
|
+
includeInactive?: boolean;
|
|
3068
|
+
};
|
|
3069
|
+
/**
|
|
3070
|
+
* A single `Discoverable` handler's discovery failure, captured during a
|
|
3071
|
+
* {@link IContractManager.scanContracts} run instead of aborting the loop.
|
|
3072
|
+
*/
|
|
3073
|
+
interface HandlerError {
|
|
3074
|
+
handler: string;
|
|
3075
|
+
/** The failed index, or the first index of a failed `discoverRange` window. */
|
|
3076
|
+
fromIndex: number;
|
|
3077
|
+
/** Inclusive end of a failed `discoverRange` window; absent for a single index. */
|
|
3078
|
+
toIndex?: number;
|
|
3079
|
+
error: unknown;
|
|
3080
|
+
}
|
|
3081
|
+
/** Outcome of a {@link IContractManager.scanContracts} run. */
|
|
3082
|
+
interface ScanResult {
|
|
3083
|
+
/**
|
|
3084
|
+
* Highest HD index at which any handler confirmed a contract (`-1` if none), including hits
|
|
3085
|
+
* past {@link ScanResult.truncatedAt}. Safe to record unconditionally (the watermark is a
|
|
3086
|
+
* monotonic max); withholding it risks re-issuing a funded index as a fresh address.
|
|
3087
|
+
*/
|
|
3088
|
+
highestConfirmedUsedIndex: number;
|
|
3089
|
+
/**
|
|
3090
|
+
* First index a handler failed at (neither hit nor confirmed miss). Indices `>= truncatedAt`
|
|
3091
|
+
* are unverified and the caller must retry; scanning is idempotent. `undefined` when the
|
|
3092
|
+
* scan closed a genuine gap.
|
|
3093
|
+
*/
|
|
3094
|
+
truncatedAt?: number;
|
|
3095
|
+
/** Per-handler discovery failures. Non-empty implies `truncatedAt` is set. */
|
|
3096
|
+
handlerErrors: HandlerError[];
|
|
3097
|
+
}
|
|
3098
|
+
/** Options for {@link IContractManager.scanContracts}. */
|
|
3099
|
+
interface ScanContractsOptions {
|
|
3100
|
+
/** Default 20. A non-positive / non-integer value throws. */
|
|
3101
|
+
gapLimit?: number;
|
|
3102
|
+
/**
|
|
3103
|
+
* HD indices probed per window (default {@link DEFAULT_SCAN_BATCH}); also the width a
|
|
3104
|
+
* {@link Discoverable.discoverRange} handler collapses into one request. The discovered set
|
|
3105
|
+
* is independent of it. A non-positive / non-integer value throws. Ignored when `hd` is false.
|
|
3106
|
+
*/
|
|
3107
|
+
batchSize?: number;
|
|
3108
|
+
/** HD mode → gap loop guided by the gap counter; false → probe only index 0. */
|
|
3109
|
+
hd: boolean;
|
|
3110
|
+
/** Materialize the descriptor at an HD index. A throw here is fatal and propagates. */
|
|
3111
|
+
materialize: (index: number) => string;
|
|
3112
|
+
/** Read-only context injected into every `discoverAt` call. */
|
|
3113
|
+
deps: DiscoveryDeps;
|
|
3114
|
+
}
|
|
3115
|
+
/**
|
|
3116
|
+
* Freshness of the ContractManager's provider-backed sync. `degraded` means the most recent sync
|
|
3117
|
+
* hit a retryable indexer/operator failure and repository state is being served; it returns to
|
|
3118
|
+
* `online` on the next successful sync.
|
|
3119
|
+
*
|
|
3120
|
+
* `syncing` says a provider sync is in flight right now, so a read can be served from the
|
|
3121
|
+
* repository while the work that refreshes it runs on. Optional so adding it breaks no
|
|
3122
|
+
* implementer of this public interface; {@link ContractManager} always sets it.
|
|
3123
|
+
*/
|
|
3124
|
+
type ContractSyncState = {
|
|
3125
|
+
mode: "online";
|
|
3126
|
+
syncing?: boolean;
|
|
3127
|
+
lastSyncedAt?: number;
|
|
3128
|
+
} | {
|
|
3129
|
+
mode: "degraded";
|
|
3130
|
+
syncing?: boolean;
|
|
3131
|
+
reason: string;
|
|
3132
|
+
lastSyncedAt?: number;
|
|
3133
|
+
};
|
|
3134
|
+
interface IContractManager extends Disposable {
|
|
3135
|
+
/**
|
|
3136
|
+
* Create and register a new contract, keyed by its script. Implementations may validate that
|
|
3137
|
+
* a handler exists for `params.type` and that `params.script` matches the derived script.
|
|
3138
|
+
*/
|
|
3139
|
+
createContract(params: CreateContractParams): Promise<Contract>;
|
|
3140
|
+
/**
|
|
3141
|
+
* {@link createContract} for a set, one indexer round trip instead of N. Optional so existing
|
|
3142
|
+
* implementers (e.g. the service-worker proxy) keep compiling; callers fall back.
|
|
3143
|
+
*/
|
|
3144
|
+
createContracts?(paramsList: CreateContractParams[]): Promise<Contract[]>;
|
|
3145
|
+
/**
|
|
3146
|
+
* List contracts with optional filters.
|
|
3147
|
+
*
|
|
3148
|
+
* @example
|
|
3149
|
+
* ```typescript
|
|
3150
|
+
* const vhtlcs = await manager.getContracts({ type: "vhtlc" });
|
|
3151
|
+
* const active = await manager.getContracts({ state: "active" });
|
|
3152
|
+
* ```
|
|
3153
|
+
*/
|
|
3154
|
+
getContracts(filter?: GetContractsFilter): Promise<Contract[]>;
|
|
3155
|
+
/** List contracts (all when no filter) with their current virtual outputs. `unspentOnly`
|
|
3156
|
+
* omits spent VTXOs from the repository result; it does not narrow the provider sync. */
|
|
3157
|
+
getContractsWithVtxos(filter?: GetContractsFilter, pageSize?: number, options?: {
|
|
3158
|
+
maxSyncAgeMs?: number;
|
|
3159
|
+
unspentOnly?: boolean;
|
|
3160
|
+
requireSynced?: boolean;
|
|
3161
|
+
}): Promise<ContractWithVtxos[]>;
|
|
3162
|
+
/** Latest provider-sync health. See {@link ContractSyncState}. */
|
|
3163
|
+
getSyncState(): ContractSyncState;
|
|
3164
|
+
/**
|
|
3165
|
+
* Contracts with their repository VTXOs, answered without waiting on the indexer. A sync
|
|
3166
|
+
* older than `vtxoSyncMaxAgeMs` is requested in the background (skipped while the lazy boot
|
|
3167
|
+
* runs); check {@link getSyncState} before trusting the result. For display, never coin
|
|
3168
|
+
* selection.
|
|
3169
|
+
*
|
|
3170
|
+
* The read itself never waits, but reaching the manager can: without `lazyInitialization`
|
|
3171
|
+
* its construction runs the boot sync, and a read racing it (a worker still handling
|
|
3172
|
+
* `INIT_WALLET`) waits for that. Through the service worker, {@link getSyncState} is cached
|
|
3173
|
+
* right after the read, so it usually reports `syncing` until the next proxy call refreshes it.
|
|
3174
|
+
*/
|
|
3175
|
+
getStoredContractsWithVtxos(filter?: GetContractsFilter): Promise<ContractWithVtxos[]>;
|
|
3176
|
+
/**
|
|
3177
|
+
* Settles when the `lazyInitialization` boot (look-ahead drain, reconcile, watcher start)
|
|
3087
3178
|
* finishes; immediately when there is none. Never rejects: a failed boot is reported through
|
|
3088
3179
|
* {@link getSyncState}.
|
|
3089
3180
|
*/
|
|
@@ -3179,9 +3270,30 @@ interface IContractManager extends Disposable {
|
|
|
3179
3270
|
*/
|
|
3180
3271
|
refreshOutpoints(outpoints: Outpoint[]): Promise<void>;
|
|
3181
3272
|
/**
|
|
3182
|
-
*
|
|
3183
|
-
*
|
|
3184
|
-
*
|
|
3273
|
+
* Fetch onchain coins for onchain-scoped contracts (and contracts holding
|
|
3274
|
+
* unspent unrolled outputs), upsert them, and mark vanished ones spent.
|
|
3275
|
+
* No-op without `onchainProvider` and `network`. Narrowed by `scripts`; `fetched` holds coins
|
|
3276
|
+
* the caller already fetched, by script, so they are not fetched again.
|
|
3277
|
+
* Optional (like {@link watchScript}): the service-worker proxy does not forward it yet.
|
|
3278
|
+
*/
|
|
3279
|
+
syncOnchain?(scripts?: string[], fetched?: ReadonlyMap<string, Coin[]>): Promise<void>;
|
|
3280
|
+
/**
|
|
3281
|
+
* Record `txid` as the pending spender of stored onchain coins. A sync confirms it once the
|
|
3282
|
+
* coin is spent, or releases it if still unspent `ONCHAIN_PENDING_RELEASE_BLOCKS` later.
|
|
3283
|
+
* `skipUnknown` marks the stored coins and logs the rest instead of rejecting them all.
|
|
3284
|
+
* `height` starts the release countdown; without it the chain tip is fetched.
|
|
3285
|
+
*/
|
|
3286
|
+
markOnchainSpendPending?(outpoints: Outpoint[], txid: string, options?: {
|
|
3287
|
+
skipUnknown?: boolean;
|
|
3288
|
+
height?: number;
|
|
3289
|
+
}): Promise<void>;
|
|
3290
|
+
/**
|
|
3291
|
+
* Rebuild the HD look-ahead watch window around the current allocation
|
|
3292
|
+
* watermark. No-op when the manager was configured without `lookAhead`.
|
|
3293
|
+
*
|
|
3294
|
+
* Call after anything that moves the watermark (restore, boarding
|
|
3295
|
+
* allocation, receive rotation, server-signer rotation). Concurrent calls
|
|
3296
|
+
* coalesce into a single drain.
|
|
3185
3297
|
*/
|
|
3186
3298
|
refillLookAhead(): Promise<void>;
|
|
3187
3299
|
/**
|
|
@@ -3258,7 +3370,6 @@ type GetAllSpendingPathsOptions = {
|
|
|
3258
3370
|
/** Wallet descriptor to determine role */
|
|
3259
3371
|
walletDescriptor?: string;
|
|
3260
3372
|
};
|
|
3261
|
-
/** Configuration for the ContractManager. */
|
|
3262
3373
|
interface ContractManagerConfig {
|
|
3263
3374
|
/** Opt in to background boot; inspect getSyncState() before using cached data. */
|
|
3264
3375
|
lazyInitialization?: boolean;
|
|
@@ -3270,7 +3381,7 @@ interface ContractManagerConfig {
|
|
|
3270
3381
|
* When present, the online sync reconciles persisted non-terminal settlement intents against
|
|
3271
3382
|
* indexer state (crash recovery) on boot and reconnect; see {@link reconcileIntents}.
|
|
3272
3383
|
*/
|
|
3273
|
-
intentRepository?:
|
|
3384
|
+
intentRepository?: BatchRegistrationRepository;
|
|
3274
3385
|
/** Lets the reconciliation release stale intents from arkd; see {@link IntentReconciliationDeps}. */
|
|
3275
3386
|
intentReconciliation?: Pick<IntentReconciliationDeps, "deleteIntent" | "isOutpointInFlight">;
|
|
3276
3387
|
/**
|
|
@@ -3310,6 +3421,9 @@ interface ContractManagerConfig {
|
|
|
3310
3421
|
* on arkd's clock, so this must cover how far this host's clock can run ahead of it.
|
|
3311
3422
|
*/
|
|
3312
3423
|
vtxoSyncOverlapMs?: number;
|
|
3424
|
+
/** Enables onchain coin discovery and watching; needs `network` too. */
|
|
3425
|
+
onchainProvider?: OnchainProvider;
|
|
3426
|
+
network?: Network;
|
|
3313
3427
|
}
|
|
3314
3428
|
/**
|
|
3315
3429
|
* Wallet-injected surface backing the HD look-ahead window; a callback bundle so the contracts
|
|
@@ -3413,6 +3527,9 @@ declare class ContractManager implements IContractManager {
|
|
|
3413
3527
|
/** Set by {@link dispose}, cleared by a re-`initialize`. A drain outlives the synchronous
|
|
3414
3528
|
* `dispose()`, so it re-checks this at every await rather than run on a torn-down watcher. */
|
|
3415
3529
|
private disposed;
|
|
3530
|
+
private onchainWatcher?;
|
|
3531
|
+
/** Serializes onchain read-modify-writes so a pending spender is never overwritten. */
|
|
3532
|
+
private onchainChain;
|
|
3416
3533
|
private constructor();
|
|
3417
3534
|
/**
|
|
3418
3535
|
* Create a ContractManager, load persisted contracts and start watching all of them. Use
|
|
@@ -3617,997 +3734,711 @@ declare class ContractManager implements IContractManager {
|
|
|
3617
3734
|
* Delete a contract, dropping the row along with the watch. To stop watching a finished
|
|
3618
3735
|
* contract without losing its history, use {@link setContractWatchState}(`"retained"`).
|
|
3619
3736
|
*/
|
|
3620
|
-
deleteContract(script: string): Promise<void>;
|
|
3621
|
-
/**
|
|
3622
|
-
* Chain tip for a {@link PathContext}, or `undefined` when no source is configured or it
|
|
3623
|
-
* can't be read. Cached for {@link CHAIN_TIP_TTL_MS}.
|
|
3624
|
-
*/
|
|
3625
|
-
private currentChainTip;
|
|
3626
|
-
/** One chain tip read, bounded by {@link CHAIN_TIP_TIMEOUT_MS}. Never rejects. */
|
|
3627
|
-
private readChainTip;
|
|
3628
|
-
/** Get currently spendable paths for a contract. */
|
|
3629
|
-
getSpendablePaths(options: GetSpendablePathsOptions): Promise<PathSelection[]>;
|
|
3630
|
-
/**
|
|
3631
|
-
* Get every currently valid spending path for a contract. No `blockHeight`: no handler
|
|
3632
|
-
* evaluates a timelock here, so fetching the tip would only add network latency.
|
|
3633
|
-
*/
|
|
3634
|
-
getAllSpendingPaths(options: GetAllSpendingPathsOptions): Promise<PathSelection[]>;
|
|
3635
|
-
/**
|
|
3636
|
-
* Register a callback for contract events (watching already started in `initialize()`).
|
|
3637
|
-
*
|
|
3638
|
-
* @returns Unsubscribe function to remove this callback
|
|
3639
|
-
*
|
|
3640
|
-
* @example
|
|
3641
|
-
* ```typescript
|
|
3642
|
-
* const unsubscribe = manager.onContractEvent((event) => {
|
|
3643
|
-
* console.log(`${event.type} on ${event.contractScript}`);
|
|
3644
|
-
* });
|
|
3645
|
-
*
|
|
3646
|
-
* // Later: stop receiving events
|
|
3647
|
-
* unsubscribe();
|
|
3648
|
-
* ```
|
|
3649
|
-
*/
|
|
3650
|
-
onContractEvent(callback: ContractEventCallback): () => void;
|
|
3651
|
-
/**
|
|
3652
|
-
* Force refresh virtual outputs from the indexer. Without options, re-fetches the watched set
|
|
3653
|
-
* and advances the global cursor; see {@link RefreshVtxosOptions} for how each option scopes.
|
|
3654
|
-
*/
|
|
3655
|
-
refreshVtxos(opts?: RefreshVtxosOptions): Promise<void>;
|
|
3656
|
-
refreshOutpoints(outpoints: Outpoint[]): Promise<void>;
|
|
3657
|
-
isWatching(): Promise<boolean>;
|
|
3658
|
-
/** @see IContractManager.watchScript */
|
|
3659
|
-
watchScript(script: string | string[], options?: {
|
|
3660
|
-
label?: string;
|
|
3661
|
-
}): Promise<void>;
|
|
3662
|
-
/** @see IContractManager.unwatchScript */
|
|
3663
|
-
unwatchScript(script: string | string[]): Promise<void>;
|
|
3664
|
-
/** @see IContractManager.getWatchedScripts */
|
|
3665
|
-
getWatchedScripts(): Promise<WatchedScript[]>;
|
|
3666
|
-
private emitEvent;
|
|
3667
|
-
/** Resolves `false` when the event's sync failed, so the watcher keeps its poll off. */
|
|
3668
|
-
private handleContractEvent;
|
|
3669
|
-
private getVtxosForContracts;
|
|
3670
|
-
/** Sync virtual outputs for the given contracts (default: the watched set). */
|
|
3671
|
-
private syncContracts;
|
|
3672
|
-
private performContractSync;
|
|
3673
|
-
private syncedWithin;
|
|
3674
|
-
/**
|
|
3675
|
-
* Demote every funded `awaiting-funds` contract to `retained` (see {@link ContractWatchState}).
|
|
3676
|
-
*
|
|
3677
|
-
* Runs after the sync persisted, so the funding VTXO is saved while still watched, and reads
|
|
3678
|
-
* the repository rather than this delta: funds that landed while the app was closed are
|
|
3679
|
-
* outside every later window. Best-effort: must not fail the sync that carried it.
|
|
3680
|
-
*/
|
|
3681
|
-
private demoteFundedAwaitingContracts;
|
|
3682
|
-
/**
|
|
3683
|
-
* Fetch all pending (unfinalized) virtual outputs and upsert them, catching state changes
|
|
3684
|
-
* outside the delta window (e.g. a spend that hasn't settled yet).
|
|
3685
|
-
*/
|
|
3686
|
-
private reconcilePendingFrontier;
|
|
3687
|
-
private persistContractVtxos;
|
|
3688
|
-
private fetchContractVxosFromIndexer;
|
|
3689
|
-
private fetchContractVtxosBulk;
|
|
3690
|
-
/**
|
|
3691
|
-
* Stop the watcher, clear callbacks, and mark the manager uninitialized.
|
|
3692
|
-
*
|
|
3693
|
-
* Teardown is synchronous. The returned promise settles once watcher events already being
|
|
3694
|
-
* handled, any look-ahead drain, and any lazy boot sequence finish; after that nothing more is written to the
|
|
3695
|
-
* repositories.
|
|
3696
|
-
*/
|
|
3697
|
-
dispose(): Promise<void>;
|
|
3698
|
-
/**
|
|
3699
|
-
* Symbol.dispose implementation for the `using` keyword. Teardown is immediate, but it does
|
|
3700
|
-
* not wait for in-flight work; use `await using` for that.
|
|
3701
|
-
*/
|
|
3702
|
-
[Symbol.dispose](): void;
|
|
3703
|
-
/**
|
|
3704
|
-
* Symbol.asyncDispose implementation for the `await using` keyword; waits like {@link dispose}.
|
|
3705
|
-
* @example
|
|
3706
|
-
* ```typescript
|
|
3707
|
-
* {
|
|
3708
|
-
* await using manager = await wallet.getContractManager();
|
|
3709
|
-
* // ... use manager
|
|
3710
|
-
* } // disposed, with in-flight events finished
|
|
3711
|
-
* ```
|
|
3712
|
-
*/
|
|
3713
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
3714
|
-
}
|
|
3715
|
-
|
|
3716
|
-
/**
|
|
3717
|
-
* Contract lifecycle state. Governs receive-address selection only: `inactive` does **not**
|
|
3718
|
-
* unsubscribe (a retired receive address can still be paid; coverage follows
|
|
3719
|
-
* {@link Contract.watch} alone). To stop watching but keep the row use `retained`
|
|
3720
|
-
* {@link ContractWatchState}; to drop both, {@link IContractManager.deleteContract}.
|
|
3721
|
-
*/
|
|
3722
|
-
type ContractState = "active" | "inactive";
|
|
3723
|
-
/**
|
|
3724
|
-
* Whether a contract is covered by background monitoring (subscription and failsafe/indexer
|
|
3725
|
-
* sweep, {@link ContractWatcher.getWatchedContracts}). Orthogonal to {@link ContractState}.
|
|
3726
|
-
*
|
|
3727
|
-
* NArk parity: `ContractActivityState`; renamed because `active`/`inactive` are taken by
|
|
3728
|
-
* {@link ContractState}.
|
|
3729
|
-
*/
|
|
3730
|
-
type ContractWatchState =
|
|
3731
|
-
/** Subscribed and polled. */
|
|
3732
|
-
"watched"
|
|
3733
|
-
/**
|
|
3734
|
-
* Watched until the first VTXO lands, then demoted to `retained` by the contract manager.
|
|
3735
|
-
* For one-shot destinations (refund address, swap lockup).
|
|
3736
|
-
*/
|
|
3737
|
-
| "awaiting-funds"
|
|
3738
|
-
/**
|
|
3739
|
-
* Not subscribed or polled, but still resolves in `getContracts`, annotates its VTXOs and
|
|
3740
|
-
* feeds transaction history.
|
|
3741
|
-
*/
|
|
3742
|
-
| "retained";
|
|
3743
|
-
/**
|
|
3744
|
-
* A contract that can receive and manage virtual outputs. Its type and parameters determine the
|
|
3745
|
-
* VtxoScript (spending paths); the wallet's default receiving address is a `"default"` contract,
|
|
3746
|
-
* and external services (swaps, etc.) register their own types.
|
|
3747
|
-
*
|
|
3748
|
-
* @example
|
|
3749
|
-
* ```typescript
|
|
3750
|
-
* const vhtlcContract: Contract = {
|
|
3751
|
-
* type: "vhtlc",
|
|
3752
|
-
* params: {
|
|
3753
|
-
* sender: "ab12...",
|
|
3754
|
-
* receiver: "cd34...",
|
|
3755
|
-
* server: "ef56...",
|
|
3756
|
-
* hash: "1234...",
|
|
3757
|
-
* refundLocktime: "800000",
|
|
3758
|
-
* // ... timelocks
|
|
3759
|
-
* },
|
|
3760
|
-
* script: "5120...",
|
|
3761
|
-
* address: "ark1q...",
|
|
3762
|
-
* state: "active",
|
|
3763
|
-
* createdAt: 1704067200000,
|
|
3764
|
-
* };
|
|
3765
|
-
* ```
|
|
3766
|
-
*/
|
|
3767
|
-
interface Contract {
|
|
3768
|
-
/** Human-readable label for display purposes. */
|
|
3769
|
-
label?: string;
|
|
3770
|
-
/** Contract type identifier (e.g. "default", "vhtlc"); custom types add a ContractHandler. */
|
|
3771
|
-
type: string;
|
|
3772
|
-
/**
|
|
3773
|
-
* Type-specific VtxoScript parameters, serialized as strings (hex for bytes, string for
|
|
3774
|
-
* bigint) and interpreted by the type's ContractHandler.
|
|
3775
|
-
*/
|
|
3776
|
-
params: Record<string, string>;
|
|
3777
|
-
/** The pkScript hex, used as the unique identifier and primary key for contracts. */
|
|
3778
|
-
script: string;
|
|
3779
|
-
/** Address derived from the contract script. */
|
|
3780
|
-
address: string;
|
|
3781
|
-
/** Current state of the contract. */
|
|
3782
|
-
state: ContractState;
|
|
3783
|
-
/**
|
|
3784
|
-
* Background-monitoring scope. Absent means `watched`.
|
|
3785
|
-
* @see ContractWatchState
|
|
3786
|
-
*/
|
|
3787
|
-
watch?: ContractWatchState;
|
|
3788
|
-
/** Unix timestamp in milliseconds when this contract was created. */
|
|
3789
|
-
createdAt: number;
|
|
3790
|
-
/** Optional metadata for external integrations. */
|
|
3791
|
-
metadata?: Record<string, unknown>;
|
|
3792
|
-
}
|
|
3793
|
-
/** A virtual output associated with a specific contract. */
|
|
3794
|
-
type ContractVtxo = VirtualCoin & Partial<TapLeaves & EncodedVtxoScript> & {
|
|
3795
|
-
extraWitness?: Bytes[];
|
|
3796
|
-
contractScript: string;
|
|
3797
|
-
};
|
|
3798
|
-
/**
|
|
3799
|
-
* A {@link ContractVtxo} with all taproot annotation fields required (mirrors the
|
|
3800
|
-
* {@link ExtendedVirtualCoin} / {@link VirtualCoin} split). Use it wherever the compiler should
|
|
3801
|
-
* enforce that `annotateVtxos` has run, e.g. `saveVtxos` and forfeit construction.
|
|
3802
|
-
*/
|
|
3803
|
-
type ExtendedContractVtxo = NormalizedExtendedVirtualCoin & {
|
|
3804
|
-
contractScript: string;
|
|
3805
|
-
};
|
|
3806
|
-
/** Result of path selection: the tapleaf to use and any extra witness data. */
|
|
3807
|
-
interface PathSelection {
|
|
3808
|
-
/** Tapleaf script to use for spending. */
|
|
3809
|
-
leaf: TapLeafScript;
|
|
3810
|
-
/** Additional witness elements, for example a preimage for HTLC-like paths. */
|
|
3811
|
-
extraWitness?: Bytes[];
|
|
3812
|
-
/**
|
|
3813
|
-
* nSequence for the spending input, BIP-68 encoded when the leaf
|
|
3814
|
-
* uses CSV. Decode with `sequenceToTimelock`; do NOT use as an
|
|
3815
|
-
* absolute `Transaction.lockTime`.
|
|
3816
|
-
*/
|
|
3817
|
-
sequence?: number;
|
|
3818
|
-
}
|
|
3819
|
-
/** Context for path selection decisions. */
|
|
3820
|
-
interface PathContext {
|
|
3821
|
-
/** Whether collaborative spending is available through server cooperation. */
|
|
3822
|
-
collaborative: boolean;
|
|
3823
|
-
/** Current time in milliseconds. */
|
|
3824
|
-
currentTime: number;
|
|
3825
|
-
/** Current block height, when known. */
|
|
3826
|
-
blockHeight?: number;
|
|
3827
|
-
/**
|
|
3828
|
-
* Wallet's signing descriptor: `tr(pubkey)` for static keys,
|
|
3829
|
-
* `tr([fingerprint/path']xpub/0/{index})` for HD. Handlers use it to find the wallet's role.
|
|
3830
|
-
*/
|
|
3831
|
-
walletDescriptor?: string;
|
|
3832
|
-
/**
|
|
3833
|
-
* Explicit role override for multi-party contracts such as VHTLC. If absent, handlers may
|
|
3834
|
-
* match {@link walletDescriptor} against the contract's sender/receiver params.
|
|
3835
|
-
*/
|
|
3836
|
-
role?: string;
|
|
3837
|
-
/**
|
|
3838
|
-
* Chain tip timestamp in SECONDS, when known. Seconds-typed timelock checks should prefer it
|
|
3839
|
-
* over {@link currentTime}: the server matures absolute locktimes against median-time-past,
|
|
3840
|
-
* which trails wall clock, and host clock drift would skew the decision.
|
|
3841
|
-
*/
|
|
3842
|
-
chainTime?: number;
|
|
3843
|
-
/** The specific virtual output being evaluated. */
|
|
3844
|
-
vtxo?: VirtualCoin;
|
|
3845
|
-
}
|
|
3846
|
-
/**
|
|
3847
|
-
* Handler for a specific contract type.
|
|
3848
|
-
*
|
|
3849
|
-
* Each contract type (`default`, `vhtlc`, etc.) has a handler that knows how to:
|
|
3850
|
-
* 1. Create the VtxoScript from parameters
|
|
3851
|
-
* 2. Serialize/deserialize parameters for storage
|
|
3852
|
-
* 3. Select the appropriate spending path based on context
|
|
3853
|
-
*
|
|
3854
|
-
* @example
|
|
3855
|
-
* ```typescript
|
|
3856
|
-
* const vhtlcHandler: ContractHandler = {
|
|
3857
|
-
* type: "vhtlc",
|
|
3858
|
-
* createScript(params) {
|
|
3859
|
-
* return new VHTLC.Script(this.deserializeParams(params));
|
|
3860
|
-
* },
|
|
3861
|
-
* selectPath(script, contract, context) {
|
|
3862
|
-
* const vhtlc = script as VHTLC.Script;
|
|
3863
|
-
* const preimage = contract.data?.preimage;
|
|
3864
|
-
* if (context.collaborative && preimage) {
|
|
3865
|
-
* return { leaf: vhtlc.claim(), extraWitness: [hex.decode(preimage)] };
|
|
3866
|
-
* }
|
|
3867
|
-
* // ... other paths
|
|
3868
|
-
* },
|
|
3869
|
-
* // ...
|
|
3870
|
-
* };
|
|
3871
|
-
* ```
|
|
3872
|
-
*/
|
|
3873
|
-
interface ContractHandler<P = Record<string, unknown>, S extends VtxoScript = VtxoScript> {
|
|
3874
|
-
/** Contract type managed by this handler. */
|
|
3875
|
-
readonly type: string;
|
|
3876
|
-
/** Create the VtxoScript from serialized parameters. */
|
|
3877
|
-
createScript(params: Record<string, string>): S;
|
|
3878
|
-
/** Serialize typed parameters to string key-value pairs. */
|
|
3879
|
-
serializeParams(params: P): Record<string, string>;
|
|
3880
|
-
/** Deserialize string key-value pairs to typed parameters. */
|
|
3881
|
-
deserializeParams(params: Record<string, string>): P;
|
|
3882
|
-
/**
|
|
3883
|
-
* Select the preferred spending path (e.g. collaborative over unilateral).
|
|
3884
|
-
*
|
|
3885
|
-
* @returns PathSelection if a viable path exists, null otherwise
|
|
3886
|
-
*/
|
|
3887
|
-
selectPath(script: S, contract: Contract, context: PathContext): PathSelection | null;
|
|
3888
|
-
/** All possible spending paths for the context, regardless of current spendability. */
|
|
3889
|
-
getAllSpendingPaths(script: S, contract: Contract, context: PathContext): PathSelection[];
|
|
3890
|
-
/** All currently spendable paths (empty if none). */
|
|
3891
|
-
getSpendablePaths(script: S, contract: Contract, context: PathContext): PathSelection[];
|
|
3892
|
-
/**
|
|
3893
|
-
* Whether this contract's VTXOs may be picked by *generic* wallet spending (send, settle,
|
|
3894
|
-
* renewal, asset operations, offboard, `available` balance). Explicit-input APIs
|
|
3895
|
-
* (`settle({ inputs })`, `send({ selectedVtxos })`) stay open regardless.
|
|
3896
|
-
*
|
|
3897
|
-
* Pure, synchronous and offline (runs in the service worker). Absent or `false` ⇒ NOT
|
|
3898
|
-
* spendable, so an unknown type can't leak by omission. No `script` param: deriving a taproot
|
|
3899
|
-
* tree per contract on a read path is costly (#521); use `createScript` if needed.
|
|
3900
|
-
*/
|
|
3901
|
-
isGenericallySpendable?(contract: Contract): boolean;
|
|
3902
|
-
/**
|
|
3903
|
-
* Refuse, before signing, an explicitly named input this contract definitively cannot spend
|
|
3904
|
-
* now (e.g. an immature timelock), with an actionable reason instead of an opaque server
|
|
3905
|
-
* rejection. Counterpart to {@link isGenericallySpendable}, which leaves explicit inputs open.
|
|
3906
|
-
*
|
|
3907
|
-
* **Throw only on a definite no**; absent or unsure means the spend proceeds. An empty
|
|
3908
|
-
* `getSpendablePaths` is not a no (`arkade`'s skips covenant leaves), nor is an unreadable
|
|
3909
|
-
* timelock (height-typed with no chain tip) — @see cltvMaturity. May return a promise for
|
|
3910
|
-
* I/O, but prefer synchronous: it sits on the spend path.
|
|
3911
|
-
*
|
|
3912
|
-
* @throws Error when the contract provably cannot be spent at `context`
|
|
3913
|
-
*/
|
|
3914
|
-
assertSpendableNow?(script: S, contract: Contract, context: PathContext): void | Promise<void>;
|
|
3915
|
-
}
|
|
3916
|
-
/**
|
|
3917
|
-
* What {@link Discoverable.discoverAt} returns: exactly what `ContractManager.createContract`
|
|
3918
|
-
* accepts (script-keyed, idempotent on re-register).
|
|
3919
|
-
*/
|
|
3920
|
-
interface DiscoveredContract {
|
|
3921
|
-
type: string;
|
|
3922
|
-
params: Record<string, string>;
|
|
3923
|
-
script: string;
|
|
3924
|
-
address: string;
|
|
3925
|
-
metadata?: Record<string, unknown>;
|
|
3926
|
-
label?: string;
|
|
3927
|
-
}
|
|
3928
|
-
/**
|
|
3929
|
-
* Read-only context the scanner injects into every `discoverAt` call. Never carries an external
|
|
3930
|
-
* service client; a handler needing one closes over it at registration.
|
|
3931
|
-
*/
|
|
3932
|
-
interface DiscoveryDeps {
|
|
3933
|
-
indexerProvider: IndexerProvider;
|
|
3934
|
-
onchainProvider: OnchainProvider;
|
|
3935
|
-
/** Ark-address network data; `{ hrp }` is all L2 (`default`/`delegate`) discovery needs. */
|
|
3936
|
-
network: {
|
|
3937
|
-
hrp: string;
|
|
3938
|
-
};
|
|
3939
|
-
/**
|
|
3940
|
-
* Full Bitcoin network for on-chain (P2TR) addresses, needed by boarding discovery (`{ hrp }`
|
|
3941
|
-
* lacks the `bech32` data). When absent, boarding `discoverAt` no-ops.
|
|
3942
|
-
*/
|
|
3943
|
-
onchainNetwork?: Network;
|
|
3944
|
-
/**
|
|
3945
|
-
* The server's **current** signer key (x-only, 32 bytes) from a fresh server-info snapshot at
|
|
3946
|
-
* restore time; L2 discovery probes it first.
|
|
3947
|
-
*/
|
|
3948
|
-
serverPubKey: Uint8Array;
|
|
3949
|
-
/**
|
|
3950
|
-
* The server's **deprecated** signer keys (x-only, 32 bytes) from the same snapshot. L2
|
|
3951
|
-
* discovery scans them too so signer rotation doesn't strand funds; boarding discovery
|
|
3952
|
-
* ignores them (current UTXO set only).
|
|
3953
|
-
*/
|
|
3954
|
-
deprecatedSignerPubKeys?: Uint8Array[];
|
|
3955
|
-
/** Relative timelocks the wallet treats as its baseline matrix. */
|
|
3956
|
-
csvTimelocks: RelativeTimelock[];
|
|
3957
|
-
/**
|
|
3958
|
-
* Boarding-exit CSV timelock (the server's boarding-exit delay), distinct from the
|
|
3959
|
-
* unilateral-exit {@link DiscoveryDeps.csvTimelocks}. When absent, boarding `discoverAt`
|
|
3960
|
-
* no-ops.
|
|
3961
|
-
*/
|
|
3962
|
-
boardingTimelock?: RelativeTimelock;
|
|
3963
|
-
/** Present only for delegate wallets. */
|
|
3964
|
-
delegatePubKey?: Uint8Array;
|
|
3965
|
-
}
|
|
3966
|
-
/**
|
|
3967
|
-
* The I/O-free subset of {@link DiscoveryDeps}: the axes a receive script can
|
|
3968
|
-
* be anchored to. `DiscoveryDeps` satisfies it structurally, so one
|
|
3969
|
-
* {@link Discoverable.candidatesAt} serves the scan and the look-ahead band.
|
|
3970
|
-
*/
|
|
3971
|
-
type CandidateDeps = Pick<DiscoveryDeps, "network" | "serverPubKey" | "csvTimelocks"> & Pick<Partial<DiscoveryDeps>, "deprecatedSignerPubKeys" | "delegatePubKey">;
|
|
3972
|
-
/**
|
|
3973
|
-
* Optional {@link ContractHandler} capability for `wallet.restore()`'s gap-limit scan. The scanner
|
|
3974
|
-
* owns the index loop and gap counter; the handler answers "do I own a contract at this index?"
|
|
3975
|
-
* from its own source, and may batch/cache across calls.
|
|
3976
|
-
*/
|
|
3977
|
-
interface Discoverable {
|
|
3978
|
-
discoverAt(index: number, descriptor: string, deps: DiscoveryDeps): Promise<DiscoveredContract[]>;
|
|
3979
|
-
/**
|
|
3980
|
-
* Optional: answer a whole scan window in one batched round-trip; preferred over per-index
|
|
3981
|
-
* `discoverAt` when present. Per-address sources (e.g. boarding on Esplora) omit it.
|
|
3982
|
-
*
|
|
3983
|
-
* **All-or-nothing per call.** Resolve with a map covering *every* requested index (empty
|
|
3984
|
-
* array = confirmed miss) or reject; a missing index would read as "no funds" and close the
|
|
3985
|
-
* gap window on a failed request. The scanner treats an incomplete map as a rejection (hits
|
|
3986
|
-
* still persisted, scan truncated at the range's first index); unrequested indices are ignored.
|
|
3987
|
-
*/
|
|
3988
|
-
discoverRange?(entries: readonly {
|
|
3989
|
-
index: number;
|
|
3990
|
-
descriptor: string;
|
|
3991
|
-
}[], deps: DiscoveryDeps): Promise<Map<number, DiscoveredContract[]>>;
|
|
3992
|
-
/**
|
|
3993
|
-
* Optional: every unverified contract this handler could own at one HD index (pure
|
|
3994
|
-
* derivation, no I/O). `discoverRange` probes these and the look-ahead band subscribes to
|
|
3995
|
-
* them, so the two cover the same set. `boarding` omits it (deposits have their own channel).
|
|
3996
|
-
*/
|
|
3997
|
-
candidatesAt?(index: number, descriptor: string, deps: CandidateDeps): DiscoveredContract[];
|
|
3998
|
-
}
|
|
3999
|
-
/** Duck-typed guard for the pure candidate surface. @see Discoverable.candidatesAt */
|
|
4000
|
-
declare function hasCandidates(handler: ContractHandler<unknown> | undefined): handler is ContractHandler<unknown> & Required<Pick<Discoverable, "candidatesAt">>;
|
|
4001
|
-
/** Duck-typed guard (mirrors `hasReceiveRotatorFactory`). */
|
|
4002
|
-
declare function isDiscoverable(handler: ContractHandler<unknown> | undefined): handler is ContractHandler<unknown> & Discoverable;
|
|
4003
|
-
/**
|
|
4004
|
-
* The per-contract tapscript annotation stamped onto every VTXO locked to a
|
|
4005
|
-
* contract (see `extendVirtualCoinForContract`): the leaf used to co-sign
|
|
4006
|
-
* forfeits, the leaf committed in proofs, and the encoded taproot tree.
|
|
4007
|
-
*/
|
|
4008
|
-
interface DerivedContractTapscripts {
|
|
4009
|
-
forfeitTapLeafScript: TapLeafScript;
|
|
4010
|
-
intentTapLeafScript: TapLeafScript;
|
|
4011
|
-
tapTree: Bytes;
|
|
4012
|
-
}
|
|
4013
|
-
/**
|
|
4014
|
-
* Optional {@link ContractHandler} capability providing the forfeit/intent tapscripts for VTXO
|
|
4015
|
-
* annotation, for scripts without the legacy `forfeit()` (e.g. program-compiled arkade contracts).
|
|
4016
|
-
* Must be pure in `(contract.type, contract.script, contract.params)`: `ContractManager` memoizes
|
|
4017
|
-
* the result for its lifetime.
|
|
4018
|
-
*/
|
|
4019
|
-
interface TapscriptDeriving<S extends VtxoScript = VtxoScript> {
|
|
4020
|
-
deriveTapscripts(script: S, contract: Contract): DerivedContractTapscripts;
|
|
4021
|
-
}
|
|
4022
|
-
/** A script the watcher reports on without the wallet owning it. */
|
|
4023
|
-
interface WatchedScript {
|
|
4024
|
-
script: string;
|
|
4025
|
-
/** Free-form tag echoed back by `getWatchedScripts`; never sent anywhere. */
|
|
4026
|
-
label?: string;
|
|
4027
|
-
}
|
|
4028
|
-
/**
|
|
4029
|
-
* Event emitted when contract-related changes occur. Watch-only scripts report the same
|
|
4030
|
-
* `vtxo_received` / `vtxo_spent` types without a `contract`; that absence is the ownership
|
|
4031
|
-
* boundary, so `event.contract` only compiles after {@link isContractVtxoEvent}.
|
|
4032
|
-
*/
|
|
4033
|
-
type ContractEvent = {
|
|
4034
|
-
type: "vtxo_received";
|
|
4035
|
-
contractScript: string;
|
|
4036
|
-
vtxos: ContractVtxo[];
|
|
4037
|
-
contract: Contract;
|
|
4038
|
-
timestamp: number;
|
|
4039
|
-
} | {
|
|
4040
|
-
type: "vtxo_spent";
|
|
4041
|
-
contractScript: string;
|
|
4042
|
-
vtxos: ContractVtxo[];
|
|
4043
|
-
contract: Contract;
|
|
4044
|
-
timestamp: number;
|
|
4045
|
-
} | {
|
|
4046
|
-
type: "vtxo_received";
|
|
4047
|
-
contractScript: string;
|
|
4048
|
-
vtxos: VirtualCoin[];
|
|
4049
|
-
timestamp: number;
|
|
4050
|
-
} | {
|
|
4051
|
-
type: "vtxo_spent";
|
|
4052
|
-
contractScript: string;
|
|
4053
|
-
vtxos: VirtualCoin[];
|
|
4054
|
-
timestamp: number;
|
|
4055
|
-
} | {
|
|
4056
|
-
type: "connection_reset";
|
|
4057
|
-
timestamp: number;
|
|
4058
|
-
};
|
|
4059
|
-
type ContractVtxoEvent = Extract<ContractEvent, {
|
|
4060
|
-
contract: Contract;
|
|
4061
|
-
}>;
|
|
4062
|
-
/**
|
|
4063
|
-
* Gate every wallet-side effect on this: a watch-only event has no contract.
|
|
4064
|
-
* @example `if (!isContractVtxoEvent(event)) return;` inside `onContractEvent`,
|
|
4065
|
-
* before reading `event.contract` — which does not compile without it.
|
|
4066
|
-
*/
|
|
4067
|
-
declare function isContractVtxoEvent(event: ContractEvent): event is ContractVtxoEvent;
|
|
4068
|
-
/** Callback for contract events. */
|
|
4069
|
-
type ContractEventCallback = (event: ContractEvent) => void;
|
|
4070
|
-
/** Options for retrieving contracts from the Contract Manager (currently the repository filter). */
|
|
4071
|
-
type GetContractsFilter = ContractFilter;
|
|
4072
|
-
/** Contract with its virtual outputs included. */
|
|
4073
|
-
type ContractWithVtxos = {
|
|
4074
|
-
contract: Contract;
|
|
4075
|
-
vtxos: ExtendedContractVtxo[];
|
|
4076
|
-
};
|
|
4077
|
-
/** Summary of a contract's balance. */
|
|
4078
|
-
interface ContractBalance {
|
|
4079
|
-
/** Total balance (settled + pending) in satoshis */
|
|
4080
|
-
total: number;
|
|
4081
|
-
/** Spendable balance in satoshis */
|
|
4082
|
-
spendable: number;
|
|
4083
|
-
/** Number of virtual outputs in this contract */
|
|
4084
|
-
vtxoCount: number;
|
|
4085
|
-
}
|
|
4086
|
-
|
|
4087
|
-
/**
|
|
4088
|
-
* Configuration for the ContractWatcher.
|
|
4089
|
-
*
|
|
4090
|
-
* @see ContractWatcher
|
|
4091
|
-
*
|
|
4092
|
-
* @example
|
|
4093
|
-
* ```typescript
|
|
4094
|
-
* const watcher = new ContractWatcher({
|
|
4095
|
-
* indexerProvider,
|
|
4096
|
-
* walletRepository,
|
|
4097
|
-
* })
|
|
4098
|
-
* ```
|
|
4099
|
-
*/
|
|
4100
|
-
interface ContractWatcherConfig {
|
|
4101
|
-
/** Indexer provider used for subscriptions and queries. */
|
|
4102
|
-
indexerProvider: IndexerProvider;
|
|
4103
|
-
/** Wallet repository used to store virtual output state between watcher updates. */
|
|
4104
|
-
walletRepository: WalletRepository;
|
|
3737
|
+
deleteContract(script: string): Promise<void>;
|
|
4105
3738
|
/**
|
|
4106
|
-
*
|
|
4107
|
-
*
|
|
4108
|
-
* @defaultValue `20_000` (20 seconds)
|
|
3739
|
+
* Chain tip for a {@link PathContext}, or `undefined` when no source is configured or it
|
|
3740
|
+
* can't be read. Cached for {@link CHAIN_TIP_TTL_MS}.
|
|
4109
3741
|
*/
|
|
4110
|
-
|
|
3742
|
+
private currentChainTip;
|
|
3743
|
+
/** One chain tip read, bounded by {@link CHAIN_TIP_TIMEOUT_MS}. Never rejects. */
|
|
3744
|
+
private readChainTip;
|
|
3745
|
+
/** Get currently spendable paths for a contract. */
|
|
3746
|
+
getSpendablePaths(options: GetSpendablePathsOptions): Promise<PathSelection[]>;
|
|
4111
3747
|
/**
|
|
4112
|
-
*
|
|
4113
|
-
*
|
|
4114
|
-
* @defaultValue `1_000` (1 second)
|
|
3748
|
+
* Get every currently valid spending path for a contract. No `blockHeight`: no handler
|
|
3749
|
+
* evaluates a timelock here, so fetching the tip would only add network latency.
|
|
4115
3750
|
*/
|
|
4116
|
-
|
|
3751
|
+
getAllSpendingPaths(options: GetAllSpendingPathsOptions): Promise<PathSelection[]>;
|
|
4117
3752
|
/**
|
|
4118
|
-
*
|
|
3753
|
+
* Register a callback for contract events (watching already started in `initialize()`).
|
|
4119
3754
|
*
|
|
4120
|
-
* @
|
|
3755
|
+
* @returns Unsubscribe function to remove this callback
|
|
3756
|
+
*
|
|
3757
|
+
* @example
|
|
3758
|
+
* ```typescript
|
|
3759
|
+
* const unsubscribe = manager.onContractEvent((event) => {
|
|
3760
|
+
* console.log(`${event.type} on ${event.contractScript}`);
|
|
3761
|
+
* });
|
|
3762
|
+
*
|
|
3763
|
+
* // Later: stop receiving events
|
|
3764
|
+
* unsubscribe();
|
|
3765
|
+
* ```
|
|
4121
3766
|
*/
|
|
4122
|
-
|
|
3767
|
+
onContractEvent(callback: ContractEventCallback): () => void;
|
|
4123
3768
|
/**
|
|
4124
|
-
*
|
|
3769
|
+
* Force refresh virtual outputs from the indexer. Without options, re-fetches the watched set
|
|
3770
|
+
* and advances the global cursor; see {@link RefreshVtxosOptions} for how each option scopes.
|
|
3771
|
+
*/
|
|
3772
|
+
refreshVtxos(opts?: RefreshVtxosOptions): Promise<void>;
|
|
3773
|
+
refreshOutpoints(outpoints: Outpoint[]): Promise<void>;
|
|
3774
|
+
isWatching(): Promise<boolean>;
|
|
3775
|
+
/** @see IContractManager.watchScript */
|
|
3776
|
+
watchScript(script: string | string[], options?: {
|
|
3777
|
+
label?: string;
|
|
3778
|
+
}): Promise<void>;
|
|
3779
|
+
/** @see IContractManager.unwatchScript */
|
|
3780
|
+
unwatchScript(script: string | string[]): Promise<void>;
|
|
3781
|
+
/** @see IContractManager.getWatchedScripts */
|
|
3782
|
+
getWatchedScripts(): Promise<WatchedScript[]>;
|
|
3783
|
+
/** @see IContractManager.syncOnchain */
|
|
3784
|
+
syncOnchain(scripts?: string[], fetched?: ReadonlyMap<string, Coin[]>): Promise<void>;
|
|
3785
|
+
/**
|
|
3786
|
+
* @see IContractManager.markOnchainSpendPending
|
|
3787
|
+
* @throws naming every outpoint that is not a stored, unconfirmed onchain coin; nothing is written then.
|
|
3788
|
+
*/
|
|
3789
|
+
markOnchainSpendPending(outpoints: Outpoint[], txid: string, options?: {
|
|
3790
|
+
skipUnknown?: boolean;
|
|
3791
|
+
height?: number;
|
|
3792
|
+
}): Promise<void>;
|
|
3793
|
+
private readPendingSpends;
|
|
3794
|
+
private updatePendingSpends;
|
|
3795
|
+
private inOnchainOrder;
|
|
3796
|
+
private runOnchainSync;
|
|
3797
|
+
private syncOnchainContract;
|
|
3798
|
+
/**
|
|
3799
|
+
* arkd's record of how these onchain coins were spent, by outpoint: empty if it keeps none,
|
|
3800
|
+
* undefined if the lookup failed.
|
|
3801
|
+
*/
|
|
3802
|
+
private serverSpends;
|
|
3803
|
+
/**
|
|
3804
|
+
* Emit an event to all registered callbacks.
|
|
3805
|
+
*/
|
|
3806
|
+
private emitEvent;
|
|
3807
|
+
/** Resolves `false` when the event's sync failed, so the watcher keeps its poll off. */
|
|
3808
|
+
private handleContractEvent;
|
|
3809
|
+
private getVtxosForContracts;
|
|
3810
|
+
/** Sync virtual outputs for the given contracts (default: the watched set). */
|
|
3811
|
+
private syncContracts;
|
|
3812
|
+
private performContractSync;
|
|
3813
|
+
private syncedWithin;
|
|
3814
|
+
/**
|
|
3815
|
+
* Demote every funded `awaiting-funds` contract to `retained` (see {@link ContractWatchState}).
|
|
4125
3816
|
*
|
|
4126
|
-
*
|
|
3817
|
+
* Runs after the sync persisted, so the funding VTXO is saved while still watched, and reads
|
|
3818
|
+
* the repository rather than this delta: funds that landed while the app was closed are
|
|
3819
|
+
* outside every later window. Best-effort: must not fail the sync that carried it.
|
|
4127
3820
|
*/
|
|
4128
|
-
|
|
3821
|
+
private demoteFundedAwaitingContracts;
|
|
4129
3822
|
/**
|
|
4130
|
-
*
|
|
4131
|
-
*
|
|
3823
|
+
* Fetch all pending (unfinalized) virtual outputs and upsert them, catching state changes
|
|
3824
|
+
* outside the delta window (e.g. a spend that hasn't settled yet).
|
|
3825
|
+
*/
|
|
3826
|
+
private reconcilePendingFrontier;
|
|
3827
|
+
private persistContractVtxos;
|
|
3828
|
+
private fetchContractVxosFromIndexer;
|
|
3829
|
+
private fetchContractVtxosBulk;
|
|
3830
|
+
/**
|
|
3831
|
+
* Stop the watcher, clear callbacks, and mark the manager uninitialized.
|
|
4132
3832
|
*
|
|
4133
|
-
*
|
|
4134
|
-
*
|
|
3833
|
+
* Teardown is synchronous. The returned promise settles once watcher events already being
|
|
3834
|
+
* handled, any look-ahead drain, any onchain sync and any lazy boot sequence finish; after that
|
|
3835
|
+
* nothing more is written to the repositories.
|
|
4135
3836
|
*/
|
|
4136
|
-
|
|
3837
|
+
dispose(): Promise<void>;
|
|
3838
|
+
/**
|
|
3839
|
+
* Symbol.dispose implementation for the `using` keyword. Teardown is immediate, but it does
|
|
3840
|
+
* not wait for in-flight work; use `await using` for that.
|
|
3841
|
+
*/
|
|
3842
|
+
[Symbol.dispose](): void;
|
|
3843
|
+
/**
|
|
3844
|
+
* Symbol.asyncDispose implementation for the `await using` keyword; waits like {@link dispose}.
|
|
3845
|
+
* @example
|
|
3846
|
+
* ```typescript
|
|
3847
|
+
* {
|
|
3848
|
+
* await using manager = await wallet.getContractManager();
|
|
3849
|
+
* // ... use manager
|
|
3850
|
+
* } // disposed, with in-flight events finished
|
|
3851
|
+
* ```
|
|
3852
|
+
*/
|
|
3853
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
4137
3854
|
}
|
|
3855
|
+
|
|
4138
3856
|
/**
|
|
4139
|
-
*
|
|
4140
|
-
*
|
|
3857
|
+
* Contract lifecycle state. Governs receive-address selection only: `inactive` does **not**
|
|
3858
|
+
* unsubscribe (a retired receive address can still be paid; coverage follows
|
|
3859
|
+
* {@link Contract.watch} alone). To stop watching but keep the row use `retained`
|
|
3860
|
+
* {@link ContractWatchState}; to drop both, {@link IContractManager.deleteContract}.
|
|
4141
3861
|
*/
|
|
4142
|
-
type
|
|
4143
|
-
type ConnectionState = "disconnected" | "connecting" | "connected" | "reconnecting";
|
|
3862
|
+
type ContractState = "active" | "inactive";
|
|
4144
3863
|
/**
|
|
4145
|
-
*
|
|
4146
|
-
*
|
|
3864
|
+
* Whether a contract is covered by background monitoring (subscription and failsafe/indexer
|
|
3865
|
+
* sweep, {@link ContractWatcher.getWatchedContracts}). Orthogonal to {@link ContractState}.
|
|
4147
3866
|
*
|
|
4148
|
-
*
|
|
4149
|
-
*
|
|
3867
|
+
* NArk parity: `ContractActivityState`; renamed because `active`/`inactive` are taken by
|
|
3868
|
+
* {@link ContractState}.
|
|
3869
|
+
*/
|
|
3870
|
+
type ContractWatchState =
|
|
3871
|
+
/** Subscribed and polled. */
|
|
3872
|
+
"watched"
|
|
3873
|
+
/**
|
|
3874
|
+
* Watched until the first VTXO lands, then demoted to `retained` by the contract manager.
|
|
3875
|
+
* For one-shot destinations (refund address, swap lockup).
|
|
3876
|
+
*/
|
|
3877
|
+
| "awaiting-funds"
|
|
3878
|
+
/**
|
|
3879
|
+
* Not subscribed or polled, but still resolves in `getContracts`, annotates its VTXOs and
|
|
3880
|
+
* feeds transaction history.
|
|
3881
|
+
*/
|
|
3882
|
+
| "retained";
|
|
3883
|
+
/** Which layer(s) a contract's coins live on. */
|
|
3884
|
+
type ContractScope = "offchain" | "onchain" | "both";
|
|
3885
|
+
/**
|
|
3886
|
+
* A contract that can receive and manage virtual outputs. Its type and parameters determine the
|
|
3887
|
+
* VtxoScript (spending paths); the wallet's default receiving address is a `"default"` contract,
|
|
3888
|
+
* and external services (swaps, etc.) register their own types.
|
|
4150
3889
|
*
|
|
4151
3890
|
* @example
|
|
4152
3891
|
* ```typescript
|
|
4153
|
-
* const
|
|
4154
|
-
*
|
|
4155
|
-
*
|
|
4156
|
-
*
|
|
4157
|
-
*
|
|
4158
|
-
*
|
|
4159
|
-
*
|
|
4160
|
-
*
|
|
4161
|
-
*
|
|
4162
|
-
*
|
|
4163
|
-
*
|
|
4164
|
-
*
|
|
4165
|
-
*
|
|
4166
|
-
*
|
|
4167
|
-
*
|
|
4168
|
-
* // Later: stop watching
|
|
4169
|
-
* stop();
|
|
3892
|
+
* const vhtlcContract: Contract = {
|
|
3893
|
+
* type: "vhtlc",
|
|
3894
|
+
* params: {
|
|
3895
|
+
* sender: "ab12...",
|
|
3896
|
+
* receiver: "cd34...",
|
|
3897
|
+
* server: "ef56...",
|
|
3898
|
+
* hash: "1234...",
|
|
3899
|
+
* refundLocktime: "800000",
|
|
3900
|
+
* // ... timelocks
|
|
3901
|
+
* },
|
|
3902
|
+
* script: "5120...",
|
|
3903
|
+
* address: "ark1q...",
|
|
3904
|
+
* state: "active",
|
|
3905
|
+
* createdAt: 1704067200000,
|
|
3906
|
+
* };
|
|
4170
3907
|
* ```
|
|
4171
3908
|
*/
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
/**
|
|
4176
|
-
|
|
4177
|
-
private subscriptionId?;
|
|
4178
|
-
private abortController?;
|
|
4179
|
-
private isWatching;
|
|
4180
|
-
private eventCallback?;
|
|
4181
|
-
private connectionState;
|
|
4182
|
-
private reconnectAttempts;
|
|
4183
|
-
private reconnectTimeoutId?;
|
|
4184
|
-
private failsafePollIntervalId?;
|
|
4185
|
-
/** See {@link withCoalescedSubscription}. */
|
|
4186
|
-
private subscriptionBatchDepth;
|
|
4187
|
-
private subscriptionUpdateDeferred;
|
|
4188
|
-
/** Subscription POSTs can fail while the event stream remains healthy. */
|
|
4189
|
-
private subscriptionRetryTimeoutId?;
|
|
4190
|
-
private subscriptionRetryAttempts;
|
|
4191
|
-
/** A failed update needs catch-up even when reconnect owns the next attempt. */
|
|
4192
|
-
private subscriptionNeedsCatchUp;
|
|
4193
|
-
/** Serialize subscription creation and updates against the latest desired scripts. */
|
|
4194
|
-
private subscriptionUpdate;
|
|
4195
|
-
/** See {@link reportEventSourceUnavailable} — said once, not per attempt. */
|
|
4196
|
-
private eventSourceReported;
|
|
4197
|
-
/** @see ContractWatcherConfig */
|
|
4198
|
-
constructor(config: ContractWatcherConfig);
|
|
4199
|
-
/**
|
|
4200
|
-
* Add a contract to be watched. Every contract is subscribed and polled whatever its
|
|
4201
|
-
* {@link ContractState}, except a `retained` one, which is held for reads only.
|
|
4202
|
-
*
|
|
4203
|
-
* @see getWatchedContracts
|
|
4204
|
-
*/
|
|
4205
|
-
addContract(contract: Contract): Promise<void>;
|
|
4206
|
-
/** Pre-populate `lastKnownVtxos` from the wallet repository so polls emit only real deltas. */
|
|
4207
|
-
private seedLastKnownVtxos;
|
|
4208
|
-
updateContract(contract: Contract): Promise<void>;
|
|
4209
|
-
removeContract(contractScript: string): Promise<void>;
|
|
4210
|
-
/** All in-memory contracts. */
|
|
4211
|
-
getAllContracts(): Contract[];
|
|
4212
|
-
/**
|
|
4213
|
-
* Every registered contract except `retained` ones, retired (`inactive`) addresses included.
|
|
4214
|
-
*
|
|
4215
|
-
* Feeds both the subscription and the sweep scope. `state` must never narrow it: an Ark
|
|
4216
|
-
* receive address can be paid again after the wallet rotated past it, and such a payment
|
|
4217
|
-
* would stay invisible. Only an owner's explicit {@link ContractWatchState} narrows it; the
|
|
4218
|
-
* row stays in the repository for reads, annotation and history.
|
|
4219
|
-
*/
|
|
4220
|
-
getWatchedContracts(): Contract[];
|
|
4221
|
-
/** Scripts the subscription carries; wider than the sync scope {@link getWatchedContracts}. */
|
|
4222
|
-
private getSubscribedScripts;
|
|
4223
|
-
/** @see IContractManager.watchScript for the delivery and filter contract. */
|
|
4224
|
-
addWatchedScript(script: string | string[], options?: {
|
|
4225
|
-
label?: string;
|
|
4226
|
-
}): Promise<void>;
|
|
4227
|
-
/** Stop watching a script added by {@link addWatchedScript}. */
|
|
4228
|
-
removeWatchedScript(script: string | string[]): Promise<void>;
|
|
4229
|
-
/** Every script registered via {@link addWatchedScript}. */
|
|
4230
|
-
getWatchedScripts(): WatchedScript[];
|
|
4231
|
-
/** Repository virtual outputs for contracts, grouped by contract script. */
|
|
4232
|
-
private getContractVtxos;
|
|
4233
|
-
/** Start watching for virtual output events across all watched contracts. */
|
|
4234
|
-
startWatching(callback: ContractWatcherEventCallback): Promise<() => void>;
|
|
4235
|
-
stopWatching(): Promise<void>;
|
|
4236
|
-
isCurrentlyWatching(): boolean;
|
|
4237
|
-
getConnectionState(): ConnectionState;
|
|
4238
|
-
/** Force a poll of all watched contracts (manual refresh, app resume). */
|
|
4239
|
-
forcePoll(): Promise<void>;
|
|
4240
|
-
/** @param skipUpdate - The caller already established `subscriptionId`. */
|
|
4241
|
-
private connect;
|
|
4242
|
-
/**
|
|
4243
|
-
* Handle "this environment has no `EventSource`": warn once and return true so the caller
|
|
4244
|
-
* skips reconnecting. A missing global is not a dropped connection; unlimited backoff would
|
|
4245
|
-
* retry forever and fire a `connection_reset` (read as "resync, stream coming back") every
|
|
4246
|
-
* few seconds.
|
|
4247
|
-
*/
|
|
4248
|
-
private reportEventSourceUnavailable;
|
|
4249
|
-
private scheduleReconnect;
|
|
4250
|
-
/** Replays repository state — only what a sync stored; watch-only scripts poll the indexer. */
|
|
4251
|
-
private startFailsafePolling;
|
|
4252
|
-
private pollAllContracts;
|
|
3909
|
+
interface Contract {
|
|
3910
|
+
/** Human-readable label for display purposes. */
|
|
3911
|
+
label?: string;
|
|
3912
|
+
/** Contract type identifier (e.g. "default", "vhtlc"); custom types add a ContractHandler. */
|
|
3913
|
+
type: string;
|
|
4253
3914
|
/**
|
|
4254
|
-
*
|
|
4255
|
-
*
|
|
4256
|
-
* every live output would read as spent.
|
|
3915
|
+
* Type-specific VtxoScript parameters, serialized as strings (hex for bytes, string for
|
|
3916
|
+
* bigint) and interpreted by the type's ContractHandler.
|
|
4257
3917
|
*/
|
|
4258
|
-
|
|
4259
|
-
/**
|
|
4260
|
-
|
|
3918
|
+
params: Record<string, string>;
|
|
3919
|
+
/** The pkScript hex, used as the unique identifier and primary key for contracts. */
|
|
3920
|
+
script: string;
|
|
3921
|
+
/** Address derived from the contract script. */
|
|
3922
|
+
address: string;
|
|
3923
|
+
/** Current state of the contract. */
|
|
3924
|
+
state: ContractState;
|
|
4261
3925
|
/**
|
|
4262
|
-
*
|
|
4263
|
-
*
|
|
4264
|
-
* be quadratic.
|
|
4265
|
-
*
|
|
4266
|
-
* A contract added inside the scope isn't streaming until the flush, and the failsafe poll
|
|
4267
|
-
* only replays repository state. Callers must supply their own catch-up (`Wallet.restore`
|
|
4268
|
-
* follows `scanContracts` with a bulk `refreshVtxos`) or keep the scope short.
|
|
3926
|
+
* Background-monitoring scope. Absent means `watched`.
|
|
3927
|
+
* @see ContractWatchState
|
|
4269
3928
|
*/
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
3929
|
+
watch?: ContractWatchState;
|
|
3930
|
+
/** Layers this contract's coins live on. Absent ⇒ the handler's `defaultScope`, else `"offchain"`. */
|
|
3931
|
+
scope?: ContractScope;
|
|
3932
|
+
/** Unix timestamp in milliseconds when this contract was created. */
|
|
3933
|
+
createdAt: number;
|
|
3934
|
+
/** Optional metadata for external integrations. */
|
|
3935
|
+
metadata?: Record<string, unknown>;
|
|
3936
|
+
}
|
|
3937
|
+
/** A virtual output associated with a specific contract. */
|
|
3938
|
+
type ContractVtxo = VirtualCoin & Partial<TapLeaves & EncodedVtxoScript> & {
|
|
3939
|
+
extraWitness?: Bytes[];
|
|
3940
|
+
contractScript: string;
|
|
3941
|
+
};
|
|
3942
|
+
/**
|
|
3943
|
+
* A {@link ContractVtxo} with all taproot annotation fields required (mirrors the
|
|
3944
|
+
* {@link ExtendedVirtualCoin} / {@link VirtualCoin} split). Use it wherever the compiler should
|
|
3945
|
+
* enforce that `annotateVtxos` has run, e.g. `saveVtxos` and forfeit construction.
|
|
3946
|
+
*/
|
|
3947
|
+
type ExtendedContractVtxo = NormalizedExtendedVirtualCoin & {
|
|
3948
|
+
contractScript: string;
|
|
3949
|
+
};
|
|
3950
|
+
/** Result of path selection: the tapleaf to use and any extra witness data. */
|
|
3951
|
+
interface PathSelection {
|
|
3952
|
+
/** Tapleaf script to use for spending. */
|
|
3953
|
+
leaf: TapLeafScript;
|
|
3954
|
+
/** Additional witness elements, for example a preimage for HTLC-like paths. */
|
|
3955
|
+
extraWitness?: Bytes[];
|
|
4279
3956
|
/**
|
|
4280
|
-
*
|
|
4281
|
-
*
|
|
3957
|
+
* nSequence for the spending input, BIP-68 encoded when the leaf
|
|
3958
|
+
* uses CSV. Decode with `sequenceToTimelock`; do NOT use as an
|
|
3959
|
+
* absolute `Transaction.lockTime`.
|
|
4282
3960
|
*/
|
|
4283
|
-
|
|
3961
|
+
sequence?: number;
|
|
3962
|
+
}
|
|
3963
|
+
/** Context for path selection decisions. */
|
|
3964
|
+
interface PathContext {
|
|
3965
|
+
/** Whether collaborative spending is available through server cooperation. */
|
|
3966
|
+
collaborative: boolean;
|
|
3967
|
+
/** Current time in milliseconds. */
|
|
3968
|
+
currentTime: number;
|
|
3969
|
+
/** Current block height, when known. */
|
|
3970
|
+
blockHeight?: number;
|
|
4284
3971
|
/**
|
|
4285
|
-
*
|
|
4286
|
-
*
|
|
3972
|
+
* Wallet's signing descriptor: `tr(pubkey)` for static keys,
|
|
3973
|
+
* `tr([fingerprint/path']xpub/0/{index})` for HD. Handlers use it to find the wallet's role.
|
|
4287
3974
|
*/
|
|
4288
|
-
|
|
4289
|
-
/** As {@link emitVtxoEvent}, less the `contract` and the annotation. */
|
|
4290
|
-
private emitWatchedScriptEvent;
|
|
4291
|
-
private emitVtxoEvent;
|
|
4292
|
-
/** A successful reset reconciles every watched contract, so it clears {@link ContractState.stale}. */
|
|
4293
|
-
private emitConnectionReset;
|
|
4294
|
-
}
|
|
4295
|
-
|
|
4296
|
-
/** Delegate identity and fee information returned by `getDelegateInfo`. */
|
|
4297
|
-
interface DelegateInfo {
|
|
4298
|
-
/** Delegate public key. */
|
|
4299
|
-
pubkey: string;
|
|
4300
|
-
/** Delegate fee amount or expression returned by the delegate. */
|
|
4301
|
-
fee: string;
|
|
4302
|
-
/** Address for delegate fee collection. */
|
|
4303
|
-
delegateAddress: string;
|
|
4304
|
-
}
|
|
4305
|
-
/** Optional delegate behavior flags. */
|
|
4306
|
-
interface DelegateOptions {
|
|
3975
|
+
walletDescriptor?: string;
|
|
4307
3976
|
/**
|
|
4308
|
-
*
|
|
4309
|
-
*
|
|
4310
|
-
*
|
|
4311
|
-
* @defaultValue `false`
|
|
3977
|
+
* Explicit role override for multi-party contracts such as VHTLC. If absent, handlers may
|
|
3978
|
+
* match {@link walletDescriptor} against the contract's sender/receiver params.
|
|
4312
3979
|
*/
|
|
4313
|
-
|
|
4314
|
-
}
|
|
4315
|
-
/** Provider interface for a remote delegation service. */
|
|
4316
|
-
interface DelegateProvider {
|
|
3980
|
+
role?: string;
|
|
4317
3981
|
/**
|
|
4318
|
-
*
|
|
4319
|
-
*
|
|
4320
|
-
*
|
|
3982
|
+
* Chain tip timestamp in SECONDS, when known. Seconds-typed timelock checks should prefer it
|
|
3983
|
+
* over {@link currentTime}: the server matures absolute locktimes against median-time-past,
|
|
3984
|
+
* which trails wall clock, and host clock drift would skew the decision.
|
|
4321
3985
|
*/
|
|
4322
|
-
|
|
4323
|
-
/**
|
|
4324
|
-
|
|
3986
|
+
chainTime?: number;
|
|
3987
|
+
/** The specific virtual output being evaluated. */
|
|
3988
|
+
vtxo?: VirtualCoin;
|
|
4325
3989
|
}
|
|
4326
3990
|
/**
|
|
4327
|
-
*
|
|
3991
|
+
* Handler for a specific contract type.
|
|
3992
|
+
*
|
|
3993
|
+
* Each contract type (`default`, `vhtlc`, etc.) has a handler that knows how to:
|
|
3994
|
+
* 1. Create the VtxoScript from parameters
|
|
3995
|
+
* 2. Serialize/deserialize parameters for storage
|
|
3996
|
+
* 3. Select the appropriate spending path based on context
|
|
3997
|
+
*
|
|
4328
3998
|
* @example
|
|
4329
3999
|
* ```typescript
|
|
4330
|
-
* const
|
|
4331
|
-
*
|
|
4332
|
-
*
|
|
4000
|
+
* const vhtlcHandler: ContractHandler = {
|
|
4001
|
+
* type: "vhtlc",
|
|
4002
|
+
* createScript(params) {
|
|
4003
|
+
* return new VHTLC.Script(this.deserializeParams(params));
|
|
4004
|
+
* },
|
|
4005
|
+
* selectPath(script, contract, context) {
|
|
4006
|
+
* const vhtlc = script as VHTLC.Script;
|
|
4007
|
+
* const preimage = contract.data?.preimage;
|
|
4008
|
+
* if (context.collaborative && preimage) {
|
|
4009
|
+
* return { leaf: vhtlc.claim(), extraWitness: [hex.decode(preimage)] };
|
|
4010
|
+
* }
|
|
4011
|
+
* // ... other paths
|
|
4012
|
+
* },
|
|
4013
|
+
* // ...
|
|
4014
|
+
* };
|
|
4333
4015
|
* ```
|
|
4334
4016
|
*/
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4017
|
+
interface ContractHandler<P = Record<string, unknown>, S extends VtxoScript = VtxoScript> {
|
|
4018
|
+
/** Contract type managed by this handler. */
|
|
4019
|
+
readonly type: string;
|
|
4020
|
+
/** Scope of contracts of this type that don't set {@link Contract.scope}. */
|
|
4021
|
+
readonly defaultScope?: ContractScope;
|
|
4022
|
+
/** Create the VtxoScript from serialized parameters. */
|
|
4023
|
+
createScript(params: Record<string, string>): S;
|
|
4024
|
+
/** Serialize typed parameters to string key-value pairs. */
|
|
4025
|
+
serializeParams(params: P): Record<string, string>;
|
|
4026
|
+
/** Deserialize string key-value pairs to typed parameters. */
|
|
4027
|
+
deserializeParams(params: Record<string, string>): P;
|
|
4339
4028
|
/**
|
|
4340
|
-
*
|
|
4029
|
+
* Select the preferred spending path (e.g. collaborative over unilateral).
|
|
4341
4030
|
*
|
|
4342
|
-
* @
|
|
4031
|
+
* @returns PathSelection if a viable path exists, null otherwise
|
|
4343
4032
|
*/
|
|
4344
|
-
|
|
4033
|
+
selectPath(script: S, contract: Contract, context: PathContext): PathSelection | null;
|
|
4034
|
+
/** All possible spending paths for the context, regardless of current spendability. */
|
|
4035
|
+
getAllSpendingPaths(script: S, contract: Contract, context: PathContext): PathSelection[];
|
|
4036
|
+
/** All currently spendable paths (empty if none). */
|
|
4037
|
+
getSpendablePaths(script: S, contract: Contract, context: PathContext): PathSelection[];
|
|
4345
4038
|
/**
|
|
4346
|
-
*
|
|
4039
|
+
* Whether this contract's VTXOs may be picked by *generic* wallet spending (send, settle,
|
|
4040
|
+
* renewal, asset operations, offboard, `available` balance). Explicit-input APIs
|
|
4041
|
+
* (`settle({ inputs })`, `send({ selectedVtxos })`) stay open regardless.
|
|
4347
4042
|
*
|
|
4348
|
-
*
|
|
4043
|
+
* Pure, synchronous and offline (runs in the service worker). Absent or `false` ⇒ NOT
|
|
4044
|
+
* spendable, so an unknown type can't leak by omission. No `script` param: deriving a taproot
|
|
4045
|
+
* tree per contract on a read path is costly (#521); use `createScript` if needed.
|
|
4349
4046
|
*/
|
|
4350
|
-
|
|
4351
|
-
}
|
|
4352
|
-
|
|
4353
|
-
interface IDelegateManager {
|
|
4047
|
+
isGenericallySpendable?(contract: Contract): boolean;
|
|
4354
4048
|
/**
|
|
4355
|
-
*
|
|
4049
|
+
* Refuse, before signing, an explicitly named input this contract definitively cannot spend
|
|
4050
|
+
* now (e.g. an immature timelock), with an actionable reason instead of an opaque server
|
|
4051
|
+
* rejection. Counterpart to {@link isGenericallySpendable}, which leaves explicit inputs open.
|
|
4356
4052
|
*
|
|
4357
|
-
*
|
|
4358
|
-
*
|
|
4359
|
-
*
|
|
4053
|
+
* **Throw only on a definite no**; absent or unsure means the spend proceeds. An empty
|
|
4054
|
+
* `getSpendablePaths` is not a no (`arkade`'s skips covenant leaves), nor is an unreadable
|
|
4055
|
+
* timelock (height-typed with no chain tip) — @see cltvMaturity. May return a promise for
|
|
4056
|
+
* I/O, but prefer synchronous: it sits on the spend path.
|
|
4360
4057
|
*
|
|
4361
|
-
* @
|
|
4362
|
-
* @param destination - Arkade address that should receive renewed funds
|
|
4363
|
-
* @param delegateAt - Optional timestamp to force a specific delegation time
|
|
4364
|
-
* @returns Successfully delegated and failed outpoint groups
|
|
4058
|
+
* @throws Error when the contract provably cannot be spent at `context`
|
|
4365
4059
|
*/
|
|
4366
|
-
|
|
4367
|
-
delegated: Outpoint[];
|
|
4368
|
-
failed: {
|
|
4369
|
-
outpoints: Outpoint[];
|
|
4370
|
-
error: unknown;
|
|
4371
|
-
}[];
|
|
4372
|
-
}>;
|
|
4373
|
-
/** Fetch delegate metadata such as pubkey, fee, and delegate address. */
|
|
4374
|
-
getDelegateInfo(): Promise<DelegateInfo>;
|
|
4060
|
+
assertSpendableNow?(script: S, contract: Contract, context: PathContext): void | Promise<void>;
|
|
4375
4061
|
}
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
error: unknown;
|
|
4388
|
-
}[];
|
|
4389
|
-
}>;
|
|
4062
|
+
/**
|
|
4063
|
+
* What {@link Discoverable.discoverAt} returns: exactly what `ContractManager.createContract`
|
|
4064
|
+
* accepts (script-keyed, idempotent on re-register).
|
|
4065
|
+
*/
|
|
4066
|
+
interface DiscoveredContract {
|
|
4067
|
+
type: string;
|
|
4068
|
+
params: Record<string, string>;
|
|
4069
|
+
script: string;
|
|
4070
|
+
address: string;
|
|
4071
|
+
metadata?: Record<string, unknown>;
|
|
4072
|
+
label?: string;
|
|
4390
4073
|
}
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4074
|
+
/**
|
|
4075
|
+
* Read-only context the scanner injects into every `discoverAt` call. Never carries an external
|
|
4076
|
+
* service client; a handler needing one closes over it at registration.
|
|
4077
|
+
*/
|
|
4078
|
+
interface DiscoveryDeps {
|
|
4079
|
+
indexerProvider: IndexerProvider;
|
|
4080
|
+
onchainProvider: OnchainProvider;
|
|
4081
|
+
/** Ark-address network data; `{ hrp }` is all L2 (`default`/`delegate`) discovery needs. */
|
|
4082
|
+
network: {
|
|
4083
|
+
hrp: string;
|
|
4084
|
+
};
|
|
4085
|
+
/**
|
|
4086
|
+
* Full Bitcoin network for on-chain (P2TR) addresses, needed by boarding discovery (`{ hrp }`
|
|
4087
|
+
* lacks the `bech32` data). When absent, boarding `discoverAt` no-ops.
|
|
4399
4088
|
*/
|
|
4400
|
-
|
|
4401
|
-
/** Human label for the action, e.g. "Dice game". */
|
|
4402
|
-
label?: string;
|
|
4403
|
-
/** App category for icon/filtering, e.g. "game". */
|
|
4404
|
-
kind?: string;
|
|
4089
|
+
onchainNetwork?: Network;
|
|
4405
4090
|
/**
|
|
4406
|
-
*
|
|
4407
|
-
*
|
|
4408
|
-
* copy or icon, not display text. Merged first-writer-wins across
|
|
4409
|
-
* resolvers sharing a `groupId`, like `label` and `kind`.
|
|
4091
|
+
* The server's **current** signer key (x-only, 32 bytes) from a fresh server-info snapshot at
|
|
4092
|
+
* restore time; L2 discovery probes it first.
|
|
4410
4093
|
*/
|
|
4411
|
-
|
|
4094
|
+
serverPubKey: Uint8Array;
|
|
4412
4095
|
/**
|
|
4413
|
-
*
|
|
4414
|
-
*
|
|
4096
|
+
* The server's **deprecated** signer keys (x-only, 32 bytes) from the same snapshot. L2
|
|
4097
|
+
* discovery scans them too so signer rotation doesn't strand funds; boarding discovery
|
|
4098
|
+
* ignores them (current UTXO set only).
|
|
4415
4099
|
*/
|
|
4416
|
-
|
|
4100
|
+
deprecatedSignerPubKeys?: Uint8Array[];
|
|
4101
|
+
/** Relative timelocks the wallet treats as its baseline matrix. */
|
|
4102
|
+
csvTimelocks: RelativeTimelock[];
|
|
4417
4103
|
/**
|
|
4418
|
-
*
|
|
4419
|
-
*
|
|
4420
|
-
*
|
|
4421
|
-
* as change and excluded from `Activity.amount`. A membership with a
|
|
4422
|
-
* non-finite amount (NaN/Infinity) is dropped.
|
|
4104
|
+
* Boarding-exit CSV timelock (the server's boarding-exit delay), distinct from the
|
|
4105
|
+
* unilateral-exit {@link DiscoveryDeps.csvTimelocks}. When absent, boarding `discoverAt`
|
|
4106
|
+
* no-ops.
|
|
4423
4107
|
*/
|
|
4424
|
-
|
|
4108
|
+
boardingTimelock?: RelativeTimelock;
|
|
4109
|
+
/** Present only for delegate wallets. */
|
|
4110
|
+
delegatePubKey?: Uint8Array;
|
|
4425
4111
|
}
|
|
4426
|
-
/**
|
|
4427
|
-
|
|
4112
|
+
/**
|
|
4113
|
+
* The I/O-free subset of {@link DiscoveryDeps}: the axes a receive script can
|
|
4114
|
+
* be anchored to. `DiscoveryDeps` satisfies it structurally, so one
|
|
4115
|
+
* {@link Discoverable.candidatesAt} serves the scan and the look-ahead band.
|
|
4116
|
+
*/
|
|
4117
|
+
type CandidateDeps = Pick<DiscoveryDeps, "network" | "serverPubKey" | "csvTimelocks"> & Pick<Partial<DiscoveryDeps>, "deprecatedSignerPubKeys" | "delegatePubKey">;
|
|
4118
|
+
/**
|
|
4119
|
+
* Optional {@link ContractHandler} capability for `wallet.restore()`'s gap-limit scan. The scanner
|
|
4120
|
+
* owns the index loop and gap counter; the handler answers "do I own a contract at this index?"
|
|
4121
|
+
* from its own source, and may batch/cache across calls.
|
|
4122
|
+
*/
|
|
4123
|
+
interface Discoverable {
|
|
4124
|
+
discoverAt(index: number, descriptor: string, deps: DiscoveryDeps): Promise<DiscoveredContract[]>;
|
|
4428
4125
|
/**
|
|
4429
|
-
*
|
|
4430
|
-
*
|
|
4431
|
-
*
|
|
4126
|
+
* Optional: answer a whole scan window in one batched round-trip; preferred over per-index
|
|
4127
|
+
* `discoverAt` when present. Per-address sources (e.g. boarding on Esplora) omit it.
|
|
4128
|
+
*
|
|
4129
|
+
* **All-or-nothing per call.** Resolve with a map covering *every* requested index (empty
|
|
4130
|
+
* array = confirmed miss) or reject; a missing index would read as "no funds" and close the
|
|
4131
|
+
* gap window on a failed request. The scanner treats an incomplete map as a rejection (hits
|
|
4132
|
+
* still persisted, scan truncated at the range's first index); unrequested indices are ignored.
|
|
4432
4133
|
*/
|
|
4433
|
-
|
|
4134
|
+
discoverRange?(entries: readonly {
|
|
4135
|
+
index: number;
|
|
4136
|
+
descriptor: string;
|
|
4137
|
+
}[], deps: DiscoveryDeps): Promise<Map<number, DiscoveredContract[]>>;
|
|
4434
4138
|
/**
|
|
4435
|
-
*
|
|
4436
|
-
*
|
|
4139
|
+
* Optional: every unverified contract this handler could own at one HD index (pure
|
|
4140
|
+
* derivation, no I/O). `discoverRange` probes these and the look-ahead band subscribes to
|
|
4141
|
+
* them, so the two cover the same set. `boarding` omits it (deposits have their own channel).
|
|
4437
4142
|
*/
|
|
4438
|
-
|
|
4439
|
-
/** Pure and synchronous. The groups this tx belongs to, or undefined to leave it plain. */
|
|
4440
|
-
resolve(tx: ArkTransaction): GroupMembership[] | undefined;
|
|
4143
|
+
candidatesAt?(index: number, descriptor: string, deps: CandidateDeps): DiscoveredContract[];
|
|
4441
4144
|
}
|
|
4442
|
-
/**
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
/**
|
|
4455
|
-
|
|
4145
|
+
/** Duck-typed guard for the pure candidate surface. @see Discoverable.candidatesAt */
|
|
4146
|
+
declare function hasCandidates(handler: ContractHandler<unknown> | undefined): handler is ContractHandler<unknown> & Required<Pick<Discoverable, "candidatesAt">>;
|
|
4147
|
+
/** Duck-typed guard (mirrors `hasReceiveRotatorFactory`). */
|
|
4148
|
+
declare function isDiscoverable(handler: ContractHandler<unknown> | undefined): handler is ContractHandler<unknown> & Discoverable;
|
|
4149
|
+
/**
|
|
4150
|
+
* The per-contract tapscript annotation stamped onto every VTXO locked to a
|
|
4151
|
+
* contract (see `extendVirtualCoinForContract`): the leaf used to co-sign
|
|
4152
|
+
* forfeits, the leaf committed in proofs, and the encoded taproot tree.
|
|
4153
|
+
*/
|
|
4154
|
+
interface DerivedContractTapscripts {
|
|
4155
|
+
forfeitTapLeafScript: TapLeafScript;
|
|
4156
|
+
proofTapLeafScript: TapLeafScript;
|
|
4157
|
+
/** @deprecated Use {@link proofTapLeafScript}. */
|
|
4158
|
+
intentTapLeafScript?: TapLeafScript;
|
|
4159
|
+
tapTree: Bytes;
|
|
4456
4160
|
}
|
|
4457
|
-
/**
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
/** Signed net sats: positive received, negative sent; same-key change rows are excluded. */
|
|
4466
|
-
amount: number;
|
|
4467
|
-
/** Earliest member createdAt (ms since epoch). */
|
|
4468
|
-
createdAt: number;
|
|
4469
|
-
/** True once every member tx is settled. */
|
|
4470
|
-
settled: boolean;
|
|
4161
|
+
/**
|
|
4162
|
+
* Optional {@link ContractHandler} capability providing the forfeit/proof tapscripts for VTXO
|
|
4163
|
+
* annotation, for scripts without the legacy `forfeit()` (e.g. program-compiled arkade contracts).
|
|
4164
|
+
* Must be pure in `(contract.type, contract.script, contract.params)`: `ContractManager` memoizes
|
|
4165
|
+
* the result for its lifetime.
|
|
4166
|
+
*/
|
|
4167
|
+
interface TapscriptDeriving<S extends VtxoScript = VtxoScript> {
|
|
4168
|
+
deriveTapscripts(script: S, contract: Contract): DerivedContractTapscripts;
|
|
4471
4169
|
}
|
|
4472
|
-
/**
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
/**
|
|
4476
|
-
|
|
4477
|
-
/** Remove a resolver (built-in or custom) by id. */
|
|
4478
|
-
remove(id: string): void;
|
|
4479
|
-
/** The registered resolver ids, in registration order. */
|
|
4480
|
-
list(): string[];
|
|
4481
|
-
/** All registered resolvers, in registration (priority) order. */
|
|
4482
|
-
all(): ActivityResolver[];
|
|
4170
|
+
/** A script the watcher reports on without the wallet owning it. */
|
|
4171
|
+
interface WatchedScript {
|
|
4172
|
+
script: string;
|
|
4173
|
+
/** Free-form tag echoed back by `getWatchedScripts`; never sent anywhere. */
|
|
4174
|
+
label?: string;
|
|
4483
4175
|
}
|
|
4484
|
-
/** Built-in resolver: labels on-chain boarding (deposit) transactions. */
|
|
4485
|
-
declare function boardingResolver(): ActivityResolver;
|
|
4486
|
-
/** Built-in resolver: labels collaborative exits (VTXOs forfeited to chain in a batch). */
|
|
4487
|
-
declare function collabExitResolver(): ActivityResolver;
|
|
4488
4176
|
/**
|
|
4489
|
-
*
|
|
4490
|
-
*
|
|
4491
|
-
*
|
|
4492
|
-
* transfers carry the asset under a different `arkTxid`, so they are left plain.
|
|
4493
|
-
*
|
|
4494
|
-
* `metadata.amount` is the decimal string of the asset's `bigint` amount, kept
|
|
4495
|
-
* as a string so large supplies survive JSON round-trips without truncation.
|
|
4496
|
-
* Recover the value with `BigInt(metadata.amount as string)` — using it
|
|
4497
|
-
* directly in arithmetic coerces (`"10" + 1` is `"101"`, not `11`) and loses
|
|
4498
|
-
* precision past `Number.MAX_SAFE_INTEGER`.
|
|
4177
|
+
* Event emitted when contract-related changes occur. Watch-only scripts report the same
|
|
4178
|
+
* `vtxo_received` / `vtxo_spent` types without a `contract`; that absence is the ownership
|
|
4179
|
+
* boundary, so `event.contract` only compiles after {@link isContractVtxoEvent}.
|
|
4499
4180
|
*/
|
|
4500
|
-
|
|
4181
|
+
type ContractEvent = {
|
|
4182
|
+
type: "vtxo_received";
|
|
4183
|
+
contractScript: string;
|
|
4184
|
+
vtxos: ContractVtxo[];
|
|
4185
|
+
contract: Contract;
|
|
4186
|
+
timestamp: number;
|
|
4187
|
+
} | {
|
|
4188
|
+
type: "vtxo_spent";
|
|
4189
|
+
contractScript: string;
|
|
4190
|
+
vtxos: ContractVtxo[];
|
|
4191
|
+
contract: Contract;
|
|
4192
|
+
timestamp: number;
|
|
4193
|
+
} | {
|
|
4194
|
+
type: "vtxo_received";
|
|
4195
|
+
contractScript: string;
|
|
4196
|
+
vtxos: VirtualCoin[];
|
|
4197
|
+
timestamp: number;
|
|
4198
|
+
} | {
|
|
4199
|
+
type: "vtxo_spent";
|
|
4200
|
+
contractScript: string;
|
|
4201
|
+
vtxos: VirtualCoin[];
|
|
4202
|
+
timestamp: number;
|
|
4203
|
+
} | {
|
|
4204
|
+
type: "connection_reset";
|
|
4205
|
+
timestamp: number;
|
|
4206
|
+
};
|
|
4207
|
+
type ContractVtxoEvent = Extract<ContractEvent, {
|
|
4208
|
+
contract: Contract;
|
|
4209
|
+
}>;
|
|
4501
4210
|
/**
|
|
4502
|
-
*
|
|
4503
|
-
* `
|
|
4211
|
+
* Gate every wallet-side effect on this: a watch-only event has no contract.
|
|
4212
|
+
* @example `if (!isContractVtxoEvent(event)) return;` inside `onContractEvent`,
|
|
4213
|
+
* before reading `event.contract` — which does not compile without it.
|
|
4504
4214
|
*/
|
|
4505
|
-
declare function
|
|
4215
|
+
declare function isContractVtxoEvent(event: ContractEvent): event is ContractVtxoEvent;
|
|
4216
|
+
/** Callback for contract events. */
|
|
4217
|
+
type ContractEventCallback = (event: ContractEvent) => void;
|
|
4218
|
+
/** Options for retrieving contracts from the Contract Manager (currently the repository filter). */
|
|
4219
|
+
type GetContractsFilter = ContractFilter;
|
|
4220
|
+
/** Contract with its virtual outputs included. */
|
|
4221
|
+
type ContractWithVtxos = {
|
|
4222
|
+
contract: Contract;
|
|
4223
|
+
vtxos: ExtendedContractVtxo[];
|
|
4224
|
+
};
|
|
4225
|
+
/** Summary of a contract's balance. */
|
|
4226
|
+
interface ContractBalance {
|
|
4227
|
+
/** Total balance (settled + pending) in satoshis */
|
|
4228
|
+
total: number;
|
|
4229
|
+
/** Spendable balance in satoshis */
|
|
4230
|
+
spendable: number;
|
|
4231
|
+
/** Number of virtual outputs in this contract */
|
|
4232
|
+
vtxoCount: number;
|
|
4233
|
+
}
|
|
4506
4234
|
|
|
4507
4235
|
/**
|
|
4508
|
-
*
|
|
4509
|
-
*
|
|
4510
|
-
*
|
|
4236
|
+
* Configuration for the ContractWatcher.
|
|
4237
|
+
*
|
|
4238
|
+
* @see ContractWatcher
|
|
4239
|
+
*
|
|
4240
|
+
* @example
|
|
4241
|
+
* ```typescript
|
|
4242
|
+
* const watcher = new ContractWatcher({
|
|
4243
|
+
* indexerProvider,
|
|
4244
|
+
* walletRepository,
|
|
4245
|
+
* })
|
|
4246
|
+
* ```
|
|
4511
4247
|
*/
|
|
4512
|
-
interface
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
4248
|
+
interface ContractWatcherConfig {
|
|
4249
|
+
/** Indexer provider used for subscriptions and queries. */
|
|
4250
|
+
indexerProvider: IndexerProvider;
|
|
4251
|
+
/** Wallet repository used to store virtual output state between watcher updates. */
|
|
4252
|
+
walletRepository: WalletRepository;
|
|
4253
|
+
/**
|
|
4254
|
+
* Failsafe polling interval (ms); polls even while subscribed, to catch missed events.
|
|
4255
|
+
*
|
|
4256
|
+
* @defaultValue `20_000` (20 seconds)
|
|
4257
|
+
*/
|
|
4258
|
+
failsafePollIntervalMs?: number;
|
|
4259
|
+
/**
|
|
4260
|
+
* Initial delay for reconnection and subscription update retries (ms), backed off exponentially.
|
|
4261
|
+
*
|
|
4262
|
+
* @defaultValue `1_000` (1 second)
|
|
4263
|
+
*/
|
|
4264
|
+
reconnectDelayMs?: number;
|
|
4265
|
+
/**
|
|
4266
|
+
* Maximum delay for reconnection and subscription update retries (ms).
|
|
4267
|
+
*
|
|
4268
|
+
* @defaultValue `5_000` (5 seconds)
|
|
4269
|
+
*/
|
|
4270
|
+
maxReconnectDelayMs?: number;
|
|
4271
|
+
/**
|
|
4272
|
+
* Maximum retry attempts per reconnection or subscription update failure; 0 for unlimited.
|
|
4273
|
+
*
|
|
4274
|
+
* @defaultValue `0` (unlimited)
|
|
4275
|
+
*/
|
|
4276
|
+
maxReconnectAttempts?: number;
|
|
4277
|
+
/**
|
|
4278
|
+
* Deadline for each subscription POST, including its response body (ms).
|
|
4279
|
+
* Timeouts use the subscription retry policy without interrupting the event stream.
|
|
4280
|
+
*
|
|
4281
|
+
* @defaultValue `30_000` (30 seconds)
|
|
4282
|
+
* @remarks Must be greater than zero; a subscription request needs a finite deadline.
|
|
4283
|
+
*/
|
|
4284
|
+
subscriptionRequestTimeoutMs?: number;
|
|
4523
4285
|
}
|
|
4524
4286
|
/**
|
|
4525
|
-
*
|
|
4526
|
-
*
|
|
4527
|
-
* repository. With no repository this is exactly the indexer path (a no-op seam).
|
|
4287
|
+
* A returned promise holds off the poll until the event's handling settles; resolving `false` or
|
|
4288
|
+
* rejecting keeps it off until a later handling succeeds.
|
|
4528
4289
|
*/
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
repository?: VirtualTxRepository;
|
|
4532
|
-
extraSources?: ExitDataSource[];
|
|
4533
|
-
}): ExitChainResolver;
|
|
4534
|
-
|
|
4535
|
-
type ExitCaptureMode = "lite" | "full";
|
|
4536
|
-
|
|
4290
|
+
type ContractWatcherEventCallback = (event: ContractEvent) => unknown;
|
|
4291
|
+
type ConnectionState = "disconnected" | "connecting" | "connected" | "reconnecting";
|
|
4537
4292
|
/**
|
|
4538
|
-
*
|
|
4539
|
-
*
|
|
4540
|
-
* The emulator is a signing service that executes Arkade scripts
|
|
4541
|
-
* and co-signs transactions when the scripts pass validation.
|
|
4293
|
+
* Watches contracts for virtual output changes: subscription with exponential-backoff reconnect,
|
|
4294
|
+
* a poll after every (re)connect, and failsafe polling for missed events.
|
|
4542
4295
|
*
|
|
4543
|
-
*
|
|
4544
|
-
*
|
|
4545
|
-
* deliberately do not: aborting a submit would not tell the caller whether the
|
|
4546
|
-
* emulator signed, and none of them has a way to find out, so they stay on the
|
|
4547
|
-
* global `fetch` with their transport-error type unchanged.
|
|
4548
|
-
*/
|
|
4549
|
-
|
|
4550
|
-
interface EmulatorInfo {
|
|
4551
|
-
signerPubkey: string;
|
|
4552
|
-
}
|
|
4553
|
-
interface EmulatorProvider {
|
|
4554
|
-
getInfo(): Promise<EmulatorInfo>;
|
|
4555
|
-
submitTx(arkTx: string, checkpointTxs: string[]): Promise<{
|
|
4556
|
-
signedArkTx: string;
|
|
4557
|
-
signedCheckpointTxs: string[];
|
|
4558
|
-
}>;
|
|
4559
|
-
submitIntent(intent: {
|
|
4560
|
-
proof: string;
|
|
4561
|
-
message: Intent.RegisterMessage;
|
|
4562
|
-
}): Promise<string>;
|
|
4563
|
-
submitFinalization(intent: {
|
|
4564
|
-
proof: string;
|
|
4565
|
-
message: Proof.RegisterMessage;
|
|
4566
|
-
}, forfeits: string[], connectorTree: ConnectorTreeNode[] | null, commitmentTx: string): Promise<{
|
|
4567
|
-
signedForfeits: string[];
|
|
4568
|
-
signedCommitmentTx?: string;
|
|
4569
|
-
}>;
|
|
4570
|
-
submitOnchainTx(tx: string): Promise<{
|
|
4571
|
-
signedTx: string;
|
|
4572
|
-
}>;
|
|
4573
|
-
}
|
|
4574
|
-
interface ConnectorTreeNode {
|
|
4575
|
-
txid: string;
|
|
4576
|
-
tx: string;
|
|
4577
|
-
children: Record<string, string>;
|
|
4578
|
-
}
|
|
4579
|
-
/**
|
|
4580
|
-
* REST-based emulator client.
|
|
4296
|
+
* Event-only: it reads the wallet repository for baselines but never writes it;
|
|
4297
|
+
* `ContractManager` owns persistence.
|
|
4581
4298
|
*
|
|
4582
4299
|
* @example
|
|
4583
4300
|
* ```typescript
|
|
4584
|
-
* const
|
|
4585
|
-
*
|
|
4586
|
-
*
|
|
4301
|
+
* const watcher = new ContractWatcher({
|
|
4302
|
+
* indexerProvider: wallet.indexerProvider,
|
|
4303
|
+
* });
|
|
4304
|
+
*
|
|
4305
|
+
* // Add the wallet's default contract
|
|
4306
|
+
* await watcher.addContract(defaultContract);
|
|
4307
|
+
*
|
|
4308
|
+
* // Add additional contracts (swaps, etc.)
|
|
4309
|
+
* await watcher.addContract(swapContract);
|
|
4310
|
+
*
|
|
4311
|
+
* // Start watching for events
|
|
4312
|
+
* const stop = await watcher.startWatching((event) => {
|
|
4313
|
+
* console.log(`${event.type} on contract ${event.contractScript}`);
|
|
4314
|
+
* });
|
|
4315
|
+
*
|
|
4316
|
+
* // Later: stop watching
|
|
4317
|
+
* stop();
|
|
4587
4318
|
* ```
|
|
4588
4319
|
*/
|
|
4589
|
-
declare class
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4320
|
+
declare class ContractWatcher {
|
|
4321
|
+
private config;
|
|
4322
|
+
private contracts;
|
|
4323
|
+
/** In-memory and process-lifetime; never persisted. */
|
|
4324
|
+
private watchedScripts;
|
|
4325
|
+
private subscriptionId?;
|
|
4326
|
+
private abortController?;
|
|
4327
|
+
private isWatching;
|
|
4328
|
+
private eventCallback?;
|
|
4329
|
+
private connectionState;
|
|
4330
|
+
private reconnectAttempts;
|
|
4331
|
+
private reconnectTimeoutId?;
|
|
4332
|
+
private failsafePollIntervalId?;
|
|
4333
|
+
/** See {@link withCoalescedSubscription}. */
|
|
4334
|
+
private subscriptionBatchDepth;
|
|
4335
|
+
private subscriptionUpdateDeferred;
|
|
4336
|
+
/** Subscription POSTs can fail while the event stream remains healthy. */
|
|
4337
|
+
private subscriptionRetryTimeoutId?;
|
|
4338
|
+
private subscriptionRetryAttempts;
|
|
4339
|
+
/** A failed update needs catch-up even when reconnect owns the next attempt. */
|
|
4340
|
+
private subscriptionNeedsCatchUp;
|
|
4341
|
+
/** Serialize subscription creation and updates against the latest desired scripts. */
|
|
4342
|
+
private subscriptionUpdate;
|
|
4343
|
+
/** See {@link reportEventSourceUnavailable} — said once, not per attempt. */
|
|
4344
|
+
private eventSourceReported;
|
|
4345
|
+
/** @see ContractWatcherConfig */
|
|
4346
|
+
constructor(config: ContractWatcherConfig);
|
|
4347
|
+
/**
|
|
4348
|
+
* Add a contract to be watched. Every contract is subscribed and polled whatever its
|
|
4349
|
+
* {@link ContractState}, except a `retained` one, which is held for reads only.
|
|
4350
|
+
*
|
|
4351
|
+
* @see getWatchedContracts
|
|
4352
|
+
*/
|
|
4353
|
+
addContract(contract: Contract): Promise<void>;
|
|
4354
|
+
/** Pre-populate `lastKnownVtxos` from the wallet repository so polls emit only real deltas. */
|
|
4355
|
+
private seedLastKnownVtxos;
|
|
4356
|
+
updateContract(contract: Contract): Promise<void>;
|
|
4357
|
+
removeContract(contractScript: string): Promise<void>;
|
|
4358
|
+
/** All in-memory contracts. */
|
|
4359
|
+
getAllContracts(): Contract[];
|
|
4360
|
+
/**
|
|
4361
|
+
* Every registered contract except `retained` ones, retired (`inactive`) addresses included.
|
|
4362
|
+
*
|
|
4363
|
+
* Feeds both the subscription and the sweep scope. `state` must never narrow it: an Ark
|
|
4364
|
+
* receive address can be paid again after the wallet rotated past it, and such a payment
|
|
4365
|
+
* would stay invisible. Only an owner's explicit {@link ContractWatchState} narrows it; the
|
|
4366
|
+
* row stays in the repository for reads, annotation and history.
|
|
4367
|
+
*/
|
|
4368
|
+
getWatchedContracts(): Contract[];
|
|
4369
|
+
/** Scripts the subscription carries; wider than the sync scope {@link getWatchedContracts}. */
|
|
4370
|
+
private getSubscribedScripts;
|
|
4371
|
+
/** @see IContractManager.watchScript for the delivery and filter contract. */
|
|
4372
|
+
addWatchedScript(script: string | string[], options?: {
|
|
4373
|
+
label?: string;
|
|
4374
|
+
}): Promise<void>;
|
|
4375
|
+
/** Stop watching a script added by {@link addWatchedScript}. */
|
|
4376
|
+
removeWatchedScript(script: string | string[]): Promise<void>;
|
|
4377
|
+
/** Every script registered via {@link addWatchedScript}. */
|
|
4378
|
+
getWatchedScripts(): WatchedScript[];
|
|
4379
|
+
/** Repository virtual outputs for contracts, grouped by contract script. */
|
|
4380
|
+
private getContractVtxos;
|
|
4381
|
+
/** Start watching for virtual output events across all watched contracts. */
|
|
4382
|
+
startWatching(callback: ContractWatcherEventCallback): Promise<() => void>;
|
|
4383
|
+
stopWatching(): Promise<void>;
|
|
4384
|
+
isCurrentlyWatching(): boolean;
|
|
4385
|
+
getConnectionState(): ConnectionState;
|
|
4386
|
+
/** Force a poll of all watched contracts (manual refresh, app resume). */
|
|
4387
|
+
forcePoll(): Promise<void>;
|
|
4388
|
+
/** @param skipUpdate - The caller already established `subscriptionId`. */
|
|
4389
|
+
private connect;
|
|
4390
|
+
/**
|
|
4391
|
+
* Handle "this environment has no `EventSource`": warn once and return true so the caller
|
|
4392
|
+
* skips reconnecting. A missing global is not a dropped connection; unlimited backoff would
|
|
4393
|
+
* retry forever and fire a `connection_reset` (read as "resync, stream coming back") every
|
|
4394
|
+
* few seconds.
|
|
4395
|
+
*/
|
|
4396
|
+
private reportEventSourceUnavailable;
|
|
4397
|
+
private scheduleReconnect;
|
|
4398
|
+
/** Replays repository state — only what a sync stored; watch-only scripts poll the indexer. */
|
|
4399
|
+
private startFailsafePolling;
|
|
4400
|
+
private pollAllContracts;
|
|
4401
|
+
/**
|
|
4402
|
+
* Poll watch-only scripts against the indexer and emit the delta. Not {@link pollContracts}:
|
|
4403
|
+
* that diffs the wallet repository, permanently empty for a script the wallet doesn't own, so
|
|
4404
|
+
* every live output would read as spent.
|
|
4405
|
+
*/
|
|
4406
|
+
private pollWatchedScripts;
|
|
4407
|
+
/** Poll specific contracts' repository state and emit events for changes. */
|
|
4408
|
+
private pollContracts;
|
|
4409
|
+
/**
|
|
4410
|
+
* Run `fn` with subscription updates coalesced into one `subscribeForScripts` on the way out
|
|
4411
|
+
* (success or error). Each subscribe posts the *whole* script list, so N eager updates would
|
|
4412
|
+
* be quadratic.
|
|
4413
|
+
*
|
|
4414
|
+
* A contract added inside the scope isn't streaming until the flush, and the failsafe poll
|
|
4415
|
+
* only replays repository state. Callers must supply their own catch-up (`Wallet.restore`
|
|
4416
|
+
* follows `scanContracts` with a bulk `refreshVtxos`) or keep the scope short.
|
|
4417
|
+
*/
|
|
4418
|
+
withCoalescedSubscription<T>(fn: () => Promise<T>): Promise<T>;
|
|
4419
|
+
private tryUpdateSubscription;
|
|
4420
|
+
private cancelSubscriptionRetry;
|
|
4421
|
+
private scheduleSubscriptionRetry;
|
|
4422
|
+
/** @see getSubscribedScripts */
|
|
4423
|
+
private updateSubscription;
|
|
4424
|
+
private sendSubscriptionUpdate;
|
|
4425
|
+
private subscribeWithTimeout;
|
|
4426
|
+
private listenLoop;
|
|
4427
|
+
/**
|
|
4428
|
+
* Normalization boundary: a consumer `IndexerProvider` may yield legacy-shaped VTXOs, and the
|
|
4429
|
+
* normalized shape is what external event consumers receive.
|
|
4430
|
+
*/
|
|
4431
|
+
private handleSubscriptionUpdate;
|
|
4432
|
+
/**
|
|
4433
|
+
* Route each subscription VTXO to the single contract locking it via `vtxo.script`, skipping
|
|
4434
|
+
* unknown scripts: fan-out produced phantom state in non-owning contracts.
|
|
4435
|
+
*/
|
|
4436
|
+
private processSubscriptionVtxos;
|
|
4437
|
+
/** As {@link emitVtxoEvent}, less the `contract` and the annotation. */
|
|
4438
|
+
private emitWatchedScriptEvent;
|
|
4439
|
+
private emitVtxoEvent;
|
|
4440
|
+
/** A successful reset reconciles every watched contract, so it clears {@link ContractState.stale}. */
|
|
4441
|
+
private emitConnectionReset;
|
|
4611
4442
|
}
|
|
4612
4443
|
|
|
4613
4444
|
/**
|
|
@@ -4640,7 +4471,7 @@ interface ResolvedArkadeService {
|
|
|
4640
4471
|
/** The operator's cosigner that emulates Arkade Script; absent for an `operatorUrl` service
|
|
4641
4472
|
* without `emulatorUrl`. */
|
|
4642
4473
|
emulator?: EmulatorProvider;
|
|
4643
|
-
info:
|
|
4474
|
+
info: OperatorInfo;
|
|
4644
4475
|
}
|
|
4645
4476
|
/**
|
|
4646
4477
|
* Resolve a service into providers and the operator's info.
|
|
@@ -4651,7 +4482,7 @@ interface ResolvedArkadeService {
|
|
|
4651
4482
|
*/
|
|
4652
4483
|
declare function resolveArkadeService(service: ArkadeService, opts?: {
|
|
4653
4484
|
arkProvider?: OperatorProvider;
|
|
4654
|
-
info?:
|
|
4485
|
+
info?: OperatorInfo;
|
|
4655
4486
|
}): Promise<ResolvedArkadeService>;
|
|
4656
4487
|
|
|
4657
4488
|
/**
|
|
@@ -4716,7 +4547,7 @@ interface NewAddress {
|
|
|
4716
4547
|
* @see StorageConfig
|
|
4717
4548
|
*/
|
|
4718
4549
|
interface BaseWalletConfig {
|
|
4719
|
-
/** Optional
|
|
4550
|
+
/** Optional operator public key used to construct and validate Arkade addresses. */
|
|
4720
4551
|
arkServerPublicKey?: string;
|
|
4721
4552
|
/** Relative timelock applied to boarding scripts. */
|
|
4722
4553
|
boardingTimelock?: RelativeTimelock;
|
|
@@ -4858,6 +4689,15 @@ interface WalletConfig extends ReadonlyWalletConfig {
|
|
|
4858
4689
|
* @defaultValue `false`
|
|
4859
4690
|
*/
|
|
4860
4691
|
concurrentSpending?: boolean;
|
|
4692
|
+
/** Cosigns onchain inputs whose spend carries an emulator packet; no default. */
|
|
4693
|
+
emulator?: EmulatorProvider;
|
|
4694
|
+
/**
|
|
4695
|
+
* Minimum blocks that must remain before a coin's exit CSV matures for the
|
|
4696
|
+
* client to request an onchain cosign. Non-negative integer.
|
|
4697
|
+
*
|
|
4698
|
+
* @defaultValue 6
|
|
4699
|
+
*/
|
|
4700
|
+
onchainCosignMarginBlocks?: number;
|
|
4861
4701
|
}
|
|
4862
4702
|
/**
|
|
4863
4703
|
* Repository implementations used to store wallet and contract state.
|
|
@@ -4875,10 +4715,10 @@ type StorageConfig = {
|
|
|
4875
4715
|
* Optional intent-lifecycle repository. Opt-in: when present, the wallet
|
|
4876
4716
|
* persists settlement intents and excludes intent-locked VTXOs from
|
|
4877
4717
|
* spendable balance. Absent ⇒ those code paths are no-ops. Only one wallet
|
|
4878
|
-
* instance may settle against it: reconciliation deletes from the
|
|
4718
|
+
* instance may settle against it: reconciliation deletes from the operator any
|
|
4879
4719
|
* pending intent that instance is not settling itself.
|
|
4880
4720
|
*/
|
|
4881
|
-
intentRepository?:
|
|
4721
|
+
intentRepository?: BatchRegistrationRepository;
|
|
4882
4722
|
/**
|
|
4883
4723
|
* Optional virtual-tx (exit-branch) repository. When set, the wallet captures each received
|
|
4884
4724
|
* VTXO's exit branch into it and prunes it on spend (both best-effort, see
|
|
@@ -4901,8 +4741,8 @@ type StorageConfig = {
|
|
|
4901
4741
|
};
|
|
4902
4742
|
/** Provider class constructor shape for dependency injection. */
|
|
4903
4743
|
interface ProviderClass<T> {
|
|
4904
|
-
/** @param
|
|
4905
|
-
new (
|
|
4744
|
+
/** @param operatorUrl - Base operator URL used by the provider */
|
|
4745
|
+
new (operatorUrl: string): T;
|
|
4906
4746
|
}
|
|
4907
4747
|
/**
|
|
4908
4748
|
* Balance summary returned by `IWallet.getBalance`.
|
|
@@ -5082,6 +4922,17 @@ interface SendParams {
|
|
|
5082
4922
|
/** Maximum sats of unavoidable change this send may pay as an offchain fee. Defaults to any change below the operator's VTXO minimum; 0 disables it. */
|
|
5083
4923
|
maxChangeFee?: number;
|
|
5084
4924
|
}
|
|
4925
|
+
/** Arguments of {@link IWallet.sendOnchain}. */
|
|
4926
|
+
type SendOnchainParams = {
|
|
4927
|
+
outputs: {
|
|
4928
|
+
address: string;
|
|
4929
|
+
amount: number;
|
|
4930
|
+
}[];
|
|
4931
|
+
/** Spend only these onchain coins; defaults to every cosignable generically spendable coin. */
|
|
4932
|
+
inputs?: Outpoint[];
|
|
4933
|
+
/** Spend every selected cosignable coin to this address (Σin − fee); `outputs` must be empty. */
|
|
4934
|
+
sweepTo?: string;
|
|
4935
|
+
};
|
|
5085
4936
|
/**
|
|
5086
4937
|
* Known asset metadata fields.
|
|
5087
4938
|
*
|
|
@@ -5214,6 +5065,8 @@ interface Status {
|
|
|
5214
5065
|
block_hash?: string;
|
|
5215
5066
|
/** Block time where the output was confirmed, when known. */
|
|
5216
5067
|
block_time?: number;
|
|
5068
|
+
/** Set on an onchain coin the contract manager stored from the onchain provider. */
|
|
5069
|
+
fromExplorer?: boolean;
|
|
5217
5070
|
}
|
|
5218
5071
|
/** Onchain output location data. */
|
|
5219
5072
|
interface Outpoint {
|
|
@@ -5254,7 +5107,7 @@ interface VirtualCoin extends Coin {
|
|
|
5254
5107
|
isUnrolled: boolean;
|
|
5255
5108
|
/** Whether this output was spent offchain (`spentBy` helper); not set for unrolled or swept. */
|
|
5256
5109
|
isSpent?: boolean;
|
|
5257
|
-
/** Whether the
|
|
5110
|
+
/** Whether the operator has swept the batch this virtual output belongs to. */
|
|
5258
5111
|
isSwept?: boolean;
|
|
5259
5112
|
/** Whether this virtual output is not yet finalized in a batch. */
|
|
5260
5113
|
isPreconfirmed?: boolean;
|
|
@@ -5272,14 +5125,14 @@ interface VirtualCoin extends Coin {
|
|
|
5272
5125
|
/** Batch commitment transaction(s) this virtual output depends on. */
|
|
5273
5126
|
commitmentTxIds?: string[];
|
|
5274
5127
|
/**
|
|
5275
|
-
* Wall-clock batch expiry, when the
|
|
5128
|
+
* Wall-clock batch expiry, when the operator expressed expiry as a timestamp.
|
|
5276
5129
|
*
|
|
5277
5130
|
* @remarks
|
|
5278
5131
|
* Mutually exclusive with `expiresAtHeight`; both are absent when there is no expiry.
|
|
5279
5132
|
*/
|
|
5280
5133
|
expiresAt?: Date;
|
|
5281
5134
|
/**
|
|
5282
|
-
* Block-height batch expiry, when the
|
|
5135
|
+
* Block-height batch expiry, when the operator expressed expiry as a height (regtest-like
|
|
5283
5136
|
* deployments). Evaluating it needs a chain tip — see {@link isPastExpiry}.
|
|
5284
5137
|
*/
|
|
5285
5138
|
expiresAtHeight?: number;
|
|
@@ -5350,8 +5203,13 @@ interface ArkTransaction {
|
|
|
5350
5203
|
type TapLeaves = {
|
|
5351
5204
|
/** Tapleaf script used for the forfeit path. */
|
|
5352
5205
|
forfeitTapLeafScript: TapLeafScript;
|
|
5353
|
-
/** Tapleaf script
|
|
5354
|
-
|
|
5206
|
+
/** Tapleaf script a proof signs for this coin. */
|
|
5207
|
+
proofTapLeafScript: TapLeafScript;
|
|
5208
|
+
/**
|
|
5209
|
+
* @deprecated Use {@link proofTapLeafScript}. SDK coins never set this key.
|
|
5210
|
+
* A coin that sets it signs proofs with this leaf.
|
|
5211
|
+
*/
|
|
5212
|
+
intentTapLeafScript?: TapLeafScript;
|
|
5355
5213
|
};
|
|
5356
5214
|
/**
|
|
5357
5215
|
* Onchain output data enriched with tapscript and witness data.
|
|
@@ -5453,12 +5311,14 @@ interface IAssetManager extends IReadonlyAssetManager {
|
|
|
5453
5311
|
*/
|
|
5454
5312
|
burn(params: BurnParams): Promise<string>;
|
|
5455
5313
|
}
|
|
5456
|
-
/** Options for {@link IReadonlyWallet.
|
|
5457
|
-
type
|
|
5314
|
+
/** Options for {@link IReadonlyWallet.getOperatorInfo}. */
|
|
5315
|
+
type GetOperatorInfoOptions = {
|
|
5458
5316
|
/** Throw when the operator is unreachable instead of answering from the
|
|
5459
5317
|
* persisted snapshot — for callers binding the answer into a covenant. */
|
|
5460
5318
|
requireLive?: boolean;
|
|
5461
5319
|
};
|
|
5320
|
+
/** @deprecated Use {@link GetOperatorInfoOptions}. */
|
|
5321
|
+
type GetArkadeInfoOptions = GetOperatorInfoOptions;
|
|
5462
5322
|
/**
|
|
5463
5323
|
* Chain reads beyond the wallet's own VTXOs: an arbitrary script's virtual outputs and the
|
|
5464
5324
|
* transactions that spent them.
|
|
@@ -5492,9 +5352,9 @@ type ArkadeBroadcaster = Pick<OperatorProvider, "submitTx" | "finalizeTx">;
|
|
|
5492
5352
|
*/
|
|
5493
5353
|
interface IWallet extends IReadonlyWallet {
|
|
5494
5354
|
/**
|
|
5495
|
-
* Broadcast access to this wallet's
|
|
5355
|
+
* Broadcast access to this wallet's operator, so a plugin needs no operator URL of its own.
|
|
5496
5356
|
*
|
|
5497
|
-
* @returns A submit/finalize pair bound to this wallet's
|
|
5357
|
+
* @returns A submit/finalize pair bound to this wallet's operator
|
|
5498
5358
|
* @see ArkadeBroadcaster
|
|
5499
5359
|
*/
|
|
5500
5360
|
getArkadeBroadcaster(): Promise<ArkadeBroadcaster>;
|
|
@@ -5514,7 +5374,9 @@ interface IWallet extends IReadonlyWallet {
|
|
|
5514
5374
|
* @returns Arkade transaction id
|
|
5515
5375
|
* @see SettleParams
|
|
5516
5376
|
*/
|
|
5517
|
-
settle(params?: SettleParams, eventCallback?: (event: SettlementEvent) => void
|
|
5377
|
+
settle(params?: SettleParams, eventCallback?: (event: SettlementEvent) => void, hooks?: {
|
|
5378
|
+
onPhase?: (phase: "preparing" | "registration_attempt") => void;
|
|
5379
|
+
}): Promise<string>;
|
|
5518
5380
|
/**
|
|
5519
5381
|
* Send bitcoin and/or assets to one or more Arkade recipients, as variadic `Recipient`s or a
|
|
5520
5382
|
* `SendParams` object (which can also name the inputs).
|
|
@@ -5533,6 +5395,24 @@ interface IWallet extends IReadonlyWallet {
|
|
|
5533
5395
|
* ```
|
|
5534
5396
|
*/
|
|
5535
5397
|
send(...args: [SendParams] | [Recipient, ...Recipient[]]): Promise<string>;
|
|
5398
|
+
/**
|
|
5399
|
+
* Fill, sign and cosign the wallet-owned onchain inputs of a PSBT through
|
|
5400
|
+
* the collaborative leaf, then broadcast it. Foreign inputs are left as given:
|
|
5401
|
+
* sign them but do not finalize them, since arkd refuses a finalized input and
|
|
5402
|
+
* finalizes the transaction itself.
|
|
5403
|
+
*
|
|
5404
|
+
* @param psbt - Base64 PSBT or transaction
|
|
5405
|
+
* @returns Onchain transaction id
|
|
5406
|
+
*/
|
|
5407
|
+
cosignOnchainTx(psbt: string | Transaction$1): Promise<string>;
|
|
5408
|
+
/**
|
|
5409
|
+
* Spend onchain contract coins (boarding, unrolled) immediately via
|
|
5410
|
+
* {@link cosignOnchainTx}, selecting inputs and adding change.
|
|
5411
|
+
*
|
|
5412
|
+
* @returns Onchain transaction id
|
|
5413
|
+
* @see SendOnchainParams
|
|
5414
|
+
*/
|
|
5415
|
+
sendOnchain(params: SendOnchainParams): Promise<string>;
|
|
5536
5416
|
/** Asset manager bound to this wallet instance. */
|
|
5537
5417
|
assetManager: IAssetManager;
|
|
5538
5418
|
/** @returns Delegation manager, when configured. */
|
|
@@ -5551,18 +5431,20 @@ interface IReadonlyWallet {
|
|
|
5551
5431
|
/** @returns Onchain boarding address used to move funds into Arkade. */
|
|
5552
5432
|
getBoardingAddress(): Promise<string>;
|
|
5553
5433
|
/**
|
|
5554
|
-
* Info (network, signer key, delays, dust, fees, limits) for this wallet's
|
|
5434
|
+
* Info (network, signer key, delays, dust, fees, limits) for this wallet's operator.
|
|
5555
5435
|
* Live when reachable, else the snapshot persisted at construction.
|
|
5556
5436
|
*
|
|
5557
5437
|
* With `requireLive` it throws instead of using the cache — for callers binding
|
|
5558
5438
|
* `signerPubkey` or a delay into a covenant, where a stale snapshot could derive an address
|
|
5559
5439
|
* the operator no longer co-signs for.
|
|
5560
5440
|
*
|
|
5561
|
-
* @see
|
|
5441
|
+
* @see OperatorInfo
|
|
5562
5442
|
*/
|
|
5563
|
-
|
|
5443
|
+
getOperatorInfo(opts?: GetOperatorInfoOptions): Promise<OperatorInfo>;
|
|
5444
|
+
/** @deprecated Use {@link getOperatorInfo}. */
|
|
5445
|
+
getArkadeInfo(opts?: GetOperatorInfoOptions): Promise<OperatorInfo>;
|
|
5564
5446
|
/**
|
|
5565
|
-
*
|
|
5447
|
+
* Operator-side chain reads for scripts the wallet does not own (e.g. a plugin's covenant);
|
|
5566
5448
|
* {@link getVtxos} reads the wallet's own outputs from repositories.
|
|
5567
5449
|
*
|
|
5568
5450
|
* @see ArkadeReader
|
|
@@ -5772,4 +5654,4 @@ declare function isBatchSignable(identity: Identity): identity is BatchSignableI
|
|
|
5772
5654
|
*/
|
|
5773
5655
|
declare function isSigningIdentity(value: unknown): value is Identity;
|
|
5774
5656
|
|
|
5775
|
-
export { type
|
|
5657
|
+
export { type VirtualTxRepository as $, type ArkadeReader as A, type Outpoint as B, type ContractRepository as C, type PageResult as D, type ExtendedCoin as E, type ScriptVtxoCursor as F, type GetOperatorInfoOptions as G, type ScriptVtxoPageOptions as H, type IWallet as I, type StoredVtxo as J, type VtxoRepositoryKey as K, type TransactionHistoryPageFilter as L, type TransactionHistoryPageCursor as M, type NormalizedExtendedVirtualCoin as N, type OperatorInfo as O, type PageRequest as P, type AtomicWalletState as Q, type Recipient as R, type SettleParams as S, type TxNotificationEvent as T, type WalletState as U, type VirtualCoin as V, type WalletRepository as W, type ContractFilter as X, type BatchRegistrationRepository as Y, type BatchRegistration as Z, type BatchRegistrationPageFilter as _, type Identity as a, type ContractEvent as a$, type VirtualTx as a0, type VtxoBranch as a1, ChainedTxType as a2, type Network as a3, type BatchStartedEvent as a4, type TreeSigningStartedEvent as a5, TxTree as a6, type TreeNoncesEvent as a7, type BatchFinalizationEvent as a8, type BatchFinalizedEvent as a9, Intent as aA, type SignedProof as aB, Proof as aC, type TimeHeight as aD, type DescriptorSigningRequest as aE, type IntentFeeConfig as aF, type OffchainInput as aG, FeeAmount as aH, type OnchainInput as aI, type FeeOutput as aJ, type ContractWatcherConfig as aK, type Asset as aL, type FeeInfo as aM, type GetVtxosOptions as aN, type PaginationOptions as aO, type CreateContractParams as aP, type GetContractsFilter as aQ, type GetSpendablePathsOptions as aR, type GetAllSpendingPathsOptions as aS, type InputExpiryFloor as aT, type IssuanceParams as aU, type ReissuanceParams as aV, type BurnParams as aW, type RenewVtxosOptions as aX, type NormalizedVtxoPage as aY, type WatchedScript as aZ, type PathSelection as a_, type BatchFailedEvent as aa, type TreeTxEvent as ab, type TreeSignatureEvent as ac, type DescriptorProvider as ad, type IReadonlyWallet as ae, type ReadonlyIdentity as af, type OnchainProvider as ag, type DelegateProvider as ah, type ReadonlyWalletConfig as ai, type ExitCaptureMode as aj, type ExitDataSource as ak, type IReadonlyAssetManager as al, type ContractSyncState as am, type RecipientArkadeAddressContext as an, EsploraProvider as ao, type NetworkName as ap, type ContractWithVtxos as aq, selectPendingRecoveryOutpoints as ar, type Coin as as, ContractManager as at, type ContractManagerConfig as au, type SettlementConfig as av, VtxoManager as aw, type SignerSession as ax, Transaction as ay, type SignedIntent as az, type WalletConfig as b, type ExitChainResolver as b$, type AssetDetails as b0, type IssuanceResult as b1, type DelegateInfo as b2, type MigrationGlobalSkipReason as b3, type MigrationLegSkipReason as b4, type SignerStatus as b5, type StorageConfig as b6, type IVtxoManager as b7, type SendBitcoinParams as b8, type ExplorerTransaction as b9, ChainTxType as bA, type CommitmentTx as bB, type ConnectorTreeNode as bC, type ContractBalance as bD, type ContractEventCallback as bE, type ContractHandler as bF, type ContractScope as bG, type ContractState as bH, type ContractVtxo as bI, ContractWatcher as bJ, type ContractWatcherEventCallback as bK, DEFAULT_ARKADE_EMULATOR_URL as bL, DEFAULT_VTXO_PAGE_SIZE as bM, DelegateManagerImpl as bN, type DelegateOptions as bO, type DeprecatedSignerMigrationReport as bP, type DeprecatedSignerReport as bQ, DigestMismatchError as bR, type Discoverable as bS, type DiscoveredContract as bT, type DiscoveryDeps as bU, ESPLORA_URL as bV, type EmulatorInfo as bW, type EventSourceCapable as bX, type EventSourceFactory as bY, type EventSourceLike as bZ, EventSourceUnavailableError as b_, type TreeNonces as ba, type TreePartialSigs as bb, type PendingTx as bc, type EmulatorProvider as bd, type Status as be, type ChainTx as bf, type ArkadeService as bg, type ContractVtxoEvent as bh, type ExtendedContractVtxo as bi, type ResolvedArkadeService as bj, resolveArkadeService as bk, type PathContext as bl, type ActivityIntent as bm, type ActivityResolver as bn, type ArkIntent as bo, type ArkIntentState as bp, type ArkadeInfo as bq, type AssetMetadata as br, BATCH_REGISTRATION_TERMINAL_STATES as bs, BITCOIN_EMULATOR_PUBKEY as bt, type BaseWalletConfig as bu, type BatchInfo as bv, type BatchRegistrationFilter as bw, type BatchRegistrationState as bx, type BatchSignableIdentity as by, type CandidateDeps as bz, type ArkadeBroadcaster as c, assertRecipientArkadeAddress as c$, type GetArkadeInfoOptions as c0, type GetUtxosOptions as c1, type GroupMembership as c2, type HandlerError as c3, INTENT_TERMINAL_STATES as c4, IndexerTxType as c5, type IndexerUtxo as c6, IndexerUtxosUnsupportedError as c7, type IntentCoin as c8, type IntentFilter as c9, RestEmulatorProvider as cA, type ScanContractsOptions as cB, type ScanResult as cC, type ScheduledSession as cD, SettlementEventType as cE, type SignRequest as cF, type SignerClassification as cG, type SignerSet as cH, type SubscriptionFilter as cI, type SubscriptionResponse as cJ, type SweepTxNotification as cK, type TapLeaves as cL, TreeSignerSession as cM, type Tx as cN, type TxHistoryRecord as cO, type TxKey as cP, type TxNotification as cQ, type TxTag as cR, type TxTreeNode as cS, TxType as cT, type Vtxo as cU, type VtxoChain as cV, type VtxoType as cW, type WalletMode as cX, type WithPrevTx as cY, assertAllowedSighashTypes as cZ, assertPageRequest as c_, type IntentPageFilter as ca, type IntentRepository as cb, type KnownMetadata as cc, MAX_PAGE_SIZE as cd, MUTINYNET_EMULATOR_PUBKEY as ce, type MigrateDeprecatedSignerOptions as cf, type MigrationLegReport as cg, type MigrationVtxoRef as ch, type NewAddressType as ci, type Nonces as cj, OnchainCosignAmbiguousError as ck, OnchainCosignRejectedError as cl, OnchainCosignUnsupportedError as cm, type Output as cn, type PageResponse as co, PartialSig as cp, type PrevTxSource as cq, PrevTxUnavailableError as cr, type ProofInput as cs, type ProviderClass as ct, REGTEST_EMULATOR_PUBKEY as cu, type RawTxSource as cv, type RenewalSplit as cw, type RenewalSplitContext as cx, RestArkProvider as cy, RestDelegateProvider as cz, type WalletBalance as d, assetMintResolver as d0, attachPrevArkTxs as d1, attachPrevoutTxs as d2, boardingResolver as d3, canRecoverOnchain as d4, canSpendOffchain as d5, canSweepOnchain as d6, classifyAgainstSignerSet as d7, classifyContractSigner as d8, collabExitResolver as d9, isSubdust as dA, isTerminalBatchRegistrationState as dB, isTerminalIntentState as dC, isVirtualCoin as dD, isVtxoExpiringSoon as dE, isVtxoSpent as dF, iteratePages as dG, networkFromArkadeInfo as dH, networkFromOperatorInfo as dI, networks as dJ, pageResult as dK, resolveEmulatorPubkey as dL, resolveEventSource as dM, resolvePrevTxs as dN, signerSetFromInfo as dO, toOffchainInputFeeParams as dP, toXOnlySignerHex as dQ, withPrevTxs as dR, type TapscriptDeriving as dS, collectBatchRegistrations as da, collectContracts as db, collectIntents as dc, collectPages as dd, collectScriptVtxos as de, collectTransactionHistory as df, collectUtxos as dg, collectVtxos as dh, configureEventSource as di, createDefaultActivityRegistry as dj, createExitChainResolver as dk, defaultEmulatorPubkey as dl, getAllNormalizedVtxos as dm, getConfiguredEventSource as dn, getNetwork as dp, getNormalizedVtxos as dq, getRandomId as dr, hasCandidates as ds, isBatchSignable as dt, isContractVtxoEvent as du, isCooperativelyMigratable as dv, isDiscoverable as dw, isEventSourceUnavailableError as dx, isPastExpiry as dy, isSigningIdentity as dz, type GetVtxosFilter as e, type GetSpendableVtxosFilter as f, type ArkTransaction as g, ActivityRegistry as h, type Activity as i, type IContractManager as j, type GetNewAddressesOptions as k, type NewAddress as l, type IDelegateManager as m, type SettlementEvent as n, type SendParams as o, type SendOnchainParams as p, type IAssetManager as q, RestOperatorProvider as r, RestIndexerProvider as s, type SubscriptionEvent as t, type SubscriptionHeartbeat as u, type ArkProvider as v, type IndexerProvider as w, type OperatorProvider as x, type Contract as y, type ExtendedVirtualCoin as z };
|