@rabby-wallet/eth-hd-keyring 4.3.2-beta → 4.3.3-beta.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/dist/index.d.ts +5 -5
- package/dist/index.js +121 -98
- package/index.ts +12 -12
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -63,8 +63,8 @@ declare class HdKeyring extends SimpleKeyring {
|
|
|
63
63
|
publicKey: string;
|
|
64
64
|
isSlip39: boolean;
|
|
65
65
|
}>;
|
|
66
|
-
deserialize(opts?: DeserializeOption):
|
|
67
|
-
initFromMnemonic(mnemonic: string, passphrase?: string): void
|
|
66
|
+
deserialize(opts?: DeserializeOption): Promise<any[]>;
|
|
67
|
+
initFromMnemonic(mnemonic: string, passphrase?: string): Promise<void>;
|
|
68
68
|
private calcBasePublicKey;
|
|
69
69
|
addAccounts(numberOfAccounts?: number): Promise<string[]>;
|
|
70
70
|
activeAccounts(indexes: number[]): string[];
|
|
@@ -95,16 +95,16 @@ declare class HdKeyring extends SimpleKeyring {
|
|
|
95
95
|
private getChildForIndex;
|
|
96
96
|
private isLedgerLiveHdPath;
|
|
97
97
|
private getPathForIndex;
|
|
98
|
-
setPassphrase(passphrase: string): void
|
|
98
|
+
setPassphrase(passphrase: string): Promise<void>;
|
|
99
99
|
/**
|
|
100
100
|
* if passphrase is correct, the publicKey will be the same as the stored one
|
|
101
101
|
*/
|
|
102
|
-
checkPassphrase(passphrase: string): boolean
|
|
102
|
+
checkPassphrase(passphrase: string): Promise<boolean>;
|
|
103
103
|
setAccountDetail: (address: string, accountDetail: AccountDetail) => void;
|
|
104
104
|
getAccountDetail: (address: string) => AccountDetail;
|
|
105
105
|
private getHDPathBase;
|
|
106
106
|
setHDPathType(hdPathType: HDPathType): Promise<void>;
|
|
107
|
-
getSeed(mnemonic: string, passphrase?: string): Uint8Array
|
|
107
|
+
getSeed(mnemonic: string, passphrase?: string): Promise<Uint8Array>;
|
|
108
108
|
slip39MnemonicToSeedSync(mnemonic: string, passphrase?: string): Uint8Array;
|
|
109
109
|
static checkMnemonicIsSlip39(mnemonic: string): boolean;
|
|
110
110
|
static slip39GetThreshold(shares: string[]): number;
|
package/dist/index.js
CHANGED
|
@@ -45,7 +45,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
45
45
|
mod
|
|
46
46
|
));
|
|
47
47
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
48
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
49
48
|
var __async = (__this, __arguments, generator) => {
|
|
50
49
|
return new Promise((resolve, reject) => {
|
|
51
50
|
var fulfilled = (value) => {
|
|
@@ -100,20 +99,38 @@ var require_slip39_helper = __commonJS({
|
|
|
100
99
|
var ROUND_COUNT = 4;
|
|
101
100
|
var DIGEST_INDEX = 254;
|
|
102
101
|
var SECRET_INDEX = 255;
|
|
103
|
-
|
|
102
|
+
String.prototype.slip39EncodeHex = function() {
|
|
104
103
|
let bytes = [];
|
|
105
|
-
for (let i = 0; i <
|
|
106
|
-
bytes.push(
|
|
104
|
+
for (let i = 0; i < this.length; ++i) {
|
|
105
|
+
bytes.push(this.charCodeAt(i));
|
|
107
106
|
}
|
|
108
107
|
return bytes;
|
|
109
108
|
};
|
|
110
|
-
|
|
111
|
-
let
|
|
112
|
-
const
|
|
109
|
+
Array.prototype.slip39DecodeHex = function() {
|
|
110
|
+
let str = [];
|
|
111
|
+
const hex = this.toString().split(",");
|
|
112
|
+
for (let i = 0; i < hex.length; i++) {
|
|
113
|
+
str.push(String.fromCharCode(hex[i]));
|
|
114
|
+
}
|
|
115
|
+
return str.toString().replace(/,/g, "");
|
|
116
|
+
};
|
|
117
|
+
Array.prototype.slip39Generate = function(m, v = (_) => _) {
|
|
118
|
+
let n = m || this.length;
|
|
113
119
|
for (let i = 0; i < n; i++) {
|
|
114
|
-
|
|
120
|
+
this[i] = v(i);
|
|
121
|
+
}
|
|
122
|
+
return this;
|
|
123
|
+
};
|
|
124
|
+
Array.prototype.toHexString = function() {
|
|
125
|
+
return Array.prototype.map.call(this, function(byte) {
|
|
126
|
+
return ("0" + (byte & 255).toString(16)).slice(-2);
|
|
127
|
+
}).join("");
|
|
128
|
+
};
|
|
129
|
+
Array.prototype.toByteArray = function(hexString) {
|
|
130
|
+
for (let i = 0; i < hexString.length; i = i + 2) {
|
|
131
|
+
this.push(parseInt(hexString.substr(i, 2), 16));
|
|
115
132
|
}
|
|
116
|
-
return
|
|
133
|
+
return this;
|
|
117
134
|
};
|
|
118
135
|
var BIGINT_WORD_BITS = BigInt(8);
|
|
119
136
|
function decodeBigInt(bytes) {
|
|
@@ -179,9 +196,9 @@ var require_slip39_helper = __commonJS({
|
|
|
179
196
|
}
|
|
180
197
|
let IL = masterSecret.slice().slice(0, masterSecret.length / 2);
|
|
181
198
|
let IR = masterSecret.slice().slice(masterSecret.length / 2);
|
|
182
|
-
const pwd = slip39EncodeHex(
|
|
199
|
+
const pwd = passphrase.slip39EncodeHex();
|
|
183
200
|
const salt = getSalt(identifier, extendableBackupFlag);
|
|
184
|
-
let range = slip39Generate(ROUND_COUNT);
|
|
201
|
+
let range = Array().slip39Generate(ROUND_COUNT);
|
|
185
202
|
range = encrypt ? range : range.reverse();
|
|
186
203
|
range.forEach((round) => {
|
|
187
204
|
const f = roundFunction(round, pwd, iterationExponent, salt, IR);
|
|
@@ -215,7 +232,7 @@ var require_slip39_helper = __commonJS({
|
|
|
215
232
|
);
|
|
216
233
|
}
|
|
217
234
|
if (threshold === 1) {
|
|
218
|
-
return slip39Generate(shareCount, () => sharedSecret);
|
|
235
|
+
return Array().slip39Generate(shareCount, () => sharedSecret);
|
|
219
236
|
}
|
|
220
237
|
const randomShareCount = threshold - 2;
|
|
221
238
|
const randomPart = randomBytes(sharedSecret.length - DIGEST_LENGTH);
|
|
@@ -223,7 +240,7 @@ var require_slip39_helper = __commonJS({
|
|
|
223
240
|
let baseShares = /* @__PURE__ */ new Map();
|
|
224
241
|
let shares = [];
|
|
225
242
|
if (randomShareCount) {
|
|
226
|
-
shares = slip39Generate(
|
|
243
|
+
shares = Array().slip39Generate(
|
|
227
244
|
randomShareCount,
|
|
228
245
|
() => randomBytes(sharedSecret.length)
|
|
229
246
|
);
|
|
@@ -252,13 +269,13 @@ var require_slip39_helper = __commonJS({
|
|
|
252
269
|
`Invalid padding in mnemonic or insufficient length of mnemonics (${a.length} or ${b.length})`
|
|
253
270
|
);
|
|
254
271
|
}
|
|
255
|
-
return slip39Generate(a.length, (i) => a[i] ^ b[i]);
|
|
272
|
+
return Array().slip39Generate(a.length, (i) => a[i] ^ b[i]);
|
|
256
273
|
}
|
|
257
274
|
function getSalt(identifier, extendableBackupFlag) {
|
|
258
275
|
if (extendableBackupFlag) {
|
|
259
276
|
return [];
|
|
260
277
|
} else {
|
|
261
|
-
const salt = slip39EncodeHex(
|
|
278
|
+
const salt = CUSTOMIZATION_STRING_NON_EXTENDABLE.slip39EncodeHex();
|
|
262
279
|
return salt.concat(identifier);
|
|
263
280
|
}
|
|
264
281
|
}
|
|
@@ -282,7 +299,7 @@ var require_slip39_helper = __commonJS({
|
|
|
282
299
|
shares.forEach((v, k) => {
|
|
283
300
|
logProd = logProd + LOG_TABLE[k ^ x];
|
|
284
301
|
});
|
|
285
|
-
let results = slip39Generate(
|
|
302
|
+
let results = Array().slip39Generate(
|
|
286
303
|
sharesValueLengths.values().next().value,
|
|
287
304
|
() => 0
|
|
288
305
|
);
|
|
@@ -331,14 +348,14 @@ var require_slip39_helper = __commonJS({
|
|
|
331
348
|
return extendableBackupFlag ? CUSTOMIZATION_STRING_EXTENDABLE : CUSTOMIZATION_STRING_NON_EXTENDABLE;
|
|
332
349
|
}
|
|
333
350
|
function rs1024CreateChecksum(data, extendableBackupFlag) {
|
|
334
|
-
const values =
|
|
351
|
+
const values = get_customization_string(extendableBackupFlag).slip39EncodeHex().concat(data).concat(Array().slip39Generate(CHECKSUM_WORDS_LENGTH, () => 0));
|
|
335
352
|
const polymod = rs1024Polymod(values) ^ 1;
|
|
336
|
-
const result = slip39Generate(CHECKSUM_WORDS_LENGTH, (i) => polymod >> 10 * i & 1023).reverse();
|
|
353
|
+
const result = Array().slip39Generate(CHECKSUM_WORDS_LENGTH, (i) => polymod >> 10 * i & 1023).reverse();
|
|
337
354
|
return result;
|
|
338
355
|
}
|
|
339
356
|
function rs1024VerifyChecksum(data, extendableBackupFlag) {
|
|
340
357
|
return rs1024Polymod(
|
|
341
|
-
|
|
358
|
+
get_customization_string(extendableBackupFlag).slip39EncodeHex().concat(data)
|
|
342
359
|
) === 1;
|
|
343
360
|
}
|
|
344
361
|
function intFromIndices(indices) {
|
|
@@ -351,7 +368,7 @@ var require_slip39_helper = __commonJS({
|
|
|
351
368
|
}
|
|
352
369
|
function intToIndices(value, length, bits) {
|
|
353
370
|
const mask = BigInt((1 << bits) - 1);
|
|
354
|
-
const result = slip39Generate(
|
|
371
|
+
const result = Array().slip39Generate(
|
|
355
372
|
length,
|
|
356
373
|
(i) => parseInt(value >> BigInt(i) * BigInt(bits) & mask, 10)
|
|
357
374
|
);
|
|
@@ -2163,9 +2180,7 @@ var require_slip39_helper = __commonJS({
|
|
|
2163
2180
|
combineMnemonics,
|
|
2164
2181
|
crypt,
|
|
2165
2182
|
bitsToBytes,
|
|
2166
|
-
WORD_LIST
|
|
2167
|
-
decodeMnemonics,
|
|
2168
|
-
decodeMnemonic
|
|
2183
|
+
WORD_LIST
|
|
2169
2184
|
};
|
|
2170
2185
|
}
|
|
2171
2186
|
});
|
|
@@ -2192,7 +2207,7 @@ var require_slip39 = __commonJS({
|
|
|
2192
2207
|
return result;
|
|
2193
2208
|
}
|
|
2194
2209
|
};
|
|
2195
|
-
var
|
|
2210
|
+
var Slip39 = class _Slip39 {
|
|
2196
2211
|
constructor({
|
|
2197
2212
|
iterationExponent = 0,
|
|
2198
2213
|
extendableBackupFlag = 0,
|
|
@@ -2349,10 +2364,6 @@ var require_slip39 = __commonJS({
|
|
|
2349
2364
|
return result;
|
|
2350
2365
|
}
|
|
2351
2366
|
};
|
|
2352
|
-
__publicField(_Slip39, "decodeMnemonics", slipHelper.decodeMnemonics);
|
|
2353
|
-
__publicField(_Slip39, "decodeMnemonic", slipHelper.decodeMnemonic);
|
|
2354
|
-
__publicField(_Slip39, "combineMnemonics", slipHelper.combineMnemonics);
|
|
2355
|
-
var Slip39 = _Slip39;
|
|
2356
2367
|
exports2 = module2.exports = Slip39;
|
|
2357
2368
|
}
|
|
2358
2369
|
});
|
|
@@ -2434,34 +2445,38 @@ var _HdKeyring = class _HdKeyring extends import_eth_simple_keyring.default {
|
|
|
2434
2445
|
isSlip39: this.isSlip39
|
|
2435
2446
|
});
|
|
2436
2447
|
}
|
|
2437
|
-
deserialize(
|
|
2438
|
-
this
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2448
|
+
deserialize() {
|
|
2449
|
+
return __async(this, arguments, function* (opts = {}) {
|
|
2450
|
+
this.wallets = [];
|
|
2451
|
+
this.mnemonic = null;
|
|
2452
|
+
this.hdPath = opts.hdPath || HD_PATH_BASE["BIP44" /* BIP44 */];
|
|
2453
|
+
this.byImport = !!opts.byImport;
|
|
2454
|
+
this.index = opts.index || 0;
|
|
2455
|
+
this.needPassphrase = opts.needPassphrase || !!opts.passphrase;
|
|
2456
|
+
this.passphrase = opts.passphrase;
|
|
2457
|
+
this.accounts = opts.accounts || [];
|
|
2458
|
+
this.accountDetails = opts.accountDetails || {};
|
|
2459
|
+
this.publicKey = opts.publicKey || "";
|
|
2460
|
+
this.isSlip39 = opts.isSlip39 || false;
|
|
2461
|
+
if (opts.mnemonic) {
|
|
2462
|
+
this.mnemonic = opts.mnemonic;
|
|
2463
|
+
yield this.setPassphrase(opts.passphrase || "");
|
|
2464
|
+
}
|
|
2465
|
+
if (!this.accounts.length && opts.activeIndexes) {
|
|
2466
|
+
return this.activeAccounts(opts.activeIndexes);
|
|
2467
|
+
}
|
|
2468
|
+
return Promise.resolve([]);
|
|
2469
|
+
});
|
|
2457
2470
|
}
|
|
2458
2471
|
initFromMnemonic(mnemonic, passphrase) {
|
|
2459
|
-
this
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2472
|
+
return __async(this, null, function* () {
|
|
2473
|
+
this.mnemonic = mnemonic;
|
|
2474
|
+
const seed = yield this.getSeed(mnemonic, passphrase);
|
|
2475
|
+
this.hdWallet = import_hdkey.HDKey.fromMasterSeed(seed);
|
|
2476
|
+
if (!this.publicKey) {
|
|
2477
|
+
this.publicKey = this.calcBasePublicKey(this.hdWallet);
|
|
2478
|
+
}
|
|
2479
|
+
});
|
|
2465
2480
|
}
|
|
2466
2481
|
calcBasePublicKey(hdKey) {
|
|
2467
2482
|
return (0, import_util.bytesToHex)(
|
|
@@ -2469,33 +2484,35 @@ var _HdKeyring = class _HdKeyring extends import_eth_simple_keyring.default {
|
|
|
2469
2484
|
);
|
|
2470
2485
|
}
|
|
2471
2486
|
addAccounts(numberOfAccounts = 1) {
|
|
2472
|
-
|
|
2473
|
-
this.
|
|
2474
|
-
|
|
2475
|
-
let count = numberOfAccounts;
|
|
2476
|
-
let currentIdx = 0;
|
|
2477
|
-
const addresses = [];
|
|
2478
|
-
while (count) {
|
|
2479
|
-
const [address, wallet] = this._addressFromIndex(currentIdx);
|
|
2480
|
-
if (this.wallets.find(
|
|
2481
|
-
(w) => (0, import_util.bytesToHex)(w.publicKey) === (0, import_util.bytesToHex)(wallet.publicKey)
|
|
2482
|
-
)) {
|
|
2483
|
-
currentIdx++;
|
|
2484
|
-
} else {
|
|
2485
|
-
this.wallets.push(wallet);
|
|
2486
|
-
addresses.push(address);
|
|
2487
|
-
this.setAccountDetail(address, {
|
|
2488
|
-
hdPath: this.hdPath,
|
|
2489
|
-
hdPathType: HD_PATH_TYPE[this.hdPath],
|
|
2490
|
-
index: currentIdx
|
|
2491
|
-
});
|
|
2492
|
-
count--;
|
|
2487
|
+
return __async(this, null, function* () {
|
|
2488
|
+
if (!this.hdWallet) {
|
|
2489
|
+
yield this.initFromMnemonic(bip39.generateMnemonic(import_english.wordlist));
|
|
2493
2490
|
}
|
|
2494
|
-
|
|
2495
|
-
|
|
2491
|
+
let count = numberOfAccounts;
|
|
2492
|
+
let currentIdx = 0;
|
|
2493
|
+
const addresses = [];
|
|
2494
|
+
while (count) {
|
|
2495
|
+
const [address, wallet] = this._addressFromIndex(currentIdx);
|
|
2496
|
+
if (this.wallets.find(
|
|
2497
|
+
(w) => (0, import_util.bytesToHex)(w.publicKey) === (0, import_util.bytesToHex)(wallet.publicKey)
|
|
2498
|
+
)) {
|
|
2499
|
+
currentIdx++;
|
|
2500
|
+
} else {
|
|
2501
|
+
this.wallets.push(wallet);
|
|
2502
|
+
addresses.push(address);
|
|
2503
|
+
this.setAccountDetail(address, {
|
|
2504
|
+
hdPath: this.hdPath,
|
|
2505
|
+
hdPathType: HD_PATH_TYPE[this.hdPath],
|
|
2506
|
+
index: currentIdx
|
|
2507
|
+
});
|
|
2508
|
+
count--;
|
|
2509
|
+
}
|
|
2510
|
+
if (!this.accounts.includes(address)) {
|
|
2511
|
+
this.accounts.push(address);
|
|
2512
|
+
}
|
|
2496
2513
|
}
|
|
2497
|
-
|
|
2498
|
-
|
|
2514
|
+
return Promise.resolve(addresses);
|
|
2515
|
+
});
|
|
2499
2516
|
}
|
|
2500
2517
|
activeAccounts(indexes) {
|
|
2501
2518
|
const accounts = [];
|
|
@@ -2628,27 +2645,31 @@ var _HdKeyring = class _HdKeyring extends import_eth_simple_keyring.default {
|
|
|
2628
2645
|
return this.isLedgerLiveHdPath() ? `m/44'/60'/${index}'/0/0` : `${this.hdPath}/${index}`;
|
|
2629
2646
|
}
|
|
2630
2647
|
setPassphrase(passphrase) {
|
|
2631
|
-
this
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
const
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2648
|
+
return __async(this, null, function* () {
|
|
2649
|
+
this.passphrase = passphrase;
|
|
2650
|
+
yield this.initFromMnemonic(this.mnemonic, passphrase);
|
|
2651
|
+
for (const acc of this.accounts) {
|
|
2652
|
+
const detail = this.getAccountDetail(acc);
|
|
2653
|
+
if (detail) {
|
|
2654
|
+
this.setHdPath(detail.hdPath);
|
|
2655
|
+
const [address, wallet] = this._addressFromIndex(detail.index);
|
|
2656
|
+
if (address.toLowerCase() === acc.toLowerCase()) {
|
|
2657
|
+
this.wallets.push(wallet);
|
|
2658
|
+
}
|
|
2640
2659
|
}
|
|
2641
2660
|
}
|
|
2642
|
-
}
|
|
2661
|
+
});
|
|
2643
2662
|
}
|
|
2644
2663
|
/**
|
|
2645
2664
|
* if passphrase is correct, the publicKey will be the same as the stored one
|
|
2646
2665
|
*/
|
|
2647
2666
|
checkPassphrase(passphrase) {
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2667
|
+
return __async(this, null, function* () {
|
|
2668
|
+
const seed = yield this.getSeed(this.mnemonic, passphrase);
|
|
2669
|
+
const hdWallet = import_hdkey.HDKey.fromMasterSeed(seed);
|
|
2670
|
+
const publicKey = this.calcBasePublicKey(hdWallet);
|
|
2671
|
+
return this.publicKey === publicKey;
|
|
2672
|
+
});
|
|
2652
2673
|
}
|
|
2653
2674
|
getHDPathBase(hdPathType) {
|
|
2654
2675
|
return HD_PATH_BASE[hdPathType];
|
|
@@ -2660,11 +2681,13 @@ var _HdKeyring = class _HdKeyring extends import_eth_simple_keyring.default {
|
|
|
2660
2681
|
});
|
|
2661
2682
|
}
|
|
2662
2683
|
getSeed(mnemonic, passphrase) {
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2684
|
+
return __async(this, null, function* () {
|
|
2685
|
+
if (_HdKeyring.checkMnemonicIsSlip39(mnemonic)) {
|
|
2686
|
+
this.isSlip39 = true;
|
|
2687
|
+
return this.slip39MnemonicToSeedSync(mnemonic, passphrase);
|
|
2688
|
+
}
|
|
2689
|
+
return bip39.mnemonicToSeed(mnemonic, passphrase);
|
|
2690
|
+
});
|
|
2668
2691
|
}
|
|
2669
2692
|
slip39MnemonicToSeedSync(mnemonic, passphrase) {
|
|
2670
2693
|
const secretShares = mnemonic.split("\n");
|
package/index.ts
CHANGED
|
@@ -103,7 +103,7 @@ class HdKeyring extends SimpleKeyring {
|
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
deserialize(opts: DeserializeOption = {} as any) {
|
|
106
|
+
async deserialize(opts: DeserializeOption = {} as any) {
|
|
107
107
|
this.wallets = [];
|
|
108
108
|
this.mnemonic = null;
|
|
109
109
|
this.hdPath = opts.hdPath || HD_PATH_BASE[HDPathType.BIP44];
|
|
@@ -118,7 +118,7 @@ class HdKeyring extends SimpleKeyring {
|
|
|
118
118
|
|
|
119
119
|
if (opts.mnemonic) {
|
|
120
120
|
this.mnemonic = opts.mnemonic;
|
|
121
|
-
this.setPassphrase(opts.passphrase || '');
|
|
121
|
+
await this.setPassphrase(opts.passphrase || '');
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
// activeIndexes is deprecated, if accounts is not empty, use accounts
|
|
@@ -129,9 +129,9 @@ class HdKeyring extends SimpleKeyring {
|
|
|
129
129
|
return Promise.resolve([]);
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
initFromMnemonic(mnemonic: string, passphrase?: string) {
|
|
132
|
+
async initFromMnemonic(mnemonic: string, passphrase?: string) {
|
|
133
133
|
this.mnemonic = mnemonic;
|
|
134
|
-
const seed = this.getSeed(mnemonic, passphrase);
|
|
134
|
+
const seed = await this.getSeed(mnemonic, passphrase);
|
|
135
135
|
this.hdWallet = HDKey.fromMasterSeed(seed);
|
|
136
136
|
if (!this.publicKey) {
|
|
137
137
|
this.publicKey = this.calcBasePublicKey(this.hdWallet!);
|
|
@@ -144,9 +144,9 @@ class HdKeyring extends SimpleKeyring {
|
|
|
144
144
|
);
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
addAccounts(numberOfAccounts = 1) {
|
|
147
|
+
async addAccounts(numberOfAccounts = 1) {
|
|
148
148
|
if (!this.hdWallet) {
|
|
149
|
-
this.initFromMnemonic(bip39.generateMnemonic(wordlist));
|
|
149
|
+
await this.initFromMnemonic(bip39.generateMnemonic(wordlist));
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
let count = numberOfAccounts;
|
|
@@ -347,9 +347,9 @@ class HdKeyring extends SimpleKeyring {
|
|
|
347
347
|
: `${this.hdPath}/${index}`;
|
|
348
348
|
}
|
|
349
349
|
|
|
350
|
-
setPassphrase(passphrase: string) {
|
|
350
|
+
async setPassphrase(passphrase: string) {
|
|
351
351
|
this.passphrase = passphrase;
|
|
352
|
-
this.initFromMnemonic(this.mnemonic, passphrase);
|
|
352
|
+
await this.initFromMnemonic(this.mnemonic, passphrase);
|
|
353
353
|
|
|
354
354
|
for (const acc of this.accounts) {
|
|
355
355
|
const detail = this.getAccountDetail(acc);
|
|
@@ -366,8 +366,8 @@ class HdKeyring extends SimpleKeyring {
|
|
|
366
366
|
/**
|
|
367
367
|
* if passphrase is correct, the publicKey will be the same as the stored one
|
|
368
368
|
*/
|
|
369
|
-
checkPassphrase(passphrase: string) {
|
|
370
|
-
const seed = this.getSeed(this.mnemonic!, passphrase);
|
|
369
|
+
async checkPassphrase(passphrase: string) {
|
|
370
|
+
const seed = await this.getSeed(this.mnemonic!, passphrase);
|
|
371
371
|
const hdWallet = HDKey.fromMasterSeed(seed);
|
|
372
372
|
const publicKey = this.calcBasePublicKey(hdWallet);
|
|
373
373
|
|
|
@@ -394,12 +394,12 @@ class HdKeyring extends SimpleKeyring {
|
|
|
394
394
|
this.setHdPath(hdPath);
|
|
395
395
|
}
|
|
396
396
|
|
|
397
|
-
getSeed(mnemonic: string, passphrase?: string) {
|
|
397
|
+
async getSeed(mnemonic: string, passphrase?: string) {
|
|
398
398
|
if (HdKeyring.checkMnemonicIsSlip39(mnemonic)) {
|
|
399
399
|
this.isSlip39 = true;
|
|
400
400
|
return this.slip39MnemonicToSeedSync(mnemonic, passphrase);
|
|
401
401
|
}
|
|
402
|
-
return bip39.
|
|
402
|
+
return bip39.mnemonicToSeed(mnemonic, passphrase);
|
|
403
403
|
}
|
|
404
404
|
|
|
405
405
|
slip39MnemonicToSeedSync(mnemonic: string, passphrase?: string) {
|