def sigcheck(a_key, a_hash_for_sig, a_sig): """ Returns True if a_key was used to generate a_sig from a_hash_for_sig; False otherwise. """ r, s = sigdecode_der(a_sig) return ecdsa_verify(generator_secp256k1, a_key.public_pair(), a_hash_for_sig, ( r, s ))
def sigcheck(a_key, a_hash_for_sig, a_sig): """ Returns True if a_key was used to generate a_sig from a_hash_for_sig; False otherwise. """ r, s = sigdecode_der(a_sig) return ecdsa_verify(generator_secp256k1, a_key.public_pair(), a_hash_for_sig, (r, s))
def get_signature(sign_hex, unsign_hex, pubkey): rs = sigdecode_der(h2b(sign_hex)) r, s = rs bin_pubkey = b2h(encode_pubkey(h2b(pubkey), 'bin')) for v in [27, 28, 29, 30, 31]: v, r, s = decode_sig(encode_sig(v, r, s)) Q = ecdsa_raw_recover(h2b(unsign_hex), (v, r, s)) pubkey = encode_pubkey(Q, 'hex_compressed' if v >= 30 else 'hex') if pubkey != bin_pubkey: continue else: return v, r, s return v, r, s
def verify(self, h, sig): """ Return whether a signature is valid for hash h using this key. """ val = from_bytes_32(h) pubkey = self.public_pair() rs = sigdecode_der(sig) if self.public_pair() is None: # find the pubkey from the signature and see if it matches # our key possible_pubkeys = secp256k1_generator.possible_public_pairs_for_signature(val, rs) hash160 = self.hash160() for candidate in possible_pubkeys: if hash160 == public_pair_to_hash160_sec(candidate, True): pubkey = candidate break if hash160 == public_pair_to_hash160_sec(candidate, False): pubkey = candidate break else: # signature is using a pubkey that's not this key return False return secp256k1_generator.verify(pubkey, val, rs)
def verify(self, h, sig): """ Return whether a signature is valid for hash h using this key. """ val = from_bytes_32(h) pubkey = self.public_pair() rs = sigdecode_der(sig) if self.public_pair() is None: # find the pubkey from the signature and see if it matches # our key possible_pubkeys = ecdsa.possible_public_pairs_for_signature( ecdsa.generator_secp256k1, val, rs) hash160 = self.hash160() for candidate in possible_pubkeys: if hash160 == public_pair_to_hash160_sec(candidate, True): pubkey = candidate break if hash160 == public_pair_to_hash160_sec(candidate, False): pubkey = candidate break else: # signature is using a pubkey that's not this key return False return ecdsa.verify(ecdsa.generator_secp256k1, pubkey, val, rs)