Пример #1
0
    def force_pair_wallet(self, plugin, wallet, devices):
        first_address, derivation = wallet.first_address()
        assert first_address

        # The wallet has not been previously paired, so let the user
        # choose an unpaired device and compare its first address.
        info = self.select_device(wallet, plugin, devices)
        if info:
            client = self.client_lookup(info.device.id_)
            if client and client.is_pairable():
                # See comment above for same code
                client.handler = wallet.handler
                # This will trigger a PIN/passphrase entry request
                client_first_address = client.first_address(derivation)
                if client_first_address == first_address:
                    self.pair_wallet(wallet, info.device.id_)
                    return client

        if info and client:
            # The user input has wrong PIN or passphrase
            raise DeviceUnpairableError(
                _('Unable to pair with your %s.') % plugin.device)

        raise DeviceNotFoundError(
            _('Could not connect to your %s.  Verify the cable is '
              'connected and that no other application is using it.')
            % plugin.device)
Пример #2
0
    def client_for_wallet(self, plugin, wallet, force_pair):
        assert wallet.handler

        devices = self.scan_devices(wallet.handler)
        wallet_id = self.wallet_id(wallet)

        client = self.client_lookup(wallet_id)
        if client:
            return client

        for device in devices:
            if device.id_ == wallet_id:
                return self.create_client(device, wallet.handler, plugin)

        if force_pair:
            first_address, derivation = wallet.first_address()
            assert first_address

            # The wallet has not been previously paired, so let the user
            # choose an unpaired device and compare its first address.
            info = self.select_device(wallet, plugin, devices)
            if info:
                client = self.client_lookup(info.device.id_)
                if client and not client.features.bootloader_mode:
                    # An unpaired client might have another wallet's handler
                    # from a prior scan.  Replace to fix dialog parenting.
                    client.handler = wallet.handler
                    # This will trigger a PIN/passphrase entry request
                    client_first_address = client.first_address(derivation)
                    if client_first_address == first_address:
                        self.pair_wallet(wallet, info.device.id_)
                        return client

        return None
Пример #3
0
    def client_for_wallet(self, plugin, wallet, force_pair):
        assert wallet.handler

        devices = self.scan_devices(wallet.handler)
        wallet_id = self.wallet_id(wallet)

        client = self.client_lookup(wallet_id)
        if client:
            return client

        for device in devices:
            if device.id_ == wallet_id:
                return self.create_client(device, wallet.handler, plugin)

        if force_pair:
            first_address, derivation = wallet.first_address()
            assert first_address

            # The wallet has not been previously paired, so let the user
            # choose an unpaired device and compare its first address.
            info = self.select_device(wallet, plugin, devices)
            if info:
                client = self.client_lookup(info.device.id_)
                if client and not client.features.bootloader_mode:
                    # An unpaired client might have another wallet's handler
                    # from a prior scan.  Replace to fix dialog parenting.
                    client.handler = wallet.handler
                    # This will trigger a PIN/passphrase entry request
                    client_first_address = client.first_address(derivation)
                    if client_first_address == first_address:
                        self.pair_wallet(wallet, info.device.id_)
                        return client

        return None
Пример #4
0
    def get_client(self, wallet, lookup=PAIRED):
        '''Returns a client for the wallet, or None if one could not be
        found.'''
        with self.lock:
            device_id = self.wallets.get(wallet)
            client = self.client_by_device_id(device_id)
            if client:
                return client

        if lookup == DeviceMgr.CACHED:
            return None

        first_address, derivation = wallet.first_address()
        # Wallets don't have a first address in the install wizard
        # until account creation
        if not first_address:
            self.print_error("no first address for ", wallet)
            return None

        # We didn't find it, so scan for new devices.  We scan as
        # little as possible: some people report a USB scan is slow on
        # Linux when a Trezor is plugged in
        self.scan_devices()

        with self.lock:
            # Maybe the scan found it?  If the wallet has a device_id
            # from a prior pairing, we can determine success now.
            if device_id:
                return self.client_by_device_id(device_id)

            # Stop here if no wake and we couldn't find it.
            if lookup == DeviceMgr.PRESENT:
                return None

            # The wallet has not been previously paired, so get the
            # first address of all unpaired clients and compare.
            for client in self.clients:
                # If already paired skip it
                if self.wallet_by_device_id(client.device_id()):
                    continue
                # This will trigger a PIN/passphrase entry request
                if client.first_address(wallet, derivation) == first_address:
                    self.pair_wallet(wallet, client)
                    return client

            # Not found
            return None
Пример #5
0
    def force_pair_wallet(self, plugin, wallet, devices):
        first_address, derivation = wallet.first_address()
        assert first_address

        # The wallet has not been previously paired, so let the user
        # choose an unpaired device and compare its first address.
        info = self.select_device(wallet, plugin, devices)

        client = self.client_lookup(info.device.id_)
        if client and client.is_pairable():
            # See comment above for same code
            client.handler = wallet.handler
            # This will trigger a PIN/passphrase entry request
            client_first_address = client.first_address(derivation)
            if client_first_address == first_address:
                self.pair_wallet(wallet, info.device.id_)
                return client

        # The user input has wrong PIN or passphrase, or it is not pairable
        raise DeviceUnpairableError(
            _('Unable to pair with your %s.') % plugin.device)
Пример #6
0
    def get_client(self, wallet, force_pair=True):
        '''Returns a client for the wallet, or None if one could not be found.
        If force_pair is False then if an already paired client cannot
        be found None is returned rather than requiring user
        interaction.'''
        # We must scan devices to get an up-to-date idea of which
        # devices are present.  Operating on a client when its device
        # has been removed can cause the process to hang.
        # Unfortunately there is no plugged / unplugged notification
        # system.
        self.scan_devices(wallet.handler)

        # Previously paired wallets only need look for matching HID IDs
        hid_id = self.wallet_hid_id(wallet)
        if hid_id:
            return self.client_by_hid_id(hid_id)

        first_address, derivation = wallet.first_address()
        # Wallets don't have a first address in the install wizard
        # until account creation
        if not first_address:
            self.print_error("no first address for ", wallet)
            return None

        with self.lock:
            # The wallet has not been previously paired, so get the
            # first address of all unpaired clients and compare.
            for client in self.clients:
                # If already paired skip it
                if self.wallet_by_hid_id(client.hid_id()):
                    continue
                # This will trigger a PIN/passphrase entry request
                if client.first_address(derivation) == first_address:
                    self.pair_wallet(wallet, client)
                    return client

            # Not found
            return None
Пример #7
0
    def client_for_wallet(self, plugin, wallet, force_pair):
        assert wallet.handler

        devices = self.scan_devices(wallet.handler)
        wallet_id = self.wallet_id(wallet)

        client = self.client_lookup(wallet_id)
        if client:
            return client

        for device in devices:
            if device.id_ == wallet_id:
                return self.create_client(device, wallet.handler, plugin)

        if force_pair:
            first_address, derivation = wallet.first_address()
            # Wallets don't have a first address in the install wizard
            # until account creation
            if not first_address:
                self.print_error("no first address for ", wallet)
                return None

            # The wallet has not been previously paired, so get the
            # first address of all unpaired clients and compare.
            for device in devices:
                # Skip already-paired devices
                if self.wallet_by_id(device.id_):
                    continue
                client = self.create_client(device, wallet.handler, plugin)
                if client and not client.features.bootloader_mode:
                    # This will trigger a PIN/passphrase entry request
                    client_first_address = client.first_address(derivation)
                    if client_first_address == first_address:
                        self.pair_wallet(wallet, device.id_)
                        return client

        return None