@rabby-wallet/eth-hd-keyring 3.6.11 → 3.6.12

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 (3) hide show
  1. package/dist/index.js +14 -0
  2. package/index.ts +18 -0
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -53,6 +53,7 @@ class HdKeyring extends eth_simple_keyring_1.default {
53
53
  this.page = 0;
54
54
  this.perPage = 5;
55
55
  this.byImport = false;
56
+ this.publicKey = '';
56
57
  this.deserialize(opts);
57
58
  }
58
59
  serialize() {
@@ -62,6 +63,7 @@ class HdKeyring extends eth_simple_keyring_1.default {
62
63
  hdPath: this.hdPath,
63
64
  byImport: this.byImport,
64
65
  index: this.index,
66
+ publicKey: this.publicKey,
65
67
  });
66
68
  }
67
69
  deserialize(opts = {}) {
@@ -71,6 +73,7 @@ class HdKeyring extends eth_simple_keyring_1.default {
71
73
  this.hdPath = opts.hdPath || hdPathString;
72
74
  this.byImport = !!opts.byImport;
73
75
  this.index = opts.index || 0;
76
+ this.publicKey = opts.publicKey || '';
74
77
  if (opts.mnemonic) {
75
78
  this.initFromMnemonic(opts.mnemonic);
76
79
  }
@@ -79,12 +82,23 @@ class HdKeyring extends eth_simple_keyring_1.default {
79
82
  }
80
83
  return Promise.resolve([]);
81
84
  }
85
+ initPublicKey() {
86
+ this.root = this.hdWallet.derivePath(this.hdPath);
87
+ const wallet = this.root.getWallet();
88
+ this.publicKey = wallet.getPublicKey().toString('hex');
89
+ }
90
+ getPublicKey() {
91
+ return this.publicKey;
92
+ }
82
93
  initFromMnemonic(mnemonic) {
83
94
  this.mnemonic = mnemonic;
84
95
  this._index2wallet = {};
85
96
  const seed = bip39.mnemonicToSeedSync(mnemonic);
86
97
  this.hdWallet = ethereumjs_wallet_1.hdkey.fromMasterSeed(seed);
87
98
  this.root = this.hdWallet.derivePath(this.hdPath);
99
+ if (!this.publicKey) {
100
+ this.initPublicKey();
101
+ }
88
102
  }
89
103
  addAccounts(numberOfAccounts = 1) {
90
104
  if (!this.root) {
package/index.ts CHANGED
@@ -13,6 +13,7 @@ interface DeserializeOption {
13
13
  activeIndexes?: number[];
14
14
  byImport?: boolean;
15
15
  index?: number;
16
+ publicKey?: string;
16
17
  }
17
18
 
18
19
  class HdKeyring extends SimpleKeyring {
@@ -30,6 +31,7 @@ class HdKeyring extends SimpleKeyring {
30
31
  page = 0;
31
32
  perPage = 5;
32
33
  byImport = false;
34
+ publicKey: string = '';
33
35
 
34
36
  /* PUBLIC METHODS */
35
37
  constructor(opts = {}) {
@@ -44,6 +46,7 @@ class HdKeyring extends SimpleKeyring {
44
46
  hdPath: this.hdPath,
45
47
  byImport: this.byImport,
46
48
  index: this.index,
49
+ publicKey: this.publicKey,
47
50
  });
48
51
  }
49
52
 
@@ -54,6 +57,7 @@ class HdKeyring extends SimpleKeyring {
54
57
  this.hdPath = opts.hdPath || hdPathString;
55
58
  this.byImport = !!opts.byImport;
56
59
  this.index = opts.index || 0;
60
+ this.publicKey = opts.publicKey || '';
57
61
 
58
62
  if (opts.mnemonic) {
59
63
  this.initFromMnemonic(opts.mnemonic);
@@ -66,12 +70,26 @@ class HdKeyring extends SimpleKeyring {
66
70
  return Promise.resolve([]);
67
71
  }
68
72
 
73
+ private initPublicKey() {
74
+ this.root = this.hdWallet!.derivePath(this.hdPath);
75
+ const wallet = this.root.getWallet();
76
+ this.publicKey = wallet.getPublicKey().toString('hex');
77
+ }
78
+
79
+ getPublicKey() {
80
+ return this.publicKey;
81
+ }
82
+
69
83
  initFromMnemonic(mnemonic) {
70
84
  this.mnemonic = mnemonic;
71
85
  this._index2wallet = {};
72
86
  const seed = bip39.mnemonicToSeedSync(mnemonic);
73
87
  this.hdWallet = hdkey.fromMasterSeed(seed);
74
88
  this.root = this.hdWallet!.derivePath(this.hdPath);
89
+
90
+ if (!this.publicKey) {
91
+ this.initPublicKey();
92
+ }
75
93
  }
76
94
 
77
95
  addAccounts(numberOfAccounts = 1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/eth-hd-keyring",
3
- "version": "3.6.11",
3
+ "version": "3.6.12",
4
4
  "description": "A simple standard interface for a seed phrase generated set of Ethereum accounts.",
5
5
  "keywords": [
6
6
  "ethereum",