electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit d5c3c09bbcec490c9a6f6bb4e33ffe0214c051c6
parent 9cf0a9720fac7020486530462319a6b61fae73a2
Author: Neil Booth <kyuupichan@gmail.com>
Date:   Sun, 10 Jan 2016 14:21:40 +0900

Trezor: Implement decrypt message

For reasons I don't yet understand this can only decrypt
messages encrypted by the Trezor, not by Electrum

Diffstat:
Mplugins/trezor/client.py | 4++--
Mplugins/trezor/plugin.py | 12++++++++++--
2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/plugins/trezor/client.py b/plugins/trezor/client.py @@ -185,8 +185,8 @@ def trezor_client_class(protocol_mixin, base_client, proto): return wrapped cls = TrezorClient - for method in ['apply_settings', 'change_pin', 'get_address', - 'get_public_node', 'load_device_by_mnemonic', + for method in ['apply_settings', 'change_pin', 'decrypt_message', + 'get_address', 'get_public_node', 'load_device_by_mnemonic', 'load_device_by_xprv', 'recovery_device', 'reset_device', 'sign_message', 'sign_tx', 'wipe_device']: setattr(cls, method, wrapper(getattr(cls, method))) diff --git a/plugins/trezor/plugin.py b/plugins/trezor/plugin.py @@ -1,3 +1,4 @@ +import base64 import re import time @@ -6,7 +7,7 @@ from struct import pack from electrum.account import BIP32_Account from electrum.bitcoin import (bc_address_to_hash_160, xpub_from_pubkey, - EncodeBase58Check) + public_key_to_bc_address, EncodeBase58Check) from electrum.i18n import _ from electrum.plugins import BasePlugin, hook from electrum.transaction import (deserialize, is_extended_pubkey, @@ -116,7 +117,14 @@ class TrezorCompatibleWallet(BIP44_Wallet): return pack('>I', x) def decrypt_message(self, pubkey, message, password): - raise RuntimeError(_('Decrypt method is not implemented')) + address = public_key_to_bc_address(pubkey.decode('hex')) + client = self.get_client() + address_path = self.address_id(address) + address_n = client.expand_path(address_path) + payload = base64.b64decode(message) + nonce, message, msg_hmac = payload[:33], payload[33:-8], payload[-8:] + result = client.decrypt_message(address_n, nonce, message, msg_hmac) + return result.message def sign_message(self, address, message, password): client = self.get_client()