actr_platform_traits/platform.rs
1//! Composite platform provider trait.
2
3use std::sync::Arc;
4
5use async_trait::async_trait;
6
7use crate::PlatformError;
8use crate::crypto::CryptoProvider;
9use crate::storage::KvStore;
10
11/// Composite platform provider — the three OS-level services a Hyper needs.
12///
13/// Deliberately narrow and noun-shaped: each method answers one question.
14///
15/// | Method | Question |
16/// |-----------------|-----------------------------------------|
17/// | `instance_uid` | "What's my stable ID, across restarts?" |
18/// | `secret_store` | "Where do I keep actor credentials?" |
19/// | `crypto` | "How do I verify signatures?" |
20///
21/// Implementations own their own root (a filesystem dir on native, a localStorage
22/// prefix on web) and handle setup internally. Callers never think in terms of
23/// filesystem paths or directory creation.
24#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
25#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
26pub trait PlatformProvider: Send + Sync {
27 /// Stable instance UID that survives restarts.
28 ///
29 /// Must return the same value for the lifetime of the underlying storage
30 /// (e.g. a given `data_dir` on native, a given localStorage prefix on web).
31 async fn instance_uid(&self) -> Result<String, PlatformError>;
32
33 /// Open a namespaced KV store (per-actor credential / PSK storage).
34 ///
35 /// The namespace is supplied by the caller; the provider decides how to
36 /// combine it with its own root to produce a real storage location.
37 async fn secret_store(&self, namespace: &str) -> Result<Arc<dyn KvStore>, PlatformError>;
38
39 /// Cryptographic primitives (signature verification, hashing).
40 fn crypto(&self) -> Arc<dyn CryptoProvider>;
41}