예제 #1
0
def CheckSig(sig, pubkey, script, txTo, inIdx, hashtype):
    key = CKey()
    key.set_pubkey(pubkey)

    if len(sig) == 0:
        return False
    if hashtype == 0:
        hashtype = ord(sig[-1])
    elif hashtype != ord(sig[-1]):
        return False
    sig = sig[:-1]

    tup = SignatureHash(script, txTo, inIdx, hashtype)
    return key.verify(ser_uint256(tup[0]), sig)
예제 #2
0
def CheckSig(sig, pubkey, script, txTo, inIdx, hashtype):
    key = CKey()
    key.set_pubkey(pubkey)

    if len(sig) == 0:
        return False
    if hashtype == 0:
        hashtype = ord(sig[-1])
    elif hashtype != ord(sig[-1]):
        return False
    sig = sig[:-1]

    tup = SignatureHash(script, txTo, inIdx, hashtype)
    return key.verify(ser_uint256(tup[0]), sig)
예제 #3
0
def verify(jsonbuf):
    '''
    :param jsondoc: str with JSON
    :type jsondoc: str
    returns: bool - True if signature verification succeeds
    :raises: BadJSONError
    '''
    basedict = {}
    jsondoc = json.loads(jsonbuf)
    signatures = jsondoc.get('signatures', [])

    if not len(signatures):
        raise BadJSONError('Signatures not found')

    for key in jsondoc.get('signed_keys', []):
        value = jsondoc.get(key, None)
        if not value:
            raise BadJSONError('Missing attribute: %s' % (repr(key), ))
        basedict[key] = value

    ckey = CKey()
    sigchecks = []
    for signature_dict in signatures:
        if 'secp256k1' != signature_dict.get('signature_type', ''):
            continue
        sig = binascii.unhexlify(signature_dict.get('signature', ''))
        pubkey = binascii.unhexlify(signature_dict.get('pubkey', ''))
        sigdict = {}
        for key in signature_dict.get('extra_signed_keys', []):
            value = jsondoc.get(key, None)
            if not value:
                raise BadJSONError('Missing attribute: %s' % (repr(key), ))
            sigdict[key] = value
        sigdict.update(basedict)
        ckey.set_pubkey(pubkey)
        instr = json.dumps(sigdict, separators=(',', ':'), sort_keys=True)
        hash = hashlib.sha256(hashlib.sha256(instr).digest()).digest()
        sigchecks.append(ckey.verify(hash, sig))

    return (sigchecks and 0 not in sigchecks and -1 not in sigchecks)
예제 #4
0
def verify(jsonbuf):
    '''
    :param jsondoc: str with JSON
    :type jsondoc: str
    returns: bool - True if signature verification succeeds
    :raises: BadJSONError
    '''
    basedict = {}
    jsondoc = json.loads(jsonbuf)
    signatures = jsondoc.get('signatures', [])
    
    if not len(signatures):
        raise BadJSONError('Signatures not found')
    
    for key in jsondoc.get('signed_keys', []):
        value = jsondoc.get(key, None)
        if not value:
            raise BadJSONError('Missing attribute: %s' % (repr(key),))
        basedict[key] = value
        
    ckey = CKey()
    sigchecks = []
    for signature_dict in signatures:
        if 'secp256k1' != signature_dict.get('signature_type', ''):
            continue
        sig = binascii.unhexlify(signature_dict.get('signature', ''))
        pubkey = binascii.unhexlify(signature_dict.get('pubkey', ''))
        sigdict = {}
        for key in signature_dict.get('extra_signed_keys', []):
            value = jsondoc.get(key, None)
            if not value:
                raise BadJSONError('Missing attribute: %s' % (repr(key),))
            sigdict[key] = value
        sigdict.update(basedict)
        ckey.set_pubkey(pubkey)
        instr = json.dumps(sigdict, separators=(',',':'), sort_keys=True)
        hash = hashlib.sha256(hashlib.sha256(instr).digest()).digest()
        sigchecks.append(ckey.verify(hash, sig))
        
    return (sigchecks and 0 not in sigchecks and -1 not in sigchecks)