@bitpay-labs/crypto-wallet-core 11.5.1

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 (343) hide show
  1. package/README.md +13 -0
  2. package/package.json +58 -0
  3. package/src/constants/address.ts +7 -0
  4. package/src/constants/algorithms.ts +9 -0
  5. package/src/constants/chains.ts +64 -0
  6. package/src/constants/feeMinimums.ts +20 -0
  7. package/src/constants/index.ts +37 -0
  8. package/src/constants/tokens.ts +224 -0
  9. package/src/constants/units.ts +289 -0
  10. package/src/derivation/arb/index.ts +3 -0
  11. package/src/derivation/base/index.ts +3 -0
  12. package/src/derivation/bch/index.ts +11 -0
  13. package/src/derivation/btc/index.ts +39 -0
  14. package/src/derivation/doge/index.ts +6 -0
  15. package/src/derivation/eth/index.ts +58 -0
  16. package/src/derivation/index.ts +124 -0
  17. package/src/derivation/ltc/index.ts +6 -0
  18. package/src/derivation/matic/index.ts +3 -0
  19. package/src/derivation/op/index.ts +3 -0
  20. package/src/derivation/paths.ts +42 -0
  21. package/src/derivation/sol/index.ts +57 -0
  22. package/src/derivation/xrp/index.ts +38 -0
  23. package/src/index.ts +48 -0
  24. package/src/message/btc.ts +28 -0
  25. package/src/message/eth.ts +47 -0
  26. package/src/message/index.ts +70 -0
  27. package/src/message/sol.ts +3 -0
  28. package/src/message/xrp.ts +4 -0
  29. package/src/transactions/arb/index.ts +14 -0
  30. package/src/transactions/base/index.ts +13 -0
  31. package/src/transactions/bch/index.ts +25 -0
  32. package/src/transactions/btc/index.ts +227 -0
  33. package/src/transactions/doge/index.ts +31 -0
  34. package/src/transactions/erc20/abi.ts +418 -0
  35. package/src/transactions/erc20/index.ts +57 -0
  36. package/src/transactions/eth/index.ts +183 -0
  37. package/src/transactions/eth-multisig/abi.ts +724 -0
  38. package/src/transactions/eth-multisig/index.ts +172 -0
  39. package/src/transactions/index.ts +83 -0
  40. package/src/transactions/ltc/index.ts +31 -0
  41. package/src/transactions/matic/index.ts +14 -0
  42. package/src/transactions/matic-multisig/index.ts +172 -0
  43. package/src/transactions/op/index.ts +14 -0
  44. package/src/transactions/sol/index.ts +292 -0
  45. package/src/transactions/spl/index.ts +192 -0
  46. package/src/transactions/xrp/index.ts +129 -0
  47. package/src/types/derivation.ts +17 -0
  48. package/src/types/index.ts +3 -0
  49. package/src/types/message.ts +15 -0
  50. package/src/types/utils.ts +1 -0
  51. package/src/types/validation.ts +4 -0
  52. package/src/utils/bigint.ts +238 -0
  53. package/src/utils/index.ts +94 -0
  54. package/src/validation/arb/index.ts +8 -0
  55. package/src/validation/base/index.ts +8 -0
  56. package/src/validation/bch/index.ts +17 -0
  57. package/src/validation/btc/index.ts +17 -0
  58. package/src/validation/doge/index.ts +16 -0
  59. package/src/validation/eth/index.ts +29 -0
  60. package/src/validation/index.ts +43 -0
  61. package/src/validation/ltc/index.ts +16 -0
  62. package/src/validation/matic/index.ts +8 -0
  63. package/src/validation/op/index.ts +8 -0
  64. package/src/validation/sol/index.ts +34 -0
  65. package/src/validation/xrp/index.ts +50 -0
  66. package/test/address.test.ts +178 -0
  67. package/test/bigint.test.ts +373 -0
  68. package/test/transactions.test.ts +1777 -0
  69. package/test/utils.test.ts +121 -0
  70. package/test/validation.test.ts +261 -0
  71. package/ts_build/src/constants/address.d.ts +8 -0
  72. package/ts_build/src/constants/address.d.ts.map +1 -0
  73. package/ts_build/src/constants/address.js +11 -0
  74. package/ts_build/src/constants/address.js.map +1 -0
  75. package/ts_build/src/constants/algorithms.d.ts +9 -0
  76. package/ts_build/src/constants/algorithms.d.ts.map +1 -0
  77. package/ts_build/src/constants/algorithms.js +12 -0
  78. package/ts_build/src/constants/algorithms.js.map +1 -0
  79. package/ts_build/src/constants/chains.d.ts +42 -0
  80. package/ts_build/src/constants/chains.d.ts.map +1 -0
  81. package/ts_build/src/constants/chains.js +54 -0
  82. package/ts_build/src/constants/chains.js.map +1 -0
  83. package/ts_build/src/constants/feeMinimums.d.ts +21 -0
  84. package/ts_build/src/constants/feeMinimums.d.ts.map +1 -0
  85. package/ts_build/src/constants/feeMinimums.js +24 -0
  86. package/ts_build/src/constants/feeMinimums.js.map +1 -0
  87. package/ts_build/src/constants/index.d.ts +569 -0
  88. package/ts_build/src/constants/index.d.ts.map +1 -0
  89. package/ts_build/src/constants/index.js +31 -0
  90. package/ts_build/src/constants/index.js.map +1 -0
  91. package/ts_build/src/constants/tokens.d.ts +423 -0
  92. package/ts_build/src/constants/tokens.d.ts.map +1 -0
  93. package/ts_build/src/constants/tokens.js +222 -0
  94. package/ts_build/src/constants/tokens.js.map +1 -0
  95. package/ts_build/src/constants/units.d.ts +289 -0
  96. package/ts_build/src/constants/units.d.ts.map +1 -0
  97. package/ts_build/src/constants/units.js +292 -0
  98. package/ts_build/src/constants/units.js.map +1 -0
  99. package/ts_build/src/derivation/arb/index.d.ts +4 -0
  100. package/ts_build/src/derivation/arb/index.d.ts.map +1 -0
  101. package/ts_build/src/derivation/arb/index.js +8 -0
  102. package/ts_build/src/derivation/arb/index.js.map +1 -0
  103. package/ts_build/src/derivation/base/index.d.ts +4 -0
  104. package/ts_build/src/derivation/base/index.d.ts.map +1 -0
  105. package/ts_build/src/derivation/base/index.js +8 -0
  106. package/ts_build/src/derivation/base/index.js.map +1 -0
  107. package/ts_build/src/derivation/bch/index.d.ts +6 -0
  108. package/ts_build/src/derivation/bch/index.d.ts.map +1 -0
  109. package/ts_build/src/derivation/bch/index.js +17 -0
  110. package/ts_build/src/derivation/bch/index.js.map +1 -0
  111. package/ts_build/src/derivation/btc/index.d.ts +23 -0
  112. package/ts_build/src/derivation/btc/index.d.ts.map +1 -0
  113. package/ts_build/src/derivation/btc/index.js +40 -0
  114. package/ts_build/src/derivation/btc/index.js.map +1 -0
  115. package/ts_build/src/derivation/doge/index.d.ts +5 -0
  116. package/ts_build/src/derivation/doge/index.d.ts.map +1 -0
  117. package/ts_build/src/derivation/doge/index.js +13 -0
  118. package/ts_build/src/derivation/doge/index.js.map +1 -0
  119. package/ts_build/src/derivation/eth/index.d.ts +21 -0
  120. package/ts_build/src/derivation/eth/index.d.ts.map +1 -0
  121. package/ts_build/src/derivation/eth/index.js +58 -0
  122. package/ts_build/src/derivation/eth/index.js.map +1 -0
  123. package/ts_build/src/derivation/index.d.ts +12 -0
  124. package/ts_build/src/derivation/index.d.ts.map +1 -0
  125. package/ts_build/src/derivation/index.js +68 -0
  126. package/ts_build/src/derivation/index.js.map +1 -0
  127. package/ts_build/src/derivation/ltc/index.d.ts +5 -0
  128. package/ts_build/src/derivation/ltc/index.d.ts.map +1 -0
  129. package/ts_build/src/derivation/ltc/index.js +13 -0
  130. package/ts_build/src/derivation/ltc/index.js.map +1 -0
  131. package/ts_build/src/derivation/matic/index.d.ts +4 -0
  132. package/ts_build/src/derivation/matic/index.d.ts.map +1 -0
  133. package/ts_build/src/derivation/matic/index.js +8 -0
  134. package/ts_build/src/derivation/matic/index.js.map +1 -0
  135. package/ts_build/src/derivation/op/index.d.ts +4 -0
  136. package/ts_build/src/derivation/op/index.d.ts.map +1 -0
  137. package/ts_build/src/derivation/op/index.js +8 -0
  138. package/ts_build/src/derivation/op/index.js.map +1 -0
  139. package/ts_build/src/derivation/paths.d.ts +43 -0
  140. package/ts_build/src/derivation/paths.d.ts.map +1 -0
  141. package/ts_build/src/derivation/paths.js +46 -0
  142. package/ts_build/src/derivation/paths.js.map +1 -0
  143. package/ts_build/src/derivation/sol/index.d.ts +17 -0
  144. package/ts_build/src/derivation/sol/index.d.ts.map +1 -0
  145. package/ts_build/src/derivation/sol/index.js +85 -0
  146. package/ts_build/src/derivation/sol/index.js.map +1 -0
  147. package/ts_build/src/derivation/xrp/index.d.ts +19 -0
  148. package/ts_build/src/derivation/xrp/index.d.ts.map +1 -0
  149. package/ts_build/src/derivation/xrp/index.js +40 -0
  150. package/ts_build/src/derivation/xrp/index.js.map +1 -0
  151. package/ts_build/src/index.d.ts +30 -0
  152. package/ts_build/src/index.d.ts.map +1 -0
  153. package/ts_build/src/index.js +81 -0
  154. package/ts_build/src/index.js.map +1 -0
  155. package/ts_build/src/message/btc.d.ts +19 -0
  156. package/ts_build/src/message/btc.d.ts.map +1 -0
  157. package/ts_build/src/message/btc.js +32 -0
  158. package/ts_build/src/message/btc.js.map +1 -0
  159. package/ts_build/src/message/eth.d.ts +19 -0
  160. package/ts_build/src/message/eth.d.ts.map +1 -0
  161. package/ts_build/src/message/eth.js +39 -0
  162. package/ts_build/src/message/eth.js.map +1 -0
  163. package/ts_build/src/message/index.d.ts +25 -0
  164. package/ts_build/src/message/index.d.ts.map +1 -0
  165. package/ts_build/src/message/index.js +50 -0
  166. package/ts_build/src/message/index.js.map +1 -0
  167. package/ts_build/src/message/sol.d.ts +4 -0
  168. package/ts_build/src/message/sol.d.ts.map +1 -0
  169. package/ts_build/src/message/sol.js +9 -0
  170. package/ts_build/src/message/sol.js.map +1 -0
  171. package/ts_build/src/message/xrp.d.ts +4 -0
  172. package/ts_build/src/message/xrp.d.ts.map +1 -0
  173. package/ts_build/src/message/xrp.js +9 -0
  174. package/ts_build/src/message/xrp.js.map +1 -0
  175. package/ts_build/src/transactions/arb/index.d.ts +9 -0
  176. package/ts_build/src/transactions/arb/index.d.ts.map +1 -0
  177. package/ts_build/src/transactions/arb/index.js +18 -0
  178. package/ts_build/src/transactions/arb/index.js.map +1 -0
  179. package/ts_build/src/transactions/base/index.d.ts +8 -0
  180. package/ts_build/src/transactions/base/index.d.ts.map +1 -0
  181. package/ts_build/src/transactions/base/index.js +17 -0
  182. package/ts_build/src/transactions/base/index.js.map +1 -0
  183. package/ts_build/src/transactions/bch/index.d.ts +12 -0
  184. package/ts_build/src/transactions/bch/index.d.ts.map +1 -0
  185. package/ts_build/src/transactions/bch/index.js +32 -0
  186. package/ts_build/src/transactions/bch/index.js.map +1 -0
  187. package/ts_build/src/transactions/btc/index.d.ts +84 -0
  188. package/ts_build/src/transactions/btc/index.d.ts.map +1 -0
  189. package/ts_build/src/transactions/btc/index.js +184 -0
  190. package/ts_build/src/transactions/btc/index.js.map +1 -0
  191. package/ts_build/src/transactions/doge/index.d.ts +12 -0
  192. package/ts_build/src/transactions/doge/index.d.ts.map +1 -0
  193. package/ts_build/src/transactions/doge/index.js +38 -0
  194. package/ts_build/src/transactions/doge/index.js.map +1 -0
  195. package/ts_build/src/transactions/erc20/abi.d.ts +78 -0
  196. package/ts_build/src/transactions/erc20/abi.d.ts.map +1 -0
  197. package/ts_build/src/transactions/erc20/abi.js +421 -0
  198. package/ts_build/src/transactions/erc20/abi.js.map +1 -0
  199. package/ts_build/src/transactions/erc20/index.d.ts +29 -0
  200. package/ts_build/src/transactions/erc20/index.d.ts.map +1 -0
  201. package/ts_build/src/transactions/erc20/index.js +46 -0
  202. package/ts_build/src/transactions/erc20/index.js.map +1 -0
  203. package/ts_build/src/transactions/eth/index.d.ts +53 -0
  204. package/ts_build/src/transactions/eth/index.d.ts.map +1 -0
  205. package/ts_build/src/transactions/eth/index.js +156 -0
  206. package/ts_build/src/transactions/eth/index.js.map +1 -0
  207. package/ts_build/src/transactions/eth-multisig/abi.d.ts +51 -0
  208. package/ts_build/src/transactions/eth-multisig/abi.d.ts.map +1 -0
  209. package/ts_build/src/transactions/eth-multisig/abi.js +728 -0
  210. package/ts_build/src/transactions/eth-multisig/abi.js.map +1 -0
  211. package/ts_build/src/transactions/eth-multisig/index.d.ts +65 -0
  212. package/ts_build/src/transactions/eth-multisig/index.d.ts.map +1 -0
  213. package/ts_build/src/transactions/eth-multisig/index.js +143 -0
  214. package/ts_build/src/transactions/eth-multisig/index.js.map +1 -0
  215. package/ts_build/src/transactions/index.d.ts +15 -0
  216. package/ts_build/src/transactions/index.d.ts.map +1 -0
  217. package/ts_build/src/transactions/index.js +69 -0
  218. package/ts_build/src/transactions/index.js.map +1 -0
  219. package/ts_build/src/transactions/ltc/index.d.ts +12 -0
  220. package/ts_build/src/transactions/ltc/index.d.ts.map +1 -0
  221. package/ts_build/src/transactions/ltc/index.js +38 -0
  222. package/ts_build/src/transactions/ltc/index.js.map +1 -0
  223. package/ts_build/src/transactions/matic/index.d.ts +9 -0
  224. package/ts_build/src/transactions/matic/index.d.ts.map +1 -0
  225. package/ts_build/src/transactions/matic/index.js +18 -0
  226. package/ts_build/src/transactions/matic/index.js.map +1 -0
  227. package/ts_build/src/transactions/matic-multisig/index.d.ts +65 -0
  228. package/ts_build/src/transactions/matic-multisig/index.d.ts.map +1 -0
  229. package/ts_build/src/transactions/matic-multisig/index.js +143 -0
  230. package/ts_build/src/transactions/matic-multisig/index.js.map +1 -0
  231. package/ts_build/src/transactions/op/index.d.ts +9 -0
  232. package/ts_build/src/transactions/op/index.d.ts.map +1 -0
  233. package/ts_build/src/transactions/op/index.js +18 -0
  234. package/ts_build/src/transactions/op/index.js.map +1 -0
  235. package/ts_build/src/transactions/sol/index.d.ts +56 -0
  236. package/ts_build/src/transactions/sol/index.d.ts.map +1 -0
  237. package/ts_build/src/transactions/sol/index.js +261 -0
  238. package/ts_build/src/transactions/sol/index.js.map +1 -0
  239. package/ts_build/src/transactions/spl/index.d.ts +57 -0
  240. package/ts_build/src/transactions/spl/index.d.ts.map +1 -0
  241. package/ts_build/src/transactions/spl/index.js +129 -0
  242. package/ts_build/src/transactions/spl/index.js.map +1 -0
  243. package/ts_build/src/transactions/xrp/index.d.ts +50 -0
  244. package/ts_build/src/transactions/xrp/index.d.ts.map +1 -0
  245. package/ts_build/src/transactions/xrp/index.js +146 -0
  246. package/ts_build/src/transactions/xrp/index.js.map +1 -0
  247. package/ts_build/src/types/derivation.d.ts +13 -0
  248. package/ts_build/src/types/derivation.d.ts.map +1 -0
  249. package/ts_build/src/types/derivation.js +3 -0
  250. package/ts_build/src/types/derivation.js.map +1 -0
  251. package/ts_build/src/types/index.d.ts +4 -0
  252. package/ts_build/src/types/index.d.ts.map +1 -0
  253. package/ts_build/src/types/index.js +40 -0
  254. package/ts_build/src/types/index.js.map +1 -0
  255. package/ts_build/src/types/message.d.ts +26 -0
  256. package/ts_build/src/types/message.d.ts.map +1 -0
  257. package/ts_build/src/types/message.js +3 -0
  258. package/ts_build/src/types/message.js.map +1 -0
  259. package/ts_build/src/types/utils.d.ts +2 -0
  260. package/ts_build/src/types/utils.d.ts.map +1 -0
  261. package/ts_build/src/types/utils.js +3 -0
  262. package/ts_build/src/types/utils.js.map +1 -0
  263. package/ts_build/src/types/validation.d.ts +5 -0
  264. package/ts_build/src/types/validation.d.ts.map +1 -0
  265. package/ts_build/src/types/validation.js +3 -0
  266. package/ts_build/src/types/validation.js.map +1 -0
  267. package/ts_build/src/utils/bigint.d.ts +14 -0
  268. package/ts_build/src/utils/bigint.d.ts.map +1 -0
  269. package/ts_build/src/utils/bigint.js +165 -0
  270. package/ts_build/src/utils/bigint.js.map +1 -0
  271. package/ts_build/src/utils/index.d.ts +12 -0
  272. package/ts_build/src/utils/index.d.ts.map +1 -0
  273. package/ts_build/src/utils/index.js +118 -0
  274. package/ts_build/src/utils/index.js.map +1 -0
  275. package/ts_build/src/validation/arb/index.d.ts +5 -0
  276. package/ts_build/src/validation/arb/index.d.ts.map +1 -0
  277. package/ts_build/src/validation/arb/index.js +12 -0
  278. package/ts_build/src/validation/arb/index.js.map +1 -0
  279. package/ts_build/src/validation/base/index.d.ts +5 -0
  280. package/ts_build/src/validation/base/index.d.ts.map +1 -0
  281. package/ts_build/src/validation/base/index.js +12 -0
  282. package/ts_build/src/validation/base/index.js.map +1 -0
  283. package/ts_build/src/validation/bch/index.d.ts +6 -0
  284. package/ts_build/src/validation/bch/index.d.ts.map +1 -0
  285. package/ts_build/src/validation/bch/index.js +19 -0
  286. package/ts_build/src/validation/bch/index.js.map +1 -0
  287. package/ts_build/src/validation/btc/index.d.ts +6 -0
  288. package/ts_build/src/validation/btc/index.d.ts.map +1 -0
  289. package/ts_build/src/validation/btc/index.js +19 -0
  290. package/ts_build/src/validation/btc/index.js.map +1 -0
  291. package/ts_build/src/validation/doge/index.d.ts +6 -0
  292. package/ts_build/src/validation/doge/index.d.ts.map +1 -0
  293. package/ts_build/src/validation/doge/index.js +19 -0
  294. package/ts_build/src/validation/doge/index.js.map +1 -0
  295. package/ts_build/src/validation/eth/index.d.ts +9 -0
  296. package/ts_build/src/validation/eth/index.d.ts.map +1 -0
  297. package/ts_build/src/validation/eth/index.js +28 -0
  298. package/ts_build/src/validation/eth/index.js.map +1 -0
  299. package/ts_build/src/validation/index.d.ts +9 -0
  300. package/ts_build/src/validation/index.d.ts.map +1 -0
  301. package/ts_build/src/validation/index.js +42 -0
  302. package/ts_build/src/validation/index.js.map +1 -0
  303. package/ts_build/src/validation/ltc/index.d.ts +6 -0
  304. package/ts_build/src/validation/ltc/index.d.ts.map +1 -0
  305. package/ts_build/src/validation/ltc/index.js +19 -0
  306. package/ts_build/src/validation/ltc/index.js.map +1 -0
  307. package/ts_build/src/validation/matic/index.d.ts +5 -0
  308. package/ts_build/src/validation/matic/index.d.ts.map +1 -0
  309. package/ts_build/src/validation/matic/index.js +12 -0
  310. package/ts_build/src/validation/matic/index.js.map +1 -0
  311. package/ts_build/src/validation/op/index.d.ts +5 -0
  312. package/ts_build/src/validation/op/index.d.ts.map +1 -0
  313. package/ts_build/src/validation/op/index.js +12 -0
  314. package/ts_build/src/validation/op/index.js.map +1 -0
  315. package/ts_build/src/validation/sol/index.d.ts +9 -0
  316. package/ts_build/src/validation/sol/index.d.ts.map +1 -0
  317. package/ts_build/src/validation/sol/index.js +34 -0
  318. package/ts_build/src/validation/sol/index.js.map +1 -0
  319. package/ts_build/src/validation/xrp/index.d.ts +7 -0
  320. package/ts_build/src/validation/xrp/index.d.ts.map +1 -0
  321. package/ts_build/src/validation/xrp/index.js +50 -0
  322. package/ts_build/src/validation/xrp/index.js.map +1 -0
  323. package/ts_build/test/address.test.d.ts +2 -0
  324. package/ts_build/test/address.test.d.ts.map +1 -0
  325. package/ts_build/test/address.test.js +139 -0
  326. package/ts_build/test/address.test.js.map +1 -0
  327. package/ts_build/test/bigint.test.d.ts +2 -0
  328. package/ts_build/test/bigint.test.d.ts.map +1 -0
  329. package/ts_build/test/bigint.test.js +298 -0
  330. package/ts_build/test/bigint.test.js.map +1 -0
  331. package/ts_build/test/transactions.test.d.ts +2 -0
  332. package/ts_build/test/transactions.test.d.ts.map +1 -0
  333. package/ts_build/test/transactions.test.js +1549 -0
  334. package/ts_build/test/transactions.test.js.map +1 -0
  335. package/ts_build/test/utils.test.d.ts +2 -0
  336. package/ts_build/test/utils.test.d.ts.map +1 -0
  337. package/ts_build/test/utils.test.js +137 -0
  338. package/ts_build/test/utils.test.js.map +1 -0
  339. package/ts_build/test/validation.test.d.ts +2 -0
  340. package/ts_build/test/validation.test.d.ts.map +1 -0
  341. package/ts_build/test/validation.test.js +210 -0
  342. package/ts_build/test/validation.test.js.map +1 -0
  343. package/tsconfig.json +29 -0
package/src/index.ts ADDED
@@ -0,0 +1,48 @@
1
+ import * as BitcoreLib from '@bitpay-labs/bitcore-lib';
2
+ import * as BitcoreLibCash from '@bitpay-labs/bitcore-lib-cash';
3
+ import * as BitcoreLibDoge from '@bitpay-labs/bitcore-lib-doge';
4
+ import * as BitcoreLibLtc from '@bitpay-labs/bitcore-lib-ltc';
5
+ import * as SolKit from '@solana/kit';
6
+ import * as ComputeBudget from '@solana-program/compute-budget';
7
+ import * as Memo from '@solana-program/memo';
8
+ import * as System from '@solana-program/system';
9
+ import * as Token from '@solana-program/token';
10
+ import * as HDKey from 'ed25519-hd-key';
11
+ import { ethers } from 'ethers';
12
+ import Web3 from 'web3';
13
+ import * as xrpl from 'xrpl';
14
+ import { Constants } from './constants';
15
+ import Deriver from './derivation';
16
+ import Message from './message';
17
+ import Transactions from './transactions';
18
+ import * as Utils from './utils';
19
+ import Validation from './validation';
20
+
21
+ export type * as Types from './types';
22
+ export type * as Web3Types from 'web3-types';
23
+
24
+
25
+ const SolanaProgram = {
26
+ ComputeBudget,
27
+ Memo,
28
+ System,
29
+ Token,
30
+ HDKey
31
+ };
32
+ export {
33
+ BitcoreLib,
34
+ BitcoreLibCash,
35
+ BitcoreLibDoge,
36
+ BitcoreLibLtc,
37
+ Deriver,
38
+ Message,
39
+ Transactions,
40
+ Validation,
41
+ ethers,
42
+ Web3,
43
+ SolKit,
44
+ SolanaProgram,
45
+ Constants,
46
+ xrpl,
47
+ Utils
48
+ };
@@ -0,0 +1,28 @@
1
+ import BitcoreLib from '@bitpay-labs/bitcore-lib';
2
+ import { encodeBuffer } from '../utils';
3
+ import type { Encoding, HDKeyType, IMessageClass, ISignedMessage, KeyType } from '../types/message';
4
+
5
+ export class BtcMessage implements IMessageClass {
6
+ getMessageHash(args: { message: string; encoding?: Encoding }): Buffer | string {
7
+ const { message, encoding } = args;
8
+ const buf = Buffer.from(new BitcoreLib.Message(message).magicHash());
9
+ return encodeBuffer(buf, encoding);
10
+ }
11
+
12
+ signMessage(args: { message: string; privateKey: KeyType; encoding?: Encoding }): ISignedMessage {
13
+ const { message, encoding } = args;
14
+ let { privateKey } = args;
15
+ privateKey = new BitcoreLib.PrivateKey(privateKey);
16
+ const buf = Buffer.from(new BitcoreLib.Message(message).sign(privateKey), 'base64');
17
+ return {
18
+ signature: encodeBuffer(buf, encoding),
19
+ publicKey: privateKey.publicKey.toString()
20
+ };
21
+ }
22
+
23
+ signMessageWithPath(args: { message: string; hdPrivateKey: HDKeyType; derivationPath: string; encoding?: Encoding }): ISignedMessage {
24
+ const { message, hdPrivateKey, derivationPath, encoding } = args;
25
+ const privateKey = new BitcoreLib.HDPrivateKey(hdPrivateKey).deriveChild(derivationPath).privateKey;
26
+ return this.signMessage({ message, privateKey, encoding });
27
+ }
28
+ }
@@ -0,0 +1,47 @@
1
+ import BitcoreLib from '@bitpay-labs/bitcore-lib';
2
+ import { ethers } from 'ethers';
3
+ import { encodeBuffer } from '../utils';
4
+ import type { Encoding, HDKeyType, IMessageClass, ISignedMessage, KeyType } from '../types/message';
5
+
6
+ export class EthMessage implements IMessageClass {
7
+ getMessageHash(args: {
8
+ message: string;
9
+ encoding?: Encoding;
10
+ }): Buffer | string {
11
+ const { message, encoding } = args;
12
+ const prefix = '\x19Ethereum Signed Message:\n' + message.length;
13
+ const messageHash = ethers.keccak256(ethers.toUtf8Bytes(prefix + message));
14
+ const buf = Buffer.from(messageHash.slice(2), 'hex');
15
+ return encodeBuffer(buf, encoding);
16
+ }
17
+
18
+ signMessage(args: {
19
+ message: string;
20
+ privateKey: KeyType;
21
+ encoding?: Encoding;
22
+ }): ISignedMessage {
23
+ const { message, encoding } = args;
24
+ let { privateKey } = args;
25
+ privateKey = typeof privateKey === 'string' && privateKey.startsWith('0x') ? privateKey.slice(2) : privateKey;
26
+ privateKey = new BitcoreLib.PrivateKey(privateKey);
27
+ const messageHash = this.getMessageHash({ message });
28
+ const signingKey = new ethers.SigningKey('0x' + privateKey.toString('hex'));
29
+ const sig = signingKey.sign(messageHash);
30
+ const buf = Buffer.from(sig.serialized.slice(2), 'hex');
31
+ return {
32
+ signature: encodeBuffer(buf, encoding),
33
+ publicKey: privateKey.publicKey.toString()
34
+ };
35
+ }
36
+
37
+ signMessageWithPath(args: {
38
+ message: string;
39
+ hdPrivateKey: HDKeyType;
40
+ derivationPath: string;
41
+ encoding?: Encoding;
42
+ }): ISignedMessage {
43
+ const { message, hdPrivateKey, derivationPath, encoding } = args;
44
+ const privateKey = new BitcoreLib.HDPrivateKey(hdPrivateKey).deriveChild(derivationPath).privateKey;
45
+ return this.signMessage({ message, privateKey, encoding });
46
+ }
47
+ }
@@ -0,0 +1,70 @@
1
+ import { BtcMessage } from './btc';
2
+ import { EthMessage } from './eth';
3
+ import { SolMessage } from './sol';
4
+ import { XrpMessage } from './xrp';
5
+ import type { Encoding, HDKeyType, IMessageClass, ISignedMessage, KeyType } from '../types/message';
6
+
7
+
8
+ const MessageClasses: Record<string, IMessageClass> = {
9
+ btc: new BtcMessage(),
10
+ bch: new BtcMessage(),
11
+ doge: new BtcMessage(),
12
+ ltc: new BtcMessage(),
13
+ eth: new EthMessage(),
14
+ matic: new EthMessage(),
15
+ arb: new EthMessage(),
16
+ base: new EthMessage(),
17
+ op: new EthMessage(),
18
+ sol: new SolMessage(),
19
+ xrp: new XrpMessage()
20
+ };
21
+
22
+ export class MessageProxy {
23
+ private get(chain: string): IMessageClass {
24
+ const normalizedChain = chain.toLowerCase();
25
+ const messageClass = MessageClasses[normalizedChain];
26
+ if (!messageClass) {
27
+ throw new Error(`Unsupported chain: ${chain}`);
28
+ }
29
+ return messageClass;
30
+ }
31
+
32
+ getMessageHash(args: {
33
+ chain: string;
34
+ message: string;
35
+ /** The encoding to use for the output. Will return a Buffer if not specified. */
36
+ encoding?: Encoding;
37
+ }): Buffer | string {
38
+ const { message, chain, encoding } = args;
39
+ const messageClass = this.get(chain);
40
+ return messageClass.getMessageHash({ message, encoding });
41
+ }
42
+
43
+ signMessage(args: {
44
+ chain: string;
45
+ message: string;
46
+ privateKey: KeyType;
47
+ /** The encoding to use for the output. Will return a Buffer if not specified. */
48
+ encoding?: Encoding;
49
+ }): ISignedMessage {
50
+ const { message, chain, privateKey, encoding } = args;
51
+ const messageClass = this.get(chain);
52
+ if (!messageClass) throw new Error(`Unsupported chain: ${chain}`);
53
+ return messageClass.signMessage({ message, privateKey, encoding });
54
+ }
55
+
56
+ signMessageWithPath(args: {
57
+ chain: string;
58
+ message: string;
59
+ hdPrivateKey: HDKeyType;
60
+ derivationPath: string;
61
+ /** The encoding to use for the output. Will return a Buffer if not specified. */
62
+ encoding?: Encoding;
63
+ }): ISignedMessage {
64
+ const { message, chain, hdPrivateKey, derivationPath, encoding } = args;
65
+ const messageClass = this.get(chain);
66
+ return messageClass.signMessageWithPath({ message, hdPrivateKey, derivationPath, encoding });
67
+ }
68
+ }
69
+
70
+ export default new MessageProxy();
@@ -0,0 +1,3 @@
1
+ import { EthMessage } from './eth';
2
+
3
+ export class SolMessage extends EthMessage {}; // TODO
@@ -0,0 +1,4 @@
1
+ import { EthMessage } from './eth';
2
+
3
+ // XRP reuses Ethereum-compatible message signing format
4
+ export class XrpMessage extends EthMessage {};
@@ -0,0 +1,14 @@
1
+ import { ERC20TxProvider } from '../erc20';
2
+ import { ETHTxProvider } from '../eth';
3
+
4
+ export class ARBTxProvider extends ETHTxProvider {
5
+ constructor() {
6
+ super('ARB');
7
+ }
8
+ }
9
+
10
+ export class ARBERC20TxProvider extends ERC20TxProvider {
11
+ constructor() {
12
+ super('ARB');
13
+ }
14
+ }
@@ -0,0 +1,13 @@
1
+ import { OPERC20TxProvider, OPTxProvider } from '../op';
2
+
3
+ export class BASETxProvider extends OPTxProvider {
4
+ constructor() {
5
+ super('BASE');
6
+ }
7
+ }
8
+
9
+ export class BASEERC20TxProvider extends OPERC20TxProvider {
10
+ constructor() {
11
+ super('BASE');
12
+ }
13
+ }
@@ -0,0 +1,25 @@
1
+ import BitcoreLibCash from '@bitpay-labs/bitcore-lib-cash';
2
+ import { BTCTxProvider } from '../btc';
3
+
4
+ export class BCHTxProvider extends BTCTxProvider {
5
+ lib = BitcoreLibCash;
6
+ create({ recipients, utxos = [], change, fee = 20000, isSweep }) {
7
+ const filteredUtxos = isSweep ? utxos : this.selectCoins(recipients, utxos, fee);
8
+ const btcUtxos = filteredUtxos.map(utxo => {
9
+ const btcUtxo = Object.assign({}, utxo, {
10
+ amount: utxo.value / 1e8,
11
+ txid: utxo.mintTxid,
12
+ outputIndex: utxo.mintIndex
13
+ });
14
+ return new this.lib.Transaction.UnspentOutput(btcUtxo);
15
+ });
16
+ const tx = new this.lib.Transaction().from(btcUtxos).feePerByte(Number(fee) + 2);
17
+ if (change) {
18
+ tx.change(change);
19
+ }
20
+ for (const recipient of recipients) {
21
+ tx.to(recipient.address, parseInt(recipient.amount));
22
+ }
23
+ return tx.uncheckedSerialize();
24
+ }
25
+ }
@@ -0,0 +1,227 @@
1
+ import assert from 'assert';
2
+ import BitcoreLib from '@bitpay-labs/bitcore-lib';
3
+ import type { Key } from '../../types/derivation';
4
+
5
+ const $ = BitcoreLib.util.preconditions;
6
+
7
+ interface TssSig {
8
+ r: string;
9
+ s: string;
10
+ v: number;
11
+ pubKey: string;
12
+ };
13
+
14
+ export class BTCTxProvider {
15
+ lib = BitcoreLib;
16
+
17
+ selectCoins(
18
+ recipients: Array<{ amount: number }>,
19
+ utxos: Array<{
20
+ value: number;
21
+ mintHeight: number;
22
+ txid?: string;
23
+ mintTxid?: string;
24
+ mintIndex?: number;
25
+ }>,
26
+ fee: number
27
+ ) {
28
+ utxos = utxos.sort(function(a, b) {
29
+ return a.mintHeight - b.mintHeight;
30
+ });
31
+
32
+ let index = 0;
33
+ let utxoSum = 0;
34
+ const recepientSum = recipients.reduce((sum, cur) => sum + Number(cur.amount), fee || 0);
35
+ while (utxoSum < recepientSum) {
36
+ const utxo = utxos[index];
37
+ utxoSum += Number(utxo.value);
38
+ index += 1;
39
+ }
40
+ const filteredUtxos = utxos.slice(0, index);
41
+ return filteredUtxos;
42
+ }
43
+
44
+ create({ recipients, utxos = [], change, feeRate, fee, isSweep, replaceByFee, lockUntilDate, lockUntilBlock }) {
45
+ const filteredUtxos = isSweep ? utxos : this.selectCoins(recipients, utxos, fee);
46
+ const btcUtxos = filteredUtxos.map(utxo => {
47
+ const btcUtxo = Object.assign({}, utxo, {
48
+ amount: utxo.value / 1e8,
49
+ txid: utxo.mintTxid,
50
+ outputIndex: utxo.mintIndex
51
+ });
52
+ return new this.lib.Transaction.UnspentOutput(btcUtxo);
53
+ });
54
+ const tx = new this.lib.Transaction().from(btcUtxos);
55
+ if (fee) {
56
+ tx.fee(fee);
57
+ }
58
+ if (feeRate) {
59
+ tx.feePerByte(Number(feeRate));
60
+ }
61
+ if (change) {
62
+ tx.change(change);
63
+ }
64
+ for (const recipient of recipients) {
65
+ tx.to(recipient.address, parseInt(recipient.amount));
66
+ }
67
+ if (replaceByFee && typeof tx.enableRBF === 'function') {
68
+ tx.enableRBF();
69
+ }
70
+ if (lockUntilBlock > 0) {
71
+ tx.lockUntilBlockHeight(lockUntilBlock);
72
+ } else if (lockUntilDate > 0) {
73
+ tx.lockUntilDate(lockUntilDate);
74
+ }
75
+ return tx.uncheckedSerialize();
76
+ }
77
+
78
+ getSignature() {
79
+ throw new Error('function getSignature not implemented for UTXO coins');
80
+ }
81
+
82
+ transformSignatureObject(params: { obj: any; sigtype?: number }) {
83
+ const { obj, sigtype } = params;
84
+ const { v } = obj;
85
+ let { r, s, i, nhashtype } = obj;
86
+ if (typeof r === 'string') {
87
+ r = Buffer.from(r.startsWith('0x') ? r.slice(2) : r, 'hex');
88
+ } else if (r instanceof Uint8Array || Array.isArray(r)) {
89
+ r = Buffer.from(r);
90
+ } else if (typeof r.toBuffer === 'function') {
91
+ r = r.toBuffer();
92
+ }
93
+ r = this.lib.crypto.BN.fromBuffer(r);
94
+
95
+ if (typeof s === 'string') {
96
+ s = Buffer.from(s.startsWith('0x') ? s.slice(2) : s, 'hex');
97
+ } else if (s instanceof Uint8Array || Array.isArray(s)) {
98
+ s = Buffer.from(s);
99
+ } else if (typeof s.toBuffer === 'function') {
100
+ s = s.toBuffer();
101
+ }
102
+ s = this.lib.crypto.BN.fromBuffer(s);
103
+
104
+ i = parseInt(i) || parseInt(v);
105
+ nhashtype = sigtype ?? nhashtype;
106
+
107
+ return new this.lib.crypto.Signature({ r, s, i, nhashtype }).toString();
108
+ }
109
+
110
+ applySignature(params: { tx: BitcoreLib.Transaction; signature: SignatureType; index: number; sigtype?: number }) {
111
+ const { index, sigtype, tx } = params;
112
+ let { signature } = params;
113
+ assert(tx instanceof this.lib.Transaction, 'tx must be an instance of Transaction');
114
+ assert(signature instanceof this.lib.Transaction.Signature || (signature?.r && signature?.s), 'signature must be a valid signature object');
115
+
116
+ if (signature.r) {
117
+ const nhashtype = sigtype ?? signature.sigtype ?? signature.nhashtype ?? this.lib.crypto.Signature.SIGHASH_ALL;
118
+ signature = new this.lib.Transaction.Signature({
119
+ publicKey: signature.pubKey,
120
+ inputIndex: index,
121
+ outputIndex: tx.inputs[index].outputIndex,
122
+ prevTxId: tx.inputs[index].prevTxId,
123
+ signature: this.transformSignatureObject({ obj: signature, sigtype: nhashtype }),
124
+ sigtype: nhashtype,
125
+ });
126
+ }
127
+ tx.applySignature(signature);
128
+ return tx;
129
+ }
130
+
131
+ getHash(params: { tx: string }) {
132
+ const bitcoreTx = new this.lib.Transaction(params.tx);
133
+ return bitcoreTx.hash;
134
+ }
135
+
136
+ sign(params: { tx: string; keys: Array<Key>; utxos: any[]; pubkeys?: any[]; threshold?: number; opts: any }) {
137
+ const { tx, keys, pubkeys, threshold, opts } = params;
138
+ const utxos = params.utxos || [];
139
+ const bitcoreTx = new this.lib.Transaction(tx);
140
+ const applicableUtxos = this.getRelatedUtxos({
141
+ outputs: bitcoreTx.inputs,
142
+ utxos
143
+ });
144
+ bitcoreTx.associateInputs(applicableUtxos, pubkeys, threshold, opts);
145
+ const uniqePrivKeys = Object.values(keys.reduce((map, key) => {
146
+ // Need to preserve (un)compressed property, so don't use key.privKey.toString();
147
+ const pk = new this.lib.PrivateKey(key.privKey);
148
+ map[pk.publicKey.toString()] = pk;
149
+ return map;
150
+ }, {}));
151
+ const signedTx = bitcoreTx.sign(uniqePrivKeys).toString();
152
+ return signedTx;
153
+ }
154
+
155
+ getRelatedUtxos({ outputs, utxos }) {
156
+ const txids = outputs.map(output => output.toObject().prevTxId);
157
+ const applicableUtxos = utxos.filter(utxo => txids.includes(utxo.txid || utxo.mintTxid));
158
+ return applicableUtxos.map(utxo => {
159
+ const btcUtxo = Object.assign({}, utxo, {
160
+ amount: utxo.value / Math.pow(10, 8),
161
+ txid: utxo.mintTxid,
162
+ outputIndex: utxo.mintIndex
163
+ });
164
+ return new this.lib.Transaction.UnspentOutput(btcUtxo);
165
+ });
166
+ }
167
+
168
+ getOutputsFromTx({ tx }) {
169
+ return tx.outputs.map(({ script, satoshis }) => {
170
+ const address = script;
171
+ return { address, satoshis };
172
+ });
173
+ }
174
+
175
+ getSigningAddresses({ tx, utxos }): string[] {
176
+ const bitcoreTx = new this.lib.Transaction(tx);
177
+ const applicableUtxos = this.getRelatedUtxos({
178
+ outputs: bitcoreTx.inputs,
179
+ utxos
180
+ });
181
+ return applicableUtxos.map(utxo => utxo.address);
182
+ }
183
+
184
+ getSighash(params: {
185
+ tx: string | BitcoreLib.Transaction;
186
+ index: number;
187
+ utxos?: BitcoreLib.Transaction.UnspentOutput[];
188
+ pubKey?: string | BitcoreLib.PublicKey | BitcoreLib.HDPublicKey;
189
+ path?: string;
190
+ sigtype?: number;
191
+ // Multisig params for `associateInputs()`
192
+ /** Multisig public keys */
193
+ pubKeys?: string[] | BitcoreLib.PublicKey[];
194
+ /** Threshold for multisig */
195
+ threshold?: number;
196
+ /** Options for multisig */
197
+ opts?: any;
198
+ // end Multisig params for `associateInputs()`
199
+ }): string {
200
+ const { index, utxos, path, sigtype, pubKeys, threshold, opts } = params;
201
+ let { tx, pubKey } = params;
202
+
203
+ if (!(tx instanceof this.lib.Transaction)) {
204
+ tx = new this.lib.Transaction(tx);
205
+ }
206
+ if (utxos) {
207
+ tx.associateInputs(utxos.map(this.lib.Transaction.UnspentOutput), pubKeys, threshold, opts);
208
+ }
209
+ $.checkState(tx.inputs[index].output instanceof this.lib.Transaction.Output, 'Input must have all utxo info');
210
+
211
+ pubKey = pubKey?.toString();
212
+ if (pubKey) {
213
+ try {
214
+ pubKey = new this.lib.PublicKey(pubKey);
215
+ } catch {
216
+ $.checkArgument(path, '`path` param is required to derive child key');
217
+ pubKey = new this.lib.HDPublicKey(pubKey).deriveChild(path).publicKey;
218
+ }
219
+ }
220
+ // Not all input types require the public key
221
+ $.checkState(!pubKey || pubKey instanceof this.lib.PublicKey, 'Invalid public key');
222
+
223
+ return tx.inputs[index].getSighash(tx, pubKey, index, sigtype).toString('hex');
224
+ }
225
+ }
226
+
227
+ type SignatureType = BitcoreLib.Transaction.Signature | BitcoreLib.crypto.Signature | TssSig;
@@ -0,0 +1,31 @@
1
+ import BitcoreLibDoge from '@bitpay-labs/bitcore-lib-doge';
2
+ import { BTCTxProvider } from '../btc';
3
+
4
+ export class DOGETxProvider extends BTCTxProvider {
5
+ lib = BitcoreLibDoge;
6
+ create({ recipients, utxos = [], change, feeRate, fee = 20000 }) {
7
+ const filteredUtxos = this.selectCoins(recipients, utxos, fee);
8
+ const btcUtxos = filteredUtxos.map(utxo => {
9
+ const btcUtxo = Object.assign({}, utxo, {
10
+ amount: utxo.value / 1e8,
11
+ txid: utxo.mintTxid,
12
+ outputIndex: utxo.mintIndex
13
+ });
14
+ return new this.lib.Transaction.UnspentOutput(btcUtxo);
15
+ });
16
+ const tx = new this.lib.Transaction().from(btcUtxos);
17
+ if (fee) {
18
+ tx.fee(fee);
19
+ }
20
+ if (feeRate) {
21
+ tx.feePerKb(Number(feeRate) * 1000); // feeRate is in feePerByte
22
+ }
23
+ if (change) {
24
+ tx.change(change);
25
+ }
26
+ for (const recipient of recipients) {
27
+ tx.to(recipient.address, parseInt(recipient.amount));
28
+ }
29
+ return tx.uncheckedSerialize();
30
+ }
31
+ }