pub struct DeviceIdentity { /* private fields */ }Expand description
A device’s cryptographic identity
Contains an Ed25519 signing key and derives a unique NodeId from it. The private key should be stored securely (platform secure enclave if available).
Implementations§
Source§impl DeviceIdentity
impl DeviceIdentity
Sourcepub fn generate() -> Self
pub fn generate() -> Self
Generate a new random device identity
Uses the platform’s cryptographically secure random number generator.
Sourcepub fn from_private_key(private_key: &[u8; 32]) -> Result<Self, IdentityError>
pub fn from_private_key(private_key: &[u8; 32]) -> Result<Self, IdentityError>
Sourcepub fn private_key_bytes(&self) -> [u8; 32]
pub fn private_key_bytes(&self) -> [u8; 32]
Get the private key bytes for secure storage
Security: This exposes the private key. Only use for persisting to secure storage (keychain, secure enclave, encrypted NVS).
Sourcepub fn public_key(&self) -> [u8; 32]
pub fn public_key(&self) -> [u8; 32]
Get the public key bytes
This can be shared freely to allow others to verify signatures.
Sourcepub fn verifying_key(&self) -> VerifyingKey
pub fn verifying_key(&self) -> VerifyingKey
Get the verifying key for signature verification
Sourcepub fn node_id(&self) -> NodeId
pub fn node_id(&self) -> NodeId
Derive the NodeId from the public key
The NodeId is the first 4 bytes of the BLAKE3 hash of the public key, interpreted as a little-endian u32. This provides:
- Deterministic derivation (same key = same node_id)
- Collision resistance (BLAKE3 is cryptographically secure)
- Compact representation (4 bytes vs 32 bytes)
Sourcepub fn create_attestation(&self, timestamp_ms: u64) -> IdentityAttestation
pub fn create_attestation(&self, timestamp_ms: u64) -> IdentityAttestation
Create an identity attestation
An attestation proves that the holder of this identity controls the claimed node_id at a specific point in time.