bitcoinjs / bip38

BIP38 is a standard process to encrypt Bitcoin and crypto currency private keys that is less susceptible to brute force attacks thus protecting the user.
http://cryptocoinjs.com/modules/currency/bip38/
MIT License
208 stars 100 forks source link

Altcoin encrypted wallets? #27

Closed proletesseract closed 7 years ago

proletesseract commented 7 years ago

Does this work with altcoins or only bitcoin? There's a comment in the code with a TODO about being bitcoin only?

I seem to get different values when i encrypt and decrypt a private key i have generated for my altcoin using your other library.

The WIF private key and public keys generated are correct and working, just this BIP38 encrypt / decyrpt gives me different values..

Also, i had to write the code different from your examples. It was complaining that Bip38 was not a contstructor. So here's my code

var CoinKey = require('coinkey')
var secureRandom = require('secure-random')
var qrcode = require('qrcode-generator')
var bip38 = require('bip38')
var wif = require('wif')

var version = {
    private: 0x96,
    public: 0x35
  }
  var bytes = secureRandom.randomBuffer(32)
  var key = new CoinKey(bytes, version)

  var decoded = wif.decode(key.privateWif)

  bip38.version = version;

  var encryptedKey = bip38.encrypt(decoded.privateKey, decoded.compressed, 'MyPassword', function (status) {
    console.log('encrypting', Math.round(status.percent), '%')
  })

  var decryptedKey = bip38.decrypt(encryptedKey, 'MyPassword', function (status) {
    console.log('decrypting', Math.round(status.percent), '%')
  })

  console.log(wif.encode(decryptedKey, decryptedKey.compressed), key.privateWif, decryptedKey, encryptedKey)

and the output:

12dsPqsKogz4yTLLVAVXLMTT5cMbKn1NYePLb5U6hPoVeLjVP2D2 PDcTA3vG4kQh95KZSXhUkTeWQnVSYYgQxuptXDSJMArFszXXfVPC Object {privateKey: Uint8Array(32), compressed: true} 6PYLsBPwgLhrtzfReFf4phQk9Yb3iLCtoXb8ehbVmiPfmeSQxaZdiftCoD

i thought the output of the wif.encode should match key.privateWif?

postaci commented 7 years ago

I had the same issue and it does not seem to support altcoins (as the TODO comment suggests). Instead of 0x00, 'pubKeyHash' property of corresponding altcoin network object should have been passed as first argument to writeUInt8 method in getAddress function.

dcousens commented 7 years ago

Closing in favour of https://github.com/bitcoinjs/bip38/issues/20, as that is where addressPrefix would come back in