def extra_poc(self, zero, hs0, B): # --- Extra --- # Extract view key and address reconstruction. # Not needed for the PoC print('\nExtracting view-key...') encr = self.derive_secret_key(zero, 0, self.fake_a) r = self.mlsag_sign_s(zero, encr) rsc = crypto.decodeint(r[0]) asc = crypto.sc_sub(rsc, hs0) a = crypto.encodeint(asc) print(' a: %s' % binascii.hexlify(a).decode('ascii')) A = crypto.scalarmult_base(asc) print(' A: %s' % binascii.hexlify(crypto.encodepoint(A)).decode('ascii')) AA = self.scalarmult(self.fake_a) print(' aG: %s' % binascii.hexlify(AA).decode('ascii')) main_addr = addr.encode_addr( xmr_net.net_version(xmr_net.NetworkTypes.MAINNET), crypto.encodepoint(B), crypto.encodepoint(A), ) test_addr = addr.encode_addr( xmr_net.net_version(xmr_net.NetworkTypes.TESTNET), crypto.encodepoint(B), crypto.encodepoint(A), ) print('Mainnet address: %s' % main_addr.decode('ascii')) print('Testnet address: %s' % test_addr.decode('ascii'))
def public_addr_encode(pub_addr, is_sub=False, net=NetworkTypes.MAINNET): """ Encodes public address to Monero address :param pub_addr: :type pub_addr: apps.monero.xmr.serialize_messages.addr.AccountPublicAddress :param is_sub: :param net: :return: """ net_ver = net_version(net, is_sub) return encode_addr(net_ver, pub_addr.m_spend_public_key, pub_addr.m_view_public_key)
def gen_sub_address(sd, net_type, major_max, minor_max): for major in range(major_max): for minor in range(minor_max): if major == 0 and minor == 0: continue D, C = monero.generate_sub_address_keys(sd.view_sec, sd.spend_pub, major, minor) addr = encode_addr( net_version(net_type, is_subaddr=True), crypto.encodepoint(D), crypto.encodepoint(C), ) yield major, minor, 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, )
def public_addr_encode(pub_addr, is_sub=False, net=NetworkTypes.MAINNET, payment_id=None): """ Encodes public address to Monero address :param pub_addr: :type pub_addr: apps.monero.xmr.serialize_messages.addr.AccountPublicAddress :param is_sub: :param net: :param payment_id: for integrated address :return: """ if payment_id and len(payment_id) != 8: raise ValueError( "Payment ID has to have exactly 8B for an integrated address") net_ver = net_version(net, is_sub, payment_id is not None) return encode_addr(net_ver, pub_addr.spend_public_key, pub_addr.view_public_key, payment_id)