I have this:
const crypto = require('crypto')
const bs58 = require('bs58')
const a = crypto.randomBytes(32)
const b = crypto.createHash('sha256').update(a).digest('hex')
const c = '80' + b
const d = crypto.createHash('sha256').update(c).digest('hex')
const e = crypto.createHash('sha256').update(d).digest('hex')
const f = c + e.substr(0, 4)
const bytes = Buffer.from(f, 'hex')
const address = bs58.encode(bytes)
console.log(address)
Which was inspired from this. But when I do this:
bitcoin-cli importprivkey "<key>" "foo"
I get this:
error code: -5
error message:
Invalid private key encoding
What am I doing wrong?
a
to be the private key or for it's hashb
to be the private key?