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?

5
  • Possible duplicate of OP_SHA256 mismatch!
    – Claris
    Oct 28, 2019 at 14:34
  • I don't understand what that is saying :/
    – Lance
    Oct 28, 2019 at 15:03
  • @Anonymous I don't think that's the problem. Oct 28, 2019 at 15:33
  • Did you intend for a to be the private key or for it's hash b to be the private key?
    – Ava Chow
    Oct 28, 2019 at 15:35
  • 1
    @PieterWuille They are hashing the output of tohex(). It’s at least one of the problems.
    – Claris
    Oct 28, 2019 at 16:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.