1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const bip32_1 = require("bip32");
|
4 | const bip39_1 = require("bip39");
|
5 | const managers_1 = require("../managers");
|
6 | class HDWallet {
|
7 | |
8 |
|
9 |
|
10 | static fromMnemonic(mnemonic, passphrase) {
|
11 | return bip32_1.fromSeed(bip39_1.mnemonicToSeedSync(mnemonic, passphrase), managers_1.configManager.get("network"));
|
12 | }
|
13 | |
14 |
|
15 |
|
16 | static fromKeys(keys, chainCode) {
|
17 | if (!keys.compressed) {
|
18 | throw new TypeError("BIP32 only allows compressed keys.");
|
19 | }
|
20 | return bip32_1.fromPrivateKey(Buffer.from(keys.privateKey, "hex"), chainCode, managers_1.configManager.get("network"));
|
21 | }
|
22 | |
23 |
|
24 |
|
25 | static getKeys(node) {
|
26 | return {
|
27 | publicKey: node.publicKey.toString("hex"),
|
28 | privateKey: node.privateKey.toString("hex"),
|
29 | compressed: true,
|
30 | };
|
31 | }
|
32 | |
33 |
|
34 |
|
35 | static deriveSlip44(root, hardened = true) {
|
36 | return root.derivePath(`m/44'/${this.slip44}${hardened ? "'" : ""}`);
|
37 | }
|
38 | |
39 |
|
40 |
|
41 | static deriveNetwork(root) {
|
42 | return this.deriveSlip44(root).deriveHardened(managers_1.configManager.get("network.aip20") || 1);
|
43 | }
|
44 | }
|
45 | HDWallet.slip44 = 111;
|
46 | exports.HDWallet = HDWallet;
|
47 |
|
\ | No newline at end of file |