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
205 stars 100 forks source link

TypeError: Cannot read property 'copy' of undefined #29

Closed grio closed 7 years ago

grio commented 7 years ago

Decode function have a problem. The code is:

var bip38 = require('bip38')
var wif = require('wif')
var encryptedKey = '6PRVWUbkzzsbcVac2qwfssoUJAN1Xhrg6bNk8J7Nzm5H7kxEbn2Nh2ZoGg'
var decryptedKey = bip38.decrypt(encryptedKey, 'TestingOneTwoThree', function (status) {
    //console.log(status.percent) // will print the precent every time current increases by 1000
})
console.log(wif.encode(decryptedKey.privateKey, decryptedKey.compressed))

The error is:

$ node test.js 
/home/grio/temp/node_modules/wif/index.js:33
  privateKey.copy(result, 1)
            ^

TypeError: Cannot read property 'copy' of undefined
    at encodeRaw (/home/grio/temp/node_modules/wif/index.js:33:13)
    at Object.encode (/home/grio/temp/node_modules/wif/index.js:50:5)
    at Object.<anonymous> (/home/grio/temp/test.js:8:17)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:389:7)
dcousens commented 7 years ago

@grio encryptedKey should be a Buffer, not a String

var encryptedKey = Buffer.from('6PRVWUbkzzsbcVac2qwfssoUJAN1Xhrg6bNk8J7Nzm5H7kxEbn2Nh2ZoGg', 'hex')
grio commented 7 years ago

Still have a problem. `$ node de.js /home/grio/temp/node_modules/bs58check/index.js:46 if (!payload) throw new Error('Invalid checksum') ^

Error: Invalid checksum at Object.decode (/home/grio/temp/node_modules/bs58check/index.js:46:23) at Object.decrypt (/home/grio/temp/node_modules/bip38/index.js:130:31) at Object. (/home/grio/temp/de.js:4:26) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.runMain (module.js:604:10) at run (bootstrap_node.js:389:7) `