@bsv/wallet-toolbox-client 2.1.23 → 2.1.25

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 (504) hide show
  1. package/out/src/CWIStyleWalletManager.d.ts +33 -7
  2. package/out/src/CWIStyleWalletManager.d.ts.map +1 -1
  3. package/out/src/CWIStyleWalletManager.js +281 -313
  4. package/out/src/CWIStyleWalletManager.js.map +1 -1
  5. package/out/src/SetupClient.d.ts +6 -6
  6. package/out/src/SetupClient.d.ts.map +1 -1
  7. package/out/src/SetupClient.js +5 -5
  8. package/out/src/SetupClient.js.map +1 -1
  9. package/out/src/SetupWallet.d.ts.map +1 -1
  10. package/out/src/SimpleWalletManager.d.ts +12 -2
  11. package/out/src/SimpleWalletManager.d.ts.map +1 -1
  12. package/out/src/SimpleWalletManager.js +46 -30
  13. package/out/src/SimpleWalletManager.js.map +1 -1
  14. package/out/src/Wallet.d.ts +1 -1
  15. package/out/src/Wallet.d.ts.map +1 -1
  16. package/out/src/Wallet.js +102 -100
  17. package/out/src/Wallet.js.map +1 -1
  18. package/out/src/WalletAuthenticationManager.d.ts +1 -1
  19. package/out/src/WalletAuthenticationManager.d.ts.map +1 -1
  20. package/out/src/WalletAuthenticationManager.js +3 -3
  21. package/out/src/WalletAuthenticationManager.js.map +1 -1
  22. package/out/src/WalletLogger.d.ts.map +1 -1
  23. package/out/src/WalletLogger.js +16 -8
  24. package/out/src/WalletLogger.js.map +1 -1
  25. package/out/src/WalletPermissionsManager.d.ts +89 -18
  26. package/out/src/WalletPermissionsManager.d.ts.map +1 -1
  27. package/out/src/WalletPermissionsManager.js +656 -870
  28. package/out/src/WalletPermissionsManager.js.map +1 -1
  29. package/out/src/WalletSettingsManager.d.ts +2 -2
  30. package/out/src/WalletSettingsManager.d.ts.map +1 -1
  31. package/out/src/WalletSettingsManager.js.map +1 -1
  32. package/out/src/fundWalletP2PKH.d.ts +2 -2
  33. package/out/src/fundWalletP2PKH.d.ts.map +1 -1
  34. package/out/src/fundWalletP2PKH.js +11 -10
  35. package/out/src/fundWalletP2PKH.js.map +1 -1
  36. package/out/src/mockchain/MockChainMigrations.d.ts +3 -3
  37. package/out/src/mockchain/MockChainMigrations.d.ts.map +1 -1
  38. package/out/src/mockchain/MockChainMigrations.js.map +1 -1
  39. package/out/src/mockchain/MockChainStorage.d.ts.map +1 -1
  40. package/out/src/mockchain/MockChainStorage.js +5 -5
  41. package/out/src/mockchain/MockChainStorage.js.map +1 -1
  42. package/out/src/mockchain/MockChainTracker.d.ts.map +1 -1
  43. package/out/src/mockchain/MockChainTracker.js +10 -10
  44. package/out/src/mockchain/MockChainTracker.js.map +1 -1
  45. package/out/src/mockchain/MockMiner.d.ts.map +1 -1
  46. package/out/src/mockchain/MockMiner.js +3 -3
  47. package/out/src/mockchain/MockMiner.js.map +1 -1
  48. package/out/src/mockchain/MockServices.d.ts +9 -0
  49. package/out/src/mockchain/MockServices.d.ts.map +1 -1
  50. package/out/src/mockchain/MockServices.js +195 -238
  51. package/out/src/mockchain/MockServices.js.map +1 -1
  52. package/out/src/mockchain/merkleTree.d.ts.map +1 -1
  53. package/out/src/mockchain/merkleTree.js +21 -12
  54. package/out/src/mockchain/merkleTree.js.map +1 -1
  55. package/out/src/monitor/Monitor.d.ts +17 -0
  56. package/out/src/monitor/Monitor.d.ts.map +1 -1
  57. package/out/src/monitor/Monitor.js +56 -75
  58. package/out/src/monitor/Monitor.js.map +1 -1
  59. package/out/src/monitor/tasks/TaskArcSSE.d.ts +2 -2
  60. package/out/src/monitor/tasks/TaskArcSSE.d.ts.map +1 -1
  61. package/out/src/monitor/tasks/TaskArcSSE.js +10 -23
  62. package/out/src/monitor/tasks/TaskArcSSE.js.map +1 -1
  63. package/out/src/monitor/tasks/TaskCheckForProofs.d.ts +2 -2
  64. package/out/src/monitor/tasks/TaskCheckForProofs.d.ts.map +1 -1
  65. package/out/src/monitor/tasks/TaskCheckForProofs.js +28 -16
  66. package/out/src/monitor/tasks/TaskCheckForProofs.js.map +1 -1
  67. package/out/src/monitor/tasks/TaskCheckNoSends.d.ts +1 -1
  68. package/out/src/monitor/tasks/TaskCheckNoSends.d.ts.map +1 -1
  69. package/out/src/monitor/tasks/TaskCheckNoSends.js +1 -2
  70. package/out/src/monitor/tasks/TaskCheckNoSends.js.map +1 -1
  71. package/out/src/monitor/tasks/TaskClock.d.ts +1 -1
  72. package/out/src/monitor/tasks/TaskClock.d.ts.map +1 -1
  73. package/out/src/monitor/tasks/TaskClock.js +0 -1
  74. package/out/src/monitor/tasks/TaskClock.js.map +1 -1
  75. package/out/src/monitor/tasks/TaskFailAbandoned.d.ts +1 -1
  76. package/out/src/monitor/tasks/TaskFailAbandoned.d.ts.map +1 -1
  77. package/out/src/monitor/tasks/TaskFailAbandoned.js.map +1 -1
  78. package/out/src/monitor/tasks/TaskMineBlock.d.ts +1 -1
  79. package/out/src/monitor/tasks/TaskMineBlock.d.ts.map +1 -1
  80. package/out/src/monitor/tasks/TaskMineBlock.js.map +1 -1
  81. package/out/src/monitor/tasks/TaskMonitorCallHistory.d.ts +1 -1
  82. package/out/src/monitor/tasks/TaskMonitorCallHistory.d.ts.map +1 -1
  83. package/out/src/monitor/tasks/TaskMonitorCallHistory.js +1 -1
  84. package/out/src/monitor/tasks/TaskMonitorCallHistory.js.map +1 -1
  85. package/out/src/monitor/tasks/TaskNewHeader.d.ts +2 -2
  86. package/out/src/monitor/tasks/TaskNewHeader.d.ts.map +1 -1
  87. package/out/src/monitor/tasks/TaskNewHeader.js +7 -5
  88. package/out/src/monitor/tasks/TaskNewHeader.js.map +1 -1
  89. package/out/src/monitor/tasks/TaskPurge.d.ts +1 -1
  90. package/out/src/monitor/tasks/TaskPurge.d.ts.map +1 -1
  91. package/out/src/monitor/tasks/TaskPurge.js.map +1 -1
  92. package/out/src/monitor/tasks/TaskReorg.d.ts +1 -1
  93. package/out/src/monitor/tasks/TaskReorg.d.ts.map +1 -1
  94. package/out/src/monitor/tasks/TaskReorg.js +2 -2
  95. package/out/src/monitor/tasks/TaskReorg.js.map +1 -1
  96. package/out/src/monitor/tasks/TaskReviewDoubleSpends.d.ts +1 -1
  97. package/out/src/monitor/tasks/TaskReviewDoubleSpends.d.ts.map +1 -1
  98. package/out/src/monitor/tasks/TaskReviewDoubleSpends.js +10 -10
  99. package/out/src/monitor/tasks/TaskReviewDoubleSpends.js.map +1 -1
  100. package/out/src/monitor/tasks/TaskReviewProvenTxs.d.ts +1 -1
  101. package/out/src/monitor/tasks/TaskReviewProvenTxs.d.ts.map +1 -1
  102. package/out/src/monitor/tasks/TaskReviewProvenTxs.js +2 -2
  103. package/out/src/monitor/tasks/TaskReviewProvenTxs.js.map +1 -1
  104. package/out/src/monitor/tasks/TaskReviewStatus.d.ts +1 -1
  105. package/out/src/monitor/tasks/TaskReviewStatus.d.ts.map +1 -1
  106. package/out/src/monitor/tasks/TaskReviewStatus.js.map +1 -1
  107. package/out/src/monitor/tasks/TaskReviewUtxos.d.ts +1 -1
  108. package/out/src/monitor/tasks/TaskReviewUtxos.d.ts.map +1 -1
  109. package/out/src/monitor/tasks/TaskReviewUtxos.js.map +1 -1
  110. package/out/src/monitor/tasks/TaskSendWaiting.d.ts +1 -1
  111. package/out/src/monitor/tasks/TaskSendWaiting.d.ts.map +1 -1
  112. package/out/src/monitor/tasks/TaskSendWaiting.js +4 -5
  113. package/out/src/monitor/tasks/TaskSendWaiting.js.map +1 -1
  114. package/out/src/monitor/tasks/TaskUnFail.d.ts +1 -1
  115. package/out/src/monitor/tasks/TaskUnFail.d.ts.map +1 -1
  116. package/out/src/monitor/tasks/TaskUnFail.js +13 -15
  117. package/out/src/monitor/tasks/TaskUnFail.js.map +1 -1
  118. package/out/src/monitor/tasks/WalletMonitorTask.d.ts.map +1 -1
  119. package/out/src/monitor/tasks/WalletMonitorTask.js +3 -1
  120. package/out/src/monitor/tasks/WalletMonitorTask.js.map +1 -1
  121. package/out/src/sdk/CertOpsWallet.d.ts +3 -3
  122. package/out/src/sdk/CertOpsWallet.d.ts.map +1 -1
  123. package/out/src/sdk/PrivilegedKeyManager.d.ts +3 -3
  124. package/out/src/sdk/PrivilegedKeyManager.d.ts.map +1 -1
  125. package/out/src/sdk/PrivilegedKeyManager.js +26 -21
  126. package/out/src/sdk/PrivilegedKeyManager.js.map +1 -1
  127. package/out/src/sdk/WERR_errors.d.ts.map +1 -1
  128. package/out/src/sdk/WERR_errors.js +5 -5
  129. package/out/src/sdk/WERR_errors.js.map +1 -1
  130. package/out/src/sdk/WalletError.d.ts +1 -1
  131. package/out/src/sdk/WalletError.d.ts.map +1 -1
  132. package/out/src/sdk/WalletError.js +10 -3
  133. package/out/src/sdk/WalletError.js.map +1 -1
  134. package/out/src/sdk/WalletErrorFromJson.d.ts.map +1 -1
  135. package/out/src/sdk/WalletErrorFromJson.js +1 -3
  136. package/out/src/sdk/WalletErrorFromJson.js.map +1 -1
  137. package/out/src/sdk/WalletServices.interfaces.d.ts +19 -19
  138. package/out/src/sdk/WalletServices.interfaces.d.ts.map +1 -1
  139. package/out/src/sdk/types.d.ts +4 -4
  140. package/out/src/sdk/types.d.ts.map +1 -1
  141. package/out/src/sdk/types.js +3 -3
  142. package/out/src/sdk/types.js.map +1 -1
  143. package/out/src/services/ServiceCollection.d.ts +6 -6
  144. package/out/src/services/ServiceCollection.d.ts.map +1 -1
  145. package/out/src/services/ServiceCollection.js +3 -4
  146. package/out/src/services/ServiceCollection.js.map +1 -1
  147. package/out/src/services/Services.d.ts +5 -0
  148. package/out/src/services/Services.d.ts.map +1 -1
  149. package/out/src/services/Services.js +174 -182
  150. package/out/src/services/Services.js.map +1 -1
  151. package/out/src/services/chaintracker/BHServiceClient.d.ts.map +1 -1
  152. package/out/src/services/chaintracker/BHServiceClient.js +7 -7
  153. package/out/src/services/chaintracker/BHServiceClient.js.map +1 -1
  154. package/out/src/services/chaintracker/ChaintracksChainTracker.d.ts.map +1 -1
  155. package/out/src/services/chaintracker/ChaintracksChainTracker.js +5 -5
  156. package/out/src/services/chaintracker/ChaintracksChainTracker.js.map +1 -1
  157. package/out/src/services/chaintracker/chaintracks/Api/BlockHeaderApi.d.ts +5 -3
  158. package/out/src/services/chaintracker/chaintracks/Api/BlockHeaderApi.d.ts.map +1 -1
  159. package/out/src/services/chaintracker/chaintracks/Api/BlockHeaderApi.js.map +1 -1
  160. package/out/src/services/chaintracker/chaintracks/Api/BulkStorageApi.d.ts.map +1 -1
  161. package/out/src/services/chaintracker/chaintracks/Chaintracks.d.ts +20 -10
  162. package/out/src/services/chaintracker/chaintracks/Chaintracks.d.ts.map +1 -1
  163. package/out/src/services/chaintracker/chaintracks/Chaintracks.js +228 -221
  164. package/out/src/services/chaintracker/chaintracks/Chaintracks.js.map +1 -1
  165. package/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.d.ts.map +1 -1
  166. package/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.js +9 -10
  167. package/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.js.map +1 -1
  168. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorBase.d.ts.map +1 -1
  169. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorBase.js +1 -1
  170. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorBase.js.map +1 -1
  171. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.d.ts +1 -2
  172. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.d.ts.map +1 -1
  173. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.js +3 -3
  174. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.js.map +1 -1
  175. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDNBabbage.d.ts.map +1 -1
  176. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDNBabbage.js.map +1 -1
  177. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorWhatsOnChainCdn.d.ts.map +1 -1
  178. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorWhatsOnChainCdn.js +3 -3
  179. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorWhatsOnChainCdn.js.map +1 -1
  180. package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorBase.d.ts.map +1 -1
  181. package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorBase.js +1 -1
  182. package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorBase.js.map +1 -1
  183. package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.d.ts.map +1 -1
  184. package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.js +2 -2
  185. package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.js.map +1 -1
  186. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainIngestorWs.d.ts +2 -2
  187. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainIngestorWs.d.ts.map +1 -1
  188. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainIngestorWs.js +6 -39
  189. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainIngestorWs.js.map +1 -1
  190. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.d.ts +3 -3
  191. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.d.ts.map +1 -1
  192. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.js +8 -6
  193. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.js.map +1 -1
  194. package/out/src/services/chaintracker/chaintracks/Storage/BulkStorageBase.d.ts.map +1 -1
  195. package/out/src/services/chaintracker/chaintracks/Storage/BulkStorageBase.js +9 -16
  196. package/out/src/services/chaintracker/chaintracks/Storage/BulkStorageBase.js.map +1 -1
  197. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageBase.d.ts.map +1 -1
  198. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageBase.js +34 -22
  199. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageBase.js.map +1 -1
  200. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageIdb.d.ts.map +1 -1
  201. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageIdb.js +31 -30
  202. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageIdb.js.map +1 -1
  203. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageNoDb.d.ts +2 -2
  204. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageNoDb.d.ts.map +1 -1
  205. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageNoDb.js +11 -10
  206. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageNoDb.js.map +1 -1
  207. package/out/src/services/chaintracker/chaintracks/createIdbChaintracks.d.ts.map +1 -1
  208. package/out/src/services/chaintracker/chaintracks/createNoDbChaintracks.d.ts.map +1 -1
  209. package/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.d.ts +6 -1
  210. package/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.d.ts.map +1 -1
  211. package/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.js +247 -227
  212. package/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.js.map +1 -1
  213. package/out/src/services/chaintracker/chaintracks/util/BulkFileDataReader.d.ts.map +1 -1
  214. package/out/src/services/chaintracker/chaintracks/util/BulkFileDataReader.js +8 -7
  215. package/out/src/services/chaintracker/chaintracks/util/BulkFileDataReader.js.map +1 -1
  216. package/out/src/services/chaintracker/chaintracks/util/BulkFilesReader.d.ts.map +1 -1
  217. package/out/src/services/chaintracker/chaintracks/util/BulkFilesReader.js +35 -25
  218. package/out/src/services/chaintracker/chaintracks/util/BulkFilesReader.js.map +1 -1
  219. package/out/src/services/chaintracker/chaintracks/util/BulkHeaderFile.d.ts +5 -5
  220. package/out/src/services/chaintracker/chaintracks/util/BulkHeaderFile.d.ts.map +1 -1
  221. package/out/src/services/chaintracker/chaintracks/util/BulkHeaderFile.js +13 -11
  222. package/out/src/services/chaintracker/chaintracks/util/BulkHeaderFile.js.map +1 -1
  223. package/out/src/services/chaintracker/chaintracks/util/ChaintracksFetch.d.ts +0 -1
  224. package/out/src/services/chaintracker/chaintracks/util/ChaintracksFetch.d.ts.map +1 -1
  225. package/out/src/services/chaintracker/chaintracks/util/ChaintracksFetch.js.map +1 -1
  226. package/out/src/services/chaintracker/chaintracks/util/HeightRange.d.ts.map +1 -1
  227. package/out/src/services/chaintracker/chaintracks/util/HeightRange.js +21 -13
  228. package/out/src/services/chaintracker/chaintracks/util/HeightRange.js.map +1 -1
  229. package/out/src/services/chaintracker/chaintracks/util/SingleWriterMultiReaderLock.d.ts +2 -2
  230. package/out/src/services/chaintracker/chaintracks/util/SingleWriterMultiReaderLock.d.ts.map +1 -1
  231. package/out/src/services/chaintracker/chaintracks/util/SingleWriterMultiReaderLock.js.map +1 -1
  232. package/out/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.d.ts +1 -1
  233. package/out/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.d.ts.map +1 -1
  234. package/out/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.js +28 -24
  235. package/out/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.js.map +1 -1
  236. package/out/src/services/chaintracker/chaintracks/util/dirtyHashes.d.ts.map +1 -1
  237. package/out/src/services/chaintracker/chaintracks/util/dirtyHashes.js.map +1 -1
  238. package/out/src/services/chaintracker/chaintracks/util/validBulkHeaderFilesByFileHash.d.ts.map +1 -1
  239. package/out/src/services/chaintracker/chaintracks/util/validBulkHeaderFilesByFileHash.js +9 -10
  240. package/out/src/services/chaintracker/chaintracks/util/validBulkHeaderFilesByFileHash.js.map +1 -1
  241. package/out/src/services/createDefaultWalletServicesOptions.d.ts.map +1 -1
  242. package/out/src/services/createDefaultWalletServicesOptions.js +3 -3
  243. package/out/src/services/createDefaultWalletServicesOptions.js.map +1 -1
  244. package/out/src/services/providers/ARC.d.ts.map +1 -1
  245. package/out/src/services/providers/ARC.js +7 -14
  246. package/out/src/services/providers/ARC.js.map +1 -1
  247. package/out/src/services/providers/ArcSSEClient.d.ts.map +1 -1
  248. package/out/src/services/providers/ArcSSEClient.js +1 -1
  249. package/out/src/services/providers/ArcSSEClient.js.map +1 -1
  250. package/out/src/services/providers/Bitails.d.ts.map +1 -1
  251. package/out/src/services/providers/Bitails.js +17 -17
  252. package/out/src/services/providers/Bitails.js.map +1 -1
  253. package/out/src/services/providers/SdkWhatsOnChain.d.ts.map +1 -1
  254. package/out/src/services/providers/SdkWhatsOnChain.js.map +1 -1
  255. package/out/src/services/providers/WhatsOnChain.d.ts +2 -0
  256. package/out/src/services/providers/WhatsOnChain.d.ts.map +1 -1
  257. package/out/src/services/providers/WhatsOnChain.js +109 -233
  258. package/out/src/services/providers/WhatsOnChain.js.map +1 -1
  259. package/out/src/services/providers/exchangeRates.d.ts.map +1 -1
  260. package/out/src/services/providers/exchangeRates.js +3 -3
  261. package/out/src/services/providers/exchangeRates.js.map +1 -1
  262. package/out/src/services/providers/getBeefForTxid.d.ts +1 -1
  263. package/out/src/services/providers/getBeefForTxid.d.ts.map +1 -1
  264. package/out/src/services/providers/getBeefForTxid.js.map +1 -1
  265. package/out/src/services/providers/whatsOnChainHelpers.d.ts +68 -0
  266. package/out/src/services/providers/whatsOnChainHelpers.d.ts.map +1 -0
  267. package/out/src/services/providers/whatsOnChainHelpers.js +147 -0
  268. package/out/src/services/providers/whatsOnChainHelpers.js.map +1 -0
  269. package/out/src/signer/WalletSigner.d.ts.map +1 -1
  270. package/out/src/signer/WalletSigner.js.map +1 -1
  271. package/out/src/signer/methods/acquireDirectCertificate.js +1 -1
  272. package/out/src/signer/methods/acquireDirectCertificate.js.map +1 -1
  273. package/out/src/signer/methods/buildSignableTransaction.d.ts.map +1 -1
  274. package/out/src/signer/methods/buildSignableTransaction.js +21 -13
  275. package/out/src/signer/methods/buildSignableTransaction.js.map +1 -1
  276. package/out/src/signer/methods/completeSignedTransaction.d.ts.map +1 -1
  277. package/out/src/signer/methods/completeSignedTransaction.js +20 -21
  278. package/out/src/signer/methods/completeSignedTransaction.js.map +1 -1
  279. package/out/src/signer/methods/createAction.d.ts.map +1 -1
  280. package/out/src/signer/methods/createAction.js +8 -7
  281. package/out/src/signer/methods/createAction.js.map +1 -1
  282. package/out/src/signer/methods/internalizeAction.d.ts.map +1 -1
  283. package/out/src/signer/methods/internalizeAction.js +8 -6
  284. package/out/src/signer/methods/internalizeAction.js.map +1 -1
  285. package/out/src/signer/methods/proveCertificate.js +1 -1
  286. package/out/src/signer/methods/signAction.d.ts.map +1 -1
  287. package/out/src/signer/methods/signAction.js +8 -10
  288. package/out/src/signer/methods/signAction.js.map +1 -1
  289. package/out/src/storage/StorageIdb.d.ts +16 -1
  290. package/out/src/storage/StorageIdb.d.ts.map +1 -1
  291. package/out/src/storage/StorageIdb.js +536 -1221
  292. package/out/src/storage/StorageIdb.js.map +1 -1
  293. package/out/src/storage/StorageProvider.d.ts +10 -0
  294. package/out/src/storage/StorageProvider.d.ts.map +1 -1
  295. package/out/src/storage/StorageProvider.js +152 -182
  296. package/out/src/storage/StorageProvider.js.map +1 -1
  297. package/out/src/storage/StorageReader.d.ts.map +1 -1
  298. package/out/src/storage/StorageReader.js +8 -7
  299. package/out/src/storage/StorageReader.js.map +1 -1
  300. package/out/src/storage/StorageReaderWriter.d.ts.map +1 -1
  301. package/out/src/storage/StorageReaderWriter.js +32 -32
  302. package/out/src/storage/StorageReaderWriter.js.map +1 -1
  303. package/out/src/storage/StorageSyncReader.d.ts.map +1 -1
  304. package/out/src/storage/StorageSyncReader.js +3 -3
  305. package/out/src/storage/StorageSyncReader.js.map +1 -1
  306. package/out/src/storage/WalletStorageManager.d.ts +3 -0
  307. package/out/src/storage/WalletStorageManager.d.ts.map +1 -1
  308. package/out/src/storage/WalletStorageManager.js +83 -73
  309. package/out/src/storage/WalletStorageManager.js.map +1 -1
  310. package/out/src/storage/idbHelpers.d.ts +42 -0
  311. package/out/src/storage/idbHelpers.d.ts.map +1 -0
  312. package/out/src/storage/idbHelpers.js +375 -0
  313. package/out/src/storage/idbHelpers.js.map +1 -0
  314. package/out/src/storage/methods/ListActionsSpecOp.d.ts +6 -1
  315. package/out/src/storage/methods/ListActionsSpecOp.d.ts.map +1 -1
  316. package/out/src/storage/methods/ListActionsSpecOp.js +28 -2
  317. package/out/src/storage/methods/ListActionsSpecOp.js.map +1 -1
  318. package/out/src/storage/methods/ListOutputsSpecOp.d.ts.map +1 -1
  319. package/out/src/storage/methods/ListOutputsSpecOp.js +8 -11
  320. package/out/src/storage/methods/ListOutputsSpecOp.js.map +1 -1
  321. package/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts +83 -0
  322. package/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts.map +1 -1
  323. package/out/src/storage/methods/attemptToPostReqsToNetwork.js +224 -61
  324. package/out/src/storage/methods/attemptToPostReqsToNetwork.js.map +1 -1
  325. package/out/src/storage/methods/createAction.d.ts.map +1 -1
  326. package/out/src/storage/methods/createAction.js +230 -270
  327. package/out/src/storage/methods/createAction.js.map +1 -1
  328. package/out/src/storage/methods/generateChange.d.ts.map +1 -1
  329. package/out/src/storage/methods/generateChange.js +99 -80
  330. package/out/src/storage/methods/generateChange.js.map +1 -1
  331. package/out/src/storage/methods/getBeefForTransaction.js +15 -13
  332. package/out/src/storage/methods/getBeefForTransaction.js.map +1 -1
  333. package/out/src/storage/methods/getSyncChunk.d.ts.map +1 -1
  334. package/out/src/storage/methods/getSyncChunk.js +4 -3
  335. package/out/src/storage/methods/getSyncChunk.js.map +1 -1
  336. package/out/src/storage/methods/internalizeAction.js +41 -51
  337. package/out/src/storage/methods/internalizeAction.js.map +1 -1
  338. package/out/src/storage/methods/listActionsIdb.d.ts.map +1 -1
  339. package/out/src/storage/methods/listActionsIdb.js +85 -110
  340. package/out/src/storage/methods/listActionsIdb.js.map +1 -1
  341. package/out/src/storage/methods/listCertificates.d.ts +1 -1
  342. package/out/src/storage/methods/listCertificates.d.ts.map +1 -1
  343. package/out/src/storage/methods/listCertificates.js +7 -7
  344. package/out/src/storage/methods/listCertificates.js.map +1 -1
  345. package/out/src/storage/methods/listOutputsIdb.d.ts.map +1 -1
  346. package/out/src/storage/methods/listOutputsIdb.js +24 -27
  347. package/out/src/storage/methods/listOutputsIdb.js.map +1 -1
  348. package/out/src/storage/methods/offsetKey.d.ts +1 -1
  349. package/out/src/storage/methods/offsetKey.d.ts.map +1 -1
  350. package/out/src/storage/methods/offsetKey.js +3 -5
  351. package/out/src/storage/methods/offsetKey.js.map +1 -1
  352. package/out/src/storage/methods/processAction.d.ts +0 -11
  353. package/out/src/storage/methods/processAction.d.ts.map +1 -1
  354. package/out/src/storage/methods/processAction.js +90 -83
  355. package/out/src/storage/methods/processAction.js.map +1 -1
  356. package/out/src/storage/methods/purgeDataIdb.d.ts.map +1 -1
  357. package/out/src/storage/methods/purgeDataIdb.js +1 -1
  358. package/out/src/storage/methods/purgeDataIdb.js.map +1 -1
  359. package/out/src/storage/methods/reviewStatusIdb.d.ts +1 -1
  360. package/out/src/storage/methods/reviewStatusIdb.d.ts.map +1 -1
  361. package/out/src/storage/methods/reviewStatusIdb.js.map +1 -1
  362. package/out/src/storage/methods/utils.d.ts.map +1 -1
  363. package/out/src/storage/methods/utils.js +7 -1
  364. package/out/src/storage/methods/utils.js.map +1 -1
  365. package/out/src/storage/remoting/StorageClient.d.ts +4 -270
  366. package/out/src/storage/remoting/StorageClient.d.ts.map +1 -1
  367. package/out/src/storage/remoting/StorageClient.js +16 -423
  368. package/out/src/storage/remoting/StorageClient.js.map +1 -1
  369. package/out/src/storage/remoting/StorageClientBase.d.ts +289 -0
  370. package/out/src/storage/remoting/StorageClientBase.d.ts.map +1 -0
  371. package/out/src/storage/remoting/StorageClientBase.js +375 -0
  372. package/out/src/storage/remoting/StorageClientBase.js.map +1 -0
  373. package/out/src/storage/remoting/entityValidationHelpers.d.ts +29 -0
  374. package/out/src/storage/remoting/entityValidationHelpers.d.ts.map +1 -0
  375. package/out/src/storage/remoting/entityValidationHelpers.js +91 -0
  376. package/out/src/storage/remoting/entityValidationHelpers.js.map +1 -0
  377. package/out/src/storage/schema/StorageIdbSchema.d.ts +1 -1
  378. package/out/src/storage/schema/StorageIdbSchema.d.ts.map +1 -1
  379. package/out/src/storage/schema/entities/EntityBase.d.ts.map +1 -1
  380. package/out/src/storage/schema/entities/EntityBase.js.map +1 -1
  381. package/out/src/storage/schema/entities/EntityCertificate.d.ts.map +1 -1
  382. package/out/src/storage/schema/entities/EntityCertificate.js +5 -4
  383. package/out/src/storage/schema/entities/EntityCertificate.js.map +1 -1
  384. package/out/src/storage/schema/entities/EntityCertificateField.d.ts.map +1 -1
  385. package/out/src/storage/schema/entities/EntityCertificateField.js +5 -7
  386. package/out/src/storage/schema/entities/EntityCertificateField.js.map +1 -1
  387. package/out/src/storage/schema/entities/EntityCommission.d.ts.map +1 -1
  388. package/out/src/storage/schema/entities/EntityCommission.js +6 -8
  389. package/out/src/storage/schema/entities/EntityCommission.js.map +1 -1
  390. package/out/src/storage/schema/entities/EntityOutput.d.ts.map +1 -1
  391. package/out/src/storage/schema/entities/EntityOutput.js +21 -24
  392. package/out/src/storage/schema/entities/EntityOutput.js.map +1 -1
  393. package/out/src/storage/schema/entities/EntityOutputBasket.d.ts.map +1 -1
  394. package/out/src/storage/schema/entities/EntityOutputBasket.js +6 -6
  395. package/out/src/storage/schema/entities/EntityOutputBasket.js.map +1 -1
  396. package/out/src/storage/schema/entities/EntityOutputTag.d.ts.map +1 -1
  397. package/out/src/storage/schema/entities/EntityOutputTag.js +2 -2
  398. package/out/src/storage/schema/entities/EntityOutputTag.js.map +1 -1
  399. package/out/src/storage/schema/entities/EntityOutputTagMap.d.ts.map +1 -1
  400. package/out/src/storage/schema/entities/EntityOutputTagMap.js +4 -6
  401. package/out/src/storage/schema/entities/EntityOutputTagMap.js.map +1 -1
  402. package/out/src/storage/schema/entities/EntityProvenTx.d.ts +3 -3
  403. package/out/src/storage/schema/entities/EntityProvenTx.d.ts.map +1 -1
  404. package/out/src/storage/schema/entities/EntityProvenTx.js +22 -23
  405. package/out/src/storage/schema/entities/EntityProvenTx.js.map +1 -1
  406. package/out/src/storage/schema/entities/EntityProvenTxReq.d.ts +9 -0
  407. package/out/src/storage/schema/entities/EntityProvenTxReq.d.ts.map +1 -1
  408. package/out/src/storage/schema/entities/EntityProvenTxReq.js +116 -68
  409. package/out/src/storage/schema/entities/EntityProvenTxReq.js.map +1 -1
  410. package/out/src/storage/schema/entities/EntitySyncState.d.ts.map +1 -1
  411. package/out/src/storage/schema/entities/EntitySyncState.js +19 -18
  412. package/out/src/storage/schema/entities/EntitySyncState.js.map +1 -1
  413. package/out/src/storage/schema/entities/EntityTransaction.d.ts.map +1 -1
  414. package/out/src/storage/schema/entities/EntityTransaction.js +25 -26
  415. package/out/src/storage/schema/entities/EntityTransaction.js.map +1 -1
  416. package/out/src/storage/schema/entities/EntityTxLabel.d.ts.map +1 -1
  417. package/out/src/storage/schema/entities/EntityTxLabel.js +2 -2
  418. package/out/src/storage/schema/entities/EntityTxLabel.js.map +1 -1
  419. package/out/src/storage/schema/entities/EntityTxLabelMap.d.ts.map +1 -1
  420. package/out/src/storage/schema/entities/EntityTxLabelMap.js +4 -6
  421. package/out/src/storage/schema/entities/EntityTxLabelMap.js.map +1 -1
  422. package/out/src/storage/schema/entities/EntityUser.d.ts.map +1 -1
  423. package/out/src/storage/schema/entities/EntityUser.js +3 -3
  424. package/out/src/storage/schema/entities/EntityUser.js.map +1 -1
  425. package/out/src/storage/schema/entities/MergeEntity.d.ts.map +1 -1
  426. package/out/src/storage/schema/entities/MergeEntity.js +6 -6
  427. package/out/src/storage/schema/entities/MergeEntity.js.map +1 -1
  428. package/out/src/storage/schema/tables/TableCertificate.d.ts +2 -1
  429. package/out/src/storage/schema/tables/TableCertificate.d.ts.map +1 -1
  430. package/out/src/storage/schema/tables/TableCertificateField.d.ts +1 -1
  431. package/out/src/storage/schema/tables/TableCertificateField.d.ts.map +1 -1
  432. package/out/src/storage/schema/tables/TableCommission.d.ts +1 -1
  433. package/out/src/storage/schema/tables/TableCommission.d.ts.map +1 -1
  434. package/out/src/storage/schema/tables/TableMonitorEvent.d.ts +1 -1
  435. package/out/src/storage/schema/tables/TableMonitorEvent.d.ts.map +1 -1
  436. package/out/src/storage/schema/tables/TableOutput.d.ts +3 -2
  437. package/out/src/storage/schema/tables/TableOutput.d.ts.map +1 -1
  438. package/out/src/storage/schema/tables/TableOutput.js +1 -1
  439. package/out/src/storage/schema/tables/TableOutput.js.map +1 -1
  440. package/out/src/storage/schema/tables/TableOutputBasket.d.ts +1 -1
  441. package/out/src/storage/schema/tables/TableOutputBasket.d.ts.map +1 -1
  442. package/out/src/storage/schema/tables/TableOutputTag.d.ts +1 -1
  443. package/out/src/storage/schema/tables/TableOutputTag.d.ts.map +1 -1
  444. package/out/src/storage/schema/tables/TableOutputTagMap.d.ts +1 -1
  445. package/out/src/storage/schema/tables/TableOutputTagMap.d.ts.map +1 -1
  446. package/out/src/storage/schema/tables/TableProvenTx.d.ts +1 -1
  447. package/out/src/storage/schema/tables/TableProvenTx.d.ts.map +1 -1
  448. package/out/src/storage/schema/tables/TableProvenTxReq.d.ts +24 -1
  449. package/out/src/storage/schema/tables/TableProvenTxReq.d.ts.map +1 -1
  450. package/out/src/storage/schema/tables/TableSettings.d.ts +1 -1
  451. package/out/src/storage/schema/tables/TableSettings.d.ts.map +1 -1
  452. package/out/src/storage/schema/tables/TableSyncState.d.ts +1 -1
  453. package/out/src/storage/schema/tables/TableSyncState.d.ts.map +1 -1
  454. package/out/src/storage/schema/tables/TableTransaction.d.ts +1 -1
  455. package/out/src/storage/schema/tables/TableTransaction.d.ts.map +1 -1
  456. package/out/src/storage/schema/tables/TableTxLabel.d.ts +1 -1
  457. package/out/src/storage/schema/tables/TableTxLabel.d.ts.map +1 -1
  458. package/out/src/storage/schema/tables/TableTxLabelMap.d.ts +1 -1
  459. package/out/src/storage/schema/tables/TableTxLabelMap.d.ts.map +1 -1
  460. package/out/src/storage/schema/tables/TableUser.d.ts +1 -1
  461. package/out/src/storage/schema/tables/TableUser.d.ts.map +1 -1
  462. package/out/src/storage/storageProviderHelpers.d.ts +34 -0
  463. package/out/src/storage/storageProviderHelpers.d.ts.map +1 -0
  464. package/out/src/storage/storageProviderHelpers.js +100 -0
  465. package/out/src/storage/storageProviderHelpers.js.map +1 -0
  466. package/out/src/utility/ScriptTemplateBRC29.d.ts.map +1 -1
  467. package/out/src/utility/ScriptTemplateBRC29.js +2 -1
  468. package/out/src/utility/ScriptTemplateBRC29.js.map +1 -1
  469. package/out/src/utility/aggregateResults.d.ts +1 -1
  470. package/out/src/utility/aggregateResults.d.ts.map +1 -1
  471. package/out/src/utility/aggregateResults.js +2 -2
  472. package/out/src/utility/aggregateResults.js.map +1 -1
  473. package/out/src/utility/brc114ActionTimeLabels.d.ts +2 -2
  474. package/out/src/utility/brc114ActionTimeLabels.d.ts.map +1 -1
  475. package/out/src/utility/brc114ActionTimeLabels.js +16 -9
  476. package/out/src/utility/brc114ActionTimeLabels.js.map +1 -1
  477. package/out/src/utility/identityUtils.js +1 -1
  478. package/out/src/utility/identityUtils.js.map +1 -1
  479. package/out/src/utility/parseTxScriptOffsets.d.ts +4 -4
  480. package/out/src/utility/parseTxScriptOffsets.d.ts.map +1 -1
  481. package/out/src/utility/parseTxScriptOffsets.js.map +1 -1
  482. package/out/src/utility/stampLog.d.ts.map +1 -1
  483. package/out/src/utility/stampLog.js +7 -5
  484. package/out/src/utility/stampLog.js.map +1 -1
  485. package/out/src/utility/tscProofToMerklePath.d.ts.map +1 -1
  486. package/out/src/utility/tscProofToMerklePath.js +1 -1
  487. package/out/src/utility/tscProofToMerklePath.js.map +1 -1
  488. package/out/src/utility/utilityHelpers.d.ts +1 -2
  489. package/out/src/utility/utilityHelpers.d.ts.map +1 -1
  490. package/out/src/utility/utilityHelpers.js +10 -10
  491. package/out/src/utility/utilityHelpers.js.map +1 -1
  492. package/out/src/utility/utilityHelpers.noBuffer.d.ts +7 -3
  493. package/out/src/utility/utilityHelpers.noBuffer.d.ts.map +1 -1
  494. package/out/src/utility/utilityHelpers.noBuffer.js +3 -3
  495. package/out/src/utility/utilityHelpers.noBuffer.js.map +1 -1
  496. package/out/src/wab-client/WABClient.d.ts +1 -1
  497. package/out/src/wab-client/WABClient.d.ts.map +1 -1
  498. package/out/src/wab-client/WABClient.js +12 -12
  499. package/out/src/wab-client/WABClient.js.map +1 -1
  500. package/out/src/wab-client/auth-method-interactors/AuthMethodInteractor.d.ts.map +1 -1
  501. package/out/src/wab-client/auth-method-interactors/AuthMethodInteractor.js +3 -3
  502. package/out/src/wab-client/auth-method-interactors/AuthMethodInteractor.js.map +1 -1
  503. package/out/tsconfig.client.tsbuildinfo +1 -1
  504. package/package.json +7 -6
@@ -18,14 +18,16 @@ function setDisableDoubleSpendCheckForTest(v) {
18
18
  }
19
19
  async function createAction(storage, auth, vargs, originator) {
20
20
  const logger = vargs.logger;
21
- logger === null || logger === void 0 ? void 0 : logger.group(`storage createAction`);
22
- //stampLog(vargs, `start storage createTransactionSdk`)
21
+ logger === null || logger === void 0 ? void 0 : logger.group('storage createAction');
22
+ // stampLog(vargs, `start storage createTransactionSdk`)
23
23
  if (vargs.isTestWerrReviewActions)
24
24
  (0, Wallet_1.throwDummyReviewActions)();
25
- if (!vargs.isNewTx)
26
- // The purpose of this function is to create the initial storage records associated
27
- // with a new transaction. It's an error if we have no new inputs or outputs...
25
+ if (!vargs.isNewTx)
26
+ // The purpose of this function is to create the initial storage records associated
27
+ // with a new transaction. It's an error if we have no new inputs or outputs...
28
+ {
28
29
  throw new WERR_errors_1.WERR_INTERNAL();
30
+ }
29
31
  /**
30
32
  * Steps to create a transaction:
31
33
  * - Verify that all inputs either have proof in vargs.inputBEEF or that options.trustSelf === 'known' and input txid.vout are known valid to storage.
@@ -59,7 +61,7 @@ async function createAction(storage, auth, vargs, originator) {
59
61
  await preflightInsufficientFundsFastPath(vargs, xinputs, xoutputs, noSendChangeIn, availableChangeCount, feeModel);
60
62
  logger === null || logger === void 0 ? void 0 : logger.log('passed insufficient-funds preflight');
61
63
  const newTx = await createNewTxRecord(storage, userId, vargs, storageBeef);
62
- logger === null || logger === void 0 ? void 0 : logger.log(`created new transaction record`);
64
+ logger === null || logger === void 0 ? void 0 : logger.log('created new transaction record');
63
65
  const ctx = {
64
66
  xinputs,
65
67
  xoutputs,
@@ -70,23 +72,23 @@ async function createAction(storage, auth, vargs, originator) {
70
72
  transactionId: newTx.transactionId
71
73
  };
72
74
  const { allocatedChange, changeOutputs, derivationPrefix, maxPossibleSatoshisAdjustment } = await fundNewTransactionSdk(storage, userId, vargs, ctx);
73
- logger === null || logger === void 0 ? void 0 : logger.log(`funded new transaction`);
74
- if (maxPossibleSatoshisAdjustment) {
75
+ logger === null || logger === void 0 ? void 0 : logger.log('funded new transaction');
76
+ if (maxPossibleSatoshisAdjustment != null) {
75
77
  const a = maxPossibleSatoshisAdjustment;
76
78
  if (ctx.xoutputs[a.fixedOutputIndex].satoshis !== generateChange_1.maxPossibleSatoshis)
77
79
  throw new WERR_errors_1.WERR_INTERNAL();
78
80
  ctx.xoutputs[a.fixedOutputIndex].satoshis = a.satoshis;
79
- logger === null || logger === void 0 ? void 0 : logger.log(`adjusted change outputs to max possible`);
81
+ logger === null || logger === void 0 ? void 0 : logger.log('adjusted change outputs to max possible');
80
82
  }
81
83
  // The satoshis of the transaction is the satoshis we get back in change minus the satoshis we spend.
82
84
  const satoshis = changeOutputs.reduce((a, e) => a + e.satoshis, 0) - allocatedChange.reduce((a, e) => a + e.satoshis, 0);
83
85
  await storage.updateTransaction(newTx.transactionId, { satoshis });
84
86
  const { outputs, changeVouts } = await createNewOutputs(storage, userId, vargs, ctx, changeOutputs);
85
- logger === null || logger === void 0 ? void 0 : logger.log(`created new output records`);
87
+ logger === null || logger === void 0 ? void 0 : logger.log('created new output records');
86
88
  const inputBeef = await mergeAllocatedChangeBeefs(storage, userId, vargs, allocatedChange, beef);
87
- logger === null || logger === void 0 ? void 0 : logger.log(`merged allocated change beefs`);
89
+ logger === null || logger === void 0 ? void 0 : logger.log('merged allocated change beefs');
88
90
  const inputs = await createNewInputs(storage, userId, vargs, ctx, allocatedChange);
89
- logger === null || logger === void 0 ? void 0 : logger.log(`created new inputs`);
91
+ logger === null || logger === void 0 ? void 0 : logger.log('created new inputs');
90
92
  const r = {
91
93
  reference: newTx.reference,
92
94
  version: newTx.version,
@@ -108,7 +110,7 @@ function makeDefaultOutput(userId, transactionId, satoshis, vout) {
108
110
  outputId: 0,
109
111
  userId,
110
112
  transactionId,
111
- satoshis: satoshis,
113
+ satoshis,
112
114
  vout,
113
115
  basketId: undefined,
114
116
  change: false,
@@ -128,115 +130,162 @@ function makeDefaultOutput(userId, transactionId, satoshis, vout) {
128
130
  };
129
131
  return output;
130
132
  }
133
+ /** Check known outputs for double-spend, mark them spent, return competing txid if found. */
134
+ async function markKnownInputsSpent(storage, knownInputRows, transactionId) {
135
+ let doubleSpendTxid;
136
+ await storage.transaction(async (trx) => {
137
+ const outputIds = knownInputRows.map(ni => (0, utilityHelpers_1.verifyId)(ni.o.outputId));
138
+ const knownOutputsById = await storage.findOutputsByIds(outputIds, trx);
139
+ for (const ni of knownInputRows) {
140
+ const { i, o } = ni;
141
+ const o2 = knownOutputsById[(0, utilityHelpers_1.verifyId)(o.outputId)];
142
+ if (!o2)
143
+ throw new WERR_errors_1.WERR_INTERNAL(`missing outputId ${o.outputId}`);
144
+ if (o2.spentBy !== undefined) {
145
+ const spendingTx = await storage.findTransactionById((0, utilityHelpers_1.verifyId)(o2.spentBy), trx);
146
+ if (spendingTx === null || spendingTx === void 0 ? void 0 : spendingTx.txid) {
147
+ doubleSpendTxid = spendingTx.txid;
148
+ return;
149
+ }
150
+ }
151
+ if (!o2.spendable) {
152
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER(`inputs[${i.vin}]`, `spendable output. output ${o.txid}:${o.vout} appears to have been spent (spendable=${o2.spendable}).`);
153
+ }
154
+ await storage.updateOutput((0, utilityHelpers_1.verifyId)(o.outputId), { spendable: false, spentBy: transactionId, spendingDescription: i.inputDescription }, trx);
155
+ o.spendable = false;
156
+ o.spentBy = transactionId;
157
+ o.spendingDescription = i.inputDescription;
158
+ }
159
+ });
160
+ return doubleSpendTxid;
161
+ }
162
+ /** Build an SDK input record for a new-input row that has a backing output. */
163
+ async function buildSdkInputFromOutput(storage, vargs, vin, i, o, unlockLen) {
164
+ if ((i == null) && !unlockLen)
165
+ throw new WERR_errors_1.WERR_INTERNAL(`vin ${vin} non-fixedInput without unlockLen`);
166
+ const sourceTransaction = vargs.includeAllSourceTransactions && vargs.isSignAction
167
+ ? await storage.getRawTxOfKnownValidTransaction(o.txid)
168
+ : undefined;
169
+ return {
170
+ vin,
171
+ sourceTxid: o.txid,
172
+ sourceVout: o.vout,
173
+ sourceSatoshis: o.satoshis,
174
+ sourceLockingScript: (0, utilityHelpers_noBuffer_1.asString)(o.lockingScript),
175
+ sourceTransaction,
176
+ unlockingScriptLength: unlockLen || i.unlockingScriptLength,
177
+ providedBy: (i != null) && o.providedBy === 'storage' ? 'you-and-storage' : o.providedBy,
178
+ type: o.type,
179
+ spendingDescription: o.spendingDescription || undefined,
180
+ derivationPrefix: o.derivationPrefix || undefined,
181
+ derivationSuffix: o.derivationSuffix || undefined,
182
+ senderIdentityKey: o.senderIdentityKey || undefined
183
+ };
184
+ }
185
+ /** Build an SDK input record for a user-specified input with no corresponding stored output. */
186
+ function buildSdkInputFromXInput(vin, i) {
187
+ return {
188
+ vin,
189
+ sourceTxid: i.outpoint.txid,
190
+ sourceVout: i.outpoint.vout,
191
+ sourceSatoshis: i.satoshis,
192
+ sourceLockingScript: i.lockingScript.toHex(),
193
+ unlockingScriptLength: i.unlockingScriptLength,
194
+ providedBy: 'you',
195
+ type: 'custom',
196
+ spendingDescription: undefined,
197
+ derivationPrefix: undefined,
198
+ derivationSuffix: undefined,
199
+ senderIdentityKey: undefined
200
+ };
201
+ }
131
202
  async function createNewInputs(storage, userId, vargs, ctx, allocatedChange) {
132
203
  const r = [];
133
204
  const newInputs = [];
134
- for (const i of ctx.xinputs) {
135
- const o = i.output;
136
- newInputs.push({ i, o });
137
- }
138
- const knownInputRows = newInputs.filter((ni) => !!ni.i && !!ni.o);
205
+ for (const i of ctx.xinputs)
206
+ newInputs.push({ i, o: i.output });
207
+ const knownInputRows = newInputs.filter((ni) => ni.i != null && ni.o != null);
139
208
  if (knownInputRows.length > 0) {
140
- let doubleSpendTxid;
141
- await storage.transaction(async (trx) => {
142
- const outputIds = knownInputRows.map(ni => (0, utilityHelpers_1.verifyId)(ni.o.outputId));
143
- const knownOutputsById = await storage.findOutputsByIds(outputIds, trx);
144
- for (const ni of knownInputRows) {
145
- const { i, o } = ni;
146
- const o2 = knownOutputsById[(0, utilityHelpers_1.verifyId)(o.outputId)];
147
- if (!o2)
148
- throw new WERR_errors_1.WERR_INTERNAL(`missing outputId ${o.outputId}`);
149
- if (o2.spentBy !== undefined) {
150
- const spendingTx = await storage.findTransactionById((0, utilityHelpers_1.verifyId)(o2.spentBy), trx);
151
- if (spendingTx === null || spendingTx === void 0 ? void 0 : spendingTx.txid) {
152
- doubleSpendTxid = spendingTx.txid;
153
- return;
154
- }
155
- }
156
- if (o2.spendable != true) {
157
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(`inputs[${i.vin}]`, `spendable output. output ${o.txid}:${o.vout} appears to have been spent (spendable=${o2.spendable}).`);
158
- }
159
- await storage.updateOutput((0, utilityHelpers_1.verifyId)(o.outputId), {
160
- spendable: false,
161
- spentBy: ctx.transactionId,
162
- spendingDescription: i.inputDescription
163
- }, trx);
164
- o.spendable = false;
165
- o.spentBy = ctx.transactionId;
166
- o.spendingDescription = i.inputDescription;
167
- }
168
- });
209
+ const doubleSpendTxid = await markKnownInputsSpent(storage, knownInputRows, ctx.transactionId);
169
210
  if (doubleSpendTxid) {
170
211
  const beef = await storage.getBeefForTransaction(doubleSpendTxid, {});
171
- const rar = {
172
- txid: '',
173
- status: 'doubleSpend',
174
- competingTxs: [doubleSpendTxid],
175
- competingBeef: beef.toBinary()
176
- };
177
- throw new WERR_errors_1.WERR_REVIEW_ACTIONS([rar], []);
212
+ throw new WERR_errors_1.WERR_REVIEW_ACTIONS([{ txid: '', status: 'doubleSpend', competingTxs: [doubleSpendTxid], competingBeef: beef.toBinary() }], []);
178
213
  }
179
214
  }
180
- for (const o of allocatedChange) {
215
+ for (const o of allocatedChange)
181
216
  newInputs.push({ o, unlockLen: 107 });
182
- }
183
217
  let vin = -1;
184
218
  for (const { i, o, unlockLen } of newInputs) {
185
219
  vin++;
186
- if (o) {
187
- if (!i && !unlockLen)
188
- throw new WERR_errors_1.WERR_INTERNAL(`vin ${vin} non-fixedInput without unlockLen`);
189
- const sourceTransaction = vargs.includeAllSourceTransactions && vargs.isSignAction
190
- ? await storage.getRawTxOfKnownValidTransaction(o.txid)
191
- : undefined;
192
- const ri = {
193
- vin,
194
- sourceTxid: o.txid,
195
- sourceVout: o.vout,
196
- sourceSatoshis: o.satoshis,
197
- sourceLockingScript: (0, utilityHelpers_noBuffer_1.asString)(o.lockingScript),
198
- sourceTransaction,
199
- unlockingScriptLength: unlockLen ? unlockLen : i.unlockingScriptLength,
200
- providedBy: i && o.providedBy === 'storage' ? 'you-and-storage' : o.providedBy,
201
- type: o.type,
202
- spendingDescription: o.spendingDescription || undefined,
203
- derivationPrefix: o.derivationPrefix || undefined,
204
- derivationSuffix: o.derivationSuffix || undefined,
205
- senderIdentityKey: o.senderIdentityKey || undefined
206
- };
207
- r.push(ri);
220
+ if (o != null) {
221
+ r.push(await buildSdkInputFromOutput(storage, vargs, vin, i, o, unlockLen));
208
222
  }
209
223
  else {
210
- if (!i)
224
+ if (i == null)
211
225
  throw new WERR_errors_1.WERR_INTERNAL(`vin ${vin} without output or xinput`);
212
- // user specified input with no corresponding output being spent.
213
- const ri = {
214
- vin,
215
- sourceTxid: i.outpoint.txid,
216
- sourceVout: i.outpoint.vout,
217
- sourceSatoshis: i.satoshis,
218
- sourceLockingScript: i.lockingScript.toHex(),
219
- unlockingScriptLength: i.unlockingScriptLength,
220
- providedBy: 'you',
221
- type: 'custom',
222
- spendingDescription: undefined,
223
- derivationPrefix: undefined,
224
- derivationSuffix: undefined,
225
- senderIdentityKey: undefined
226
- };
227
- r.push(ri);
226
+ r.push(buildSdkInputFromXInput(vin, i));
228
227
  }
229
228
  }
230
229
  return r;
231
230
  }
232
- async function createNewOutputs(storage, userId, vargs, ctx, changeOutputs) {
231
+ /** Randomly reassign vout values across newOutputs using either the provided randomVals or crypto-random bytes. */
232
+ function randomizeOutputVouts(newOutputs, randomVals) {
233
+ const vals = [...(randomVals || [])];
234
+ const nextRandom = () => {
235
+ if (vals.length > 0) {
236
+ const v = vals.shift();
237
+ vals.push(v);
238
+ return v;
239
+ }
240
+ const bytes = (0, sdk_1.Random)(4);
241
+ return (((bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3]) >>> 0) / 0x100000000;
242
+ };
243
+ const newVouts = Array.from({ length: newOutputs.length }, (_, i) => i);
244
+ for (let cur = newVouts.length; cur > 0; cur--) {
245
+ const rnd = Math.floor(nextRandom() * cur);
246
+ [newVouts[cur - 1], newVouts[rnd]] = [newVouts[rnd], newVouts[cur - 1]];
247
+ }
248
+ let vout = -1;
249
+ for (const no of newOutputs) {
250
+ vout++;
251
+ if (no.o.vout !== vout)
252
+ throw new WERR_errors_1.WERR_INTERNAL(`new output ${vout} has out of order vout ${no.o.vout}`);
253
+ no.o.vout = newVouts[vout];
254
+ }
255
+ }
256
+ /** Insert the output and attach its tags; return the SDK output descriptor. */
257
+ async function persistNewOutput(storage, o, tags, txTags, txBaskets) {
233
258
  var _a;
234
- const outputs = [];
235
- // Lookup output baskets
259
+ o.outputId = await storage.insertOutput(o);
260
+ const changeVout = (o.change && o.purpose === 'change' && o.providedBy === 'storage') ? o.vout : undefined;
261
+ for (const tagName of new Set(tags)) {
262
+ const tag = txTags[tagName];
263
+ await storage.insertOutputTagMap({
264
+ outputId: (0, utilityHelpers_1.verifyId)(o.outputId),
265
+ outputTagId: (0, utilityHelpers_1.verifyId)(tag.outputTagId),
266
+ created_at: new Date(),
267
+ updated_at: new Date(),
268
+ isDeleted: false
269
+ });
270
+ }
271
+ const ro = {
272
+ vout: (0, utilityHelpers_1.verifyInteger)(o.vout),
273
+ satoshis: sdk_1.Validation.validateSatoshis(o.satoshis, 'o.satoshis'),
274
+ lockingScript: (o.lockingScript == null) ? '' : (0, utilityHelpers_noBuffer_1.asString)(o.lockingScript),
275
+ providedBy: (0, utilityHelpers_1.verifyTruthy)(o.providedBy),
276
+ purpose: o.purpose || undefined,
277
+ basket: (_a = Object.values(txBaskets).find(b => b.basketId === o.basketId)) === null || _a === void 0 ? void 0 : _a.name,
278
+ tags,
279
+ outputDescription: o.outputDescription,
280
+ derivationSuffix: o.derivationSuffix,
281
+ customInstructions: o.customInstructions
282
+ };
283
+ return { changeVout, ro };
284
+ }
285
+ async function createNewOutputs(storage, userId, vargs, ctx, changeOutputs) {
236
286
  const txBaskets = {};
237
287
  const basketNames = [...new Set(ctx.xoutputs.map(x => x.basket).filter((v) => !!v))];
238
288
  Object.assign(txBaskets, await storage.findOrInsertOutputBasketsBulk(userId, basketNames));
239
- // Lookup output tags
240
289
  const txTags = {};
241
290
  const tagNames = [...new Set(ctx.xoutputs.flatMap(x => x.tags))];
242
291
  Object.assign(txTags, await storage.findOrInsertOutputTagsBulk(userId, tagNames));
@@ -245,17 +294,7 @@ async function createNewOutputs(storage, userId, vargs, ctx, changeOutputs) {
245
294
  const lockingScript = (0, utilityHelpers_noBuffer_1.asArray)(xo.lockingScript);
246
295
  if (xo.purpose === 'service-charge') {
247
296
  const now = new Date();
248
- await storage.insertCommission({
249
- userId,
250
- transactionId: ctx.transactionId,
251
- lockingScript,
252
- satoshis: xo.satoshis,
253
- isRedeemed: false,
254
- keyOffset: (0, utilityHelpers_1.verifyTruthy)(xo.keyOffset),
255
- created_at: now,
256
- updated_at: now,
257
- commissionId: 0
258
- });
297
+ await storage.insertCommission({ userId, transactionId: ctx.transactionId, lockingScript, satoshis: xo.satoshis, isRedeemed: false, keyOffset: (0, utilityHelpers_1.verifyTruthy)(xo.keyOffset), created_at: now, updated_at: now, commissionId: 0 });
259
298
  const o = makeDefaultOutput(userId, ctx.transactionId, xo.satoshis, xo.vout);
260
299
  o.lockingScript = lockingScript;
261
300
  o.providedBy = 'storage';
@@ -265,11 +304,9 @@ async function createNewOutputs(storage, userId, vargs, ctx, changeOutputs) {
265
304
  newOutputs.push({ o, tags: [] });
266
305
  }
267
306
  else {
268
- // The user wants tracking if they put their output in a basket
269
- const basketId = !xo.basket ? undefined : txBaskets[xo.basket].basketId;
270
307
  const o = makeDefaultOutput(userId, ctx.transactionId, xo.satoshis, xo.vout);
271
308
  o.lockingScript = lockingScript;
272
- o.basketId = basketId;
309
+ o.basketId = xo.basket ? txBaskets[xo.basket].basketId : undefined;
273
310
  o.customInstructions = xo.customInstructions;
274
311
  o.outputDescription = xo.outputDescription;
275
312
  o.providedBy = xo.providedBy;
@@ -282,74 +319,14 @@ async function createNewOutputs(storage, userId, vargs, ctx, changeOutputs) {
282
319
  o.spendable = true;
283
320
  newOutputs.push({ o, tags: [] });
284
321
  }
285
- if (vargs.options.randomizeOutputs) {
286
- const randomVals = [];
287
- const nextRandomVal = () => {
288
- let val = 0;
289
- if (!randomVals || randomVals.length === 0) {
290
- const bytes = (0, sdk_1.Random)(4);
291
- val = (((bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3]) >>> 0) / 0x100000000;
292
- }
293
- else {
294
- val = randomVals.shift() || 0;
295
- randomVals.push(val);
296
- }
297
- return val;
298
- };
299
- /** In-place array shuffle */
300
- const shuffleArray = (array) => {
301
- let currentIndex = array.length;
302
- let temporaryValue;
303
- let randomIndex;
304
- while (currentIndex !== 0) {
305
- randomIndex = Math.floor(nextRandomVal() * currentIndex);
306
- currentIndex -= 1;
307
- temporaryValue = array[currentIndex];
308
- array[currentIndex] = array[randomIndex];
309
- array[randomIndex] = temporaryValue;
310
- }
311
- return array;
312
- };
313
- let vout = -1;
314
- const newVouts = Array(newOutputs.length);
315
- for (let i = 0; i < newVouts.length; i++)
316
- newVouts[i] = i;
317
- shuffleArray(newVouts);
318
- for (const no of newOutputs) {
319
- vout++;
320
- if (no.o.vout !== vout)
321
- throw new WERR_errors_1.WERR_INTERNAL(`new output ${vout} has out of order vout ${no.o.vout}`);
322
- no.o.vout = newVouts[vout];
323
- }
324
- }
322
+ if (vargs.options.randomizeOutputs)
323
+ randomizeOutputVouts(newOutputs, vargs.randomVals);
324
+ const outputs = [];
325
325
  const changeVouts = [];
326
326
  for (const { o, tags } of newOutputs) {
327
- o.outputId = await storage.insertOutput(o);
328
- if (o.change && o.purpose === 'change' && o.providedBy === 'storage')
329
- changeVouts.push(o.vout);
330
- // Add tags to the output
331
- for (const tagName of [...new Set(tags)]) {
332
- const tag = txTags[tagName];
333
- await storage.insertOutputTagMap({
334
- outputId: (0, utilityHelpers_1.verifyId)(o.outputId),
335
- outputTagId: (0, utilityHelpers_1.verifyId)(tag.outputTagId),
336
- created_at: new Date(),
337
- updated_at: new Date(),
338
- isDeleted: false
339
- });
340
- }
341
- const ro = {
342
- vout: (0, utilityHelpers_1.verifyInteger)(o.vout),
343
- satoshis: sdk_1.Validation.validateSatoshis(o.satoshis, 'o.satoshis'),
344
- lockingScript: !o.lockingScript ? '' : (0, utilityHelpers_noBuffer_1.asString)(o.lockingScript),
345
- providedBy: (0, utilityHelpers_1.verifyTruthy)(o.providedBy),
346
- purpose: o.purpose || undefined,
347
- basket: (_a = Object.values(txBaskets).find(b => b.basketId === o.basketId)) === null || _a === void 0 ? void 0 : _a.name,
348
- tags: tags,
349
- outputDescription: o.outputDescription,
350
- derivationSuffix: o.derivationSuffix,
351
- customInstructions: o.customInstructions
352
- };
327
+ const { changeVout, ro } = await persistNewOutput(storage, o, tags, txTags, txBaskets);
328
+ if (changeVout !== undefined)
329
+ changeVouts.push(changeVout);
353
330
  outputs.push(ro);
354
331
  }
355
332
  return { outputs, changeVouts };
@@ -455,11 +432,11 @@ function validateRequiredOutputs(storage, userId, vargs) {
455
432
  * @returns {xinputs} extended validated required inputs.
456
433
  */
457
434
  async function validateRequiredInputs(storage, userId, vargs) {
458
- //stampLog(vargs, `start storage verifyInputBeef`)
435
+ // stampLog(vargs, `start storage verifyInputBeef`)
459
436
  const beef = new sdk_1.Beef();
460
437
  if (vargs.inputs.length === 0)
461
438
  return { storageBeef: beef, beef, xinputs: [] };
462
- if (vargs.inputBEEF)
439
+ if (vargs.inputBEEF != null)
463
440
  beef.mergeBeef(vargs.inputBEEF);
464
441
  const xinputs = vargs.inputs.map((input, vin) => ({
465
442
  ...input,
@@ -472,98 +449,78 @@ async function validateRequiredInputs(storage, userId, vargs) {
472
449
  const inputTxids = {};
473
450
  for (const input of xinputs)
474
451
  inputTxids[input.outpoint.txid] = true;
475
- // Check beef from user that either there are no txidOnly entries,
476
- // or that we can trust storage data and it does indeed vouch
477
- // for any txidOnly entries
452
+ await validateBeefTxidOnlyEntries(beef, inputTxids, trustSelf, storage);
453
+ await ensureBeefContainsAllInputTxids(beef, inputTxids, trustSelf, storage);
454
+ if (!(await beef.verify(await storage.getServices().getChainTracker(), true))) {
455
+ console.log(`verifyInputBeef failed, inputBEEF failed to verify.\n${beef.toLogString()}\n`);
456
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('inputBEEF', 'valid Beef when factoring options.trustSelf');
457
+ }
458
+ const storageBeef = beef.clone();
459
+ const preloadedOutputsByOutpoint = await storage.findOutputsByOutpoints(userId, xinputs.map(i => ({ txid: i.outpoint.txid, vout: i.outpoint.vout })));
460
+ for (const input of xinputs) {
461
+ await resolveInputScript(storage, userId, vargs, input, beef, preloadedOutputsByOutpoint);
462
+ }
463
+ return { beef, storageBeef, xinputs };
464
+ }
465
+ /** Check all txidOnly entries in beef: require either trustSelf vouch or throw. */
466
+ async function validateBeefTxidOnlyEntries(beef, inputTxids, trustSelf, storage) {
478
467
  for (const btx of beef.txs) {
479
- if (btx.isTxidOnly) {
480
- if (!trustSelf)
481
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('inputBEEF', `valid and contain complete proof data for ${btx.txid}`);
482
- if (!inputTxids[btx.txid]) {
483
- // inputTxids are checked next
484
- const isKnown = await storage.verifyKnownValidTransaction(btx.txid);
485
- if (!isKnown)
486
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('inputBEEF', `valid and contain complete proof data for unknown ${btx.txid}`);
487
- }
468
+ if (!btx.isTxidOnly)
469
+ continue;
470
+ if (!trustSelf)
471
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('inputBEEF', `valid and contain complete proof data for ${btx.txid}`);
472
+ if (!inputTxids[btx.txid]) {
473
+ const isKnown = await storage.verifyKnownValidTransaction(btx.txid);
474
+ if (!isKnown)
475
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('inputBEEF', `valid and contain complete proof data for unknown ${btx.txid}`);
488
476
  }
489
477
  }
490
- // Make sure that there's an entry for all inputs txid values:
478
+ }
479
+ /** Ensure beef has an entry (or txidOnly) for every input txid. */
480
+ async function ensureBeefContainsAllInputTxids(beef, inputTxids, trustSelf, storage) {
491
481
  for (const txid of Object.keys(inputTxids)) {
492
482
  let btx = beef.findTxid(txid);
493
- if (!btx && trustSelf) {
483
+ if (btx == null && trustSelf) {
494
484
  if (await storage.verifyKnownValidTransaction(txid))
495
485
  btx = beef.mergeTxidOnly(txid);
496
486
  }
497
- if (!btx) {
487
+ if (btx == null) {
498
488
  throw new WERR_errors_1.WERR_INVALID_PARAMETER('inputBEEF', `valid and contain proof data for possibly known ${txid}, beef ${beef.toLogString()}`);
499
489
  }
500
490
  }
501
- if (!(await beef.verify(await storage.getServices().getChainTracker(), true))) {
502
- console.log(`verifyInputBeef failed, inputBEEF failed to verify.\n${beef.toLogString()}\n`);
503
- //console.log(`verifyInputBeef failed, inputBEEF failed to verify.\n${stampLogFormat(vargs.log)}\n${beef.toLogString()}\n`)
504
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('inputBEEF', 'valid Beef when factoring options.trustSelf');
505
- }
506
- // beef may now be trusted and has a BeefTx for every input txid.
507
- const storageBeef = beef.clone();
508
- const preloadedOutputsByOutpoint = await storage.findOutputsByOutpoints(userId, xinputs.map(i => ({ txid: i.outpoint.txid, vout: i.outpoint.vout })));
509
- for (const input of xinputs) {
510
- const { txid, vout } = input.outpoint;
511
- let output = preloadedOutputsByOutpoint[`${txid}.${vout}`];
512
- if (!output)
513
- output = (0, utilityHelpers_1.verifyOneOrNone)(await storage.findOutputs({ partial: { userId, txid, vout } }));
514
- if (output) {
515
- if (output.change) {
516
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(`inputs[${input.vin}]`, 'an unmanaged input. Change outputs are managed by your wallet.');
517
- }
518
- input.output = output;
519
- if (!Array.isArray(output.lockingScript) || !Number.isInteger(output.satoshis))
520
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(`${txid}.${vout}`, 'output with valid lockingScript and satoshis');
521
- if (!disableDoubleSpendCheckForTest && !output.spendable && !vargs.isNoSend)
522
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(`${txid}.${vout}`, 'spendable output unless noSend is true');
523
- // input is spending an existing user output which has an lockingScript
524
- input.satoshis = sdk_1.Validation.validateSatoshis(output.satoshis, 'output.satoshis');
525
- input.lockingScript = sdk_1.Script.fromBinary((0, utilityHelpers_noBuffer_1.asArray)(output.lockingScript));
526
- }
527
- else {
528
- let btx = beef.findTxid(txid);
529
- if (btx.isTxidOnly) {
530
- const { rawTx, proven } = await storage.getProvenOrRawTx(txid);
531
- //stampLog(vargs, `... storage verifyInputBeef getProvenOrRawTx ${txid} ${proven ? 'proven' : rawTx ? 'rawTx' : 'unknown'}`)
532
- if (!rawTx)
533
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('inputBEEF', `valid and contain proof data for ${txid}`);
534
- btx = beef.mergeRawTx((0, utilityHelpers_noBuffer_1.asArray)(rawTx));
535
- if (proven)
536
- beef.mergeBump(new EntityProvenTx_1.EntityProvenTx(proven).getMerklePath());
537
- }
538
- // btx is valid has parsed transaction data.
539
- if (vout >= btx.tx.outputs.length)
540
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(`${txid}.${vout}`, 'valid outpoint');
541
- const so = btx.tx.outputs[vout];
542
- input.satoshis = sdk_1.Validation.validateSatoshis(so.satoshis, 'so.satoshis');
543
- input.lockingScript = so.lockingScript;
544
- }
545
- }
546
- return { beef, storageBeef, xinputs };
547
491
  }
548
- async function verifyBeefFixOrhpans(beef, storage) {
549
- const r = beef.verifyValid();
550
- if (!r.valid) {
551
- // Beef is structurally invalid.
552
- return false;
492
+ /** Resolve satoshis and lockingScript for one xinput from either storage or the beef. */
493
+ async function resolveInputScript(storage, userId, vargs, input, beef, preloadedOutputsByOutpoint) {
494
+ const { txid, vout } = input.outpoint;
495
+ let output = preloadedOutputsByOutpoint[`${txid}.${vout}`];
496
+ output !== null && output !== void 0 ? output : (output = (0, utilityHelpers_1.verifyOneOrNone)(await storage.findOutputs({ partial: { userId, txid, vout } })));
497
+ if (output != null) {
498
+ if (output.change)
499
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER(`inputs[${input.vin}]`, 'an unmanaged input. Change outputs are managed by your wallet.');
500
+ input.output = output;
501
+ if (!Array.isArray(output.lockingScript) || !Number.isInteger(output.satoshis))
502
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER(`${txid}.${vout}`, 'output with valid lockingScript and satoshis');
503
+ if (!disableDoubleSpendCheckForTest && !output.spendable && !vargs.isNoSend)
504
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER(`${txid}.${vout}`, 'spendable output unless noSend is true');
505
+ input.satoshis = sdk_1.Validation.validateSatoshis(output.satoshis, 'output.satoshis');
506
+ input.lockingScript = sdk_1.Script.fromBinary((0, utilityHelpers_noBuffer_1.asArray)(output.lockingScript));
553
507
  }
554
- const heights = Object.keys(r.roots);
555
- const services = storage.getServices();
556
- const chainTracker = await services.getChainTracker();
557
- let rootsAreValid = true;
558
- for (const height of heights) {
559
- const isValid = await chainTracker.isValidRootForHeight(r.roots[height], Number(height));
560
- if (isValid)
561
- continue;
562
- // The original block may have been orphaned, check for a new proof.
563
- const mp = beef.bumps.find(b => b.blockHeight === Number(height));
564
- //const p = await services.getMerklePath()
508
+ else {
509
+ let btx = beef.findTxid(txid);
510
+ if (btx.isTxidOnly) {
511
+ const { rawTx, proven } = await storage.getProvenOrRawTx(txid);
512
+ if (rawTx == null)
513
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('inputBEEF', `valid and contain proof data for ${txid}`);
514
+ btx = beef.mergeRawTx((0, utilityHelpers_noBuffer_1.asArray)(rawTx));
515
+ if (proven != null)
516
+ beef.mergeBump(new EntityProvenTx_1.EntityProvenTx(proven).getMerklePath());
517
+ }
518
+ if (vout >= btx.tx.outputs.length)
519
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER(`${txid}.${vout}`, 'valid outpoint');
520
+ const so = btx.tx.outputs[vout];
521
+ input.satoshis = sdk_1.Validation.validateSatoshis(so.satoshis, 'so.satoshis');
522
+ input.lockingScript = so.lockingScript;
565
523
  }
566
- return false;
567
524
  }
568
525
  async function validateNoSendChange(storage, userId, vargs, changeBasket) {
569
526
  const r = [];
@@ -576,17 +533,19 @@ async function validateNoSendChange(storage, userId, vargs, changeBasket) {
576
533
  partial: { userId, txid: op.txid, vout: op.vout }
577
534
  }));
578
535
  // noSendChange is not marked spendable until sent, may not already be spent, and must have a valid greater than zero satoshis
579
- if (!output ||
580
- output.providedBy !== 'storage' ||
536
+ if ((output === null || output === void 0 ? void 0 : output.providedBy) !== 'storage' ||
581
537
  output.purpose !== 'change' ||
582
- output.spendable === false ||
538
+ !output.spendable ||
583
539
  Number.isInteger(output.spentBy) ||
584
540
  !(0, utilityHelpers_1.verifyNumber)(output.satoshis) ||
585
- output.basketId !== changeBasket.basketId)
541
+ output.basketId !== changeBasket.basketId) {
586
542
  throw new WERR_errors_1.WERR_INVALID_PARAMETER('noSendChange outpoint', 'valid');
587
- if (-1 < r.findIndex(o => o.outputId === output.outputId))
588
- // noSendChange duplicate OutPoints are not allowed.
543
+ }
544
+ if (r.some(o => o.outputId === output.outputId))
545
+ // noSendChange duplicate OutPoints are not allowed.
546
+ {
589
547
  throw new WERR_errors_1.WERR_INVALID_PARAMETER('noSendChange outpoint', 'unique. Duplicates are not allowed.');
548
+ }
590
549
  r.push(output);
591
550
  }
592
551
  }
@@ -652,7 +611,7 @@ async function fundNewTransactionSdk(storage, userId, vargs, ctx) {
652
611
  }
653
612
  const basketId = ctx.changeBasket.basketId;
654
613
  const o = await storage.allocateChangeInput(userId, basketId, targetSatoshis, exactSatoshis, !vargs.isDelayed, ctx.transactionId);
655
- if (!o)
614
+ if (o == null)
656
615
  return undefined;
657
616
  outputs[o.outputId] = o;
658
617
  const r = {
@@ -663,7 +622,7 @@ async function fundNewTransactionSdk(storage, userId, vargs, ctx) {
663
622
  };
664
623
  const releaseChangeInput = async (outputId) => {
665
624
  const nsco = ctx.noSendChangeIn.find(o => o.outputId === outputId);
666
- if (nsco) {
625
+ if (nsco != null) {
667
626
  noSendChange.push(nsco);
668
627
  return;
669
628
  }
@@ -675,7 +634,7 @@ async function fundNewTransactionSdk(storage, userId, vargs, ctx) {
675
634
  const gcr = await (0, generateChange_1.generateChangeSdk)(params, allocateChangeInput, releaseChangeInput, vargs.logger);
676
635
  const nextRandomVal = () => {
677
636
  let val = 0;
678
- if (!vargs.randomVals || vargs.randomVals.length === 0) {
637
+ if ((vargs.randomVals == null) || vargs.randomVals.length === 0) {
679
638
  const bytes = (0, sdk_1.Random)(4);
680
639
  val = (((bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3]) >>> 0) / 0x100000000;
681
640
  }
@@ -695,7 +654,7 @@ async function fundNewTransactionSdk(storage, userId, vargs, ctx) {
695
654
  };
696
655
  const randomDerivation = (count) => {
697
656
  let val = [];
698
- if (!vargs.randomVals || vargs.randomVals.length === 0) {
657
+ if ((vargs.randomVals == null) || vargs.randomVals.length === 0) {
699
658
  val = (0, sdk_1.Random)(count);
700
659
  }
701
660
  else {
@@ -757,6 +716,7 @@ function trimInputBeef(beef, vargs) {
757
716
  return beef.toBinary();
758
717
  }
759
718
  async function mergeAllocatedChangeBeefs(storage, userId, vargs, allocatedChange, beef) {
719
+ var _a;
760
720
  const options = {
761
721
  trustSelf: undefined,
762
722
  knownTxids: vargs.options.knownTxids,
@@ -769,7 +729,7 @@ async function mergeAllocatedChangeBeefs(storage, userId, vargs, allocatedChange
769
729
  if (vargs.options.returnTXIDOnly)
770
730
  return undefined;
771
731
  for (const o of allocatedChange) {
772
- if (!beef.findTxid(o.txid) && !(vargs.options.knownTxids || []).find(txid => txid === o.txid)) {
732
+ if ((beef.findTxid(o.txid) == null) && !((_a = vargs.options.knownTxids) !== null && _a !== void 0 ? _a : []).some(txid => txid === o.txid)) {
773
733
  await storage.getBeefForTransaction(o.txid, options);
774
734
  }
775
735
  }