예제 #1
0
def _get_key_for_payment_id_encryption(destinations: list, change_addr=None):
    """
    Returns destination address public view key to be used for
    payment id encryption.
    """
    from apps.monero.xmr.addresses import addr_eq
    from trezor.messages.MoneroAccountPublicAddress import MoneroAccountPublicAddress

    addr = MoneroAccountPublicAddress(spend_public_key=crypto.NULL_KEY_ENC,
                                      view_public_key=crypto.NULL_KEY_ENC)
    count = 0
    for dest in destinations:
        if dest.amount == 0:
            continue
        if change_addr and addr_eq(dest.addr, change_addr):
            continue
        if addr_eq(dest.addr, addr):
            continue
        if count > 0:
            raise ValueError(
                "Destinations have to have exactly one output to support encrypted payment ids"
            )
        addr = dest.addr
        count += 1

    if count == 0 and change_addr:
        return change_addr.view_public_key

    if addr.view_public_key == crypto.NULL_KEY_ENC:
        raise ValueError("Invalid key")

    return addr.view_public_key
def _get_primary_change_address(state: State) -> MoneroAccountPublicAddress:
    """
    Computes primary change address for the current account index
    """
    from trezor.messages.MoneroAccountPublicAddress import MoneroAccountPublicAddress

    D, C = monero.generate_sub_address_keys(state.creds.view_key_private,
                                            state.creds.spend_key_public,
                                            state.account_idx, 0)
    return MoneroAccountPublicAddress(view_public_key=crypto.encodepoint(C),
                                      spend_public_key=crypto.encodepoint(D))
def _get_key_for_payment_id_encryption(
    tsx_data: MoneroTransactionData,
    change_addr=None,
    add_dummy_payment_id: bool = False,
) -> bytes:
    """
    Returns destination address public view key to be used for
    payment id encryption. If no encrypted payment ID is chosen,
    dummy payment ID is set for better transaction uniformity if possible.
    """
    from apps.monero.xmr.addresses import addr_eq
    from trezor.messages.MoneroAccountPublicAddress import MoneroAccountPublicAddress

    addr = MoneroAccountPublicAddress(spend_public_key=crypto.NULL_KEY_ENC,
                                      view_public_key=crypto.NULL_KEY_ENC)
    count = 0
    for dest in tsx_data.outputs:
        if dest.amount == 0:
            continue
        if change_addr and addr_eq(dest.addr, change_addr):
            continue
        if addr_eq(dest.addr, addr):
            continue
        if count > 0 and tsx_data.payment_id:
            raise ValueError(
                "Destinations have to have exactly one output to support encrypted payment ids"
            )
        addr = dest.addr
        count += 1

    # Insert dummy payment id for transaction uniformity
    if not tsx_data.payment_id and count <= 1 and add_dummy_payment_id:
        tsx_data.payment_id = bytearray(8)

    if count == 0 and change_addr:
        return change_addr.view_public_key

    if addr.view_public_key == crypto.NULL_KEY_ENC:
        raise ValueError("Invalid key")

    return addr.view_public_key