mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-27 07:23:25 +00:00
Trezor: Implement decrypt message
For reasons I don't yet understand this can only decrypt messages encrypted by the Trezor, not by Electrum
This commit is contained in:
parent
9cf0a9720f
commit
d5c3c09bbc
2 changed files with 12 additions and 4 deletions
|
@ -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)))
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Reference in a new issue