use vta_sdk::webvh::WebvhServerRecord;
use crate::error::AppError;
use crate::webvh_host::{
AgentNameAvailability, AgentNameEntry, HostDomains, HostedDidEntry, RequestUriResponse,
WebvhHostClient,
};
pub(crate) async fn host_client<'a>(
deps: &super::WebvhDeps<'a>,
vta_did: &str,
server: &WebvhServerRecord,
) -> Result<WebvhHostClient<'a>, AppError> {
WebvhHostClient::for_server(
&server.did,
vta_did,
deps.did_resolver,
deps.didcomm_bridge,
#[cfg(feature = "tsp")]
deps.tsp.clone(),
)
.await
}
pub async fn publish_log_to_server(
deps: &super::WebvhDeps<'_>,
vta_did: &str,
server: &WebvhServerRecord,
mnemonic: &str,
log_content: &str,
domain: Option<&str>,
) -> Result<(), AppError> {
host_client(deps, vta_did, server)
.await?
.publish_did(mnemonic, log_content, domain)
.await
}
pub async fn delete_log_on_server(
deps: &super::WebvhDeps<'_>,
vta_did: &str,
server: &WebvhServerRecord,
mnemonic: &str,
domain: Option<&str>,
) -> Result<(), AppError> {
host_client(deps, vta_did, server)
.await?
.delete_did(mnemonic, domain)
.await
}
pub async fn register_did_atomic_on_server(
deps: &super::WebvhDeps<'_>,
vta_did: &str,
server: &WebvhServerRecord,
path: &str,
did_log: &str,
force: bool,
domain: Option<&str>,
) -> Result<RequestUriResponse, AppError> {
host_client(deps, vta_did, server)
.await?
.register_did_atomic(path, did_log, force, domain)
.await
}
#[allow(clippy::too_many_arguments)]
pub async fn agent_name_op_on_server(
deps: &super::WebvhDeps<'_>,
vta_did: &str,
server: &WebvhServerRecord,
verb: super::update::AgentNameVerb,
mnemonic: &str,
name: &str,
did_log: &str,
domain: Option<&str>,
) -> Result<(), AppError> {
let client = host_client(deps, vta_did, server).await?;
match verb.host_state() {
Some(state) => {
client
.update_agent_name(mnemonic, name, state, did_log, domain)
.await
}
None => {
client
.remove_agent_name(mnemonic, name, did_log, domain)
.await
}
}
}
pub async fn list_agent_names_on_server(
deps: &super::WebvhDeps<'_>,
vta_did: &str,
server: &WebvhServerRecord,
mnemonic: &str,
domain: Option<&str>,
) -> Result<Vec<AgentNameEntry>, AppError> {
host_client(deps, vta_did, server)
.await?
.list_agent_names(mnemonic, domain)
.await
}
pub async fn check_agent_name_on_server(
deps: &super::WebvhDeps<'_>,
vta_did: &str,
server: &WebvhServerRecord,
name: &str,
domain: Option<&str>,
) -> Result<AgentNameAvailability, AppError> {
host_client(deps, vta_did, server)
.await?
.check_agent_name(name, domain)
.await
}
pub async fn my_domains_on_server(
deps: &super::WebvhDeps<'_>,
vta_did: &str,
server: &WebvhServerRecord,
) -> Result<HostDomains, AppError> {
host_client(deps, vta_did, server).await?.my_domains().await
}
pub async fn list_dids_on_server(
deps: &super::WebvhDeps<'_>,
vta_did: &str,
server: &WebvhServerRecord,
) -> Result<Vec<HostedDidEntry>, AppError> {
host_client(deps, vta_did, server)
.await?
.list_dids(vta_did)
.await
}