syntax = "proto3";
package account;

import "types/primitives.proto";

// ACCOUNT
// ================================================================================================

// Uniquely identifies a specific account.
//
// A Miden account ID is a 120-bit value derived from the commitments to account code and storage,
// and a random user-provided seed.
message AccountId {
    // 15 bytes (120 bits) encoded using [winter_utils::Serializable] implementation for
    // [miden_protocol::account::account_id::AccountId].
    bytes id = 1;
}

// The state of an account at a specific block height.
message AccountSummary {
    // The account ID.
    AccountId account_id = 1;

    // The current account commitment or zero if the account does not exist.
    primitives.Digest account_commitment = 2;

    // Block number at which the summary was made.
    uint32 block_num = 3;
}

// Represents the storage header of an account.
message AccountStorageHeader {
    // A single storage slot in the account storage header.
    message StorageSlot {
        // The name of the storage slot.
        string slot_name = 1;

        // The type of the storage slot.
        uint32 slot_type = 2;

        // The data (Word) for this storage slot.
        // For value slots (slot_type=0), this is the actual value stored in the slot.
        // For map slots (slot_type=1), this is the root of the storage map.
        primitives.Digest commitment = 3;
    }

    // Storage slots with their types and data.
    repeated StorageSlot slots = 1;
}

// An account details.
message AccountDetails {
    // Account summary.
    AccountSummary summary = 1;

    // Account details encoded using [winter_utils::Serializable] implementation for
    // [miden_protocol::account::Account].
    optional bytes details = 2;
}

// An account header.
message AccountHeader {
    // The account ID.
    AccountId account_id = 1;

    // Vault root hash.
    primitives.Digest vault_root = 2;

    // Storage root hash.
    primitives.Digest storage_commitment = 3;

    // Code root hash.
    primitives.Digest code_commitment = 4;

    // Account nonce.
    uint64 nonce = 5;
}

// An account witness.
message AccountWitness {
    // Account ID for which this proof is requested.
    account.AccountId account_id = 1;

    // The account ID within the proof, which may be different from the above account ID.
    // This can happen when the requested account ID's prefix matches the prefix of an existing
    // account ID in the tree. Then the witness will prove inclusion of this witness ID in the tree.
    account.AccountId witness_id = 2;

    // The state commitment whose inclusion the witness proves.
    primitives.Digest commitment = 3;

    // The merkle path of the state commitment in the account tree.
    primitives.SparseMerklePath path = 4;
}
