async def sign_tx(ctx, msg, keychain): signer = signing.sign_tx(msg, keychain) res = None while True: try: req = signer.send(res) except signing.SigningError as e: raise wire.Error(*e.args) except multisig.MultisigError as e: raise wire.Error(*e.args) except addresses.AddressError as e: raise wire.Error(*e.args) except scripts.ScriptsError as e: raise wire.Error(*e.args) except segwit_bip143.Bip143Error as e: raise wire.Error(*e.args) if isinstance(req, TxRequest): if req.request_type == TXFINISHED: break res = await ctx.call(req, TxAck) elif isinstance(req, helpers.UiConfirmOutput): mods = utils.unimport_begin() res = await layout.confirm_output(ctx, req.output, req.coin) utils.unimport_end(mods) progress.report_init() elif isinstance(req, helpers.UiConfirmTotal): mods = utils.unimport_begin() res = await layout.confirm_total(ctx, req.spending, req.fee, req.coin) utils.unimport_end(mods) progress.report_init() elif isinstance(req, helpers.UiConfirmFeeOverThreshold): mods = utils.unimport_begin() res = await layout.confirm_feeoverthreshold(ctx, req.fee, req.coin) utils.unimport_end(mods) progress.report_init() elif isinstance(req, helpers.UiConfirmNonDefaultLocktime): mods = utils.unimport_begin() res = await layout.confirm_nondefault_locktime(ctx, req.lock_time) utils.unimport_end(mods) progress.report_init() elif isinstance(req, helpers.UiConfirmForeignAddress): mods = utils.unimport_begin() res = await paths.show_path_warning(ctx, req.address_n) utils.unimport_end(mods) progress.report_init() else: raise TypeError("Invalid signing instruction") return req
async def sign_tx(ctx, msg): from apps.wallet.sign_tx import layout, progress, signing coin_name = msg.coin_name or "Bitcoin" coin = coins.by_name(coin_name) # TODO: rework this so we don't have to pass root to signing.sign_tx root = await seed.derive_node(ctx, [], curve_name=coin.curve_name) signer = signing.sign_tx(msg, root) res = None while True: try: req = signer.send(res) except signing.SigningError as e: raise wire.Error(*e.args) except signing.MultisigError as e: raise wire.Error(*e.args) except signing.AddressError as e: raise wire.Error(*e.args) except signing.ScriptsError as e: raise wire.Error(*e.args) except signing.Bip143Error as e: raise wire.Error(*e.args) if isinstance(req, TxRequest): if req.request_type == TXFINISHED: break res = await ctx.call(req, TxAck) elif isinstance(req, UiConfirmOutput): res = await layout.confirm_output(ctx, req.output, req.coin) progress.report_init() elif isinstance(req, UiConfirmTotal): res = await layout.confirm_total(ctx, req.spending, req.fee, req.coin) progress.report_init() elif isinstance(req, UiConfirmFeeOverThreshold): res = await layout.confirm_feeoverthreshold(ctx, req.fee, req.coin) progress.report_init() elif isinstance(req, UiConfirmForeignAddress): res = await layout.confirm_foreign_address(ctx, req.address_n, req.coin) else: raise TypeError("Invalid signing instruction") return req
async def sign_tx(ctx, msg): from apps.wallet.sign_tx import layout, progress, signing # TODO: rework this so we don't have to pass root to signing.sign_tx root = await seed.derive_node(ctx, []) signer = signing.sign_tx(msg, root) res = None while True: try: req = signer.send(res) except signing.SigningError as e: raise wire.Error(*e.args) except signing.MultisigError as e: raise wire.Error(*e.args) except signing.AddressError as e: raise wire.Error(*e.args) except signing.ScriptsError as e: raise wire.Error(*e.args) except signing.Bip143Error as e: raise wire.Error(*e.args) if req.__qualname__ == 'TxRequest': if req.request_type == TXFINISHED: break res = await ctx.call(req, TxAck) elif req.__qualname__ == 'UiConfirmOutput': res = await layout.confirm_output(ctx, req.output, req.coin) progress.report_init() elif req.__qualname__ == 'UiConfirmTotal': res = await layout.confirm_total(ctx, req.spending, req.fee, req.coin) progress.report_init() elif req.__qualname__ == 'UiConfirmFeeOverThreshold': res = await layout.confirm_feeoverthreshold(ctx, req.fee, req.coin) progress.report_init() else: raise TypeError('Invalid signing instruction') return req
async def sign_tx(ctx: wire.Context, msg: SignTx, keychain: seed.Keychain) -> TxRequest: coin_name = msg.coin_name if msg.coin_name is not None else "Bitcoin" coin = coins.by_name(coin_name) if not utils.BITCOIN_ONLY: if coin.decred: signer_class = decred.Decred # type: Type[bitcoin.Bitcoin] elif coin.overwintered: signer_class = zcash.Overwintered elif coin_name not in BITCOIN_NAMES: signer_class = bitcoinlike.Bitcoinlike else: signer_class = bitcoin.Bitcoin else: signer_class = bitcoin.Bitcoin try: signer = signer_class(msg, keychain, coin).signer() except common.SigningError as e: raise wire.Error(*e.args) res = None # type: Union[TxAck, bool, None] while True: try: req = signer.send(res) except ( common.SigningError, multisig.MultisigError, addresses.AddressError, scripts.ScriptsError, ) as e: raise wire.Error(*e.args) if isinstance(req, TxRequest): if req.request_type == TXFINISHED: break res = await ctx.call(req, TxAck) elif isinstance(req, helpers.UiConfirmOutput): mods = utils.unimport_begin() res = await layout.confirm_output(ctx, req.output, req.coin) utils.unimport_end(mods) progress.report_init() elif isinstance(req, helpers.UiConfirmTotal): mods = utils.unimport_begin() res = await layout.confirm_total(ctx, req.spending, req.fee, req.coin) utils.unimport_end(mods) progress.report_init() elif isinstance(req, helpers.UiConfirmFeeOverThreshold): mods = utils.unimport_begin() res = await layout.confirm_feeoverthreshold(ctx, req.fee, req.coin) utils.unimport_end(mods) progress.report_init() elif isinstance(req, helpers.UiConfirmNonDefaultLocktime): mods = utils.unimport_begin() res = await layout.confirm_nondefault_locktime(ctx, req.lock_time) utils.unimport_end(mods) progress.report_init() elif isinstance(req, helpers.UiConfirmForeignAddress): mods = utils.unimport_begin() res = await paths.show_path_warning(ctx, req.address_n) utils.unimport_end(mods) progress.report_init() else: raise TypeError("Invalid signing instruction") return req