@arkade-os/sdk 0.4.15 → 0.4.17

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 (197) hide show
  1. package/README.md +102 -96
  2. package/dist/cjs/arkfee/estimator.js +1 -1
  3. package/dist/cjs/arkfee/types.js +2 -1
  4. package/dist/cjs/arknote/index.js +43 -4
  5. package/dist/cjs/bip322/index.js +1 -1
  6. package/dist/cjs/contracts/arkcontract.js +1 -1
  7. package/dist/cjs/contracts/contractManager.js +60 -28
  8. package/dist/cjs/contracts/contractWatcher.js +29 -22
  9. package/dist/cjs/contracts/handlers/default.js +1 -1
  10. package/dist/cjs/contracts/handlers/delegate.js +1 -1
  11. package/dist/cjs/contracts/handlers/helpers.js +1 -1
  12. package/dist/cjs/extension/asset/assetGroup.js +92 -5
  13. package/dist/cjs/extension/asset/assetId.js +67 -3
  14. package/dist/cjs/extension/asset/assetInput.js +18 -0
  15. package/dist/cjs/extension/asset/assetOutput.js +15 -0
  16. package/dist/cjs/extension/asset/assetRef.js +66 -0
  17. package/dist/cjs/extension/asset/metadata.js +15 -0
  18. package/dist/cjs/extension/asset/packet.js +4 -1
  19. package/dist/cjs/extension/index.js +1 -1
  20. package/dist/cjs/forfeit.js +14 -0
  21. package/dist/cjs/identity/seedIdentity.js +2 -2
  22. package/dist/cjs/identity/singleKey.js +4 -0
  23. package/dist/cjs/intent/index.js +28 -12
  24. package/dist/cjs/providers/ark.js +3 -2
  25. package/dist/cjs/providers/delegator.js +20 -1
  26. package/dist/cjs/providers/expoArk.js +2 -2
  27. package/dist/cjs/providers/indexer.js +2 -2
  28. package/dist/cjs/providers/onchain.js +2 -1
  29. package/dist/cjs/repositories/realm/schemas.js +2 -2
  30. package/dist/cjs/repositories/realm/types.js +1 -1
  31. package/dist/cjs/script/address.js +37 -6
  32. package/dist/cjs/script/base.js +70 -1
  33. package/dist/cjs/script/default.js +3 -0
  34. package/dist/cjs/script/delegate.js +4 -0
  35. package/dist/cjs/script/tapscript.js +17 -2
  36. package/dist/cjs/script/vhtlc.js +35 -27
  37. package/dist/cjs/storage/fileSystem.js +1 -1
  38. package/dist/cjs/storage/inMemory.js +1 -1
  39. package/dist/cjs/storage/indexedDB.js +1 -1
  40. package/dist/cjs/storage/localStorage.js +1 -1
  41. package/dist/cjs/tree/validation.js +1 -1
  42. package/dist/cjs/utils/arkTransaction.js +5 -5
  43. package/dist/cjs/utils/bip21.js +16 -3
  44. package/dist/cjs/utils/syncCursors.js +4 -4
  45. package/dist/cjs/utils/transaction.js +1 -1
  46. package/dist/cjs/utils/transactionHistory.js +11 -11
  47. package/dist/cjs/utils/unknownFields.js +3 -3
  48. package/dist/cjs/wallet/asset-manager.js +4 -4
  49. package/dist/cjs/wallet/batch.js +5 -5
  50. package/dist/cjs/wallet/delegator.js +9 -8
  51. package/dist/cjs/wallet/expo/background.js +3 -3
  52. package/dist/cjs/wallet/expo/wallet.js +7 -7
  53. package/dist/cjs/wallet/index.js +43 -0
  54. package/dist/cjs/wallet/onchain.js +43 -5
  55. package/dist/cjs/wallet/ramps.js +44 -14
  56. package/dist/cjs/wallet/serviceWorker/wallet-message-handler.js +22 -22
  57. package/dist/cjs/wallet/serviceWorker/wallet.js +28 -24
  58. package/dist/cjs/wallet/unroll.js +12 -8
  59. package/dist/cjs/wallet/utils.js +1 -1
  60. package/dist/cjs/wallet/vtxo-manager.js +122 -82
  61. package/dist/cjs/wallet/wallet.js +140 -77
  62. package/dist/cjs/worker/expo/asyncStorageTaskQueue.js +1 -1
  63. package/dist/cjs/worker/expo/processors/contractPollProcessor.js +2 -2
  64. package/dist/cjs/worker/expo/taskRunner.js +3 -3
  65. package/dist/cjs/worker/messageBus.js +3 -0
  66. package/dist/esm/arkfee/estimator.js +1 -1
  67. package/dist/esm/arkfee/types.js +2 -1
  68. package/dist/esm/arknote/index.js +43 -4
  69. package/dist/esm/bip322/index.js +1 -1
  70. package/dist/esm/contracts/arkcontract.js +1 -1
  71. package/dist/esm/contracts/contractManager.js +60 -28
  72. package/dist/esm/contracts/contractWatcher.js +29 -22
  73. package/dist/esm/contracts/handlers/default.js +1 -1
  74. package/dist/esm/contracts/handlers/delegate.js +1 -1
  75. package/dist/esm/contracts/handlers/helpers.js +1 -1
  76. package/dist/esm/extension/asset/assetGroup.js +92 -5
  77. package/dist/esm/extension/asset/assetId.js +67 -3
  78. package/dist/esm/extension/asset/assetInput.js +18 -0
  79. package/dist/esm/extension/asset/assetOutput.js +15 -0
  80. package/dist/esm/extension/asset/assetRef.js +66 -0
  81. package/dist/esm/extension/asset/metadata.js +15 -0
  82. package/dist/esm/extension/asset/packet.js +4 -1
  83. package/dist/esm/extension/index.js +1 -1
  84. package/dist/esm/forfeit.js +14 -0
  85. package/dist/esm/identity/seedIdentity.js +2 -2
  86. package/dist/esm/identity/singleKey.js +4 -0
  87. package/dist/esm/index.js +1 -1
  88. package/dist/esm/intent/index.js +28 -12
  89. package/dist/esm/providers/ark.js +3 -2
  90. package/dist/esm/providers/delegator.js +20 -1
  91. package/dist/esm/providers/expoArk.js +2 -2
  92. package/dist/esm/providers/indexer.js +2 -2
  93. package/dist/esm/providers/onchain.js +2 -1
  94. package/dist/esm/repositories/realm/schemas.js +2 -2
  95. package/dist/esm/repositories/realm/types.js +1 -1
  96. package/dist/esm/script/address.js +37 -6
  97. package/dist/esm/script/base.js +70 -1
  98. package/dist/esm/script/default.js +3 -0
  99. package/dist/esm/script/delegate.js +4 -0
  100. package/dist/esm/script/tapscript.js +17 -2
  101. package/dist/esm/script/vhtlc.js +35 -27
  102. package/dist/esm/storage/fileSystem.js +1 -1
  103. package/dist/esm/storage/inMemory.js +1 -1
  104. package/dist/esm/storage/indexedDB.js +1 -1
  105. package/dist/esm/storage/localStorage.js +1 -1
  106. package/dist/esm/tree/validation.js +1 -1
  107. package/dist/esm/utils/arkTransaction.js +5 -5
  108. package/dist/esm/utils/bip21.js +16 -3
  109. package/dist/esm/utils/syncCursors.js +4 -4
  110. package/dist/esm/utils/transaction.js +1 -1
  111. package/dist/esm/utils/transactionHistory.js +11 -11
  112. package/dist/esm/utils/unknownFields.js +3 -3
  113. package/dist/esm/wallet/asset-manager.js +4 -4
  114. package/dist/esm/wallet/batch.js +5 -5
  115. package/dist/esm/wallet/delegator.js +9 -8
  116. package/dist/esm/wallet/expo/background.js +3 -3
  117. package/dist/esm/wallet/expo/wallet.js +7 -7
  118. package/dist/esm/wallet/index.js +43 -0
  119. package/dist/esm/wallet/onchain.js +43 -5
  120. package/dist/esm/wallet/ramps.js +44 -14
  121. package/dist/esm/wallet/serviceWorker/wallet-message-handler.js +22 -22
  122. package/dist/esm/wallet/serviceWorker/wallet.js +28 -24
  123. package/dist/esm/wallet/unroll.js +12 -8
  124. package/dist/esm/wallet/utils.js +1 -1
  125. package/dist/esm/wallet/vtxo-manager.js +121 -81
  126. package/dist/esm/wallet/wallet.js +140 -77
  127. package/dist/esm/worker/expo/asyncStorageTaskQueue.js +1 -1
  128. package/dist/esm/worker/expo/processors/contractPollProcessor.js +2 -2
  129. package/dist/esm/worker/expo/taskRunner.js +3 -3
  130. package/dist/esm/worker/messageBus.js +3 -0
  131. package/dist/types/arkfee/estimator.d.ts +1 -1
  132. package/dist/types/arkfee/types.d.ts +2 -1
  133. package/dist/types/arknote/index.d.ts +44 -4
  134. package/dist/types/bip322/index.d.ts +1 -1
  135. package/dist/types/contracts/arkcontract.d.ts +1 -1
  136. package/dist/types/contracts/contractManager.d.ts +39 -65
  137. package/dist/types/contracts/contractWatcher.d.ts +39 -18
  138. package/dist/types/contracts/handlers/default.d.ts +1 -1
  139. package/dist/types/contracts/handlers/delegate.d.ts +1 -1
  140. package/dist/types/contracts/handlers/helpers.d.ts +1 -1
  141. package/dist/types/contracts/types.d.ts +36 -26
  142. package/dist/types/extension/asset/assetGroup.d.ts +92 -1
  143. package/dist/types/extension/asset/assetId.d.ts +67 -3
  144. package/dist/types/extension/asset/assetInput.d.ts +18 -0
  145. package/dist/types/extension/asset/assetOutput.d.ts +15 -0
  146. package/dist/types/extension/asset/assetRef.d.ts +66 -0
  147. package/dist/types/extension/asset/metadata.d.ts +15 -0
  148. package/dist/types/extension/asset/packet.d.ts +4 -1
  149. package/dist/types/extension/index.d.ts +1 -1
  150. package/dist/types/forfeit.d.ts +14 -0
  151. package/dist/types/identity/index.d.ts +16 -0
  152. package/dist/types/identity/seedIdentity.d.ts +8 -6
  153. package/dist/types/identity/singleKey.d.ts +4 -0
  154. package/dist/types/intent/index.d.ts +19 -6
  155. package/dist/types/providers/ark.d.ts +40 -2
  156. package/dist/types/providers/delegator.d.ts +54 -1
  157. package/dist/types/providers/expoArk.d.ts +2 -2
  158. package/dist/types/providers/indexer.d.ts +105 -2
  159. package/dist/types/providers/onchain.d.ts +62 -1
  160. package/dist/types/repositories/realm/schemas.d.ts +2 -2
  161. package/dist/types/repositories/realm/types.d.ts +2 -2
  162. package/dist/types/repositories/walletRepository.d.ts +16 -0
  163. package/dist/types/script/address.d.ts +35 -2
  164. package/dist/types/script/base.d.ts +66 -1
  165. package/dist/types/script/default.d.ts +3 -0
  166. package/dist/types/script/delegate.d.ts +4 -0
  167. package/dist/types/script/tapscript.d.ts +17 -2
  168. package/dist/types/script/vhtlc.d.ts +35 -27
  169. package/dist/types/storage/fileSystem.d.ts +1 -1
  170. package/dist/types/storage/inMemory.d.ts +1 -1
  171. package/dist/types/storage/index.d.ts +1 -1
  172. package/dist/types/storage/indexedDB.d.ts +1 -1
  173. package/dist/types/storage/localStorage.d.ts +1 -1
  174. package/dist/types/utils/arkTransaction.d.ts +3 -3
  175. package/dist/types/utils/bip21.d.ts +17 -0
  176. package/dist/types/utils/syncCursors.d.ts +4 -4
  177. package/dist/types/utils/transaction.d.ts +1 -1
  178. package/dist/types/utils/transactionHistory.d.ts +3 -3
  179. package/dist/types/utils/unknownFields.d.ts +5 -5
  180. package/dist/types/wallet/asset-manager.d.ts +3 -3
  181. package/dist/types/wallet/batch.d.ts +27 -7
  182. package/dist/types/wallet/delegator.d.ts +10 -0
  183. package/dist/types/wallet/expo/background.d.ts +4 -4
  184. package/dist/types/wallet/expo/wallet.d.ts +10 -10
  185. package/dist/types/wallet/index.d.ts +457 -25
  186. package/dist/types/wallet/onchain.d.ts +42 -4
  187. package/dist/types/wallet/ramps.d.ts +40 -10
  188. package/dist/types/wallet/serviceWorker/wallet-message-handler.d.ts +4 -4
  189. package/dist/types/wallet/serviceWorker/wallet.d.ts +71 -33
  190. package/dist/types/wallet/unroll.d.ts +8 -6
  191. package/dist/types/wallet/vtxo-manager.d.ts +146 -93
  192. package/dist/types/wallet/wallet.d.ts +91 -33
  193. package/dist/types/worker/expo/asyncStorageTaskQueue.d.ts +1 -1
  194. package/dist/types/worker/expo/processors/contractPollProcessor.d.ts +1 -1
  195. package/dist/types/worker/expo/taskRunner.d.ts +6 -6
  196. package/dist/types/worker/messageBus.d.ts +5 -3
  197. package/package.json +1 -1
@@ -7,30 +7,50 @@ const base_1 = require("@scure/base");
7
7
  const networks_1 = require("../networks");
8
8
  const address_1 = require("../script/address");
9
9
  /**
10
- * Ramps is a class wrapping IWallet.settle method to provide a more convenient interface for onboarding and offboarding operations.
10
+ * Ramps is a class wrapping `settle` method to provide a more convenient interface for onboarding and offboarding operations.
11
+ *
12
+ * @see IWallet.settle
13
+ * @see onboard
14
+ * @see offboard
11
15
  *
12
16
  * @example
13
17
  * ```typescript
14
18
  * const ramps = new Ramps(wallet);
15
- * await ramps.onboard(); // onboard all boarding utxos
16
- * await ramps.offboard(myOnchainAddress); // collaborative exit all vtxos to onchain address
19
+ * const feeInfo = { intentFee: {}, txFeeRate: '1' };
20
+ * await ramps.onboard(feeInfo); // onboard all boarding inputs
21
+ * await ramps.offboard('bc1q...', feeInfo); // collaboratively exit all virtual outputs to an onchain address
17
22
  * ```
18
23
  */
19
24
  class Ramps {
25
+ /**
26
+ * Create convenience wrappers for onboarding and offboarding flows.
27
+ *
28
+ * @param wallet - Wallet used to query funds and execute settlement transactions
29
+ */
20
30
  constructor(wallet) {
21
31
  this.wallet = wallet;
22
32
  }
23
33
  /**
24
- * Onboard boarding utxos.
34
+ * Onboard boarding inputs.
25
35
  *
26
36
  * @param feeInfo - The fee info to deduct from the onboard amount.
27
- * @param boardingUtxos - The boarding utxos to onboard. If not provided, all boarding utxos will be used.
28
- * @param amount - The amount to onboard. If not provided, the total amount of boarding utxos will be onboarded.
29
- * @param eventCallback - The callback to receive settlement events. optional.
37
+ * @param boardingUtxos - Specific boarding inputs to onboard. If not provided, all boarding inputs will be used.
38
+ * @param amount - Amount to onboard. If not provided, the total amount of boarding inputs will be onboarded.
39
+ * @param eventCallback - Optional callback that receives settlement events
40
+ * @returns The Arkade transaction id created by settlement
41
+ * @throws Error if no boarding inputs remain after fee deduction or if `amount` exceeds available value
42
+ * @see IWallet.getBoardingUtxos
43
+ * @see IWallet.settle
44
+ * @example
45
+ * ```typescript
46
+ * const feeInfo = { intentFee: {}, txFeeRate: '1' };
47
+ * const ramps = new Ramps(wallet);
48
+ * await ramps.onboard(feeInfo);
49
+ * ```
30
50
  */
31
51
  async onboard(feeInfo, boardingUtxos, amount, eventCallback) {
32
52
  boardingUtxos = boardingUtxos ?? (await this.wallet.getBoardingUtxos());
33
- // Calculate input fees and filter out utxos where fee >= value
53
+ // Calculate input fees and filter out boarding inputs where fee >= value.
34
54
  const estimator = new arkfee_1.Estimator(feeInfo?.intentFee ?? {});
35
55
  const filteredBoardingUtxos = [];
36
56
  let totalAmount = 0n;
@@ -39,7 +59,7 @@ class Ramps {
39
59
  amount: BigInt(utxo.value),
40
60
  });
41
61
  if (inputFee.satoshis >= utxo.value) {
42
- // skip if fees are greater than or equal to the utxo value
62
+ // Skip boarding inputs where spending fees are greater than or equal to the input value.
43
63
  continue;
44
64
  }
45
65
  filteredBoardingUtxos.push(utxo);
@@ -87,19 +107,29 @@ class Ramps {
87
107
  }, eventCallback);
88
108
  }
89
109
  /**
90
- * Offboard vtxos, or "collaborative exit" vtxos to onchain address.
110
+ * Offboard virtual outputs, or collaboratively exit them to an onchain address.
91
111
  *
92
112
  * @param destinationAddress - The destination address to offboard to.
93
113
  * @param feeInfo - The fee info to deduct from the offboard amount.
94
- * @param amount - The amount to offboard. If not provided, the total amount of vtxos will be offboarded.
95
- * @param eventCallback - The callback to receive settlement events. optional.
114
+ * @param amount - The amount to offboard. If not provided, the total amount of virtual outputs will be offboarded.
115
+ * @param eventCallback - Optional callback that receives settlement events
116
+ * @returns The Arkade transaction id created by settlement
117
+ * @throws Error if no virtual outputs remain after fee deduction or the destination address cannot be decoded
118
+ * @see IWallet.getVtxos
119
+ * @see IWallet.settle
120
+ * @example
121
+ * ```typescript
122
+ * const feeInfo = { intentFee: {}, txFeeRate: '1' };
123
+ * const ramps = new Ramps(wallet);
124
+ * await ramps.offboard('bc1q...', feeInfo);
125
+ * ```
96
126
  */
97
127
  async offboard(destinationAddress, feeInfo, amount, eventCallback) {
98
128
  const vtxos = await this.wallet.getVtxos({
99
129
  withRecoverable: true,
100
130
  withUnrolled: false,
101
131
  });
102
- // Calculate input fees and filter out vtxos where fee >= value
132
+ // Calculate input fees and filter out virtual outputs where fee >= value.
103
133
  const estimator = new arkfee_1.Estimator(feeInfo?.intentFee ?? {});
104
134
  const filteredVtxos = [];
105
135
  let totalAmount = 0n;
@@ -116,7 +146,7 @@ class Ramps {
116
146
  : undefined,
117
147
  });
118
148
  if (inputFee.satoshis >= vtxo.value) {
119
- // skip if fees are greater than or equal to the vtxo value
149
+ // Skip virtual outputs where spending fees are greater than or equal to the output value.
120
150
  continue;
121
151
  }
122
152
  filteredVtxos.push(vtxo);
@@ -55,7 +55,7 @@ class WalletMessageHandler {
55
55
  this.contractEventsSubscription = undefined;
56
56
  }
57
57
  // Dispose the wallet to stop VtxoManager background tasks
58
- // (auto-renewal, boarding UTXO polling) and ContractWatcher.
58
+ // (auto-renewal, boarding input polling) and ContractWatcher.
59
59
  try {
60
60
  if (this.wallet) {
61
61
  await this.wallet.dispose();
@@ -490,7 +490,7 @@ class WalletMessageHandler {
490
490
  }
491
491
  const totalBoarding = confirmed + unconfirmed;
492
492
  const totalOffchain = settled + preconfirmed + recoverable;
493
- // aggregate asset balances from spendable vtxos
493
+ // aggregate asset balances from spendable virtual outputs
494
494
  const assetBalances = new Map();
495
495
  for (const vtxo of spendableVtxos) {
496
496
  if (vtxo.assets) {
@@ -535,9 +535,9 @@ class WalletMessageHandler {
535
535
  return;
536
536
  }
537
537
  // Initialize contract manager FIRST — this populates the repository
538
- // with full VTXO history for all contracts (one indexer call per contract)
538
+ // with full virtual output history for all contracts (one indexer call per contract)
539
539
  await this.ensureContractEventBroadcasting();
540
- // Refresh cached data (VTXOs, boarding UTXOs, tx history)
540
+ // Refresh cached data (virtual outputs, boarding inputs, tx history)
541
541
  await this.refreshCachedData();
542
542
  // Recover pending transactions (init-only, not on reload).
543
543
  // Pending txs only exist if a send was interrupted mid-finalization.
@@ -568,12 +568,12 @@ class WalletMessageHandler {
568
568
  : [];
569
569
  if ([...newVtxos, ...spentVtxos].length === 0)
570
570
  return;
571
- // save vtxos using unified repository
571
+ // save virtual outputs using unified repository
572
572
  await this.walletRepository?.saveVtxos(address, [
573
573
  ...newVtxos,
574
574
  ...spentVtxos,
575
575
  ]);
576
- // notify all clients about the vtxo update
576
+ // notify all clients about the virtual output state update
577
577
  this.scheduleForNextTick(() => this.tagged({
578
578
  type: "VTXO_UPDATE",
579
579
  broadcast: true,
@@ -583,11 +583,11 @@ class WalletMessageHandler {
583
583
  if (funds.type === "utxo") {
584
584
  const utxos = funds.coins.map((utxo) => (0, utils_1.extendCoin)(this.readonlyWallet, utxo));
585
585
  const boardingAddress = await this.readonlyWallet.getBoardingAddress();
586
- // save utxos using unified repository
587
- // TODO: remove UTXOS by address
586
+ // save boarding inputs using unified repository
587
+ // TODO: remove UTXOs by address
588
588
  // await this.walletRepository.clearUtxos(boardingAddress);
589
589
  await this.walletRepository?.saveUtxos(boardingAddress, utxos);
590
- // notify all clients about the utxo update
590
+ // notify all clients about the boarding input state update
591
591
  this.scheduleForNextTick(() => this.tagged({
592
592
  type: "UTXO_UPDATE",
593
593
  broadcast: true,
@@ -596,8 +596,8 @@ class WalletMessageHandler {
596
596
  }
597
597
  });
598
598
  // Eagerly start the VtxoManager so its background tasks (auto-renewal,
599
- // boarding UTXO polling/sweep) run inside the service worker without
600
- // waiting for a client to send a vtxo-manager message first.
599
+ // boarding input polling/sweep) run inside the service worker without
600
+ // waiting for a client to send a VtxoManager message first.
601
601
  if (this.wallet) {
602
602
  try {
603
603
  await this.wallet.getVtxoManager();
@@ -608,7 +608,7 @@ class WalletMessageHandler {
608
608
  }
609
609
  }
610
610
  /**
611
- * Refresh VTXOs, boarding UTXOs, and transaction history from cache.
611
+ * Refresh virtual outputs, boarding inputs, and transaction history from cache.
612
612
  * Shared by onWalletInitialized (full bootstrap) and reloadWallet
613
613
  * (post-refresh), avoiding duplicate subscriptions and VtxoManager restarts.
614
614
  */
@@ -616,14 +616,14 @@ class WalletMessageHandler {
616
616
  if (!this.readonlyWallet || !this.walletRepository) {
617
617
  return;
618
618
  }
619
- // Read VTXOs from repository (now populated by contract manager)
619
+ // Read virtual outputs from repository (now populated by contract manager)
620
620
  const vtxos = await this.getVtxosFromRepo();
621
- // Fetch boarding utxos and save using unified repository
621
+ // Fetch boarding inputs and save using unified repository
622
622
  const boardingAddress = await this.readonlyWallet.getBoardingAddress();
623
623
  const coins = await this.readonlyWallet.onchainProvider.getCoins(boardingAddress);
624
624
  await this.walletRepository.deleteUtxos(boardingAddress);
625
625
  await this.walletRepository.saveUtxos(boardingAddress, coins.map((utxo) => (0, utils_1.extendCoin)(this.readonlyWallet, utxo)));
626
- // Build transaction history from cached VTXOs (no indexer call)
626
+ // Build transaction history from cached virtual outputs (no indexer call)
627
627
  const address = await this.readonlyWallet.getAddress();
628
628
  const txs = await this.buildTransactionHistoryFromCache(vtxos);
629
629
  if (txs)
@@ -765,7 +765,7 @@ class WalletMessageHandler {
765
765
  this.indexerProvider = undefined;
766
766
  }
767
767
  /**
768
- * Read all VTXOs from the repository, aggregated across all contract
768
+ * Read all virtual outputs from the repository, aggregated across all contract
769
769
  * addresses and the wallet's primary address, with deduplication.
770
770
  */
771
771
  async getVtxosFromRepo() {
@@ -782,7 +782,7 @@ class WalletMessageHandler {
782
782
  }
783
783
  }
784
784
  };
785
- // Aggregate VTXOs from all contract addresses
785
+ // Aggregate virtual outputs from all contract addresses
786
786
  const manager = await this.readonlyWallet.getContractManager();
787
787
  const contracts = await manager.getContracts();
788
788
  for (const contract of contracts) {
@@ -796,15 +796,15 @@ class WalletMessageHandler {
796
796
  return allVtxos;
797
797
  }
798
798
  /**
799
- * Build transaction history from cached VTXOs without hitting the indexer.
799
+ * Build transaction history from cached virtual outputs without hitting the indexer.
800
800
  * Falls back to indexer only for uncached transaction timestamps.
801
801
  */
802
802
  async buildTransactionHistoryFromCache(vtxos) {
803
803
  if (!this.readonlyWallet)
804
804
  return null;
805
805
  const { boardingTxs, commitmentsToIgnore } = await this.readonlyWallet.getBoardingTxs();
806
- // Build a lookup for cached VTXO timestamps, keyed by txid.
807
- // Multiple VTXOs can share a txid (different vouts) — we keep the
806
+ // Build a lookup for cached virtual output timestamps, keyed by txid.
807
+ // Multiple virtual outputs can share a txid (different vouts) — we keep the
808
808
  // earliest createdAt so the history ordering is stable.
809
809
  const vtxoCreatedAt = new Map();
810
810
  for (const vtxo of vtxos) {
@@ -815,8 +815,8 @@ class WalletMessageHandler {
815
815
  }
816
816
  }
817
817
  // Pre-fetch uncached timestamps in a single batched indexer call.
818
- // buildTransactionHistory needs these for spent-offchain VTXOs with
819
- // no change outputs (i.e. arkTxId is set but no VTXO has txid === arkTxId).
818
+ // buildTransactionHistory needs these for spent-offchain virtual outputs with
819
+ // no change outputs (i.e. arkTxId is set but no virtual output has txid === arkTxId).
820
820
  if (this.indexerProvider) {
821
821
  const uncachedTxids = new Set();
822
822
  for (const vtxo of vtxos) {
@@ -182,6 +182,13 @@ class ServiceWorkerReadonlyWallet {
182
182
  getTimeoutForRequest(request) {
183
183
  return this.messageTimeouts[request.type] ?? 30000;
184
184
  }
185
+ /**
186
+ * Create a readonly service-worker wallet bound to an already-registered worker.
187
+ *
188
+ * @param options - Service worker, identity, and backend configuration
189
+ * @returns Initialized readonly service-worker wallet
190
+ * @throws Error if service-worker initialization fails
191
+ */
185
192
  static async create(options) {
186
193
  const walletRepository = options.storage?.walletRepository ??
187
194
  new repositories_1.IndexedDBWalletRepository();
@@ -242,23 +249,17 @@ class ServiceWorkerReadonlyWallet {
242
249
  return wallet;
243
250
  }
244
251
  /**
245
- * Simplified setup method that handles service worker registration,
246
- * identity creation, and wallet initialization automatically.
252
+ * Simplified setup method that handles service worker registration
253
+ * and wallet initialization automatically.
254
+ *
255
+ * @see ServiceWorkerReadonlyWallet.create
247
256
  *
248
257
  * @example
249
258
  * ```typescript
250
- * // One-liner setup - handles everything automatically!
251
259
  * const wallet = await ServiceWorkerReadonlyWallet.setup({
252
260
  * serviceWorkerPath: '/service-worker.js',
253
- * arkServerUrl: 'https://mutinynet.arkade.sh'
254
- * });
255
- *
256
- * // With custom readonly identity
257
- * const identity = ReadonlySingleKey.fromPublicKey('your_public_key_hex');
258
- * const wallet = await ServiceWorkerReadonlyWallet.setup({
259
- * serviceWorkerPath: '/service-worker.js',
260
- * arkServerUrl: 'https://mutinynet.arkade.sh',
261
- * identity
261
+ * arkServerUrl: 'https://arkade.computer',
262
+ * identity: ReadonlySingleKey.fromPublicKey('your_public_key_hex')
262
263
  * });
263
264
  * ```
264
265
  */
@@ -460,6 +461,7 @@ class ServiceWorkerReadonlyWallet {
460
461
  });
461
462
  return this.reinitPromise;
462
463
  }
464
+ /** Clear cached wallet state from both the page and service worker storage. */
463
465
  async clear() {
464
466
  const message = {
465
467
  id: (0, utils_2.getRandomId)(),
@@ -532,6 +534,11 @@ class ServiceWorkerReadonlyWallet {
532
534
  throw new Error(`Failed to get boarding UTXOs: ${error}`);
533
535
  }
534
536
  }
537
+ /**
538
+ * Return service-worker wallet status, including connectivity and sync state.
539
+ *
540
+ * @returns Current service-worker wallet status payload including `walletInitalized` and `xOnlyPublicKey`
541
+ */
535
542
  async getStatus() {
536
543
  const message = {
537
544
  id: (0, utils_2.getRandomId)(),
@@ -576,6 +583,11 @@ class ServiceWorkerReadonlyWallet {
576
583
  throw new Error(`Failed to get vtxos: ${error}`);
577
584
  }
578
585
  }
586
+ /**
587
+ * Trigger a wallet reload inside the service worker.
588
+ *
589
+ * @returns `true` when the wallet was reloaded
590
+ */
579
591
  async reload() {
580
592
  const message = {
581
593
  id: (0, utils_2.getRandomId)(),
@@ -855,23 +867,15 @@ class ServiceWorkerWallet extends ServiceWorkerReadonlyWallet {
855
867
  return wallet;
856
868
  }
857
869
  /**
858
- * Simplified setup method that handles service worker registration,
859
- * identity creation, and wallet initialization automatically.
870
+ * Simplified setup method that handles service worker registration
871
+ * and wallet initialization automatically.
860
872
  *
861
873
  * @example
862
874
  * ```typescript
863
- * // One-liner setup - handles everything automatically!
864
- * const wallet = await ServiceWorkerWallet.setup({
865
- * serviceWorkerPath: '/service-worker.js',
866
- * arkServerUrl: 'https://mutinynet.arkade.sh'
867
- * });
868
- *
869
- * // With custom identity
870
- * const identity = SingleKey.fromHex('your_private_key_hex');
871
875
  * const wallet = await ServiceWorkerWallet.setup({
872
876
  * serviceWorkerPath: '/service-worker.js',
873
- * arkServerUrl: 'https://mutinynet.arkade.sh',
874
- * identity
877
+ * arkServerUrl: 'https://arkade.computer',
878
+ * identity: MnemonicIdentity.fromMnemonic('abandon abandon...')
875
879
  * });
876
880
  * ```
877
881
  */
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Unroll = void 0;
4
4
  const base_1 = require("@scure/base");
5
5
  const btc_signer_1 = require("@scure/btc-signer");
6
+ const helpers_1 = require("../contracts/handlers/helpers");
6
7
  const indexer_1 = require("../providers/indexer");
7
8
  const base_2 = require("../script/base");
8
9
  const txSizeEstimator_1 = require("../utils/txSizeEstimator");
@@ -18,7 +19,7 @@ var Unroll;
18
19
  StepType[StepType["DONE"] = 2] = "DONE";
19
20
  })(StepType = Unroll.StepType || (Unroll.StepType = {}));
20
21
  /**
21
- * Manages the unrolling process of a VTXO back to the Bitcoin blockchain.
22
+ * Manages the unrolling process of a virtual output back to the Bitcoin blockchain.
22
23
  *
23
24
  * The Session class implements an async iterator that processes the unrolling steps:
24
25
  * 1. **WAIT**: Waits for a transaction to be confirmed onchain (if it's in mempool)
@@ -42,19 +43,21 @@ var Unroll;
42
43
  * console.log(`Broadcasting transaction ${doneStep.tx.id}`);
43
44
  * break;
44
45
  * case Unroll.StepType.DONE:
45
- * console.log(`Unrolling complete for VTXO ${doneStep.vtxoTxid}`);
46
+ * console.log(`Unrolling complete for virtual output ${doneStep.vtxoTxid}`);
46
47
  * break;
47
48
  * }
48
49
  * }
49
50
  * ```
50
51
  **/
51
52
  class Session {
53
+ /** Create an unroll session from a virtual output outpoint and its dependency chain. */
52
54
  constructor(toUnroll, bumper, explorer, indexer) {
53
55
  this.toUnroll = toUnroll;
54
56
  this.bumper = bumper;
55
57
  this.explorer = explorer;
56
58
  this.indexer = indexer;
57
59
  }
60
+ /** Create an unroll session by loading the virtual output chain from the indexer. */
58
61
  static async create(toUnroll, bumper, explorer, indexer) {
59
62
  const { chain } = await indexer.getVtxoChain(toUnroll);
60
63
  return new Session({ ...toUnroll, chain }, bumper, explorer, indexer);
@@ -123,7 +126,7 @@ var Unroll;
123
126
  });
124
127
  }
125
128
  else {
126
- // finalize ark transaction
129
+ // finalize Arkade transaction
127
130
  tx.finalize();
128
131
  }
129
132
  return {
@@ -153,11 +156,11 @@ var Unroll;
153
156
  }
154
157
  Unroll.Session = Session;
155
158
  /**
156
- * Complete the unroll of a VTXO by broadcasting the transaction that spends the CSV path.
157
- * @param wallet the wallet owning the VTXO(s)
158
- * @param vtxoTxids the txids of the VTXO(s) to complete unroll
159
+ * Complete the unroll of a virtual output by broadcasting the transaction that spends the CSV path.
160
+ * @param wallet the wallet owning the virtual output(s)
161
+ * @param vtxoTxids the txids of the virtual output(s) to complete unroll
159
162
  * @param outputAddress the address to send the unrolled funds to
160
- * @throws if the VTXO(s) are not fully unrolled, if the txids are not found, if the tx is not confirmed, if no exit path is found or not available
163
+ * @throws if the virtual output(s) are not fully unrolled, if the txids are not found, if the tx is not confirmed, if no exit path is found or not available
161
164
  * @returns the txid of the transaction spending the unrolled funds
162
165
  */
163
166
  async function completeUnroll(wallet, vtxoTxids, outputAddress) {
@@ -187,11 +190,12 @@ var Unroll;
187
190
  throw new Error(`spending leaf not found for vtxo ${vtxo.txid}:${vtxo.vout}`);
188
191
  }
189
192
  totalAmount += BigInt(vtxo.value);
193
+ const sequence = (0, helpers_1.timelockToSequence)(exit.params.timelock);
190
194
  inputs.push({
191
195
  txid: vtxo.txid,
192
196
  index: vtxo.vout,
193
197
  tapLeafScript: [spendingLeaf],
194
- sequence: 0xffffffff - 1,
198
+ sequence,
195
199
  witnessUtxo: {
196
200
  amount: BigInt(vtxo.value),
197
201
  script: base_2.VtxoScript.decode(vtxo.tapTree).pkScript,
@@ -61,7 +61,7 @@ function validateRecipients(recipients, dustAmount) {
61
61
  address = __1.ArkAddress.decode(recipient.address);
62
62
  }
63
63
  catch (e) {
64
- throw new Error(`Invalid Ark address: ${recipient.address}`);
64
+ throw new Error(`Invalid Arkade address: ${recipient.address}`);
65
65
  }
66
66
  const amount = recipient.amount || dustAmount;
67
67
  if (amount <= 0) {