ethereumjs/keythereum

TypeError: Cannot read properties of undefined (reading 'iv')

JohnWestlund opened this issue · 3 comments

Getting the following error:

/key/node_modules/keythereum/index.js:411
    iv = this.str2buf(keyObjectCrypto.cipherparams.iv);
                                                   ^

TypeError: Cannot read properties of undefined (reading 'iv')
    at Object.recover (/Users/jawestlu/Downloads/key/node_modules/keythereum/index.js:411:52)
    at Object.<anonymous> (/Users/jawestlu/Downloads/key/test.js:8:31)
    at Module._compile (node:internal/modules/cjs/loader:1246:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1300:10)
    at Module.load (node:internal/modules/cjs/loader:1103:32)
    at Module._load (node:internal/modules/cjs/loader:942:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47

Node.js v19.5.0

Executing using this code:

const fs = require("fs");
const keythereum = require("keythereum");

const KEYSTORE = "/key/key.json";
const PASSWORD = "*****";

const keyObject = JSON.parse(fs.readFileSync(KEYSTORE, {encoding: "utf8"}));
const privateKey = keythereum.recover(PASSWORD, keyObject).toString("hex");
console.log(`0x${keyObject.address}: 0x${privateKey}`);

These are the keys in the json:

"crypto":
"kdf":
"function":
"params":
"dklen":
"salt":
"n":
"r":
"p":
"message":
"checksum":
"function":
"params":
"message":
"cipher":
"function":
"params":
"iv":
"message":
"description":
"pubkey":
"path":
"uuid":
"version":

What's your use case with this library? We no longer maintain this library and this same functionality should be available in ethers via the ethers.wallet.fromEncryptedJson method call. If that's not applicable, let us know and we'll see if we can help further.

I've got a keystore file from when I staked 2 years ago. I have the password and the keystore tests as valid, but I'm trying to get the privatekey/mnemonic back out of it.

I've got a keystore file from when I staked 2 years ago. I have the password and the keystore tests as valid, but I'm trying to get the privatekey/mnemonic back out of it.

Gotcha, try ethers. If that doesn't work, we can look at this code again but it's hasn't been touched in years