@yerofey/cryptowallet-cli 1.43.1 â 1.43.2
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/cli.js +2 -1
- package/package.json +1 -1
- package/src/Method.js +47 -7
- package/src/chains/DOGE.json +1 -1
package/cli.js
CHANGED
|
@@ -60,9 +60,10 @@ if (options.list) {
|
|
|
60
60
|
// generate mnemonic string (12/15/18/21/24 words)
|
|
61
61
|
if (isMnemonicString) {
|
|
62
62
|
(async () => {
|
|
63
|
-
new Method('mnemonic').init({
|
|
63
|
+
await new Method('mnemonic').init({
|
|
64
64
|
mnemonic: options.mnemonic,
|
|
65
65
|
copy: options?.copy || false,
|
|
66
|
+
chain: options.chain,
|
|
66
67
|
});
|
|
67
68
|
exit(0);
|
|
68
69
|
})();
|
package/package.json
CHANGED
package/src/Method.js
CHANGED
|
@@ -6,6 +6,7 @@ import columnify from 'columnify';
|
|
|
6
6
|
import CsvWriter from 'csv-writer';
|
|
7
7
|
import qr from 'qrcode-terminal';
|
|
8
8
|
import CW from './CW.js';
|
|
9
|
+
import { mnemonicNew as newTonMnemonic } from '@ton/crypto';
|
|
9
10
|
import { generateMnemonicString } from './Wallet.js';
|
|
10
11
|
import { log, supportedChains, loadJson } from './utils.js';
|
|
11
12
|
|
|
@@ -32,6 +33,19 @@ const pkg = await loadJson(
|
|
|
32
33
|
const _version = pkg['version'] || 0;
|
|
33
34
|
|
|
34
35
|
class Method {
|
|
36
|
+
static mnemonicGenerators = {
|
|
37
|
+
TON: {
|
|
38
|
+
defaultLength: 24,
|
|
39
|
+
resolveLength: () => 24,
|
|
40
|
+
generate: async () => (await newTonMnemonic()).join(' '),
|
|
41
|
+
},
|
|
42
|
+
DEFAULT: {
|
|
43
|
+
defaultLength: 12,
|
|
44
|
+
allowedLengths: ['12', '15', '18', '21', '24'],
|
|
45
|
+
generate: async (length) => generateMnemonicString(length),
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
35
49
|
constructor(name, params = {}) {
|
|
36
50
|
this.name = name;
|
|
37
51
|
this.params = params;
|
|
@@ -50,6 +64,30 @@ class Method {
|
|
|
50
64
|
};
|
|
51
65
|
}
|
|
52
66
|
|
|
67
|
+
_getMnemonicGenerator(chain) {
|
|
68
|
+
return Method.mnemonicGenerators[chain] || Method.mnemonicGenerators.DEFAULT;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
_resolveMnemonicLength(chain, mnemonicValue) {
|
|
72
|
+
const generator = this._getMnemonicGenerator(chain);
|
|
73
|
+
if (typeof generator.resolveLength === 'function') {
|
|
74
|
+
return generator.resolveLength(mnemonicValue);
|
|
75
|
+
}
|
|
76
|
+
const mnemonic = mnemonicValue || `${generator.defaultLength || 12}`;
|
|
77
|
+
const allowed =
|
|
78
|
+
generator.allowedLengths || ['12', '15', '18', '21', '24'];
|
|
79
|
+
return allowed.includes(mnemonic)
|
|
80
|
+
? parseInt(mnemonic, 10)
|
|
81
|
+
: generator.defaultLength || 12;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async _generateMnemonic(chain, mnemonicValue) {
|
|
85
|
+
const generator = this._getMnemonicGenerator(chain);
|
|
86
|
+
const length = this._resolveMnemonicLength(chain, mnemonicValue);
|
|
87
|
+
const mnemonicString = await generator.generate(length);
|
|
88
|
+
return { length, mnemonicString };
|
|
89
|
+
}
|
|
90
|
+
|
|
53
91
|
async _list() {
|
|
54
92
|
log(`đ All supported chains & tickers:\n`);
|
|
55
93
|
let cryptos = {};
|
|
@@ -77,12 +115,10 @@ class Method {
|
|
|
77
115
|
log(`âšī¸ Use flag "-c TICKER" to select specific chain or ticker`);
|
|
78
116
|
}
|
|
79
117
|
|
|
80
|
-
_mnemonic() {
|
|
81
|
-
const
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
: 12;
|
|
85
|
-
const mnemonicString = generateMnemonicString(mnemonicLength);
|
|
118
|
+
async _mnemonic() {
|
|
119
|
+
const chain = (this.inputOptions.chain || '').toString().toUpperCase();
|
|
120
|
+
const { length: mnemonicLength, mnemonicString } =
|
|
121
|
+
await this._generateMnemonic(chain, this.inputOptions.mnemonic);
|
|
86
122
|
|
|
87
123
|
log(
|
|
88
124
|
`⨠${green('Done!')} ${blueBright(
|
|
@@ -147,7 +183,11 @@ class Method {
|
|
|
147
183
|
);
|
|
148
184
|
}
|
|
149
185
|
|
|
150
|
-
if (
|
|
186
|
+
if (
|
|
187
|
+
cw.options.mnemonic != '' &&
|
|
188
|
+
cw.wallet.mnemonic == undefined &&
|
|
189
|
+
cw.wallet.error === undefined
|
|
190
|
+
) {
|
|
151
191
|
log(
|
|
152
192
|
`đĸ ${yellow(
|
|
153
193
|
'Sorry, ' + chainFullName + ' does not support mnemonic yet...'
|