From fe5f9b60d694cda59ab51544164cc329e2dbdd52 Mon Sep 17 00:00:00 2001 From: Lennart Date: Mon, 15 Jan 2024 14:04:57 +0100 Subject: [PATCH] Raise more informative error when trying to use unsupported EC multiplied BIP38 key --- bitcoinlib/encoding.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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.")