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,050 points
52 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
• 27,630 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,050 points
173 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,050 points
233 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
556 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
• 67,290 points
39 views
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 ariaholic
• 7,340 points
63 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
126 views
0 votes
1 answer
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
• 27,630 points
61 views
0 votes
1 answer