@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,473 +0,0 @@
1
- "use strict";
2
- /// <reference lib="webworker" />
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.MessageBus = void 0;
5
- const service_worker_manager_1 = require("./browser/service-worker-manager");
6
- const ark_1 = require("../providers/ark");
7
- const delegator_1 = require("../providers/delegator");
8
- const identity_1 = require("../identity");
9
- const wallet_1 = require("../wallet/wallet");
10
- const errors_1 = require("./errors");
11
- /**
12
- * Grace period after a handler times out during which late handler
13
- * completion is still delivered to the client. Once this expires,
14
- * the bus sends an "Operation abandoned" error so the message id
15
- * never goes silent indefinitely.
16
- */
17
- const LATE_DELIVERY_GRACE_MS = 5 * 60000;
18
- class MessageBus {
19
- /** Create the service-worker message bus with repositories and handler configuration. */
20
- constructor(walletRepository, contractRepository, { messageHandlers, tickIntervalMs = 10000, messageTimeoutMs = 30000, messageTimeoutOverrides = {}, debug = false, buildServices, }) {
21
- this.walletRepository = walletRepository;
22
- this.contractRepository = contractRepository;
23
- this.lateDeliveries = new Set();
24
- this.running = false;
25
- this.tickTimeout = null;
26
- this.tickInProgress = false;
27
- this.debug = false;
28
- this.initialized = false;
29
- this.boundOnMessage = this.onMessage.bind(this);
30
- this.handlers = new Map(messageHandlers.map((u) => [u.messageTag, u]));
31
- this.tickIntervalMs = tickIntervalMs;
32
- this.messageTimeoutMs = messageTimeoutMs;
33
- this.constructorTimeoutOverrides = { ...messageTimeoutOverrides };
34
- this.messageTimeoutOverrides = { ...this.constructorTimeoutOverrides };
35
- this.debug = debug;
36
- this.buildServicesFn = buildServices ?? this.buildServices.bind(this);
37
- }
38
- /** Start the message bus and attach service-worker event listeners. */
39
- async start() {
40
- if (this.running)
41
- return;
42
- this.running = true;
43
- if (this.debug)
44
- console.log("MessageBus starting");
45
- // Hook message routing
46
- self.addEventListener("message", this.boundOnMessage);
47
- // activate service worker immediately
48
- self.addEventListener("install", () => {
49
- self.skipWaiting();
50
- });
51
- // take control of clients immediately
52
- self.addEventListener("activate", () => {
53
- self.clients.claim();
54
- if (this.initialized) {
55
- this.runTick();
56
- }
57
- });
58
- }
59
- /** Stop the message bus, cancel ticks, and stop all registered handlers. */
60
- async stop() {
61
- if (this.debug)
62
- console.log("MessageBus stopping");
63
- this.running = false;
64
- this.tickInProgress = false;
65
- this.initialized = false;
66
- if (this.tickTimeout !== null) {
67
- self.clearTimeout(this.tickTimeout);
68
- this.tickTimeout = null;
69
- }
70
- for (const record of this.lateDeliveries) {
71
- record.settled = true;
72
- self.clearTimeout(record.deadline);
73
- }
74
- this.lateDeliveries.clear();
75
- self.removeEventListener("message", this.boundOnMessage);
76
- await Promise.all(Array.from(this.handlers.values()).map((updater) => updater.stop()));
77
- }
78
- scheduleNextTick() {
79
- if (!this.running)
80
- return;
81
- if (this.tickTimeout !== null)
82
- return;
83
- if (this.tickInProgress)
84
- return;
85
- this.tickTimeout = self.setTimeout(() => this.runTick(), this.tickIntervalMs);
86
- }
87
- async runTick() {
88
- if (!this.running)
89
- return;
90
- if (this.tickInProgress)
91
- return;
92
- this.tickInProgress = true;
93
- if (this.tickTimeout !== null) {
94
- self.clearTimeout(this.tickTimeout);
95
- this.tickTimeout = null;
96
- }
97
- try {
98
- const now = Date.now();
99
- for (const updater of this.handlers.values()) {
100
- try {
101
- const tickLabel = `${updater.messageTag}:tick`;
102
- const response = await this.withTimeout(updater.tick(now), this.resolveTimeoutMs(tickLabel, updater.messageTag), tickLabel);
103
- if (this.debug)
104
- console.log(`[${updater.messageTag}] outgoing tick response:`, response);
105
- if (response && response.length > 0) {
106
- self.clients
107
- .matchAll({
108
- includeUncontrolled: true,
109
- type: "window",
110
- })
111
- .then((clients) => {
112
- for (const message of response) {
113
- clients.forEach((client) => {
114
- client.postMessage(message);
115
- });
116
- }
117
- });
118
- }
119
- }
120
- catch (err) {
121
- if (this.debug)
122
- console.error(`[${updater.messageTag}] tick failed`, err);
123
- }
124
- }
125
- }
126
- finally {
127
- this.tickInProgress = false;
128
- this.scheduleNextTick();
129
- }
130
- }
131
- async waitForInit(config) {
132
- if (this.initialized) {
133
- // Stop existing handlers before re-initializing.
134
- // This handles the case where CLEAR was called, which nullifies
135
- // handler state (readonlyWallet, etc.) without resetting the
136
- // initialized flag. Without this, handlers never get start()
137
- // called again and all messages fail with "not initialized".
138
- //
139
- // Clear the flag first so onMessage() rejects incoming messages
140
- // during the stop/start window instead of routing them to
141
- // half-reset handlers. Restored to true after start() completes.
142
- this.initialized = false;
143
- await Promise.all(Array.from(this.handlers.values()).map((h) => h.stop().catch(() => { })));
144
- }
145
- // Recompute the active timeout map from scratch so a prior init's
146
- // keys cannot linger after re-init with a smaller map.
147
- this.messageTimeoutOverrides = {
148
- ...this.constructorTimeoutOverrides,
149
- ...(config.messageTimeouts ?? {}),
150
- };
151
- const services = await this.buildServicesFn(config);
152
- // Start all handlers
153
- for (const updater of this.handlers.values()) {
154
- if (this.debug)
155
- console.log(`Starting updater: ${updater.messageTag}`);
156
- await updater.start(services, {
157
- walletRepository: this.walletRepository,
158
- });
159
- }
160
- // Kick off scheduler
161
- this.scheduleNextTick();
162
- this.initialized = true;
163
- }
164
- async buildServices(config) {
165
- const arkProvider = new ark_1.RestArkProvider(config.arkServer.url);
166
- const storage = {
167
- walletRepository: this.walletRepository,
168
- contractRepository: this.contractRepository,
169
- };
170
- const delegatorProvider = config.delegatorUrl
171
- ? new delegator_1.RestDelegatorProvider(config.delegatorUrl)
172
- : undefined;
173
- const serialized = (0, identity_1.normalizeSerializedIdentity)(config.wallet);
174
- if ((0, identity_1.isSigningSerialized)(serialized)) {
175
- const identity = (0, identity_1.hydrateIdentity)(serialized);
176
- const wallet = await wallet_1.Wallet.create({
177
- identity,
178
- arkServerUrl: config.arkServer.url,
179
- arkServerPublicKey: config.arkServer.publicKey,
180
- indexerUrl: config.indexerUrl,
181
- esploraUrl: config.esploraUrl,
182
- storage,
183
- delegatorProvider,
184
- settlementConfig: config.settlementConfig,
185
- watcherConfig: config.watcherConfig,
186
- });
187
- return { wallet, arkProvider, readonlyWallet: wallet };
188
- }
189
- const identity = (0, identity_1.hydrateIdentity)(serialized);
190
- const readonlyWallet = await wallet_1.ReadonlyWallet.create({
191
- identity,
192
- arkServerUrl: config.arkServer.url,
193
- arkServerPublicKey: config.arkServer.publicKey,
194
- indexerUrl: config.indexerUrl,
195
- esploraUrl: config.esploraUrl,
196
- storage,
197
- delegatorProvider,
198
- watcherConfig: config.watcherConfig,
199
- });
200
- return { readonlyWallet, arkProvider };
201
- }
202
- onMessage(event) {
203
- // Keep the service worker alive while async work is pending.
204
- // Without this, the browser may terminate the SW mid-operation,
205
- // causing all pending responses to be lost silently.
206
- const promise = this.processMessage(event);
207
- if (typeof event.waitUntil === "function") {
208
- event.waitUntil(promise);
209
- }
210
- return promise;
211
- }
212
- async processMessage(event) {
213
- const { id, tag, broadcast } = event.data;
214
- if (tag === "PING") {
215
- this.deliverResponse(event.source, { id, tag: "PONG" }, { id, tag: "PONG" });
216
- return;
217
- }
218
- if (tag === "INITIALIZE_MESSAGE_BUS") {
219
- if (this.debug) {
220
- console.log("Init Command received");
221
- }
222
- // Intentionally not wrapped with withTimeout: initialization
223
- // performs network calls (buildServices) and handler startup
224
- // that may legitimately exceed the message timeout.
225
- await this.waitForInit(event.data.config);
226
- this.deliverResponse(event.source, { id, tag }, { id, tag });
227
- if (this.debug) {
228
- console.log("MessageBus initialized");
229
- }
230
- return;
231
- }
232
- if (!this.initialized) {
233
- if (this.debug)
234
- console.warn("Event received before initialization, dropping", event.data);
235
- // Send error response so the caller's promise rejects instead of
236
- // hanging forever. This happens when the browser kills and restarts
237
- // the service worker — the new instance has initialized=false and
238
- // messages arrive before INITIALIZE_MESSAGE_BUS is re-sent.
239
- const fallbackTag = tag ?? "unknown";
240
- this.deliverResponse(event.source, {
241
- id,
242
- tag: fallbackTag,
243
- error: new errors_1.MessageBusNotInitializedError(),
244
- }, { id, tag: fallbackTag });
245
- return;
246
- }
247
- if (!id || !tag) {
248
- if (this.debug)
249
- console.error("Invalid message received, missing required fields:", event.data);
250
- const fallbackTag = tag ?? "unknown";
251
- this.deliverResponse(event.source, {
252
- id,
253
- tag: fallbackTag,
254
- error: new TypeError("Invalid message received, missing required fields"),
255
- }, { id, tag: fallbackTag });
256
- return;
257
- }
258
- const messageType = this.extractMessageType(event.data);
259
- if (broadcast) {
260
- const updaters = Array.from(this.handlers.values());
261
- const entries = updaters.map((updater) => {
262
- const label = this.labelFor(messageType, updater.messageTag);
263
- const timeoutMs = this.resolveTimeoutMs(messageType, updater.messageTag);
264
- const handlerPromise = updater.handleMessage(event.data);
265
- const raced = updater.isLongRunning?.(event.data)
266
- ? handlerPromise
267
- : this.withTimeout(handlerPromise, timeoutMs, label);
268
- return { updater, handlerPromise, raced };
269
- });
270
- const results = await Promise.allSettled(entries.map((e) => e.raced));
271
- results.forEach((result, index) => {
272
- const { updater, handlerPromise } = entries[index];
273
- const handlerTag = updater.messageTag;
274
- const context = { id, tag: handlerTag, messageType };
275
- if (result.status === "fulfilled") {
276
- const response = result.value;
277
- // Always deliver a response so the caller's message id
278
- // never goes silent. Handlers returning null/undefined
279
- // get an explicit ack envelope.
280
- this.deliverResponse(event.source, response ?? { id, tag: handlerTag }, context);
281
- }
282
- else {
283
- if (this.debug)
284
- console.error(`[${handlerTag}] handleMessage failed`, result.reason);
285
- const error = toError(result.reason);
286
- this.deliverResponse(event.source, { id, tag: handlerTag, error }, context);
287
- // If the error was a timeout, keep watching the
288
- // underlying handler and surface its eventual result
289
- // under the same id.
290
- if (result.reason instanceof errors_1.ServiceWorkerTimeoutError) {
291
- this.attachLateDelivery(handlerPromise, event.source, id, handlerTag, messageType);
292
- }
293
- }
294
- });
295
- return;
296
- }
297
- const updater = this.handlers.get(tag);
298
- if (!updater) {
299
- if (this.debug)
300
- console.warn(`[${tag}] unknown message tag, ignoring message`);
301
- this.deliverResponse(event.source, {
302
- id,
303
- tag,
304
- error: new Error(`Unknown handler tag: ${tag}`),
305
- }, { id, tag, messageType });
306
- return;
307
- }
308
- const label = this.labelFor(messageType, tag);
309
- const timeoutMs = this.resolveTimeoutMs(messageType, tag);
310
- const handlerPromise = updater.handleMessage(event.data);
311
- const context = { id, tag, messageType };
312
- try {
313
- const response = updater.isLongRunning?.(event.data)
314
- ? await handlerPromise
315
- : await this.withTimeout(handlerPromise, timeoutMs, label);
316
- if (this.debug)
317
- console.log(`[${tag}] outgoing response:`, response);
318
- // Always deliver a response so the caller's message id never
319
- // goes silent. A handler returning null/undefined yields an
320
- // explicit ack envelope.
321
- this.deliverResponse(event.source, response ?? { id, tag }, context);
322
- }
323
- catch (err) {
324
- if (this.debug)
325
- console.error(`[${tag}] handleMessage failed`, err);
326
- const error = toError(err);
327
- this.deliverResponse(event.source, { id, tag, error }, context);
328
- // When we abandoned the handler via timeout, keep watching it
329
- // so the client's message id eventually gets a final response.
330
- if (err instanceof errors_1.ServiceWorkerTimeoutError) {
331
- this.attachLateDelivery(handlerPromise, event.source, id, tag, messageType);
332
- }
333
- }
334
- }
335
- /**
336
- * Race `promise` against a timeout. Note: this does NOT cancel the
337
- * underlying work — the original promise keeps running. Call
338
- * `attachLateDelivery` after catching the timeout to surface the
339
- * eventual result so the message id does not go silent.
340
- */
341
- withTimeout(promise, timeoutMs, label) {
342
- if (timeoutMs <= 0)
343
- return promise;
344
- return new Promise((resolve, reject) => {
345
- const timer = self.setTimeout(() => {
346
- reject(new errors_1.ServiceWorkerTimeoutError(`Message handler timed out after ${timeoutMs}ms (${label})`));
347
- }, timeoutMs);
348
- promise.then((val) => {
349
- self.clearTimeout(timer);
350
- resolve(val);
351
- }, (err) => {
352
- self.clearTimeout(timer);
353
- reject(err);
354
- });
355
- });
356
- }
357
- /**
358
- * Extract the declared `type` from a request envelope (e.g. "SETTLE").
359
- * Not every envelope carries a type (PING/INIT are special cased
360
- * earlier), so this returns undefined for envelopes that lack one.
361
- */
362
- extractMessageType(data) {
363
- const maybeType = data.type;
364
- return typeof maybeType === "string" ? maybeType : undefined;
365
- }
366
- /**
367
- * Resolve the timeout for an operation. Message-type overrides take
368
- * precedence over handler-tag overrides, with the bus-wide default
369
- * (`messageTimeoutMs`) as the final fallback.
370
- */
371
- resolveTimeoutMs(messageType, handlerTag) {
372
- if (messageType &&
373
- Object.prototype.hasOwnProperty.call(this.messageTimeoutOverrides, messageType)) {
374
- return this.messageTimeoutOverrides[messageType];
375
- }
376
- if (Object.prototype.hasOwnProperty.call(this.messageTimeoutOverrides, handlerTag)) {
377
- return this.messageTimeoutOverrides[handlerTag];
378
- }
379
- return this.messageTimeoutMs;
380
- }
381
- /**
382
- * Build a human-readable label for timeout errors. Format:
383
- * `"<MESSAGE_TYPE> via <HANDLER_TAG>"` when both are known, else the
384
- * handler tag alone. Used so timeout errors name the operation the
385
- * client actually triggered (e.g. SETTLE) rather than just the
386
- * handler that received it (e.g. WALLET_UPDATER).
387
- */
388
- labelFor(messageType, handlerTag) {
389
- return messageType ? `${messageType} via ${handlerTag}` : handlerTag;
390
- }
391
- /**
392
- * Post a response to the originating client. When `source` is null
393
- * (client tab closed, detached frame, etc.) the response cannot be
394
- * delivered; we log the drop in debug mode so it is not invisible.
395
- */
396
- deliverResponse(source, response, context) {
397
- if (!source) {
398
- if (this.debug)
399
- console.warn(`[${context.tag}] cannot deliver response: event.source is null`, {
400
- id: context.id,
401
- messageType: context.messageType,
402
- });
403
- return;
404
- }
405
- source.postMessage(response);
406
- }
407
- /**
408
- * After a handler times out the client has already received a timeout
409
- * error, but the handler keeps running. Attach a follow-up so the
410
- * handler's eventual result (or error) is delivered under the same
411
- * message id, or — if the handler never completes within
412
- * {@link LATE_DELIVERY_GRACE_MS} — an "Operation abandoned" error is
413
- * sent so the client's listener (if still attached) does not hang.
414
- */
415
- attachLateDelivery(handlerPromise, source, id, tag, messageType) {
416
- const context = { id, tag, messageType };
417
- const record = {
418
- settled: false,
419
- deadline: self.setTimeout(() => {
420
- if (record.settled)
421
- return;
422
- record.settled = true;
423
- this.lateDeliveries.delete(record);
424
- this.deliverResponse(source, {
425
- id,
426
- tag,
427
- error: new Error(`Operation abandoned: handler did not complete within ${LATE_DELIVERY_GRACE_MS}ms after timeout (${this.labelFor(messageType, tag)})`),
428
- }, context);
429
- }, LATE_DELIVERY_GRACE_MS),
430
- };
431
- this.lateDeliveries.add(record);
432
- handlerPromise.then((response) => {
433
- if (record.settled)
434
- return;
435
- record.settled = true;
436
- self.clearTimeout(record.deadline);
437
- this.lateDeliveries.delete(record);
438
- this.deliverResponse(source, response ?? { id, tag }, context);
439
- }, (err) => {
440
- if (record.settled)
441
- return;
442
- record.settled = true;
443
- self.clearTimeout(record.deadline);
444
- this.lateDeliveries.delete(record);
445
- this.deliverResponse(source, { id, tag, error: toError(err) }, context);
446
- });
447
- }
448
- /**
449
- * Returns the registered SW for the path.
450
- * It uses the functions in `service-worker-manager.ts` module.
451
- * @param path
452
- * @return the Service Worker
453
- * @throws if not running in a browser environment
454
- */
455
- static async getServiceWorker(path) {
456
- return (0, service_worker_manager_1.getActiveServiceWorker)(path);
457
- }
458
- /**
459
- * Set up and register the Service Worker, ensuring it's done once at most.
460
- * It uses the functions in `service-worker-manager.ts` module.
461
- * @param path
462
- * @return the Service Worker
463
- * @throws if not running in a browser environment
464
- */
465
- static async setup(path) {
466
- await (0, service_worker_manager_1.setupServiceWorkerOnce)(path);
467
- return (0, service_worker_manager_1.getActiveServiceWorker)(path);
468
- }
469
- }
470
- exports.MessageBus = MessageBus;
471
- function toError(value) {
472
- return value instanceof Error ? value : new Error(String(value));
473
- }
@@ -1 +0,0 @@
1
- export { AsyncStorageAdapter } from "../storage/asyncStorage.js";
@@ -1,3 +0,0 @@
1
- // Expo adapter for React Native/Expo environments
2
- export { ExpoArkProvider } from "../providers/expoArk.js";
3
- export { ExpoIndexerProvider } from "../providers/expoIndexer.js";
@@ -1 +0,0 @@
1
- export { FileSystemStorageAdapter } from "../storage/fileSystem.js";
@@ -1 +0,0 @@
1
- export { IndexedDBStorageAdapter } from "../storage/indexedDB.js";
@@ -1 +0,0 @@
1
- export { LocalStorageAdapter } from "../storage/localStorage.js";
@@ -1,40 +0,0 @@
1
- import { Environment } from "@marcbachmann/cel-js";
2
- /**
3
- * Variable names used in CEL expressions
4
- */
5
- export const AmountVariableName = "amount";
6
- export const ExpiryVariableName = "expiry";
7
- export const BirthVariableName = "birth";
8
- export const WeightVariableName = "weight";
9
- export const InputTypeVariableName = "inputType";
10
- export const OutputScriptVariableName = "script";
11
- const nowFunction = {
12
- signature: "now(): double",
13
- implementation: () => Math.floor(Date.now() / 1000),
14
- };
15
- /**
16
- * IntentOutputEnv is the CEL environment for output fee calculation
17
- * Variables: amount, script
18
- */
19
- export const IntentOutputEnv = new Environment()
20
- .registerVariable(AmountVariableName, "double")
21
- .registerVariable(OutputScriptVariableName, "string")
22
- .registerFunction(nowFunction.signature, nowFunction.implementation);
23
- /**
24
- * IntentOffchainInputEnv is the CEL environment for offchain input fee calculation
25
- * Variables: amount, expiry, birth, weight, inputType
26
- */
27
- export const IntentOffchainInputEnv = new Environment()
28
- .registerVariable(AmountVariableName, "double")
29
- .registerVariable(ExpiryVariableName, "double")
30
- .registerVariable(BirthVariableName, "double")
31
- .registerVariable(WeightVariableName, "double")
32
- .registerVariable(InputTypeVariableName, "string")
33
- .registerFunction(nowFunction.signature, nowFunction.implementation);
34
- /**
35
- * IntentOnchainInputEnv is the CEL environment for onchain input fee calculation
36
- * Variables: amount
37
- */
38
- export const IntentOnchainInputEnv = new Environment()
39
- .registerVariable(AmountVariableName, "double")
40
- .registerFunction(nowFunction.signature, nowFunction.implementation);
@@ -1,139 +0,0 @@
1
- import { IntentOffchainInputEnv, IntentOnchainInputEnv, IntentOutputEnv, } from "./celenv.js";
2
- import { FeeAmount, } from "./types.js";
3
- /**
4
- * Estimator evaluates CEL expressions to calculate fees for Arkade intents
5
- */
6
- export class Estimator {
7
- /**
8
- * Creates a new Estimator with the given config
9
- * @param config - Configuration containing CEL programs for fee calculation
10
- */
11
- constructor(config) {
12
- this.config = config;
13
- this.intentOffchainInput = config.offchainInput
14
- ? parseProgram(config.offchainInput, IntentOffchainInputEnv)
15
- : undefined;
16
- this.intentOnchainInput = config.onchainInput
17
- ? parseProgram(config.onchainInput, IntentOnchainInputEnv)
18
- : undefined;
19
- this.intentOffchainOutput = config.offchainOutput
20
- ? parseProgram(config.offchainOutput, IntentOutputEnv)
21
- : undefined;
22
- this.intentOnchainOutput = config.onchainOutput
23
- ? parseProgram(config.onchainOutput, IntentOutputEnv)
24
- : undefined;
25
- }
26
- /**
27
- * Evaluates the fee for a given vtxo input
28
- * @param input - The offchain input to evaluate
29
- * @returns The fee amount for this input
30
- */
31
- evalOffchainInput(input) {
32
- if (!this.intentOffchainInput) {
33
- return FeeAmount.ZERO;
34
- }
35
- const args = inputToArgs(input);
36
- return new FeeAmount(this.intentOffchainInput.program(args));
37
- }
38
- /**
39
- * Evaluates the fee for a given boarding input
40
- * @param input - The onchain input to evaluate
41
- * @returns The fee amount for this input
42
- */
43
- evalOnchainInput(input) {
44
- if (!this.intentOnchainInput) {
45
- return FeeAmount.ZERO;
46
- }
47
- const args = {
48
- amount: Number(input.amount),
49
- };
50
- return new FeeAmount(this.intentOnchainInput.program(args));
51
- }
52
- /**
53
- * Evaluates the fee for a given vtxo output
54
- * @param output - The output to evaluate
55
- * @returns The fee amount for this output
56
- */
57
- evalOffchainOutput(output) {
58
- if (!this.intentOffchainOutput) {
59
- return FeeAmount.ZERO;
60
- }
61
- const args = outputToArgs(output);
62
- return new FeeAmount(this.intentOffchainOutput.program(args));
63
- }
64
- /**
65
- * Evaluates the fee for a given collaborative exit output
66
- * @param output - The output to evaluate
67
- * @returns The fee amount for this output
68
- */
69
- evalOnchainOutput(output) {
70
- if (!this.intentOnchainOutput) {
71
- return FeeAmount.ZERO;
72
- }
73
- const args = outputToArgs(output);
74
- return new FeeAmount(this.intentOnchainOutput.program(args));
75
- }
76
- /**
77
- * Evaluates the fee for a given set of inputs and outputs
78
- * @param offchainInputs - Array of offchain inputs to evaluate
79
- * @param onchainInputs - Array of onchain inputs to evaluate
80
- * @param offchainOutputs - Array of offchain outputs to evaluate
81
- * @param onchainOutputs - Array of onchain outputs to evaluate
82
- * @returns The total fee amount
83
- */
84
- eval(offchainInputs, onchainInputs, offchainOutputs, onchainOutputs) {
85
- let fee = FeeAmount.ZERO;
86
- for (const input of offchainInputs) {
87
- fee = fee.add(this.evalOffchainInput(input));
88
- }
89
- for (const input of onchainInputs) {
90
- fee = fee.add(this.evalOnchainInput(input));
91
- }
92
- for (const output of offchainOutputs) {
93
- fee = fee.add(this.evalOffchainOutput(output));
94
- }
95
- for (const output of onchainOutputs) {
96
- fee = fee.add(this.evalOnchainOutput(output));
97
- }
98
- return fee;
99
- }
100
- }
101
- function inputToArgs(input) {
102
- const args = {
103
- amount: Number(input.amount),
104
- inputType: input.type,
105
- weight: input.weight,
106
- };
107
- if (input.expiry) {
108
- args.expiry = Math.floor(input.expiry.getTime() / 1000);
109
- }
110
- if (input.birth) {
111
- args.birth = Math.floor(input.birth.getTime() / 1000);
112
- }
113
- return args;
114
- }
115
- function outputToArgs(output) {
116
- return {
117
- amount: Number(output.amount),
118
- script: output.script,
119
- };
120
- }
121
- /**
122
- * Parses a CEL program and validates its return type
123
- * @param text - The CEL program text to parse
124
- * @param env - The CEL environment to use
125
- * @returns parsed and validated program
126
- */
127
- function parseProgram(text, env) {
128
- const program = env.parse(text);
129
- // Type check the program
130
- const checkResult = program.check();
131
- if (!checkResult.valid) {
132
- throw new Error(`type check failed: ${checkResult.error?.message ?? "unknown error"}`);
133
- }
134
- // Verify return type is double
135
- if (checkResult.type !== "double") {
136
- throw new Error(`expected return type double, got ${checkResult.type}`);
137
- }
138
- return { program, text };
139
- }
@@ -1 +0,0 @@
1
- export { Estimator } from "./estimator.js";