diff --git a/bitcoinlib/encoding.py b/bitcoinlib/encoding.py index 7196fe81..e970610d 100644 --- a/bitcoinlib/encoding.py +++ b/bitcoinlib/encoding.py @@ -962,12 +962,20 @@ def bip38_decrypt(encrypted_privkey, password): :return tupple (bytes, bytes): (Private Key bytes, 4 byte address hash for verification) """ - d = change_base(encrypted_privkey, 58, 256)[2:] - flagbyte = d[0:1] - d = d[1:] + d = change_base(encrypted_privkey, 58, 256) + identifier = d[0:2] + flagbyte = d[2:3] + d = d[3:] + # ec_multiply = False + if identifier == b'\x01\x43': + # ec_multiply = True + raise EncodingError("EC multiply BIP38 keys are not supported at the moment") + elif identifier != b'\x01\x42': + raise EncodingError("Unknown BIP38 identifier, value must be 0x0142 (non-EC-multiplied) or " + "0x0143 (EC-multiplied)") if flagbyte == b'\xc0': compressed = False - elif flagbyte == b'\xe0': + elif flagbyte == b'\xe0' or flagbyte == b'\x20': compressed = True else: raise EncodingError("Unrecognised password protected key format. Flagbyte incorrect.")