def get_hwi_client(): '''create hwi client for plugged-in hardware wallet''' # list devices devices = commands.enumerate() # make sure there is only one assert len(devices) == 1, "One hardware wallet must be plugged in" # make sure it's unlocked device = devices[0] fingerprint = device.get("fingerprint") assert fingerprint is not None, f"Your ${device.type} is locked" # return client that can address this device if device['type'] == 'ledger': client = ledger.LedgerClient(device['path']) elif device['type'] == 'coldcard': client = coldcard.ColdcardClient(device['path']) elif device['type'] == 'trezor': client = trezor.TrezorClient(device['path']) else: raise Exception( f"Couldn't create client for you \"${device.type}\" device") # set HWI to testnet client.is_testnet = True return client
def get_client_and_device(args, multisig): # Make sure one and only one device is plugged in devices = commands.enumerate(args.password) if not devices: raise JunctionError( 'No devices available. Enter your pin if device already plugged in' ) if len(devices) > 1: raise JunctionError('You can only plug in one device at a time') device = devices[0] # Can't instantiate bitbox client w/o pasphrase, so this needs to be before next block if device.get("needs_passphrase_sent") and not args.password: raise JunctionError( 'Please supply your device password with the --password flag') # Define an HWI "client" based on depending on which device is plugged in if device['type'] == 'ledger': client = ledger.LedgerClient(device['path']) elif device['type'] == 'digitalbitbox': client = digitalbitbox.DigitalbitboxClient(device['path'], args.password) elif device['type'] == 'coldcard': client = coldcard.ColdcardClient(device['path']) elif device['type'] == 'trezor': client = trezor.TrezorClient(device['path']) else: raise JunctionError( f'Devices of type "{device["type"]}" not yet supported') client.is_testnet = True # this requires a client, so it needs to come after previous block if device.get('needs_pin_sent'): # this prints to stderr ... suppress it with contextlib.redirect_stderr(io.StringIO()): client.prompt_pin() pin = input( "Use the numeric keypad to enter your pin. The layout is:\n\t7 8 9\n\t4 5 6\n\t1 2 3\nPin: " ) if not client.send_pin(pin)["success"]: raise JunctionError('Pin is wrong') # FIXME: device dict has not "fingerprint" key and we calling commands.enumerate() again throws error # This hack retrievs and sets it manually import time time.sleep(1) device['fingerprint'] = commands.get_xpub_fingerprint_as_id( commands.getxpub(client, 'm/0h')['xpub']) # FIXME: Commenting out for now because device variable is outdated in "needs_pin_sent" case and I can't manage to refresh it ... # Get updated "device" (prior value may lack "fingerprint" if device was locked) # if device.get("error"): # raise JunctionError(f"Unexpected error: {device['error']}") return client, device
def get_client(device, network): if device['type'] == 'ledger': client = ledger.LedgerClient(device['path']) elif device['type'] == 'coldcard': client = coldcard.ColdcardClient(device['path']) elif device['type'] == 'trezor': client = trezor.TrezorClient(device['path']) else: raise JunctionError(f'Devices of type "{device["type"]}" not yet supported') # FIXME: junction needs mainnet / testnet flag somewhere ... client.is_testnet = network != "mainnet" return client
def devices(): devices = commands.enumerate() # prompt pins for device in devices: if device.get('needs_pin_sent'): global trezor_client trezor_client = trezor.TrezorClient(device['path']) trezor_client.prompt_pin() everything_unlocked = not any(['error' in device for device in devices]) return render_template('devices.html', devices=devices, everything_unlocked=everything_unlocked)
def get_client_and_device(fingerprint): # get device devices = commands.enumerate() device = None for d in devices: if d.get("fingerprint") == fingerprint: device = d assert device is not None # get client if device["type"] == "ledger": client = ledger.LedgerClient(device["path"]) elif device["type"] == "coldcard": client = coldcard.ColdcardClient(device["path"]) elif device["type"] == "trezor": client = trezor.TrezorClient(device["path"]) else: raise JunctionError(f'Devices of type "{device["type"]}" not yet supported') client.is_testnet = True return client, device