@arkade-os/sdk 0.4.8 → 0.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/contracts/contractManager.js +59 -11
- package/dist/cjs/contracts/contractWatcher.js +21 -2
- package/dist/cjs/index.js +4 -3
- package/dist/cjs/providers/expoIndexer.js +1 -0
- package/dist/cjs/providers/indexer.js +1 -0
- package/dist/cjs/utils/arkTransaction.js +17 -6
- package/dist/cjs/utils/transactionHistory.js +2 -1
- package/dist/cjs/wallet/serviceWorker/wallet-message-handler.js +109 -29
- package/dist/cjs/wallet/serviceWorker/wallet.js +25 -2
- package/dist/cjs/wallet/vtxo-manager.js +81 -50
- package/dist/cjs/wallet/wallet.js +46 -34
- package/dist/cjs/worker/errors.js +3 -4
- package/dist/cjs/worker/messageBus.js +7 -0
- package/dist/esm/contracts/contractManager.js +59 -11
- package/dist/esm/contracts/contractWatcher.js +21 -2
- package/dist/esm/index.js +2 -2
- package/dist/esm/providers/expoIndexer.js +1 -0
- package/dist/esm/providers/indexer.js +1 -0
- package/dist/esm/utils/arkTransaction.js +17 -6
- package/dist/esm/utils/transactionHistory.js +2 -1
- package/dist/esm/wallet/serviceWorker/wallet-message-handler.js +109 -29
- package/dist/esm/wallet/serviceWorker/wallet.js +26 -3
- package/dist/esm/wallet/vtxo-manager.js +81 -50
- package/dist/esm/wallet/wallet.js +46 -34
- package/dist/esm/worker/errors.js +2 -3
- package/dist/esm/worker/messageBus.js +7 -0
- package/dist/types/contracts/contractManager.d.ts +10 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/repositories/serialization.d.ts +1 -0
- package/dist/types/utils/transactionHistory.d.ts +1 -1
- package/dist/types/wallet/index.d.ts +2 -0
- package/dist/types/wallet/serviceWorker/wallet-message-handler.d.ts +23 -6
- package/dist/types/wallet/serviceWorker/wallet.d.ts +9 -1
- package/dist/types/wallet/vtxo-manager.d.ts +5 -0
- package/dist/types/worker/errors.d.ts +1 -0
- package/dist/types/worker/messageBus.d.ts +6 -0
- package/package.json +1 -1
package/dist/types/index.d.ts
CHANGED
|
@@ -48,6 +48,6 @@ import type { Contract, ContractVtxo, ContractState, ContractEvent, ContractEven
|
|
|
48
48
|
import { IContractManager } from "./contracts/contractManager";
|
|
49
49
|
import { closeDatabase, openDatabase } from "./repositories/indexedDB/manager";
|
|
50
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, };
|
|
51
|
+
import { MESSAGE_BUS_NOT_INITIALIZED, 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, MESSAGE_BUS_NOT_INITIALIZED, 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
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, };
|
|
@@ -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",
|
|
@@ -228,6 +228,12 @@ export type ResponseIsContractManagerWatching = ResponseEnvelope & {
|
|
|
228
228
|
isWatching: boolean;
|
|
229
229
|
};
|
|
230
230
|
};
|
|
231
|
+
export type RequestRefreshVtxos = RequestEnvelope & {
|
|
232
|
+
type: "REFRESH_VTXOS";
|
|
233
|
+
};
|
|
234
|
+
export type ResponseRefreshVtxos = ResponseEnvelope & {
|
|
235
|
+
type: "REFRESH_VTXOS_SUCCESS";
|
|
236
|
+
};
|
|
231
237
|
export type RequestGetAllSpendingPaths = RequestEnvelope & {
|
|
232
238
|
type: "GET_ALL_SPENDING_PATHS";
|
|
233
239
|
payload: {
|
|
@@ -432,8 +438,8 @@ export type ResponseSweepExpiredBoardingUtxos = ResponseEnvelope & {
|
|
|
432
438
|
txid: string;
|
|
433
439
|
};
|
|
434
440
|
};
|
|
435
|
-
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 | RequestRecoverVtxos | RequestGetRecoverableBalance | RequestGetExpiringVtxos | RequestRenewVtxos | RequestGetExpiredBoardingUtxos | RequestSweepExpiredBoardingUtxos;
|
|
436
|
-
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 | ResponseRecoverVtxos | ResponseRecoverVtxosEvent | ResponseGetRecoverableBalance | ResponseGetExpiringVtxos | ResponseRenewVtxos | ResponseRenewVtxosEvent | ResponseGetExpiredBoardingUtxos | ResponseSweepExpiredBoardingUtxos);
|
|
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);
|
|
437
443
|
export declare class WalletMessageHandler implements MessageHandler<WalletUpdaterRequest, WalletUpdaterResponse> {
|
|
438
444
|
readonly messageTag: string;
|
|
439
445
|
private wallet;
|
|
@@ -463,19 +469,30 @@ export declare class WalletMessageHandler implements MessageHandler<WalletUpdate
|
|
|
463
469
|
private handleGetBalance;
|
|
464
470
|
private getAllBoardingUtxos;
|
|
465
471
|
/**
|
|
466
|
-
* Get spendable vtxos
|
|
472
|
+
* Get spendable vtxos from the repository
|
|
467
473
|
*/
|
|
468
474
|
private getSpendableVtxos;
|
|
475
|
+
private onWalletInitialized;
|
|
469
476
|
/**
|
|
470
|
-
*
|
|
477
|
+
* Force a full VTXO refresh from the indexer, then re-run bootstrap.
|
|
478
|
+
* Used by RELOAD_WALLET to ensure fresh data.
|
|
471
479
|
*/
|
|
472
|
-
private
|
|
473
|
-
private onWalletInitialized;
|
|
480
|
+
private reloadWallet;
|
|
474
481
|
private handleSettle;
|
|
475
482
|
private handleSendBitcoin;
|
|
476
483
|
private handleSignTransaction;
|
|
477
484
|
private handleDelegate;
|
|
478
485
|
private handleGetVtxos;
|
|
479
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;
|
|
480
497
|
private ensureContractEventBroadcasting;
|
|
481
498
|
}
|
|
@@ -6,7 +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 } from "../vtxo-manager";
|
|
9
|
+
import type { IVtxoManager, SettlementConfig } from "../vtxo-manager";
|
|
10
|
+
import type { ContractWatcherConfig } from "../../contracts/contractWatcher";
|
|
10
11
|
type PrivateKeyIdentity = Identity & {
|
|
11
12
|
toHex(): string;
|
|
12
13
|
};
|
|
@@ -45,12 +46,15 @@ type PrivateKeyIdentity = Identity & {
|
|
|
45
46
|
interface ServiceWorkerWalletOptions {
|
|
46
47
|
arkServerPublicKey?: string;
|
|
47
48
|
arkServerUrl: string;
|
|
49
|
+
indexerUrl?: string;
|
|
48
50
|
esploraUrl?: string;
|
|
49
51
|
storage?: StorageConfig;
|
|
50
52
|
identity: ReadonlyIdentity | Identity;
|
|
51
53
|
delegatorUrl?: string;
|
|
52
54
|
walletUpdaterTag?: string;
|
|
53
55
|
messageBusTimeoutMs?: number;
|
|
56
|
+
settlementConfig?: SettlementConfig | false;
|
|
57
|
+
watcherConfig?: Partial<Omit<ContractWatcherConfig, "indexerProvider">>;
|
|
54
58
|
}
|
|
55
59
|
export type ServiceWorkerWalletCreateOptions = ServiceWorkerWalletOptions & {
|
|
56
60
|
serviceWorker: ServiceWorker;
|
|
@@ -70,7 +74,11 @@ type MessageBusInitConfig = {
|
|
|
70
74
|
publicKey?: string;
|
|
71
75
|
};
|
|
72
76
|
delegatorUrl?: string;
|
|
77
|
+
indexerUrl?: string;
|
|
78
|
+
esploraUrl?: string;
|
|
73
79
|
timeoutMs?: number;
|
|
80
|
+
settlementConfig?: SettlementConfig | false;
|
|
81
|
+
watcherConfig?: Partial<Omit<ContractWatcherConfig, "indexerProvider">>;
|
|
74
82
|
};
|
|
75
83
|
export declare class ServiceWorkerReadonlyWallet implements IReadonlyWallet {
|
|
76
84
|
readonly serviceWorker: ServiceWorker;
|
|
@@ -171,8 +171,13 @@ export declare class VtxoManager implements AsyncDisposable, IVtxoManager {
|
|
|
171
171
|
private knownBoardingUtxos;
|
|
172
172
|
private sweptBoardingUtxos;
|
|
173
173
|
private pollInProgress;
|
|
174
|
+
private disposed;
|
|
174
175
|
private consecutivePollFailures;
|
|
176
|
+
private startupPollTimeoutId?;
|
|
175
177
|
private static readonly MAX_BACKOFF_MS;
|
|
178
|
+
private renewalInProgress;
|
|
179
|
+
private lastRenewalTimestamp;
|
|
180
|
+
private static readonly RENEWAL_COOLDOWN_MS;
|
|
176
181
|
constructor(wallet: IWallet,
|
|
177
182
|
/** @deprecated Use settlementConfig instead */
|
|
178
183
|
renewalConfig?: RenewalConfig | undefined, settlementConfig?: SettlementConfig | false);
|
|
@@ -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 {
|