@bopen-io/wallet-toolbox 1.7.18

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 (390) hide show
  1. package/.claude/settings.local.json +10 -0
  2. package/.env.template +22 -0
  3. package/.github/ISSUE_TEMPLATE/bug_report.md +40 -0
  4. package/.github/ISSUE_TEMPLATE/discussion.md +24 -0
  5. package/.github/pull_request_template.md +22 -0
  6. package/.github/workflows/push.yaml +145 -0
  7. package/.prettierrc +10 -0
  8. package/CHANGELOG.md +280 -0
  9. package/CONTRIBUTING.md +89 -0
  10. package/README.md +43 -0
  11. package/docs/README.md +85 -0
  12. package/docs/client.md +19627 -0
  13. package/docs/monitor.md +953 -0
  14. package/docs/open-rpc/index.html +46 -0
  15. package/docs/services.md +6377 -0
  16. package/docs/setup.md +1268 -0
  17. package/docs/storage.md +5367 -0
  18. package/docs/wallet.md +19626 -0
  19. package/jest.config.ts +25 -0
  20. package/license.md +28 -0
  21. package/out/tsconfig.all.tsbuildinfo +1 -0
  22. package/package.json +63 -0
  23. package/src/CWIStyleWalletManager.ts +1999 -0
  24. package/src/Setup.ts +579 -0
  25. package/src/SetupClient.ts +322 -0
  26. package/src/SetupWallet.ts +108 -0
  27. package/src/SimpleWalletManager.ts +526 -0
  28. package/src/Wallet.ts +1169 -0
  29. package/src/WalletAuthenticationManager.ts +153 -0
  30. package/src/WalletLogger.ts +213 -0
  31. package/src/WalletPermissionsManager.ts +3660 -0
  32. package/src/WalletSettingsManager.ts +114 -0
  33. package/src/__tests/CWIStyleWalletManager.test.d.ts.map +1 -0
  34. package/src/__tests/CWIStyleWalletManager.test.js.map +1 -0
  35. package/src/__tests/CWIStyleWalletManager.test.ts +675 -0
  36. package/src/__tests/WalletPermissionsManager.callbacks.test.ts +323 -0
  37. package/src/__tests/WalletPermissionsManager.checks.test.ts +844 -0
  38. package/src/__tests/WalletPermissionsManager.encryption.test.ts +412 -0
  39. package/src/__tests/WalletPermissionsManager.fixtures.ts +307 -0
  40. package/src/__tests/WalletPermissionsManager.flows.test.ts +462 -0
  41. package/src/__tests/WalletPermissionsManager.initialization.test.ts +300 -0
  42. package/src/__tests/WalletPermissionsManager.pmodules.test.ts +798 -0
  43. package/src/__tests/WalletPermissionsManager.proxying.test.ts +724 -0
  44. package/src/__tests/WalletPermissionsManager.tokens.test.ts +503 -0
  45. package/src/index.all.ts +27 -0
  46. package/src/index.client.ts +25 -0
  47. package/src/index.mobile.ts +21 -0
  48. package/src/index.ts +1 -0
  49. package/src/monitor/Monitor.ts +412 -0
  50. package/src/monitor/MonitorDaemon.ts +188 -0
  51. package/src/monitor/README.md +3 -0
  52. package/src/monitor/__test/MonitorDaemon.man.test.ts +45 -0
  53. package/src/monitor/tasks/TaskCheckForProofs.ts +243 -0
  54. package/src/monitor/tasks/TaskCheckNoSends.ts +73 -0
  55. package/src/monitor/tasks/TaskClock.ts +33 -0
  56. package/src/monitor/tasks/TaskFailAbandoned.ts +54 -0
  57. package/src/monitor/tasks/TaskMonitorCallHistory.ts +26 -0
  58. package/src/monitor/tasks/TaskNewHeader.ts +93 -0
  59. package/src/monitor/tasks/TaskPurge.ts +68 -0
  60. package/src/monitor/tasks/TaskReorg.ts +89 -0
  61. package/src/monitor/tasks/TaskReviewStatus.ts +48 -0
  62. package/src/monitor/tasks/TaskSendWaiting.ts +122 -0
  63. package/src/monitor/tasks/TaskSyncWhenIdle.ts +26 -0
  64. package/src/monitor/tasks/TaskUnFail.ts +151 -0
  65. package/src/monitor/tasks/WalletMonitorTask.ts +47 -0
  66. package/src/sdk/CertOpsWallet.ts +18 -0
  67. package/src/sdk/PrivilegedKeyManager.ts +372 -0
  68. package/src/sdk/README.md +13 -0
  69. package/src/sdk/WERR_errors.ts +234 -0
  70. package/src/sdk/WalletError.ts +170 -0
  71. package/src/sdk/WalletErrorFromJson.ts +80 -0
  72. package/src/sdk/WalletServices.interfaces.ts +700 -0
  73. package/src/sdk/WalletSigner.interfaces.ts +11 -0
  74. package/src/sdk/WalletStorage.interfaces.ts +606 -0
  75. package/src/sdk/__test/CertificateLifeCycle.test.ts +131 -0
  76. package/src/sdk/__test/PrivilegedKeyManager.test.ts +738 -0
  77. package/src/sdk/__test/WalletError.test.ts +318 -0
  78. package/src/sdk/__test/validationHelpers.test.ts +21 -0
  79. package/src/sdk/index.ts +10 -0
  80. package/src/sdk/types.ts +226 -0
  81. package/src/services/README.md +11 -0
  82. package/src/services/ServiceCollection.ts +248 -0
  83. package/src/services/Services.ts +603 -0
  84. package/src/services/__tests/ARC.man.test.ts +123 -0
  85. package/src/services/__tests/ARC.timeout.man.test.ts +79 -0
  86. package/src/services/__tests/ArcGorillaPool.man.test.ts +108 -0
  87. package/src/services/__tests/arcServices.test.ts +8 -0
  88. package/src/services/__tests/bitrails.test.ts +56 -0
  89. package/src/services/__tests/getMerklePath.test.ts +15 -0
  90. package/src/services/__tests/getRawTx.test.ts +13 -0
  91. package/src/services/__tests/postBeef.test.ts +104 -0
  92. package/src/services/__tests/verifyBeef.test.ts +50 -0
  93. package/src/services/chaintracker/BHServiceClient.ts +212 -0
  94. package/src/services/chaintracker/ChaintracksChainTracker.ts +71 -0
  95. package/src/services/chaintracker/__tests/ChaintracksChainTracker.test.ts +33 -0
  96. package/src/services/chaintracker/__tests/ChaintracksServiceClient.test.ts +29 -0
  97. package/src/services/chaintracker/chaintracks/Api/BlockHeaderApi.ts +72 -0
  98. package/src/services/chaintracker/chaintracks/Api/BulkIngestorApi.ts +83 -0
  99. package/src/services/chaintracker/chaintracks/Api/BulkStorageApi.ts +92 -0
  100. package/src/services/chaintracker/chaintracks/Api/ChaintracksApi.ts +64 -0
  101. package/src/services/chaintracker/chaintracks/Api/ChaintracksClientApi.ts +189 -0
  102. package/src/services/chaintracker/chaintracks/Api/ChaintracksFetchApi.ts +18 -0
  103. package/src/services/chaintracker/chaintracks/Api/ChaintracksFsApi.ts +58 -0
  104. package/src/services/chaintracker/chaintracks/Api/ChaintracksStorageApi.ts +386 -0
  105. package/src/services/chaintracker/chaintracks/Api/LiveIngestorApi.ts +25 -0
  106. package/src/services/chaintracker/chaintracks/Chaintracks.ts +609 -0
  107. package/src/services/chaintracker/chaintracks/ChaintracksService.ts +199 -0
  108. package/src/services/chaintracker/chaintracks/ChaintracksServiceClient.ts +154 -0
  109. package/src/services/chaintracker/chaintracks/Ingest/BulkIngestorBase.ts +176 -0
  110. package/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.ts +174 -0
  111. package/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDNBabbage.ts +18 -0
  112. package/src/services/chaintracker/chaintracks/Ingest/BulkIngestorWhatsOnChainCdn.ts +113 -0
  113. package/src/services/chaintracker/chaintracks/Ingest/BulkIngestorWhatsOnChainWs.ts +81 -0
  114. package/src/services/chaintracker/chaintracks/Ingest/LiveIngestorBase.ts +86 -0
  115. package/src/services/chaintracker/chaintracks/Ingest/LiveIngestorTeranodeP2P.ts +59 -0
  116. package/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.ts +104 -0
  117. package/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainWs.ts +66 -0
  118. package/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainIngestorWs.ts +566 -0
  119. package/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.ts +219 -0
  120. package/src/services/chaintracker/chaintracks/Ingest/__tests/BulkIngestorCDNBabbage.test.ts +54 -0
  121. package/src/services/chaintracker/chaintracks/Ingest/__tests/LiveIngestorWhatsOnChainPoll.test.ts +33 -0
  122. package/src/services/chaintracker/chaintracks/Ingest/__tests/WhatsOnChainServices.test.ts +124 -0
  123. package/src/services/chaintracker/chaintracks/Storage/BulkStorageBase.ts +92 -0
  124. package/src/services/chaintracker/chaintracks/Storage/ChaintracksKnexMigrations.ts +104 -0
  125. package/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageBase.ts +382 -0
  126. package/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageIdb.ts +574 -0
  127. package/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageKnex.ts +438 -0
  128. package/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageMemory.ts +29 -0
  129. package/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageNoDb.ts +304 -0
  130. package/src/services/chaintracker/chaintracks/Storage/__tests/ChaintracksStorageIdb.test.ts +102 -0
  131. package/src/services/chaintracker/chaintracks/Storage/__tests/ChaintracksStorageKnex.test.ts +45 -0
  132. package/src/services/chaintracker/chaintracks/__tests/Chaintracks.test.ts +77 -0
  133. package/src/services/chaintracker/chaintracks/__tests/ChaintracksClientApi.test.ts +192 -0
  134. package/src/services/chaintracker/chaintracks/__tests/LocalCdnServer.ts +75 -0
  135. package/src/services/chaintracker/chaintracks/__tests/createIdbChaintracks.test.ts +62 -0
  136. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest349/mainNetBlockHeaders.json +1 -0
  137. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest349/mainNet_0.headers +0 -0
  138. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest349/mainNet_1.headers +0 -0
  139. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest349/mainNet_2.headers +0 -0
  140. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest349/mainNet_3.headers +0 -0
  141. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest379/mainNetBlockHeaders.json +1 -0
  142. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest379/mainNet_0.headers +0 -0
  143. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest379/mainNet_1.headers +0 -0
  144. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest379/mainNet_2.headers +0 -0
  145. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest379/mainNet_3.headers +0 -0
  146. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest399/mainNetBlockHeaders.json +1 -0
  147. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest399/mainNet_0.headers +0 -0
  148. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest399/mainNet_1.headers +0 -0
  149. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest399/mainNet_2.headers +0 -0
  150. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest399/mainNet_3.headers +0 -0
  151. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNetBlockHeaders.json +1 -0
  152. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNet_0.headers +0 -0
  153. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNet_1.headers +0 -0
  154. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNet_2.headers +0 -0
  155. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNet_3.headers +0 -0
  156. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNet_4.headers +0 -0
  157. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNetBlockHeaders.json +1 -0
  158. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNet_0.headers +0 -0
  159. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNet_1.headers +0 -0
  160. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNet_2.headers +0 -0
  161. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNet_3.headers +0 -0
  162. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNet_4.headers +0 -0
  163. package/src/services/chaintracker/chaintracks/createDefaultIdbChaintracksOptions.ts +92 -0
  164. package/src/services/chaintracker/chaintracks/createDefaultKnexChaintracksOptions.ts +111 -0
  165. package/src/services/chaintracker/chaintracks/createDefaultNoDbChaintracksOptions.ts +91 -0
  166. package/src/services/chaintracker/chaintracks/createIdbChaintracks.ts +60 -0
  167. package/src/services/chaintracker/chaintracks/createKnexChaintracks.ts +65 -0
  168. package/src/services/chaintracker/chaintracks/createNoDbChaintracks.ts +60 -0
  169. package/src/services/chaintracker/chaintracks/index.all.ts +12 -0
  170. package/src/services/chaintracker/chaintracks/index.client.ts +4 -0
  171. package/src/services/chaintracker/chaintracks/index.mobile.ts +37 -0
  172. package/src/services/chaintracker/chaintracks/util/BulkFileDataManager.ts +975 -0
  173. package/src/services/chaintracker/chaintracks/util/BulkFileDataReader.ts +60 -0
  174. package/src/services/chaintracker/chaintracks/util/BulkFilesReader.ts +336 -0
  175. package/src/services/chaintracker/chaintracks/util/BulkHeaderFile.ts +247 -0
  176. package/src/services/chaintracker/chaintracks/util/ChaintracksFetch.ts +69 -0
  177. package/src/services/chaintracker/chaintracks/util/ChaintracksFs.ts +141 -0
  178. package/src/services/chaintracker/chaintracks/util/HeightRange.ts +153 -0
  179. package/src/services/chaintracker/chaintracks/util/SingleWriterMultiReaderLock.ts +76 -0
  180. package/src/services/chaintracker/chaintracks/util/__tests/BulkFileDataManager.test.ts +304 -0
  181. package/src/services/chaintracker/chaintracks/util/__tests/ChaintracksFetch.test.ts +60 -0
  182. package/src/services/chaintracker/chaintracks/util/__tests/HeightRange.test.ts +67 -0
  183. package/src/services/chaintracker/chaintracks/util/__tests/SingleWriterMultiReaderLock.test.ts +49 -0
  184. package/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.ts +573 -0
  185. package/src/services/chaintracker/chaintracks/util/dirtyHashes.ts +29 -0
  186. package/src/services/chaintracker/chaintracks/util/validBulkHeaderFilesByFileHash.ts +432 -0
  187. package/src/services/chaintracker/index.all.ts +4 -0
  188. package/src/services/chaintracker/index.client.ts +4 -0
  189. package/src/services/chaintracker/index.mobile.ts +4 -0
  190. package/src/services/createDefaultWalletServicesOptions.ts +77 -0
  191. package/src/services/index.ts +1 -0
  192. package/src/services/processingErrors/arcSuccessError.json +76 -0
  193. package/src/services/providers/ARC.ts +350 -0
  194. package/src/services/providers/Bitails.ts +256 -0
  195. package/src/services/providers/SdkWhatsOnChain.ts +83 -0
  196. package/src/services/providers/WhatsOnChain.ts +883 -0
  197. package/src/services/providers/__tests/WhatsOnChain.test.ts +242 -0
  198. package/src/services/providers/__tests/exchangeRates.test.ts +18 -0
  199. package/src/services/providers/exchangeRates.ts +265 -0
  200. package/src/services/providers/getBeefForTxid.ts +369 -0
  201. package/src/signer/README.md +5 -0
  202. package/src/signer/WalletSigner.ts +17 -0
  203. package/src/signer/methods/acquireDirectCertificate.ts +52 -0
  204. package/src/signer/methods/buildSignableTransaction.ts +183 -0
  205. package/src/signer/methods/completeSignedTransaction.ts +117 -0
  206. package/src/signer/methods/createAction.ts +172 -0
  207. package/src/signer/methods/internalizeAction.ts +106 -0
  208. package/src/signer/methods/proveCertificate.ts +43 -0
  209. package/src/signer/methods/signAction.ts +54 -0
  210. package/src/storage/README.md +14 -0
  211. package/src/storage/StorageIdb.ts +2304 -0
  212. package/src/storage/StorageKnex.ts +1425 -0
  213. package/src/storage/StorageProvider.ts +810 -0
  214. package/src/storage/StorageReader.ts +194 -0
  215. package/src/storage/StorageReaderWriter.ts +432 -0
  216. package/src/storage/StorageSyncReader.ts +34 -0
  217. package/src/storage/WalletStorageManager.ts +943 -0
  218. package/src/storage/__test/StorageIdb.test.ts +43 -0
  219. package/src/storage/__test/WalletStorageManager.test.ts +275 -0
  220. package/src/storage/__test/adminStats.man.test.ts +89 -0
  221. package/src/storage/__test/getBeefForTransaction.test.ts +385 -0
  222. package/src/storage/index.all.ts +11 -0
  223. package/src/storage/index.client.ts +7 -0
  224. package/src/storage/index.mobile.ts +6 -0
  225. package/src/storage/methods/ListActionsSpecOp.ts +70 -0
  226. package/src/storage/methods/ListOutputsSpecOp.ts +129 -0
  227. package/src/storage/methods/__test/GenerateChange/generateChangeSdk.test.ts +1057 -0
  228. package/src/storage/methods/__test/GenerateChange/randomValsUsed1.ts +20 -0
  229. package/src/storage/methods/__test/offsetKey.test.ts +274 -0
  230. package/src/storage/methods/attemptToPostReqsToNetwork.ts +389 -0
  231. package/src/storage/methods/createAction.ts +947 -0
  232. package/src/storage/methods/generateChange.ts +556 -0
  233. package/src/storage/methods/getBeefForTransaction.ts +139 -0
  234. package/src/storage/methods/getSyncChunk.ts +293 -0
  235. package/src/storage/methods/internalizeAction.ts +562 -0
  236. package/src/storage/methods/listActionsIdb.ts +183 -0
  237. package/src/storage/methods/listActionsKnex.ts +226 -0
  238. package/src/storage/methods/listCertificates.ts +73 -0
  239. package/src/storage/methods/listOutputsIdb.ts +203 -0
  240. package/src/storage/methods/listOutputsKnex.ts +263 -0
  241. package/src/storage/methods/offsetKey.ts +89 -0
  242. package/src/storage/methods/processAction.ts +420 -0
  243. package/src/storage/methods/purgeData.ts +251 -0
  244. package/src/storage/methods/purgeDataIdb.ts +10 -0
  245. package/src/storage/methods/reviewStatus.ts +101 -0
  246. package/src/storage/methods/reviewStatusIdb.ts +43 -0
  247. package/src/storage/methods/utils.Buffer.ts +33 -0
  248. package/src/storage/methods/utils.ts +56 -0
  249. package/src/storage/remoting/StorageClient.ts +567 -0
  250. package/src/storage/remoting/StorageMobile.ts +544 -0
  251. package/src/storage/remoting/StorageServer.ts +291 -0
  252. package/src/storage/remoting/__test/StorageClient.test.ts +113 -0
  253. package/src/storage/schema/KnexMigrations.ts +489 -0
  254. package/src/storage/schema/StorageIdbSchema.ts +150 -0
  255. package/src/storage/schema/entities/EntityBase.ts +210 -0
  256. package/src/storage/schema/entities/EntityCertificate.ts +188 -0
  257. package/src/storage/schema/entities/EntityCertificateField.ts +136 -0
  258. package/src/storage/schema/entities/EntityCommission.ts +148 -0
  259. package/src/storage/schema/entities/EntityOutput.ts +290 -0
  260. package/src/storage/schema/entities/EntityOutputBasket.ts +153 -0
  261. package/src/storage/schema/entities/EntityOutputTag.ts +121 -0
  262. package/src/storage/schema/entities/EntityOutputTagMap.ts +123 -0
  263. package/src/storage/schema/entities/EntityProvenTx.ts +319 -0
  264. package/src/storage/schema/entities/EntityProvenTxReq.ts +580 -0
  265. package/src/storage/schema/entities/EntitySyncState.ts +389 -0
  266. package/src/storage/schema/entities/EntityTransaction.ts +306 -0
  267. package/src/storage/schema/entities/EntityTxLabel.ts +121 -0
  268. package/src/storage/schema/entities/EntityTxLabelMap.ts +123 -0
  269. package/src/storage/schema/entities/EntityUser.ts +112 -0
  270. package/src/storage/schema/entities/MergeEntity.ts +73 -0
  271. package/src/storage/schema/entities/__tests/CertificateFieldTests.test.ts +353 -0
  272. package/src/storage/schema/entities/__tests/CertificateTests.test.ts +354 -0
  273. package/src/storage/schema/entities/__tests/CommissionTests.test.ts +371 -0
  274. package/src/storage/schema/entities/__tests/OutputBasketTests.test.ts +278 -0
  275. package/src/storage/schema/entities/__tests/OutputTagMapTests.test.ts +242 -0
  276. package/src/storage/schema/entities/__tests/OutputTagTests.test.ts +288 -0
  277. package/src/storage/schema/entities/__tests/OutputTests.test.ts +464 -0
  278. package/src/storage/schema/entities/__tests/ProvenTxReqTests.test.ts +340 -0
  279. package/src/storage/schema/entities/__tests/ProvenTxTests.test.ts +504 -0
  280. package/src/storage/schema/entities/__tests/SyncStateTests.test.ts +288 -0
  281. package/src/storage/schema/entities/__tests/TransactionTests.test.ts +604 -0
  282. package/src/storage/schema/entities/__tests/TxLabelMapTests.test.ts +361 -0
  283. package/src/storage/schema/entities/__tests/TxLabelTests.test.ts +198 -0
  284. package/src/storage/schema/entities/__tests/stampLogTests.test.ts +90 -0
  285. package/src/storage/schema/entities/__tests/usersTests.test.ts +340 -0
  286. package/src/storage/schema/entities/index.ts +16 -0
  287. package/src/storage/schema/tables/TableCertificate.ts +21 -0
  288. package/src/storage/schema/tables/TableCertificateField.ts +12 -0
  289. package/src/storage/schema/tables/TableCommission.ts +13 -0
  290. package/src/storage/schema/tables/TableMonitorEvent.ts +9 -0
  291. package/src/storage/schema/tables/TableOutput.ts +64 -0
  292. package/src/storage/schema/tables/TableOutputBasket.ts +12 -0
  293. package/src/storage/schema/tables/TableOutputTag.ts +10 -0
  294. package/src/storage/schema/tables/TableOutputTagMap.ts +9 -0
  295. package/src/storage/schema/tables/TableProvenTx.ts +14 -0
  296. package/src/storage/schema/tables/TableProvenTxReq.ts +65 -0
  297. package/src/storage/schema/tables/TableSettings.ts +17 -0
  298. package/src/storage/schema/tables/TableSyncState.ts +18 -0
  299. package/src/storage/schema/tables/TableTransaction.ts +54 -0
  300. package/src/storage/schema/tables/TableTxLabel.ts +10 -0
  301. package/src/storage/schema/tables/TableTxLabelMap.ts +9 -0
  302. package/src/storage/schema/tables/TableUser.ts +16 -0
  303. package/src/storage/schema/tables/index.ts +16 -0
  304. package/src/storage/sync/StorageMySQLDojoReader.ts +696 -0
  305. package/src/storage/sync/index.ts +1 -0
  306. package/src/utility/Format.ts +133 -0
  307. package/src/utility/README.md +3 -0
  308. package/src/utility/ReaderUint8Array.ts +187 -0
  309. package/src/utility/ScriptTemplateBRC29.ts +73 -0
  310. package/src/utility/__tests/utilityHelpers.noBuffer.test.ts +109 -0
  311. package/src/utility/aggregateResults.ts +68 -0
  312. package/src/utility/identityUtils.ts +159 -0
  313. package/src/utility/index.all.ts +7 -0
  314. package/src/utility/index.client.ts +7 -0
  315. package/src/utility/parseTxScriptOffsets.ts +29 -0
  316. package/src/utility/stampLog.ts +69 -0
  317. package/src/utility/tscProofToMerklePath.ts +48 -0
  318. package/src/utility/utilityHelpers.buffer.ts +34 -0
  319. package/src/utility/utilityHelpers.noBuffer.ts +60 -0
  320. package/src/utility/utilityHelpers.ts +275 -0
  321. package/src/wab-client/WABClient.ts +94 -0
  322. package/src/wab-client/__tests/WABClient.man.test.ts +59 -0
  323. package/src/wab-client/auth-method-interactors/AuthMethodInteractor.ts +47 -0
  324. package/src/wab-client/auth-method-interactors/DevConsoleInteractor.ts +73 -0
  325. package/src/wab-client/auth-method-interactors/PersonaIDInteractor.ts +35 -0
  326. package/src/wab-client/auth-method-interactors/TwilioPhoneInteractor.ts +72 -0
  327. package/syncVersions.js +71 -0
  328. package/test/Wallet/StorageClient/storageClient.man.test.ts +75 -0
  329. package/test/Wallet/action/abortAction.test.ts +47 -0
  330. package/test/Wallet/action/createAction.test.ts +299 -0
  331. package/test/Wallet/action/createAction2.test.ts +1273 -0
  332. package/test/Wallet/action/createActionToGenerateBeefs.man.test.ts +293 -0
  333. package/test/Wallet/action/internalizeAction.a.test.ts +286 -0
  334. package/test/Wallet/action/internalizeAction.test.ts +682 -0
  335. package/test/Wallet/action/relinquishOutput.test.ts +37 -0
  336. package/test/Wallet/certificate/acquireCertificate.test.ts +298 -0
  337. package/test/Wallet/certificate/listCertificates.test.ts +346 -0
  338. package/test/Wallet/construct/Wallet.constructor.test.ts +57 -0
  339. package/test/Wallet/get/getHeaderForHeight.test.ts +82 -0
  340. package/test/Wallet/get/getHeight.test.ts +52 -0
  341. package/test/Wallet/get/getKnownTxids.test.ts +86 -0
  342. package/test/Wallet/get/getNetwork.test.ts +27 -0
  343. package/test/Wallet/get/getVersion.test.ts +27 -0
  344. package/test/Wallet/list/listActions.test.ts +279 -0
  345. package/test/Wallet/list/listActions2.test.ts +1381 -0
  346. package/test/Wallet/list/listCertificates.test.ts +118 -0
  347. package/test/Wallet/list/listOutputs.test.ts +447 -0
  348. package/test/Wallet/live/walletLive.man.test.ts +521 -0
  349. package/test/Wallet/local/localWallet.man.test.ts +93 -0
  350. package/test/Wallet/local/localWallet2.man.test.ts +277 -0
  351. package/test/Wallet/signAction/mountaintop.man.test.ts +130 -0
  352. package/test/Wallet/specOps/specOps.man.test.ts +220 -0
  353. package/test/Wallet/support/janitor.man.test.ts +40 -0
  354. package/test/Wallet/support/operations.man.test.ts +407 -0
  355. package/test/Wallet/support/reqErrorReview.2025.05.06.man.test.ts +347 -0
  356. package/test/Wallet/sync/Wallet.sync.test.ts +215 -0
  357. package/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.ts +203 -0
  358. package/test/Wallet/sync/setActive.test.ts +170 -0
  359. package/test/WalletClient/LocalKVStore.man.test.ts +114 -0
  360. package/test/WalletClient/WERR.man.test.ts +35 -0
  361. package/test/bsv-ts-sdk/LocalKVStore.test.ts +102 -0
  362. package/test/checkDB.ts +57 -0
  363. package/test/checkdb +0 -0
  364. package/test/examples/backup.man.test.ts +59 -0
  365. package/test/examples/pushdrop.test.ts +282 -0
  366. package/test/monitor/Monitor.test.ts +620 -0
  367. package/test/services/Services.test.ts +263 -0
  368. package/test/storage/KnexMigrations.test.ts +86 -0
  369. package/test/storage/StorageMySQLDojoReader.man.test.ts +60 -0
  370. package/test/storage/count.test.ts +177 -0
  371. package/test/storage/find.test.ts +195 -0
  372. package/test/storage/findLegacy.test.ts +67 -0
  373. package/test/storage/idb/allocateChange.test.ts +251 -0
  374. package/test/storage/idb/count.test.ts +158 -0
  375. package/test/storage/idb/find.test.ts +177 -0
  376. package/test/storage/idb/idbSpeed.test.ts +36 -0
  377. package/test/storage/idb/insert.test.ts +268 -0
  378. package/test/storage/idb/transactionAbort.test.ts +108 -0
  379. package/test/storage/idb/update.test.ts +999 -0
  380. package/test/storage/insert.test.ts +278 -0
  381. package/test/storage/update.test.ts +1021 -0
  382. package/test/storage/update2.test.ts +897 -0
  383. package/test/utils/TestUtilsWalletStorage.ts +2526 -0
  384. package/test/utils/localWalletMethods.ts +363 -0
  385. package/test/utils/removeFailedFromDatabase.sql +17 -0
  386. package/ts2md.json +44 -0
  387. package/tsconfig.all.json +31 -0
  388. package/tsconfig.client.json +29 -0
  389. package/tsconfig.json +17 -0
  390. package/tsconfig.mobile.json +28 -0
@@ -0,0 +1,700 @@
1
+ import {
2
+ ArcConfig,
3
+ Beef,
4
+ Transaction as BsvTransaction,
5
+ ChainTracker,
6
+ MerklePath,
7
+ WalletLoggerInterface
8
+ } from '@bsv/sdk'
9
+ import { Chain, ReqHistoryNote } from './types'
10
+ import { WalletError } from './WalletError'
11
+ import { TableOutput } from '../storage/schema/tables/TableOutput'
12
+ import { ChaintracksServiceClient } from '../services/chaintracker/chaintracks/ChaintracksServiceClient'
13
+ import { ChaintracksClientApi } from '../services/chaintracker/chaintracks/Api/ChaintracksClientApi'
14
+ /**
15
+ * Defines standard interfaces to access functionality implemented by external transaction processing services.
16
+ */
17
+ export interface WalletServices {
18
+ /**
19
+ * The chain being serviced.
20
+ */
21
+ chain: Chain
22
+
23
+ /**
24
+ * @returns standard `ChainTracker` service which requires `options.chaintracks` be valid.
25
+ */
26
+ getChainTracker(): Promise<ChainTracker>
27
+
28
+ /**
29
+ * @returns serialized block header for height on active chain
30
+ * @param height
31
+ */
32
+ getHeaderForHeight(height: number): Promise<number[]>
33
+
34
+ /**
35
+ * @returns the height of the active chain
36
+ */
37
+ getHeight(): Promise<number>
38
+
39
+ /**
40
+ * Approximate exchange rate US Dollar / BSV, USD / BSV
41
+ *
42
+ * This is the US Dollar price of one BSV
43
+ */
44
+ getBsvExchangeRate(): Promise<number>
45
+
46
+ /**
47
+ * Approximate exchange rate currency per base.
48
+ */
49
+ getFiatExchangeRate(currency: 'USD' | 'GBP' | 'EUR', base?: 'USD' | 'GBP' | 'EUR'): Promise<number>
50
+
51
+ /**
52
+ * Attempts to obtain the raw transaction bytes associated with a 32 byte transaction hash (txid).
53
+ *
54
+ * Cycles through configured transaction processing services attempting to get a valid response.
55
+ *
56
+ * On success:
57
+ * Result txid is the requested transaction hash
58
+ * Result rawTx will be an array containing raw transaction bytes.
59
+ * Result name will be the responding service's identifying name.
60
+ * Returns result without incrementing active service.
61
+ *
62
+ * On failure:
63
+ * Result txid is the requested transaction hash
64
+ * Result mapi will be the first mapi response obtained (service name and response), or null
65
+ * Result error will be the first error thrown (service name and CwiError), or null
66
+ * Increments to next configured service and tries again until all services have been tried.
67
+ *
68
+ * @param txid transaction hash for which raw transaction bytes are requested
69
+ * @param useNext optional, forces skip to next service before starting service requests cycle.
70
+ */
71
+ getRawTx(txid: string, useNext?: boolean): Promise<GetRawTxResult>
72
+
73
+ /**
74
+ * Attempts to obtain the merkle proof associated with a 32 byte transaction hash (txid).
75
+ *
76
+ * Cycles through configured transaction processing services attempting to get a valid response.
77
+ *
78
+ * On success:
79
+ * Result txid is the requested transaction hash
80
+ * Result proof will be the merkle proof.
81
+ * Result name will be the responding service's identifying name.
82
+ * Returns result without incrementing active service.
83
+ *
84
+ * On failure:
85
+ * Result txid is the requested transaction hash
86
+ * Result mapi will be the first mapi response obtained (service name and response), or null
87
+ * Result error will be the first error thrown (service name and CwiError), or null
88
+ * Increments to next configured service and tries again until all services have been tried.
89
+ *
90
+ * @param txid transaction hash for which proof is requested
91
+ * @param useNext optional, forces skip to next service before starting service requests cycle.
92
+ */
93
+ getMerklePath(txid: string, useNext?: boolean): Promise<GetMerklePathResult>
94
+
95
+ /**
96
+ *
97
+ * @param beef
98
+ * @param txids
99
+ * @param chain
100
+ * @returns
101
+ */
102
+ postBeef(beef: Beef, txids: string[], logger?: WalletLoggerInterface): Promise<PostBeefResult[]>
103
+
104
+ /**
105
+ * @param script Output script to be hashed for `getUtxoStatus` default `outputFormat`
106
+ * @returns script hash in 'hashLE' format, which is the default.
107
+ */
108
+ hashOutputScript(script: string): string
109
+
110
+ /**
111
+ * For an array of one or more txids, returns for each wether it is a 'known', 'mined', or 'unknown' transaction.
112
+ *
113
+ * Primarily useful for determining if a recently broadcast transaction is known to the processing network.
114
+ *
115
+ * Also returns the current depth from chain tip if 'mined'.
116
+ *
117
+ * @param txids
118
+ * @param useNext
119
+ */
120
+ getStatusForTxids(txids: string[], useNext?: boolean): Promise<GetStatusForTxidsResult>
121
+
122
+ /**
123
+ * Calls getUtxoStatus with the hash of the output's lockingScript,
124
+ * and ensures that the output's outpoint matches an unspent use of that script.
125
+ *
126
+ * @param output
127
+ * @returns true if the output appears to currently be spendable.
128
+ */
129
+ isUtxo(output: TableOutput): Promise<boolean>
130
+
131
+ /**
132
+ * Attempts to determine the UTXO status of a transaction output.
133
+ *
134
+ * Cycles through configured transaction processing services attempting to get a valid response.
135
+ *
136
+ * @param output transaction output identifier in format determined by `outputFormat`.
137
+ * @param chain which chain to post to, all of rawTx's inputs must be unspent on this chain.
138
+ * @param outputFormat optional, supported values:
139
+ * 'hashLE' little-endian sha256 hash of output script
140
+ * 'hashBE' big-endian sha256 hash of output script
141
+ * 'script' entire transaction output script
142
+ * undefined if length of `output` is 32 hex bytes then 'hashBE`, otherwise 'script'.
143
+ * @param outpoint if valid, result isUtxo is true only if this txid and vout match an unspent occurance of output script. `${txid}.${vout}` format.
144
+ * @param useNext optional, forces skip to next service before starting service requests cycle.
145
+ */
146
+ getUtxoStatus(
147
+ output: string,
148
+ outputFormat?: GetUtxoStatusOutputFormat,
149
+ outpoint?: string,
150
+ useNext?: boolean
151
+ ): Promise<GetUtxoStatusResult>
152
+
153
+ getScriptHashHistory(
154
+ hash: string,
155
+ useNext?: boolean,
156
+ logger?: WalletLoggerInterface
157
+ ): Promise<GetScriptHashHistoryResult>
158
+
159
+ /**
160
+ * @returns a block header
161
+ * @param hash block hash
162
+ */
163
+ hashToHeader(hash: string): Promise<BlockHeader>
164
+
165
+ /**
166
+ * @returns whether the locktime value allows the transaction to be mined at the current chain height
167
+ * @param txOrLockTime either a bitcoin locktime value or hex, binary, un-encoded Transaction
168
+ */
169
+ nLockTimeIsFinal(txOrLockTime: string | number[] | BsvTransaction | number): Promise<boolean>
170
+
171
+ /**
172
+ * Constructs a `Beef` for the given `txid` using only external data retrieval services.
173
+ *
174
+ * In most cases, the `getBeefForTransaction` method of the `StorageProvider` class should be
175
+ * used instead to avoid redundantly retrieving data.
176
+ *
177
+ * @throws errors if txid does not correspond to a valid transaction as determined by the
178
+ * configured services.
179
+ *
180
+ * @param txid
181
+ */
182
+ getBeefForTxid(txid: string): Promise<Beef>
183
+
184
+ /**
185
+ * @param reset if true, ends current interval and starts a new one.
186
+ * @returns a history of service calls made to the configured services.
187
+ */
188
+ getServicesCallHistory(reset?: boolean): ServicesCallHistory
189
+ }
190
+
191
+ export type ScriptHashFormat = 'hashLE' | 'hashBE' | 'script'
192
+ export type GetUtxoStatusOutputFormat = 'hashLE' | 'hashBE' | 'script'
193
+
194
+ export interface BsvExchangeRate {
195
+ timestamp: Date
196
+ base: 'USD'
197
+ rate: number
198
+ }
199
+
200
+ export interface FiatExchangeRates {
201
+ timestamp: Date
202
+ base: 'USD'
203
+ rates: Record<string, number>
204
+ }
205
+
206
+ export interface WalletServicesOptions {
207
+ /**
208
+ * 'main' or 'test': which BSV chain to use
209
+ */
210
+ chain: Chain
211
+ /**
212
+ * As of 2025-08-31 the `taalApiKey` is unused for default configured services.
213
+ * See `arcConfig` instead.
214
+ */
215
+ taalApiKey?: string
216
+ /**
217
+ * Api key for use accessing Bitails API at
218
+ * mainnet: `https://api.bitails.io/`
219
+ * testnet: `https://test-api.bitails.io/`
220
+ */
221
+ bitailsApiKey?: string
222
+ /**
223
+ * Api key for use accessing WhatsOnChain API at
224
+ * mainnet: `https://api.whatsonchain.com/v1/bsv/main`
225
+ * testnet: `https://api.whatsonchain.com/v1/bsv/test`
226
+ */
227
+ whatsOnChainApiKey?: string
228
+ /**
229
+ * The initial approximate BSV/USD exchange rate.
230
+ */
231
+ bsvExchangeRate: BsvExchangeRate
232
+ /**
233
+ * Update interval for BSV/USD exchange rate.
234
+ * Default is 15 minutes.
235
+ */
236
+ bsvUpdateMsecs: number
237
+ /**
238
+ * The initial approximate fiat exchange rates with USD as base.
239
+ */
240
+ fiatExchangeRates: FiatExchangeRates
241
+ /**
242
+ * Update interval for Fiat exchange rates.
243
+ * Default is 24 hours.
244
+ */
245
+ fiatUpdateMsecs: number
246
+ /**
247
+ * MAPI callbacks are deprecated at this time.
248
+ */
249
+ disableMapiCallback?: boolean
250
+ /**
251
+ * API key for use accessing fiat exchange rates API at
252
+ * `http://api.exchangeratesapi.io/v1/latest?access_key=${key}`
253
+ *
254
+ * Obtain your own api key here:
255
+ * https://manage.exchangeratesapi.io/signup/free
256
+ */
257
+ exchangeratesapiKey?: string
258
+ /**
259
+ * Due to the default use of a free exchangeratesapiKey with low usage limits,
260
+ * the `ChaintracksService` can act as a request rate multiplier.
261
+ *
262
+ * By default the following endpoint is used:
263
+ * `https://mainnet-chaintracks.babbage.systems/getFiatExchangeRates`
264
+ */
265
+ chaintracksFiatExchangeRatesUrl?: string
266
+ /**
267
+ * Optional Chaintracks client API instance.
268
+ * Default is a new instance of ChaintracksServiceClient configured to use:
269
+ * mainnet: `https://mainnet-chaintracks.babbage.systems`
270
+ * testnet: `https://testnet-chaintracks.babbage.systems`
271
+ */
272
+ chaintracks?: ChaintracksClientApi
273
+ /**
274
+ * TAAL ARC service provider endpoit to use
275
+ * Default is:
276
+ * mainnet: `https://arc.taal.com`
277
+ * testnet: `https://arc-test.taal.com`
278
+ */
279
+ arcUrl: string
280
+ /**
281
+ * TAAL ARC service configuration options.
282
+ *
283
+ * apiKey Default value is undefined.
284
+ *
285
+ * deploymentId Default value: `wallet-toolbox-${randomBytesHex(16)}`.
286
+ *
287
+ * callbackUrl Default is undefined.
288
+ * callbackToken Default is undefined.
289
+ */
290
+ arcConfig: ArcConfig
291
+ /**
292
+ * GorillaPool ARC service provider endpoit to use
293
+ * Default is:
294
+ * mainnet: `https://arc.gorillapool.io`
295
+ * testnet: undefined
296
+ */
297
+ arcGorillaPoolUrl?: string
298
+ /**
299
+ * GorillaPool ARC service configuration options.
300
+ *
301
+ * apiKey Default is undefined.
302
+ *
303
+ * deploymentId Default value: `wallet-toolbox-${randomBytesHex(16)}`.
304
+ *
305
+ * callbackUrl Default is undefined.
306
+ * callbackToken Default is undefined.
307
+ */
308
+ arcGorillaPoolConfig?: ArcConfig
309
+ }
310
+
311
+ export interface GetStatusForTxidsResult {
312
+ /**
313
+ * The name of the service returning these results.
314
+ */
315
+ name: string
316
+ status: 'success' | 'error'
317
+ /**
318
+ * The first exception error that occurred during processing, if any.
319
+ */
320
+ error?: WalletError
321
+ results: StatusForTxidResult[]
322
+ }
323
+
324
+ export interface StatusForTxidResult {
325
+ txid: string
326
+ /**
327
+ * roughly depth of block containing txid from chain tip.
328
+ */
329
+ depth: number | undefined
330
+ /**
331
+ * 'mined' if depth > 0
332
+ * 'known' if depth === 0
333
+ * 'unknown' if depth === undefined, txid may be old an purged or never processed.
334
+ */
335
+ status: 'mined' | 'known' | 'unknown'
336
+ }
337
+
338
+ /**
339
+ * Properties on result returned from `WalletServices` function `getRawTx`.
340
+ */
341
+ export interface GetRawTxResult {
342
+ /**
343
+ * Transaction hash or rawTx (and of initial request)
344
+ */
345
+ txid: string
346
+ /**
347
+ * The name of the service returning the rawTx, or undefined if no rawTx
348
+ */
349
+ name?: string
350
+ /**
351
+ * Multiple proofs may be returned when a transaction also appears in
352
+ * one or more orphaned blocks
353
+ */
354
+ rawTx?: number[]
355
+ /**
356
+ * The first exception error that occurred during processing, if any.
357
+ */
358
+ error?: WalletError
359
+ }
360
+
361
+ /**
362
+ * Properties on result returned from `WalletServices` function `getMerkleProof`.
363
+ */
364
+ export interface GetMerklePathResult {
365
+ /**
366
+ * The name of the service returning the proof, or undefined if no proof
367
+ */
368
+ name?: string
369
+ /**
370
+ * Multiple proofs may be returned when a transaction also appears in
371
+ * one or more orphaned blocks
372
+ */
373
+ merklePath?: MerklePath
374
+
375
+ header?: BlockHeader
376
+
377
+ /**
378
+ * The first exception error that occurred during processing, if any.
379
+ */
380
+ error?: WalletError
381
+
382
+ notes?: ReqHistoryNote[]
383
+ }
384
+
385
+ export interface PostTxResultForTxid {
386
+ txid: string
387
+
388
+ /**
389
+ * 'success' - The transaction was accepted for processing
390
+ */
391
+ status: 'success' | 'error'
392
+
393
+ /**
394
+ * if true, the transaction was already known to this service. Usually treat as a success.
395
+ *
396
+ * Potentially stop posting to additional transaction processors.
397
+ */
398
+ alreadyKnown?: boolean
399
+
400
+ /**
401
+ * service indicated this broadcast double spends at least one input
402
+ * `competingTxs` may be an array of txids that were first seen spends of at least one input.
403
+ */
404
+ doubleSpend?: boolean
405
+
406
+ blockHash?: string
407
+ blockHeight?: number
408
+ merklePath?: MerklePath
409
+
410
+ competingTxs?: string[]
411
+
412
+ data?: object | string | PostTxResultForTxidError
413
+
414
+ notes?: ReqHistoryNote[]
415
+
416
+ /**
417
+ * true iff service was unable to process a potentially valid transaction
418
+ */
419
+ serviceError?: boolean
420
+ }
421
+
422
+ export interface PostTxResultForTxidError {
423
+ status?: string
424
+ detail?: string
425
+ more?: object
426
+ }
427
+
428
+ export interface PostBeefResult extends PostTxsResult {}
429
+
430
+ /**
431
+ * Properties on array items of result returned from `WalletServices` function `postBeef`.
432
+ */
433
+ export interface PostTxsResult {
434
+ /**
435
+ * The name of the service to which the transaction was submitted for processing
436
+ */
437
+ name: string
438
+ /**
439
+ * 'success' all txids returned status of 'success'
440
+ * 'error' one or more txids returned status of 'error'. See txidResults for details.
441
+ */
442
+ status: 'success' | 'error'
443
+
444
+ error?: WalletError
445
+
446
+ txidResults: PostTxResultForTxid[]
447
+
448
+ /**
449
+ * Service response object. Use service name and status to infer type of object.
450
+ */
451
+ data?: object
452
+
453
+ notes?: ReqHistoryNote[]
454
+ }
455
+
456
+ export interface GetUtxoStatusDetails {
457
+ /**
458
+ * if isUtxo, the block height containing the matching unspent transaction output
459
+ *
460
+ * typically there will be only one, but future orphans can result in multiple values
461
+ */
462
+ height?: number
463
+ /**
464
+ * if isUtxo, the transaction hash (txid) of the transaction containing the matching unspent transaction output
465
+ *
466
+ * typically there will be only one, but future orphans can result in multiple values
467
+ */
468
+ txid?: string
469
+ /**
470
+ * if isUtxo, the output index in the transaction containing of the matching unspent transaction output
471
+ *
472
+ * typically there will be only one, but future orphans can result in multiple values
473
+ */
474
+ index?: number
475
+ /**
476
+ * if isUtxo, the amount of the matching unspent transaction output
477
+ *
478
+ * typically there will be only one, but future orphans can result in multiple values
479
+ */
480
+ satoshis?: number
481
+ }
482
+
483
+ export interface GetUtxoStatusResult {
484
+ /**
485
+ * The name of the service to which the transaction was submitted for processing
486
+ */
487
+ name: string
488
+ /**
489
+ * 'success' - the operation was successful, non-error results are valid.
490
+ * 'error' - the operation failed, error may have relevant information.
491
+ */
492
+ status: 'success' | 'error'
493
+ /**
494
+ * When status is 'error', provides code and description
495
+ */
496
+ error?: WalletError
497
+ /**
498
+ * true if the output is associated with at least one unspent transaction output
499
+ */
500
+ isUtxo?: boolean
501
+ /**
502
+ * Additional details about occurances of this output script as a utxo.
503
+ *
504
+ * Normally there will be one item in the array but due to the possibility of orphan races
505
+ * there could be more than one block in which it is a valid utxo.
506
+ */
507
+ details: GetUtxoStatusDetails[]
508
+ }
509
+
510
+ export interface GetScriptHashHistory {
511
+ txid: string
512
+ height?: number
513
+ }
514
+
515
+ export interface GetScriptHashHistoryResult {
516
+ /**
517
+ * The name of the service to which the transaction was submitted for processing
518
+ */
519
+ name: string
520
+ /**
521
+ * 'success' - the operation was successful, non-error results are valid.
522
+ * 'error' - the operation failed, error may have relevant information.
523
+ */
524
+ status: 'success' | 'error'
525
+ /**
526
+ * When status is 'error', provides code and description
527
+ */
528
+ error?: WalletError
529
+ /**
530
+ * Transaction txid (and height if mined) that consumes the script hash. May not be a complete history.
531
+ */
532
+ history: GetScriptHashHistory[]
533
+ }
534
+
535
+ /**
536
+ * These are fields of 80 byte serialized header in order whose double sha256 hash is a block's hash value
537
+ * and the next block's previousHash value.
538
+ *
539
+ * All block hash values and merkleRoot values are 32 byte hex string values with the byte order reversed from the serialized byte order.
540
+ */
541
+ export interface BaseBlockHeader {
542
+ /**
543
+ * Block header version value. Serialized length is 4 bytes.
544
+ */
545
+ version: number
546
+ /**
547
+ * Hash of previous block's block header. Serialized length is 32 bytes.
548
+ */
549
+ previousHash: string
550
+ /**
551
+ * Root hash of the merkle tree of all transactions in this block. Serialized length is 32 bytes.
552
+ */
553
+ merkleRoot: string
554
+ /**
555
+ * Block header time value. Serialized length is 4 bytes.
556
+ */
557
+ time: number
558
+ /**
559
+ * Block header bits value. Serialized length is 4 bytes.
560
+ */
561
+ bits: number
562
+ /**
563
+ * Block header nonce value. Serialized length is 4 bytes.
564
+ */
565
+ nonce: number
566
+ }
567
+
568
+ /**
569
+ * A `BaseBlockHeader` extended with its computed hash and height in its chain.
570
+ */
571
+ export interface BlockHeader extends BaseBlockHeader {
572
+ /**
573
+ * Height of the header, starting from zero.
574
+ */
575
+ height: number
576
+ /**
577
+ * The double sha256 hash of the serialized `BaseBlockHeader` fields.
578
+ */
579
+ hash: string
580
+ }
581
+
582
+ export type GetUtxoStatusService = (
583
+ output: string,
584
+ outputFormat?: GetUtxoStatusOutputFormat,
585
+ outpoint?: string
586
+ ) => Promise<GetUtxoStatusResult>
587
+
588
+ export type GetStatusForTxidsService = (txids: string[]) => Promise<GetStatusForTxidsResult>
589
+
590
+ export type GetScriptHashHistoryService = (hash: string) => Promise<GetScriptHashHistoryResult>
591
+
592
+ export type GetMerklePathService = (txid: string, services: WalletServices) => Promise<GetMerklePathResult>
593
+
594
+ export type GetRawTxService = (txid: string, chain: Chain) => Promise<GetRawTxResult>
595
+
596
+ export type PostTxsService = (beef: Beef, txids: string[], services: WalletServices) => Promise<PostTxsResult>
597
+
598
+ export type PostBeefService = (beef: Beef, txids: string[]) => Promise<PostBeefResult>
599
+
600
+ export type UpdateFiatExchangeRateService = (
601
+ targetCurrencies: string[],
602
+ options: WalletServicesOptions
603
+ ) => Promise<FiatExchangeRates>
604
+
605
+ /**
606
+ * Type for the service call history returned by Services.getServicesCallHistory.
607
+ */
608
+ export type ServicesCallHistory = {
609
+ version: number
610
+ getMerklePath: ServiceCallHistory
611
+ getRawTx: ServiceCallHistory
612
+ postBeef: ServiceCallHistory
613
+ getUtxoStatus: ServiceCallHistory
614
+ getStatusForTxids: ServiceCallHistory
615
+ getScriptHashHistory: ServiceCallHistory
616
+ updateFiatExchangeRates: ServiceCallHistory
617
+ }
618
+
619
+ /**
620
+ * Minimum data tracked for each service call.
621
+ */
622
+ export interface ServiceCall {
623
+ /**
624
+ * string value must be Date's toISOString format.
625
+ */
626
+ when: Date | string
627
+ msecs: number
628
+ /**
629
+ * true iff service provider successfully processed the request
630
+ * false iff service provider failed to process the request which includes thrown errors.
631
+ */
632
+ success: boolean
633
+ /**
634
+ * Simple text summary of result. e.g. `not a valid utxo` or `valid utxo`
635
+ */
636
+ result?: string
637
+ /**
638
+ * Error code and message iff success is false and a exception was thrown.
639
+ */
640
+ error?: { message: string; code: string }
641
+ }
642
+
643
+ /**
644
+ * Counts of service calls over a time interval.
645
+ */
646
+ export interface ServiceCallHistoryCounts {
647
+ /**
648
+ * count of calls returning success true.
649
+ */
650
+ success: number
651
+ /**
652
+ * count of calls returning success false.
653
+ */
654
+ failure: number
655
+ /**
656
+ * of failures (success false), count of calls with valid error code and message.
657
+ */
658
+ error: number
659
+ /**
660
+ * Counts are of calls over interval `since` to `until`.
661
+ * string value must be Date's toISOString format.
662
+ */
663
+ since: Date | string
664
+ /**
665
+ * Counts are of calls over interval `since` to `until`.
666
+ * string value must be Date's toISOString format.
667
+ */
668
+ until: Date | string
669
+ }
670
+
671
+ /**
672
+ * History of service calls for a single service, single provider.
673
+ */
674
+ export interface ProviderCallHistory {
675
+ providerName: string
676
+ serviceName: string
677
+ /**
678
+ * Most recent service calls.
679
+ * Array length is limited by Services configuration.
680
+ */
681
+ calls: ServiceCall[]
682
+ /**
683
+ * Counts since creation of Services instance.
684
+ */
685
+ totalCounts: ServiceCallHistoryCounts
686
+ /**
687
+ * Entry [0] is always the current interval being extended by new calls.
688
+ * when `getServiceCallHistory` with `reset` true is called, a new interval with zero counts is added to the start of array.
689
+ * Array length is limited by Services configuration.
690
+ */
691
+ resetCounts: ServiceCallHistoryCounts[]
692
+ }
693
+
694
+ /**
695
+ * History of service calls for a single service, all providers.
696
+ */
697
+ export interface ServiceCallHistory {
698
+ serviceName: string
699
+ historyByProvider: Record<string, ProviderCallHistory>
700
+ }
@@ -0,0 +1,11 @@
1
+ import { KeyDeriverApi } from '@bsv/sdk'
2
+ import { Chain } from './types'
3
+
4
+ /**
5
+ */
6
+ export interface WalletSigner {
7
+ isWalletSigner: true
8
+
9
+ chain: Chain
10
+ keyDeriver: KeyDeriverApi
11
+ }