async def get_address(ctx: wire.Context, msg: MoneroGetAddress, keychain: Keychain) -> MoneroAddress: await paths.validate_path(ctx, keychain, msg.address_n) creds = misc.get_creds(keychain, msg.address_n, msg.network_type) addr = creds.address have_subaddress = msg.account is not None and msg.minor is not None have_payment_id = msg.payment_id is not None if (msg.account is None) != (msg.minor is None): raise wire.ProcessError("Invalid subaddress indexes") if have_payment_id and have_subaddress: raise wire.DataError("Subaddress cannot be integrated") if have_payment_id: assert msg.payment_id is not None if len(msg.payment_id) != 8: raise ValueError("Invalid payment ID length") addr = addresses.encode_addr( net_version(msg.network_type, False, True), crypto_helpers.encodepoint(creds.spend_key_public), crypto_helpers.encodepoint(creds.view_key_public), msg.payment_id, ) if have_subaddress: assert msg.account is not None assert msg.minor is not None pub_spend, pub_view = monero.generate_sub_address_keys( creds.view_key_private, creds.spend_key_public, msg.account, msg.minor) addr = addresses.encode_addr( net_version(msg.network_type, True, False), crypto_helpers.encodepoint(pub_spend), crypto_helpers.encodepoint(pub_view), ) if msg.show_display: title = paths.address_n_to_str(msg.address_n) await show_address( ctx, address=addr, address_qr="monero:" + addr, title=title, ) return MoneroAddress(address=addr.encode())
async def _require_confirm_output( ctx, dst: MoneroTransactionDestinationEntry, network_type: int, payment_id: bytes ): """ Single transaction destination confirmation """ from apps.monero.xmr.addresses import encode_addr from apps.monero.xmr.networks import net_version version = net_version(network_type, dst.is_subaddress, payment_id is not None) addr = encode_addr( version, dst.addr.spend_public_key, dst.addr.view_public_key, payment_id ) text_addr = common.split_address(addr.decode()) text_amount = common.format_amount(dst.amount) if not await common.naive_pagination( ctx, [ui.BOLD, text_amount, ui.MONO] + list(text_addr), "Confirm send", ui.ICON_SEND, ui.GREEN, 4, ): raise wire.ActionCancelled
def test_wallet_addr(self): addr = encode_addr( net_version(), unhexlify( b"3bec484c5d7f0246af520aab550452b5b6013733feabebd681c4a60d457b7fc1" ), unhexlify( b"2d5918e31d3c003da3c778592c07b398ad6f961a67082a75fd49394d51e69bbe" ), ) self.assertEqual( addr, b"43tpGG9PKbwCpjRvNLn1jwXPpnacw2uVUcszAtgmDiVcZK4VgHwjJT9BJz1WGF9eMxSYASp8yNMkuLjeQfWqJn3CNWdWfzV", ) w = AccountCreds.new_wallet( crypto.decodeint( unhexlify( b"4ce88c168e0f5f8d6524f712d5f8d7d83233b1e7a2a60b5aba5206cc0ea2bc08" )), crypto.decodeint( unhexlify( b"f2644a3dd97d43e87887e74d1691d52baa0614206ad1b0c239ff4aa3b501750a" )), network_type=NetworkTypes.TESTNET, ) self.assertEqual( w.address, b"9vacMKaj8JJV6MnwDzh2oNVdwTLJfTDyNRiB6NzV9TT7fqvzLivH2dB8Tv7VYR3ncn8vCb3KdNMJzQWrPAF1otYJ9cPKpkr", )
def public_addr_encode(pub_addr: MoneroAccountPublicAddress, is_sub=False, net=NetworkTypes.MAINNET): """ Encodes public address to Monero address """ net_ver = net_version(net, is_sub) return encode_addr(net_ver, pub_addr.spend_public_key, pub_addr.view_public_key)
async def get_address(ctx, msg, keychain): await paths.validate_path(ctx, keychain, msg.address_n) creds = misc.get_creds(keychain, msg.address_n, msg.network_type) addr = creds.address if msg.payment_id: if len(msg.payment_id) != 8: raise ValueError("Invalid payment ID length") addr = addresses.encode_addr( net_version(msg.network_type, False, True), crypto.encodepoint(creds.spend_key_public), crypto.encodepoint(creds.view_key_public), msg.payment_id, ) if msg.account or msg.minor: if msg.payment_id: raise ValueError("Subaddress cannot be integrated") pub_spend, pub_view = monero.generate_sub_address_keys( creds.view_key_private, creds.spend_key_public, msg.account, msg.minor) addr = addresses.encode_addr( net_version(msg.network_type, True, False), crypto.encodepoint(pub_spend), crypto.encodepoint(pub_view), ) if msg.show_display: title = paths.address_n_to_str(msg.address_n) await show_address( ctx, address=addr.decode(), address_qr="monero:" + addr.decode(), title=title, ) return MoneroAddress(address=addr)
def new_wallet(cls, priv_view_key, priv_spend_key, network_type=NetworkTypes.MAINNET): pub_view_key = crypto.scalarmult_base(priv_view_key) pub_spend_key = crypto.scalarmult_base(priv_spend_key) addr = encode_addr( net_version(network_type), crypto.encodepoint(pub_spend_key), crypto.encodepoint(pub_view_key), ) return cls( view_key_private=priv_view_key, spend_key_private=priv_spend_key, view_key_public=pub_view_key, spend_key_public=pub_spend_key, address=addr, network_type=network_type, )
async def _require_confirm_output(ctx, dst: MoneroTransactionDestinationEntry, network_type: int, payment_id: bytes): """ Single transaction destination confirmation """ from apps.monero.xmr.addresses import encode_addr from apps.monero.xmr.networks import net_version version = net_version(network_type, dst.is_subaddress, payment_id is not None) addr = encode_addr(version, dst.addr.spend_public_key, dst.addr.view_public_key, payment_id) await confirm_output( ctx, address=addr.decode(), amount=_format_amount(dst.amount), font_amount=ui.BOLD, br_code=ButtonRequestType.SignTx, )
def new_wallet( cls, priv_view_key: crypto.Scalar, priv_spend_key: crypto.Scalar, network_type: MoneroNetworkType = MoneroNetworkType.MAINNET, ) -> "AccountCreds": pub_view_key = crypto.scalarmult_base_into(None, priv_view_key) pub_spend_key = crypto.scalarmult_base_into(None, priv_spend_key) addr = encode_addr( net_version(network_type), crypto_helpers.encodepoint(pub_spend_key), crypto_helpers.encodepoint(pub_view_key), ) return cls( view_key_private=priv_view_key, spend_key_private=priv_spend_key, view_key_public=pub_view_key, spend_key_public=pub_spend_key, address=addr, network_type=network_type, )