@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
@@ -0,0 +1,289 @@
1
+ export const UNITS = {
2
+ btc: {
3
+ toSatoshis: 100000000,
4
+ full: {
5
+ maxDecimals: 8,
6
+ minDecimals: 8
7
+ },
8
+ short: {
9
+ maxDecimals: 6,
10
+ minDecimals: 2
11
+ }
12
+ },
13
+ bch: {
14
+ toSatoshis: 100000000,
15
+ full: {
16
+ maxDecimals: 8,
17
+ minDecimals: 8
18
+ },
19
+ short: {
20
+ maxDecimals: 6,
21
+ minDecimals: 2
22
+ }
23
+ },
24
+ sol: {
25
+ toSatoshis: 1e9,
26
+ full: {
27
+ maxDecimals: 9,
28
+ minDecimals: 9
29
+ },
30
+ short: {
31
+ maxDecimals: 6,
32
+ minDecimals: 2
33
+ }
34
+ },
35
+ eth: {
36
+ toSatoshis: 1e18,
37
+ full: {
38
+ maxDecimals: 8,
39
+ minDecimals: 8
40
+ },
41
+ short: {
42
+ maxDecimals: 6,
43
+ minDecimals: 2
44
+ }
45
+ },
46
+ matic: {
47
+ toSatoshis: 1e18,
48
+ full: {
49
+ maxDecimals: 8,
50
+ minDecimals: 8
51
+ },
52
+ short: {
53
+ maxDecimals: 6,
54
+ minDecimals: 2
55
+ }
56
+ },
57
+ arb: {
58
+ toSatoshis: 1e18,
59
+ full: {
60
+ maxDecimals: 8,
61
+ minDecimals: 8
62
+ },
63
+ short: {
64
+ maxDecimals: 6,
65
+ minDecimals: 2
66
+ }
67
+ },
68
+ base: {
69
+ toSatoshis: 1e18,
70
+ full: {
71
+ maxDecimals: 8,
72
+ minDecimals: 8
73
+ },
74
+ short: {
75
+ maxDecimals: 6,
76
+ minDecimals: 2
77
+ }
78
+ },
79
+ op: {
80
+ toSatoshis: 1e18,
81
+ full: {
82
+ maxDecimals: 8,
83
+ minDecimals: 8
84
+ },
85
+ short: {
86
+ maxDecimals: 6,
87
+ minDecimals: 2
88
+ }
89
+ },
90
+ xrp: {
91
+ toSatoshis: 1e6,
92
+ full: {
93
+ maxDecimals: 6,
94
+ minDecimals: 6
95
+ },
96
+ short: {
97
+ maxDecimals: 6,
98
+ minDecimals: 2
99
+ }
100
+ },
101
+ busd: {
102
+ toSatoshis: 1e18,
103
+ full: {
104
+ maxDecimals: 8,
105
+ minDecimals: 8
106
+ },
107
+ short: {
108
+ maxDecimals: 6,
109
+ minDecimals: 2
110
+ }
111
+ },
112
+ dai: {
113
+ toSatoshis: 1e18,
114
+ full: {
115
+ maxDecimals: 8,
116
+ minDecimals: 8
117
+ },
118
+ short: {
119
+ maxDecimals: 6,
120
+ minDecimals: 2
121
+ }
122
+ },
123
+ wbtc: {
124
+ toSatoshis: 1e8,
125
+ full: {
126
+ maxDecimals: 8,
127
+ minDecimals: 8
128
+ },
129
+ short: {
130
+ maxDecimals: 8,
131
+ minDecimals: 2
132
+ }
133
+ },
134
+ usdc: {
135
+ toSatoshis: 1e6,
136
+ full: {
137
+ maxDecimals: 8,
138
+ minDecimals: 8
139
+ },
140
+ short: {
141
+ maxDecimals: 6,
142
+ minDecimals: 2
143
+ }
144
+ },
145
+ pyusd: {
146
+ toSatoshis: 1e6,
147
+ full: {
148
+ maxDecimals: 8,
149
+ minDecimals: 8
150
+ },
151
+ short: {
152
+ maxDecimals: 6,
153
+ minDecimals: 2
154
+ }
155
+ },
156
+ usdp: {
157
+ toSatoshis: 1e18,
158
+ full: {
159
+ maxDecimals: 8,
160
+ minDecimals: 8
161
+ },
162
+ short: {
163
+ maxDecimals: 6,
164
+ minDecimals: 2
165
+ }
166
+ },
167
+ // backwards compatibility
168
+ pax: {
169
+ toSatoshis: 1e18,
170
+ full: {
171
+ maxDecimals: 8,
172
+ minDecimals: 8
173
+ },
174
+ short: {
175
+ maxDecimals: 6,
176
+ minDecimals: 2
177
+ }
178
+ },
179
+ gusd: {
180
+ toSatoshis: 1e2,
181
+ full: {
182
+ maxDecimals: 8,
183
+ minDecimals: 8
184
+ },
185
+ short: {
186
+ maxDecimals: 6,
187
+ minDecimals: 2
188
+ }
189
+ },
190
+ bit: {
191
+ toSatoshis: 100,
192
+ full: {
193
+ maxDecimals: 2,
194
+ minDecimals: 2
195
+ },
196
+ short: {
197
+ maxDecimals: 0,
198
+ minDecimals: 0
199
+ }
200
+ },
201
+ doge: {
202
+ toSatoshis: 100000000,
203
+ full: {
204
+ maxDecimals: 8,
205
+ minDecimals: 8
206
+ },
207
+ short: {
208
+ maxDecimals: 6,
209
+ minDecimals: 2
210
+ }
211
+ },
212
+ ltc: {
213
+ toSatoshis: 100000000,
214
+ full: {
215
+ maxDecimals: 8,
216
+ minDecimals: 8
217
+ },
218
+ short: {
219
+ maxDecimals: 6,
220
+ minDecimals: 2
221
+ }
222
+ },
223
+ shib: {
224
+ toSatoshis: 1e18,
225
+ full: {
226
+ maxDecimals: 8,
227
+ minDecimals: 8
228
+ },
229
+ short: {
230
+ maxDecimals: 6,
231
+ minDecimals: 2
232
+ }
233
+ },
234
+ ape: {
235
+ toSatoshis: 1e18,
236
+ full: {
237
+ maxDecimals: 8,
238
+ minDecimals: 8
239
+ },
240
+ short: {
241
+ maxDecimals: 6,
242
+ minDecimals: 2
243
+ }
244
+ },
245
+ euroc: {
246
+ toSatoshis: 1e6,
247
+ full: {
248
+ maxDecimals: 8,
249
+ minDecimals: 8
250
+ },
251
+ short: {
252
+ maxDecimals: 6,
253
+ minDecimals: 2
254
+ }
255
+ },
256
+ usdt: {
257
+ toSatoshis: 1e6,
258
+ full: {
259
+ maxDecimals: 8,
260
+ minDecimals: 8
261
+ },
262
+ short: {
263
+ maxDecimals: 6,
264
+ minDecimals: 2
265
+ }
266
+ },
267
+ 'usdc.e': {
268
+ toSatoshis: 1e6,
269
+ full: {
270
+ maxDecimals: 8,
271
+ minDecimals: 8
272
+ },
273
+ short: {
274
+ maxDecimals: 6,
275
+ minDecimals: 2
276
+ }
277
+ },
278
+ weth: {
279
+ toSatoshis: 1e18,
280
+ full: {
281
+ maxDecimals: 8,
282
+ minDecimals: 8
283
+ },
284
+ short: {
285
+ maxDecimals: 6,
286
+ minDecimals: 2
287
+ }
288
+ }
289
+ };
@@ -0,0 +1,3 @@
1
+ import { EthDeriver } from '../eth';
2
+
3
+ export class ArbDeriver extends EthDeriver { }
@@ -0,0 +1,3 @@
1
+ import { EthDeriver } from '../eth';
2
+
3
+ export class BaseDeriver extends EthDeriver { }
@@ -0,0 +1,11 @@
1
+ import BitcoreLibCash from '@bitpay-labs/bitcore-lib-cash';
2
+ import { AbstractBitcoreLibDeriver } from '../btc';
3
+
4
+ export class BchDeriver extends AbstractBitcoreLibDeriver {
5
+ bitcoreLib = BitcoreLibCash;
6
+
7
+ getAddress(network: string, pubKey, addressType: string) {
8
+ pubKey = new this.bitcoreLib.PublicKey(pubKey);
9
+ return new this.bitcoreLib.Address(pubKey, network, addressType).toString(true);
10
+ }
11
+ }
@@ -0,0 +1,39 @@
1
+ import BitcoreLib from '@bitpay-labs/bitcore-lib';
2
+ import type { IDeriver } from '../../types/derivation';
3
+
4
+ export abstract class AbstractBitcoreLibDeriver implements IDeriver {
5
+ public abstract bitcoreLib;
6
+
7
+ deriveAddress(network, pubKey, addressIndex, isChange, addressType) {
8
+ const changeNum = isChange ? 1 : 0;
9
+ const path = `m/${changeNum}/${addressIndex}`;
10
+ return this.deriveAddressWithPath(network, pubKey, path, addressType);
11
+ }
12
+
13
+ derivePrivateKey(network, xPriv, addressIndex, isChange, addressType) {
14
+ const changeNum = isChange ? 1 : 0;
15
+ const path = `m/${changeNum}/${addressIndex}`;
16
+ return this.derivePrivateKeyWithPath(network, xPriv, path, addressType);
17
+ }
18
+
19
+ deriveAddressWithPath(network: string, xpubKey: string, path: string, addressType: string) {
20
+ const xpub = new this.bitcoreLib.HDPublicKey(xpubKey, network);
21
+ return this.getAddress(network, xpub.derive(path).publicKey, addressType);
22
+ }
23
+
24
+ derivePrivateKeyWithPath(network: string, xprivKey: string, path: string, addressType: string) {
25
+ const xpriv = new this.bitcoreLib.HDPrivateKey(xprivKey, network);
26
+ const privKey = xpriv.deriveChild(path).privateKey;
27
+ const pubKey = privKey.publicKey;
28
+ const address = this.getAddress(network, pubKey, addressType);
29
+ return { address, privKey: privKey.toString(), pubKey: pubKey.toString(), path };
30
+ }
31
+
32
+ getAddress(network: string, pubKey, addressType: string) {
33
+ pubKey = new this.bitcoreLib.PublicKey(pubKey);
34
+ return new this.bitcoreLib.Address(pubKey, network, addressType).toString();
35
+ }
36
+ }
37
+ export class BtcDeriver extends AbstractBitcoreLibDeriver {
38
+ bitcoreLib = BitcoreLib;
39
+ }
@@ -0,0 +1,6 @@
1
+ import BitcoreLibDoge from '@bitpay-labs/bitcore-lib-doge';
2
+ import { AbstractBitcoreLibDeriver } from '../btc';
3
+
4
+ export class DogeDeriver extends AbstractBitcoreLibDeriver {
5
+ bitcoreLib = BitcoreLibDoge;
6
+ }
@@ -0,0 +1,58 @@
1
+ import BitcoreLib from '@bitpay-labs/bitcore-lib';
2
+ import Web3 from 'web3';
3
+ import type { IDeriver } from '../../types/derivation';
4
+
5
+ export class EthDeriver implements IDeriver {
6
+ padTo32(msg) {
7
+ while (msg.length < 32) {
8
+ msg = Buffer.concat([Buffer.from([0]), msg]);
9
+ }
10
+ if (msg.length !== 32) {
11
+ throw new Error(`invalid key length: ${msg.length}`);
12
+ }
13
+ return msg;
14
+ }
15
+
16
+ deriveAddress(network, xpubkey, addressIndex, isChange) {
17
+ const changeNum = isChange ? 1 : 0;
18
+ const path = `m/${changeNum}/${addressIndex}`;
19
+ return this.deriveAddressWithPath(network, xpubkey, path);
20
+ }
21
+
22
+ addressFromPublicKeyBuffer(pubKey: Buffer): string {
23
+ const ecPoint = new BitcoreLib.PublicKey.fromBuffer(pubKey).point;
24
+ const x = ecPoint.getX().toBuffer({ size: 32 });
25
+ const y = ecPoint.getY().toBuffer({ size: 32 });
26
+ const paddedBuffer = Buffer.concat([x, y]);
27
+ const address = Web3.utils.keccak256(`0x${paddedBuffer.toString('hex')}`).slice(26);
28
+ return Web3.utils.toChecksumAddress(address);
29
+ }
30
+
31
+ derivePrivateKey(network, xPriv, addressIndex, isChange) {
32
+ const changeNum = isChange ? 1 : 0;
33
+ const path = `m/${changeNum}/${addressIndex}`;
34
+ return this.derivePrivateKeyWithPath(network, xPriv, path);
35
+ }
36
+
37
+ deriveAddressWithPath(network: string, xpubKey: string, path: string) {
38
+ const xpub = new BitcoreLib.HDPublicKey(xpubKey, network);
39
+ const derived = xpub.derive(path).publicKey;
40
+ return this.addressFromPublicKeyBuffer(derived.toBuffer());
41
+ }
42
+
43
+ derivePrivateKeyWithPath(network: string, xprivKey: string, path: string) {
44
+ const xpriv = new BitcoreLib.HDPrivateKey(xprivKey, network);
45
+ const derivedPrivKey = xpriv.derive(path);
46
+ const privKey = derivedPrivKey.privateKey.toString('hex');
47
+ const pubKeyObj = derivedPrivKey.publicKey;
48
+ const pubKey = pubKeyObj.toString('hex');
49
+ const pubKeyBuffer = pubKeyObj.toBuffer();
50
+ const address = this.addressFromPublicKeyBuffer(pubKeyBuffer);
51
+ return { address, privKey, pubKey, path };
52
+ }
53
+
54
+ getAddress(network: string, pubKey) {
55
+ pubKey = new BitcoreLib.PublicKey(pubKey, network); // network not needed here since ETH doesn't differentiate addresses by network.
56
+ return this.addressFromPublicKeyBuffer(pubKey.toBuffer());
57
+ }
58
+ }
@@ -0,0 +1,124 @@
1
+ import { ArbDeriver } from './arb';
2
+ import { BaseDeriver } from './base';
3
+ import { BchDeriver } from './bch';
4
+ import { BtcDeriver } from './btc';
5
+ import { DogeDeriver } from './doge';
6
+ import { EthDeriver } from './eth';
7
+ import { LtcDeriver } from './ltc';
8
+ import { MaticDeriver } from './matic';
9
+ import { OpDeriver } from './op';
10
+ import { Paths } from './paths';
11
+ import { SolDeriver } from './sol';
12
+ import { XrpDeriver } from './xrp';
13
+ import type { IDeriver } from '../types/derivation';
14
+
15
+ const derivers: { [chain: string]: IDeriver } = {
16
+ BTC: new BtcDeriver(),
17
+ BCH: new BchDeriver(),
18
+ ETH: new EthDeriver(),
19
+ XRP: new XrpDeriver(),
20
+ DOGE: new DogeDeriver(),
21
+ LTC: new LtcDeriver(),
22
+ MATIC: new MaticDeriver(),
23
+ ARB: new ArbDeriver(),
24
+ BASE: new BaseDeriver(),
25
+ OP: new OpDeriver(),
26
+ SOL: new SolDeriver()
27
+ };
28
+
29
+ export class DeriverProxy {
30
+ private get(chain) {
31
+ const normalizedChain = chain.toUpperCase();
32
+ return derivers[normalizedChain];
33
+ }
34
+
35
+ /**
36
+ * This is derives addresses using the conventional paths.
37
+ * @param chain
38
+ * @param network
39
+ * @param xpubKey
40
+ * @param addressIndex
41
+ * @param isChange
42
+ * @param addressType
43
+ * @returns
44
+ */
45
+ deriveAddress(chain, network, xpubKey, addressIndex, isChange, addressType?) {
46
+ return this.get(chain).deriveAddress(network, xpubKey, addressIndex, isChange, addressType);
47
+ }
48
+
49
+ /**
50
+ * This derives keys/addresses using the conventional paths.
51
+ * @param chain
52
+ * @param network
53
+ * @param privKey
54
+ * @param addressIndex
55
+ * @param isChange
56
+ * @param addressType
57
+ * @returns
58
+ */
59
+ derivePrivateKey(chain, network, privKey, addressIndex, isChange, addressType?) {
60
+ return this.get(chain).derivePrivateKey(network, privKey, addressIndex, isChange, addressType);
61
+ }
62
+
63
+ /**
64
+ * This derives addresses on a specific path.
65
+ * This should probably only be used when importing from another wallet
66
+ * where known paths are provided with their keys. Most of the BitPay
67
+ * codebase uses `deriveAddress()`
68
+ * @param chain
69
+ * @param network
70
+ * @param xpubKey
71
+ * @param path
72
+ * @param addressType
73
+ * @returns
74
+ */
75
+ deriveAddressWithPath(chain, network, xpubKey, path, addressType) {
76
+ return this.get(chain).deriveAddressWithPath(network, xpubKey, path, addressType);
77
+ }
78
+
79
+ /**
80
+ * This derives keys/addresses on a specific path.
81
+ * This should probably only be used when importing from another wallet
82
+ * where known paths are provided with their keys. Most of the BitPay
83
+ * codebase uses `derivePrivateKey()`
84
+ * @param chain
85
+ * @param network
86
+ * @param xprivKey
87
+ * @param path
88
+ * @param addressType
89
+ * @returns
90
+ */
91
+ derivePrivateKeyWithPath(chain, network, xprivKey, path, addressType) {
92
+ return this.get(chain).derivePrivateKeyWithPath(network, xprivKey, path, addressType);
93
+ }
94
+
95
+ /**
96
+ * This is a simple function for getting an address from a
97
+ * given pub key and chain. There is no derivation happening.
98
+ * @param chain
99
+ * @param network
100
+ * @param pubKey
101
+ * @param addressType
102
+ * @returns
103
+ */
104
+ getAddress(chain, network, pubKey, addressType?) {
105
+ return this.get(chain).getAddress(network, pubKey, addressType);
106
+ }
107
+
108
+ pathFor(chain, network, account = 0) {
109
+ const normalizedChain = chain.toUpperCase();
110
+ const accountStr = `${account}'`;
111
+ const chainConfig = Paths[normalizedChain];
112
+ if (chainConfig) {
113
+ if (chainConfig[network]) {
114
+ return chainConfig[network] + accountStr;
115
+ } else {
116
+ return chainConfig.default + accountStr;
117
+ }
118
+ } else {
119
+ return Paths.BTC.default + accountStr;
120
+ }
121
+ }
122
+ }
123
+
124
+ export default new DeriverProxy();
@@ -0,0 +1,6 @@
1
+ import BitcoreLibLtc from '@bitpay-labs/bitcore-lib-ltc';
2
+ import { AbstractBitcoreLibDeriver } from '../btc';
3
+
4
+ export class LtcDeriver extends AbstractBitcoreLibDeriver {
5
+ bitcoreLib = BitcoreLibLtc;
6
+ }
@@ -0,0 +1,3 @@
1
+ import { EthDeriver } from '../eth';
2
+
3
+ export class MaticDeriver extends EthDeriver { }
@@ -0,0 +1,3 @@
1
+ import { EthDeriver } from '../eth';
2
+
3
+ export class OpDeriver extends EthDeriver { }
@@ -0,0 +1,42 @@
1
+ export const Paths = {
2
+ BTC: {
3
+ mainnet: "m/44'/0'/",
4
+ livenet: "m/44'/0'/",
5
+ default: "m/44'/1'/"
6
+ },
7
+ BCH: {
8
+ mainnet: "m/44'/145'/",
9
+ livenet: "m/44'/145'/",
10
+ default: "m/44'/1'/"
11
+ },
12
+ ETH: {
13
+ default: "m/44'/60'/"
14
+ },
15
+ XRP: {
16
+ default: "m/44'/144'/"
17
+ },
18
+ DOGE: {
19
+ default: "m/44'/3'/"
20
+ },
21
+ LTC: {
22
+ default: "m/44'/2'/"
23
+ },
24
+ MATIC: {
25
+ default: "m/44'/60'/", // the official matic derivation path is 966 but users will expect address to be same as ETH
26
+ },
27
+ ARB: {
28
+ default: "m/44'/60'/",
29
+ },
30
+ OP: {
31
+ default: "m/44'/60'/",
32
+ },
33
+ BASE: {
34
+ default: "m/44'/60'/",
35
+ },
36
+ SOL: {
37
+ default: "m/44'/501'/",
38
+ },
39
+ default: {
40
+ testnet: "m/44'/1'/"
41
+ }
42
+ };
@@ -0,0 +1,57 @@
1
+ import { HDPrivateKey, encoding } from '@bitpay-labs/bitcore-lib';
2
+ import * as ed25519 from 'ed25519-hd-key';
3
+ import { Paths } from '../paths';
4
+ import type { IDeriver, Key } from '../../types/derivation';
5
+
6
+ export class SolDeriver implements IDeriver {
7
+ deriveAddress(_network, _xpubkey, _addressIndex, _isChange): string {
8
+ throw new Error('Cannot derive Solana addresses from just xpubkey, need to use derivePrivateKeyWithPath');
9
+ }
10
+
11
+ deriveAddressWithPath(_network: string, _xpubKey: string, _path: string): string {
12
+ throw new Error('Cannot derive Solana addresses from just xpubkey, need to use derivePrivateKeyWithPath');
13
+ }
14
+
15
+ getAddress(_network: string, pubKey: string) {
16
+ return this.addressFromPublicKeyBuffer(Buffer.from(pubKey, 'hex'));
17
+ }
18
+
19
+ addressFromPublicKeyBuffer(pubKey: Buffer): string {
20
+ if (pubKey.length > 32) {
21
+ pubKey = pubKey.subarray(pubKey.length - 32);
22
+ }
23
+ return encoding.Base58.encode(pubKey);
24
+ }
25
+
26
+ derivePrivateKey(network, xPriv, addressIndex, isChange, addressType) {
27
+ const changeNum = isChange ? 1 : 0;
28
+ const path = `${Paths['SOL'].default}${addressIndex}'/${changeNum}'`;
29
+ return this.derivePrivateKeyWithPath(network, xPriv, path, addressType);
30
+ };
31
+
32
+ deriveChild(masterKey: { key: Buffer; chainCode: Buffer }, path: string) {
33
+ const HARDENED_OFFSET = 0x80000000;
34
+ const segmented = path
35
+ .split('/')
36
+ .slice(1)
37
+ .map((val) => val.replace("'", ''))
38
+ .map(el => parseInt(el, 10));
39
+ return segmented.reduce((parentKeys, segment) => ed25519.CKDPriv(parentKeys, segment + HARDENED_OFFSET), masterKey);
40
+ }
41
+
42
+ derivePrivateKeyWithPath(network: string, xprivKey: string, path: string, _addressType: string) {
43
+ const xpriv = new HDPrivateKey(xprivKey, network);
44
+ const child = this.deriveChild({ key: xpriv._buffers.privateKey, chainCode: xpriv._buffers.chainCode }, path);
45
+ const pubKey = ed25519.getPublicKey(child.key, false);
46
+ const address = encoding.Base58.encode(pubKey);
47
+ // Solana wallets often represent the private key as a KeyPair consisting of the private key + address/public key.
48
+ // The Keypair is usually found in two formats: Base58 or Uint8Array.
49
+ // Here, we represent the keys separately in Base58, which is fine since a keypair can be built or converted by createKeyPairFromPrivateKeyBytes.
50
+ // Public Key is synonymous with Address. Here they are reprsented in two different formats.
51
+ return {
52
+ address,
53
+ privKey: encoding.Base58.encode(child.key),
54
+ pubKey: Buffer.from(pubKey).toString('hex')
55
+ } as Key;
56
+ };
57
+ }
@@ -0,0 +1,38 @@
1
+ import BitcoreLib from '@bitpay-labs/bitcore-lib';
2
+ import { deriveAddress } from 'xrpl';
3
+ import type { IDeriver } from '../../types/derivation';
4
+
5
+ export class XrpDeriver implements IDeriver {
6
+ deriveAddress(network, xpubkey, addressIndex, isChange) {
7
+ const changeNum = isChange ? 1 : 0;
8
+ const path = `m/${changeNum}/${addressIndex}`;
9
+ return this.deriveAddressWithPath(network, xpubkey, path);
10
+ }
11
+
12
+ derivePrivateKey(network, xPriv, addressIndex, isChange) {
13
+ const changeNum = isChange ? 1 : 0;
14
+ const path = `m/${changeNum}/${addressIndex}`;
15
+ return this.derivePrivateKeyWithPath(network, xPriv, path);
16
+ }
17
+
18
+ deriveAddressWithPath(network: string, xpubKey: string, path: string) {
19
+ const xpub = new BitcoreLib.HDPublicKey(xpubKey, network);
20
+ const pubKey = xpub.derive(path).toObject().publicKey;
21
+ const address = deriveAddress(pubKey);
22
+ return address;
23
+ }
24
+
25
+ derivePrivateKeyWithPath(network: string, xprivKey: string, path: string) {
26
+ const xpriv = new BitcoreLib.HDPrivateKey(xprivKey, network);
27
+ const derivedXPriv = xpriv.derive(path);
28
+ const privKey = derivedXPriv.toObject().privateKey.toUpperCase();
29
+ const pubKey = derivedXPriv.hdPublicKey.toObject().publicKey.toUpperCase();
30
+ const address = deriveAddress(pubKey);
31
+ return { address, privKey, pubKey, path };
32
+ }
33
+
34
+ getAddress(network: string, pubKey: string) {
35
+ const address = deriveAddress(pubKey);
36
+ return address;
37
+ }
38
+ }