terra.py: MnemonicKey get error bad key length

  • terra_sdk version:2.0.5
  • Python version:3.8.9
  • Operating System: Mac os 12.1

Description

mnemonic = 'notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius'
mk = MnemonicKey(mnemonic=mnemonic)

What I Did

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/edison/Library/Python/3.8/lib/python/site-packages/terra_sdk/key/mnemonic.py", line 59, in __init__
    seed = Mnemonic("english").to_seed(mnemonic)
  File "/Users/edison/Library/Python/3.8/lib/python/site-packages/mnemonic/mnemonic.py", line 249, in to_seed
    stretched = hashlib.pbkdf2_hmac("sha512", mnemonic, passphrase, PBKDF2_ROUNDS)
ValueError: [digital envelope routines: CRYPTO_internal] bad key length

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

Install as:

pyenv install 3.10.3

Set as default

pyenv global 3.10.3

Add to the path (.zshrc or .bashrc)

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/shims/:$PATH"

Reload the terminal and check

❯ python3 -V
Python 3.10.3

Check if the following works

❯ cat test.py
from terra_sdk.client.lcd import LCDClient
from terra_sdk.key.mnemonic import MnemonicKey

mk = MnemonicKey(mnemonic='notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius')
terra = LCDClient("https://lcd.terra.dev", "columbus-5")
wallet = terra.wallet(mk)
print(wallet.key.acc_address)
❯ python3 test.py
terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v

If works, send @Vritra4 a hug ❤️ !

Thank you sir, I’ll give it a try !

python3 -c "import ssl; print(ssl.OPENSSL_VERSION)"

LibreSSL 2.8.3

@Vritra4 more info

❯ python3 test.py
Traceback (most recent call last):
  File "test.py", line 4, in <module>
    mk = MnemonicKey(mnemonic='notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius')
  File "/Users/vini/Library/Python/3.8/lib/python/site-packages/terra_sdk/key/mnemonic.py", line 59, in __init__
    seed = Mnemonic("english").to_seed(mnemonic)
  File "/Users/vini/Library/Python/3.8/lib/python/site-packages/mnemonic/mnemonic.py", line 249, in to_seed
    stretched = hashlib.pbkdf2_hmac("sha512", mnemonic, passphrase, PBKDF2_ROUNDS)
ValueError: [digital envelope routines: CRYPTO_internal] bad key length
❯ cat test.py
from terra_sdk.client.lcd import LCDClient
from terra_sdk.key.mnemonic import MnemonicKey

mk = MnemonicKey(mnemonic='notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius')
terra = LCDClient("https://lcd.terra.dev", "columbus-5")
wallet = terra.wallet(mk)
print(wallet.key.acc_address)

I’m on LibreSSL 2.8.3 as well. I’m not sure what is causing this error tho but i can confirm 2x is not working for me on my mac but works on my dev vm running on .