Skip to content
This repository was archived by the owner on Oct 7, 2024. It is now read-only.

Commit 21f7fc0

Browse files
authored
add arg validation for method deserialize (#65)
1 parent 46d42a8 commit 21f7fc0

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ class HdKeyring extends SimpleKeyring {
3333
}
3434

3535
deserialize(opts = {}) {
36+
if (opts.numberOfAccounts && !opts.mnemonic) {
37+
throw new Error(
38+
'Eth-Hd-Keyring: Deserialize method cannot be called with an opts value for numberOfAccounts and no menmonic',
39+
);
40+
}
41+
3642
if (this.root) {
3743
throw new Error(
3844
'Eth-Hd-Keyring: Secret recovery phrase already provided',

test/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ describe('hd-keyring', () => {
6767
}),
6868
).toThrow('Eth-Hd-Keyring: Invalid secret recovery phrase provided');
6969
});
70+
71+
it('throws when numberOfAccounts is passed with no mnemonic', () => {
72+
expect(
73+
() =>
74+
new HdKeyring({
75+
numberOfAccounts: 2,
76+
}),
77+
).toThrow(
78+
'Eth-Hd-Keyring: Deserialize method cannot be called with an opts value for numberOfAccounts and no menmonic',
79+
);
80+
});
7081
});
7182

7283
describe('re-initialization protection', () => {

0 commit comments

Comments
 (0)