Fix default options merging in Secp256k1HdWallet

This commit is contained in:
bartmacbartek 2021-05-06 12:42:52 +02:00
parent 84ee121601
commit 47220aa12f
2 changed files with 16 additions and 3 deletions

View File

@ -33,6 +33,18 @@ describe("Secp256k1HdWallet", () => {
expect(account.pubkey).not.toEqual(defaultPubkey);
expect(account.address.slice(0, 4)).toEqual("yolo");
});
it("works with explicitly undefined options", async () => {
const wallet = await Secp256k1HdWallet.fromMnemonic(defaultMnemonic, {
bip39Password: undefined,
hdPaths: undefined,
prefix: undefined,
});
expect(wallet.mnemonic).toEqual(defaultMnemonic);
const [account] = await wallet.getAccounts();
expect(account.pubkey).toEqual(defaultPubkey);
expect(account.address).toEqual(defaultAddress);
});
});
describe("generate", () => {

View File

@ -246,12 +246,13 @@ export class Secp256k1HdWallet implements OfflineAminoSigner {
private readonly accounts: readonly DerivationInfo[];
protected constructor(mnemonic: EnglishMnemonic, options: Secp256k1HdWalletConstructorOptions) {
const { seed, hdPaths, prefix } = { ...defaultOptions, ...options };
const hdPaths = options.hdPaths ?? defaultOptions.hdPaths;
const prefix = options.prefix ?? defaultOptions.prefix;
this.secret = mnemonic;
this.seed = seed;
this.seed = options.seed;
this.accounts = hdPaths.map((hdPath) => ({
hdPath: hdPath,
prefix: prefix,
prefix,
}));
}