mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-11 14:09:15 +00:00
Fix default options merging in Secp256k1HdWallet
This commit is contained in:
parent
84ee121601
commit
47220aa12f
@ -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", () => {
|
||||
|
@ -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,
|
||||
}));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user