def get_address_and_pubkey(main_ui, bip32_path): client = main_ui.hw_client if client: bip32_path.strip() if bip32_path.lower().find('m/') >= 0: # removing m/ prefix because of keepkey library bip32_path = bip32_path[2:] if main_ui.config.hw_type in (HWType.trezor, HWType.keepkey): if isinstance(bip32_path, str): # trezor/keepkey require bip32 path argument as an array of integers bip32_path = client.expand_path(bip32_path) return { 'address': client.get_address('Dash', bip32_path, False), 'publicKey': client.get_public_node(bip32_path).node.public_key } elif main_ui.config.hw_type == HWType.ledger_nano_s: import hw_intf_ledgernano as ledger if isinstance(bip32_path, list): # ledger requires bip32 path argument as a string bip32_path = bip32_path_n_to_string(bip32_path) return ledger.get_address_and_pubkey(client, bip32_path) else: raise Exception('Unknown hwardware wallet type: ' + main_ui.config.hw_type)
def decrypt(ctrl, hw_session: HwSessionInfo, bip32_path_n: List[int], label: str, value: bytearray): ctrl.dlg_config_fun(dlg_title="Data decryption", show_progress_bar=False) ctrl.display_msg_fun(f'<b>Decrypting \'{label}\'...</b><br><br>Enter the hardware wallet PIN/passphrase ' f'(if needed)<br> and click the confirmation button to decrypt data.') if hw_session.hw_type == HWType.trezor: from trezorlib import misc, btc client = hw_session.hw_client data = misc.decrypt_keyvalue(client, bip32_path_n, label, value, ask_on_encrypt, ask_on_decrypt) pub_key = btc.get_public_node(client, bip32_path_n).node.public_key return data, pub_key elif hw_session.hw_type == HWType.keepkey: client = hw_session.hw_client data = client.decrypt_keyvalue(bip32_path_n, label, value, ask_on_encrypt, ask_on_decrypt) pub_key = client.get_public_node(bip32_path_n).node.public_key return data, pub_key elif hw_session.hw_type == HWType.ledger_nano_s: raise Exception('Feature not available for Ledger Nano S.') else: raise Exception('Invalid HW type: ' + str(hw_session))
def get_xpub(hw_session: HwSessionInfo, bip32_path): client = hw_session.hw_client if client: if isinstance(bip32_path, str): bip32_path.strip() if bip32_path.lower().find('m/') >= 0: bip32_path = bip32_path[2:] if hw_session.app_config.hw_type == HWType.trezor: from trezorlib import btc if isinstance(bip32_path, str): bip32_path = dash_utils.bip32_path_string_to_n(bip32_path) return btc.get_public_node(client, bip32_path).xpub elif hw_session.app_config.hw_type == HWType.keepkey: if isinstance(bip32_path, str): bip32_path = dash_utils.bip32_path_string_to_n(bip32_path) return client.get_public_node(bip32_path).xpub elif hw_session.app_config.hw_type == HWType.ledger_nano_s: import hw_intf_ledgernano as ledger if isinstance(bip32_path, list): # ledger requires bip32 path argument as a string bip32_path = bip32_path_n_to_string(bip32_path) return ledger.get_xpub(client, bip32_path) else: raise Exception('Unknown hardware wallet type: ' + hw_session.app_config.hw_type) else: raise Exception('HW client not open.')
def encrypt(ctrl, hw_session: HwSessionInfo, bip32_path_n: List[int], label: str, value: bytearray): ctrl.dlg_config_fun(dlg_title="Data encryption", show_progress_bar=False) ctrl.display_msg_fun(f'<b>Encrypting \'{label}\'...</b>' f'<br><br>Enter the hardware wallet PIN/passphrase (if needed) to encrypt data.<br><br>' f'<b>Note:</b> encryption passphrase is independent from the wallet passphrase <br>' f'and can vary for each encrypted file.') if hw_session.hw_type == HWType.trezor: from trezorlib import misc, btc from trezorlib import exceptions try: client = hw_session.hw_client data = misc.encrypt_keyvalue(client, bip32_path_n, label, value, ask_on_encrypt, ask_on_decrypt) pub_key = btc.get_public_node(client, bip32_path_n).node.public_key return data, pub_key except (CancelException, exceptions.Cancelled): raise CancelException() elif hw_session.hw_type == HWType.keepkey: client = hw_session.hw_client data = client.encrypt_keyvalue(bip32_path_n, label, value, ask_on_encrypt, ask_on_decrypt) pub_key = client.get_public_node(bip32_path_n).node.public_key return data, pub_key elif hw_session.hw_type == HWType.ledger_nano_s: raise Exception('Feature not available for Ledger Nano S.') else: raise Exception('Invalid HW type: ' + str(hw_session))
def get_address_and_pubkey(hw_session: HwSessionInfo, bip32_path): client = hw_session.hw_client if client: if isinstance(bip32_path, str): bip32_path.strip() if bip32_path.lower().find('m/') >= 0: # removing m/ prefix because of keepkey library bip32_path = bip32_path[2:] if hw_session.app_config.hw_type == HWType.trezor: from trezorlib import btc if isinstance(bip32_path, str): bip32_path = fix_utils.bip32_path_string_to_n(bip32_path) return { 'address': btc.get_address(client, hw_session.app_config.hw_coin_name, bip32_path, False), 'publicKey': btc.get_public_node(client, bip32_path).node.public_key } elif hw_session.app_config.hw_type == HWType.keepkey: if isinstance(bip32_path, str): bip32_path = fix_utils.bip32_path_string_to_n(bip32_path) return { 'address': client.get_address(hw_session.app_config.hw_coin_name, bip32_path, False), 'publicKey': client.get_public_node(bip32_path).node.public_key } elif hw_session.app_config.hw_type == HWType.ledger_nano_s: import hw_intf_ledgernano as ledger if isinstance(bip32_path, list): # ledger requires bip32 path argument as a string bip32_path = bip32_path_n_to_string(bip32_path) return ledger.get_address_and_pubkey(client, bip32_path) else: raise Exception('Unknown hardware wallet type: ' + hw_session.app_config.hw_type)