ethereumjs / keythereum

Create, import and export Ethereum keys
MIT License
609 stars 163 forks source link

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

Open JohnWestlund opened 1 year ago

JohnWestlund commented 1 year ago

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":
acolytec3 commented 1 year ago

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.

JohnWestlund commented 1 year ago

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.

acolytec3 commented 1 year ago

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