I have a small script basically taken from this test script in bitcoinjs-lib
function getAddress(node) {
const bitcoin = require('bitcoinjs-lib');
return bitcoin.payments.p2pkh({ pubkey: node.publicKey }).address;
}
function BIP44() {
/* create a BIP44, rvn, account 0, external address */
const bip32 = require('bip32');
const root = bip32.fromSeed(
Buffer.from(
'dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd',
'hex',
),
);
const childAuto = root.derivePath("m/44'/175'/0'/0/0");
const childManual = root
.deriveHardened(44)
.deriveHardened(175)
.deriveHardened(0)
.derive(0)
.derive(0);
return getAddress(childAuto);
}
console.log(BIP44());
It works perfectly for deriving a bitcoin address (derivation path "m/44'/0'/0'/0/0"
) but when trying to derive any other address it doesn't seem to work. The output is this:
16CzcgCURH83h3cLQ91ZpavDjXSfuNru4c
That address starts with a 1, whereas RVN addresses start with R.
I mistakenly assumed that merely by changing the derivation path to match RVN (175
) it would generate Raven addresses, but there must be something else I'm missing.
Can you help me figure out where I'm going wrong?
Other resources I've explored:
looking over https://github.com/iancoleman/bip39 I found I had to specify the correct ravencoin network specifications (don't really understand what this object means) but once I did, it worked perfectly.
function getAddress(node, network) {
const bitcoin = require('bitcoinjs-lib');
return bitcoin.payments.p2pkh({ pubkey: node.publicKey, network }).address;
}
function getNetwork() {
/* https://github.com/iancoleman/bip39/blob/c4f0c2908faab1452937e50a7d3a400fed42a0a8/src/js/bitcoinjs-extensions.js */
return {
messagePrefix: '\x16Raven Signed Message:\n',
bip32: {
public: 0x0488B21E,
private: 0x0488ADE4,
},
pubKeyHash: 0x3c,
scriptHash: 0x7a,
wif: 0x80,
};
}
function BIP44() {
/* create a BIP44, rvn, account 0, external address */
const bip32 = require('bip32');
const root = bip32.fromSeed(
Buffer.from(
'dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd',
'hex',
),
);
const childAuto = root.derivePath("m/44'/175'/0'/0/0");
const childManual = root
.deriveHardened(44)
.deriveHardened(175)
.deriveHardened(0)
.derive(0)
.derive(0);
return getAddress(childAuto, getNetwork());
}
console.log(BIP44());