let assert = require('assert')
let bitcoin = require('bitcoinjs-lib')
let dhttp = require('dhttp/200')
// deterministic RNG for testing only
// function rng () { return Buffer.from('zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz') }
function rng () {
return Buffer.from('YT8dAtK4d16A3P1z+TpwB2jJ4aFH3g9M1EioIBkLEV4=', 'base64')
}
// TODO: remove
let baddress = bitcoin.address
let bcrypto = bitcoin.crypto
function getAddress (node, network) {
network = network || bitcoin.networks.bitcoin
return baddress.toBase58Check(bcrypto.hash160(node.publicKey), network.pubKeyHash)
}
var keyPair = bitcoin.ECPair.makeRandom({ rng: rng })
console.log(keyPair)
var address = getAddress(keyPair)
TypeError: Data must be a string or a buffer
at Hash.update (crypto.js:99:16)
at sha256 (\node_modules\bitcoinjs-lib\src\crypto.js:12:31)
at Object.hash160 (\node_modules\bitcoinjs-lib\src\crypto.js:16:20)
at getAddress (I\src\bitcoinjs\addresses.js:19:41)
at Object.<anonymous> \src\bitcoinjs\addresses.js:25:19)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
keyPair don't have publicKey
@JQiMeng this is using master branch, yes?
What does
console.log(keyPair)
Print?
use node.getPubkeyBuffer() instead of node.publicKey
@dabura667 our example links should ref the latest release, probably
thank your help,
I use the command ( npm install bitcoinjs-lib) to install ,is it stable?
and i see code as follows:
ECPair.prototype.getAddress = function () {
return baddress.toBase58Check(bcrypto.hash160(this.getPublicKeyBuffer()), this.getNetwork().pubKeyHash)
}
so we can Modify the code as follows:
var keyPair = bitcoin.ECPair.makeRandom({ rng: rng })
keyPair.getAddress()
rather then var address = getAddress(keyPair)
is this right?
@JQiMeng that is stable.
And that is right.
The master branch on this repository is about to release to 4.0.0.
Please see https://github.com/bitcoinjs/bitcoinjs-lib/blob/v3.3.2/test/integration/addresses.js#L13-L16 for the examples for 3.3.2 (latest release).
@dcousens So when the 4.0.0 version to release? I found the latest version is 3.3.2
@zhaozhiming hopefully soon :)
Most helpful comment
@zhaozhiming hopefully soon :)