This commit is contained in:
SomberNight 2018-03-11 07:18:07 +01:00
parent d71d22d279
commit e31c2d491d

View file

@ -408,7 +408,10 @@ def base_decode(v, length, base):
chars = __b43chars
long_value = 0
for (i, c) in enumerate(v[::-1]):
long_value += chars.find(bytes([c])) * (base**i)
digit = chars.find(bytes([c]))
if digit == -1:
raise ValueError('Forbidden character {} for base {}'.format(c, base))
long_value += digit * (base**i)
result = bytearray()
while long_value >= 256:
div, mod = divmod(long_value, 256)
@ -428,6 +431,10 @@ def base_decode(v, length, base):
return bytes(result)
class InvalidChecksum(Exception):
pass
def EncodeBase58Check(vchIn):
hash = Hash(vchIn)
return base_encode(vchIn + hash[0:4], base=58)
@ -440,7 +447,7 @@ def DecodeBase58Check(psz):
hash = Hash(key)
cs32 = hash[0:4]
if cs32 != csum:
return None
raise InvalidChecksum('expected {}, actual {}'.format(bh2u(cs32), bh2u(csum)))
else:
return key
@ -479,8 +486,9 @@ def deserialize_privkey(key):
if ':' in key:
txin_type, key = key.split(sep=':', maxsplit=1)
assert txin_type in SCRIPT_TYPES
try:
vch = DecodeBase58Check(key)
if not vch:
except BaseException:
neutered_privkey = str(key)[:3] + '..' + str(key)[-2:]
raise BaseException("cannot deserialize", neutered_privkey)