Skip to content

What's default derive path for getnewaddress? #13302

@dancju

Description

@dancju

From a same private key I got different derived address from bitcoin-cli and my own code. I am wondering what mistakes I made.

I created a HD wallet (under BIP49) and generated a derived address from this piece of code,

const btc = require('bitcoinjs-lib');
const btc_prv = btc.HDNode.fromSeedBuffer(seed).derivePath("m/49'/0'/0'");
const btc_pub = btc_prv.neutered();
const btc_prv0 = btc_prv.derivePath("0/0");
const btc_pub0 = btc_pub.derivePath("0/0");
const btc_add0 = btc.address.fromOutputScript(btc.script.scriptHash.output.encode(btc.crypto.hash160(btc.script.witnessPubKeyHash.output.encode(btc.crypto.hash160(btc_pub0.getPublicKeyBuffer())))));
console.log("private WIF  : "+btc_prv.keyPair.toWIF());
console.log("public key   : "+btc_pub.getPublicKeyBuffer().toString('hex'));
console.log("private WIF 0: "+btc_prv0.keyPair.toWIF());
console.log("public key  0: "+btc_pub0.getPublicKeyBuffer().toString('hex'));
console.log("address     0: "+btc_add0);

and got this output.

private WIF  : L4R...
public key   : 036124c83be4781cf7294a4d200c49d8161535f1fb5b4bdfef07d282d3219d81b4
private WIF 0: Kxf...
public key  0: 0259dcde34aa3cc5c4949bfdd8a35d189db40db3706b82f0879ba52b69be28f2f9
address     0: 36H1KVwD1BuLPFaNGDDnAwLP8vPNTak71R

Importing this private key into bitcoin-cli and generating derived key from

bitcoin-cli --version
bitcoin-cli importprivkey L4R... "" false
bitcoin-cli getnewaddress

, yields

Bitcoin Core RPC client version v0.16.0.0-g4b4d7eb255
38jrZ3ojUPvxbhG8pzqVSNae1MgmVVsMHd

. Why did I get different addresses? What is the algorithm behind getnewaddress? Can I generate address from custom derive path?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions