How to change network on BitcoinJS-lib with Coininfo and generate Dogecoin address?

0

1

Can't find out how to change network on BitcoinJS-lib with Coininfo and generate Dogecoin address?

In a Coininfo's example I found this: https://github.com/cryptocoinjs/coininfo#want-to-use-with-bitcore-or-bitconjs-lib

But what to do next?

Oysho Boy

Posted 2018-07-06T08:20:57.860

Reputation: 13

Answers

0

Solved, and here here is my code:

const coininfo = require('coininfo');
var bitcoin = require("bitcoinjs-lib");

generateDOGE = function() {
    var coininfo = require('coininfo');
    var curr = coininfo.dogecoin.main;
    var frmt = curr.toBitcoinJS();

    const netGain = {
        messagePrefix: '\x19' + frmt.name + ' Signed Message:\n',
        bip32: {
            public: frmt.bip32.public,
            private: frmt.bip32.private
        },
        pubKeyHash: frmt.pubKeyHash,
        scriptHash: frmt.scriptHash,
        wif: frmt.wif
    }

    const keyPair = bitcoin.ECPair.makeRandom({ network: netGain })
    const wif = keyPair.toWIF()
    const address = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey, network: netGain });
}

Oysho Boy

Posted 2018-07-06T08:20:57.860

Reputation: 13

0

Theoretically, you would just replace the network argument in the bitcoinjs function calls to the one generated by coininfo. You'll have to figure out the message prefix (don't know if mine is correct) because it doesn't look like that's defined by coininfo.

const coininfo = require('coininfo')
const doge = coininfo.dogecoin.main
const dogeNetwork = doge.toBitcoinJS()
const bitcoin = require('bitcoinjs-lib')

dogeNetwork.messagePrefix = '\x18Dogecoin Signed Message:\n'
console.log('network: ' + JSON.stringify(dogeNetwork));

const keyPair = bitcoin.ECPair.makeRandom({ network: dogeNetwork })
const wif = keyPair.toWIF()
const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey, network: dogeNetwork })

console.log('address: ' + address)

JBaczuk

Posted 2018-07-06T08:20:57.860

Reputation: 6 172