@bsv/wallet-toolbox 1.3.20 → 1.3.22

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 (517) hide show
  1. package/.github/workflows/push.yaml +5 -0
  2. package/mobile/out/src/CWIStyleWalletManager.d.ts +437 -0
  3. package/mobile/out/src/CWIStyleWalletManager.d.ts.map +1 -0
  4. package/mobile/out/src/CWIStyleWalletManager.js +1255 -0
  5. package/mobile/out/src/CWIStyleWalletManager.js.map +1 -0
  6. package/mobile/out/src/SetupClient.d.ts +126 -0
  7. package/mobile/out/src/SetupClient.d.ts.map +1 -0
  8. package/mobile/out/src/SetupClient.js +220 -0
  9. package/mobile/out/src/SetupClient.js.map +1 -0
  10. package/mobile/out/src/SetupWallet.d.ts +100 -0
  11. package/mobile/out/src/SetupWallet.d.ts.map +1 -0
  12. package/mobile/out/src/SetupWallet.js +3 -0
  13. package/mobile/out/src/SetupWallet.js.map +1 -0
  14. package/mobile/out/src/SimpleWalletManager.d.ts +169 -0
  15. package/mobile/out/src/SimpleWalletManager.d.ts.map +1 -0
  16. package/mobile/out/src/SimpleWalletManager.js +315 -0
  17. package/mobile/out/src/SimpleWalletManager.js.map +1 -0
  18. package/mobile/out/src/Wallet.d.ts +177 -0
  19. package/mobile/out/src/Wallet.d.ts.map +1 -0
  20. package/mobile/out/src/Wallet.js +742 -0
  21. package/mobile/out/src/Wallet.js.map +1 -0
  22. package/mobile/out/src/WalletAuthenticationManager.d.ts +33 -0
  23. package/mobile/out/src/WalletAuthenticationManager.d.ts.map +1 -0
  24. package/mobile/out/src/WalletAuthenticationManager.js +113 -0
  25. package/mobile/out/src/WalletAuthenticationManager.js.map +1 -0
  26. package/mobile/out/src/WalletPermissionsManager.d.ts +598 -0
  27. package/mobile/out/src/WalletPermissionsManager.d.ts.map +1 -0
  28. package/mobile/out/src/WalletPermissionsManager.js +1868 -0
  29. package/mobile/out/src/WalletPermissionsManager.js.map +1 -0
  30. package/mobile/out/src/WalletSettingsManager.d.ts +52 -0
  31. package/mobile/out/src/WalletSettingsManager.d.ts.map +1 -0
  32. package/mobile/out/src/WalletSettingsManager.js +82 -0
  33. package/mobile/out/src/WalletSettingsManager.js.map +1 -0
  34. package/mobile/out/src/index.client.d.ts +19 -0
  35. package/mobile/out/src/index.client.d.ts.map +1 -0
  36. package/mobile/out/src/index.client.js +58 -0
  37. package/mobile/out/src/index.client.js.map +1 -0
  38. package/mobile/out/src/index.mobile.d.ts +19 -0
  39. package/mobile/out/src/index.mobile.d.ts.map +1 -0
  40. package/mobile/out/src/index.mobile.js +58 -0
  41. package/mobile/out/src/index.mobile.js.map +1 -0
  42. package/mobile/out/src/monitor/Monitor.d.ts +91 -0
  43. package/mobile/out/src/monitor/Monitor.d.ts.map +1 -0
  44. package/mobile/out/src/monitor/Monitor.js +298 -0
  45. package/mobile/out/src/monitor/Monitor.js.map +1 -0
  46. package/mobile/out/src/monitor/tasks/TaskCheckForProofs.d.ts +53 -0
  47. package/mobile/out/src/monitor/tasks/TaskCheckForProofs.d.ts.map +1 -0
  48. package/mobile/out/src/monitor/tasks/TaskCheckForProofs.js +194 -0
  49. package/mobile/out/src/monitor/tasks/TaskCheckForProofs.js.map +1 -0
  50. package/mobile/out/src/monitor/tasks/TaskCheckNoSends.d.ts +33 -0
  51. package/mobile/out/src/monitor/tasks/TaskCheckNoSends.d.ts.map +1 -0
  52. package/mobile/out/src/monitor/tasks/TaskCheckNoSends.js +65 -0
  53. package/mobile/out/src/monitor/tasks/TaskCheckNoSends.js.map +1 -0
  54. package/mobile/out/src/monitor/tasks/TaskClock.d.ts +14 -0
  55. package/mobile/out/src/monitor/tasks/TaskClock.d.ts.map +1 -0
  56. package/mobile/out/src/monitor/tasks/TaskClock.js +27 -0
  57. package/mobile/out/src/monitor/tasks/TaskClock.js.map +1 -0
  58. package/mobile/out/src/monitor/tasks/TaskFailAbandoned.d.ts +20 -0
  59. package/mobile/out/src/monitor/tasks/TaskFailAbandoned.d.ts.map +1 -0
  60. package/mobile/out/src/monitor/tasks/TaskFailAbandoned.js +52 -0
  61. package/mobile/out/src/monitor/tasks/TaskFailAbandoned.js.map +1 -0
  62. package/mobile/out/src/monitor/tasks/TaskNewHeader.d.ts +15 -0
  63. package/mobile/out/src/monitor/tasks/TaskNewHeader.d.ts.map +1 -0
  64. package/mobile/out/src/monitor/tasks/TaskNewHeader.js +43 -0
  65. package/mobile/out/src/monitor/tasks/TaskNewHeader.js.map +1 -0
  66. package/mobile/out/src/monitor/tasks/TaskPurge.d.ts +45 -0
  67. package/mobile/out/src/monitor/tasks/TaskPurge.d.ts.map +1 -0
  68. package/mobile/out/src/monitor/tasks/TaskPurge.js +34 -0
  69. package/mobile/out/src/monitor/tasks/TaskPurge.js.map +1 -0
  70. package/mobile/out/src/monitor/tasks/TaskReviewStatus.d.ts +26 -0
  71. package/mobile/out/src/monitor/tasks/TaskReviewStatus.d.ts.map +1 -0
  72. package/mobile/out/src/monitor/tasks/TaskReviewStatus.js +43 -0
  73. package/mobile/out/src/monitor/tasks/TaskReviewStatus.js.map +1 -0
  74. package/mobile/out/src/monitor/tasks/TaskSendWaiting.d.ts +35 -0
  75. package/mobile/out/src/monitor/tasks/TaskSendWaiting.d.ts.map +1 -0
  76. package/mobile/out/src/monitor/tasks/TaskSendWaiting.js +107 -0
  77. package/mobile/out/src/monitor/tasks/TaskSendWaiting.js.map +1 -0
  78. package/mobile/out/src/monitor/tasks/TaskSyncWhenIdle.d.ts +12 -0
  79. package/mobile/out/src/monitor/tasks/TaskSyncWhenIdle.d.ts.map +1 -0
  80. package/mobile/out/src/monitor/tasks/TaskSyncWhenIdle.js +22 -0
  81. package/mobile/out/src/monitor/tasks/TaskSyncWhenIdle.js.map +1 -0
  82. package/mobile/out/src/monitor/tasks/TaskUnFail.d.ts +41 -0
  83. package/mobile/out/src/monitor/tasks/TaskUnFail.d.ts.map +1 -0
  84. package/mobile/out/src/monitor/tasks/TaskUnFail.js +144 -0
  85. package/mobile/out/src/monitor/tasks/TaskUnFail.js.map +1 -0
  86. package/mobile/out/src/monitor/tasks/WalletMonitorTask.d.ts +40 -0
  87. package/mobile/out/src/monitor/tasks/WalletMonitorTask.d.ts.map +1 -0
  88. package/mobile/out/src/monitor/tasks/WalletMonitorTask.js +37 -0
  89. package/mobile/out/src/monitor/tasks/WalletMonitorTask.js.map +1 -0
  90. package/mobile/out/src/sdk/CertOpsWallet.d.ts +7 -0
  91. package/mobile/out/src/sdk/CertOpsWallet.d.ts.map +1 -0
  92. package/mobile/out/src/sdk/CertOpsWallet.js +3 -0
  93. package/mobile/out/src/sdk/CertOpsWallet.js.map +1 -0
  94. package/mobile/out/src/sdk/PrivilegedKeyManager.d.ts +125 -0
  95. package/mobile/out/src/sdk/PrivilegedKeyManager.d.ts.map +1 -0
  96. package/mobile/out/src/sdk/PrivilegedKeyManager.js +293 -0
  97. package/mobile/out/src/sdk/PrivilegedKeyManager.js.map +1 -0
  98. package/mobile/out/src/sdk/WERR_errors.d.ts +115 -0
  99. package/mobile/out/src/sdk/WERR_errors.d.ts.map +1 -0
  100. package/mobile/out/src/sdk/WERR_errors.js +158 -0
  101. package/mobile/out/src/sdk/WERR_errors.js.map +1 -0
  102. package/mobile/out/src/sdk/WalletError.d.ts +44 -0
  103. package/mobile/out/src/sdk/WalletError.d.ts.map +1 -0
  104. package/mobile/out/src/sdk/WalletError.js +118 -0
  105. package/mobile/out/src/sdk/WalletError.js.map +1 -0
  106. package/mobile/out/src/sdk/WalletServices.interfaces.d.ts +430 -0
  107. package/mobile/out/src/sdk/WalletServices.interfaces.d.ts.map +1 -0
  108. package/mobile/out/src/sdk/WalletServices.interfaces.js +3 -0
  109. package/mobile/out/src/sdk/WalletServices.interfaces.js.map +1 -0
  110. package/mobile/out/src/sdk/WalletSigner.interfaces.d.ts +10 -0
  111. package/mobile/out/src/sdk/WalletSigner.interfaces.d.ts.map +1 -0
  112. package/mobile/out/src/sdk/WalletSigner.interfaces.js +3 -0
  113. package/mobile/out/src/sdk/WalletSigner.interfaces.js.map +1 -0
  114. package/mobile/out/src/sdk/WalletStorage.interfaces.d.ts +452 -0
  115. package/mobile/out/src/sdk/WalletStorage.interfaces.d.ts.map +1 -0
  116. package/mobile/out/src/sdk/WalletStorage.interfaces.js +3 -0
  117. package/mobile/out/src/sdk/WalletStorage.interfaces.js.map +1 -0
  118. package/mobile/out/src/sdk/index.d.ts +10 -0
  119. package/mobile/out/src/sdk/index.d.ts.map +1 -0
  120. package/mobile/out/src/sdk/index.js +26 -0
  121. package/mobile/out/src/sdk/index.js.map +1 -0
  122. package/mobile/out/src/sdk/types.d.ts +158 -0
  123. package/mobile/out/src/sdk/types.d.ts.map +1 -0
  124. package/mobile/out/src/sdk/types.js +90 -0
  125. package/mobile/out/src/sdk/types.js.map +1 -0
  126. package/mobile/out/src/sdk/validationHelpers.d.ts +301 -0
  127. package/mobile/out/src/sdk/validationHelpers.d.ts.map +1 -0
  128. package/mobile/out/src/sdk/validationHelpers.js +629 -0
  129. package/mobile/out/src/sdk/validationHelpers.js.map +1 -0
  130. package/mobile/out/src/services/ServiceCollection.d.ts +25 -0
  131. package/mobile/out/src/services/ServiceCollection.d.ts.map +1 -0
  132. package/mobile/out/src/services/ServiceCollection.js +43 -0
  133. package/mobile/out/src/services/ServiceCollection.js.map +1 -0
  134. package/mobile/out/src/services/Services.d.ts +67 -0
  135. package/mobile/out/src/services/Services.d.ts.map +1 -0
  136. package/mobile/out/src/services/Services.js +391 -0
  137. package/mobile/out/src/services/Services.js.map +1 -0
  138. package/mobile/out/src/services/chaintracker/ChaintracksChainTracker.d.ts +15 -0
  139. package/mobile/out/src/services/chaintracker/ChaintracksChainTracker.d.ts.map +1 -0
  140. package/mobile/out/src/services/chaintracker/ChaintracksChainTracker.js +51 -0
  141. package/mobile/out/src/services/chaintracker/ChaintracksChainTracker.js.map +1 -0
  142. package/mobile/out/src/services/chaintracker/chaintracks/BlockHeaderApi.d.ts +98 -0
  143. package/mobile/out/src/services/chaintracker/chaintracks/BlockHeaderApi.d.ts.map +1 -0
  144. package/mobile/out/src/services/chaintracker/chaintracks/BlockHeaderApi.js +38 -0
  145. package/mobile/out/src/services/chaintracker/chaintracks/BlockHeaderApi.js.map +1 -0
  146. package/mobile/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.d.ts +36 -0
  147. package/mobile/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.d.ts.map +1 -0
  148. package/mobile/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.js +128 -0
  149. package/mobile/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.js.map +1 -0
  150. package/mobile/out/src/services/chaintracker/chaintracks/index.d.ts +3 -0
  151. package/mobile/out/src/services/chaintracker/chaintracks/index.d.ts.map +1 -0
  152. package/mobile/out/src/services/chaintracker/chaintracks/index.js +19 -0
  153. package/mobile/out/src/services/chaintracker/chaintracks/index.js.map +1 -0
  154. package/mobile/out/src/services/chaintracker/index.d.ts +3 -0
  155. package/mobile/out/src/services/chaintracker/index.d.ts.map +1 -0
  156. package/mobile/out/src/services/chaintracker/index.js +19 -0
  157. package/mobile/out/src/services/chaintracker/index.js.map +1 -0
  158. package/mobile/out/src/services/createDefaultWalletServicesOptions.d.ts +4 -0
  159. package/mobile/out/src/services/createDefaultWalletServicesOptions.d.ts.map +1 -0
  160. package/mobile/out/src/services/createDefaultWalletServicesOptions.js +46 -0
  161. package/mobile/out/src/services/createDefaultWalletServicesOptions.js.map +1 -0
  162. package/mobile/out/src/services/index.d.ts +2 -0
  163. package/mobile/out/src/services/index.d.ts.map +1 -0
  164. package/mobile/out/src/services/index.js +18 -0
  165. package/mobile/out/src/services/index.js.map +1 -0
  166. package/mobile/out/src/services/providers/ARC.d.ts +91 -0
  167. package/mobile/out/src/services/providers/ARC.d.ts.map +1 -0
  168. package/mobile/out/src/services/providers/ARC.js +267 -0
  169. package/mobile/out/src/services/providers/ARC.js.map +1 -0
  170. package/mobile/out/src/services/providers/Bitails.d.ts +49 -0
  171. package/mobile/out/src/services/providers/Bitails.d.ts.map +1 -0
  172. package/mobile/out/src/services/providers/Bitails.js +222 -0
  173. package/mobile/out/src/services/providers/Bitails.js.map +1 -0
  174. package/mobile/out/src/services/providers/SdkWhatsOnChain.d.ts +21 -0
  175. package/mobile/out/src/services/providers/SdkWhatsOnChain.d.ts.map +1 -0
  176. package/mobile/out/src/services/providers/SdkWhatsOnChain.js +67 -0
  177. package/mobile/out/src/services/providers/SdkWhatsOnChain.js.map +1 -0
  178. package/mobile/out/src/services/providers/WhatsOnChain.d.ts +71 -0
  179. package/mobile/out/src/services/providers/WhatsOnChain.d.ts.map +1 -0
  180. package/mobile/out/src/services/providers/WhatsOnChain.js +582 -0
  181. package/mobile/out/src/services/providers/WhatsOnChain.js.map +1 -0
  182. package/mobile/out/src/services/providers/echangeRates.d.ts +12 -0
  183. package/mobile/out/src/services/providers/echangeRates.d.ts.map +1 -0
  184. package/mobile/out/src/services/providers/echangeRates.js +237 -0
  185. package/mobile/out/src/services/providers/echangeRates.js.map +1 -0
  186. package/mobile/out/src/services/providers/getBeefForTxid.d.ts +4 -0
  187. package/mobile/out/src/services/providers/getBeefForTxid.d.ts.map +1 -0
  188. package/mobile/out/src/services/providers/getBeefForTxid.js +286 -0
  189. package/mobile/out/src/services/providers/getBeefForTxid.js.map +1 -0
  190. package/mobile/out/src/signer/WalletSigner.d.ts +11 -0
  191. package/mobile/out/src/signer/WalletSigner.d.ts.map +1 -0
  192. package/mobile/out/src/signer/WalletSigner.js +13 -0
  193. package/mobile/out/src/signer/WalletSigner.js.map +1 -0
  194. package/mobile/out/src/signer/methods/acquireDirectCertificate.d.ts +4 -0
  195. package/mobile/out/src/signer/methods/acquireDirectCertificate.d.ts.map +1 -0
  196. package/mobile/out/src/signer/methods/acquireDirectCertificate.js +45 -0
  197. package/mobile/out/src/signer/methods/acquireDirectCertificate.js.map +1 -0
  198. package/mobile/out/src/signer/methods/buildSignableTransaction.d.ts +10 -0
  199. package/mobile/out/src/signer/methods/buildSignableTransaction.d.ts.map +1 -0
  200. package/mobile/out/src/signer/methods/buildSignableTransaction.js +126 -0
  201. package/mobile/out/src/signer/methods/buildSignableTransaction.js.map +1 -0
  202. package/mobile/out/src/signer/methods/createAction.d.ts +20 -0
  203. package/mobile/out/src/signer/methods/createAction.d.ts.map +1 -0
  204. package/mobile/out/src/signer/methods/createAction.js +160 -0
  205. package/mobile/out/src/signer/methods/createAction.js.map +1 -0
  206. package/mobile/out/src/signer/methods/internalizeAction.d.ts +31 -0
  207. package/mobile/out/src/signer/methods/internalizeAction.d.ts.map +1 -0
  208. package/mobile/out/src/signer/methods/internalizeAction.js +95 -0
  209. package/mobile/out/src/signer/methods/internalizeAction.js.map +1 -0
  210. package/mobile/out/src/signer/methods/proveCertificate.d.ts +4 -0
  211. package/mobile/out/src/signer/methods/proveCertificate.d.ts.map +1 -0
  212. package/mobile/out/src/signer/methods/proveCertificate.js +29 -0
  213. package/mobile/out/src/signer/methods/proveCertificate.js.map +1 -0
  214. package/mobile/out/src/signer/methods/signAction.d.ts +13 -0
  215. package/mobile/out/src/signer/methods/signAction.d.ts.map +1 -0
  216. package/mobile/out/src/signer/methods/signAction.js +89 -0
  217. package/mobile/out/src/signer/methods/signAction.js.map +1 -0
  218. package/mobile/out/src/storage/StorageIdb.d.ts +208 -0
  219. package/mobile/out/src/storage/StorageIdb.d.ts.map +1 -0
  220. package/mobile/out/src/storage/StorageIdb.js +2296 -0
  221. package/mobile/out/src/storage/StorageIdb.js.map +1 -0
  222. package/mobile/out/src/storage/StorageProvider.d.ts +209 -0
  223. package/mobile/out/src/storage/StorageProvider.d.ts.map +1 -0
  224. package/mobile/out/src/storage/StorageProvider.js +550 -0
  225. package/mobile/out/src/storage/StorageProvider.js.map +1 -0
  226. package/mobile/out/src/storage/StorageReader.d.ts +76 -0
  227. package/mobile/out/src/storage/StorageReader.d.ts.map +1 -0
  228. package/mobile/out/src/storage/StorageReader.js +129 -0
  229. package/mobile/out/src/storage/StorageReader.js.map +1 -0
  230. package/mobile/out/src/storage/StorageReaderWriter.d.ts +87 -0
  231. package/mobile/out/src/storage/StorageReaderWriter.d.ts.map +1 -0
  232. package/mobile/out/src/storage/StorageReaderWriter.js +338 -0
  233. package/mobile/out/src/storage/StorageReaderWriter.js.map +1 -0
  234. package/mobile/out/src/storage/StorageSyncReader.d.ts +17 -0
  235. package/mobile/out/src/storage/StorageSyncReader.d.ts.map +1 -0
  236. package/mobile/out/src/storage/StorageSyncReader.js +38 -0
  237. package/mobile/out/src/storage/StorageSyncReader.js.map +1 -0
  238. package/mobile/out/src/storage/WalletStorageManager.d.ts +184 -0
  239. package/mobile/out/src/storage/WalletStorageManager.d.ts.map +1 -0
  240. package/mobile/out/src/storage/WalletStorageManager.js +665 -0
  241. package/mobile/out/src/storage/WalletStorageManager.js.map +1 -0
  242. package/mobile/out/src/storage/index.client.d.ts +8 -0
  243. package/mobile/out/src/storage/index.client.d.ts.map +1 -0
  244. package/mobile/out/src/storage/index.client.js +24 -0
  245. package/mobile/out/src/storage/index.client.js.map +1 -0
  246. package/mobile/out/src/storage/index.mobile.d.ts +7 -0
  247. package/mobile/out/src/storage/index.mobile.d.ts.map +1 -0
  248. package/mobile/out/src/storage/index.mobile.js +23 -0
  249. package/mobile/out/src/storage/index.mobile.js.map +1 -0
  250. package/mobile/out/src/storage/methods/ListActionsSpecOp.d.ts +16 -0
  251. package/mobile/out/src/storage/methods/ListActionsSpecOp.d.ts.map +1 -0
  252. package/mobile/out/src/storage/methods/ListActionsSpecOp.js +40 -0
  253. package/mobile/out/src/storage/methods/ListActionsSpecOp.js.map +1 -0
  254. package/mobile/out/src/storage/methods/ListOutputsSpecOp.d.ts +26 -0
  255. package/mobile/out/src/storage/methods/ListOutputsSpecOp.d.ts.map +1 -0
  256. package/mobile/out/src/storage/methods/ListOutputsSpecOp.js +71 -0
  257. package/mobile/out/src/storage/methods/ListOutputsSpecOp.js.map +1 -0
  258. package/mobile/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts +41 -0
  259. package/mobile/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts.map +1 -0
  260. package/mobile/out/src/storage/methods/attemptToPostReqsToNetwork.js +320 -0
  261. package/mobile/out/src/storage/methods/attemptToPostReqsToNetwork.js.map +1 -0
  262. package/mobile/out/src/storage/methods/createAction.d.ts +24 -0
  263. package/mobile/out/src/storage/methods/createAction.d.ts.map +1 -0
  264. package/mobile/out/src/storage/methods/createAction.js +705 -0
  265. package/mobile/out/src/storage/methods/createAction.js.map +1 -0
  266. package/mobile/out/src/storage/methods/generateChange.d.ts +119 -0
  267. package/mobile/out/src/storage/methods/generateChange.d.ts.map +1 -0
  268. package/mobile/out/src/storage/methods/generateChange.js +448 -0
  269. package/mobile/out/src/storage/methods/generateChange.js.map +1 -0
  270. package/mobile/out/src/storage/methods/getBeefForTransaction.d.ts +22 -0
  271. package/mobile/out/src/storage/methods/getBeefForTransaction.d.ts.map +1 -0
  272. package/mobile/out/src/storage/methods/getBeefForTransaction.js +92 -0
  273. package/mobile/out/src/storage/methods/getBeefForTransaction.js.map +1 -0
  274. package/mobile/out/src/storage/methods/getSyncChunk.d.ts +10 -0
  275. package/mobile/out/src/storage/methods/getSyncChunk.d.ts.map +1 -0
  276. package/mobile/out/src/storage/methods/getSyncChunk.js +271 -0
  277. package/mobile/out/src/storage/methods/getSyncChunk.js.map +1 -0
  278. package/mobile/out/src/storage/methods/internalizeAction.d.ts +38 -0
  279. package/mobile/out/src/storage/methods/internalizeAction.d.ts.map +1 -0
  280. package/mobile/out/src/storage/methods/internalizeAction.js +371 -0
  281. package/mobile/out/src/storage/methods/internalizeAction.js.map +1 -0
  282. package/mobile/out/src/storage/methods/listActionsIdb.d.ts +5 -0
  283. package/mobile/out/src/storage/methods/listActionsIdb.d.ts.map +1 -0
  284. package/mobile/out/src/storage/methods/listActionsIdb.js +155 -0
  285. package/mobile/out/src/storage/methods/listActionsIdb.js.map +1 -0
  286. package/mobile/out/src/storage/methods/listCertificates.d.ts +5 -0
  287. package/mobile/out/src/storage/methods/listCertificates.d.ts.map +1 -0
  288. package/mobile/out/src/storage/methods/listCertificates.js +68 -0
  289. package/mobile/out/src/storage/methods/listCertificates.js.map +1 -0
  290. package/mobile/out/src/storage/methods/listOutputsIdb.d.ts +5 -0
  291. package/mobile/out/src/storage/methods/listOutputsIdb.d.ts.map +1 -0
  292. package/mobile/out/src/storage/methods/listOutputsIdb.js +181 -0
  293. package/mobile/out/src/storage/methods/listOutputsIdb.js.map +1 -0
  294. package/mobile/out/src/storage/methods/processAction.d.ts +35 -0
  295. package/mobile/out/src/storage/methods/processAction.d.ts.map +1 -0
  296. package/mobile/out/src/storage/methods/processAction.js +311 -0
  297. package/mobile/out/src/storage/methods/processAction.js.map +1 -0
  298. package/mobile/out/src/storage/methods/purgeDataIdb.d.ts +4 -0
  299. package/mobile/out/src/storage/methods/purgeDataIdb.d.ts.map +1 -0
  300. package/mobile/out/src/storage/methods/purgeDataIdb.js +9 -0
  301. package/mobile/out/src/storage/methods/purgeDataIdb.js.map +1 -0
  302. package/mobile/out/src/storage/methods/reviewStatusIdb.d.ts +20 -0
  303. package/mobile/out/src/storage/methods/reviewStatusIdb.d.ts.map +1 -0
  304. package/mobile/out/src/storage/methods/reviewStatusIdb.js +35 -0
  305. package/mobile/out/src/storage/methods/reviewStatusIdb.js.map +1 -0
  306. package/mobile/out/src/storage/remoting/StorageClient.d.ts +283 -0
  307. package/mobile/out/src/storage/remoting/StorageClient.d.ts.map +1 -0
  308. package/mobile/out/src/storage/remoting/StorageClient.js +477 -0
  309. package/mobile/out/src/storage/remoting/StorageClient.js.map +1 -0
  310. package/mobile/out/src/storage/schema/StorageIdbSchema.d.ts +133 -0
  311. package/mobile/out/src/storage/schema/StorageIdbSchema.d.ts.map +1 -0
  312. package/mobile/out/src/storage/schema/StorageIdbSchema.js +3 -0
  313. package/mobile/out/src/storage/schema/StorageIdbSchema.js.map +1 -0
  314. package/mobile/out/src/storage/schema/entities/EntityBase.d.ts +105 -0
  315. package/mobile/out/src/storage/schema/entities/EntityBase.d.ts.map +1 -0
  316. package/mobile/out/src/storage/schema/entities/EntityBase.js +100 -0
  317. package/mobile/out/src/storage/schema/entities/EntityBase.js.map +1 -0
  318. package/mobile/out/src/storage/schema/entities/EntityCertificate.d.ts +43 -0
  319. package/mobile/out/src/storage/schema/entities/EntityCertificate.d.ts.map +1 -0
  320. package/mobile/out/src/storage/schema/entities/EntityCertificate.js +162 -0
  321. package/mobile/out/src/storage/schema/entities/EntityCertificate.js.map +1 -0
  322. package/mobile/out/src/storage/schema/entities/EntityCertificateField.d.ts +32 -0
  323. package/mobile/out/src/storage/schema/entities/EntityCertificateField.d.ts.map +1 -0
  324. package/mobile/out/src/storage/schema/entities/EntityCertificateField.js +111 -0
  325. package/mobile/out/src/storage/schema/entities/EntityCertificateField.js.map +1 -0
  326. package/mobile/out/src/storage/schema/entities/EntityCommission.d.ts +37 -0
  327. package/mobile/out/src/storage/schema/entities/EntityCommission.d.ts.map +1 -0
  328. package/mobile/out/src/storage/schema/entities/EntityCommission.js +127 -0
  329. package/mobile/out/src/storage/schema/entities/EntityCommission.js.map +1 -0
  330. package/mobile/out/src/storage/schema/entities/EntityOutput.d.ts +67 -0
  331. package/mobile/out/src/storage/schema/entities/EntityOutput.d.ts.map +1 -0
  332. package/mobile/out/src/storage/schema/entities/EntityOutput.js +264 -0
  333. package/mobile/out/src/storage/schema/entities/EntityOutput.js.map +1 -0
  334. package/mobile/out/src/storage/schema/entities/EntityOutputBasket.d.ts +35 -0
  335. package/mobile/out/src/storage/schema/entities/EntityOutputBasket.d.ts.map +1 -0
  336. package/mobile/out/src/storage/schema/entities/EntityOutputBasket.js +133 -0
  337. package/mobile/out/src/storage/schema/entities/EntityOutputBasket.js.map +1 -0
  338. package/mobile/out/src/storage/schema/entities/EntityOutputTag.d.ts +31 -0
  339. package/mobile/out/src/storage/schema/entities/EntityOutputTag.d.ts.map +1 -0
  340. package/mobile/out/src/storage/schema/entities/EntityOutputTag.js +104 -0
  341. package/mobile/out/src/storage/schema/entities/EntityOutputTag.js.map +1 -0
  342. package/mobile/out/src/storage/schema/entities/EntityOutputTagMap.d.ts +28 -0
  343. package/mobile/out/src/storage/schema/entities/EntityOutputTagMap.d.ts.map +1 -0
  344. package/mobile/out/src/storage/schema/entities/EntityOutputTagMap.js +97 -0
  345. package/mobile/out/src/storage/schema/entities/EntityOutputTagMap.js.map +1 -0
  346. package/mobile/out/src/storage/schema/entities/EntityProvenTx.d.ts +84 -0
  347. package/mobile/out/src/storage/schema/entities/EntityProvenTx.d.ts.map +1 -0
  348. package/mobile/out/src/storage/schema/entities/EntityProvenTx.js +276 -0
  349. package/mobile/out/src/storage/schema/entities/EntityProvenTx.js.map +1 -0
  350. package/mobile/out/src/storage/schema/entities/EntityProvenTxReq.d.ts +135 -0
  351. package/mobile/out/src/storage/schema/entities/EntityProvenTxReq.d.ts.map +1 -0
  352. package/mobile/out/src/storage/schema/entities/EntityProvenTxReq.js +522 -0
  353. package/mobile/out/src/storage/schema/entities/EntityProvenTxReq.js.map +1 -0
  354. package/mobile/out/src/storage/schema/entities/EntitySyncState.d.ts +67 -0
  355. package/mobile/out/src/storage/schema/entities/EntitySyncState.d.ts.map +1 -0
  356. package/mobile/out/src/storage/schema/entities/EntitySyncState.js +319 -0
  357. package/mobile/out/src/storage/schema/entities/EntitySyncState.js.map +1 -0
  358. package/mobile/out/src/storage/schema/entities/EntityTransaction.d.ts +67 -0
  359. package/mobile/out/src/storage/schema/entities/EntityTransaction.d.ts.map +1 -0
  360. package/mobile/out/src/storage/schema/entities/EntityTransaction.js +255 -0
  361. package/mobile/out/src/storage/schema/entities/EntityTransaction.js.map +1 -0
  362. package/mobile/out/src/storage/schema/entities/EntityTxLabel.d.ts +31 -0
  363. package/mobile/out/src/storage/schema/entities/EntityTxLabel.d.ts.map +1 -0
  364. package/mobile/out/src/storage/schema/entities/EntityTxLabel.js +104 -0
  365. package/mobile/out/src/storage/schema/entities/EntityTxLabel.js.map +1 -0
  366. package/mobile/out/src/storage/schema/entities/EntityTxLabelMap.d.ts +28 -0
  367. package/mobile/out/src/storage/schema/entities/EntityTxLabelMap.d.ts.map +1 -0
  368. package/mobile/out/src/storage/schema/entities/EntityTxLabelMap.js +97 -0
  369. package/mobile/out/src/storage/schema/entities/EntityTxLabelMap.js.map +1 -0
  370. package/mobile/out/src/storage/schema/entities/EntityUser.d.ts +29 -0
  371. package/mobile/out/src/storage/schema/entities/EntityUser.d.ts.map +1 -0
  372. package/mobile/out/src/storage/schema/entities/EntityUser.js +98 -0
  373. package/mobile/out/src/storage/schema/entities/EntityUser.js.map +1 -0
  374. package/mobile/out/src/storage/schema/entities/MergeEntity.d.ts +33 -0
  375. package/mobile/out/src/storage/schema/entities/MergeEntity.d.ts.map +1 -0
  376. package/mobile/out/src/storage/schema/entities/MergeEntity.js +62 -0
  377. package/mobile/out/src/storage/schema/entities/MergeEntity.js.map +1 -0
  378. package/mobile/out/src/storage/schema/entities/index.d.ts +17 -0
  379. package/mobile/out/src/storage/schema/entities/index.d.ts.map +1 -0
  380. package/mobile/out/src/storage/schema/entities/index.js +33 -0
  381. package/mobile/out/src/storage/schema/entities/index.js.map +1 -0
  382. package/mobile/out/src/storage/schema/tables/TableCertificate.d.ts +20 -0
  383. package/mobile/out/src/storage/schema/tables/TableCertificate.d.ts.map +1 -0
  384. package/mobile/out/src/storage/schema/tables/TableCertificate.js +3 -0
  385. package/mobile/out/src/storage/schema/tables/TableCertificate.js.map +1 -0
  386. package/mobile/out/src/storage/schema/tables/TableCertificateField.d.ts +12 -0
  387. package/mobile/out/src/storage/schema/tables/TableCertificateField.d.ts.map +1 -0
  388. package/mobile/out/src/storage/schema/tables/TableCertificateField.js +3 -0
  389. package/mobile/out/src/storage/schema/tables/TableCertificateField.js.map +1 -0
  390. package/mobile/out/src/storage/schema/tables/TableCommission.d.ts +13 -0
  391. package/mobile/out/src/storage/schema/tables/TableCommission.d.ts.map +1 -0
  392. package/mobile/out/src/storage/schema/tables/TableCommission.js +3 -0
  393. package/mobile/out/src/storage/schema/tables/TableCommission.js.map +1 -0
  394. package/mobile/out/src/storage/schema/tables/TableMonitorEvent.d.ts +9 -0
  395. package/mobile/out/src/storage/schema/tables/TableMonitorEvent.d.ts.map +1 -0
  396. package/mobile/out/src/storage/schema/tables/TableMonitorEvent.js +3 -0
  397. package/mobile/out/src/storage/schema/tables/TableMonitorEvent.js.map +1 -0
  398. package/mobile/out/src/storage/schema/tables/TableOutput.d.ts +36 -0
  399. package/mobile/out/src/storage/schema/tables/TableOutput.d.ts.map +1 -0
  400. package/mobile/out/src/storage/schema/tables/TableOutput.js +31 -0
  401. package/mobile/out/src/storage/schema/tables/TableOutput.js.map +1 -0
  402. package/mobile/out/src/storage/schema/tables/TableOutputBasket.d.ts +12 -0
  403. package/mobile/out/src/storage/schema/tables/TableOutputBasket.d.ts.map +1 -0
  404. package/mobile/out/src/storage/schema/tables/TableOutputBasket.js +3 -0
  405. package/mobile/out/src/storage/schema/tables/TableOutputBasket.js.map +1 -0
  406. package/mobile/out/src/storage/schema/tables/TableOutputTag.d.ts +10 -0
  407. package/mobile/out/src/storage/schema/tables/TableOutputTag.d.ts.map +1 -0
  408. package/mobile/out/src/storage/schema/tables/TableOutputTag.js +3 -0
  409. package/mobile/out/src/storage/schema/tables/TableOutputTag.js.map +1 -0
  410. package/mobile/out/src/storage/schema/tables/TableOutputTagMap.d.ts +9 -0
  411. package/mobile/out/src/storage/schema/tables/TableOutputTagMap.d.ts.map +1 -0
  412. package/mobile/out/src/storage/schema/tables/TableOutputTagMap.js +3 -0
  413. package/mobile/out/src/storage/schema/tables/TableOutputTagMap.js.map +1 -0
  414. package/mobile/out/src/storage/schema/tables/TableProvenTx.d.ts +14 -0
  415. package/mobile/out/src/storage/schema/tables/TableProvenTx.d.ts.map +1 -0
  416. package/mobile/out/src/storage/schema/tables/TableProvenTx.js +3 -0
  417. package/mobile/out/src/storage/schema/tables/TableProvenTx.js.map +1 -0
  418. package/mobile/out/src/storage/schema/tables/TableProvenTxReq.d.ts +64 -0
  419. package/mobile/out/src/storage/schema/tables/TableProvenTxReq.d.ts.map +1 -0
  420. package/mobile/out/src/storage/schema/tables/TableProvenTxReq.js +3 -0
  421. package/mobile/out/src/storage/schema/tables/TableProvenTxReq.js.map +1 -0
  422. package/mobile/out/src/storage/schema/tables/TableSettings.d.ts +17 -0
  423. package/mobile/out/src/storage/schema/tables/TableSettings.d.ts.map +1 -0
  424. package/mobile/out/src/storage/schema/tables/TableSettings.js +3 -0
  425. package/mobile/out/src/storage/schema/tables/TableSettings.js.map +1 -0
  426. package/mobile/out/src/storage/schema/tables/TableSyncState.d.ts +18 -0
  427. package/mobile/out/src/storage/schema/tables/TableSyncState.d.ts.map +1 -0
  428. package/mobile/out/src/storage/schema/tables/TableSyncState.js +3 -0
  429. package/mobile/out/src/storage/schema/tables/TableSyncState.js.map +1 -0
  430. package/mobile/out/src/storage/schema/tables/TableTransaction.d.ts +37 -0
  431. package/mobile/out/src/storage/schema/tables/TableTransaction.d.ts.map +1 -0
  432. package/mobile/out/src/storage/schema/tables/TableTransaction.js +21 -0
  433. package/mobile/out/src/storage/schema/tables/TableTransaction.js.map +1 -0
  434. package/mobile/out/src/storage/schema/tables/TableTxLabel.d.ts +10 -0
  435. package/mobile/out/src/storage/schema/tables/TableTxLabel.d.ts.map +1 -0
  436. package/mobile/out/src/storage/schema/tables/TableTxLabel.js +3 -0
  437. package/mobile/out/src/storage/schema/tables/TableTxLabel.js.map +1 -0
  438. package/mobile/out/src/storage/schema/tables/TableTxLabelMap.d.ts +9 -0
  439. package/mobile/out/src/storage/schema/tables/TableTxLabelMap.d.ts.map +1 -0
  440. package/mobile/out/src/storage/schema/tables/TableTxLabelMap.js +3 -0
  441. package/mobile/out/src/storage/schema/tables/TableTxLabelMap.js.map +1 -0
  442. package/mobile/out/src/storage/schema/tables/TableUser.d.ts +16 -0
  443. package/mobile/out/src/storage/schema/tables/TableUser.d.ts.map +1 -0
  444. package/mobile/out/src/storage/schema/tables/TableUser.js +3 -0
  445. package/mobile/out/src/storage/schema/tables/TableUser.js.map +1 -0
  446. package/mobile/out/src/storage/schema/tables/index.d.ts +17 -0
  447. package/mobile/out/src/storage/schema/tables/index.d.ts.map +1 -0
  448. package/mobile/out/src/storage/schema/tables/index.js +33 -0
  449. package/mobile/out/src/storage/schema/tables/index.js.map +1 -0
  450. package/mobile/out/src/utility/ScriptTemplateBRC29.d.ts +25 -0
  451. package/mobile/out/src/utility/ScriptTemplateBRC29.d.ts.map +1 -0
  452. package/mobile/out/src/utility/ScriptTemplateBRC29.js +48 -0
  453. package/mobile/out/src/utility/ScriptTemplateBRC29.js.map +1 -0
  454. package/mobile/out/src/utility/identityUtils.d.ts +31 -0
  455. package/mobile/out/src/utility/identityUtils.d.ts.map +1 -0
  456. package/mobile/out/src/utility/identityUtils.js +116 -0
  457. package/mobile/out/src/utility/identityUtils.js.map +1 -0
  458. package/mobile/out/src/utility/index.client.d.ts +7 -0
  459. package/mobile/out/src/utility/index.client.d.ts.map +1 -0
  460. package/mobile/out/src/utility/index.client.js +23 -0
  461. package/mobile/out/src/utility/index.client.js.map +1 -0
  462. package/mobile/out/src/utility/parseTxScriptOffsets.d.ts +14 -0
  463. package/mobile/out/src/utility/parseTxScriptOffsets.d.ts.map +1 -0
  464. package/mobile/out/src/utility/parseTxScriptOffsets.js +26 -0
  465. package/mobile/out/src/utility/parseTxScriptOffsets.js.map +1 -0
  466. package/mobile/out/src/utility/stampLog.d.ts +18 -0
  467. package/mobile/out/src/utility/stampLog.d.ts.map +1 -0
  468. package/mobile/out/src/utility/stampLog.js +72 -0
  469. package/mobile/out/src/utility/stampLog.js.map +1 -0
  470. package/mobile/out/src/utility/tscProofToMerklePath.d.ts +8 -0
  471. package/mobile/out/src/utility/tscProofToMerklePath.d.ts.map +1 -0
  472. package/mobile/out/src/utility/tscProofToMerklePath.js +41 -0
  473. package/mobile/out/src/utility/tscProofToMerklePath.js.map +1 -0
  474. package/mobile/out/src/utility/utilityHelpers.d.ts +129 -0
  475. package/mobile/out/src/utility/utilityHelpers.d.ts.map +1 -0
  476. package/mobile/out/src/utility/utilityHelpers.js +266 -0
  477. package/mobile/out/src/utility/utilityHelpers.js.map +1 -0
  478. package/mobile/out/src/utility/utilityHelpers.noBuffer.d.ts +9 -0
  479. package/mobile/out/src/utility/utilityHelpers.noBuffer.d.ts.map +1 -0
  480. package/mobile/out/src/utility/utilityHelpers.noBuffer.js +23 -0
  481. package/mobile/out/src/utility/utilityHelpers.noBuffer.js.map +1 -0
  482. package/mobile/out/src/wab-client/WABClient.d.ts +49 -0
  483. package/mobile/out/src/wab-client/WABClient.d.ts.map +1 -0
  484. package/mobile/out/src/wab-client/WABClient.js +80 -0
  485. package/mobile/out/src/wab-client/WABClient.js.map +1 -0
  486. package/mobile/out/src/wab-client/auth-method-interactors/AuthMethodInteractor.d.ts +34 -0
  487. package/mobile/out/src/wab-client/auth-method-interactors/AuthMethodInteractor.d.ts.map +1 -0
  488. package/mobile/out/src/wab-client/auth-method-interactors/AuthMethodInteractor.js +16 -0
  489. package/mobile/out/src/wab-client/auth-method-interactors/AuthMethodInteractor.js.map +1 -0
  490. package/mobile/out/src/wab-client/auth-method-interactors/PersonaIDInteractor.d.ts +7 -0
  491. package/mobile/out/src/wab-client/auth-method-interactors/PersonaIDInteractor.d.ts.map +1 -0
  492. package/mobile/out/src/wab-client/auth-method-interactors/PersonaIDInteractor.js +36 -0
  493. package/mobile/out/src/wab-client/auth-method-interactors/PersonaIDInteractor.js.map +1 -0
  494. package/mobile/out/src/wab-client/auth-method-interactors/TwilioPhoneInteractor.d.ts +28 -0
  495. package/mobile/out/src/wab-client/auth-method-interactors/TwilioPhoneInteractor.d.ts.map +1 -0
  496. package/mobile/out/src/wab-client/auth-method-interactors/TwilioPhoneInteractor.js +69 -0
  497. package/mobile/out/src/wab-client/auth-method-interactors/TwilioPhoneInteractor.js.map +1 -0
  498. package/mobile/out/tsconfig.mobile.tsbuildinfo +1 -0
  499. package/mobile/package-lock.json +22 -0
  500. package/mobile/package.json +25 -0
  501. package/out/src/index.mobile.d.ts +19 -0
  502. package/out/src/index.mobile.d.ts.map +1 -0
  503. package/out/src/index.mobile.js +58 -0
  504. package/out/src/index.mobile.js.map +1 -0
  505. package/out/src/storage/index.mobile.d.ts +7 -0
  506. package/out/src/storage/index.mobile.d.ts.map +1 -0
  507. package/out/src/storage/index.mobile.js +23 -0
  508. package/out/src/storage/index.mobile.js.map +1 -0
  509. package/out/src/wab-client/WABClient.js +2 -5
  510. package/out/src/wab-client/WABClient.js.map +1 -1
  511. package/out/tsconfig.all.tsbuildinfo +1 -1
  512. package/package.json +1 -1
  513. package/src/index.mobile.ts +18 -0
  514. package/src/storage/index.mobile.ts +6 -0
  515. package/src/wab-client/WABClient.ts +2 -2
  516. package/tsconfig.json +3 -0
  517. package/tsconfig.mobile.json +22 -0
@@ -0,0 +1,2296 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StorageIdb = void 0;
4
+ const idb_1 = require("idb");
5
+ const index_client_1 = require("../index.client");
6
+ const StorageProvider_1 = require("./StorageProvider");
7
+ const listActionsIdb_1 = require("./methods/listActionsIdb");
8
+ const listOutputsIdb_1 = require("./methods/listOutputsIdb");
9
+ const reviewStatusIdb_1 = require("./methods/reviewStatusIdb");
10
+ const purgeDataIdb_1 = require("./methods/purgeDataIdb");
11
+ /**
12
+ * This class implements the `StorageProvider` interface using IndexedDB,
13
+ * via the promises wrapper package `idb`.
14
+ */
15
+ class StorageIdb extends StorageProvider_1.StorageProvider {
16
+ constructor(options) {
17
+ super(options);
18
+ this.allStores = [
19
+ 'certificates',
20
+ 'certificate_fields',
21
+ 'commissions',
22
+ 'monitor_events',
23
+ 'outputs',
24
+ 'output_baskets',
25
+ 'output_tags',
26
+ 'output_tags_map',
27
+ 'proven_txs',
28
+ 'proven_tx_reqs',
29
+ 'sync_states',
30
+ 'transactions',
31
+ 'tx_labels',
32
+ 'tx_labels_map',
33
+ 'users'
34
+ ];
35
+ this.dbName = `wallet-toolbox-${this.chain}net`;
36
+ }
37
+ /**
38
+ * This method must be called at least once before any other method accesses the database,
39
+ * and each time the schema may have updated.
40
+ *
41
+ * If the database has already been created in this context, `storageName` and `storageIdentityKey`
42
+ * are ignored.
43
+ *
44
+ * @param storageName
45
+ * @param storageIdentityKey
46
+ * @returns
47
+ */
48
+ async migrate(storageName, storageIdentityKey) {
49
+ const db = await this.verifyDB(storageName, storageIdentityKey);
50
+ return db.version.toString();
51
+ }
52
+ /**
53
+ * Following initial database initialization, this method verfies that db is ready for use.
54
+ *
55
+ * @throws `WERR_INVALID_OPERATION` if the database has not been initialized by a call to `migrate`.
56
+ *
57
+ * @param storageName
58
+ * @param storageIdentityKey
59
+ *
60
+ * @returns
61
+ */
62
+ async verifyDB(storageName, storageIdentityKey) {
63
+ if (this.db)
64
+ return this.db;
65
+ this.db = await this.initDB(storageName, storageIdentityKey);
66
+ this._settings = (await this.db.getAll('settings'))[0];
67
+ this.whenLastAccess = new Date();
68
+ return this.db;
69
+ }
70
+ /**
71
+ * Convert the standard optional `TrxToken` parameter into either a direct knex database instance,
72
+ * or a Knex.Transaction as appropriate.
73
+ */
74
+ toDbTrx(stores, mode, trx) {
75
+ if (trx) {
76
+ const t = trx;
77
+ return t;
78
+ }
79
+ else {
80
+ if (!this.db)
81
+ throw new Error('not initialized');
82
+ const db = this.db;
83
+ const trx = db.transaction(stores || this.allStores, mode || 'readwrite');
84
+ this.whenLastAccess = new Date();
85
+ return trx;
86
+ }
87
+ }
88
+ /**
89
+ * Called by `makeAvailable` to return storage `TableSettings`.
90
+ * Since this is the first async method that must be called by all clients,
91
+ * it is where async initialization occurs.
92
+ *
93
+ * After initialization, cached settings are returned.
94
+ *
95
+ * @param trx
96
+ */
97
+ async readSettings(trx) {
98
+ await this.verifyDB();
99
+ return this._settings;
100
+ }
101
+ async initDB(storageName, storageIdentityKey) {
102
+ const chain = this.chain;
103
+ const maxOutputScript = 1024;
104
+ const db = await (0, idb_1.openDB)(this.dbName, 1, {
105
+ upgrade(db, oldVersion, newVersion, transaction) {
106
+ if (!db.objectStoreNames.contains('proven_txs')) {
107
+ // proven_txs object store
108
+ const provenTxsStore = db.createObjectStore('proven_txs', {
109
+ keyPath: 'provenTxId',
110
+ autoIncrement: true
111
+ });
112
+ provenTxsStore.createIndex('txid', 'txid', { unique: true });
113
+ }
114
+ if (!db.objectStoreNames.contains('proven_tx_reqs')) {
115
+ // proven_tx_reqs object store
116
+ const provenTxReqsStore = db.createObjectStore('proven_tx_reqs', {
117
+ keyPath: 'provenTxReqId',
118
+ autoIncrement: true
119
+ });
120
+ provenTxReqsStore.createIndex('provenTxId', 'provenTxId');
121
+ provenTxReqsStore.createIndex('txid', 'txid', { unique: true });
122
+ provenTxReqsStore.createIndex('status', 'status');
123
+ provenTxReqsStore.createIndex('batch', 'batch');
124
+ }
125
+ if (!db.objectStoreNames.contains('users')) {
126
+ const users = db.createObjectStore('users', {
127
+ keyPath: 'userId',
128
+ autoIncrement: true
129
+ });
130
+ users.createIndex('identityKey', 'identityKey', { unique: true });
131
+ }
132
+ if (!db.objectStoreNames.contains('certificates')) {
133
+ // certificates object store
134
+ const certificatesStore = db.createObjectStore('certificates', {
135
+ keyPath: 'certificateId',
136
+ autoIncrement: true
137
+ });
138
+ certificatesStore.createIndex('userId', 'userId');
139
+ certificatesStore.createIndex('userId_type_certifier_serialNumber', ['userId', 'type', 'certifier', 'serialNumber'], { unique: true });
140
+ }
141
+ if (!db.objectStoreNames.contains('certificate_fields')) {
142
+ // certificate_fields object store
143
+ const certificateFieldsStore = db.createObjectStore('certificate_fields', {
144
+ keyPath: ['certificateId', 'fieldName'] // Composite key
145
+ });
146
+ certificateFieldsStore.createIndex('userId', 'userId');
147
+ certificateFieldsStore.createIndex('certificateId', 'certificateId');
148
+ }
149
+ if (!db.objectStoreNames.contains('output_baskets')) {
150
+ // output_baskets object store
151
+ const outputBasketsStore = db.createObjectStore('output_baskets', {
152
+ keyPath: 'basketId',
153
+ autoIncrement: true
154
+ });
155
+ outputBasketsStore.createIndex('userId', 'userId');
156
+ outputBasketsStore.createIndex('name_userId', ['name', 'userId'], { unique: true });
157
+ }
158
+ if (!db.objectStoreNames.contains('transactions')) {
159
+ // transactions object store
160
+ const transactionsStore = db.createObjectStore('transactions', {
161
+ keyPath: 'transactionId',
162
+ autoIncrement: true
163
+ });
164
+ transactionsStore.createIndex('userId', 'userId');
165
+ transactionsStore.createIndex('status', 'status'),
166
+ transactionsStore.createIndex('status_userId', ['status', 'userId']);
167
+ transactionsStore.createIndex('provenTxId', 'provenTxId');
168
+ transactionsStore.createIndex('reference', 'reference', { unique: true });
169
+ }
170
+ if (!db.objectStoreNames.contains('commissions')) {
171
+ // commissions object store
172
+ const commissionsStore = db.createObjectStore('commissions', {
173
+ keyPath: 'commissionId',
174
+ autoIncrement: true
175
+ });
176
+ commissionsStore.createIndex('userId', 'userId');
177
+ commissionsStore.createIndex('transactionId', 'transactionId', { unique: true });
178
+ }
179
+ if (!db.objectStoreNames.contains('outputs')) {
180
+ // outputs object store
181
+ const outputsStore = db.createObjectStore('outputs', {
182
+ keyPath: 'outputId',
183
+ autoIncrement: true
184
+ });
185
+ outputsStore.createIndex('userId', 'userId');
186
+ outputsStore.createIndex('transactionId', 'transactionId');
187
+ outputsStore.createIndex('basketId', 'basketId');
188
+ outputsStore.createIndex('spentBy', 'spentBy');
189
+ outputsStore.createIndex('transactionId_vout_userId', ['transactionId', 'vout', 'userId'], { unique: true });
190
+ }
191
+ if (!db.objectStoreNames.contains('output_tags')) {
192
+ // output_tags object store
193
+ const outputTagsStore = db.createObjectStore('output_tags', {
194
+ keyPath: 'outputTagId',
195
+ autoIncrement: true
196
+ });
197
+ outputTagsStore.createIndex('userId', 'userId');
198
+ outputTagsStore.createIndex('tag_userId', ['tag', 'userId'], { unique: true });
199
+ }
200
+ if (!db.objectStoreNames.contains('output_tags_map')) {
201
+ // output_tags_map object store
202
+ const outputTagsMapStore = db.createObjectStore('output_tags_map', {
203
+ keyPath: ['outputTagId', 'outputId']
204
+ });
205
+ outputTagsMapStore.createIndex('outputTagId', 'outputTagId');
206
+ outputTagsMapStore.createIndex('outputId', 'outputId');
207
+ }
208
+ if (!db.objectStoreNames.contains('tx_labels')) {
209
+ // tx_labels object store
210
+ const txLabelsStore = db.createObjectStore('tx_labels', {
211
+ keyPath: 'txLabelId',
212
+ autoIncrement: true
213
+ });
214
+ txLabelsStore.createIndex('userId', 'userId');
215
+ txLabelsStore.createIndex('label_userId', ['label', 'userId'], { unique: true });
216
+ }
217
+ if (!db.objectStoreNames.contains('tx_labels_map')) {
218
+ // tx_labels_map object store
219
+ const txLabelsMapStore = db.createObjectStore('tx_labels_map', {
220
+ keyPath: ['txLabelId', 'transactionId']
221
+ });
222
+ txLabelsMapStore.createIndex('txLabelId', 'txLabelId');
223
+ txLabelsMapStore.createIndex('transactionId', 'transactionId');
224
+ }
225
+ if (!db.objectStoreNames.contains('monitor_events')) {
226
+ // monitor_events object store
227
+ const monitorEventsStore = db.createObjectStore('monitor_events', {
228
+ keyPath: 'id',
229
+ autoIncrement: true
230
+ });
231
+ }
232
+ if (!db.objectStoreNames.contains('sync_states')) {
233
+ // sync_states object store
234
+ const syncStatesStore = db.createObjectStore('sync_states', {
235
+ keyPath: 'syncStateId',
236
+ autoIncrement: true
237
+ });
238
+ syncStatesStore.createIndex('userId', 'userId');
239
+ syncStatesStore.createIndex('refNum', 'refNum', { unique: true });
240
+ syncStatesStore.createIndex('status', 'status');
241
+ }
242
+ if (!db.objectStoreNames.contains('settings')) {
243
+ if (!storageName || !storageIdentityKey) {
244
+ throw new index_client_1.sdk.WERR_INVALID_OPERATION('migrate must be called before first access');
245
+ }
246
+ const settings = db.createObjectStore('settings', {
247
+ keyPath: 'storageIdentityKey'
248
+ });
249
+ const s = {
250
+ created_at: new Date(),
251
+ updated_at: new Date(),
252
+ storageIdentityKey,
253
+ storageName,
254
+ chain,
255
+ dbtype: 'IndexedDB',
256
+ maxOutputScript
257
+ };
258
+ settings.put(s);
259
+ }
260
+ }
261
+ });
262
+ return db;
263
+ }
264
+ //
265
+ // StorageProvider abstract methods
266
+ //
267
+ async reviewStatus(args) {
268
+ return await (0, reviewStatusIdb_1.reviewStatusIdb)(this, args);
269
+ }
270
+ async purgeData(params, trx) {
271
+ return await (0, purgeDataIdb_1.purgeDataIdb)(this, params, trx);
272
+ }
273
+ /**
274
+ * Proceeds in three stages:
275
+ * 1. Find an output that exactly funds the transaction (if exactSatoshis is not undefined).
276
+ * 2. Find an output that overfunds by the least amount (targetSatoshis).
277
+ * 3. Find an output that comes as close to funding as possible (targetSatoshis).
278
+ * 4. Return undefined if no output is found.
279
+ *
280
+ * Outputs must belong to userId and basketId and have spendable true.
281
+ * Their corresponding transaction must have status of 'completed', 'unproven', or 'sending' (if excludeSending is false).
282
+ *
283
+ * @param userId
284
+ * @param basketId
285
+ * @param targetSatoshis
286
+ * @param exactSatoshis
287
+ * @param excludeSending
288
+ * @param transactionId
289
+ * @returns next funding output to add to transaction or undefined if there are none.
290
+ */
291
+ async allocateChangeInput(userId, basketId, targetSatoshis, exactSatoshis, excludeSending, transactionId) {
292
+ const dbTrx = this.toDbTrx(['outputs', 'transactions'], 'readwrite');
293
+ try {
294
+ const txStatus = ['completed', 'unproven'];
295
+ if (!excludeSending)
296
+ txStatus.push('sending');
297
+ const args = {
298
+ partial: { userId, basketId, spendable: true },
299
+ txStatus,
300
+ trx: dbTrx
301
+ };
302
+ const outputs = await this.findOutputs(args);
303
+ let output;
304
+ let scores = [];
305
+ for (const o of outputs) {
306
+ if (exactSatoshis && o.satoshis === exactSatoshis) {
307
+ output = o;
308
+ break;
309
+ }
310
+ const score = o.satoshis - targetSatoshis;
311
+ scores.push({ output: o, score });
312
+ }
313
+ if (!output) {
314
+ // sort scores increasing by score property
315
+ scores = scores.sort((a, b) => a.score - b.score);
316
+ // find the first score that is greater than or equal to 0
317
+ const o = scores.find(s => s.score >= 0);
318
+ if (o) {
319
+ // stage 2 satisfied (minimally funded)
320
+ output = o.output;
321
+ }
322
+ else if (scores.length > 0) {
323
+ // stage 3 satisfied (minimally under-funded)
324
+ output = scores.slice(-1)[0].output;
325
+ }
326
+ else {
327
+ // no available funding outputs
328
+ output = undefined;
329
+ }
330
+ }
331
+ if (output) {
332
+ // mark output as spent by transactionId
333
+ await this.updateOutput(output.outputId, { spendable: false, spentBy: transactionId }, dbTrx);
334
+ }
335
+ return output;
336
+ }
337
+ finally {
338
+ await dbTrx.done;
339
+ }
340
+ }
341
+ async getProvenOrRawTx(txid, trx) {
342
+ const r = {
343
+ proven: undefined,
344
+ rawTx: undefined,
345
+ inputBEEF: undefined
346
+ };
347
+ r.proven = (0, index_client_1.verifyOneOrNone)(await this.findProvenTxs({ partial: { txid: txid }, trx }));
348
+ if (!r.proven) {
349
+ const req = (0, index_client_1.verifyOneOrNone)(await this.findProvenTxReqs({ partial: { txid: txid }, trx }));
350
+ if (req && ['unsent', 'unmined', 'unconfirmed', 'sending', 'nosend', 'completed'].includes(req.status)) {
351
+ r.rawTx = req.rawTx;
352
+ r.inputBEEF = req.inputBEEF;
353
+ }
354
+ }
355
+ return r;
356
+ }
357
+ async getRawTxOfKnownValidTransaction(txid, offset, length, trx) {
358
+ if (!txid)
359
+ return undefined;
360
+ if (!this.isAvailable())
361
+ await this.makeAvailable();
362
+ let rawTx = undefined;
363
+ const r = await this.getProvenOrRawTx(txid, trx);
364
+ if (r.proven)
365
+ rawTx = r.proven.rawTx;
366
+ else
367
+ rawTx = r.rawTx;
368
+ if (rawTx && offset !== undefined && length !== undefined && Number.isInteger(offset) && Number.isInteger(length)) {
369
+ rawTx = rawTx.slice(offset, offset + length);
370
+ }
371
+ return rawTx;
372
+ }
373
+ async getLabelsForTransactionId(transactionId, trx) {
374
+ const maps = await this.findTxLabelMaps({ partial: { transactionId, isDeleted: false }, trx });
375
+ const labelIds = maps.map(m => m.txLabelId);
376
+ const labels = [];
377
+ for (const txLabelId of labelIds) {
378
+ const label = (0, index_client_1.verifyOne)(await this.findTxLabels({ partial: { txLabelId, isDeleted: false }, trx }));
379
+ labels.push(label);
380
+ }
381
+ return labels;
382
+ }
383
+ async getTagsForOutputId(outputId, trx) {
384
+ const maps = await this.findOutputTagMaps({ partial: { outputId, isDeleted: false }, trx });
385
+ const tagIds = maps.map(m => m.outputTagId);
386
+ const tags = [];
387
+ for (const outputTagId of tagIds) {
388
+ const tag = (0, index_client_1.verifyOne)(await this.findOutputTags({ partial: { outputTagId, isDeleted: false }, trx }));
389
+ tags.push(tag);
390
+ }
391
+ return tags;
392
+ }
393
+ async listActions(auth, vargs) {
394
+ if (!auth.userId)
395
+ throw new index_client_1.sdk.WERR_UNAUTHORIZED();
396
+ return await (0, listActionsIdb_1.listActionsIdb)(this, auth, vargs);
397
+ }
398
+ async listOutputs(auth, vargs) {
399
+ if (!auth.userId)
400
+ throw new index_client_1.sdk.WERR_UNAUTHORIZED();
401
+ return await (0, listOutputsIdb_1.listOutputsIdb)(this, auth, vargs);
402
+ }
403
+ async countChangeInputs(userId, basketId, excludeSending) {
404
+ const txStatus = ['completed', 'unproven'];
405
+ if (!excludeSending)
406
+ txStatus.push('sending');
407
+ const args = { partial: { userId, basketId }, txStatus };
408
+ let count = 0;
409
+ await this.filterOutputs(args, r => {
410
+ count++;
411
+ });
412
+ return count;
413
+ }
414
+ async findCertificatesAuth(auth, args) {
415
+ if (!auth.userId || (args.partial.userId && args.partial.userId !== auth.userId))
416
+ throw new index_client_1.sdk.WERR_UNAUTHORIZED();
417
+ args.partial.userId = auth.userId;
418
+ return await this.findCertificates(args);
419
+ }
420
+ async findOutputBasketsAuth(auth, args) {
421
+ if (!auth.userId || (args.partial.userId && args.partial.userId !== auth.userId))
422
+ throw new index_client_1.sdk.WERR_UNAUTHORIZED();
423
+ args.partial.userId = auth.userId;
424
+ return await this.findOutputBaskets(args);
425
+ }
426
+ async findOutputsAuth(auth, args) {
427
+ if (!auth.userId || (args.partial.userId && args.partial.userId !== auth.userId))
428
+ throw new index_client_1.sdk.WERR_UNAUTHORIZED();
429
+ args.partial.userId = auth.userId;
430
+ return await this.findOutputs(args);
431
+ }
432
+ async insertCertificateAuth(auth, certificate) {
433
+ if (!auth.userId || (certificate.userId && certificate.userId !== auth.userId))
434
+ throw new index_client_1.sdk.WERR_UNAUTHORIZED();
435
+ certificate.userId = auth.userId;
436
+ return await this.insertCertificate(certificate);
437
+ }
438
+ //
439
+ // StorageReaderWriter abstract methods
440
+ //
441
+ async dropAllData() {
442
+ await (0, idb_1.deleteDB)(this.dbName);
443
+ }
444
+ async filterOutputTagMaps(args, filtered, userId) {
445
+ var _a, _b, _c, _d;
446
+ const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
447
+ let skipped = 0;
448
+ let count = 0;
449
+ const dbTrx = this.toDbTrx(['output_tags_map'], 'readonly', args.trx);
450
+ let cursor;
451
+ if (((_b = args.partial) === null || _b === void 0 ? void 0 : _b.outputTagId) !== undefined) {
452
+ cursor = await dbTrx.objectStore('output_tags_map').index('outputTagId').openCursor(args.partial.outputTagId);
453
+ }
454
+ else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.outputId) !== undefined) {
455
+ cursor = await dbTrx.objectStore('output_tags_map').index('outputId').openCursor(args.partial.outputId);
456
+ }
457
+ else {
458
+ cursor = await dbTrx.objectStore('output_tags_map').openCursor();
459
+ }
460
+ let firstTime = true;
461
+ while (cursor) {
462
+ if (!firstTime)
463
+ cursor = await cursor.continue();
464
+ if (!cursor)
465
+ break;
466
+ firstTime = false;
467
+ const r = cursor.value;
468
+ if (args.since && args.since > r.updated_at)
469
+ continue;
470
+ if (args.tagIds && !args.tagIds.includes(r.outputTagId))
471
+ continue;
472
+ if (args.partial) {
473
+ if (args.partial.outputTagId && r.outputTagId !== args.partial.outputTagId)
474
+ continue;
475
+ if (args.partial.outputId && r.outputId !== args.partial.outputId)
476
+ continue;
477
+ if (args.partial.created_at && r.created_at.getTime() !== args.partial.created_at.getTime())
478
+ continue;
479
+ if (args.partial.updated_at && r.updated_at.getTime() !== args.partial.updated_at.getTime())
480
+ continue;
481
+ if (args.partial.isDeleted !== undefined && r.isDeleted !== args.partial.isDeleted)
482
+ continue;
483
+ }
484
+ if (userId !== undefined && r.txid) {
485
+ const count = await this.countOutputTags({ partial: { userId, outputTagId: r.outputTagId }, trx: args.trx });
486
+ if (count === 0)
487
+ continue;
488
+ }
489
+ if (skipped < offset) {
490
+ skipped++;
491
+ continue;
492
+ }
493
+ filtered(r);
494
+ count++;
495
+ if (((_d = args.paged) === null || _d === void 0 ? void 0 : _d.limit) && count >= args.paged.limit)
496
+ break;
497
+ }
498
+ if (!args.trx)
499
+ await dbTrx.done;
500
+ }
501
+ async findOutputTagMaps(args) {
502
+ const results = [];
503
+ await this.filterOutputTagMaps(args, r => {
504
+ results.push(this.validateEntity(r));
505
+ });
506
+ return results;
507
+ }
508
+ async filterProvenTxReqs(args, filtered, userId) {
509
+ var _a, _b, _c, _d, _e, _f, _g;
510
+ if (args.partial.rawTx)
511
+ throw new index_client_1.sdk.WERR_INVALID_PARAMETER('args.partial.rawTx', `undefined. ProvenTxReqs may not be found by rawTx value.`);
512
+ if (args.partial.inputBEEF)
513
+ throw new index_client_1.sdk.WERR_INVALID_PARAMETER('args.partial.inputBEEF', `undefined. ProvenTxReqs may not be found by inputBEEF value.`);
514
+ const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
515
+ let skipped = 0;
516
+ let count = 0;
517
+ const dbTrx = this.toDbTrx(['proven_tx_reqs'], 'readonly', args.trx);
518
+ let cursor;
519
+ if ((_b = args.partial) === null || _b === void 0 ? void 0 : _b.provenTxReqId) {
520
+ cursor = await dbTrx.objectStore('proven_tx_reqs').openCursor(args.partial.provenTxReqId);
521
+ }
522
+ else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.provenTxId) !== undefined) {
523
+ cursor = await dbTrx.objectStore('proven_tx_reqs').index('provenTxId').openCursor(args.partial.provenTxId);
524
+ }
525
+ else if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.txid) !== undefined) {
526
+ cursor = await dbTrx.objectStore('proven_tx_reqs').index('txid').openCursor(args.partial.txid);
527
+ }
528
+ else if (((_e = args.partial) === null || _e === void 0 ? void 0 : _e.status) !== undefined) {
529
+ cursor = await dbTrx.objectStore('proven_tx_reqs').index('status').openCursor(args.partial.status);
530
+ }
531
+ else if (((_f = args.partial) === null || _f === void 0 ? void 0 : _f.batch) !== undefined) {
532
+ cursor = await dbTrx.objectStore('proven_tx_reqs').index('batch').openCursor(args.partial.batch);
533
+ }
534
+ else {
535
+ cursor = await dbTrx.objectStore('proven_tx_reqs').openCursor();
536
+ }
537
+ let firstTime = true;
538
+ while (cursor) {
539
+ if (!firstTime)
540
+ cursor = await cursor.continue();
541
+ if (!cursor)
542
+ break;
543
+ firstTime = false;
544
+ const r = cursor.value;
545
+ if (args.since && args.since > r.updated_at)
546
+ continue;
547
+ if (args.partial) {
548
+ if (args.partial.provenTxReqId && r.provenTxReqId !== args.partial.provenTxReqId)
549
+ continue;
550
+ if (args.partial.provenTxId && r.provenTxId !== args.partial.provenTxId)
551
+ continue;
552
+ if (args.partial.created_at && r.created_at.getTime() !== args.partial.created_at.getTime())
553
+ continue;
554
+ if (args.partial.updated_at && r.updated_at.getTime() !== args.partial.updated_at.getTime())
555
+ continue;
556
+ if (args.partial.status && r.status !== args.partial.status)
557
+ continue;
558
+ if (args.partial.attempts !== undefined && r.attempts !== args.partial.attempts)
559
+ continue;
560
+ if (args.partial.notified !== undefined && r.notified !== args.partial.notified)
561
+ continue;
562
+ if (args.partial.txid && r.txid !== args.partial.txid)
563
+ continue;
564
+ if (args.partial.batch && r.batch !== args.partial.batch)
565
+ continue;
566
+ if (args.partial.history && r.history !== args.partial.history)
567
+ continue;
568
+ if (args.partial.notify && r.notify !== args.partial.notify)
569
+ continue;
570
+ }
571
+ if (userId !== undefined && r.txid) {
572
+ const count = await this.countTransactions({ partial: { userId, txid: r.txid }, trx: args.trx });
573
+ if (count === 0)
574
+ continue;
575
+ }
576
+ if (skipped < offset) {
577
+ skipped++;
578
+ continue;
579
+ }
580
+ filtered(r);
581
+ count++;
582
+ if (((_g = args.paged) === null || _g === void 0 ? void 0 : _g.limit) && count >= args.paged.limit)
583
+ break;
584
+ }
585
+ if (!args.trx)
586
+ await dbTrx.done;
587
+ }
588
+ async findProvenTxReqs(args) {
589
+ const results = [];
590
+ await this.filterProvenTxReqs(args, r => {
591
+ results.push(this.validateEntity(r));
592
+ });
593
+ return results;
594
+ }
595
+ async filterProvenTxs(args, filtered, userId) {
596
+ var _a, _b, _c, _d;
597
+ if (args.partial.rawTx)
598
+ throw new index_client_1.sdk.WERR_INVALID_PARAMETER('args.partial.rawTx', `undefined. ProvenTxs may not be found by rawTx value.`);
599
+ if (args.partial.merklePath)
600
+ throw new index_client_1.sdk.WERR_INVALID_PARAMETER('args.partial.merklePath', `undefined. ProvenTxs may not be found by merklePath value.`);
601
+ const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
602
+ let skipped = 0;
603
+ let count = 0;
604
+ const dbTrx = this.toDbTrx(['proven_txs'], 'readonly', args.trx);
605
+ let cursor;
606
+ if ((_b = args.partial) === null || _b === void 0 ? void 0 : _b.provenTxId) {
607
+ cursor = await dbTrx.objectStore('proven_txs').openCursor(args.partial.provenTxId);
608
+ }
609
+ else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.txid) !== undefined) {
610
+ cursor = await dbTrx.objectStore('proven_txs').index('txid').openCursor(args.partial.txid);
611
+ }
612
+ else {
613
+ cursor = await dbTrx.objectStore('proven_txs').openCursor();
614
+ }
615
+ let firstTime = true;
616
+ while (cursor) {
617
+ if (!firstTime)
618
+ cursor = await cursor.continue();
619
+ if (!cursor)
620
+ break;
621
+ firstTime = false;
622
+ const r = cursor.value;
623
+ if (args.since && args.since > r.updated_at)
624
+ continue;
625
+ if (args.partial) {
626
+ if (args.partial.provenTxId && r.provenTxId !== args.partial.provenTxId)
627
+ continue;
628
+ if (args.partial.created_at && r.created_at.getTime() !== args.partial.created_at.getTime())
629
+ continue;
630
+ if (args.partial.updated_at && r.updated_at.getTime() !== args.partial.updated_at.getTime())
631
+ continue;
632
+ if (args.partial.txid && r.txid !== args.partial.txid)
633
+ continue;
634
+ if (args.partial.height !== undefined && r.height !== args.partial.height)
635
+ continue;
636
+ if (args.partial.index !== undefined && r.index !== args.partial.index)
637
+ continue;
638
+ if (args.partial.blockHash && r.blockHash !== args.partial.blockHash)
639
+ continue;
640
+ if (args.partial.merkleRoot && r.merkleRoot !== args.partial.merkleRoot)
641
+ continue;
642
+ }
643
+ if (userId !== undefined) {
644
+ const count = await this.countTransactions({ partial: { userId, provenTxId: r.provenTxId }, trx: args.trx });
645
+ if (count === 0)
646
+ continue;
647
+ }
648
+ if (skipped < offset) {
649
+ skipped++;
650
+ continue;
651
+ }
652
+ filtered(r);
653
+ count++;
654
+ if (((_d = args.paged) === null || _d === void 0 ? void 0 : _d.limit) && count >= args.paged.limit)
655
+ break;
656
+ }
657
+ if (!args.trx)
658
+ await dbTrx.done;
659
+ }
660
+ async findProvenTxs(args) {
661
+ const results = [];
662
+ await this.filterProvenTxs(args, r => {
663
+ results.push(this.validateEntity(r));
664
+ });
665
+ return results;
666
+ }
667
+ async filterTxLabelMaps(args, filtered, userId) {
668
+ var _a, _b, _c, _d;
669
+ const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
670
+ let skipped = 0;
671
+ let count = 0;
672
+ const dbTrx = this.toDbTrx(['tx_labels_map'], 'readonly', args.trx);
673
+ let cursor;
674
+ if (((_b = args.partial) === null || _b === void 0 ? void 0 : _b.transactionId) !== undefined) {
675
+ cursor = await dbTrx.objectStore('tx_labels_map').index('transactionId').openCursor(args.partial.transactionId);
676
+ }
677
+ else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.txLabelId) !== undefined) {
678
+ cursor = await dbTrx.objectStore('tx_labels_map').index('txLabelId').openCursor(args.partial.txLabelId);
679
+ }
680
+ else {
681
+ cursor = await dbTrx.objectStore('tx_labels_map').openCursor();
682
+ }
683
+ let firstTime = true;
684
+ while (cursor) {
685
+ if (!firstTime)
686
+ cursor = await cursor.continue();
687
+ if (!cursor)
688
+ break;
689
+ firstTime = false;
690
+ const r = cursor.value;
691
+ if (args.since && args.since > r.updated_at)
692
+ continue;
693
+ if (args.partial) {
694
+ if (args.partial.txLabelId && r.txLabelId !== args.partial.txLabelId)
695
+ continue;
696
+ if (args.partial.transactionId && r.transactionId !== args.partial.transactionId)
697
+ continue;
698
+ if (args.partial.created_at && r.created_at.getTime() !== args.partial.created_at.getTime())
699
+ continue;
700
+ if (args.partial.updated_at && r.updated_at.getTime() !== args.partial.updated_at.getTime())
701
+ continue;
702
+ if (args.partial.isDeleted !== undefined && r.isDeleted !== args.partial.isDeleted)
703
+ continue;
704
+ }
705
+ if (userId !== undefined) {
706
+ const count = await this.countTxLabels({ partial: { userId, txLabelId: r.txLabelId }, trx: args.trx });
707
+ if (count === 0)
708
+ continue;
709
+ }
710
+ if (skipped < offset) {
711
+ skipped++;
712
+ continue;
713
+ }
714
+ filtered(r);
715
+ count++;
716
+ if (((_d = args.paged) === null || _d === void 0 ? void 0 : _d.limit) && count >= args.paged.limit)
717
+ break;
718
+ }
719
+ if (!args.trx)
720
+ await dbTrx.done;
721
+ }
722
+ async findTxLabelMaps(args) {
723
+ const results = [];
724
+ await this.filterTxLabelMaps(args, r => {
725
+ results.push(this.validateEntity(r));
726
+ });
727
+ return results;
728
+ }
729
+ async countOutputTagMaps(args) {
730
+ let count = 0;
731
+ await this.filterOutputTagMaps(args, () => {
732
+ count++;
733
+ });
734
+ return count;
735
+ }
736
+ async countProvenTxReqs(args) {
737
+ let count = 0;
738
+ await this.filterProvenTxReqs(args, () => {
739
+ count++;
740
+ });
741
+ return count;
742
+ }
743
+ async countProvenTxs(args) {
744
+ let count = 0;
745
+ await this.filterProvenTxs(args, () => {
746
+ count++;
747
+ });
748
+ return count;
749
+ }
750
+ async countTxLabelMaps(args) {
751
+ let count = 0;
752
+ await this.filterTxLabelMaps(args, () => {
753
+ count++;
754
+ });
755
+ return count;
756
+ }
757
+ async insertCertificate(certificate, trx) {
758
+ const e = await this.validateEntityForInsert(certificate, trx, undefined, ['isDeleted']);
759
+ const fields = e.fields;
760
+ if (e.fields)
761
+ delete e.fields;
762
+ if (e.certificateId === 0)
763
+ delete e.certificateId;
764
+ const dbTrx = this.toDbTrx(['certificates', 'certificate_fields'], 'readwrite', trx);
765
+ const store = dbTrx.objectStore('certificates');
766
+ try {
767
+ const id = Number(await store.add(e));
768
+ certificate.certificateId = id;
769
+ if (fields) {
770
+ for (const field of fields) {
771
+ field.certificateId = certificate.certificateId;
772
+ field.userId = certificate.userId;
773
+ await this.insertCertificateField(field, dbTrx);
774
+ }
775
+ }
776
+ }
777
+ finally {
778
+ if (!trx)
779
+ await dbTrx.done;
780
+ }
781
+ return certificate.certificateId;
782
+ }
783
+ async insertCertificateField(certificateField, trx) {
784
+ const e = await this.validateEntityForInsert(certificateField, trx);
785
+ const dbTrx = this.toDbTrx(['certificate_fields'], 'readwrite', trx);
786
+ const store = dbTrx.objectStore('certificate_fields');
787
+ try {
788
+ await store.add(e);
789
+ }
790
+ finally {
791
+ if (!trx)
792
+ await dbTrx.done;
793
+ }
794
+ }
795
+ async insertCommission(commission, trx) {
796
+ const e = await this.validateEntityForInsert(commission, trx);
797
+ if (e.commissionId === 0)
798
+ delete e.commissionId;
799
+ const dbTrx = this.toDbTrx(['commissions'], 'readwrite', trx);
800
+ const store = dbTrx.objectStore('commissions');
801
+ try {
802
+ const id = Number(await store.add(e));
803
+ commission.commissionId = id;
804
+ }
805
+ finally {
806
+ if (!trx)
807
+ await dbTrx.done;
808
+ }
809
+ return commission.commissionId;
810
+ }
811
+ async insertMonitorEvent(event, trx) {
812
+ const e = await this.validateEntityForInsert(event, trx);
813
+ if (e.id === 0)
814
+ delete e.id;
815
+ const dbTrx = this.toDbTrx(['monitor_events'], 'readwrite', trx);
816
+ const store = dbTrx.objectStore('monitor_events');
817
+ try {
818
+ const id = Number(await store.add(e));
819
+ event.id = id;
820
+ }
821
+ finally {
822
+ if (!trx)
823
+ await dbTrx.done;
824
+ }
825
+ return event.id;
826
+ }
827
+ async insertOutput(output, trx) {
828
+ const e = await this.validateEntityForInsert(output, trx);
829
+ if (e.outputId === 0)
830
+ delete e.outputId;
831
+ const dbTrx = this.toDbTrx(['outputs'], 'readwrite', trx);
832
+ const store = dbTrx.objectStore('outputs');
833
+ try {
834
+ const id = Number(await store.add(e));
835
+ output.outputId = id;
836
+ }
837
+ finally {
838
+ if (!trx)
839
+ await dbTrx.done;
840
+ }
841
+ return output.outputId;
842
+ }
843
+ async insertOutputBasket(basket, trx) {
844
+ const e = await this.validateEntityForInsert(basket, trx, undefined, ['isDeleted']);
845
+ if (e.basketId === 0)
846
+ delete e.basketId;
847
+ const dbTrx = this.toDbTrx(['output_baskets'], 'readwrite', trx);
848
+ const store = dbTrx.objectStore('output_baskets');
849
+ try {
850
+ const id = Number(await store.add(e));
851
+ basket.basketId = id;
852
+ }
853
+ finally {
854
+ if (!trx)
855
+ await dbTrx.done;
856
+ }
857
+ return basket.basketId;
858
+ }
859
+ async insertOutputTag(tag, trx) {
860
+ const e = await this.validateEntityForInsert(tag, trx, undefined, ['isDeleted']);
861
+ if (e.outputTagId === 0)
862
+ delete e.outputTagId;
863
+ const dbTrx = this.toDbTrx(['output_tags'], 'readwrite', trx);
864
+ const store = dbTrx.objectStore('output_tags');
865
+ try {
866
+ const id = Number(await store.add(e));
867
+ tag.outputTagId = id;
868
+ }
869
+ finally {
870
+ if (!trx)
871
+ await dbTrx.done;
872
+ }
873
+ return tag.outputTagId;
874
+ }
875
+ async insertOutputTagMap(tagMap, trx) {
876
+ const e = await this.validateEntityForInsert(tagMap, trx, undefined, ['isDeleted']);
877
+ const dbTrx = this.toDbTrx(['output_tags_map'], 'readwrite', trx);
878
+ const store = dbTrx.objectStore('output_tags_map');
879
+ try {
880
+ await store.add(e);
881
+ }
882
+ finally {
883
+ if (!trx)
884
+ await dbTrx.done;
885
+ }
886
+ }
887
+ async insertProvenTx(tx, trx) {
888
+ const e = await this.validateEntityForInsert(tx, trx);
889
+ if (e.provenTxId === 0)
890
+ delete e.provenTxId;
891
+ const dbTrx = this.toDbTrx(['proven_txs'], 'readwrite', trx);
892
+ const store = dbTrx.objectStore('proven_txs');
893
+ try {
894
+ const id = Number(await store.add(e));
895
+ tx.provenTxId = id;
896
+ }
897
+ finally {
898
+ if (!trx)
899
+ await dbTrx.done;
900
+ }
901
+ return tx.provenTxId;
902
+ }
903
+ async insertProvenTxReq(tx, trx) {
904
+ const e = await this.validateEntityForInsert(tx, trx);
905
+ if (e.provenTxReqId === 0)
906
+ delete e.provenTxReqId;
907
+ const dbTrx = this.toDbTrx(['proven_tx_reqs'], 'readwrite', trx);
908
+ const store = dbTrx.objectStore('proven_tx_reqs');
909
+ try {
910
+ const id = Number(await store.add(e));
911
+ tx.provenTxReqId = id;
912
+ }
913
+ finally {
914
+ if (!trx)
915
+ await dbTrx.done;
916
+ }
917
+ return tx.provenTxReqId;
918
+ }
919
+ async insertSyncState(syncState, trx) {
920
+ const e = await this.validateEntityForInsert(syncState, trx, ['when'], ['init']);
921
+ if (e.syncStateId === 0)
922
+ delete e.syncStateId;
923
+ const dbTrx = this.toDbTrx(['sync_states'], 'readwrite', trx);
924
+ const store = dbTrx.objectStore('sync_states');
925
+ try {
926
+ const id = Number(await store.add(e));
927
+ syncState.syncStateId = id;
928
+ }
929
+ finally {
930
+ if (!trx)
931
+ await dbTrx.done;
932
+ }
933
+ return syncState.syncStateId;
934
+ }
935
+ async insertTransaction(tx, trx) {
936
+ const e = await this.validateEntityForInsert(tx, trx);
937
+ if (e.transactionId === 0)
938
+ delete e.transactionId;
939
+ const dbTrx = this.toDbTrx(['transactions'], 'readwrite', trx);
940
+ const store = dbTrx.objectStore('transactions');
941
+ try {
942
+ const id = Number(await store.add(e));
943
+ tx.transactionId = id;
944
+ }
945
+ finally {
946
+ if (!trx)
947
+ await dbTrx.done;
948
+ }
949
+ return tx.transactionId;
950
+ }
951
+ async insertTxLabel(label, trx) {
952
+ const e = await this.validateEntityForInsert(label, trx, undefined, ['isDeleted']);
953
+ if (e.txLabelId === 0)
954
+ delete e.txLabelId;
955
+ const dbTrx = this.toDbTrx(['tx_labels'], 'readwrite', trx);
956
+ const store = dbTrx.objectStore('tx_labels');
957
+ try {
958
+ const id = Number(await store.add(e));
959
+ label.txLabelId = id;
960
+ }
961
+ finally {
962
+ if (!trx)
963
+ await dbTrx.done;
964
+ }
965
+ return label.txLabelId;
966
+ }
967
+ async insertTxLabelMap(labelMap, trx) {
968
+ const e = await this.validateEntityForInsert(labelMap, trx, undefined, ['isDeleted']);
969
+ const dbTrx = this.toDbTrx(['tx_labels_map'], 'readwrite', trx);
970
+ const store = dbTrx.objectStore('tx_labels_map');
971
+ try {
972
+ await store.add(e);
973
+ }
974
+ finally {
975
+ if (!trx)
976
+ await dbTrx.done;
977
+ }
978
+ }
979
+ async insertUser(user, trx) {
980
+ const e = await this.validateEntityForInsert(user, trx);
981
+ if (e.userId === 0)
982
+ delete e.userId;
983
+ const dbTrx = this.toDbTrx(['users'], 'readwrite', trx);
984
+ const store = dbTrx.objectStore('users');
985
+ try {
986
+ const id = Number(await store.add(e));
987
+ user.userId = id;
988
+ }
989
+ finally {
990
+ if (!trx)
991
+ await dbTrx.done;
992
+ }
993
+ return user.userId;
994
+ }
995
+ async updateIdb(id, update, keyProp, storeName, trx) {
996
+ if (update[keyProp] !== undefined && (Array.isArray(id) || update[keyProp] !== id)) {
997
+ throw new index_client_1.sdk.WERR_INVALID_PARAMETER(`update.${keyProp}`, `undefined`);
998
+ }
999
+ const u = this.validatePartialForUpdate(update);
1000
+ const dbTrx = this.toDbTrx([storeName], 'readwrite', trx);
1001
+ const store = dbTrx.objectStore(storeName);
1002
+ const ids = Array.isArray(id) ? id : [id];
1003
+ try {
1004
+ for (const i of ids) {
1005
+ const e = await store.get(i);
1006
+ if (!e)
1007
+ throw new index_client_1.sdk.WERR_INVALID_PARAMETER('id', `an existing record to update ${keyProp} ${i} not found`);
1008
+ const v = {
1009
+ ...e,
1010
+ ...u
1011
+ };
1012
+ const uid = await store.put(v);
1013
+ if (uid !== i)
1014
+ throw new index_client_1.sdk.WERR_INTERNAL(`updated id ${uid} does not match original ${id}`);
1015
+ }
1016
+ }
1017
+ finally {
1018
+ if (!trx)
1019
+ await dbTrx.done;
1020
+ }
1021
+ return 1;
1022
+ }
1023
+ async updateIdbKey(key, update, keyProps, storeName, trx) {
1024
+ if (key.length !== keyProps.length)
1025
+ throw new index_client_1.sdk.WERR_INTERNAL(`key.length ${key.length} !== keyProps.length ${keyProps.length}`);
1026
+ for (let i = 0; i < key.length; i++) {
1027
+ if (update[keyProps[i]] !== undefined && update[keyProps[i]] !== key[i]) {
1028
+ throw new index_client_1.sdk.WERR_INVALID_PARAMETER(`update.${keyProps[i]}`, `undefined`);
1029
+ }
1030
+ }
1031
+ const u = this.validatePartialForUpdate(update);
1032
+ const dbTrx = this.toDbTrx([storeName], 'readwrite', trx);
1033
+ const store = dbTrx.objectStore(storeName);
1034
+ try {
1035
+ const e = await store.get(key);
1036
+ if (!e)
1037
+ throw new index_client_1.sdk.WERR_INVALID_PARAMETER('key', `an existing record to update ${keyProps.join(',')} ${key.join(',')} not found`);
1038
+ const v = {
1039
+ ...e,
1040
+ ...u
1041
+ };
1042
+ const uid = await store.put(v);
1043
+ for (let i = 0; i < key.length; i++) {
1044
+ if (uid[i] !== key[i])
1045
+ throw new index_client_1.sdk.WERR_INTERNAL(`updated key ${uid[i]} does not match original ${key[i]}`);
1046
+ }
1047
+ }
1048
+ finally {
1049
+ if (!trx)
1050
+ await dbTrx.done;
1051
+ }
1052
+ return 1;
1053
+ }
1054
+ async updateCertificate(id, update, trx) {
1055
+ return this.updateIdb(id, update, 'certificateId', 'certificates', trx);
1056
+ }
1057
+ async updateCertificateField(certificateId, fieldName, update, trx) {
1058
+ return this.updateIdbKey([certificateId, fieldName], update, ['certificateId', 'fieldName'], 'certificate_fields', trx);
1059
+ }
1060
+ async updateCommission(id, update, trx) {
1061
+ return this.updateIdb(id, update, 'commissionId', 'commissions', trx);
1062
+ }
1063
+ async updateMonitorEvent(id, update, trx) {
1064
+ return this.updateIdb(id, update, 'id', 'monitor_events', trx);
1065
+ }
1066
+ async updateOutput(id, update, trx) {
1067
+ return this.updateIdb(id, update, 'outputId', 'outputs', trx);
1068
+ }
1069
+ async updateOutputBasket(id, update, trx) {
1070
+ return this.updateIdb(id, update, 'basketId', 'output_baskets', trx);
1071
+ }
1072
+ async updateOutputTag(id, update, trx) {
1073
+ return this.updateIdb(id, update, 'outputTagId', 'output_tags', trx);
1074
+ }
1075
+ async updateProvenTx(id, update, trx) {
1076
+ return this.updateIdb(id, update, 'provenTxId', 'proven_txs', trx);
1077
+ }
1078
+ async updateProvenTxReq(id, update, trx) {
1079
+ return this.updateIdb(id, update, 'provenTxReqId', 'proven_tx_reqs', trx);
1080
+ }
1081
+ async updateSyncState(id, update, trx) {
1082
+ return this.updateIdb(id, update, 'syncStateId', 'sync_states', trx);
1083
+ }
1084
+ async updateTransaction(id, update, trx) {
1085
+ return this.updateIdb(id, update, 'transactionId', 'transactions', trx);
1086
+ }
1087
+ async updateTxLabel(id, update, trx) {
1088
+ return this.updateIdb(id, update, 'txLabelId', 'tx_labels', trx);
1089
+ }
1090
+ async updateUser(id, update, trx) {
1091
+ return this.updateIdb(id, update, 'userId', 'users', trx);
1092
+ }
1093
+ async updateOutputTagMap(outputId, tagId, update, trx) {
1094
+ return this.updateIdbKey([tagId, outputId], update, ['outputTagId', 'outputId'], 'output_tags_map', trx);
1095
+ }
1096
+ async updateTxLabelMap(transactionId, txLabelId, update, trx) {
1097
+ return this.updateIdbKey([txLabelId, transactionId], update, ['txLabelId', 'transactionId'], 'tx_labels_map', trx);
1098
+ }
1099
+ //
1100
+ // StorageReader abstract methods
1101
+ //
1102
+ async destroy() {
1103
+ if (this.db) {
1104
+ this.db.close();
1105
+ }
1106
+ this.db = undefined;
1107
+ this._settings = undefined;
1108
+ }
1109
+ /**
1110
+ * @param scope
1111
+ * @param trx
1112
+ * @returns
1113
+ */
1114
+ async transaction(scope, trx) {
1115
+ if (trx)
1116
+ return await scope(trx);
1117
+ const stores = this.allStores;
1118
+ const db = await this.verifyDB();
1119
+ const tx = db.transaction(stores, 'readwrite');
1120
+ try {
1121
+ const r = await scope(tx);
1122
+ await tx.done;
1123
+ return r;
1124
+ }
1125
+ catch (err) {
1126
+ tx.abort();
1127
+ await tx.done;
1128
+ throw err;
1129
+ }
1130
+ }
1131
+ async filterCertificateFields(args, filtered) {
1132
+ var _a, _b, _c, _d;
1133
+ const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
1134
+ let skipped = 0;
1135
+ let count = 0;
1136
+ const dbTrx = this.toDbTrx(['certificate_fields'], 'readonly', args.trx);
1137
+ let cursor;
1138
+ if (((_b = args.partial) === null || _b === void 0 ? void 0 : _b.certificateId) !== undefined) {
1139
+ cursor = await dbTrx
1140
+ .objectStore('certificate_fields')
1141
+ .index('certificateId')
1142
+ .openCursor(args.partial.certificateId);
1143
+ }
1144
+ else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.userId) !== undefined) {
1145
+ cursor = await dbTrx.objectStore('certificate_fields').index('userId').openCursor(args.partial.userId);
1146
+ }
1147
+ else {
1148
+ cursor = await dbTrx.objectStore('certificate_fields').openCursor();
1149
+ }
1150
+ let firstTime = true;
1151
+ while (cursor) {
1152
+ if (!firstTime)
1153
+ cursor = await cursor.continue();
1154
+ if (!cursor)
1155
+ break;
1156
+ firstTime = false;
1157
+ const r = cursor.value;
1158
+ if (args.since && args.since > r.updated_at)
1159
+ continue;
1160
+ if (args.partial) {
1161
+ if (args.partial.userId && r.userId !== args.partial.userId)
1162
+ continue;
1163
+ if (args.partial.certificateId && r.certificateId !== args.partial.certificateId)
1164
+ continue;
1165
+ if (args.partial.created_at && r.created_at.getTime() !== args.partial.created_at.getTime())
1166
+ continue;
1167
+ if (args.partial.updated_at && r.updated_at.getTime() !== args.partial.updated_at.getTime())
1168
+ continue;
1169
+ if (args.partial.fieldName && r.fieldName !== args.partial.fieldName)
1170
+ continue;
1171
+ if (args.partial.fieldValue && r.fieldValue !== args.partial.fieldValue)
1172
+ continue;
1173
+ if (args.partial.masterKey && r.masterKey !== args.partial.masterKey)
1174
+ continue;
1175
+ }
1176
+ if (skipped < offset) {
1177
+ skipped++;
1178
+ continue;
1179
+ }
1180
+ filtered(r);
1181
+ count++;
1182
+ if (((_d = args.paged) === null || _d === void 0 ? void 0 : _d.limit) && count >= args.paged.limit)
1183
+ break;
1184
+ }
1185
+ if (!args.trx)
1186
+ await dbTrx.done;
1187
+ }
1188
+ async findCertificateFields(args) {
1189
+ const result = [];
1190
+ await this.filterCertificateFields(args, r => {
1191
+ result.push(this.validateEntity(r));
1192
+ });
1193
+ return result;
1194
+ }
1195
+ async filterCertificates(args, filtered) {
1196
+ var _a, _b, _c, _d, _e, _f, _g;
1197
+ const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
1198
+ let skipped = 0;
1199
+ let count = 0;
1200
+ const dbTrx = this.toDbTrx(['certificates'], 'readonly', args.trx);
1201
+ let cursor;
1202
+ if ((_b = args.partial) === null || _b === void 0 ? void 0 : _b.certificateId) {
1203
+ cursor = await dbTrx.objectStore('certificates').openCursor(args.partial.certificateId);
1204
+ }
1205
+ else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.userId) !== undefined) {
1206
+ if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.type) && ((_e = args.partial) === null || _e === void 0 ? void 0 : _e.certifier) && ((_f = args.partial) === null || _f === void 0 ? void 0 : _f.serialNumber)) {
1207
+ cursor = await dbTrx
1208
+ .objectStore('certificates')
1209
+ .index('userId_type_certifier_serialNumber')
1210
+ .openCursor([args.partial.userId, args.partial.type, args.partial.certifier, args.partial.serialNumber]);
1211
+ }
1212
+ else {
1213
+ cursor = await dbTrx.objectStore('certificates').index('userId').openCursor(args.partial.userId);
1214
+ }
1215
+ }
1216
+ else {
1217
+ cursor = await dbTrx.objectStore('certificates').openCursor();
1218
+ }
1219
+ let firstTime = true;
1220
+ while (cursor) {
1221
+ if (!firstTime)
1222
+ cursor = await cursor.continue();
1223
+ if (!cursor)
1224
+ break;
1225
+ firstTime = false;
1226
+ const r = cursor.value;
1227
+ if (args.since && args.since > r.updated_at)
1228
+ continue;
1229
+ if (args.certifiers && !args.certifiers.includes(r.certifier))
1230
+ continue;
1231
+ if (args.types && !args.types.includes(r.type))
1232
+ continue;
1233
+ if (args.partial) {
1234
+ if (args.partial.userId && r.userId !== args.partial.userId)
1235
+ continue;
1236
+ if (args.partial.certificateId && r.certificateId !== args.partial.certificateId)
1237
+ continue;
1238
+ if (args.partial.created_at && r.created_at.getTime() !== args.partial.created_at.getTime())
1239
+ continue;
1240
+ if (args.partial.updated_at && r.updated_at.getTime() !== args.partial.updated_at.getTime())
1241
+ continue;
1242
+ if (args.partial.type && r.type !== args.partial.type)
1243
+ continue;
1244
+ if (args.partial.serialNumber && r.serialNumber !== args.partial.serialNumber)
1245
+ continue;
1246
+ if (args.partial.certifier && r.certifier !== args.partial.certifier)
1247
+ continue;
1248
+ if (args.partial.subject && r.subject !== args.partial.subject)
1249
+ continue;
1250
+ if (args.partial.verifier && r.verifier !== args.partial.verifier)
1251
+ continue;
1252
+ if (args.partial.revocationOutpoint && r.revocationOutpoint !== args.partial.revocationOutpoint)
1253
+ continue;
1254
+ if (args.partial.signature && r.signature !== args.partial.signature)
1255
+ continue;
1256
+ if (args.partial.isDeleted && r.isDeleted !== args.partial.isDeleted)
1257
+ continue;
1258
+ }
1259
+ if (skipped < offset) {
1260
+ skipped++;
1261
+ continue;
1262
+ }
1263
+ filtered(r);
1264
+ count++;
1265
+ if (((_g = args.paged) === null || _g === void 0 ? void 0 : _g.limit) && count >= args.paged.limit)
1266
+ break;
1267
+ }
1268
+ if (!args.trx)
1269
+ await dbTrx.done;
1270
+ }
1271
+ async findCertificates(args) {
1272
+ const result = [];
1273
+ await this.filterCertificates(args, r => {
1274
+ result.push(this.validateEntity(r));
1275
+ });
1276
+ if (args.includeFields) {
1277
+ for (const c of result) {
1278
+ const fields = await this.findCertificateFields({ partial: { certificateId: c.certificateId }, trx: args.trx });
1279
+ c.fields = fields;
1280
+ }
1281
+ }
1282
+ return result;
1283
+ }
1284
+ async filterCommissions(args, filtered) {
1285
+ var _a, _b, _c, _d, _e;
1286
+ if (args.partial.lockingScript)
1287
+ throw new index_client_1.sdk.WERR_INVALID_PARAMETER('partial.lockingScript', `undefined. Commissions may not be found by lockingScript value.`);
1288
+ const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
1289
+ let skipped = 0;
1290
+ let count = 0;
1291
+ const dbTrx = this.toDbTrx(['commissions'], 'readonly', args.trx);
1292
+ let cursor;
1293
+ if ((_b = args.partial) === null || _b === void 0 ? void 0 : _b.commissionId) {
1294
+ cursor = await dbTrx.objectStore('commissions').openCursor(args.partial.commissionId);
1295
+ }
1296
+ else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.userId) !== undefined) {
1297
+ cursor = await dbTrx.objectStore('commissions').index('userId').openCursor(args.partial.userId);
1298
+ }
1299
+ else if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.transactionId) !== undefined) {
1300
+ cursor = await dbTrx.objectStore('commissions').index('transactionId').openCursor(args.partial.transactionId);
1301
+ }
1302
+ else {
1303
+ cursor = await dbTrx.objectStore('commissions').openCursor();
1304
+ }
1305
+ let firstTime = true;
1306
+ while (cursor) {
1307
+ if (!firstTime)
1308
+ cursor = await cursor.continue();
1309
+ if (!cursor)
1310
+ break;
1311
+ firstTime = false;
1312
+ const r = cursor.value;
1313
+ if (args.since && args.since > r.updated_at)
1314
+ continue;
1315
+ if (args.partial) {
1316
+ if (args.partial.commissionId && r.commissionId !== args.partial.commissionId)
1317
+ continue;
1318
+ if (args.partial.transactionId && r.transactionId !== args.partial.transactionId)
1319
+ continue;
1320
+ if (args.partial.userId && r.userId !== args.partial.userId)
1321
+ continue;
1322
+ if (args.partial.created_at && r.created_at.getTime() !== args.partial.created_at.getTime())
1323
+ continue;
1324
+ if (args.partial.updated_at && r.updated_at.getTime() !== args.partial.updated_at.getTime())
1325
+ continue;
1326
+ if (args.partial.satoshis !== undefined && r.satoshis !== args.partial.satoshis)
1327
+ continue;
1328
+ if (args.partial.keyOffset && r.keyOffset !== args.partial.keyOffset)
1329
+ continue;
1330
+ if (args.partial.isRedeemed !== undefined && r.isRedeemed !== args.partial.isRedeemed)
1331
+ continue;
1332
+ }
1333
+ if (skipped < offset) {
1334
+ skipped++;
1335
+ continue;
1336
+ }
1337
+ filtered(r);
1338
+ count++;
1339
+ if (((_e = args.paged) === null || _e === void 0 ? void 0 : _e.limit) && count >= args.paged.limit)
1340
+ break;
1341
+ }
1342
+ if (!args.trx)
1343
+ await dbTrx.done;
1344
+ }
1345
+ async findCommissions(args) {
1346
+ const result = [];
1347
+ await this.filterCommissions(args, r => {
1348
+ result.push(this.validateEntity(r));
1349
+ });
1350
+ return result;
1351
+ }
1352
+ async filterMonitorEvents(args, filtered) {
1353
+ var _a, _b, _c;
1354
+ const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
1355
+ let skipped = 0;
1356
+ let count = 0;
1357
+ const dbTrx = this.toDbTrx(['monitor_events'], 'readonly', args.trx);
1358
+ let cursor;
1359
+ if ((_b = args.partial) === null || _b === void 0 ? void 0 : _b.id) {
1360
+ cursor = await dbTrx.objectStore('monitor_events').openCursor(args.partial.id);
1361
+ }
1362
+ else {
1363
+ cursor = await dbTrx.objectStore('monitor_events').openCursor();
1364
+ }
1365
+ let firstTime = true;
1366
+ while (cursor) {
1367
+ if (!firstTime)
1368
+ cursor = await cursor.continue();
1369
+ if (!cursor)
1370
+ break;
1371
+ firstTime = false;
1372
+ const r = cursor.value;
1373
+ if (args.since && args.since > r.updated_at)
1374
+ continue;
1375
+ if (args.partial) {
1376
+ if (args.partial.id && r.id !== args.partial.id)
1377
+ continue;
1378
+ if (args.partial.created_at && r.created_at.getTime() !== args.partial.created_at.getTime())
1379
+ continue;
1380
+ if (args.partial.updated_at && r.updated_at.getTime() !== args.partial.updated_at.getTime())
1381
+ continue;
1382
+ if (args.partial.event && r.event !== args.partial.event)
1383
+ continue;
1384
+ if (args.partial.details && r.details !== args.partial.details)
1385
+ continue;
1386
+ }
1387
+ if (skipped < offset) {
1388
+ skipped++;
1389
+ continue;
1390
+ }
1391
+ filtered(r);
1392
+ count++;
1393
+ if (((_c = args.paged) === null || _c === void 0 ? void 0 : _c.limit) && count >= args.paged.limit)
1394
+ break;
1395
+ }
1396
+ if (!args.trx)
1397
+ await dbTrx.done;
1398
+ }
1399
+ async findMonitorEvents(args) {
1400
+ const result = [];
1401
+ await this.filterMonitorEvents(args, r => {
1402
+ result.push(this.validateEntity(r));
1403
+ });
1404
+ return result;
1405
+ }
1406
+ async filterOutputBaskets(args, filtered) {
1407
+ var _a, _b, _c, _d, _e;
1408
+ const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
1409
+ let skipped = 0;
1410
+ let count = 0;
1411
+ const dbTrx = this.toDbTrx(['output_baskets'], 'readonly', args.trx);
1412
+ let cursor;
1413
+ if ((_b = args.partial) === null || _b === void 0 ? void 0 : _b.basketId) {
1414
+ cursor = await dbTrx.objectStore('output_baskets').openCursor(args.partial.basketId);
1415
+ }
1416
+ else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.userId) !== undefined) {
1417
+ if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.name) !== undefined) {
1418
+ cursor = await dbTrx
1419
+ .objectStore('output_baskets')
1420
+ .index('name_userId')
1421
+ .openCursor([args.partial.name, args.partial.userId]);
1422
+ }
1423
+ else {
1424
+ cursor = await dbTrx.objectStore('output_baskets').index('userId').openCursor(args.partial.userId);
1425
+ }
1426
+ }
1427
+ else {
1428
+ cursor = await dbTrx.objectStore('output_baskets').openCursor();
1429
+ }
1430
+ let firstTime = true;
1431
+ while (cursor) {
1432
+ if (!firstTime)
1433
+ cursor = await cursor.continue();
1434
+ if (!cursor)
1435
+ break;
1436
+ firstTime = false;
1437
+ const r = cursor.value;
1438
+ if (args.since && args.since > r.updated_at)
1439
+ continue;
1440
+ if (args.partial) {
1441
+ if (args.partial.basketId && r.basketId !== args.partial.basketId)
1442
+ continue;
1443
+ if (args.partial.userId && r.userId !== args.partial.userId)
1444
+ continue;
1445
+ if (args.partial.created_at && r.created_at.getTime() !== args.partial.created_at.getTime())
1446
+ continue;
1447
+ if (args.partial.updated_at && r.updated_at.getTime() !== args.partial.updated_at.getTime())
1448
+ continue;
1449
+ if (args.partial.name && r.name !== args.partial.name)
1450
+ continue;
1451
+ if (args.partial.numberOfDesiredUTXOs !== undefined &&
1452
+ r.numberOfDesiredUTXOs !== args.partial.numberOfDesiredUTXOs)
1453
+ continue;
1454
+ if (args.partial.minimumDesiredUTXOValue !== undefined &&
1455
+ r.numberOfDesiredSatoshis !== args.partial.minimumDesiredUTXOValue)
1456
+ continue;
1457
+ if (args.partial.isDeleted !== undefined && r.isDeleted !== args.partial.isDeleted)
1458
+ continue;
1459
+ }
1460
+ if (skipped < offset) {
1461
+ skipped++;
1462
+ continue;
1463
+ }
1464
+ filtered(r);
1465
+ count++;
1466
+ if (((_e = args.paged) === null || _e === void 0 ? void 0 : _e.limit) && count >= args.paged.limit)
1467
+ break;
1468
+ }
1469
+ if (!args.trx)
1470
+ await dbTrx.done;
1471
+ }
1472
+ async findOutputBaskets(args) {
1473
+ const result = [];
1474
+ await this.filterOutputBaskets(args, r => {
1475
+ result.push(this.validateEntity(r));
1476
+ });
1477
+ return result;
1478
+ }
1479
+ async filterOutputs(args, filtered, tagIds, isQueryModeAll) {
1480
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1481
+ // args.txStatus
1482
+ // args.noScript
1483
+ if (args.partial.lockingScript)
1484
+ throw new index_client_1.sdk.WERR_INVALID_PARAMETER('args.partial.lockingScript', `undefined. Outputs may not be found by lockingScript value.`);
1485
+ const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
1486
+ let skipped = 0;
1487
+ let count = 0;
1488
+ const stores = ['outputs'];
1489
+ if (tagIds && tagIds.length > 0) {
1490
+ stores.push('output_tags_map');
1491
+ }
1492
+ if (args.txStatus) {
1493
+ stores.push('transactions');
1494
+ }
1495
+ const dbTrx = this.toDbTrx(stores, 'readonly', args.trx);
1496
+ let cursor;
1497
+ if ((_b = args.partial) === null || _b === void 0 ? void 0 : _b.outputId) {
1498
+ cursor = await dbTrx.objectStore('outputs').openCursor(args.partial.outputId);
1499
+ }
1500
+ else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.userId) !== undefined) {
1501
+ if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.transactionId) && ((_e = args.partial) === null || _e === void 0 ? void 0 : _e.vout) !== undefined) {
1502
+ cursor = await dbTrx
1503
+ .objectStore('outputs')
1504
+ .index('transactionId_vout_userId')
1505
+ .openCursor([args.partial.transactionId, args.partial.vout, args.partial.userId]);
1506
+ }
1507
+ else {
1508
+ cursor = await dbTrx.objectStore('outputs').index('userId').openCursor(args.partial.userId);
1509
+ }
1510
+ }
1511
+ else if (((_f = args.partial) === null || _f === void 0 ? void 0 : _f.transactionId) !== undefined) {
1512
+ cursor = await dbTrx.objectStore('outputs').index('transactionId').openCursor(args.partial.transactionId);
1513
+ }
1514
+ else if (((_g = args.partial) === null || _g === void 0 ? void 0 : _g.basketId) !== undefined) {
1515
+ cursor = await dbTrx.objectStore('outputs').index('basketId').openCursor(args.partial.basketId);
1516
+ }
1517
+ else if (((_h = args.partial) === null || _h === void 0 ? void 0 : _h.spentBy) !== undefined) {
1518
+ cursor = await dbTrx.objectStore('outputs').index('spentBy').openCursor(args.partial.spentBy);
1519
+ }
1520
+ else {
1521
+ cursor = await dbTrx.objectStore('outputs').openCursor();
1522
+ }
1523
+ let firstTime = true;
1524
+ while (cursor) {
1525
+ if (!firstTime)
1526
+ cursor = await cursor.continue();
1527
+ if (!cursor)
1528
+ break;
1529
+ firstTime = false;
1530
+ const r = cursor.value;
1531
+ if (args.since && args.since > r.updated_at)
1532
+ continue;
1533
+ if (args.partial) {
1534
+ if (args.partial.outputId && r.outputId !== args.partial.outputId)
1535
+ continue;
1536
+ if (args.partial.userId && r.userId !== args.partial.userId)
1537
+ continue;
1538
+ if (args.partial.transactionId && r.transactionId !== args.partial.transactionId)
1539
+ continue;
1540
+ if (args.partial.basketId && r.basketId !== args.partial.basketId)
1541
+ continue;
1542
+ if (args.partial.created_at && r.created_at.getTime() !== args.partial.created_at.getTime())
1543
+ continue;
1544
+ if (args.partial.updated_at && r.updated_at.getTime() !== args.partial.updated_at.getTime())
1545
+ continue;
1546
+ if (args.partial.spendable !== undefined && r.spendable !== args.partial.spendable)
1547
+ continue;
1548
+ if (args.partial.change !== undefined && r.change !== args.partial.change)
1549
+ continue;
1550
+ if (args.partial.outputDescription && r.outputDescription !== args.partial.outputDescription)
1551
+ continue;
1552
+ if (args.partial.vout !== undefined && r.vout !== args.partial.vout)
1553
+ continue;
1554
+ if (args.partial.satoshis !== undefined && r.satoshis !== args.partial.satoshis)
1555
+ continue;
1556
+ if (args.partial.providedBy && r.providedBy !== args.partial.providedBy)
1557
+ continue;
1558
+ if (args.partial.purpose && r.purpose !== args.partial.purpose)
1559
+ continue;
1560
+ if (args.partial.type && r.type !== args.partial.type)
1561
+ continue;
1562
+ if (args.partial.txid && r.txid !== args.partial.txid)
1563
+ continue;
1564
+ if (args.partial.senderIdentityKey && r.senderIdentityKey !== args.partial.senderIdentityKey)
1565
+ continue;
1566
+ if (args.partial.derivationPrefix && r.derivationPrefix !== args.partial.derivationPrefix)
1567
+ continue;
1568
+ if (args.partial.derivationSuffix && r.derivationSuffix !== args.partial.derivationSuffix)
1569
+ continue;
1570
+ if (args.partial.customInstructions && r.customInstructions !== args.partial.customInstructions)
1571
+ continue;
1572
+ if (args.partial.spentBy && r.spentBy !== args.partial.spentBy)
1573
+ continue;
1574
+ if (args.partial.sequenceNumber !== undefined && r.sequenceNumber !== args.partial.sequenceNumber)
1575
+ continue;
1576
+ if (args.partial.scriptLength !== undefined && r.scriptLength !== args.partial.scriptLength)
1577
+ continue;
1578
+ if (args.partial.scriptOffset !== undefined && r.scriptOffset !== args.partial.scriptOffset)
1579
+ continue;
1580
+ }
1581
+ if (args.txStatus !== undefined) {
1582
+ const count = await this.countTransactions({
1583
+ partial: { transactionId: r.transactionId },
1584
+ status: args.txStatus,
1585
+ trx: dbTrx
1586
+ });
1587
+ if (count === 0)
1588
+ continue;
1589
+ }
1590
+ if (tagIds && tagIds.length > 0) {
1591
+ let ids = [...tagIds];
1592
+ await this.filterOutputTagMaps({ partial: { outputId: r.outputId }, trx: dbTrx }, tm => {
1593
+ if (ids.length > 0) {
1594
+ const i = ids.indexOf(tm.outputTagId);
1595
+ if (i >= 0) {
1596
+ if (isQueryModeAll) {
1597
+ ids.splice(i, 1);
1598
+ }
1599
+ else {
1600
+ ids = [];
1601
+ }
1602
+ }
1603
+ }
1604
+ });
1605
+ if (ids.length > 0)
1606
+ continue;
1607
+ }
1608
+ if (skipped < offset) {
1609
+ skipped++;
1610
+ continue;
1611
+ }
1612
+ if (args.noScript === true) {
1613
+ r.script = undefined;
1614
+ }
1615
+ filtered(r);
1616
+ count++;
1617
+ if (((_j = args.paged) === null || _j === void 0 ? void 0 : _j.limit) && count >= args.paged.limit)
1618
+ break;
1619
+ }
1620
+ if (!args.trx)
1621
+ await dbTrx.done;
1622
+ }
1623
+ async findOutputs(args, tagIds, isQueryModeAll) {
1624
+ const results = [];
1625
+ await this.filterOutputs(args, r => {
1626
+ results.push(this.validateEntity(r));
1627
+ }, tagIds, isQueryModeAll);
1628
+ for (const o of results) {
1629
+ if (!args.noScript) {
1630
+ await this.validateOutputScript(o);
1631
+ }
1632
+ else {
1633
+ o.lockingScript = undefined;
1634
+ }
1635
+ }
1636
+ return results;
1637
+ }
1638
+ async filterOutputTags(args, filtered) {
1639
+ var _a, _b, _c, _d, _e;
1640
+ const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
1641
+ let skipped = 0;
1642
+ let count = 0;
1643
+ const dbTrx = this.toDbTrx(['output_tags'], 'readonly', args.trx);
1644
+ let cursor;
1645
+ if ((_b = args.partial) === null || _b === void 0 ? void 0 : _b.outputTagId) {
1646
+ cursor = await dbTrx.objectStore('output_tags').openCursor(args.partial.outputTagId);
1647
+ }
1648
+ else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.userId) !== undefined) {
1649
+ if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.tag) !== undefined) {
1650
+ cursor = await dbTrx
1651
+ .objectStore('output_tags')
1652
+ .index('tag_userId')
1653
+ .openCursor([args.partial.tag, args.partial.userId]);
1654
+ }
1655
+ else {
1656
+ cursor = await dbTrx.objectStore('output_tags').index('userId').openCursor(args.partial.userId);
1657
+ }
1658
+ }
1659
+ else {
1660
+ cursor = await dbTrx.objectStore('output_tags').openCursor();
1661
+ }
1662
+ let firstTime = true;
1663
+ while (cursor) {
1664
+ if (!firstTime)
1665
+ cursor = await cursor.continue();
1666
+ if (!cursor)
1667
+ break;
1668
+ firstTime = false;
1669
+ const r = cursor.value;
1670
+ if (args.since && args.since > r.updated_at)
1671
+ continue;
1672
+ if (args.partial) {
1673
+ if (args.partial.outputTagId && r.outputTagId !== args.partial.outputTagId)
1674
+ continue;
1675
+ if (args.partial.userId && r.userId !== args.partial.userId)
1676
+ continue;
1677
+ if (args.partial.created_at && r.created_at.getTime() !== args.partial.created_at.getTime())
1678
+ continue;
1679
+ if (args.partial.updated_at && r.updated_at.getTime() !== args.partial.updated_at.getTime())
1680
+ continue;
1681
+ if (args.partial.tag && r.tag !== args.partial.tag)
1682
+ continue;
1683
+ if (args.partial.isDeleted !== undefined && r.isDeleted !== args.partial.isDeleted)
1684
+ continue;
1685
+ }
1686
+ if (skipped < offset) {
1687
+ skipped++;
1688
+ continue;
1689
+ }
1690
+ filtered(r);
1691
+ count++;
1692
+ if (((_e = args.paged) === null || _e === void 0 ? void 0 : _e.limit) && count >= args.paged.limit)
1693
+ break;
1694
+ }
1695
+ if (!args.trx)
1696
+ await dbTrx.done;
1697
+ }
1698
+ async findOutputTags(args) {
1699
+ const result = [];
1700
+ await this.filterOutputTags(args, r => {
1701
+ result.push(this.validateEntity(r));
1702
+ });
1703
+ return result;
1704
+ }
1705
+ async filterSyncStates(args, filtered) {
1706
+ var _a, _b, _c, _d, _e, _f, _g;
1707
+ if (args.partial.syncMap)
1708
+ throw new index_client_1.sdk.WERR_INVALID_PARAMETER('args.partial.syncMap', `undefined. SyncStates may not be found by syncMap value.`);
1709
+ const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
1710
+ let skipped = 0;
1711
+ let count = 0;
1712
+ const dbTrx = this.toDbTrx(['sync_states'], 'readonly', args.trx);
1713
+ let cursor;
1714
+ if ((_b = args.partial) === null || _b === void 0 ? void 0 : _b.syncStateId) {
1715
+ cursor = await dbTrx.objectStore('sync_states').openCursor(args.partial.syncStateId);
1716
+ }
1717
+ else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.userId) !== undefined) {
1718
+ cursor = await dbTrx.objectStore('sync_states').index('userId').openCursor(args.partial.userId);
1719
+ }
1720
+ else if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.refNum) !== undefined) {
1721
+ cursor = await dbTrx.objectStore('sync_states').index('refNum').openCursor(args.partial.refNum);
1722
+ }
1723
+ else if (((_e = args.partial) === null || _e === void 0 ? void 0 : _e.status) !== undefined) {
1724
+ cursor = await dbTrx.objectStore('sync_states').index('status').openCursor(args.partial.status);
1725
+ }
1726
+ else {
1727
+ cursor = await dbTrx.objectStore('sync_states').openCursor();
1728
+ }
1729
+ let firstTime = true;
1730
+ while (cursor) {
1731
+ if (!firstTime)
1732
+ cursor = await cursor.continue();
1733
+ if (!cursor)
1734
+ break;
1735
+ firstTime = false;
1736
+ const r = cursor.value;
1737
+ if (args.since && args.since > r.updated_at)
1738
+ continue;
1739
+ if (args.partial) {
1740
+ if (args.partial.syncStateId && r.syncStateId !== args.partial.syncStateId)
1741
+ continue;
1742
+ if (args.partial.userId && r.userId !== args.partial.userId)
1743
+ continue;
1744
+ if (args.partial.created_at && r.created_at.getTime() !== args.partial.created_at.getTime())
1745
+ continue;
1746
+ if (args.partial.updated_at && r.updated_at.getTime() !== args.partial.updated_at.getTime())
1747
+ continue;
1748
+ if (args.partial.storageIdentityKey && r.storageIdentityKey !== args.partial.storageIdentityKey)
1749
+ continue;
1750
+ if (args.partial.storageName && r.storageName !== args.partial.storageName)
1751
+ continue;
1752
+ if (args.partial.status && r.status !== args.partial.status)
1753
+ continue;
1754
+ if (args.partial.init !== undefined && r.init !== args.partial.init)
1755
+ continue;
1756
+ if (args.partial.refNum !== undefined && r.refNum !== args.partial.refNum)
1757
+ continue;
1758
+ if (args.partial.when && ((_f = r.when) === null || _f === void 0 ? void 0 : _f.getTime()) !== args.partial.when.getTime())
1759
+ continue;
1760
+ if (args.partial.satoshis !== undefined && r.satoshis !== args.partial.satoshis)
1761
+ continue;
1762
+ if (args.partial.errorLocal && r.errorLocale !== args.partial.errorLocal)
1763
+ continue;
1764
+ if (args.partial.errorOther && r.errorOther !== args.partial.errorOther)
1765
+ continue;
1766
+ }
1767
+ if (skipped < offset) {
1768
+ skipped++;
1769
+ continue;
1770
+ }
1771
+ filtered(r);
1772
+ count++;
1773
+ if (((_g = args.paged) === null || _g === void 0 ? void 0 : _g.limit) && count >= args.paged.limit)
1774
+ break;
1775
+ }
1776
+ if (!args.trx)
1777
+ await dbTrx.done;
1778
+ }
1779
+ async findSyncStates(args) {
1780
+ const result = [];
1781
+ await this.filterSyncStates(args, r => {
1782
+ result.push(this.validateEntity(r));
1783
+ });
1784
+ return result;
1785
+ }
1786
+ async filterTransactions(args, filtered, labelIds, isQueryModeAll) {
1787
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1788
+ if (args.partial.rawTx)
1789
+ throw new index_client_1.sdk.WERR_INVALID_PARAMETER('args.partial.rawTx', `undefined. Transactions may not be found by rawTx value.`);
1790
+ if (args.partial.inputBEEF)
1791
+ throw new index_client_1.sdk.WERR_INVALID_PARAMETER('args.partial.inputBEEF', `undefined. Transactions may not be found by inputBEEF value.`);
1792
+ const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
1793
+ let skipped = 0;
1794
+ let count = 0;
1795
+ const stores = ['transactions'];
1796
+ if (labelIds && labelIds.length > 0) {
1797
+ stores.push('tx_labels_map');
1798
+ }
1799
+ const dbTrx = this.toDbTrx(stores, 'readonly', args.trx);
1800
+ let cursor;
1801
+ if ((_b = args.partial) === null || _b === void 0 ? void 0 : _b.transactionId) {
1802
+ cursor = await dbTrx.objectStore('transactions').openCursor(args.partial.transactionId);
1803
+ }
1804
+ else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.userId) !== undefined) {
1805
+ if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.status) !== undefined) {
1806
+ cursor = await dbTrx
1807
+ .objectStore('transactions')
1808
+ .index('status_userId')
1809
+ .openCursor([args.partial.status, args.partial.userId]);
1810
+ }
1811
+ else {
1812
+ cursor = await dbTrx.objectStore('transactions').index('userId').openCursor(args.partial.userId);
1813
+ }
1814
+ }
1815
+ else if (((_e = args.partial) === null || _e === void 0 ? void 0 : _e.status) !== undefined) {
1816
+ cursor = await dbTrx.objectStore('transactions').index('status').openCursor(args.partial.status);
1817
+ }
1818
+ else if (((_f = args.partial) === null || _f === void 0 ? void 0 : _f.provenTxId) !== undefined) {
1819
+ cursor = await dbTrx.objectStore('transactions').index('provenTxId').openCursor(args.partial.provenTxId);
1820
+ }
1821
+ else if (((_g = args.partial) === null || _g === void 0 ? void 0 : _g.reference) !== undefined) {
1822
+ cursor = await dbTrx.objectStore('transactions').index('reference').openCursor(args.partial.reference);
1823
+ }
1824
+ else {
1825
+ cursor = await dbTrx.objectStore('transactions').openCursor();
1826
+ }
1827
+ let firstTime = true;
1828
+ while (cursor) {
1829
+ if (!firstTime)
1830
+ cursor = await cursor.continue();
1831
+ if (!cursor)
1832
+ break;
1833
+ firstTime = false;
1834
+ const r = cursor.value;
1835
+ if (args.since && args.since > r.updated_at)
1836
+ continue;
1837
+ if (args.status && !args.status.includes(r.status))
1838
+ continue;
1839
+ if (args.partial) {
1840
+ if (args.partial.transactionId && r.transactionId !== args.partial.transactionId)
1841
+ continue;
1842
+ if (args.partial.userId && r.userId !== args.partial.userId)
1843
+ continue;
1844
+ if (args.partial.created_at && r.created_at.getTime() !== args.partial.created_at.getTime())
1845
+ continue;
1846
+ if (args.partial.updated_at && r.updated_at.getTime() !== args.partial.updated_at.getTime())
1847
+ continue;
1848
+ if (args.partial.provenTxId && r.provenTxId !== args.partial.provenTxId)
1849
+ continue;
1850
+ if (args.partial.status && r.status !== args.partial.status)
1851
+ continue;
1852
+ if (args.partial.reference && r.reference !== args.partial.reference)
1853
+ continue;
1854
+ if (args.partial.isOutgoing !== undefined && r.isOutgoing !== args.partial.isOutgoing)
1855
+ continue;
1856
+ if (args.partial.satoshis !== undefined && r.satoshis !== args.partial.satoshis)
1857
+ continue;
1858
+ if (args.partial.description && r.description !== args.partial.description)
1859
+ continue;
1860
+ if (args.partial.version !== undefined && r.version !== args.partial.version)
1861
+ continue;
1862
+ if (args.partial.lockTime !== undefined && r.lockTime !== args.partial.lockTime)
1863
+ continue;
1864
+ if (args.partial.txid && r.txid !== args.partial.txid)
1865
+ continue;
1866
+ }
1867
+ if (labelIds && labelIds.length > 0) {
1868
+ let ids = [...labelIds];
1869
+ await this.filterTxLabelMaps({ partial: { transactionId: r.transactionId }, trx: dbTrx }, lm => {
1870
+ if (ids.length > 0) {
1871
+ const i = ids.indexOf(lm.txLabelId);
1872
+ if (i >= 0) {
1873
+ if (isQueryModeAll) {
1874
+ ids.splice(i, 1);
1875
+ }
1876
+ else {
1877
+ ids = [];
1878
+ }
1879
+ }
1880
+ }
1881
+ });
1882
+ if (ids.length > 0)
1883
+ continue;
1884
+ }
1885
+ if (skipped < offset) {
1886
+ skipped++;
1887
+ continue;
1888
+ }
1889
+ filtered(r);
1890
+ count++;
1891
+ if (((_h = args.paged) === null || _h === void 0 ? void 0 : _h.limit) && count >= args.paged.limit)
1892
+ break;
1893
+ }
1894
+ if (!args.trx)
1895
+ await dbTrx.done;
1896
+ }
1897
+ async findTransactions(args, labelIds, isQueryModeAll) {
1898
+ const results = [];
1899
+ await this.filterTransactions(args, r => {
1900
+ results.push(this.validateEntity(r));
1901
+ }, labelIds, isQueryModeAll);
1902
+ for (const t of results) {
1903
+ if (!args.noRawTx) {
1904
+ await this.validateRawTransaction(t, args.trx);
1905
+ }
1906
+ else {
1907
+ t.rawTx = undefined;
1908
+ t.inputBEEF = undefined;
1909
+ }
1910
+ }
1911
+ return results;
1912
+ }
1913
+ async filterTxLabels(args, filtered) {
1914
+ var _a, _b, _c, _d, _e;
1915
+ const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
1916
+ let skipped = 0;
1917
+ let count = 0;
1918
+ const dbTrx = this.toDbTrx(['tx_labels'], 'readonly', args.trx);
1919
+ let cursor;
1920
+ if ((_b = args.partial) === null || _b === void 0 ? void 0 : _b.txLabelId) {
1921
+ cursor = await dbTrx.objectStore('tx_labels').openCursor(args.partial.txLabelId);
1922
+ }
1923
+ else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.userId) !== undefined) {
1924
+ if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.label) !== undefined) {
1925
+ cursor = await dbTrx
1926
+ .objectStore('tx_labels')
1927
+ .index('label_userId')
1928
+ .openCursor([args.partial.label, args.partial.userId]);
1929
+ }
1930
+ else {
1931
+ cursor = await dbTrx.objectStore('tx_labels').index('userId').openCursor(args.partial.userId);
1932
+ }
1933
+ }
1934
+ else {
1935
+ cursor = await dbTrx.objectStore('tx_labels').openCursor();
1936
+ }
1937
+ let firstTime = true;
1938
+ while (cursor) {
1939
+ if (!firstTime)
1940
+ cursor = await cursor.continue();
1941
+ if (!cursor)
1942
+ break;
1943
+ firstTime = false;
1944
+ const r = cursor.value;
1945
+ if (args.since && args.since > r.updated_at)
1946
+ continue;
1947
+ if (args.partial) {
1948
+ if (args.partial.txLabelId && r.txLabelId !== args.partial.txLabelId)
1949
+ continue;
1950
+ if (args.partial.userId && r.userId !== args.partial.userId)
1951
+ continue;
1952
+ if (args.partial.created_at && r.created_at.getTime() !== args.partial.created_at.getTime())
1953
+ continue;
1954
+ if (args.partial.updated_at && r.updated_at.getTime() !== args.partial.updated_at.getTime())
1955
+ continue;
1956
+ if (args.partial.label && r.label !== args.partial.label)
1957
+ continue;
1958
+ if (args.partial.isDeleted !== undefined && r.isDeleted !== args.partial.isDeleted)
1959
+ continue;
1960
+ }
1961
+ if (skipped < offset) {
1962
+ skipped++;
1963
+ continue;
1964
+ }
1965
+ filtered(r);
1966
+ count++;
1967
+ if (((_e = args.paged) === null || _e === void 0 ? void 0 : _e.limit) && count >= args.paged.limit)
1968
+ break;
1969
+ }
1970
+ if (!args.trx)
1971
+ await dbTrx.done;
1972
+ }
1973
+ async findTxLabels(args) {
1974
+ const result = [];
1975
+ await this.filterTxLabels(args, r => {
1976
+ result.push(this.validateEntity(r));
1977
+ });
1978
+ return result;
1979
+ }
1980
+ async filterUsers(args, filtered) {
1981
+ var _a, _b;
1982
+ const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
1983
+ let skipped = 0;
1984
+ let count = 0;
1985
+ const dbTrx = this.toDbTrx(['users'], 'readonly', args.trx);
1986
+ let cursor = await dbTrx.objectStore('users').openCursor();
1987
+ let firstTime = true;
1988
+ while (cursor) {
1989
+ if (!firstTime)
1990
+ cursor = await cursor.continue();
1991
+ if (!cursor)
1992
+ break;
1993
+ firstTime = false;
1994
+ const r = cursor.value;
1995
+ if (args.since && args.since > r.updated_at)
1996
+ continue;
1997
+ if (args.partial) {
1998
+ if (args.partial.userId && r.userId !== args.partial.userId)
1999
+ continue;
2000
+ if (args.partial.created_at && r.created_at.getTime() !== args.partial.created_at.getTime())
2001
+ continue;
2002
+ if (args.partial.updated_at && r.updated_at.getTime() !== args.partial.updated_at.getTime())
2003
+ continue;
2004
+ if (args.partial.identityKey && r.identityKey !== args.partial.identityKey)
2005
+ continue;
2006
+ if (args.partial.activeStorage && r.activeStorage !== args.partial.activeStorage)
2007
+ continue;
2008
+ }
2009
+ if (skipped < offset) {
2010
+ skipped++;
2011
+ continue;
2012
+ }
2013
+ filtered(r);
2014
+ count++;
2015
+ if (((_b = args.paged) === null || _b === void 0 ? void 0 : _b.limit) && count >= args.paged.limit)
2016
+ break;
2017
+ }
2018
+ if (!args.trx)
2019
+ await dbTrx.done;
2020
+ }
2021
+ async findUsers(args) {
2022
+ const result = [];
2023
+ await this.filterUsers(args, r => {
2024
+ result.push(this.validateEntity(r));
2025
+ });
2026
+ return result;
2027
+ }
2028
+ async countCertificateFields(args) {
2029
+ let count = 0;
2030
+ await this.filterCertificateFields(args, () => {
2031
+ count++;
2032
+ });
2033
+ return count;
2034
+ }
2035
+ async countCertificates(args) {
2036
+ let count = 0;
2037
+ await this.filterCertificates(args, () => {
2038
+ count++;
2039
+ });
2040
+ return count;
2041
+ }
2042
+ async countCommissions(args) {
2043
+ let count = 0;
2044
+ await this.filterCommissions(args, () => {
2045
+ count++;
2046
+ });
2047
+ return count;
2048
+ }
2049
+ async countMonitorEvents(args) {
2050
+ let count = 0;
2051
+ await this.filterMonitorEvents(args, () => {
2052
+ count++;
2053
+ });
2054
+ return count;
2055
+ }
2056
+ async countOutputBaskets(args) {
2057
+ let count = 0;
2058
+ await this.filterOutputBaskets(args, () => {
2059
+ count++;
2060
+ });
2061
+ return count;
2062
+ }
2063
+ async countOutputs(args, tagIds, isQueryModeAll) {
2064
+ let count = 0;
2065
+ await this.filterOutputs({ ...args, noScript: true }, () => {
2066
+ count++;
2067
+ }, tagIds, isQueryModeAll);
2068
+ return count;
2069
+ }
2070
+ async countOutputTags(args) {
2071
+ let count = 0;
2072
+ await this.filterOutputTags(args, () => {
2073
+ count++;
2074
+ });
2075
+ return count;
2076
+ }
2077
+ async countSyncStates(args) {
2078
+ let count = 0;
2079
+ await this.filterSyncStates(args, () => {
2080
+ count++;
2081
+ });
2082
+ return count;
2083
+ }
2084
+ async countTransactions(args, labelIds, isQueryModeAll) {
2085
+ let count = 0;
2086
+ await this.filterTransactions({ ...args, noRawTx: true }, () => {
2087
+ count++;
2088
+ }, labelIds, isQueryModeAll);
2089
+ return count;
2090
+ }
2091
+ async countTxLabels(args) {
2092
+ let count = 0;
2093
+ await this.filterTxLabels(args, () => {
2094
+ count++;
2095
+ });
2096
+ return count;
2097
+ }
2098
+ async countUsers(args) {
2099
+ let count = 0;
2100
+ await this.filterUsers(args, () => {
2101
+ count++;
2102
+ });
2103
+ return count;
2104
+ }
2105
+ async getProvenTxsForUser(args) {
2106
+ const results = [];
2107
+ const fargs = {
2108
+ partial: {},
2109
+ since: args.since,
2110
+ paged: args.paged,
2111
+ trx: args.trx
2112
+ };
2113
+ await this.filterProvenTxs(fargs, r => {
2114
+ results.push(this.validateEntity(r));
2115
+ }, args.userId);
2116
+ return results;
2117
+ }
2118
+ async getProvenTxReqsForUser(args) {
2119
+ const results = [];
2120
+ const fargs = {
2121
+ partial: {},
2122
+ since: args.since,
2123
+ paged: args.paged,
2124
+ trx: args.trx
2125
+ };
2126
+ await this.filterProvenTxReqs(fargs, r => {
2127
+ results.push(this.validateEntity(r));
2128
+ }, args.userId);
2129
+ return results;
2130
+ }
2131
+ async getTxLabelMapsForUser(args) {
2132
+ const results = [];
2133
+ const fargs = {
2134
+ partial: {},
2135
+ since: args.since,
2136
+ paged: args.paged,
2137
+ trx: args.trx
2138
+ };
2139
+ await this.filterTxLabelMaps(fargs, r => {
2140
+ results.push(this.validateEntity(r));
2141
+ }, args.userId);
2142
+ return results;
2143
+ }
2144
+ async getOutputTagMapsForUser(args) {
2145
+ const results = [];
2146
+ const fargs = {
2147
+ partial: {},
2148
+ since: args.since,
2149
+ paged: args.paged,
2150
+ trx: args.trx
2151
+ };
2152
+ await this.filterOutputTagMaps(fargs, r => {
2153
+ results.push(this.validateEntity(r));
2154
+ }, args.userId);
2155
+ return results;
2156
+ }
2157
+ async verifyReadyForDatabaseAccess(trx) {
2158
+ if (!this._settings) {
2159
+ this._settings = await this.readSettings();
2160
+ }
2161
+ return this._settings.dbtype;
2162
+ }
2163
+ /**
2164
+ * Helper to force uniform behavior across database engines.
2165
+ * Use to process all individual records with time stamps or number[] retreived from database.
2166
+ */
2167
+ validateEntity(entity, dateFields, booleanFields) {
2168
+ entity.created_at = this.validateDate(entity.created_at);
2169
+ entity.updated_at = this.validateDate(entity.updated_at);
2170
+ if (dateFields) {
2171
+ for (const df of dateFields) {
2172
+ if (entity[df])
2173
+ entity[df] = this.validateDate(entity[df]);
2174
+ }
2175
+ }
2176
+ if (booleanFields) {
2177
+ for (const df of booleanFields) {
2178
+ if (entity[df] !== undefined)
2179
+ entity[df] = !!entity[df];
2180
+ }
2181
+ }
2182
+ for (const key of Object.keys(entity)) {
2183
+ const val = entity[key];
2184
+ if (val === null) {
2185
+ entity[key] = undefined;
2186
+ }
2187
+ else if (val instanceof Uint8Array) {
2188
+ entity[key] = Array.from(val);
2189
+ }
2190
+ }
2191
+ return entity;
2192
+ }
2193
+ /**
2194
+ * Helper to force uniform behavior across database engines.
2195
+ * Use to process all arrays of records with time stamps retreived from database.
2196
+ * @returns input `entities` array with contained values validated.
2197
+ */
2198
+ validateEntities(entities, dateFields, booleanFields) {
2199
+ for (let i = 0; i < entities.length; i++) {
2200
+ entities[i] = this.validateEntity(entities[i], dateFields, booleanFields);
2201
+ }
2202
+ return entities;
2203
+ }
2204
+ /**
2205
+ * Helper to force uniform behavior across database engines.
2206
+ * Use to process the update template for entities being updated.
2207
+ */
2208
+ validatePartialForUpdate(update, dateFields, booleanFields) {
2209
+ if (!this.dbtype)
2210
+ throw new index_client_1.sdk.WERR_INTERNAL('must call verifyReadyForDatabaseAccess first');
2211
+ const v = { ...update };
2212
+ if (v.created_at)
2213
+ v.created_at = this.validateEntityDate(v.created_at);
2214
+ if (v.updated_at)
2215
+ v.updated_at = this.validateEntityDate(v.updated_at);
2216
+ if (!v.created_at)
2217
+ delete v.created_at;
2218
+ if (!v.updated_at)
2219
+ v.updated_at = this.validateEntityDate(new Date());
2220
+ if (dateFields) {
2221
+ for (const df of dateFields) {
2222
+ if (v[df])
2223
+ v[df] = this.validateOptionalEntityDate(v[df]);
2224
+ }
2225
+ }
2226
+ if (booleanFields) {
2227
+ for (const df of booleanFields) {
2228
+ if (update[df] !== undefined)
2229
+ update[df] = !!update[df] ? 1 : 0;
2230
+ }
2231
+ }
2232
+ for (const key of Object.keys(v)) {
2233
+ const val = v[key];
2234
+ if (Array.isArray(val) && (val.length === 0 || Number.isInteger(val[0]))) {
2235
+ v[key] = Uint8Array.from(val);
2236
+ }
2237
+ else if (val === null) {
2238
+ v[key] = undefined;
2239
+ }
2240
+ }
2241
+ this.isDirty = true;
2242
+ return v;
2243
+ }
2244
+ /**
2245
+ * Helper to force uniform behavior across database engines.
2246
+ * Use to process new entities being inserted into the database.
2247
+ */
2248
+ async validateEntityForInsert(entity, trx, dateFields, booleanFields) {
2249
+ await this.verifyReadyForDatabaseAccess(trx);
2250
+ const v = { ...entity };
2251
+ v.created_at = this.validateOptionalEntityDate(v.created_at, true);
2252
+ v.updated_at = this.validateOptionalEntityDate(v.updated_at, true);
2253
+ if (!v.created_at)
2254
+ delete v.created_at;
2255
+ if (!v.updated_at)
2256
+ delete v.updated_at;
2257
+ if (dateFields) {
2258
+ for (const df of dateFields) {
2259
+ if (v[df])
2260
+ v[df] = this.validateOptionalEntityDate(v[df]);
2261
+ }
2262
+ }
2263
+ if (booleanFields) {
2264
+ for (const df of booleanFields) {
2265
+ if (entity[df] !== undefined)
2266
+ entity[df] = !!entity[df] ? 1 : 0;
2267
+ }
2268
+ }
2269
+ for (const key of Object.keys(v)) {
2270
+ const val = v[key];
2271
+ if (Array.isArray(val) && (val.length === 0 || Number.isInteger(val[0]))) {
2272
+ v[key] = Uint8Array.from(val);
2273
+ }
2274
+ else if (val === null) {
2275
+ v[key] = undefined;
2276
+ }
2277
+ }
2278
+ this.isDirty = true;
2279
+ return v;
2280
+ }
2281
+ async validateRawTransaction(t, trx) {
2282
+ // if there is no txid or there is a rawTransaction return what we have.
2283
+ if (t.rawTx || !t.txid)
2284
+ return;
2285
+ // rawTransaction is missing, see if we moved it ...
2286
+ const rawTx = await this.getRawTxOfKnownValidTransaction(t.txid, undefined, undefined, trx);
2287
+ if (!rawTx)
2288
+ return;
2289
+ t.rawTx = rawTx;
2290
+ }
2291
+ async adminStats(adminIdentityKey) {
2292
+ throw new Error('Method intentionally not implemented for personal storage.');
2293
+ }
2294
+ }
2295
+ exports.StorageIdb = StorageIdb;
2296
+ //# sourceMappingURL=StorageIdb.js.map