Beispiel #1
0
    def display_address(
        self,
        descriptor="",
        device_type=None,
        path=None,
        fingerprint=None,
        passphrase="",
        chain="",
    ):
        if descriptor == "":
            raise Exception("Descriptor must not be empty")

        with self._get_client(
                device_type=device_type,
                fingerprint=fingerprint,
                path=path,
                passphrase=passphrase,
                chain=chain,
        ) as client:
            status = hwi_commands.displayaddress(client, desc=descriptor)
            client.close()
            if "error" in status:
                raise Exception(status["error"])
            elif "address" in status:
                return status["address"]
            else:
                raise Exception(
                    "Failed to validate address on device: Unknown Error")
Beispiel #2
0
    def display_address(self,
                        descriptor='',
                        device_type=None,
                        path=None,
                        fingerprint=None,
                        passphrase='',
                        chain=''):
        if descriptor == '':
            raise Exception("Descriptor must not be empty")

        client = self._get_client(device_type=device_type,
                                  fingerprint=fingerprint,
                                  path=path,
                                  passphrase=passphrase,
                                  chain=chain)
        try:
            status = hwi_commands.displayaddress(client, desc=descriptor)
            client.close()
            if 'error' in status:
                raise Exception(status['error'])
            elif 'address' in status:
                return status['address']
            else:
                raise Exception(
                    "Failed to validate address on device: Unknown Error")
        except Exception as e:
            if client:
                client.close()
            raise e
Beispiel #3
0
    def display_address(
        self,
        descriptor="",
        device_type=None,
        path=None,
        fingerprint=None,
        passphrase="",
        chain="",
    ):
        if descriptor == "":
            raise Exception("Descriptor must not be empty")

        with self._get_client(
                device_type=device_type,
                fingerprint=fingerprint,
                path=path,
                passphrase=passphrase,
                chain=chain,
        ) as client:
            if descriptor.get("xpubs_descriptor", None):
                try:
                    # fix the sortedmulti bug in HWI descriptor parsing
                    desc = AddChecksum(descriptor["xpubs_descriptor"].replace(
                        "sortedmulti", "multi").split("#")[0])
                    status = hwi_commands.displayaddress(client, desc=desc)
                except Exception:
                    status = hwi_commands.displayaddress(client,
                                                         desc=descriptor.get(
                                                             "descriptor", ""))
            else:
                status = hwi_commands.displayaddress(client,
                                                     desc=descriptor.get(
                                                         "descriptor", ""))
            client.close()
            if "error" in status:
                raise Exception(status["error"])
            elif "address" in status:
                return status["address"]
            else:
                raise Exception(
                    "Failed to validate address on device: Unknown Error")
Beispiel #4
0
def hwi_display_address():
    type = request.form.get("type")
    path = request.form.get("path")
    passphrase = request.form.get("passphrase")
    descriptor = request.form.get("descriptor")

    try:
        client = get_hwi_client(type, path, passphrase=passphrase)
        status = hwilib_commands.displayaddress(client, desc=descriptor)
        if 'error' in status:
            return jsonify(success=False, error=status['error'])
        return jsonify(success=True, status=status)
    except Exception as e:
        print(e)
        return jsonify(success=False, error=e)
Beispiel #5
0
def display_address():
    wallet_name = request.json['wallet_name']
    address = request.json['address']
    device_id = request.json['device_id']
    wallet = Wallet.open(wallet_name)

    device = get_device(device_id)

    address_info = wallet.node.wallet_rpc.getaddressinfo(address)
    descriptor = address_info.get('desc')

    # HWI doesn't cover multisig, so we have to cover separately
    if wallet.is_multisig():
        # Get redeem script
        if wallet.script_type == ScriptTypes.NATIVE:
            redeem_script = address_info.get('hex')
        else:
            redeem_script = address_info.get('embedded', {}).get('hex')

        # Make sure we have redeem_script and descriptor
        if not redeem_script or not descriptor:
            raise JunctionError('Unknown address')

        # Grab derivation path portions of descriptor
        derivation_paths = re.findall(r'\[(.*?)\]', descriptor)

        # Handle Trezors
        if device['type'] == 'trezor':
            # FIXME: give descriptor to custom_trezor.display_multisig_address and have it do this ...
            derivation_path = ''
            for path in derivation_paths:
                slash_index = path.index('/')
                path = 'm' + path[slash_index:]
                if derivation_path:
                    assert derivation_path == path
                else:
                    derivation_path = path

            with hwi_lock:
                custom_trezor.display_multisig_address(
                    redeem_script, derivation_path,
                    wallet.network != 'mainnet', device, wallet.script_type)
        # Handle ColdCards
        elif device['type'] == 'coldcard':
            with hwi_lock:
                custom_coldcard.display_multisig_address(
                    redeem_script, derivation_paths,
                    wallet.script_type == 'native')
        # Reject everything else
        else:
            raise JunctionError(
                f'Devices of type "{device["type"]}" do not support multisig address display'
            )
    # HWI covers single-sig
    else:
        with get_client_and_device(device_id,
                                   wallet.network) as (client, device):
            with hwi_lock:
                commands.displayaddress(client, desc=descriptor)

    return jsonify({'ok': True})