use serde_json::to_string_pretty;
use ssi::did_resolve::ResolutionResult;
use tokio::runtime::Runtime;
use trustchain_api::{api::TrustchainDIDAPI, TrustchainAPI};
use trustchain_core::chain::DIDChain;
use trustchain_core::verifier::Verifier;
use trustchain_ion::{get_ion_resolver, verifier::TrustchainVerifier};
pub fn greet() -> String {
"Hello from Rust! 🦀".into()
}
pub fn resolve_prototype(did: String) -> String {
let rt = Runtime::new().unwrap();
rt.block_on(async {
let resolver = get_ion_resolver("http://127.0.0.1:3000/");
let (_, doc, _) = resolver.resolve_as_result(&did).await.unwrap();
to_string_pretty(&doc.unwrap()).expect("Cannot convert to JSON.")
})
}
pub fn verify_prototype(did: String, root_timestamp: u32) -> DIDChain {
let rt = Runtime::new().unwrap();
rt.block_on(async {
let resolver = get_ion_resolver("http://localhost:3000/");
let verifier = TrustchainVerifier::new(resolver);
verifier.verify(&did, root_timestamp).await.unwrap()
})
}
fn create(document_state: Option<String>, verbose: bool) -> anyhow::Result<()> {
todo!()
}
fn attest(did: String, controlled_did: String, verbose: bool) -> anyhow::Result<()> {
todo!()
}
fn resolve(did: String, verbose: bool) -> anyhow::Result<String> {
let rt = Runtime::new().unwrap();
let resolver = get_ion_resolver("http://localhost:3000/");
rt.block_on(async {
let (res_meta, doc, doc_meta) = TrustchainAPI::resolve(&did, &resolver).await?;
Ok(serde_json::to_string_pretty(&ResolutionResult {
context: Some(serde_json::Value::String(
"https://w3id.org/did-resolution/v1".to_string(),
)),
did_document: doc,
did_resolution_metadata: Some(res_meta),
did_document_metadata: doc_meta,
property_set: None,
})?)
})
}
fn verify(did: String, verbose: bool) -> anyhow::Result<DIDChain> {
todo!()
}
fn update(did: String, controlled_did: String, verbose: bool) -> anyhow::Result<()> {
todo!()
}
fn recover(did: String, verbose: bool) -> anyhow::Result<()> {
todo!()
}
fn deactivate(did: String, verbose: bool) -> anyhow::Result<()> {
todo!()
}
fn publish(did: String, verbose: bool) -> anyhow::Result<()> {
todo!()
}