0
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?
Possible duplicate of OP_SHA256 mismatch!
– Anonymous – 2019-10-28T14:34:32.240I don't understand what that is saying :/ – Lance Pollard – 2019-10-28T15:03:59.000
@Anonymous I don't think that's the problem. – Pieter Wuille – 2019-10-28T15:33:30.243
Did you intend for
ato be the private key or for it's hashbto be the private key? – Andrew Chow – 2019-10-28T15:35:11.7701@PieterWuille They are hashing the output of tohex(). It’s at least one of the problems. – Anonymous – 2019-10-28T16:41:42.893