@arkade-os/sdk 0.4.7 → 0.4.9

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.
Files changed (39) hide show
  1. package/dist/cjs/contracts/contractManager.js +59 -11
  2. package/dist/cjs/contracts/contractWatcher.js +21 -2
  3. package/dist/cjs/identity/seedIdentity.js +2 -2
  4. package/dist/cjs/index.js +9 -2
  5. package/dist/cjs/providers/expoIndexer.js +1 -0
  6. package/dist/cjs/providers/indexer.js +1 -0
  7. package/dist/cjs/utils/transactionHistory.js +2 -1
  8. package/dist/cjs/wallet/serviceWorker/wallet-message-handler.js +249 -36
  9. package/dist/cjs/wallet/serviceWorker/wallet.js +286 -34
  10. package/dist/cjs/wallet/vtxo-manager.js +123 -86
  11. package/dist/cjs/wallet/wallet.js +140 -68
  12. package/dist/cjs/worker/errors.js +17 -0
  13. package/dist/cjs/worker/messageBus.js +14 -2
  14. package/dist/esm/contracts/contractManager.js +59 -11
  15. package/dist/esm/contracts/contractWatcher.js +21 -2
  16. package/dist/esm/identity/seedIdentity.js +2 -2
  17. package/dist/esm/index.js +3 -2
  18. package/dist/esm/providers/expoIndexer.js +1 -0
  19. package/dist/esm/providers/indexer.js +1 -0
  20. package/dist/esm/utils/transactionHistory.js +2 -1
  21. package/dist/esm/wallet/serviceWorker/wallet-message-handler.js +245 -35
  22. package/dist/esm/wallet/serviceWorker/wallet.js +286 -34
  23. package/dist/esm/wallet/vtxo-manager.js +123 -86
  24. package/dist/esm/wallet/wallet.js +140 -68
  25. package/dist/esm/worker/errors.js +12 -0
  26. package/dist/esm/worker/messageBus.js +14 -2
  27. package/dist/types/contracts/contractManager.d.ts +10 -0
  28. package/dist/types/identity/seedIdentity.d.ts +5 -2
  29. package/dist/types/index.d.ts +5 -4
  30. package/dist/types/repositories/serialization.d.ts +1 -0
  31. package/dist/types/utils/transactionHistory.d.ts +1 -1
  32. package/dist/types/wallet/index.d.ts +2 -0
  33. package/dist/types/wallet/serviceWorker/wallet-message-handler.d.ts +101 -7
  34. package/dist/types/wallet/serviceWorker/wallet.d.ts +16 -0
  35. package/dist/types/wallet/vtxo-manager.d.ts +29 -2
  36. package/dist/types/wallet/wallet.d.ts +10 -0
  37. package/dist/types/worker/errors.d.ts +6 -0
  38. package/dist/types/worker/messageBus.d.ts +6 -0
  39. package/package.json +1 -1
@@ -102,6 +102,11 @@ export interface IContractManager extends Disposable {
102
102
  * @returns Unsubscribe function
103
103
  */
104
104
  onContractEvent(callback: ContractEventCallback): () => void;
105
+ /**
106
+ * Force a full VTXO refresh from the indexer for all contracts.
107
+ * Populates the wallet repository with complete VTXO history.
108
+ */
109
+ refreshVtxos(): Promise<void>;
105
110
  /**
106
111
  * Whether the underlying watcher is currently active.
107
112
  */
@@ -292,6 +297,11 @@ export declare class ContractManager implements IContractManager {
292
297
  * ```
293
298
  */
294
299
  onContractEvent(callback: ContractEventCallback): () => void;
300
+ /**
301
+ * Force a full VTXO refresh from the indexer for all contracts.
302
+ * Populates the wallet repository with complete VTXO history.
303
+ */
304
+ refreshVtxos(): Promise<void>;
295
305
  /**
296
306
  * Check if currently watching.
297
307
  */
@@ -3,8 +3,11 @@ import { Transaction } from "../utils/transaction";
3
3
  import { SignerSession } from "../tree/signingSession";
4
4
  /** Use default BIP86 derivation with network selection. */
5
5
  export interface NetworkOptions {
6
- /** Mainnet (coin type 0) or testnet (coin type 1). */
7
- isMainnet: boolean;
6
+ /**
7
+ * Mainnet (coin type 0) or testnet (coin type 1).
8
+ * @default true
9
+ */
10
+ isMainnet?: boolean;
8
11
  }
9
12
  /** Use a custom output descriptor for derivation. */
10
13
  export interface DescriptorOptions {
@@ -16,7 +16,7 @@ import { TxTree, TxTreeNode } from "./tree/txTree";
16
16
  import { SignerSession, TreeNonces, TreePartialSigs } from "./tree/signingSession";
17
17
  import { Ramps } from "./wallet/ramps";
18
18
  import { isVtxoExpiringSoon, VtxoManager } from "./wallet/vtxo-manager";
19
- import type { SettlementConfig } from "./wallet/vtxo-manager";
19
+ import type { IVtxoManager, SettlementConfig } from "./wallet/vtxo-manager";
20
20
  import { ServiceWorkerWallet, ServiceWorkerReadonlyWallet } from "./wallet/serviceWorker/wallet";
21
21
  import { OnchainWallet } from "./wallet/onchain";
22
22
  import { setupServiceWorker } from "./worker/browser/utils";
@@ -47,6 +47,7 @@ import { ContractManager, ContractWatcher, contractHandlers, DefaultContractHand
47
47
  import type { Contract, ContractVtxo, ContractState, ContractEvent, ContractEventCallback, ContractBalance, ContractWithVtxos, ContractHandler, PathSelection, PathContext, ContractManagerConfig, CreateContractParams, ContractWatcherConfig, ParsedArkContract, DefaultContractParams, DelegateContractParams, VHTLCContractParams } from "./contracts";
48
48
  import { IContractManager } from "./contracts/contractManager";
49
49
  import { closeDatabase, openDatabase } from "./repositories/indexedDB/manager";
50
- import { WalletMessageHandler } from "./wallet/serviceWorker/wallet-message-handler";
51
- export { Wallet, ReadonlyWallet, SingleKey, ReadonlySingleKey, SeedIdentity, MnemonicIdentity, ReadonlyDescriptorIdentity, OnchainWallet, Ramps, VtxoManager, DelegatorManagerImpl, RestDelegatorProvider, ESPLORA_URL, EsploraProvider, RestArkProvider, RestIndexerProvider, ArkAddress, DefaultVtxo, DelegateVtxo, VtxoScript, VHTLC, TxType, IndexerTxType, ChainTxType, SettlementEventType, setupServiceWorker, MessageBus, WalletMessageHandler, ServiceWorkerWallet, ServiceWorkerReadonlyWallet, decodeTapscript, MultisigTapscript, CSVMultisigTapscript, ConditionCSVMultisigTapscript, ConditionMultisigTapscript, CLTVMultisigTapscript, TapTreeCoder, ArkPsbtFieldKey, ArkPsbtFieldKeyType, setArkPsbtField, getArkPsbtFields, CosignerPublicKey, VtxoTreeExpiry, VtxoTaprootTree, ConditionWitness, buildOffchainTx, verifyTapscriptSignatures, waitForIncomingFunds, hasBoardingTxExpired, combineTapscriptSigs, isVtxoExpiringSoon, isValidArkAddress, ArkNote, networks, closeDatabase, openDatabase, IndexedDBWalletRepository, IndexedDBContractRepository, InMemoryWalletRepository, InMemoryContractRepository, MIGRATION_KEY, migrateWalletRepository, requiresMigration, getMigrationStatus, rollbackMigration, WalletRepositoryImpl, ContractRepositoryImpl, Intent, BIP322, TxTree, P2A, Unroll, Transaction, ArkError, maybeArkError, Batch, validateVtxoTxGraph, validateConnectorsTxGraph, buildForfeitTx, isRecoverable, isSpendable, isSubdust, isExpired, getSequence, ContractManager, ContractWatcher, contractHandlers, DefaultContractHandler, DelegateContractHandler, VHTLCContractHandler, encodeArkContract, decodeArkContract, contractFromArkContract, contractFromArkContractWithAddress, isArkContract, };
52
- export type { Identity, ReadonlyIdentity, IWallet, IReadonlyWallet, BaseWalletConfig, WalletConfig, ReadonlyWalletConfig, ProviderClass, ArkTransaction, Coin, ExtendedCoin, ExtendedVirtualCoin, WalletBalance, SendBitcoinParams, SettleParams, Status, VirtualStatus, Outpoint, VirtualCoin, TxKey, TapscriptType, ArkTxInput, OffchainTx, TapLeaves, IncomingFunds, SeedIdentityOptions, MnemonicOptions, NetworkOptions, DescriptorOptions, IndexerProvider, PageResponse, BatchInfo, ChainTx, CommitmentTx, TxHistoryRecord, Vtxo, VtxoChain, Tx, OnchainProvider, ArkProvider, SettlementEvent, FeeInfo, ArkInfo, SignedIntent, Output, TxNotification, ExplorerTransaction, BatchFinalizationEvent, BatchFinalizedEvent, BatchFailedEvent, TreeSigningStartedEvent, TreeNoncesEvent, BatchStartedEvent, TreeTxEvent, TreeSignatureEvent, ScheduledSession, PaginationOptions, SubscriptionResponse, SubscriptionHeartbeat, SubscriptionEvent, Network, NetworkName, ArkTapscript, RelativeTimelock, EncodedVtxoScript, TapLeafScript, SignerSession, TreeNonces, TreePartialSigs, GetVtxosFilter, SettlementConfig, Asset, Recipient, IssuanceParams, IssuanceResult, ReissuanceParams, BurnParams, AssetDetails, AssetMetadata, KnownMetadata, Nonces, PartialSig, ArkPsbtFieldCoder, TxTreeNode, AnchorBumper, StorageConfig, Contract, ContractVtxo, ContractState, ContractEvent, ContractEventCallback, ContractBalance, ContractWithVtxos, ContractHandler, IContractManager, PathSelection, PathContext, ContractManagerConfig, CreateContractParams, ContractWatcherConfig, ParsedArkContract, DefaultContractParams, DelegateContractParams, VHTLCContractParams, MessageHandler, RequestEnvelope, ResponseEnvelope, IDelegatorManager, DelegatorProvider, DelegateInfo, DelegateOptions, WalletRepository, ContractRepository, MigrationStatus, };
50
+ import { WalletMessageHandler, WalletNotInitializedError, ReadonlyWalletError, DelegatorNotConfiguredError } from "./wallet/serviceWorker/wallet-message-handler";
51
+ import { MessageBusNotInitializedError, ServiceWorkerTimeoutError } from "./worker/errors";
52
+ export { Wallet, ReadonlyWallet, SingleKey, ReadonlySingleKey, SeedIdentity, MnemonicIdentity, ReadonlyDescriptorIdentity, OnchainWallet, Ramps, VtxoManager, DelegatorManagerImpl, RestDelegatorProvider, ESPLORA_URL, EsploraProvider, RestArkProvider, RestIndexerProvider, ArkAddress, DefaultVtxo, DelegateVtxo, VtxoScript, VHTLC, TxType, IndexerTxType, ChainTxType, SettlementEventType, setupServiceWorker, MessageBus, WalletMessageHandler, WalletNotInitializedError, ReadonlyWalletError, DelegatorNotConfiguredError, MessageBusNotInitializedError, ServiceWorkerTimeoutError, ServiceWorkerWallet, ServiceWorkerReadonlyWallet, decodeTapscript, MultisigTapscript, CSVMultisigTapscript, ConditionCSVMultisigTapscript, ConditionMultisigTapscript, CLTVMultisigTapscript, TapTreeCoder, ArkPsbtFieldKey, ArkPsbtFieldKeyType, setArkPsbtField, getArkPsbtFields, CosignerPublicKey, VtxoTreeExpiry, VtxoTaprootTree, ConditionWitness, buildOffchainTx, verifyTapscriptSignatures, waitForIncomingFunds, hasBoardingTxExpired, combineTapscriptSigs, isVtxoExpiringSoon, isValidArkAddress, ArkNote, networks, closeDatabase, openDatabase, IndexedDBWalletRepository, IndexedDBContractRepository, InMemoryWalletRepository, InMemoryContractRepository, MIGRATION_KEY, migrateWalletRepository, requiresMigration, getMigrationStatus, rollbackMigration, WalletRepositoryImpl, ContractRepositoryImpl, Intent, BIP322, TxTree, P2A, Unroll, Transaction, ArkError, maybeArkError, Batch, validateVtxoTxGraph, validateConnectorsTxGraph, buildForfeitTx, isRecoverable, isSpendable, isSubdust, isExpired, getSequence, ContractManager, ContractWatcher, contractHandlers, DefaultContractHandler, DelegateContractHandler, VHTLCContractHandler, encodeArkContract, decodeArkContract, contractFromArkContract, contractFromArkContractWithAddress, isArkContract, };
53
+ export type { Identity, ReadonlyIdentity, IWallet, IReadonlyWallet, BaseWalletConfig, WalletConfig, ReadonlyWalletConfig, ProviderClass, ArkTransaction, Coin, ExtendedCoin, ExtendedVirtualCoin, WalletBalance, SendBitcoinParams, SettleParams, Status, VirtualStatus, Outpoint, VirtualCoin, TxKey, TapscriptType, ArkTxInput, OffchainTx, TapLeaves, IncomingFunds, SeedIdentityOptions, MnemonicOptions, NetworkOptions, DescriptorOptions, IndexerProvider, PageResponse, BatchInfo, ChainTx, CommitmentTx, TxHistoryRecord, Vtxo, VtxoChain, Tx, OnchainProvider, ArkProvider, SettlementEvent, FeeInfo, ArkInfo, SignedIntent, Output, TxNotification, ExplorerTransaction, BatchFinalizationEvent, BatchFinalizedEvent, BatchFailedEvent, TreeSigningStartedEvent, TreeNoncesEvent, BatchStartedEvent, TreeTxEvent, TreeSignatureEvent, ScheduledSession, PaginationOptions, SubscriptionResponse, SubscriptionHeartbeat, SubscriptionEvent, Network, NetworkName, ArkTapscript, RelativeTimelock, EncodedVtxoScript, TapLeafScript, SignerSession, TreeNonces, TreePartialSigs, GetVtxosFilter, SettlementConfig, IVtxoManager, Asset, Recipient, IssuanceParams, IssuanceResult, ReissuanceParams, BurnParams, AssetDetails, AssetMetadata, KnownMetadata, Nonces, PartialSig, ArkPsbtFieldCoder, TxTreeNode, AnchorBumper, StorageConfig, Contract, ContractVtxo, ContractState, ContractEvent, ContractEventCallback, ContractBalance, ContractWithVtxos, ContractHandler, IContractManager, PathSelection, PathContext, ContractManagerConfig, CreateContractParams, ContractWatcherConfig, ParsedArkContract, DefaultContractParams, DelegateContractParams, VHTLCContractParams, MessageHandler, RequestEnvelope, ResponseEnvelope, IDelegatorManager, DelegatorProvider, DelegateInfo, DelegateOptions, WalletRepository, ContractRepository, MigrationStatus, };
@@ -20,6 +20,7 @@ export declare const serializeVtxo: (v: ExtendedVirtualCoin) => {
20
20
  isUnrolled: boolean;
21
21
  isSpent?: boolean;
22
22
  assets?: import("../wallet").Asset[];
23
+ script?: string;
23
24
  value: number;
24
25
  status: import("../wallet").Status;
25
26
  txid: string;
@@ -11,5 +11,5 @@ type ExtendedArkTransaction = ArkTransaction & {
11
11
  * @param {Set<string>} commitmentsToIgnore - A set of commitment IDs that should be excluded from processing.
12
12
  * @return {ExtendedArkTransaction[]} A sorted array of extended Ark transactions, representing the transaction history.
13
13
  */
14
- export declare function buildTransactionHistory(vtxos: VirtualCoin[], allBoardingTxs: ArkTransaction[], commitmentsToIgnore: Set<string>, getTxCreatedAt?: (txid: string) => Promise<number>): Promise<ExtendedArkTransaction[]>;
14
+ export declare function buildTransactionHistory(vtxos: VirtualCoin[], allBoardingTxs: ArkTransaction[], commitmentsToIgnore: Set<string>, getTxCreatedAt?: (txid: string) => Promise<number | undefined>): Promise<ExtendedArkTransaction[]>;
15
15
  export {};
@@ -220,6 +220,8 @@ export interface VirtualCoin extends Coin {
220
220
  isUnrolled: boolean;
221
221
  isSpent?: boolean;
222
222
  assets?: Asset[];
223
+ /** The scriptPubKey (hex) locking this VTXO, as returned by the indexer. */
224
+ script?: string;
223
225
  }
224
226
  export declare enum TxType {
225
227
  TxSent = "SENT",
@@ -1,10 +1,19 @@
1
1
  import { SettlementEvent } from "../../providers/ark";
2
2
  import type { Contract, ContractEvent, ContractWithVtxos, GetContractsFilter, PathSelection } from "../../contracts";
3
3
  import type { CreateContractParams, GetAllSpendingPathsOptions, GetSpendablePathsOptions } from "../../contracts/contractManager";
4
- import { ArkTransaction, AssetDetails, BurnParams, ExtendedCoin, GetVtxosFilter, IssuanceParams, IssuanceResult, IWallet, Recipient, ReissuanceParams, SendBitcoinParams, SettleParams, WalletBalance } from "../index";
4
+ import { ArkTransaction, AssetDetails, BurnParams, ExtendedCoin, ExtendedVirtualCoin, GetVtxosFilter, IssuanceParams, IssuanceResult, IWallet, Recipient, ReissuanceParams, SendBitcoinParams, SettleParams, WalletBalance } from "../index";
5
5
  import { DelegateInfo } from "../../providers/delegator";
6
6
  import { MessageHandler, RequestEnvelope, ResponseEnvelope } from "../../worker/messageBus";
7
7
  import { Transaction } from "../../utils/transaction";
8
+ export declare class WalletNotInitializedError extends Error {
9
+ constructor();
10
+ }
11
+ export declare class ReadonlyWalletError extends Error {
12
+ constructor();
13
+ }
14
+ export declare class DelegatorNotConfiguredError extends Error {
15
+ constructor();
16
+ }
8
17
  export declare const DEFAULT_MESSAGE_TAG = "WALLET_UPDATER";
9
18
  export type RequestInitWallet = RequestEnvelope & {
10
19
  type: "INIT_WALLET";
@@ -219,6 +228,12 @@ export type ResponseIsContractManagerWatching = ResponseEnvelope & {
219
228
  isWatching: boolean;
220
229
  };
221
230
  };
231
+ export type RequestRefreshVtxos = RequestEnvelope & {
232
+ type: "REFRESH_VTXOS";
233
+ };
234
+ export type ResponseRefreshVtxos = ResponseEnvelope & {
235
+ type: "REFRESH_VTXOS_SUCCESS";
236
+ };
222
237
  export type RequestGetAllSpendingPaths = RequestEnvelope & {
223
238
  type: "GET_ALL_SPENDING_PATHS";
224
239
  payload: {
@@ -236,6 +251,14 @@ export type ResponseSettleEvent = ResponseEnvelope & {
236
251
  type: "SETTLE_EVENT";
237
252
  payload: SettlementEvent;
238
253
  };
254
+ export type ResponseRecoverVtxosEvent = ResponseEnvelope & {
255
+ type: "RECOVER_VTXOS_EVENT";
256
+ payload: SettlementEvent;
257
+ };
258
+ export type ResponseRenewVtxosEvent = ResponseEnvelope & {
259
+ type: "RENEW_VTXOS_EVENT";
260
+ payload: SettlementEvent;
261
+ };
239
262
  export type ResponseUtxoUpdate = ResponseEnvelope & {
240
263
  broadcast: true;
241
264
  type: "UTXO_UPDATE";
@@ -355,8 +378,68 @@ export type ResponseGetDelegateInfo = ResponseEnvelope & {
355
378
  info: DelegateInfo;
356
379
  };
357
380
  };
358
- export type WalletUpdaterRequest = RequestInitWallet | RequestSettle | RequestSendBitcoin | RequestGetAddress | RequestGetBoardingAddress | RequestGetBalance | RequestGetVtxos | RequestGetBoardingUtxos | RequestGetTransactionHistory | RequestGetStatus | RequestClear | RequestReloadWallet | RequestSignTransaction | RequestCreateContract | RequestGetContracts | RequestGetContractsWithVtxos | RequestUpdateContract | RequestDeleteContract | RequestGetSpendablePaths | RequestGetAllSpendingPaths | RequestIsContractManagerWatching | RequestSend | RequestGetAssetDetails | RequestIssue | RequestReissue | RequestBurn | RequestDelegate | RequestGetDelegateInfo;
359
- export type WalletUpdaterResponse = ResponseEnvelope & (ResponseInitWallet | ResponseSettle | ResponseSettleEvent | ResponseSendBitcoin | ResponseGetAddress | ResponseGetBoardingAddress | ResponseGetBalance | ResponseGetVtxos | ResponseGetBoardingUtxos | ResponseGetTransactionHistory | ResponseGetStatus | ResponseClear | ResponseReloadWallet | ResponseUtxoUpdate | ResponseVtxoUpdate | ResponseSignTransaction | ResponseCreateContract | ResponseGetContracts | ResponseGetContractsWithVtxos | ResponseUpdateContract | ResponseDeleteContract | ResponseGetSpendablePaths | ResponseGetAllSpendingPaths | ResponseIsContractManagerWatching | ResponseContractEvent | ResponseSend | ResponseGetAssetDetails | ResponseIssue | ResponseReissue | ResponseBurn | ResponseDelegate | ResponseGetDelegateInfo);
381
+ export type RequestRecoverVtxos = RequestEnvelope & {
382
+ type: "RECOVER_VTXOS";
383
+ };
384
+ export type ResponseRecoverVtxos = ResponseEnvelope & {
385
+ type: "RECOVER_VTXOS_SUCCESS";
386
+ payload: {
387
+ txid: string;
388
+ };
389
+ };
390
+ export type RequestGetRecoverableBalance = RequestEnvelope & {
391
+ type: "GET_RECOVERABLE_BALANCE";
392
+ };
393
+ export type ResponseGetRecoverableBalance = ResponseEnvelope & {
394
+ type: "RECOVERABLE_BALANCE";
395
+ payload: {
396
+ recoverable: string;
397
+ subdust: string;
398
+ includesSubdust: boolean;
399
+ vtxoCount: number;
400
+ };
401
+ };
402
+ export type RequestGetExpiringVtxos = RequestEnvelope & {
403
+ type: "GET_EXPIRING_VTXOS";
404
+ payload: {
405
+ thresholdMs?: number;
406
+ };
407
+ };
408
+ export type ResponseGetExpiringVtxos = ResponseEnvelope & {
409
+ type: "EXPIRING_VTXOS";
410
+ payload: {
411
+ vtxos: ExtendedVirtualCoin[];
412
+ };
413
+ };
414
+ export type RequestRenewVtxos = RequestEnvelope & {
415
+ type: "RENEW_VTXOS";
416
+ };
417
+ export type ResponseRenewVtxos = ResponseEnvelope & {
418
+ type: "RENEW_VTXOS_SUCCESS";
419
+ payload: {
420
+ txid: string;
421
+ };
422
+ };
423
+ export type RequestGetExpiredBoardingUtxos = RequestEnvelope & {
424
+ type: "GET_EXPIRED_BOARDING_UTXOS";
425
+ };
426
+ export type ResponseGetExpiredBoardingUtxos = ResponseEnvelope & {
427
+ type: "EXPIRED_BOARDING_UTXOS";
428
+ payload: {
429
+ utxos: ExtendedCoin[];
430
+ };
431
+ };
432
+ export type RequestSweepExpiredBoardingUtxos = RequestEnvelope & {
433
+ type: "SWEEP_EXPIRED_BOARDING_UTXOS";
434
+ };
435
+ export type ResponseSweepExpiredBoardingUtxos = ResponseEnvelope & {
436
+ type: "SWEEP_EXPIRED_BOARDING_UTXOS_SUCCESS";
437
+ payload: {
438
+ txid: string;
439
+ };
440
+ };
441
+ export type WalletUpdaterRequest = RequestInitWallet | RequestSettle | RequestSendBitcoin | RequestGetAddress | RequestGetBoardingAddress | RequestGetBalance | RequestGetVtxos | RequestGetBoardingUtxos | RequestGetTransactionHistory | RequestGetStatus | RequestClear | RequestReloadWallet | RequestSignTransaction | RequestCreateContract | RequestGetContracts | RequestGetContractsWithVtxos | RequestUpdateContract | RequestDeleteContract | RequestGetSpendablePaths | RequestGetAllSpendingPaths | RequestIsContractManagerWatching | RequestRefreshVtxos | RequestSend | RequestGetAssetDetails | RequestIssue | RequestReissue | RequestBurn | RequestDelegate | RequestGetDelegateInfo | RequestRecoverVtxos | RequestGetRecoverableBalance | RequestGetExpiringVtxos | RequestRenewVtxos | RequestGetExpiredBoardingUtxos | RequestSweepExpiredBoardingUtxos;
442
+ export type WalletUpdaterResponse = ResponseEnvelope & (ResponseInitWallet | ResponseSettle | ResponseSettleEvent | ResponseSendBitcoin | ResponseGetAddress | ResponseGetBoardingAddress | ResponseGetBalance | ResponseGetVtxos | ResponseGetBoardingUtxos | ResponseGetTransactionHistory | ResponseGetStatus | ResponseClear | ResponseReloadWallet | ResponseUtxoUpdate | ResponseVtxoUpdate | ResponseSignTransaction | ResponseCreateContract | ResponseGetContracts | ResponseGetContractsWithVtxos | ResponseUpdateContract | ResponseDeleteContract | ResponseGetSpendablePaths | ResponseGetAllSpendingPaths | ResponseIsContractManagerWatching | ResponseRefreshVtxos | ResponseContractEvent | ResponseSend | ResponseGetAssetDetails | ResponseIssue | ResponseReissue | ResponseBurn | ResponseDelegate | ResponseGetDelegateInfo | ResponseRecoverVtxos | ResponseRecoverVtxosEvent | ResponseGetRecoverableBalance | ResponseGetExpiringVtxos | ResponseRenewVtxos | ResponseRenewVtxosEvent | ResponseGetExpiredBoardingUtxos | ResponseSweepExpiredBoardingUtxos);
360
443
  export declare class WalletMessageHandler implements MessageHandler<WalletUpdaterRequest, WalletUpdaterResponse> {
361
444
  readonly messageTag: string;
362
445
  private wallet;
@@ -386,19 +469,30 @@ export declare class WalletMessageHandler implements MessageHandler<WalletUpdate
386
469
  private handleGetBalance;
387
470
  private getAllBoardingUtxos;
388
471
  /**
389
- * Get spendable vtxos for the current wallet address
472
+ * Get spendable vtxos from the repository
390
473
  */
391
474
  private getSpendableVtxos;
475
+ private onWalletInitialized;
392
476
  /**
393
- * Get swept vtxos for the current wallet address
477
+ * Force a full VTXO refresh from the indexer, then re-run bootstrap.
478
+ * Used by RELOAD_WALLET to ensure fresh data.
394
479
  */
395
- private getSweptVtxos;
396
- private onWalletInitialized;
480
+ private reloadWallet;
397
481
  private handleSettle;
398
482
  private handleSendBitcoin;
399
483
  private handleSignTransaction;
400
484
  private handleDelegate;
401
485
  private handleGetVtxos;
402
486
  private clear;
487
+ /**
488
+ * Read all VTXOs from the repository, aggregated across all contract
489
+ * addresses and the wallet's primary address, with deduplication.
490
+ */
491
+ private getVtxosFromRepo;
492
+ /**
493
+ * Build transaction history from cached VTXOs without hitting the indexer.
494
+ * Falls back to indexer only for uncached transaction timestamps.
495
+ */
496
+ private buildTransactionHistoryFromCache;
403
497
  private ensureContractEventBroadcasting;
404
498
  }
@@ -6,6 +6,8 @@ import { ContractRepository } from "../../repositories/contractRepository";
6
6
  import { RequestInitWallet, ResponseGetStatus, WalletUpdaterRequest, WalletUpdaterResponse } from "./wallet-message-handler";
7
7
  import type { IContractManager } from "../../contracts/contractManager";
8
8
  import type { IDelegatorManager } from "../delegator";
9
+ import type { IVtxoManager, SettlementConfig } from "../vtxo-manager";
10
+ import type { ContractWatcherConfig } from "../../contracts/contractWatcher";
9
11
  type PrivateKeyIdentity = Identity & {
10
12
  toHex(): string;
11
13
  };
@@ -44,12 +46,15 @@ type PrivateKeyIdentity = Identity & {
44
46
  interface ServiceWorkerWalletOptions {
45
47
  arkServerPublicKey?: string;
46
48
  arkServerUrl: string;
49
+ indexerUrl?: string;
47
50
  esploraUrl?: string;
48
51
  storage?: StorageConfig;
49
52
  identity: ReadonlyIdentity | Identity;
50
53
  delegatorUrl?: string;
51
54
  walletUpdaterTag?: string;
52
55
  messageBusTimeoutMs?: number;
56
+ settlementConfig?: SettlementConfig | false;
57
+ watcherConfig?: Partial<Omit<ContractWatcherConfig, "indexerProvider">>;
53
58
  }
54
59
  export type ServiceWorkerWalletCreateOptions = ServiceWorkerWalletOptions & {
55
60
  serviceWorker: ServiceWorker;
@@ -69,7 +74,11 @@ type MessageBusInitConfig = {
69
74
  publicKey?: string;
70
75
  };
71
76
  delegatorUrl?: string;
77
+ indexerUrl?: string;
78
+ esploraUrl?: string;
72
79
  timeoutMs?: number;
80
+ settlementConfig?: SettlementConfig | false;
81
+ watcherConfig?: Partial<Omit<ContractWatcherConfig, "indexerProvider">>;
73
82
  };
74
83
  export declare class ServiceWorkerReadonlyWallet implements IReadonlyWallet {
75
84
  readonly serviceWorker: ServiceWorker;
@@ -82,6 +91,8 @@ export declare class ServiceWorkerReadonlyWallet implements IReadonlyWallet {
82
91
  protected initWalletPayload: RequestInitWallet["payload"] | null;
83
92
  protected messageBusTimeoutMs?: number;
84
93
  private reinitPromise;
94
+ private pingPromise;
95
+ private inflightRequests;
85
96
  get assetManager(): IReadonlyAssetManager;
86
97
  protected constructor(serviceWorker: ServiceWorker, identity: ReadonlyIdentity, walletRepository: WalletRepository, contractRepository: ContractRepository, messageTag: string);
87
98
  static create(options: ServiceWorkerWalletCreateOptions): Promise<ServiceWorkerReadonlyWallet>;
@@ -108,7 +119,11 @@ export declare class ServiceWorkerReadonlyWallet implements IReadonlyWallet {
108
119
  */
109
120
  static setup(options: ServiceWorkerWalletSetupOptions): Promise<ServiceWorkerReadonlyWallet>;
110
121
  private sendMessageDirect;
122
+ private sendMessageStreaming;
111
123
  protected sendMessage(request: WalletUpdaterRequest): Promise<WalletUpdaterResponse>;
124
+ private pingServiceWorker;
125
+ private sendMessageWithRetry;
126
+ protected sendMessageWithEvents(request: WalletUpdaterRequest, onEvent: (response: WalletUpdaterResponse) => void, isComplete: (response: WalletUpdaterResponse) => boolean): Promise<WalletUpdaterResponse>;
112
127
  private reinitialize;
113
128
  clear(): Promise<void>;
114
129
  getAddress(): Promise<string>;
@@ -157,5 +172,6 @@ export declare class ServiceWorkerWallet extends ServiceWorkerReadonlyWallet imp
157
172
  settle(params?: SettleParams, callback?: (event: SettlementEvent) => void): Promise<string>;
158
173
  send(...recipients: Recipient[]): Promise<string>;
159
174
  getDelegatorManager(): Promise<IDelegatorManager | undefined>;
175
+ getVtxoManager(): Promise<IVtxoManager>;
160
176
  }
161
177
  export {};
@@ -145,7 +145,21 @@ export declare function getExpiringAndRecoverableVtxos(vtxos: ExtendedVirtualCoi
145
145
  * }
146
146
  * ```
147
147
  */
148
- export declare class VtxoManager implements AsyncDisposable {
148
+ export interface IVtxoManager {
149
+ recoverVtxos(eventCallback?: (event: SettlementEvent) => void): Promise<string>;
150
+ getRecoverableBalance(): Promise<{
151
+ recoverable: bigint;
152
+ subdust: bigint;
153
+ includesSubdust: boolean;
154
+ vtxoCount: number;
155
+ }>;
156
+ getExpiringVtxos(thresholdMs?: number): Promise<ExtendedVirtualCoin[]>;
157
+ renewVtxos(eventCallback?: (event: SettlementEvent) => void): Promise<string>;
158
+ getExpiredBoardingUtxos(): Promise<ExtendedCoin[]>;
159
+ sweepExpiredBoardingUtxos(): Promise<string>;
160
+ dispose(): Promise<void>;
161
+ }
162
+ export declare class VtxoManager implements AsyncDisposable, IVtxoManager {
149
163
  readonly wallet: IWallet;
150
164
  /** @deprecated Use settlementConfig instead */
151
165
  readonly renewalConfig?: RenewalConfig | undefined;
@@ -153,10 +167,17 @@ export declare class VtxoManager implements AsyncDisposable {
153
167
  private contractEventsSubscription?;
154
168
  private readonly contractEventsSubscriptionReady;
155
169
  private disposePromise?;
156
- private pollIntervalId?;
170
+ private pollTimeoutId?;
157
171
  private knownBoardingUtxos;
158
172
  private sweptBoardingUtxos;
159
173
  private pollInProgress;
174
+ private disposed;
175
+ private consecutivePollFailures;
176
+ private startupPollTimeoutId?;
177
+ private static readonly MAX_BACKOFF_MS;
178
+ private renewalInProgress;
179
+ private lastRenewalTimestamp;
180
+ private static readonly RENEWAL_COOLDOWN_MS;
160
181
  constructor(wallet: IWallet,
161
182
  /** @deprecated Use settlementConfig instead */
162
183
  renewalConfig?: RenewalConfig | undefined, settlementConfig?: SettlementConfig | false);
@@ -323,12 +344,18 @@ export declare class VtxoManager implements AsyncDisposable {
323
344
  /** Returns the wallet's identity for transaction signing. */
324
345
  private getIdentity;
325
346
  private initializeSubscription;
347
+ /** Computes the next poll delay, applying exponential backoff on failures. */
348
+ private getNextPollDelay;
326
349
  /**
327
350
  * Starts a polling loop that:
328
351
  * 1. Auto-settles new boarding UTXOs into Ark
329
352
  * 2. Sweeps expired boarding UTXOs (when boardingUtxoSweep is enabled)
353
+ *
354
+ * Uses setTimeout chaining (not setInterval) so a slow/blocked poll
355
+ * cannot stack up and the next delay can incorporate backoff.
330
356
  */
331
357
  private startBoardingUtxoPoll;
358
+ private schedulePoll;
332
359
  private pollBoardingUtxos;
333
360
  /**
334
361
  * Auto-settle new (unexpired) boarding UTXOs into the Ark.
@@ -171,6 +171,14 @@ export declare class Wallet extends ReadonlyWallet implements IWallet {
171
171
  private _vtxoManager?;
172
172
  private _vtxoManagerInitializing?;
173
173
  private _walletAssetManager?;
174
+ /**
175
+ * Async mutex that serializes all operations submitting VTXOs to the Ark
176
+ * server (`settle`, `send`, `sendBitcoin`). This prevents VtxoManager's
177
+ * background renewal from racing with user-initiated transactions for the
178
+ * same VTXO inputs.
179
+ */
180
+ private _txLock;
181
+ private _withTxLock;
174
182
  /** @deprecated Use settlementConfig instead */
175
183
  readonly renewalConfig: Required<Omit<WalletConfig["renewalConfig"], "enabled">> & {
176
184
  enabled: boolean;
@@ -209,6 +217,7 @@ export declare class Wallet extends ReadonlyWallet implements IWallet {
209
217
  */
210
218
  sendBitcoin(params: SendBitcoinParams): Promise<string>;
211
219
  settle(params?: SettleParams, eventCallback?: (event: SettlementEvent) => void): Promise<string>;
220
+ private _settleImpl;
212
221
  private handleSettlementFinalizationEvent;
213
222
  /**
214
223
  * @implements Batch.Handler interface.
@@ -247,6 +256,7 @@ export declare class Wallet extends ReadonlyWallet implements IWallet {
247
256
  * ```
248
257
  */
249
258
  send(...args: Recipient[]): Promise<string>;
259
+ private _sendImpl;
250
260
  /**
251
261
  * Build an offchain transaction from the given inputs and outputs,
252
262
  * sign it, submit to the ark provider, and finalize.
@@ -0,0 +1,6 @@
1
+ export declare class MessageBusNotInitializedError extends Error {
2
+ constructor();
3
+ }
4
+ export declare class ServiceWorkerTimeoutError extends Error {
5
+ constructor(detail: string);
6
+ }
@@ -1,5 +1,7 @@
1
1
  import { ArkProvider } from "../providers/ark";
2
2
  import { ReadonlyWallet, Wallet } from "../wallet/wallet";
3
+ import type { SettlementConfig } from "../wallet/vtxo-manager";
4
+ import type { ContractWatcherConfig } from "../contracts/contractWatcher";
3
5
  import { ContractRepository, WalletRepository } from "../repositories";
4
6
  export type RequestEnvelope = {
5
7
  tag: string;
@@ -70,6 +72,10 @@ type Initialize = {
70
72
  publicKey?: string;
71
73
  };
72
74
  delegatorUrl?: string;
75
+ indexerUrl?: string;
76
+ esploraUrl?: string;
77
+ settlementConfig?: SettlementConfig | false;
78
+ watcherConfig?: Partial<Omit<ContractWatcherConfig, "indexerProvider">>;
73
79
  };
74
80
  };
75
81
  export declare class MessageBus {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkade-os/sdk",
3
- "version": "0.4.7",
3
+ "version": "0.4.9",
4
4
  "description": "Bitcoin wallet SDK with Taproot and Ark integration",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",