cryptocoinjs / coinkey

JavaScript component for private keys, public keys, and addresess for crypto currencies such as Bitcoin, Litecoin, and Dogecoin
149 stars 58 forks source link

Issue with creating WIF from private key hex #6

Closed admin4life closed 6 years ago

admin4life commented 6 years ago

It looks like coinkey is creating a valid WIF addresses from private key hex. However, they are the wrong WIF address. One example is a0dc65ffca799873cbea0ac274015b9526505daaaed385155425f7337704883e

If you use

var buffer = new Buffer("a0dc65ffca799873cbea0ac274015b9526505daaaed385155425f7337704883e",'hex')

var ck = coinkey(buffer)

The resulting WIF is L2cQMfbGpih4yTTTa3Dx4YHo4CLXqvJ5rKsggs9iswuXQYECC8aK

However, it should be 5K38ZKiJBMmsk9iLcaakHfMa6FoZpLKpmhyo9aZnjossPc49J7e

I might be all wrong as I'm no expert I was just trying to verify my own code against an established library. But all other sources I've tried to check against point to the coinstring code being wrong (which you are also the owner of). Please let me know if I'm wrong. The basic code I'm using to generate a WIF is here

  var bs58 = require('bs58')
  var privateKeyHex = privateKeyBuffer.toString('hex')
  var keyVersion = "80"+privateKeyHex
  var newKeyBuffer = Buffer.from(keyVersion, 'hex');
  var round1 = sha256Buffer(newKeyBuffer);
  var round2 = sha256Buffer(round1.digest());
  var checksum = round2.digest('hex').substr(0,8).toUpperCase();
  var keyWithChecksum = keyVersion + checksum;
  var wifKey = bs58.encode(Buffer.from(keyWithChecksum, 'hex'));
fanatid commented 6 years ago

By default key is compressed, because this result L2cQMfbGpih4yTTTa3Dx4YHo4CLXqvJ5rKsggs9iswuXQYECC8aK.

5K38ZKiJBMmsk9iLcaakHfMa6FoZpLKpmhyo9aZnjossPc49J7e also valid, but this WIF key for uncompressed public key.