diff --git a/aries/aries_vcx/src/protocols/did_exchange/state_machine/requester/request_sent/mod.rs b/aries/aries_vcx/src/protocols/did_exchange/state_machine/requester/request_sent/mod.rs index ccf0c0a80e..c2439df280 100644 --- a/aries/aries_vcx/src/protocols/did_exchange/state_machine/requester/request_sent/mod.rs +++ b/aries/aries_vcx/src/protocols/did_exchange/state_machine/requester/request_sent/mod.rs @@ -3,9 +3,8 @@ use std::sync::Arc; use did_parser::Did; use did_peer::{ peer_did::{numalgos::numalgo2::Numalgo2, PeerDid}, - resolver::{options::PublicKeyEncoding, PeerDidResolver}, + resolver::options::PublicKeyEncoding, }; -use did_resolver::traits::resolvable::resolution_output::DidResolutionOutput; use did_resolver_registry::ResolverRegistry; use messages::msg_fields::protocols::did_exchange::{ complete::Complete as CompleteMessage, request::Request, response::Response, @@ -34,10 +33,8 @@ impl DidExchangeRequester { let their_did_document = resolver_registry .resolve(their_did, &Default::default()) .await? - .did_document - .clone(); - let DidResolutionOutput { did_document, .. } = - PeerDidResolver::resolve_peerdid2(our_peer_did, PublicKeyEncoding::Base58).await?; + .did_document; + let did_document = our_peer_did.resolve(PublicKeyEncoding::Base58)?; let invitation_id = Uuid::new_v4().to_string(); let request = construct_request(invitation_id.clone(), our_peer_did.to_string()); @@ -76,11 +73,9 @@ impl DidExchangeRequester { } else { let peer_did = PeerDid::::parse(response.content.did) .map_err(to_transition_error(self.clone()))?; - let DidResolutionOutput { did_document, .. } = - PeerDidResolver::resolve_peerdid2(&peer_did, PublicKeyEncoding::Base58) - .await - .map_err(to_transition_error(self.clone()))?; - did_document + peer_did + .resolve(PublicKeyEncoding::Base58) + .map_err(to_transition_error(self.clone()))? }; let complete_message = construct_didexchange_complete( diff --git a/aries/aries_vcx/src/protocols/did_exchange/state_machine/responder/response_sent/mod.rs b/aries/aries_vcx/src/protocols/did_exchange/state_machine/responder/response_sent/mod.rs index 4f516f36e3..c2a289cf33 100644 --- a/aries/aries_vcx/src/protocols/did_exchange/state_machine/responder/response_sent/mod.rs +++ b/aries/aries_vcx/src/protocols/did_exchange/state_machine/responder/response_sent/mod.rs @@ -4,9 +4,8 @@ use aries_vcx_core::wallet::base_wallet::BaseWallet; use did_doc::schema::did_doc::DidDocument; use did_peer::{ peer_did::{numalgos::numalgo2::Numalgo2, PeerDid}, - resolver::{options::PublicKeyEncoding, PeerDidResolver}, + resolver::options::PublicKeyEncoding, }; -use did_resolver::traits::resolvable::resolution_output::DidResolutionOutput; use did_resolver_registry::ResolverRegistry; use messages::msg_fields::protocols::did_exchange::{ complete::Complete, request::Request, response::Response, @@ -34,10 +33,7 @@ impl DidExchangeResponder { invitation_key: Key, ) -> Result, Response>, AriesVcxError> { let their_ddo = resolve_ddo_from_request(&resolver_registry, &request).await?; - let DidResolutionOutput { - did_document: our_did_document, - .. - } = PeerDidResolver::resolve_peerdid2(our_peer_did, PublicKeyEncoding::Base58).await?; + let our_did_document = our_peer_did.resolve(PublicKeyEncoding::Base58)?; // TODO: Response should sign the new *did* with invitation_key only if key was rotated // In practice if the invitation was public, we definitely will be rotating to // peer:did diff --git a/aries/aries_vcx/tests/test_did_exchange.rs b/aries/aries_vcx/tests/test_did_exchange.rs index d4b50d4fc4..be068d40cb 100644 --- a/aries/aries_vcx/tests/test_did_exchange.rs +++ b/aries/aries_vcx/tests/test_did_exchange.rs @@ -27,7 +27,6 @@ use did_peer::{ peer_did::{numalgos::numalgo2::Numalgo2, PeerDid}, resolver::{options::PublicKeyEncoding, PeerDidResolver}, }; -use did_resolver::traits::resolvable::resolution_output::DidResolutionOutput; use did_resolver_registry::ResolverRegistry; use did_resolver_sov::resolution::DidSovResolver; use log::info; @@ -138,12 +137,7 @@ async fn did_exchange_test() -> Result<(), Box> { let responders_peer_did = PeerDid::::from_did_doc(responders_did_document.clone())?; info!("Responder prepares their peer:did: {responders_peer_did}"); - let DidResolutionOutput { - did_document: check_diddoc, - .. - } = PeerDidResolver::resolve_peerdid2(&responders_peer_did, PublicKeyEncoding::Base58) - .await - .unwrap(); + let check_diddoc = responders_peer_did.resolve(PublicKeyEncoding::Base58)?; info!("Responder decodes constructed peer:did as did document: {check_diddoc}"); let TransitionResult { diff --git a/did_core/did_methods/did_peer/examples/demo.rs b/did_core/did_methods/did_peer/examples/demo.rs index dbcf03bae1..6959ea6b27 100644 --- a/did_core/did_methods/did_peer/examples/demo.rs +++ b/did_core/did_methods/did_peer/examples/demo.rs @@ -10,9 +10,8 @@ use did_peer::{ numalgos::{numalgo2::Numalgo2, numalgo3::Numalgo3}, PeerDid, }, - resolver::{options::PublicKeyEncoding, PeerDidResolver}, + resolver::options::PublicKeyEncoding, }; -use did_resolver::traits::resolvable::resolution_output::DidResolutionOutput; #[tokio::main(flavor = "current_thread")] async fn main() -> Result<(), Box> { @@ -47,10 +46,7 @@ async fn demo() -> Result<(), Box> { peer_did_3_v2 ); - let DidResolutionOutput { did_document, .. } = - PeerDidResolver::resolve_peerdid2(&peer_did_2, PublicKeyEncoding::Base58) - .await - .unwrap(); + let did_document = peer_did_2.resolve(PublicKeyEncoding::Base58)?; println!( "Decoded did document: \n{}", serde_json::to_string_pretty(&did_document)? diff --git a/did_core/did_methods/did_peer/src/peer_did/numalgos/numalgo2/mod.rs b/did_core/did_methods/did_peer/src/peer_did/numalgos/numalgo2/mod.rs index 4afed44c4c..7be2da4448 100644 --- a/did_core/did_methods/did_peer/src/peer_did/numalgos/numalgo2/mod.rs +++ b/did_core/did_methods/did_peer/src/peer_did/numalgos/numalgo2/mod.rs @@ -42,6 +42,17 @@ impl PeerDid { didpeer_elements_to_diddoc(did_doc_builder, self.did(), public_key_encoding)?; Ok(did_doc_builder) } + + pub fn resolve( + &self, + public_key_encoding: PublicKeyEncoding, + ) -> Result { + let builder: DidDocumentBuilder = self.to_did_doc_builder(public_key_encoding)?; + let did_doc = builder + .add_also_known_as(self.to_numalgo3()?.to_string().parse()?) + .build(); + Ok(did_doc) + } } #[derive(Clone, Copy, Default, Debug, PartialEq)] diff --git a/did_core/did_methods/did_peer/src/resolver/mod.rs b/did_core/did_methods/did_peer/src/resolver/mod.rs index 0325f44a89..e7ecadb8f9 100644 --- a/did_core/did_methods/did_peer/src/resolver/mod.rs +++ b/did_core/did_methods/did_peer/src/resolver/mod.rs @@ -1,5 +1,4 @@ use async_trait::async_trait; -use did_doc::schema::did_doc::DidDocumentBuilder; use did_parser::Did; use did_resolver::{ error::GenericError, @@ -11,9 +10,7 @@ use did_resolver::{ use serde::{Deserialize, Serialize}; use crate::{ - error::DidPeerError, - peer_did::{generic::AnyPeerDid, numalgos::numalgo2::Numalgo2, PeerDid}, - resolver::options::PublicKeyEncoding, + error::DidPeerError, peer_did::generic::AnyPeerDid, resolver::options::PublicKeyEncoding, }; pub mod options; @@ -32,24 +29,6 @@ pub struct PeerDidResolutionOptions { pub encoding: Option, } -impl PeerDidResolver { - pub async fn resolve_peerdid2( - peer_did: &PeerDid, - public_key_encoding: PublicKeyEncoding, - ) -> Result { - let builder: DidDocumentBuilder = peer_did.to_did_doc_builder(public_key_encoding)?; - let did_doc = builder - .add_also_known_as(peer_did.to_numalgo3()?.to_string().parse()?) - .build(); - let resolution_metadata = DidResolutionMetadata::builder() - .content_type("application/did+json".to_string()) - .build(); - let builder = - DidResolutionOutput::builder(did_doc).did_resolution_metadata(resolution_metadata); - Ok(builder.build()) - } -} - #[async_trait] impl DidResolvable for PeerDidResolver { type DidResolutionOptions = PeerDidResolutionOptions; @@ -62,11 +41,14 @@ impl DidResolvable for PeerDidResolver { let peer_did = AnyPeerDid::parse(did.to_owned())?; match peer_did { AnyPeerDid::Numalgo2(peer_did) => { - Self::resolve_peerdid2( - &peer_did, - options.encoding.unwrap_or(PublicKeyEncoding::Multibase), - ) - .await + let did_doc = + peer_did.resolve(options.encoding.unwrap_or(PublicKeyEncoding::Base58))?; + let resolution_metadata = DidResolutionMetadata::builder() + .content_type("application/did+json".to_string()) + .build(); + let builder = DidResolutionOutput::builder(did_doc) + .did_resolution_metadata(resolution_metadata); + Ok(builder.build()) } n => Err(Box::new(DidPeerError::UnsupportedNumalgo(n.numalgo()))), }