Skip to content

Instantly share code, notes, and snippets.

@tiero
Last active December 23, 2021 10:50
Show Gist options
  • Save tiero/2b5b604ed2a3aef2ee657b18260c2364 to your computer and use it in GitHub Desktop.
Save tiero/2b5b604ed2a3aef2ee657b18260c2364 to your computer and use it in GitHub Desktop.
LiquidJS HD Wallet Example
const bip39 = require("bip39")
const bip32 = require("bip32")
const slip77 = require("slip77")
const liquid = require('liquidjs-lib')
const regtest = liquid.networks.regtest
try {
const mnemonic = bip39.generateMnemonic()
const seed = await bip39.mnemonicToSeed(mnemonic)
const node = bip32.fromSeed(seed, regtest)
const nodeBlinding = slip77.fromSeed(seed)
const addressIndex = 0
const child = node.derivePath(`m/44'/0'/0'/${addressIndex}`)
const p2wpkh = liquid.payments.p2wpkh({ pubkey: child.publicKey, network:regtest })
// Now we pass the scriptPubKey down to the derive function to get the corresponding blinding key
const blindingKeyPair = nodeBlinding.derive(p2wpkh.output)
console.log(p2pkh.address)
console.log(blindingKeyPair.privateKey, blindingKeyPair.publicKey)
} catch (err) {
console.log(err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment