Example #1
0
def VerifyMessage(address, message, sig):
    sig = base64.b64decode(sig)
    hash = message.GetHash()

    pubkey = CPubKey.recover_compact(hash, sig)

    return str(P2PKHBitcoinAddress.from_pubkey(pubkey)) == str(address)
Example #2
0
    def is_valid(self):
        mb = BitcoinMessage(self.message)
        sig = base64.b64decode(self.sig)
        message_hash = mb.GetHash()

        #print("hash: %s" % message_hash.hex())
        pubkey = CPubKey.recover_compact(message_hash, sig)
        if not pubkey:
            return False
        #print("pubkey: %s" % pubkey.hex())
        if pubkey.hex() == self.address:
            return True
        for txin_type in ['p2pkh', 'p2wpkh', 'p2wpkh-p2sh']:
            addr = pubkey_to_address(txin_type, pubkey.hex())
            if addr == str(self.address):
                return True
        return False
    data = json.load(data_file)

pprint(data)
pprint(data['va'])
parts = data['va'].split('|')
pprint(parts)

msg = parts[0]
sig = parts[2]

pprint(sig)
sig = sig + "==="
pprint(sig)
sig = base64.b64decode(sig, '-_')

msg = BitcoinMessage(msg)
hash = msg.GetHash()

pubkey = CPubKey.recover_compact(hash, sig)
pprint(pubkey)
hex_bytes = binascii.hexlify(pubkey)
pprint(hex_bytes)

print('\n\n')
print('Address:')
print(data['ad'])

print('Pubkey:')
hex_str = hex_bytes.decode("ascii")
print(hex_str)