Exemplo n.º 1
0
def decode_pubkey(pub,formt=None):
    if not formt: formt = get_pubkey_format(pub)
    if formt == 'decimal': return pub
    elif formt == 'bin': return (decode(pub[1:33],256),decode(pub[33:65],256))
    elif formt == 'bin_compressed':
        x = decode(pub[1:33],256)
        beta = pow(x*x*x+B,(P+1)//4,P)
        y = (P-beta) if ((beta + b2i(pub[0])) % 2) else beta
        return (x,y)
    elif formt == 'hex': return (decode(pub[2:66],16),decode(pub[66:130],16))
    elif formt == 'hex_compressed': return decode_pubkey(binascii.unhexlify(pub),'bin_compressed')
    elif formt == 'bin_electrum': return (decode(pub[:32],256),decode(pub[32:64],256))
    elif formt == 'hex_electrum': return (decode(pub[:64],16),decode(pub[64:128],16))
    else: raise Exception("Invalid format!")
Exemplo n.º 2
0
def decode_pubkey(pub, formt=None):
    if not formt: formt = get_pubkey_format(pub)
    if formt == 'decimal': return pub
    elif formt == 'bin':
        return (decode(pub[1:33], 256), decode(pub[33:65], 256))
    elif formt == 'bin_compressed':
        x = decode(pub[1:33], 256)
        beta = pow(x * x * x + B, (P + 1) // 4, P)
        y = (P - beta) if ((beta + b2i(pub[0])) % 2) else beta
        return (x, y)
    elif formt == 'hex':
        return (decode(pub[2:66], 16), decode(pub[66:130], 16))
    elif formt == 'hex_compressed':
        return decode_pubkey(binascii.unhexlify(pub), 'bin_compressed')
    elif formt == 'bin_electrum':
        return (decode(pub[:32], 256), decode(pub[32:64], 256))
    elif formt == 'hex_electrum':
        return (decode(pub[:64], 16), decode(pub[64:128], 16))
    else:
        raise Exception("Invalid format!")
Exemplo n.º 3
0
def decode_sig(sig):
    bytez = base64.b64decode(sig)
    return b2i(bytez[0]), decode(bytez[1:33],256), decode(bytez[33:],256)
Exemplo n.º 4
0
def get_version_byte(inp):
    leadingzbytes = len(re.match(b'^1*',inp).group(0))
    data = b'\x00' * leadingzbytes + changebase(inp,58,256)
    assert bin_dbl_sha256(data[:-4])[:4] == data[-4:]
    return b2i(data[0])
Exemplo n.º 5
0
def decode_sig(sig):
    bytez = base64.b64decode(sig)
    return b2i(bytez[0]), decode(bytez[1:33], 256), decode(bytez[33:], 256)
Exemplo n.º 6
0
def get_version_byte(inp):
    leadingzbytes = len(re.match(b'^1*', inp).group(0))
    data = b'\x00' * leadingzbytes + changebase(inp, 58, 256)
    assert bin_dbl_sha256(data[:-4])[:4] == data[-4:]
    return b2i(data[0])