mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
bitcoin.py: nicer exception in deserialize_privkey if prefix byte is invalid
related: #4364
This commit is contained in:
parent
b175c6b609
commit
a94e1d92a3
1 changed files with 7 additions and 2 deletions
|
@ -567,11 +567,16 @@ def deserialize_privkey(key):
|
|||
|
||||
if txin_type is None:
|
||||
# keys exported in version 3.0.x encoded script type in first byte
|
||||
txin_type = inv_dict(SCRIPT_TYPES)[vch[0] - constants.net.WIF_PREFIX]
|
||||
prefix_value = vch[0] - constants.net.WIF_PREFIX
|
||||
inverse_script_types = inv_dict(SCRIPT_TYPES)
|
||||
try:
|
||||
txin_type = inverse_script_types[prefix_value]
|
||||
except KeyError:
|
||||
raise BitcoinException('invalid prefix ({}) for WIF key (1)'.format(vch[0]))
|
||||
else:
|
||||
# all other keys must have a fixed first byte
|
||||
if vch[0] != constants.net.WIF_PREFIX:
|
||||
raise BitcoinException('invalid prefix ({}) for WIF key'.format(vch[0]))
|
||||
raise BitcoinException('invalid prefix ({}) for WIF key (2)'.format(vch[0]))
|
||||
|
||||
if len(vch) not in [33, 34]:
|
||||
raise BitcoinException('invalid vch len for WIF key: {}'.format(len(vch)))
|
||||
|
|
Loading…
Add table
Reference in a new issue