Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need library/tool to convert WIF to base58 #15

Open
kimdhamilton opened this issue Aug 8, 2019 · 6 comments
Open

Need library/tool to convert WIF to base58 #15

kimdhamilton opened this issue Aug 8, 2019 · 6 comments
Labels
good first issue Good for newcomers

Comments

@kimdhamilton
Copy link
Collaborator

  • Need library/tool to convert WIF to base58
  • Many tools don't work with mainnet
  • Must work with testnet
@kimdhamilton kimdhamilton added the good first issue Good for newcomers label Aug 8, 2019
@kimdhamilton
Copy link
Collaborator Author

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

@kimdhamilton
Copy link
Collaborator Author

@mattcollier
Copy link
Collaborator

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

@ghost
Copy link

ghost commented Aug 8, 2019

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
Copy link

ghost commented Aug 8, 2019

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants