mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-17 05:03:07 +00:00
apps.wallet: implement SignMessage
This commit is contained in:
parent
f367d91cb7
commit
388e2dc305
@ -70,7 +70,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Nist256p1_sign(size_t n_args, const mp_obj_t *a
|
|||||||
mp_buffer_info_t sk, dig;
|
mp_buffer_info_t sk, dig;
|
||||||
mp_get_buffer_raise(args[1], &sk, MP_BUFFER_READ);
|
mp_get_buffer_raise(args[1], &sk, MP_BUFFER_READ);
|
||||||
mp_get_buffer_raise(args[2], &dig, MP_BUFFER_READ);
|
mp_get_buffer_raise(args[2], &dig, MP_BUFFER_READ);
|
||||||
bool compressed = n_args > 3 && args[3] == mp_const_true;
|
bool compressed = n_args < 4 || args[3] == mp_const_true;
|
||||||
if (sk.len != 32) {
|
if (sk.len != 32) {
|
||||||
mp_raise_ValueError("Invalid length of secret key");
|
mp_raise_ValueError("Invalid length of secret key");
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Secp256k1_sign(size_t n_args, const mp_obj_t *a
|
|||||||
mp_buffer_info_t sk, dig;
|
mp_buffer_info_t sk, dig;
|
||||||
mp_get_buffer_raise(args[1], &sk, MP_BUFFER_READ);
|
mp_get_buffer_raise(args[1], &sk, MP_BUFFER_READ);
|
||||||
mp_get_buffer_raise(args[2], &dig, MP_BUFFER_READ);
|
mp_get_buffer_raise(args[2], &dig, MP_BUFFER_READ);
|
||||||
bool compressed = n_args > 3 && args[3] == mp_const_true;
|
bool compressed = n_args < 4 || args[3] == mp_const_true;
|
||||||
if (sk.len != 32) {
|
if (sk.len != 32) {
|
||||||
mp_raise_ValueError("Invalid length of secret key");
|
mp_raise_ValueError("Invalid length of secret key");
|
||||||
}
|
}
|
||||||
|
@ -3,14 +3,37 @@ from trezor.utils import unimport
|
|||||||
|
|
||||||
|
|
||||||
@unimport
|
@unimport
|
||||||
async def layout_sign_message(message, session_id):
|
async def layout_sign_message(msg, session_id):
|
||||||
from trezor.messages.Success import Success
|
from trezor.messages.MessageSignature import MessageSignature
|
||||||
|
from trezor.crypto.hashlib import sha256
|
||||||
|
from trezor.crypto.curve import secp256k1
|
||||||
|
from ..common.signtx import node_derive, HashWriter, write_varint
|
||||||
|
from ..common.seed import get_root_node
|
||||||
|
from ..common import coins
|
||||||
|
|
||||||
ui.display.clear()
|
ui.display.clear()
|
||||||
ui.display.text(10, 30, 'Signing message',
|
ui.display.text(10, 30, 'Signing message',
|
||||||
ui.BOLD, ui.LIGHT_GREEN, ui.BLACK)
|
ui.BOLD, ui.LIGHT_GREEN, ui.BLACK)
|
||||||
ui.display.text(10, 60, message.message, ui.MONO, ui.WHITE, ui.BLACK)
|
ui.display.text(10, 60, msg.message, ui.MONO, ui.WHITE, ui.BLACK)
|
||||||
|
|
||||||
# TODO
|
address_n = msg.address_n
|
||||||
|
message = msg.message
|
||||||
|
coin_name = getattr(msg, 'coin_name', 'Bitcoin')
|
||||||
|
coin = coins.by_name(coin_name)
|
||||||
|
|
||||||
return Success(message='Signed')
|
root = await get_root_node(session_id)
|
||||||
|
node = node_derive(root, address_n)
|
||||||
|
seckey = node.private_key()
|
||||||
|
address = node.address(coin.address_type)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
digest = sha256(h.getvalue()).digest()
|
||||||
|
|
||||||
|
signature = secp256k1.sign(seckey, digest)
|
||||||
|
|
||||||
|
return MessageSignature(address=address, signature=signature)
|
||||||
|
Loading…
Reference in New Issue
Block a user