def _verify(pubkey, signature, txhash, tx_b, prefix): try: verify(msg=tx_b, sign=signature, pk=pubkey) address = get_address(pk=pubkey, prefix=prefix) return pubkey, signature, txhash, address except ValueError: error = "Failed verify tx {}".format(hexlify(txhash).decode()) logging.debug(error) except BaseException as e: error = 'Signature verification error. "{}"'.format(e) logging.error(error) return pubkey, signature, txhash, error
def check_sign(self): d = { 'version': self.version, 'coin_id': self.coin_id, 'name': self.name, 'unit': self.unit, 'digit': self.digit, 'amount': self.amount, 'additional_issue': self.additional_issue, 'owner': self.owner } binary = bjson.dumps(d, compress=False) try: verify(msg=binary, sign=self.sign, pk=self.owner) except ValueError: raise MintCoinError('signature verification failed.')
def test(): PUB = '80d2ae0d784d28db38b5b85fd77e190981cea6f4328235ec173a90c2853c0761' PRI = '6a858fb93e0202fa62f894e591478caa23b06f90471e7976c30fb95efda4b312' MSG = "how silent! the cicada's voice soaks into the rocks. " \ "Up here, a stillness the sound of the cicadas seeps into the crags.".encode() address = get_address(pk=PUB, main_net=True) print(address) sign_raw = sign(msg=MSG, sk=PRI, pk=PUB) print(sign_raw) # raised ValueError if verification filed verify(msg=MSG, sign=sign_raw, pk=PUB) PUB2 = '28e8469422106f406051a24f2ea6402bac6f1977cf7e02eb3bf8c11d4070157a' PRI2 = '3c60f29c84b63c76ca8e3f1068ad328285ae8d5af2a95aa99ceb83d327dfb97e' print("pub2 address", get_address(pk=PUB2, main_net=True)) enc = encrypt(sk=PRI, pk=PUB2, msg=MSG) print(enc) dec = decrypt(sk=PRI2, pk=PUB, enc=enc) print(dec)
import os from time import time from nem_ed25519.signature import sign, verify import cProfile sk = '78f8932df54d22319a16dc4940c269205ae0946f98d38ef30aea488a47426153' pk = '77041bfb4b6afebc31aaab7b02d68e577fe069524b3c661c804b42ef381f717b' ck = 'NBOGOGSENUPBFMAPTGHVI4UIAQPVSNKJLWUVHBED' COUNT = 300 start = time() pr = cProfile.Profile() sign_list = list() pr.enable() for i in range(COUNT): msg = os.urandom(i + 1) signature = sign(msg, sk, pk) sign_list.append((msg, signature)) # pr.disable() for msg, signature in sign_list: verify(msg, signature, pk) pr.disable() print(round((time() - start) * 1000 / COUNT, 3), 'mS/sign&verify') pr.print_stats() # before 3.85 mS/sign&verify
def verify(msg, sign, pk): try: signature.verify(msg, sign, pk) return True except ValueError: return False