syntax = "proto2";
package hw.trezor.messages.tezos;

// Sugar for easier handling in Java
option java_package = "com.satoshilabs.trezor.lib.protobuf";
option java_outer_classname = "TrezorMessageTezos";

/**
 * Request: Ask device for Tezos address corresponding to address_n path
 * @start
 * @next TezosAddress
 * @next Failure
 */
message TezosGetAddress {
    repeated uint32 address_n = 1;      // BIP-32 path to derive the key from master node
    optional bool show_display = 2;     // optionally show on display before sending the result
}

/**
 * Response: Contains Tezos address derived from device private seed
 * @end
 */
message TezosAddress {
    optional string address = 1;        // Coin address in Base58 encoding
}

/**
 * Request: Ask device for Tezos public key corresponding to address_n path
 * @start
 * @next TezosPublicKey
 */
message TezosGetPublicKey {
    repeated uint32 address_n = 1;          // BIP-32 path to derive the key from master node
    optional bool show_display = 2;         // Optionally show on display before sending the result
}

/**
 * Response: Contains Tezos public key derived from device private seed
 * @end
 */
message TezosPublicKey {
    optional string public_key = 1;          // b58 encoded Tezos public key with prefix
}

/**
 * Request: Ask device to sign Tezos transaction
 * @start
 * @next TezosSignedTx
 */
message TezosSignTx {
    repeated uint32 address_n = 1;                  // BIP-32 path to derive the key from master node
    optional bytes branch = 2;

    optional TezosRevealOp reveal = 3;              // Tezos reveal operation (may be bundled with other op)
    optional TezosTransactionOp transaction = 4;    // Tezos transaction operation
    optional TezosOriginationOp origination = 5;    // Tezos origination operation
    optional TezosDelegationOp delegation = 6;      // Tezos delegation operation
    optional TezosProposalOp proposal = 7;          // Tezos proposal operation
    optional TezosBallotOp ballot = 8;              // Tezos ballot operation
    /*
     * Tezos contract ID
     */
    message TezosContractID {
        optional TezosContractType tag = 1;
        optional bytes hash = 2;                    // Implicit = 21B, originated = 20B + 1B padding
        /*
         * Type of Tezos Contract type
         */
        enum TezosContractType {
            Implicit = 0;
            Originated = 1;
        }
    }
    /**
     * Structure representing information for reveal
     */
    message TezosRevealOp {
        optional bytes source = 7;
        optional uint64 fee = 2;
        optional uint64 counter = 3;
        optional uint64 gas_limit = 4;
        optional uint64 storage_limit = 5;
        optional bytes public_key = 6;
    }
    /**
     * Structure representing information for transaction
     */
    message TezosTransactionOp {
        optional bytes source = 9;
        optional uint64 fee = 2;
        optional uint64 counter = 3;
        optional uint64 gas_limit = 4;
        optional uint64 storage_limit = 5;
        optional uint64 amount = 6;
        optional TezosContractID destination = 7;
        optional bytes parameters = 8;
        optional TezosParametersManager parameters_manager = 10;

        message TezosParametersManager {
            optional bytes set_delegate = 1;
            optional bool cancel_delegate = 2;
            optional TezosManagerTransfer transfer = 3;

            message TezosManagerTransfer {
                optional TezosContractID destination = 1;
                optional uint64 amount = 2;
            }
        }
    }
    /**
     * Structure representing information for origination
     */
    message TezosOriginationOp {
        optional bytes source = 12;
        optional uint64 fee = 2;
        optional uint64 counter = 3;
        optional uint64 gas_limit = 4;
        optional uint64 storage_limit = 5;
        optional bytes manager_pubkey = 6;
        optional uint64 balance = 7;
        optional bool spendable = 8;
        optional bool delegatable = 9;
        optional bytes delegate = 10;
        optional bytes script = 11;
    }
    /**
     * Structure representing information for delegation
     */
    message TezosDelegationOp {
        optional bytes source = 7;
        optional uint64 fee = 2;
        optional uint64 counter = 3;
        optional uint64 gas_limit = 4;
        optional uint64 storage_limit = 5;
        optional bytes delegate = 6;
    }
    /**
     * Structure representing information for proposal
     */
    message TezosProposalOp {
        optional bytes source = 1;                  //Contains only public_key_hash, not to be confused with TezosContractID
        optional uint64 period = 2;
        repeated bytes proposals = 4;
    }
    /**
     * Structure representing information for ballot
     */
    message TezosBallotOp {
        optional bytes source = 1;                  //Contains only public_key_hash, not to be confused with TezosContractID
        optional uint64 period = 2;
        optional bytes proposal = 3;
        optional TezosBallotType ballot = 4;

        enum TezosBallotType {
            Yay = 0;
            Nay = 1;
            Pass = 2;
        }
    }
}

/**
 * Response: Contains Tezos transaction signature
 * @end
 */
message TezosSignedTx {
    optional string signature = 1;          // Tezos b58 encoded transaction signature with prefix
    optional bytes sig_op_contents = 2;     // operation_bytes + signed operation_bytes
    optional string operation_hash = 3;     // b58 encoded hashed operation contents with prefix
}
