ethereumjs / ethereumjs-wallet

Utilities for handling Ethereum keys
MIT License
986 stars 295 forks source link

OpenSSL error in Node.js v17 and v18 #171

Closed odanado closed 1 year ago

odanado commented 2 years ago

I ran the following code and got an error.

import bip39 from "bip39";
import * as WalletOriginal from "ethereumjs-wallet";
import { interopImportCJSDefault } from "node-cjs-interop";

const Wallet = interopImportCJSDefault(WalletOriginal);
const { hdkey } = Wallet;

async function main(): Promise<void> {
  hdkey.fromMasterSeed(bip39.mnemonicToSeedSync("basket actual"));
}

main();

error

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)
    at Object.createHash (node:crypto:133:10)
    at hash160 (/Users/odan/source/github.com/odan-sandbox/hdwallet-provider-node18-sandbox/node_modules/ethereumjs-wallet/node_modules/ethereum-cryptography/vendor/hdkey-without-crypto.js:249:21)
    at HDKey.set (/Users/odan/source/github.com/odan-sandbox/hdwallet-provider-node18-sandbox/node_modules/ethereumjs-wallet/node_modules/ethereum-cryptography/vendor/hdkey-without-crypto.js:50:24)
    at Function.HDKey.fromMasterSeed (/Users/odan/source/github.com/odan-sandbox/hdwallet-provider-node18-sandbox/node_modules/ethereumjs-wallet/node_modules/ethereum-cryptography/vendor/hdkey-without-crypto.js:194:20)
    at Function.fromMasterSeed (/Users/odan/source/github.com/odan-sandbox/hdwallet-provider-node18-sandbox/node_modules/ethereumjs-wallet/src/hdkey.ts:13:36)
    at main (file:///Users/odan/source/github.com/odan-sandbox/hdwallet-provider-node18-sandbox/src/ethereumjs-wallet-sample.ts:9:9)
    at file:///Users/odan/source/github.com/odan-sandbox/hdwallet-provider-node18-sandbox/src/ethereumjs-wallet-sample.ts:12:1
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0) {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

The latest version (1.1.0) of ethereum-cryptography does not generate this error. You need to update the version of the dependent libraries.

Reproduction Repository: https://github.com/odan-sandbox/hdwallet-provider-node18-sandbox

eggplantzzz commented 2 years ago

I am also getting the same error while using Node 18 using the same function

const { hdkey } = require("ethereumjs-wallet");
let hdwallet = hdkey.fromMasterSeed(
  Buffer.from(mnemonicToSeedSync(mnemonic))
);

For more context, here is the function using this utility in our project.

azerella commented 1 year ago

This is still a problem in 1.0.2, can we please get #172 reviewed again?