Closed maciejhirsz closed 7 years ago
Good catch, thanks!
Was this patched? I'm still having some issues with using an empty password
[machinehum@localhost geth]$ cat get_key.js
var keythereum = require("keythereum");
const PASSWORD = '';
var keyObject = keythereum.importFromFile('aa2896c25489aa2629626d11481556d9a4bf59f4', 'node01');
var privateKey = keythereum.recover(PASSWORD, keyObject);
console.log(privateKey.toString('hex'));
[machinehum@localhost geth]$ node get_key.js
/home/machinehum/geth/node_modules/scrypt-js/scrypt.js:274
throw new Error('password must be an array or buffer');
^
Error: password must be an array or buffer
at _scrypt (/home/machinehum/geth/node_modules/scrypt-js/scrypt.js:274:19)
at Object.syncScrypt (/home/machinehum/geth/node_modules/scrypt-js/scrypt.js:463:35)
at Object.deriveKeyUsingScrypt (/home/machinehum/geth/node_modules/keythereum/index.js:196:33)
at Object.deriveKey (/home/machinehum/geth/node_modules/keythereum/index.js:225:19)
at Object.recover (/home/machinehum/geth/node_modules/keythereum/index.js:430:36)
at Object.<anonymous> (/home/machinehum/geth/get_key.js:5:29)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
Confirmed it works fine on a UTC w/ a key.
Passing an empty array var PASSWORD = [];
works.
deriveKey
internally performs aif (password && salt)
before proceeding. This works fine for most scenarios, but will fail whenpassword
is an empty string (which should still be a valid use case).Additionally when it does fail, it does not throw an informative exception, it just returns undefined and tends to cause a confusing error somewhere down the line (calling
slice
ofundefined
and what not).Suggested tweaks:
password != null
ortypeof password === 'string'
.password
orsalt
are missing, throw an exception.