def test_verify_message_simple(self): address = "1F26pNMrywyZJdr22jErtKcjF8R3Ttt55G" message = address signature = "H85WKpqtNZDrajOnYDgUY+abh0KCAcOsAIOQwx2PftAbLEPRA7mzXA/CjXRxzz0MC225pR/hx02Vf2Ag2x33kU4=" message = BitcoinMessage(message) self.assertTrue(VerifyMessage(address, message, signature))
def test_verify_message_vectors(self) -> None: for vector in load_test_vectors('signmessage.json'): message = BitcoinMessage(vector['address']) self.assertTrue(VerifyMessage( P2PKHCoinAddress(vector['address']), message, vector['signature'] ))
def test_verify_message_simple(self) -> None: address = P2PKHCoinAddress("1F26pNMrywyZJdr22jErtKcjF8R3Ttt55G") message = str(address) signature = ("H85WKpqtNZDrajOnYDgUY+abh0KCAcOsAIOQwx2PftAbLEPRA7mzXA" "/CjXRxzz0MC225pR/hx02Vf2Ag2x33kU4=") message_to_verify = BitcoinMessage(message) self.assertTrue(VerifyMessage(address, message_to_verify, signature))
def print_verbose(signature, key, msg): secret = CBitcoinSecret(key) address = P2PKHBitcoinAddress.from_pubkey(secret.pub) message = BitcoinMessage(msg) print('Address: %s' % address) print('Message: %s' % msg) print('Signature: %s' % signature) print('Verified: %s' % VerifyMessage(address, message, signature)) print('\nTo verify using bitcoin core:') print('\n`bitcoin-cli verifymessage %s \'%s\' \'%s\'`\n' % (address, signature.decode('ascii'), msg))
def test_sign_message_simple(self): key = CBitcoinSecret( "L4vB5fomsK8L95wQ7GFzvErYGht49JsCPJyJMHpB4xGM6xgi2jvG") address = "1F26pNMrywyZJdr22jErtKcjF8R3Ttt55G" message = address message = BitcoinMessage(message) signature = SignMessage(key, message) self.assertTrue(signature) self.assertTrue(VerifyMessage(address, message, signature))
def print_verbose(signature: bytes, key: str, msg: str) -> None: secret = CCoinKey(key) address = P2PKHCoinAddress.from_pubkey(secret.pub) message = BitcoinMessage(msg) print('Address: %s' % str(address)) print('Message: %s' % msg) print('Signature: %s' % signature.decode('ascii')) print('Verified: %s' % VerifyMessage(address, message, signature)) print('\nTo verify using bitcoin core:') print('\n`bitcoin-cli verifymessage %s \'%s\' \'%s\'`\n' % (str(address), signature.decode('ascii'), msg))
def test_sign_message_simple(self) -> None: key = CBitcoinKey( "L4vB5fomsK8L95wQ7GFzvErYGht49JsCPJyJMHpB4xGM6xgi2jvG") address = P2PKHCoinAddress("1F26pNMrywyZJdr22jErtKcjF8R3Ttt55G") message = str(address) message_to_sign = BitcoinMessage(message) signature = SignMessage(key, message_to_sign) self.assertTrue(signature) self.assertTrue(VerifyMessage(address, message_to_sign, signature))
def test_sign_message_vectors(self): for vector in load_test_vectors('signmessage.json'): key = CBitcoinSecret(vector['wif']) message = BitcoinMessage(vector['address']) signature = SignMessage(key, message) self.assertTrue(signature, "Failed to sign for [%s]" % vector['address']) self.assertTrue( VerifyMessage(vector['address'], message, vector['signature']), "Failed to verify signature for [%s]" % vector['address'])
def sign_message(key, msg): secret = CBitcoinSecret(key) message = BitcoinMessage(msg) return SignMessage(secret, message)
def ecdsa_verify(msg, sig, pub): hashed_msg = BitcoinMessage(msg).GetHash() sig = base64.b64decode(sig) return ecdsa_raw_verify(hashed_msg, pub, sig, rawmsg=True)
def ecdsa_sign(msg, priv, formsg=False): hashed_msg = BitcoinMessage(msg).GetHash() sig = ecdsa_raw_sign(hashed_msg, priv, rawmsg=True, formsg=formsg) return base64.b64encode(sig).decode('ascii')
def sign_message(key: str, msg: str) -> bytes: secret = CCoinKey(key) message = BitcoinMessage(msg) return SignMessage(secret, message)