@bitpay-labs/crypto-wallet-core 11.11.4 → 11.11.6

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 (91) hide show
  1. package/package.json +9 -3
  2. package/ts_build/src/constants/index.d.ts +18 -1
  3. package/ts_build/src/constants/index.d.ts.map +1 -1
  4. package/ts_build/src/constants/tokens.d.ts +14 -2
  5. package/ts_build/src/constants/tokens.d.ts.map +1 -1
  6. package/ts_build/src/constants/tokens.js +8 -2
  7. package/ts_build/src/constants/tokens.js.map +1 -1
  8. package/ts_build/src/constants/units.d.ts +11 -0
  9. package/ts_build/src/constants/units.d.ts.map +1 -1
  10. package/ts_build/src/constants/units.js +11 -0
  11. package/ts_build/src/constants/units.js.map +1 -1
  12. package/ts_build/src/transactions/index.d.ts +1 -1
  13. package/ts_build/src/transactions/index.d.ts.map +1 -1
  14. package/ts_build/src/transactions/index.js.map +1 -1
  15. package/ts_build/src/types/derivation.d.ts +1 -0
  16. package/ts_build/src/types/derivation.d.ts.map +1 -1
  17. package/.mocharc.json +0 -6
  18. package/LICENSE +0 -21
  19. package/mcr.config.js +0 -17
  20. package/src/constants/address.ts +0 -7
  21. package/src/constants/algorithms.ts +0 -9
  22. package/src/constants/arc.ts +0 -4
  23. package/src/constants/chains.ts +0 -68
  24. package/src/constants/feeMinimums.ts +0 -23
  25. package/src/constants/index.ts +0 -40
  26. package/src/constants/tokens.ts +0 -227
  27. package/src/constants/units.ts +0 -300
  28. package/src/derivation/arb/index.ts +0 -3
  29. package/src/derivation/base/index.ts +0 -3
  30. package/src/derivation/bch/index.ts +0 -11
  31. package/src/derivation/btc/index.ts +0 -68
  32. package/src/derivation/doge/index.ts +0 -6
  33. package/src/derivation/eth/index.ts +0 -86
  34. package/src/derivation/index.ts +0 -140
  35. package/src/derivation/ltc/index.ts +0 -6
  36. package/src/derivation/matic/index.ts +0 -3
  37. package/src/derivation/op/index.ts +0 -3
  38. package/src/derivation/paths.ts +0 -45
  39. package/src/derivation/sol/index.ts +0 -81
  40. package/src/derivation/xrp/index.ts +0 -63
  41. package/src/index.ts +0 -48
  42. package/src/message/btc.ts +0 -28
  43. package/src/message/eth.ts +0 -47
  44. package/src/message/index.ts +0 -71
  45. package/src/message/sol.ts +0 -3
  46. package/src/message/xrp.ts +0 -4
  47. package/src/transactions/arb/index.ts +0 -14
  48. package/src/transactions/base/index.ts +0 -13
  49. package/src/transactions/bch/index.ts +0 -25
  50. package/src/transactions/btc/index.ts +0 -316
  51. package/src/transactions/doge/index.ts +0 -31
  52. package/src/transactions/erc20/abi.ts +0 -418
  53. package/src/transactions/erc20/index.ts +0 -57
  54. package/src/transactions/eth/index.ts +0 -192
  55. package/src/transactions/eth-multisig/abi.ts +0 -724
  56. package/src/transactions/eth-multisig/index.ts +0 -172
  57. package/src/transactions/index.ts +0 -85
  58. package/src/transactions/ltc/index.ts +0 -31
  59. package/src/transactions/matic/index.ts +0 -14
  60. package/src/transactions/matic-multisig/index.ts +0 -172
  61. package/src/transactions/op/index.ts +0 -14
  62. package/src/transactions/sol/index.ts +0 -306
  63. package/src/transactions/spl/index.ts +0 -192
  64. package/src/transactions/xrp/index.ts +0 -167
  65. package/src/types/derivation.ts +0 -34
  66. package/src/types/index.ts +0 -3
  67. package/src/types/message.ts +0 -15
  68. package/src/types/utils.ts +0 -1
  69. package/src/types/validation.ts +0 -4
  70. package/src/utils/bigint.ts +0 -238
  71. package/src/utils/index.ts +0 -188
  72. package/src/validation/arb/index.ts +0 -8
  73. package/src/validation/arc/index.ts +0 -8
  74. package/src/validation/base/index.ts +0 -8
  75. package/src/validation/bch/index.ts +0 -17
  76. package/src/validation/btc/index.ts +0 -17
  77. package/src/validation/doge/index.ts +0 -16
  78. package/src/validation/eth/index.ts +0 -29
  79. package/src/validation/index.ts +0 -45
  80. package/src/validation/ltc/index.ts +0 -16
  81. package/src/validation/matic/index.ts +0 -8
  82. package/src/validation/op/index.ts +0 -8
  83. package/src/validation/sol/index.ts +0 -34
  84. package/src/validation/xrp/index.ts +0 -50
  85. package/test/address.test.ts +0 -190
  86. package/test/bigint.test.ts +0 -373
  87. package/test/deriver.test.ts +0 -126
  88. package/test/transactions.test.ts +0 -2103
  89. package/test/utils.test.ts +0 -446
  90. package/test/validation.test.ts +0 -282
  91. package/tsconfig.json +0 -29
@@ -1,227 +0,0 @@
1
- export const ETH_TOKEN_OPTS = {
2
- '0x4fabb145d64652a948d72533023f6e7a623c7c53': {
3
- name: 'Binance USD Coin',
4
- symbol: 'BUSD',
5
- decimals: 18,
6
- address: '0x4fabb145d64652a948d72533023f6e7a623c7c53'
7
- },
8
- '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48': {
9
- name: 'USD Coin',
10
- symbol: 'USDC',
11
- decimals: 6,
12
- address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
13
- },
14
- '0x6c3ea9036406852006290770BEdFcAbA0e23A0e8': {
15
- name: 'PayPal USD',
16
- symbol: 'PYUSD',
17
- decimals: 6,
18
- address: '0x6c3ea9036406852006290770BEdFcAbA0e23A0e8'
19
- },
20
- '0x8e870d67f660d95d5be530380d0ec0bd388289e1': {
21
- name: 'Paxos Dollar',
22
- symbol: 'USDP',
23
- decimals: 18,
24
- address: '0x8e870d67f660d95d5be530380d0ec0bd388289e1'
25
- },
26
- '0x056fd409e1d7a124bd7017459dfea2f387b6d5cd': {
27
- name: 'Gemini Dollar',
28
- symbol: 'GUSD',
29
- decimals: 2,
30
- address: '0x056fd409e1d7a124bd7017459dfea2f387b6d5cd'
31
- },
32
- '0x6b175474e89094c44da98b954eedeac495271d0f': {
33
- name: 'Dai',
34
- symbol: 'DAI',
35
- decimals: 18,
36
- address: '0x6b175474e89094c44da98b954eedeac495271d0f'
37
- },
38
- '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599': {
39
- name: 'Wrapped Bitcoin',
40
- symbol: 'WBTC',
41
- decimals: 8,
42
- address: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599'
43
- },
44
- '0x95ad61b0a150d79219dcf64e1e6cc01f0b64c4ce': {
45
- address: '0x95ad61b0a150d79219dcf64e1e6cc01f0b64c4ce',
46
- decimals: 18,
47
- name: 'SHIBA INU',
48
- symbol: 'SHIB'
49
- },
50
- '0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c': {
51
- name: 'Euro Coin',
52
- symbol: 'EUROC',
53
- decimals: 6,
54
- address: '0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c'
55
- },
56
- '0x4d224452801aced8b2f0aebe155379bb5d594381': {
57
- name: 'ApeCoin',
58
- symbol: 'APE',
59
- decimals: 18,
60
- address: '0x4d224452801aced8b2f0aebe155379bb5d594381'
61
- },
62
- '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0': {
63
- name: 'Matic Token',
64
- symbol: 'MATIC',
65
- decimals: 18,
66
- address: '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0'
67
- },
68
- '0xdac17f958d2ee523a2206206994597c13d831ec7': {
69
- name: 'Tether USD',
70
- symbol: 'USDT',
71
- decimals: 6,
72
- address: '0xdac17f958d2ee523a2206206994597c13d831ec7'
73
- }
74
- };
75
-
76
- export const MATIC_TOKEN_OPTS = {
77
- '0x2791bca1f2de4661ed88a30c99a7a9449aa84174': {
78
- name: 'USDC.e',
79
- symbol: 'USDC.e',
80
- decimals: 6,
81
- address: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174'
82
- },
83
- '0xdab529f40e671a1d4bf91361c21bf9f0c9712ab7': {
84
- name: 'binance-usd',
85
- symbol: 'BUSD',
86
- decimals: 18,
87
- address: '0xdab529f40e671a1d4bf91361c21bf9f0c9712ab7'
88
- },
89
- '0x8f3cf7ad23cd3cadbd9735aff958023239c6a063': {
90
- name: '(PoS) Dai Stablecoin',
91
- symbol: 'DAI',
92
- decimals: 18,
93
- address: '0x8f3cf7ad23cd3cadbd9735aff958023239c6a063'
94
- },
95
- '0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6': {
96
- name: '(PoS) Wrapped BTC',
97
- symbol: 'WBTC',
98
- decimals: 8,
99
- address: '0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6'
100
- },
101
- '0x6f8a06447ff6fcf75d803135a7de15ce88c1d4ec': {
102
- name: 'SHIBA INU (PoS)',
103
- symbol: 'SHIB',
104
- decimals: 18,
105
- address: '0x6f8a06447ff6fcf75d803135a7de15ce88c1d4ec'
106
- },
107
- '0xb7b31a6bc18e48888545ce79e83e06003be70930': {
108
- name: 'ApeCoin (PoS)',
109
- symbol: 'APE',
110
- decimals: 18,
111
- address: '0xb7b31a6bc18e48888545ce79e83e06003be70930'
112
- },
113
- '0xc2132d05d31c914a87c6611c10748aeb04b58e8f': {
114
- name: 'Tether USD',
115
- symbol: 'USDT',
116
- decimals: 6,
117
- address: '0xc2132d05d31c914a87c6611c10748aeb04b58e8f'
118
- },
119
- '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619': {
120
- name: 'Wrapped Ether',
121
- symbol: 'WETH',
122
- decimals: 18,
123
- address: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',
124
- },
125
- '0x3c499c542cef5e3811e1192ce70d8cc03d5c3359': {
126
- name: 'USDC',
127
- symbol: 'USDC',
128
- decimals: 6,
129
- address: '0x3c499c542cef5e3811e1192ce70d8cc03d5c3359',
130
- }
131
- };
132
-
133
- export const ARB_TOKEN_OPTS = {
134
- '0xaf88d065e77c8cc2239327c5edb3a432268e5831': {
135
- name: 'USD Coin',
136
- symbol: 'USDC',
137
- decimals: 6,
138
- address: '0xaf88d065e77c8cc2239327c5edb3a432268e5831'
139
- },
140
- '0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f': {
141
- name: 'Wrapped Bitcoin',
142
- symbol: 'WBTC',
143
- decimals: 8,
144
- address: '0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f'
145
- },
146
- '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9': {
147
- name: 'Tether USD',
148
- symbol: 'USDT',
149
- decimals: 6,
150
- address: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9'
151
- },
152
- '0x82af49447d8a07e3bd95bd0d56f35241523fbab1': {
153
- name: 'Wrapped Ether',
154
- symbol: 'WETH',
155
- decimals: 18,
156
- address: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
157
- }
158
- };
159
-
160
- export const BASE_TOKEN_OPTS = {
161
- '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913': {
162
- name: 'USD Coin',
163
- symbol: 'USDC',
164
- decimals: 6,
165
- address: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913'
166
- },
167
- '0x4200000000000000000000000000000000000006': {
168
- name: 'Wrapped Ether',
169
- symbol: 'WETH',
170
- decimals: 18,
171
- address: '0x4200000000000000000000000000000000000006',
172
- }
173
- };
174
-
175
- export const OP_TOKEN_OPTS = {
176
- '0x0b2c639c533813f4aa9d7837caf62653d097ff85': {
177
- name: 'USD Coin',
178
- symbol: 'USDC',
179
- decimals: 6,
180
- address: '0x0b2c639c533813f4aa9d7837caf62653d097ff85'
181
- },
182
- '0x68f180fcce6836688e9084f035309e29bf0a2095': {
183
- name: 'Wrapped Bitcoin',
184
- symbol: 'WBTC',
185
- decimals: 8,
186
- address: '0x68f180fcce6836688e9084f035309e29bf0a2095'
187
- },
188
- '0x94b008aa00579c1307b0ef2c499ad98a8ce58e58': {
189
- name: 'Tether USD',
190
- symbol: 'USDT',
191
- decimals: 6,
192
- address: '0x94b008aa00579c1307b0ef2c499ad98a8ce58e58'
193
- },
194
- '0x4200000000000000000000000000000000000006': {
195
- name: 'Wrapped Ether',
196
- symbol: 'WETH',
197
- decimals: 18,
198
- address: '0x4200000000000000000000000000000000000006',
199
- }
200
- };
201
-
202
- export const ARC_TOKEN_OPTS = {};
203
-
204
- export const SOL_TOKEN_OPTS = {
205
- 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v': {
206
- name: 'USD Coin',
207
- symbol: 'USDC',
208
- decimals: 6,
209
- address: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'
210
- },
211
- 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB': {
212
- name: 'Tether USD',
213
- symbol: 'USDT',
214
- decimals: 6,
215
- address: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB'
216
- },
217
- };
218
-
219
- export const TOKEN_OPTS = {
220
- ETH_TOKEN_OPTS,
221
- MATIC_TOKEN_OPTS,
222
- ARB_TOKEN_OPTS,
223
- BASE_TOKEN_OPTS,
224
- OP_TOKEN_OPTS,
225
- ARC_TOKEN_OPTS,
226
- SOL_TOKEN_OPTS
227
- };
@@ -1,300 +0,0 @@
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
- arc: {
91
- toSatoshis: 1e18,
92
- full: {
93
- maxDecimals: 6,
94
- minDecimals: 6
95
- },
96
- short: {
97
- maxDecimals: 6,
98
- minDecimals: 2
99
- }
100
- },
101
- xrp: {
102
- toSatoshis: 1e6,
103
- full: {
104
- maxDecimals: 6,
105
- minDecimals: 6
106
- },
107
- short: {
108
- maxDecimals: 6,
109
- minDecimals: 2
110
- }
111
- },
112
- busd: {
113
- toSatoshis: 1e18,
114
- full: {
115
- maxDecimals: 8,
116
- minDecimals: 8
117
- },
118
- short: {
119
- maxDecimals: 6,
120
- minDecimals: 2
121
- }
122
- },
123
- dai: {
124
- toSatoshis: 1e18,
125
- full: {
126
- maxDecimals: 8,
127
- minDecimals: 8
128
- },
129
- short: {
130
- maxDecimals: 6,
131
- minDecimals: 2
132
- }
133
- },
134
- wbtc: {
135
- toSatoshis: 1e8,
136
- full: {
137
- maxDecimals: 8,
138
- minDecimals: 8
139
- },
140
- short: {
141
- maxDecimals: 8,
142
- minDecimals: 2
143
- }
144
- },
145
- usdc: {
146
- toSatoshis: 1e6,
147
- full: {
148
- maxDecimals: 8,
149
- minDecimals: 8
150
- },
151
- short: {
152
- maxDecimals: 6,
153
- minDecimals: 2
154
- }
155
- },
156
- pyusd: {
157
- toSatoshis: 1e6,
158
- full: {
159
- maxDecimals: 8,
160
- minDecimals: 8
161
- },
162
- short: {
163
- maxDecimals: 6,
164
- minDecimals: 2
165
- }
166
- },
167
- usdp: {
168
- toSatoshis: 1e18,
169
- full: {
170
- maxDecimals: 8,
171
- minDecimals: 8
172
- },
173
- short: {
174
- maxDecimals: 6,
175
- minDecimals: 2
176
- }
177
- },
178
- // backwards compatibility
179
- pax: {
180
- toSatoshis: 1e18,
181
- full: {
182
- maxDecimals: 8,
183
- minDecimals: 8
184
- },
185
- short: {
186
- maxDecimals: 6,
187
- minDecimals: 2
188
- }
189
- },
190
- gusd: {
191
- toSatoshis: 1e2,
192
- full: {
193
- maxDecimals: 8,
194
- minDecimals: 8
195
- },
196
- short: {
197
- maxDecimals: 6,
198
- minDecimals: 2
199
- }
200
- },
201
- bit: {
202
- toSatoshis: 100,
203
- full: {
204
- maxDecimals: 2,
205
- minDecimals: 2
206
- },
207
- short: {
208
- maxDecimals: 0,
209
- minDecimals: 0
210
- }
211
- },
212
- doge: {
213
- toSatoshis: 100000000,
214
- full: {
215
- maxDecimals: 8,
216
- minDecimals: 8
217
- },
218
- short: {
219
- maxDecimals: 6,
220
- minDecimals: 2
221
- }
222
- },
223
- ltc: {
224
- toSatoshis: 100000000,
225
- full: {
226
- maxDecimals: 8,
227
- minDecimals: 8
228
- },
229
- short: {
230
- maxDecimals: 6,
231
- minDecimals: 2
232
- }
233
- },
234
- shib: {
235
- toSatoshis: 1e18,
236
- full: {
237
- maxDecimals: 8,
238
- minDecimals: 8
239
- },
240
- short: {
241
- maxDecimals: 6,
242
- minDecimals: 2
243
- }
244
- },
245
- ape: {
246
- toSatoshis: 1e18,
247
- full: {
248
- maxDecimals: 8,
249
- minDecimals: 8
250
- },
251
- short: {
252
- maxDecimals: 6,
253
- minDecimals: 2
254
- }
255
- },
256
- euroc: {
257
- toSatoshis: 1e6,
258
- full: {
259
- maxDecimals: 8,
260
- minDecimals: 8
261
- },
262
- short: {
263
- maxDecimals: 6,
264
- minDecimals: 2
265
- }
266
- },
267
- usdt: {
268
- toSatoshis: 1e6,
269
- full: {
270
- maxDecimals: 8,
271
- minDecimals: 8
272
- },
273
- short: {
274
- maxDecimals: 6,
275
- minDecimals: 2
276
- }
277
- },
278
- 'usdc.e': {
279
- toSatoshis: 1e6,
280
- full: {
281
- maxDecimals: 8,
282
- minDecimals: 8
283
- },
284
- short: {
285
- maxDecimals: 6,
286
- minDecimals: 2
287
- }
288
- },
289
- weth: {
290
- toSatoshis: 1e18,
291
- full: {
292
- maxDecimals: 8,
293
- minDecimals: 8
294
- },
295
- short: {
296
- maxDecimals: 6,
297
- minDecimals: 2
298
- }
299
- }
300
- };
@@ -1,3 +0,0 @@
1
- import { EthDeriver } from '../eth';
2
-
3
- export class ArbDeriver extends EthDeriver { }
@@ -1,3 +0,0 @@
1
- import { EthDeriver } from '../eth';
2
-
3
- export class BaseDeriver extends EthDeriver { }
@@ -1,11 +0,0 @@
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
- }
@@ -1,68 +0,0 @@
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
- getPublicKey(network: string, privKey: Buffer): string {
38
- if (!Buffer.isBuffer(privKey)) {
39
- throw new Error('Expected privKey to be a Buffer');
40
- }
41
- // Force compressed pubkey (buffer does not encode compression flag)
42
- const bn = this.bitcoreLib.crypto.BN.fromBuffer(privKey);
43
- const key = new this.bitcoreLib.PrivateKey({ bn, network, compressed: true });
44
- return key.publicKey.toString();
45
- }
46
-
47
- /**
48
- * @returns {Buffer} raw secpk1 private key buffer (32 bytes, big-endian)
49
- * @throws {Error} If privKey is not a Buffer (planned forwards compatibility) or string. Propagates all other errors
50
- */
51
- privateKeyToBuffer(privKey: Buffer | string): Buffer {
52
- if (Buffer.isBuffer(privKey)) return privKey; // forward compatibility
53
- if (typeof privKey !== 'string') throw new Error(`Expected key to be a string, got ${typeof privKey}`);
54
-
55
- const key = new this.bitcoreLib.PrivateKey(privKey);
56
- return key.toBuffer();
57
- }
58
-
59
- bufferToPrivateKey_TEMP(buf: Buffer, network: string): string {
60
- // force compressed WIF without mutating instances
61
- const bn = this.bitcoreLib.crypto.BN.fromBuffer(buf);
62
- const key = new this.bitcoreLib.PrivateKey({ bn, network, compressed: true });
63
- return key.toWIF();
64
- }
65
- }
66
- export class BtcDeriver extends AbstractBitcoreLibDeriver {
67
- bitcoreLib = BitcoreLib;
68
- }
@@ -1,6 +0,0 @@
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
- }
@@ -1,86 +0,0 @@
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
-
59
- getPublicKey(network: string, privKey: Buffer): string {
60
- if (!Buffer.isBuffer(privKey)) {
61
- throw new Error('Expected privKey to be a Buffer');
62
- }
63
- const bn = BitcoreLib.crypto.BN.fromBuffer(privKey);
64
- const key = new BitcoreLib.PrivateKey({ bn, network, compressed: true });
65
- return key.publicKey.toString('hex');
66
- }
67
-
68
- /**
69
- * @param {Buffer | string} privKey - expects hex-encoded string, as returned from EthDeriver.derivePrivateKey
70
- * @returns {Buffer}
71
- * @throws {Error} If privKey is not a Buffer (planned forwards compatibility) or string. Propagates all other errors
72
- */
73
- privateKeyToBuffer(privKey: Buffer | string): Buffer {
74
- if (Buffer.isBuffer(privKey)) return privKey;
75
- if (typeof privKey !== 'string') throw new Error(`Expected string, got ${typeof privKey}`);
76
- if (privKey.startsWith('0x')) {
77
- privKey = privKey.slice(2);
78
- };
79
- // Expects to match return from derivePrivateKey's privKey.
80
- return Buffer.from(privKey, 'hex');
81
- }
82
-
83
- bufferToPrivateKey_TEMP(buf: Buffer, _network: string): string {
84
- return buf.toString('hex');
85
- }
86
- }