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