import * as _chainsafe_ssz from '@chainsafe/ssz';
import { ByteVectorType, UintBigintType, ContainerType, ByteListType, ListCompositeType, UintNumberType } from '@chainsafe/ssz';

/**
 * Primitive SSZ schemas and constants used across AsentumChain's type system.
 *
 * These are the low-level building blocks: byte vectors for addresses and
 * hashes, bigint types for balances and nonces, and canonical sizes for
 * Dilithium3 keys and signatures.
 */

/** Length of an AsentumChain address in bytes. */
declare const ADDRESS_BYTES = 20;
/** Length of a chain hash (BLAKE3 output) in bytes. */
declare const HASH_BYTES = 32;
/** Exact size of a Dilithium3 (ML-DSA-65) public key in bytes, per NIST FIPS 204. */
declare const DILITHIUM3_PUBLIC_KEY_BYTES = 1952;
/** Exact size of a Dilithium3 (ML-DSA-65) signature in bytes, per NIST FIPS 204. */
declare const DILITHIUM3_SIGNATURE_BYTES = 3309;
/** The zero address (20 zero bytes). Used for contract creation and null-sender sentinel. */
declare const ZERO_ADDRESS_BYTES: Uint8Array;
/** The zero hash (32 zero bytes). Used as a sentinel for EOA code hash and storage root. */
declare const ZERO_HASH: Uint8Array;
/** SSZ schema for a 20-byte address. */
declare const AddressBytesSchema: ByteVectorType;
/** SSZ schema for a 32-byte chain hash. */
declare const HashSchema: ByteVectorType;
/** SSZ schema for a 256-bit unsigned integer (represented as bigint at runtime). */
declare const Uint256Schema: UintBigintType;
/** SSZ schema for a 64-bit unsigned integer (represented as bigint at runtime). */
declare const Uint64Schema: UintBigintType;

/** SSZ schema for an AsentumChain account. */
declare const AccountSchema: ContainerType<{
    balance: _chainsafe_ssz.UintBigintType;
    nonce: _chainsafe_ssz.UintBigintType;
    codeHash: _chainsafe_ssz.ByteVectorType;
    storageRoot: _chainsafe_ssz.ByteVectorType;
}>;
/** An AsentumChain account at rest (the value stored against an address in state). */
interface Account {
    balance: bigint;
    nonce: bigint;
    codeHash: Uint8Array;
    storageRoot: Uint8Array;
}
/**
 * Returns a fresh, empty externally-owned account: zero balance, zero nonce,
 * zero code hash, zero storage root. Used as the default for addresses that
 * have never been touched.
 */
declare function emptyAccount(): Account;

/**
 * The body of a transaction — the portion that gets hashed and signed.
 *
 * A receiver `to` value of 20 zero bytes indicates a contract creation.
 */
declare const TransactionBodySchema: ContainerType<{
    chainId: _chainsafe_ssz.UintBigintType;
    nonce: _chainsafe_ssz.UintBigintType;
    maxPriorityFeePerGas: _chainsafe_ssz.UintBigintType;
    maxFeePerGas: _chainsafe_ssz.UintBigintType;
    gasLimit: _chainsafe_ssz.UintBigintType;
    to: ByteVectorType;
    value: _chainsafe_ssz.UintBigintType;
    data: ByteListType;
}>;
/** Runtime shape of a transaction body. */
interface TransactionBody {
    chainId: bigint;
    nonce: bigint;
    maxPriorityFeePerGas: bigint;
    maxFeePerGas: bigint;
    gasLimit: bigint;
    to: Uint8Array;
    value: bigint;
    data: Uint8Array;
}
/**
 * A fully signed transaction: a body plus the sender's Dilithium3 public key
 * and signature.
 *
 * The sender address is derivable from `publicKey` (per D16), so we don't
 * store it redundantly. Future optimization: allow the public key to be
 * replaced by an already-known account reference, per the "repeat sender"
 * optimization in `post-quantum.md`.
 */
declare const SignedTransactionSchema: ContainerType<{
    body: ContainerType<{
        chainId: _chainsafe_ssz.UintBigintType;
        nonce: _chainsafe_ssz.UintBigintType;
        maxPriorityFeePerGas: _chainsafe_ssz.UintBigintType;
        maxFeePerGas: _chainsafe_ssz.UintBigintType;
        gasLimit: _chainsafe_ssz.UintBigintType;
        to: ByteVectorType;
        value: _chainsafe_ssz.UintBigintType;
        data: ByteListType;
    }>;
    publicKey: ByteVectorType;
    signature: ByteVectorType;
}>;
/** Runtime shape of a signed transaction. */
interface SignedTransaction {
    body: TransactionBody;
    publicKey: Uint8Array;
    signature: Uint8Array;
}

/** Maximum number of transactions per block. */
declare const MAX_TRANSACTIONS_PER_BLOCK = 10000;
/**
 * Maximum committee size we can encode in the lastCommit bitmap.
 * 16 bytes × 8 bits/byte = 128 slots — comfortably above the 100-validator
 * committee cap, leaves headroom if the cap is raised in v2.
 */
declare const LAST_COMMIT_BITMAP_BYTES = 16;
declare const LAST_COMMIT_BITMAP_SLOTS: number;
/** Fixed-size byte vector for the last-commit bitmap. */
declare const LastCommitBitmapSchema: ByteVectorType;
/**
 * Committee cap for lastCommit signatures list. Same cap as the bitmap
 * (128 slots); the list encoding is sparse — only actual signers appear.
 */
declare const LAST_COMMIT_MAX_SIGS: number;
/**
 * A single precommit signature slot inside `LastCommit`. The proposer of
 * block h collects these during the round it decides h-1 is finalized:
 * for each committee member who precommitted h-1's block hash, one entry
 * with their committee-order index and their raw Dilithium3 signature over
 * the precommit-vote body.
 *
 * On apply, every full node verifies each signature against the h-1 block
 * hash + the h-1 committee's public keys before crediting rewards. Reward
 * distribution reads signers from THIS list, not from any locally-observed
 * vote state, so all nodes compute identical post-apply state.
 */
declare const LastCommitSigSchema: ContainerType<{
    /** Index into the h-1 committee (deterministic committee order). */
    validatorIdx: UintNumberType;
    /** Dilithium3 public key of the signing validator. Verifiers use it directly rather than
     *  incurring a per-block staking-contract state read. Bloat is real (1952 B per slot) but
     *  acceptable at v1 committee cap; sig aggregation is a separate design. */
    publicKey: ByteVectorType;
    /** Dilithium3 signature over the (precommit, chainId, h-1, round, blockHash, validator) vote body. */
    signature: ByteVectorType;
}>;
/** Runtime shape of a single precommit signature slot. */
interface LastCommitSig {
    validatorIdx: number;
    publicKey: Uint8Array;
    signature: Uint8Array;
}
/**
 * The commit certificate for block h-1, embedded in block h.
 *
 * Structural anti-fork guarantee: the proposer of h can only build a valid
 * `LastCommit` if it collected 2/3-stake precommits on h-1's specific
 * block hash. Two proposers who saw different precommit subsets produce
 * different `LastCommit`s → different block hashes → only one can gather
 * fresh 2/3 precommits on its version → single canonical h. Reward
 * derivation reads signers from this field, so all applying nodes agree.
 *
 * See notes/last-commit-cert-design-2026-07-01.md.
 *
 * Genesis-adjacent handling: block 1 has no predecessor. Convention:
 * `blockHash = 32-byte zero`, `round = 0`, `signatures = []`. Apply-time
 * reward path skips crediting on block 1.
 */
declare const LastCommitSchema: ContainerType<{
    /** Block hash of h-1 that the signatures below commit to. */
    blockHash: ByteVectorType;
    /** Round at which h-1 was finalized (part of the vote-signing domain). */
    round: _chainsafe_ssz.UintBigintType;
    /** Per-signer precommit signatures. Sparse — only present signers. */
    signatures: ListCompositeType<ContainerType<{
        /** Index into the h-1 committee (deterministic committee order). */
        validatorIdx: UintNumberType;
        /** Dilithium3 public key of the signing validator. Verifiers use it directly rather than
         *  incurring a per-block staking-contract state read. Bloat is real (1952 B per slot) but
         *  acceptable at v1 committee cap; sig aggregation is a separate design. */
        publicKey: ByteVectorType;
        /** Dilithium3 signature over the (precommit, chainId, h-1, round, blockHash, validator) vote body. */
        signature: ByteVectorType;
    }>>;
}>;
/** Runtime shape of a commit cert. */
interface LastCommit {
    blockHash: Uint8Array;
    round: bigint;
    signatures: LastCommitSig[];
}
/** SSZ schema for a block header. */
declare const BlockHeaderSchema: ContainerType<{
    parentHash: ByteVectorType;
    stateRoot: ByteVectorType;
    transactionsRoot: ByteVectorType;
    receiptsRoot: ByteVectorType;
    number: _chainsafe_ssz.UintBigintType;
    timestamp: _chainsafe_ssz.UintBigintType;
    gasLimit: _chainsafe_ssz.UintBigintType;
    gasUsed: _chainsafe_ssz.UintBigintType;
    baseFeePerGas: _chainsafe_ssz.UintBigintType;
    proposer: ByteVectorType;
    /**
     * Bitmap of which validators in the PRIOR block's committee precommitted
     * the prior block. Bit `i` is 1 iff committee[i] (in deterministic order)
     * had a precommit observed by this block's producer. Used by the rewards
     * distributor to credit only validators who actually signed — the
     * "auto-liveness" mechanism. Empty (all-zero) for block 1, since there
     * is no prior block.
     *
     * TRANSITIONAL (2026-07-02): kept in the header while the block-builder
     * and apply-path migrate to reading signers from `block.lastCommit`.
     * Slated for removal once every caller reads from `lastCommit` — see
     * task #315 / notes/last-commit-cert-design-2026-07-01.md.
     */
    lastCommitBitmap: ByteVectorType;
    /**
     * hashTreeRoot of the `lastCommit` field on the block. Binds the
     * signature set into the block header so that a block with the wrong
     * `lastCommit` fails hash verification.
     */
    lastCommitHash: ByteVectorType;
}>;
/** Runtime shape of a block header. */
interface BlockHeader {
    parentHash: Uint8Array;
    stateRoot: Uint8Array;
    transactionsRoot: Uint8Array;
    receiptsRoot: Uint8Array;
    number: bigint;
    timestamp: bigint;
    gasLimit: bigint;
    gasUsed: bigint;
    baseFeePerGas: bigint;
    proposer: Uint8Array;
    lastCommitBitmap: Uint8Array;
    lastCommitHash: Uint8Array;
}
/** SSZ schema for a full block. */
declare const BlockSchema: ContainerType<{
    header: ContainerType<{
        parentHash: ByteVectorType;
        stateRoot: ByteVectorType;
        transactionsRoot: ByteVectorType;
        receiptsRoot: ByteVectorType;
        number: _chainsafe_ssz.UintBigintType;
        timestamp: _chainsafe_ssz.UintBigintType;
        gasLimit: _chainsafe_ssz.UintBigintType;
        gasUsed: _chainsafe_ssz.UintBigintType;
        baseFeePerGas: _chainsafe_ssz.UintBigintType;
        proposer: ByteVectorType;
        /**
         * Bitmap of which validators in the PRIOR block's committee precommitted
         * the prior block. Bit `i` is 1 iff committee[i] (in deterministic order)
         * had a precommit observed by this block's producer. Used by the rewards
         * distributor to credit only validators who actually signed — the
         * "auto-liveness" mechanism. Empty (all-zero) for block 1, since there
         * is no prior block.
         *
         * TRANSITIONAL (2026-07-02): kept in the header while the block-builder
         * and apply-path migrate to reading signers from `block.lastCommit`.
         * Slated for removal once every caller reads from `lastCommit` — see
         * task #315 / notes/last-commit-cert-design-2026-07-01.md.
         */
        lastCommitBitmap: ByteVectorType;
        /**
         * hashTreeRoot of the `lastCommit` field on the block. Binds the
         * signature set into the block header so that a block with the wrong
         * `lastCommit` fails hash verification.
         */
        lastCommitHash: ByteVectorType;
    }>;
    transactions: ListCompositeType<ContainerType<{
        body: ContainerType<{
            chainId: _chainsafe_ssz.UintBigintType;
            nonce: _chainsafe_ssz.UintBigintType;
            maxPriorityFeePerGas: _chainsafe_ssz.UintBigintType;
            maxFeePerGas: _chainsafe_ssz.UintBigintType;
            gasLimit: _chainsafe_ssz.UintBigintType;
            to: ByteVectorType;
            value: _chainsafe_ssz.UintBigintType;
            data: _chainsafe_ssz.ByteListType;
        }>;
        publicKey: ByteVectorType;
        signature: ByteVectorType;
    }>>;
    lastCommit: ContainerType<{
        /** Block hash of h-1 that the signatures below commit to. */
        blockHash: ByteVectorType;
        /** Round at which h-1 was finalized (part of the vote-signing domain). */
        round: _chainsafe_ssz.UintBigintType;
        /** Per-signer precommit signatures. Sparse — only present signers. */
        signatures: ListCompositeType<ContainerType<{
            /** Index into the h-1 committee (deterministic committee order). */
            validatorIdx: UintNumberType;
            /** Dilithium3 public key of the signing validator. Verifiers use it directly rather than
             *  incurring a per-block staking-contract state read. Bloat is real (1952 B per slot) but
             *  acceptable at v1 committee cap; sig aggregation is a separate design. */
            publicKey: ByteVectorType;
            /** Dilithium3 signature over the (precommit, chainId, h-1, round, blockHash, validator) vote body. */
            signature: ByteVectorType;
        }>>;
    }>;
}>;
/** Runtime shape of a full block. */
interface Block {
    header: BlockHeader;
    transactions: SignedTransaction[];
    lastCommit: LastCommit;
}
/**
 * The canonical empty LastCommit used for genesis / block 1.
 *
 * A helper (not a constant) because the SSZ types layer requires callers
 * to allocate fresh Uint8Arrays rather than share a global one.
 */
declare function emptyLastCommit(): LastCommit;
/** SSZ schema for a v3 Aura block header. */
declare const AuraBlockHeaderSchema: ContainerType<{
    parentHash: ByteVectorType;
    stateRoot: ByteVectorType;
    transactionsRoot: ByteVectorType;
    receiptsRoot: ByteVectorType;
    number: _chainsafe_ssz.UintBigintType;
    slot: _chainsafe_ssz.UintBigintType;
    timestamp: _chainsafe_ssz.UintBigintType;
    gasLimit: _chainsafe_ssz.UintBigintType;
    gasUsed: _chainsafe_ssz.UintBigintType;
    baseFeePerGas: _chainsafe_ssz.UintBigintType;
    proposer: ByteVectorType;
}>;
/** Runtime shape of an Aura block header. */
interface AuraBlockHeader {
    parentHash: Uint8Array;
    stateRoot: Uint8Array;
    transactionsRoot: Uint8Array;
    receiptsRoot: Uint8Array;
    number: bigint;
    slot: bigint;
    timestamp: bigint;
    gasLimit: bigint;
    gasUsed: bigint;
    baseFeePerGas: bigint;
    proposer: Uint8Array;
}
/** SSZ schema for a full v3 Aura block. */
declare const AuraBlockSchema: ContainerType<{
    header: ContainerType<{
        parentHash: ByteVectorType;
        stateRoot: ByteVectorType;
        transactionsRoot: ByteVectorType;
        receiptsRoot: ByteVectorType;
        number: _chainsafe_ssz.UintBigintType;
        slot: _chainsafe_ssz.UintBigintType;
        timestamp: _chainsafe_ssz.UintBigintType;
        gasLimit: _chainsafe_ssz.UintBigintType;
        gasUsed: _chainsafe_ssz.UintBigintType;
        baseFeePerGas: _chainsafe_ssz.UintBigintType;
        proposer: ByteVectorType;
    }>;
    transactions: ListCompositeType<ContainerType<{
        body: ContainerType<{
            chainId: _chainsafe_ssz.UintBigintType;
            nonce: _chainsafe_ssz.UintBigintType;
            maxPriorityFeePerGas: _chainsafe_ssz.UintBigintType;
            maxFeePerGas: _chainsafe_ssz.UintBigintType;
            gasLimit: _chainsafe_ssz.UintBigintType;
            to: ByteVectorType;
            value: _chainsafe_ssz.UintBigintType;
            data: _chainsafe_ssz.ByteListType;
        }>;
        publicKey: ByteVectorType;
        signature: ByteVectorType;
    }>>;
}>;
/** Runtime shape of a full v3 Aura block. */
interface AuraBlock {
    header: AuraBlockHeader;
    transactions: SignedTransaction[];
}

/**
 * An empty transaction body with zero values everywhere. Useful for tests
 * and for building up transactions field-by-field.
 */
declare function emptyTransactionBody(): TransactionBody;
/**
 * An empty block header with zero values everywhere. Useful for constructing
 * a genesis block or for tests that only care about a subset of fields.
 */
declare function emptyBlockHeader(): BlockHeader;

/** Vote kind discriminator — PreVote (0) or PreCommit (1). */
declare const VOTE_KIND_PREVOTE = 0;
declare const VOTE_KIND_PRECOMMIT = 1;
/**
 * SSZ schema for the signed portion of a vote — the canonical bytes
 * that get hashed and signed.
 */
declare const VoteBodySchema: ContainerType<{
    /** 0 = PreVote, 1 = PreCommit. uint8 so a single byte differentiates the two phases. */
    kind: UintNumberType;
    /** Chain ID, to prevent cross-chain vote replay. */
    chainId: _chainsafe_ssz.UintBigintType;
    /** Block number being voted on. */
    height: _chainsafe_ssz.UintBigintType;
    /** Consensus round within the height — increments on timeout or nil-block. */
    round: _chainsafe_ssz.UintBigintType;
    /**
     * Hash of the proposed block header. 32 bytes of zero is a "nil" vote,
     * meaning "I'm voting to advance the round without committing any block".
     */
    blockHash: ByteVectorType;
    /** Validator's 20-byte address, derivable from their public key. */
    validator: ByteVectorType;
}>;
/** Runtime shape of the signed portion of a vote. */
interface VoteBody {
    kind: number;
    chainId: bigint;
    height: bigint;
    round: bigint;
    blockHash: Uint8Array;
    validator: Uint8Array;
}
/** SSZ schema for a signed vote — body plus the validator's Dilithium3 key and signature. */
declare const SignedVoteSchema: ContainerType<{
    body: ContainerType<{
        /** 0 = PreVote, 1 = PreCommit. uint8 so a single byte differentiates the two phases. */
        kind: UintNumberType;
        /** Chain ID, to prevent cross-chain vote replay. */
        chainId: _chainsafe_ssz.UintBigintType;
        /** Block number being voted on. */
        height: _chainsafe_ssz.UintBigintType;
        /** Consensus round within the height — increments on timeout or nil-block. */
        round: _chainsafe_ssz.UintBigintType;
        /**
         * Hash of the proposed block header. 32 bytes of zero is a "nil" vote,
         * meaning "I'm voting to advance the round without committing any block".
         */
        blockHash: ByteVectorType;
        /** Validator's 20-byte address, derivable from their public key. */
        validator: ByteVectorType;
    }>;
    publicKey: ByteVectorType;
    signature: ByteVectorType;
}>;
/** Runtime shape of a signed vote. */
interface SignedVote {
    body: VoteBody;
    publicKey: Uint8Array;
    signature: Uint8Array;
}

export { ADDRESS_BYTES, type Account, AccountSchema, AddressBytesSchema, type AuraBlock, type AuraBlockHeader, AuraBlockHeaderSchema, AuraBlockSchema, type Block, type BlockHeader, BlockHeaderSchema, BlockSchema, DILITHIUM3_PUBLIC_KEY_BYTES, DILITHIUM3_SIGNATURE_BYTES, HASH_BYTES, HashSchema, LAST_COMMIT_BITMAP_BYTES, LAST_COMMIT_BITMAP_SLOTS, LAST_COMMIT_MAX_SIGS, type LastCommit, LastCommitBitmapSchema, LastCommitSchema, type LastCommitSig, LastCommitSigSchema, MAX_TRANSACTIONS_PER_BLOCK, type SignedTransaction, SignedTransactionSchema, type SignedVote, SignedVoteSchema, type TransactionBody, TransactionBodySchema, Uint256Schema, Uint64Schema, VOTE_KIND_PRECOMMIT, VOTE_KIND_PREVOTE, type VoteBody, VoteBodySchema, ZERO_ADDRESS_BYTES, ZERO_HASH, emptyAccount, emptyBlockHeader, emptyLastCommit, emptyTransactionBody };
