Exemplo n.º 1
0
async def verify_message(ctx, msg):
    digest = message_digest(msg.message)
    if len(msg.signature) != 65:
        raise wire.DataError("Invalid signature")
    sig = bytearray([msg.signature[64]]) + msg.signature[:64]

    try:
        pubkey = secp256k1.verify_recover(sig, digest)
    except ValueError:
        raise wire.DataError("Invalid signature")

    if not pubkey:
        raise wire.DataError("Invalid signature")

    pkh = sha3_256(pubkey[1:], keccak=True).digest()[-20:]

    address_bytes = bytes_from_address(msg.address)
    if address_bytes != pkh:
        raise wire.DataError("Invalid signature")

    address = address_from_bytes(address_bytes)

    await require_confirm_verify_message(ctx, address, msg.message)

    return Success(message="Message verified")
Exemplo n.º 2
0
async def verify_message(ctx, msg):
    digest = message_digest(msg.message)
    sig = bytearray([msg.signature[64]]) + msg.signature[:64]
    pubkey = secp256k1.verify_recover(sig, digest)

    if not pubkey:
        raise ValueError("Invalid signature")

    pkh = sha3_256(pubkey[1:], keccak=True).digest()[-20:]

    if msg.address != pkh:
        raise ValueError("Invalid signature")

    address = "0x" + hexlify(msg.address).decode()

    await require_confirm_verify_message(ctx, address, msg.message)

    return Success(message="Message verified")
Exemplo n.º 3
0
async def ethereum_verify_message(ctx, msg):

    digest = message_digest(msg.message)
    sig = bytearray([msg.signature[64]]) + msg.signature[:64]
    pubkey = secp256k1.verify_recover(sig, digest)

    if not pubkey:
        raise ValueError('Invalid signature')

    pkh = sha3_256(pubkey[1:]).digest(True)[-20:]

    if msg.address != pkh:
        raise ValueError('Invalid signature')

    address = '0x' + hexlify(msg.address).decode()

    await require_confirm_verify_message(ctx, address, msg.message)

    return Success(message='Message verified')