@arkade-os/sdk 0.4.27 → 0.4.28

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 (531) hide show
  1. package/README.md +31 -100
  2. package/dist/adapters/asyncStorage.cjs +48 -0
  3. package/dist/adapters/asyncStorage.cjs.map +1 -0
  4. package/dist/adapters/asyncStorage.d.cts +16 -0
  5. package/dist/{types/storage → adapters}/asyncStorage.d.ts +5 -2
  6. package/dist/adapters/asyncStorage.js +46 -0
  7. package/dist/adapters/asyncStorage.js.map +1 -0
  8. package/dist/adapters/expo.cjs +19 -0
  9. package/dist/adapters/expo.cjs.map +1 -0
  10. package/dist/adapters/expo.d.cts +48 -0
  11. package/dist/adapters/expo.d.ts +48 -0
  12. package/dist/adapters/expo.js +6 -0
  13. package/dist/adapters/expo.js.map +1 -0
  14. package/dist/adapters/fileSystem.cjs +116 -0
  15. package/dist/adapters/fileSystem.cjs.map +1 -0
  16. package/dist/adapters/fileSystem.d.cts +17 -0
  17. package/dist/{types/storage → adapters}/fileSystem.d.ts +5 -2
  18. package/dist/adapters/fileSystem.js +93 -0
  19. package/dist/adapters/fileSystem.js.map +1 -0
  20. package/dist/adapters/indexedDB.cjs +103 -0
  21. package/dist/adapters/indexedDB.cjs.map +1 -0
  22. package/dist/adapters/indexedDB.d.cts +18 -0
  23. package/dist/{types/storage → adapters}/indexedDB.d.ts +5 -2
  24. package/dist/adapters/indexedDB.js +101 -0
  25. package/dist/adapters/indexedDB.js.map +1 -0
  26. package/dist/adapters/localStorage.cjs +50 -0
  27. package/dist/adapters/localStorage.cjs.map +1 -0
  28. package/dist/{types/storage/inMemory.d.ts → adapters/localStorage.d.cts} +6 -3
  29. package/dist/{types/storage → adapters}/localStorage.d.ts +5 -2
  30. package/dist/adapters/localStorage.js +48 -0
  31. package/dist/adapters/localStorage.js.map +1 -0
  32. package/dist/ark-TZ1gXAXU.d.cts +3880 -0
  33. package/dist/ark-TZ1gXAXU.d.ts +3880 -0
  34. package/dist/{types/worker/expo/asyncStorageTaskQueue.d.ts → asyncStorageTaskQueue-Cb1F_Z9s.d.ts} +6 -3
  35. package/dist/asyncStorageTaskQueue-EFqSmYTg.d.cts +49 -0
  36. package/dist/chunk-5BLDMQED.cjs +18 -0
  37. package/dist/chunk-5BLDMQED.cjs.map +1 -0
  38. package/dist/chunk-5PG7DV7A.cjs +805 -0
  39. package/dist/chunk-5PG7DV7A.cjs.map +1 -0
  40. package/dist/chunk-A3EMF7RN.js +95 -0
  41. package/dist/chunk-A3EMF7RN.js.map +1 -0
  42. package/dist/chunk-ADV27S4N.cjs +2701 -0
  43. package/dist/chunk-ADV27S4N.cjs.map +1 -0
  44. package/dist/chunk-BQLHADL7.js +13805 -0
  45. package/dist/chunk-BQLHADL7.js.map +1 -0
  46. package/dist/chunk-CFZMTDWI.js +209 -0
  47. package/dist/chunk-CFZMTDWI.js.map +1 -0
  48. package/dist/chunk-FG5ACJJW.cjs +212 -0
  49. package/dist/chunk-FG5ACJJW.cjs.map +1 -0
  50. package/dist/chunk-HW3JJ323.js +768 -0
  51. package/dist/chunk-HW3JJ323.js.map +1 -0
  52. package/dist/chunk-I3DGUUCT.cjs +838 -0
  53. package/dist/chunk-I3DGUUCT.cjs.map +1 -0
  54. package/dist/chunk-IPX2R7FR.cjs +100 -0
  55. package/dist/chunk-IPX2R7FR.cjs.map +1 -0
  56. package/dist/chunk-NSBPE2FW.js +15 -0
  57. package/dist/chunk-NSBPE2FW.js.map +1 -0
  58. package/dist/chunk-T64LAI7L.js +829 -0
  59. package/dist/chunk-T64LAI7L.js.map +1 -0
  60. package/dist/chunk-ZBUDLTBO.js +2671 -0
  61. package/dist/chunk-ZBUDLTBO.js.map +1 -0
  62. package/dist/chunk-ZLO6NETT.cjs +13910 -0
  63. package/dist/chunk-ZLO6NETT.cjs.map +1 -0
  64. package/dist/contracts/handlers/index.cjs +26 -0
  65. package/dist/contracts/handlers/index.cjs.map +1 -0
  66. package/dist/contracts/handlers/index.d.cts +7 -0
  67. package/dist/contracts/handlers/index.d.ts +7 -0
  68. package/dist/contracts/handlers/index.js +5 -0
  69. package/dist/contracts/handlers/index.js.map +1 -0
  70. package/dist/delegate-BFZs69hp.d.cts +84 -0
  71. package/dist/delegate-aaVGfWsV.d.ts +84 -0
  72. package/dist/index-B22cA64m.d.cts +199 -0
  73. package/dist/{types/storage/index.d.ts → index-C0IanN1m.d.cts} +3 -1
  74. package/dist/index-C0IanN1m.d.ts +11 -0
  75. package/dist/index-NDla_UoJ.d.ts +199 -0
  76. package/dist/index.cjs +480 -0
  77. package/dist/index.cjs.map +1 -0
  78. package/dist/index.d.cts +3343 -0
  79. package/dist/index.d.ts +3343 -0
  80. package/dist/index.js +7 -0
  81. package/dist/index.js.map +1 -0
  82. package/dist/repositories/realm/index.cjs +513 -0
  83. package/dist/repositories/realm/index.cjs.map +1 -0
  84. package/dist/repositories/realm/index.d.cts +217 -0
  85. package/dist/{types/repositories/realm/schemas.d.ts → repositories/realm/index.d.ts} +80 -112
  86. package/dist/repositories/realm/index.js +507 -0
  87. package/dist/repositories/realm/index.js.map +1 -0
  88. package/dist/repositories/sqlite/index.cjs +588 -0
  89. package/dist/repositories/sqlite/index.cjs.map +1 -0
  90. package/dist/repositories/sqlite/index.d.cts +118 -0
  91. package/dist/{types/repositories/sqlite/walletRepository.d.ts → repositories/sqlite/index.d.ts} +58 -5
  92. package/dist/repositories/sqlite/index.js +585 -0
  93. package/dist/repositories/sqlite/index.js.map +1 -0
  94. package/dist/taskRunner-C6Ff4OaU.d.cts +114 -0
  95. package/dist/taskRunner-yvPN8Z0K.d.ts +114 -0
  96. package/dist/wallet/expo/background.cjs +93 -0
  97. package/dist/wallet/expo/background.cjs.map +1 -0
  98. package/dist/wallet/expo/background.d.cts +84 -0
  99. package/dist/wallet/expo/background.d.ts +84 -0
  100. package/dist/wallet/expo/background.js +68 -0
  101. package/dist/wallet/expo/background.js.map +1 -0
  102. package/dist/wallet/expo/index.cjs +171 -0
  103. package/dist/wallet/expo/index.cjs.map +1 -0
  104. package/dist/wallet/expo/index.d.cts +122 -0
  105. package/dist/{types/wallet/expo/wallet.d.ts → wallet/expo/index.d.ts} +45 -22
  106. package/dist/wallet/expo/index.js +169 -0
  107. package/dist/wallet/expo/index.js.map +1 -0
  108. package/dist/wallet-AF-p-OWj.d.cts +774 -0
  109. package/dist/wallet-D9NBRqvC.d.ts +774 -0
  110. package/dist/worker/expo/index.cjs +140 -0
  111. package/dist/worker/expo/index.cjs.map +1 -0
  112. package/dist/worker/expo/index.d.cts +29 -0
  113. package/dist/worker/expo/index.d.ts +29 -0
  114. package/dist/worker/expo/index.js +121 -0
  115. package/dist/worker/expo/index.js.map +1 -0
  116. package/package.json +110 -76
  117. package/dist/cjs/adapters/asyncStorage.js +0 -5
  118. package/dist/cjs/adapters/expo.js +0 -8
  119. package/dist/cjs/adapters/fileSystem.js +0 -5
  120. package/dist/cjs/adapters/indexedDB.js +0 -5
  121. package/dist/cjs/adapters/localStorage.js +0 -5
  122. package/dist/cjs/arkfee/celenv.js +0 -43
  123. package/dist/cjs/arkfee/estimator.js +0 -143
  124. package/dist/cjs/arkfee/index.js +0 -5
  125. package/dist/cjs/arkfee/types.js +0 -26
  126. package/dist/cjs/arknote/index.js +0 -128
  127. package/dist/cjs/bip322/index.js +0 -270
  128. package/dist/cjs/contracts/arkcontract.js +0 -147
  129. package/dist/cjs/contracts/contractManager.js +0 -649
  130. package/dist/cjs/contracts/contractWatcher.js +0 -598
  131. package/dist/cjs/contracts/handlers/default.js +0 -93
  132. package/dist/cjs/contracts/handlers/delegate.js +0 -90
  133. package/dist/cjs/contracts/handlers/helpers.js +0 -115
  134. package/dist/cjs/contracts/handlers/index.js +0 -19
  135. package/dist/cjs/contracts/handlers/registry.js +0 -89
  136. package/dist/cjs/contracts/handlers/vhtlc.js +0 -194
  137. package/dist/cjs/contracts/index.js +0 -41
  138. package/dist/cjs/contracts/types.js +0 -2
  139. package/dist/cjs/contracts/vtxoOwnership.js +0 -78
  140. package/dist/cjs/extension/asset/assetGroup.js +0 -228
  141. package/dist/cjs/extension/asset/assetId.js +0 -152
  142. package/dist/cjs/extension/asset/assetInput.js +0 -222
  143. package/dist/cjs/extension/asset/assetOutput.js +0 -174
  144. package/dist/cjs/extension/asset/assetRef.js +0 -148
  145. package/dist/cjs/extension/asset/index.js +0 -23
  146. package/dist/cjs/extension/asset/metadata.js +0 -187
  147. package/dist/cjs/extension/asset/packet.js +0 -114
  148. package/dist/cjs/extension/asset/types.js +0 -22
  149. package/dist/cjs/extension/asset/utils.js +0 -105
  150. package/dist/cjs/extension/index.js +0 -254
  151. package/dist/cjs/extension/packet.js +0 -20
  152. package/dist/cjs/forfeit.js +0 -45
  153. package/dist/cjs/identity/descriptor.js +0 -169
  154. package/dist/cjs/identity/descriptorProvider.js +0 -2
  155. package/dist/cjs/identity/hdCapableIdentity.js +0 -20
  156. package/dist/cjs/identity/index.js +0 -40
  157. package/dist/cjs/identity/seedIdentity.js +0 -477
  158. package/dist/cjs/identity/serialize.js +0 -171
  159. package/dist/cjs/identity/singleKey.js +0 -126
  160. package/dist/cjs/identity/staticDescriptorProvider.js +0 -65
  161. package/dist/cjs/index.js +0 -202
  162. package/dist/cjs/intent/index.js +0 -259
  163. package/dist/cjs/musig2/index.js +0 -11
  164. package/dist/cjs/musig2/keys.js +0 -57
  165. package/dist/cjs/musig2/nonces.js +0 -48
  166. package/dist/cjs/musig2/sign.js +0 -102
  167. package/dist/cjs/networks.js +0 -26
  168. package/dist/cjs/package.json +0 -3
  169. package/dist/cjs/providers/ark.js +0 -577
  170. package/dist/cjs/providers/delegator.js +0 -85
  171. package/dist/cjs/providers/electrum.js +0 -869
  172. package/dist/cjs/providers/errors.js +0 -59
  173. package/dist/cjs/providers/expoArk.js +0 -82
  174. package/dist/cjs/providers/expoIndexer.js +0 -111
  175. package/dist/cjs/providers/expoUtils.js +0 -124
  176. package/dist/cjs/providers/indexer.js +0 -630
  177. package/dist/cjs/providers/onchain.js +0 -262
  178. package/dist/cjs/providers/utils.js +0 -121
  179. package/dist/cjs/repositories/contractRepository.js +0 -2
  180. package/dist/cjs/repositories/inMemory/contractRepository.js +0 -55
  181. package/dist/cjs/repositories/inMemory/walletRepository.js +0 -115
  182. package/dist/cjs/repositories/index.js +0 -34
  183. package/dist/cjs/repositories/indexedDB/contractRepository.js +0 -187
  184. package/dist/cjs/repositories/indexedDB/db.js +0 -19
  185. package/dist/cjs/repositories/indexedDB/manager.js +0 -100
  186. package/dist/cjs/repositories/indexedDB/schema.js +0 -204
  187. package/dist/cjs/repositories/indexedDB/walletRepository.js +0 -474
  188. package/dist/cjs/repositories/indexedDB/websqlAdapter.js +0 -144
  189. package/dist/cjs/repositories/migrations/contractRepositoryImpl.js +0 -127
  190. package/dist/cjs/repositories/migrations/fromStorageAdapter.js +0 -66
  191. package/dist/cjs/repositories/migrations/walletRepositoryImpl.js +0 -184
  192. package/dist/cjs/repositories/realm/contractRepository.js +0 -116
  193. package/dist/cjs/repositories/realm/index.js +0 -11
  194. package/dist/cjs/repositories/realm/schemas.js +0 -157
  195. package/dist/cjs/repositories/realm/types.js +0 -7
  196. package/dist/cjs/repositories/realm/walletRepository.js +0 -305
  197. package/dist/cjs/repositories/scriptFromAddress.js +0 -16
  198. package/dist/cjs/repositories/serialization.js +0 -82
  199. package/dist/cjs/repositories/sqlite/contractRepository.js +0 -135
  200. package/dist/cjs/repositories/sqlite/index.js +0 -7
  201. package/dist/cjs/repositories/sqlite/types.js +0 -2
  202. package/dist/cjs/repositories/sqlite/walletRepository.js +0 -441
  203. package/dist/cjs/repositories/walletRepository.js +0 -2
  204. package/dist/cjs/script/address.js +0 -108
  205. package/dist/cjs/script/base.js +0 -185
  206. package/dist/cjs/script/default.js +0 -57
  207. package/dist/cjs/script/delegate.js +0 -53
  208. package/dist/cjs/script/tapscript.js +0 -619
  209. package/dist/cjs/script/vhtlc.js +0 -170
  210. package/dist/cjs/storage/asyncStorage.js +0 -50
  211. package/dist/cjs/storage/fileSystem.js +0 -141
  212. package/dist/cjs/storage/inMemory.js +0 -24
  213. package/dist/cjs/storage/index.js +0 -2
  214. package/dist/cjs/storage/indexedDB.js +0 -101
  215. package/dist/cjs/storage/localStorage.js +0 -51
  216. package/dist/cjs/tree/signingSession.js +0 -229
  217. package/dist/cjs/tree/txTree.js +0 -192
  218. package/dist/cjs/tree/validation.js +0 -107
  219. package/dist/cjs/utils/anchor.js +0 -35
  220. package/dist/cjs/utils/arkTransaction.js +0 -271
  221. package/dist/cjs/utils/bip21.js +0 -127
  222. package/dist/cjs/utils/syncCursors.js +0 -128
  223. package/dist/cjs/utils/timelock.js +0 -59
  224. package/dist/cjs/utils/transaction.js +0 -28
  225. package/dist/cjs/utils/transactionHistory.js +0 -183
  226. package/dist/cjs/utils/txSizeEstimator.js +0 -132
  227. package/dist/cjs/utils/unknownFields.js +0 -174
  228. package/dist/cjs/wallet/asset-manager.js +0 -330
  229. package/dist/cjs/wallet/asset.js +0 -119
  230. package/dist/cjs/wallet/batch.js +0 -183
  231. package/dist/cjs/wallet/delegator.js +0 -308
  232. package/dist/cjs/wallet/expo/background.js +0 -116
  233. package/dist/cjs/wallet/expo/index.js +0 -9
  234. package/dist/cjs/wallet/expo/wallet.js +0 -230
  235. package/dist/cjs/wallet/hdDescriptorProvider.js +0 -188
  236. package/dist/cjs/wallet/index.js +0 -82
  237. package/dist/cjs/wallet/inputSignerRouter.js +0 -98
  238. package/dist/cjs/wallet/onchain.js +0 -290
  239. package/dist/cjs/wallet/ramps.js +0 -216
  240. package/dist/cjs/wallet/serviceWorker/wallet-message-handler.js +0 -953
  241. package/dist/cjs/wallet/serviceWorker/wallet.js +0 -1174
  242. package/dist/cjs/wallet/signingErrors.js +0 -32
  243. package/dist/cjs/wallet/unroll.js +0 -293
  244. package/dist/cjs/wallet/utils.js +0 -111
  245. package/dist/cjs/wallet/validation.js +0 -154
  246. package/dist/cjs/wallet/vtxo-manager.js +0 -1142
  247. package/dist/cjs/wallet/wallet.js +0 -2195
  248. package/dist/cjs/wallet/walletReceiveRotator.js +0 -547
  249. package/dist/cjs/worker/browser/service-worker-manager.js +0 -183
  250. package/dist/cjs/worker/browser/utils.js +0 -67
  251. package/dist/cjs/worker/errors.js +0 -16
  252. package/dist/cjs/worker/expo/asyncStorageTaskQueue.js +0 -78
  253. package/dist/cjs/worker/expo/index.js +0 -13
  254. package/dist/cjs/worker/expo/processors/contractPollProcessor.js +0 -62
  255. package/dist/cjs/worker/expo/processors/index.js +0 -6
  256. package/dist/cjs/worker/expo/taskQueue.js +0 -41
  257. package/dist/cjs/worker/expo/taskRunner.js +0 -73
  258. package/dist/cjs/worker/messageBus.js +0 -474
  259. package/dist/esm/adapters/asyncStorage.js +0 -1
  260. package/dist/esm/adapters/expo.js +0 -3
  261. package/dist/esm/adapters/fileSystem.js +0 -1
  262. package/dist/esm/adapters/indexedDB.js +0 -1
  263. package/dist/esm/adapters/localStorage.js +0 -1
  264. package/dist/esm/arkfee/celenv.js +0 -40
  265. package/dist/esm/arkfee/estimator.js +0 -139
  266. package/dist/esm/arkfee/index.js +0 -1
  267. package/dist/esm/arkfee/types.js +0 -22
  268. package/dist/esm/arknote/index.js +0 -124
  269. package/dist/esm/bip322/index.js +0 -267
  270. package/dist/esm/contracts/arkcontract.js +0 -140
  271. package/dist/esm/contracts/contractManager.js +0 -645
  272. package/dist/esm/contracts/contractWatcher.js +0 -594
  273. package/dist/esm/contracts/handlers/default.js +0 -90
  274. package/dist/esm/contracts/handlers/delegate.js +0 -87
  275. package/dist/esm/contracts/handlers/helpers.js +0 -110
  276. package/dist/esm/contracts/handlers/index.js +0 -12
  277. package/dist/esm/contracts/handlers/registry.js +0 -86
  278. package/dist/esm/contracts/handlers/vhtlc.js +0 -191
  279. package/dist/esm/contracts/index.js +0 -13
  280. package/dist/esm/contracts/types.js +0 -1
  281. package/dist/esm/contracts/vtxoOwnership.js +0 -69
  282. package/dist/esm/extension/asset/assetGroup.js +0 -224
  283. package/dist/esm/extension/asset/assetId.js +0 -148
  284. package/dist/esm/extension/asset/assetInput.js +0 -217
  285. package/dist/esm/extension/asset/assetOutput.js +0 -169
  286. package/dist/esm/extension/asset/assetRef.js +0 -144
  287. package/dist/esm/extension/asset/index.js +0 -8
  288. package/dist/esm/extension/asset/metadata.js +0 -182
  289. package/dist/esm/extension/asset/packet.js +0 -110
  290. package/dist/esm/extension/asset/types.js +0 -19
  291. package/dist/esm/extension/asset/utils.js +0 -99
  292. package/dist/esm/extension/index.js +0 -248
  293. package/dist/esm/extension/packet.js +0 -16
  294. package/dist/esm/forfeit.js +0 -41
  295. package/dist/esm/identity/descriptor.js +0 -161
  296. package/dist/esm/identity/descriptorProvider.js +0 -1
  297. package/dist/esm/identity/hdCapableIdentity.js +0 -17
  298. package/dist/esm/identity/index.js +0 -13
  299. package/dist/esm/identity/seedIdentity.js +0 -469
  300. package/dist/esm/identity/serialize.js +0 -164
  301. package/dist/esm/identity/singleKey.js +0 -121
  302. package/dist/esm/identity/staticDescriptorProvider.js +0 -61
  303. package/dist/esm/index.js +0 -87
  304. package/dist/esm/intent/index.js +0 -255
  305. package/dist/esm/musig2/index.js +0 -3
  306. package/dist/esm/musig2/keys.js +0 -21
  307. package/dist/esm/musig2/nonces.js +0 -11
  308. package/dist/esm/musig2/sign.js +0 -63
  309. package/dist/esm/networks.js +0 -22
  310. package/dist/esm/package.json +0 -3
  311. package/dist/esm/providers/ark.js +0 -572
  312. package/dist/esm/providers/delegator.js +0 -81
  313. package/dist/esm/providers/electrum.js +0 -864
  314. package/dist/esm/providers/errors.js +0 -54
  315. package/dist/esm/providers/expoArk.js +0 -78
  316. package/dist/esm/providers/expoIndexer.js +0 -107
  317. package/dist/esm/providers/expoUtils.js +0 -87
  318. package/dist/esm/providers/indexer.js +0 -626
  319. package/dist/esm/providers/onchain.js +0 -258
  320. package/dist/esm/providers/utils.js +0 -117
  321. package/dist/esm/repositories/contractRepository.js +0 -1
  322. package/dist/esm/repositories/inMemory/contractRepository.js +0 -51
  323. package/dist/esm/repositories/inMemory/walletRepository.js +0 -111
  324. package/dist/esm/repositories/index.js +0 -10
  325. package/dist/esm/repositories/indexedDB/contractRepository.js +0 -183
  326. package/dist/esm/repositories/indexedDB/db.js +0 -4
  327. package/dist/esm/repositories/indexedDB/manager.js +0 -95
  328. package/dist/esm/repositories/indexedDB/schema.js +0 -199
  329. package/dist/esm/repositories/indexedDB/walletRepository.js +0 -470
  330. package/dist/esm/repositories/indexedDB/websqlAdapter.js +0 -138
  331. package/dist/esm/repositories/migrations/contractRepositoryImpl.js +0 -121
  332. package/dist/esm/repositories/migrations/fromStorageAdapter.js +0 -58
  333. package/dist/esm/repositories/migrations/walletRepositoryImpl.js +0 -180
  334. package/dist/esm/repositories/realm/contractRepository.js +0 -112
  335. package/dist/esm/repositories/realm/index.js +0 -3
  336. package/dist/esm/repositories/realm/schemas.js +0 -153
  337. package/dist/esm/repositories/realm/types.js +0 -6
  338. package/dist/esm/repositories/realm/walletRepository.js +0 -301
  339. package/dist/esm/repositories/scriptFromAddress.js +0 -13
  340. package/dist/esm/repositories/serialization.js +0 -67
  341. package/dist/esm/repositories/sqlite/contractRepository.js +0 -131
  342. package/dist/esm/repositories/sqlite/index.js +0 -2
  343. package/dist/esm/repositories/sqlite/types.js +0 -1
  344. package/dist/esm/repositories/sqlite/walletRepository.js +0 -437
  345. package/dist/esm/repositories/walletRepository.js +0 -1
  346. package/dist/esm/script/address.js +0 -104
  347. package/dist/esm/script/base.js +0 -179
  348. package/dist/esm/script/default.js +0 -54
  349. package/dist/esm/script/delegate.js +0 -50
  350. package/dist/esm/script/tapscript.js +0 -615
  351. package/dist/esm/script/vhtlc.js +0 -167
  352. package/dist/esm/storage/asyncStorage.js +0 -46
  353. package/dist/esm/storage/fileSystem.js +0 -104
  354. package/dist/esm/storage/inMemory.js +0 -20
  355. package/dist/esm/storage/index.js +0 -1
  356. package/dist/esm/storage/indexedDB.js +0 -97
  357. package/dist/esm/storage/localStorage.js +0 -47
  358. package/dist/esm/tree/signingSession.js +0 -191
  359. package/dist/esm/tree/txTree.js +0 -188
  360. package/dist/esm/tree/validation.js +0 -101
  361. package/dist/esm/utils/anchor.js +0 -31
  362. package/dist/esm/utils/arkTransaction.js +0 -264
  363. package/dist/esm/utils/bip21.js +0 -123
  364. package/dist/esm/utils/syncCursors.js +0 -119
  365. package/dist/esm/utils/timelock.js +0 -22
  366. package/dist/esm/utils/transaction.js +0 -24
  367. package/dist/esm/utils/transactionHistory.js +0 -180
  368. package/dist/esm/utils/txSizeEstimator.js +0 -128
  369. package/dist/esm/utils/unknownFields.js +0 -169
  370. package/dist/esm/wallet/asset-manager.js +0 -325
  371. package/dist/esm/wallet/asset.js +0 -113
  372. package/dist/esm/wallet/batch.js +0 -180
  373. package/dist/esm/wallet/delegator.js +0 -303
  374. package/dist/esm/wallet/expo/background.js +0 -111
  375. package/dist/esm/wallet/expo/index.js +0 -2
  376. package/dist/esm/wallet/expo/wallet.js +0 -193
  377. package/dist/esm/wallet/hdDescriptorProvider.js +0 -184
  378. package/dist/esm/wallet/index.js +0 -75
  379. package/dist/esm/wallet/inputSignerRouter.js +0 -94
  380. package/dist/esm/wallet/onchain.js +0 -285
  381. package/dist/esm/wallet/ramps.js +0 -212
  382. package/dist/esm/wallet/serviceWorker/wallet-message-handler.js +0 -946
  383. package/dist/esm/wallet/serviceWorker/wallet.js +0 -1169
  384. package/dist/esm/wallet/signingErrors.js +0 -27
  385. package/dist/esm/wallet/unroll.js +0 -289
  386. package/dist/esm/wallet/utils.js +0 -103
  387. package/dist/esm/wallet/validation.js +0 -142
  388. package/dist/esm/wallet/vtxo-manager.js +0 -1136
  389. package/dist/esm/wallet/wallet.js +0 -2186
  390. package/dist/esm/wallet/walletReceiveRotator.js +0 -540
  391. package/dist/esm/worker/browser/service-worker-manager.js +0 -177
  392. package/dist/esm/worker/browser/utils.js +0 -63
  393. package/dist/esm/worker/errors.js +0 -11
  394. package/dist/esm/worker/expo/asyncStorageTaskQueue.js +0 -74
  395. package/dist/esm/worker/expo/index.js +0 -4
  396. package/dist/esm/worker/expo/processors/contractPollProcessor.js +0 -59
  397. package/dist/esm/worker/expo/processors/index.js +0 -1
  398. package/dist/esm/worker/expo/taskQueue.js +0 -37
  399. package/dist/esm/worker/expo/taskRunner.js +0 -69
  400. package/dist/esm/worker/messageBus.js +0 -470
  401. package/dist/types/adapters/asyncStorage.d.ts +0 -2
  402. package/dist/types/adapters/expo.d.ts +0 -4
  403. package/dist/types/adapters/fileSystem.d.ts +0 -2
  404. package/dist/types/adapters/indexedDB.d.ts +0 -2
  405. package/dist/types/adapters/localStorage.d.ts +0 -2
  406. package/dist/types/arkfee/celenv.d.ts +0 -25
  407. package/dist/types/arkfee/estimator.d.ts +0 -49
  408. package/dist/types/arkfee/index.d.ts +0 -2
  409. package/dist/types/arkfee/types.d.ts +0 -38
  410. package/dist/types/arknote/index.d.ts +0 -84
  411. package/dist/types/bip322/index.d.ts +0 -55
  412. package/dist/types/contracts/arkcontract.d.ts +0 -99
  413. package/dist/types/contracts/contractManager.d.ts +0 -411
  414. package/dist/types/contracts/contractWatcher.d.ts +0 -217
  415. package/dist/types/contracts/handlers/default.d.ts +0 -19
  416. package/dist/types/contracts/handlers/delegate.d.ts +0 -21
  417. package/dist/types/contracts/handlers/helpers.d.ts +0 -19
  418. package/dist/types/contracts/handlers/index.d.ts +0 -7
  419. package/dist/types/contracts/handlers/registry.d.ts +0 -65
  420. package/dist/types/contracts/handlers/vhtlc.d.ts +0 -32
  421. package/dist/types/contracts/index.d.ts +0 -14
  422. package/dist/types/contracts/types.d.ts +0 -250
  423. package/dist/types/contracts/vtxoOwnership.d.ts +0 -33
  424. package/dist/types/extension/asset/assetGroup.d.ts +0 -119
  425. package/dist/types/extension/asset/assetId.d.ts +0 -83
  426. package/dist/types/extension/asset/assetInput.d.ts +0 -64
  427. package/dist/types/extension/asset/assetOutput.d.ts +0 -54
  428. package/dist/types/extension/asset/assetRef.d.ts +0 -91
  429. package/dist/types/extension/asset/index.d.ts +0 -8
  430. package/dist/types/extension/asset/metadata.d.ts +0 -52
  431. package/dist/types/extension/asset/packet.d.ts +0 -41
  432. package/dist/types/extension/asset/types.d.ts +0 -16
  433. package/dist/types/extension/asset/utils.d.ts +0 -21
  434. package/dist/types/extension/index.d.ts +0 -56
  435. package/dist/types/extension/packet.d.ts +0 -21
  436. package/dist/types/forfeit.d.ts +0 -18
  437. package/dist/types/identity/descriptor.d.ts +0 -61
  438. package/dist/types/identity/descriptorProvider.d.ts +0 -42
  439. package/dist/types/identity/hdCapableIdentity.d.ts +0 -71
  440. package/dist/types/identity/index.d.ts +0 -57
  441. package/dist/types/identity/seedIdentity.d.ts +0 -270
  442. package/dist/types/identity/serialize.d.ts +0 -96
  443. package/dist/types/identity/singleKey.d.ts +0 -62
  444. package/dist/types/identity/staticDescriptorProvider.d.ts +0 -18
  445. package/dist/types/index.d.ts +0 -59
  446. package/dist/types/intent/index.d.ts +0 -86
  447. package/dist/types/musig2/index.d.ts +0 -4
  448. package/dist/types/musig2/keys.d.ts +0 -9
  449. package/dist/types/musig2/nonces.d.ts +0 -14
  450. package/dist/types/musig2/sign.d.ts +0 -27
  451. package/dist/types/networks.d.ts +0 -16
  452. package/dist/types/providers/ark.d.ts +0 -369
  453. package/dist/types/providers/delegator.d.ts +0 -82
  454. package/dist/types/providers/electrum.d.ts +0 -312
  455. package/dist/types/providers/errors.d.ts +0 -13
  456. package/dist/types/providers/expoArk.d.ts +0 -22
  457. package/dist/types/providers/expoIndexer.d.ts +0 -18
  458. package/dist/types/providers/expoUtils.d.ts +0 -18
  459. package/dist/types/providers/indexer.d.ts +0 -301
  460. package/dist/types/providers/onchain.d.ts +0 -148
  461. package/dist/types/providers/utils.d.ts +0 -12
  462. package/dist/types/repositories/contractRepository.d.ts +0 -32
  463. package/dist/types/repositories/inMemory/contractRepository.d.ts +0 -17
  464. package/dist/types/repositories/inMemory/walletRepository.d.ts +0 -29
  465. package/dist/types/repositories/index.d.ts +0 -9
  466. package/dist/types/repositories/indexedDB/contractRepository.d.ts +0 -21
  467. package/dist/types/repositories/indexedDB/db.d.ts +0 -4
  468. package/dist/types/repositories/indexedDB/manager.d.ts +0 -25
  469. package/dist/types/repositories/indexedDB/schema.d.ts +0 -9
  470. package/dist/types/repositories/indexedDB/walletRepository.d.ts +0 -28
  471. package/dist/types/repositories/indexedDB/websqlAdapter.d.ts +0 -49
  472. package/dist/types/repositories/migrations/contractRepositoryImpl.d.ts +0 -24
  473. package/dist/types/repositories/migrations/fromStorageAdapter.d.ts +0 -19
  474. package/dist/types/repositories/migrations/walletRepositoryImpl.d.ts +0 -27
  475. package/dist/types/repositories/realm/contractRepository.d.ts +0 -24
  476. package/dist/types/repositories/realm/index.d.ts +0 -4
  477. package/dist/types/repositories/realm/types.d.ts +0 -16
  478. package/dist/types/repositories/realm/walletRepository.d.ts +0 -34
  479. package/dist/types/repositories/scriptFromAddress.d.ts +0 -9
  480. package/dist/types/repositories/serialization.d.ts +0 -65
  481. package/dist/types/repositories/sqlite/contractRepository.d.ts +0 -33
  482. package/dist/types/repositories/sqlite/index.d.ts +0 -3
  483. package/dist/types/repositories/sqlite/types.d.ts +0 -18
  484. package/dist/types/repositories/walletRepository.d.ts +0 -72
  485. package/dist/types/script/address.d.ts +0 -67
  486. package/dist/types/script/base.d.ts +0 -105
  487. package/dist/types/script/default.d.ts +0 -44
  488. package/dist/types/script/delegate.d.ts +0 -40
  489. package/dist/types/script/tapscript.d.ts +0 -169
  490. package/dist/types/script/vhtlc.d.ts +0 -66
  491. package/dist/types/tree/signingSession.d.ts +0 -37
  492. package/dist/types/tree/txTree.d.ts +0 -28
  493. package/dist/types/tree/validation.d.ts +0 -15
  494. package/dist/types/utils/anchor.d.ts +0 -19
  495. package/dist/types/utils/arkTransaction.d.ts +0 -49
  496. package/dist/types/utils/bip21.d.ts +0 -38
  497. package/dist/types/utils/syncCursors.d.ts +0 -60
  498. package/dist/types/utils/timelock.d.ts +0 -9
  499. package/dist/types/utils/transaction.d.ts +0 -13
  500. package/dist/types/utils/transactionHistory.d.ts +0 -15
  501. package/dist/types/utils/txSizeEstimator.d.ts +0 -40
  502. package/dist/types/utils/unknownFields.d.ts +0 -83
  503. package/dist/types/wallet/asset-manager.d.ts +0 -69
  504. package/dist/types/wallet/asset.d.ts +0 -21
  505. package/dist/types/wallet/batch.d.ts +0 -107
  506. package/dist/types/wallet/delegator.d.ts +0 -48
  507. package/dist/types/wallet/expo/background.d.ts +0 -66
  508. package/dist/types/wallet/expo/index.d.ts +0 -4
  509. package/dist/types/wallet/hdDescriptorProvider.d.ts +0 -114
  510. package/dist/types/wallet/index.d.ts +0 -789
  511. package/dist/types/wallet/inputSignerRouter.d.ts +0 -35
  512. package/dist/types/wallet/onchain.d.ts +0 -109
  513. package/dist/types/wallet/ramps.d.ts +0 -64
  514. package/dist/types/wallet/serviceWorker/wallet-message-handler.d.ts +0 -543
  515. package/dist/types/wallet/serviceWorker/wallet.d.ts +0 -248
  516. package/dist/types/wallet/signingErrors.d.ts +0 -19
  517. package/dist/types/wallet/unroll.d.ts +0 -114
  518. package/dist/types/wallet/utils.d.ts +0 -36
  519. package/dist/types/wallet/validation.d.ts +0 -24
  520. package/dist/types/wallet/vtxo-manager.d.ts +0 -476
  521. package/dist/types/wallet/wallet.d.ts +0 -409
  522. package/dist/types/wallet/walletReceiveRotator.d.ts +0 -306
  523. package/dist/types/worker/browser/service-worker-manager.d.ts +0 -32
  524. package/dist/types/worker/browser/utils.d.ts +0 -17
  525. package/dist/types/worker/errors.d.ts +0 -7
  526. package/dist/types/worker/expo/index.d.ts +0 -7
  527. package/dist/types/worker/expo/processors/contractPollProcessor.d.ts +0 -19
  528. package/dist/types/worker/expo/processors/index.d.ts +0 -1
  529. package/dist/types/worker/expo/taskQueue.d.ts +0 -50
  530. package/dist/types/worker/expo/taskRunner.d.ts +0 -66
  531. package/dist/types/worker/messageBus.d.ts +0 -189
@@ -1,1169 +0,0 @@
1
- import { hex } from "@scure/base";
2
- import { serializeReadonlyIdentity, serializeSigningIdentity, } from "../../identity/index.js";
3
- import { setupServiceWorker } from "../../worker/browser/utils.js";
4
- import { IndexedDBContractRepository, IndexedDBWalletRepository, } from "../../repositories/index.js";
5
- import { DEFAULT_MESSAGE_TAG, } from "./wallet-message-handler.js";
6
- import { getRandomId } from "../utils.js";
7
- import { MESSAGE_BUS_NOT_INITIALIZED, ServiceWorkerTimeoutError, } from "../../worker/errors.js";
8
- import { getArkadeServerUrl } from "../wallet.js";
9
- // Check by error message content instead of instanceof because postMessage uses the
10
- // structured clone algorithm which strips the prototype chain — the page
11
- // receives a plain Error, not the original MessageBusNotInitializedError.
12
- function isMessageBusNotInitializedError(error) {
13
- return (error instanceof Error &&
14
- error.message.includes(MESSAGE_BUS_NOT_INITIALIZED));
15
- }
16
- export const DEFAULT_MESSAGE_TIMEOUTS = {
17
- // Fast reads — fail quickly
18
- GET_ADDRESS: 10000,
19
- GET_BALANCE: 10000,
20
- GET_BOARDING_ADDRESS: 10000,
21
- GET_STATUS: 10000,
22
- GET_DELEGATE_INFO: 10000,
23
- IS_CONTRACT_MANAGER_WATCHING: 10000,
24
- // Medium reads — may involve indexer queries
25
- GET_VTXOS: 20000,
26
- GET_BOARDING_UTXOS: 20000,
27
- GET_TRANSACTION_HISTORY: 20000,
28
- GET_CONTRACTS: 20000,
29
- GET_CONTRACTS_WITH_VTXOS: 20000,
30
- ANNOTATE_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
- // SETTLE / RECOVER_VTXOS / RENEW_VTXOS go through the streaming path and
40
- // are treated as long-running on both sides of the bus: the values below
41
- // are retained only for type completeness and are never enforced.
42
- SEND_BITCOIN: 50000,
43
- SEND: 50000,
44
- SETTLE: 50000,
45
- ISSUE: 50000,
46
- REISSUE: 50000,
47
- BURN: 50000,
48
- DELEGATE: 50000,
49
- RECOVER_VTXOS: 50000,
50
- RENEW_VTXOS: 50000,
51
- SWEEP_EXPIRED_BOARDING_UTXOS: 50000,
52
- // Misc writes
53
- INIT_WALLET: 30000,
54
- CLEAR: 10000,
55
- SIGN_TRANSACTION: 30000,
56
- CREATE_CONTRACT: 30000,
57
- UPDATE_CONTRACT: 30000,
58
- DELETE_CONTRACT: 10000,
59
- REFRESH_VTXOS: 30000,
60
- REFRESH_OUTPOINTS: 30000,
61
- };
62
- const DEDUPABLE_REQUEST_TYPES = new Set([
63
- "GET_ADDRESS",
64
- "GET_BALANCE",
65
- "GET_BOARDING_ADDRESS",
66
- "GET_BOARDING_UTXOS",
67
- "GET_STATUS",
68
- "GET_TRANSACTION_HISTORY",
69
- "IS_CONTRACT_MANAGER_WATCHING",
70
- "GET_DELEGATE_INFO",
71
- "GET_RECOVERABLE_BALANCE",
72
- "GET_EXPIRED_BOARDING_UTXOS",
73
- "GET_VTXOS",
74
- "GET_CONTRACTS",
75
- "GET_CONTRACTS_WITH_VTXOS",
76
- "ANNOTATE_VTXOS",
77
- "GET_SPENDABLE_PATHS",
78
- "GET_ALL_SPENDING_PATHS",
79
- "GET_ASSET_DETAILS",
80
- "GET_EXPIRING_VTXOS",
81
- "RELOAD_WALLET",
82
- ]);
83
- function getRequestDedupKey(request) {
84
- const { id, tag, ...rest } = request;
85
- return JSON.stringify(rest);
86
- }
87
- function isSigningCapable(identity) {
88
- const candidate = identity;
89
- return (typeof candidate.signMessage === "function" &&
90
- typeof candidate.sign === "function" &&
91
- typeof candidate.signerSession === "function");
92
- }
93
- class ServiceWorkerReadonlyAssetManager {
94
- constructor(sendMessage, messageTag) {
95
- this.sendMessage = sendMessage;
96
- this.messageTag = messageTag;
97
- }
98
- async getAssetDetails(assetId) {
99
- const message = {
100
- tag: this.messageTag,
101
- type: "GET_ASSET_DETAILS",
102
- id: getRandomId(),
103
- payload: { assetId },
104
- };
105
- const response = await this.sendMessage(message);
106
- return response.payload.assetDetails;
107
- }
108
- }
109
- class ServiceWorkerAssetManager extends ServiceWorkerReadonlyAssetManager {
110
- async issue(params) {
111
- const message = {
112
- tag: this.messageTag,
113
- type: "ISSUE",
114
- id: getRandomId(),
115
- payload: { params },
116
- };
117
- const response = await this.sendMessage(message);
118
- return response.payload.result;
119
- }
120
- async reissue(params) {
121
- const message = {
122
- tag: this.messageTag,
123
- type: "REISSUE",
124
- id: getRandomId(),
125
- payload: { params },
126
- };
127
- const response = await this.sendMessage(message);
128
- return response.payload.txid;
129
- }
130
- async burn(params) {
131
- const message = {
132
- tag: this.messageTag,
133
- type: "BURN",
134
- id: getRandomId(),
135
- payload: { params },
136
- };
137
- const response = await this.sendMessage(message);
138
- return response.payload.txid;
139
- }
140
- }
141
- const initializeMessageBus = (serviceWorker, config, timeoutMs = 2000) => {
142
- const initCmd = {
143
- tag: "INITIALIZE_MESSAGE_BUS",
144
- id: getRandomId(),
145
- config: { ...config, timeoutMs },
146
- };
147
- return new Promise((resolve, reject) => {
148
- const cleanup = () => {
149
- navigator.serviceWorker.removeEventListener("message", onMessage);
150
- clearTimeout(timeoutId);
151
- };
152
- const onMessage = (event) => {
153
- const response = event.data;
154
- if (response?.id !== initCmd.id)
155
- return;
156
- cleanup();
157
- if (response.error) {
158
- reject(response.error);
159
- }
160
- else {
161
- resolve();
162
- }
163
- };
164
- const timeoutId = setTimeout(() => {
165
- cleanup();
166
- reject(new ServiceWorkerTimeoutError("MessageBus timed out"));
167
- }, timeoutMs);
168
- navigator.serviceWorker.addEventListener("message", onMessage);
169
- serviceWorker.postMessage(initCmd);
170
- });
171
- };
172
- export class ServiceWorkerReadonlyWallet {
173
- get assetManager() {
174
- return this._readonlyAssetManager;
175
- }
176
- constructor(serviceWorker, identity, walletRepository, contractRepository, messageTag) {
177
- this.serviceWorker = serviceWorker;
178
- this.messageTag = messageTag;
179
- this.initConfig = null;
180
- this.initWalletPayload = null;
181
- this.messageTimeouts = DEFAULT_MESSAGE_TIMEOUTS;
182
- this.reinitPromise = null;
183
- this.pingPromise = null;
184
- this.inflightRequests = new Map();
185
- this.identity = identity;
186
- this.walletRepository = walletRepository;
187
- this.contractRepository = contractRepository;
188
- this._readonlyAssetManager = new ServiceWorkerReadonlyAssetManager((msg) => this.sendMessage(msg), messageTag);
189
- }
190
- getTimeoutForRequest(request) {
191
- return this.messageTimeouts[request.type] ?? 30000;
192
- }
193
- /**
194
- * Create a readonly service-worker wallet bound to an already-registered worker.
195
- *
196
- * @param options - Service worker, identity, and backend configuration
197
- * @returns Initialized readonly service-worker wallet
198
- * @throws Error if service-worker initialization fails
199
- */
200
- static async create(options) {
201
- const walletRepository = options.storage?.walletRepository ??
202
- new IndexedDBWalletRepository();
203
- const contractRepository = options.storage?.contractRepository ??
204
- new IndexedDBContractRepository();
205
- const messageTag = options.walletUpdaterTag ?? DEFAULT_MESSAGE_TAG;
206
- // Create the wallet instance
207
- const wallet = new ServiceWorkerReadonlyWallet(options.serviceWorker, options.identity, walletRepository, contractRepository, messageTag);
208
- const serializedWallet = await serializeReadonlyIdentity(options.identity);
209
- // INIT_WALLET retains the legacy `key` payload for wire compatibility
210
- // with older workers; the current handler does not read it.
211
- const publicKey = await options.identity
212
- .compressedPublicKey()
213
- .then(hex.encode);
214
- const initWalletPayload = {
215
- key: { publicKey },
216
- arkServerUrl: getArkadeServerUrl(options),
217
- arkServerPublicKey: options.arkServerPublicKey,
218
- delegatorUrl: options.delegatorUrl,
219
- };
220
- // Precompute the merged timeout map so page-side waiting and
221
- // worker-side enforcement are derived from the same source.
222
- const messageTimeouts = options.messageTimeouts
223
- ? {
224
- ...DEFAULT_MESSAGE_TIMEOUTS,
225
- ...options.messageTimeouts,
226
- }
227
- : DEFAULT_MESSAGE_TIMEOUTS;
228
- const busInitConfig = {
229
- wallet: serializedWallet,
230
- arkServer: {
231
- url: getArkadeServerUrl(options),
232
- publicKey: options.arkServerPublicKey,
233
- },
234
- delegatorUrl: options.delegatorUrl,
235
- indexerUrl: options.indexerUrl,
236
- esploraUrl: options.esploraUrl,
237
- watcherConfig: options.watcherConfig,
238
- messageTimeouts,
239
- };
240
- // Bootstrap the MessageBus in the service worker
241
- await initializeMessageBus(options.serviceWorker, { ...busInitConfig, timeoutMs: options.messageBusTimeoutMs }, options.messageBusTimeoutMs);
242
- // Initialize the wallet handler
243
- const initMessage = {
244
- tag: messageTag,
245
- type: "INIT_WALLET",
246
- id: getRandomId(),
247
- payload: initWalletPayload,
248
- };
249
- await wallet.sendMessage(initMessage);
250
- // Persist the full init config (including messageTimeouts) so
251
- // reinitialize() re-sends the same map to a restarted worker.
252
- wallet.initConfig = busInitConfig;
253
- wallet.initWalletPayload = initWalletPayload;
254
- wallet.messageBusTimeoutMs = options.messageBusTimeoutMs;
255
- wallet.messageTimeouts = messageTimeouts;
256
- return wallet;
257
- }
258
- /**
259
- * Simplified setup method that handles service worker registration
260
- * and wallet initialization automatically.
261
- *
262
- * @see ServiceWorkerReadonlyWallet.create
263
- *
264
- * @example
265
- * ```typescript
266
- * const wallet = await ServiceWorkerReadonlyWallet.setup({
267
- * serviceWorkerPath: '/service-worker.js',
268
- * arkServerUrl: 'https://arkade.computer',
269
- * identity: ReadonlySingleKey.fromPublicKey('your_public_key_hex')
270
- * });
271
- * ```
272
- */
273
- static async setup(options) {
274
- // Register and setup the service worker
275
- const serviceWorker = await setupServiceWorker({
276
- path: options.serviceWorkerPath,
277
- activationTimeoutMs: options.serviceWorkerActivationTimeoutMs,
278
- });
279
- // Use the existing create method
280
- return await ServiceWorkerReadonlyWallet.create({
281
- ...options,
282
- serviceWorker,
283
- });
284
- }
285
- sendMessageDirect(request, timeoutMs) {
286
- return new Promise((resolve, reject) => {
287
- const cleanup = () => {
288
- clearTimeout(timeoutId);
289
- navigator.serviceWorker.removeEventListener("message", messageHandler);
290
- };
291
- const timeoutId = setTimeout(() => {
292
- cleanup();
293
- reject(new ServiceWorkerTimeoutError(`Service worker message timed out (${request.type})`));
294
- }, timeoutMs);
295
- const messageHandler = (event) => {
296
- const response = event.data;
297
- if (request.id !== response.id) {
298
- return;
299
- }
300
- cleanup();
301
- if (response.error) {
302
- reject(response.error);
303
- }
304
- else {
305
- resolve(response);
306
- }
307
- };
308
- navigator.serviceWorker.addEventListener("message", messageHandler);
309
- this.serviceWorker.postMessage(request);
310
- });
311
- }
312
- // Like sendMessageDirect but supports streaming responses: intermediate
313
- // messages are forwarded via onEvent while the promise resolves on the
314
- // first response for which isComplete returns true. No inactivity deadline:
315
- // settlement-class flows surrender control to remote peers and can sit
316
- // idle for long stretches between protocol events. Service-worker death
317
- // is detected out-of-band via concurrent short requests that surface
318
- // MESSAGE_BUS_NOT_INITIALIZED.
319
- sendMessageStreaming(request, onEvent, isComplete) {
320
- return new Promise((resolve, reject) => {
321
- const cleanup = () => {
322
- navigator.serviceWorker.removeEventListener("message", messageHandler);
323
- };
324
- const messageHandler = (event) => {
325
- const response = event.data;
326
- if (request.id !== response.id)
327
- return;
328
- if (response.error) {
329
- cleanup();
330
- reject(response.error);
331
- return;
332
- }
333
- if (isComplete(response)) {
334
- cleanup();
335
- resolve(response);
336
- }
337
- else {
338
- onEvent(response);
339
- }
340
- };
341
- navigator.serviceWorker.addEventListener("message", messageHandler);
342
- this.serviceWorker.postMessage(request);
343
- });
344
- }
345
- async sendMessage(request) {
346
- if (!DEDUPABLE_REQUEST_TYPES.has(request.type)) {
347
- return this.sendMessageWithRetry(request);
348
- }
349
- const key = getRequestDedupKey(request);
350
- const existing = this.inflightRequests.get(key);
351
- if (existing)
352
- return existing;
353
- const promise = this.sendMessageWithRetry(request).finally(() => {
354
- this.inflightRequests.delete(key);
355
- });
356
- this.inflightRequests.set(key, promise);
357
- return promise;
358
- }
359
- pingServiceWorker() {
360
- if (this.pingPromise)
361
- return this.pingPromise;
362
- this.pingPromise = new Promise((resolve, reject) => {
363
- const pingId = getRandomId();
364
- const cleanup = () => {
365
- clearTimeout(timeoutId);
366
- navigator.serviceWorker.removeEventListener("message", onMessage);
367
- };
368
- const timeoutId = setTimeout(() => {
369
- cleanup();
370
- reject(new ServiceWorkerTimeoutError("Service worker ping timed out"));
371
- }, 2000);
372
- const onMessage = (event) => {
373
- if (event.data?.id === pingId && event.data?.tag === "PONG") {
374
- cleanup();
375
- resolve();
376
- }
377
- };
378
- navigator.serviceWorker.addEventListener("message", onMessage);
379
- this.serviceWorker.postMessage({
380
- id: pingId,
381
- tag: "PING",
382
- });
383
- }).finally(() => {
384
- this.pingPromise = null;
385
- });
386
- return this.pingPromise;
387
- }
388
- // send a message, retrying up to 2 times if the service worker was
389
- // killed and restarted by the OS (mobile browsers do this aggressively)
390
- async sendMessageWithRetry(request) {
391
- // Skip the preflight ping during the initial INIT_WALLET call:
392
- // create() hasn't set initConfig yet, so reinitialize() would throw.
393
- if (this.initConfig) {
394
- try {
395
- await this.pingServiceWorker();
396
- }
397
- catch {
398
- await this.reinitialize();
399
- }
400
- }
401
- const timeoutMs = this.getTimeoutForRequest(request);
402
- const maxRetries = 2;
403
- for (let attempt = 0;; attempt++) {
404
- try {
405
- return await this.sendMessageDirect(request, timeoutMs);
406
- }
407
- catch (error) {
408
- if (!isMessageBusNotInitializedError(error) ||
409
- attempt >= maxRetries) {
410
- throw error;
411
- }
412
- await this.reinitialize();
413
- }
414
- }
415
- }
416
- // Like sendMessage but for streaming responses — retries with
417
- // reinitialize when the service worker has been killed/restarted.
418
- async sendMessageWithEvents(request, onEvent, isComplete) {
419
- if (this.initConfig) {
420
- try {
421
- await this.pingServiceWorker();
422
- }
423
- catch {
424
- await this.reinitialize();
425
- }
426
- }
427
- const maxRetries = 2;
428
- for (let attempt = 0;; attempt++) {
429
- try {
430
- return await this.sendMessageStreaming(request, onEvent, isComplete);
431
- }
432
- catch (error) {
433
- if (!isMessageBusNotInitializedError(error) ||
434
- attempt >= maxRetries) {
435
- throw error;
436
- }
437
- await this.reinitialize();
438
- }
439
- }
440
- }
441
- /**
442
- * Produce a serialized envelope for the wallet's identity. The base
443
- * class always emits a readonly envelope; `ServiceWorkerWallet`
444
- * overrides to emit a signing envelope.
445
- */
446
- async serializeIdentity() {
447
- return serializeReadonlyIdentity(this.identity);
448
- }
449
- /**
450
- * Return the cached init config, or rebuild one from live instance
451
- * state when the cache was never populated. Recovery path for
452
- * SDK-factory-created wallets; manual constructor bypasses do not
453
- * retain enough state here and will hit the "never initialized" throw.
454
- */
455
- async buildInitConfig() {
456
- if (this.initConfig)
457
- return this.initConfig;
458
- if (!this.arkServerUrl) {
459
- throw new Error("Cannot re-initialize: wallet was not initialized via the SDK factory");
460
- }
461
- const wallet = await this.serializeIdentity();
462
- this.initConfig = {
463
- wallet,
464
- arkServer: {
465
- url: this.arkServerUrl,
466
- publicKey: this.arkServerPublicKey,
467
- },
468
- delegatorUrl: this.delegatorUrl,
469
- indexerUrl: this.indexerUrl,
470
- esploraUrl: this.esploraUrl,
471
- watcherConfig: this.watcherConfig,
472
- settlementConfig: this.settlementConfig,
473
- };
474
- return this.initConfig;
475
- }
476
- /** Minimal INIT_WALLET payload used on reinitialize when the cache is gone. */
477
- buildInitWalletPayload() {
478
- if (this.initWalletPayload)
479
- return this.initWalletPayload;
480
- if (!this.arkServerUrl) {
481
- throw new Error("Cannot re-initialize: wallet was not initialized via the SDK factory");
482
- }
483
- this.initWalletPayload = {
484
- // `key` is deprecated and ignored by the current handler.
485
- key: {},
486
- arkServerUrl: this.arkServerUrl,
487
- arkServerPublicKey: this.arkServerPublicKey,
488
- };
489
- return this.initWalletPayload;
490
- }
491
- async reinitialize() {
492
- if (this.reinitPromise)
493
- return this.reinitPromise;
494
- this.reinitPromise = (async () => {
495
- const config = await this.buildInitConfig();
496
- const payload = this.buildInitWalletPayload();
497
- await initializeMessageBus(this.serviceWorker, config, this.messageBusTimeoutMs);
498
- const initMessage = {
499
- tag: this.messageTag,
500
- type: "INIT_WALLET",
501
- id: getRandomId(),
502
- payload,
503
- };
504
- await this.sendMessageDirect(initMessage, this.getTimeoutForRequest(initMessage));
505
- })().finally(() => {
506
- this.reinitPromise = null;
507
- });
508
- return this.reinitPromise;
509
- }
510
- /** Clear cached wallet state from both the page and service worker storage. */
511
- async clear() {
512
- const message = {
513
- id: getRandomId(),
514
- tag: this.messageTag,
515
- type: "CLEAR",
516
- };
517
- // Clear page-side storage to maintain parity with SW
518
- try {
519
- const address = await this.getAddress();
520
- await this.walletRepository.deleteVtxos(address);
521
- }
522
- catch (_) {
523
- console.warn("Failed to clear vtxos from wallet repository");
524
- }
525
- await this.sendMessage(message);
526
- }
527
- async getAddress() {
528
- const message = {
529
- id: getRandomId(),
530
- tag: this.messageTag,
531
- type: "GET_ADDRESS",
532
- };
533
- try {
534
- const response = await this.sendMessage(message);
535
- return response.payload.address;
536
- }
537
- catch (error) {
538
- throw new Error(`Failed to get address: ${error}`);
539
- }
540
- }
541
- async getBoardingAddress() {
542
- const message = {
543
- id: getRandomId(),
544
- tag: this.messageTag,
545
- type: "GET_BOARDING_ADDRESS",
546
- };
547
- try {
548
- const response = await this.sendMessage(message);
549
- return response.payload.address;
550
- }
551
- catch (error) {
552
- throw new Error(`Failed to get boarding address: ${error}`);
553
- }
554
- }
555
- async getBalance() {
556
- const message = {
557
- id: getRandomId(),
558
- tag: this.messageTag,
559
- type: "GET_BALANCE",
560
- };
561
- try {
562
- const response = await this.sendMessage(message);
563
- return response.payload;
564
- }
565
- catch (error) {
566
- throw new Error(`Failed to get balance: ${error}`);
567
- }
568
- }
569
- async getBoardingUtxos() {
570
- const message = {
571
- id: getRandomId(),
572
- tag: this.messageTag,
573
- type: "GET_BOARDING_UTXOS",
574
- };
575
- try {
576
- const response = await this.sendMessage(message);
577
- return response.payload.utxos;
578
- }
579
- catch (error) {
580
- throw new Error(`Failed to get boarding UTXOs: ${error}`);
581
- }
582
- }
583
- /**
584
- * Return service-worker wallet status, including connectivity and sync state.
585
- *
586
- * @returns Current service-worker wallet status payload including `walletInitalized` and `xOnlyPublicKey`
587
- */
588
- async getStatus() {
589
- const message = {
590
- id: getRandomId(),
591
- tag: this.messageTag,
592
- type: "GET_STATUS",
593
- };
594
- try {
595
- const response = await this.sendMessage(message);
596
- return response.payload;
597
- }
598
- catch (error) {
599
- throw new Error(`Failed to get status: ${error}`);
600
- }
601
- }
602
- async getTransactionHistory() {
603
- const message = {
604
- id: getRandomId(),
605
- tag: this.messageTag,
606
- type: "GET_TRANSACTION_HISTORY",
607
- };
608
- try {
609
- const response = await this.sendMessage(message);
610
- return response.payload
611
- .transactions;
612
- }
613
- catch (error) {
614
- throw new Error(`Failed to get transaction history: ${error}`);
615
- }
616
- }
617
- async getVtxos(filter) {
618
- const message = {
619
- id: getRandomId(),
620
- tag: this.messageTag,
621
- type: "GET_VTXOS",
622
- payload: { filter },
623
- };
624
- try {
625
- const response = await this.sendMessage(message);
626
- return response.payload.vtxos;
627
- }
628
- catch (error) {
629
- throw new Error(`Failed to get vtxos: ${error}`);
630
- }
631
- }
632
- /**
633
- * Trigger a wallet reload inside the service worker.
634
- *
635
- * @returns `true` when the wallet was reloaded
636
- */
637
- async reload() {
638
- const message = {
639
- id: getRandomId(),
640
- tag: this.messageTag,
641
- type: "RELOAD_WALLET",
642
- };
643
- try {
644
- const response = await this.sendMessage(message);
645
- return response.payload.reloaded;
646
- }
647
- catch (error) {
648
- throw new Error(`Failed to reload wallet: ${error}`);
649
- }
650
- }
651
- async getContractManager() {
652
- const wallet = this;
653
- const sendContractMessage = async (message) => {
654
- return wallet.sendMessage(message);
655
- };
656
- const messageTag = this.messageTag;
657
- const manager = {
658
- async createContract(params) {
659
- const message = {
660
- type: "CREATE_CONTRACT",
661
- id: getRandomId(),
662
- tag: messageTag,
663
- payload: params,
664
- };
665
- try {
666
- const response = await sendContractMessage(message);
667
- return response.payload
668
- .contract;
669
- }
670
- catch (e) {
671
- throw new Error("Failed to create contract");
672
- }
673
- },
674
- async getContracts(filter) {
675
- const message = {
676
- type: "GET_CONTRACTS",
677
- id: getRandomId(),
678
- tag: messageTag,
679
- payload: { filter },
680
- };
681
- try {
682
- const response = await sendContractMessage(message);
683
- return response.payload.contracts;
684
- }
685
- catch (e) {
686
- throw new Error("Failed to get contracts");
687
- }
688
- },
689
- async getContractsWithVtxos(filter) {
690
- const message = {
691
- type: "GET_CONTRACTS_WITH_VTXOS",
692
- id: getRandomId(),
693
- tag: messageTag,
694
- payload: { filter },
695
- };
696
- try {
697
- const response = await sendContractMessage(message);
698
- return response.payload
699
- .contracts;
700
- }
701
- catch (e) {
702
- throw new Error("Failed to get contracts with vtxos");
703
- }
704
- },
705
- async annotateVtxos(vtxos) {
706
- if (vtxos.length === 0)
707
- return [];
708
- const message = {
709
- type: "ANNOTATE_VTXOS",
710
- id: getRandomId(),
711
- tag: messageTag,
712
- payload: { vtxos },
713
- };
714
- try {
715
- const response = await sendContractMessage(message);
716
- return response.payload.vtxos;
717
- }
718
- catch (e) {
719
- throw new Error("Failed to annotate vtxos");
720
- }
721
- },
722
- async updateContract(script, updates) {
723
- const message = {
724
- type: "UPDATE_CONTRACT",
725
- id: getRandomId(),
726
- tag: messageTag,
727
- payload: { script, updates },
728
- };
729
- try {
730
- const response = await sendContractMessage(message);
731
- return response.payload
732
- .contract;
733
- }
734
- catch (e) {
735
- throw new Error("Failed to update contract");
736
- }
737
- },
738
- async setContractState(script, state) {
739
- const message = {
740
- type: "UPDATE_CONTRACT",
741
- id: getRandomId(),
742
- tag: messageTag,
743
- payload: { script, updates: { state } },
744
- };
745
- try {
746
- await sendContractMessage(message);
747
- return;
748
- }
749
- catch (e) {
750
- throw new Error("Failed to update contract state");
751
- }
752
- },
753
- async deleteContract(script) {
754
- const message = {
755
- type: "DELETE_CONTRACT",
756
- id: getRandomId(),
757
- tag: messageTag,
758
- payload: { script },
759
- };
760
- try {
761
- await sendContractMessage(message);
762
- return;
763
- }
764
- catch (e) {
765
- throw new Error("Failed to delete contract");
766
- }
767
- },
768
- async getSpendablePaths(options) {
769
- const message = {
770
- type: "GET_SPENDABLE_PATHS",
771
- id: getRandomId(),
772
- tag: messageTag,
773
- payload: { options },
774
- };
775
- try {
776
- const response = await sendContractMessage(message);
777
- return response.payload
778
- .paths;
779
- }
780
- catch (e) {
781
- throw new Error("Failed to get spendable paths");
782
- }
783
- },
784
- async getAllSpendingPaths(options) {
785
- const message = {
786
- type: "GET_ALL_SPENDING_PATHS",
787
- id: getRandomId(),
788
- tag: messageTag,
789
- payload: { options },
790
- };
791
- try {
792
- const response = await sendContractMessage(message);
793
- return response.payload
794
- .paths;
795
- }
796
- catch (e) {
797
- throw new Error("Failed to get all spending paths");
798
- }
799
- },
800
- onContractEvent(callback) {
801
- const messageHandler = (event) => {
802
- const response = event.data;
803
- if (response.type !== "CONTRACT_EVENT") {
804
- return;
805
- }
806
- if (response.tag !== messageTag) {
807
- return;
808
- }
809
- callback(response.payload.event);
810
- };
811
- navigator.serviceWorker.addEventListener("message", messageHandler);
812
- return () => {
813
- navigator.serviceWorker.removeEventListener("message", messageHandler);
814
- };
815
- },
816
- async refreshVtxos(opts) {
817
- const message = {
818
- type: "REFRESH_VTXOS",
819
- id: getRandomId(),
820
- tag: messageTag,
821
- payload: opts,
822
- };
823
- await sendContractMessage(message);
824
- },
825
- async refreshOutpoints(outpoints) {
826
- const message = {
827
- type: "REFRESH_OUTPOINTS",
828
- id: getRandomId(),
829
- tag: messageTag,
830
- payload: { outpoints },
831
- };
832
- await sendContractMessage(message);
833
- },
834
- async isWatching() {
835
- const message = {
836
- type: "IS_CONTRACT_MANAGER_WATCHING",
837
- id: getRandomId(),
838
- tag: messageTag,
839
- };
840
- try {
841
- const response = await sendContractMessage(message);
842
- return response
843
- .payload.isWatching;
844
- }
845
- catch (e) {
846
- throw new Error("Failed to check if contract manager is watching");
847
- }
848
- },
849
- dispose() {
850
- return;
851
- },
852
- [Symbol.dispose]() {
853
- // no-op
854
- return;
855
- },
856
- };
857
- return manager;
858
- }
859
- }
860
- export class ServiceWorkerWallet extends ServiceWorkerReadonlyWallet {
861
- constructor(serviceWorker, identity, walletRepository, contractRepository, messageTag, hasDelegator) {
862
- super(serviceWorker, identity, walletRepository, contractRepository, messageTag);
863
- this.serviceWorker = serviceWorker;
864
- this.identity = identity;
865
- this.walletRepository = walletRepository;
866
- this.contractRepository = contractRepository;
867
- this._assetManager = new ServiceWorkerAssetManager((msg) => this.sendMessage(msg), messageTag);
868
- this.hasDelegator = hasDelegator;
869
- }
870
- get assetManager() {
871
- return this._assetManager;
872
- }
873
- async serializeIdentity() {
874
- return serializeSigningIdentity(this.identity);
875
- }
876
- static async create(options) {
877
- const walletRepository = options.storage?.walletRepository ??
878
- new IndexedDBWalletRepository();
879
- const contractRepository = options.storage?.contractRepository ??
880
- new IndexedDBContractRepository();
881
- if (!isSigningCapable(options.identity)) {
882
- throw new Error("ServiceWorkerWallet.create() requires a signing Identity; got a ReadonlyIdentity");
883
- }
884
- const identity = options.identity;
885
- const serializedWallet = serializeSigningIdentity(identity);
886
- const messageTag = options.walletUpdaterTag ?? DEFAULT_MESSAGE_TAG;
887
- // Create the wallet instance
888
- const wallet = new ServiceWorkerWallet(options.serviceWorker, identity, walletRepository, contractRepository, messageTag, !!options.delegatorUrl);
889
- // INIT_WALLET retains the legacy `key` payload for wire compatibility
890
- // with older workers; the current handler does not read it, and only
891
- // SingleKey-style identities can populate it. Kept optional so seed /
892
- // mnemonic identities simply omit it.
893
- const legacyPrivateKey = serializedWallet.type === "single-key"
894
- ? serializedWallet.privateKey
895
- : null;
896
- const initWalletPayload = {
897
- key: legacyPrivateKey ? { privateKey: legacyPrivateKey } : {},
898
- arkServerUrl: getArkadeServerUrl(options),
899
- arkServerPublicKey: options.arkServerPublicKey,
900
- delegatorUrl: options.delegatorUrl,
901
- };
902
- // Precompute the merged timeout map so page-side waiting and
903
- // worker-side enforcement are derived from the same source.
904
- const messageTimeouts = options.messageTimeouts
905
- ? {
906
- ...DEFAULT_MESSAGE_TIMEOUTS,
907
- ...options.messageTimeouts,
908
- }
909
- : DEFAULT_MESSAGE_TIMEOUTS;
910
- const busInitConfig = {
911
- wallet: serializedWallet,
912
- arkServer: {
913
- url: getArkadeServerUrl(options),
914
- publicKey: options.arkServerPublicKey,
915
- },
916
- delegatorUrl: options.delegatorUrl,
917
- indexerUrl: options.indexerUrl,
918
- esploraUrl: options.esploraUrl,
919
- settlementConfig: options.settlementConfig,
920
- walletMode: options.walletMode,
921
- watcherConfig: options.watcherConfig,
922
- messageTimeouts,
923
- };
924
- await initializeMessageBus(options.serviceWorker, { ...busInitConfig, timeoutMs: options.messageBusTimeoutMs }, options.messageBusTimeoutMs);
925
- // Initialize the service worker with the config
926
- const initMessage = {
927
- tag: messageTag,
928
- type: "INIT_WALLET",
929
- id: getRandomId(),
930
- payload: initWalletPayload,
931
- };
932
- // Initialize the service worker
933
- await wallet.sendMessage(initMessage);
934
- // Persist the full init config (including messageTimeouts) so
935
- // reinitialize() re-sends the same map to a restarted worker.
936
- wallet.initConfig = busInitConfig;
937
- wallet.initWalletPayload = initWalletPayload;
938
- wallet.messageBusTimeoutMs = options.messageBusTimeoutMs;
939
- wallet.messageTimeouts = messageTimeouts;
940
- return wallet;
941
- }
942
- /**
943
- * Simplified setup method that handles service worker registration
944
- * and wallet initialization automatically.
945
- *
946
- * @example
947
- * ```typescript
948
- * const wallet = await ServiceWorkerWallet.setup({
949
- * serviceWorkerPath: '/service-worker.js',
950
- * arkServerUrl: 'https://arkade.computer',
951
- * identity: MnemonicIdentity.fromMnemonic('abandon abandon...')
952
- * });
953
- * ```
954
- */
955
- static async setup(options) {
956
- // Register and setup the service worker
957
- const serviceWorker = await setupServiceWorker({
958
- path: options.serviceWorkerPath,
959
- activationTimeoutMs: options.serviceWorkerActivationTimeoutMs,
960
- });
961
- // Use the existing create method
962
- return ServiceWorkerWallet.create({
963
- ...options,
964
- serviceWorker,
965
- });
966
- }
967
- async sendBitcoin(params) {
968
- const message = {
969
- id: getRandomId(),
970
- tag: this.messageTag,
971
- type: "SEND_BITCOIN",
972
- payload: params,
973
- };
974
- try {
975
- const response = await this.sendMessage(message);
976
- return response.payload.txid;
977
- }
978
- catch (error) {
979
- throw new Error(`Failed to send bitcoin: ${error}`);
980
- }
981
- }
982
- async settle(params, callback) {
983
- const message = {
984
- id: getRandomId(),
985
- tag: this.messageTag,
986
- type: "SETTLE",
987
- payload: { params },
988
- };
989
- try {
990
- const response = await this.sendMessageWithEvents(message, (resp) => callback?.(resp.payload), (resp) => resp.type === "SETTLE_SUCCESS");
991
- return response.payload.txid;
992
- }
993
- catch (error) {
994
- throw new Error(`Settlement failed: ${error}`);
995
- }
996
- }
997
- async send(...recipients) {
998
- const message = {
999
- tag: this.messageTag,
1000
- type: "SEND",
1001
- id: getRandomId(),
1002
- payload: { recipients },
1003
- };
1004
- try {
1005
- const response = await this.sendMessage(message);
1006
- return response.payload.txid;
1007
- }
1008
- catch (error) {
1009
- throw new Error(`Send failed: ${error}`);
1010
- }
1011
- }
1012
- async getDelegatorManager() {
1013
- if (!this.hasDelegator) {
1014
- return undefined;
1015
- }
1016
- const wallet = this;
1017
- const messageTag = this.messageTag;
1018
- const manager = {
1019
- async delegate(vtxos, destination, delegateAt) {
1020
- const message = {
1021
- tag: messageTag,
1022
- type: "DELEGATE",
1023
- id: getRandomId(),
1024
- payload: {
1025
- vtxoOutpoints: vtxos.map((v) => ({
1026
- txid: v.txid,
1027
- vout: v.vout,
1028
- })),
1029
- destination,
1030
- delegateAt: delegateAt?.getTime(),
1031
- },
1032
- };
1033
- try {
1034
- const response = await wallet.sendMessage(message);
1035
- const payload = response.payload;
1036
- return {
1037
- delegated: payload.delegated,
1038
- failed: payload.failed.map((f) => ({
1039
- outpoints: f.outpoints,
1040
- error: f.error,
1041
- })),
1042
- };
1043
- }
1044
- catch (error) {
1045
- throw new Error(`Delegation failed: ${error}`);
1046
- }
1047
- },
1048
- async getDelegateInfo() {
1049
- const message = {
1050
- type: "GET_DELEGATE_INFO",
1051
- id: getRandomId(),
1052
- tag: messageTag,
1053
- };
1054
- try {
1055
- const response = await wallet.sendMessage(message);
1056
- return response.payload.info;
1057
- }
1058
- catch (e) {
1059
- throw new Error("Failed to get delegate info");
1060
- }
1061
- },
1062
- };
1063
- return manager;
1064
- }
1065
- async getVtxoManager() {
1066
- const wallet = this;
1067
- const messageTag = this.messageTag;
1068
- const manager = {
1069
- async recoverVtxos(eventCallback) {
1070
- const message = {
1071
- tag: messageTag,
1072
- type: "RECOVER_VTXOS",
1073
- id: getRandomId(),
1074
- };
1075
- try {
1076
- const response = await wallet.sendMessageWithEvents(message, (resp) => eventCallback?.(resp.payload), (resp) => resp.type === "RECOVER_VTXOS_SUCCESS");
1077
- return response.payload.txid;
1078
- }
1079
- catch (e) {
1080
- throw new Error(`Failed to recover vtxos: ${e}`);
1081
- }
1082
- },
1083
- async getRecoverableBalance() {
1084
- const message = {
1085
- tag: messageTag,
1086
- type: "GET_RECOVERABLE_BALANCE",
1087
- id: getRandomId(),
1088
- };
1089
- try {
1090
- const response = await wallet.sendMessage(message);
1091
- const payload = response
1092
- .payload;
1093
- return {
1094
- recoverable: BigInt(payload.recoverable),
1095
- subdust: BigInt(payload.subdust),
1096
- includesSubdust: payload.includesSubdust,
1097
- vtxoCount: payload.vtxoCount,
1098
- };
1099
- }
1100
- catch (e) {
1101
- throw new Error(`Failed to get recoverable balance: ${e}`);
1102
- }
1103
- },
1104
- async getExpiringVtxos(thresholdMs) {
1105
- const message = {
1106
- tag: messageTag,
1107
- type: "GET_EXPIRING_VTXOS",
1108
- id: getRandomId(),
1109
- payload: { thresholdMs },
1110
- };
1111
- try {
1112
- const response = await wallet.sendMessage(message);
1113
- return response.payload.vtxos;
1114
- }
1115
- catch (e) {
1116
- throw new Error(`Failed to get expiring vtxos: ${e}`);
1117
- }
1118
- },
1119
- async renewVtxos(eventCallback) {
1120
- const message = {
1121
- tag: messageTag,
1122
- type: "RENEW_VTXOS",
1123
- id: getRandomId(),
1124
- };
1125
- try {
1126
- const response = await wallet.sendMessageWithEvents(message, (resp) => eventCallback?.(resp.payload), (resp) => resp.type === "RENEW_VTXOS_SUCCESS");
1127
- return response.payload.txid;
1128
- }
1129
- catch (e) {
1130
- throw new Error(`Failed to renew vtxos: ${e}`);
1131
- }
1132
- },
1133
- async getExpiredBoardingUtxos() {
1134
- const message = {
1135
- tag: messageTag,
1136
- type: "GET_EXPIRED_BOARDING_UTXOS",
1137
- id: getRandomId(),
1138
- };
1139
- try {
1140
- const response = await wallet.sendMessage(message);
1141
- return response.payload
1142
- .utxos;
1143
- }
1144
- catch (e) {
1145
- throw new Error(`Failed to get expired boarding utxos: ${e}`);
1146
- }
1147
- },
1148
- async sweepExpiredBoardingUtxos() {
1149
- const message = {
1150
- tag: messageTag,
1151
- type: "SWEEP_EXPIRED_BOARDING_UTXOS",
1152
- id: getRandomId(),
1153
- };
1154
- try {
1155
- const response = await wallet.sendMessage(message);
1156
- return response
1157
- .payload.txid;
1158
- }
1159
- catch (e) {
1160
- throw new Error(`Failed to sweep expired boarding utxos: ${e}`);
1161
- }
1162
- },
1163
- async dispose() {
1164
- return;
1165
- },
1166
- };
1167
- return manager;
1168
- }
1169
- }