Exemple #1
0
    def init(self, expect_initialized: Optional[bool] = True) -> bitbox02.BitBox02:
        if self.bb02 is not None:
            return self.bb02

        for device_info in devices.get_any_bitbox02s():
            if device_info["path"].decode() == self.device_path:
                bb02 = bitbox02.BitBox02(
                    transport=self.transport,
                    device_info=device_info,
                    noise_config=self.noise_config,
                )
                try:
                    bb02.check_min_version()
                except FirmwareVersionOutdatedException as exc:
                    sys.stderr.write("WARNING: {}\n".format(exc))
                    raise
            self.bb02 = bb02
            is_initialized = bb02.device_info()["initialized"]
            if expect_initialized is not None:
                if expect_initialized:
                    if not is_initialized:
                        raise HWWError(
                            "The BitBox02 must be initialized first.",
                            DEVICE_NOT_INITIALIZED,
                        )
                elif is_initialized:
                    raise UnavailableActionError(
                        "The BitBox02 must be wiped before setup."
                    )

            return bb02
        raise Exception(
            "Could not find the hid device info for path {}".format(self.device_path)
        )
Exemple #2
0
    def display_address(
        self,
        bip32_path: str,
        p2sh_p2wpkh: bool,
        bech32: bool,
        redeem_script: Optional[str] = None,
        descriptor: Optional[Descriptor] = None,
    ) -> Dict[str, str]:
        if redeem_script:
            raise NotImplementedError("BitBox02 multisig not integrated into HWI yet")

        if p2sh_p2wpkh:
            script_config = bitbox02.btc.BTCScriptConfig(
                simple_type=bitbox02.btc.BTCScriptConfig.P2WPKH_P2SH
            )
        elif bech32:
            script_config = bitbox02.btc.BTCScriptConfig(
                simple_type=bitbox02.btc.BTCScriptConfig.P2WPKH
            )
        else:
            raise UnavailableActionError(
                "The BitBox02 does not support legacy p2pkh addresses"
            )
        address = self.init().btc_address(
            _parse_path(bip32_path),
            coin=self._get_coin(),
            script_config=script_config,
            display=True,
        )
        return {"address": address}
Exemple #3
0
    def setup_device(self, label="", passphrase=""):
        """
        The Blockstream Jade does not support setup via software.

        :raises UnavailableActionError: Always, this function is unavailable
        """
        raise UnavailableActionError(
            "The Blockstream Jade does not support software setup")
Exemple #4
0
    def wipe_device(self):
        """
        The Blockstream Jade does not support wiping via software.

        :raises UnavailableActionError: Always, this function is unavailable
        """
        raise UnavailableActionError(
            "The Blockstream Jade does not support wiping via software")
Exemple #5
0
    def restore_device(self, label="", word_count=24):
        """
        The Blockstream Jade does not support restoring via software.

        :raises UnavailableActionError: Always, this function is unavailable
        """
        raise UnavailableActionError(
            "The Blockstream Jade does not support restoring via software")
Exemple #6
0
    def send_pin(self, pin):
        """
        The Blockstream Jade does not need a PIN sent from the host.

        :raises UnavailableActionError: Always, this function is unavailable
        """
        raise UnavailableActionError(
            "The Blockstream Jade does not need a PIN sent from the host")
Exemple #7
0
    def backup_device(
        self, label: str = "", passphrase: str = ""
    ) -> Dict[str, Union[bool, str, int]]:
        if label or passphrase:
            raise UnavailableActionError(
                "Label/passphrase not needed when exporting mnemonic from the BitBox02."
            )

        return {"success": self.init().show_mnemonic()}
Exemple #8
0
    def backup_device(self, label="", passphrase=""):
        """
        The Blockstream Jade does not support backing up via software.

        :raises UnavailableActionError: Always, this function is unavailable
        """
        raise UnavailableActionError(
            "The Blockstream Jade does not support creating a backup via software"
        )
Exemple #9
0
    def backup_device(self, label: str = "", passphrase: str = "") -> bool:
        """
        Trezor devices do not support backing up via software.

        :raises UnavailableActionError: Always, this function is unavailable
        """
        raise UnavailableActionError(
            "The {} does not support creating a backup via software".format(self.type)
        )
Exemple #10
0
    def toggle_passphrase(self):
        """
        The Blockstream Jade does not support toggling passphrase from the host.

        :raises UnavailableActionError: Always, this function is unavailable
        """
        raise UnavailableActionError(
            "The Blockstream Jade does not support toggling passphrase from the host"
        )
 def query(self, data: str, timeout: Optional[float] = None) -> str:
     """Send a text-based query to the device and get back the response"""
     res = self.dev.query(data, timeout)
     if res == "error: User cancelled":
         raise ActionCanceledError("User didn't confirm action")
     elif res.startswith("error: Unknown command"):
         raise UnavailableActionError(res[7:])
     elif res.startswith("error: "):
         raise BadArgumentError(res[7:])
     return res
Exemple #12
0
    def display_multisig_address(self, threshold: int,
                                 pubkeys: List[PubkeyProvider],
                                 addr_type: AddressType) -> str:
        """
        The Blockstream Jade does not support multisig addresses.

        :raises UnavailableActionError: Always, this function is unavailable
        """
        raise UnavailableActionError(
            "The Blockstream Jade does not support generic multisig P2SH address display"
        )
Exemple #13
0
    def setup_device(self,
                     label: str = "",
                     passphrase: str = "") -> Dict[str, Union[bool, str, int]]:
        if passphrase:
            raise UnavailableActionError(
                "Passphrase not needed when setting up a BitBox02.")

        bb02 = self.init(expect_initialized=False)

        if label:
            bb02.set_device_name(label)
        if not bb02.set_password():
            return {"success": False}
        return {"success": bb02.create_backup()}
Exemple #14
0
 def send_pin(self, pin):
     raise UnavailableActionError('Specter does not need a PIN sent from the host')
Exemple #15
0
 def restore_device(self, label="", word_count=24):
     raise UnavailableActionError(
         "The Ledger Nano S and X do not support restoring via software")
Exemple #16
0
 def backup_device(self, label="", passphrase=""):
     raise UnavailableActionError(
         "The Ledger Nano S and X do not support creating a backup via software"
     )
Exemple #17
0
 def sign_message(
     self, message: Union[str, bytes], bip32_path: str
 ) -> Dict[str, str]:
     raise UnavailableActionError("The BitBox02 does not support 'signmessage'")
Exemple #18
0
 def send_pin(self, pin):
     raise UnavailableActionError(
         "The Ledger Nano S and X do not need a PIN sent from the host")
Exemple #19
0
 def send_pin(self, pin: str) -> Dict[str, Union[bool, str, int]]:
     raise UnavailableActionError(
         "The BitBox02 does not need a PIN sent from the host"
     )
Exemple #20
0
 def toggle_passphrase(self):
     raise UnavailableActionError(
         "The Ledger Nano S and X do not support toggling passphrase from the host"
     )
Exemple #21
0
 def setup_device(self, label='', passphrase=''):
     raise UnavailableActionError('Specter does not support software setup')
Exemple #22
0
 def wipe_device(self):
     raise UnavailableActionError('Specter does not support wiping via software')
Exemple #23
0
 def wipe_device(self):
     raise UnavailableActionError(
         "The Ledger Nano S and X do not support wiping via software")
Exemple #24
0
 def restore_device(self, label=''):
     raise UnavailableActionError('Specter does not support restoring via software')
Exemple #25
0
 def backup_device(self, label='', passphrase=''):
     raise UnavailableActionError('Specter does not support backups')
Exemple #26
0
 def backup_device(self, label="", passphrase=""):
     raise UnavailableActionError(
         "The {} does not support creating a backup via software".format(
             self.type))
Exemple #27
0
 def setup_device(self, label="", passphrase=""):
     raise UnavailableActionError(
         "The Ledger Nano S and X do not support software setup")