pub struct DeviceKeypair { /* private fields */ }Expand description
Ed25519 keypair for device identity and authentication.
The keypair consists of:
- A 32-byte secret (signing) key
- A 32-byte public (verifying) key
The DeviceId is derived from the public key.
§Example
use peat_mesh::security::DeviceKeypair;
// Generate a new keypair
let keypair = DeviceKeypair::generate();
// Get the device ID
let device_id = keypair.device_id();
// Sign a message
let message = b"hello world";
let signature = keypair.sign(message);
// Verify the signature
assert!(keypair.verify(message, &signature).is_ok());Implementations§
Source§impl DeviceKeypair
impl DeviceKeypair
Sourcepub fn from_signing_key(signing_key: SigningKey) -> Self
pub fn from_signing_key(signing_key: SigningKey) -> Self
Create from an existing signing key.
Sourcepub fn from_seed(seed: &[u8], context: &str) -> Result<Self, SecurityError>
pub fn from_seed(seed: &[u8], context: &str) -> Result<Self, SecurityError>
Create a deterministic keypair from a seed and context string.
Uses HKDF-SHA256 to derive 32 bytes from seed (IKM) with
context as the info parameter. Same seed + context always
produces the same keypair; different context → different key.
Useful for Kubernetes deployments where pods derive stable identities from a shared secret + pod-specific context.
Sourcepub fn from_secret_bytes(bytes: &[u8]) -> Result<Self, SecurityError>
pub fn from_secret_bytes(bytes: &[u8]) -> Result<Self, SecurityError>
Create from raw secret key bytes (32 bytes).
Sourcepub fn load_from_file(path: &Path) -> Result<Self, SecurityError>
pub fn load_from_file(path: &Path) -> Result<Self, SecurityError>
Load keypair from a file (raw 32-byte secret key).
Sourcepub fn save_to_file(&self, path: &Path) -> Result<(), SecurityError>
pub fn save_to_file(&self, path: &Path) -> Result<(), SecurityError>
Save keypair to a file (raw 32-byte secret key).
§Security Note
In MVP, this saves the key unencrypted. Production deployments should use encrypted key storage (Phase 2).
Sourcepub fn verifying_key(&self) -> VerifyingKey
pub fn verifying_key(&self) -> VerifyingKey
Get the public (verifying) key.
Sourcepub fn public_key_bytes(&self) -> [u8; 32]
pub fn public_key_bytes(&self) -> [u8; 32]
Get the public key as bytes.
Sourcepub fn secret_key_bytes(&self) -> [u8; 32]
pub fn secret_key_bytes(&self) -> [u8; 32]
Get the secret key bytes (32 bytes).
§Security Warning
This exposes the private key material. Only use for:
- Secure storage/persistence
- Cross-crate interop (e.g., converting to peat_btle::DeviceIdentity)
Sourcepub fn verify(
&self,
message: &[u8],
signature: &Signature,
) -> Result<(), SecurityError>
pub fn verify( &self, message: &[u8], signature: &Signature, ) -> Result<(), SecurityError>
Verify a signature against this keypair’s public key.
Sourcepub fn verify_with_key(
public_key: &VerifyingKey,
message: &[u8],
signature: &Signature,
) -> Result<(), SecurityError>
pub fn verify_with_key( public_key: &VerifyingKey, message: &[u8], signature: &Signature, ) -> Result<(), SecurityError>
Verify a signature against a specific public key.
Sourcepub fn signature_from_bytes(bytes: &[u8]) -> Result<Signature, SecurityError>
pub fn signature_from_bytes(bytes: &[u8]) -> Result<Signature, SecurityError>
Parse a signature from bytes.
Sourcepub fn verifying_key_from_bytes(
bytes: &[u8],
) -> Result<VerifyingKey, SecurityError>
pub fn verifying_key_from_bytes( bytes: &[u8], ) -> Result<VerifyingKey, SecurityError>
Parse a verifying key from bytes.
Trait Implementations§
Source§impl Clone for DeviceKeypair
impl Clone for DeviceKeypair
Source§fn clone(&self) -> DeviceKeypair
fn clone(&self) -> DeviceKeypair
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more