@metamask/eth-hd-keyring 4.0.0 → 4.0.1
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/CHANGELOG.md +11 -2
- package/index.js +2 -3
- package/package.json +1 -1
- package/test/index.js +37 -2
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [4.0.1]
|
|
10
|
+
### Added
|
|
11
|
+
- Add tests to get coverage to 100% ([#62](https://github.com/MetaMask/eth-hd-keyring/pull/62))
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
- Fix bug where an unexpected error would occur if the mnemonic passed to `_initFromMnemonic` was a buffer array ([#62](https://github.com/MetaMask/eth-hd-keyring/pull/62))
|
|
15
|
+
|
|
9
16
|
## [4.0.0]
|
|
10
17
|
### Changed
|
|
11
18
|
- **BREAKING**: Do not allow re-initialization of keyring instance ([#55](https://github.com/MetaMask/eth-hd-keyring/pull/55))
|
|
@@ -14,7 +21,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
14
21
|
- Add `@lavamoat/allow-scripts` ([#47](https://github.com/MetaMask/eth-hd-keyring/pull/47))
|
|
15
22
|
- We now have an allowlist for all post-install scripts. The standard setup script has been added, along with new contributor documentation in the README to explain this script.
|
|
16
23
|
- Obfuscate serialized mnemonic ([#59](https://github.com/MetaMask/eth-hd-keyring/pull/59))
|
|
17
|
-
-
|
|
24
|
+
- Class variable `mnemonic` on `HdKeyring` can now be either type `Buffer` or type `string`.
|
|
25
|
+
- Package name changed from `eth-hd-keyring` to `@metamask/eth-hd-keyring`.
|
|
18
26
|
|
|
19
|
-
[Unreleased]: https://github.com/MetaMask/eth-hd-keyring/compare/v4.0.
|
|
27
|
+
[Unreleased]: https://github.com/MetaMask/eth-hd-keyring/compare/v4.0.1...HEAD
|
|
28
|
+
[4.0.1]: https://github.com/MetaMask/eth-hd-keyring/compare/v4.0.0...v4.0.1
|
|
20
29
|
[4.0.0]: https://github.com/MetaMask/eth-hd-keyring/releases/tag/v4.0.0
|
package/index.js
CHANGED
|
@@ -38,8 +38,7 @@ class HdKeyring extends SimpleKeyring {
|
|
|
38
38
|
'Eth-Hd-Keyring: Secret recovery phrase already provided',
|
|
39
39
|
);
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
this.opts = opts || {};
|
|
41
|
+
this.opts = opts;
|
|
43
42
|
this.wallets = [];
|
|
44
43
|
this.mnemonic = null;
|
|
45
44
|
this.root = null;
|
|
@@ -116,7 +115,7 @@ class HdKeyring extends SimpleKeyring {
|
|
|
116
115
|
}
|
|
117
116
|
|
|
118
117
|
// eslint-disable-next-line node/no-sync
|
|
119
|
-
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
118
|
+
const seed = bip39.mnemonicToSeedSync(this.mnemonic);
|
|
120
119
|
this.hdWallet = hdkey.fromMasterSeed(seed);
|
|
121
120
|
this.root = this.hdWallet.derivePath(this.hdPath);
|
|
122
121
|
}
|
package/package.json
CHANGED
package/test/index.js
CHANGED
|
@@ -25,7 +25,7 @@ describe('hd-keyring', () => {
|
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
describe('constructor', () => {
|
|
28
|
-
it('constructs', async () => {
|
|
28
|
+
it('constructs with a typeof string mnemonic', async () => {
|
|
29
29
|
keyring = new HdKeyring({
|
|
30
30
|
mnemonic: sampleMnemonic,
|
|
31
31
|
numberOfAccounts: 2,
|
|
@@ -36,6 +36,28 @@ describe('hd-keyring', () => {
|
|
|
36
36
|
expect(accounts[1]).toStrictEqual(secondAcct);
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
+
it('constructs with a typeof array mnemonic', async () => {
|
|
40
|
+
keyring = new HdKeyring({
|
|
41
|
+
mnemonic: Array.from(Buffer.from(sampleMnemonic, 'utf8').values()),
|
|
42
|
+
numberOfAccounts: 2,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const accounts = await keyring.getAccounts();
|
|
46
|
+
expect(accounts[0]).toStrictEqual(firstAcct);
|
|
47
|
+
expect(accounts[1]).toStrictEqual(secondAcct);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('constructs with a typeof buffer mnemonic', async () => {
|
|
51
|
+
keyring = new HdKeyring({
|
|
52
|
+
mnemonic: Buffer.from(sampleMnemonic, 'utf8'),
|
|
53
|
+
numberOfAccounts: 2,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const accounts = await keyring.getAccounts();
|
|
57
|
+
expect(accounts[0]).toStrictEqual(firstAcct);
|
|
58
|
+
expect(accounts[1]).toStrictEqual(secondAcct);
|
|
59
|
+
});
|
|
60
|
+
|
|
39
61
|
it('throws on invalid mnemonic', () => {
|
|
40
62
|
expect(
|
|
41
63
|
() =>
|
|
@@ -99,12 +121,19 @@ describe('hd-keyring', () => {
|
|
|
99
121
|
});
|
|
100
122
|
|
|
101
123
|
describe('#serialize mnemonic.', () => {
|
|
102
|
-
it('serializes mnemonic class variable into a buffer array and does not add accounts', async () => {
|
|
124
|
+
it('serializes mnemonic stored as a buffer in a class variable into a buffer array and does not add accounts', async () => {
|
|
103
125
|
keyring.generateRandomMnemonic();
|
|
104
126
|
const output = await keyring.serialize();
|
|
105
127
|
expect(output.numberOfAccounts).toBe(0);
|
|
106
128
|
expect(Array.isArray(output.mnemonic)).toBe(true);
|
|
107
129
|
});
|
|
130
|
+
|
|
131
|
+
it('serializes mnemonic stored as a string in a class variable into a buffer array and does not add accounts', async () => {
|
|
132
|
+
keyring.mnemonic = sampleMnemonic;
|
|
133
|
+
const output = await keyring.serialize();
|
|
134
|
+
expect(output.numberOfAccounts).toBe(0);
|
|
135
|
+
expect(Array.isArray(output.mnemonic)).toBe(true);
|
|
136
|
+
});
|
|
108
137
|
});
|
|
109
138
|
|
|
110
139
|
describe('#deserialize a private key', () => {
|
|
@@ -133,6 +162,12 @@ describe('hd-keyring', () => {
|
|
|
133
162
|
await keyring.addAccounts();
|
|
134
163
|
expect(keyring.wallets).toHaveLength(1);
|
|
135
164
|
});
|
|
165
|
+
|
|
166
|
+
it('throws an error when no SRP has been generated yet', async () => {
|
|
167
|
+
expect(() => keyring.addAccounts()).toThrow(
|
|
168
|
+
'Eth-Hd-Keyring: No secret recovery phrase provided',
|
|
169
|
+
);
|
|
170
|
+
});
|
|
136
171
|
});
|
|
137
172
|
|
|
138
173
|
describe('with a numeric argument', () => {
|