Skip to content

Commit

Permalink
Did-exchange PR revival (#1046)
Browse files Browse the repository at this point in the history
* Restore did-exchange
* Address code review
  • Loading branch information
Patrik-Stas authored Nov 20, 2023
1 parent dcd987c commit 23e2b0f
Show file tree
Hide file tree
Showing 71 changed files with 1,232 additions and 1,177 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/mediator.pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

test-integration-mediator:
runs-on: ubuntu-22.04
services:
services:
mysql:
image: mysql:latest
env:
Expand All @@ -53,4 +53,9 @@ jobs:
- name: Setup database
run: DATABASE_URL=${MYSQL_URL} sqlx migrate run --source aries/agents/rust/mediator/mediation/migrations
- name: "Run mediator integration tests"
run: cargo run --bin mediator & sleep 5 && cargo test --verbose --package mediator -- --nocapture;
run: cargo run --bin mediator & sleep 5 && cargo test --verbose --package mediator -- --nocapture;
- name: "Collect docker logs on failure"
if: failure()
uses: ./.github/actions/upload-docker-logs
with:
name: "docker-services-${{ github.job }}"
1 change: 1 addition & 0 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions aries/agents/rust/aries-vcx-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +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" }
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
7 changes: 3 additions & 4 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,13 +6,12 @@ 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::{
connection::ServiceConnections, credential_definition::ServiceCredentialDefinitions,
holder::ServiceCredentialsHolder, issuer::ServiceCredentialsIssuer, prover::ServiceProver,
did_exchange::ServiceDidExchange, holder::ServiceCredentialsHolder,
issuer::ServiceCredentialsIssuer, out_of_band::ServiceOutOfBand, prover::ServiceProver,
revocation_registry::ServiceRevocationRegistries, schema::ServiceSchemas,
verifier::ServiceVerifier,
},
Expand Down Expand Up @@ -103,6 +102,6 @@ impl Agent {
}

pub fn public_did(&self) -> &str {
self.did_exchange.public_did().as_ref()
self.did_exchange.public_did()
}
}
51 changes: 34 additions & 17 deletions aries/agents/rust/aries-vcx-agent/src/agent/init.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
use std::sync::Arc;

use aries_vcx::global::settings::DEFAULT_LINK_SECRET_ALIAS;
use aries_vcx::{
common::ledger::{
service_didsov::{DidSovServiceType, EndpointDidSov},
transactions::{add_new_did, write_endpoint},
},
global::settings::DEFAULT_LINK_SECRET_ALIAS,
};
use aries_vcx_core::{
self,
anoncreds::{base_anoncreds::BaseAnonCreds, credx_anoncreds::IndyCredxAnonCreds},
ledger::indy_vdr_ledger::DefaultIndyLedgerRead,
wallet::indy::{
wallet::{create_and_open_wallet, wallet_configure_issuer},
IndySdkWallet, WalletConfig,
},
};
use did_peer::resolver::PeerDidResolver;
use did_resolver_registry::ResolverRegistry;
use did_resolver_sov::resolution::DidSovResolver;

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,
did_exchange::ServiceDidExchange,
holder::ServiceCredentialsHolder,
issuer::ServiceCredentialsIssuer,
out_of_band::ServiceOutOfBand,
prover::ServiceProver,
revocation_registry::ServiceRevocationRegistries,
schema::ServiceSchemas,
verifier::ServiceVerifier,
},
};
Expand Down Expand Up @@ -75,7 +85,7 @@ impl Agent {
};

let anoncreds = IndyCredxAnonCreds;
let (ledger_read, ledger_write) = build_ledger_components(vcx_pool_config).unwrap();
let (ledger_read, ledger_write) = build_ledger_components(vcx_pool_config.clone()).unwrap();

let ledger_read = Arc::new(ledger_read);
let ledger_write = Arc::new(ledger_write);
Expand All @@ -88,24 +98,30 @@ impl Agent {
// 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(),
wallet.as_ref(),
ledger_write.as_ref(),
&config_issuer.institution_did,
None,
)
.await?;
.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?;
write_endpoint(
wallet.as_ref(),
ledger_write.as_ref(),
&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_sov_resolver: DidSovResolver<Arc<DefaultIndyLedgerRead>, DefaultIndyLedgerRead> =
DidSovResolver::new(ledger_read.clone());
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()),
.register_resolver("peer".into(), did_peer_resolver)
.register_resolver("sov".into(), did_sov_resolver),
);

let connections = Arc::new(ServiceConnections::new(
Expand All @@ -114,13 +130,14 @@ impl Agent {
init_config.service_endpoint.clone(),
));
let did_exchange = Arc::new(ServiceDidExchange::new(
Arc::clone(&profile),
did_resolver_registry.clone(),
ledger_read.clone(),
wallet.clone(),
did_resolver_registry,
init_config.service_endpoint.clone(),
public_did,
));
let out_of_band = Arc::new(ServiceOutOfBand::new(
Arc::clone(&profile),
wallet.clone(),
init_config.service_endpoint,
));
let schemas = Arc::new(ServiceSchemas::new(
Expand Down
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(&format!("{}: {}", self.kind.to_string(), self.message.to_string()))
f.write_str(&format!("{}: {}", self.kind, self.message))
}
}

Expand Down
57 changes: 57 additions & 0 deletions aries/agents/rust/aries-vcx-agent/src/helper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use aries_vcx::{
did_doc_sov::{service::ServiceSov, DidDocumentSov},
messages::AriesMessage,
utils::{encryption_envelope::EncryptionEnvelope, from_did_doc_sov_to_legacy},
};
use aries_vcx_core::wallet::base_wallet::BaseWallet;
use serde_json::json;
use url::Url;

use crate::{AgentError, AgentErrorKind, AgentResult};

pub fn get_their_endpoint(did_document: &DidDocumentSov) -> AgentResult<Url> {
let service = did_document.service().first().ok_or(AgentError::from_msg(
AgentErrorKind::InvalidState,
"No service found",
))?;
// todo: will get cleaned up after service is de-generified
let url: String = match service {
ServiceSov::Legacy(d) => d.service_endpoint().to_string(),
ServiceSov::AIP1(d) => d.service_endpoint().to_string(),
ServiceSov::DIDCommV1(d) => d.service_endpoint().to_string(),
ServiceSov::DIDCommV2(d) => d.service_endpoint().to_string(),
};
Url::parse(&url).map_err(|err| {
AgentError::from_msg(
AgentErrorKind::InvalidState,
&format!("Failed to parse url found in did document due: {:?}", err),
)
})
}

pub async fn pairwise_encrypt(
our_did_doc: &DidDocumentSov,
their_did_doc: &DidDocumentSov,
wallet: &impl BaseWallet,
message: &AriesMessage,
) -> AgentResult<EncryptionEnvelope> {
let sender_verkey = our_did_doc
.resolved_key_agreement()
.next()
.ok_or_else(|| {
AgentError::from_msg(
AgentErrorKind::InvalidState,
"No key agreement method found in our did document",
)
})?
.public_key()?
.base58();
EncryptionEnvelope::create(
wallet,
json!(message).to_string().as_bytes(),
Some(&sender_verkey),
&from_did_doc_sov_to_legacy(their_did_doc.clone())?,
)
.await
.map_err(|err| err.into())
}
1 change: 1 addition & 0 deletions aries/agents/rust/aries-vcx-agent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extern crate uuid;

mod agent;
mod error;
pub mod helper;
mod http;
mod services;
mod storage;
Expand Down
Loading

0 comments on commit 23e2b0f

Please sign in to comment.