Add bch-mnemonic protocol

This commit is contained in:
Jim Hamill
2025-06-27 06:44:14 +00:00
parent 1545255a4a
commit f01699a961
5 changed files with 217 additions and 14 deletions
+15 -4
View File
@@ -27,7 +27,11 @@ export type WalletHDGenesisData = {
type: 'WalletHD';
derivationPath: string;
addressGap?: number;
} & ({ seed: string } | { mnemonic: string } | { xpriv: string });
} & (
| { seed: string }
| { mnemonic: string; passphrase?: string }
| { xpriv: string }
);
/**
* A Hierarhical Determinstic (BIP44) Wallet.
@@ -111,9 +115,16 @@ export class WalletHD extends BaseWallet {
if ('seed' in genesisData) {
this.hdPrivateNode = HDPrivateNode.fromSeed(genesisData.seed);
} else if ('mnemonic' in genesisData) {
this.hdPrivateNode = HDPrivateNode.fromMnemonic(
Mnemonic.fromPhrase(genesisData.mnemonic),
);
// TODO: We really want to support multiple word-lists somehow.
// But this is not trivial because other word-lists are technically not standard.
// For now, we are allowing any phrase (BIP39 derives seed from literal phrase, not word indexes).
const mnemonic = Mnemonic.fromRaw({
words: genesisData.mnemonic.split(' '),
passphrase: genesisData.passphrase,
});
// Create the HD Node from our Mnemonic instance.
this.hdPrivateNode = HDPrivateNode.fromMnemonic(mnemonic);
} else {
this.hdPrivateNode = HDPrivateNode.fromXPriv(genesisData.xpriv);
}