2

This is how to create a brainwallet with bitcore

const Bitcore = require("bitcore-lib");
// const Mnemonic = require("bitcore-mnemonic");
// https://bitcore.io/api/lib/crypto
let brainsrc= 'satoshi'
let input = new Buffer(brainsrc)
let hash = Bitcore.crypto.Hash.sha256(input)
let bn = Bitcore.crypto.BN.fromBuffer(hash)
let pk = new Bitcore.PrivateKey(bn).toWIF()
let addy = new Bitcore.PrivateKey(bn).toAddress();
console.log('The brain wallet of '+brainsrc+' \nAddress: '+addy,' Private key:'+pk)

For bitcoinjs, I only know how to create random address:

// https://github.com/bitcoinjs/bitcoinjs-lib/blob/v3.3.2/test/integration/addresses.js

const bitcoin = require('bitcoinjs-lib')
var keyPair = bitcoin.ECPair.makeRandom()
var secret = (keyPair.toWIF())
var addr = (keyPair.getAddress())

console.log('The brain wallet of '+brainsrc+' \nAddress: '+addr,' Private key:'+secret)

How to do it?

1 Answer 1

0

First of all, don't use 1 word seeds, that will be too easy to brute force...

index.js

const bitcoin = require('bitcoinjs-lib')

const brainsrc = 'satoshi'
const hash = bitcoin.crypto.sha256(Buffer.from(brainsrc))
const keyPair = bitcoin.ECPair.fromPrivateKey(hash)
const addr = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey }).address
const secret = keyPair.toWIF()

console.log('The brain wallet of '+brainsrc+' \nAddress: '+addr,' Private key:'+secret)

output:

$ node index.js
The brain wallet of satoshi
Address: 1xm4vFerV3pSgvBFkyzLgT1Ew3HQYrS1V  Private key:L4XnHhvLC1b4ag9L2PM9kRicQxUoYT1Q36PQ21YtLNkrAdWZNos6

Examples can be found on the git repo: https://github.com/bitcoinjs/bitcoinjs-lib#examples

5
  • TypeError: bitcoin.ECPair.fromPrivateKey is not a function
    – TSR
    Sep 13, 2018 at 0:48
  • what version of bitcoinjs-lib and node are you using?
    – JBaczuk
    Sep 13, 2018 at 1:31
  • Yes node. I upgraded to 4.0.0 and it works.
    – TSR
    Sep 13, 2018 at 2:05
  • It would be a plus if you can provide a link to the documentation
    – TSR
    Sep 13, 2018 at 2:05
  • Good idea, just edited the answer, Bitcoinjs-lib doesn't have formal docs, but there are examples.
    – JBaczuk
    Sep 13, 2018 at 2:20

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.