How to create a brainwallet with bitcoinjs? 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?
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