@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,229 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.TreeSignerSession = exports.ErrMissingAggregateKey = exports.ErrMissingVtxoGraph = void 0;
37
- exports.validateTreeSigs = validateTreeSigs;
38
- const musig2 = __importStar(require("../musig2"));
39
- const script_js_1 = require("@scure/btc-signer/script.js");
40
- const transaction_js_1 = require("@scure/btc-signer/transaction.js");
41
- const base_1 = require("@scure/base");
42
- const secp256k1_js_1 = require("@noble/curves/secp256k1.js");
43
- const utils_js_1 = require("@scure/btc-signer/utils.js");
44
- const unknownFields_1 = require("../utils/unknownFields");
45
- exports.ErrMissingVtxoGraph = new Error("missing vtxo graph");
46
- exports.ErrMissingAggregateKey = new Error("missing aggregate key");
47
- class TreeSignerSession {
48
- constructor(secretKey) {
49
- this.secretKey = secretKey;
50
- this.myNonces = null;
51
- this.aggregateNonces = null;
52
- this.graph = null;
53
- this.scriptRoot = null;
54
- this.rootSharedOutputAmount = null;
55
- }
56
- static random() {
57
- const secretKey = (0, utils_js_1.randomPrivateKeyBytes)();
58
- return new TreeSignerSession(secretKey);
59
- }
60
- async init(tree, scriptRoot, rootInputAmount) {
61
- this.graph = tree;
62
- this.scriptRoot = scriptRoot;
63
- this.rootSharedOutputAmount = rootInputAmount;
64
- }
65
- async getPublicKey() {
66
- return secp256k1_js_1.secp256k1.getPublicKey(this.secretKey);
67
- }
68
- async getNonces() {
69
- if (!this.graph)
70
- throw exports.ErrMissingVtxoGraph;
71
- if (!this.myNonces) {
72
- this.myNonces = this.generateNonces();
73
- }
74
- const publicNonces = new Map();
75
- for (const [txid, nonces] of this.myNonces) {
76
- publicNonces.set(txid, { pubNonce: nonces.pubNonce });
77
- }
78
- return publicNonces;
79
- }
80
- async aggregatedNonces(txid, noncesByPubkey) {
81
- if (!this.graph)
82
- throw exports.ErrMissingVtxoGraph;
83
- if (!this.aggregateNonces) {
84
- this.aggregateNonces = new Map();
85
- }
86
- if (!this.myNonces) {
87
- await this.getNonces(); // generate nonces if not generated yet
88
- }
89
- if (this.aggregateNonces.has(txid)) {
90
- return {
91
- hasAllNonces: this.aggregateNonces.size === this.myNonces?.size,
92
- };
93
- }
94
- const myNonce = this.myNonces.get(txid);
95
- if (!myNonce)
96
- throw new Error(`missing nonce for txid ${txid}`);
97
- const myPublicKey = await this.getPublicKey();
98
- // set my nonce to not rely on server
99
- noncesByPubkey.set(base_1.hex.encode(myPublicKey.subarray(1)), myNonce);
100
- const tx = this.graph.find(txid);
101
- if (!tx)
102
- throw new Error(`missing tx for txid ${txid}`);
103
- const cosigners = (0, unknownFields_1.getArkPsbtFields)(tx.root, 0, unknownFields_1.CosignerPublicKey).map((c) => base_1.hex.encode(c.key.subarray(1)) // xonly pubkey
104
- );
105
- const pubNonces = [];
106
- for (const cosigner of cosigners) {
107
- const nonce = noncesByPubkey.get(cosigner);
108
- if (!nonce) {
109
- throw new Error(`missing nonce for cosigner ${cosigner}`);
110
- }
111
- pubNonces.push(nonce.pubNonce);
112
- }
113
- const aggregateNonce = musig2.aggregateNonces(pubNonces);
114
- this.aggregateNonces.set(txid, { pubNonce: aggregateNonce });
115
- return {
116
- hasAllNonces: this.aggregateNonces.size === this.myNonces?.size,
117
- };
118
- }
119
- async sign() {
120
- if (!this.graph)
121
- throw exports.ErrMissingVtxoGraph;
122
- if (!this.aggregateNonces)
123
- throw new Error("nonces not set");
124
- if (!this.myNonces)
125
- throw new Error("nonces not generated");
126
- const sigs = new Map();
127
- for (const g of this.graph.iterator()) {
128
- const sig = this.signPartial(g);
129
- sigs.set(g.txid, sig);
130
- }
131
- return sigs;
132
- }
133
- generateNonces() {
134
- if (!this.graph)
135
- throw exports.ErrMissingVtxoGraph;
136
- const myNonces = new Map();
137
- const publicKey = secp256k1_js_1.secp256k1.getPublicKey(this.secretKey);
138
- for (const g of this.graph.iterator()) {
139
- const nonces = musig2.generateNonces(publicKey);
140
- myNonces.set(g.txid, nonces);
141
- }
142
- return myNonces;
143
- }
144
- signPartial(g) {
145
- if (!this.graph || !this.scriptRoot || !this.rootSharedOutputAmount) {
146
- throw TreeSignerSession.NOT_INITIALIZED;
147
- }
148
- if (!this.myNonces || !this.aggregateNonces) {
149
- throw new Error("session not properly initialized");
150
- }
151
- const myNonce = this.myNonces.get(g.txid);
152
- if (!myNonce)
153
- throw new Error("missing private nonce");
154
- const aggNonce = this.aggregateNonces.get(g.txid);
155
- if (!aggNonce)
156
- throw new Error("missing aggregate nonce");
157
- const prevoutAmounts = [];
158
- const prevoutScripts = [];
159
- const cosigners = (0, unknownFields_1.getArkPsbtFields)(g.root, 0, unknownFields_1.CosignerPublicKey).map((c) => c.key);
160
- const { finalKey } = musig2.aggregateKeys(cosigners, true, {
161
- taprootTweak: this.scriptRoot,
162
- });
163
- for (let inputIndex = 0; inputIndex < g.root.inputsLength; inputIndex++) {
164
- const prevout = getPrevOutput(finalKey, this.graph, this.rootSharedOutputAmount, g.root);
165
- prevoutAmounts.push(prevout.amount);
166
- prevoutScripts.push(prevout.script);
167
- }
168
- const message = g.root.preimageWitnessV1(0, // always first input
169
- prevoutScripts, transaction_js_1.SigHash.DEFAULT, prevoutAmounts);
170
- return musig2.sign(myNonce.secNonce, this.secretKey, aggNonce.pubNonce, cosigners, message, {
171
- taprootTweak: this.scriptRoot,
172
- sortKeys: true,
173
- });
174
- }
175
- }
176
- exports.TreeSignerSession = TreeSignerSession;
177
- TreeSignerSession.NOT_INITIALIZED = new Error("session not initialized, call init method");
178
- // Helper function to validate tree signatures
179
- async function validateTreeSigs(finalAggregatedKey, sharedOutputAmount, vtxoTree) {
180
- // Iterate through each level of the tree
181
- for (const g of vtxoTree.iterator()) {
182
- // Parse the transaction
183
- const input = g.root.getInput(0);
184
- // Check if input has signature
185
- if (!input.tapKeySig) {
186
- throw new Error("unsigned tree input");
187
- }
188
- // Get the previous output information
189
- const prevout = getPrevOutput(finalAggregatedKey, vtxoTree, sharedOutputAmount, g.root);
190
- // Calculate the message that was signed
191
- const message = g.root.preimageWitnessV1(0, // always first input
192
- [prevout.script], transaction_js_1.SigHash.DEFAULT, [prevout.amount]);
193
- // Verify the signature
194
- const isValid = secp256k1_js_1.schnorr.verify(input.tapKeySig, message, finalAggregatedKey);
195
- if (!isValid) {
196
- throw new Error("invalid signature");
197
- }
198
- }
199
- }
200
- function getPrevOutput(finalKey, graph, sharedOutputAmount, tx) {
201
- // generate P2TR script from musig2 final key
202
- const pkScript = script_js_1.Script.encode(["OP_1", finalKey.slice(1)]);
203
- // if the input is the root input, return the shared output amount
204
- if (tx.id === graph.txid) {
205
- return {
206
- amount: sharedOutputAmount,
207
- script: pkScript,
208
- };
209
- }
210
- // find the parent transaction
211
- const parentInput = tx.getInput(0);
212
- if (!parentInput.txid)
213
- throw new Error("missing parent input txid");
214
- const parentTxid = base_1.hex.encode(parentInput.txid);
215
- const parent = graph.find(parentTxid);
216
- if (!parent)
217
- throw new Error("parent tx not found");
218
- if (parentInput.index === undefined)
219
- throw new Error("missing input index");
220
- const parentOutput = parent.root.getOutput(parentInput.index);
221
- if (!parentOutput)
222
- throw new Error("parent output not found");
223
- if (!parentOutput.amount)
224
- throw new Error("parent output amount not found");
225
- return {
226
- amount: parentOutput.amount,
227
- script: pkScript,
228
- };
229
- }
@@ -1,192 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TxTree = void 0;
4
- const transaction_js_1 = require("@scure/btc-signer/transaction.js");
5
- const base_1 = require("@scure/base");
6
- const base_2 = require("@scure/base");
7
- /**
8
- * TxTree is a graph of bitcoin transactions.
9
- * It is used to represent batch tree created during settlement session
10
- */
11
- class TxTree {
12
- constructor(root, children = new Map()) {
13
- this.root = root;
14
- this.children = children;
15
- }
16
- static create(chunks) {
17
- if (chunks.length === 0) {
18
- throw new Error("empty chunks");
19
- }
20
- // Create a map to store all chunks by their txid for easy lookup
21
- const chunksByTxid = new Map();
22
- for (const chunk of chunks) {
23
- const decodedChunk = decodeNode(chunk);
24
- const txid = decodedChunk.tx.id;
25
- chunksByTxid.set(txid, decodedChunk);
26
- }
27
- // Find the root chunks (the ones that aren't referenced as a child)
28
- const rootTxids = [];
29
- for (const [txid] of chunksByTxid) {
30
- let isChild = false;
31
- for (const [otherTxid, otherChunk] of chunksByTxid) {
32
- if (otherTxid === txid) {
33
- // skip self
34
- continue;
35
- }
36
- // check if the current chunk is a child of the other chunk
37
- isChild = hasChild(otherChunk, txid);
38
- if (isChild) {
39
- break;
40
- }
41
- }
42
- // if the chunk is not a child of any other chunk, it is a root
43
- if (!isChild) {
44
- rootTxids.push(txid);
45
- continue;
46
- }
47
- }
48
- if (rootTxids.length === 0) {
49
- throw new Error("no root chunk found");
50
- }
51
- if (rootTxids.length > 1) {
52
- throw new Error(`multiple root chunks found: ${rootTxids.join(", ")}`);
53
- }
54
- const graph = buildGraph(rootTxids[0], chunksByTxid);
55
- if (!graph) {
56
- throw new Error(`chunk not found for root txid: ${rootTxids[0]}`);
57
- }
58
- // verify that the number of chunks is equal to the number node in the graph
59
- if (graph.nbOfNodes() !== chunks.length) {
60
- throw new Error(`number of chunks (${chunks.length}) is not equal to the number of nodes in the graph (${graph.nbOfNodes()})`);
61
- }
62
- return graph;
63
- }
64
- nbOfNodes() {
65
- let count = 1; // count this node
66
- for (const child of this.children.values()) {
67
- count += child.nbOfNodes();
68
- }
69
- return count;
70
- }
71
- validate() {
72
- if (!this.root) {
73
- throw new Error("unexpected nil root");
74
- }
75
- const nbOfOutputs = this.root.outputsLength;
76
- const nbOfInputs = this.root.inputsLength;
77
- if (nbOfInputs !== 1) {
78
- throw new Error(`unexpected number of inputs: ${nbOfInputs}, expected 1`);
79
- }
80
- // the children map can't be bigger than the number of outputs (excluding the P2A)
81
- // a graph can be "partial" and specify only some of the outputs as children,
82
- // that's why we allow len(g.Children) to be less than nbOfOutputs-1
83
- if (this.children.size > nbOfOutputs - 1) {
84
- throw new Error(`unexpected number of children: ${this.children.size}, expected maximum ${nbOfOutputs - 1}`);
85
- }
86
- // validate each child
87
- for (const [outputIndex, child] of this.children) {
88
- if (outputIndex >= nbOfOutputs) {
89
- throw new Error(`output index ${outputIndex} is out of bounds (nb of outputs: ${nbOfOutputs})`);
90
- }
91
- child.validate();
92
- const childInput = child.root.getInput(0);
93
- const parentTxid = this.root.id;
94
- // verify the input of the child is the output of the parent
95
- if (!childInput.txid ||
96
- base_2.hex.encode(childInput.txid) !== parentTxid ||
97
- childInput.index !== outputIndex) {
98
- throw new Error(`input of child ${outputIndex} is not the output of the parent`);
99
- }
100
- // verify the sum of the child's outputs is equal to the output of the parent
101
- let childOutputsSum = 0n;
102
- for (let i = 0; i < child.root.outputsLength; i++) {
103
- const output = child.root.getOutput(i);
104
- if (output?.amount) {
105
- childOutputsSum += output.amount;
106
- }
107
- }
108
- const parentOutput = this.root.getOutput(outputIndex);
109
- if (!parentOutput?.amount) {
110
- throw new Error(`parent output ${outputIndex} has no amount`);
111
- }
112
- if (childOutputsSum !== parentOutput.amount) {
113
- throw new Error(`sum of child's outputs is not equal to the output of the parent: ${childOutputsSum} != ${parentOutput.amount}`);
114
- }
115
- }
116
- }
117
- leaves() {
118
- if (this.children.size === 0) {
119
- return [this.root];
120
- }
121
- const leaves = [];
122
- for (const child of this.children.values()) {
123
- leaves.push(...child.leaves());
124
- }
125
- return leaves;
126
- }
127
- get txid() {
128
- return this.root.id;
129
- }
130
- find(txid) {
131
- if (txid === this.txid) {
132
- return this;
133
- }
134
- for (const child of this.children.values()) {
135
- const found = child.find(txid);
136
- if (found) {
137
- return found;
138
- }
139
- }
140
- return null;
141
- }
142
- update(txid, fn) {
143
- if (txid === this.txid) {
144
- fn(this.root);
145
- return;
146
- }
147
- for (const child of this.children.values()) {
148
- try {
149
- child.update(txid, fn);
150
- return;
151
- }
152
- catch (error) {
153
- // Continue searching in other children if not found
154
- continue;
155
- }
156
- }
157
- throw new Error(`tx not found: ${txid}`);
158
- }
159
- *iterator() {
160
- for (const child of this.children.values()) {
161
- yield* child.iterator();
162
- }
163
- yield this;
164
- }
165
- }
166
- exports.TxTree = TxTree;
167
- // Helper function to check if a chunk has a specific child
168
- function hasChild(chunk, childTxid) {
169
- return Object.values(chunk.children).includes(childTxid);
170
- }
171
- // buildGraph recursively builds the TxGraph starting from the given txid
172
- function buildGraph(rootTxid, chunksByTxid) {
173
- const chunk = chunksByTxid.get(rootTxid);
174
- if (!chunk) {
175
- return null;
176
- }
177
- const rootTx = chunk.tx;
178
- const children = new Map();
179
- // Recursively build children graphs
180
- for (const [outputIndexStr, childTxid] of Object.entries(chunk.children)) {
181
- const outputIndex = parseInt(outputIndexStr);
182
- const childGraph = buildGraph(childTxid, chunksByTxid);
183
- if (childGraph) {
184
- children.set(outputIndex, childGraph);
185
- }
186
- }
187
- return new TxTree(rootTx, children);
188
- }
189
- function decodeNode(chunk) {
190
- const tx = transaction_js_1.Transaction.fromPSBT(base_1.base64.decode(chunk.tx));
191
- return { tx, children: chunk.children };
192
- }
@@ -1,107 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ErrMissingCosignersPublicKeys = exports.ErrWrongCommitmentTxid = exports.ErrInvalidRoundTxOutputs = exports.ErrInvalidTaprootScript = exports.ErrNoLeaves = exports.ErrInvalidAmount = exports.ErrWrongSettlementTxid = exports.ErrNumberOfInputs = exports.ErrEmptyTree = exports.ErrInvalidSettlementTxOutputs = exports.ErrInvalidSettlementTx = void 0;
4
- exports.validateConnectorsTxGraph = validateConnectorsTxGraph;
5
- exports.validateVtxoTxGraph = validateVtxoTxGraph;
6
- const base_1 = require("@scure/base");
7
- const transaction_js_1 = require("@scure/btc-signer/transaction.js");
8
- const base_2 = require("@scure/base");
9
- const musig2_1 = require("../musig2");
10
- const unknownFields_1 = require("../utils/unknownFields");
11
- const ErrInvalidSettlementTx = (tx) => new Error(`invalid settlement transaction: ${tx}`);
12
- exports.ErrInvalidSettlementTx = ErrInvalidSettlementTx;
13
- exports.ErrInvalidSettlementTxOutputs = new Error("invalid settlement transaction outputs");
14
- exports.ErrEmptyTree = new Error("empty tree");
15
- exports.ErrNumberOfInputs = new Error("invalid number of inputs");
16
- exports.ErrWrongSettlementTxid = new Error("wrong settlement txid");
17
- exports.ErrInvalidAmount = new Error("invalid amount");
18
- exports.ErrNoLeaves = new Error("no leaves");
19
- exports.ErrInvalidTaprootScript = new Error("invalid taproot script");
20
- exports.ErrInvalidRoundTxOutputs = new Error("invalid round transaction outputs");
21
- exports.ErrWrongCommitmentTxid = new Error("wrong commitment txid");
22
- exports.ErrMissingCosignersPublicKeys = new Error("missing cosigners public keys");
23
- const BATCH_OUTPUT_VTXO_INDEX = 0;
24
- const BATCH_OUTPUT_CONNECTORS_INDEX = 1;
25
- function validateConnectorsTxGraph(settlementTxB64, connectorsGraph) {
26
- connectorsGraph.validate();
27
- if (connectorsGraph.root.inputsLength !== 1)
28
- throw exports.ErrNumberOfInputs;
29
- const rootInput = connectorsGraph.root.getInput(0);
30
- const settlementTx = transaction_js_1.Transaction.fromPSBT(base_2.base64.decode(settlementTxB64));
31
- if (settlementTx.outputsLength <= BATCH_OUTPUT_CONNECTORS_INDEX)
32
- throw exports.ErrInvalidSettlementTxOutputs;
33
- const expectedRootTxid = settlementTx.id;
34
- if (!rootInput.txid)
35
- throw exports.ErrWrongSettlementTxid;
36
- if (base_1.hex.encode(rootInput.txid) !== expectedRootTxid)
37
- throw exports.ErrWrongSettlementTxid;
38
- if (rootInput.index !== BATCH_OUTPUT_CONNECTORS_INDEX)
39
- throw exports.ErrWrongSettlementTxid;
40
- }
41
- // ValidateVtxoTxGraph checks if the given virtual output tx graph is valid.
42
- // The function validates:
43
- // - the number of nodes
44
- // - the number of leaves
45
- // - children coherence with parent.
46
- // - every control block and taproot output scripts.
47
- // - input and output amounts.
48
- function validateVtxoTxGraph(graph, roundTransaction, sweepTapTreeRoot) {
49
- if (roundTransaction.outputsLength < BATCH_OUTPUT_VTXO_INDEX + 1) {
50
- throw exports.ErrInvalidRoundTxOutputs;
51
- }
52
- const batchOutputAmount = roundTransaction.getOutput(BATCH_OUTPUT_VTXO_INDEX)?.amount;
53
- if (!batchOutputAmount) {
54
- throw exports.ErrInvalidRoundTxOutputs;
55
- }
56
- if (!graph.root) {
57
- throw exports.ErrEmptyTree;
58
- }
59
- const rootInput = graph.root.getInput(0);
60
- const commitmentTxid = roundTransaction.id;
61
- if (!rootInput.txid ||
62
- base_1.hex.encode(rootInput.txid) !== commitmentTxid ||
63
- rootInput.index !== BATCH_OUTPUT_VTXO_INDEX) {
64
- throw exports.ErrWrongCommitmentTxid;
65
- }
66
- let sumRootValue = 0n;
67
- for (let i = 0; i < graph.root.outputsLength; i++) {
68
- const output = graph.root.getOutput(i);
69
- if (output?.amount) {
70
- sumRootValue += output.amount;
71
- }
72
- }
73
- if (sumRootValue !== batchOutputAmount) {
74
- throw exports.ErrInvalidAmount;
75
- }
76
- const leaves = graph.leaves();
77
- if (leaves.length === 0) {
78
- throw exports.ErrNoLeaves;
79
- }
80
- // validate the graph structure
81
- graph.validate();
82
- // iterates over all the nodes of the graph to verify that cosigners public keys are corresponding to the parent output
83
- for (const g of graph.iterator()) {
84
- for (const [childIndex, child] of g.children) {
85
- const parentOutput = g.root.getOutput(childIndex);
86
- if (!parentOutput?.script) {
87
- throw new Error(`parent output ${childIndex} not found`);
88
- }
89
- const previousScriptKey = parentOutput.script.slice(2);
90
- if (previousScriptKey.length !== 32) {
91
- throw new Error(`parent output ${childIndex} has invalid script`);
92
- }
93
- const cosigners = (0, unknownFields_1.getArkPsbtFields)(child.root, 0, unknownFields_1.CosignerPublicKey);
94
- if (cosigners.length === 0) {
95
- throw exports.ErrMissingCosignersPublicKeys;
96
- }
97
- const cosignerKeys = cosigners.map((c) => c.key);
98
- const { finalKey } = (0, musig2_1.aggregateKeys)(cosignerKeys, true, {
99
- taprootTweak: sweepTapTreeRoot,
100
- });
101
- if (!finalKey ||
102
- base_1.hex.encode(finalKey.slice(1)) !== base_1.hex.encode(previousScriptKey)) {
103
- throw exports.ErrInvalidTaprootScript;
104
- }
105
- }
106
- }
107
- }
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.P2A = exports.ANCHOR_PKSCRIPT = exports.ANCHOR_VALUE = void 0;
4
- exports.findP2AOutput = findP2AOutput;
5
- const base_1 = require("@scure/base");
6
- exports.ANCHOR_VALUE = 0n;
7
- exports.ANCHOR_PKSCRIPT = new Uint8Array([0x51, 0x02, 0x4e, 0x73]);
8
- /**
9
- * A zero-value anchor output.
10
- */
11
- exports.P2A = {
12
- script: exports.ANCHOR_PKSCRIPT,
13
- amount: exports.ANCHOR_VALUE,
14
- };
15
- const hexP2Ascript = base_1.hex.encode(exports.P2A.script);
16
- /**
17
- * search for anchor in the given transaction.
18
- * @throws {Error} if the anchor is not found or has the wrong amount
19
- */
20
- function findP2AOutput(tx) {
21
- for (let i = 0; i < tx.outputsLength; i++) {
22
- const output = tx.getOutput(i);
23
- if (output.script && base_1.hex.encode(output.script) === hexP2Ascript) {
24
- if (output.amount !== exports.P2A.amount) {
25
- throw new Error(`P2A output has wrong amount, expected ${exports.P2A.amount} got ${output.amount}`);
26
- }
27
- return {
28
- txid: tx.id,
29
- index: i,
30
- witnessUtxo: exports.P2A,
31
- };
32
- }
33
- }
34
- throw new Error("P2A output not found");
35
- }