@arkade-os/sdk 0.4.13 → 0.4.14

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 CHANGED
@@ -3,7 +3,7 @@
3
3
  The Arkade SDK is a TypeScript library for building Bitcoin wallets with support for both on-chain and off-chain transactions via the Ark protocol.
4
4
 
5
5
  [![TypeScript Documentation](https://img.shields.io/badge/TypeScript-Documentation-blue?style=flat-square)](https://arkade-os.github.io/ts-sdk/)
6
- [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/ark-ts-sdk)
6
+ [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/arkade-os/ts-sdk)
7
7
 
8
8
  ## Installation
9
9
 
package/dist/cjs/index.js CHANGED
@@ -36,9 +36,9 @@ var __importStar = (this && this.__importStar) || (function () {
36
36
  };
37
37
  })();
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.VtxoTreeExpiry = exports.CosignerPublicKey = exports.getArkPsbtFields = exports.setArkPsbtField = exports.ArkPsbtFieldKeyType = exports.ArkPsbtFieldKey = exports.TapTreeCoder = exports.CLTVMultisigTapscript = exports.ConditionMultisigTapscript = exports.ConditionCSVMultisigTapscript = exports.CSVMultisigTapscript = exports.MultisigTapscript = exports.decodeTapscript = exports.ServiceWorkerReadonlyWallet = exports.ServiceWorkerWallet = exports.ServiceWorkerTimeoutError = exports.MessageBusNotInitializedError = exports.MESSAGE_BUS_NOT_INITIALIZED = exports.DelegatorNotConfiguredError = exports.ReadonlyWalletError = exports.WalletNotInitializedError = exports.WalletMessageHandler = exports.MessageBus = exports.setupServiceWorker = exports.SettlementEventType = exports.ChainTxType = exports.IndexerTxType = exports.TxType = exports.VHTLC = exports.VtxoScript = exports.DelegateVtxo = exports.DefaultVtxo = exports.ArkAddress = exports.RestIndexerProvider = exports.RestArkProvider = exports.EsploraProvider = exports.ESPLORA_URL = exports.RestDelegatorProvider = exports.DelegatorManagerImpl = exports.VtxoManager = exports.Ramps = exports.OnchainWallet = exports.ReadonlyDescriptorIdentity = exports.MnemonicIdentity = exports.SeedIdentity = exports.ReadonlySingleKey = exports.SingleKey = exports.ReadonlyWallet = exports.Wallet = exports.asset = void 0;
40
- exports.contractFromArkContract = exports.decodeArkContract = exports.encodeArkContract = exports.VHTLCContractHandler = exports.DelegateContractHandler = exports.DefaultContractHandler = exports.contractHandlers = exports.ContractWatcher = exports.ContractManager = exports.getSequence = exports.isExpired = exports.isSubdust = exports.isSpendable = exports.isRecoverable = exports.buildForfeitTx = exports.validateConnectorsTxGraph = exports.validateVtxoTxGraph = exports.Batch = exports.maybeArkError = exports.ArkError = exports.Transaction = exports.Unroll = exports.P2A = exports.TxTree = exports.BIP322 = exports.Intent = exports.ContractRepositoryImpl = exports.WalletRepositoryImpl = exports.rollbackMigration = exports.getMigrationStatus = exports.requiresMigration = exports.migrateWalletRepository = exports.MIGRATION_KEY = exports.InMemoryContractRepository = exports.InMemoryWalletRepository = exports.IndexedDBContractRepository = exports.IndexedDBWalletRepository = exports.openDatabase = exports.closeDatabase = exports.networks = exports.ArkNote = exports.isValidArkAddress = exports.isVtxoExpiringSoon = exports.combineTapscriptSigs = exports.hasBoardingTxExpired = exports.waitForIncomingFunds = exports.verifyTapscriptSignatures = exports.buildOffchainTx = exports.ConditionWitness = exports.VtxoTaprootTree = void 0;
41
- exports.isArkContract = exports.contractFromArkContractWithAddress = void 0;
39
+ exports.CosignerPublicKey = exports.getArkPsbtFields = exports.setArkPsbtField = exports.ArkPsbtFieldKeyType = exports.ArkPsbtFieldKey = exports.TapTreeCoder = exports.CLTVMultisigTapscript = exports.ConditionMultisigTapscript = exports.ConditionCSVMultisigTapscript = exports.CSVMultisigTapscript = exports.MultisigTapscript = exports.decodeTapscript = exports.DEFAULT_MESSAGE_TIMEOUTS = exports.ServiceWorkerReadonlyWallet = exports.ServiceWorkerWallet = exports.ServiceWorkerTimeoutError = exports.MessageBusNotInitializedError = exports.MESSAGE_BUS_NOT_INITIALIZED = exports.DelegatorNotConfiguredError = exports.ReadonlyWalletError = exports.WalletNotInitializedError = exports.WalletMessageHandler = exports.MessageBus = exports.setupServiceWorker = exports.SettlementEventType = exports.ChainTxType = exports.IndexerTxType = exports.TxType = exports.VHTLC = exports.VtxoScript = exports.DelegateVtxo = exports.DefaultVtxo = exports.ArkAddress = exports.RestIndexerProvider = exports.RestArkProvider = exports.EsploraProvider = exports.ESPLORA_URL = exports.RestDelegatorProvider = exports.DelegatorManagerImpl = exports.VtxoManager = exports.Ramps = exports.OnchainWallet = exports.ReadonlyDescriptorIdentity = exports.MnemonicIdentity = exports.SeedIdentity = exports.ReadonlySingleKey = exports.SingleKey = exports.ReadonlyWallet = exports.Wallet = exports.asset = void 0;
40
+ exports.decodeArkContract = exports.encodeArkContract = exports.VHTLCContractHandler = exports.DelegateContractHandler = exports.DefaultContractHandler = exports.contractHandlers = exports.ContractWatcher = exports.ContractManager = exports.getSequence = exports.isExpired = exports.isSubdust = exports.isSpendable = exports.isRecoverable = exports.buildForfeitTx = exports.validateConnectorsTxGraph = exports.validateVtxoTxGraph = exports.Batch = exports.maybeArkError = exports.ArkError = exports.Transaction = exports.Unroll = exports.P2A = exports.TxTree = exports.BIP322 = exports.Intent = exports.ContractRepositoryImpl = exports.WalletRepositoryImpl = exports.rollbackMigration = exports.getMigrationStatus = exports.requiresMigration = exports.migrateWalletRepository = exports.MIGRATION_KEY = exports.InMemoryContractRepository = exports.InMemoryWalletRepository = exports.IndexedDBContractRepository = exports.IndexedDBWalletRepository = exports.openDatabase = exports.closeDatabase = exports.networks = exports.ArkNote = exports.isValidArkAddress = exports.isVtxoExpiringSoon = exports.combineTapscriptSigs = exports.hasBoardingTxExpired = exports.waitForIncomingFunds = exports.verifyTapscriptSignatures = exports.buildOffchainTx = exports.ConditionWitness = exports.VtxoTaprootTree = exports.VtxoTreeExpiry = void 0;
41
+ exports.isArkContract = exports.contractFromArkContractWithAddress = exports.contractFromArkContract = void 0;
42
42
  const transaction_1 = require("./utils/transaction");
43
43
  Object.defineProperty(exports, "Transaction", { enumerable: true, get: function () { return transaction_1.Transaction; } });
44
44
  const singleKey_1 = require("./identity/singleKey");
@@ -84,6 +84,7 @@ Object.defineProperty(exports, "VtxoManager", { enumerable: true, get: function
84
84
  const wallet_3 = require("./wallet/serviceWorker/wallet");
85
85
  Object.defineProperty(exports, "ServiceWorkerWallet", { enumerable: true, get: function () { return wallet_3.ServiceWorkerWallet; } });
86
86
  Object.defineProperty(exports, "ServiceWorkerReadonlyWallet", { enumerable: true, get: function () { return wallet_3.ServiceWorkerReadonlyWallet; } });
87
+ Object.defineProperty(exports, "DEFAULT_MESSAGE_TIMEOUTS", { enumerable: true, get: function () { return wallet_3.DEFAULT_MESSAGE_TIMEOUTS; } });
87
88
  const onchain_1 = require("./wallet/onchain");
88
89
  Object.defineProperty(exports, "OnchainWallet", { enumerable: true, get: function () { return onchain_1.OnchainWallet; } });
89
90
  const utils_1 = require("./worker/browser/utils");
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ServiceWorkerWallet = exports.ServiceWorkerReadonlyWallet = void 0;
3
+ exports.ServiceWorkerWallet = exports.ServiceWorkerReadonlyWallet = exports.DEFAULT_MESSAGE_TIMEOUTS = void 0;
4
4
  const base_1 = require("@scure/base");
5
5
  const utils_1 = require("../../worker/browser/utils");
6
6
  const repositories_1 = require("../../repositories");
@@ -14,6 +14,47 @@ function isMessageBusNotInitializedError(error) {
14
14
  return (error instanceof Error &&
15
15
  error.message.includes(errors_1.MESSAGE_BUS_NOT_INITIALIZED));
16
16
  }
17
+ exports.DEFAULT_MESSAGE_TIMEOUTS = {
18
+ // Fast reads — fail quickly
19
+ GET_ADDRESS: 10000,
20
+ GET_BALANCE: 10000,
21
+ GET_BOARDING_ADDRESS: 10000,
22
+ GET_STATUS: 10000,
23
+ GET_DELEGATE_INFO: 10000,
24
+ IS_CONTRACT_MANAGER_WATCHING: 10000,
25
+ // Medium reads — may involve indexer queries
26
+ GET_VTXOS: 20000,
27
+ GET_BOARDING_UTXOS: 20000,
28
+ GET_TRANSACTION_HISTORY: 20000,
29
+ GET_CONTRACTS: 20000,
30
+ GET_CONTRACTS_WITH_VTXOS: 20000,
31
+ GET_SPENDABLE_PATHS: 20000,
32
+ GET_ALL_SPENDING_PATHS: 20000,
33
+ GET_ASSET_DETAILS: 20000,
34
+ GET_EXPIRING_VTXOS: 20000,
35
+ GET_EXPIRED_BOARDING_UTXOS: 20000,
36
+ GET_RECOVERABLE_BALANCE: 20000,
37
+ RELOAD_WALLET: 20000,
38
+ // Transactions — need more headroom
39
+ SEND_BITCOIN: 50000,
40
+ SEND: 50000,
41
+ SETTLE: 50000,
42
+ ISSUE: 50000,
43
+ REISSUE: 50000,
44
+ BURN: 50000,
45
+ DELEGATE: 50000,
46
+ RECOVER_VTXOS: 50000,
47
+ RENEW_VTXOS: 50000,
48
+ SWEEP_EXPIRED_BOARDING_UTXOS: 50000,
49
+ // Misc writes
50
+ INIT_WALLET: 30000,
51
+ CLEAR: 10000,
52
+ SIGN_TRANSACTION: 30000,
53
+ CREATE_CONTRACT: 30000,
54
+ UPDATE_CONTRACT: 30000,
55
+ DELETE_CONTRACT: 10000,
56
+ REFRESH_VTXOS: 30000,
57
+ };
17
58
  const DEDUPABLE_REQUEST_TYPES = new Set([
18
59
  "GET_ADDRESS",
19
60
  "GET_BALANCE",
@@ -129,6 +170,7 @@ class ServiceWorkerReadonlyWallet {
129
170
  this.messageTag = messageTag;
130
171
  this.initConfig = null;
131
172
  this.initWalletPayload = null;
173
+ this.messageTimeouts = exports.DEFAULT_MESSAGE_TIMEOUTS;
132
174
  this.reinitPromise = null;
133
175
  this.pingPromise = null;
134
176
  this.inflightRequests = new Map();
@@ -137,6 +179,9 @@ class ServiceWorkerReadonlyWallet {
137
179
  this.contractRepository = contractRepository;
138
180
  this._readonlyAssetManager = new ServiceWorkerReadonlyAssetManager((msg) => this.sendMessage(msg), messageTag);
139
181
  }
182
+ getTimeoutForRequest(request) {
183
+ return this.messageTimeouts[request.type] ?? 30000;
184
+ }
140
185
  static async create(options) {
141
186
  const walletRepository = options.storage?.walletRepository ??
142
187
  new repositories_1.IndexedDBWalletRepository();
@@ -188,6 +233,12 @@ class ServiceWorkerReadonlyWallet {
188
233
  };
189
234
  wallet.initWalletPayload = initConfig;
190
235
  wallet.messageBusTimeoutMs = options.messageBusTimeoutMs;
236
+ if (options.messageTimeouts) {
237
+ wallet.messageTimeouts = {
238
+ ...exports.DEFAULT_MESSAGE_TIMEOUTS,
239
+ ...options.messageTimeouts,
240
+ };
241
+ }
191
242
  return wallet;
192
243
  }
193
244
  /**
@@ -223,7 +274,7 @@ class ServiceWorkerReadonlyWallet {
223
274
  serviceWorker,
224
275
  });
225
276
  }
226
- sendMessageDirect(request) {
277
+ sendMessageDirect(request, timeoutMs) {
227
278
  return new Promise((resolve, reject) => {
228
279
  const cleanup = () => {
229
280
  clearTimeout(timeoutId);
@@ -232,7 +283,7 @@ class ServiceWorkerReadonlyWallet {
232
283
  const timeoutId = setTimeout(() => {
233
284
  cleanup();
234
285
  reject(new errors_1.ServiceWorkerTimeoutError(`Service worker message timed out (${request.type})`));
235
- }, 30000);
286
+ }, timeoutMs);
236
287
  const messageHandler = (event) => {
237
288
  const response = event.data;
238
289
  if (request.id !== response.id) {
@@ -255,14 +306,14 @@ class ServiceWorkerReadonlyWallet {
255
306
  // first response for which isComplete returns true. The timeout resets
256
307
  // on every intermediate event so long-running but progressing operations
257
308
  // don't time out prematurely.
258
- sendMessageStreaming(request, onEvent, isComplete) {
309
+ sendMessageStreaming(request, onEvent, isComplete, timeoutMs) {
259
310
  return new Promise((resolve, reject) => {
260
311
  const resetTimeout = () => {
261
312
  clearTimeout(timeoutId);
262
313
  timeoutId = setTimeout(() => {
263
314
  cleanup();
264
315
  reject(new errors_1.ServiceWorkerTimeoutError(`Service worker message timed out (${request.type})`));
265
- }, 30000);
316
+ }, timeoutMs);
266
317
  };
267
318
  const cleanup = () => {
268
319
  clearTimeout(timeoutId);
@@ -348,10 +399,11 @@ class ServiceWorkerReadonlyWallet {
348
399
  await this.reinitialize();
349
400
  }
350
401
  }
402
+ const timeoutMs = this.getTimeoutForRequest(request);
351
403
  const maxRetries = 2;
352
404
  for (let attempt = 0;; attempt++) {
353
405
  try {
354
- return await this.sendMessageDirect(request);
406
+ return await this.sendMessageDirect(request, timeoutMs);
355
407
  }
356
408
  catch (error) {
357
409
  if (!isMessageBusNotInitializedError(error) ||
@@ -373,10 +425,11 @@ class ServiceWorkerReadonlyWallet {
373
425
  await this.reinitialize();
374
426
  }
375
427
  }
428
+ const timeoutMs = this.getTimeoutForRequest(request);
376
429
  const maxRetries = 2;
377
430
  for (let attempt = 0;; attempt++) {
378
431
  try {
379
- return await this.sendMessageStreaming(request, onEvent, isComplete);
432
+ return await this.sendMessageStreaming(request, onEvent, isComplete, timeoutMs);
380
433
  }
381
434
  catch (error) {
382
435
  if (!isMessageBusNotInitializedError(error) ||
@@ -401,7 +454,7 @@ class ServiceWorkerReadonlyWallet {
401
454
  id: (0, utils_2.getRandomId)(),
402
455
  payload: this.initWalletPayload,
403
456
  };
404
- await this.sendMessageDirect(initMessage);
457
+ await this.sendMessageDirect(initMessage, this.getTimeoutForRequest(initMessage));
405
458
  })().finally(() => {
406
459
  this.reinitPromise = null;
407
460
  });
@@ -793,6 +846,12 @@ class ServiceWorkerWallet extends ServiceWorkerReadonlyWallet {
793
846
  };
794
847
  wallet.initWalletPayload = initConfig;
795
848
  wallet.messageBusTimeoutMs = options.messageBusTimeoutMs;
849
+ if (options.messageTimeouts) {
850
+ wallet.messageTimeouts = {
851
+ ...exports.DEFAULT_MESSAGE_TIMEOUTS,
852
+ ...options.messageTimeouts,
853
+ };
854
+ }
796
855
  return wallet;
797
856
  }
798
857
  /**
package/dist/esm/index.js CHANGED
@@ -13,7 +13,7 @@ import { Wallet, ReadonlyWallet, waitForIncomingFunds, } from './wallet/wallet.j
13
13
  import { TxTree } from './tree/txTree.js';
14
14
  import { Ramps } from './wallet/ramps.js';
15
15
  import { isVtxoExpiringSoon, VtxoManager } from './wallet/vtxo-manager.js';
16
- import { ServiceWorkerWallet, ServiceWorkerReadonlyWallet, } from './wallet/serviceWorker/wallet.js';
16
+ import { ServiceWorkerWallet, ServiceWorkerReadonlyWallet, DEFAULT_MESSAGE_TIMEOUTS, } from './wallet/serviceWorker/wallet.js';
17
17
  import { OnchainWallet } from './wallet/onchain.js';
18
18
  import { setupServiceWorker } from './worker/browser/utils.js';
19
19
  import { ESPLORA_URL, EsploraProvider, } from './providers/onchain.js';
@@ -51,7 +51,7 @@ ArkAddress, DefaultVtxo, DelegateVtxo, VtxoScript, VHTLC,
51
51
  // Enums
52
52
  TxType, IndexerTxType, ChainTxType, SettlementEventType,
53
53
  // Service Worker
54
- setupServiceWorker, MessageBus, WalletMessageHandler, WalletNotInitializedError, ReadonlyWalletError, DelegatorNotConfiguredError, MESSAGE_BUS_NOT_INITIALIZED, MessageBusNotInitializedError, ServiceWorkerTimeoutError, ServiceWorkerWallet, ServiceWorkerReadonlyWallet,
54
+ setupServiceWorker, MessageBus, WalletMessageHandler, WalletNotInitializedError, ReadonlyWalletError, DelegatorNotConfiguredError, MESSAGE_BUS_NOT_INITIALIZED, MessageBusNotInitializedError, ServiceWorkerTimeoutError, ServiceWorkerWallet, ServiceWorkerReadonlyWallet, DEFAULT_MESSAGE_TIMEOUTS,
55
55
  // Tapscript
56
56
  decodeTapscript, MultisigTapscript, CSVMultisigTapscript, ConditionCSVMultisigTapscript, ConditionMultisigTapscript, CLTVMultisigTapscript, TapTreeCoder,
57
57
  // Ark PSBT fields
@@ -11,6 +11,47 @@ function isMessageBusNotInitializedError(error) {
11
11
  return (error instanceof Error &&
12
12
  error.message.includes(MESSAGE_BUS_NOT_INITIALIZED));
13
13
  }
14
+ export const DEFAULT_MESSAGE_TIMEOUTS = {
15
+ // Fast reads — fail quickly
16
+ GET_ADDRESS: 10000,
17
+ GET_BALANCE: 10000,
18
+ GET_BOARDING_ADDRESS: 10000,
19
+ GET_STATUS: 10000,
20
+ GET_DELEGATE_INFO: 10000,
21
+ IS_CONTRACT_MANAGER_WATCHING: 10000,
22
+ // Medium reads — may involve indexer queries
23
+ GET_VTXOS: 20000,
24
+ GET_BOARDING_UTXOS: 20000,
25
+ GET_TRANSACTION_HISTORY: 20000,
26
+ GET_CONTRACTS: 20000,
27
+ GET_CONTRACTS_WITH_VTXOS: 20000,
28
+ GET_SPENDABLE_PATHS: 20000,
29
+ GET_ALL_SPENDING_PATHS: 20000,
30
+ GET_ASSET_DETAILS: 20000,
31
+ GET_EXPIRING_VTXOS: 20000,
32
+ GET_EXPIRED_BOARDING_UTXOS: 20000,
33
+ GET_RECOVERABLE_BALANCE: 20000,
34
+ RELOAD_WALLET: 20000,
35
+ // Transactions — need more headroom
36
+ SEND_BITCOIN: 50000,
37
+ SEND: 50000,
38
+ SETTLE: 50000,
39
+ ISSUE: 50000,
40
+ REISSUE: 50000,
41
+ BURN: 50000,
42
+ DELEGATE: 50000,
43
+ RECOVER_VTXOS: 50000,
44
+ RENEW_VTXOS: 50000,
45
+ SWEEP_EXPIRED_BOARDING_UTXOS: 50000,
46
+ // Misc writes
47
+ INIT_WALLET: 30000,
48
+ CLEAR: 10000,
49
+ SIGN_TRANSACTION: 30000,
50
+ CREATE_CONTRACT: 30000,
51
+ UPDATE_CONTRACT: 30000,
52
+ DELETE_CONTRACT: 10000,
53
+ REFRESH_VTXOS: 30000,
54
+ };
14
55
  const DEDUPABLE_REQUEST_TYPES = new Set([
15
56
  "GET_ADDRESS",
16
57
  "GET_BALANCE",
@@ -126,6 +167,7 @@ export class ServiceWorkerReadonlyWallet {
126
167
  this.messageTag = messageTag;
127
168
  this.initConfig = null;
128
169
  this.initWalletPayload = null;
170
+ this.messageTimeouts = DEFAULT_MESSAGE_TIMEOUTS;
129
171
  this.reinitPromise = null;
130
172
  this.pingPromise = null;
131
173
  this.inflightRequests = new Map();
@@ -134,6 +176,9 @@ export class ServiceWorkerReadonlyWallet {
134
176
  this.contractRepository = contractRepository;
135
177
  this._readonlyAssetManager = new ServiceWorkerReadonlyAssetManager((msg) => this.sendMessage(msg), messageTag);
136
178
  }
179
+ getTimeoutForRequest(request) {
180
+ return this.messageTimeouts[request.type] ?? 30000;
181
+ }
137
182
  static async create(options) {
138
183
  const walletRepository = options.storage?.walletRepository ??
139
184
  new IndexedDBWalletRepository();
@@ -185,6 +230,12 @@ export class ServiceWorkerReadonlyWallet {
185
230
  };
186
231
  wallet.initWalletPayload = initConfig;
187
232
  wallet.messageBusTimeoutMs = options.messageBusTimeoutMs;
233
+ if (options.messageTimeouts) {
234
+ wallet.messageTimeouts = {
235
+ ...DEFAULT_MESSAGE_TIMEOUTS,
236
+ ...options.messageTimeouts,
237
+ };
238
+ }
188
239
  return wallet;
189
240
  }
190
241
  /**
@@ -220,7 +271,7 @@ export class ServiceWorkerReadonlyWallet {
220
271
  serviceWorker,
221
272
  });
222
273
  }
223
- sendMessageDirect(request) {
274
+ sendMessageDirect(request, timeoutMs) {
224
275
  return new Promise((resolve, reject) => {
225
276
  const cleanup = () => {
226
277
  clearTimeout(timeoutId);
@@ -229,7 +280,7 @@ export class ServiceWorkerReadonlyWallet {
229
280
  const timeoutId = setTimeout(() => {
230
281
  cleanup();
231
282
  reject(new ServiceWorkerTimeoutError(`Service worker message timed out (${request.type})`));
232
- }, 30000);
283
+ }, timeoutMs);
233
284
  const messageHandler = (event) => {
234
285
  const response = event.data;
235
286
  if (request.id !== response.id) {
@@ -252,14 +303,14 @@ export class ServiceWorkerReadonlyWallet {
252
303
  // first response for which isComplete returns true. The timeout resets
253
304
  // on every intermediate event so long-running but progressing operations
254
305
  // don't time out prematurely.
255
- sendMessageStreaming(request, onEvent, isComplete) {
306
+ sendMessageStreaming(request, onEvent, isComplete, timeoutMs) {
256
307
  return new Promise((resolve, reject) => {
257
308
  const resetTimeout = () => {
258
309
  clearTimeout(timeoutId);
259
310
  timeoutId = setTimeout(() => {
260
311
  cleanup();
261
312
  reject(new ServiceWorkerTimeoutError(`Service worker message timed out (${request.type})`));
262
- }, 30000);
313
+ }, timeoutMs);
263
314
  };
264
315
  const cleanup = () => {
265
316
  clearTimeout(timeoutId);
@@ -345,10 +396,11 @@ export class ServiceWorkerReadonlyWallet {
345
396
  await this.reinitialize();
346
397
  }
347
398
  }
399
+ const timeoutMs = this.getTimeoutForRequest(request);
348
400
  const maxRetries = 2;
349
401
  for (let attempt = 0;; attempt++) {
350
402
  try {
351
- return await this.sendMessageDirect(request);
403
+ return await this.sendMessageDirect(request, timeoutMs);
352
404
  }
353
405
  catch (error) {
354
406
  if (!isMessageBusNotInitializedError(error) ||
@@ -370,10 +422,11 @@ export class ServiceWorkerReadonlyWallet {
370
422
  await this.reinitialize();
371
423
  }
372
424
  }
425
+ const timeoutMs = this.getTimeoutForRequest(request);
373
426
  const maxRetries = 2;
374
427
  for (let attempt = 0;; attempt++) {
375
428
  try {
376
- return await this.sendMessageStreaming(request, onEvent, isComplete);
429
+ return await this.sendMessageStreaming(request, onEvent, isComplete, timeoutMs);
377
430
  }
378
431
  catch (error) {
379
432
  if (!isMessageBusNotInitializedError(error) ||
@@ -398,7 +451,7 @@ export class ServiceWorkerReadonlyWallet {
398
451
  id: getRandomId(),
399
452
  payload: this.initWalletPayload,
400
453
  };
401
- await this.sendMessageDirect(initMessage);
454
+ await this.sendMessageDirect(initMessage, this.getTimeoutForRequest(initMessage));
402
455
  })().finally(() => {
403
456
  this.reinitPromise = null;
404
457
  });
@@ -789,6 +842,12 @@ export class ServiceWorkerWallet extends ServiceWorkerReadonlyWallet {
789
842
  };
790
843
  wallet.initWalletPayload = initConfig;
791
844
  wallet.messageBusTimeoutMs = options.messageBusTimeoutMs;
845
+ if (options.messageTimeouts) {
846
+ wallet.messageTimeouts = {
847
+ ...DEFAULT_MESSAGE_TIMEOUTS,
848
+ ...options.messageTimeouts,
849
+ };
850
+ }
792
851
  return wallet;
793
852
  }
794
853
  /**
@@ -17,7 +17,8 @@ import { SignerSession, TreeNonces, TreePartialSigs } from "./tree/signingSessio
17
17
  import { Ramps } from "./wallet/ramps";
18
18
  import { isVtxoExpiringSoon, VtxoManager } from "./wallet/vtxo-manager";
19
19
  import type { IVtxoManager, SettlementConfig } from "./wallet/vtxo-manager";
20
- import { ServiceWorkerWallet, ServiceWorkerReadonlyWallet } from "./wallet/serviceWorker/wallet";
20
+ import { ServiceWorkerWallet, ServiceWorkerReadonlyWallet, DEFAULT_MESSAGE_TIMEOUTS } from "./wallet/serviceWorker/wallet";
21
+ import type { MessageTimeouts } from "./wallet/serviceWorker/wallet";
21
22
  import { OnchainWallet } from "./wallet/onchain";
22
23
  import { setupServiceWorker } from "./worker/browser/utils";
23
24
  import { ESPLORA_URL, EsploraProvider, OnchainProvider, ExplorerTransaction } from "./providers/onchain";
@@ -49,5 +50,5 @@ import { IContractManager } from "./contracts/contractManager";
49
50
  import { closeDatabase, openDatabase } from "./repositories/indexedDB/manager";
50
51
  import { WalletMessageHandler, WalletNotInitializedError, ReadonlyWalletError, DelegatorNotConfiguredError } from "./wallet/serviceWorker/wallet-message-handler";
51
52
  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
- 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, };
53
+ 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, DEFAULT_MESSAGE_TIMEOUTS, 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, };
54
+ 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, MessageTimeouts, IDelegatorManager, DelegatorProvider, DelegateInfo, DelegateOptions, WalletRepository, ContractRepository, MigrationStatus, };
@@ -8,6 +8,9 @@ import type { IContractManager } from "../../contracts/contractManager";
8
8
  import type { IDelegatorManager } from "../delegator";
9
9
  import type { IVtxoManager, SettlementConfig } from "../vtxo-manager";
10
10
  import type { ContractWatcherConfig } from "../../contracts/contractWatcher";
11
+ type RequestType = WalletUpdaterRequest["type"];
12
+ export type MessageTimeouts = Partial<Record<RequestType, number>>;
13
+ export declare const DEFAULT_MESSAGE_TIMEOUTS: Readonly<Record<RequestType, number>>;
11
14
  type PrivateKeyIdentity = Identity & {
12
15
  toHex(): string;
13
16
  };
@@ -55,6 +58,7 @@ interface ServiceWorkerWalletOptions {
55
58
  messageBusTimeoutMs?: number;
56
59
  settlementConfig?: SettlementConfig | false;
57
60
  watcherConfig?: Partial<Omit<ContractWatcherConfig, "indexerProvider">>;
61
+ messageTimeouts?: MessageTimeouts;
58
62
  }
59
63
  export type ServiceWorkerWalletCreateOptions = ServiceWorkerWalletOptions & {
60
64
  serviceWorker: ServiceWorker;
@@ -90,11 +94,13 @@ export declare class ServiceWorkerReadonlyWallet implements IReadonlyWallet {
90
94
  protected initConfig: MessageBusInitConfig | null;
91
95
  protected initWalletPayload: RequestInitWallet["payload"] | null;
92
96
  protected messageBusTimeoutMs?: number;
97
+ protected messageTimeouts: Record<RequestType, number>;
93
98
  private reinitPromise;
94
99
  private pingPromise;
95
100
  private inflightRequests;
96
101
  get assetManager(): IReadonlyAssetManager;
97
102
  protected constructor(serviceWorker: ServiceWorker, identity: ReadonlyIdentity, walletRepository: WalletRepository, contractRepository: ContractRepository, messageTag: string);
103
+ private getTimeoutForRequest;
98
104
  static create(options: ServiceWorkerWalletCreateOptions): Promise<ServiceWorkerReadonlyWallet>;
99
105
  /**
100
106
  * Simplified setup method that handles service worker registration,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkade-os/sdk",
3
- "version": "0.4.13",
3
+ "version": "0.4.14",
4
4
  "description": "Bitcoin wallet SDK with Taproot and Ark integration",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
@@ -80,7 +80,7 @@
80
80
  "registry": "https://registry.npmjs.org/"
81
81
  },
82
82
  "dependencies": {
83
- "@bitcoinerlab/descriptors-scure": "3.1.4",
83
+ "@bitcoinerlab/descriptors-scure": "3.1.7",
84
84
  "@marcbachmann/cel-js": "7.3.1",
85
85
  "@noble/curves": "2.0.1",
86
86
  "@noble/secp256k1": "3.0.0",