rialo-types 0.12.2

Rialo Types
Documentation
// Copyright (c) Subzero Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//! This crate contains basic types used by Rialo network.
//! When a type is referenced by multiple crates, it is a
//! good idea to have it in crate for simpler dependency management.
//!
//! This crate now includes REX-specific types with TEE attestation support.

/// Transaction validity window in milliseconds.
///
/// A transaction is valid from its `valid_from` timestamp until `valid_from + TRANSACTION_VALIDITY_WINDOW_SECS`.
/// This value is used by both the consensus layer (to filter invalid transactions before proposal)
/// and the execution layer (to reject transactions during processing).
///
/// The value of 120 seconds (2 minutes) provides a reasonable window for:
/// - Client clock drift tolerance
/// - Network propagation delays
/// - Transaction retry attempts
pub const TRANSACTION_VALIDITY_WINDOW_MS: u64 = 120 * 1000;

/// A random seed value derived from consensus.
///
/// This is a newtype wrapper around `u64` that provides type safety for random seed values
/// used in block execution and transaction processing.
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default, serde::Serialize, serde::Deserialize)]
pub struct RandomSeed(pub [u8; 32]);

impl From<[u8; 32]> for RandomSeed {
    fn from(value: [u8; 32]) -> Self {
        Self(value)
    }
}

impl From<u64> for RandomSeed {
    fn from(value: u64) -> Self {
        Self((0..4).fold([0u8; 32], |mut acc, i| {
            acc[i * 8..(i + 1) * 8].copy_from_slice(&value.to_le_bytes());
            acc
        }))
    }
}

impl From<RandomSeed> for u64 {
    fn from(seed: RandomSeed) -> Self {
        u64::from_be_bytes(seed.0[0..8].try_into().expect("to succeed"))
    }
}

// Consensus cryptographic types (only available in non-pdk builds)
#[cfg(feature = "non-pdk")]
pub mod consensus_crypto;

// Core cryptographic types
pub mod crypto;

pub mod headers;
pub mod http_filter;
#[cfg(test)]
mod http_filter_tests;
#[cfg(feature = "non-pdk")]
pub mod multiaddr;
pub mod nonce;
#[cfg(test)]
mod nonce_tests;
mod prelude;
pub mod shared_rpc_types;
pub mod transaction_execution_results;

// REX-specific modules
pub mod attestation;
pub mod duties;
pub mod duty_config;
pub mod error;
pub mod modified_entries;
pub mod output;
pub mod program_format;
pub use program_format::{PVM_MAGIC, WASM_COMPONENT_MAGIC, WASM_MAGIC};
pub mod rex;
pub mod rex_info;
pub mod tee_types;
#[cfg(test)]
mod tests;
pub mod websocket;
pub mod websocket_op;

// Re-export consensus crypto types (only available in non-pdk builds)
#[cfg(feature = "non-pdk")]
pub use attestation::{ed25519_keypair_to_pubkey_slice, ed25519_signature_to_slice};
pub use attestation::{
    AttestationReport, AttestationReportInner, VerificationError, VerifiedAttestation,
};
#[cfg(feature = "non-pdk")]
pub use consensus_crypto::{
    AuthorityPublicKey, GenesisSignature, NetworkKeyPair, NetworkPrivateKey, NetworkPublicKey,
    ProtocolKeyPair, ProtocolKeySignature, ProtocolPublicKey,
};
// Re-export crypto types
pub use crypto::{PublicKey, TeeUserData, TEE_USER_DATA_SIZE, X25519_KEY_SIZE};
pub use duties::{AuthorityKeyBytes, RexDutiesMap, RexDutiesMapKey, RexDutiesMapValue};
pub use duty_config::*;
pub use error::*;
pub use modified_entries::*;
// Re-export multiaddr types
#[cfg(feature = "non-pdk")]
pub use multiaddr::{Multiaddr, Protocol, EPOCH_PORT_OFFSET};
pub use output::*;
/// Re-export for convenience
pub use prelude::*;
pub use rex_info::*;
pub use tee_types::{
    parse_evidence, AttestationEvidence, AwsSevSnpEvidenceData, AzureSevSnpEvidenceData,
    AzureSnpHclEvidence, AzureSnpVtpmEvidence, SevSnpEvidenceData, TeeEvidenceError, TeeType,
};
pub use websocket_op::*;