actr_platform_traits/crypto.rs
1//! Platform-agnostic cryptography provider trait
2
3use async_trait::async_trait;
4
5use crate::PlatformError;
6
7/// Platform-agnostic cryptography provider
8///
9/// Native: ed25519-dalek + sha2
10/// Web: SubtleCrypto (Web Crypto API)
11#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
12#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
13pub trait CryptoProvider: Send + Sync {
14 /// Ed25519 signature verification
15 ///
16 /// Returns `Ok(())` if the signature is valid, `Err` otherwise.
17 async fn ed25519_verify(
18 &self,
19 public_key: &[u8],
20 message: &[u8],
21 signature: &[u8],
22 ) -> Result<(), PlatformError>;
23
24 /// SHA-256 hash
25 async fn sha256(&self, data: &[u8]) -> Result<[u8; 32], PlatformError>;
26}