mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 14:28:07 +00:00
apps.wallet: refactor message digest method into shared module
naming would need some further thoughts, though
This commit is contained in:
parent
620ed74aa7
commit
ecac1d79f2
13
src/apps/common/signverify.py
Normal file
13
src/apps/common/signverify.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
from trezor.crypto.hashlib import sha256
|
||||||
|
|
||||||
|
from .signtx import HashWriter, write_varint
|
||||||
|
|
||||||
|
def message_digest(coin, message):
|
||||||
|
|
||||||
|
h = HashWriter(sha256)
|
||||||
|
write_varint(h, len(coin.signed_message_header))
|
||||||
|
h.extend(coin.signed_message_header)
|
||||||
|
write_varint(h, len(message))
|
||||||
|
h.extend(message)
|
||||||
|
|
||||||
|
return sha256(h.getvalue()).digest()
|
@ -5,11 +5,11 @@ from trezor.utils import unimport
|
|||||||
@unimport
|
@unimport
|
||||||
async def layout_sign_message(msg, session_id):
|
async def layout_sign_message(msg, session_id):
|
||||||
from trezor.messages.MessageSignature import MessageSignature
|
from trezor.messages.MessageSignature import MessageSignature
|
||||||
from trezor.crypto.hashlib import sha256
|
|
||||||
from trezor.crypto.curve import secp256k1
|
from trezor.crypto.curve import secp256k1
|
||||||
from ..common.signtx import node_derive, HashWriter, write_varint
|
from ..common.signtx import node_derive
|
||||||
from ..common.seed import get_root_node
|
from ..common.seed import get_root_node
|
||||||
from ..common import coins
|
from ..common import coins
|
||||||
|
from ..common.signverify import message_digest
|
||||||
|
|
||||||
ui.display.clear()
|
ui.display.clear()
|
||||||
ui.display.text(10, 30, 'Signing message',
|
ui.display.text(10, 30, 'Signing message',
|
||||||
@ -26,13 +26,7 @@ async def layout_sign_message(msg, session_id):
|
|||||||
seckey = node.private_key()
|
seckey = node.private_key()
|
||||||
address = node.address(coin.address_type)
|
address = node.address(coin.address_type)
|
||||||
|
|
||||||
h = HashWriter(sha256)
|
digest = message_digest(coin, message)
|
||||||
write_varint(h, len(coin.signed_message_header))
|
|
||||||
h.extend(coin.signed_message_header)
|
|
||||||
write_varint(h, len(message))
|
|
||||||
h.extend(message)
|
|
||||||
|
|
||||||
digest = sha256(h.getvalue()).digest()
|
|
||||||
|
|
||||||
signature = secp256k1.sign(seckey, digest)
|
signature = secp256k1.sign(seckey, digest)
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ async def layout_verify_message(msg, session_id):
|
|||||||
from trezor.crypto import base58
|
from trezor.crypto import base58
|
||||||
from ..common import address_type
|
from ..common import address_type
|
||||||
from ..common import coins
|
from ..common import coins
|
||||||
from ..common.signtx import node_derive, HashWriter, write_varint
|
from ..common.signverify import message_digest
|
||||||
|
|
||||||
address = msg.address
|
address = msg.address
|
||||||
message = msg.message
|
message = msg.message
|
||||||
@ -23,13 +23,7 @@ async def layout_verify_message(msg, session_id):
|
|||||||
ui.display.text(10, 60, message, ui.MONO, ui.WHITE, ui.BLACK)
|
ui.display.text(10, 60, message, ui.MONO, ui.WHITE, ui.BLACK)
|
||||||
ui.display.text(10, 80, address, ui.MONO, ui.WHITE, ui.BLACK)
|
ui.display.text(10, 80, address, ui.MONO, ui.WHITE, ui.BLACK)
|
||||||
|
|
||||||
h = HashWriter(sha256)
|
digest = message_digest(coin, message)
|
||||||
write_varint(h, len(coin.signed_message_header))
|
|
||||||
h.extend(coin.signed_message_header)
|
|
||||||
write_varint(h, len(message))
|
|
||||||
h.extend(message)
|
|
||||||
|
|
||||||
digest = sha256(h.getvalue()).digest()
|
|
||||||
pubkey = secp256k1.verify_recover(signature, digest)
|
pubkey = secp256k1.verify_recover(signature, digest)
|
||||||
|
|
||||||
if not pubkey:
|
if not pubkey:
|
||||||
|
Loading…
Reference in New Issue
Block a user