Beispiel #1
0
async def verify_signature(message):
    """Verifies a signature of a message, return True if verified, false if not"""
    loop = asyncio.get_event_loop()

    sig_raw = bytes(bytearray.fromhex(message["signature"]))
    sig = NulsSignature(sig_raw)

    sender_hash = hash_from_address(message["sender"])
    (sender_chain_id, ) = struct.unpack("h", sender_hash[:2])

    hash = public_key_to_hash(sig.pub_key, sender_chain_id)

    address = address_from_hash(hash)
    if address != message["sender"]:
        LOGGER.warning("Received bad signature from %s for %s" %
                       (address, message["sender"]))
        return False

    verification = await get_verification_buffer(message)
    try:
        result = await run_in_executor(None, sig.verify, verification)
    except Exception:
        LOGGER.exception("NULS Signature verification error")
        result = False
    # result = sig.verify(verification)
    return result
def test_sign_data_deprecated():
    """Test the data signature"""
    data = None
    signature = NulsSignature(data=data)

    delete_private_key_file()
    private_key = get_fallback_private_key()

    assert signature
    sign_deprecated: NulsSignatureSecp256k1 = (
        NulsSignatureSecp256k1.sign_data_deprecated(pri_key=private_key,
                                                    digest_bytes=b"x" *
                                                    (256 // 8)))
    assert sign_deprecated