Skip to content

Commit

Permalink
WIP: 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 committed Aug 17, 2023
1 parent fcb4616 commit fe4ffd4
Show file tree
Hide file tree
Showing 64 changed files with 2,431 additions and 17 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ on:
push:
branches:
- main
pull_request:
branches:
- "**"
# pull_request:
# branches:
# - "**"

env:
DOCKER_BUILDKIT: 1
Expand Down
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 agents/rust/aries-vcx-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ edition.workspace = true
serde = "1.0.145"
aries-vcx = { path = "../../../aries_vcx" }
aries_vcx_core = { path = "../../../aries_vcx_core" }
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.11.2"
serde_json = "1.0.85"
Expand Down
16 changes: 16 additions & 0 deletions agents/rust/aries-vcx-agent/src/agent/agent_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use crate::agent::agent_config::AgentConfig;

use crate::error::*;
use crate::services::connection::ServiceConnections;
use crate::services::did_exchange::ServiceDidExchange;
use crate::services::out_of_band::ServiceOutOfBand;
use crate::services::{
credential_definition::ServiceCredentialDefinitions, holder::ServiceCredentialsHolder,
issuer::ServiceCredentialsIssuer, mediated_connection::ServiceMediatedConnections, prover::ServiceProver,
Expand All @@ -27,6 +29,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 @@ -64,6 +68,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 mediated_connections(&self) -> AgentResult<Arc<ServiceMediatedConnections>> {
self.mediated_connections
.clone()
Expand Down Expand Up @@ -97,4 +109,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()
}
}
44 changes: 44 additions & 0 deletions agents/rust/aries-vcx-agent/src/agent/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ use aries_vcx::core::profile::ledger::{build_ledger_components, VcxPoolConfig};
use aries_vcx::global::settings::DEFAULT_LINK_SECRET_ALIAS;
use aries_vcx::{
agency_client::{agency_client::AgencyClient, configuration::AgentProvisionConfig},
common::ledger::{
service_didsov::{DidSovServiceType, EndpointDidSov},
transactions::{add_new_did, write_endpoint},
},
core::profile::{profile::Profile, vdrtools_profile::VdrtoolsProfile},
global::settings::init_issuer_config,
utils::provision::provision_cloud_agent,
};
use aries_vcx_core::ledger::base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite};
use aries_vcx_core::wallet::indy::wallet::{create_and_open_wallet, wallet_configure_issuer};
use aries_vcx_core::wallet::indy::{IndySdkWallet, WalletConfig};
use did_peer::peer_did_resolver::resolver::PeerDidResolver;
use did_resolver_registry::ResolverRegistry;
use did_resolver_sov::{reader::ConcreteAttrReader, resolution::DidSovResolver};
use url::Url;

use crate::{
Expand All @@ -20,9 +27,11 @@ use crate::{
services::{
connection::{ServiceConnections, ServiceEndpoint},
credential_definition::ServiceCredentialDefinitions,
did_exchange::ServiceDidExchange,
holder::ServiceCredentialsHolder,
issuer::ServiceCredentialsIssuer,
mediated_connection::ServiceMediatedConnections,
out_of_band::ServiceOutOfBand,
prover::ServiceProver,
revocation_registry::ServiceRevocationRegistries,
schema::ServiceSchemas,
Expand Down Expand Up @@ -101,6 +110,29 @@ 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 (mediated_connections, config_agency_client) = if let Some(agency_config) = init_config.agency_config {
let config_provision_agent = AgentProvisionConfig {
agency_did: agency_config.agency_did,
Expand All @@ -124,6 +156,16 @@ impl Agent {
};

let connections = Arc::new(ServiceConnections::new(
Arc::clone(&profile),
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,
));
Expand All @@ -144,7 +186,9 @@ impl Agent {
Ok(Self {
profile,
connections,
did_exchange,
mediated_connections,
out_of_band,
schemas,
cred_defs,
rev_regs,
Expand Down
55 changes: 54 additions & 1 deletion 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::service::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 agents/rust/aries-vcx-agent/src/error/error_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ pub enum AgentErrorKind {
CredDefAlreadyCreated,
#[error("Mediated connections not configured")]
MediatedConnectionServiceUnavailable,
#[error("Invalid state")]
InvalidState,
}
2 changes: 1 addition & 1 deletion agents/rust/aries-vcx-agent/src/error/error_struct.rs
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 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;
#[macro_use]
extern crate serde_json;
#[macro_use]
extern crate log;
Expand Down
Loading

0 comments on commit fe4ffd4

Please sign in to comment.