Skip to main content

inferadb_ledger_types/
lib.rs

1//! Core types, errors, and cryptographic primitives for InferaDB Ledger.
2//!
3//! Provides the foundational types used throughout the ledger:
4//! - Newtype identifiers for organizations, vaults, users, teams, apps, invitations, and signing
5//!   keys (both internal `i64` IDs and external Snowflake `u64` slugs), plus geographic region enum
6//!   (`Region`)
7//! - Data structures for blocks, transactions, and operations
8//! - Configuration types with validated builders
9//! - Cryptographic hashing functions (SHA-256, seahash)
10//! - Merkle tree implementation
11//! - Error types using snafu
12
13#![deny(unsafe_code)]
14#![warn(missing_docs)]
15
16/// Serialization and deserialization via postcard.
17pub mod codec;
18/// Configuration types with validated builders.
19pub mod config;
20/// Email blinding key and HMAC-based email hashing for global uniqueness.
21pub mod email_hash;
22/// Error types using snafu with structured error codes.
23pub mod error;
24/// Structured error codes for Raft state machine responses.
25mod error_code;
26/// Event logging domain types for organization-scoped audit trails.
27pub mod events;
28/// Cryptographic hashing (SHA-256, seahash) and block/transaction hashing.
29pub mod hash;
30/// Organization invitation types: status, records, and index entries.
31pub mod invitation;
32/// Merkle tree construction and verification.
33pub mod merkle;
34/// Constants for user onboarding (email verification + account creation).
35pub mod onboarding;
36/// Snowflake-style globally unique ID generation.
37pub mod snowflake;
38/// JWT token types for user sessions and vault access.
39pub mod token;
40/// Core domain types: identifiers, blocks, transactions, operations.
41pub mod types;
42/// Input validation for gRPC request fields.
43pub mod validation;
44
45pub use codec::{CodecError, decode, encode};
46pub use email_hash::{
47    EmailBlindingKey, EmailBlindingKeyParseError, bytes_to_hex, compute_email_hmac, normalize_email,
48};
49pub use error::{DiagnosticCode, LedgerError, Result};
50pub use error_code::ErrorCode;
51pub use hash::{
52    BucketHasher, EMPTY_HASH, Hash, ZERO_HASH, bucket_id, compute_chain_commitment,
53    compute_tx_merkle_root, hash_eq, sha256, sha256_concat, tx_hash, vault_entry_hash,
54};
55pub use invitation::{
56    InvitationStatus, InviteEmailEntry, InviteIndexEntry, OrganizationInvitation,
57    effective_invitation_status,
58};
59pub use token::{
60    SESSION_AUDIENCE, SIGNING_KEY_ENVELOPE_SIZE, SigningKeyEnvelope, TokenError, TokenSubject,
61    TokenType, UserSessionClaims, VAULT_AUDIENCE, ValidatedToken, VaultTokenClaims,
62};
63pub use types::{
64    // Constants
65    ALL_REGIONS,
66    // App identifiers
67    AppCredentialType,
68    AppId,
69    AppSlug,
70    // Structs
71    BlockHeader,
72    BlockRetentionMode,
73    BlockRetentionPolicy,
74    ChainCommitment,
75    ClientAssertionId,
76    // Type aliases
77    ClientId,
78    // Credential types
79    CredentialData,
80    CredentialType,
81    EmailVerifyTokenId,
82    Entity,
83    // Invitation identifiers
84    InviteId,
85    InviteSlug,
86    // Raft node ID
87    LedgerNodeId,
88    NodeId,
89    // Enums
90    Operation,
91    OrganizationId,
92    OrganizationMemberRole,
93    // External organization identifier
94    OrganizationSlug,
95    // Resource accounting
96    OrganizationUsage,
97    // Credential data structs
98    PasskeyCredential,
99    // TOTP challenge
100    PendingTotpChallenge,
101    // Primary auth method
102    PrimaryAuthMethod,
103    // Recovery codes
104    RecoveryCodeCredential,
105    // Refresh token identifier
106    RefreshTokenId,
107    // Region types
108    Region,
109    RegionBlock,
110    RegionParseError,
111    Relationship,
112    SetCondition,
113    // Signing key types
114    SigningKeyId,
115    SigningKeyScope,
116    SigningKeyStatus,
117    // Team identifiers
118    TeamId,
119    TeamSlug,
120    // Token version counter
121    TokenVersion,
122    // TOTP types
123    TotpAlgorithm,
124    TotpCredential,
125    Transaction,
126    TransactionValidationError,
127    TxId,
128    // User credential types
129    UserCredential,
130    UserCredentialId,
131    UserEmailId,
132    UserId,
133    // User enums
134    UserRole,
135    // External user identifier
136    UserSlug,
137    UserStatus,
138    VaultBlock,
139    VaultEntry,
140    VaultHealth,
141    VaultId,
142    // External vault identifier
143    VaultSlug,
144    WriteResult,
145    WriteStatus,
146};