@yerofey/cryptowallet-cli 1.6.1 → 1.7.0
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 +71 -57
- package/cli.js +51 -33
- package/package.json +15 -11
- package/src/CW.js +37 -34
- package/src/Chain.js +32 -23
- package/src/Method.js +379 -221
- package/src/Wallet.js +471 -351
- package/src/chains/BCH.json +7 -10
- package/src/chains/BLK.json +7 -10
- package/src/chains/BNB.json +27 -57
- package/src/chains/BTC.json +32 -55
- package/src/chains/BTG.json +7 -10
- package/src/chains/DASH.json +7 -10
- package/src/chains/DCR.json +7 -10
- package/src/chains/DGB.json +7 -10
- package/src/chains/DOGE.json +31 -52
- package/src/chains/ERC.json +7 -16
- package/src/chains/ETC.json +12 -20
- package/src/chains/ETH.json +7 -15
- package/src/chains/LTC.json +32 -55
- package/src/chains/MONA.json +7 -10
- package/src/chains/NBT.json +7 -10
- package/src/chains/NMC.json +7 -10
- package/src/chains/ONE.json +7 -14
- package/src/chains/POLYGON.json +7 -15
- package/src/chains/PPC.json +7 -10
- package/src/chains/QTUM.json +7 -10
- package/src/chains/RDD.json +7 -10
- package/src/chains/TRX.json +7 -13
- package/src/chains/VIA.json +7 -10
- package/src/chains/VTC.json +7 -10
- package/src/chains/XTZ.json +6 -9
- package/src/chains/ZEC.json +7 -10
- package/src/utils.js +41 -15
package/src/Wallet.js
CHANGED
|
@@ -1,373 +1,493 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { log } from './utils.js';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
const { red } = chalk;
|
|
4
|
+
import CoinKey from 'coinkey';
|
|
5
|
+
import CoinInfo from 'coininfo';
|
|
6
|
+
import bip39 from 'bip39';
|
|
7
|
+
import bip84 from 'bip84';
|
|
8
|
+
const {
|
|
9
|
+
fromMnemonic,
|
|
10
|
+
fromZPrv,
|
|
11
|
+
} = bip84;
|
|
12
|
+
import ethereumBip from 'ethereum-bip84';
|
|
13
|
+
const {
|
|
14
|
+
fromMnemonic: fromMnemonicEthereum,
|
|
15
|
+
fromZPrv: fromZPrvEthereum,
|
|
16
|
+
} = ethereumBip;
|
|
17
|
+
import dogecoinBip from '@yerofey/dogecoin-bip84';
|
|
18
|
+
const {
|
|
19
|
+
fromMnemonic: fromMnemonicDoge,
|
|
20
|
+
fromZPrv: fromZPrvDoge
|
|
21
|
+
} = dogecoinBip;
|
|
22
|
+
import litecoinBip from '@yerofey/litecoin-bip84';
|
|
23
|
+
const {
|
|
24
|
+
fromMnemonic: fromMnemonicLite,
|
|
25
|
+
fromZPrv: fromZPrvLite,
|
|
26
|
+
} = litecoinBip;
|
|
27
|
+
import { Account } from 'eth-lib/lib/index.js';
|
|
28
|
+
import { Wallet as HarmonyWallet } from '@harmony-js/account';
|
|
29
|
+
import pkutils from 'ethereum-mnemonic-privatekey-utils';
|
|
30
|
+
import bCrypto from '@binance-chain/javascript-sdk/lib/crypto/index.js';
|
|
31
|
+
import tronWeb from 'tronweb';
|
|
32
|
+
import tezos from 'tezos-sign';
|
|
3
33
|
|
|
4
34
|
class Wallet {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
35
|
+
constructor(cw) {
|
|
36
|
+
this.cw = cw;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async init() {
|
|
40
|
+
const cw = this.cw;
|
|
41
|
+
const row = cw.row;
|
|
42
|
+
const options = cw.options;
|
|
43
|
+
|
|
44
|
+
const desiredSymbolsArray =
|
|
45
|
+
options.prefix.length > 0 || options.suffix.length > 0
|
|
46
|
+
? options.prefix.split('').concat(options.suffix.split(''))
|
|
47
|
+
: [];
|
|
48
|
+
const desiredSymbolsUniqueArray = desiredSymbolsArray.filter(
|
|
49
|
+
(item, pos) => desiredSymbolsArray.indexOf(item) === pos
|
|
50
|
+
);
|
|
51
|
+
const badSymbolsArray =
|
|
52
|
+
desiredSymbolsUniqueArray.filter(
|
|
53
|
+
(char) => !RegExp(row.prefixTest, 'g').test(char)
|
|
54
|
+
) || [];
|
|
55
|
+
|
|
56
|
+
let wallet = {};
|
|
57
|
+
let prefixFound = false;
|
|
58
|
+
let prefixFoundInWallets = [];
|
|
59
|
+
let suffixFound = false;
|
|
60
|
+
let suffixFoundInWallets = [];
|
|
61
|
+
let onlyPrefix = false;
|
|
62
|
+
let onlySuffix = false;
|
|
63
|
+
let onlyBoth = false;
|
|
64
|
+
|
|
65
|
+
const prefixFoundInAddress = (address, isCaseSensitive, prefix, symbol) =>
|
|
66
|
+
(isCaseSensitive && address.startsWith(symbol + '' + prefix)) ||
|
|
67
|
+
(!isCaseSensitive &&
|
|
68
|
+
address.toUpperCase().startsWith((symbol + '' + prefix).toUpperCase()));
|
|
69
|
+
const suffixFoundInAddress = (address, isCaseSensitive, suffix) =>
|
|
70
|
+
(isCaseSensitive && address.endsWith(suffix)) ||
|
|
71
|
+
(!isCaseSensitive && address.toUpperCase().endsWith(suffix));
|
|
72
|
+
|
|
73
|
+
if (
|
|
74
|
+
(options.prefix && row.flags.includes('p')) ||
|
|
75
|
+
(options.suffix && row.flags.includes('s'))
|
|
76
|
+
) {
|
|
77
|
+
if (badSymbolsArray.length === 0) {
|
|
78
|
+
if (options.prefix && options.suffix) {
|
|
79
|
+
// prefix & suffix
|
|
80
|
+
log(
|
|
81
|
+
`⏳ Generating wallet with "${options.prefix}" prefix and "${options.suffix}" suffix, this for sure will take a while...`
|
|
82
|
+
);
|
|
83
|
+
onlyBoth = true;
|
|
84
|
+
} else {
|
|
85
|
+
// prefix
|
|
86
|
+
if (
|
|
87
|
+
options.prefix.length > 0 ||
|
|
88
|
+
('rareSymbols' in row &&
|
|
89
|
+
RegExp(row.rareSymbols, 'g').test(options.prefix))
|
|
90
|
+
) {
|
|
91
|
+
log(
|
|
92
|
+
`⏳ Generating wallet with "${options.prefix}" prefix, this might take a while...`
|
|
93
|
+
);
|
|
94
|
+
onlyPrefix = true;
|
|
95
|
+
}
|
|
96
|
+
// suffix
|
|
97
|
+
if (
|
|
98
|
+
options.suffix.length > 0 ||
|
|
99
|
+
('rareSymbols' in row &&
|
|
100
|
+
RegExp(row.rareSymbols, 'g').test(options.suffix))
|
|
101
|
+
) {
|
|
102
|
+
log(
|
|
103
|
+
`⏳ Generating wallet with "${options.suffix}" suffix, this might take a while...`
|
|
104
|
+
);
|
|
105
|
+
onlySuffix = true;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const startsWithSymbols = row.startsWith.split('|');
|
|
110
|
+
// eslint-disable-next-line no-constant-condition
|
|
111
|
+
loop: while (true) {
|
|
112
|
+
wallet = await this.createWallet();
|
|
113
|
+
for (let firstSymbol of startsWithSymbols) {
|
|
114
|
+
if (wallet.address !== undefined) {
|
|
115
|
+
// one address
|
|
116
|
+
if (
|
|
117
|
+
onlyPrefix &&
|
|
118
|
+
prefixFoundInAddress(
|
|
119
|
+
wallet.address,
|
|
120
|
+
options.prefixIsCaseSensitive,
|
|
121
|
+
options.prefix,
|
|
122
|
+
firstSymbol
|
|
123
|
+
)
|
|
124
|
+
) {
|
|
125
|
+
prefixFound = true;
|
|
126
|
+
break loop;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (
|
|
130
|
+
onlySuffix &&
|
|
131
|
+
suffixFoundInAddress(
|
|
132
|
+
wallet.address,
|
|
133
|
+
options.suffixIsCaseSensitive,
|
|
134
|
+
options.suffix
|
|
135
|
+
)
|
|
136
|
+
) {
|
|
137
|
+
suffixFound = true;
|
|
138
|
+
break loop;
|
|
139
|
+
}
|
|
8
140
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
// suffix
|
|
43
|
-
if (options.suffix.length > 0 || 'rareSymbols' in row && RegExp(row.rareSymbols, 'g').test(options.suffix)) {
|
|
44
|
-
log(`⏳ Generating wallet with "${options.suffix}" suffix, this might take a while...`);
|
|
45
|
-
onlySuffix = true;
|
|
46
|
-
}
|
|
141
|
+
if (
|
|
142
|
+
onlyBoth &&
|
|
143
|
+
prefixFoundInAddress(
|
|
144
|
+
wallet.address,
|
|
145
|
+
options.prefixIsCaseSensitive,
|
|
146
|
+
options.prefix,
|
|
147
|
+
firstSymbol
|
|
148
|
+
) &&
|
|
149
|
+
suffixFoundInAddress(
|
|
150
|
+
wallet.address,
|
|
151
|
+
options.suffixIsCaseSensitive,
|
|
152
|
+
options.suffix
|
|
153
|
+
)
|
|
154
|
+
) {
|
|
155
|
+
prefixFound = true;
|
|
156
|
+
suffixFound = true;
|
|
157
|
+
break loop;
|
|
158
|
+
}
|
|
159
|
+
} else if (wallet.addresses !== undefined) {
|
|
160
|
+
// multiple addresses
|
|
161
|
+
for (let item of wallet.addresses) {
|
|
162
|
+
if (
|
|
163
|
+
onlyPrefix &&
|
|
164
|
+
prefixFoundInAddress(
|
|
165
|
+
item.address,
|
|
166
|
+
options.prefixIsCaseSensitive,
|
|
167
|
+
options.prefix,
|
|
168
|
+
firstSymbol
|
|
169
|
+
)
|
|
170
|
+
) {
|
|
171
|
+
prefixFound = true;
|
|
172
|
+
prefixFoundInWallets.push(item.address);
|
|
47
173
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (onlySuffix && suffixFoundInAddress(wallet.address, options.suffixIsCaseSensitive, options.suffix)) {
|
|
61
|
-
suffixFound = true;
|
|
62
|
-
break loop;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (onlyBoth && prefixFoundInAddress(wallet.address, options.prefixIsCaseSensitive, options.prefix, firstSymbol) && suffixFoundInAddress(wallet.address, options.suffixIsCaseSensitive, options.suffix)) {
|
|
66
|
-
prefixFound = true;
|
|
67
|
-
suffixFound = true;
|
|
68
|
-
break loop;
|
|
69
|
-
}
|
|
70
|
-
} else if (wallet.addresses !== undefined) { // multiple addresses
|
|
71
|
-
for (let item of wallet.addresses) {
|
|
72
|
-
if (onlyPrefix && prefixFoundInAddress(item.address, options.prefixIsCaseSensitive, options.prefix, firstSymbol)) {
|
|
73
|
-
prefixFound = true;
|
|
74
|
-
prefixFoundInWallets.push(item.address);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (onlySuffix && suffixFoundInAddress(item.address, options.suffixIsCaseSensitive, options.suffix)) {
|
|
78
|
-
suffixFound = true;
|
|
79
|
-
suffixFoundInWallets.push(item.address);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (onlyBoth && prefixFoundInAddress(item.address, options.prefixIsCaseSensitive, options.prefix, firstSymbol) && suffixFoundInAddress(item.address, options.suffixIsCaseSensitive, options.suffix)) {
|
|
83
|
-
prefixFound = true;
|
|
84
|
-
prefixFoundInWallets.push(item.address);
|
|
85
|
-
suffixFound = true;
|
|
86
|
-
suffixFoundInWallets.push(item.address);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (onlyPrefix && prefixFound || onlySuffix && suffixFound || onlyBoth && prefixFound && suffixFound) {
|
|
90
|
-
break loop;
|
|
91
|
-
}
|
|
92
|
-
} else {
|
|
93
|
-
break loop;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
}
|
|
174
|
+
|
|
175
|
+
if (
|
|
176
|
+
onlySuffix &&
|
|
177
|
+
suffixFoundInAddress(
|
|
178
|
+
item.address,
|
|
179
|
+
options.suffixIsCaseSensitive,
|
|
180
|
+
options.suffix
|
|
181
|
+
)
|
|
182
|
+
) {
|
|
183
|
+
suffixFound = true;
|
|
184
|
+
suffixFoundInWallets.push(item.address);
|
|
97
185
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
186
|
+
|
|
187
|
+
if (
|
|
188
|
+
onlyBoth &&
|
|
189
|
+
prefixFoundInAddress(
|
|
190
|
+
item.address,
|
|
191
|
+
options.prefixIsCaseSensitive,
|
|
192
|
+
options.prefix,
|
|
193
|
+
firstSymbol
|
|
194
|
+
) &&
|
|
195
|
+
suffixFoundInAddress(
|
|
196
|
+
item.address,
|
|
197
|
+
options.suffixIsCaseSensitive,
|
|
198
|
+
options.suffix
|
|
199
|
+
)
|
|
200
|
+
) {
|
|
201
|
+
prefixFound = true;
|
|
202
|
+
prefixFoundInWallets.push(item.address);
|
|
203
|
+
suffixFound = true;
|
|
204
|
+
suffixFoundInWallets.push(item.address);
|
|
102
205
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
206
|
+
}
|
|
207
|
+
if (
|
|
208
|
+
(onlyPrefix && prefixFound) ||
|
|
209
|
+
(onlySuffix && suffixFound) ||
|
|
210
|
+
(onlyBoth && prefixFound && suffixFound)
|
|
211
|
+
) {
|
|
212
|
+
break loop;
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
break loop;
|
|
107
216
|
}
|
|
108
|
-
|
|
109
|
-
wallet = await this.createWallet();
|
|
217
|
+
}
|
|
110
218
|
}
|
|
219
|
+
} else {
|
|
220
|
+
let badSymbolsString = '';
|
|
221
|
+
for (const symbol of badSymbolsArray) {
|
|
222
|
+
badSymbolsString += '"' + symbol + '", ';
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// TODO: add prefix/suffix own message log
|
|
226
|
+
log(
|
|
227
|
+
red(
|
|
228
|
+
'⛔️ Error: prefix or suffix contains non-supported characters (' +
|
|
229
|
+
badSymbolsString.substr(0, badSymbolsString.length - 2) +
|
|
230
|
+
')!'
|
|
231
|
+
)
|
|
232
|
+
);
|
|
233
|
+
// eslint-disable-next-line no-undef
|
|
234
|
+
process.exit(1);
|
|
235
|
+
}
|
|
236
|
+
} else {
|
|
237
|
+
wallet = await this.createWallet();
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
wallet,
|
|
242
|
+
prefixFound,
|
|
243
|
+
prefixFoundInWallets,
|
|
244
|
+
suffixFound,
|
|
245
|
+
suffixFoundInWallets,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
async createWallet() {
|
|
250
|
+
const cw = this.cw;
|
|
251
|
+
const chain = cw.chain;
|
|
252
|
+
const row = cw.row;
|
|
253
|
+
const options = cw.options;
|
|
111
254
|
|
|
255
|
+
let format = options.format || '';
|
|
256
|
+
let mnemonicString = options.mnemonic || '';
|
|
257
|
+
let number = options.number || 1;
|
|
258
|
+
let result = {};
|
|
259
|
+
|
|
260
|
+
if (row.length == 0) {
|
|
261
|
+
return {
|
|
262
|
+
error: 'this blockchain is not found',
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (row.script == 'coinkey') {
|
|
267
|
+
const wallet = CoinKey.createRandom(CoinInfo(chain).versions);
|
|
268
|
+
|
|
269
|
+
result = Object.assign(result, {
|
|
270
|
+
format,
|
|
271
|
+
addresses: [
|
|
272
|
+
{
|
|
273
|
+
index: 0,
|
|
274
|
+
address: wallet.publicAddress,
|
|
275
|
+
privateKey: wallet.privateWif,
|
|
276
|
+
},
|
|
277
|
+
],
|
|
278
|
+
});
|
|
279
|
+
} else if (chain == 'BTC') {
|
|
280
|
+
if (mnemonicString != '' && !bip39.validateMnemonic(mnemonicString)) {
|
|
112
281
|
return {
|
|
113
|
-
|
|
114
|
-
prefixFound,
|
|
115
|
-
prefixFoundInWallets,
|
|
116
|
-
suffixFound,
|
|
117
|
-
suffixFoundInWallets,
|
|
282
|
+
error: 'mnemonic is not valid',
|
|
118
283
|
};
|
|
119
|
-
|
|
284
|
+
}
|
|
120
285
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
let
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
error: 'this blockchain is not found',
|
|
135
|
-
}
|
|
286
|
+
const mnemonic = mnemonicString || bip39.generateMnemonic();
|
|
287
|
+
const root = new fromMnemonic(mnemonic, '');
|
|
288
|
+
const child = root.deriveAccount(0);
|
|
289
|
+
const account = new fromZPrv(child);
|
|
290
|
+
|
|
291
|
+
let addresses = [];
|
|
292
|
+
if (number >= 1) {
|
|
293
|
+
for (let i = 0; i < number; i++) {
|
|
294
|
+
addresses.push({
|
|
295
|
+
index: i,
|
|
296
|
+
address: account.getAddress(i, false, row.purpose),
|
|
297
|
+
privateKey: account.getPrivateKey(i),
|
|
298
|
+
});
|
|
136
299
|
}
|
|
137
|
-
|
|
138
|
-
if (row.script == 'coinkey') {
|
|
139
|
-
const CoinKey = require('coinkey');
|
|
140
|
-
const CoinInfo = require('coininfo');
|
|
141
|
-
|
|
142
|
-
const wallet = CoinKey.createRandom(CoinInfo(chain).versions);
|
|
143
|
-
|
|
144
|
-
result = Object.assign(result, {
|
|
145
|
-
format,
|
|
146
|
-
addresses: [{
|
|
147
|
-
index: 0,
|
|
148
|
-
address: wallet.publicAddress,
|
|
149
|
-
privateKey: wallet.privateWif,
|
|
150
|
-
}]
|
|
151
|
-
});
|
|
152
|
-
} else if (chain == 'BTC') {
|
|
153
|
-
const bip39 = require('bip39');
|
|
154
|
-
const { fromMnemonic, fromZPrv } = require('bip84');
|
|
155
|
-
|
|
156
|
-
if (mnemonicString != '' && !bip39.validateMnemonic(mnemonicString)) {
|
|
157
|
-
return {
|
|
158
|
-
error: 'mnemonic is not valid'
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const mnemonic = mnemonicString || bip39.generateMnemonic();
|
|
163
|
-
const root = new fromMnemonic(mnemonic, '');
|
|
164
|
-
const child = root.deriveAccount(0);
|
|
165
|
-
const account = new fromZPrv(child);
|
|
166
|
-
|
|
167
|
-
let addresses = [];
|
|
168
|
-
if (number >= 1) {
|
|
169
|
-
for (let i = 0; i < number; i++) {
|
|
170
|
-
addresses.push({
|
|
171
|
-
index: i,
|
|
172
|
-
address: account.getAddress(i, false, row.purpose),
|
|
173
|
-
privateKey: account.getPrivateKey(i)
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
Object.assign(result, {
|
|
179
|
-
format: row.format,
|
|
180
|
-
addresses,
|
|
181
|
-
privateExtendedKey: account.getAccountPrivateKey(),
|
|
182
|
-
mnemonic
|
|
183
|
-
});
|
|
184
|
-
} else if (chain == 'DOGE' || chain == 'LTC') {
|
|
185
|
-
const bip39 = require('bip39');
|
|
186
|
-
const { fromMnemonic, fromZPrv } = require('@yerofey/' + row.title.toLowerCase() + '-bip84');
|
|
187
|
-
|
|
188
|
-
if (mnemonicString != '' && !bip39.validateMnemonic(mnemonicString)) {
|
|
189
|
-
return {
|
|
190
|
-
error: 'mnemonic is not valid'
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const mnemonic = mnemonicString || bip39.generateMnemonic();
|
|
195
|
-
const root = new fromMnemonic(mnemonic, '');
|
|
196
|
-
const child = root.deriveAccount(0);
|
|
197
|
-
const account = new fromZPrv(child);
|
|
198
|
-
|
|
199
|
-
let addresses = [];
|
|
200
|
-
if (number >= 1) {
|
|
201
|
-
for (let i = 0; i < number; i++) {
|
|
202
|
-
addresses.push({
|
|
203
|
-
index: i,
|
|
204
|
-
address: account.getAddress(i, false, row.purpose),
|
|
205
|
-
privateKey: account.getPrivateKey(i)
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
Object.assign(result, {
|
|
211
|
-
format: row.format,
|
|
212
|
-
addresses,
|
|
213
|
-
privateExtendedKey: account.getAccountPrivateKey(),
|
|
214
|
-
mnemonic
|
|
215
|
-
});
|
|
216
|
-
} else if (row.format == 'BEP2') {
|
|
217
|
-
const bip39 = require('bip39');
|
|
218
|
-
const bCrypto = require('@binance-chain/javascript-sdk/lib/crypto');
|
|
219
|
-
|
|
220
|
-
if (mnemonicString != '' && !bip39.validateMnemonic(mnemonicString)) {
|
|
221
|
-
return {
|
|
222
|
-
error: 'mnemonic is not valid'
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
let addresses = [];
|
|
227
|
-
const mnemonic = mnemonicString || bip39.generateMnemonic();
|
|
228
|
-
|
|
229
|
-
if (number == 1) {
|
|
230
|
-
const privateKey = bCrypto.getPrivateKeyFromMnemonic(mnemonic, true, 0);
|
|
231
|
-
addresses.push({
|
|
232
|
-
index: 0,
|
|
233
|
-
address: bCrypto.getAddressFromPrivateKey(privateKey, 'bnb'),
|
|
234
|
-
privateKey
|
|
235
|
-
});
|
|
236
|
-
} else {
|
|
237
|
-
for (let i = 0; i <= number; i++) {
|
|
238
|
-
const privateKey = bCrypto.getPrivateKeyFromMnemonic(mnemonic, true, i);
|
|
239
|
-
addresses.push({
|
|
240
|
-
index: i,
|
|
241
|
-
address: bCrypto.getAddressFromPrivateKey(privateKey, 'bnb'),
|
|
242
|
-
privateKey
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
}
|
|
300
|
+
}
|
|
246
301
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
Object.assign(result, {
|
|
315
|
-
addresses: [{
|
|
316
|
-
index: 0,
|
|
317
|
-
address: account.bech32Address,
|
|
318
|
-
privateKey: account.privateKey,
|
|
319
|
-
}],
|
|
320
|
-
mnemonic,
|
|
321
|
-
});
|
|
322
|
-
} else if (chain == 'TRX') {
|
|
323
|
-
const tronWeb = require('tronweb');
|
|
324
|
-
|
|
325
|
-
try {
|
|
326
|
-
const wallet = await tronWeb.createAccount();
|
|
327
|
-
|
|
328
|
-
Object.assign(result, {
|
|
329
|
-
addresses: [{
|
|
330
|
-
index: 0,
|
|
331
|
-
address: wallet.address.base58,
|
|
332
|
-
privateKey: wallet.privateKey
|
|
333
|
-
}],
|
|
334
|
-
});
|
|
335
|
-
} catch (error) {
|
|
336
|
-
return {
|
|
337
|
-
error
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
} else if (chain == 'XTZ') {
|
|
341
|
-
const tezos = require('tezos-sign');
|
|
342
|
-
const wallet = tezos.generateKeysNoSeed();
|
|
343
|
-
|
|
344
|
-
Object.assign(result, {
|
|
345
|
-
addresses: [{
|
|
346
|
-
index: 0,
|
|
347
|
-
address: wallet.pkh,
|
|
348
|
-
privateKey: wallet.sk,
|
|
349
|
-
}],
|
|
350
|
-
});
|
|
351
|
-
} else {
|
|
352
|
-
return {
|
|
353
|
-
error: 'your desired blockchain is not supported yet'
|
|
354
|
-
}
|
|
302
|
+
Object.assign(result, {
|
|
303
|
+
format: row.format,
|
|
304
|
+
addresses,
|
|
305
|
+
privateExtendedKey: account.getAccountPrivateKey(),
|
|
306
|
+
mnemonic,
|
|
307
|
+
});
|
|
308
|
+
} else if (chain == 'DOGE' || chain == 'LTC') {
|
|
309
|
+
if (mnemonicString != '' && !bip39.validateMnemonic(mnemonicString)) {
|
|
310
|
+
return {
|
|
311
|
+
error: 'mnemonic is not valid',
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const _fromMnemonic = (chain == 'DOGE') ? fromMnemonicDoge : fromMnemonicLite;
|
|
316
|
+
const _fromZPrv = (chain == 'DOGE') ? fromZPrvDoge : fromZPrvLite;
|
|
317
|
+
const mnemonic = mnemonicString || bip39.generateMnemonic();
|
|
318
|
+
const root = new _fromMnemonic(mnemonic, '');
|
|
319
|
+
const child = root.deriveAccount(0);
|
|
320
|
+
const account = new _fromZPrv(child);
|
|
321
|
+
|
|
322
|
+
let addresses = [];
|
|
323
|
+
if (number >= 1) {
|
|
324
|
+
for (let i = 0; i < number; i++) {
|
|
325
|
+
addresses.push({
|
|
326
|
+
index: i,
|
|
327
|
+
address: account.getAddress(i, false, row.purpose),
|
|
328
|
+
privateKey: account.getPrivateKey(i),
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
Object.assign(result, {
|
|
334
|
+
format: row.format,
|
|
335
|
+
addresses,
|
|
336
|
+
privateExtendedKey: account.getAccountPrivateKey(),
|
|
337
|
+
mnemonic,
|
|
338
|
+
});
|
|
339
|
+
} else if (row.format == 'BEP2') {
|
|
340
|
+
if (mnemonicString != '' && !bip39.validateMnemonic(mnemonicString)) {
|
|
341
|
+
return {
|
|
342
|
+
error: 'mnemonic is not valid',
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
let addresses = [];
|
|
347
|
+
const mnemonic = mnemonicString || bip39.generateMnemonic();
|
|
348
|
+
|
|
349
|
+
if (number == 1) {
|
|
350
|
+
const privateKey = bCrypto.getPrivateKeyFromMnemonic(mnemonic, true, 0);
|
|
351
|
+
addresses.push({
|
|
352
|
+
index: 0,
|
|
353
|
+
address: bCrypto.getAddressFromPrivateKey(privateKey, 'bnb'),
|
|
354
|
+
privateKey,
|
|
355
|
+
});
|
|
356
|
+
} else {
|
|
357
|
+
for (let i = 0; i <= number; i++) {
|
|
358
|
+
const privateKey = bCrypto.getPrivateKeyFromMnemonic(
|
|
359
|
+
mnemonic,
|
|
360
|
+
true,
|
|
361
|
+
i
|
|
362
|
+
);
|
|
363
|
+
addresses.push({
|
|
364
|
+
index: i,
|
|
365
|
+
address: bCrypto.getAddressFromPrivateKey(privateKey, 'bnb'),
|
|
366
|
+
privateKey,
|
|
367
|
+
});
|
|
355
368
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
Object.assign(result, {
|
|
372
|
+
format: 'BEP2',
|
|
373
|
+
addresses,
|
|
374
|
+
mnemonic,
|
|
375
|
+
});
|
|
376
|
+
} else if (row.network == 'EVM') {
|
|
377
|
+
if (mnemonicString != '' && !bip39.validateMnemonic(mnemonicString)) {
|
|
378
|
+
return {
|
|
379
|
+
error: 'mnemonic is not valid',
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
let addresses = [];
|
|
384
|
+
const mnemonic = mnemonicString || bip39.generateMnemonic();
|
|
385
|
+
const privateKey = pkutils.getPrivateKeyFromMnemonic(mnemonic);
|
|
386
|
+
|
|
387
|
+
if (number == 1) {
|
|
388
|
+
const account = Account.fromPrivate('0x' + privateKey);
|
|
389
|
+
|
|
390
|
+
addresses.push({
|
|
391
|
+
index: 0,
|
|
392
|
+
address: account.address,
|
|
393
|
+
privateKey,
|
|
394
|
+
});
|
|
395
|
+
} else {
|
|
396
|
+
// TODO: add variable for accountId
|
|
397
|
+
const root = new fromMnemonicEthereum(mnemonic, '');
|
|
398
|
+
const child = root.deriveAccount(0);
|
|
399
|
+
const account = new fromZPrvEthereum(child);
|
|
400
|
+
for (let walletId = 0; walletId <= number; walletId++) {
|
|
401
|
+
const walletAddress = account.getAddress(walletId);
|
|
402
|
+
const privateKey = account.getPrivateKey(walletId);
|
|
403
|
+
|
|
404
|
+
addresses.push({
|
|
405
|
+
index: walletId,
|
|
406
|
+
address: walletAddress,
|
|
407
|
+
privateKey,
|
|
408
|
+
});
|
|
361
409
|
}
|
|
362
|
-
|
|
363
|
-
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
Object.assign(result, {
|
|
413
|
+
format: row.format || '',
|
|
414
|
+
addresses,
|
|
415
|
+
mnemonic,
|
|
416
|
+
});
|
|
417
|
+
} else if (chain == 'ONE') {
|
|
418
|
+
if (mnemonicString != '' && !bip39.validateMnemonic(mnemonicString)) {
|
|
419
|
+
return {
|
|
420
|
+
error: 'mnemonic is not valid',
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const wallet = new HarmonyWallet();
|
|
425
|
+
const mnemonic = mnemonicString || bip39.generateMnemonic();
|
|
426
|
+
wallet.addByMnemonic(mnemonic);
|
|
427
|
+
const publicKey = wallet.accounts[0];
|
|
428
|
+
const account = wallet.getAccount(publicKey);
|
|
429
|
+
|
|
430
|
+
Object.assign(result, {
|
|
431
|
+
addresses: [
|
|
432
|
+
{
|
|
433
|
+
index: 0,
|
|
434
|
+
address: account.bech32Address,
|
|
435
|
+
privateKey: account.privateKey,
|
|
436
|
+
},
|
|
437
|
+
],
|
|
438
|
+
mnemonic,
|
|
439
|
+
});
|
|
440
|
+
} else if (chain == 'TRX') {
|
|
441
|
+
try {
|
|
442
|
+
const wallet = await tronWeb.createAccount();
|
|
443
|
+
|
|
444
|
+
Object.assign(result, {
|
|
445
|
+
addresses: [
|
|
446
|
+
{
|
|
447
|
+
index: 0,
|
|
448
|
+
address: wallet.address.base58,
|
|
449
|
+
privateKey: wallet.privateKey,
|
|
450
|
+
},
|
|
451
|
+
],
|
|
452
|
+
});
|
|
453
|
+
} catch (error) {
|
|
454
|
+
return {
|
|
455
|
+
error,
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
} else if (chain == 'XTZ') {
|
|
459
|
+
const wallet = tezos.generateKeysNoSeed();
|
|
460
|
+
|
|
461
|
+
Object.assign(result, {
|
|
462
|
+
addresses: [
|
|
463
|
+
{
|
|
464
|
+
index: 0,
|
|
465
|
+
address: wallet.pkh,
|
|
466
|
+
privateKey: wallet.sk,
|
|
467
|
+
},
|
|
468
|
+
],
|
|
469
|
+
});
|
|
470
|
+
} else {
|
|
471
|
+
return {
|
|
472
|
+
error: 'your desired blockchain is not supported yet',
|
|
473
|
+
};
|
|
364
474
|
}
|
|
475
|
+
|
|
476
|
+
if (row.tested !== undefined && row.tested == false) {
|
|
477
|
+
Object.assign(result, {
|
|
478
|
+
tested: false,
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
return result;
|
|
483
|
+
}
|
|
365
484
|
}
|
|
366
485
|
|
|
367
486
|
function generateMnemonicString() {
|
|
368
|
-
|
|
369
|
-
return bip39.generateMnemonic();
|
|
487
|
+
return bip39.generateMnemonic();
|
|
370
488
|
}
|
|
371
489
|
|
|
372
|
-
|
|
373
|
-
|
|
490
|
+
const _generateMnemonicString = generateMnemonicString;
|
|
491
|
+
export { _generateMnemonicString as generateMnemonicString };
|
|
492
|
+
const _Wallet = Wallet;
|
|
493
|
+
export { _Wallet as Wallet };
|