@arkade-os/sdk 0.4.27 → 0.4.29

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 (532) hide show
  1. package/README.md +45 -116
  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-ChhTwpLf.d.cts +3892 -0
  33. package/dist/ark-ChhTwpLf.d.ts +3892 -0
  34. package/dist/asyncStorageTaskQueue-DW1-BpI7.d.cts +49 -0
  35. package/dist/{types/worker/expo/asyncStorageTaskQueue.d.ts → asyncStorageTaskQueue-DZ0nUuEJ.d.ts} +6 -3
  36. package/dist/chunk-5BLDMQED.cjs +18 -0
  37. package/dist/chunk-5BLDMQED.cjs.map +1 -0
  38. package/dist/chunk-6FLL2Q36.cjs +2701 -0
  39. package/dist/chunk-6FLL2Q36.cjs.map +1 -0
  40. package/dist/chunk-6NWNOLL3.js +2671 -0
  41. package/dist/chunk-6NWNOLL3.js.map +1 -0
  42. package/dist/chunk-ABWRLTX5.js +210 -0
  43. package/dist/chunk-ABWRLTX5.js.map +1 -0
  44. package/dist/chunk-BVP2U66Q.js +13943 -0
  45. package/dist/chunk-BVP2U66Q.js.map +1 -0
  46. package/dist/chunk-GDCTOSMV.cjs +14058 -0
  47. package/dist/chunk-GDCTOSMV.cjs.map +1 -0
  48. package/dist/chunk-GIGILVVP.cjs +213 -0
  49. package/dist/chunk-GIGILVVP.cjs.map +1 -0
  50. package/dist/chunk-IEO3XDKI.cjs +838 -0
  51. package/dist/chunk-IEO3XDKI.cjs.map +1 -0
  52. package/dist/chunk-NSBPE2FW.js +15 -0
  53. package/dist/chunk-NSBPE2FW.js.map +1 -0
  54. package/dist/chunk-PJUFOJ2L.cjs +100 -0
  55. package/dist/chunk-PJUFOJ2L.cjs.map +1 -0
  56. package/dist/chunk-TH6T23XG.js +95 -0
  57. package/dist/chunk-TH6T23XG.js.map +1 -0
  58. package/dist/chunk-TU3LVAPX.js +769 -0
  59. package/dist/chunk-TU3LVAPX.js.map +1 -0
  60. package/dist/chunk-WMIPYZSB.cjs +803 -0
  61. package/dist/chunk-WMIPYZSB.cjs.map +1 -0
  62. package/dist/chunk-YA4G7RFB.js +829 -0
  63. package/dist/chunk-YA4G7RFB.js.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-4JBUkUhR.d.cts +84 -0
  71. package/dist/delegate-DN7RELL1.d.ts +84 -0
  72. package/dist/{types/storage/index.d.ts → index-C0IanN1m.d.cts} +3 -1
  73. package/dist/index-C0IanN1m.d.ts +11 -0
  74. package/dist/index-Cn82bBUu.d.ts +199 -0
  75. package/dist/index-DfT5xzgY.d.cts +199 -0
  76. package/dist/index.cjs +504 -0
  77. package/dist/index.cjs.map +1 -0
  78. package/dist/index.d.cts +3469 -0
  79. package/dist/index.d.ts +3469 -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-B-aPfHhK.d.cts +114 -0
  95. package/dist/taskRunner-B-vG08pX.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 +175 -0
  103. package/dist/wallet/expo/index.cjs.map +1 -0
  104. package/dist/wallet/expo/index.d.cts +124 -0
  105. package/dist/wallet/expo/index.d.ts +124 -0
  106. package/dist/wallet/expo/index.js +173 -0
  107. package/dist/wallet/expo/index.js.map +1 -0
  108. package/dist/wallet-CCtqT2Wb.d.ts +778 -0
  109. package/dist/wallet-DjgFb_4T.d.cts +778 -0
  110. package/dist/worker/expo/index.cjs +140 -0
  111. package/dist/worker/expo/index.cjs.map +1 -0
  112. package/dist/worker/expo/index.d.cts +29 -0
  113. package/dist/worker/expo/index.d.ts +29 -0
  114. package/dist/worker/expo/index.js +121 -0
  115. package/dist/worker/expo/index.js.map +1 -0
  116. package/package.json +110 -76
  117. package/dist/cjs/adapters/asyncStorage.js +0 -5
  118. package/dist/cjs/adapters/expo.js +0 -8
  119. package/dist/cjs/adapters/fileSystem.js +0 -5
  120. package/dist/cjs/adapters/indexedDB.js +0 -5
  121. package/dist/cjs/adapters/localStorage.js +0 -5
  122. package/dist/cjs/arkfee/celenv.js +0 -43
  123. package/dist/cjs/arkfee/estimator.js +0 -143
  124. package/dist/cjs/arkfee/index.js +0 -5
  125. package/dist/cjs/arkfee/types.js +0 -26
  126. package/dist/cjs/arknote/index.js +0 -128
  127. package/dist/cjs/bip322/index.js +0 -270
  128. package/dist/cjs/contracts/arkcontract.js +0 -147
  129. package/dist/cjs/contracts/contractManager.js +0 -649
  130. package/dist/cjs/contracts/contractWatcher.js +0 -598
  131. package/dist/cjs/contracts/handlers/default.js +0 -93
  132. package/dist/cjs/contracts/handlers/delegate.js +0 -90
  133. package/dist/cjs/contracts/handlers/helpers.js +0 -115
  134. package/dist/cjs/contracts/handlers/index.js +0 -19
  135. package/dist/cjs/contracts/handlers/registry.js +0 -89
  136. package/dist/cjs/contracts/handlers/vhtlc.js +0 -194
  137. package/dist/cjs/contracts/index.js +0 -41
  138. package/dist/cjs/contracts/types.js +0 -2
  139. package/dist/cjs/contracts/vtxoOwnership.js +0 -78
  140. package/dist/cjs/extension/asset/assetGroup.js +0 -228
  141. package/dist/cjs/extension/asset/assetId.js +0 -152
  142. package/dist/cjs/extension/asset/assetInput.js +0 -222
  143. package/dist/cjs/extension/asset/assetOutput.js +0 -174
  144. package/dist/cjs/extension/asset/assetRef.js +0 -148
  145. package/dist/cjs/extension/asset/index.js +0 -23
  146. package/dist/cjs/extension/asset/metadata.js +0 -187
  147. package/dist/cjs/extension/asset/packet.js +0 -114
  148. package/dist/cjs/extension/asset/types.js +0 -22
  149. package/dist/cjs/extension/asset/utils.js +0 -105
  150. package/dist/cjs/extension/index.js +0 -254
  151. package/dist/cjs/extension/packet.js +0 -20
  152. package/dist/cjs/forfeit.js +0 -45
  153. package/dist/cjs/identity/descriptor.js +0 -169
  154. package/dist/cjs/identity/descriptorProvider.js +0 -2
  155. package/dist/cjs/identity/hdCapableIdentity.js +0 -20
  156. package/dist/cjs/identity/index.js +0 -40
  157. package/dist/cjs/identity/seedIdentity.js +0 -477
  158. package/dist/cjs/identity/serialize.js +0 -171
  159. package/dist/cjs/identity/singleKey.js +0 -126
  160. package/dist/cjs/identity/staticDescriptorProvider.js +0 -65
  161. package/dist/cjs/index.js +0 -202
  162. package/dist/cjs/intent/index.js +0 -259
  163. package/dist/cjs/musig2/index.js +0 -11
  164. package/dist/cjs/musig2/keys.js +0 -57
  165. package/dist/cjs/musig2/nonces.js +0 -48
  166. package/dist/cjs/musig2/sign.js +0 -102
  167. package/dist/cjs/networks.js +0 -26
  168. package/dist/cjs/package.json +0 -3
  169. package/dist/cjs/providers/ark.js +0 -577
  170. package/dist/cjs/providers/delegator.js +0 -85
  171. package/dist/cjs/providers/electrum.js +0 -869
  172. package/dist/cjs/providers/errors.js +0 -59
  173. package/dist/cjs/providers/expoArk.js +0 -82
  174. package/dist/cjs/providers/expoIndexer.js +0 -111
  175. package/dist/cjs/providers/expoUtils.js +0 -124
  176. package/dist/cjs/providers/indexer.js +0 -630
  177. package/dist/cjs/providers/onchain.js +0 -262
  178. package/dist/cjs/providers/utils.js +0 -121
  179. package/dist/cjs/repositories/contractRepository.js +0 -2
  180. package/dist/cjs/repositories/inMemory/contractRepository.js +0 -55
  181. package/dist/cjs/repositories/inMemory/walletRepository.js +0 -115
  182. package/dist/cjs/repositories/index.js +0 -34
  183. package/dist/cjs/repositories/indexedDB/contractRepository.js +0 -187
  184. package/dist/cjs/repositories/indexedDB/db.js +0 -19
  185. package/dist/cjs/repositories/indexedDB/manager.js +0 -100
  186. package/dist/cjs/repositories/indexedDB/schema.js +0 -204
  187. package/dist/cjs/repositories/indexedDB/walletRepository.js +0 -474
  188. package/dist/cjs/repositories/indexedDB/websqlAdapter.js +0 -144
  189. package/dist/cjs/repositories/migrations/contractRepositoryImpl.js +0 -127
  190. package/dist/cjs/repositories/migrations/fromStorageAdapter.js +0 -66
  191. package/dist/cjs/repositories/migrations/walletRepositoryImpl.js +0 -184
  192. package/dist/cjs/repositories/realm/contractRepository.js +0 -116
  193. package/dist/cjs/repositories/realm/index.js +0 -11
  194. package/dist/cjs/repositories/realm/schemas.js +0 -157
  195. package/dist/cjs/repositories/realm/types.js +0 -7
  196. package/dist/cjs/repositories/realm/walletRepository.js +0 -305
  197. package/dist/cjs/repositories/scriptFromAddress.js +0 -16
  198. package/dist/cjs/repositories/serialization.js +0 -82
  199. package/dist/cjs/repositories/sqlite/contractRepository.js +0 -135
  200. package/dist/cjs/repositories/sqlite/index.js +0 -7
  201. package/dist/cjs/repositories/sqlite/types.js +0 -2
  202. package/dist/cjs/repositories/sqlite/walletRepository.js +0 -441
  203. package/dist/cjs/repositories/walletRepository.js +0 -2
  204. package/dist/cjs/script/address.js +0 -108
  205. package/dist/cjs/script/base.js +0 -185
  206. package/dist/cjs/script/default.js +0 -57
  207. package/dist/cjs/script/delegate.js +0 -53
  208. package/dist/cjs/script/tapscript.js +0 -619
  209. package/dist/cjs/script/vhtlc.js +0 -170
  210. package/dist/cjs/storage/asyncStorage.js +0 -50
  211. package/dist/cjs/storage/fileSystem.js +0 -141
  212. package/dist/cjs/storage/inMemory.js +0 -24
  213. package/dist/cjs/storage/index.js +0 -2
  214. package/dist/cjs/storage/indexedDB.js +0 -101
  215. package/dist/cjs/storage/localStorage.js +0 -51
  216. package/dist/cjs/tree/signingSession.js +0 -229
  217. package/dist/cjs/tree/txTree.js +0 -192
  218. package/dist/cjs/tree/validation.js +0 -107
  219. package/dist/cjs/utils/anchor.js +0 -35
  220. package/dist/cjs/utils/arkTransaction.js +0 -271
  221. package/dist/cjs/utils/bip21.js +0 -127
  222. package/dist/cjs/utils/syncCursors.js +0 -128
  223. package/dist/cjs/utils/timelock.js +0 -59
  224. package/dist/cjs/utils/transaction.js +0 -28
  225. package/dist/cjs/utils/transactionHistory.js +0 -183
  226. package/dist/cjs/utils/txSizeEstimator.js +0 -132
  227. package/dist/cjs/utils/unknownFields.js +0 -174
  228. package/dist/cjs/wallet/asset-manager.js +0 -330
  229. package/dist/cjs/wallet/asset.js +0 -119
  230. package/dist/cjs/wallet/batch.js +0 -183
  231. package/dist/cjs/wallet/delegator.js +0 -308
  232. package/dist/cjs/wallet/expo/background.js +0 -116
  233. package/dist/cjs/wallet/expo/index.js +0 -9
  234. package/dist/cjs/wallet/expo/wallet.js +0 -230
  235. package/dist/cjs/wallet/hdDescriptorProvider.js +0 -188
  236. package/dist/cjs/wallet/index.js +0 -82
  237. package/dist/cjs/wallet/inputSignerRouter.js +0 -98
  238. package/dist/cjs/wallet/onchain.js +0 -290
  239. package/dist/cjs/wallet/ramps.js +0 -216
  240. package/dist/cjs/wallet/serviceWorker/wallet-message-handler.js +0 -953
  241. package/dist/cjs/wallet/serviceWorker/wallet.js +0 -1174
  242. package/dist/cjs/wallet/signingErrors.js +0 -32
  243. package/dist/cjs/wallet/unroll.js +0 -293
  244. package/dist/cjs/wallet/utils.js +0 -111
  245. package/dist/cjs/wallet/validation.js +0 -154
  246. package/dist/cjs/wallet/vtxo-manager.js +0 -1142
  247. package/dist/cjs/wallet/wallet.js +0 -2195
  248. package/dist/cjs/wallet/walletReceiveRotator.js +0 -547
  249. package/dist/cjs/worker/browser/service-worker-manager.js +0 -183
  250. package/dist/cjs/worker/browser/utils.js +0 -67
  251. package/dist/cjs/worker/errors.js +0 -16
  252. package/dist/cjs/worker/expo/asyncStorageTaskQueue.js +0 -78
  253. package/dist/cjs/worker/expo/index.js +0 -13
  254. package/dist/cjs/worker/expo/processors/contractPollProcessor.js +0 -62
  255. package/dist/cjs/worker/expo/processors/index.js +0 -6
  256. package/dist/cjs/worker/expo/taskQueue.js +0 -41
  257. package/dist/cjs/worker/expo/taskRunner.js +0 -73
  258. package/dist/cjs/worker/messageBus.js +0 -474
  259. package/dist/esm/adapters/asyncStorage.js +0 -1
  260. package/dist/esm/adapters/expo.js +0 -3
  261. package/dist/esm/adapters/fileSystem.js +0 -1
  262. package/dist/esm/adapters/indexedDB.js +0 -1
  263. package/dist/esm/adapters/localStorage.js +0 -1
  264. package/dist/esm/arkfee/celenv.js +0 -40
  265. package/dist/esm/arkfee/estimator.js +0 -139
  266. package/dist/esm/arkfee/index.js +0 -1
  267. package/dist/esm/arkfee/types.js +0 -22
  268. package/dist/esm/arknote/index.js +0 -124
  269. package/dist/esm/bip322/index.js +0 -267
  270. package/dist/esm/contracts/arkcontract.js +0 -140
  271. package/dist/esm/contracts/contractManager.js +0 -645
  272. package/dist/esm/contracts/contractWatcher.js +0 -594
  273. package/dist/esm/contracts/handlers/default.js +0 -90
  274. package/dist/esm/contracts/handlers/delegate.js +0 -87
  275. package/dist/esm/contracts/handlers/helpers.js +0 -110
  276. package/dist/esm/contracts/handlers/index.js +0 -12
  277. package/dist/esm/contracts/handlers/registry.js +0 -86
  278. package/dist/esm/contracts/handlers/vhtlc.js +0 -191
  279. package/dist/esm/contracts/index.js +0 -13
  280. package/dist/esm/contracts/types.js +0 -1
  281. package/dist/esm/contracts/vtxoOwnership.js +0 -69
  282. package/dist/esm/extension/asset/assetGroup.js +0 -224
  283. package/dist/esm/extension/asset/assetId.js +0 -148
  284. package/dist/esm/extension/asset/assetInput.js +0 -217
  285. package/dist/esm/extension/asset/assetOutput.js +0 -169
  286. package/dist/esm/extension/asset/assetRef.js +0 -144
  287. package/dist/esm/extension/asset/index.js +0 -8
  288. package/dist/esm/extension/asset/metadata.js +0 -182
  289. package/dist/esm/extension/asset/packet.js +0 -110
  290. package/dist/esm/extension/asset/types.js +0 -19
  291. package/dist/esm/extension/asset/utils.js +0 -99
  292. package/dist/esm/extension/index.js +0 -248
  293. package/dist/esm/extension/packet.js +0 -16
  294. package/dist/esm/forfeit.js +0 -41
  295. package/dist/esm/identity/descriptor.js +0 -161
  296. package/dist/esm/identity/descriptorProvider.js +0 -1
  297. package/dist/esm/identity/hdCapableIdentity.js +0 -17
  298. package/dist/esm/identity/index.js +0 -13
  299. package/dist/esm/identity/seedIdentity.js +0 -469
  300. package/dist/esm/identity/serialize.js +0 -164
  301. package/dist/esm/identity/singleKey.js +0 -121
  302. package/dist/esm/identity/staticDescriptorProvider.js +0 -61
  303. package/dist/esm/index.js +0 -87
  304. package/dist/esm/intent/index.js +0 -255
  305. package/dist/esm/musig2/index.js +0 -3
  306. package/dist/esm/musig2/keys.js +0 -21
  307. package/dist/esm/musig2/nonces.js +0 -11
  308. package/dist/esm/musig2/sign.js +0 -63
  309. package/dist/esm/networks.js +0 -22
  310. package/dist/esm/package.json +0 -3
  311. package/dist/esm/providers/ark.js +0 -572
  312. package/dist/esm/providers/delegator.js +0 -81
  313. package/dist/esm/providers/electrum.js +0 -864
  314. package/dist/esm/providers/errors.js +0 -54
  315. package/dist/esm/providers/expoArk.js +0 -78
  316. package/dist/esm/providers/expoIndexer.js +0 -107
  317. package/dist/esm/providers/expoUtils.js +0 -87
  318. package/dist/esm/providers/indexer.js +0 -626
  319. package/dist/esm/providers/onchain.js +0 -258
  320. package/dist/esm/providers/utils.js +0 -117
  321. package/dist/esm/repositories/contractRepository.js +0 -1
  322. package/dist/esm/repositories/inMemory/contractRepository.js +0 -51
  323. package/dist/esm/repositories/inMemory/walletRepository.js +0 -111
  324. package/dist/esm/repositories/index.js +0 -10
  325. package/dist/esm/repositories/indexedDB/contractRepository.js +0 -183
  326. package/dist/esm/repositories/indexedDB/db.js +0 -4
  327. package/dist/esm/repositories/indexedDB/manager.js +0 -95
  328. package/dist/esm/repositories/indexedDB/schema.js +0 -199
  329. package/dist/esm/repositories/indexedDB/walletRepository.js +0 -470
  330. package/dist/esm/repositories/indexedDB/websqlAdapter.js +0 -138
  331. package/dist/esm/repositories/migrations/contractRepositoryImpl.js +0 -121
  332. package/dist/esm/repositories/migrations/fromStorageAdapter.js +0 -58
  333. package/dist/esm/repositories/migrations/walletRepositoryImpl.js +0 -180
  334. package/dist/esm/repositories/realm/contractRepository.js +0 -112
  335. package/dist/esm/repositories/realm/index.js +0 -3
  336. package/dist/esm/repositories/realm/schemas.js +0 -153
  337. package/dist/esm/repositories/realm/types.js +0 -6
  338. package/dist/esm/repositories/realm/walletRepository.js +0 -301
  339. package/dist/esm/repositories/scriptFromAddress.js +0 -13
  340. package/dist/esm/repositories/serialization.js +0 -67
  341. package/dist/esm/repositories/sqlite/contractRepository.js +0 -131
  342. package/dist/esm/repositories/sqlite/index.js +0 -2
  343. package/dist/esm/repositories/sqlite/types.js +0 -1
  344. package/dist/esm/repositories/sqlite/walletRepository.js +0 -437
  345. package/dist/esm/repositories/walletRepository.js +0 -1
  346. package/dist/esm/script/address.js +0 -104
  347. package/dist/esm/script/base.js +0 -179
  348. package/dist/esm/script/default.js +0 -54
  349. package/dist/esm/script/delegate.js +0 -50
  350. package/dist/esm/script/tapscript.js +0 -615
  351. package/dist/esm/script/vhtlc.js +0 -167
  352. package/dist/esm/storage/asyncStorage.js +0 -46
  353. package/dist/esm/storage/fileSystem.js +0 -104
  354. package/dist/esm/storage/inMemory.js +0 -20
  355. package/dist/esm/storage/index.js +0 -1
  356. package/dist/esm/storage/indexedDB.js +0 -97
  357. package/dist/esm/storage/localStorage.js +0 -47
  358. package/dist/esm/tree/signingSession.js +0 -191
  359. package/dist/esm/tree/txTree.js +0 -188
  360. package/dist/esm/tree/validation.js +0 -101
  361. package/dist/esm/utils/anchor.js +0 -31
  362. package/dist/esm/utils/arkTransaction.js +0 -264
  363. package/dist/esm/utils/bip21.js +0 -123
  364. package/dist/esm/utils/syncCursors.js +0 -119
  365. package/dist/esm/utils/timelock.js +0 -22
  366. package/dist/esm/utils/transaction.js +0 -24
  367. package/dist/esm/utils/transactionHistory.js +0 -180
  368. package/dist/esm/utils/txSizeEstimator.js +0 -128
  369. package/dist/esm/utils/unknownFields.js +0 -169
  370. package/dist/esm/wallet/asset-manager.js +0 -325
  371. package/dist/esm/wallet/asset.js +0 -113
  372. package/dist/esm/wallet/batch.js +0 -180
  373. package/dist/esm/wallet/delegator.js +0 -303
  374. package/dist/esm/wallet/expo/background.js +0 -111
  375. package/dist/esm/wallet/expo/index.js +0 -2
  376. package/dist/esm/wallet/expo/wallet.js +0 -193
  377. package/dist/esm/wallet/hdDescriptorProvider.js +0 -184
  378. package/dist/esm/wallet/index.js +0 -75
  379. package/dist/esm/wallet/inputSignerRouter.js +0 -94
  380. package/dist/esm/wallet/onchain.js +0 -285
  381. package/dist/esm/wallet/ramps.js +0 -212
  382. package/dist/esm/wallet/serviceWorker/wallet-message-handler.js +0 -946
  383. package/dist/esm/wallet/serviceWorker/wallet.js +0 -1169
  384. package/dist/esm/wallet/signingErrors.js +0 -27
  385. package/dist/esm/wallet/unroll.js +0 -289
  386. package/dist/esm/wallet/utils.js +0 -103
  387. package/dist/esm/wallet/validation.js +0 -142
  388. package/dist/esm/wallet/vtxo-manager.js +0 -1136
  389. package/dist/esm/wallet/wallet.js +0 -2186
  390. package/dist/esm/wallet/walletReceiveRotator.js +0 -540
  391. package/dist/esm/worker/browser/service-worker-manager.js +0 -177
  392. package/dist/esm/worker/browser/utils.js +0 -63
  393. package/dist/esm/worker/errors.js +0 -11
  394. package/dist/esm/worker/expo/asyncStorageTaskQueue.js +0 -74
  395. package/dist/esm/worker/expo/index.js +0 -4
  396. package/dist/esm/worker/expo/processors/contractPollProcessor.js +0 -59
  397. package/dist/esm/worker/expo/processors/index.js +0 -1
  398. package/dist/esm/worker/expo/taskQueue.js +0 -37
  399. package/dist/esm/worker/expo/taskRunner.js +0 -69
  400. package/dist/esm/worker/messageBus.js +0 -470
  401. package/dist/types/adapters/asyncStorage.d.ts +0 -2
  402. package/dist/types/adapters/expo.d.ts +0 -4
  403. package/dist/types/adapters/fileSystem.d.ts +0 -2
  404. package/dist/types/adapters/indexedDB.d.ts +0 -2
  405. package/dist/types/adapters/localStorage.d.ts +0 -2
  406. package/dist/types/arkfee/celenv.d.ts +0 -25
  407. package/dist/types/arkfee/estimator.d.ts +0 -49
  408. package/dist/types/arkfee/index.d.ts +0 -2
  409. package/dist/types/arkfee/types.d.ts +0 -38
  410. package/dist/types/arknote/index.d.ts +0 -84
  411. package/dist/types/bip322/index.d.ts +0 -55
  412. package/dist/types/contracts/arkcontract.d.ts +0 -99
  413. package/dist/types/contracts/contractManager.d.ts +0 -411
  414. package/dist/types/contracts/contractWatcher.d.ts +0 -217
  415. package/dist/types/contracts/handlers/default.d.ts +0 -19
  416. package/dist/types/contracts/handlers/delegate.d.ts +0 -21
  417. package/dist/types/contracts/handlers/helpers.d.ts +0 -19
  418. package/dist/types/contracts/handlers/index.d.ts +0 -7
  419. package/dist/types/contracts/handlers/registry.d.ts +0 -65
  420. package/dist/types/contracts/handlers/vhtlc.d.ts +0 -32
  421. package/dist/types/contracts/index.d.ts +0 -14
  422. package/dist/types/contracts/types.d.ts +0 -250
  423. package/dist/types/contracts/vtxoOwnership.d.ts +0 -33
  424. package/dist/types/extension/asset/assetGroup.d.ts +0 -119
  425. package/dist/types/extension/asset/assetId.d.ts +0 -83
  426. package/dist/types/extension/asset/assetInput.d.ts +0 -64
  427. package/dist/types/extension/asset/assetOutput.d.ts +0 -54
  428. package/dist/types/extension/asset/assetRef.d.ts +0 -91
  429. package/dist/types/extension/asset/index.d.ts +0 -8
  430. package/dist/types/extension/asset/metadata.d.ts +0 -52
  431. package/dist/types/extension/asset/packet.d.ts +0 -41
  432. package/dist/types/extension/asset/types.d.ts +0 -16
  433. package/dist/types/extension/asset/utils.d.ts +0 -21
  434. package/dist/types/extension/index.d.ts +0 -56
  435. package/dist/types/extension/packet.d.ts +0 -21
  436. package/dist/types/forfeit.d.ts +0 -18
  437. package/dist/types/identity/descriptor.d.ts +0 -61
  438. package/dist/types/identity/descriptorProvider.d.ts +0 -42
  439. package/dist/types/identity/hdCapableIdentity.d.ts +0 -71
  440. package/dist/types/identity/index.d.ts +0 -57
  441. package/dist/types/identity/seedIdentity.d.ts +0 -270
  442. package/dist/types/identity/serialize.d.ts +0 -96
  443. package/dist/types/identity/singleKey.d.ts +0 -62
  444. package/dist/types/identity/staticDescriptorProvider.d.ts +0 -18
  445. package/dist/types/index.d.ts +0 -59
  446. package/dist/types/intent/index.d.ts +0 -86
  447. package/dist/types/musig2/index.d.ts +0 -4
  448. package/dist/types/musig2/keys.d.ts +0 -9
  449. package/dist/types/musig2/nonces.d.ts +0 -14
  450. package/dist/types/musig2/sign.d.ts +0 -27
  451. package/dist/types/networks.d.ts +0 -16
  452. package/dist/types/providers/ark.d.ts +0 -369
  453. package/dist/types/providers/delegator.d.ts +0 -82
  454. package/dist/types/providers/electrum.d.ts +0 -312
  455. package/dist/types/providers/errors.d.ts +0 -13
  456. package/dist/types/providers/expoArk.d.ts +0 -22
  457. package/dist/types/providers/expoIndexer.d.ts +0 -18
  458. package/dist/types/providers/expoUtils.d.ts +0 -18
  459. package/dist/types/providers/indexer.d.ts +0 -301
  460. package/dist/types/providers/onchain.d.ts +0 -148
  461. package/dist/types/providers/utils.d.ts +0 -12
  462. package/dist/types/repositories/contractRepository.d.ts +0 -32
  463. package/dist/types/repositories/inMemory/contractRepository.d.ts +0 -17
  464. package/dist/types/repositories/inMemory/walletRepository.d.ts +0 -29
  465. package/dist/types/repositories/index.d.ts +0 -9
  466. package/dist/types/repositories/indexedDB/contractRepository.d.ts +0 -21
  467. package/dist/types/repositories/indexedDB/db.d.ts +0 -4
  468. package/dist/types/repositories/indexedDB/manager.d.ts +0 -25
  469. package/dist/types/repositories/indexedDB/schema.d.ts +0 -9
  470. package/dist/types/repositories/indexedDB/walletRepository.d.ts +0 -28
  471. package/dist/types/repositories/indexedDB/websqlAdapter.d.ts +0 -49
  472. package/dist/types/repositories/migrations/contractRepositoryImpl.d.ts +0 -24
  473. package/dist/types/repositories/migrations/fromStorageAdapter.d.ts +0 -19
  474. package/dist/types/repositories/migrations/walletRepositoryImpl.d.ts +0 -27
  475. package/dist/types/repositories/realm/contractRepository.d.ts +0 -24
  476. package/dist/types/repositories/realm/index.d.ts +0 -4
  477. package/dist/types/repositories/realm/types.d.ts +0 -16
  478. package/dist/types/repositories/realm/walletRepository.d.ts +0 -34
  479. package/dist/types/repositories/scriptFromAddress.d.ts +0 -9
  480. package/dist/types/repositories/serialization.d.ts +0 -65
  481. package/dist/types/repositories/sqlite/contractRepository.d.ts +0 -33
  482. package/dist/types/repositories/sqlite/index.d.ts +0 -3
  483. package/dist/types/repositories/sqlite/types.d.ts +0 -18
  484. package/dist/types/repositories/walletRepository.d.ts +0 -72
  485. package/dist/types/script/address.d.ts +0 -67
  486. package/dist/types/script/base.d.ts +0 -105
  487. package/dist/types/script/default.d.ts +0 -44
  488. package/dist/types/script/delegate.d.ts +0 -40
  489. package/dist/types/script/tapscript.d.ts +0 -169
  490. package/dist/types/script/vhtlc.d.ts +0 -66
  491. package/dist/types/tree/signingSession.d.ts +0 -37
  492. package/dist/types/tree/txTree.d.ts +0 -28
  493. package/dist/types/tree/validation.d.ts +0 -15
  494. package/dist/types/utils/anchor.d.ts +0 -19
  495. package/dist/types/utils/arkTransaction.d.ts +0 -49
  496. package/dist/types/utils/bip21.d.ts +0 -38
  497. package/dist/types/utils/syncCursors.d.ts +0 -60
  498. package/dist/types/utils/timelock.d.ts +0 -9
  499. package/dist/types/utils/transaction.d.ts +0 -13
  500. package/dist/types/utils/transactionHistory.d.ts +0 -15
  501. package/dist/types/utils/txSizeEstimator.d.ts +0 -40
  502. package/dist/types/utils/unknownFields.d.ts +0 -83
  503. package/dist/types/wallet/asset-manager.d.ts +0 -69
  504. package/dist/types/wallet/asset.d.ts +0 -21
  505. package/dist/types/wallet/batch.d.ts +0 -107
  506. package/dist/types/wallet/delegator.d.ts +0 -48
  507. package/dist/types/wallet/expo/background.d.ts +0 -66
  508. package/dist/types/wallet/expo/index.d.ts +0 -4
  509. package/dist/types/wallet/expo/wallet.d.ts +0 -99
  510. package/dist/types/wallet/hdDescriptorProvider.d.ts +0 -114
  511. package/dist/types/wallet/index.d.ts +0 -789
  512. package/dist/types/wallet/inputSignerRouter.d.ts +0 -35
  513. package/dist/types/wallet/onchain.d.ts +0 -109
  514. package/dist/types/wallet/ramps.d.ts +0 -64
  515. package/dist/types/wallet/serviceWorker/wallet-message-handler.d.ts +0 -543
  516. package/dist/types/wallet/serviceWorker/wallet.d.ts +0 -248
  517. package/dist/types/wallet/signingErrors.d.ts +0 -19
  518. package/dist/types/wallet/unroll.d.ts +0 -114
  519. package/dist/types/wallet/utils.d.ts +0 -36
  520. package/dist/types/wallet/validation.d.ts +0 -24
  521. package/dist/types/wallet/vtxo-manager.d.ts +0 -476
  522. package/dist/types/wallet/wallet.d.ts +0 -409
  523. package/dist/types/wallet/walletReceiveRotator.d.ts +0 -306
  524. package/dist/types/worker/browser/service-worker-manager.d.ts +0 -32
  525. package/dist/types/worker/browser/utils.d.ts +0 -17
  526. package/dist/types/worker/errors.d.ts +0 -7
  527. package/dist/types/worker/expo/index.d.ts +0 -7
  528. package/dist/types/worker/expo/processors/contractPollProcessor.d.ts +0 -19
  529. package/dist/types/worker/expo/processors/index.d.ts +0 -1
  530. package/dist/types/worker/expo/taskQueue.d.ts +0 -50
  531. package/dist/types/worker/expo/taskRunner.d.ts +0 -66
  532. package/dist/types/worker/messageBus.d.ts +0 -189
@@ -1,188 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HDDescriptorProvider = void 0;
4
- const descriptors_scure_1 = require("@bitcoinerlab/descriptors-scure");
5
- const descriptor_1 = require("../identity/descriptor");
6
- const syncCursors_1 = require("../utils/syncCursors");
7
- const walletReceiveRotator_1 = require("./walletReceiveRotator");
8
- /** Settings key under {@link WalletState.settings} where HD state lives. */
9
- const HD_SETTINGS_KEY = "hd";
10
- /**
11
- * HD-wallet {@link DescriptorProvider} that allocates a fresh signing
12
- * descriptor on every call. The provider holds no notion of "current" — it
13
- * is a pure rotating allocator. The question of "which descriptor is the
14
- * wallet currently bound to?" is answered by querying the contract
15
- * repository for active contracts, not by asking this provider.
16
- *
17
- * State is persisted under `WalletRepository.getWalletState().settings.hd` so
18
- * that no storage-schema migration is required when switching a wallet from
19
- * single-key to HD. The provider is backed by an {@link HDCapableIdentity},
20
- * which carries the wildcard account descriptor template (for derivation)
21
- * and the signing primitives.
22
- *
23
- * The read-modify-write of the persisted index runs inside the shared per-
24
- * repo `updateWalletState` mutex, so two `getNextSigningDescriptor` callers
25
- * — including those driving separate `HDDescriptorProvider` instances on
26
- * the same repo — can never observe the same index.
27
- *
28
- * @example
29
- * ```ts
30
- * const provider = await HDDescriptorProvider.create(identity, walletRepo);
31
- * const descriptor = await provider.getNextSigningDescriptor();
32
- * // descriptor: tr([fp/86'/0'/0']xpub/0/0)
33
- * const next = await provider.getNextSigningDescriptor();
34
- * // next: tr([fp/86'/0'/0']xpub/0/1)
35
- * ```
36
- */
37
- class HDDescriptorProvider {
38
- constructor(identity, walletRepository) {
39
- this.identity = identity;
40
- this.walletRepository = walletRepository;
41
- }
42
- /**
43
- * Construct an HDDescriptorProvider. No I/O is performed here;
44
- * persisted state is read lazily on the first call to
45
- * `getNextSigningDescriptor`. A descriptor-mismatch error surfaces on
46
- * first use rather than at boot.
47
- */
48
- static async create(identity, walletRepository) {
49
- return new HDDescriptorProvider(identity, walletRepository);
50
- }
51
- /**
52
- * Allocate the next descriptor and return it. The first call on a fresh
53
- * wallet returns descriptor at index 0; subsequent calls return 1, 2, 3,
54
- * ... in order. Each call is atomic with respect to other rotations on
55
- * the same repo: two concurrent callers can never observe the same
56
- * index.
57
- */
58
- async getNextSigningDescriptor() {
59
- return this.mutate((settings) => {
60
- const next = settings.lastIndexUsed === undefined
61
- ? 0
62
- : settings.lastIndexUsed + 1;
63
- settings.lastIndexUsed = next;
64
- return this.materializeAt(next);
65
- });
66
- }
67
- /**
68
- * Re-derive the descriptor at the most recently allocated index
69
- * WITHOUT advancing — i.e. read the same descriptor
70
- * `getNextSigningDescriptor` last returned. Returns `undefined`
71
- * when no descriptor has ever been allocated on this repo.
72
- *
73
- * Used by the boot path to keep the wallet's display address
74
- * stable across restarts: when no tagged display contract exists
75
- * (e.g. a fresh wallet that hasn't rotated yet, or a wallet whose
76
- * baseline-only repo carries no rotation history), the boot should
77
- * re-derive the existing index rather than burn a new one.
78
- */
79
- async getCurrentSigningDescriptor() {
80
- const state = await this.walletRepository.getWalletState();
81
- const settings = this.parseSettings(state ?? {});
82
- if (settings.lastIndexUsed === undefined)
83
- return undefined;
84
- return this.materializeAt(settings.lastIndexUsed);
85
- }
86
- /**
87
- * Returns true when the given descriptor is derivable from this wallet's
88
- * seed. Delegates to the underlying identity, which handles both HD and
89
- * simple `tr(pubkey)` descriptors.
90
- */
91
- isOurs(descriptor) {
92
- return this.identity.isOurs(descriptor);
93
- }
94
- /**
95
- * Signs each request with the key derived from its descriptor. Delegates
96
- * to the identity's signing primitives — the identity, not the provider,
97
- * holds the seed.
98
- */
99
- async signWithDescriptor(requests) {
100
- return this.identity.signWithDescriptor(requests);
101
- }
102
- /** Signs a message using the key derived from `descriptor`. */
103
- async signMessageWithDescriptor(descriptor, message, signatureType = "schnorr") {
104
- return this.identity.signMessageWithDescriptor(descriptor, message, signatureType);
105
- }
106
- /**
107
- * HD providers participate in receive rotation. The default
108
- * factory boot (contract-repo lookup → allocate fresh descriptor)
109
- * is exactly what we want, so this just delegates to
110
- * {@link WalletReceiveRotator.defaultBoot}.
111
- */
112
- async createReceiveRotator(opts) {
113
- return walletReceiveRotator_1.WalletReceiveRotator.defaultBoot(this, opts);
114
- }
115
- // ── internals ────────────────────────────────────────────────────
116
- /**
117
- * Substitute the wildcard in the identity's account-descriptor template
118
- * with a concrete index, going through the descriptors-scure parser
119
- * rather than ad-hoc string substitution. The parser's `expand({ index })`
120
- * call validates that the input is a ranged template AND produces a
121
- * canonical materialized key expression at the given index.
122
- */
123
- materializeAt(index) {
124
- const descriptor = this.identity.descriptor;
125
- const network = (0, descriptor_1.isMainnetDescriptor)(descriptor)
126
- ? descriptors_scure_1.networks.bitcoin
127
- : descriptors_scure_1.networks.testnet;
128
- const expansion = (0, descriptors_scure_1.expand)({ descriptor, network, index });
129
- const keyInfo = expansion.expansionMap?.["@0"];
130
- if (!keyInfo?.keyExpression) {
131
- throw new Error(`HDDescriptorProvider: cannot materialize descriptor at index ${index}`);
132
- }
133
- return `tr(${keyInfo.keyExpression})`;
134
- }
135
- /**
136
- * Run the read-modify-write of HD settings inside the shared per-repo
137
- * wallet-state mutex. The closure receives a freshly-validated settings
138
- * snapshot, mutates it, and returns whatever value the caller wants to
139
- * surface; the mutated settings are then persisted as part of the same
140
- * atomic update.
141
- *
142
- * Doing the read inside the lock is what prevents two providers (or two
143
- * concurrent callers on the same provider) from racing on a stale index.
144
- */
145
- async mutate(fn) {
146
- let result;
147
- await (0, syncCursors_1.updateWalletState)(this.walletRepository, (state) => {
148
- const settings = this.parseSettings(state);
149
- result = fn(settings);
150
- return {
151
- ...state,
152
- settings: {
153
- ...(state.settings ?? {}),
154
- [HD_SETTINGS_KEY]: settings,
155
- },
156
- };
157
- });
158
- return result;
159
- }
160
- /**
161
- * Validate the persisted HD settings (or initialize a fresh record when
162
- * absent) and return a clone safe for the caller to mutate.
163
- *
164
- * The cast to `HDWalletSettings` trusts storage; a corrupted or
165
- * partially-migrated repo could otherwise produce `NaN` descriptors.
166
- * Fail loud rather than silently derive garbage.
167
- */
168
- parseSettings(state) {
169
- const stored = state.settings?.[HD_SETTINGS_KEY];
170
- const expected = this.identity.descriptor;
171
- if (!stored) {
172
- return { descriptor: expected };
173
- }
174
- if (stored.descriptor !== expected) {
175
- throw new Error(`HD descriptor mismatch: stored "${stored.descriptor}", expected "${expected}". ` +
176
- `Refusing to reuse HD state from a different identity.`);
177
- }
178
- if (stored.lastIndexUsed !== undefined &&
179
- (typeof stored.lastIndexUsed !== "number" ||
180
- !Number.isInteger(stored.lastIndexUsed) ||
181
- stored.lastIndexUsed < 0)) {
182
- throw new Error(`Corrupt HD settings: lastIndexUsed is not a non-negative integer (got ${String(stored.lastIndexUsed)}).`);
183
- }
184
- // Shallow clone so the closure may mutate without aliasing the repo's copy.
185
- return { ...stored };
186
- }
187
- }
188
- exports.HDDescriptorProvider = HDDescriptorProvider;
@@ -1,82 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TxType = exports.DEFAULT_NETWORK_NAME = exports.DEFAULT_ARKADE_HRP = exports.DEFAULT_ARKADE_SERVER_URL = void 0;
4
- exports.isSpendable = isSpendable;
5
- exports.isRecoverable = isRecoverable;
6
- exports.isExpired = isExpired;
7
- exports.isSubdust = isSubdust;
8
- /** Defaults */
9
- exports.DEFAULT_ARKADE_SERVER_URL = "https://arkade.computer";
10
- exports.DEFAULT_ARKADE_HRP = "ark";
11
- exports.DEFAULT_NETWORK_NAME = "bitcoin";
12
- /** Wallet transaction direction. */
13
- var TxType;
14
- (function (TxType) {
15
- TxType["TxSent"] = "SENT";
16
- TxType["TxReceived"] = "RECEIVED";
17
- })(TxType || (exports.TxType = TxType = {}));
18
- /**
19
- * Return whether a virtual output is still spendable.
20
- *
21
- * @param vtxo - virtual output to inspect
22
- * @returns `true` when the virtual output is not marked as spent
23
- *
24
- * @see isRecoverable
25
- * @see isExpired
26
- */
27
- function isSpendable(vtxo) {
28
- return !vtxo.isSpent;
29
- }
30
- /**
31
- * Return whether a virtual output is recoverable.
32
- *
33
- * @param vtxo - virtual output to inspect
34
- * @returns `true` when the virtual output is swept but still spendable
35
- *
36
- * @remarks
37
- * Recoverable virtual outputs are typically re-settled into fresh virtual outputs by the virtual output manager.
38
- *
39
- * @see isSpendable
40
- * @see isExpired
41
- */
42
- function isRecoverable(vtxo) {
43
- return vtxo.virtualStatus.state === "swept" && isSpendable(vtxo);
44
- }
45
- /**
46
- * Return whether a virtual output should be treated as expired.
47
- *
48
- * @param vtxo - virtual output to inspect
49
- * @returns `true` when the virtual output is swept or its batch expiry has passed
50
- * @remarks
51
- * On regtest-like environments the upstream expiry value may be expressed as a block
52
- * height instead of a timestamp. This helper intentionally ignores obviously non-time
53
- * values to avoid false positives.
54
- *
55
- * @see VirtualStatus.batchExpiry
56
- */
57
- function isExpired(vtxo) {
58
- if (vtxo.virtualStatus.state === "swept")
59
- return true; // swept by server = expired
60
- const expiry = vtxo.virtualStatus.batchExpiry;
61
- if (!expiry)
62
- return false;
63
- // we use this as a workaround to avoid issue on regtest where expiry date is expressed in blockheight instead of timestamp
64
- // if expiry, as Date, is before 2025, then we admit it's too small to be a timestamp
65
- // TODO: API should return the expiry unit
66
- const expireAt = new Date(expiry);
67
- if (expireAt.getFullYear() < 2025)
68
- return false;
69
- return expiry <= Date.now();
70
- }
71
- /**
72
- * Return whether a virtual output is below the dust threshold.
73
- *
74
- * @param vtxo - virtual output to inspect
75
- * @param dust - dust threshold in satoshis
76
- * @returns `true` when the virtual output value is below `dust`
77
- *
78
- * @see isRecoverable
79
- */
80
- function isSubdust(vtxo, dust) {
81
- return vtxo.value < dust;
82
- }
@@ -1,98 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InputSignerRouter = void 0;
4
- const base_1 = require("@scure/base");
5
- const signingErrors_1 = require("./signingErrors");
6
- const DESCRIPTOR_CAPABLE_CONTRACT_TYPES = new Set(["default", "delegate"]);
7
- /**
8
- * Routes PSBT inputs to the correct signer based on the owning contract.
9
- * Inputs whose script matches a `default`/`delegate` contract with a
10
- * non-baseline owner are sent to {@link DescriptorProvider}; everything
11
- * else (baseline-owned contracts, non-default/non-delegate contracts,
12
- * and the boarding script) is sent to {@link Identity}. Inputs with no
13
- * matching contract and no boarding match are silently skipped, matching
14
- * how the wallet historically handled cosigner/connector inputs.
15
- */
16
- class InputSignerRouter {
17
- constructor(deps) {
18
- this.deps = deps;
19
- }
20
- async sign(tx, jobs) {
21
- if (jobs.length === 0)
22
- return tx;
23
- const distinctScripts = Array.from(new Set(jobs.map((j) => base_1.hex.encode(j.lookupScript))));
24
- const contracts = await this.deps.contractRepository.getContracts({
25
- script: distinctScripts,
26
- });
27
- // Repo may yield duplicates if seeded oddly; keep the first one
28
- // for each script to match the wallet's historical behaviour.
29
- const scriptToContract = new Map();
30
- for (const contract of contracts) {
31
- if (!scriptToContract.has(contract.script)) {
32
- scriptToContract.set(contract.script, contract);
33
- }
34
- }
35
- const baselinePubKeyHex = base_1.hex.encode(await this.deps.identity.xOnlyPublicKey());
36
- const boardingScriptHex = base_1.hex.encode(this.deps.boardingPkScript);
37
- const identityIndexes = [];
38
- const descriptorGroups = new Map();
39
- for (const job of jobs) {
40
- const scriptHex = base_1.hex.encode(job.lookupScript);
41
- const contract = scriptToContract.get(scriptHex);
42
- if (!contract) {
43
- if (scriptHex === boardingScriptHex) {
44
- identityIndexes.push(job.index);
45
- }
46
- continue;
47
- }
48
- if (!DESCRIPTOR_CAPABLE_CONTRACT_TYPES.has(contract.type)) {
49
- identityIndexes.push(job.index);
50
- continue;
51
- }
52
- // `baselinePubKeyHex` is freshly produced by `hex.encode`,
53
- // so it is already lowercase. `contract.params.pubKey` is
54
- // persisted data: a migration or custom repository adapter
55
- // could legitimately store it uppercase, so canonicalize
56
- // before comparing to match the legacy router behaviour.
57
- const ownerPubKeyHex = contract.params.pubKey?.toLowerCase();
58
- if (ownerPubKeyHex && ownerPubKeyHex === baselinePubKeyHex) {
59
- identityIndexes.push(job.index);
60
- continue;
61
- }
62
- const descriptor = contract.metadata?.signingDescriptor;
63
- if (typeof descriptor !== "string" || descriptor.length === 0) {
64
- throw new signingErrors_1.MissingSigningDescriptorError(contract.script, contract.type);
65
- }
66
- const bucket = descriptorGroups.get(descriptor);
67
- if (bucket) {
68
- bucket.push(job.index);
69
- }
70
- else {
71
- descriptorGroups.set(descriptor, [job.index]);
72
- }
73
- }
74
- let signed = tx;
75
- if (identityIndexes.length > 0) {
76
- signed = await this.deps.identity.sign(signed, identityIndexes);
77
- }
78
- if (descriptorGroups.size > 0) {
79
- if (!this.deps.descriptorProvider) {
80
- throw new signingErrors_1.DescriptorSigningProviderMissingError();
81
- }
82
- const sortedDescriptors = Array.from(descriptorGroups.keys()).sort();
83
- for (const descriptor of sortedDescriptors) {
84
- const indexes = descriptorGroups.get(descriptor);
85
- const [next] = await this.deps.descriptorProvider.signWithDescriptor([
86
- {
87
- tx: signed,
88
- descriptor,
89
- inputIndexes: indexes,
90
- },
91
- ]);
92
- signed = next;
93
- }
94
- }
95
- return signed;
96
- }
97
- }
98
- exports.InputSignerRouter = InputSignerRouter;
@@ -1,290 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OnchainWallet = void 0;
4
- exports.selectCoins = selectCoins;
5
- const btc_signer_1 = require("@scure/btc-signer");
6
- const _1 = require(".");
7
- const networks_1 = require("../networks");
8
- const onchain_1 = require("../providers/onchain");
9
- const anchor_1 = require("../utils/anchor");
10
- const txSizeEstimator_1 = require("../utils/txSizeEstimator");
11
- const transaction_1 = require("../utils/transaction");
12
- const utils_1 = require("./utils");
13
- /**
14
- * Onchain Bitcoin wallet implementation for traditional Bitcoin transactions.
15
- *
16
- * This wallet handles regular Bitcoin transactions on the blockchain without
17
- * using the Arkade protocol. It supports P2TR (Pay-to-Taproot) addresses and
18
- * provides basic Bitcoin wallet functionality.
19
- *
20
- * @example
21
- * ```typescript
22
- * const wallet = await OnchainWallet.create(identity, 'mainnet');
23
- * const balance = await wallet.getBalance();
24
- * const txid = await wallet.send({
25
- * address: 'bc1...',
26
- * amount: 50000
27
- * });
28
- * ```
29
- */
30
- class OnchainWallet {
31
- constructor(identity, network, onchainP2TR, provider) {
32
- this.identity = identity;
33
- this.network = network;
34
- this.onchainP2TR = onchainP2TR;
35
- this.provider = provider;
36
- }
37
- /**
38
- * Create an onchain wallet for the given identity and Bitcoin network.
39
- *
40
- * @param identity - Identity used to derive the Taproot key and sign transactions
41
- * @param networkName - Bitcoin network name, @see NetworkName
42
- * @param provider - Optional onchain provider override, @see OnchainProvider
43
- * @returns Configured onchain wallet
44
- * @defaultValue `provider = new EsploraProvider('https://mempool.space/api')`
45
- * @throws Error if the configured identity cannot produce a valid x-only public key
46
- */
47
- static async create(identity, networkName = _1.DEFAULT_NETWORK_NAME, provider) {
48
- const pubkey = await identity.xOnlyPublicKey();
49
- if (!pubkey) {
50
- throw new Error("Invalid configured public key");
51
- }
52
- const network = (0, networks_1.getNetwork)(networkName);
53
- const onchainProvider = provider || new onchain_1.EsploraProvider(onchain_1.ESPLORA_URL[networkName]);
54
- const onchainP2TR = (0, btc_signer_1.p2tr)(pubkey, undefined, network);
55
- return new OnchainWallet(identity, network, onchainP2TR, onchainProvider);
56
- }
57
- get address() {
58
- return this.onchainP2TR.address || "";
59
- }
60
- /**
61
- * Fetch spendable onchain outputs for the wallet address.
62
- *
63
- * @returns Spendable onchain outputs for the wallet address
64
- * @see getBalance
65
- */
66
- async getCoins() {
67
- return this.provider.getCoins(this.address);
68
- }
69
- /**
70
- * Return the wallet's total onchain balance in satoshis.
71
- *
72
- * @returns Confirmed plus unconfirmed onchain balance
73
- * @see getCoins
74
- */
75
- async getBalance() {
76
- const coins = await this.getCoins();
77
- const onchainConfirmed = coins
78
- .filter((coin) => coin.status.confirmed)
79
- .reduce((sum, coin) => sum + coin.value, 0);
80
- const onchainUnconfirmed = coins
81
- .filter((coin) => !coin.status.confirmed)
82
- .reduce((sum, coin) => sum + coin.value, 0);
83
- const onchainTotal = onchainConfirmed + onchainUnconfirmed;
84
- return onchainTotal;
85
- }
86
- /**
87
- * Iteratively selects coins and estimates transaction fees until convergence.
88
- *
89
- * This method handles the circular dependency between output selection and fee
90
- * estimation: the fee depends on transaction size, which depends on the number
91
- * of inputs (selected outputs) and whether a change output is needed.
92
- *
93
- * The algorithm iterates up to 10 times, refining the fee estimate based on
94
- * the actual transaction structure. It resolves dust oscillation loops that
95
- * occur when the change amount hovers near the dust threshold—adding/removing
96
- * the change output causes the fee to fluctuate, preventing convergence.
97
- * When a lower fee is computed (indicating the change output was dropped),
98
- * the function accepts this state to guarantee termination.
99
- *
100
- * @param coins - Available onchain outputs to select from
101
- * @param amount - Target send amount in satoshis
102
- * @param feeRate - Fee rate in sat/vbyte
103
- * @param recipientAddress - Destination address for size estimation
104
- * @returns Selected inputs, change amount, and calculated fee
105
- * @throws Error if fee estimation fails to converge within max iterations
106
- */
107
- estimateFeesAndSelectCoins(coins, amount, feeRate, recipientAddress) {
108
- const MAX_ITERATIONS = 10;
109
- let fee = 0;
110
- for (let i = 0; i < MAX_ITERATIONS; i++) {
111
- const totalNeeded = amount + fee;
112
- const selected = selectCoins(coins, totalNeeded);
113
- const estimator = txSizeEstimator_1.TxWeightEstimator.create();
114
- for (const _ of selected.inputs) {
115
- estimator.addKeySpendInput();
116
- }
117
- estimator.addOutputAddress(recipientAddress, this.network);
118
- if (selected.changeAmount >= BigInt(utils_1.DUST_AMOUNT)) {
119
- estimator.addOutputAddress(this.address, this.network);
120
- }
121
- const newFee = Number(estimator.vsize().value) * feeRate;
122
- const roundedNewFee = Math.ceil(newFee);
123
- // Prevent oscillation loops when change falls just below the dust limit.
124
- // If removing the change output reduces the fee below our budget,
125
- // we accept the valid transaction state to guarantee convergence.
126
- if (roundedNewFee <= fee) {
127
- return { ...selected, fee: roundedNewFee };
128
- }
129
- fee = roundedNewFee;
130
- }
131
- throw new Error("Fee estimation failed: could not converge");
132
- }
133
- /**
134
- * Send bitcoin to a single onchain address.
135
- *
136
- * @param params - destination `address`, `amount` (in satoshis), and optional `feeRate` override (other fields ignored)
137
- * @returns Broadcast transaction id
138
- * @throws Error if the amount is non-positive, below dust, or cannot be funded
139
- * @see SendBitcoinParams
140
- */
141
- async send(params) {
142
- if (params.amount <= 0) {
143
- throw new Error("Amount must be positive");
144
- }
145
- if (params.amount < utils_1.DUST_AMOUNT) {
146
- throw new Error("Amount is below dust limit");
147
- }
148
- const coins = await this.getCoins();
149
- let feeRate = params.feeRate;
150
- if (!feeRate) {
151
- feeRate = await this.provider.getFeeRate();
152
- }
153
- if (!feeRate || feeRate < OnchainWallet.MIN_FEE_RATE) {
154
- feeRate = OnchainWallet.MIN_FEE_RATE;
155
- }
156
- const { inputs, changeAmount } = this.estimateFeesAndSelectCoins(coins, params.amount, feeRate, params.address);
157
- if (!inputs) {
158
- throw new Error("Fee estimation failed");
159
- }
160
- // Create transaction
161
- let tx = new transaction_1.Transaction();
162
- // Add inputs
163
- for (const input of inputs) {
164
- tx.addInput({
165
- txid: input.txid,
166
- index: input.vout,
167
- witnessUtxo: {
168
- script: this.onchainP2TR.script,
169
- amount: BigInt(input.value),
170
- },
171
- tapInternalKey: this.onchainP2TR.tapInternalKey,
172
- });
173
- }
174
- // Add payment output
175
- tx.addOutputAddress(params.address, BigInt(params.amount), this.network);
176
- if (changeAmount >= BigInt(utils_1.DUST_AMOUNT)) {
177
- tx.addOutputAddress(this.address, changeAmount, this.network);
178
- }
179
- // Sign inputs and Finalize
180
- tx = await this.identity.sign(tx);
181
- tx.finalize();
182
- // Broadcast
183
- const txid = await this.provider.broadcastTransaction(tx.hex);
184
- return txid;
185
- }
186
- /**
187
- * CPFP-bump a parent transaction that contains a pay-to-anchor output.
188
- *
189
- * @param parent - Parent transaction containing a pay-to-anchor output
190
- * @returns Tuple of parent transaction id and child transaction id
191
- * @throws Error if the parent transaction has no pay-to-anchor output or bumping cannot be funded
192
- * @see send
193
- */
194
- async bumpP2A(parent) {
195
- const parentVsize = parent.vsize;
196
- let child = new transaction_1.Transaction({
197
- version: 3,
198
- allowLegacyWitnessUtxo: true,
199
- });
200
- child.addInput((0, anchor_1.findP2AOutput)(parent)); // throws if not found
201
- const childVsize = txSizeEstimator_1.TxWeightEstimator.create()
202
- .addKeySpendInput(true)
203
- .addP2AInput()
204
- .addOutputAddress(this.address, this.network)
205
- .vsize().value;
206
- const packageVSize = parentVsize + Number(childVsize);
207
- let feeRate = await this.provider.getFeeRate();
208
- if (!feeRate || feeRate < OnchainWallet.MIN_FEE_RATE) {
209
- feeRate = OnchainWallet.MIN_FEE_RATE;
210
- }
211
- const fee = Math.ceil(feeRate * packageVSize);
212
- if (!fee) {
213
- throw new Error(`invalid fee, got ${fee} with vsize ${packageVSize}, feeRate ${feeRate}`);
214
- }
215
- // Select onchain outputs
216
- const coins = await this.getCoins();
217
- const selected = selectCoins(coins, fee, true);
218
- for (const input of selected.inputs) {
219
- child.addInput({
220
- txid: input.txid,
221
- index: input.vout,
222
- witnessUtxo: {
223
- script: this.onchainP2TR.script,
224
- amount: BigInt(input.value),
225
- },
226
- tapInternalKey: this.onchainP2TR.tapInternalKey,
227
- });
228
- }
229
- child.addOutputAddress(this.address, anchor_1.P2A.amount + selected.changeAmount, this.network);
230
- // Sign inputs and Finalize
231
- child = await this.identity.sign(child);
232
- for (let i = 1; i < child.inputsLength; i++) {
233
- child.finalizeIdx(i);
234
- }
235
- try {
236
- await this.provider.broadcastTransaction(parent.hex, child.hex);
237
- }
238
- catch (error) {
239
- console.error(error);
240
- }
241
- finally {
242
- return [parent.hex, child.hex];
243
- }
244
- }
245
- }
246
- exports.OnchainWallet = OnchainWallet;
247
- OnchainWallet.MIN_FEE_RATE = 1; // sat/vbyte
248
- /**
249
- * Select coins to reach a target amount, prioritizing those closer to expiry
250
- * @param coins List of coins to select from
251
- * @param targetAmount Target amount to reach in satoshis
252
- * @param forceChange If true, ensure the coin selection will require a change output
253
- * @returns Selected coins and change amount, or null if insufficient funds
254
- */
255
- function selectCoins(coins, targetAmount, forceChange = false) {
256
- if (isNaN(targetAmount)) {
257
- throw new Error("Target amount is NaN, got " + targetAmount);
258
- }
259
- if (targetAmount < 0) {
260
- throw new Error("Target amount is negative, got " + targetAmount);
261
- }
262
- if (targetAmount === 0) {
263
- return { inputs: [], changeAmount: 0n };
264
- }
265
- // Sort coins by amount (descending)
266
- const sortedCoins = [...coins].sort((a, b) => b.value - a.value);
267
- const selectedCoins = [];
268
- let selectedAmount = 0;
269
- // Select coins until we have enough
270
- for (const coin of sortedCoins) {
271
- selectedCoins.push(coin);
272
- selectedAmount += coin.value;
273
- if (forceChange
274
- ? selectedAmount > targetAmount
275
- : selectedAmount >= targetAmount) {
276
- break;
277
- }
278
- }
279
- if (selectedAmount === targetAmount) {
280
- return { inputs: selectedCoins, changeAmount: 0n };
281
- }
282
- if (selectedAmount < targetAmount) {
283
- throw new Error("Insufficient funds");
284
- }
285
- const changeAmount = BigInt(selectedAmount - targetAmount);
286
- return {
287
- inputs: selectedCoins,
288
- changeAmount,
289
- };
290
- }