Skip to main content

prismer_sdk/
identity.rs

1use crate::{PrismerClient, types::*};
2use serde_json::json;
3
4pub struct IdentityClient<'a> {
5    pub(crate) client: &'a PrismerClient,
6}
7
8impl<'a> IdentityClient<'a> {
9    /// Get the server's Ed25519 public key.
10    pub async fn get_server_key(&self) -> Result<ApiResponse<serde_json::Value>, PrismerError> {
11        self.client.request(reqwest::Method::GET, "/api/im/keys/server", None).await
12    }
13
14    /// Register a public key for identity.
15    pub async fn register_key(&self, public_key: &str, derivation_mode: Option<&str>) -> Result<ApiResponse<serde_json::Value>, PrismerError> {
16        let mut body = json!({ "publicKey": public_key });
17        if let Some(dm) = derivation_mode { body["derivationMode"] = json!(dm); }
18        self.client.request(reqwest::Method::POST, "/api/im/keys/register", Some(body)).await
19    }
20
21    /// Get a user's public key.
22    pub async fn get_key(&self, user_id: &str) -> Result<ApiResponse<serde_json::Value>, PrismerError> {
23        self.client.request(reqwest::Method::GET, &format!("/api/im/keys/{}", user_id), None).await
24    }
25
26    /// Revoke own key.
27    pub async fn revoke_key(&self) -> Result<ApiResponse<serde_json::Value>, PrismerError> {
28        self.client.request(reqwest::Method::POST, "/api/im/keys/revoke", None).await
29    }
30
31    /// Get key audit log for a user.
32    pub async fn get_audit_log(&self, user_id: &str) -> Result<ApiResponse<Vec<serde_json::Value>>, PrismerError> {
33        self.client.request(reqwest::Method::GET, &format!("/api/im/keys/audit/{}", user_id), None).await
34    }
35
36    /// Verify audit log hash chain integrity.
37    pub async fn verify_audit_log(&self, user_id: &str) -> Result<ApiResponse<serde_json::Value>, PrismerError> {
38        self.client.request(reqwest::Method::GET, &format!("/api/im/keys/audit/{}/verify", user_id), None).await
39    }
40}