@bsv/wallet-toolbox 1.7.18 → 2.0.0-beta.0

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 (606) hide show
  1. package/out/src/sdk/validationHelpers.d.ts +303 -0
  2. package/out/src/sdk/validationHelpers.d.ts.map +1 -0
  3. package/out/src/sdk/validationHelpers.js +632 -0
  4. package/out/src/sdk/validationHelpers.js.map +1 -0
  5. package/package.json +9 -2
  6. package/.env.template +0 -22
  7. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -40
  8. package/.github/ISSUE_TEMPLATE/discussion.md +0 -24
  9. package/.github/pull_request_template.md +0 -22
  10. package/.github/workflows/push.yaml +0 -145
  11. package/.prettierrc +0 -10
  12. package/CONTRIBUTING.md +0 -89
  13. package/jest.config.ts +0 -25
  14. package/out/test/Wallet/StorageClient/storageClient.man.test.d.ts +0 -2
  15. package/out/test/Wallet/StorageClient/storageClient.man.test.d.ts.map +0 -1
  16. package/out/test/Wallet/StorageClient/storageClient.man.test.js +0 -64
  17. package/out/test/Wallet/StorageClient/storageClient.man.test.js.map +0 -1
  18. package/out/test/Wallet/action/internalizeAction.a.test.d.ts +0 -2
  19. package/out/test/Wallet/action/internalizeAction.a.test.d.ts.map +0 -1
  20. package/out/test/Wallet/action/internalizeAction.a.test.js +0 -243
  21. package/out/test/Wallet/action/internalizeAction.a.test.js.map +0 -1
  22. package/out/test/Wallet/certificate/acquireCertificate.test.d.ts +0 -2
  23. package/out/test/Wallet/certificate/acquireCertificate.test.d.ts.map +0 -1
  24. package/out/test/Wallet/certificate/acquireCertificate.test.js +0 -210
  25. package/out/test/Wallet/certificate/acquireCertificate.test.js.map +0 -1
  26. package/out/test/Wallet/certificate/listCertificates.test.d.ts +0 -2
  27. package/out/test/Wallet/certificate/listCertificates.test.d.ts.map +0 -1
  28. package/out/test/Wallet/certificate/listCertificates.test.js +0 -305
  29. package/out/test/Wallet/certificate/listCertificates.test.js.map +0 -1
  30. package/out/test/Wallet/get/getHeaderForHeight.test.d.ts +0 -2
  31. package/out/test/Wallet/get/getHeaderForHeight.test.d.ts.map +0 -1
  32. package/out/test/Wallet/get/getHeaderForHeight.test.js +0 -74
  33. package/out/test/Wallet/get/getHeaderForHeight.test.js.map +0 -1
  34. package/out/test/Wallet/get/getHeight.test.d.ts +0 -2
  35. package/out/test/Wallet/get/getHeight.test.d.ts.map +0 -1
  36. package/out/test/Wallet/get/getHeight.test.js +0 -48
  37. package/out/test/Wallet/get/getHeight.test.js.map +0 -1
  38. package/out/test/Wallet/get/getKnownTxids.test.d.ts +0 -2
  39. package/out/test/Wallet/get/getKnownTxids.test.d.ts.map +0 -1
  40. package/out/test/Wallet/get/getKnownTxids.test.js +0 -73
  41. package/out/test/Wallet/get/getKnownTxids.test.js.map +0 -1
  42. package/out/test/Wallet/get/getNetwork.test.d.ts +0 -2
  43. package/out/test/Wallet/get/getNetwork.test.d.ts.map +0 -1
  44. package/out/test/Wallet/get/getNetwork.test.js +0 -26
  45. package/out/test/Wallet/get/getNetwork.test.js.map +0 -1
  46. package/out/test/Wallet/get/getVersion.test.d.ts +0 -2
  47. package/out/test/Wallet/get/getVersion.test.d.ts.map +0 -1
  48. package/out/test/Wallet/get/getVersion.test.js +0 -25
  49. package/out/test/Wallet/get/getVersion.test.js.map +0 -1
  50. package/out/test/Wallet/live/walletLive.man.test.d.ts +0 -26
  51. package/out/test/Wallet/live/walletLive.man.test.d.ts.map +0 -1
  52. package/out/test/Wallet/live/walletLive.man.test.js +0 -417
  53. package/out/test/Wallet/live/walletLive.man.test.js.map +0 -1
  54. package/out/test/Wallet/local/localWallet.man.test.d.ts +0 -2
  55. package/out/test/Wallet/local/localWallet.man.test.d.ts.map +0 -1
  56. package/out/test/Wallet/local/localWallet.man.test.js +0 -83
  57. package/out/test/Wallet/local/localWallet.man.test.js.map +0 -1
  58. package/out/test/Wallet/local/localWallet2.man.test.d.ts +0 -2
  59. package/out/test/Wallet/local/localWallet2.man.test.d.ts.map +0 -1
  60. package/out/test/Wallet/local/localWallet2.man.test.js +0 -284
  61. package/out/test/Wallet/local/localWallet2.man.test.js.map +0 -1
  62. package/out/test/Wallet/signAction/mountaintop.man.test.d.ts +0 -2
  63. package/out/test/Wallet/signAction/mountaintop.man.test.d.ts.map +0 -1
  64. package/out/test/Wallet/signAction/mountaintop.man.test.js +0 -109
  65. package/out/test/Wallet/signAction/mountaintop.man.test.js.map +0 -1
  66. package/out/test/Wallet/specOps/specOps.man.test.d.ts +0 -2
  67. package/out/test/Wallet/specOps/specOps.man.test.d.ts.map +0 -1
  68. package/out/test/Wallet/specOps/specOps.man.test.js +0 -163
  69. package/out/test/Wallet/specOps/specOps.man.test.js.map +0 -1
  70. package/out/test/Wallet/support/janitor.man.test.d.ts +0 -2
  71. package/out/test/Wallet/support/janitor.man.test.d.ts.map +0 -1
  72. package/out/test/Wallet/support/janitor.man.test.js +0 -38
  73. package/out/test/Wallet/support/janitor.man.test.js.map +0 -1
  74. package/out/test/Wallet/support/operations.man.test.d.ts +0 -2
  75. package/out/test/Wallet/support/operations.man.test.d.ts.map +0 -1
  76. package/out/test/Wallet/support/operations.man.test.js +0 -370
  77. package/out/test/Wallet/support/operations.man.test.js.map +0 -1
  78. package/out/test/Wallet/support/reqErrorReview.2025.05.06.man.test.d.ts +0 -2
  79. package/out/test/Wallet/support/reqErrorReview.2025.05.06.man.test.d.ts.map +0 -1
  80. package/out/test/Wallet/support/reqErrorReview.2025.05.06.man.test.js +0 -385
  81. package/out/test/Wallet/support/reqErrorReview.2025.05.06.man.test.js.map +0 -1
  82. package/out/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.d.ts +0 -2
  83. package/out/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.d.ts.map +0 -1
  84. package/out/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.js +0 -206
  85. package/out/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.js.map +0 -1
  86. package/out/test/Wallet/sync/setActive.test.d.ts +0 -2
  87. package/out/test/Wallet/sync/setActive.test.d.ts.map +0 -1
  88. package/out/test/Wallet/sync/setActive.test.js +0 -161
  89. package/out/test/Wallet/sync/setActive.test.js.map +0 -1
  90. package/out/test/WalletClient/LocalKVStore.man.test.d.ts +0 -2
  91. package/out/test/WalletClient/LocalKVStore.man.test.d.ts.map +0 -1
  92. package/out/test/WalletClient/LocalKVStore.man.test.js +0 -99
  93. package/out/test/WalletClient/LocalKVStore.man.test.js.map +0 -1
  94. package/out/test/WalletClient/WERR.man.test.d.ts +0 -2
  95. package/out/test/WalletClient/WERR.man.test.d.ts.map +0 -1
  96. package/out/test/WalletClient/WERR.man.test.js +0 -34
  97. package/out/test/WalletClient/WERR.man.test.js.map +0 -1
  98. package/out/test/bsv-ts-sdk/LocalKVStore.test.d.ts +0 -2
  99. package/out/test/bsv-ts-sdk/LocalKVStore.test.d.ts.map +0 -1
  100. package/out/test/bsv-ts-sdk/LocalKVStore.test.js +0 -98
  101. package/out/test/bsv-ts-sdk/LocalKVStore.test.js.map +0 -1
  102. package/out/test/checkDB.d.ts +0 -4
  103. package/out/test/checkDB.d.ts.map +0 -1
  104. package/out/test/checkDB.js +0 -55
  105. package/out/test/checkDB.js.map +0 -1
  106. package/out/test/examples/backup.man.test.d.ts +0 -14
  107. package/out/test/examples/backup.man.test.d.ts.map +0 -1
  108. package/out/test/examples/backup.man.test.js +0 -59
  109. package/out/test/examples/backup.man.test.js.map +0 -1
  110. package/out/test/examples/pushdrop.test.d.ts +0 -56
  111. package/out/test/examples/pushdrop.test.d.ts.map +0 -1
  112. package/out/test/examples/pushdrop.test.js +0 -232
  113. package/out/test/examples/pushdrop.test.js.map +0 -1
  114. package/out/test/monitor/Monitor.test.d.ts +0 -2
  115. package/out/test/monitor/Monitor.test.d.ts.map +0 -1
  116. package/out/test/monitor/Monitor.test.js +0 -560
  117. package/out/test/monitor/Monitor.test.js.map +0 -1
  118. package/out/test/services/Services.test.d.ts +0 -2
  119. package/out/test/services/Services.test.d.ts.map +0 -1
  120. package/out/test/services/Services.test.js +0 -246
  121. package/out/test/services/Services.test.js.map +0 -1
  122. package/out/test/storage/KnexMigrations.test.d.ts +0 -2
  123. package/out/test/storage/KnexMigrations.test.d.ts.map +0 -1
  124. package/out/test/storage/KnexMigrations.test.js +0 -81
  125. package/out/test/storage/KnexMigrations.test.js.map +0 -1
  126. package/out/test/storage/StorageMySQLDojoReader.man.test.d.ts +0 -2
  127. package/out/test/storage/StorageMySQLDojoReader.man.test.d.ts.map +0 -1
  128. package/out/test/storage/StorageMySQLDojoReader.man.test.js +0 -86
  129. package/out/test/storage/StorageMySQLDojoReader.man.test.js.map +0 -1
  130. package/out/test/storage/count.test.d.ts +0 -2
  131. package/out/test/storage/count.test.d.ts.map +0 -1
  132. package/out/test/storage/count.test.js +0 -142
  133. package/out/test/storage/count.test.js.map +0 -1
  134. package/out/test/storage/find.test.d.ts +0 -2
  135. package/out/test/storage/find.test.d.ts.map +0 -1
  136. package/out/test/storage/find.test.js +0 -144
  137. package/out/test/storage/find.test.js.map +0 -1
  138. package/out/test/storage/findLegacy.test.d.ts +0 -2
  139. package/out/test/storage/findLegacy.test.d.ts.map +0 -1
  140. package/out/test/storage/findLegacy.test.js +0 -52
  141. package/out/test/storage/findLegacy.test.js.map +0 -1
  142. package/out/test/storage/idb/allocateChange.test.d.ts +0 -2
  143. package/out/test/storage/idb/allocateChange.test.d.ts.map +0 -1
  144. package/out/test/storage/idb/allocateChange.test.js +0 -110
  145. package/out/test/storage/idb/allocateChange.test.js.map +0 -1
  146. package/out/test/storage/idb/count.test.d.ts +0 -2
  147. package/out/test/storage/idb/count.test.d.ts.map +0 -1
  148. package/out/test/storage/idb/count.test.js +0 -129
  149. package/out/test/storage/idb/count.test.js.map +0 -1
  150. package/out/test/storage/idb/find.test.d.ts +0 -2
  151. package/out/test/storage/idb/find.test.d.ts.map +0 -1
  152. package/out/test/storage/idb/find.test.js +0 -131
  153. package/out/test/storage/idb/find.test.js.map +0 -1
  154. package/out/test/storage/idb/idbSpeed.test.d.ts +0 -2
  155. package/out/test/storage/idb/idbSpeed.test.d.ts.map +0 -1
  156. package/out/test/storage/idb/idbSpeed.test.js +0 -30
  157. package/out/test/storage/idb/idbSpeed.test.js.map +0 -1
  158. package/out/test/storage/idb/insert.test.d.ts +0 -2
  159. package/out/test/storage/idb/insert.test.d.ts.map +0 -1
  160. package/out/test/storage/idb/insert.test.js +0 -242
  161. package/out/test/storage/idb/insert.test.js.map +0 -1
  162. package/out/test/storage/idb/transactionAbort.test.d.ts +0 -2
  163. package/out/test/storage/idb/transactionAbort.test.d.ts.map +0 -1
  164. package/out/test/storage/idb/transactionAbort.test.js +0 -97
  165. package/out/test/storage/idb/transactionAbort.test.js.map +0 -1
  166. package/out/test/storage/idb/update.test.d.ts +0 -2
  167. package/out/test/storage/idb/update.test.d.ts.map +0 -1
  168. package/out/test/storage/idb/update.test.js +0 -902
  169. package/out/test/storage/idb/update.test.js.map +0 -1
  170. package/out/test/storage/insert.test.d.ts +0 -2
  171. package/out/test/storage/insert.test.d.ts.map +0 -1
  172. package/out/test/storage/insert.test.js +0 -256
  173. package/out/test/storage/insert.test.js.map +0 -1
  174. package/out/test/storage/update.test.d.ts +0 -2
  175. package/out/test/storage/update.test.d.ts.map +0 -1
  176. package/out/test/storage/update.test.js +0 -919
  177. package/out/test/storage/update.test.js.map +0 -1
  178. package/out/test/storage/update2.test.d.ts +0 -2
  179. package/out/test/storage/update2.test.d.ts.map +0 -1
  180. package/out/test/storage/update2.test.js +0 -767
  181. package/out/test/storage/update2.test.js.map +0 -1
  182. package/out/test/utils/TestUtilsWalletStorage.d.ts +0 -523
  183. package/out/test/utils/TestUtilsWalletStorage.d.ts.map +0 -1
  184. package/out/test/utils/TestUtilsWalletStorage.js +0 -1958
  185. package/out/test/utils/TestUtilsWalletStorage.js.map +0 -1
  186. package/out/test/utils/localWalletMethods.d.ts +0 -33
  187. package/out/test/utils/localWalletMethods.d.ts.map +0 -1
  188. package/out/test/utils/localWalletMethods.js +0 -304
  189. package/out/test/utils/localWalletMethods.js.map +0 -1
  190. package/out/test/wallet/action/abortAction.test.d.ts +0 -2
  191. package/out/test/wallet/action/abortAction.test.d.ts.map +0 -1
  192. package/out/test/wallet/action/abortAction.test.js +0 -44
  193. package/out/test/wallet/action/abortAction.test.js.map +0 -1
  194. package/out/test/wallet/action/createAction.test.d.ts +0 -2
  195. package/out/test/wallet/action/createAction.test.d.ts.map +0 -1
  196. package/out/test/wallet/action/createAction.test.js +0 -272
  197. package/out/test/wallet/action/createAction.test.js.map +0 -1
  198. package/out/test/wallet/action/createAction2.test.d.ts +0 -37
  199. package/out/test/wallet/action/createAction2.test.d.ts.map +0 -1
  200. package/out/test/wallet/action/createAction2.test.js +0 -1143
  201. package/out/test/wallet/action/createAction2.test.js.map +0 -1
  202. package/out/test/wallet/action/createActionToGenerateBeefs.man.test.d.ts +0 -2
  203. package/out/test/wallet/action/createActionToGenerateBeefs.man.test.d.ts.map +0 -1
  204. package/out/test/wallet/action/createActionToGenerateBeefs.man.test.js +0 -273
  205. package/out/test/wallet/action/createActionToGenerateBeefs.man.test.js.map +0 -1
  206. package/out/test/wallet/action/internalizeAction.test.d.ts +0 -2
  207. package/out/test/wallet/action/internalizeAction.test.d.ts.map +0 -1
  208. package/out/test/wallet/action/internalizeAction.test.js +0 -608
  209. package/out/test/wallet/action/internalizeAction.test.js.map +0 -1
  210. package/out/test/wallet/action/relinquishOutput.test.d.ts +0 -2
  211. package/out/test/wallet/action/relinquishOutput.test.d.ts.map +0 -1
  212. package/out/test/wallet/action/relinquishOutput.test.js +0 -31
  213. package/out/test/wallet/action/relinquishOutput.test.js.map +0 -1
  214. package/out/test/wallet/construct/Wallet.constructor.test.d.ts +0 -2
  215. package/out/test/wallet/construct/Wallet.constructor.test.d.ts.map +0 -1
  216. package/out/test/wallet/construct/Wallet.constructor.test.js +0 -49
  217. package/out/test/wallet/construct/Wallet.constructor.test.js.map +0 -1
  218. package/out/test/wallet/list/listActions.test.d.ts +0 -2
  219. package/out/test/wallet/list/listActions.test.d.ts.map +0 -1
  220. package/out/test/wallet/list/listActions.test.js +0 -271
  221. package/out/test/wallet/list/listActions.test.js.map +0 -1
  222. package/out/test/wallet/list/listActions2.test.d.ts +0 -2
  223. package/out/test/wallet/list/listActions2.test.d.ts.map +0 -1
  224. package/out/test/wallet/list/listActions2.test.js +0 -1141
  225. package/out/test/wallet/list/listActions2.test.js.map +0 -1
  226. package/out/test/wallet/list/listCertificates.test.d.ts +0 -2
  227. package/out/test/wallet/list/listCertificates.test.d.ts.map +0 -1
  228. package/out/test/wallet/list/listCertificates.test.js +0 -111
  229. package/out/test/wallet/list/listCertificates.test.js.map +0 -1
  230. package/out/test/wallet/list/listOutputs.test.d.ts +0 -2
  231. package/out/test/wallet/list/listOutputs.test.d.ts.map +0 -1
  232. package/out/test/wallet/list/listOutputs.test.js +0 -424
  233. package/out/test/wallet/list/listOutputs.test.js.map +0 -1
  234. package/out/test/wallet/sync/Wallet.sync.test.d.ts +0 -2
  235. package/out/test/wallet/sync/Wallet.sync.test.d.ts.map +0 -1
  236. package/out/test/wallet/sync/Wallet.sync.test.js +0 -155
  237. package/out/test/wallet/sync/Wallet.sync.test.js.map +0 -1
  238. package/out/tsconfig.all.tsbuildinfo +0 -1
  239. package/src/CWIStyleWalletManager.ts +0 -1999
  240. package/src/Setup.ts +0 -579
  241. package/src/SetupClient.ts +0 -322
  242. package/src/SetupWallet.ts +0 -108
  243. package/src/SimpleWalletManager.ts +0 -526
  244. package/src/Wallet.ts +0 -1169
  245. package/src/WalletAuthenticationManager.ts +0 -153
  246. package/src/WalletLogger.ts +0 -213
  247. package/src/WalletPermissionsManager.ts +0 -3660
  248. package/src/WalletSettingsManager.ts +0 -114
  249. package/src/__tests/CWIStyleWalletManager.test.d.ts.map +0 -1
  250. package/src/__tests/CWIStyleWalletManager.test.js.map +0 -1
  251. package/src/__tests/CWIStyleWalletManager.test.ts +0 -675
  252. package/src/__tests/WalletPermissionsManager.callbacks.test.ts +0 -323
  253. package/src/__tests/WalletPermissionsManager.checks.test.ts +0 -844
  254. package/src/__tests/WalletPermissionsManager.encryption.test.ts +0 -412
  255. package/src/__tests/WalletPermissionsManager.fixtures.ts +0 -307
  256. package/src/__tests/WalletPermissionsManager.flows.test.ts +0 -462
  257. package/src/__tests/WalletPermissionsManager.initialization.test.ts +0 -300
  258. package/src/__tests/WalletPermissionsManager.pmodules.test.ts +0 -798
  259. package/src/__tests/WalletPermissionsManager.proxying.test.ts +0 -724
  260. package/src/__tests/WalletPermissionsManager.tokens.test.ts +0 -503
  261. package/src/index.all.ts +0 -27
  262. package/src/index.client.ts +0 -25
  263. package/src/index.mobile.ts +0 -21
  264. package/src/index.ts +0 -1
  265. package/src/monitor/Monitor.ts +0 -412
  266. package/src/monitor/MonitorDaemon.ts +0 -188
  267. package/src/monitor/README.md +0 -3
  268. package/src/monitor/__test/MonitorDaemon.man.test.ts +0 -45
  269. package/src/monitor/tasks/TaskCheckForProofs.ts +0 -243
  270. package/src/monitor/tasks/TaskCheckNoSends.ts +0 -73
  271. package/src/monitor/tasks/TaskClock.ts +0 -33
  272. package/src/monitor/tasks/TaskFailAbandoned.ts +0 -54
  273. package/src/monitor/tasks/TaskMonitorCallHistory.ts +0 -26
  274. package/src/monitor/tasks/TaskNewHeader.ts +0 -93
  275. package/src/monitor/tasks/TaskPurge.ts +0 -68
  276. package/src/monitor/tasks/TaskReorg.ts +0 -89
  277. package/src/monitor/tasks/TaskReviewStatus.ts +0 -48
  278. package/src/monitor/tasks/TaskSendWaiting.ts +0 -122
  279. package/src/monitor/tasks/TaskSyncWhenIdle.ts +0 -26
  280. package/src/monitor/tasks/TaskUnFail.ts +0 -151
  281. package/src/monitor/tasks/WalletMonitorTask.ts +0 -47
  282. package/src/sdk/CertOpsWallet.ts +0 -18
  283. package/src/sdk/PrivilegedKeyManager.ts +0 -372
  284. package/src/sdk/README.md +0 -13
  285. package/src/sdk/WERR_errors.ts +0 -234
  286. package/src/sdk/WalletError.ts +0 -170
  287. package/src/sdk/WalletErrorFromJson.ts +0 -80
  288. package/src/sdk/WalletServices.interfaces.ts +0 -700
  289. package/src/sdk/WalletSigner.interfaces.ts +0 -11
  290. package/src/sdk/WalletStorage.interfaces.ts +0 -606
  291. package/src/sdk/__test/CertificateLifeCycle.test.ts +0 -131
  292. package/src/sdk/__test/PrivilegedKeyManager.test.ts +0 -738
  293. package/src/sdk/__test/WalletError.test.ts +0 -318
  294. package/src/sdk/__test/validationHelpers.test.ts +0 -21
  295. package/src/sdk/index.ts +0 -10
  296. package/src/sdk/types.ts +0 -226
  297. package/src/services/README.md +0 -11
  298. package/src/services/ServiceCollection.ts +0 -248
  299. package/src/services/Services.ts +0 -603
  300. package/src/services/__tests/ARC.man.test.ts +0 -123
  301. package/src/services/__tests/ARC.timeout.man.test.ts +0 -79
  302. package/src/services/__tests/ArcGorillaPool.man.test.ts +0 -108
  303. package/src/services/__tests/arcServices.test.ts +0 -8
  304. package/src/services/__tests/bitrails.test.ts +0 -56
  305. package/src/services/__tests/getMerklePath.test.ts +0 -15
  306. package/src/services/__tests/getRawTx.test.ts +0 -13
  307. package/src/services/__tests/postBeef.test.ts +0 -104
  308. package/src/services/__tests/verifyBeef.test.ts +0 -50
  309. package/src/services/chaintracker/BHServiceClient.ts +0 -212
  310. package/src/services/chaintracker/ChaintracksChainTracker.ts +0 -71
  311. package/src/services/chaintracker/__tests/ChaintracksChainTracker.test.ts +0 -33
  312. package/src/services/chaintracker/__tests/ChaintracksServiceClient.test.ts +0 -29
  313. package/src/services/chaintracker/chaintracks/Api/BlockHeaderApi.ts +0 -72
  314. package/src/services/chaintracker/chaintracks/Api/BulkIngestorApi.ts +0 -83
  315. package/src/services/chaintracker/chaintracks/Api/BulkStorageApi.ts +0 -92
  316. package/src/services/chaintracker/chaintracks/Api/ChaintracksApi.ts +0 -64
  317. package/src/services/chaintracker/chaintracks/Api/ChaintracksClientApi.ts +0 -189
  318. package/src/services/chaintracker/chaintracks/Api/ChaintracksFetchApi.ts +0 -18
  319. package/src/services/chaintracker/chaintracks/Api/ChaintracksFsApi.ts +0 -58
  320. package/src/services/chaintracker/chaintracks/Api/ChaintracksStorageApi.ts +0 -386
  321. package/src/services/chaintracker/chaintracks/Api/LiveIngestorApi.ts +0 -25
  322. package/src/services/chaintracker/chaintracks/Chaintracks.ts +0 -609
  323. package/src/services/chaintracker/chaintracks/ChaintracksService.ts +0 -199
  324. package/src/services/chaintracker/chaintracks/ChaintracksServiceClient.ts +0 -154
  325. package/src/services/chaintracker/chaintracks/Ingest/BulkIngestorBase.ts +0 -176
  326. package/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.ts +0 -174
  327. package/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDNBabbage.ts +0 -18
  328. package/src/services/chaintracker/chaintracks/Ingest/BulkIngestorWhatsOnChainCdn.ts +0 -113
  329. package/src/services/chaintracker/chaintracks/Ingest/BulkIngestorWhatsOnChainWs.ts +0 -81
  330. package/src/services/chaintracker/chaintracks/Ingest/LiveIngestorBase.ts +0 -86
  331. package/src/services/chaintracker/chaintracks/Ingest/LiveIngestorTeranodeP2P.ts +0 -59
  332. package/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.ts +0 -104
  333. package/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainWs.ts +0 -66
  334. package/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainIngestorWs.ts +0 -566
  335. package/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.ts +0 -219
  336. package/src/services/chaintracker/chaintracks/Ingest/__tests/BulkIngestorCDNBabbage.test.ts +0 -54
  337. package/src/services/chaintracker/chaintracks/Ingest/__tests/LiveIngestorWhatsOnChainPoll.test.ts +0 -33
  338. package/src/services/chaintracker/chaintracks/Ingest/__tests/WhatsOnChainServices.test.ts +0 -124
  339. package/src/services/chaintracker/chaintracks/Storage/BulkStorageBase.ts +0 -92
  340. package/src/services/chaintracker/chaintracks/Storage/ChaintracksKnexMigrations.ts +0 -104
  341. package/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageBase.ts +0 -382
  342. package/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageIdb.ts +0 -574
  343. package/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageKnex.ts +0 -438
  344. package/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageMemory.ts +0 -29
  345. package/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageNoDb.ts +0 -304
  346. package/src/services/chaintracker/chaintracks/Storage/__tests/ChaintracksStorageIdb.test.ts +0 -102
  347. package/src/services/chaintracker/chaintracks/Storage/__tests/ChaintracksStorageKnex.test.ts +0 -45
  348. package/src/services/chaintracker/chaintracks/__tests/Chaintracks.test.ts +0 -77
  349. package/src/services/chaintracker/chaintracks/__tests/ChaintracksClientApi.test.ts +0 -192
  350. package/src/services/chaintracker/chaintracks/__tests/LocalCdnServer.ts +0 -75
  351. package/src/services/chaintracker/chaintracks/__tests/createIdbChaintracks.test.ts +0 -62
  352. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest349/mainNetBlockHeaders.json +0 -1
  353. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest349/mainNet_0.headers +0 -0
  354. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest349/mainNet_1.headers +0 -0
  355. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest349/mainNet_2.headers +0 -0
  356. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest349/mainNet_3.headers +0 -0
  357. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest379/mainNetBlockHeaders.json +0 -1
  358. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest379/mainNet_0.headers +0 -0
  359. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest379/mainNet_1.headers +0 -0
  360. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest379/mainNet_2.headers +0 -0
  361. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest379/mainNet_3.headers +0 -0
  362. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest399/mainNetBlockHeaders.json +0 -1
  363. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest399/mainNet_0.headers +0 -0
  364. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest399/mainNet_1.headers +0 -0
  365. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest399/mainNet_2.headers +0 -0
  366. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest399/mainNet_3.headers +0 -0
  367. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNetBlockHeaders.json +0 -1
  368. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNet_0.headers +0 -0
  369. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNet_1.headers +0 -0
  370. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNet_2.headers +0 -0
  371. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNet_3.headers +0 -0
  372. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNet_4.headers +0 -0
  373. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNetBlockHeaders.json +0 -1
  374. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNet_0.headers +0 -0
  375. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNet_1.headers +0 -0
  376. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNet_2.headers +0 -0
  377. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNet_3.headers +0 -0
  378. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNet_4.headers +0 -0
  379. package/src/services/chaintracker/chaintracks/createDefaultIdbChaintracksOptions.ts +0 -92
  380. package/src/services/chaintracker/chaintracks/createDefaultKnexChaintracksOptions.ts +0 -111
  381. package/src/services/chaintracker/chaintracks/createDefaultNoDbChaintracksOptions.ts +0 -91
  382. package/src/services/chaintracker/chaintracks/createIdbChaintracks.ts +0 -60
  383. package/src/services/chaintracker/chaintracks/createKnexChaintracks.ts +0 -65
  384. package/src/services/chaintracker/chaintracks/createNoDbChaintracks.ts +0 -60
  385. package/src/services/chaintracker/chaintracks/index.all.ts +0 -12
  386. package/src/services/chaintracker/chaintracks/index.client.ts +0 -4
  387. package/src/services/chaintracker/chaintracks/index.mobile.ts +0 -37
  388. package/src/services/chaintracker/chaintracks/util/BulkFileDataManager.ts +0 -975
  389. package/src/services/chaintracker/chaintracks/util/BulkFileDataReader.ts +0 -60
  390. package/src/services/chaintracker/chaintracks/util/BulkFilesReader.ts +0 -336
  391. package/src/services/chaintracker/chaintracks/util/BulkHeaderFile.ts +0 -247
  392. package/src/services/chaintracker/chaintracks/util/ChaintracksFetch.ts +0 -69
  393. package/src/services/chaintracker/chaintracks/util/ChaintracksFs.ts +0 -141
  394. package/src/services/chaintracker/chaintracks/util/HeightRange.ts +0 -153
  395. package/src/services/chaintracker/chaintracks/util/SingleWriterMultiReaderLock.ts +0 -76
  396. package/src/services/chaintracker/chaintracks/util/__tests/BulkFileDataManager.test.ts +0 -304
  397. package/src/services/chaintracker/chaintracks/util/__tests/ChaintracksFetch.test.ts +0 -60
  398. package/src/services/chaintracker/chaintracks/util/__tests/HeightRange.test.ts +0 -67
  399. package/src/services/chaintracker/chaintracks/util/__tests/SingleWriterMultiReaderLock.test.ts +0 -49
  400. package/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.ts +0 -573
  401. package/src/services/chaintracker/chaintracks/util/dirtyHashes.ts +0 -29
  402. package/src/services/chaintracker/chaintracks/util/validBulkHeaderFilesByFileHash.ts +0 -432
  403. package/src/services/chaintracker/index.all.ts +0 -4
  404. package/src/services/chaintracker/index.client.ts +0 -4
  405. package/src/services/chaintracker/index.mobile.ts +0 -4
  406. package/src/services/createDefaultWalletServicesOptions.ts +0 -77
  407. package/src/services/index.ts +0 -1
  408. package/src/services/processingErrors/arcSuccessError.json +0 -76
  409. package/src/services/providers/ARC.ts +0 -350
  410. package/src/services/providers/Bitails.ts +0 -256
  411. package/src/services/providers/SdkWhatsOnChain.ts +0 -83
  412. package/src/services/providers/WhatsOnChain.ts +0 -883
  413. package/src/services/providers/__tests/WhatsOnChain.test.ts +0 -242
  414. package/src/services/providers/__tests/exchangeRates.test.ts +0 -18
  415. package/src/services/providers/exchangeRates.ts +0 -265
  416. package/src/services/providers/getBeefForTxid.ts +0 -369
  417. package/src/signer/README.md +0 -5
  418. package/src/signer/WalletSigner.ts +0 -17
  419. package/src/signer/methods/acquireDirectCertificate.ts +0 -52
  420. package/src/signer/methods/buildSignableTransaction.ts +0 -183
  421. package/src/signer/methods/completeSignedTransaction.ts +0 -117
  422. package/src/signer/methods/createAction.ts +0 -172
  423. package/src/signer/methods/internalizeAction.ts +0 -106
  424. package/src/signer/methods/proveCertificate.ts +0 -43
  425. package/src/signer/methods/signAction.ts +0 -54
  426. package/src/storage/README.md +0 -14
  427. package/src/storage/StorageIdb.ts +0 -2304
  428. package/src/storage/StorageKnex.ts +0 -1425
  429. package/src/storage/StorageProvider.ts +0 -810
  430. package/src/storage/StorageReader.ts +0 -194
  431. package/src/storage/StorageReaderWriter.ts +0 -432
  432. package/src/storage/StorageSyncReader.ts +0 -34
  433. package/src/storage/WalletStorageManager.ts +0 -943
  434. package/src/storage/__test/StorageIdb.test.ts +0 -43
  435. package/src/storage/__test/WalletStorageManager.test.ts +0 -275
  436. package/src/storage/__test/adminStats.man.test.ts +0 -89
  437. package/src/storage/__test/getBeefForTransaction.test.ts +0 -385
  438. package/src/storage/index.all.ts +0 -11
  439. package/src/storage/index.client.ts +0 -7
  440. package/src/storage/index.mobile.ts +0 -6
  441. package/src/storage/methods/ListActionsSpecOp.ts +0 -70
  442. package/src/storage/methods/ListOutputsSpecOp.ts +0 -129
  443. package/src/storage/methods/__test/GenerateChange/generateChangeSdk.test.ts +0 -1057
  444. package/src/storage/methods/__test/GenerateChange/randomValsUsed1.ts +0 -20
  445. package/src/storage/methods/__test/offsetKey.test.ts +0 -274
  446. package/src/storage/methods/attemptToPostReqsToNetwork.ts +0 -389
  447. package/src/storage/methods/createAction.ts +0 -947
  448. package/src/storage/methods/generateChange.ts +0 -556
  449. package/src/storage/methods/getBeefForTransaction.ts +0 -139
  450. package/src/storage/methods/getSyncChunk.ts +0 -293
  451. package/src/storage/methods/internalizeAction.ts +0 -562
  452. package/src/storage/methods/listActionsIdb.ts +0 -183
  453. package/src/storage/methods/listActionsKnex.ts +0 -226
  454. package/src/storage/methods/listCertificates.ts +0 -73
  455. package/src/storage/methods/listOutputsIdb.ts +0 -203
  456. package/src/storage/methods/listOutputsKnex.ts +0 -263
  457. package/src/storage/methods/offsetKey.ts +0 -89
  458. package/src/storage/methods/processAction.ts +0 -420
  459. package/src/storage/methods/purgeData.ts +0 -251
  460. package/src/storage/methods/purgeDataIdb.ts +0 -10
  461. package/src/storage/methods/reviewStatus.ts +0 -101
  462. package/src/storage/methods/reviewStatusIdb.ts +0 -43
  463. package/src/storage/methods/utils.Buffer.ts +0 -33
  464. package/src/storage/methods/utils.ts +0 -56
  465. package/src/storage/remoting/StorageClient.ts +0 -567
  466. package/src/storage/remoting/StorageMobile.ts +0 -544
  467. package/src/storage/remoting/StorageServer.ts +0 -291
  468. package/src/storage/remoting/__test/StorageClient.test.ts +0 -113
  469. package/src/storage/schema/KnexMigrations.ts +0 -489
  470. package/src/storage/schema/StorageIdbSchema.ts +0 -150
  471. package/src/storage/schema/entities/EntityBase.ts +0 -210
  472. package/src/storage/schema/entities/EntityCertificate.ts +0 -188
  473. package/src/storage/schema/entities/EntityCertificateField.ts +0 -136
  474. package/src/storage/schema/entities/EntityCommission.ts +0 -148
  475. package/src/storage/schema/entities/EntityOutput.ts +0 -290
  476. package/src/storage/schema/entities/EntityOutputBasket.ts +0 -153
  477. package/src/storage/schema/entities/EntityOutputTag.ts +0 -121
  478. package/src/storage/schema/entities/EntityOutputTagMap.ts +0 -123
  479. package/src/storage/schema/entities/EntityProvenTx.ts +0 -319
  480. package/src/storage/schema/entities/EntityProvenTxReq.ts +0 -580
  481. package/src/storage/schema/entities/EntitySyncState.ts +0 -389
  482. package/src/storage/schema/entities/EntityTransaction.ts +0 -306
  483. package/src/storage/schema/entities/EntityTxLabel.ts +0 -121
  484. package/src/storage/schema/entities/EntityTxLabelMap.ts +0 -123
  485. package/src/storage/schema/entities/EntityUser.ts +0 -112
  486. package/src/storage/schema/entities/MergeEntity.ts +0 -73
  487. package/src/storage/schema/entities/__tests/CertificateFieldTests.test.ts +0 -353
  488. package/src/storage/schema/entities/__tests/CertificateTests.test.ts +0 -354
  489. package/src/storage/schema/entities/__tests/CommissionTests.test.ts +0 -371
  490. package/src/storage/schema/entities/__tests/OutputBasketTests.test.ts +0 -278
  491. package/src/storage/schema/entities/__tests/OutputTagMapTests.test.ts +0 -242
  492. package/src/storage/schema/entities/__tests/OutputTagTests.test.ts +0 -288
  493. package/src/storage/schema/entities/__tests/OutputTests.test.ts +0 -464
  494. package/src/storage/schema/entities/__tests/ProvenTxReqTests.test.ts +0 -340
  495. package/src/storage/schema/entities/__tests/ProvenTxTests.test.ts +0 -504
  496. package/src/storage/schema/entities/__tests/SyncStateTests.test.ts +0 -288
  497. package/src/storage/schema/entities/__tests/TransactionTests.test.ts +0 -604
  498. package/src/storage/schema/entities/__tests/TxLabelMapTests.test.ts +0 -361
  499. package/src/storage/schema/entities/__tests/TxLabelTests.test.ts +0 -198
  500. package/src/storage/schema/entities/__tests/stampLogTests.test.ts +0 -90
  501. package/src/storage/schema/entities/__tests/usersTests.test.ts +0 -340
  502. package/src/storage/schema/entities/index.ts +0 -16
  503. package/src/storage/schema/tables/TableCertificate.ts +0 -21
  504. package/src/storage/schema/tables/TableCertificateField.ts +0 -12
  505. package/src/storage/schema/tables/TableCommission.ts +0 -13
  506. package/src/storage/schema/tables/TableMonitorEvent.ts +0 -9
  507. package/src/storage/schema/tables/TableOutput.ts +0 -64
  508. package/src/storage/schema/tables/TableOutputBasket.ts +0 -12
  509. package/src/storage/schema/tables/TableOutputTag.ts +0 -10
  510. package/src/storage/schema/tables/TableOutputTagMap.ts +0 -9
  511. package/src/storage/schema/tables/TableProvenTx.ts +0 -14
  512. package/src/storage/schema/tables/TableProvenTxReq.ts +0 -65
  513. package/src/storage/schema/tables/TableSettings.ts +0 -17
  514. package/src/storage/schema/tables/TableSyncState.ts +0 -18
  515. package/src/storage/schema/tables/TableTransaction.ts +0 -54
  516. package/src/storage/schema/tables/TableTxLabel.ts +0 -10
  517. package/src/storage/schema/tables/TableTxLabelMap.ts +0 -9
  518. package/src/storage/schema/tables/TableUser.ts +0 -16
  519. package/src/storage/schema/tables/index.ts +0 -16
  520. package/src/storage/sync/StorageMySQLDojoReader.ts +0 -696
  521. package/src/storage/sync/index.ts +0 -1
  522. package/src/utility/Format.ts +0 -133
  523. package/src/utility/README.md +0 -3
  524. package/src/utility/ReaderUint8Array.ts +0 -187
  525. package/src/utility/ScriptTemplateBRC29.ts +0 -73
  526. package/src/utility/__tests/utilityHelpers.noBuffer.test.ts +0 -109
  527. package/src/utility/aggregateResults.ts +0 -68
  528. package/src/utility/identityUtils.ts +0 -159
  529. package/src/utility/index.all.ts +0 -7
  530. package/src/utility/index.client.ts +0 -7
  531. package/src/utility/parseTxScriptOffsets.ts +0 -29
  532. package/src/utility/stampLog.ts +0 -69
  533. package/src/utility/tscProofToMerklePath.ts +0 -48
  534. package/src/utility/utilityHelpers.buffer.ts +0 -34
  535. package/src/utility/utilityHelpers.noBuffer.ts +0 -60
  536. package/src/utility/utilityHelpers.ts +0 -275
  537. package/src/wab-client/WABClient.ts +0 -94
  538. package/src/wab-client/__tests/WABClient.man.test.ts +0 -59
  539. package/src/wab-client/auth-method-interactors/AuthMethodInteractor.ts +0 -47
  540. package/src/wab-client/auth-method-interactors/DevConsoleInteractor.ts +0 -73
  541. package/src/wab-client/auth-method-interactors/PersonaIDInteractor.ts +0 -35
  542. package/src/wab-client/auth-method-interactors/TwilioPhoneInteractor.ts +0 -72
  543. package/syncVersions.js +0 -71
  544. package/test/Wallet/StorageClient/storageClient.man.test.ts +0 -75
  545. package/test/Wallet/action/internalizeAction.a.test.ts +0 -286
  546. package/test/Wallet/certificate/acquireCertificate.test.ts +0 -298
  547. package/test/Wallet/certificate/listCertificates.test.ts +0 -346
  548. package/test/Wallet/get/getHeaderForHeight.test.ts +0 -82
  549. package/test/Wallet/get/getHeight.test.ts +0 -52
  550. package/test/Wallet/get/getKnownTxids.test.ts +0 -86
  551. package/test/Wallet/get/getNetwork.test.ts +0 -27
  552. package/test/Wallet/get/getVersion.test.ts +0 -27
  553. package/test/Wallet/live/walletLive.man.test.ts +0 -521
  554. package/test/Wallet/local/localWallet.man.test.ts +0 -93
  555. package/test/Wallet/local/localWallet2.man.test.ts +0 -277
  556. package/test/Wallet/signAction/mountaintop.man.test.ts +0 -130
  557. package/test/Wallet/specOps/specOps.man.test.ts +0 -220
  558. package/test/Wallet/support/janitor.man.test.ts +0 -40
  559. package/test/Wallet/support/operations.man.test.ts +0 -407
  560. package/test/Wallet/support/reqErrorReview.2025.05.06.man.test.ts +0 -347
  561. package/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.ts +0 -203
  562. package/test/Wallet/sync/setActive.test.ts +0 -170
  563. package/test/WalletClient/LocalKVStore.man.test.ts +0 -114
  564. package/test/WalletClient/WERR.man.test.ts +0 -35
  565. package/test/bsv-ts-sdk/LocalKVStore.test.ts +0 -102
  566. package/test/checkDB.ts +0 -57
  567. package/test/checkdb +0 -0
  568. package/test/examples/backup.man.test.ts +0 -59
  569. package/test/examples/pushdrop.test.ts +0 -282
  570. package/test/monitor/Monitor.test.ts +0 -620
  571. package/test/services/Services.test.ts +0 -263
  572. package/test/storage/KnexMigrations.test.ts +0 -86
  573. package/test/storage/StorageMySQLDojoReader.man.test.ts +0 -60
  574. package/test/storage/count.test.ts +0 -177
  575. package/test/storage/find.test.ts +0 -195
  576. package/test/storage/findLegacy.test.ts +0 -67
  577. package/test/storage/idb/allocateChange.test.ts +0 -251
  578. package/test/storage/idb/count.test.ts +0 -158
  579. package/test/storage/idb/find.test.ts +0 -177
  580. package/test/storage/idb/idbSpeed.test.ts +0 -36
  581. package/test/storage/idb/insert.test.ts +0 -268
  582. package/test/storage/idb/transactionAbort.test.ts +0 -108
  583. package/test/storage/idb/update.test.ts +0 -999
  584. package/test/storage/insert.test.ts +0 -278
  585. package/test/storage/update.test.ts +0 -1021
  586. package/test/storage/update2.test.ts +0 -897
  587. package/test/utils/TestUtilsWalletStorage.ts +0 -2526
  588. package/test/utils/localWalletMethods.ts +0 -363
  589. package/test/utils/removeFailedFromDatabase.sql +0 -17
  590. package/test/wallet/action/abortAction.test.ts +0 -47
  591. package/test/wallet/action/createAction.test.ts +0 -299
  592. package/test/wallet/action/createAction2.test.ts +0 -1273
  593. package/test/wallet/action/createActionToGenerateBeefs.man.test.ts +0 -293
  594. package/test/wallet/action/internalizeAction.test.ts +0 -682
  595. package/test/wallet/action/relinquishOutput.test.ts +0 -37
  596. package/test/wallet/construct/Wallet.constructor.test.ts +0 -57
  597. package/test/wallet/list/listActions.test.ts +0 -279
  598. package/test/wallet/list/listActions2.test.ts +0 -1381
  599. package/test/wallet/list/listCertificates.test.ts +0 -118
  600. package/test/wallet/list/listOutputs.test.ts +0 -447
  601. package/test/wallet/sync/Wallet.sync.test.ts +0 -215
  602. package/ts2md.json +0 -44
  603. package/tsconfig.all.json +0 -31
  604. package/tsconfig.client.json +0 -29
  605. package/tsconfig.json +0 -17
  606. package/tsconfig.mobile.json +0 -28
@@ -1,943 +0,0 @@
1
- import {
2
- AbortActionArgs,
3
- AbortActionResult,
4
- Beef,
5
- InternalizeActionArgs,
6
- ListActionsResult,
7
- ListCertificatesResult,
8
- ListOutputsResult,
9
- RelinquishCertificateArgs,
10
- RelinquishOutputArgs,
11
- Validation
12
- } from '@bsv/sdk'
13
- import { EntitySyncState } from '../storage/schema/entities'
14
- import * as sdk from '../sdk'
15
- import {
16
- TableCertificate,
17
- TableCertificateX,
18
- TableOutput,
19
- TableOutputBasket,
20
- TableProvenTx,
21
- TableProvenTxReq,
22
- TableSettings,
23
- TableUser
24
- } from '../storage/schema/tables'
25
- import { StorageProvider } from './StorageProvider'
26
- import { StorageClient } from './remoting/StorageClient'
27
-
28
- class ManagedStorage {
29
- isAvailable: boolean
30
- isStorageProvider: boolean
31
- settings?: TableSettings
32
- user?: TableUser
33
-
34
- constructor(public storage: sdk.WalletStorageProvider) {
35
- this.isStorageProvider = storage.isStorageProvider()
36
- this.isAvailable = false
37
- }
38
- }
39
-
40
- /**
41
- * The `WalletStorageManager` class delivers authentication checking storage access to the wallet.
42
- *
43
- * If manages multiple `StorageBase` derived storage services: one actice, the rest as backups.
44
- *
45
- * Of the storage services, one is 'active' at any one time.
46
- * On startup, and whenever triggered by the wallet, `WalletStorageManager` runs a syncrhonization sequence:
47
- *
48
- * 1. While synchronizing, all other access to storage is blocked waiting.
49
- * 2. The active service is confirmed, potentially triggering a resolution process if there is disagreement.
50
- * 3. Changes are pushed from the active storage service to each inactive, backup service.
51
- *
52
- * Some storage services do not support multiple writers. `WalletStorageManager` manages wait-blocking write requests
53
- * for these services.
54
- */
55
- export class WalletStorageManager implements sdk.WalletStorage {
56
- /**
57
- * All configured stores including current active, backups, and conflicting actives.
58
- */
59
- _stores: ManagedStorage[] = []
60
- /**
61
- * True if makeAvailable has been run and access to managed stores (active) is allowed
62
- */
63
- _isAvailable: boolean = false
64
- /**
65
- * The current active store which is only enabled if the store's user record activeStorage property matches its settings record storageIdentityKey property
66
- */
67
- _active?: ManagedStorage
68
- /**
69
- * Stores to which state is pushed by updateBackups.
70
- */
71
- _backups?: ManagedStorage[]
72
- /**
73
- * Stores whose user record activeStorage property disagrees with the active store's user record activeStorage property.
74
- */
75
- _conflictingActives?: ManagedStorage[]
76
- /**
77
- * identityKey is always valid, userId and isActive are valid only if _isAvailable
78
- */
79
- _authId: sdk.AuthId
80
- /**
81
- * Configured services if any. If valid, shared with stores (which may ignore it).
82
- */
83
- _services?: sdk.WalletServices
84
-
85
- /**
86
- * Creates a new WalletStorageManager with the given identityKey and optional active and backup storage providers.
87
- *
88
- * @param identityKey The identity key of the user for whom this wallet is being managed.
89
- * @param active An optional active storage provider. If not provided, no active storage will be set.
90
- * @param backups An optional array of backup storage providers. If not provided, no backups will be set.
91
- */
92
- constructor(identityKey: string, active?: sdk.WalletStorageProvider, backups?: sdk.WalletStorageProvider[]) {
93
- const stores = [...(backups || [])]
94
- if (active) stores.unshift(active)
95
- this._stores = stores.map(s => new ManagedStorage(s))
96
- this._authId = { identityKey }
97
- }
98
-
99
- isStorageProvider(): boolean {
100
- return false
101
- }
102
-
103
- isAvailable(): boolean {
104
- return this._isAvailable
105
- }
106
-
107
- /**
108
- * The active storage is "enabled" only if its `storageIdentityKey` matches the user's currently selected `activeStorage`,
109
- * and only if there are no stores with conflicting `activeStorage` selections.
110
- *
111
- * A wallet may be created without including the user's currently selected active storage. This allows readonly access to their wallet data.
112
- *
113
- * In addition, if there are conflicting `activeStorage` selections among backup storage providers then the active remains disabled.
114
- */
115
- get isActiveEnabled(): boolean {
116
- return (
117
- this._active !== undefined &&
118
- this._active.settings!.storageIdentityKey === this._active.user!.activeStorage &&
119
- this._conflictingActives !== undefined &&
120
- this._conflictingActives.length === 0
121
- )
122
- }
123
-
124
- /**
125
- * @returns true if at least one WalletStorageProvider has been added.
126
- */
127
- canMakeAvailable(): boolean {
128
- return this._stores.length > 0
129
- }
130
-
131
- /**
132
- * This async function must be called after construction and before
133
- * any other async function can proceed.
134
- *
135
- * Runs through `_stores` validating all properties and partitioning across `_active`, `_backups`, `_conflictingActives`.
136
- *
137
- * @throws WERR_INVALID_PARAMETER if canMakeAvailable returns false.
138
- *
139
- * @returns {TableSettings} from the active storage.
140
- */
141
- async makeAvailable(): Promise<TableSettings> {
142
- if (this._isAvailable) return this._active!.settings!
143
-
144
- this._active = undefined
145
- this._backups = []
146
- this._conflictingActives = []
147
-
148
- if (this._stores.length < 1)
149
- throw new sdk.WERR_INVALID_PARAMETER('active', 'valid. Must add active storage provider to wallet.')
150
-
151
- // Initial backups. conflictingActives will be removed.
152
- const backups: ManagedStorage[] = []
153
- let i = -1
154
- for (const store of this._stores) {
155
- i++
156
- if (!store.isAvailable || !store.settings || !store.user) {
157
- // Validate all ManagedStorage properties.
158
- store.settings = await store.storage.makeAvailable()
159
- const r = await store.storage.findOrInsertUser(this._authId.identityKey)
160
- store.user = r.user
161
- store.isAvailable = true
162
- }
163
- if (!this._active)
164
- // _stores[0] becomes the default active store. It may be replaced if it is not the user's "enabled" activeStorage and that store is found among the remainder (backups).
165
- this._active = store
166
- else {
167
- const ua = store.user!.activeStorage
168
- const si = store.settings!.storageIdentityKey
169
- if (ua === si && !this.isActiveEnabled) {
170
- // This store's user record selects it as an enabled active storage...
171
- // swap the current not-enabled active for this storeage.
172
- backups.push(this._active!)
173
- this._active = store
174
- } else {
175
- // This store is a backup: Its user record selects some other storage as active.
176
- backups.push(store)
177
- }
178
- }
179
- }
180
-
181
- // Review backups, partition out conflicting actives.
182
- const si = this._active!.settings?.storageIdentityKey
183
- for (const store of backups) {
184
- if (store.user!.activeStorage !== si) this._conflictingActives.push(store)
185
- else this._backups.push(store)
186
- }
187
-
188
- this._isAvailable = true
189
- this._authId.userId = this._active!.user!.userId
190
- this._authId.isActive = this.isActiveEnabled
191
-
192
- return this._active!.settings!
193
- }
194
-
195
- private verifyActive(): ManagedStorage {
196
- if (!this._active || !this._isAvailable)
197
- throw new sdk.WERR_INVALID_OPERATION(
198
- 'An active WalletStorageProvider must be added to this WalletStorageManager and makeAvailable must be called.'
199
- )
200
- return this._active
201
- }
202
-
203
- async getAuth(mustBeActive?: boolean): Promise<sdk.AuthId> {
204
- if (!this.isAvailable()) await this.makeAvailable()
205
- if (mustBeActive && !this._authId.isActive) throw new sdk.WERR_NOT_ACTIVE()
206
- return this._authId
207
- }
208
-
209
- async getUserId(): Promise<number> {
210
- return (await this.getAuth()).userId!
211
- }
212
-
213
- getActive(): sdk.WalletStorageProvider {
214
- return this.verifyActive().storage
215
- }
216
-
217
- getActiveSettings(): TableSettings {
218
- return this.verifyActive().settings!
219
- }
220
-
221
- getActiveUser(): TableUser {
222
- return this.verifyActive().user!
223
- }
224
-
225
- getActiveStore(): string {
226
- return this.verifyActive().settings!.storageIdentityKey
227
- }
228
-
229
- getActiveStoreName(): string {
230
- return this.verifyActive().settings!.storageName
231
- }
232
-
233
- getBackupStores(): string[] {
234
- this.verifyActive()
235
- return this._backups!.map(b => b.settings!.storageIdentityKey)
236
- }
237
-
238
- getConflictingStores(): string[] {
239
- this.verifyActive()
240
- return this._conflictingActives!.map(b => b.settings!.storageIdentityKey)
241
- }
242
-
243
- getAllStores(): string[] {
244
- this.verifyActive()
245
- return this._stores.map(b => b.settings!.storageIdentityKey)
246
- }
247
-
248
- private readonly readerLocks: Array<(value: void | PromiseLike<void>) => void> = []
249
- private readonly writerLocks: Array<(value: void | PromiseLike<void>) => void> = []
250
- private readonly syncLocks: Array<(value: void | PromiseLike<void>) => void> = []
251
- private readonly spLocks: Array<(value: void | PromiseLike<void>) => void> = []
252
-
253
- private async getActiveLock(lockQueue: Array<(value: void | PromiseLike<void>) => void>): Promise<void> {
254
- if (!this.isAvailable()) await this.makeAvailable()
255
-
256
- let resolveNewLock: () => void = () => {}
257
- const newLock = new Promise<void>(resolve => {
258
- resolveNewLock = resolve
259
- lockQueue.push(resolve)
260
- })
261
- if (lockQueue.length === 1) {
262
- resolveNewLock()
263
- }
264
- await newLock
265
- }
266
-
267
- private releaseActiveLock(queue: Array<(value: void | PromiseLike<void>) => void>): void {
268
- queue.shift() // Remove the current lock from the queue
269
- if (queue.length > 0) {
270
- queue[0]()
271
- }
272
- }
273
-
274
- private async getActiveForReader(): Promise<sdk.WalletStorageReader> {
275
- await this.getActiveLock(this.readerLocks)
276
- return this.getActive()
277
- }
278
- private releaseActiveForReader(): void {
279
- this.releaseActiveLock(this.readerLocks)
280
- }
281
-
282
- private async getActiveForWriter(): Promise<sdk.WalletStorageWriter> {
283
- await this.getActiveLock(this.readerLocks)
284
- await this.getActiveLock(this.writerLocks)
285
- return this.getActive()
286
- }
287
- private releaseActiveForWriter(): void {
288
- this.releaseActiveLock(this.writerLocks)
289
- this.releaseActiveLock(this.readerLocks)
290
- }
291
-
292
- private async getActiveForSync(): Promise<sdk.WalletStorageSync> {
293
- await this.getActiveLock(this.readerLocks)
294
- await this.getActiveLock(this.writerLocks)
295
- await this.getActiveLock(this.syncLocks)
296
- return this.getActive()
297
- }
298
- private releaseActiveForSync(): void {
299
- this.releaseActiveLock(this.syncLocks)
300
- this.releaseActiveLock(this.writerLocks)
301
- this.releaseActiveLock(this.readerLocks)
302
- }
303
-
304
- private async getActiveForStorageProvider(): Promise<StorageProvider> {
305
- await this.getActiveLock(this.readerLocks)
306
- await this.getActiveLock(this.writerLocks)
307
- await this.getActiveLock(this.syncLocks)
308
- await this.getActiveLock(this.spLocks)
309
-
310
- const active = this.getActive()
311
- // We can finally confirm that active storage is still able to support `StorageProvider`
312
- if (!active.isStorageProvider())
313
- throw new sdk.WERR_INVALID_OPERATION(
314
- 'Active "WalletStorageProvider" does not support "StorageProvider" interface.'
315
- )
316
- // Allow the sync to proceed on the active store.
317
- return active as unknown as StorageProvider
318
- }
319
- private releaseActiveForStorageProvider(): void {
320
- this.releaseActiveLock(this.spLocks)
321
- this.releaseActiveLock(this.syncLocks)
322
- this.releaseActiveLock(this.writerLocks)
323
- this.releaseActiveLock(this.readerLocks)
324
- }
325
-
326
- async runAsWriter<R>(writer: (active: sdk.WalletStorageWriter) => Promise<R>): Promise<R> {
327
- try {
328
- const active = await this.getActiveForWriter()
329
- const r = await writer(active)
330
- return r
331
- } finally {
332
- this.releaseActiveForWriter()
333
- }
334
- }
335
-
336
- async runAsReader<R>(reader: (active: sdk.WalletStorageReader) => Promise<R>): Promise<R> {
337
- try {
338
- const active = await this.getActiveForReader()
339
- const r = await reader(active)
340
- return r
341
- } finally {
342
- this.releaseActiveForReader()
343
- }
344
- }
345
-
346
- /**
347
- *
348
- * @param sync the function to run with sync access lock
349
- * @param activeSync from chained sync functions, active storage already held under sync access lock.
350
- * @returns
351
- */
352
- async runAsSync<R>(
353
- sync: (active: sdk.WalletStorageSync) => Promise<R>,
354
- activeSync?: sdk.WalletStorageSync
355
- ): Promise<R> {
356
- try {
357
- const active = activeSync || (await this.getActiveForSync())
358
- const r = await sync(active)
359
- return r
360
- } finally {
361
- if (!activeSync) this.releaseActiveForSync()
362
- }
363
- }
364
-
365
- async runAsStorageProvider<R>(sync: (active: StorageProvider) => Promise<R>): Promise<R> {
366
- try {
367
- const active = await this.getActiveForStorageProvider()
368
- const r = await sync(active)
369
- return r
370
- } finally {
371
- this.releaseActiveForStorageProvider()
372
- }
373
- }
374
-
375
- /**
376
- *
377
- * @returns true if the active `WalletStorageProvider` also implements `StorageProvider`
378
- */
379
- isActiveStorageProvider(): boolean {
380
- return this.getActive().isStorageProvider()
381
- }
382
-
383
- async addWalletStorageProvider(provider: sdk.WalletStorageProvider): Promise<void> {
384
- await provider.makeAvailable()
385
- if (this._services) provider.setServices(this._services)
386
- this._stores.push(new ManagedStorage(provider))
387
- this._isAvailable = false
388
- await this.makeAvailable()
389
- }
390
-
391
- setServices(v: sdk.WalletServices) {
392
- this._services = v
393
- for (const store of this._stores) store.storage.setServices(v)
394
- }
395
- getServices(): sdk.WalletServices {
396
- if (!this._services) throw new sdk.WERR_INVALID_OPERATION('Must setServices first.')
397
- return this._services
398
- }
399
-
400
- getSettings(): TableSettings {
401
- return this.getActive().getSettings()
402
- }
403
-
404
- async migrate(storageName: string, storageIdentityKey: string): Promise<string> {
405
- return await this.runAsWriter(async writer => {
406
- return writer.migrate(storageName, storageIdentityKey)
407
- })
408
- }
409
-
410
- async destroy(): Promise<void> {
411
- if (this._stores.length < 1) return
412
- return await this.runAsWriter(async writer => {
413
- for (const store of this._stores) await store.storage.destroy()
414
- })
415
- }
416
-
417
- async findOrInsertUser(identityKey: string): Promise<{ user: TableUser; isNew: boolean }> {
418
- const auth = await this.getAuth()
419
- if (identityKey != auth.identityKey) throw new sdk.WERR_UNAUTHORIZED()
420
-
421
- return await this.runAsWriter(async writer => {
422
- const r = await writer.findOrInsertUser(identityKey)
423
-
424
- if (auth.userId && auth.userId !== r.user.userId)
425
- throw new sdk.WERR_INTERNAL('userId may not change for given identityKey')
426
- this._authId.userId = r.user.userId
427
- return r
428
- })
429
- }
430
-
431
- async abortAction(args: AbortActionArgs): Promise<AbortActionResult> {
432
- Validation.validateAbortActionArgs(args)
433
- return await this.runAsWriter(async writer => {
434
- const auth = await this.getAuth(true)
435
- return await writer.abortAction(auth, args)
436
- })
437
- }
438
- async createAction(vargs: Validation.ValidCreateActionArgs): Promise<sdk.StorageCreateActionResult> {
439
- return await this.runAsWriter(async writer => {
440
- const auth = await this.getAuth(true)
441
- return await writer.createAction(auth, vargs)
442
- })
443
- }
444
- async internalizeAction(args: InternalizeActionArgs): Promise<sdk.StorageInternalizeActionResult> {
445
- Validation.validateInternalizeActionArgs(args)
446
- return await this.runAsWriter(async writer => {
447
- const auth = await this.getAuth(true)
448
- return await writer.internalizeAction(auth, args)
449
- })
450
- }
451
-
452
- async relinquishCertificate(args: RelinquishCertificateArgs): Promise<number> {
453
- Validation.validateRelinquishCertificateArgs(args)
454
- return await this.runAsWriter(async writer => {
455
- const auth = await this.getAuth(true)
456
- return await writer.relinquishCertificate(auth, args)
457
- })
458
- }
459
- async relinquishOutput(args: RelinquishOutputArgs): Promise<number> {
460
- Validation.validateRelinquishOutputArgs(args)
461
- return await this.runAsWriter(async writer => {
462
- const auth = await this.getAuth(true)
463
- return await writer.relinquishOutput(auth, args)
464
- })
465
- }
466
-
467
- async processAction(args: sdk.StorageProcessActionArgs): Promise<sdk.StorageProcessActionResults> {
468
- return await this.runAsWriter(async writer => {
469
- const auth = await this.getAuth(true)
470
- return await writer.processAction(auth, args)
471
- })
472
- }
473
- async insertCertificate(certificate: TableCertificate): Promise<number> {
474
- return await this.runAsWriter(async writer => {
475
- const auth = await this.getAuth(true)
476
- return await writer.insertCertificateAuth(auth, certificate)
477
- })
478
- }
479
-
480
- async listActions(vargs: Validation.ValidListActionsArgs): Promise<ListActionsResult> {
481
- const auth = await this.getAuth()
482
- return await this.runAsReader(async reader => {
483
- return await reader.listActions(auth, vargs)
484
- })
485
- }
486
- async listCertificates(args: Validation.ValidListCertificatesArgs): Promise<ListCertificatesResult> {
487
- const auth = await this.getAuth()
488
- return await this.runAsReader(async reader => {
489
- return await reader.listCertificates(auth, args)
490
- })
491
- }
492
- async listOutputs(vargs: Validation.ValidListOutputsArgs): Promise<ListOutputsResult> {
493
- const auth = await this.getAuth()
494
- return await this.runAsReader(async reader => {
495
- return await reader.listOutputs(auth, vargs)
496
- })
497
- }
498
- async findCertificates(args: sdk.FindCertificatesArgs): Promise<TableCertificateX[]> {
499
- const auth = await this.getAuth()
500
- return await this.runAsReader(async reader => {
501
- return await reader.findCertificatesAuth(auth, args)
502
- })
503
- }
504
- async findOutputBaskets(args: sdk.FindOutputBasketsArgs): Promise<TableOutputBasket[]> {
505
- const auth = await this.getAuth()
506
- return await this.runAsReader(async reader => {
507
- return await reader.findOutputBasketsAuth(auth, args)
508
- })
509
- }
510
- async findOutputs(args: sdk.FindOutputsArgs): Promise<TableOutput[]> {
511
- const auth = await this.getAuth()
512
- return await this.runAsReader(async reader => {
513
- return await reader.findOutputsAuth(auth, args)
514
- })
515
- }
516
-
517
- async findProvenTxReqs(args: sdk.FindProvenTxReqsArgs): Promise<TableProvenTxReq[]> {
518
- return await this.runAsReader(async reader => {
519
- return await reader.findProvenTxReqs(args)
520
- })
521
- }
522
-
523
- /**
524
- * For each proven_txs record currently sourcing its transaction merkle proof from the given deactivated header,
525
- * attempt to reprove the transaction against the current chain,
526
- * updating the proven_txs record if a new valid proof is found.
527
- *
528
- * @param deactivatedHash An orphaned header than may have served as a proof source for proven_txs records.
529
- * @returns
530
- */
531
- async reproveHeader(deactivatedHash: string): Promise<sdk.ReproveHeaderResult> {
532
- const r: sdk.ReproveHeaderResult = { log: '', updated: [], unchanged: [], unavailable: [] }
533
- const services = this.getServices()
534
- const chaintracker = await services.getChainTracker()
535
-
536
- // Lookup all the proven_txs records matching the deactivated headers
537
- let ptxs: TableProvenTx[] = []
538
- await this.runAsStorageProvider(async sp => {
539
- ptxs = await sp.findProvenTxs({ partial: { blockHash: deactivatedHash } })
540
- })
541
-
542
- r.log += ` block ${deactivatedHash} orphaned with ${ptxs.length} impacted transactions\n`
543
-
544
- for (const ptx of ptxs) {
545
- // Loop over proven_txs records matching the deactivated header
546
- const rp = await this.reproveProven(ptx, true)
547
-
548
- r.log += rp.log
549
- if (rp.unavailable) r.unavailable.push(ptx)
550
- if (rp.unchanged) r.unchanged.push(ptx)
551
- if (rp.updated) r.updated.push({ was: ptx, update: rp.updated.update, logUpdate: rp.updated.logUpdate })
552
- }
553
-
554
- if (r.updated.length > 0) {
555
- await this.runAsStorageProvider(async sp => {
556
- for (const u of r.updated) {
557
- await sp.updateProvenTx(u.was.provenTxId, u.update)
558
- r.log += ` txid ${u.was.txid} proof data updated\n` + u.logUpdate
559
- }
560
- })
561
- }
562
-
563
- return r
564
- }
565
-
566
- /**
567
- * Extends the Beef `verify` function to handle BUMPs that have become invalid due to a chain reorg,
568
- * and originated from proven_txs records tracked by this storage.
569
- *
570
- * This method is optimized for making sure outgoing beefs are valid before sharing them externally.
571
- * In particular, it only "repairs" proofs previously tracked by this storage.
572
- *
573
- * Any merkle root that fails `isValidRootForHeight` triggers a reprove attempt for that block header.
574
- * This results in proven_txs with invalid proofs being updated with new valid proofs where possible.
575
- *
576
- * @param beef
577
- * @param allowTxidOnly
578
- * @returns VerifyAndRepairBeefResult, in particular `verifiedBeef` is valid only verify and repair succeeded fully.
579
- */
580
- async verifyAndRepairBeef(beef: Beef, allowTxidOnly?: boolean): Promise<VerifyAndRepairBeefResult> {
581
- throw new sdk.WERR_NOT_IMPLEMENTED()
582
-
583
- const r: VerifyAndRepairBeefResult = {
584
- isStructurallyValid: false,
585
- originalRoots: {},
586
- invalidRoots: {}
587
- }
588
- const services = this.getServices()
589
- const chaintracker = await services.getChainTracker()
590
-
591
- ;({ valid: r.isStructurallyValid, roots: r.originalRoots } = beef.verifyValid(allowTxidOnly))
592
-
593
- if (!r.isStructurallyValid) return r
594
-
595
- for (const [heightStr, root] of Object.entries(r.originalRoots)) {
596
- const height = Number(heightStr)
597
- const isValid = await chaintracker.isValidRootForHeight(root, height)
598
- if (!isValid) {
599
- // root is not currently the valid hash for this height according to the chaintracker.
600
- // What beef txids depended on this root:
601
- const txids = beef.txs
602
- .filter(tx => tx.bumpIndex !== undefined && beef.bumps[tx.bumpIndex].blockHeight === height)
603
- .map(tx => tx.txid)
604
- const reproveResults = await this.reproveHeader(root)
605
- r.invalidRoots[height] = { root, reproveResults }
606
- }
607
- }
608
-
609
- if (Object.keys(r.invalidRoots).length === 0) {
610
- // There are no invalid merkle roots and the beef is structurally valid.
611
- // The beef is fully verified.
612
- return r
613
- }
614
-
615
- // beef is structurally valid but has invalid merkle roots.
616
- // Attempt to repair the invalid roots by reproving all txids in this beef that relied on them.
617
-
618
- // All invalid BUMPs must be removed from the beef
619
- // and all txid's that were proven by those BUMPs need
620
- // new beefs merged into the beef.
621
- // In most cases, this will be a replacement BUMP,
622
- // but it may also require a deeper proof.
623
-
624
- return r
625
- }
626
-
627
- /**
628
- * Attempt to reprove the transaction against the current chain,
629
- * If a new valid proof is found and noUpdate is not true,
630
- * update the proven_txs record with new block and merkle proof data.
631
- * If noUpdate is true, the update to be applied is available in the returned result.
632
- *
633
- * @param ptx proven_txs record to reprove
634
- * @param noUpdate
635
- * @returns
636
- */
637
- async reproveProven(ptx: TableProvenTx, noUpdate?: boolean): Promise<sdk.ReproveProvenResult> {
638
- const r: sdk.ReproveProvenResult = { log: '', updated: undefined, unchanged: false, unavailable: false }
639
- const services = this.getServices()
640
- const chaintracker = await services.getChainTracker()
641
-
642
- const mpr = await services.getMerklePath(ptx.txid)
643
- if (mpr.merklePath && mpr.header) {
644
- const mp = mpr.merklePath
645
- const h = mpr.header
646
- const leaf = mp.path[0].find(leaf => leaf.txid === true && leaf.hash === ptx.txid)
647
- if (leaf) {
648
- const update: Partial<TableProvenTx> = {
649
- height: mp.blockHeight,
650
- index: leaf.offset,
651
- merklePath: mp.toBinary(),
652
- merkleRoot: h.merkleRoot,
653
- blockHash: h.hash
654
- }
655
- if (update.blockHash === ptx.blockHash) {
656
- r.log += ` txid ${ptx.txid} merkle path update still based on deactivated header ${ptx.blockHash}\n`
657
- r.unchanged = true
658
- } else {
659
- // Verify the new proof's validity.
660
- const merkleRoot = mp.computeRoot(ptx.txid)
661
- const isValid = await chaintracker.isValidRootForHeight(merkleRoot, update.height!)
662
- const logUpdate = ` height ${ptx.height} ${ptx.height === update.height ? 'unchanged' : `-> ${update.height}`}\n`
663
- r.log += ` blockHash ${ptx.blockHash} -> ${update.blockHash}\n`
664
- r.log += ` merkleRoot ${ptx.merkleRoot} -> ${update.merkleRoot}\n`
665
- r.log += ` index ${ptx.index} -> ${update.index}\n`
666
- if (isValid) {
667
- r.updated = { update, logUpdate }
668
- } else {
669
- r.log +=
670
- ` txid ${ptx.txid} chaintracker fails to confirm updated merkle path update invalid\n` + logUpdate
671
- r.unavailable = true
672
- }
673
- }
674
- } else {
675
- r.log += ` txid ${ptx.txid} merkle path update doesn't include txid\n`
676
- r.unavailable = true
677
- }
678
- } else {
679
- r.log += ` txid ${ptx.txid} merkle path update unavailable\n`
680
- r.unavailable = true
681
- }
682
-
683
- if (r.updated && !noUpdate) {
684
- await this.runAsStorageProvider(async sp => {
685
- await sp.updateProvenTx(ptx.provenTxId, r.updated!.update)
686
- r.log += ` txid ${ptx.txid} proof data updated\n` + r.updated!.logUpdate
687
- })
688
- }
689
-
690
- return r
691
- }
692
-
693
- async syncFromReader(
694
- identityKey: string,
695
- reader: sdk.WalletStorageSyncReader,
696
- activeSync?: sdk.WalletStorageSync,
697
- log: string = ''
698
- ): Promise<{ inserts: number; updates: number; log: string }> {
699
- const auth = await this.getAuth()
700
- if (identityKey !== auth.identityKey) throw new sdk.WERR_UNAUTHORIZED()
701
-
702
- const readerSettings = await reader.makeAvailable()
703
-
704
- let inserts = 0,
705
- updates = 0
706
-
707
- log = await this.runAsSync(async sync => {
708
- const writer = sync
709
- const writerSettings = this.getSettings()
710
-
711
- log += `syncFromReader from ${readerSettings.storageName} to ${writerSettings.storageName}\n`
712
-
713
- let i = -1
714
- for (;;) {
715
- i++
716
- const ss = await EntitySyncState.fromStorage(writer, identityKey, readerSettings)
717
- const args = ss.makeRequestSyncChunkArgs(identityKey, writerSettings.storageIdentityKey)
718
- const chunk = await reader.getSyncChunk(args)
719
- if (chunk.user) {
720
- // Merging state from a reader cannot update activeStorage
721
- chunk.user.activeStorage = this._active!.user!.activeStorage
722
- }
723
- const r = await writer.processSyncChunk(args, chunk)
724
- inserts += r.inserts
725
- updates += r.updates
726
- log += `chunk ${i} inserted ${r.inserts} updated ${r.updates} ${r.maxUpdated_at}\n`
727
- if (r.done) break
728
- }
729
- log += `syncFromReader complete: ${inserts} inserts, ${updates} updates\n`
730
- return log
731
- }, activeSync)
732
-
733
- return { inserts, updates, log }
734
- }
735
-
736
- async syncToWriter(
737
- auth: sdk.AuthId,
738
- writer: sdk.WalletStorageProvider,
739
- activeSync?: sdk.WalletStorageSync,
740
- log: string = '',
741
- progLog?: (s: string) => string
742
- ): Promise<{ inserts: number; updates: number; log: string }> {
743
- progLog ||= s => s
744
- const identityKey = auth.identityKey
745
-
746
- const writerSettings = await writer.makeAvailable()
747
-
748
- let inserts = 0,
749
- updates = 0
750
-
751
- log = await this.runAsSync(async sync => {
752
- const reader = sync
753
- const readerSettings = reader.getSettings()
754
-
755
- log += progLog(`syncToWriter from ${readerSettings.storageName} to ${writerSettings.storageName}\n`)
756
-
757
- let i = -1
758
- for (;;) {
759
- i++
760
- const ss = await EntitySyncState.fromStorage(writer, identityKey, readerSettings)
761
- const args = ss.makeRequestSyncChunkArgs(identityKey, writerSettings.storageIdentityKey)
762
- const chunk = await reader.getSyncChunk(args)
763
- log += EntitySyncState.syncChunkSummary(chunk)
764
- const r = await writer.processSyncChunk(args, chunk)
765
- inserts += r.inserts
766
- updates += r.updates
767
- log += progLog(`chunk ${i} inserted ${r.inserts} updated ${r.updates} ${r.maxUpdated_at}\n`)
768
- if (r.done) break
769
- }
770
- log += progLog(`syncToWriter complete: ${inserts} inserts, ${updates} updates\n`)
771
- return log
772
- }, activeSync)
773
-
774
- return { inserts, updates, log }
775
- }
776
-
777
- async updateBackups(activeSync?: sdk.WalletStorageSync, progLog?: (s: string) => string): Promise<string> {
778
- progLog ||= s => s
779
- const auth = await this.getAuth(true)
780
- return await this.runAsSync(async sync => {
781
- let log = progLog(`BACKUP CURRENT ACTIVE TO ${this._backups!.length} STORES\n`)
782
- for (const backup of this._backups!) {
783
- const stwr = await this.syncToWriter(auth, backup.storage, sync, undefined, progLog)
784
- log += stwr.log
785
- }
786
- return log
787
- }, activeSync)
788
- }
789
-
790
- /**
791
- * Updates backups and switches to new active storage provider from among current backup providers.
792
- *
793
- * Also resolves conflicting actives.
794
- *
795
- * @param storageIdentityKey of current backup storage provider that is to become the new active provider.
796
- */
797
- async setActive(storageIdentityKey: string, progLog?: (s: string) => string): Promise<string> {
798
- progLog ||= s => s
799
- if (!this.isAvailable()) await this.makeAvailable()
800
-
801
- // Confirm a valid storageIdentityKey: must match one of the _stores.
802
- const newActiveIndex = this._stores.findIndex(s => s.settings!.storageIdentityKey === storageIdentityKey)
803
- if (newActiveIndex < 0)
804
- throw new sdk.WERR_INVALID_PARAMETER(
805
- 'storageIdentityKey',
806
- `registered with this "WalletStorageManager". ${storageIdentityKey} does not match any managed store.`
807
- )
808
-
809
- const identityKey = (await this.getAuth()).identityKey
810
- const newActive = this._stores[newActiveIndex]
811
-
812
- let log = progLog(`setActive to ${newActive.settings!.storageName}`)
813
-
814
- if (storageIdentityKey === this.getActiveStore() && this.isActiveEnabled)
815
- /** Setting the current active as the new active is a permitted no-op. */
816
- return log + progLog(` unchanged\n`)
817
-
818
- log += progLog('\n')
819
-
820
- log += await this.runAsSync(async sync => {
821
- let log = ''
822
-
823
- if (this._conflictingActives!.length > 0) {
824
- // Merge state from conflicting actives into `newActive`.
825
-
826
- // Handle case where new active is current active to resolve conflicts.
827
- // And where new active is one of the current conflict actives.
828
- this._conflictingActives!.push(this._active!)
829
- // Remove the new active from conflicting actives and
830
- // set new active as the conflicting active that matches the target `storageIdentityKey`
831
- this._conflictingActives = this._conflictingActives!.filter(ca => {
832
- const isNewActive = ca.settings!.storageIdentityKey === storageIdentityKey
833
- return !isNewActive
834
- })
835
-
836
- // Merge state from conflicting actives into `newActive`.
837
- for (const conflict of this._conflictingActives) {
838
- log += progLog('MERGING STATE FROM CONFLICTING ACTIVES:\n')
839
- const sfr = await this.syncToWriter(
840
- { identityKey, userId: newActive.user!.userId, isActive: false },
841
- newActive.storage,
842
- conflict.storage,
843
- undefined,
844
- progLog
845
- )
846
- log += sfr.log
847
- }
848
- log += progLog('PROPAGATE MERGED ACTIVE STATE TO NON-ACTIVES\n')
849
- } else {
850
- log += progLog('BACKUP CURRENT ACTIVE STATE THEN SET NEW ACTIVE\n')
851
- }
852
-
853
- // If there were conflicting actives,
854
- // Push state merged from all merged actives into newActive to all stores other than the now single active.
855
- // Otherwise,
856
- // Push state from current active to all other stores.
857
- const backupSource = this._conflictingActives!.length > 0 ? newActive : this._active!
858
-
859
- // Update the backupSource's user record with the new activeStorage
860
- // which will propagate to all other stores in the following backup loop.
861
- await backupSource.storage.setActive({ identityKey, userId: backupSource.user!.userId }, storageIdentityKey)
862
-
863
- for (const store of this._stores) {
864
- // Update cached user.activeStorage of all stores
865
- store.user!.activeStorage = storageIdentityKey
866
-
867
- if (store.settings!.storageIdentityKey !== backupSource.settings!.storageIdentityKey) {
868
- // If this store is not the backupSource store push state from backupSource to this store.
869
- const stwr = await this.syncToWriter(
870
- { identityKey, userId: store.user!.userId, isActive: false },
871
- store.storage,
872
- backupSource.storage,
873
- undefined,
874
- progLog
875
- )
876
- log += stwr.log
877
- }
878
- }
879
-
880
- this._isAvailable = false
881
- await this.makeAvailable()
882
-
883
- return log
884
- })
885
-
886
- return log
887
- }
888
-
889
- getStoreEndpointURL(store: ManagedStorage): string | undefined {
890
- if (store.storage.constructor.name === 'StorageClient') return (store.storage as StorageClient).endpointUrl
891
- return undefined
892
- }
893
-
894
- getStores(): sdk.WalletStorageInfo[] {
895
- const stores: sdk.WalletStorageInfo[] = []
896
- if (this._active) {
897
- stores.push({
898
- isActive: true,
899
- isEnabled: this.isActiveEnabled,
900
- isBackup: false,
901
- isConflicting: false,
902
- userId: this._active.user!.userId,
903
- storageIdentityKey: this._active.settings!.storageIdentityKey,
904
- storageName: this._active.settings!.storageName,
905
- storageClass: this._active.storage.constructor.name,
906
- endpointURL: this.getStoreEndpointURL(this._active)
907
- })
908
- }
909
- for (const store of this._conflictingActives || []) {
910
- stores.push({
911
- isActive: true,
912
- isEnabled: false,
913
- isBackup: false,
914
- isConflicting: true,
915
- userId: store.user!.userId,
916
- storageIdentityKey: store.settings!.storageIdentityKey,
917
- storageName: store.settings!.storageName,
918
- storageClass: store.storage.constructor.name,
919
- endpointURL: this.getStoreEndpointURL(store)
920
- })
921
- }
922
- for (const store of this._backups || []) {
923
- stores.push({
924
- isActive: false,
925
- isEnabled: false,
926
- isBackup: true,
927
- isConflicting: false,
928
- userId: store.user!.userId,
929
- storageIdentityKey: store.settings!.storageIdentityKey,
930
- storageName: store.settings!.storageName,
931
- storageClass: store.storage.constructor.name,
932
- endpointURL: this.getStoreEndpointURL(store)
933
- })
934
- }
935
- return stores
936
- }
937
- }
938
-
939
- export interface VerifyAndRepairBeefResult {
940
- isStructurallyValid: boolean
941
- originalRoots: Record<number, string>
942
- invalidRoots: Record<number, { root: string; reproveResults: sdk.ReproveHeaderResult }>
943
- }