Creating a private public key with 64 characters that are already known using bitcoinjs

0 votes

So I'm trying to create a private/public key from 64 characters that I already know using bitcoinjs with the code below:

key = Bitcoin.ECKey.makeRandom();

// Print your private key (in WIF format)
document.write(key.toWIF());
// => Kxr9tQED9H44gCmp6HAdmemAzU3n84H3dGkuWTKvE23JgHMW8gct

// Print your public key (toString defaults to a Bitcoin address)
document.write(key.pub.getAddress().toString());
// => 14bZ7YWde4KdRb5YN7GYkToz3EHVCvRxkF

If I try to set "key" to my 64 characters instead of "Bitcoin.ECKey.makeRandom();" it fails. Is there a method or library that I overlooked that would allow me to use the known 64 characters in order to generate the private key in wif format and the public address?

Sep 10, 2018 in Blockchain by digger
• 26,740 points
1,802 views

2 answers to this question.

0 votes

You should use fromWIF method to pass your own data.

from source code of eckey.js

// Static constructors
ECKey.fromWIF = function(string) {
  var payload = base58check.decode(string)
  var compressed = false

  // Ignore the version byte
  payload = payload.slice(1)

  if (payload.length === 33) {
    assert.strictEqual(payload[32], 0x01, 'Invalid compression flag')

    // Truncate the compression flag
    payload = payload.slice(0, -1)
    compressed = true
  }

To create WIF from your key please follow https://en.bitcoin.it/wiki/Wallet_import_format Here is interactive tool http://gobittest.appspot.com/PrivateKey

answered Sep 10, 2018 by slayer
• 29,370 points
0 votes
//public-key
var address = eckey.getBitcoinAddress().toString();

var privateKeyBytesCompressed = privateKeyBytes.slice(0); 
privateKeyBytesCompressed.push(0x01);
var privateKeyWIFCompressed = new Bitcoin.Address(privateKeyBytesCompressed);
privateKeyWIFCompressed.version = 0x80;


//private-key
privateKeyWIFCompressed = privateKeyWIFCompressed.toString();
answered Sep 10, 2018 by Misty

Related Questions In Blockchain

0 votes
1 answer

Can we protect a Private Blockchain with a Public Blockchain and how?

I have recently reviewed Exonum framework  and ...READ MORE

answered Jun 19, 2018 in Blockchain by Perry
• 17,100 points
660 views
0 votes
1 answer
+1 vote
1 answer

How can I initiate a transaction on ethereum private network using mobile device?

There is no android wallet to connect ...READ MORE

answered Apr 18, 2018 in Blockchain by Shashank
• 10,400 points
917 views
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,460 points
1,459 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,942 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,468 views
+1 vote
4 answers

How to connect peers to a private network using geth?

Follow the below steps to connect peers ...READ MORE

answered Jul 13, 2018 in Blockchain by slayer
• 29,370 points
14,284 views
0 votes
2 answers

How is a transaction public key related to original public?

The details like account balance, nonce etc., ...READ MORE

answered Jul 24, 2018 in Blockchain by digger
• 26,740 points
735 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP