Overview
The Internet Computer protocol defines a comprehensive set of base types that form the foundation of the system. These types are defined inrs/types/base_types/ and handle identity, versioning, resource management, and memory addressing.
Principal Types
PrincipalId
The fundamental identity type representing principals as described in the IC interface specification.A principal is a blob with variable length (bounded by 29 bytes) that uniquely identifies entities in the IC.
Returns the principal as a byte slice
Converts the principal to a byte vector
Returns the class of this principal (Opaque, SelfAuthenticating, Derived, or Anonymous)
PrincipalIdClass
Defines the different classes of principals in the IC:CanisterId
A specialized principal type representing canister identities.Represents a canister’s PrincipalId with additional validation constraints.
Creates a CanisterId from a u64 value using big-endian encoding. The generated principal maintains ordering.
Returns the management canister ID (aaaaa-aa)
Validates and converts a PrincipalId to CanisterId with proper validation checks
Registry and Network Types
RegistryVersion
Represents the registry’s version number as a monotonically increasing counter.
NodeId
Represents a node’s PrincipalId in the network.
SubnetId
Represents a subnet’s PrincipalId in the network.
Resource Management Types
NumBytes
Models a non-negative number of bytes, primarily used for tracking memory usage and allocation in canisters.
- Automatically formats using appropriate binary power units (KiB, MiB, GiB, etc.)
- Shows up to 2 decimal places (e.g., “123.45 MiB”)
- No decimals for byte-level precision
NumSeconds
Models a non-negative number of seconds.
NumOsPages
Represents a number of OS-sized memory pages.
Memory Management Types
InternalAddress
Represents an internal memory address used for pointer arithmetic in canister memory management.
Creates a new InternalAddress
Returns the underlying address value
Safely adds two addresses with overflow checking
Safely subtracts addresses with underflow checking
SnapshotId
Represents a canister snapshot ID, unique across all subnets. Composed of a local snapshot ID (u64) and canister ID.
Extracts the canister ID from the snapshot ID
Extracts the local snapshot counter
Constructs a SnapshotId from a canister ID and local ID pair
Management Canister Types
For detailed management canister types, see the Management Canister Types Reference.IC_00 Constant
The management canister ID, used for system-level operations.
Hashing Utilities
hash_of_map
Computes the hash of a BTreeMap following the IC interface specification’s hash-of-map algorithm.
- Hash each key-value pair using the provided function
- Sort the resulting hashes
- Concatenate and hash the sorted list with SHA-256
Serialization
All types implement standard Rust serialization traits:- Candid:
CandidTypefor inter-canister communication - Serde:
SerializeandDeserializefor data persistence - Protobuf: Protocol buffer encoding for network transmission
Example Usage
See Also
- Core Interfaces - Trait definitions using these types
- Registry API - Registry canister using network types
- IC Interface Specification - Official protocol specification