From 017693fa572daae673471dc59eef756b9edee696 Mon Sep 17 00:00:00 2001 From: Michael Wozniak Date: Sun, 3 Aug 2014 17:37:26 -0400 Subject: [PATCH 1/2] Update trezor plugin for message signing --- plugins/trezor.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/plugins/trezor.py b/plugins/trezor.py index 2387cca7..848c5756 100644 --- a/plugins/trezor.py +++ b/plugins/trezor.py @@ -1,8 +1,10 @@ from PyQt4.Qt import QMessageBox, QDialog, QVBoxLayout, QLabel, QThread, SIGNAL +import PyQt4.QtCore as QtCore from binascii import unhexlify from struct import pack from sys import stderr from time import sleep +from base64 import b64encode from electrum_gui.qt.password_dialog import make_password_dialog, run_password_dialog from electrum_gui.qt.util import ok_cancel_buttons @@ -164,6 +166,21 @@ class TrezorWallet(NewWallet): #do nothing - no priv keys available pass + def sign_message(self, address, message, password): + try: + address_path = self.address_id(address) + address_n = self.get_client().expand_path(address_path) + except Exception, e: + raise + try: + msg_sig = self.get_client().sign_message('Bitcoin', address_n, message) + except Exception, e: + raise e + finally: + twd.emit(SIGNAL('trezor_done')) + b64_msg_sig = b64encode(msg_sig.signature) + return str(b64_msg_sig) + def sign_transaction(self, tx, keypairs, password): if tx.error or tx.is_complete(): return @@ -289,6 +306,8 @@ class TrezorQtGuiMixin(object): message = "Confirm transaction outputs on Trezor device to continue" elif msg.code == 8: message = "Confirm transaction fee on Trezor device to continue" + elif msg.code == 7: + message = "Confirm message to sign on Trezor device to continue" else: message = "Check Trezor device to continue" twd.start(message) @@ -355,8 +374,9 @@ class TrezorWaitingDialog(QThread): def start(self, message): self.d = QDialog() - self.d.setModal(True) + self.d.setModal(1) self.d.setWindowTitle('Please Check Trezor Device') + self.d.setWindowFlags(self.d.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) l = QLabel(message) vbox = QVBoxLayout(self.d) vbox.addWidget(l) From 0c81010290ebf3d49dcaa8fbd8d01725b90c68b0 Mon Sep 17 00:00:00 2001 From: Michael Wozniak Date: Sun, 3 Aug 2014 19:10:20 -0400 Subject: [PATCH 2/2] Add decrypt function Not yet supported in Trezor device, so it currently returns an Unknown Message error --- plugins/trezor.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/plugins/trezor.py b/plugins/trezor.py index 848c5756..b25032a1 100644 --- a/plugins/trezor.py +++ b/plugins/trezor.py @@ -4,12 +4,12 @@ from binascii import unhexlify from struct import pack from sys import stderr from time import sleep -from base64 import b64encode +from base64 import b64encode, b64decode from electrum_gui.qt.password_dialog import make_password_dialog, run_password_dialog from electrum_gui.qt.util import ok_cancel_buttons from electrum.account import BIP32_Account -from electrum.bitcoin import EncodeBase58Check +from electrum.bitcoin import EncodeBase58Check, public_key_to_bc_address from electrum.i18n import _ from electrum.plugins import BasePlugin from electrum.transaction import deserialize @@ -166,6 +166,21 @@ class TrezorWallet(NewWallet): #do nothing - no priv keys available pass + def decrypt_message(self, pubkey, message, password): + try: + address = public_key_to_bc_address(pubkey.decode('hex')) + address_path = self.address_id(address) + address_n = self.get_client().expand_path(address_path) + except Exception, e: + raise e + try: + decrypted_msg = self.get_client().decrypt_message(address_n, b64decode(message)) + except Exception, e: + raise e + finally: + twd.emit(SIGNAL('trezor_done')) + return str(decrypted_msg) + def sign_message(self, address, message, password): try: address_path = self.address_id(address)