class TestSignUnicode(unittest.TestCase): def setUp(self): self.api = BtcTxStore(dryrun=True, testnet=True) def test_sign_a(self): wif = fixtures["wallet"]["wif"] message = u"üöä" address = self.api.get_address(wif) sig = self.api.sign_unicode(wif, message) valid = self.api.verify_signature_unicode(address, sig, message) self.assertEqual(valid, True) def test_sign_b(self): wif = "cSuT2J14dYbe1zvB5z5WTXeRcMbj4tnoKssAK1ZQbnX5HtHfW3bi" message = u"üöä" address = self.api.get_address(wif) sig = self.api.sign_unicode(wif, message) valid = self.api.verify_signature_unicode(address, sig, message) self.assertEqual(valid, True)
def verify_signature(msg, wif, node_id=None): # FIXME use read instead assert(isinstance(msg, OrderedDict)) if u"signature" not in msg: return 0 msg = msg.copy() # work on a copy for thread saftey sig = msg.pop("signature") # Use our address. api = BtcTxStore(testnet=False, dryrun=True) try: if node_id is None: address = api.get_address(wif) ret = api.verify_signature_unicode(address, sig, str(msg)) else: address = node_id_to_address(node_id) ret = api.verify_signature_unicode(address, sig, str(msg)) except TypeError: return 0 return ret
# Copyright (c) 2015 Fabian Barkhau <*****@*****.**> # License: MIT (see LICENSE file) from __future__ import print_function from __future__ import unicode_literals from btctxstore import BtcTxStore import time import cProfile from pstats import Stats api = BtcTxStore(testnet=True, dryrun=True) # use testing setup for example wif = api.create_key() # create new private key address = api.get_address(wif) # get private key address message = "Signed ünicöde message." signature = api.sign_unicode(wif, message) profile = cProfile.Profile() profile.enable() begin = time.time() for i in range(10): assert (api.verify_signature_unicode(address, signature, message)) end = time.time() stats = Stats(profile) stats.strip_dirs() stats.sort_stats('cumtime') stats.print_stats() print(end - begin)
from __future__ import print_function from __future__ import unicode_literals from btctxstore import BtcTxStore import time import cProfile from pstats import Stats api = BtcTxStore(testnet=True, dryrun=True) # use testing setup for example wif = api.create_key() # create new private key address = api.get_address(wif) # get private key address message = "Signed ünicöde message." signature = api.sign_unicode(wif, message) profile = cProfile.Profile() profile.enable() begin = time.time() for i in range(10): assert(api.verify_signature_unicode(address, signature, message)) end = time.time() stats = Stats(profile) stats.strip_dirs() stats.sort_stats('cumtime') stats.print_stats() print(end - begin)