Open kimdhamilton opened 5 years ago
Somewhere in here is code that does it: https://github.com/json-ld/json-ld.org/tree/master/playground
Playground is using a copy of this lib from ~3 years ago (not current): https://github.com/bitpay/bitcore-message
Here's what I'm using right now: https://gist.github.com/3d2c8dcc8fbfc279014baa40d06ef269#file-create-bitcoin-wif-js
const bitcoin = require('bitcoinjs-lib')
const NETWORKS = bitcoin.networks
// enter private key and network here
const privateKey = ''
const network = NETWORKS.testnet
const KEY = Buffer.from(privateKey, 'hex')
const keyPair = bitcoin.ECPair.fromPrivateKey(KEY, {
compressed: false,
network: network
})
let { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey, network: network })
console.log("Public Key: ", keyPair.publicKey.toString('hex'))
console.log("Address: ", address)
console.log("WIF: ", keyPair.toWIF());
Go here https://repl.it/languages/nodejs and just add bitcoinjs-lib
to the packages on the left first.
As I understand it, the WIF is the base58 encoding of a private key, but if that's incorrect let me know.
CC @ChristopherA
I'm getting no luck actually using the above for signing with vs-js-cli demo though. Probably doing something wrong, either above or hacking it into the demo.
@AnthonyRonning you may want to compare the encoding techniques with what's here: https://github.com/digitalbazaar/secp256k1-key-pair/blob/master/lib/index.js#L52
I believe the bitcoinjs-lib also uses the same elliptic
module for doing the secp256k operations.