@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,372 @@
1
+ import {
2
+ Random,
3
+ Utils,
4
+ PrivateKey,
5
+ CreateHmacArgs,
6
+ CreateHmacResult,
7
+ CreateSignatureArgs,
8
+ CreateSignatureResult,
9
+ GetPublicKeyArgs,
10
+ ProtoWallet,
11
+ PubKeyHex,
12
+ RevealCounterpartyKeyLinkageArgs,
13
+ RevealCounterpartyKeyLinkageResult,
14
+ RevealSpecificKeyLinkageArgs,
15
+ RevealSpecificKeyLinkageResult,
16
+ VerifyHmacArgs,
17
+ VerifyHmacResult,
18
+ VerifySignatureArgs,
19
+ VerifySignatureResult,
20
+ WalletDecryptArgs,
21
+ WalletDecryptResult,
22
+ WalletEncryptArgs,
23
+ WalletEncryptResult
24
+ } from '@bsv/sdk'
25
+
26
+ /**
27
+ * PrivilegedKeyManager
28
+ *
29
+ * This class manages a privileged (i.e., very sensitive) private key, obtained from
30
+ * an external function (`keyGetter`), which might be backed by HSMs, secure enclaves,
31
+ * or other secure storage. The manager retains the key in memory only for a limited
32
+ * duration (`retentionPeriod`), uses XOR-based chunk-splitting obfuscation, and
33
+ * includes decoy data to raise the difficulty of discovering the real key in memory.
34
+ *
35
+ * IMPORTANT: While these measures raise the bar for attackers, JavaScript environments
36
+ * do not provide perfect in-memory secrecy.
37
+ */
38
+ export class PrivilegedKeyManager implements ProtoWallet {
39
+ /**
40
+ * Function that will retrieve the PrivateKey from a secure environment,
41
+ * e.g., an HSM or secure enclave. The reason for key usage is passed in
42
+ * to help with user consent, auditing, and access policy checks.
43
+ */
44
+ private keyGetter: (reason: string) => Promise<PrivateKey>
45
+
46
+ /**
47
+ * Time (in ms) for which the obfuscated key remains in memory
48
+ * before being automatically destroyed.
49
+ */
50
+ private retentionPeriod: number
51
+
52
+ /**
53
+ * A list of dynamically generated property names used to store
54
+ * real key chunks (XORed with random pads).
55
+ */
56
+ private chunkPropNames: string[] = []
57
+
58
+ /**
59
+ * A list of dynamically generated property names used to store
60
+ * the random pads that correspond to the real key chunks.
61
+ */
62
+ private chunkPadPropNames: string[] = []
63
+
64
+ /**
65
+ * A list of decoy property names that will be removed
66
+ * when the real key is destroyed.
67
+ */
68
+ private decoyPropNamesDestroy: string[] = []
69
+
70
+ /**
71
+ * A list of decoy property names that remain in memory
72
+ * even after the real key is destroyed (just to cause confusion).
73
+ */
74
+ private decoyPropNamesRemain: string[] = []
75
+
76
+ /**
77
+ * Handle to the timer that will remove the key from memory
78
+ * after the retention period. If the key is refreshed again
79
+ * within that period, the timer is cleared and re-set.
80
+ */
81
+ private destroyTimer: any | undefined
82
+
83
+ /**
84
+ * Number of chunks to split the 32-byte key into.
85
+ * Adjust to increase or decrease obfuscation complexity.
86
+ */
87
+ private readonly CHUNK_COUNT = 4
88
+
89
+ /**
90
+ * @param keyGetter - Asynchronous function that retrieves the PrivateKey from a secure environment.
91
+ * @param retentionPeriod - Time in milliseconds to retain the obfuscated key in memory before zeroizing.
92
+ */
93
+ constructor(keyGetter: (reason: string) => Promise<PrivateKey>, retentionPeriod = 120_000) {
94
+ this.keyGetter = keyGetter
95
+ this.retentionPeriod = retentionPeriod
96
+
97
+ // Initialize some random decoy properties that always remain:
98
+ for (let i = 0; i < 2; i++) {
99
+ const propName = this.generateRandomPropName()
100
+ // Store random garbage to cause confusion
101
+ ;(this as any)[propName] = Uint8Array.from(Random(16))
102
+ this.decoyPropNamesRemain.push(propName)
103
+ }
104
+ }
105
+
106
+ /**
107
+ * Safely destroys the in-memory obfuscated key material by zeroizing
108
+ * and deleting related fields. Also destroys some (but not all) decoy
109
+ * properties to further confuse an attacker.
110
+ */
111
+ destroyKey(): void {
112
+ try {
113
+ // Zero out real chunk data
114
+ for (const name of this.chunkPropNames) {
115
+ const data: Uint8Array | undefined = (this as any)[name]
116
+ if (data) {
117
+ data.fill(0)
118
+ }
119
+ delete (this as any)[name]
120
+ }
121
+ for (const name of this.chunkPadPropNames) {
122
+ const data: Uint8Array | undefined = (this as any)[name]
123
+ if (data) {
124
+ data.fill(0)
125
+ }
126
+ delete (this as any)[name]
127
+ }
128
+
129
+ // Destroy some decoys
130
+ for (const name of this.decoyPropNamesDestroy) {
131
+ const data: Uint8Array | undefined = (this as any)[name]
132
+ if (data) {
133
+ data.fill(0)
134
+ }
135
+ delete (this as any)[name]
136
+ }
137
+
138
+ // Clear arrays of property names
139
+ this.chunkPropNames = []
140
+ this.chunkPadPropNames = []
141
+ this.decoyPropNamesDestroy = []
142
+ } catch (_) {
143
+ // Swallow any errors in the destruction process
144
+ } finally {
145
+ if (this.destroyTimer) {
146
+ clearTimeout(this.destroyTimer)
147
+ this.destroyTimer = undefined
148
+ }
149
+ }
150
+ }
151
+
152
+ /**
153
+ * Re/sets the destruction timer that removes the key from memory
154
+ * after `retentionPeriod` ms. If a timer is already running, it
155
+ * is cleared and re-set. This ensures the key remains in memory
156
+ * for exactly the desired window after its most recent acquisition.
157
+ */
158
+ private scheduleKeyDestruction(): void {
159
+ if (this.destroyTimer) {
160
+ // TODO: Consider a constructor flag to avoid clearing timers for higher security
161
+ clearTimeout(this.destroyTimer)
162
+ }
163
+ this.destroyTimer = setTimeout(() => {
164
+ this.destroyKey()
165
+ }, this.retentionPeriod)
166
+ }
167
+
168
+ /**
169
+ * XOR-based obfuscation on a per-chunk basis.
170
+ * This function takes two equal-length byte arrays
171
+ * and returns the XOR combination.
172
+ */
173
+ private xorBytes(a: Uint8Array, b: Uint8Array): Uint8Array {
174
+ const out = new Uint8Array(a.length)
175
+ for (let i = 0; i < a.length; i++) {
176
+ out[i] = a[i] ^ b[i]
177
+ }
178
+ return out
179
+ }
180
+
181
+ /**
182
+ * Splits the 32-byte key into `this.CHUNK_COUNT` smaller chunks
183
+ * (mostly equal length; the last chunk picks up leftover bytes
184
+ * if 32 is not evenly divisible).
185
+ */
186
+ private splitKeyIntoChunks(keyBytes: Uint8Array): Uint8Array[] {
187
+ const chunkSize = Math.floor(keyBytes.length / this.CHUNK_COUNT)
188
+ const chunks: Uint8Array[] = []
189
+ let offset = 0
190
+
191
+ for (let i = 0; i < this.CHUNK_COUNT; i++) {
192
+ const size = i === this.CHUNK_COUNT - 1 ? keyBytes.length - offset : chunkSize
193
+ chunks.push(keyBytes.slice(offset, offset + size))
194
+ offset += size
195
+ }
196
+ return chunks
197
+ }
198
+
199
+ /**
200
+ * Reassembles the chunks from the dynamic properties, XORs them
201
+ * with their corresponding pads, and returns a single 32-byte
202
+ * Uint8Array representing the raw key.
203
+ */
204
+ private reassembleKeyFromChunks(): Uint8Array | null {
205
+ try {
206
+ const chunkArrays: Uint8Array[] = []
207
+ for (let i = 0; i < this.chunkPropNames.length; i++) {
208
+ const chunkEnc = (this as any)[this.chunkPropNames[i]] as Uint8Array
209
+ const chunkPad = (this as any)[this.chunkPadPropNames[i]] as Uint8Array
210
+ if (!chunkEnc || !chunkPad || chunkEnc.length !== chunkPad.length) {
211
+ return null
212
+ }
213
+ const rawChunk = this.xorBytes(chunkEnc, chunkPad)
214
+ chunkArrays.push(rawChunk)
215
+ }
216
+ // Concat them back to a single 32-byte array:
217
+ const totalLength = chunkArrays.reduce((sum, c) => sum + c.length, 0)
218
+ if (totalLength !== 32) {
219
+ // We only handle 32-byte keys
220
+ return null
221
+ }
222
+ const rawKey = new Uint8Array(totalLength)
223
+ let offset = 0
224
+ for (const chunk of chunkArrays) {
225
+ rawKey.set(chunk, offset)
226
+ offset += chunk.length
227
+ // Attempt to zero the ephemeral chunk
228
+ chunk.fill(0)
229
+ }
230
+ return rawKey
231
+ } catch (_) {
232
+ // If any property is missing or type mismatch, we return null
233
+ return null
234
+ }
235
+ }
236
+
237
+ /**
238
+ * Generates a random property name to store key chunks or decoy data.
239
+ */
240
+ private generateRandomPropName(): string {
241
+ // E.g., 8 random hex characters for the property name
242
+ const randomHex = Utils.toHex(Random(4))
243
+ return `_${randomHex}_${Math.floor(Math.random() * 1e6)}`
244
+ }
245
+
246
+ /**
247
+ * Forces a PrivateKey to be represented as exactly 32 bytes, left-padding
248
+ * with zeros if its numeric value has fewer than 32 bytes.
249
+ */
250
+ private get32ByteRepresentation(privKey: PrivateKey): Uint8Array {
251
+ // The internal "toArray()" can be up to 32 bytes, but sometimes fewer
252
+ // if the numeric value has leading zeros.
253
+ const buf = privKey.toArray()
254
+ if (buf.length > 32) {
255
+ throw new Error('PrivilegedKeyManager: Expected a 32-byte key, but got more.')
256
+ }
257
+ // Left-pad with zeros if needed
258
+ const keyBytes = new Uint8Array(32)
259
+ keyBytes.set(buf, 32 - buf.length)
260
+ return keyBytes
261
+ }
262
+
263
+ /**
264
+ * Returns the privileged key needed to perform cryptographic operations.
265
+ * Uses in-memory chunk-based obfuscation if the key was already fetched.
266
+ * Otherwise, it calls out to `keyGetter`, splits the 32-byte representation
267
+ * of the key, XORs each chunk with a random pad, and stores them under
268
+ * dynamic property names. Also populates new decoy properties.
269
+ *
270
+ * @param reason - The reason for why the key is needed, passed to keyGetter.
271
+ * @returns The PrivateKey object needed for cryptographic operations.
272
+ */
273
+ private async getPrivilegedKey(reason: string): Promise<PrivateKey> {
274
+ // If we already have chunk properties, try reassemble
275
+ if (this.chunkPropNames.length > 0 && this.chunkPadPropNames.length > 0) {
276
+ const rawKeyBytes = this.reassembleKeyFromChunks()
277
+ if (rawKeyBytes && rawKeyBytes.length === 32) {
278
+ // Convert 32 raw bytes back to a PrivateKey
279
+ // (Leading zeros are preserved, but PrivateKey() will parse it as a big integer.)
280
+ const hexKey = Utils.toHex([...rawKeyBytes]) // 64 hex chars
281
+ rawKeyBytes.fill(0) // Zero ephemeral copy
282
+ this.scheduleKeyDestruction()
283
+ return new PrivateKey(hexKey, 'hex')
284
+ }
285
+ }
286
+
287
+ // Otherwise, fetch a fresh key from the secure environment
288
+ const fetchedKey = await this.keyGetter(reason)
289
+
290
+ // Force 32‑byte representation (left-pad if necessary)
291
+ const keyBytes = this.get32ByteRepresentation(fetchedKey)
292
+
293
+ // Clean up any old data first (in case we had something stale)
294
+ this.destroyKey()
295
+
296
+ // Split the key
297
+ const chunks = this.splitKeyIntoChunks(keyBytes)
298
+
299
+ // Store new chunk data under random property names
300
+ for (let i = 0; i < chunks.length; i++) {
301
+ const chunkProp = this.generateRandomPropName()
302
+ const padProp = this.generateRandomPropName()
303
+ this.chunkPropNames.push(chunkProp)
304
+ this.chunkPadPropNames.push(padProp)
305
+
306
+ // Generate random pad of the same length as the chunk
307
+ const pad = Uint8Array.from(Random(chunks[i].length))
308
+ // XOR the chunk to obfuscate
309
+ const obf = this.xorBytes(chunks[i], pad)
310
+
311
+ // Store them in dynamic properties
312
+ ;(this as any)[chunkProp] = obf
313
+ ;(this as any)[padProp] = pad
314
+ }
315
+
316
+ // Generate some decoy properties that will be destroyed with the key
317
+ for (let i = 0; i < 2; i++) {
318
+ const decoyProp = this.generateRandomPropName()
319
+ ;(this as any)[decoyProp] = Uint8Array.from(Random(32))
320
+ this.decoyPropNamesDestroy.push(decoyProp)
321
+ }
322
+
323
+ // Zero out ephemeral original
324
+ keyBytes.fill(0)
325
+
326
+ // Schedule destruction
327
+ this.scheduleKeyDestruction()
328
+
329
+ // Return the newly fetched key as a normal PrivateKey
330
+ return fetchedKey
331
+ }
332
+
333
+ async getPublicKey(args: GetPublicKeyArgs): Promise<{ publicKey: PubKeyHex }> {
334
+ return new ProtoWallet(await this.getPrivilegedKey(args.privilegedReason as string)).getPublicKey(args)
335
+ }
336
+
337
+ async revealCounterpartyKeyLinkage(
338
+ args: RevealCounterpartyKeyLinkageArgs
339
+ ): Promise<RevealCounterpartyKeyLinkageResult> {
340
+ return new ProtoWallet(await this.getPrivilegedKey(args.privilegedReason as string)).revealCounterpartyKeyLinkage(
341
+ args
342
+ )
343
+ }
344
+
345
+ async revealSpecificKeyLinkage(args: RevealSpecificKeyLinkageArgs): Promise<RevealSpecificKeyLinkageResult> {
346
+ return new ProtoWallet(await this.getPrivilegedKey(args.privilegedReason as string)).revealSpecificKeyLinkage(args)
347
+ }
348
+
349
+ async encrypt(args: WalletEncryptArgs): Promise<WalletEncryptResult> {
350
+ return new ProtoWallet(await this.getPrivilegedKey(args.privilegedReason as string)).encrypt(args)
351
+ }
352
+
353
+ async decrypt(args: WalletDecryptArgs): Promise<WalletDecryptResult> {
354
+ return new ProtoWallet(await this.getPrivilegedKey(args.privilegedReason as string)).decrypt(args)
355
+ }
356
+
357
+ async createHmac(args: CreateHmacArgs): Promise<CreateHmacResult> {
358
+ return new ProtoWallet(await this.getPrivilegedKey(args.privilegedReason as string)).createHmac(args)
359
+ }
360
+
361
+ async verifyHmac(args: VerifyHmacArgs): Promise<VerifyHmacResult> {
362
+ return new ProtoWallet(await this.getPrivilegedKey(args.privilegedReason as string)).verifyHmac(args)
363
+ }
364
+
365
+ async createSignature(args: CreateSignatureArgs): Promise<CreateSignatureResult> {
366
+ return new ProtoWallet(await this.getPrivilegedKey(args.privilegedReason as string)).createSignature(args)
367
+ }
368
+
369
+ async verifySignature(args: VerifySignatureArgs): Promise<VerifySignatureResult> {
370
+ return new ProtoWallet(await this.getPrivilegedKey(args.privilegedReason as string)).verifySignature(args)
371
+ }
372
+ }
@@ -0,0 +1,13 @@
1
+ # Wallet SDK
2
+
3
+ Primarily `interface` declarations of most abstract Wallet.interfaces related APIs.
4
+
5
+ This includes:
6
+
7
+ - Local copy of Wallet.interfaces, WalletCrypto, WalletSigner, ProtoWallet, CachedKeyDeriver to be merged back to `@bsv/ts-sdk`
8
+ - Certificate and CertOps for standardized certificate handling.
9
+ - WERR_errors.ts standard error classes.
10
+ - WalletError standard error base class.
11
+ - StorageSyncReadyer: a standard subset of WalletStorage for legacy import services.
12
+ - validationHelpers non-asynchronous Wallet.interfaces args object validation methods and interfaces. For interface details standardization and enforcement.
13
+ - `types` generic types for standardization.
@@ -0,0 +1,234 @@
1
+ import { AtomicBEEF, OutpointString, SendWithResult, TXIDHexString, WalletNetwork } from '@bsv/sdk'
2
+ import { WalletError } from './WalletError'
3
+ import { ReviewActionResult } from './WalletStorage.interfaces'
4
+
5
+ /**
6
+ * Not implemented.
7
+ */
8
+ export class WERR_NOT_IMPLEMENTED extends WalletError {
9
+ constructor(message?: string) {
10
+ super('WERR_NOT_IMPLEMENTED', message ?? 'Not implemented.')
11
+ }
12
+ }
13
+
14
+ /**
15
+ * An internal error has occurred.
16
+ *
17
+ * This is an example of an error with an optional custom `message`.
18
+ */
19
+ export class WERR_INTERNAL extends WalletError {
20
+ constructor(message?: string) {
21
+ super('WERR_INTERNAL', message ?? 'An internal error has occurred.')
22
+ }
23
+ }
24
+
25
+ /**
26
+ * The ${parameter} parameter is invalid.
27
+ *
28
+ * This is an example of an error object with a custom property `parameter` and templated `message`.
29
+ */
30
+ export class WERR_INVALID_OPERATION extends WalletError {
31
+ constructor(message?: string) {
32
+ super('WERR_INVALID_OPERATION', message ?? `An invalid operation was requested.`)
33
+ }
34
+ }
35
+
36
+ /**
37
+ * Unable to broadcast transaction at this time.
38
+ */
39
+ export class WERR_BROADCAST_UNAVAILABLE extends WalletError {
40
+ constructor(message?: string) {
41
+ super('WERR_BROADCAST_UNAVAILABLE', `Unable to broadcast transaction at this time.`)
42
+ }
43
+ }
44
+
45
+ /**
46
+ * The ${parameter} parameter is invalid.
47
+ *
48
+ * This is an example of an error object with a custom property `parameter` and templated `message`.
49
+ */
50
+ export class WERR_INVALID_PARAMETER extends WalletError {
51
+ constructor(
52
+ public parameter: string,
53
+ mustBe?: string
54
+ ) {
55
+ super('WERR_INVALID_PARAMETER', `The ${parameter} parameter must be ${mustBe ?? 'valid.'}`)
56
+ }
57
+ override toJson(): string {
58
+ const obj = JSON.parse(super.toJson())
59
+ obj.code = 6 // Must match HTTPWalletJSON.ts code
60
+ obj.parameter = this.parameter
61
+ return JSON.stringify(obj)
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Invalid merkleRoot ${merkleRoot} for block ${blockHash} at height ${blockHeight}${txid ? ` for txid ${txid}` : ''}.
67
+ *
68
+ * Typically thrown when a chain tracker fails to validate a merkle root.
69
+ */
70
+ export class WERR_INVALID_MERKLE_ROOT extends WalletError {
71
+ constructor(
72
+ public blockHash: string,
73
+ public blockHeight: number,
74
+ public merkleRoot: string,
75
+ public txid?: string
76
+ ) {
77
+ super(
78
+ 'WERR_INVALID_MERKLE_ROOT',
79
+ `Invalid merkleRoot ${merkleRoot} for block ${blockHash} at height ${blockHeight}${txid ? ` for txid ${txid}` : ''}.`
80
+ )
81
+ }
82
+ override toJson(): string {
83
+ const obj = JSON.parse(super.toJson())
84
+ obj.code = 8 // Must match HTTPWalletJSON.ts code
85
+ obj.blockHash = this.blockHash
86
+ obj.blockHeight = this.blockHeight
87
+ obj.merkleRoot = this.merkleRoot
88
+ obj.txid = this.txid
89
+ return JSON.stringify(obj)
90
+ }
91
+ }
92
+
93
+ /**
94
+ * The required ${parameter} parameter is missing.
95
+ *
96
+ * This is an example of an error object with a custom property `parameter`
97
+ */
98
+ export class WERR_MISSING_PARAMETER extends WalletError {
99
+ constructor(public parameter: string) {
100
+ super('WERR_MISSING_PARAMETER', `The required ${parameter} parameter is missing.`)
101
+ }
102
+ override toJson(): string {
103
+ const obj = JSON.parse(super.toJson())
104
+ obj.parameter = this.parameter
105
+ return JSON.stringify(obj)
106
+ }
107
+ }
108
+
109
+ /**
110
+ * The request is invalid.
111
+ */
112
+ export class WERR_BAD_REQUEST extends WalletError {
113
+ constructor(message?: string) {
114
+ super('WERR_BAD_REQUEST', message ?? 'The request is invalid.')
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Configured network chain is invalid or does not match across services.
120
+ */
121
+ export class WERR_NETWORK_CHAIN extends WalletError {
122
+ constructor(message?: string) {
123
+ super('WERR_NETWORK_CHAIN', message ?? 'Configured network chain is invalid or does not match across services.')
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Access is denied due to an authorization error.
129
+ */
130
+ export class WERR_UNAUTHORIZED extends WalletError {
131
+ constructor(message?: string) {
132
+ super('WERR_UNAUTHORIZED', message ?? 'Access is denied due to an authorization error.')
133
+ }
134
+ }
135
+
136
+ /**
137
+ * WalletStorageManager is not accessing user's active storage or there are conflicting active stores configured.
138
+ */
139
+ export class WERR_NOT_ACTIVE extends WalletError {
140
+ constructor(message?: string) {
141
+ super(
142
+ 'WERR_NOT_ACTIVE',
143
+ message ??
144
+ `WalletStorageManager is not accessing user's active storage or there are conflicting active stores configured.`
145
+ )
146
+ }
147
+ }
148
+
149
+ /**
150
+ * Insufficient funds in the available inputs to cover the cost of the required outputs
151
+ * and the transaction fee (${moreSatoshisNeeded} more satoshis are needed,
152
+ * for a total of ${totalSatoshisNeeded}), plus whatever would be required in order
153
+ * to pay the fee to unlock and spend the outputs used to provide the additional satoshis.
154
+ */
155
+ export class WERR_INSUFFICIENT_FUNDS extends WalletError {
156
+ /**
157
+ * @param totalSatoshisNeeded Total satoshis required to fund transactions after net of required inputs and outputs.
158
+ * @param moreSatoshisNeeded Shortfall on total satoshis required to fund transactions after net of required inputs and outputs.
159
+ */
160
+ constructor(
161
+ public totalSatoshisNeeded: number,
162
+ public moreSatoshisNeeded: number
163
+ ) {
164
+ super(
165
+ 'WERR_INSUFFICIENT_FUNDS',
166
+ `Insufficient funds in the available inputs to cover the cost of the required outputs and the transaction fee (${moreSatoshisNeeded} more satoshis are needed, for a total of ${totalSatoshisNeeded}), plus whatever would be required in order to pay the fee to unlock and spend the outputs used to provide the additional satoshis.`
167
+ )
168
+ }
169
+ override toJson(): string {
170
+ const obj = JSON.parse(super.toJson())
171
+ obj.code = 7 // Must match HTTPWalletJSON.ts code
172
+ obj.totalSatoshisNeeded = this.totalSatoshisNeeded
173
+ obj.moreSatoshisNeeded = this.moreSatoshisNeeded
174
+ return JSON.stringify(obj)
175
+ }
176
+ }
177
+
178
+ export class WERR_INVALID_PUBLIC_KEY extends WalletError {
179
+ /**
180
+ * @param key The invalid public key that caused the error.
181
+ * @param environment Optional environment flag to control whether the key is included in the message.
182
+ */
183
+ constructor(
184
+ public key: string,
185
+ network: WalletNetwork = 'mainnet'
186
+ ) {
187
+ const message =
188
+ network === 'mainnet'
189
+ ? `The provided public key "${key}" is invalid or malformed.`
190
+ : `The provided public key is invalid or malformed.`
191
+ super('WERR_INVALID_PUBLIC_KEY', message)
192
+ }
193
+ protected override toJson(): string {
194
+ const obj = JSON.parse(super.toJson())
195
+ obj.key = this.key
196
+ return JSON.stringify(obj)
197
+ }
198
+ }
199
+
200
+ /**
201
+ * When a `createAction` or `signAction` is completed in undelayed mode (`acceptDelayedBroadcast`: false),
202
+ * any unsucccessful result will return the results by way of this exception to ensure attention is
203
+ * paid to processing errors.
204
+ */
205
+ export class WERR_REVIEW_ACTIONS extends WalletError {
206
+ /**
207
+ * All parameters correspond to their comparable `createAction` or `signSction` results
208
+ * with the exception of `reviewActionResults`;
209
+ * which contains more details, particularly for double spend results.
210
+ */
211
+ constructor(
212
+ public reviewActionResults: ReviewActionResult[],
213
+ public sendWithResults: SendWithResult[],
214
+ public txid?: TXIDHexString,
215
+ public tx?: AtomicBEEF,
216
+ public noSendChange?: OutpointString[]
217
+ ) {
218
+ super('WERR_REVIEW_ACTIONS', 'Undelayed createAction or signAction results require review.')
219
+ }
220
+ override toJson(): string {
221
+ const obj = JSON.parse(super.toJson())
222
+ obj.code = 5 // Must match HTTPWalletJSON.ts code
223
+ obj.reviewActionResults = this.reviewActionResults
224
+ obj.sendWithResults = this.sendWithResults
225
+ obj.txid = this.txid
226
+ obj.tx = this.tx
227
+ obj.noSendChange = this.noSendChange
228
+ return JSON.stringify(obj)
229
+ }
230
+ }
231
+
232
+ /**
233
+ * IF YOU ADD NEW ERRORS, ALSO UPDATE THE WalletError.fromJson METHOD IN src/sdk/WalletError.ts
234
+ */