use serde_json::{Value, json};
use super::VtaClient;
use crate::error::VtaError;
use crate::trust_tasks;
const CREDENTIALS_TT_TIMEOUT: u64 = 30;
impl VtaClient {
pub async fn issue_credential(
&self,
holder: &str,
claims: Value,
credential_type: Option<&str>,
validity_seconds: u64,
purpose: Option<&str>,
) -> Result<Value, VtaError> {
let mut payload = json!({
"holder": holder,
"claims": claims,
"validitySeconds": validity_seconds,
});
if let Some(ct) = credential_type {
payload["credentialType"] = Value::String(ct.to_string());
}
if let Some(p) = purpose {
payload["purpose"] = Value::String(p.to_string());
}
self.dispatch_trust_task(
trust_tasks::TASK_VTA_CREDENTIALS_ISSUE_0_1,
payload,
CREDENTIALS_TT_TIMEOUT,
)
.await
}
pub async fn revoke_credential(
&self,
credential_id: &str,
reason: Option<&str>,
) -> Result<Value, VtaError> {
let mut payload = json!({ "credentialId": credential_id });
if let Some(r) = reason {
payload["reason"] = Value::String(r.to_string());
}
self.dispatch_trust_task(
trust_tasks::TASK_VTA_CREDENTIALS_REVOKE_0_1,
payload,
CREDENTIALS_TT_TIMEOUT,
)
.await
}
}