88import re
99import secrets
1010
11- from Crypto .Cipher import AES
1211from collections import namedtuple
1312from typing import Dict , List , Sequence , Tuple , Union , Callable
1413
1514from shamir_mnemonic import generate_mnemonics
1615
1716import hdwallet
17+
18+ # Support for private key encryption via BIP-38 and Ethereum JSON wallet is optional; pip install slip39[wallet]
19+ try :
20+ from Crypto .Cipher import AES
21+ except ImportError :
22+ AES = None
1823try :
1924 import scrypt
2025except ImportError :
@@ -245,7 +250,7 @@ def from_encrypted( self, encrypted_privkey, passphrase, strict=True ):
245250
246251 def bip38 ( self , passphrase , flagbyte = b'\xe0 ' ):
247252 """BIP-38 encrypt the private key"""
248- if not scrypt :
253+ if not scrypt or not AES :
249254 raise NotImplementedError ( "The scrypt module is required to support BIP-38 encryption; pip install slip39[wallet]" )
250255 if self .crypto not in self .BIP38_ENCRYPT :
251256 raise NotImplementedError ( f"{ self .crypto } does not support BIP-38 private key encryption" )
@@ -267,7 +272,7 @@ def bip38( self, passphrase, flagbyte=b'\xe0' ):
267272
268273 def from_bip38 ( self , encrypted_privkey , passphrase , strict = True ):
269274 """Bip-38 decrypt and import the private key."""
270- if not scrypt :
275+ if not scrypt or not AES :
271276 raise NotImplementedError ( "The scrypt module is required to support BIP-38 decryption; pip install slip39[wallet]" )
272277 if self .crypto not in self .BIP38_ENCRYPT :
273278 raise NotImplementedError ( f"{ self .crypto } does not support BIP-38 private key decryption" )
0 commit comments