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

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.js CHANGED
@@ -49,8 +49,10 @@ class HdKeyring extends eth_simple_keyring_1.default {
49
49
  this.wallets = [];
50
50
  this._index2wallet = {};
51
51
  this.activeIndexes = [];
52
+ this.index = 0;
52
53
  this.page = 0;
53
54
  this.perPage = 5;
55
+ this.byImport = false;
54
56
  this.deserialize(opts);
55
57
  }
56
58
  serialize() {
@@ -58,6 +60,8 @@ class HdKeyring extends eth_simple_keyring_1.default {
58
60
  mnemonic: this.mnemonic,
59
61
  activeIndexes: this.activeIndexes,
60
62
  hdPath: this.hdPath,
63
+ byImport: this.byImport,
64
+ index: this.index,
61
65
  });
62
66
  }
63
67
  deserialize(opts = {}) {
@@ -65,6 +69,8 @@ class HdKeyring extends eth_simple_keyring_1.default {
65
69
  this.mnemonic = null;
66
70
  this.root = null;
67
71
  this.hdPath = opts.hdPath || hdPathString;
72
+ this.byImport = !!opts.byImport;
73
+ this.index = opts.index || 0;
68
74
  if (opts.mnemonic) {
69
75
  this.initFromMnemonic(opts.mnemonic);
70
76
  }
@@ -137,6 +143,11 @@ class HdKeyring extends eth_simple_keyring_1.default {
137
143
  }
138
144
  return accounts;
139
145
  }
146
+ removeAccount(address) {
147
+ super.removeAccount(address);
148
+ const index = this.getIndexByAddress(address);
149
+ this.activeIndexes = this.activeIndexes.filter((i) => i !== index);
150
+ }
140
151
  __getPage(increment) {
141
152
  return __awaiter(this, void 0, void 0, function* () {
142
153
  this.page += increment;
package/index.ts CHANGED
@@ -11,6 +11,8 @@ interface DeserializeOption {
11
11
  hdPath?: string;
12
12
  mnemonic?: string;
13
13
  activeIndexes?: number[];
14
+ byImport?: boolean;
15
+ index?: number;
14
16
  }
15
17
 
16
18
  class HdKeyring extends SimpleKeyring {
@@ -24,8 +26,10 @@ class HdKeyring extends SimpleKeyring {
24
26
  wallets: Wallet[] = [];
25
27
  _index2wallet: Record<number, [string, Wallet]> = {};
26
28
  activeIndexes: number[] = [];
29
+ index = 0;
27
30
  page = 0;
28
31
  perPage = 5;
32
+ byImport = false;
29
33
 
30
34
  /* PUBLIC METHODS */
31
35
  constructor(opts = {}) {
@@ -38,6 +42,8 @@ class HdKeyring extends SimpleKeyring {
38
42
  mnemonic: this.mnemonic,
39
43
  activeIndexes: this.activeIndexes,
40
44
  hdPath: this.hdPath,
45
+ byImport: this.byImport,
46
+ index: this.index,
41
47
  });
42
48
  }
43
49
 
@@ -46,6 +52,8 @@ class HdKeyring extends SimpleKeyring {
46
52
  this.mnemonic = null;
47
53
  this.root = null;
48
54
  this.hdPath = opts.hdPath || hdPathString;
55
+ this.byImport = !!opts.byImport;
56
+ this.index = opts.index || 0;
49
57
 
50
58
  if (opts.mnemonic) {
51
59
  this.initFromMnemonic(opts.mnemonic);
@@ -132,10 +140,14 @@ class HdKeyring extends SimpleKeyring {
132
140
  }
133
141
  return accounts;
134
142
  }
135
-
136
- async __getPage(
137
- increment: number
138
- ): Promise<
143
+
144
+ removeAccount(address) {
145
+ super.removeAccount(address);
146
+ const index = this.getIndexByAddress(address);
147
+ this.activeIndexes = this.activeIndexes.filter((i) => i !== index);
148
+ }
149
+
150
+ async __getPage(increment: number): Promise<
139
151
  Array<{
140
152
  address: string;
141
153
  index: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/eth-hd-keyring",
3
- "version": "3.6.8",
3
+ "version": "3.6.11",
4
4
  "description": "A simple standard interface for a seed phrase generated set of Ethereum accounts.",
5
5
  "keywords": [
6
6
  "ethereum",
package/test/index.js CHANGED
@@ -57,7 +57,7 @@ describe('hd-keyring', function () {
57
57
  describe('#serialize empty wallets.', function () {
58
58
  it('serializes a new mnemonic', function () {
59
59
  keyring.serialize().then((output) => {
60
- assert.equal(output.numberOfAccounts, 0);
60
+ // assert.equal(output.numberOfAccounts, 0);
61
61
  assert.equal(output.mnemonic, null);
62
62
  });
63
63
  });
@@ -507,4 +507,20 @@ describe('hd-keyring', function () {
507
507
  });
508
508
  });
509
509
  });
510
+
511
+ describe('removeAccount', function () {
512
+ it('should return correct activeIndexes', async function () {
513
+ const address = firstAcct;
514
+
515
+ keyring = new HdKeyring({
516
+ mnemonic: sampleMnemonic,
517
+ activeIndexes: [0, 2, 3, 6],
518
+ });
519
+ await keyring.removeAccount(address);
520
+ const { activeIndexes } = await keyring.serialize();
521
+
522
+ assert.equal(activeIndexes.length, 3);
523
+ assert.deepEqual(activeIndexes, [2, 3, 6]);
524
+ });
525
+ });
510
526
  });