Esempio n. 1
0
def sign_psbt(fingerprint):
    wallet = MultisigWallet.open(wallet_name)
    client, device = get_client_and_device(fingerprint)
    psbt = wallet.psbt
    raw_signed_psbt = client.sign_tx(wallet.psbt)['psbt']
    new_psbt = serializations.PSBT()
    new_psbt.deserialize(raw_signed_psbt)
    wallet.psbt = new_psbt
    wallet.save()
    # FIXME: display the signer name here ...
    flash_success(f'{device["type"]} signed successfully')
    return redirect(url_for('wallet'))
Esempio n. 2
0
def sign_psbt():
    wallet_name = request.json['wallet_name']
    wallet = Wallet.open(wallet_name)
    fingerprint = request.json['device_id']
    index = request.json['index']
    old_psbt = wallet.psbts[index]
    with get_client_and_device(fingerprint,
                               wallet.network) as (client, device):
        raw_signed_psbt = client.sign_tx(old_psbt)['psbt']
    new_psbt = serializations.PSBT()
    new_psbt.deserialize(raw_signed_psbt)
    wallet.update_psbt(new_psbt, index)
    return jsonify({
        'psbt': new_psbt.serialize(),
    })
Esempio n. 3
0
def add_signer(fingerprint):
    wallet = MultisigWallet.open(wallet_name)
    client, device = get_client_and_device(fingerprint)

    # Add a "signer" to the wallet
    account_path = "m/44h/1h/0h"
    base_key = client.get_pubkey_at_path(account_path)['xpub']
    wallet.add_signer(device['type'], device['fingerprint'], base_key,
                      account_path)

    # FIXME: only works when coldcard added last
    if device['type'] == 'coldcard':
        client.close()
        coldcard_enroll(wallet)

    msg = f"Signer \"{device['type']}\" has been added to your \"{wallet.name}\" wallet"
    flash_success(msg)

    return redirect(url_for('wallet'))
Esempio n. 4
0
def add_signer():
    wallet_name = request.json['wallet_name']
    signer_name = request.json['signer_name']
    device_id = request.json['device_id']
    wallet = Wallet.open(wallet_name)
    with get_client_and_device(device_id, wallet.network) as (client, device):
        derivation_path = wallet.account_derivation_path()
        # Get XPUB and validate against wallet.network
        xpub = client.get_pubkey_at_path(derivation_path)['xpub']
        if 'xpub' == xpub[:4] and wallet.network != 'mainnet':
            raise JunctionError(
                'Invalid xpub. Make sure your device is set to the correct chain.'
            )
        if 'tpub' == xpub[:4] and wallet.network == 'mainnet':
            raise JunctionError(
                'Invalid xpub. Make sure your device is set to the correct chain.'
            )
        client.close()
        wallet.add_signer(name=signer_name,
                          fingerprint=device['fingerprint'],
                          type=device['type'],
                          xpub=xpub,
                          derivation_path=derivation_path)
    return jsonify(wallet.to_dict())
Esempio n. 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})