Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove didcore generics, update did-exchange #1097

Merged
merged 40 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a2d2343
Enhancement: find first comptabile key agreement verification method
Patrik-Stas Jan 4, 2024
4ec2710
Used TypedBulder for didcomm-service data models
Patrik-Stas Jan 4, 2024
29a9a28
Do not leak DidDocumentBuilder out of did_doc crate
Patrik-Stas Jan 4, 2024
448093b
Refactor construct_request didexchange transition
Patrik-Stas Jan 4, 2024
d7cc06a
Reformat
Patrik-Stas Jan 4, 2024
052e301
Rename resolve_their_ddo -> resolve_ddo_from_request
Patrik-Stas Jan 4, 2024
b38affa
Reorganize typed didcomm service models
Patrik-Stas Jan 4, 2024
6bc226a
Make encryption envelope api more general and safer
Patrik-Stas Jan 4, 2024
21e6fe6
Change MissingField to wrap 'str rather than String
Patrik-Stas Jan 5, 2024
5e1c31e
Reduce use of OneOrList
Patrik-Stas Jan 5, 2024
089e1ce
Remove DidDocumentSovError
Patrik-Stas Jan 5, 2024
c53b823
Add negative test cases for verification method
Patrik-Stas Jan 5, 2024
f96b27f
Do not return DidDocumentBuilderError from JsonWebKey methods
Patrik-Stas Jan 5, 2024
17559f3
Multibase wrapper use custom error instead of DidDocumentBuilderError
Patrik-Stas Jan 5, 2024
4985b21
Add todo about using ? with Jwk decoding
Patrik-Stas Jan 5, 2024
5330ea7
Handle jwk error explicitly
Patrik-Stas Jan 5, 2024
cedcc87
Remove now unnecessary serde:error->DidDocumentBuilderError mapping
Patrik-Stas Jan 5, 2024
1b457b3
Uri wrapper use custom error instead of DidDocumentBuilderError
Patrik-Stas Jan 5, 2024
3e7a42f
Create custom error for KeyDecoding errors
Patrik-Stas Jan 6, 2024
159ba39
Remove unused InvalidInput error variant
Patrik-Stas Jan 6, 2024
c6e7ae1
Use PeerDid resolver in favor of peer_did.to_did_doc
Patrik-Stas Jan 8, 2024
32b72ca
Typed service object represents service with particular value of type…
Patrik-Stas Jan 8, 2024
4ac24c2
Fix didpeer test, fix did:peer:2 regex validation
Patrik-Stas Jan 8, 2024
89a29fd
Fix didpeer regex, fix test test_peer_did_2_encode_decode, fix servic…
Patrik-Stas Jan 8, 2024
f6e31cf
Add todo note
Patrik-Stas Jan 8, 2024
204d2f0
Fix invalid peer did fixture, remove comments
Patrik-Stas Jan 8, 2024
e3ddf64
Remove forgotten logs
Patrik-Stas Jan 10, 2024
6f4d52f
Use global uri error mapping in aries-vcx
Patrik-Stas Jan 10, 2024
7e8f671
Create DidDocumentLookupError
Patrik-Stas Jan 10, 2024
8f25e89
Remove getters of DidResolutionOutput in favor of public fields (comm…
Patrik-Stas Jan 10, 2024
f8559c1
Replace for cycles by find()
Patrik-Stas Jan 10, 2024
15b3566
Tweak send_message to take Url by reference
Patrik-Stas Jan 10, 2024
aa25ac4
Change to_did_doc to to_did_doc_builder
Patrik-Stas Jan 10, 2024
9dde0c6
Add source attribute to MultibaseWrapperError
Patrik-Stas Jan 10, 2024
80f151c
Create JsonWebKeyError
Patrik-Stas Jan 10, 2024
0e5ad27
Turn KeyDecodingError enum into struct with source err as trait object
Patrik-Stas Jan 10, 2024
36e7f1c
Define peer2 resolution on peer_did itself
Patrik-Stas Jan 11, 2024
1550c5e
Refactor service_types()
Patrik-Stas Jan 15, 2024
ec5bdd4
Fix formatting
Patrik-Stas Jan 16, 2024
49b3a10
refactor: keep single way to resolve peer dids (#1106)
Patrik-Stas Jan 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

2 changes: 1 addition & 1 deletion aries/agents/node/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ typings/
# End of https://www.gitignore.io/api/node


vcxagent-core/storage-proofs/
vcxagent-core/storage-*

**/test/tmp
19 changes: 9 additions & 10 deletions aries/agents/rust/aries-vcx-agent/src/error/convertors.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::convert::From;

use aries_vcx::{
did_doc::error::{DidDocumentBuilderError, DidDocumentSovError},
did_doc::error::DidDocumentBuilderError,
errors::error::{AriesVcxError, AriesVcxErrorKind},
protocols::did_exchange::state_machine::generic::GenericDidExchange,
};
use aries_vcx_core::errors::error::AriesVcxCoreError;
use did_resolver_sov::did_resolver::did_doc::schema::utils::error::DidDocumentLookupError;

use crate::error::*;

Expand All @@ -29,7 +30,6 @@ impl From<serde_json::Error> for AgentError {
}
}

// TODO
impl From<AriesVcxCoreError> for AgentError {
fn from(err: AriesVcxCoreError) -> Self {
let kind = AgentErrorKind::GenericAriesVcxError;
Expand All @@ -38,14 +38,6 @@ impl From<AriesVcxCoreError> for AgentError {
}
}

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;
Expand Down Expand Up @@ -93,3 +85,10 @@ impl From<(GenericDidExchange, AriesVcxError)> for AgentError {
AgentError { message, kind }
}
}
impl From<DidDocumentLookupError> for AgentError {
fn from(err: DidDocumentLookupError) -> Self {
let kind = AgentErrorKind::GenericAriesVcxError;
let message = format!("DidDocumentLookupError; err: {:?}", err.to_string());
AgentError { message, kind }
}
}
2 changes: 1 addition & 1 deletion aries/agents/rust/aries-vcx-agent/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub struct VcxHttpClient;

#[async_trait]
impl Transport for VcxHttpClient {
async fn send_message(&self, msg: Vec<u8>, service_endpoint: Url) -> VcxResult<()> {
async fn send_message(&self, msg: Vec<u8>, service_endpoint: &Url) -> VcxResult<()> {
shared::http_client::post_message(msg, service_endpoint).await?;
Ok(())
}
Expand Down
51 changes: 33 additions & 18 deletions aries/agents/rust/aries-vcx-agent/src/services/did_exchange.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::sync::Arc;

use aries_vcx::{
did_doc::schema::{service::typed::ServiceType, types::uri::Uri},
messages::{
msg_fields::protocols::{
did_exchange::{
Expand All @@ -25,7 +26,6 @@ use aries_vcx_core::wallet::{base_wallet::BaseWallet, indy::IndySdkWallet};
use did_peer::peer_did::{numalgos::numalgo2::Numalgo2, PeerDid};
use did_resolver_registry::ResolverRegistry;
use did_resolver_sov::did_resolver::did_doc::schema::did_doc::DidDocument;
use url::Url;

use super::connection::ServiceEndpoint;
use crate::{
Expand Down Expand Up @@ -83,10 +83,17 @@ impl ServiceDidExchange {
.thid;
let ddo_their = requester.their_did_doc();
let ddo_our = requester.our_did_document();
let encryption_envelope =
pairwise_encrypt(ddo_our, ddo_their, self.wallet.as_ref(), &request.into()).await?;
let service = ddo_their.get_service_of_type(&ServiceType::DIDCommV1)?;
let encryption_envelope = pairwise_encrypt(
ddo_our,
ddo_their,
self.wallet.as_ref(),
&request.into(),
service.id(),
)
.await?;
VcxHttpClient
.send_message(encryption_envelope.0, get_first_endpoint(ddo_their)?)
.send_message(encryption_envelope.0, service.service_endpoint())
.await?;
self.did_exchange.insert(&request_id, requester.clone())
}
Expand Down Expand Up @@ -127,10 +134,17 @@ impl ServiceDidExchange {
.await?;
let ddo_their = responder.their_did_doc();
let ddo_our = responder.our_did_document();
let encryption_envelope =
pairwise_encrypt(ddo_our, ddo_their, self.wallet.as_ref(), &response.into()).await?;
let service = ddo_their.get_service_of_type(&ServiceType::DIDCommV1)?;
let encryption_envelope = pairwise_encrypt(
ddo_our,
ddo_their,
self.wallet.as_ref(),
&response.into(),
service.id(),
)
.await?;
VcxHttpClient
.send_message(encryption_envelope.0, get_first_endpoint(ddo_their)?)
.send_message(encryption_envelope.0, service.service_endpoint())
.await?;
self.did_exchange.insert(&request_id, responder.clone())
}
Expand All @@ -144,10 +158,17 @@ impl ServiceDidExchange {
.await?;
let ddo_their = requester.their_did_doc();
let ddo_our = requester.our_did_document();
let encryption_envelope =
pairwise_encrypt(ddo_our, ddo_their, self.wallet.as_ref(), &complete.into()).await?;
let service = ddo_their.get_service_of_type(&ServiceType::DIDCommV1)?;
let encryption_envelope = pairwise_encrypt(
ddo_our,
ddo_their,
self.wallet.as_ref(),
&complete.into(),
service.id(),
)
.await?;
VcxHttpClient
.send_message(encryption_envelope.0, get_first_endpoint(ddo_their)?)
.send_message(encryption_envelope.0, service.service_endpoint())
.await?;
self.did_exchange.insert(&thread_id, requester.clone())
}
Expand Down Expand Up @@ -187,25 +208,19 @@ impl ServiceDidExchange {
}
}

pub fn get_first_endpoint(did_document: &DidDocument) -> AgentResult<Url> {
let service = did_document.service().first().ok_or(AgentError::from_msg(
AgentErrorKind::InvalidState,
"No service found",
))?;
Ok(service.service_endpoint().clone())
}

pub async fn pairwise_encrypt(
our_did_doc: &DidDocument,
their_did_doc: &DidDocument,
wallet: &impl BaseWallet,
message: &AriesMessage,
their_service_id: &Uri,
) -> AgentResult<EncryptionEnvelope> {
EncryptionEnvelope::create(
wallet,
serde_json::json!(message).to_string().as_bytes(),
our_did_doc,
their_did_doc,
their_service_id,
)
.await
.map_err(|err| {
Expand Down
2 changes: 1 addition & 1 deletion aries/agents/rust/mediator/src/aries_agent/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub struct MockTransport;

#[async_trait]
impl Transport for MockTransport {
async fn send_message(&self, _msg: Vec<u8>, _service_endpoint: url::Url) -> VcxResult<()> {
async fn send_message(&self, _msg: Vec<u8>, _service_endpoint: &url::Url) -> VcxResult<()> {
Ok(())
}
}
12 changes: 9 additions & 3 deletions aries/aries_vcx/src/errors/mapping_others.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::sync::PoisonError;

use aries_vcx_core::errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind};
use did_doc::schema::{types::uri::UriWrapperError, utils::error::DidDocumentLookupError};
use shared::errors::http_error::HttpError;

use crate::{
Expand Down Expand Up @@ -45,8 +46,8 @@ impl From<did_doc::error::DidDocumentBuilderError> for AriesVcxError {
}
}

impl From<did_doc::error::DidDocumentSovError> for AriesVcxError {
fn from(err: did_doc::error::DidDocumentSovError) -> Self {
impl From<DidDocumentLookupError> for AriesVcxError {
fn from(err: DidDocumentLookupError) -> Self {
AriesVcxError::from_msg(AriesVcxErrorKind::InvalidState, err.to_string())
}
}
Expand Down Expand Up @@ -75,7 +76,12 @@ impl From<did_key::error::DidKeyError> for AriesVcxError {
}
}

// TODO
impl From<UriWrapperError> for AriesVcxError {
fn from(err: UriWrapperError) -> Self {
AriesVcxError::from_msg(AriesVcxErrorKind::InvalidInput, err.to_string())
}
}

impl From<AriesVcxCoreError> for AriesVcxError {
fn from(err: AriesVcxCoreError) -> Self {
let kind = match err.kind() {
Expand Down
2 changes: 1 addition & 1 deletion aries/aries_vcx/src/handlers/mediated_connection/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub async fn send_message(

post_message(
envelope,
did_doc.get_endpoint().ok_or_else(|| {
&did_doc.get_endpoint().ok_or_else(|| {
AriesVcxError::from_msg(AriesVcxErrorKind::InvalidUrl, "No URL in DID Doc")
})?,
)
Expand Down
4 changes: 2 additions & 2 deletions aries/aries_vcx/src/protocols/connection/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl GenericConnection {
let service_endpoint = did_doc.get_endpoint().ok_or_else(|| {
AriesVcxError::from_msg(AriesVcxErrorKind::InvalidUrl, "No URL in DID Doc")
})?;
transport.send_message(msg, service_endpoint).await
transport.send_message(msg, &service_endpoint).await
}
}

Expand Down Expand Up @@ -341,7 +341,7 @@ mod connection_serde_tests {

#[async_trait]
impl Transport for MockTransport {
async fn send_message(&self, _msg: Vec<u8>, _service_endpoint: Url) -> VcxResult<()> {
async fn send_message(&self, _msg: Vec<u8>, _service_endpoint: &Url) -> VcxResult<()> {
Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion aries/aries_vcx/src/protocols/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ where
let service_endpoint = self.their_did_doc().get_endpoint().ok_or_else(|| {
AriesVcxError::from_msg(AriesVcxErrorKind::InvalidUrl, "No URL in DID Doc")
})?;
transport.send_message(msg, service_endpoint).await
transport.send_message(msg, &service_endpoint).await
}
}

Expand Down
2 changes: 1 addition & 1 deletion aries/aries_vcx/src/protocols/did_exchange/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub async fn resolve_enc_key_from_invitation(
})?;
info!("DID resolution output {:?}", output);
Ok(output
.did_document()
.did_document
.verification_method()
.first()
.ok_or_else(|| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use base64::engine::general_purpose::URL_SAFE_NO_PAD;
use chrono::Utc;
use did_doc::schema::{
did_doc::DidDocument,
service::{extra_fields::ServiceKeyKind, typed::didcommv1::ServiceDidCommV1, Service},
service::{service_key_kind::ServiceKeyKind, typed::didcommv1::ServiceDidCommV1, Service},
types::uri::Uri,
verification_method::{VerificationMethod, VerificationMethodType},
};
Expand Down Expand Up @@ -246,17 +246,9 @@ mod tests {
assert_eq!(&ddo_service.id().to_string(), "#service-0");
assert_eq!(
ddo_service.service_type(),
&OneOrList::List(vec![ServiceType::DIDCommV1])
&OneOrList::One(ServiceType::DIDCommV1)
);
assert_eq!(ddo_service.service_endpoint(), &service_endpoint);
let recipient_keys = ddo_service
.extra_field_recipient_keys()
.map(|keys| {
keys.into_iter()
.map(|key| key.to_string())
.collect::<Vec<_>>()
})
.unwrap();
assert_eq!(
ddo_service.extra_field_routing_keys().unwrap(),
vec![
Expand All @@ -265,7 +257,6 @@ mod tests {
]
);

println!("did_doc: {}", did_doc);
assert_eq!(did_doc.key_agreement().len(), 1);
match did_doc.key_agreement().first().unwrap() {
VerificationMethodKind::Resolved(key_agreement) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use messages::{
timing::Timing,
},
msg_fields::protocols::{
did_exchange::request::{Request, RequestContent, RequestDecorators},
did_exchange::{
complete::{Complete, CompleteDecorators},
request::{Request, RequestContent, RequestDecorators},
},
out_of_band::invitation::{Invitation, OobService},
},
};
Expand Down Expand Up @@ -40,6 +43,22 @@ pub fn construct_request(invitation_id: String, our_did: String) -> Request {
.build()
}

pub fn construct_didexchange_complete(request_id: String, invitation_id: String) -> Complete {
let decorators = CompleteDecorators::builder()
.thread(
Thread::builder()
.thid(request_id)
.pthid(invitation_id)
.build(),
)
.timing(Timing::builder().out_time(Utc::now()).build())
.build();
Complete::builder()
.id(Uuid::new_v4().to_string())
.decorators(decorators)
.build()
}

/// We are going to support only DID service values in did-exchange protocol unless there's explicit
/// good reason to keep support for "embedded" type of service value.
/// This function returns first found DID based service value from invitation.
Expand Down
Loading
Loading