Skip to content

Commit

Permalink
Fix HD segwit
Browse files Browse the repository at this point in the history
  • Loading branch information
22388o committed Dec 5, 2024
1 parent 6851637 commit 8773bf2
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/app/HD wallet/segwit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ console.log('Mnemonic:', mnemonic);
const seed = bip39.mnemonicToSeedSync(mnemonic);

// Create the root node from the seed
const root = bip32.fromSeed(seed);
const root = bip32.BIP32Factory.fromSeed(seed);

// Networks (mainnet by default, change to bitcoin.networks.testnet for testnet)
const network = bitcoin.networks.bitcoin;
Expand All @@ -21,19 +21,17 @@ function deriveAccountNode(root: bip32.BIP32Interface, path: string): bip32.BIP3

// Generate P2SH-P2WPKH (SegWit) address
function generateP2SH_P2WPKH(accountNode: bip32.BIP32Interface): string {
const keyPair = bitcoin.ECPair.fromPrivateKey(accountNode.privateKey as Buffer);
const keyPair = bitcoin.ECPairFactory.fromPrivateKey(accountNode.privateKey as Buffer);
const p2wpkh = bitcoin.payments.p2wpkh({ pubkey: keyPair.publicKey, network });
const p2sh = bitcoin.payments.p2sh({ redeem: p2wpkh, network });
return p2sh.address as string;
}

// Generate P2WPKH (Native SegWit) address
function generateP2WPKH(accountNode: bip32.BIP32Interface): string {
const keyPair = bitcoin.ECPair.fromPrivateKey(accountNode.privateKey as Buffer);
const keyPair = bitcoin.ECPair.fromPrivateKey(accountNode.privateKey as Buffer, network);
const p2wpkh = bitcoin.payments.p2wpkh({ pubkey: keyPair.publicKey, network });
return p2wpkh.address as string;
}
// BIP paths
}// BIP paths
const paths = {
p2sh_p2wpkh: "m/49'/0'/0'/0/0", // BIP-49 path
p2wpkh: "m/84'/0'/0'/0/0", // BIP-84 path
Expand Down

0 comments on commit 8773bf2

Please sign in to comment.