Not able to generate WIF from extended private key

0 votes

I've followed instructions from this link and got this code:

 var crypto = require('crypto');
  var bitcore = require('bitcore');
  var HierarchicalKey = bitcore.HierarchicalKey;
  var Address = bitcore.Address;
  var networks = bitcore.networks;
  var coinUtil = bitcore.util;

    var knownBytes = coinUtil.sha256('testing');
    var hkey = HierarchicalKey.seed(knownBytes,'testnet');

    var key = new Buffer(hkey.derive('m/0\'/0/0').extendedPrivateKey);
    var hash = new Buffer ([0xef].concat(key).concat([1]));

    var hashses = doubleSHA256(hash);
    var checksum = hashses.slice(0, 4);
    var data = Buffer.concat([hash, checksum]);
    var ress = bitcore.base58.encode(data);
    console.log(ress);

    function sha256(data) {
    return new Buffer(crypto.createHash('sha256').update(data).digest('binary'), 'binary');
    };
    function doubleSHA256(data) {
    return sha256(sha256(data));
    };

When I try to generate WIF from extendedprivatekey, but i am get invalid WIF.

Aug 29, 2018 in Blockchain by slayer
• 29,350 points
889 views

1 answer to this question.

0 votes

I found the answer to this in the WalletKey.js code:

var bitcore = require('bitcore');
var HierarchicalKey = bitcore.HierarchicalKey;
var Address = bitcore.Address;
var networks = bitcore.networks;
var coinUtil = bitcore.util;

var knownBytes = coinUtil.sha256('testing');
var hkey = HierarchicalKey.seed(knownBytes,'testnet');

var derived = hkey.derive('m/0\'/0/0');
var priv = new bitcore.PrivateKey(networks.testnet.privKeyVersion, derived.eckey.private, derived.eckey.compressed);
var wif = priv.toString();
answered Aug 29, 2018 by digger
• 26,740 points

Related Questions In Blockchain

0 votes
1 answer

Bitcoin private key: translate from bash to perl

use bignum; # Get arbitrary precision arithmetic # ...READ MORE

answered Sep 4, 2018 in Blockchain by slayer
• 29,350 points
1,016 views
0 votes
1 answer

BitcoinJ generate address from private key

Convert string private key into bytes[]: ECKey key = ...READ MORE

answered Sep 4, 2018 in Blockchain by slayer
• 29,350 points
2,067 views
+1 vote
3 answers

Not able to read a file from my assets folder

Hi.. I faced a similar problem in ...READ MORE

answered Oct 25, 2018 in Blockchain by Shrikanth
6,444 views
0 votes
1 answer

Not able to invoke a contract in Ethereum Private chain using geth

Hope this helps: contract mortal { /* ...READ MORE

answered Oct 22, 2018 in Blockchain by Omkar
• 69,210 points
718 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,450 points
1,129 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,663 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,215 views
0 votes
1 answer

Blockchain Hyperledger private key not able to send coins

From the code you posted, if(whichType == TX_SCRIPTHASH){//pay ...READ MORE

answered Sep 14, 2018 in Blockchain by digger
• 26,740 points
443 views
0 votes
1 answer
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