WebOfTrustInfo / btcr-hackathon-2019

BTCR Hackathon 2019
https://weboftrustinfo.github.io/btcr-hackathon-2019/
MIT License
2 stars 0 forks source link

Need library/tool to convert WIF to base58 #15

Open kimdhamilton opened 4 years ago

kimdhamilton commented 4 years ago
kimdhamilton commented 4 years ago

Somewhere in here is code that does it: https://github.com/json-ld/json-ld.org/tree/master/playground

kimdhamilton commented 4 years ago

https://gist.github.com/t4sk/ac6f2d607c96156ca15f577290716fcc

mattcollier commented 4 years ago

Playground is using a copy of this lib from ~3 years ago (not current): https://github.com/bitpay/bitcore-message

ghost commented 4 years ago

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

ghost commented 4 years ago

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.

mattcollier commented 4 years ago

@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.