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 Oct 28 '19 at 14:34
  • I don't understand what that is saying :/ – Lance Pollard Oct 28 '19 at 15:03
  • @Anonymous I don't think that's the problem. – Pieter Wuille Oct 28 '19 at 15:33
  • Did you intend for a to be the private key or for it's hash b to be the private key? – Andrew Chow Oct 28 '19 at 15:35
  • 1
    @PieterWuille They are hashing the output of tohex(). It’s at least one of the problems. – Anonymous Oct 28 '19 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.