<!-- Describe the issue -->
<!--- What behavior did you expect? -->
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?
<!--- What was the actual behavior (provide screenshots if the issue is GUI-related)? -->
<!--- How reliably can you reproduce the issue, what are the steps to do so? -->
<!-- What version of Bitcoin Core are you using, where did you get it (website, self-compiled, etc)? -->
<!-- What type of machine are you observing the error on (OS/CPU and disk type)? -->
<!-- Any extra information that might be useful in the debugging process. -->
<!--- This is normally the contents of a `debug.log` or `config.log` file. Raw text or a link to a pastebin type site are preferred. -->