react-native-nitro-bsx 0.0.0-stage → 0.2.35

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 (931) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +7 -2
  3. package/android/CMakeLists.txt +28 -0
  4. package/android/build.gradle +99 -0
  5. package/android/src/main/AndroidManifest.xml +35 -0
  6. package/android/src/main/cpp/cpp-adapter.cpp +12 -0
  7. package/android/src/main/java/com/nitrobsx/BSXAlarmReceiver.kt +29 -0
  8. package/android/src/main/java/com/nitrobsx/BSXAlarmScheduler.kt +112 -0
  9. package/android/src/main/java/com/nitrobsx/BSXForegroundService.kt +78 -0
  10. package/android/src/main/java/com/nitrobsx/BSXNotifications.kt +47 -0
  11. package/android/src/main/java/com/nitrobsx/BSXServiceController.kt +90 -0
  12. package/android/src/main/java/com/nitrobsx/BSXWakeWorker.kt +136 -0
  13. package/android/src/main/java/com/nitrobsx/HeadlessJsTaskSupportShim.kt +41 -0
  14. package/android/src/main/java/com/nitrobsx/NitroBSXPackage.kt +28 -0
  15. package/android/src/main/res/drawable/bsx_ic_stat_swap.xml +9 -0
  16. package/cpp/BSXContext.cpp +263 -0
  17. package/cpp/BSXContext.h +49 -0
  18. package/cpp/BSXModule.cpp +21191 -0
  19. package/cpp/BSXModule.h +1523 -0
  20. package/cpp/CMakeLists.txt +463 -0
  21. package/cpp/HybridNitroBSX.cpp +1483 -0
  22. package/cpp/HybridNitroBSX.hpp +173 -0
  23. package/cpp/arith_uint256.cpp +232 -0
  24. package/cpp/arith_uint256.h +277 -0
  25. package/cpp/bsx/event.cpp +48 -0
  26. package/cpp/bsx/event.h +29 -0
  27. package/cpp/bsx/swap.h +293 -0
  28. package/cpp/bsx/types.cpp +486 -0
  29. package/cpp/bsx/types.h +308 -0
  30. package/cpp/bsx_db.cpp +4951 -0
  31. package/cpp/bsx_db.h +465 -0
  32. package/cpp/chain_client.h +143 -0
  33. package/cpp/cmake/GenVersion.cmake +52 -0
  34. package/cpp/coin_config.h.in +12 -0
  35. package/cpp/coins/block_index.cpp +33 -0
  36. package/cpp/coins/block_index.h +35 -0
  37. package/cpp/coins/btc/chainparams.cpp +70 -0
  38. package/cpp/coins/btc/chainparams.h +23 -0
  39. package/cpp/coins/btc/interface.h +30 -0
  40. package/cpp/coins/btc_base/interface.cpp +2200 -0
  41. package/cpp/coins/btc_base/interface.h +225 -0
  42. package/cpp/coins/btc_base/primitives.cpp +560 -0
  43. package/cpp/coins/btc_base/primitives.h +157 -0
  44. package/cpp/coins/btc_base/psbt.cpp +150 -0
  45. package/cpp/coins/btc_base/psbt.h +52 -0
  46. package/cpp/coins/btc_base/script.cpp +304 -0
  47. package/cpp/coins/btc_base/script.h +181 -0
  48. package/cpp/coins/chainparams.cpp +47 -0
  49. package/cpp/coins/chainparams.h +58 -0
  50. package/cpp/coins/firo/chainparams.cpp +52 -0
  51. package/cpp/coins/firo/chainparams.h +24 -0
  52. package/cpp/coins/firo/firo.cpp +118 -0
  53. package/cpp/coins/firo/firo.h +79 -0
  54. package/cpp/coins/firo/primitives.cpp +109 -0
  55. package/cpp/coins/firo/primitives.h +47 -0
  56. package/cpp/coins/interface.cpp +1815 -0
  57. package/cpp/coins/interface.h +554 -0
  58. package/cpp/coins/ltc/chainparams.cpp +70 -0
  59. package/cpp/coins/ltc/chainparams.h +22 -0
  60. package/cpp/coins/ltc/ltc.cpp +69 -0
  61. package/cpp/coins/ltc/ltc.h +82 -0
  62. package/cpp/coins/ltc/primitives.cpp +20 -0
  63. package/cpp/coins/ltc/primitives.h +18 -0
  64. package/cpp/coins/part/chainparams.cpp +89 -0
  65. package/cpp/coins/part/chainparams.h +47 -0
  66. package/cpp/coins/part/part.cpp +905 -0
  67. package/cpp/coins/part/part.h +164 -0
  68. package/cpp/coins/part/primitives.cpp +548 -0
  69. package/cpp/coins/part/primitives.h +187 -0
  70. package/cpp/coins/part/stake.cpp +330 -0
  71. package/cpp/coins/part/stake.h +92 -0
  72. package/cpp/coins/primitives.h +125 -0
  73. package/cpp/coins/registry.cpp +99 -0
  74. package/cpp/coins/registry.h +32 -0
  75. package/cpp/coins/script.h +18 -0
  76. package/cpp/coins/types.cpp +60 -0
  77. package/cpp/coins/types.h +41 -0
  78. package/cpp/coins/xmr/chainparams.cpp +28 -0
  79. package/cpp/coins/xmr/chainparams.h +24 -0
  80. package/cpp/coins/xmr/tx.cpp +670 -0
  81. package/cpp/coins/xmr/tx.h +77 -0
  82. package/cpp/coins/xmr/xmr.cpp +639 -0
  83. package/cpp/coins/xmr/xmr.h +223 -0
  84. package/cpp/compat/byteswap.h +74 -0
  85. package/cpp/compat/endian.h +98 -0
  86. package/cpp/compat/mbedtls/threading_alt.h +20 -0
  87. package/cpp/compat/sockets.h +160 -0
  88. package/cpp/contrib/mbedtls/CMakeLists.txt +566 -0
  89. package/cpp/contrib/mbedtls/LICENSE +553 -0
  90. package/cpp/contrib/mbedtls/cmake/MbedTLSConfig.cmake.in +3 -0
  91. package/cpp/contrib/mbedtls/doxygen/input/doc_encdec.h +52 -0
  92. package/cpp/contrib/mbedtls/doxygen/input/doc_hashing.h +30 -0
  93. package/cpp/contrib/mbedtls/doxygen/input/doc_mainpage.h +52 -0
  94. package/cpp/contrib/mbedtls/doxygen/input/doc_rng.h +27 -0
  95. package/cpp/contrib/mbedtls/doxygen/input/doc_ssltls.h +37 -0
  96. package/cpp/contrib/mbedtls/doxygen/input/doc_tcpip.h +32 -0
  97. package/cpp/contrib/mbedtls/doxygen/input/doc_x509.h +31 -0
  98. package/cpp/contrib/mbedtls/doxygen/mbedtls.doxyfile +56 -0
  99. package/cpp/contrib/mbedtls/framework/CMakeLists.txt +1 -0
  100. package/cpp/contrib/mbedtls/framework/LICENSE +553 -0
  101. package/cpp/contrib/mbedtls/include/CMakeLists.txt +21 -0
  102. package/cpp/contrib/mbedtls/include/mbedtls/build_info.h +93 -0
  103. package/cpp/contrib/mbedtls/include/mbedtls/debug.h +120 -0
  104. package/cpp/contrib/mbedtls/include/mbedtls/error.h +39 -0
  105. package/cpp/contrib/mbedtls/include/mbedtls/mbedtls_config.h +1189 -0
  106. package/cpp/contrib/mbedtls/include/mbedtls/net_sockets.h +299 -0
  107. package/cpp/contrib/mbedtls/include/mbedtls/oid.h +304 -0
  108. package/cpp/contrib/mbedtls/include/mbedtls/pkcs7.h +250 -0
  109. package/cpp/contrib/mbedtls/include/mbedtls/private/config_adjust_ssl.h +84 -0
  110. package/cpp/contrib/mbedtls/include/mbedtls/private/config_adjust_x509.h +35 -0
  111. package/cpp/contrib/mbedtls/include/mbedtls/ssl.h +5622 -0
  112. package/cpp/contrib/mbedtls/include/mbedtls/ssl_cache.h +187 -0
  113. package/cpp/contrib/mbedtls/include/mbedtls/ssl_ciphersuites.h +303 -0
  114. package/cpp/contrib/mbedtls/include/mbedtls/ssl_cookie.h +90 -0
  115. package/cpp/contrib/mbedtls/include/mbedtls/ssl_ticket.h +186 -0
  116. package/cpp/contrib/mbedtls/include/mbedtls/timing.h +105 -0
  117. package/cpp/contrib/mbedtls/include/mbedtls/version.h +69 -0
  118. package/cpp/contrib/mbedtls/include/mbedtls/x509.h +503 -0
  119. package/cpp/contrib/mbedtls/include/mbedtls/x509_crl.h +180 -0
  120. package/cpp/contrib/mbedtls/include/mbedtls/x509_crt.h +1174 -0
  121. package/cpp/contrib/mbedtls/include/mbedtls/x509_csr.h +368 -0
  122. package/cpp/contrib/mbedtls/library/CMakeLists.txt +375 -0
  123. package/cpp/contrib/mbedtls/library/Makefile +334 -0
  124. package/cpp/contrib/mbedtls/library/debug.c +285 -0
  125. package/cpp/contrib/mbedtls/library/debug_internal.h +108 -0
  126. package/cpp/contrib/mbedtls/library/error.c +505 -0
  127. package/cpp/contrib/mbedtls/library/mbedtls_check_config.h +376 -0
  128. package/cpp/contrib/mbedtls/library/mbedtls_common.h +51 -0
  129. package/cpp/contrib/mbedtls/library/mbedtls_config.c +40 -0
  130. package/cpp/contrib/mbedtls/library/mbedtls_config_check_before.h +1769 -0
  131. package/cpp/contrib/mbedtls/library/mbedtls_config_check_final.h +12 -0
  132. package/cpp/contrib/mbedtls/library/mbedtls_config_check_user.h +2436 -0
  133. package/cpp/contrib/mbedtls/library/mbedtls_platform_requirements.h +55 -0
  134. package/cpp/contrib/mbedtls/library/mbedtls_utils.h +23 -0
  135. package/cpp/contrib/mbedtls/library/mps_common.h +181 -0
  136. package/cpp/contrib/mbedtls/library/mps_error.h +89 -0
  137. package/cpp/contrib/mbedtls/library/mps_reader.c +538 -0
  138. package/cpp/contrib/mbedtls/library/mps_reader.h +366 -0
  139. package/cpp/contrib/mbedtls/library/mps_trace.c +112 -0
  140. package/cpp/contrib/mbedtls/library/mps_trace.h +154 -0
  141. package/cpp/contrib/mbedtls/library/net_sockets.c +684 -0
  142. package/cpp/contrib/mbedtls/library/pkcs7.c +784 -0
  143. package/cpp/contrib/mbedtls/library/ssl_cache.c +409 -0
  144. package/cpp/contrib/mbedtls/library/ssl_ciphersuites.c +996 -0
  145. package/cpp/contrib/mbedtls/library/ssl_ciphersuites_internal.h +108 -0
  146. package/cpp/contrib/mbedtls/library/ssl_client.c +1019 -0
  147. package/cpp/contrib/mbedtls/library/ssl_client.h +18 -0
  148. package/cpp/contrib/mbedtls/library/ssl_cookie.c +251 -0
  149. package/cpp/contrib/mbedtls/library/ssl_debug_helpers.h +83 -0
  150. package/cpp/contrib/mbedtls/library/ssl_debug_helpers_generated.c +243 -0
  151. package/cpp/contrib/mbedtls/library/ssl_misc.h +2851 -0
  152. package/cpp/contrib/mbedtls/library/ssl_msg.c +6275 -0
  153. package/cpp/contrib/mbedtls/library/ssl_ticket.c +453 -0
  154. package/cpp/contrib/mbedtls/library/ssl_tls.c +9048 -0
  155. package/cpp/contrib/mbedtls/library/ssl_tls12_client.c +3054 -0
  156. package/cpp/contrib/mbedtls/library/ssl_tls12_server.c +3546 -0
  157. package/cpp/contrib/mbedtls/library/ssl_tls13_client.c +3202 -0
  158. package/cpp/contrib/mbedtls/library/ssl_tls13_generic.c +1773 -0
  159. package/cpp/contrib/mbedtls/library/ssl_tls13_invasive.h +23 -0
  160. package/cpp/contrib/mbedtls/library/ssl_tls13_keys.c +1860 -0
  161. package/cpp/contrib/mbedtls/library/ssl_tls13_keys.h +668 -0
  162. package/cpp/contrib/mbedtls/library/ssl_tls13_server.c +3602 -0
  163. package/cpp/contrib/mbedtls/library/timing.c +76 -0
  164. package/cpp/contrib/mbedtls/library/version.c +30 -0
  165. package/cpp/contrib/mbedtls/library/version_features.c +244 -0
  166. package/cpp/contrib/mbedtls/library/x509.c +1848 -0
  167. package/cpp/contrib/mbedtls/library/x509_create.c +747 -0
  168. package/cpp/contrib/mbedtls/library/x509_crl.c +701 -0
  169. package/cpp/contrib/mbedtls/library/x509_crt.c +3278 -0
  170. package/cpp/contrib/mbedtls/library/x509_csr.c +642 -0
  171. package/cpp/contrib/mbedtls/library/x509_internal.h +97 -0
  172. package/cpp/contrib/mbedtls/library/x509_oid.c +603 -0
  173. package/cpp/contrib/mbedtls/library/x509_oid.h +150 -0
  174. package/cpp/contrib/mbedtls/library/x509write.c +171 -0
  175. package/cpp/contrib/mbedtls/library/x509write_crt.c +637 -0
  176. package/cpp/contrib/mbedtls/library/x509write_csr.c +317 -0
  177. package/cpp/contrib/mbedtls/pkgconfig/CMakeLists.txt +25 -0
  178. package/cpp/contrib/mbedtls/pkgconfig/JoinPaths.cmake +27 -0
  179. package/cpp/contrib/mbedtls/pkgconfig/mbedcrypto.pc.in +10 -0
  180. package/cpp/contrib/mbedtls/pkgconfig/mbedtls.pc.in +11 -0
  181. package/cpp/contrib/mbedtls/pkgconfig/mbedx509.pc.in +11 -0
  182. package/cpp/contrib/mbedtls/tf-psa-crypto/CMakeLists.txt +584 -0
  183. package/cpp/contrib/mbedtls/tf-psa-crypto/LICENSE +552 -0
  184. package/cpp/contrib/mbedtls/tf-psa-crypto/cmake/TF-PSA-CryptoConfig.cmake.in +3 -0
  185. package/cpp/contrib/mbedtls/tf-psa-crypto/core/CMakeLists.txt +193 -0
  186. package/cpp/contrib/mbedtls/tf-psa-crypto/core/alignment.h +700 -0
  187. package/cpp/contrib/mbedtls/tf-psa-crypto/core/check_crypto_config.h +111 -0
  188. package/cpp/contrib/mbedtls/tf-psa-crypto/core/crypto-library.make +57 -0
  189. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto.c +9820 -0
  190. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_client.c +22 -0
  191. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_core.h +972 -0
  192. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_core_common.h +52 -0
  193. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_driver_wrappers.h +3395 -0
  194. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_driver_wrappers_no_static.c +247 -0
  195. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_invasive.h +85 -0
  196. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_its.h +131 -0
  197. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_random.c +168 -0
  198. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_random.h +72 -0
  199. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_random_impl.h +215 -0
  200. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_slot_management.c +998 -0
  201. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_slot_management.h +330 -0
  202. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_storage.c +400 -0
  203. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_storage.h +201 -0
  204. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_its_file.c +254 -0
  205. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_util.c +295 -0
  206. package/cpp/contrib/mbedtls/tf-psa-crypto/core/tf_psa_crypto_check_config.h +598 -0
  207. package/cpp/contrib/mbedtls/tf-psa-crypto/core/tf_psa_crypto_common.h +628 -0
  208. package/cpp/contrib/mbedtls/tf-psa-crypto/core/tf_psa_crypto_config.c +72 -0
  209. package/cpp/contrib/mbedtls/tf-psa-crypto/core/tf_psa_crypto_config_check_before.h +12 -0
  210. package/cpp/contrib/mbedtls/tf-psa-crypto/core/tf_psa_crypto_config_check_final.h +12 -0
  211. package/cpp/contrib/mbedtls/tf-psa-crypto/core/tf_psa_crypto_config_check_user.h +1220 -0
  212. package/cpp/contrib/mbedtls/tf-psa-crypto/core/tf_psa_crypto_platform_requirements.h +62 -0
  213. package/cpp/contrib/mbedtls/tf-psa-crypto/core/tf_psa_crypto_version.c +28 -0
  214. package/cpp/contrib/mbedtls/tf-psa-crypto/dispatch/psa_crypto_driver_wrappers_no_static.h +31 -0
  215. package/cpp/contrib/mbedtls/tf-psa-crypto/doxygen/input/doc_mainpage.h.in +51 -0
  216. package/cpp/contrib/mbedtls/tf-psa-crypto/doxygen/tfpsacrypto.doxyfile.in +54 -0
  217. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/CMakeLists.txt +142 -0
  218. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/CMakeLists.txt +3 -0
  219. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/aes.h +607 -0
  220. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/aria.h +342 -0
  221. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/bignum.h +1137 -0
  222. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/block_cipher.h +76 -0
  223. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/camellia.h +302 -0
  224. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/ccm.h +523 -0
  225. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/chacha20.h +230 -0
  226. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/chachapoly.h +339 -0
  227. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/cipher.h +1173 -0
  228. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/cmac.h +209 -0
  229. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/config_adjust_test_accelerators.h +111 -0
  230. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/crypto_adjust_config_enable_builtins.h +820 -0
  231. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/crypto_adjust_config_tweak_builtins.h +203 -0
  232. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/crypto_builtin_composites.h +278 -0
  233. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/crypto_builtin_key_derivation.h +120 -0
  234. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/crypto_builtin_primitives.h +136 -0
  235. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/ctr_drbg.h +554 -0
  236. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/ecdsa.h +667 -0
  237. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/ecjpake.h +296 -0
  238. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/ecp.h +1452 -0
  239. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/entropy.h +253 -0
  240. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/error_common.h +79 -0
  241. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/gcm.h +382 -0
  242. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/hmac_drbg.h +426 -0
  243. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/md5.h +169 -0
  244. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/pkcs5.h +123 -0
  245. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/poly1305.h +165 -0
  246. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/ripemd160.h +120 -0
  247. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/rsa.h +821 -0
  248. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/sha1.h +196 -0
  249. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/sha256.h +180 -0
  250. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/sha3.h +189 -0
  251. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/sha512.h +188 -0
  252. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private_access.h +53 -0
  253. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/aes.c +2236 -0
  254. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/aesce.c +624 -0
  255. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/aesce.h +135 -0
  256. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/aesni.c +846 -0
  257. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/aesni.h +162 -0
  258. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/aria.c +966 -0
  259. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/bignum.c +2635 -0
  260. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/bignum_core.c +1242 -0
  261. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/bignum_core.h +885 -0
  262. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/bignum_core_invasive.h +38 -0
  263. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/bignum_internal.h +164 -0
  264. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/bignum_mod.c +394 -0
  265. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/bignum_mod.h +452 -0
  266. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/bignum_mod_raw.c +276 -0
  267. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/bignum_mod_raw.h +416 -0
  268. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/bignum_mod_raw_invasive.h +34 -0
  269. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/block_cipher.c +207 -0
  270. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/block_cipher_internal.h +99 -0
  271. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/bn_mul.h +1094 -0
  272. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/camellia.c +1055 -0
  273. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/ccm.c +773 -0
  274. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/chacha20.c +576 -0
  275. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/chacha20_neon.c +294 -0
  276. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/chacha20_neon.h +62 -0
  277. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/chachapoly.c +479 -0
  278. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/cipher.c +1126 -0
  279. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/cipher_invasive.h +28 -0
  280. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/cipher_wrap.c +1937 -0
  281. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/cipher_wrap.h +173 -0
  282. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/cmac.c +911 -0
  283. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/ctr.h +35 -0
  284. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/ctr_drbg.c +1017 -0
  285. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/ecdsa.c +826 -0
  286. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/ecjpake.c +1206 -0
  287. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/ecp.c +3478 -0
  288. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/ecp_curves.c +4798 -0
  289. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/ecp_invasive.h +220 -0
  290. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/entropy.c +677 -0
  291. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/entropy_poll.c +89 -0
  292. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/entropy_poll.h +44 -0
  293. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/gcm.c +1314 -0
  294. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/hmac_drbg.c +639 -0
  295. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/md5.c +419 -0
  296. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/md_psa.h +26 -0
  297. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/poly1305.c +488 -0
  298. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_aead.c +648 -0
  299. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_aead.h +499 -0
  300. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_cipher.c +752 -0
  301. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_cipher.h +314 -0
  302. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_ecp.c +921 -0
  303. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_ecp.h +516 -0
  304. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_ffdh.c +781 -0
  305. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_ffdh.h +131 -0
  306. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_hash.c +458 -0
  307. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_hash.h +211 -0
  308. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_mac.c +495 -0
  309. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_mac.h +264 -0
  310. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_pake.c +568 -0
  311. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_pake.h +159 -0
  312. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_rsa.c +698 -0
  313. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_rsa.h +321 -0
  314. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_xof.c +149 -0
  315. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_xof.h +155 -0
  316. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_util_internal.c +282 -0
  317. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_util_internal.h +132 -0
  318. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/ripemd160.c +482 -0
  319. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/rsa.c +2720 -0
  320. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/rsa_alt_helpers.c +294 -0
  321. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/rsa_alt_helpers.h +185 -0
  322. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/rsa_internal.h +172 -0
  323. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/rsa_invasive.h +57 -0
  324. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/sha1.c +473 -0
  325. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/sha256.c +956 -0
  326. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/sha3.c +951 -0
  327. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/sha512.c +1089 -0
  328. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/driver.cmake +54 -0
  329. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/CMakeLists.txt +45 -0
  330. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/Makefile.inc +5 -0
  331. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/README.md +5 -0
  332. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/Hacl_Curve25519.h +25 -0
  333. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/kremlib/FStar_UInt128.h +124 -0
  334. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/kremlib/FStar_UInt64_FStar_UInt32_FStar_UInt16_FStar_UInt8.h +280 -0
  335. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/kremlib.h +29 -0
  336. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/kremlin/c_endianness.h +206 -0
  337. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/kremlin/internal/builtin.h +16 -0
  338. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/kremlin/internal/callconv.h +48 -0
  339. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/kremlin/internal/compat.h +34 -0
  340. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/kremlin/internal/debug.h +57 -0
  341. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/kremlin/internal/target.h +102 -0
  342. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/kremlin/internal/types.h +61 -0
  343. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/kremlin/internal/wasmsupport.h +5 -0
  344. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/vs2013/Hacl_Curve25519.h +21 -0
  345. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/x25519.h +48 -0
  346. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/library/Hacl_Curve25519.c +760 -0
  347. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/library/Hacl_Curve25519_joined.c +50 -0
  348. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/library/kremlib/FStar_UInt128_extracted.c +413 -0
  349. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/library/kremlib/FStar_UInt64_FStar_UInt32_FStar_UInt16_FStar_UInt8.c +100 -0
  350. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/library/legacy/Hacl_Curve25519.c +805 -0
  351. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/library/x25519.c +52 -0
  352. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/p256-m/CMakeLists.txt +36 -0
  353. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/p256-m/Makefile.inc +5 -0
  354. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/p256-m/README.md +4 -0
  355. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/p256-m/p256-m/README.md +544 -0
  356. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/p256-m/p256-m/p256-m.c +1514 -0
  357. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/p256-m/p256-m/p256-m.h +135 -0
  358. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/p256-m/p256-m_driver_entrypoints.c +312 -0
  359. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/p256-m/p256-m_driver_entrypoints.h +219 -0
  360. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/pqcp/CMakeLists.txt +14 -0
  361. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/pqcp/Makefile.inc +6 -0
  362. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/pqcp/include/tf-psa-crypto/private/crypto_struct_pqcp.h +52 -0
  363. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/pqcp/src/fips202_psa.h +117 -0
  364. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/pqcp/src/pqcp-config.h +68 -0
  365. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/pqcp/src/psa_crypto_mldsa.c +528 -0
  366. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/pqcp/src/psa_crypto_mldsa.h +301 -0
  367. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/pqcp/src/wrap_mldsa_native.c +66 -0
  368. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/pqcp/src/wrap_mldsa_native.h +37 -0
  369. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/CMakeLists.txt +3 -0
  370. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/lmots.c +768 -0
  371. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/lmots.h +272 -0
  372. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/lms.c +772 -0
  373. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/md.c +1182 -0
  374. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/md_wrap.h +46 -0
  375. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/nist_kw.c +458 -0
  376. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/pk.c +1464 -0
  377. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/pk_ecc.c +175 -0
  378. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/pk_internal.h +188 -0
  379. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/pk_rsa.c +106 -0
  380. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/pk_wrap.c +667 -0
  381. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/pk_wrap.h +101 -0
  382. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/pkparse.c +1351 -0
  383. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/pkwrite.c +574 -0
  384. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/pkwrite.h +101 -0
  385. package/cpp/contrib/mbedtls/tf-psa-crypto/framework/CMakeLists.txt +1 -0
  386. package/cpp/contrib/mbedtls/tf-psa-crypto/framework/LICENSE +553 -0
  387. package/cpp/contrib/mbedtls/tf-psa-crypto/include/CMakeLists.txt +41 -0
  388. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/asn1.h +623 -0
  389. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/asn1write.h +397 -0
  390. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/base64.h +81 -0
  391. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/compat-3-crypto.h +43 -0
  392. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/constant_time.h +36 -0
  393. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/lms.h +431 -0
  394. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/md.h +538 -0
  395. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/memory_buffer_alloc.h +142 -0
  396. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/nist_kw.h +106 -0
  397. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/pem.h +157 -0
  398. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/pk.h +888 -0
  399. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/platform.h +513 -0
  400. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/platform_time.h +79 -0
  401. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/platform_util.h +197 -0
  402. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/private/pk_private.h +150 -0
  403. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/psa_util.h +199 -0
  404. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/threading.h +412 -0
  405. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto.h +6082 -0
  406. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_compat.h +74 -0
  407. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_config.h +2073 -0
  408. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_driver_common.h +42 -0
  409. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_driver_contexts_composites.h +182 -0
  410. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_driver_contexts_key_derivation.h +54 -0
  411. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_driver_contexts_primitives.h +135 -0
  412. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_driver_random.h +49 -0
  413. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_extra.h +2115 -0
  414. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_platform.h +94 -0
  415. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_sizes.h +1301 -0
  416. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_struct.h +682 -0
  417. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_types.h +466 -0
  418. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_values.h +2827 -0
  419. package/cpp/contrib/mbedtls/tf-psa-crypto/include/tf-psa-crypto/build_info.h +193 -0
  420. package/cpp/contrib/mbedtls/tf-psa-crypto/include/tf-psa-crypto/private/crypto_adjust_config_auto_enabled.h +23 -0
  421. package/cpp/contrib/mbedtls/tf-psa-crypto/include/tf-psa-crypto/private/crypto_adjust_config_dependencies.h +58 -0
  422. package/cpp/contrib/mbedtls/tf-psa-crypto/include/tf-psa-crypto/private/crypto_adjust_config_derived.h +135 -0
  423. package/cpp/contrib/mbedtls/tf-psa-crypto/include/tf-psa-crypto/private/crypto_adjust_config_key_pair_types.h +93 -0
  424. package/cpp/contrib/mbedtls/tf-psa-crypto/include/tf-psa-crypto/private/crypto_adjust_config_support.h +211 -0
  425. package/cpp/contrib/mbedtls/tf-psa-crypto/include/tf-psa-crypto/private/crypto_adjust_config_synonyms.h +41 -0
  426. package/cpp/contrib/mbedtls/tf-psa-crypto/include/tf-psa-crypto/version.h +44 -0
  427. package/cpp/contrib/mbedtls/tf-psa-crypto/objlib.cmake +71 -0
  428. package/cpp/contrib/mbedtls/tf-psa-crypto/pkgconfig/CMakeLists.txt +15 -0
  429. package/cpp/contrib/mbedtls/tf-psa-crypto/pkgconfig/JoinPaths.cmake +27 -0
  430. package/cpp/contrib/mbedtls/tf-psa-crypto/pkgconfig/tfpsacrypto.pc.in +10 -0
  431. package/cpp/contrib/mbedtls/tf-psa-crypto/platform/CMakeLists.txt +3 -0
  432. package/cpp/contrib/mbedtls/tf-psa-crypto/platform/memory_buffer_alloc.c +751 -0
  433. package/cpp/contrib/mbedtls/tf-psa-crypto/platform/platform.c +362 -0
  434. package/cpp/contrib/mbedtls/tf-psa-crypto/platform/platform_util.c +428 -0
  435. package/cpp/contrib/mbedtls/tf-psa-crypto/platform/threading.c +311 -0
  436. package/cpp/contrib/mbedtls/tf-psa-crypto/platform/threading_internal.h +75 -0
  437. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/CMakeLists.txt +3 -0
  438. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/asn1parse.c +483 -0
  439. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/asn1write.c +465 -0
  440. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/base64.c +322 -0
  441. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/base64_internal.h +45 -0
  442. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/constant_time.c +247 -0
  443. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/constant_time_impl.h +514 -0
  444. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/constant_time_internal.h +540 -0
  445. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/crypto_oid.h +354 -0
  446. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/oid.c +469 -0
  447. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/pem.c +458 -0
  448. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/pkcs5.c +475 -0
  449. package/cpp/contrib/monero/LICENSE +41 -0
  450. package/cpp/contrib/monero/bsx/common/perf_timer.h +15 -0
  451. package/cpp/contrib/monero/bsx/common/threadpool.h +43 -0
  452. package/cpp/contrib/monero/bsx/hex.h +25 -0
  453. package/cpp/contrib/monero/bsx/misc_log_ex.h +61 -0
  454. package/cpp/contrib/monero/bsx/random.cpp +20 -0
  455. package/cpp/contrib/monero/contrib/epee/include/int-util.h +320 -0
  456. package/cpp/contrib/monero/contrib/epee/include/memwipe.h +81 -0
  457. package/cpp/contrib/monero/contrib/epee/include/misc_language.h +109 -0
  458. package/cpp/contrib/monero/contrib/epee/include/mlocker.h +89 -0
  459. package/cpp/contrib/monero/contrib/epee/include/span.h +189 -0
  460. package/cpp/contrib/monero/contrib/epee/include/warnings.h +31 -0
  461. package/cpp/contrib/monero/contrib/epee/src/memwipe.c +115 -0
  462. package/cpp/contrib/monero/contrib/epee/src/mlocker.cpp +197 -0
  463. package/cpp/contrib/monero/src/common/aligned.c +139 -0
  464. package/cpp/contrib/monero/src/common/aligned.h +42 -0
  465. package/cpp/contrib/monero/src/common/base58.cpp +259 -0
  466. package/cpp/contrib/monero/src/common/base58.h +46 -0
  467. package/cpp/contrib/monero/src/common/pod-class.h +43 -0
  468. package/cpp/contrib/monero/src/common/varint.h +138 -0
  469. package/cpp/contrib/monero/src/crypto/chacha.h +96 -0
  470. package/cpp/contrib/monero/src/crypto/crypto-ops-data.c +881 -0
  471. package/cpp/contrib/monero/src/crypto/crypto-ops.c +3891 -0
  472. package/cpp/contrib/monero/src/crypto/crypto-ops.h +167 -0
  473. package/cpp/contrib/monero/src/crypto/crypto.cpp +792 -0
  474. package/cpp/contrib/monero/src/crypto/crypto.h +359 -0
  475. package/cpp/contrib/monero/src/crypto/generic-ops.h +103 -0
  476. package/cpp/contrib/monero/src/crypto/hash-ops.h +105 -0
  477. package/cpp/contrib/monero/src/crypto/hash.c +57 -0
  478. package/cpp/contrib/monero/src/crypto/hash.h +110 -0
  479. package/cpp/contrib/monero/src/crypto/keccak.c +239 -0
  480. package/cpp/contrib/monero/src/crypto/keccak.h +40 -0
  481. package/cpp/contrib/monero/src/crypto/random.h +46 -0
  482. package/cpp/contrib/monero/src/crypto/tree-hash.c +257 -0
  483. package/cpp/contrib/monero/src/crypto/wallet/crypto.h +57 -0
  484. package/cpp/contrib/monero/src/crypto/wallet/ops.h +32 -0
  485. package/cpp/contrib/monero/src/cryptonote_config.h +365 -0
  486. package/cpp/contrib/monero/src/device/device.cpp +105 -0
  487. package/cpp/contrib/monero/src/device/device.hpp +274 -0
  488. package/cpp/contrib/monero/src/device/device_default.cpp +343 -0
  489. package/cpp/contrib/monero/src/device/device_default.hpp +156 -0
  490. package/cpp/contrib/monero/src/ringct/bulletproofs.cc +1097 -0
  491. package/cpp/contrib/monero/src/ringct/bulletproofs.h +51 -0
  492. package/cpp/contrib/monero/src/ringct/bulletproofs_plus.cc +1120 -0
  493. package/cpp/contrib/monero/src/ringct/bulletproofs_plus.h +49 -0
  494. package/cpp/contrib/monero/src/ringct/multiexp.cc +708 -0
  495. package/cpp/contrib/monero/src/ringct/multiexp.h +72 -0
  496. package/cpp/contrib/monero/src/ringct/rctCryptoOps.c +221 -0
  497. package/cpp/contrib/monero/src/ringct/rctCryptoOps.h +37 -0
  498. package/cpp/contrib/monero/src/ringct/rctOps.cpp +727 -0
  499. package/cpp/contrib/monero/src/ringct/rctOps.h +191 -0
  500. package/cpp/contrib/monero/src/ringct/rctSigs.cpp +1652 -0
  501. package/cpp/contrib/monero/src/ringct/rctSigs.h +143 -0
  502. package/cpp/contrib/monero/src/ringct/rctTypes.cpp +338 -0
  503. package/cpp/contrib/monero/src/ringct/rctTypes.h +842 -0
  504. package/cpp/contrib/monero/src/serialization/binary_archive.h +243 -0
  505. package/cpp/contrib/monero/src/serialization/container.h +146 -0
  506. package/cpp/contrib/monero/src/serialization/containers.h +127 -0
  507. package/cpp/contrib/monero/src/serialization/crypto.h +97 -0
  508. package/cpp/contrib/monero/src/serialization/debug_archive.h +53 -0
  509. package/cpp/contrib/monero/src/serialization/json_archive.h +193 -0
  510. package/cpp/contrib/monero/src/serialization/serialization.h +328 -0
  511. package/cpp/contrib/monero/src/serialization/variant.h +50 -0
  512. package/cpp/contrib/nlohmann/LICENSE.MIT +21 -0
  513. package/cpp/contrib/nlohmann/json.hpp +25526 -0
  514. package/cpp/contrib/nlohmann/json_fwd.hpp +187 -0
  515. package/cpp/contrib/notes.txt +96 -0
  516. package/cpp/contrib/secp256k1/CHANGELOG.md +214 -0
  517. package/cpp/contrib/secp256k1/CMakeLists.txt +392 -0
  518. package/cpp/contrib/secp256k1/CMakePresets.json +18 -0
  519. package/cpp/contrib/secp256k1/CONTRIBUTING.md +111 -0
  520. package/cpp/contrib/secp256k1/COPYING +19 -0
  521. package/cpp/contrib/secp256k1/Makefile.am +332 -0
  522. package/cpp/contrib/secp256k1/README.md +176 -0
  523. package/cpp/contrib/secp256k1/SECURITY.md +15 -0
  524. package/cpp/contrib/secp256k1/autogen.sh +3 -0
  525. package/cpp/contrib/secp256k1/ci/ci.sh +147 -0
  526. package/cpp/contrib/secp256k1/ci/linux-debian.Dockerfile +84 -0
  527. package/cpp/contrib/secp256k1/ci/travis.sh +68 -0
  528. package/cpp/contrib/secp256k1/cmake/CheckArm32Assembly.cmake +6 -0
  529. package/cpp/contrib/secp256k1/cmake/CheckMemorySanitizer.cmake +18 -0
  530. package/cpp/contrib/secp256k1/cmake/CheckStringOptionValue.cmake +10 -0
  531. package/cpp/contrib/secp256k1/cmake/CheckX86_64Assembly.cmake +15 -0
  532. package/cpp/contrib/secp256k1/cmake/DiscoverTests.cmake +71 -0
  533. package/cpp/contrib/secp256k1/cmake/FindValgrind.cmake +41 -0
  534. package/cpp/contrib/secp256k1/cmake/GeneratePkgConfigFile.cmake +8 -0
  535. package/cpp/contrib/secp256k1/cmake/TryAppendCFlags.cmake +24 -0
  536. package/cpp/contrib/secp256k1/cmake/arm-linux-gnueabihf.toolchain.cmake +3 -0
  537. package/cpp/contrib/secp256k1/cmake/config.cmake.in +5 -0
  538. package/cpp/contrib/secp256k1/cmake/source_arm32.s +9 -0
  539. package/cpp/contrib/secp256k1/cmake/x86_64-w64-mingw32.toolchain.cmake +3 -0
  540. package/cpp/contrib/secp256k1/configure.ac +590 -0
  541. package/cpp/contrib/secp256k1/contrib/lax_der_parsing.c +148 -0
  542. package/cpp/contrib/secp256k1/contrib/lax_der_parsing.h +97 -0
  543. package/cpp/contrib/secp256k1/contrib/lax_der_privatekey_parsing.c +112 -0
  544. package/cpp/contrib/secp256k1/contrib/lax_der_privatekey_parsing.h +95 -0
  545. package/cpp/contrib/secp256k1/doc/ellswift.md +483 -0
  546. package/cpp/contrib/secp256k1/doc/musig.md +54 -0
  547. package/cpp/contrib/secp256k1/doc/release-process.md +94 -0
  548. package/cpp/contrib/secp256k1/doc/safegcd_implementation.md +819 -0
  549. package/cpp/contrib/secp256k1/examples/CMakeLists.txt +33 -0
  550. package/cpp/contrib/secp256k1/examples/EXAMPLES_COPYING +121 -0
  551. package/cpp/contrib/secp256k1/examples/ecdh.c +121 -0
  552. package/cpp/contrib/secp256k1/examples/ecdsa.c +138 -0
  553. package/cpp/contrib/secp256k1/examples/ellswift.c +122 -0
  554. package/cpp/contrib/secp256k1/examples/examples_util.h +108 -0
  555. package/cpp/contrib/secp256k1/examples/musig.c +261 -0
  556. package/cpp/contrib/secp256k1/examples/schnorr.c +154 -0
  557. package/cpp/contrib/secp256k1/include/secp256k1.h +877 -0
  558. package/cpp/contrib/secp256k1/include/secp256k1_dleag.h +150 -0
  559. package/cpp/contrib/secp256k1/include/secp256k1_ecdh.h +63 -0
  560. package/cpp/contrib/secp256k1/include/secp256k1_ecdsaotves.h +55 -0
  561. package/cpp/contrib/secp256k1/include/secp256k1_ed25519.h +239 -0
  562. package/cpp/contrib/secp256k1/include/secp256k1_ellswift.h +200 -0
  563. package/cpp/contrib/secp256k1/include/secp256k1_extrakeys.h +250 -0
  564. package/cpp/contrib/secp256k1/include/secp256k1_generator.h +106 -0
  565. package/cpp/contrib/secp256k1/include/secp256k1_hash.h +45 -0
  566. package/cpp/contrib/secp256k1/include/secp256k1_musig.h +588 -0
  567. package/cpp/contrib/secp256k1/include/secp256k1_preallocated.h +134 -0
  568. package/cpp/contrib/secp256k1/include/secp256k1_recovery.h +123 -0
  569. package/cpp/contrib/secp256k1/include/secp256k1_schnorrsig.h +190 -0
  570. package/cpp/contrib/secp256k1/include/visibility.h +58 -0
  571. package/cpp/contrib/secp256k1/libsecp256k1.pc.in +12 -0
  572. package/cpp/contrib/secp256k1/sage/gen_exhaustive_groups.sage +156 -0
  573. package/cpp/contrib/secp256k1/sage/gen_split_lambda_constants.sage +123 -0
  574. package/cpp/contrib/secp256k1/sage/group_prover.sage +353 -0
  575. package/cpp/contrib/secp256k1/sage/prove_group_implementations.sage +285 -0
  576. package/cpp/contrib/secp256k1/sage/secp256k1_params.sage +39 -0
  577. package/cpp/contrib/secp256k1/sage/weierstrass_prover.sage +275 -0
  578. package/cpp/contrib/secp256k1/src/CMakeLists.txt +253 -0
  579. package/cpp/contrib/secp256k1/src/asm/field_10x26_arm.s +916 -0
  580. package/cpp/contrib/secp256k1/src/assumptions.h +87 -0
  581. package/cpp/contrib/secp256k1/src/checkmem.h +117 -0
  582. package/cpp/contrib/secp256k1/src/ecdsa.h +21 -0
  583. package/cpp/contrib/secp256k1/src/ecdsa_impl.h +312 -0
  584. package/cpp/contrib/secp256k1/src/eckey.h +28 -0
  585. package/cpp/contrib/secp256k1/src/eckey_impl.h +94 -0
  586. package/cpp/contrib/secp256k1/src/ecmult.h +64 -0
  587. package/cpp/contrib/secp256k1/src/ecmult_compute_table.h +16 -0
  588. package/cpp/contrib/secp256k1/src/ecmult_compute_table_impl.h +49 -0
  589. package/cpp/contrib/secp256k1/src/ecmult_const.h +38 -0
  590. package/cpp/contrib/secp256k1/src/ecmult_const_impl.h +402 -0
  591. package/cpp/contrib/secp256k1/src/ecmult_gen.h +144 -0
  592. package/cpp/contrib/secp256k1/src/ecmult_gen_compute_table.h +14 -0
  593. package/cpp/contrib/secp256k1/src/ecmult_gen_compute_table_impl.h +108 -0
  594. package/cpp/contrib/secp256k1/src/ecmult_gen_impl.h +341 -0
  595. package/cpp/contrib/secp256k1/src/ecmult_impl.h +869 -0
  596. package/cpp/contrib/secp256k1/src/field.h +354 -0
  597. package/cpp/contrib/secp256k1/src/field_10x26.h +57 -0
  598. package/cpp/contrib/secp256k1/src/field_10x26_impl.h +1234 -0
  599. package/cpp/contrib/secp256k1/src/field_5x52.h +62 -0
  600. package/cpp/contrib/secp256k1/src/field_5x52_impl.h +524 -0
  601. package/cpp/contrib/secp256k1/src/field_5x52_int128_impl.h +274 -0
  602. package/cpp/contrib/secp256k1/src/field_impl.h +462 -0
  603. package/cpp/contrib/secp256k1/src/group.h +224 -0
  604. package/cpp/contrib/secp256k1/src/group_impl.h +1024 -0
  605. package/cpp/contrib/secp256k1/src/hash.h +54 -0
  606. package/cpp/contrib/secp256k1/src/hash_impl.h +360 -0
  607. package/cpp/contrib/secp256k1/src/hsort.h +33 -0
  608. package/cpp/contrib/secp256k1/src/hsort_impl.h +125 -0
  609. package/cpp/contrib/secp256k1/src/int128.h +90 -0
  610. package/cpp/contrib/secp256k1/src/int128_impl.h +18 -0
  611. package/cpp/contrib/secp256k1/src/int128_native.h +19 -0
  612. package/cpp/contrib/secp256k1/src/int128_native_impl.h +94 -0
  613. package/cpp/contrib/secp256k1/src/int128_struct.h +14 -0
  614. package/cpp/contrib/secp256k1/src/int128_struct_impl.h +205 -0
  615. package/cpp/contrib/secp256k1/src/modinv32.h +43 -0
  616. package/cpp/contrib/secp256k1/src/modinv32_impl.h +725 -0
  617. package/cpp/contrib/secp256k1/src/modinv64.h +47 -0
  618. package/cpp/contrib/secp256k1/src/modinv64_impl.h +780 -0
  619. package/cpp/contrib/secp256k1/src/modules/dleag/Makefile.am.include +3 -0
  620. package/cpp/contrib/secp256k1/src/modules/dleag/main_impl.h +1073 -0
  621. package/cpp/contrib/secp256k1/src/modules/dleag/tests_impl.h +68 -0
  622. package/cpp/contrib/secp256k1/src/modules/ecdh/Makefile.am.include +5 -0
  623. package/cpp/contrib/secp256k1/src/modules/ecdh/bench_impl.h +54 -0
  624. package/cpp/contrib/secp256k1/src/modules/ecdh/main_impl.h +79 -0
  625. package/cpp/contrib/secp256k1/src/modules/ecdh/tests_impl.h +218 -0
  626. package/cpp/contrib/secp256k1/src/modules/ecdsaotves/Makefile.am.include +3 -0
  627. package/cpp/contrib/secp256k1/src/modules/ecdsaotves/main_impl.h +365 -0
  628. package/cpp/contrib/secp256k1/src/modules/ecdsaotves/tests_impl.h +49 -0
  629. package/cpp/contrib/secp256k1/src/modules/ed25519/Makefile.am.include +16 -0
  630. package/cpp/contrib/secp256k1/src/modules/ed25519/common.h +68 -0
  631. package/cpp/contrib/secp256k1/src/modules/ed25519/core_ed25519.h +229 -0
  632. package/cpp/contrib/secp256k1/src/modules/ed25519/main_impl.h +98 -0
  633. package/cpp/contrib/secp256k1/src/modules/ed25519/ref10/common.h +21 -0
  634. package/cpp/contrib/secp256k1/src/modules/ed25519/ref10/ed25519_ref10.h +2698 -0
  635. package/cpp/contrib/secp256k1/src/modules/ed25519/ref10/ed25519_ref10_fe_25_5.h +1056 -0
  636. package/cpp/contrib/secp256k1/src/modules/ed25519/ref10/ed25519_ref10_fe_51.h +518 -0
  637. package/cpp/contrib/secp256k1/src/modules/ed25519/ref10/fe_25_5/base.h +1344 -0
  638. package/cpp/contrib/secp256k1/src/modules/ed25519/ref10/fe_25_5/base2.h +40 -0
  639. package/cpp/contrib/secp256k1/src/modules/ed25519/ref10/fe_25_5/constants.h +40 -0
  640. package/cpp/contrib/secp256k1/src/modules/ed25519/ref10/fe_25_5/fe.h +220 -0
  641. package/cpp/contrib/secp256k1/src/modules/ed25519/scalarmult_ed25519_ref10.h +417 -0
  642. package/cpp/contrib/secp256k1/src/modules/ed25519/sha512/hash_sha512.h +14 -0
  643. package/cpp/contrib/secp256k1/src/modules/ed25519/sha512/hash_sha512_cp.h +287 -0
  644. package/cpp/contrib/secp256k1/src/modules/ed25519/tests_impl.h +109 -0
  645. package/cpp/contrib/secp256k1/src/modules/ed25519/utils.h +97 -0
  646. package/cpp/contrib/secp256k1/src/modules/ellswift/Makefile.am.include +5 -0
  647. package/cpp/contrib/secp256k1/src/modules/ellswift/bench_impl.h +106 -0
  648. package/cpp/contrib/secp256k1/src/modules/ellswift/main_impl.h +581 -0
  649. package/cpp/contrib/secp256k1/src/modules/ellswift/tests_exhaustive_impl.h +39 -0
  650. package/cpp/contrib/secp256k1/src/modules/ellswift/tests_impl.h +544 -0
  651. package/cpp/contrib/secp256k1/src/modules/extrakeys/Makefile.am.include +4 -0
  652. package/cpp/contrib/secp256k1/src/modules/extrakeys/main_impl.h +285 -0
  653. package/cpp/contrib/secp256k1/src/modules/extrakeys/tests_exhaustive_impl.h +68 -0
  654. package/cpp/contrib/secp256k1/src/modules/extrakeys/tests_impl.h +484 -0
  655. package/cpp/contrib/secp256k1/src/modules/generator/Makefile.am.include +9 -0
  656. package/cpp/contrib/secp256k1/src/modules/generator/main_impl.h +271 -0
  657. package/cpp/contrib/secp256k1/src/modules/generator/tests_impl.h +227 -0
  658. package/cpp/contrib/secp256k1/src/modules/musig/Makefile.am.include +8 -0
  659. package/cpp/contrib/secp256k1/src/modules/musig/keyagg.h +32 -0
  660. package/cpp/contrib/secp256k1/src/modules/musig/keyagg_impl.h +275 -0
  661. package/cpp/contrib/secp256k1/src/modules/musig/main_impl.h +12 -0
  662. package/cpp/contrib/secp256k1/src/modules/musig/session.h +24 -0
  663. package/cpp/contrib/secp256k1/src/modules/musig/session_impl.h +795 -0
  664. package/cpp/contrib/secp256k1/src/modules/musig/tests_impl.h +1161 -0
  665. package/cpp/contrib/secp256k1/src/modules/musig/vectors.h +346 -0
  666. package/cpp/contrib/secp256k1/src/modules/recovery/Makefile.am.include +5 -0
  667. package/cpp/contrib/secp256k1/src/modules/recovery/bench_impl.h +62 -0
  668. package/cpp/contrib/secp256k1/src/modules/recovery/main_impl.h +159 -0
  669. package/cpp/contrib/secp256k1/src/modules/recovery/tests_exhaustive_impl.h +148 -0
  670. package/cpp/contrib/secp256k1/src/modules/recovery/tests_impl.h +339 -0
  671. package/cpp/contrib/secp256k1/src/modules/schnorrsig/Makefile.am.include +5 -0
  672. package/cpp/contrib/secp256k1/src/modules/schnorrsig/bench_impl.h +104 -0
  673. package/cpp/contrib/secp256k1/src/modules/schnorrsig/main_impl.h +263 -0
  674. package/cpp/contrib/secp256k1/src/modules/schnorrsig/tests_exhaustive_impl.h +214 -0
  675. package/cpp/contrib/secp256k1/src/modules/schnorrsig/tests_impl.h +1010 -0
  676. package/cpp/contrib/secp256k1/src/precompute_ecmult.c +91 -0
  677. package/cpp/contrib/secp256k1/src/precompute_ecmult_gen.c +101 -0
  678. package/cpp/contrib/secp256k1/src/precomputed_ecmult.c +16456 -0
  679. package/cpp/contrib/secp256k1/src/precomputed_ecmult.h +40 -0
  680. package/cpp/contrib/secp256k1/src/precomputed_ecmult_gen.c +1779 -0
  681. package/cpp/contrib/secp256k1/src/precomputed_ecmult_gen.h +28 -0
  682. package/cpp/contrib/secp256k1/src/scalar.h +108 -0
  683. package/cpp/contrib/secp256k1/src/scalar_4x64.h +19 -0
  684. package/cpp/contrib/secp256k1/src/scalar_4x64_impl.h +1010 -0
  685. package/cpp/contrib/secp256k1/src/scalar_8x32.h +19 -0
  686. package/cpp/contrib/secp256k1/src/scalar_8x32_impl.h +830 -0
  687. package/cpp/contrib/secp256k1/src/scalar_impl.h +321 -0
  688. package/cpp/contrib/secp256k1/src/scalar_low.h +24 -0
  689. package/cpp/contrib/secp256k1/src/scalar_low_impl.h +215 -0
  690. package/cpp/contrib/secp256k1/src/scratch.h +44 -0
  691. package/cpp/contrib/secp256k1/src/scratch_impl.h +99 -0
  692. package/cpp/contrib/secp256k1/src/secp256k1.c +896 -0
  693. package/cpp/contrib/secp256k1/src/selftest.h +35 -0
  694. package/cpp/contrib/secp256k1/src/testrand.h +45 -0
  695. package/cpp/contrib/secp256k1/src/testrand_impl.h +162 -0
  696. package/cpp/contrib/secp256k1/src/testutil.h +161 -0
  697. package/cpp/contrib/secp256k1/src/unit_test.c +479 -0
  698. package/cpp/contrib/secp256k1/src/unit_test.h +147 -0
  699. package/cpp/contrib/secp256k1/src/util.h +469 -0
  700. package/cpp/contrib/secp256k1/src/util_local_visibility.h +12 -0
  701. package/cpp/contrib/secp256k1/tools/check-abi.sh +67 -0
  702. package/cpp/contrib/secp256k1/tools/symbol-check.py +72 -0
  703. package/cpp/contrib/secp256k1/tools/test_vectors_musig2_generate.py +656 -0
  704. package/cpp/contrib/secp256k1/tools/tests_wycheproof_generate_ecdh.py +166 -0
  705. package/cpp/contrib/secp256k1/tools/tests_wycheproof_generate_ecdsa.py +111 -0
  706. package/cpp/contrib/secp256k1/tools/wycheproof_utils.py +12 -0
  707. package/cpp/contrib/secp256k1/wasm/test_module.html +320 -0
  708. package/cpp/contrib/secp256k1/wasm/wrap.cpp +331 -0
  709. package/cpp/contrib/sqlite3.h +14349 -0
  710. package/cpp/contrib/sqlite3mc_amalgamation.c +369890 -0
  711. package/cpp/contrib/sqlite3mc_amalgamation.h +15548 -0
  712. package/cpp/contrib/unilib/uninorms.cpp +393 -0
  713. package/cpp/contrib/unilib/uninorms.h +56 -0
  714. package/cpp/contrib/unilib/utf8.cpp +78 -0
  715. package/cpp/contrib/unilib/utf8.h +260 -0
  716. package/cpp/contrib/update_mbedtls.sh +85 -0
  717. package/cpp/crypto/aes.cpp +141 -0
  718. package/cpp/crypto/aes.h +67 -0
  719. package/cpp/crypto/chacha20.cpp +342 -0
  720. package/cpp/crypto/chacha20.h +82 -0
  721. package/cpp/crypto/chacha20poly1305.cpp +91 -0
  722. package/cpp/crypto/chacha20poly1305.h +46 -0
  723. package/cpp/crypto/common.h +85 -0
  724. package/cpp/crypto/ctaes/COPYING +21 -0
  725. package/cpp/crypto/ctaes/README.md +41 -0
  726. package/cpp/crypto/ctaes/bench.c +170 -0
  727. package/cpp/crypto/ctaes/ctaes.c +556 -0
  728. package/cpp/crypto/ctaes/ctaes.h +41 -0
  729. package/cpp/crypto/ctaes/test.c +110 -0
  730. package/cpp/crypto/extkey.cpp +257 -0
  731. package/cpp/crypto/extkey.h +66 -0
  732. package/cpp/crypto/hmac_sha512.cpp +37 -0
  733. package/cpp/crypto/hmac_sha512.h +32 -0
  734. package/cpp/crypto/merkle.cpp +47 -0
  735. package/cpp/crypto/merkle.h +20 -0
  736. package/cpp/crypto/poly1305.cpp +223 -0
  737. package/cpp/crypto/poly1305.h +59 -0
  738. package/cpp/crypto/ripemd160.cpp +292 -0
  739. package/cpp/crypto/ripemd160.h +28 -0
  740. package/cpp/crypto/scrypt-sse2.cpp +141 -0
  741. package/cpp/crypto/scrypt.cpp +336 -0
  742. package/cpp/crypto/scrypt.h +49 -0
  743. package/cpp/crypto/sealed_key.cpp +62 -0
  744. package/cpp/crypto/sealed_key.h +34 -0
  745. package/cpp/crypto/secure_bytes.h +16 -0
  746. package/cpp/crypto/sha512.cpp +206 -0
  747. package/cpp/crypto/sha512.h +29 -0
  748. package/cpp/crypto/util.cpp +77 -0
  749. package/cpp/crypto/util.h +32 -0
  750. package/cpp/debug_rpc.cpp +703 -0
  751. package/cpp/debug_rpc.h +63 -0
  752. package/cpp/electrum.cpp +931 -0
  753. package/cpp/electrum.h +169 -0
  754. package/cpp/engine/xmr_engine.cpp +463 -0
  755. package/cpp/engine/xmr_engine.h +84 -0
  756. package/cpp/engine/xmr_engine_c.cpp +141 -0
  757. package/cpp/engine/xmr_engine_c.h +35 -0
  758. package/cpp/fees.cpp +270 -0
  759. package/cpp/fees.h +60 -0
  760. package/cpp/height_search.cpp +64 -0
  761. package/cpp/height_search.h +27 -0
  762. package/cpp/main.cpp +146 -0
  763. package/cpp/messages_npb.cpp +701 -0
  764. package/cpp/messages_npb.h +667 -0
  765. package/cpp/mnemonic/mnemonic.cpp +715 -0
  766. package/cpp/mnemonic/mnemonic.h +52 -0
  767. package/cpp/mnemonic/wordlists/english.h +1103 -0
  768. package/cpp/mnemonic/wordlists/japanese.h +2212 -0
  769. package/cpp/network/bridge.cpp +232 -0
  770. package/cpp/network/bridge.h +115 -0
  771. package/cpp/network/ca_roots.cpp +114 -0
  772. package/cpp/network/ca_roots.h +12 -0
  773. package/cpp/network/http_client.cpp +261 -0
  774. package/cpp/network/http_client.h +33 -0
  775. package/cpp/network/pem.cpp +84 -0
  776. package/cpp/network/pem.h +22 -0
  777. package/cpp/network/psa_user_config.h +15 -0
  778. package/cpp/network/socks5.cpp +180 -0
  779. package/cpp/network/socks5.h +26 -0
  780. package/cpp/network/tls_transport.cpp +502 -0
  781. package/cpp/network/tls_transport.h +62 -0
  782. package/cpp/network/transport.cpp +169 -0
  783. package/cpp/network/transport.h +115 -0
  784. package/cpp/network/url.cpp +88 -0
  785. package/cpp/network/url.h +25 -0
  786. package/cpp/network/websocket.cpp +253 -0
  787. package/cpp/network/websocket.h +68 -0
  788. package/cpp/network/ws_transport.cpp +361 -0
  789. package/cpp/network/ws_transport.h +72 -0
  790. package/cpp/node_client.cpp +1196 -0
  791. package/cpp/node_client.h +209 -0
  792. package/cpp/node_scan.h +35 -0
  793. package/cpp/schema.cpp +1249 -0
  794. package/cpp/schema.h +132 -0
  795. package/cpp/smsg.cpp +453 -0
  796. package/cpp/smsg.h +43 -0
  797. package/cpp/support/allocators/secure.h +85 -0
  798. package/cpp/support/cleanse.cpp +35 -0
  799. package/cpp/support/cleanse.h +15 -0
  800. package/cpp/support/coop.cpp +319 -0
  801. package/cpp/support/coop.h +157 -0
  802. package/cpp/support/lockedpool.cpp +406 -0
  803. package/cpp/support/lockedpool.h +240 -0
  804. package/cpp/uint256.cpp +62 -0
  805. package/cpp/uint256.h +121 -0
  806. package/cpp/util/base58.cpp +181 -0
  807. package/cpp/util/base58.h +45 -0
  808. package/cpp/util/bech32.cpp +578 -0
  809. package/cpp/util/bech32.h +96 -0
  810. package/cpp/util/debug.cpp +23 -0
  811. package/cpp/util/debug.h +12 -0
  812. package/cpp/util/int.cpp +118 -0
  813. package/cpp/util/int.h +18 -0
  814. package/cpp/util/json.h +26 -0
  815. package/cpp/util/log.cpp +137 -0
  816. package/cpp/util/log.h +37 -0
  817. package/cpp/util/mutex.h +89 -0
  818. package/cpp/util/platform.cpp +90 -0
  819. package/cpp/util/platform.h +17 -0
  820. package/cpp/util/random.cpp +136 -0
  821. package/cpp/util/random.h +28 -0
  822. package/cpp/util/rpc.cpp +192 -0
  823. package/cpp/util/rpc.h +454 -0
  824. package/cpp/util/str.cpp +254 -0
  825. package/cpp/util/str.h +54 -0
  826. package/cpp/util/thread.cpp +17 -0
  827. package/cpp/util/thread.h +12 -0
  828. package/cpp/util/time.cpp +30 -0
  829. package/cpp/util/time.h +30 -0
  830. package/cpp/util/tinyformat.h +1163 -0
  831. package/cpp/util/vector.h +83 -0
  832. package/cpp/version.h.in +12 -0
  833. package/cpp/view_key_chain.h +283 -0
  834. package/cpp/wallet/account_wallet.cpp +668 -0
  835. package/cpp/wallet/account_wallet.h +136 -0
  836. package/cpp/wallet/base_wallet.cpp +302 -0
  837. package/cpp/wallet/base_wallet.h +129 -0
  838. package/cpp/wallet/debug_wallet.cpp +40 -0
  839. package/cpp/wallet/debug_wallet.h +36 -0
  840. package/cpp/wallet/encrypted_seed.cpp +96 -0
  841. package/cpp/wallet/encrypted_seed.h +41 -0
  842. package/cpp/wallet/host_wallet.cpp +85 -0
  843. package/cpp/wallet/host_wallet.h +51 -0
  844. package/cpp/wallet/native_wallet.cpp +34 -0
  845. package/cpp/wallet/native_wallet.h +28 -0
  846. package/cpp/wallet/xmr/account_wallet.cpp +803 -0
  847. package/cpp/wallet/xmr/account_wallet.h +139 -0
  848. package/cpp/wallet/xmr/builder.cpp +568 -0
  849. package/cpp/wallet/xmr/builder.h +65 -0
  850. package/cpp/wallet/xmr/chain.cpp +1437 -0
  851. package/cpp/wallet/xmr/chain.h +213 -0
  852. package/cpp/wallet/xmr/daemon.cpp +583 -0
  853. package/cpp/wallet/xmr/daemon.h +153 -0
  854. package/cpp/wallet/xmr/decoys.cpp +197 -0
  855. package/cpp/wallet/xmr/decoys.h +64 -0
  856. package/cpp/wallet/xmr/epee.cpp +448 -0
  857. package/cpp/wallet/xmr/epee.h +25 -0
  858. package/cpp/wallet/xmr/fee.cpp +169 -0
  859. package/cpp/wallet/xmr/fee.h +61 -0
  860. package/cpp/wallet/xmr/reserve_proof.cpp +169 -0
  861. package/cpp/wallet/xmr/reserve_proof.h +24 -0
  862. package/cpp/wallet/xmr/scanner.cpp +860 -0
  863. package/cpp/wallet/xmr/scanner.h +239 -0
  864. package/lib/commonjs/NativeNitroBSX.js +128 -0
  865. package/lib/commonjs/NativeNitroBSX.js.map +1 -0
  866. package/lib/commonjs/format.js +21 -0
  867. package/lib/commonjs/format.js.map +1 -0
  868. package/lib/commonjs/index.js +50 -0
  869. package/lib/commonjs/index.js.map +1 -0
  870. package/lib/commonjs/service.js +75 -0
  871. package/lib/commonjs/service.js.map +1 -0
  872. package/lib/commonjs/specs/NitroBSX.nitro.js +6 -0
  873. package/lib/commonjs/specs/NitroBSX.nitro.js.map +1 -0
  874. package/lib/module/NativeNitroBSX.js +124 -0
  875. package/lib/module/NativeNitroBSX.js.map +1 -0
  876. package/lib/module/format.js +15 -0
  877. package/lib/module/format.js.map +1 -0
  878. package/lib/module/index.js +7 -0
  879. package/lib/module/index.js.map +1 -0
  880. package/lib/module/service.js +66 -0
  881. package/lib/module/service.js.map +1 -0
  882. package/lib/module/specs/NitroBSX.nitro.js +4 -0
  883. package/lib/module/specs/NitroBSX.nitro.js.map +1 -0
  884. package/lib/typescript/commonjs/package.json +1 -0
  885. package/lib/typescript/commonjs/src/NativeNitroBSX.d.ts +94 -0
  886. package/lib/typescript/commonjs/src/NativeNitroBSX.d.ts.map +1 -0
  887. package/lib/typescript/commonjs/src/format.d.ts +3 -0
  888. package/lib/typescript/commonjs/src/format.d.ts.map +1 -0
  889. package/lib/typescript/commonjs/src/index.d.ts +5 -0
  890. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  891. package/lib/typescript/commonjs/src/service.d.ts +28 -0
  892. package/lib/typescript/commonjs/src/service.d.ts.map +1 -0
  893. package/lib/typescript/commonjs/src/specs/NitroBSX.nitro.d.ts +251 -0
  894. package/lib/typescript/commonjs/src/specs/NitroBSX.nitro.d.ts.map +1 -0
  895. package/lib/typescript/module/package.json +1 -0
  896. package/lib/typescript/module/src/NativeNitroBSX.d.ts +94 -0
  897. package/lib/typescript/module/src/NativeNitroBSX.d.ts.map +1 -0
  898. package/lib/typescript/module/src/format.d.ts +3 -0
  899. package/lib/typescript/module/src/format.d.ts.map +1 -0
  900. package/lib/typescript/module/src/index.d.ts +5 -0
  901. package/lib/typescript/module/src/index.d.ts.map +1 -0
  902. package/lib/typescript/module/src/service.d.ts +28 -0
  903. package/lib/typescript/module/src/service.d.ts.map +1 -0
  904. package/lib/typescript/module/src/specs/NitroBSX.nitro.d.ts +251 -0
  905. package/lib/typescript/module/src/specs/NitroBSX.nitro.d.ts.map +1 -0
  906. package/nitro.json +19 -0
  907. package/nitrogen/generated/android/NitroBSX+autolinking.cmake +81 -0
  908. package/nitrogen/generated/android/NitroBSX+autolinking.gradle +27 -0
  909. package/nitrogen/generated/android/NitroBSXOnLoad.cpp +49 -0
  910. package/nitrogen/generated/android/NitroBSXOnLoad.hpp +34 -0
  911. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrobsx/NitroBSXOnLoad.kt +35 -0
  912. package/nitrogen/generated/ios/NitroBSX+autolinking.rb +62 -0
  913. package/nitrogen/generated/ios/NitroBSX-Swift-Cxx-Bridge.cpp +17 -0
  914. package/nitrogen/generated/ios/NitroBSX-Swift-Cxx-Bridge.hpp +27 -0
  915. package/nitrogen/generated/ios/NitroBSX-Swift-Cxx-Umbrella.hpp +38 -0
  916. package/nitrogen/generated/ios/NitroBSXAutolinking.mm +35 -0
  917. package/nitrogen/generated/ios/NitroBSXAutolinking.swift +16 -0
  918. package/nitrogen/generated/shared/c++/HybridNitroBSXSpec.cpp +91 -0
  919. package/nitrogen/generated/shared/c++/HybridNitroBSXSpec.hpp +142 -0
  920. package/nitrogen/generated/shared/c++/NotificationPair.hpp +87 -0
  921. package/nitrogen/generated/shared/c++/SignOutcome.hpp +80 -0
  922. package/nitrogen/generated/shared/c++/SignTxResult.hpp +89 -0
  923. package/package.json +172 -4
  924. package/react-native-nitro-bsx.podspec +33 -0
  925. package/react-native.config.js +26 -0
  926. package/scripts/build-ios.sh +49 -0
  927. package/src/NativeNitroBSX.ts +203 -0
  928. package/src/format.ts +14 -0
  929. package/src/index.ts +4 -0
  930. package/src/service.ts +77 -0
  931. package/src/specs/NitroBSX.nitro.ts +300 -0
@@ -0,0 +1,1523 @@
1
+ /*Copyright (c) 2025-2026 The Basicswap developers
2
+ Distributed under the MIT software license, see the accompanying
3
+ file LICENSE or http://www.opensource.org/licenses/mit-license.php.*/
4
+
5
+ #pragma once
6
+
7
+ #include "BSXContext.h"
8
+ #include "bsx/types.h"
9
+ #include "bsx_db.h"
10
+ #include "coins/chainparams.h"
11
+ #include "crypto/sealed_key.h"
12
+ #include "electrum.h"
13
+ #include "fees.h"
14
+ #include "height_search.h"
15
+ #include "network/bridge.h"
16
+ #include "node_client.h"
17
+ #include "support/allocators/secure.h"
18
+ #include "util/mutex.h"
19
+ #include "view_key_chain.h"
20
+ #include "wallet/base_wallet.h"
21
+
22
+ #include "contrib/nlohmann/json.hpp"
23
+ #include "contrib/sqlite3.h"
24
+
25
+ #include <array>
26
+ #include <atomic>
27
+ #include <condition_variable>
28
+ #include <deque>
29
+ #include <functional>
30
+ #include <map>
31
+ #include <set>
32
+ #include <string>
33
+ #include <vector>
34
+
35
+ namespace bsx {
36
+ namespace xmr {
37
+ class AccountWallet;
38
+ }
39
+ class NonProtobuf;
40
+
41
+ class SwapOptions {
42
+ public:
43
+ int m_coin_from;
44
+ int m_coin_to;
45
+ int64_t m_amount_from;
46
+ int64_t m_amount_to;
47
+ std::string m_address_to;
48
+ // Where lock tx a's change goes, and with it the whole amount on a failed
49
+ // swap. Empty means the module's own wallet.
50
+ std::string m_change_address;
51
+ std::vector<SwapInput> m_outputs_from;
52
+ bool m_spend_all{false};
53
+ // A spend-all request names the rate its own lock is priced at
54
+ int64_t m_fee_rate_from{0};
55
+ // A view-key chain's deposit, and the outputs of it the request proves
56
+ std::vector<unsigned char> m_deposit_id;
57
+ std::vector<std::pair<std::vector<unsigned char>, uint32_t>> m_deposit_outputs;
58
+ };
59
+
60
+ class DepositOptions {
61
+ public:
62
+ int m_coin_from{0};
63
+ int64_t m_amount_from{0};
64
+ int m_coin_to{0};
65
+ int64_t m_min_amount_to{0};
66
+ std::string m_address_to;
67
+ std::string m_refund_address;
68
+ };
69
+
70
+ // amount is what the address receives, or with m_subtract_fee what the wallet spends
71
+ class WalletSendOptions {
72
+ public:
73
+ int m_coin{0};
74
+ std::string m_address;
75
+ int64_t m_amount{0};
76
+ int64_t m_fee_rate{0};
77
+ bool m_subtract_fee{false};
78
+ bool m_spend_all{false};
79
+ bool m_dry_run{false};
80
+ // XMR's in place of a fee rate: Monero's priority, 1 to 4, or 0 for the wallet's choice
81
+ uint32_t m_priority{0};
82
+ };
83
+
84
+ class SwapRequestReturn {
85
+ public:
86
+ std::string m_str_error;
87
+ unsigned char m_request_id[28];
88
+ };
89
+
90
+ class WatchedScript {
91
+ public:
92
+ int64_t m_watched_id;
93
+ int m_coin_type;
94
+ int m_tx_type;
95
+ int64_t m_expect_value;
96
+ std::vector<unsigned char> m_swap_id;
97
+ // Its swap's creation: nothing paid the script before
98
+ int64_t m_since{0};
99
+ std::vector<unsigned char> m_script;
100
+ // Set once the tx is found for merkle responses
101
+ std::vector<unsigned char> m_txid;
102
+ int m_txout_n{-1};
103
+ // Height a merkle reply reported for m_txid, when it disagreed with the one
104
+ // listunspent gave. Outranks listunspent for the life of the pin, so a
105
+ // correction isn't undone by the next poll. Note most servers echo back
106
+ // the height the request asked for rather than looking it up (electrs
107
+ // returns the argument verbatim), so this only ever fires on a server that
108
+ // resolves it independently.
109
+ int m_block_height{-1};
110
+ size_t m_turn{0};
111
+ std::map<ElectrumMessageTypes, size_t> m_turns_by_type;
112
+ };
113
+
114
+ class WatchedTxn {
115
+ public:
116
+ int64_t m_watched_id{0};
117
+ int m_coin_type{0};
118
+ int m_tx_type{0};
119
+ std::vector<unsigned char> m_swap_id;
120
+ int64_t m_since{0};
121
+ std::vector<unsigned char> m_txid;
122
+ bool m_from_history{false};
123
+ size_t m_turn{0};
124
+ std::map<ElectrumMessageTypes, size_t> m_turns_by_type;
125
+ };
126
+
127
+ class DepositScanFetch {
128
+ public:
129
+ uint32_t m_index{0};
130
+ std::vector<unsigned char> m_txid;
131
+ };
132
+
133
+ class SavedDepositWatch {
134
+ public:
135
+ uint32_t m_index{0};
136
+ uint64_t m_start{0};
137
+ std::string m_outputs;
138
+ bool m_caught_up{false};
139
+ };
140
+
141
+ class DepositScan {
142
+ public:
143
+ int m_coin_type{0};
144
+ // When the deposit scripts could first be paid, for a node's block scan
145
+ int64_t m_since{0};
146
+ int64_t m_highest_used{-1};
147
+ uint32_t m_next_index{0};
148
+ std::map<int64_t, uint32_t> m_pending; // watched id to deposit index
149
+ // watched id to the first tx of an index with history
150
+ std::map<int64_t, DepositScanFetch> m_fetching;
151
+ // watched id to a used index with no deposit row, whose unspent coins are listed
152
+ std::map<int64_t, uint32_t> m_unspent;
153
+ // An index with history showed no payment to it, so the scan isn't recorded as done
154
+ bool m_unproven{false};
155
+ // A view-key chain's scan: from the height entered, each pass to the tip it had at its start
156
+ int64_t m_from_height{-1};
157
+ // Searched for a height only when none was entered
158
+ int64_t m_from_time{-1};
159
+ int64_t m_search_id{-1};
160
+ int64_t m_pass_to{-1};
161
+ std::map<int64_t, uint32_t> m_watching; // chain watch id to deposit index
162
+ // chain watch id to a used index with no deposit row, whose outputs' spends are checked
163
+ std::map<int64_t, uint32_t> m_checking;
164
+ // Where a new window's watches start: the birthday's height, then the height already scanned
165
+ int64_t m_pass_from{-1};
166
+ std::map<int64_t, uint64_t> m_starts; // chain watch id to its start height
167
+ // Progress saved as it scans: the watches to set up again at start, and the resume height
168
+ std::vector<SavedDepositWatch> m_restore;
169
+ int64_t m_saved_resume{-1};
170
+ bool m_save_due{false};
171
+ // Started by rescanDepositChain, from its own height or date rather than the birthday's
172
+ bool m_rescan{false};
173
+ // A UTXO walk's state as last saved
174
+ std::string m_saved_state;
175
+ // Watches added mid-pass, being scanned again from the birthday's height, and those done
176
+ std::set<int64_t> m_catching;
177
+ std::set<int64_t> m_caught_up;
178
+ };
179
+
180
+ class DepositUtxo {
181
+ public:
182
+ std::vector<unsigned char> m_txid;
183
+ uint32_t m_vout{0};
184
+ int64_t m_value{0};
185
+ int m_height{0};
186
+ };
187
+
188
+ class DepositTxCheck {
189
+ public:
190
+ bool m_fetched{false};
191
+ std::map<uint32_t, int64_t> m_outputs; // vout to value, deposit script outputs only
192
+ int64_t m_checked_at{0};
193
+ };
194
+
195
+ class DepositProof {
196
+ public:
197
+ int m_height{0};
198
+ bool m_proven{false};
199
+ uint256 m_block_hash;
200
+ int64_t m_checked_at{0};
201
+ };
202
+
203
+ class DepositWatch {
204
+ public:
205
+ int64_t m_watched_id{0};
206
+ int64_t m_view_key_id{0};
207
+ int m_coin_type{0};
208
+ int64_t m_since{0};
209
+ int m_created_height{0};
210
+ std::vector<unsigned char> m_deposit_id;
211
+ std::vector<unsigned char> m_script;
212
+ // The server's last listunspent reply, unchecked
213
+ bool m_listed_any{false};
214
+ std::vector<DepositUtxo> m_listed;
215
+ std::map<std::vector<unsigned char>, DepositTxCheck> m_txs;
216
+ std::map<std::vector<unsigned char>, DepositProof> m_proofs;
217
+ bool m_polled{false};
218
+ int m_polled_state{0};
219
+ std::vector<DepositUtxo> m_utxos;
220
+ int64_t m_unconfirmed{0};
221
+ std::vector<unsigned char> m_sweep_txid;
222
+ int m_sweep_height{0};
223
+ std::vector<std::vector<unsigned char>> m_replaced_sweep_txids;
224
+ int64_t m_sweep_sent_at{0};
225
+ int64_t m_sweep_started_at{0};
226
+ std::string m_sweep_error;
227
+ int64_t m_saved_resume{-1};
228
+ // Set only while the deposit is SWEPT: a confirmed sweep spent these, so a restart needn't
229
+ // scan their blocks again
230
+ std::vector<unsigned char> m_swept_outpoints;
231
+ };
232
+
233
+ class TxChainState {
234
+ public:
235
+ int depth{-2};
236
+ };
237
+
238
+ // Which host the module is embedded in. Only reached through key paths, so a
239
+ // value must never be reused for a different app.
240
+ namespace AppTypes {
241
+ enum AppTypes {
242
+ STANDALONE = 0,
243
+ NEXUS = 1,
244
+ };
245
+ } // namespace AppTypes
246
+
247
+ class BSXSettings {
248
+ public:
249
+ std::string m_datadir;
250
+ int m_app_type{AppTypes::STANDALONE};
251
+ int m_chain_type{ChainParams::MAINNET};
252
+ // The app's name to the glue, which charges it the fees for that name
253
+ std::string m_client;
254
+ bool m_debug{false};
255
+ bool m_require_tx_merkle_proof{true};
256
+ bool m_verify_pos_headers{true};
257
+ // Hand the leader the keyshare after swiping, stranding neither side's coin.
258
+ // The swipe pays a key this module derives so it can sign the mercy tx; with
259
+ // this off it pays the host wallet directly and no keyshare is sent.
260
+ bool m_altruistic{true};
261
+ // Off where the host's own seed restores the key (Nexus)
262
+ bool m_store_mnemonic{false};
263
+ bool m_encrypt_db{false};
264
+
265
+ // One tor for the whole module, so it is a module setting rather than a
266
+ // per-server one like the tls options.
267
+ ProxyOptions m_proxy;
268
+ int m_max_electrum_servers{2};
269
+
270
+ bool m_expire_data{true};
271
+ int64_t m_expire_data_after{7 * 86400};
272
+
273
+ int m_swap_request_valid_seconds{10 * 60};
274
+ int m_max_offer_valid_seconds{24 * 60 * 60};
275
+ int m_lock_tx_a_timeout{20 * 60};
276
+ int m_lock_tx_a_long_timeout{12 * 60 * 60};
277
+
278
+ // Accepted offer lock times: each within its range, and lock_time_2 never
279
+ // below lock_time_1
280
+ int m_min_lock_time_1{48 * 60 * 60};
281
+ int m_max_lock_time_1{48 * 60 * 60};
282
+ int m_min_lock_time_2{48 * 60 * 60};
283
+ int m_max_lock_time_2{48 * 60 * 60};
284
+ int m_min_lock_time_1_reverse{12 * 60 * 60};
285
+ int m_max_lock_time_1_reverse{12 * 60 * 60};
286
+ // Bridged offers: lock times outside min..max are refused, under warn shown with a warning
287
+ int m_min_lock_time_bridged{4 * 60 * 60};
288
+ int m_warn_lock_time_bridged{12 * 60 * 60};
289
+ int m_max_lock_time_bridged{96 * 60 * 60};
290
+
291
+ int m_sc_lock_release_min_margin{60 * 60};
292
+ int m_sc_lock_spend_min_margin{60 * 60};
293
+
294
+ // int m_check_update_seconds{20};
295
+ int m_check_update_seconds{5};
296
+
297
+ // Resend a message when no response is seen for this long
298
+ int m_resend_msg_seconds{60};
299
+
300
+ int m_retry_submit_delay{2 * 60};
301
+
302
+ // A pay-in refund still unconfirmed this long is signed again if the fee estimate rose
303
+ int m_deposit_sweep_resign_seconds{60 * 60};
304
+
305
+ int m_electrum_poll_seconds{30};
306
+ // How often a view-key chain asks its daemons for the tip, fee estimate and backlog
307
+ int m_view_key_info_refresh_seconds{60};
308
+ int m_view_key_tip_refresh_seconds{30};
309
+
310
+ int64_t m_max_fee_bps{500};
311
+
312
+ // Bounds what one request can be made to store; the server chooses how many
313
+ // it sends within it.
314
+ int m_max_bridged_offers{10};
315
+
316
+ // How much cheaper than the request's rate a bridged offer may be before it reads as bait.
317
+ int64_t m_bridged_rate_better_bps{4000};
318
+
319
+ // How much worse than the request's rate an offer may be before it is refused outright.
320
+ int64_t m_offer_rate_worse_bps{2000};
321
+
322
+ size_t m_debug_rpc_port{0};
323
+
324
+ // require_server_identity, which the browser build's config sets
325
+ bool m_require_server_identity{false};
326
+
327
+ // host:port -> fingerprints a config named. Checked before trust on first use.
328
+ std::map<std::string, std::vector<std::vector<unsigned char>>> m_required_pins;
329
+
330
+ // The glue, as the config names it; initialise hands these to m_bridge
331
+ std::vector<unsigned char> m_bridge_pubkey;
332
+ std::string m_bridge_host{"127.0.0.1"};
333
+ int m_bridge_port{9002};
334
+ bool m_bridge_use_ssl{false};
335
+ TlsOptions m_bridge_tls_options;
336
+ };
337
+
338
+ class BSXModule : public BSXContext, public BSXDB {
339
+ public:
340
+ BSXModule();
341
+ virtual ~BSXModule();
342
+
343
+ int initialise(bool start_thread = true);
344
+ // For a caller that has already set m_starting; it is cleared on return or throw
345
+ int initialiseClaimed(bool start_thread = true);
346
+ int finalise();
347
+
348
+ int addCi(int coin_type);
349
+ std::shared_ptr<CoinInterface> ci(int coin_type) LOCKS_EXCLUDED(m_mtx_registry);
350
+ // Snapshots: iterate these instead of the members, so no lock is held
351
+ // across the loop body.
352
+ std::vector<std::shared_ptr<CoinInterface>> coinInterfaces() const
353
+ LOCKS_EXCLUDED(m_mtx_registry);
354
+ std::vector<std::shared_ptr<BaseWallet>> wallets() const LOCKS_EXCLUDED(m_mtx_registry);
355
+ // Wallets are optional: a coin added without one falls back to the flat
356
+ // debug_keys store, which is what the tests and any pre-wallet db rely on.
357
+ int addWallet(int coin_type, int wallet_type);
358
+ int setWalletAccountKey(std::shared_ptr<BaseWallet> wallet);
359
+ std::shared_ptr<BaseWallet> wallet(int coin_type) LOCKS_EXCLUDED(m_mtx_registry);
360
+ // formatAmount through the coin interface, falling back to raw sats when the
361
+ // coin isn't configured - stored requests and swaps outlive settings changes.
362
+ std::string formatAmount(int coin_type, int64_t amount);
363
+ // The bridge server's fees for coin_type, as the outputs owed on swap_amount
364
+ int getSwapFeeOutputs(std::vector<SwapFeeOutput> &fee_outputs, int coin_type, int coin_to,
365
+ int64_t swap_amount) REQUIRES(m_mtx_db);
366
+ // Fees out of what the app receives, as follower or leader; receiveFees takes the worse role
367
+ int receiveFees(npb::FeeRule &rule, std::vector<AppFee> &fees, int64_t &bound_bps,
368
+ int coin_send, int coin_receive) REQUIRES(m_mtx_db);
369
+ int receiveFeesAs(npb::FeeRule &rule, std::vector<AppFee> &fees, int64_t &bound_bps,
370
+ int coin_send, int coin_receive, bool app_leads) REQUIRES(m_mtx_db);
371
+ int getReceiveFeeOutputs(std::vector<SwapFeeOutput> &fee_outputs, int coin_send,
372
+ int coin_receive, int64_t amount) REQUIRES(m_mtx_db);
373
+ // Before an offer: the worse of leading and following, each over every tx the app pays on
374
+ int appFeeBoundBps(int64_t &bound_bps, int coin_send, int coin_receive) REQUIRES(m_mtx_db);
375
+ int receiveFeeMinimum(int64_t &minimum, int coin_send, int coin_receive) REQUIRES(m_mtx_db);
376
+ int checkFeeCap(int coin_type, int coin_to, std::string &str_error) REQUIRES(m_mtx_db);
377
+ int checkFundingDust(int coin_type, int coin_to, int64_t amount, std::string &str_error)
378
+ REQUIRES(m_mtx_db);
379
+ int checkReceiveDust(int coin_send, int coin_receive, int64_t amount, std::string &str_error)
380
+ REQUIRES(m_mtx_db);
381
+ int snapshotSwapFees(SwapInfo &swap_info, const OfferData &offer, std::string &str_error)
382
+ LOCKS_EXCLUDED(m_mtx_registry) REQUIRES(m_mtx_db);
383
+ // On tx in coin; tx 0, before an offer: the worse of the two locks
384
+ int appFeesFor(npb::FeeRule &rule, std::vector<AppFee> &fees, int64_t &bound_bps, int coin,
385
+ int coin_other, int tx = 0) REQUIRES(m_mtx_db);
386
+ int appFeeTxs(std::vector<FeeTx> &txs, bool app_leads, bool bridged, int coin_send,
387
+ int coin_receive, int64_t amount_send, int64_t amount_receive) REQUIRES(m_mtx_db);
388
+ int checkOfferFees(const OfferData &offer, const SwapRequestInfo &request,
389
+ std::string &str_error) REQUIRES(m_mtx_db);
390
+ int loadSwapFees(std::vector<SwapFeeOutput> &fee_outputs, const SwapInfo &swap_info) const;
391
+ // The offer's lock B fee outputs, a view-key coin's with the view keys the fee rules give
392
+ int lockBFeeOutputs(std::vector<SwapFeeOutput> &expected, std::string &str_error,
393
+ const OfferData &offer, int coin_to) REQUIRES(m_mtx_db);
394
+ int lockBFeeError(std::string &str_error, const SwapInfo &swap_info) REQUIRES(m_mtx_db);
395
+ void addSwapFeesJson(nlohmann::json &j, int coin_type, int coin_to, int64_t amount,
396
+ int64_t amount_receive) REQUIRES(m_mtx_db);
397
+ // Returns the app's fees out of what it receives; txs give the rate before any dust raise
398
+ int64_t addFeeOutputsJson(nlohmann::json &j, const std::vector<npb::FeeOutput> &outputs,
399
+ int coin_send, int coin_receive, int64_t amount_send,
400
+ int64_t amount_receive, const std::vector<FeeTx> *txs = nullptr);
401
+ // The outputs lock tx a will carry, for the host to fund the real shape
402
+ int getSwapFundingOutputs(nlohmann::json &j, int coin_type, int coin_to, int64_t amount)
403
+ LOCKS_EXCLUDED(m_mtx_db);
404
+ int serverSettingsHash(std::vector<unsigned char> &hash) REQUIRES(m_mtx_db);
405
+ int storeServerSettings(const std::vector<unsigned char> &data) REQUIRES(m_mtx_db);
406
+ std::string maxMarginKey() const;
407
+ std::string feeRulesKey() const;
408
+ int loadFeeRules(std::vector<npb::FeeRule> &rules) REQUIRES(m_mtx_db);
409
+ int checkFeeRules(const std::vector<npb::FeeRule> &rules) LOCKS_EXCLUDED(m_mtx_registry);
410
+ int coinTypeFromTicker(const char *ticker);
411
+
412
+ int processHandshake(const std::vector<unsigned char> &msg_id,
413
+ const std::vector<unsigned char> &data)
414
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
415
+ int initHandshake(npb::Handshake &msg) const;
416
+ // Sets Kbf_a and Kbl_a, the chain B keys' secp256k1 forms. 2 when the offer's lock B fees
417
+ // can't be checked: the fee rules give no view key for them.
418
+ int verifyViewKeySetup(SwapInfo &swap_info, const npb::SwapSetup &swap_offer,
419
+ const OfferData &offer, std::string &str_error) REQUIRES(m_mtx_db);
420
+ // A recovered swap's setup: its checks at the accept's time, its scans from the found heights
421
+ struct SetupReplay {
422
+ int64_t m_at{0};
423
+ int64_t m_height_from{-1};
424
+ int64_t m_height_to{-1};
425
+ bool m_signed{false};
426
+ };
427
+ int tryProcessSwapSetup(const std::vector<unsigned char> &msg_id,
428
+ const std::vector<unsigned char> &data,
429
+ const SetupReplay *replay = nullptr)
430
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
431
+ int processSwapSetup(const std::vector<unsigned char> &msg_id,
432
+ const std::vector<unsigned char> &data)
433
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
434
+ int tryProcessSwapLockSigs(const std::vector<unsigned char> &data)
435
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
436
+ int queueApplyLockSigs(const std::vector<unsigned char> &swap_id) REQUIRES(m_mtx_db);
437
+ int processSwapLockSigs(const std::vector<unsigned char> &msg_id,
438
+ const std::vector<unsigned char> &data)
439
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
440
+ int processSwapRelease(const std::vector<unsigned char> &msg_id,
441
+ const std::vector<unsigned char> &data)
442
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
443
+ int verifySwapRelease(const SwapInfo &swap_info, const npb::SwapRelease &swap_release)
444
+ REQUIRES(m_mtx_db);
445
+ // The follower's lock A spend from the stored otves_l; the db open
446
+ int releaseSwapLockA(SwapInfo &swap_info) REQUIRES(m_mtx_swap_state, m_mtx_db);
447
+ int processBlockHeader(const std::vector<unsigned char> &msg_id,
448
+ const std::vector<unsigned char> &data)
449
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
450
+ int processCoinPrices(const std::vector<unsigned char> &msg_id,
451
+ const std::vector<unsigned char> &data)
452
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
453
+ static bool matchesAcceptedOffer(const SwapInfo &swap_info, const OfferData &offer,
454
+ const SwapRequestInfo &request, int64_t dust,
455
+ int64_t max_money, std::string &str_error);
456
+ // The offer offer_id names, if it is accepted and its request is waiting on it.
457
+ int loadAcceptedOffer(OfferData &offer, SwapRequestInfo &request,
458
+ const std::vector<unsigned char> &offer_id, const RequestId &request_id)
459
+ REQUIRES(m_mtx_db);
460
+ // Returns 2 when the coin has no fee estimate yet.
461
+ int checkAcceptedSwap(const SwapInfo &swap_info, std::string &str_error,
462
+ bool recovering = false) REQUIRES(m_mtx_db);
463
+ void rejectAcceptedOffer(const OfferData &offer) REQUIRES(m_mtx_db);
464
+ // The offer and its checks against now, which a recovery sets to the accept's time
465
+ int readOffer(OfferData &offer_data, const std::vector<unsigned char> &msg_id,
466
+ const std::vector<unsigned char> &data, int64_t now);
467
+ int tryProcessOffer(const std::vector<unsigned char> &msg_id,
468
+ const std::vector<unsigned char> &data) REQUIRES(m_mtx_db);
469
+ // Needs the db open: the offer's checks against its request, then the save
470
+ int checkAndSaveOffer(OfferData &offer_data, int64_t now, bool recovering) REQUIRES(m_mtx_db);
471
+
472
+ // A SwapRecovery entry once its request and accept are found to be this app's
473
+ struct RecoveredSwap {
474
+ RequestId m_request_id;
475
+ int64_t m_request_at{0};
476
+ npb::SwapRequest m_request;
477
+ std::vector<unsigned char> m_request_payload;
478
+ OfferData m_offer;
479
+ std::vector<unsigned char> m_offer_payload;
480
+ OfferData m_accepted; // the accept's fields and its time
481
+ // The glue's cached smsgs to the app, decoded, in sending order: msg id, typed payload
482
+ std::vector<std::pair<std::vector<unsigned char>, std::vector<unsigned char>>>
483
+ m_glue_messages;
484
+ int64_t m_setup_at{0}; // the setup smsg's time; 0 without one
485
+ std::vector<unsigned char> m_sign_payload, m_release_payload; // the app's, if sent
486
+ };
487
+ static constexpr int MAX_RECOVERY_DAY_KEY_COUNT{1000};
488
+ int decodeGlueMessage(std::vector<unsigned char> &msg_id, std::vector<unsigned char> &data,
489
+ const std::vector<unsigned char> &encoded_data, bool check_expiry);
490
+ // received is the glue's form of a message this app sent: time, signature, payload
491
+ int readOwnMessage(int64_t &sent_at, std::vector<unsigned char> &payload,
492
+ const std::vector<unsigned char> &received, int msg_type);
493
+ int readRecoveredSwap(RecoveredSwap &out, const npb::SwapRecovery &entry);
494
+ int processSwapRecovery(const std::vector<unsigned char> &msg_id,
495
+ const std::vector<unsigned char> &data)
496
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
497
+ int recoverSwap(Action &action) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
498
+ int rebuildRecoveredSwap(std::vector<unsigned char> &swap_id, RecoveredSwap &recovered,
499
+ const OfferData &derived, const std::vector<unsigned char> &script_to)
500
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
501
+ int claimRecoveredDeposit(const npb::SwapRequest &sr, const RequestId &request_id,
502
+ const std::vector<SwapInput> &inputs,
503
+ const std::vector<unsigned char> &script_to, int64_t pay_in_height)
504
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
505
+ int claimRecoveredDepositRow(bool &claimed, const npb::SwapRequest &sr,
506
+ const RequestId &request_id, const std::vector<SwapInput> &inputs,
507
+ const std::vector<unsigned char> &script_to) REQUIRES(m_mtx_db);
508
+ int replayRecoveredSetup(std::vector<unsigned char> &swap_id, const RecoveredSwap &recovered,
509
+ int64_t height_from, int64_t height_to)
510
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
511
+ // In one action run: the setup's and request's expiries are past, so expireSwapData ends them
512
+ void replayRecoveredSwap(const std::vector<unsigned char> &swap_id,
513
+ const RecoveredSwap &recovered)
514
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
515
+ int holdRecoveredRelease(const std::vector<unsigned char> &swap_id,
516
+ const std::vector<unsigned char> &data)
517
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
518
+ struct RecoveryLockB {
519
+ int64_t m_watched_id{-1};
520
+ bool m_answered{false};
521
+ bool m_found{false};
522
+ };
523
+ std::map<std::vector<unsigned char>, RecoveryLockB> m_recovery_lock_b GUARDED_BY(m_mtx_db);
524
+ // RETRY until the lock tx b script's history answers; 1 if it holds a tx
525
+ int recoveredLockBSeen(const SwapInfo &swap_info, CoinInterface &c_i) REQUIRES(m_mtx_db);
526
+ // The block scan can't see the pool, so a deposit spent there is a lock tx b not mined yet
527
+ int recoveredViewKeyLockBSeen(const SwapInfo &swap_info) REQUIRES(m_mtx_swap_state, m_mtx_db);
528
+ int processRecoveryLockBHistory(std::shared_ptr<ElectrumResponse> response) REQUIRES(m_mtx_db);
529
+ int requestSwapRecovery(std::string &str_error);
530
+ // A restored app asks once per connection, after its deposit scans, until fully answered
531
+ void checkSwapRecoveryAsk() REQUIRES(m_mtx_swap_state, m_mtx_db);
532
+ int swapRecoveryPending(bool &pending, size_t &queued) REQUIRES(m_mtx_db);
533
+ int noteSwapRecoveryEntry(int index, int count) REQUIRES(m_mtx_db);
534
+ int64_t m_swap_recovery_asked_for{0}; // the connection's handshake time
535
+ int m_swap_recovery_count{-1};
536
+ std::set<int> m_swap_recovery_indices GUARDED_BY(m_mtx_db);
537
+ // A recovering request's input txs, fetched by txid, held across the action's retries
538
+ struct RecoveryInputs {
539
+ int m_coin_type{0};
540
+ std::map<int64_t, std::vector<unsigned char>> m_fetching; // watched id: txid as shown
541
+ std::map<std::vector<unsigned char>, std::shared_ptr<Transaction>> m_txs;
542
+ };
543
+ std::map<RequestId, RecoveryInputs> m_recovery_inputs GUARDED_BY(m_mtx_db);
544
+ // RETRY while a tx is still being fetched
545
+ int recoveryInputs(std::vector<SwapInput> &inputs, const RequestId &request_id, int coin_type,
546
+ const std::vector<unsigned char> &utxos) REQUIRES(m_mtx_db);
547
+ int processRecoveryInputTx(std::shared_ptr<ElectrumResponse> response) REQUIRES(m_mtx_db);
548
+ // A chain's height at a recovering swap's setup time, by stepHeightSearch
549
+ struct RecoveryHeight {
550
+ HeightSearch m_search;
551
+ std::map<int64_t, uint64_t> m_asking; // watched id: height
552
+ int64_t m_view_key_id{-1};
553
+ };
554
+ std::map<std::pair<RequestId, int>, RecoveryHeight> m_recovery_heights GUARDED_BY(m_mtx_db);
555
+ // RETRY while searching
556
+ int recoveryStartHeight(int64_t &height, const RequestId &request_id, int coin_type, int64_t at)
557
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
558
+ int processRecoveryHeader(std::shared_ptr<ElectrumResponse> response) REQUIRES(m_mtx_db);
559
+ void forgetRecovery(const RequestId &request_id) REQUIRES(m_mtx_db);
560
+ // A script chain's headers fetched down from its anchor, by coin
561
+ struct RecoveryBackfill {
562
+ int m_target{-1};
563
+ int m_anchor{-1};
564
+ std::map<int, std::shared_ptr<BlockHeader>> m_headers;
565
+ std::map<int64_t, std::pair<int, int>> m_asking; // watched id: start height, count
566
+ };
567
+ std::map<int, RecoveryBackfill> m_recovery_backfills GUARDED_BY(m_mtx_db);
568
+ static constexpr int MAX_RECOVERY_HEADERS{2016};
569
+ // RETRY until coin_type's anchor is at or below height, or as low as it can go
570
+ int recoveryBackfill(int coin_type, int64_t height) REQUIRES(m_mtx_db);
571
+ int processRecoveryHeaders(std::shared_ptr<ElectrumResponse> response) REQUIRES(m_mtx_db);
572
+ int processOffer(const std::vector<unsigned char> &msg_id,
573
+ const std::vector<unsigned char> &data) REQUIRES(m_mtx_db);
574
+ int processHeaderRoot(const std::vector<unsigned char> &msg_id,
575
+ const std::vector<unsigned char> &data) REQUIRES(m_mtx_db);
576
+ int processOffersEstimate(const std::vector<unsigned char> &msg_id,
577
+ const std::vector<unsigned char> &data) REQUIRES(m_mtx_db);
578
+ int processBridgedOfferRevoke(const std::vector<unsigned char> &msg_id,
579
+ const std::vector<unsigned char> &data) REQUIRES(m_mtx_db);
580
+ int processAck(const std::vector<unsigned char> &msg_id, const std::vector<unsigned char> &data)
581
+ REQUIRES(m_mtx_db);
582
+ // 1 when a swap other than a rejected one exists, -1 when they cannot be read
583
+ int requestHasSwap(const std::vector<unsigned char> &request_id) REQUIRES(m_mtx_db);
584
+ int storeCoinPrices(const unsigned char *data, size_t len) REQUIRES(m_mtx_swap_state);
585
+
586
+ int requestSwap(SwapOptions &swap_options, SwapRequestReturn &rv);
587
+ // The account wallet's confirmed outputs, largest first, enough for lock tx a with its fee and change
588
+ int selectWalletInputs(std::vector<WalletOutput> &chosen, std::string &str_error, int coin_type,
589
+ int coin_to, int64_t amount) LOCKS_EXCLUDED(m_mtx_db);
590
+ // Funded from coin_from's account wallet: confirmed outputs held for the request, change to the wallet
591
+ int requestWalletSwap(SwapOptions &swap_options, SwapRequestReturn &srr)
592
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
593
+ // The sigs the glue holds are the app's sent ones, kept over any signed again
594
+ struct SignReplay {
595
+ int64_t m_at{0};
596
+ npb::SwapSign m_sign;
597
+ std::vector<unsigned char> m_otves_l;
598
+ };
599
+ int signSwapSetup(nlohmann::json &ai, const std::vector<unsigned char> &swap_id,
600
+ const SignReplay *replay = nullptr);
601
+ int acceptOffer(nlohmann::json &ai, const std::vector<unsigned char> &offer_id);
602
+ // acceptOffer up to the send: the guards, the keys, and the accept persisted.
603
+ int recordAccept(nlohmann::json &ai, OfferData &offer,
604
+ const std::vector<unsigned char> &offer_id) REQUIRES(m_mtx_accept)
605
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
606
+ // The keys at offer's m_accepted_at and m_day_key_count, for its role
607
+ int deriveAcceptKeys(OfferData &offer, bool leads, secure_bytes &key_b, std::string &str_error)
608
+ LOCKS_EXCLUDED(m_mtx_db);
609
+ int sendAccept(const OfferData &offer);
610
+ int getInfo(nlohmann::json &ji);
611
+ // The connected glue server's last balance and its time; {} before any
612
+ int getCoreTokens(nlohmann::json &jr) LOCKS_EXCLUDED(m_mtx_db);
613
+ // Sets fees_paid_in_tokens from a packCoreTokenFees list, when it lists any
614
+ void addCoreTokenFeesJson(nlohmann::json &j, const std::vector<unsigned char> &packed);
615
+ int processCoreTokens(const std::vector<unsigned char> &msg_id,
616
+ const std::vector<unsigned char> &data) REQUIRES(m_mtx_db);
617
+ // A balance older than the stored one is ignored; the time is the hub's, from the SMSG
618
+ int storeCoreTokens(int64_t balance, const std::vector<unsigned char> &msg_id)
619
+ REQUIRES(m_mtx_db);
620
+ // Each account wallet's coin, by ticker
621
+ int getBalances(nlohmann::json &j) LOCKS_EXCLUDED(m_mtx_db);
622
+ int sendFromWallet(nlohmann::json &jr, const WalletSendOptions &options)
623
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
624
+ // A wallet send to address, stored, being broadcast, or still being built
625
+ int walletSentTo(bool &sent, int coin_type, const std::string &address)
626
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
627
+ int getReceiveAddress(nlohmann::json &jr, int coin_type, bool new_address)
628
+ LOCKS_EXCLUDED(m_mtx_db);
629
+ // One entry per tx, unconfirmed first, then newest first
630
+ int getWalletHistory(nlohmann::json &jr, int coin_type) LOCKS_EXCLUDED(m_mtx_db);
631
+ // An empty held_for releases every hold on the coin
632
+ int releaseHolds(nlohmann::json &jr, int coin_type, const std::vector<unsigned char> &held_for)
633
+ LOCKS_EXCLUDED(m_mtx_db);
634
+ // Allocator totals and the size of every container that grows with uptime.
635
+ int getMemStats(nlohmann::json &ji) LOCKS_EXCLUDED(m_mtx_swap_state);
636
+ int getCoinPrices(nlohmann::json &jp) LOCKS_EXCLUDED(m_mtx_swap_state);
637
+ int getSwapRequestInfo(nlohmann::json &sri, const std::vector<unsigned char> &request_id);
638
+
639
+ // A host wallet's locks on the coins funding a request. The handle is
640
+ // opaque here: stored as given and handed back for the wallet to undo.
641
+ int recordWalletLock(const RequestId &request_id, int coin,
642
+ const std::vector<unsigned char> &txid, int vout,
643
+ const std::vector<unsigned char> &handle, int64_t value)
644
+ LOCKS_EXCLUDED(m_mtx_db);
645
+ int listWalletLocks(nlohmann::json &js, bool unreleased_only) LOCKS_EXCLUDED(m_mtx_db);
646
+ int markWalletLockReleased(int coin, const std::vector<unsigned char> &txid, int vout,
647
+ const RequestId &request_id) LOCKS_EXCLUDED(m_mtx_db);
648
+ // pays and receives are the request's side of the swap, in either orientation.
649
+ static bool checkOfferFloor(int64_t pays, int64_t receives, int64_t request_amount_from,
650
+ bool spend_all, int64_t min_amount_to, int64_t dust,
651
+ int64_t max_money, std::string &str_error);
652
+ static int64_t offerLimitFloor(int64_t pays, int64_t request_amount_from, int64_t min_amount_to,
653
+ int64_t worse_bps);
654
+ bool bridgedLockTimesFit(int lock_time_1, int lock_time_2) const;
655
+ // A spend-all lock tx a pays the request's rate, and the txs after it the swap's.
656
+ static int64_t lockTxAFeeRate(const SwapRequestInfo &request, int64_t swap_fee_rate);
657
+ bool marketAmount(int coin_from, int coin_to, int64_t amount_from, int64_t &market)
658
+ REQUIRES(m_mtx_swap_state);
659
+ void addOfferKind(nlohmann::json &j, const SwapInfo &swap_info) REQUIRES(m_mtx_db);
660
+ int getSwapInfo(nlohmann::json &si, const std::vector<unsigned char> &swap_id,
661
+ bool all_events = false);
662
+ int listSwaps(nlohmann::json &js);
663
+ int listRequests(nlohmann::json &js);
664
+
665
+ int getTxChainInfo(TxChainState &chain_state, int coin_type,
666
+ const std::vector<unsigned char> &tx_id);
667
+
668
+ int setSwapState(SwapInfo &swap, int new_state, bool sync_db = true);
669
+ int setSwapState(const std::vector<unsigned char> &swap_id, int new_state);
670
+ int setSwapError(SwapInfo &swap, const char *str_prefix, std::string &str_error)
671
+ REQUIRES(m_mtx_db);
672
+ int reportSwapError(const SwapId &swap_id, const char *str_prefix, const std::string &str_error)
673
+ REQUIRES(m_mtx_db);
674
+ void waitingForHostSignature(const SwapId &swap_id, int64_t seconds_left,
675
+ const std::string &reason) REQUIRES(m_mtx_db);
676
+ int activateSwap(SwapInfo &swap) REQUIRES(m_mtx_swap_state, m_mtx_db);
677
+ int deactivateSwap(const std::vector<unsigned char> &swap_id)
678
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
679
+ int activateSwaps();
680
+
681
+ // Whether the db holds a swap that is still in progress, answerable with
682
+ // only setDataDir called - starting the core to find out is the thing it
683
+ // exists to avoid.
684
+ int hasActiveSwaps(bool &has_swaps) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
685
+
686
+ // Fills in the client's trust anchors from the ca_certs table, falling back
687
+ // to the built in roots. Needs the schema, so not during the config pass.
688
+ int applyTrustAnchors(const std::string &host, uint16_t port, TlsOptions &options)
689
+ LOCKS_EXCLUDED(m_mtx_db);
690
+ int loadServerAnchors(ElectrumClient &client) LOCKS_EXCLUDED(m_mtx_db);
691
+ int loadNodeLogin(CoinInterface &c_i, NodeClient &node) LOCKS_EXCLUDED(m_mtx_db);
692
+ // The node client's scan, kept so a start resumes it
693
+ int restoreNodeScan(CoinInterface &c_i, NodeClient &node) LOCKS_EXCLUDED(m_mtx_db);
694
+ int storeNodeScan(CoinInterface &c_i, NodeClient &node) LOCKS_EXCLUDED(m_mtx_db);
695
+ void notePins(const std::string &host, uint16_t port,
696
+ std::vector<std::vector<unsigned char>> pins);
697
+ int selectElectrumServers(CoinInterface &c_i) LOCKS_EXCLUDED(m_mtx_db);
698
+ int persistElectrumServers(CoinInterface &c_i) LOCKS_EXCLUDED(m_mtx_db);
699
+ void rotateElectrumServers(CoinInterface &c_i, int64_t now) LOCKS_EXCLUDED(m_mtx_db);
700
+ int64_t m_electrum_down_rotate{120};
701
+ int64_t m_electrum_cooldown{3600};
702
+ // Stores a trust anchor. An empty host makes it general, a set one confines
703
+ // it to that server.
704
+ int addCaCert(const std::string &label, const std::string &host, uint16_t port,
705
+ const std::string &pem) LOCKS_EXCLUDED(m_mtx_db);
706
+ int removeCaCert(int64_t id) LOCKS_EXCLUDED(m_mtx_db);
707
+ int listCaCerts(nlohmann::json &jc) LOCKS_EXCLUDED(m_mtx_db);
708
+ int listPinnedCerts(nlohmann::json &jc) LOCKS_EXCLUDED(m_mtx_db);
709
+ int removePinnedCert(const std::string &host, uint16_t port) LOCKS_EXCLUDED(m_mtx_db);
710
+ // Addresses the user sends swaps to or refunds to, per coin
711
+ int savedAddresses(nlohmann::json &j, int coin_type) LOCKS_EXCLUDED(m_mtx_db);
712
+ int rememberAddress(int coin_type, const std::string &address, const std::string *label)
713
+ LOCKS_EXCLUDED(m_mtx_db);
714
+ int forgetAddress(int coin_type, const std::string &address) LOCKS_EXCLUDED(m_mtx_db);
715
+ // Set when the anchors change; the main loop reconnects the affected clients
716
+ // on its next pass, which is a reconnect rather than a module restart.
717
+ std::atomic<bool> m_reload_anchors{false};
718
+
719
+ // Blocks after the swipe confirms before giving up on sending the keyshare,
720
+ // so a swap can't sit in SENDING_MERCY forever. Matches basicswap's
721
+ // mercy_watch_timeout_blocks default.
722
+ int m_mercy_watch_timeout_blocks{100};
723
+ int m_max_msg_resends{5};
724
+
725
+ // Trust on first use for an electrum server's certificate. False refuses the
726
+ // connection, so an unreadable database must not answer true.
727
+ bool verifyServerCert(const std::string &host, uint16_t port,
728
+ const std::vector<unsigned char> &fingerprint, bool chain_valid)
729
+ LOCKS_EXCLUDED(m_mtx_db);
730
+ int removeSwap(const SwapId &swap_id) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
731
+ int abandonSwap(const SwapId &swap_id) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
732
+ int removeRequest(const RequestId &request_id) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
733
+ // 2: the request is not open: ended, or an offer accepted or chosen.
734
+ int revokeSwapRequest(const RequestId &request_id) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
735
+ int revokeOpenRequests(nlohmann::json &js) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
736
+ // Regtest only: clears all swap and chain data, leaving the settings and
737
+ // coin interfaces intact, so a new test can run against a new chain.
738
+ int resetState(nlohmann::json &jr) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
739
+ int checkWatched(int64_t now) REQUIRES(m_mtx_swap_state, m_mtx_db);
740
+ bool watchedTxScript(std::vector<unsigned char> &script, const WatchedTxn &watched_tx)
741
+ REQUIRES(m_mtx_db);
742
+ // A restored db knows none of the deposit keys handed out before it, so each
743
+ // native wallet's deposit chain is scanned once per db.
744
+ static constexpr uint32_t DEPOSIT_SCAN_GAP_LIMIT{20};
745
+ static constexpr int UPDATE_MIN_GAP_MS{100};
746
+ // Blocks a view-key restore scan moves on between saves
747
+ static constexpr int64_t DEPOSIT_SCAN_SAVE_BLOCKS{100};
748
+ int startDepositScans() REQUIRES(m_mtx_swap_state, m_mtx_db);
749
+ int checkDepositScans(int64_t now) REQUIRES(m_mtx_swap_state, m_mtx_db);
750
+ void checkViewKeyDepositScans(int64_t now) REQUIRES(m_mtx_swap_state, m_mtx_db);
751
+ // Returns 2 when no scan is running for the coin.
752
+ void depositScanInfo(nlohmann::json &j, const DepositScan &scan, bool view_key) const;
753
+ int depositScanPending(std::map<int64_t, uint32_t> &pending, int coin_type) const
754
+ REQUIRES(m_mtx_swap_state);
755
+ // Watched id to the index whose first tx is being fetched; 2 when no scan is running.
756
+ int depositScanFetching(std::map<int64_t, uint32_t> &fetching, int coin_type) const
757
+ REQUIRES(m_mtx_swap_state);
758
+ int depositScanUnspent(std::map<int64_t, uint32_t> &unspent, int coin_type) const
759
+ REQUIRES(m_mtx_swap_state);
760
+ // Returns 2 when a scan is already running for the coin.
761
+ // A view-key chain needs a height or UTC date (3 without); 4 for a bad or future date.
762
+ int clearFailedBlocks(int coin_type) LOCKS_EXCLUDED(m_mtx_db);
763
+ int rescanDepositChain(int coin_type, int64_t from_height = -1,
764
+ const std::string &from_date = "")
765
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
766
+
767
+ static constexpr int64_t DEPOSIT_VALID_SECONDS{60 * 60};
768
+ // A closed deposit is still watched this long past its expiry, and anything
769
+ // paid into it meanwhile is swept to the refund address.
770
+ static constexpr int64_t DEPOSIT_LATE_SECONDS{7 * 24 * 60 * 60};
771
+ static constexpr int64_t DEPOSIT_RECHECK_SECONDS{60};
772
+ static constexpr int64_t VIEW_KEY_SCAN_LOG_SECONDS{60};
773
+ static constexpr int CONFIRM_INTERVAL_MULTIPLE{3};
774
+ // Blocks below its scanned height a lock's scan resumes at, for a reorg replacing them
775
+ static constexpr int64_t VIEW_KEY_SCAN_RESUME_MARGIN{10};
776
+ // The lowest height a deposit's coin is mined at: the height the deposit was made at, or
777
+ // recovered from, less a reorg replacing blocks
778
+ static int depositLowestHeight(int created_height)
779
+ {
780
+ return (int)std::max<int64_t>(created_height - VIEW_KEY_SCAN_RESUME_MARGIN, 0);
781
+ }
782
+ int createDeposit(nlohmann::json &jr, const DepositOptions &options)
783
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
784
+ int listDeposits(nlohmann::json &jr) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
785
+
786
+ // Over the glue's limit of one per 10 s, which it counts from each request's arrival
787
+ static constexpr int64_t OFFERS_ESTIMATE_INTERVAL{12};
788
+ static constexpr int64_t OFFERS_ESTIMATE_TIMEOUT{30};
789
+ static constexpr int64_t OFFERS_ESTIMATE_KEEP_SECONDS{10 * 60};
790
+ int requestOffersEstimate(nlohmann::json &jr, const DepositOptions &options)
791
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
792
+ int getOffersEstimate(nlohmann::json &jr, const std::vector<unsigned char> &message_id)
793
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
794
+ int activateDeposits() LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
795
+ int checkDepositWatches(int64_t now) REQUIRES(m_mtx_swap_state, m_mtx_db);
796
+ int checkAccountWallets(int64_t now) REQUIRES(m_mtx_swap_state, m_mtx_db);
797
+ int checkProviderSig(const char *message, const std::vector<unsigned char> &key,
798
+ const std::vector<unsigned char> &context,
799
+ const std::vector<unsigned char> &sig);
800
+ int checkProviderOffer(OfferData &offer_data, const npb::PrivateOffer &offer);
801
+ void addProviderJson(nlohmann::json &j, const std::vector<unsigned char> &key,
802
+ bool label_changed) REQUIRES(m_mtx_db);
803
+ int seedKnownProviders() LOCKS_EXCLUDED(m_mtx_db);
804
+ std::vector<KnownProvider> m_listed_providers;
805
+ // Nexus's reconcileLeases for an account wallet's request holds
806
+ int releaseFinishedRequestHolds(int coin_type) REQUIRES(m_mtx_swap_state, m_mtx_db);
807
+ int checkXmrWallets(int64_t now) REQUIRES(m_mtx_swap_state, m_mtx_db);
808
+ // View-key coins with an account wallet, by gap limit; each wallet is made once the main
809
+ // key is in
810
+ std::map<int, uint32_t> m_xmr_wallet_gaps;
811
+ std::map<int, std::shared_ptr<xmr::AccountWallet>> m_xmr_wallets GUARDED_BY(m_mtx_db);
812
+ int checkDeposits(int64_t now) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
813
+ // A paused pay-in requested again at the amount received; only a recovered one names coin_to.
814
+ int requestDepositAgain(nlohmann::json &jr, const std::vector<unsigned char> &deposit_id,
815
+ int64_t min_amount_to, int coin_to = 0,
816
+ const std::string &address_to = "")
817
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
818
+ int cancelDeposit(nlohmann::json &jr, const std::vector<unsigned char> &deposit_id)
819
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
820
+ // Pays what the pay-in still needs from the coin's own wallet, in one tx, once
821
+ int payDepositFromWallet(nlohmann::json &jr, const std::vector<unsigned char> &deposit_id,
822
+ bool dry_run) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
823
+ int depositWalletPaid(bool &paid, const std::vector<unsigned char> &deposit_id)
824
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
825
+ // Refused once the deposit has one.
826
+ int setDepositRefundAddress(nlohmann::json &jr, const std::vector<unsigned char> &deposit_id,
827
+ const std::string &address)
828
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
829
+ // Sweeps the listed coins to the refund address on the server's heights, unproven.
830
+ int rescueDeposit(nlohmann::json &jr, const std::vector<unsigned char> &deposit_id)
831
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
832
+ // The largest amount whose lock output, fee outputs and lock fee fit in total
833
+ static int64_t spendAllAmount(int64_t total, int64_t lock_fee,
834
+ const std::vector<SwapFeeOutput> &fee_outputs);
835
+ // Returns 2 when the coin has no fee estimate yet.
836
+ int depositLockFee(int64_t &fee, int coin_type, const std::vector<SwapFeeOutput> &fee_outputs,
837
+ size_t num_inputs, int64_t fee_rate,
838
+ const std::vector<unsigned char> *change_script = nullptr);
839
+ // Returns 2 when the deposit is not watched.
840
+ int depositWatchId(int64_t &watched_id, const std::vector<unsigned char> &deposit_id) const
841
+ REQUIRES(m_mtx_swap_state);
842
+ // Returns 2 when no view key watches the deposit.
843
+ int depositViewKeyId(int64_t &view_key_id, const std::vector<unsigned char> &deposit_id) const
844
+ REQUIRES(m_mtx_swap_state);
845
+ int64_t depositUnconfirmed(const std::vector<unsigned char> &deposit_id) const
846
+ REQUIRES(m_mtx_swap_state);
847
+ bool depositHasWatch(const std::vector<unsigned char> &deposit_id) const
848
+ REQUIRES(m_mtx_swap_state);
849
+ // The youngest output still short of spendable; false when none is waiting.
850
+ bool depositConfirms(uint64_t &confirms, uint64_t &needed, const DepositInfo &deposit)
851
+ REQUIRES(m_mtx_swap_state);
852
+ // Returns 2 when the coin has no fee estimate yet.
853
+ int depositAmountDue(int64_t &amount_due, int coin_type, int coin_to, int64_t amount)
854
+ REQUIRES(m_mtx_db);
855
+ // A spend-all request's amount_from: 2 when the deposit changed or has no fee estimate
856
+ int depositRequestAmount(int64_t &amount, const DepositInfo &deposit, int64_t total,
857
+ size_t n_inputs, int64_t fee_rate) LOCKS_EXCLUDED(m_mtx_db);
858
+ int checkActions(int64_t now) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
859
+ int processEstimateFee(std::shared_ptr<ElectrumResponse> response);
860
+ int processEstimateLowFee(std::shared_ptr<ElectrumResponse> response);
861
+ int processRelayFee(std::shared_ptr<ElectrumResponse> response);
862
+ void clearCoinRegistries() LOCKS_EXCLUDED(m_mtx_registry, m_mtx_view_key_chains);
863
+ int addViewKeyChain(CoinInterface &c_i, const nlohmann::json &coin_data)
864
+ LOCKS_EXCLUDED(m_mtx_view_key_chains);
865
+ int withViewKeyChain(int coin_type, const std::function<int(ViewKeyChain &)> &f)
866
+ LOCKS_EXCLUDED(m_mtx_view_key_chains);
867
+ int64_t viewKeyChainHeight(int coin_type) LOCKS_EXCLUDED(m_mtx_view_key_chains);
868
+ int64_t viewKeyId(const SwapId &swap_id) const REQUIRES(m_mtx_swap_state);
869
+ int viewKeyLock(ViewKeyLock &lock, const SwapInfo &swap_info) REQUIRES(m_mtx_db);
870
+ int watchViewKeyLock(const SwapInfo &swap_info) REQUIRES(m_mtx_swap_state, m_mtx_db);
871
+ void forgetViewKeyLock(const SwapId &swap_id) REQUIRES(m_mtx_swap_state);
872
+ void checkViewKeyLocks() REQUIRES(m_mtx_swap_state, m_mtx_db);
873
+ int sendLockBSweepTx(Action &action, int tx_type) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
874
+ int endSweptLockB(const SwapId &swap_id, int coin_type, int tx_type)
875
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
876
+ // A follower's lock tx b, from the deposit that funds its request
877
+ int lockBSweepKeys(secure_bytes &spend_key, std::vector<unsigned char> &dest,
878
+ bool &no_refund_address, const SwapInfo &swap_info)
879
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
880
+ int sendViewKeyLockB(Action &action, const SwapInfo &swap_info,
881
+ const std::vector<SwapFeeOutput> &fee_outputs, bool resend)
882
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
883
+ // Its row from the daemons' check of its txid; tx_state is what was recorded, or 0.
884
+ int recordSentLockB(int &tx_state, SwapTx &stx, const ViewKeyTxStatus &status,
885
+ int blocks_confirmed) REQUIRES(m_mtx_db);
886
+ int loadSwapDeposit(DepositInfo &deposit, const SwapInfo &swap_info) REQUIRES(m_mtx_db);
887
+ int queueViewKeyRefund(const SwapId &swap_id, const secure_bytes &kbsl) REQUIRES(m_mtx_db);
888
+ int loadViewKeyChainCaches() LOCKS_EXCLUDED(m_mtx_db, m_mtx_view_key_chains);
889
+ void saveViewKeyChainCaches() LOCKS_EXCLUDED(m_mtx_db, m_mtx_view_key_chains);
890
+ // A "balance" message when an account wallet's amounts change; the first look only records them
891
+ void notifyBalances() LOCKS_EXCLUDED(m_mtx_db);
892
+ void notifyBalance(const CoinInterface &c_i, const WalletBalance &balance, bool synced);
893
+ int sendSwapLockATx(Action &action);
894
+ int expireData(int64_t now) LOCKS_EXCLUDED(m_mtx_db);
895
+ int expireSwapData(int64_t now) REQUIRES(m_mtx_swap_state, m_mtx_db);
896
+ int revokeDeadRequests(int64_t now) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
897
+ int setSwapRequestState(const RequestId &request_id, int new_state);
898
+ int checkActiveSwaps(int64_t now) REQUIRES(m_mtx_swap_state, m_mtx_db);
899
+
900
+ int updateWatchedScript(WatchedScript &watched_script, const nlohmann::json &jdata)
901
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
902
+ int updateWatchedTx(const WatchedTxn &watched_tx, const nlohmann::json &jdata)
903
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
904
+ int confirmWatchedTx(const WatchedTxn &watched_tx, SwapTx &swap_tx, bool changed)
905
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
906
+ // Resolves height to a block hash through the local header index, then
907
+ // confirms. Requests the header and returns 0 when the index doesn't reach
908
+ // that height yet. Returns ReturnTypes::REMOVE when the watch is finished.
909
+ int confirmWatchedTxAtHeight(const WatchedTxn &watched_tx, SwapTx &swap_tx, int height,
910
+ bool changed) REQUIRES(m_mtx_swap_state, m_mtx_db);
911
+ int processListUnspent(std::shared_ptr<ElectrumResponse> response)
912
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
913
+ int processDepositTx(std::shared_ptr<ElectrumResponse> response)
914
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
915
+ int processDepositScanTx(std::shared_ptr<ElectrumResponse> response)
916
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
917
+ int processDepositScanUnspent(std::shared_ptr<ElectrumResponse> response)
918
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
919
+ int processDepositProof(std::shared_ptr<ElectrumResponse> response)
920
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
921
+ int processDepositHistory(std::shared_ptr<ElectrumResponse> response)
922
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
923
+ int processWalletStatus(std::shared_ptr<ElectrumResponse> response)
924
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
925
+ int processWalletHistory(std::shared_ptr<ElectrumResponse> response)
926
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
927
+ int processWalletTx(std::shared_ptr<ElectrumResponse> response)
928
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
929
+ int processWalletProof(std::shared_ptr<ElectrumResponse> response)
930
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
931
+ int processSendBroadcast(std::shared_ptr<ElectrumResponse> response)
932
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
933
+ int processGetTransaction(std::shared_ptr<ElectrumResponse> response)
934
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
935
+ int processBroadcastTx(std::shared_ptr<ElectrumResponse> response)
936
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
937
+ int broadcastTx(int coin_type, int64_t action_id, const std::vector<unsigned char> &tx_data)
938
+ REQUIRES(m_mtx_swap_state);
939
+ int recordPublishing(SwapTx &stx) REQUIRES(m_mtx_swap_state, m_mtx_db);
940
+ int recordPublishing(const std::vector<unsigned char> &swap_id, int coin_type, int tx_type,
941
+ const std::vector<unsigned char> &tx_data)
942
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
943
+ int recordPublished(const std::vector<unsigned char> &txid)
944
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
945
+ bool broadcastWaiting(int coin_type, int64_t action_id, int64_t now) REQUIRES(m_mtx_swap_state);
946
+ int64_t m_broadcast_expiry{600};
947
+ int processStakeProofs(std::shared_ptr<ElectrumResponse> response) REQUIRES(m_mtx_db);
948
+ int processBlockHeaders(std::shared_ptr<ElectrumResponse> response)
949
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
950
+ int processElectrumBlockHeader(std::shared_ptr<ElectrumResponse> response)
951
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
952
+ int processGetHistory(std::shared_ptr<ElectrumResponse> response)
953
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
954
+ int processRefundSwipeHistory(const WatchedScript &ws, const nlohmann::json &entries)
955
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
956
+ int processMercyHistory(const WatchedScript &ws, const nlohmann::json &entries)
957
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
958
+ bool acceptHistoryCandidate(const WatchedTxn &watched_tx,
959
+ const std::vector<unsigned char> &tx_data)
960
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
961
+ int processChainTip(std::shared_ptr<ElectrumResponse> response)
962
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
963
+ int processAnchorHeader(std::shared_ptr<ElectrumResponse> response)
964
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
965
+ void proposeChainAnchor(CoinInterface &c_i, int height, const uint256 &chain_work,
966
+ std::shared_ptr<BlockHeader> header,
967
+ std::shared_ptr<BlockHeader> parent, int64_t now)
968
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
969
+ void recheckChainAnchor(CoinInterface &c_i) REQUIRES(m_mtx_swap_state, m_mtx_db);
970
+ void checkChainAnchors(int64_t now) REQUIRES(m_mtx_swap_state, m_mtx_db);
971
+ bool checkingChainAnchor(int coin_type) REQUIRES(m_mtx_db)
972
+ {
973
+ return m_anchor_checks.count(coin_type) > 0;
974
+ }
975
+ int64_t m_anchor_check_timeout{60};
976
+ int processCommitmentReply(std::shared_ptr<ElectrumResponse> response) REQUIRES(m_mtx_db);
977
+ void checkChainCommitments(int64_t now) REQUIRES(m_mtx_db);
978
+ bool checkingChainCommitment(int coin_type) REQUIRES(m_mtx_db)
979
+ {
980
+ return m_commitment_checks.count(coin_type) > 0;
981
+ }
982
+ int processTxMerklePath(std::shared_ptr<ElectrumResponse> response)
983
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
984
+ int processElectrumResponse(std::shared_ptr<ElectrumResponse> response)
985
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
986
+
987
+ int swapLockATxConfirmed(const SwapTx &stx) REQUIRES(m_mtx_swap_state, m_mtx_db);
988
+ int swapLockBTxConfirmed(const SwapTx &stx) REQUIRES(m_mtx_swap_state, m_mtx_db);
989
+ int swapLockASpendTxSeen(const SwapTx &stx) REQUIRES(m_mtx_swap_state, m_mtx_db);
990
+ int swapLockASpendTxConfirmed(const SwapTx &stx) REQUIRES(m_mtx_swap_state, m_mtx_db);
991
+ int swapLockARefundTxConfirmed(const SwapTx &stx) REQUIRES(m_mtx_swap_state, m_mtx_db);
992
+ int lockBNeverBuilt(bool &never_built, const SwapId &swap_id) REQUIRES(m_mtx_db);
993
+ int swapLockARefundSpendTxSeen(const SwapTx &stx) REQUIRES(m_mtx_swap_state, m_mtx_db);
994
+ int swapLockARefundSpendTxConfirmed(const SwapTx &stx) REQUIRES(m_mtx_swap_state, m_mtx_db);
995
+ int swapLockARefundSwipeTxConfirmed(const SwapTx &stx) REQUIRES(m_mtx_swap_state, m_mtx_db);
996
+ int swapMercyTxSeen(const SwapTx &stx) REQUIRES(m_mtx_swap_state, m_mtx_db);
997
+ int swapTxFirstSeen(int tx_type, const SwapTx &swap_tx) REQUIRES(m_mtx_swap_state, m_mtx_db);
998
+ int swapMercyTxSent(const SwapTx &stx) REQUIRES(m_mtx_swap_state, m_mtx_db);
999
+ int recoverSwapLockBFromMercy(const SwapTx &stx) REQUIRES(m_mtx_swap_state, m_mtx_db);
1000
+ int swapLockBSpendTxConfirmed(const SwapTx &stx) REQUIRES(m_mtx_swap_state, m_mtx_db);
1001
+ int swapLockBRefundTxConfirmed(const SwapTx &stx) REQUIRES(m_mtx_swap_state, m_mtx_db);
1002
+
1003
+ // Actions
1004
+ int sendSwapLockARelease(const SwapId &swap_id) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1005
+ int sendSwapLockASpendTx(Action &action) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1006
+ int sendSwapLockARefundTx(Action &action) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1007
+ int sendSwapLockARefundSpendTx(Action &action) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1008
+ int sendSwapLockARefundSwipeTx(Action &action) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1009
+ int sendSwapMercyTx(Action &action) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1010
+ int sendSwipeSweepTx(Action &action) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1011
+ int resendSwapSign(Action &action) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1012
+ int sendSwapEnded(Action &action) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1013
+ void queueSwapEnded(const std::vector<unsigned char> &swap_id, int new_state);
1014
+ int resendAccept(Action &action) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1015
+ int sendRequestRevoke(Action &action) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1016
+ int sendSwapSign(Action &action) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1017
+ int applyLockSigs(Action &action) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1018
+ int sendSwapLockBTx(Action &action) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1019
+ int signSwapLockBTx(Action &action) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1020
+ int loadLockBFunding(std::vector<SwapInput> &outputs_from, int64_t &spend_all_fee_rate,
1021
+ const SwapInfo &swap_info) REQUIRES(m_mtx_db);
1022
+ // 0, 1 with str_error set, or BaseWallet::SIGN_LATER
1023
+ int buildLockBTx(SwapTx &swap_txb, std::string &str_error, const SwapInfo &swap_info,
1024
+ const std::vector<SwapInput> &outputs_from,
1025
+ const std::vector<SwapFeeOutput> &fee_outputs, int64_t spend_all_fee_rate)
1026
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1027
+ bool lockBPresignWanted(const SwapInfo &swap_info) REQUIRES(m_mtx_db);
1028
+ int signSwapLockBSpendTx(SwapTx &lock_b_spend_tx, SwapInfo swap_info, const SwapId &swap_id)
1029
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1030
+ bool lockBByViewKey(const SwapId &swap_id) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1031
+ int sendSwapLockBSpendTx(Action &action) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1032
+ int sendSwapLockBRefundTx(Action &actiond) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1033
+
1034
+ int requestBlockHeader(int coin_type, const std::vector<unsigned char> &block_hash)
1035
+ REQUIRES(m_mtx_swap_state);
1036
+ static void expireHeaderRequests(std::map<std::vector<unsigned char>, int64_t> &requested,
1037
+ int64_t now);
1038
+ void requestHeaderRoots(int64_t now) REQUIRES(m_mtx_db);
1039
+
1040
+ void update();
1041
+ void mainLoop();
1042
+
1043
+ bool handshakeReady(int wait_ms);
1044
+ // The glue's answered version, never above this build's; this build's before a handshake
1045
+ int connectionProtocolVersion() const;
1046
+ std::atomic<int> m_glue_protocol_version{0};
1047
+ // payload, typed, as this app's smsg to the glue, signed with its send time
1048
+ int encryptToGlue(std::vector<unsigned char> &smsg_msg,
1049
+ const std::vector<unsigned char> &payload, int64_t timestamp);
1050
+ // timestamp, when set, is the smsg's signed send time; otherwise now
1051
+ virtual int sendMessage(const npb::NonProtobuf &msg,
1052
+ std::vector<unsigned char> *smsg_id = nullptr, int64_t timestamp = 0);
1053
+ int processMessage() REQUIRES(m_mtx_swap_state, m_mtx_db);
1054
+ int dispatchMessage(const std::vector<unsigned char> &msg_id,
1055
+ const std::vector<unsigned char> &data)
1056
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
1057
+
1058
+ std::string getPubkey(const std::string &vk);
1059
+ using BSXContext::getPubkey;
1060
+
1061
+ void setDataDir(std::string datadir) { m_settings.m_datadir = datadir; };
1062
+ void setDataChainType(int chain_type) { m_settings.m_chain_type = chain_type; };
1063
+ void setAppType(int app_type) { m_settings.m_app_type = app_type; };
1064
+ static const size_t SEED_LEN = 32;
1065
+ static const int64_t HANDSHAKE_RESEND_SECONDS = 10;
1066
+ // No user holds this, so it exists only to give the seed one storage format.
1067
+ // The low iteration count matches: stretching a known password buys nothing.
1068
+ static constexpr const char *SEED_PASSWORD = "mbsx-debug-wallet";
1069
+ static const uint32_t SEED_ITERATIONS = 1024;
1070
+ // Not stored with the db: changing it locks out every encrypted db
1071
+ static const uint32_t DB_KEY_ITERATIONS = 600000;
1072
+ static const size_t DB_KEY_LEN = 32;
1073
+ static const size_t DB_SALT_LEN = 16;
1074
+ // A password change on an encrypted db seals the key here before it rekeys the db
1075
+ static constexpr const char *PENDING_EXTKEY_KEY = "pending_main_extkey";
1076
+ static constexpr const char *PENDING_MNEMONIC_KEY = "pending_main_mnemonic";
1077
+
1078
+ // Loads the stored main extkey, generating one from a fresh BIP39 mnemonic on
1079
+ // first use. Both hosts end at the same place: setMainExtkey.
1080
+ int loadOrCreateMainExtkey(const SecureString &password, uint32_t iterations = SEED_ITERATIONS)
1081
+ LOCKS_EXCLUDED(m_mtx_db);
1082
+ // What setRestoreBirthday and setRestoreRefundAddress gave, as a phrase restore records it
1083
+ int recordHostRestore() LOCKS_EXCLUDED(m_mtx_db);
1084
+ int recordSkippedRecovery() LOCKS_EXCLUDED(m_mtx_db);
1085
+ // What the stored extkey is sealed with. A host with somewhere safe to keep
1086
+ // one supplies it before initialise(); without it SEED_PASSWORD is used,
1087
+ // which is fixed and public, so initialise() refuses that fallback on
1088
+ // mainnet.
1089
+ int setMainKeyPassword(const std::string &password);
1090
+ // An encrypted db's raw cipher key followed by its salt
1091
+ static int deriveDbKey(secure_bytes &key, const unsigned char *salt,
1092
+ const SecureString &password);
1093
+ // Before initialise(), on a db with no key yet; birthday is the UTC date it was made
1094
+ int setRestoreMnemonic(const SecureString &mnemonic, const std::string &birthday,
1095
+ const SecureString &passphrase, bool store_passphrase);
1096
+ static int newMnemonic(SecureString &mnemonic, int language);
1097
+ // Before initialise(), on a db with no key yet; store_passphrase seals it with the phrase
1098
+ int setMnemonic(const SecureString &mnemonic, const SecureString &passphrase,
1099
+ bool store_passphrase);
1100
+ // Before initialise(), with a host's setMainExtkey on a db new to the key: the UTC date the key
1101
+ // was made, so the deposit scans and swap recovery run as after setRestoreMnemonic
1102
+ int setRestoreBirthday(const std::string &birthday);
1103
+ // After setRestoreMnemonic or setRestoreBirthday (3 before them); checked at initialise, once
1104
+ // the coins exist
1105
+ int setRestoreRefundAddress(int coin_type, const std::string &address);
1106
+ // Before initialise(): every enabled coin's pay-in scan is recorded done and the swap
1107
+ // recovery answered, so a key the user chose not to recover scans and asks nothing. A coin
1108
+ // enabled later still gets its first scan.
1109
+ int setSkipRecovery();
1110
+ // 2 when no phrase is stored, 3 when the password does not open it
1111
+ int getMnemonic(SecureString &mnemonic, SecureString &passphrase, std::string &birthday,
1112
+ const SecureString &password) LOCKS_EXCLUDED(m_mtx_db);
1113
+ // 2 when the host supplied the key, so none is stored; 3 when old_password does not open it
1114
+ int changeMainKeyPassword(const SecureString &old_password, const SecureString &password)
1115
+ LOCKS_EXCLUDED(m_mtx_db);
1116
+ // Whether password opens the stored main key, with changeMainKeyPassword's results
1117
+ int checkMainKeyPassword(const SecureString &password) LOCKS_EXCLUDED(m_mtx_db);
1118
+ // Kept in the database for a coin whose node takes no cookie file; an empty user forgets it
1119
+ int setNodeLogin(int coin_type, const std::string &user, const SecureString &password)
1120
+ LOCKS_EXCLUDED(m_mtx_db);
1121
+ // Hands the module its main extkey instead of letting it load one, for a host
1122
+ // that derives it. Must be called before initialise(), like setDataDir, and
1123
+ // what is passed is never written to disk.
1124
+ int setMainExtkey(const unsigned char *data /* ExtKey::SERIALISED_SIZE */);
1125
+ int getIdentityPubkey(std::vector<unsigned char> &out);
1126
+
1127
+ int sealSwapKey(std::vector<unsigned char> &out, std::span<const unsigned char> key,
1128
+ const std::vector<unsigned char> &swap_id, int key_type);
1129
+ int unsealSwapKey(secure_bytes &out, const std::vector<unsigned char> &sealed,
1130
+ const std::vector<unsigned char> &swap_id, int key_type);
1131
+
1132
+ int getRandomKey(std::vector<unsigned char> &out);
1133
+ // Allocates the next wallet key for coin_type. Pass key = nullptr when only
1134
+ // the pubkey is wanted, so a host wallet is not asked for a secret it does
1135
+ // not need to release. Fails when the coin has no wallet: every coin reaching
1136
+ // a swap came from the config, which always builds one.
1137
+ int getNewSwapKey(secure_bytes *key, std::vector<unsigned char> &pubkey, int coin_type,
1138
+ int change) LOCKS_EXCLUDED(m_mtx_db);
1139
+ // Marks a swap-key path apart from the receive and change chains, which
1140
+ // share the level below the account. bsx uses 999999 for a six element tail.
1141
+ static constexpr uint32_t SWAP_KEY_PATH_MARKER{9999999};
1142
+ static std::vector<uint32_t> swapKeyPath(int64_t created_at, int day_key_count, int key_no);
1143
+ int getSwapPathKey(secure_bytes *key, std::vector<unsigned char> &pubkey, int coin_type,
1144
+ const std::vector<uint32_t> &path) LOCKS_EXCLUDED(m_mtx_db);
1145
+ // A coin without a wallet: its account path off the main key, ground as bsx grinds ed25519.
1146
+ int getWalletlessSwapKey(secure_bytes &key, std::vector<unsigned char> &pubkey, int coin_type,
1147
+ const std::vector<uint32_t> &path);
1148
+ // A view-key chain's deposit is a wallet of its own, from the deposit index
1149
+ int viewKeyDepositWallet(secure_bytes &spend_key, secure_bytes &view_key,
1150
+ std::vector<unsigned char> &script, int coin_type, uint32_t index);
1151
+ // A view-key coin's own wallet n: the main key at 44h/{slip44}h/0h/{marker}h/{n}h, every step
1152
+ // hardened, so a wallet's keys reach neither the account nor its deposits
1153
+ static constexpr uint32_t VIEW_KEY_WALLET_PATH_MARKER{9999997};
1154
+ int viewKeyWalletKeys(secure_bytes &spend_key, secure_bytes &view_key,
1155
+ std::vector<unsigned char> &script, int coin_type, uint32_t wallet_index);
1156
+ // Wallet 0's primary address and private keys, as the coin's other wallets restore them;
1157
+ // 2 when the key in use is not one stored under a password, 3 when the password does not
1158
+ // open it
1159
+ int getWalletKeys(nlohmann::json &jr, int coin_type, const SecureString &password)
1160
+ LOCKS_EXCLUDED(m_mtx_db);
1161
+ int viewKeyDepositKey(std::vector<unsigned char> &key_id,
1162
+ std::vector<unsigned char> &spend_pubkey,
1163
+ std::vector<unsigned char> &script, int coin_type, uint32_t index);
1164
+ int newViewKeyDeposit(DepositInfo &deposit) REQUIRES(m_mtx_db);
1165
+ int viewKeyDepositKeys(secure_bytes &spend_key, secure_bytes &view_key,
1166
+ const DepositInfo &deposit) REQUIRES(m_mtx_db);
1167
+ // A view-key deposit's spend-all request, with its lock B fee kept back
1168
+ int viewKeyDepositRequest(SwapOptions &options, int64_t &total, const DepositInfo &deposit,
1169
+ const std::vector<DepositUtxo> &confirmed)
1170
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1171
+ // Fills address_from and the reserve proof of a request from a view-key deposit, or leaves
1172
+ // them empty when the coin's reserve_proof setting is off.
1173
+ int proveViewKeyRequest(npb::SwapRequest &sr, const SwapOptions &options,
1174
+ std::string &str_error)
1175
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db, m_mtx_view_key_chains);
1176
+ bool viewKeyReserveProof(int coin_type) LOCKS_EXCLUDED(m_mtx_view_key_chains);
1177
+ // The leader's chain B key, for the lock A refund spend and lock B's spend.
1178
+ int getKbsf(secure_bytes &kbsf, const SwapInfo &swap_info) REQUIRES(m_mtx_db);
1179
+ int getKbsl(secure_bytes &kbsl, const SwapInfo &swap_info)
1180
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1181
+ // Advances the daily key counter, resetting it on the first allocation of
1182
+ // each utc day. Strictly greater, so a clock moving backwards never resets.
1183
+ // now is the swap's own timestamp, so the day counted is the day in its path.
1184
+ int allocateDayKeyCount(int &count, int64_t now) REQUIRES(m_mtx_db);
1185
+ int storeKey(const std::vector<unsigned char> &key_data); // For debugging
1186
+
1187
+ virtual void notifyMessage(const char *type, const std::string &message) {};
1188
+ virtual void notifySettingsChanged() {};
1189
+ virtual void notifyBridgeState(bool connected) {};
1190
+ virtual void notifyStartup(const char *step) {};
1191
+ virtual int getNewKey(std::vector<unsigned char> &key) { return 1; };
1192
+ BSXSettings m_settings;
1193
+
1194
+ Bridge m_bridge;
1195
+ bool m_bridge_enabled{true};
1196
+ std::atomic<bool> m_running{false};
1197
+ std::atomic<bool> m_starting{false};
1198
+ std::atomic<bool> m_startup_bridge{false};
1199
+ // Set while resetState is joining the main loop from the js thread.
1200
+ // getSigningKeySL must not round-trip to js then: the callback could never run.
1201
+ std::atomic<bool> m_stopping{false};
1202
+
1203
+ protected:
1204
+ // By broadcast id, until its round expires; the row is written once a server accepts it
1205
+ std::map<int64_t, WalletSend> m_pending_sends GUARDED_BY(m_mtx_swap_state);
1206
+ int updateDepositFrom(const DepositInfo &copy, const std::function<void(DepositInfo &)> &change)
1207
+ REQUIRES(m_mtx_db);
1208
+ // Protected so a host subclass can reach its own wallets: HybridNitroBSX hands
1209
+ // each host wallet the js callback once initialise has built them.
1210
+ std::vector<std::shared_ptr<BaseWallet>> m_wallets GUARDED_BY(m_mtx_registry);
1211
+
1212
+ virtual int getSigningKeySL(secure_bytes &key, int coin_type,
1213
+ const std::vector<unsigned char> &key_id)
1214
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1215
+ // REQUIRES rather than LOCKS_EXCLUDED, and unlike the annotations on BaseWallet
1216
+ // this one is enforced on callers: here both sides of the match spell the mutex
1217
+ // this->m_mtx_db, which is what clang compares. The body is exempt for the
1218
+ // same reason it is enforced elsewhere - it calls getKeyLocked, whose
1219
+ // requirement reads w->m_db->m_mtx_db, and addWallet always passes *this as
1220
+ // the db, so the two name one mutex that the analysis cannot equate.
1221
+ virtual int getSigningKey(secure_bytes &key, int coin_type,
1222
+ const std::vector<unsigned char> &key_id)
1223
+ REQUIRES(m_mtx_db) NO_THREAD_SAFETY_ANALYSIS;
1224
+ // Exempt for the same reason
1225
+ int getSwapPathKeyLocked(std::vector<unsigned char> &pubkey, std::vector<unsigned char> &key_id,
1226
+ int coin_type, const std::vector<uint32_t> &path)
1227
+ REQUIRES(m_mtx_db) NO_THREAD_SAFETY_ANALYSIS;
1228
+ // Exempt for the same reason
1229
+ int recordDepositKeyLocked(int coin_type, uint32_t index)
1230
+ REQUIRES(m_mtx_db) NO_THREAD_SAFETY_ANALYSIS;
1231
+ int loadKeySL(std::vector<unsigned char> &key, const std::vector<unsigned char> &key_hash);
1232
+ int addWatchedTransaction(WatchedTxn &wtx) REQUIRES(m_mtx_swap_state);
1233
+ const WatchedTxn *findWatchedTx(const std::vector<unsigned char> &txid) const
1234
+ REQUIRES(m_mtx_swap_state);
1235
+ int addWatchedScript(WatchedScript &ws) REQUIRES(m_mtx_swap_state);
1236
+ // Per swap; the oldest is dropped first, which costs only a second fetch of it
1237
+ static constexpr size_t m_max_rejected_spenders{1024};
1238
+ void rejectSpender(const std::vector<unsigned char> &swap_id,
1239
+ const std::vector<unsigned char> &txid) REQUIRES(m_mtx_swap_state);
1240
+ bool isRejectedSpender(const std::vector<unsigned char> &swap_id,
1241
+ const std::vector<unsigned char> &txid) const REQUIRES(m_mtx_swap_state);
1242
+ int lockARefundRemaining(int64_t &remaining, const SwapInfo &swap_info) REQUIRES(m_mtx_db);
1243
+ bool lockARefundStarted(const SwapId &swap_id) REQUIRES(m_mtx_db);
1244
+ int lockARefundClose(bool &close, const SwapInfo &swap_info, int margin) REQUIRES(m_mtx_db);
1245
+ // Least time left on lock tx a's refund timelock to send lock tx b with; the release and
1246
+ // spend margins are checked again once it confirms
1247
+ int lockBMinMargin(const CoinInterface &ci_b) const;
1248
+ bool fundsAtRisk(const SwapId &swap_id, const SwapInfo &swap_info) REQUIRES(m_mtx_db);
1249
+
1250
+ private:
1251
+ int initialiseModule(bool start_thread);
1252
+ int resealMainKey(const secure_bytes &serialised, const SecureString &old_password,
1253
+ const SecureString &password, uint32_t iterations) LOCKS_EXCLUDED(m_mtx_db);
1254
+ int prepareDbKey();
1255
+ int openStoredMainKey(secure_bytes &serialised, const SecureString &password)
1256
+ LOCKS_EXCLUDED(m_mtx_db);
1257
+ int promotePendingMainKey(secure_bytes &serialised, const SecureString &password)
1258
+ LOCKS_EXCLUDED(m_mtx_db);
1259
+ int dropPendingMainKey() LOCKS_EXCLUDED(m_mtx_db);
1260
+ int changeEncryptedDbPassword(const secure_bytes &serialised, const SecureString &old_password,
1261
+ const SecureString &password) LOCKS_EXCLUDED(m_mtx_db);
1262
+ void endBridgeStartup();
1263
+ int addDepositWatch(const DepositInfo &deposit) REQUIRES(m_mtx_swap_state, m_mtx_db);
1264
+ bool depositWatched(const DepositInfo &deposit, int64_t now) const;
1265
+ DepositWatch *findDepositWatch(int64_t watched_id) REQUIRES(m_mtx_swap_state);
1266
+ void dropDepositWatch(int64_t watched_id) REQUIRES(m_mtx_swap_state);
1267
+ int processDepositUnspent(bool &remove, DepositWatch &watch, const nlohmann::json &unspent)
1268
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
1269
+ int settleDeposit(bool &remove, DepositWatch &watch) REQUIRES(m_mtx_swap_state, m_mtx_db);
1270
+ // False while a tx or proof for the listed utxos is still to come
1271
+ bool checkDepositUtxos(std::vector<DepositUtxo> &utxos, DepositWatch &watch, CoinInterface &c_i,
1272
+ const DepositInfo &deposit) REQUIRES(m_mtx_swap_state, m_mtx_db);
1273
+ bool checkDepositProof(int &proven, DepositWatch &watch, CoinInterface &c_i,
1274
+ const std::vector<unsigned char> &txid, int height)
1275
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
1276
+ int depositSwapInputs(std::vector<SwapInput> &inputs, const DepositInfo &deposit,
1277
+ const std::vector<DepositUtxo> &utxos);
1278
+ int requestFromDeposit(const DepositInfo &deposit, const std::vector<DepositUtxo> &utxos)
1279
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1280
+ int sweepDeposit(const DepositInfo &deposit, const std::vector<DepositUtxo> &utxos)
1281
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1282
+ int signDepositSweep(DepositInfo &updated, int64_t &swept, const DepositInfo &deposit,
1283
+ const std::vector<DepositUtxo> &utxos, int64_t replaced_fee);
1284
+ int resignSweep(const DepositInfo &deposit, int64_t now)
1285
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1286
+ void viewKeyDepositUtxos(std::vector<DepositUtxo> &utxos, const DepositWatch &watch,
1287
+ const DepositInfo &deposit);
1288
+ void settleViewKeySweep(DepositInfo &deposit, DepositWatch &watch, int64_t now);
1289
+ int viewKeyLockFee(uint64_t &fee, int coin_type, size_t n_inputs, size_t n_fee_outputs)
1290
+ LOCKS_EXCLUDED(m_mtx_view_key_chains);
1291
+ // The least a swap may lock of coin_type: 2 when the coin has no fee estimate yet.
1292
+ int swapAmountFloor(int64_t &floor, int coin_type) LOCKS_EXCLUDED(m_mtx_view_key_chains);
1293
+ int checkViewKeyFloor(std::string &str_error, int coin_type, int64_t amount, const char *name)
1294
+ LOCKS_EXCLUDED(m_mtx_view_key_chains);
1295
+ int requestFromViewKeyDeposit(const DepositInfo &deposit,
1296
+ const std::vector<DepositUtxo> &confirmed)
1297
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1298
+ int sendDepositRequest(const DepositInfo &deposit, SwapOptions &options, int64_t total)
1299
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1300
+ int sweepViewKeyDeposit(const DepositInfo &deposit, const std::vector<DepositUtxo> &utxos)
1301
+ LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1302
+ void forgetViewKeyWatches() REQUIRES(m_mtx_swap_state);
1303
+ void checkViewKeyDepositScan(bool &done, DepositScan &scan, int64_t now)
1304
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
1305
+ void stepViewKeyDepositScan(bool &done, DepositScan &scan, int64_t now)
1306
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
1307
+ void forgetDepositScan(const DepositScan &scan) REQUIRES(m_mtx_swap_state);
1308
+ void checkViewKeyRecoveries(DepositScan &scan) REQUIRES(m_mtx_swap_state, m_mtx_db);
1309
+ int watchViewKeyDepositIndex(DepositScan &scan, uint32_t index, uint64_t start,
1310
+ const std::string &outputs, uint64_t recorded_start,
1311
+ bool caught_up) REQUIRES(m_mtx_swap_state, m_mtx_db);
1312
+ void saveViewKeyDepositScan(DepositScan &scan, int64_t scanned)
1313
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
1314
+ int loadViewKeyDepositScan(DepositScan &scan) REQUIRES(m_mtx_db);
1315
+ void saveUtxoDepositScan(DepositScan &scan) REQUIRES(m_mtx_swap_state, m_mtx_db);
1316
+ int loadUtxoDepositScan(DepositScan &scan) REQUIRES(m_mtx_db);
1317
+ int recordViewKeyDepositKey(int coin_type, uint32_t index) REQUIRES(m_mtx_db);
1318
+ // A used index with funds and no row comes back RECOVERED; the db must be open.
1319
+ int recoverDeposit(int coin_type, uint32_t index, int created_height,
1320
+ const std::vector<unsigned char> &spent_outpoints)
1321
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
1322
+ int recordSpentDeposit(int coin_type, uint32_t index, const std::vector<unsigned char> &spent)
1323
+ REQUIRES(m_mtx_db);
1324
+ int spentDepositIndex(bool &found, uint32_t &index, std::vector<unsigned char> &spent,
1325
+ int coin_type, const std::string &address) REQUIRES(m_mtx_db);
1326
+ int checkDepositRequest(DepositInfo &deposit, const std::vector<DepositUtxo> *utxos,
1327
+ bool expired) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1328
+ int depositSwapProgress(bool &lock_mined, bool &swap_ended, SwapTx &lock_tx,
1329
+ const RequestId &request_id) REQUIRES(m_mtx_db);
1330
+ int setDepositState(DepositInfo &deposit, int state) LOCKS_EXCLUDED(m_mtx_db);
1331
+ int broadcastSweep(const DepositInfo &deposit) REQUIRES(m_mtx_swap_state);
1332
+ int depositJson(nlohmann::json &jd, const DepositInfo &deposit, int64_t unconfirmed,
1333
+ bool watched, bool request_active);
1334
+ int processDepositScanHistory(DepositScan &scan, int64_t watched_id,
1335
+ const nlohmann::json &history)
1336
+ REQUIRES(m_mtx_swap_state, m_mtx_db);
1337
+ int64_t getActionInterval(int action_type);
1338
+ bool relativeLockExpired(std::shared_ptr<CoinInterface> c_i, int lock_type, int lock_time,
1339
+ const SwapTx &locked_tx);
1340
+ void scheduleResubmit(Action &action) REQUIRES(m_mtx_db);
1341
+ bool updateChainState(SwapTx &swap_tx, bool on_best_chain) REQUIRES(m_mtx_db);
1342
+ bool haveWatchedTx(const std::vector<unsigned char> &txid) const REQUIRES(m_mtx_swap_state);
1343
+ int removeWatchedTransaction(int64_t watched_id) REQUIRES(m_mtx_swap_state);
1344
+ int removeWatchedScript(const std::vector<unsigned char> &swap_id, int tx_type)
1345
+ REQUIRES(m_mtx_swap_state);
1346
+ void releaseWatchedScriptPin(int64_t watched_id) REQUIRES(m_mtx_swap_state);
1347
+ Action initAction(int linked_type, const std::vector<unsigned char> &linked_id,
1348
+ int action_type) const;
1349
+ Action initSwapAction(const std::vector<unsigned char> &swap_id, int action_type) const;
1350
+ ChainClient *getElectrumClient(int coin_type);
1351
+ // The coin's active servers in turn, so no one server decides what a watch sees
1352
+ ChainClient *watchClient(int coin_type, size_t &turn);
1353
+ ChainClient *watchClientFor(int coin_type, int64_t watched_id,
1354
+ ElectrumMessageTypes message_type) REQUIRES(m_mtx_swap_state);
1355
+ int signTxDebug(std::vector<unsigned char> &tx_data, int coin_type, const SwapInfo &swap_info,
1356
+ std::string &str_error) LOCKS_EXCLUDED(m_mtx_swap_state, m_mtx_db);
1357
+
1358
+ std::mutex m_mtx_cv;
1359
+ // Set under m_mtx_cv by a monerod or Electrum reply, so the main loop's next update needn't
1360
+ // wait out the second; under the lock, a wakeup between the wait's check and its sleep isn't lost
1361
+ std::atomic<bool> m_data_woken{false};
1362
+ std::condition_variable m_cv;
1363
+
1364
+ BSX_MUTEX m_mtx_swap_state;
1365
+ // Serialises acceptOffer and signSwapSetup: each reads its guard at the top and
1366
+ // writes at the bottom, with the host deriving or signing in between.
1367
+ BSX_MUTEX m_mtx_accept;
1368
+ mutable BSX_MUTEX m_mtx_registry;
1369
+ mutable BSX_MUTEX m_mtx_view_key_chains;
1370
+ std::map<int, std::shared_ptr<ViewKeyChain>>
1371
+ m_view_key_chains GUARDED_BY(m_mtx_view_key_chains);
1372
+ std::map<int, bool> m_view_key_reserve_proofs GUARDED_BY(m_mtx_view_key_chains);
1373
+ std::map<int, int> m_view_key_anchor_states GUARDED_BY(m_mtx_view_key_chains);
1374
+ std::map<int, int> m_view_key_anchor_logged GUARDED_BY(m_mtx_view_key_chains);
1375
+ std::map<int, std::array<int64_t, 3>> m_notified_balances;
1376
+ struct ViewKeySwap {
1377
+ SwapId m_swap_id;
1378
+ int m_coin_type{0};
1379
+ bool m_invalid_logged{false};
1380
+ bool m_disputed_logged{false};
1381
+ int m_logged_state{-1};
1382
+ uint64_t m_logged_depth{0};
1383
+ int64_t m_logged_at{0};
1384
+ int64_t m_saved_resume{-1};
1385
+ std::string m_sweep_error;
1386
+ int64_t m_sent_at{0};
1387
+ bool m_checking_spent{false};
1388
+ // The chain height lock tx b was first found spent at; a check a confirmation depth on ends it
1389
+ int64_t m_spent_at{-1};
1390
+ // The chain height the newest sweep was first found missing with lock tx b unspent
1391
+ int64_t m_unspent_at{-1};
1392
+ // A follower's lock tx b is built and sent under its own id, apart from the lock's sweep
1393
+ int64_t m_lock_build_id{0};
1394
+ };
1395
+ std::map<int64_t, ViewKeySwap> m_view_key_swaps GUARDED_BY(m_mtx_swap_state);
1396
+ int64_t m_next_view_key_id GUARDED_BY(m_mtx_swap_state){1};
1397
+ std::vector<unsigned char> m_key;
1398
+ int m_identity{0};
1399
+ int m_identity_key_num{0};
1400
+ // Seals the key material HD cannot cover. Derived from the main seed, so it
1401
+ // needs no storage of its own and returns on every start. A plain vector,
1402
+ // not secure_bytes: a secure_allocator member of an object with static
1403
+ // storage outlives the locked pool and faults cleansing itself at exit.
1404
+ std::vector<unsigned char> m_wrap_key;
1405
+ ExtKey m_main_key;
1406
+ bool m_have_main_key{false};
1407
+ SecureString m_main_key_password;
1408
+ SecureString m_restore_mnemonic;
1409
+ std::string m_restore_birthday;
1410
+ std::map<int, std::string> m_restore_refund_addresses;
1411
+ bool m_skip_recovery{false};
1412
+ SecureString m_new_mnemonic;
1413
+ SecureString m_mnemonic_passphrase;
1414
+ bool m_store_passphrase{false};
1415
+ std::vector<CoopThread> m_threads;
1416
+
1417
+ std::vector<std::unique_ptr<WatchedScript>> m_watched_scripts GUARDED_BY(m_mtx_swap_state);
1418
+ // Each active swap's creation, given to its watches
1419
+ std::map<std::vector<unsigned char>, int64_t> m_swap_since GUARDED_BY(m_mtx_swap_state);
1420
+ std::vector<std::unique_ptr<WatchedTxn>> m_watched_txns GUARDED_BY(m_mtx_swap_state);
1421
+ std::vector<DepositScan> m_deposit_scans GUARDED_BY(m_mtx_swap_state);
1422
+ std::vector<DepositWatch> m_deposit_watches GUARDED_BY(m_mtx_swap_state);
1423
+ int64_t m_deposit_broadcasts GUARDED_BY(m_mtx_swap_state){0};
1424
+ bool m_deposit_scans_started GUARDED_BY(m_mtx_swap_state){false};
1425
+ // txid -> consecutive merkle proof mismatches, bounding how many times a
1426
+ // proof is re-requested for a height that keeps failing. Deliberately not
1427
+ // persisted: a restart, a new server or a new height all deserve a fresh
1428
+ // attempt. Reaching the limit never ends the swap - see confirmWatchedTx.
1429
+ std::map<std::vector<unsigned char>, int> m_merkle_mismatches GUARDED_BY(m_mtx_swap_state);
1430
+ struct RejectedSpenders {
1431
+ std::set<std::vector<unsigned char>> m_txids;
1432
+ std::deque<std::vector<unsigned char>> m_order;
1433
+ };
1434
+ std::map<std::vector<unsigned char>, RejectedSpenders>
1435
+ m_rejected_spenders GUARDED_BY(m_mtx_swap_state);
1436
+ static constexpr int m_max_merkle_mismatches{3};
1437
+ static constexpr int64_t m_header_request_timeout_seconds{120};
1438
+ std::vector<std::shared_ptr<CoinInterface>> m_coin_interfaces GUARDED_BY(m_mtx_registry);
1439
+ // Replaced wholesale by each message, never merged: the server omits a coin
1440
+ // it has no price for, and a price kept past that would go stale invisibly.
1441
+ std::map<int, int64_t> m_coin_prices GUARDED_BY(m_mtx_swap_state);
1442
+ std::string m_prices_currency GUARDED_BY(m_mtx_swap_state);
1443
+ int64_t m_prices_updated_at GUARDED_BY(m_mtx_swap_state){0};
1444
+ std::map<std::vector<unsigned char>, int64_t> m_headers_requested GUARDED_BY(m_mtx_swap_state);
1445
+ std::map<int, int64_t> m_header_roots_requested GUARDED_BY(m_mtx_db);
1446
+ struct OffersEstimateState {
1447
+ int64_t m_sent_at{0};
1448
+ bool m_answered{false};
1449
+ npb::OffersEstimate m_answer;
1450
+ };
1451
+ std::map<std::vector<unsigned char>, OffersEstimateState>
1452
+ m_offers_estimates GUARDED_BY(m_mtx_db);
1453
+ std::vector<unsigned char> m_last_offers_estimate_id GUARDED_BY(m_mtx_db);
1454
+ std::vector<unsigned char> m_last_offers_estimate_request GUARDED_BY(m_mtx_db);
1455
+
1456
+ struct AnchorCheck {
1457
+ int m_height{0};
1458
+ uint256 m_hash;
1459
+ uint256 m_chain_work;
1460
+ std::shared_ptr<BlockHeader> m_header;
1461
+ std::shared_ptr<BlockHeader> m_parent;
1462
+ bool m_reloaded{false};
1463
+ std::map<int, int64_t> m_asked;
1464
+ std::set<int> m_confirmed;
1465
+ std::set<int> m_dissented;
1466
+ std::set<int> m_ignored;
1467
+ };
1468
+ std::map<int, AnchorCheck> m_anchor_checks GUARDED_BY(m_mtx_db);
1469
+ struct AnchorDispute {
1470
+ std::string m_url;
1471
+ int m_height{0};
1472
+ bool m_reloaded{false};
1473
+ };
1474
+ std::map<int, AnchorDispute> m_anchor_disputes GUARDED_BY(m_mtx_db);
1475
+ std::set<std::pair<SwapId, std::string>> m_reported_swap_errors GUARDED_BY(m_mtx_db);
1476
+ // Live servers when a stored anchor was disputed; it is checked again once they change
1477
+ std::map<int, std::set<int>> m_disputed_anchor_servers GUARDED_BY(m_mtx_db);
1478
+ std::set<int> liveServerIds(CoinInterface &c_i, int64_t now);
1479
+ struct CommitmentCheck {
1480
+ int m_height{0};
1481
+ std::map<int, int64_t> m_asked;
1482
+ std::set<int> m_confirmed;
1483
+ std::set<int> m_unable;
1484
+ std::set<int> m_contradicted;
1485
+ };
1486
+ std::map<int, CommitmentCheck> m_commitment_checks GUARDED_BY(m_mtx_db);
1487
+ void reportServerDispute(CoinInterface &c_i, const std::string &url, int height, bool reloaded,
1488
+ const char *what) REQUIRES(m_mtx_db);
1489
+ void startCommitmentCheck(CoinInterface &c_i, int height, int64_t now) REQUIRES(m_mtx_db);
1490
+ void askCommitmentServers(CoinInterface &c_i, CommitmentCheck &check, int64_t now)
1491
+ REQUIRES(m_mtx_db);
1492
+ void settleChainCommitment(CoinInterface &c_i, int64_t now) REQUIRES(m_mtx_db);
1493
+ struct BroadcastRound {
1494
+ int64_t m_started{0};
1495
+ std::set<int> m_asked;
1496
+ std::set<int> m_refused;
1497
+ bool m_settled{false};
1498
+ };
1499
+ std::map<int64_t, BroadcastRound> m_broadcasts GUARDED_BY(m_mtx_swap_state);
1500
+ std::string serverUrl(CoinInterface &c_i, int client_id);
1501
+ bool broadcastPending(CoinInterface &c_i, const BroadcastRound &round, int64_t now);
1502
+ bool lastBroadcastRefusal(CoinInterface &c_i, int64_t action_id, int client_id, int64_t now)
1503
+ REQUIRES(m_mtx_swap_state);
1504
+ void askAnchorServers(CoinInterface &c_i, AnchorCheck &check, int64_t now) REQUIRES(m_mtx_db);
1505
+ void settleChainAnchor(CoinInterface &c_i, int64_t now) REQUIRES(m_mtx_swap_state, m_mtx_db);
1506
+ void refuseChainAnchor(CoinInterface &c_i, const AnchorCheck &check) REQUIRES(m_mtx_db);
1507
+ void updateBridge(int64_t now);
1508
+ #if defined(__EMSCRIPTEN__) && !defined(__EMSCRIPTEN_PTHREADS__)
1509
+ std::atomic<uint64_t> m_update_fiber{0};
1510
+ #else
1511
+ std::atomic<std::thread::id> m_update_thread;
1512
+ #endif
1513
+
1514
+ int64_t m_watched_count{0}; // Used as an id for watched elements
1515
+
1516
+ int m_last_checked_watched{0};
1517
+ int64_t m_last_polled{0};
1518
+ int64_t m_last_expired{0};
1519
+ int m_expire_check_seconds{300};
1520
+ int m_electrum_client_count{0};
1521
+ };
1522
+
1523
+ } // namespace bsx