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)
// => Kxr9tQED9H44gCmp6HAdmemAzU3n84H3dGkuWTKvE23JgHMW8gct

// Print your public key (toString defaults to a Bitcoin address)
// => 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,720 points

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 Here is interactive tool

answered Sep 10, 2018 by slayer
• 29,310 points
0 votes
var address = eckey.getBitcoinAddress().toString();

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

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 ( ...READ MORE

answered Jun 19, 2018 in Blockchain by Perry
• 17,100 points
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
0 votes
1 answer

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

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,440 points
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,830 points
0 votes
1 answer
+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,310 points
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,720 points