Skip to content

Commit

Permalink
Implement alpha DidExchange
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Kovar <miroslav.kovar@absa.africa>
  • Loading branch information
mirgee authored and Patrik-Stas committed Nov 16, 2023
1 parent 61b7cd1 commit dcd987c
Show file tree
Hide file tree
Showing 68 changed files with 2,829 additions and 23 deletions.
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions aries/agents/rust/aries-vcx-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ aries_vcx_core = { path = "../../../../aries_vcx_core", features = [
"vdrtools_wallet",
] }
shared = { path = "../../../shared" }
did_resolver_registry = { path = "../../../did_resolver_registry" }
did_resolver_sov = { path = "../../../did_resolver_sov" }
did_peer = { path = "../../../did_peer" }
did_key = { path = "../../../did_key" }
public_key = { path = "../../../public_key" }
async-trait = "0.1.64"
derive_builder = "0.12.0"
serde_json = "1.0.85"
Expand Down
16 changes: 16 additions & 0 deletions aries/agents/rust/aries-vcx-agent/src/agent/agent_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use aries_vcx_core::{
wallet::indy::IndySdkWallet,
};

use crate::services::did_exchange::ServiceDidExchange;
use crate::services::out_of_band::ServiceOutOfBand;
use crate::{
agent::agent_config::AgentConfig,
services::{
Expand All @@ -31,6 +33,8 @@ pub struct Agent {
pub(super) issuer: Arc<ServiceCredentialsIssuer>,
pub(super) verifier: Arc<ServiceVerifier>,
pub(super) prover: Arc<ServiceProver>,
pub(super) out_of_band: Arc<ServiceOutOfBand>,
pub(super) did_exchange: Arc<ServiceDidExchange>,
}

impl Agent {
Expand Down Expand Up @@ -62,6 +66,14 @@ impl Agent {
self.connections.clone()
}

pub fn out_of_band(&self) -> Arc<ServiceOutOfBand> {
self.out_of_band.clone()
}

pub fn did_exchange(&self) -> Arc<ServiceDidExchange> {
self.did_exchange.clone()
}

pub fn schemas(&self) -> Arc<ServiceSchemas> {
self.schemas.clone()
}
Expand Down Expand Up @@ -89,4 +101,8 @@ impl Agent {
pub fn prover(&self) -> Arc<ServiceProver> {
self.prover.clone()
}

pub fn public_did(&self) -> &str {
self.did_exchange.public_did().as_ref()
}
}
41 changes: 39 additions & 2 deletions aries/agents/rust/aries-vcx-agent/src/agent/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ use crate::{
agent::{agent_config::AgentConfig, agent_struct::Agent},
error::AgentResult,
services::{
out_of_band::ServiceOutOfBand,
connection::{ServiceConnections, ServiceEndpoint},
did_exchange::ServiceDidExchange,
schema::ServiceSchemas,
credential_definition::ServiceCredentialDefinitions,
revocation_registry::ServiceRevocationRegistries,
holder::ServiceCredentialsHolder,
issuer::ServiceCredentialsIssuer,
prover::ServiceProver,
revocation_registry::ServiceRevocationRegistries,
schema::ServiceSchemas,
verifier::ServiceVerifier,
},
};
Expand Down Expand Up @@ -83,9 +85,42 @@ impl Agent {
.await
.unwrap();

// TODO: This setup should be easier
// The default issuer did can't be used - its verkey is not in base58 - TODO: double-check
let (public_did, _verkey) = add_new_did(
&wallet,
&profile.inject_indy_ledger_write(),
&config_issuer.institution_did,
None,
)
.await?;
let endpoint = EndpointDidSov::create()
.set_service_endpoint(init_config.service_endpoint.clone())
.set_types(Some(vec![DidSovServiceType::DidCommunication]));
write_endpoint(&profile.inject_indy_ledger_write(), &public_did, &endpoint).await?;

let did_peer_resolver = PeerDidResolver::new();
let did_sov_resolver =
DidSovResolver::new(Arc::<ConcreteAttrReader>::new(profile.inject_indy_ledger_read().into()));
let did_resolver_registry = Arc::new(
ResolverRegistry::new()
.register_resolver::<PeerDidResolver>("peer".into(), did_peer_resolver.into())
.register_resolver::<DidSovResolver>("sov".into(), did_sov_resolver.into()),
);

let connections = Arc::new(ServiceConnections::new(
ledger_read.clone(),
wallet.clone(),
init_config.service_endpoint.clone(),
));
let did_exchange = Arc::new(ServiceDidExchange::new(
Arc::clone(&profile),
did_resolver_registry.clone(),
init_config.service_endpoint.clone(),
public_did,
));
let out_of_band = Arc::new(ServiceOutOfBand::new(
Arc::clone(&profile),
init_config.service_endpoint,
));
let schemas = Arc::new(ServiceSchemas::new(
Expand Down Expand Up @@ -137,6 +172,8 @@ impl Agent {
anoncreds,
wallet,
connections,
did_exchange,
out_of_band,
schemas,
cred_defs,
rev_regs,
Expand Down
55 changes: 54 additions & 1 deletion aries/agents/rust/aries-vcx-agent/src/error/convertors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use std::convert::From;

use aries_vcx::errors::error::{AriesVcxError, AriesVcxErrorKind};
use aries_vcx::{
did_doc::error::DidDocumentBuilderError,
did_doc_sov::error::DidDocumentSovError,
errors::error::{AriesVcxError, AriesVcxErrorKind},
protocols::did_exchange::state_machine::generic::GenericDidExchange,
};
use aries_vcx_core::errors::error::AriesVcxCoreError;

use crate::error::*;
Expand Down Expand Up @@ -33,3 +38,51 @@ impl From<AriesVcxCoreError> for AgentError {
AgentError { message, kind }
}
}

impl From<DidDocumentSovError> for AgentError {
fn from(err: DidDocumentSovError) -> Self {
let kind = AgentErrorKind::GenericAriesVcxError;
let message = format!("DidDocumentSovError; err: {:?}", err.to_string());
AgentError { message, kind }
}
}

impl From<DidDocumentBuilderError> for AgentError {
fn from(err: DidDocumentBuilderError) -> Self {
let kind = AgentErrorKind::GenericAriesVcxError;
let message = format!("DidDocumentBuilderError; err: {:?}", err.to_string());
AgentError { message, kind }
}
}

impl From<aries_vcx::did_parser::ParseError> for AgentError {
fn from(err: aries_vcx::did_parser::ParseError) -> Self {
let kind = AgentErrorKind::GenericAriesVcxError;
let message = format!("DidParseError; err: {:?}", err.to_string());
AgentError { message, kind }
}
}

impl From<public_key::PublicKeyError> for AgentError {
fn from(err: public_key::PublicKeyError) -> Self {
let kind = AgentErrorKind::GenericAriesVcxError;
let message = format!("PublicKeyError; err: {:?}", err.to_string());
AgentError { message, kind }
}
}

impl From<did_key::error::DidKeyError> for AgentError {
fn from(err: did_key::error::DidKeyError) -> Self {
let kind = AgentErrorKind::GenericAriesVcxError;
let message = format!("DidKeyError; err: {:?}", err.to_string());
AgentError { message, kind }
}
}

impl From<(GenericDidExchange, AriesVcxError)> for AgentError {
fn from(err: (GenericDidExchange, AriesVcxError)) -> Self {
let kind = AgentErrorKind::GenericAriesVcxError;
let message = format!("GenericDidExchange; err: {:?}", err.1.to_string());
AgentError { message, kind }
}
}
2 changes: 2 additions & 0 deletions aries/agents/rust/aries-vcx-agent/src/error/error_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ pub enum AgentErrorKind {
MediatedConnectionServiceUnavailable,
#[error("Failed to submit http request")]
PostMessageFailed,
#[error("Invalid state")]
InvalidState,
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct AgentError {

impl std::fmt::Display for AgentError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
f.write_str(&self.kind.to_string())
f.write_str(&format!("{}: {}", self.kind.to_string(), self.message.to_string()))
}
}

Expand Down
1 change: 0 additions & 1 deletion aries/agents/rust/aries-vcx-agent/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
extern crate derive_builder;
extern crate serde;

extern crate serde_json;
#[macro_use]
extern crate log;
Expand Down
Loading

0 comments on commit dcd987c

Please sign in to comment.