@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.
- package/README.md +13 -0
- package/package.json +58 -0
- package/src/constants/address.ts +7 -0
- package/src/constants/algorithms.ts +9 -0
- package/src/constants/chains.ts +64 -0
- package/src/constants/feeMinimums.ts +20 -0
- package/src/constants/index.ts +37 -0
- package/src/constants/tokens.ts +224 -0
- package/src/constants/units.ts +289 -0
- package/src/derivation/arb/index.ts +3 -0
- package/src/derivation/base/index.ts +3 -0
- package/src/derivation/bch/index.ts +11 -0
- package/src/derivation/btc/index.ts +39 -0
- package/src/derivation/doge/index.ts +6 -0
- package/src/derivation/eth/index.ts +58 -0
- package/src/derivation/index.ts +124 -0
- package/src/derivation/ltc/index.ts +6 -0
- package/src/derivation/matic/index.ts +3 -0
- package/src/derivation/op/index.ts +3 -0
- package/src/derivation/paths.ts +42 -0
- package/src/derivation/sol/index.ts +57 -0
- package/src/derivation/xrp/index.ts +38 -0
- package/src/index.ts +48 -0
- package/src/message/btc.ts +28 -0
- package/src/message/eth.ts +47 -0
- package/src/message/index.ts +70 -0
- package/src/message/sol.ts +3 -0
- package/src/message/xrp.ts +4 -0
- package/src/transactions/arb/index.ts +14 -0
- package/src/transactions/base/index.ts +13 -0
- package/src/transactions/bch/index.ts +25 -0
- package/src/transactions/btc/index.ts +227 -0
- package/src/transactions/doge/index.ts +31 -0
- package/src/transactions/erc20/abi.ts +418 -0
- package/src/transactions/erc20/index.ts +57 -0
- package/src/transactions/eth/index.ts +183 -0
- package/src/transactions/eth-multisig/abi.ts +724 -0
- package/src/transactions/eth-multisig/index.ts +172 -0
- package/src/transactions/index.ts +83 -0
- package/src/transactions/ltc/index.ts +31 -0
- package/src/transactions/matic/index.ts +14 -0
- package/src/transactions/matic-multisig/index.ts +172 -0
- package/src/transactions/op/index.ts +14 -0
- package/src/transactions/sol/index.ts +292 -0
- package/src/transactions/spl/index.ts +192 -0
- package/src/transactions/xrp/index.ts +129 -0
- package/src/types/derivation.ts +17 -0
- package/src/types/index.ts +3 -0
- package/src/types/message.ts +15 -0
- package/src/types/utils.ts +1 -0
- package/src/types/validation.ts +4 -0
- package/src/utils/bigint.ts +238 -0
- package/src/utils/index.ts +94 -0
- package/src/validation/arb/index.ts +8 -0
- package/src/validation/base/index.ts +8 -0
- package/src/validation/bch/index.ts +17 -0
- package/src/validation/btc/index.ts +17 -0
- package/src/validation/doge/index.ts +16 -0
- package/src/validation/eth/index.ts +29 -0
- package/src/validation/index.ts +43 -0
- package/src/validation/ltc/index.ts +16 -0
- package/src/validation/matic/index.ts +8 -0
- package/src/validation/op/index.ts +8 -0
- package/src/validation/sol/index.ts +34 -0
- package/src/validation/xrp/index.ts +50 -0
- package/test/address.test.ts +178 -0
- package/test/bigint.test.ts +373 -0
- package/test/transactions.test.ts +1777 -0
- package/test/utils.test.ts +121 -0
- package/test/validation.test.ts +261 -0
- package/ts_build/src/constants/address.d.ts +8 -0
- package/ts_build/src/constants/address.d.ts.map +1 -0
- package/ts_build/src/constants/address.js +11 -0
- package/ts_build/src/constants/address.js.map +1 -0
- package/ts_build/src/constants/algorithms.d.ts +9 -0
- package/ts_build/src/constants/algorithms.d.ts.map +1 -0
- package/ts_build/src/constants/algorithms.js +12 -0
- package/ts_build/src/constants/algorithms.js.map +1 -0
- package/ts_build/src/constants/chains.d.ts +42 -0
- package/ts_build/src/constants/chains.d.ts.map +1 -0
- package/ts_build/src/constants/chains.js +54 -0
- package/ts_build/src/constants/chains.js.map +1 -0
- package/ts_build/src/constants/feeMinimums.d.ts +21 -0
- package/ts_build/src/constants/feeMinimums.d.ts.map +1 -0
- package/ts_build/src/constants/feeMinimums.js +24 -0
- package/ts_build/src/constants/feeMinimums.js.map +1 -0
- package/ts_build/src/constants/index.d.ts +569 -0
- package/ts_build/src/constants/index.d.ts.map +1 -0
- package/ts_build/src/constants/index.js +31 -0
- package/ts_build/src/constants/index.js.map +1 -0
- package/ts_build/src/constants/tokens.d.ts +423 -0
- package/ts_build/src/constants/tokens.d.ts.map +1 -0
- package/ts_build/src/constants/tokens.js +222 -0
- package/ts_build/src/constants/tokens.js.map +1 -0
- package/ts_build/src/constants/units.d.ts +289 -0
- package/ts_build/src/constants/units.d.ts.map +1 -0
- package/ts_build/src/constants/units.js +292 -0
- package/ts_build/src/constants/units.js.map +1 -0
- package/ts_build/src/derivation/arb/index.d.ts +4 -0
- package/ts_build/src/derivation/arb/index.d.ts.map +1 -0
- package/ts_build/src/derivation/arb/index.js +8 -0
- package/ts_build/src/derivation/arb/index.js.map +1 -0
- package/ts_build/src/derivation/base/index.d.ts +4 -0
- package/ts_build/src/derivation/base/index.d.ts.map +1 -0
- package/ts_build/src/derivation/base/index.js +8 -0
- package/ts_build/src/derivation/base/index.js.map +1 -0
- package/ts_build/src/derivation/bch/index.d.ts +6 -0
- package/ts_build/src/derivation/bch/index.d.ts.map +1 -0
- package/ts_build/src/derivation/bch/index.js +17 -0
- package/ts_build/src/derivation/bch/index.js.map +1 -0
- package/ts_build/src/derivation/btc/index.d.ts +23 -0
- package/ts_build/src/derivation/btc/index.d.ts.map +1 -0
- package/ts_build/src/derivation/btc/index.js +40 -0
- package/ts_build/src/derivation/btc/index.js.map +1 -0
- package/ts_build/src/derivation/doge/index.d.ts +5 -0
- package/ts_build/src/derivation/doge/index.d.ts.map +1 -0
- package/ts_build/src/derivation/doge/index.js +13 -0
- package/ts_build/src/derivation/doge/index.js.map +1 -0
- package/ts_build/src/derivation/eth/index.d.ts +21 -0
- package/ts_build/src/derivation/eth/index.d.ts.map +1 -0
- package/ts_build/src/derivation/eth/index.js +58 -0
- package/ts_build/src/derivation/eth/index.js.map +1 -0
- package/ts_build/src/derivation/index.d.ts +12 -0
- package/ts_build/src/derivation/index.d.ts.map +1 -0
- package/ts_build/src/derivation/index.js +68 -0
- package/ts_build/src/derivation/index.js.map +1 -0
- package/ts_build/src/derivation/ltc/index.d.ts +5 -0
- package/ts_build/src/derivation/ltc/index.d.ts.map +1 -0
- package/ts_build/src/derivation/ltc/index.js +13 -0
- package/ts_build/src/derivation/ltc/index.js.map +1 -0
- package/ts_build/src/derivation/matic/index.d.ts +4 -0
- package/ts_build/src/derivation/matic/index.d.ts.map +1 -0
- package/ts_build/src/derivation/matic/index.js +8 -0
- package/ts_build/src/derivation/matic/index.js.map +1 -0
- package/ts_build/src/derivation/op/index.d.ts +4 -0
- package/ts_build/src/derivation/op/index.d.ts.map +1 -0
- package/ts_build/src/derivation/op/index.js +8 -0
- package/ts_build/src/derivation/op/index.js.map +1 -0
- package/ts_build/src/derivation/paths.d.ts +43 -0
- package/ts_build/src/derivation/paths.d.ts.map +1 -0
- package/ts_build/src/derivation/paths.js +46 -0
- package/ts_build/src/derivation/paths.js.map +1 -0
- package/ts_build/src/derivation/sol/index.d.ts +17 -0
- package/ts_build/src/derivation/sol/index.d.ts.map +1 -0
- package/ts_build/src/derivation/sol/index.js +85 -0
- package/ts_build/src/derivation/sol/index.js.map +1 -0
- package/ts_build/src/derivation/xrp/index.d.ts +19 -0
- package/ts_build/src/derivation/xrp/index.d.ts.map +1 -0
- package/ts_build/src/derivation/xrp/index.js +40 -0
- package/ts_build/src/derivation/xrp/index.js.map +1 -0
- package/ts_build/src/index.d.ts +30 -0
- package/ts_build/src/index.d.ts.map +1 -0
- package/ts_build/src/index.js +81 -0
- package/ts_build/src/index.js.map +1 -0
- package/ts_build/src/message/btc.d.ts +19 -0
- package/ts_build/src/message/btc.d.ts.map +1 -0
- package/ts_build/src/message/btc.js +32 -0
- package/ts_build/src/message/btc.js.map +1 -0
- package/ts_build/src/message/eth.d.ts +19 -0
- package/ts_build/src/message/eth.d.ts.map +1 -0
- package/ts_build/src/message/eth.js +39 -0
- package/ts_build/src/message/eth.js.map +1 -0
- package/ts_build/src/message/index.d.ts +25 -0
- package/ts_build/src/message/index.d.ts.map +1 -0
- package/ts_build/src/message/index.js +50 -0
- package/ts_build/src/message/index.js.map +1 -0
- package/ts_build/src/message/sol.d.ts +4 -0
- package/ts_build/src/message/sol.d.ts.map +1 -0
- package/ts_build/src/message/sol.js +9 -0
- package/ts_build/src/message/sol.js.map +1 -0
- package/ts_build/src/message/xrp.d.ts +4 -0
- package/ts_build/src/message/xrp.d.ts.map +1 -0
- package/ts_build/src/message/xrp.js +9 -0
- package/ts_build/src/message/xrp.js.map +1 -0
- package/ts_build/src/transactions/arb/index.d.ts +9 -0
- package/ts_build/src/transactions/arb/index.d.ts.map +1 -0
- package/ts_build/src/transactions/arb/index.js +18 -0
- package/ts_build/src/transactions/arb/index.js.map +1 -0
- package/ts_build/src/transactions/base/index.d.ts +8 -0
- package/ts_build/src/transactions/base/index.d.ts.map +1 -0
- package/ts_build/src/transactions/base/index.js +17 -0
- package/ts_build/src/transactions/base/index.js.map +1 -0
- package/ts_build/src/transactions/bch/index.d.ts +12 -0
- package/ts_build/src/transactions/bch/index.d.ts.map +1 -0
- package/ts_build/src/transactions/bch/index.js +32 -0
- package/ts_build/src/transactions/bch/index.js.map +1 -0
- package/ts_build/src/transactions/btc/index.d.ts +84 -0
- package/ts_build/src/transactions/btc/index.d.ts.map +1 -0
- package/ts_build/src/transactions/btc/index.js +184 -0
- package/ts_build/src/transactions/btc/index.js.map +1 -0
- package/ts_build/src/transactions/doge/index.d.ts +12 -0
- package/ts_build/src/transactions/doge/index.d.ts.map +1 -0
- package/ts_build/src/transactions/doge/index.js +38 -0
- package/ts_build/src/transactions/doge/index.js.map +1 -0
- package/ts_build/src/transactions/erc20/abi.d.ts +78 -0
- package/ts_build/src/transactions/erc20/abi.d.ts.map +1 -0
- package/ts_build/src/transactions/erc20/abi.js +421 -0
- package/ts_build/src/transactions/erc20/abi.js.map +1 -0
- package/ts_build/src/transactions/erc20/index.d.ts +29 -0
- package/ts_build/src/transactions/erc20/index.d.ts.map +1 -0
- package/ts_build/src/transactions/erc20/index.js +46 -0
- package/ts_build/src/transactions/erc20/index.js.map +1 -0
- package/ts_build/src/transactions/eth/index.d.ts +53 -0
- package/ts_build/src/transactions/eth/index.d.ts.map +1 -0
- package/ts_build/src/transactions/eth/index.js +156 -0
- package/ts_build/src/transactions/eth/index.js.map +1 -0
- package/ts_build/src/transactions/eth-multisig/abi.d.ts +51 -0
- package/ts_build/src/transactions/eth-multisig/abi.d.ts.map +1 -0
- package/ts_build/src/transactions/eth-multisig/abi.js +728 -0
- package/ts_build/src/transactions/eth-multisig/abi.js.map +1 -0
- package/ts_build/src/transactions/eth-multisig/index.d.ts +65 -0
- package/ts_build/src/transactions/eth-multisig/index.d.ts.map +1 -0
- package/ts_build/src/transactions/eth-multisig/index.js +143 -0
- package/ts_build/src/transactions/eth-multisig/index.js.map +1 -0
- package/ts_build/src/transactions/index.d.ts +15 -0
- package/ts_build/src/transactions/index.d.ts.map +1 -0
- package/ts_build/src/transactions/index.js +69 -0
- package/ts_build/src/transactions/index.js.map +1 -0
- package/ts_build/src/transactions/ltc/index.d.ts +12 -0
- package/ts_build/src/transactions/ltc/index.d.ts.map +1 -0
- package/ts_build/src/transactions/ltc/index.js +38 -0
- package/ts_build/src/transactions/ltc/index.js.map +1 -0
- package/ts_build/src/transactions/matic/index.d.ts +9 -0
- package/ts_build/src/transactions/matic/index.d.ts.map +1 -0
- package/ts_build/src/transactions/matic/index.js +18 -0
- package/ts_build/src/transactions/matic/index.js.map +1 -0
- package/ts_build/src/transactions/matic-multisig/index.d.ts +65 -0
- package/ts_build/src/transactions/matic-multisig/index.d.ts.map +1 -0
- package/ts_build/src/transactions/matic-multisig/index.js +143 -0
- package/ts_build/src/transactions/matic-multisig/index.js.map +1 -0
- package/ts_build/src/transactions/op/index.d.ts +9 -0
- package/ts_build/src/transactions/op/index.d.ts.map +1 -0
- package/ts_build/src/transactions/op/index.js +18 -0
- package/ts_build/src/transactions/op/index.js.map +1 -0
- package/ts_build/src/transactions/sol/index.d.ts +56 -0
- package/ts_build/src/transactions/sol/index.d.ts.map +1 -0
- package/ts_build/src/transactions/sol/index.js +261 -0
- package/ts_build/src/transactions/sol/index.js.map +1 -0
- package/ts_build/src/transactions/spl/index.d.ts +57 -0
- package/ts_build/src/transactions/spl/index.d.ts.map +1 -0
- package/ts_build/src/transactions/spl/index.js +129 -0
- package/ts_build/src/transactions/spl/index.js.map +1 -0
- package/ts_build/src/transactions/xrp/index.d.ts +50 -0
- package/ts_build/src/transactions/xrp/index.d.ts.map +1 -0
- package/ts_build/src/transactions/xrp/index.js +146 -0
- package/ts_build/src/transactions/xrp/index.js.map +1 -0
- package/ts_build/src/types/derivation.d.ts +13 -0
- package/ts_build/src/types/derivation.d.ts.map +1 -0
- package/ts_build/src/types/derivation.js +3 -0
- package/ts_build/src/types/derivation.js.map +1 -0
- package/ts_build/src/types/index.d.ts +4 -0
- package/ts_build/src/types/index.d.ts.map +1 -0
- package/ts_build/src/types/index.js +40 -0
- package/ts_build/src/types/index.js.map +1 -0
- package/ts_build/src/types/message.d.ts +26 -0
- package/ts_build/src/types/message.d.ts.map +1 -0
- package/ts_build/src/types/message.js +3 -0
- package/ts_build/src/types/message.js.map +1 -0
- package/ts_build/src/types/utils.d.ts +2 -0
- package/ts_build/src/types/utils.d.ts.map +1 -0
- package/ts_build/src/types/utils.js +3 -0
- package/ts_build/src/types/utils.js.map +1 -0
- package/ts_build/src/types/validation.d.ts +5 -0
- package/ts_build/src/types/validation.d.ts.map +1 -0
- package/ts_build/src/types/validation.js +3 -0
- package/ts_build/src/types/validation.js.map +1 -0
- package/ts_build/src/utils/bigint.d.ts +14 -0
- package/ts_build/src/utils/bigint.d.ts.map +1 -0
- package/ts_build/src/utils/bigint.js +165 -0
- package/ts_build/src/utils/bigint.js.map +1 -0
- package/ts_build/src/utils/index.d.ts +12 -0
- package/ts_build/src/utils/index.d.ts.map +1 -0
- package/ts_build/src/utils/index.js +118 -0
- package/ts_build/src/utils/index.js.map +1 -0
- package/ts_build/src/validation/arb/index.d.ts +5 -0
- package/ts_build/src/validation/arb/index.d.ts.map +1 -0
- package/ts_build/src/validation/arb/index.js +12 -0
- package/ts_build/src/validation/arb/index.js.map +1 -0
- package/ts_build/src/validation/base/index.d.ts +5 -0
- package/ts_build/src/validation/base/index.d.ts.map +1 -0
- package/ts_build/src/validation/base/index.js +12 -0
- package/ts_build/src/validation/base/index.js.map +1 -0
- package/ts_build/src/validation/bch/index.d.ts +6 -0
- package/ts_build/src/validation/bch/index.d.ts.map +1 -0
- package/ts_build/src/validation/bch/index.js +19 -0
- package/ts_build/src/validation/bch/index.js.map +1 -0
- package/ts_build/src/validation/btc/index.d.ts +6 -0
- package/ts_build/src/validation/btc/index.d.ts.map +1 -0
- package/ts_build/src/validation/btc/index.js +19 -0
- package/ts_build/src/validation/btc/index.js.map +1 -0
- package/ts_build/src/validation/doge/index.d.ts +6 -0
- package/ts_build/src/validation/doge/index.d.ts.map +1 -0
- package/ts_build/src/validation/doge/index.js +19 -0
- package/ts_build/src/validation/doge/index.js.map +1 -0
- package/ts_build/src/validation/eth/index.d.ts +9 -0
- package/ts_build/src/validation/eth/index.d.ts.map +1 -0
- package/ts_build/src/validation/eth/index.js +28 -0
- package/ts_build/src/validation/eth/index.js.map +1 -0
- package/ts_build/src/validation/index.d.ts +9 -0
- package/ts_build/src/validation/index.d.ts.map +1 -0
- package/ts_build/src/validation/index.js +42 -0
- package/ts_build/src/validation/index.js.map +1 -0
- package/ts_build/src/validation/ltc/index.d.ts +6 -0
- package/ts_build/src/validation/ltc/index.d.ts.map +1 -0
- package/ts_build/src/validation/ltc/index.js +19 -0
- package/ts_build/src/validation/ltc/index.js.map +1 -0
- package/ts_build/src/validation/matic/index.d.ts +5 -0
- package/ts_build/src/validation/matic/index.d.ts.map +1 -0
- package/ts_build/src/validation/matic/index.js +12 -0
- package/ts_build/src/validation/matic/index.js.map +1 -0
- package/ts_build/src/validation/op/index.d.ts +5 -0
- package/ts_build/src/validation/op/index.d.ts.map +1 -0
- package/ts_build/src/validation/op/index.js +12 -0
- package/ts_build/src/validation/op/index.js.map +1 -0
- package/ts_build/src/validation/sol/index.d.ts +9 -0
- package/ts_build/src/validation/sol/index.d.ts.map +1 -0
- package/ts_build/src/validation/sol/index.js +34 -0
- package/ts_build/src/validation/sol/index.js.map +1 -0
- package/ts_build/src/validation/xrp/index.d.ts +7 -0
- package/ts_build/src/validation/xrp/index.d.ts.map +1 -0
- package/ts_build/src/validation/xrp/index.js +50 -0
- package/ts_build/src/validation/xrp/index.js.map +1 -0
- package/ts_build/test/address.test.d.ts +2 -0
- package/ts_build/test/address.test.d.ts.map +1 -0
- package/ts_build/test/address.test.js +139 -0
- package/ts_build/test/address.test.js.map +1 -0
- package/ts_build/test/bigint.test.d.ts +2 -0
- package/ts_build/test/bigint.test.d.ts.map +1 -0
- package/ts_build/test/bigint.test.js +298 -0
- package/ts_build/test/bigint.test.js.map +1 -0
- package/ts_build/test/transactions.test.d.ts +2 -0
- package/ts_build/test/transactions.test.d.ts.map +1 -0
- package/ts_build/test/transactions.test.js +1549 -0
- package/ts_build/test/transactions.test.js.map +1 -0
- package/ts_build/test/utils.test.d.ts +2 -0
- package/ts_build/test/utils.test.d.ts.map +1 -0
- package/ts_build/test/utils.test.js +137 -0
- package/ts_build/test/utils.test.js.map +1 -0
- package/ts_build/test/validation.test.d.ts +2 -0
- package/ts_build/test/validation.test.d.ts.map +1 -0
- package/ts_build/test/validation.test.js +210 -0
- package/ts_build/test/validation.test.js.map +1 -0
- 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,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,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,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
|
+
}
|