Skip to content

Commit

Permalink
fixed key derivation logic using coinType
Browse files Browse the repository at this point in the history
  • Loading branch information
aruokhai committed Dec 31, 2024
1 parent dc73a6c commit bed6896
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/wallet/src/wallet.ts
Original file line number Diff line number Diff line change
@@ -55,8 +55,10 @@ export class Wallet {
private async initializeWithMnemonic(mnemonic: string, password?: string) {
const seed = mnemonicToSeedSync(mnemonic).toString('hex');
this.masterKey = bip32.fromSeed(Buffer.from(seed, 'hex'));
this.scanKey = this.masterKey.derivePath(`m/352'/${this.network.network.bech32}'/0'/1'/0`);
this.spendKey = this.masterKey.derivePath(`m/352'/${this.network.network.bech32}'/0'/0'/0`);
const coinType = this.network.network.bech32 === 'bc' ? 0 : 1;
this.scanKey = this.masterKey.derivePath(`m/352'/${coinType}'/0'/1'/0`);
this.spendKey = this.masterKey.derivePath(`m/352'/${coinType}'/0'/0'/0`);

this.setPassword(password ?? DEFAULT_ENCRYPTION_PASSWORD);

for (let i = 0; i < this.lookahead; i++) {
@@ -78,8 +80,9 @@ export class Wallet {
).privateKey;

this.masterKey = bip32.fromPrivateKey(decryptedPrivateKey, decryptedChainCode);
this.scanKey = this.masterKey.derivePath(`m/352'/${this.network.network.bech32}'/0'/1'/0`);
this.spendKey = this.masterKey.derivePath(`m/352'/${this.network.network.bech32}'/0'/0'/0`);
const coinType = this.network.network.bech32 === 'bc' ? 0 : 1;
this.scanKey = this.masterKey.derivePath(`m/352'/${coinType}'/0'/1'/0`);
this.spendKey = this.masterKey.derivePath(`m/352'/${coinType}'/0'/0'/0`);
}


0 comments on commit bed6896

Please sign in to comment.