def sign_psbt(wallet=None, tx=None, success_callback=None): wallet.fill_psbt(tx) keystore.sign(tx) keystore.update_wallet_indexes(wallet, tx) # remove everything but partial sigs # to reduce QR code size tx.unknown = {} tx.xpubs = {} for i in range(len(tx.inputs)): tx.inputs[i].unknown = {} tx.inputs[i].non_witness_utxo = None tx.inputs[i].witness_utxo = None tx.inputs[i].sighash_type = None tx.inputs[i].bip32_derivations = {} tx.inputs[i].witness_script = None tx.inputs[i].redeem_script = None for i in range(len(tx.outputs)): tx.outputs[i].unknown = {} tx.outputs[i].bip32_derivations = {} tx.outputs[i].witness_script = None tx.outputs[i].redeem_script = None b64_tx = b2a_base64(tx.serialize()).decode('utf-8') if b64_tx[-1:] == "\n": b64_tx = b64_tx[:-1] popups.qr_alert("Signed transaction:", b64_tx, "Scan it with your software wallet", width=480) if success_callback is not None: success_callback(b64_tx)
def verify_address(s): # we will go to main afterwards show_main() # verifies address in the form [bitcoin:]addr?index=i s = s.replace("bitcoin:", "") arr = s.split("?") index = None addr = None # check that ?index= is there if len(arr) > 1: addr = arr[0] meta_arr = arr[1].split("&") # search for `index=` for meta in meta_arr: if meta.startswith("index="): try: index = int(meta.split("=")[1]) except: gui.error("Index is not an integer...") return if index is None or addr is None: # where we will go next gui.error( "No derivation index in the address metadata - can't verify.") return for w in keystore.wallets: if w.address(index) == addr: popups.qr_alert("Address #%d from wallet\n\"%s\"" % (index + 1, w.name), "bitcoin:%s" % addr, message_text=addr) return gui.error("Address doesn't belong to any wallet. Wrong device or network?")
def verify_address(s): # we will go to main afterwards show_main() # verifies address in the form [bitcoin:]addr?index=i s = s.replace("bitcoin:", "") arr = s.split("?") index = None addr = None # check that ?index= is there if len(arr) > 1: addr = arr[0] meta_arr = arr[1].split("&") # search for `index=` for meta in meta_arr: if meta.startswith("index="): try: index = int(meta.split("=")[1]) except: gui.error("Index is not an integer...") return if index is None or addr is None: # where we will go next gui.error("No derivation index in the address metadata - can't verify.") return for w in keystore.wallets: if w.address(index) == addr: warning = "" if index > w.last_rcv_idx + w.gap_limit: warning = ("\n\n #ff0000 Possible gap limit. Using this address# " "#ff0000 may lead to locking of your funds!#") elif index <= w.last_rcv_idx: warning = ("\n\n #ff0000 This address may have been used before.#\n" "#ff0000 Reusing it would diminish your privacy!#") popups.qr_alert("Address #%d from wallet\n\"%s\"" % (index, w.name), "bitcoin:%s"%addr, message_text=addr + warning) return gui.error("Address doesn't belong to any wallet. Wrong device or network?")
def host_callback(data): # close all existing popups popups.close_all_popups() if data=="fingerprint": usb_host.respond(hexlify(keystore.fingerprint).decode('ascii')) return if data.startswith("xpub "): path = data[5:].strip(" /\r\n") try: if path == "m": hd = keystore.root.to_public() else: hd = keystore.get_xpub(path) xpub = hd.to_base58(network["xpub"]) usb_host.respond(xpub) show_xpub("Master key requested from host:", path, hd) except Exception as e: print(e) usb_host.respond("error: bad derivation path '%s'" % path) return if data.startswith("sign "): def success_cb(signed_tx): usb_host.respond(signed_tx) def error_cb(error): usb_host.respond("error: %s" % error) parse_transaction(data[5:], success_callback=success_cb, error_callback=error_cb) return if data.startswith("showaddr "): arr = data.split(" ") path = arr[-1].strip() addrtype = "wpkh" if len(arr) > 2: addrtype = arr[-2].strip() # TODO: detect wallet this address belongs to try: key = keystore.get_xpub(path) if addrtype == "wpkh": sc = script.p2wpkh(key) elif addrtype == "pkh": sc = script.p2pkh(key) elif addrtype == "sh-wpkh": sc = script.p2sh(script.p2wpkh(key)) else: raise RuntimeError() addr=sc.address(network) usb_host.respond(addr) popups.qr_alert("Address with path %s\n(requested by host)" % (path), "bitcoin:"+addr, message_text=addr) except Exception as e: print(e) usb_host.respond("error: invalid argument") return if data.startswith("importwallet "): parse_new_wallet(data[13:])