BIP32 Key Derivation with HD Wallets
Generating BIP32 keys
import { HD } from '@bsv/sdk'
const randomKey = HD.fromRandom()
// Convert your "xprv" key to a string
console.log(randomKey.toString())
// Example: xprv9s21ZrQH143K2vF2szsDFhrRehet4iHNCBPWprjymByU9mzN7n687qj3ULQ2YYXdNqFwhVSsKv9W9fM675whM9ATaYrmsLpykQSxMc6RN8Vconst importedKey = HD.fromString('xprv...')Deriving Child Keys
const key = HD.fromString('xprv9s21ZrQH143K2vF2szsDFhrRehet4iHNCBPWprjymByU9mzN7n687qj3ULQ2YYXdNqFwhVSsKv9W9fM675whM9ATaYrmsLpykQSxMc6RN8V')
const child = key.derive('m/0/1/2')
console.log(child.toString())
// 'xprv9yGx5dNDfq8pt1DJ9SFCK3gNFhjrL3kTqEj98oDs6xvfaUAUs3nyvVakQzwHAEMrc6gg1c3iaNCDubUruhX75gNHC7HAnFxHuxeiMVgLEqS'Converting Between Formats
Hardened vs Non-Hardened Derivation
Non-Hardened Derivation
Why Use Non-Hardened Keys?
Key Weakness
Hardened Derivation
Why Use Hardened Keys?
Key Tradeoff
Summary of Differences
Aspect
Non-Hardened
Hardened
Practical Example
Real-World Use
Disadvantages and Risks
PreviousVerifying Spends with Script IntrepreterNextUsing Type 42 Key Derivation for Bitcoin Wallet Management
Last updated
Was this helpful?

