Esempio n. 1
0
def sighash(tx, i, prevScript, hashtype = SIGHASH_ALL):
    assert isinstance(tx, dict)
    i = int(i)

    newtx = copy.deepcopy(tx)
    for inp in newtx["ins"]:
        inp["script"] = b''

    s = script.deserialize(prevScript)
    s = [x for x in s if x is not script.Opcode.OP_CODESEPARATOR]
    newtx["ins"][i]["script"] = script.serialize(s)

    if hashtype & 0x1f == SIGHASH_NONE:
        newtx["outs"] = []
        for inp in range(len(newtx['ins'])):
            if inp != i:
                newtx['ins'][inp]['sequence'] = 0
    elif hashtype & 0x1f == SIGHASH_SINGLE:
        newtx["outs"] = newtx["outs"][:i+1]
        for out in range(i):
            newtx["outs"][out]['value'] = 2**64 - 1
            newtx["outs"][out]['script'] = b''
        for inp in range(len(newtx['ins'])):
            if inp != i:
                newtx['ins'][inp]['sequence'] = 0

    if hashtype & SIGHASH_ANYONECANPAY != 0:
        newtx["ins"] = [newtx["ins"][i]]

    hashbytes = convert.int_to_bytes_le(hashtype, 4)
    return hashes.hash256(serialize(newtx) + hashbytes)
Esempio n. 2
0
def b58check_to_bytes(b):
    data = b58_to_bytes(b)
    assert hashes.hash256(data[:-4])[:4] == data[-4:]
    return data[:-4]
Esempio n. 3
0
def bytes_to_b58check(b):
    assert isinstance(b, bytes)
    b += hashes.hash256(b)[:4]
    return bytes_to_b58(b)
Esempio n. 4
0
def txhash(tx):
    return hashes.hash256(tx)[::-1]