NomicFoundation/hardhat

Hardhat's key derivation doesn't work with Node 17

Closed this issue ยท 12 comments

Hello, just install hardhat on my local project, windows os version 10.
Iam trying to run task hardhat accounts and getting this errors :

An unexpected error occurred:

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)
    at Object.createHash (node:crypto:130:10)
    at hash160 (F:\ROXI-Repositories\ROXI Company\Roxi Token Development\hardhat-1\node_modules\ethereum-cryptography\vendor\hdkey-without-crypto.js:249:21)
    at HDKey.set (F:\ROXI-Repositories\ROXI Company\Roxi Token Development\hardhat-1\node_modules\ethereum-cryptography\vendor\hdkey-without-crypto.js:50:24)
    at Function.HDKey.fromMasterSeed (F:\ROXI-Repositories\ROXI Company\Roxi Token Development\hardhat-1\node_modules\ethereum-cryptography\vendor\hdkey-without-crypto.js:194:20)
    at Object.deriveKeyFromMnemonicAndPath (F:\ROXI-Repositories\ROXI Company\Roxi Token Development\hardhat-1\node_modules\hardhat\src\internal\util\keys-derivation.ts:21:27)
    at derivePrivateKeys (F:\ROXI-Repositories\ROXI Company\Roxi Token Development\hardhat-1\node_modules\hardhat\src\internal\core\providers\util.ts:29:24)
    at Object.normalizeHardhatNetworkAccountsConfig (F:\ROXI-Repositories\ROXI Company\Roxi Token Development\hardhat-1\node_modules\hardhat\src\internal\core\providers\util.ts:56:10)     
    at Object.createProvider (F:\ROXI-Repositories\ROXI Company\Roxi Token Development\hardhat-1\node_modules\hardhat\src\internal\core\providers\construction.ts:75:22)
    at F:\ROXI-Repositories\ROXI Company\Roxi Token Development\hardhat-1\node_modules\hardhat\src\internal\core\runtime-environment.ts:80:14 {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Here is my actual devDependencies :

  "devDependencies": {
    "@nomiclabs/hardhat-ethers": "^2.0.2",
    "@nomiclabs/hardhat-waffle": "^2.0.1",
    "chai": "^4.3.4",
    "ethereum-waffle": "^3.4.0",
    "ethers": "^5.5.1",
    "hardhat": "^2.6.7"
  }

thanks you

Are you using node 17?

If so, please try downgrading it.

For an explanation of what's going on, please take a look at this: https://medium.com/the-node-js-collection/node-js-17-is-here-8dba1e14e382#5f07

yes i am using v17.0.1, okay i will try. thank you
will update you soon

tldrs commented

try using node 14 it works best or just install WSL2 Ubuntu or any Linux distro on your machine if you hit more config problems.

The workarround for this is to set the following environmental variable:

export NODE_OPTIONS=--openssl-legacy-provider

remains an issue when that option is set with node 17.3.0

$ npx hardhat accounts
An unexpected error occurred:

Error: error:0308010C:digital envelope routines::unsupported
โ”‚ โ”‚ at new Hash (node:internal/crypto/hash:67:19)
โ”‚ โ”‚ at Object.createHash (node:crypto:130:10)
โ”‚ โ”‚ at hash160 (~/Desktop/crypto/hardhat-quickstart/node_modules/ethereum-cryptography/vendor/hdkey-without-crypto.js:249:21)
โ”‚ โ”‚ at HDKey.set (~/Desktop/crypto/hardhat-quickstart/node_modules/ethereum-cryptography/vendor/hdkey-without-crypto.js:50:24)
โ”‚ โ”‚ at Function.HDKey.fromMasterSeed (~/Desktop/crypto/hardhat-quickstart/node_modules/ethereum-cryptography/vendor/hdkey-without-crypto.js:194:20)
โ”‚ โ”‚ at deriveKeyFromMnemonicAndPath (~/Desktop/crypto/hardhat-quickstart/node_modules/hardhat/src/internal/util/keys-derivation.ts:21:27)
โ”‚ โ”‚ at derivePrivateKeys (~/Desktop/crypto/hardhat-quickstart/node_modules/hardhat/src/internal/core/providers/util.ts:29:52)
โ”‚ โ”‚ at normalizeHardhatNetworkAccountsConfig (~/Desktop/crypto/hardhat-quickstart/node_modules/hardhat/src/internal/core/providers/util.ts:56:10)
โ”‚ โ”‚ at createProvider (~/Desktop/crypto/hardhat-quickstart/node_modules/hardhat/src/internal/core/providers/construction.ts:78:59)
โ”‚ โ”‚ at ~/Desktop/crypto/hardhat-quickstart/node_modules/hardhat/src/internal/core/runtime-environment.ts:80:28 {
โ”‚ opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
โ”‚ library: 'digital envelope routines',
โ”‚ reason: 'unsupported',
โ”‚ code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

$ node -v
v17.3.0

$ echo $NODE_OPTIONS
--openssl-legacy-provider

I use asdf to manage my node versions and I tried every 17.x.x version and it wasn't until I went down to LTS v16.13.1 before this worked. For those in my situation, if you're going to use an older (long term support) version of node, remember to remove the --openssl-legacy-provider option in your NODE_OPTIONS environment variable

Will Hardhat work to make node 17+ be compatible?

The fix for this (upgrading ethereum-cryptography) has been implemented in this PR: #2705

opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
library: 'digital envelope routines',
reason: 'unsupported',
code: 'ERR_OSSL_EVP_UNSUPPORTED'

% node -v
v16.15.0

I initial downgrade hardhat from node 17 to 16.5.0 and it worked for a while. Recently it completely broke on me. Not sure whats gonig on.

This issue was marked as stale because it didn't have any activity in the last 30 days. If you think it's still relevant, please leave a comment indicating so. Otherwise, it will be closed in 7 days.

greetings!

I have the same issue and being working with a technology (blockchain) that its heart and core is cryptography and being using a tool that doesn't worry to be working with an outdated cryptographyc "framework" / algorithms seems pretty concerning to me

*Just like openssl points:
https://www.openssl.org/docs/manmaster/man7/OSSL_PROVIDER-legacy.html

_**"The OpenSSL legacy provider supplies OpenSSL implementations of algorithms that have been deemed legacy. Such algorithms have commonly fallen out of use, have been deemed insecure by the cryptography community, or something similar.

We can consider this the retirement home of cryptographic algorithms.**_"

I'm going to close this one because node 17 has already reached end of life and, as far as I know, this works well with node 18.

If someone has some problem around this, please open a new issue with reproduction steps.