@rabby-wallet/eth-hd-keyring 3.6.5 → 3.6.9
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 +12 -1
- package/index.ts +16 -5
- package/package.json +1 -1
- package/test/index.js +1 -1
package/dist/index.js
CHANGED
|
@@ -50,7 +50,8 @@ class HdKeyring extends eth_simple_keyring_1.default {
|
|
|
50
50
|
this._index2wallet = {};
|
|
51
51
|
this.activeIndexes = [];
|
|
52
52
|
this.page = 0;
|
|
53
|
-
this.perPage =
|
|
53
|
+
this.perPage = 5;
|
|
54
|
+
this.byImport = false;
|
|
54
55
|
this.deserialize(opts);
|
|
55
56
|
}
|
|
56
57
|
serialize() {
|
|
@@ -58,6 +59,7 @@ class HdKeyring extends eth_simple_keyring_1.default {
|
|
|
58
59
|
mnemonic: this.mnemonic,
|
|
59
60
|
activeIndexes: this.activeIndexes,
|
|
60
61
|
hdPath: this.hdPath,
|
|
62
|
+
byImport: this.byImport,
|
|
61
63
|
});
|
|
62
64
|
}
|
|
63
65
|
deserialize(opts = {}) {
|
|
@@ -65,6 +67,7 @@ class HdKeyring extends eth_simple_keyring_1.default {
|
|
|
65
67
|
this.mnemonic = null;
|
|
66
68
|
this.root = null;
|
|
67
69
|
this.hdPath = opts.hdPath || hdPathString;
|
|
70
|
+
this.byImport = !!opts.byImport;
|
|
68
71
|
if (opts.mnemonic) {
|
|
69
72
|
this.initFromMnemonic(opts.mnemonic);
|
|
70
73
|
}
|
|
@@ -161,6 +164,14 @@ class HdKeyring extends eth_simple_keyring_1.default {
|
|
|
161
164
|
return sigUtil.normalize(w.getAddress().toString('hex'));
|
|
162
165
|
}));
|
|
163
166
|
}
|
|
167
|
+
getIndexByAddress(address) {
|
|
168
|
+
for (const key in this._index2wallet) {
|
|
169
|
+
if (this._index2wallet[key][0].toLowerCase() === address.toLowerCase()) {
|
|
170
|
+
return Number(key);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
164
175
|
/* PRIVATE METHODS */
|
|
165
176
|
_addressFromIndex(i) {
|
|
166
177
|
if (!this._index2wallet[i]) {
|
package/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ interface DeserializeOption {
|
|
|
11
11
|
hdPath?: string;
|
|
12
12
|
mnemonic?: string;
|
|
13
13
|
activeIndexes?: number[];
|
|
14
|
+
byImport?: boolean;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
class HdKeyring extends SimpleKeyring {
|
|
@@ -25,7 +26,8 @@ class HdKeyring extends SimpleKeyring {
|
|
|
25
26
|
_index2wallet: Record<number, [string, Wallet]> = {};
|
|
26
27
|
activeIndexes: number[] = [];
|
|
27
28
|
page = 0;
|
|
28
|
-
perPage =
|
|
29
|
+
perPage = 5;
|
|
30
|
+
byImport = false;
|
|
29
31
|
|
|
30
32
|
/* PUBLIC METHODS */
|
|
31
33
|
constructor(opts = {}) {
|
|
@@ -38,6 +40,7 @@ class HdKeyring extends SimpleKeyring {
|
|
|
38
40
|
mnemonic: this.mnemonic,
|
|
39
41
|
activeIndexes: this.activeIndexes,
|
|
40
42
|
hdPath: this.hdPath,
|
|
43
|
+
byImport: this.byImport,
|
|
41
44
|
});
|
|
42
45
|
}
|
|
43
46
|
|
|
@@ -46,6 +49,7 @@ class HdKeyring extends SimpleKeyring {
|
|
|
46
49
|
this.mnemonic = null;
|
|
47
50
|
this.root = null;
|
|
48
51
|
this.hdPath = opts.hdPath || hdPathString;
|
|
52
|
+
this.byImport = !!opts.byImport;
|
|
49
53
|
|
|
50
54
|
if (opts.mnemonic) {
|
|
51
55
|
this.initFromMnemonic(opts.mnemonic);
|
|
@@ -132,10 +136,8 @@ class HdKeyring extends SimpleKeyring {
|
|
|
132
136
|
}
|
|
133
137
|
return accounts;
|
|
134
138
|
}
|
|
135
|
-
|
|
136
|
-
async __getPage(
|
|
137
|
-
increment: number
|
|
138
|
-
): Promise<
|
|
139
|
+
|
|
140
|
+
async __getPage(increment: number): Promise<
|
|
139
141
|
Array<{
|
|
140
142
|
address: string;
|
|
141
143
|
index: string;
|
|
@@ -171,6 +173,15 @@ class HdKeyring extends SimpleKeyring {
|
|
|
171
173
|
);
|
|
172
174
|
}
|
|
173
175
|
|
|
176
|
+
getIndexByAddress(address: string): number | null {
|
|
177
|
+
for (const key in this._index2wallet) {
|
|
178
|
+
if (this._index2wallet[key][0].toLowerCase() === address.toLowerCase()) {
|
|
179
|
+
return Number(key);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
|
|
174
185
|
/* PRIVATE METHODS */
|
|
175
186
|
|
|
176
187
|
_addressFromIndex(i: number): [string, Wallet] {
|
package/package.json
CHANGED
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
|
});
|