diff --git a/agents/node/vcxagent-core/package.json b/agents/node/vcxagent-core/package.json index 1c2fa34c1b..b919c3611f 100644 --- a/agents/node/vcxagent-core/package.json +++ b/agents/node/vcxagent-core/package.json @@ -35,7 +35,7 @@ "demo:faber:mysql": "node demo/faber.js --mysql", "demo:alice:sign": "node demo/alice-signature.js", "demo:faber:verify": "node demo/faber-verify-signature.js", - "test:integration": "npm run test:integration:issue-verify && npm run test:integration:signing && npm run test:integration:messaging && npm run test:integration:tails && npm run test:integration:trustping && npm run test:integration:feature-discovery && npm run test:integration:public-invite && npm run test:integration:out-of-band && npm run test:integration:nonmediated-endpoint && npm run test:integration:nonmediated-connection", + "test:integration": "npm run test:integration:issue-verify && npm run test:integration:signing && npm run test:integration:messaging && npm run test:integration:tails && npm run test:integration:trustping && npm run test:integration:feature-discovery && npm run test:integration:public-invite && npm run test:integration:out-of-band && npm run test:integration:endpoint && npm run test:integration:connection", "test:integration:issue-verify": "jest --forceExit --env=node --runInBand test/issue-verify.spec.js", "test:integration:signing": "jest --forceExit --env=node --runInBand test/sign-verify.spec.js", "test:integration:messaging": "jest --forceExit --env=node --runInBand test/messaging.spec.js", @@ -44,8 +44,8 @@ "test:integration:feature-discovery": "jest --forceExit --env=node --runInBand test/feature-discovery.spec.js", "test:integration:public-invite": "jest --forceExit --env=node --runInBand test/public-invite.spec.js", "test:integration:out-of-band": "jest --forceExit --env=node --runInBand test/out-of-band.spec.js", - "test:integration:nonmediated-endpoint": "jest --forceExit --env=node --runInBand test/nonmediated-endpoint.spec.js", - "test:integration:nonmediated-connection": "jest --forceExit --env=node --runInBand test/nonmediated-connection.spec.js" + "test:integration:endpoint": "jest --forceExit --env=node --runInBand test/endpoint.spec.js", + "test:integration:connection": "jest --forceExit --env=node --runInBand test/connection.spec.js" }, "dependencies": { "@hyperledger/node-vcx-wrapper": "file:../../../wrappers/node", diff --git a/agents/node/vcxagent-core/src/agent.js b/agents/node/vcxagent-core/src/agent.js index e2eae35506..b1997a0b7b 100644 --- a/agents/node/vcxagent-core/src/agent.js +++ b/agents/node/vcxagent-core/src/agent.js @@ -9,7 +9,7 @@ const { createServiceProver } = require('./services/service-prover') const { createServiceCredHolder } = require('./services/service-cred-holder') const { createServiceCredIssuer } = require('./services/service-cred-issuer') const { createServiceConnections } = require('./services/service-connections') -const { createServiceNonmediatedConnections } = require('./services/service-nonmediated-connections') +const { createServiceNonmediatedConnections } = require('./services/service-mediated-connections') const { createServiceOutOfBand } = require('./services/service-out-of-band') const { createServiceLedgerRevocationRegistry } = require('./services/service-revocation-registry') const { provisionAgentInAgency } = require('./utils/vcx-workflows') diff --git a/agents/node/vcxagent-core/src/services/service-nonmediated-connections.js b/agents/node/vcxagent-core/src/services/service-mediated-connections.js similarity index 100% rename from agents/node/vcxagent-core/src/services/service-nonmediated-connections.js rename to agents/node/vcxagent-core/src/services/service-mediated-connections.js diff --git a/agents/node/vcxagent-core/test/nonmediated-connection.spec.js b/agents/node/vcxagent-core/test/connection.spec.js similarity index 100% rename from agents/node/vcxagent-core/test/nonmediated-connection.spec.js rename to agents/node/vcxagent-core/test/connection.spec.js diff --git a/agents/node/vcxagent-core/test/nonmediated-endpoint.spec.js b/agents/node/vcxagent-core/test/endpoint.spec.js similarity index 100% rename from agents/node/vcxagent-core/test/nonmediated-endpoint.spec.js rename to agents/node/vcxagent-core/test/endpoint.spec.js diff --git a/agents/node/vcxagent-core/test/utils/faber.js b/agents/node/vcxagent-core/test/utils/faber.js index 7a7c0352cc..c3cc72ccec 100644 --- a/agents/node/vcxagent-core/test/utils/faber.js +++ b/agents/node/vcxagent-core/test/utils/faber.js @@ -1,7 +1,7 @@ /* eslint-env jest */ const { createVcxAgent, getSampleSchemaData } = require('../../src') const { - ConnectionStateType, IssuerStateType, VerifierStateType, generatePublicInvite, + MediatedConnectionStateType, ConnectionStateType, IssuerStateType, VerifierStateType, generatePublicInvite, createService, getServiceFromLedger, unpack, createAndStoreDid } = require('@hyperledger/node-vcx-wrapper') const { getAliceSchemaAttrs, getFaberCredDefName } = require('./data') @@ -300,7 +300,7 @@ module.exports.createFaber = async function createFaber (serviceEndpoint = 'http await vcxAgent.agentInitVcx() expect(await vcxAgent.serviceNonmediatedConnections.getState(connectionId)).toBe(ConnectionStateType.Invited) await vcxAgent.serviceNonmediatedConnections.inviterConnectionProcessRequest(connectionId, request) - expect(await vcxAgent.serviceNonmediatedConnections.getState(connectionId)).toBe(ConnectionStateType.Responded) + expect(await vcxAgent.serviceNonmediatedConnections.getState(connectionId)).toBe(ConnectionStateType.Requested) await vcxAgent.agentShutdownVcx() } @@ -310,7 +310,7 @@ module.exports.createFaber = async function createFaber (serviceEndpoint = 'http await vcxAgent.agentInitVcx() await vcxAgent.serviceNonmediatedConnections.inviterConnectionCreateFromRequest(connectionId, request, pwInfo) - expect(await vcxAgent.serviceNonmediatedConnections.getState(connectionId)).toBe(ConnectionStateType.Responded) + expect(await vcxAgent.serviceNonmediatedConnections.getState(connectionId)).toBe(ConnectionStateType.Requested) await vcxAgent.agentShutdownVcx() } @@ -330,7 +330,7 @@ module.exports.createFaber = async function createFaber (serviceEndpoint = 'http await vcxAgent.agentInitVcx() await vcxAgent.serviceConnections.inviterConnectionCreateFromRequestV2(connectionId, pwInfo, request) - expect(await vcxAgent.serviceConnections.connectionUpdate(connectionId)).toBe(ConnectionStateType.Responded) + expect(await vcxAgent.serviceConnections.connectionUpdate(connectionId)).toBe(MediatedConnectionStateType.Responded) await vcxAgent.agentShutdownVcx() } diff --git a/agents/node/vcxagent-core/test/utils/utils.js b/agents/node/vcxagent-core/test/utils/utils.js index 269da83d73..d898c6a4a7 100644 --- a/agents/node/vcxagent-core/test/utils/utils.js +++ b/agents/node/vcxagent-core/test/utils/utils.js @@ -3,8 +3,8 @@ const sleep = require('sleep-promise') const express = require('express') const { createFaber } = require('./faber') const { createAlice } = require('./alice') -const { ConnectionStateType } = require('@hyperledger/node-vcx-wrapper') const assert = require('assert') +const { MediatedConnectionStateType, ConnectionStateType } = require('@hyperledger/node-vcx-wrapper') const logger = require('../../demo/logger')('utils') module.exports.createAliceAndFaber = async function createAliceAndFaber ({ aliceEndpoint, faberEndpoint } = {}) { @@ -18,9 +18,9 @@ module.exports.createPairedAliceAndFaber = async function createPairedAliceAndFa const faber = await createFaber() const invite = await faber.createInvite() await alice.acceptInvite(invite) - await faber.updateConnection(ConnectionStateType.Responded) - await alice.updateConnection(ConnectionStateType.Finished) - await faber.updateConnection(ConnectionStateType.Finished) + await faber.updateConnection(MediatedConnectionStateType.Responded) + await alice.updateConnection(MediatedConnectionStateType.Finished) + await faber.updateConnection(MediatedConnectionStateType.Finished) return { alice, faber } } @@ -69,7 +69,7 @@ module.exports.createPairedAliceAndFaberViaPublicInvite = async function createP } const f2 = async (alice, faber, pwInfo, message) => { await faber.createConnectionFromReceivedRequestV2(pwInfo, message) - await alice.updateConnection(ConnectionStateType.Finished) + await alice.updateConnection(MediatedConnectionStateType.Finished) await faber.updateConnection(ConnectionStateType.Finished) return { alice, faber } } @@ -83,12 +83,12 @@ module.exports.createPairedAliceAndFaberViaOobMsg = async function createPairedA const pwInfo = await faber.publishService(endpoint) const msg = await faber.createOobMessageWithDid() await alice.createConnectionUsingOobMessage(msg) - await alice.updateConnection(ConnectionStateType.Requested) + await alice.updateConnection(MediatedConnectionStateType.Requested) return { alice, faber, pwInfo } } const f2 = async (alice, faber, pwInfo, message) => { await faber.createConnectionFromReceivedRequestV2(pwInfo, message) - await alice.updateConnection(ConnectionStateType.Finished) + await alice.updateConnection(MediatedConnectionStateType.Finished) await faber.updateConnection(ConnectionStateType.Finished) return { alice, faber } } @@ -99,13 +99,13 @@ module.exports.connectViaOobMessage = async function connectViaOobMessage (alice const f1 = async (endpoint) => { const pwInfo = await faber.publishService(endpoint) await alice.createConnectionUsingOobMessage(msg) - await alice.updateConnection(ConnectionStateType.Requested) + await alice.updateConnection(MediatedConnectionStateType.Requested) return { alice, faber, pwInfo } } const f2 = async (alice, faber, pwInfo, message) => { await faber.createConnectionFromReceivedRequestV2(pwInfo, message) - await alice.updateConnection(ConnectionStateType.Finished) - await faber.updateConnection(ConnectionStateType.Finished) + await alice.updateConnection(MediatedConnectionStateType.Finished) + await faber.updateConnection(MediatedConnectionStateType.Finished) return { alice, faber } } return await executeFunctionWithServer(f1, f2) diff --git a/agents/rust/aries-vcx-agent/src/services/connection.rs b/agents/rust/aries-vcx-agent/src/services/connection.rs index 52244dc830..5c77366fe9 100644 --- a/agents/rust/aries-vcx-agent/src/services/connection.rs +++ b/agents/rust/aries-vcx-agent/src/services/connection.rs @@ -55,15 +55,10 @@ impl ServiceConnections { pub async fn send_request(&self, thread_id: &str) -> AgentResult<()> { let invitee: Connection<_, _> = self.connections.get(thread_id)?.try_into()?; - let invitee = invitee - .send_request( - &self.profile.inject_wallet(), - self.service_endpoint.clone(), - vec![], - &HttpClient, - ) + let invitee = invitee.prepare_request(self.service_endpoint.clone(), vec![]).await?; + invitee + .send_message(&self.profile.inject_wallet(), invitee.get_request().into(), &HttpClient) .await?; - self.connections.insert(thread_id, invitee.into())?; Ok(()) } @@ -102,8 +97,9 @@ impl ServiceConnections { pub async fn send_response(&self, thread_id: &str) -> AgentResult<()> { let inviter: Connection<_, _> = self.connections.get(thread_id)?.try_into()?; - let inviter = inviter - .send_response(&self.profile.inject_wallet(), &HttpClient) + let response = inviter.get_connection_response_msg(); + inviter + .send_message(&self.profile.inject_wallet(), &response.into(), &HttpClient) .await?; self.connections.insert(thread_id, inviter.into())?; @@ -124,7 +120,9 @@ impl ServiceConnections { pub async fn send_ack(&self, thread_id: &str) -> AgentResult<()> { let invitee: Connection<_, _> = self.connections.get(thread_id)?.try_into()?; - let invitee = invitee.send_ack(&self.profile.inject_wallet(), &HttpClient).await?; + invitee + .send_message(&self.profile.inject_wallet(), &invitee.get_ack().into(), &HttpClient) + .await?; self.connections.insert(thread_id, invitee.into())?; diff --git a/aries_vcx/src/protocols/connection/generic/conversions.rs b/aries_vcx/src/protocols/connection/generic/conversions.rs index 9b3417b56f..dab1985e0d 100644 --- a/aries_vcx/src/protocols/connection/generic/conversions.rs +++ b/aries_vcx/src/protocols/connection/generic/conversions.rs @@ -6,12 +6,10 @@ use crate::{ invitee::states::{ completed::Completed as InviteeCompleted, initial::Initial as InviteeInitial, invited::Invited as InviteeInvited, requested::Requested as InviteeRequested, - responded::Responded as InviteeResponded, }, inviter::states::{ completed::Completed as InviterCompleted, initial::Initial as InviterInitial, invited::Invited as InviterInvited, requested::Requested as InviterRequested, - responded::Responded as InviterResponded, }, Connection, }, @@ -107,13 +105,11 @@ from_concrete_to_vague!(Invitee, InviteeState, Invitee, GenericState); from_concrete_to_vague!(InviterInitial, Initial, InviterState); from_concrete_to_vague!(InviterInvited, Invited, InviterState); from_concrete_to_vague!(InviterRequested, Requested, InviterState); -from_concrete_to_vague!(InviterResponded, Responded, InviterState); from_concrete_to_vague!(InviterCompleted, Completed, InviterState); from_concrete_to_vague!(InviteeInitial, Initial, InviteeState); from_concrete_to_vague!(InviteeInvited, Invited, InviteeState); from_concrete_to_vague!(InviteeRequested, Requested, InviteeState); -from_concrete_to_vague!(InviteeResponded, Responded, InviteeState); from_concrete_to_vague!(InviteeCompleted, Completed, InviteeState); // ---------------------------- Try From Vague State to Concrete State implementations ---------------------------- @@ -136,11 +132,9 @@ try_from_vague_to_concrete!(InviteeState, Invitee, Inviter, Invitee); try_from_vague_to_concrete!(InviterState, Initial, InviterInitial); try_from_vague_to_concrete!(InviterState, Invited, InviterInvited); try_from_vague_to_concrete!(InviterState, Requested, InviterRequested); -try_from_vague_to_concrete!(InviterState, Responded, InviterResponded); try_from_vague_to_concrete!(InviterState, Completed, InviterCompleted); try_from_vague_to_concrete!(InviteeState, Initial, InviteeInitial); try_from_vague_to_concrete!(InviteeState, Invited, InviteeInvited); try_from_vague_to_concrete!(InviteeState, Requested, InviteeRequested); -try_from_vague_to_concrete!(InviteeState, Responded, InviteeResponded); try_from_vague_to_concrete!(InviteeState, Completed, InviteeCompleted); diff --git a/aries_vcx/src/protocols/connection/generic/mod.rs b/aries_vcx/src/protocols/connection/generic/mod.rs index 4312d263de..7bbe97c627 100644 --- a/aries_vcx/src/protocols/connection/generic/mod.rs +++ b/aries_vcx/src/protocols/connection/generic/mod.rs @@ -16,12 +16,10 @@ use crate::{ invitee::states::{ completed::Completed as InviteeCompleted, initial::Initial as InviteeInitial, invited::Invited as InviteeInvited, requested::Requested as InviteeRequested, - responded::Responded as InviteeResponded, }, inviter::states::{ completed::Completed as InviterCompleted, initial::Initial as InviterInitial, invited::Invited as InviterInvited, requested::Requested as InviterRequested, - responded::Responded as InviterResponded, }, pairwise_info::PairwiseInfo, trait_bounds::{TheirDidDoc, ThreadId}, @@ -88,7 +86,6 @@ pub enum InviterState { Initial(InviterInitial), Invited(InviterInvited), Requested(InviterRequested), - Responded(InviterResponded), Completed(InviterCompleted), } @@ -97,7 +94,6 @@ pub enum InviteeState { Initial(InviteeInitial), Invited(InviteeInvited), Requested(InviteeRequested), - Responded(InviteeResponded), Completed(InviteeCompleted), } @@ -114,12 +110,10 @@ impl GenericConnection { GenericState::Invitee(InviteeState::Initial(_)) => None, GenericState::Invitee(InviteeState::Invited(s)) => Some(s.thread_id()), GenericState::Invitee(InviteeState::Requested(s)) => Some(s.thread_id()), - GenericState::Invitee(InviteeState::Responded(s)) => Some(s.thread_id()), GenericState::Invitee(InviteeState::Completed(s)) => Some(s.thread_id()), GenericState::Inviter(InviterState::Initial(_)) => None, GenericState::Inviter(InviterState::Invited(s)) => Some(s.thread_id()), GenericState::Inviter(InviterState::Requested(s)) => Some(s.thread_id()), - GenericState::Inviter(InviterState::Responded(s)) => Some(s.thread_id()), GenericState::Inviter(InviterState::Completed(s)) => Some(s.thread_id()), } } @@ -133,12 +127,10 @@ impl GenericConnection { GenericState::Invitee(InviteeState::Initial(_)) => None, GenericState::Invitee(InviteeState::Invited(s)) => Some(s.their_did_doc()), GenericState::Invitee(InviteeState::Requested(s)) => Some(s.their_did_doc()), - GenericState::Invitee(InviteeState::Responded(s)) => Some(s.their_did_doc()), GenericState::Invitee(InviteeState::Completed(s)) => Some(s.their_did_doc()), GenericState::Inviter(InviterState::Initial(_)) => None, GenericState::Inviter(InviterState::Invited(_)) => None, GenericState::Inviter(InviterState::Requested(s)) => Some(s.their_did_doc()), - GenericState::Inviter(InviterState::Responded(s)) => Some(s.their_did_doc()), GenericState::Inviter(InviterState::Completed(s)) => Some(s.their_did_doc()), } } @@ -149,7 +141,6 @@ impl GenericConnection { GenericState::Invitee(InviteeState::Initial(_)) => None, GenericState::Invitee(InviteeState::Invited(s)) => Some(s.bootstrap_did_doc()), GenericState::Invitee(InviteeState::Requested(s)) => Some(s.bootstrap_did_doc()), - GenericState::Invitee(InviteeState::Responded(s)) => Some(s.bootstrap_did_doc()), GenericState::Invitee(InviteeState::Completed(s)) => Some(s.bootstrap_did_doc()), } } @@ -223,12 +214,10 @@ mod connection_serde_tests { use super::*; use crate::common::signing::sign_connection_response; - use crate::core::profile::profile::Profile; use crate::handlers::util::AnyInvitation; use crate::protocols::connection::serializable::*; use crate::protocols::connection::{invitee::InviteeConnection, inviter::InviterConnection, Connection}; use crate::utils::mockdata::profile::mock_ledger::MockLedger; - use crate::utils::mockdata::profile::mock_profile::MockProfile; use aries_vcx_core::ledger::base_ledger::IndyLedgerRead; use aries_vcx_core::wallet::mock_wallet::MockWallet; use std::sync::Arc; @@ -239,7 +228,6 @@ mod connection_serde_tests { RefInviteeState::Initial(s) => Self::Initial(s.to_owned()), RefInviteeState::Invited(s) => Self::Invited(s.to_owned()), RefInviteeState::Requested(s) => Self::Requested(s.to_owned()), - RefInviteeState::Responded(s) => Self::Responded(s.to_owned()), RefInviteeState::Completed(s) => Self::Completed(s.to_owned()), } } @@ -251,7 +239,6 @@ mod connection_serde_tests { RefInviterState::Initial(s) => Self::Initial(s.to_owned()), RefInviterState::Invited(s) => Self::Invited(s.to_owned()), RefInviterState::Requested(s) => Self::Requested(s.to_owned()), - RefInviterState::Responded(s) => Self::Responded(s.to_owned()), RefInviterState::Completed(s) => Self::Completed(s.to_owned()), } } @@ -288,7 +275,6 @@ mod connection_serde_tests { InviteeState::Initial(s) => Self::Initial(s), InviteeState::Invited(s) => Self::Invited(s), InviteeState::Requested(s) => Self::Requested(s), - InviteeState::Responded(s) => Self::Responded(s), InviteeState::Completed(s) => Self::Completed(s), } } @@ -300,7 +286,6 @@ mod connection_serde_tests { InviterState::Initial(s) => Self::Initial(s), InviterState::Invited(s) => Self::Invited(s), InviterState::Requested(s) => Self::Requested(s), - InviterState::Responded(s) => Self::Responded(s), InviterState::Completed(s) => Self::Completed(s), } } @@ -406,18 +391,17 @@ mod connection_serde_tests { } async fn make_invitee_requested() -> InviteeConnection { - let wallet: Arc = Arc::new(MockWallet {}); let service_endpoint = SERVICE_ENDPOINT.parse().unwrap(); let routing_keys = vec![]; make_invitee_invited() .await - .send_request(&wallet, service_endpoint, routing_keys, &MockTransport) + .prepare_request(service_endpoint, routing_keys) .await .unwrap() } - async fn make_invitee_responded() -> InviteeConnection { + async fn make_invitee_completed() -> InviteeConnection { let wallet: Arc = Arc::new(MockWallet {}); let con = make_invitee_requested().await; let mut con_data = ConnectionData::new(PW_KEY.to_owned(), AriesDidDoc::default()); @@ -435,17 +419,12 @@ mod connection_serde_tests { let response = Response::with_decorators(Uuid::new_v4().to_string(), content, decorators); - con.handle_response(&wallet, response, &MockTransport).await.unwrap() - } - - async fn make_invitee_completed() -> InviteeConnection { - let wallet: Arc = Arc::new(MockWallet {}); + let con = con.handle_response(&wallet, response, &MockTransport).await.unwrap(); - make_invitee_responded() + con.send_message(&wallet, &con.get_ack().into(), &MockTransport) .await - .send_ack(&wallet, &MockTransport) - .await - .unwrap() + .unwrap(); + con } async fn make_inviter_initial() -> InviterConnection { @@ -482,18 +461,8 @@ mod connection_serde_tests { .unwrap() } - async fn make_inviter_responded() -> InviterConnection { - let wallet: Arc = Arc::new(MockWallet {}); - - make_inviter_requested() - .await - .send_response(&wallet, &MockTransport) - .await - .unwrap() - } - async fn make_inviter_completed() -> InviterConnection { - let con = make_inviter_responded().await; + let con = make_inviter_requested().await; let content = AckContent::new(AckStatus::Ok); let decorators = AckDecorators::new(Thread::new(con.thread_id().to_owned())); @@ -515,12 +484,10 @@ mod connection_serde_tests { generate_test!(invitee_connection_initial, make_invitee_initial); generate_test!(invitee_connection_invited, make_invitee_invited); generate_test!(invitee_connection_requested, make_invitee_requested); - generate_test!(invitee_connection_responded, make_invitee_responded); generate_test!(invitee_connection_complete, make_invitee_completed); generate_test!(inviter_connection_initial, make_inviter_initial); generate_test!(inviter_connection_invited, make_inviter_invited); generate_test!(inviter_connection_requested, make_inviter_requested); - generate_test!(inviter_connection_responded, make_inviter_responded); generate_test!(inviter_connection_complete, make_inviter_completed); } diff --git a/aries_vcx/src/protocols/connection/generic/thin_state.rs b/aries_vcx/src/protocols/connection/generic/thin_state.rs index 9cbadce48e..b7376d5491 100644 --- a/aries_vcx/src/protocols/connection/generic/thin_state.rs +++ b/aries_vcx/src/protocols/connection/generic/thin_state.rs @@ -34,7 +34,6 @@ impl From<&InviterState> for State { InviterState::Initial(_) => Self::Initial, InviterState::Invited(_) => Self::Invited, InviterState::Requested(_) => Self::Requested, - InviterState::Responded(_) => Self::Responded, InviterState::Completed(_) => Self::Completed, } } @@ -46,7 +45,6 @@ impl From<&InviteeState> for State { InviteeState::Initial(_) => Self::Initial, InviteeState::Invited(_) => Self::Invited, InviteeState::Requested(_) => Self::Requested, - InviteeState::Responded(_) => Self::Responded, InviteeState::Completed(_) => Self::Completed, } } diff --git a/aries_vcx/src/protocols/connection/invitee/mod.rs b/aries_vcx/src/protocols/connection/invitee/mod.rs index 747219d614..9c2804c5d2 100644 --- a/aries_vcx/src/protocols/connection/invitee/mod.rs +++ b/aries_vcx/src/protocols/connection/invitee/mod.rs @@ -29,9 +29,7 @@ use crate::{ transport::Transport, }; -use self::states::{ - completed::Completed, initial::Initial, invited::Invited, requested::Requested, responded::Responded, -}; +use self::states::{completed::Completed, initial::Initial, invited::Invited, requested::Requested}; use super::{initiation_type::Invitee, pairwise_info::PairwiseInfo, trait_bounds::BootstrapDidDoc, Connection}; use crate::{ @@ -84,17 +82,12 @@ impl InviteeConnection { /// # Errors /// /// Will error out if sending the request fails. - pub async fn send_request( + pub async fn prepare_request( self, - wallet: &Arc, service_endpoint: Url, routing_keys: Vec, - transport: &T, - ) -> VcxResult> - where - T: Transport, - { - trace!("Connection::send_request"); + ) -> VcxResult> { + trace!("Connection::prepare_request"); let recipient_keys = vec![self.pairwise_info.pw_vk.clone()]; @@ -143,10 +136,8 @@ impl InviteeConnection { let request = Request::with_decorators(id, content, decorators); - self.send_message(wallet, &request.into(), transport).await?; - Ok(Connection { - state: Requested::new(self.state.did_doc, thread_id), + state: Requested::new(self.state.did_doc, thread_id, request), source_id: self.source_id, pairwise_info: self.pairwise_info, initiation_type: Invitee, @@ -168,7 +159,7 @@ impl InviteeConnection { wallet: &Arc, response: Response, transport: &T, - ) -> VcxResult> + ) -> VcxResult> where T: Transport, { @@ -203,7 +194,7 @@ impl InviteeConnection { } }?; - let state = Responded::new(did_doc, self.state.did_doc, self.state.thread_id); + let state = Completed::new(did_doc, self.state.did_doc, self.state.thread_id, None); Ok(Connection { state, @@ -212,22 +203,19 @@ impl InviteeConnection { initiation_type: Invitee, }) } + + pub fn get_request(&self) -> &Request { + &self.state.request + } } -impl InviteeConnection { +impl InviteeConnection { /// Sends an acknowledgement message to the inviter and transitions to [`InviteeConnection`]. /// /// # Errors /// /// Will error out if sending the message fails. - pub async fn send_ack( - self, - wallet: &Arc, - transport: &T, - ) -> VcxResult> - where - T: Transport, - { + pub fn get_ack(&self) -> Ack { let id = Uuid::new_v4().to_string(); let content = AckContent::new(AckStatus::Ok); @@ -236,23 +224,7 @@ impl InviteeConnection { timing.out_time = Some(Utc::now()); decorators.timing = Some(timing); - let msg = Ack::with_decorators(id, content, decorators).into(); - - self.send_message(wallet, &msg, transport).await?; - - let state = Completed::new( - self.state.did_doc, - self.state.bootstrap_did_doc, - self.state.thread_id, - None, - ); - - Ok(Connection { - state, - source_id: self.source_id, - pairwise_info: self.pairwise_info, - initiation_type: Invitee, - }) + Ack::with_decorators(id, content, decorators) } } diff --git a/aries_vcx/src/protocols/connection/invitee/states/mod.rs b/aries_vcx/src/protocols/connection/invitee/states/mod.rs index 0cc0ecd220..b0953d0d5a 100644 --- a/aries_vcx/src/protocols/connection/invitee/states/mod.rs +++ b/aries_vcx/src/protocols/connection/invitee/states/mod.rs @@ -2,4 +2,3 @@ pub mod completed; pub mod initial; pub mod invited; pub mod requested; -pub mod responded; diff --git a/aries_vcx/src/protocols/connection/invitee/states/requested.rs b/aries_vcx/src/protocols/connection/invitee/states/requested.rs index 7c6368e4b1..49360b1be7 100644 --- a/aries_vcx/src/protocols/connection/invitee/states/requested.rs +++ b/aries_vcx/src/protocols/connection/invitee/states/requested.rs @@ -1,4 +1,5 @@ use diddoc_legacy::aries::diddoc::AriesDidDoc; +use messages::msg_fields::protocols::connection::request::Request; use crate::protocols::connection::trait_bounds::{BootstrapDidDoc, HandleProblem, TheirDidDoc, ThreadId}; @@ -6,11 +7,16 @@ use crate::protocols::connection::trait_bounds::{BootstrapDidDoc, HandleProblem, pub struct Requested { pub(crate) did_doc: AriesDidDoc, pub(crate) thread_id: String, + pub(crate) request: Request, } impl Requested { - pub fn new(did_doc: AriesDidDoc, thread_id: String) -> Self { - Self { did_doc, thread_id } + pub fn new(did_doc: AriesDidDoc, thread_id: String, request: Request) -> Self { + Self { + did_doc, + thread_id, + request, + } } } diff --git a/aries_vcx/src/protocols/connection/invitee/states/responded.rs b/aries_vcx/src/protocols/connection/invitee/states/responded.rs deleted file mode 100644 index da247a60b9..0000000000 --- a/aries_vcx/src/protocols/connection/invitee/states/responded.rs +++ /dev/null @@ -1,38 +0,0 @@ -use diddoc_legacy::aries::diddoc::AriesDidDoc; - -use crate::protocols::connection::trait_bounds::{BootstrapDidDoc, TheirDidDoc, ThreadId}; - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -pub struct Responded { - pub(crate) did_doc: AriesDidDoc, - pub(crate) bootstrap_did_doc: AriesDidDoc, - pub(crate) thread_id: String, -} - -impl Responded { - pub fn new(did_doc: AriesDidDoc, bootstrap_did_doc: AriesDidDoc, thread_id: String) -> Self { - Self { - did_doc, - bootstrap_did_doc, - thread_id, - } - } -} - -impl TheirDidDoc for Responded { - fn their_did_doc(&self) -> &AriesDidDoc { - &self.did_doc - } -} - -impl BootstrapDidDoc for Responded { - fn bootstrap_did_doc(&self) -> &AriesDidDoc { - &self.bootstrap_did_doc - } -} - -impl ThreadId for Responded { - fn thread_id(&self) -> &str { - &self.thread_id - } -} diff --git a/aries_vcx/src/protocols/connection/inviter/mod.rs b/aries_vcx/src/protocols/connection/inviter/mod.rs index 2255875f19..bc8a95b53d 100644 --- a/aries_vcx/src/protocols/connection/inviter/mod.rs +++ b/aries_vcx/src/protocols/connection/inviter/mod.rs @@ -21,9 +21,7 @@ use crate::protocols::connection::trait_bounds::ThreadId; use crate::transport::Transport; use crate::{common::signing::sign_connection_response, errors::error::VcxResult}; -use self::states::{ - completed::Completed, initial::Initial, invited::Invited, requested::Requested, responded::Responded, -}; +use self::states::{completed::Completed, initial::Initial, invited::Invited, requested::Requested}; use super::{initiation_type::Inviter, pairwise_info::PairwiseInfo, Connection}; use aries_vcx_core::wallet::base_wallet::BaseWallet; @@ -233,41 +231,15 @@ impl InviterConnection { } impl InviterConnection { - /// Sends a [`Response`] to the invitee and transitions to [`InviterConnection`]. + /// Returns pre-built [`Response`] message which shall be delivered to counterparty /// /// # Errors /// /// Will return an error if sending the response fails. - pub async fn send_response( - self, - wallet: &Arc, - transport: &T, - ) -> VcxResult> - where - T: Transport, - { - trace!( - "Connection::send_response >>> signed_response: {:?}", - &self.state.signed_response - ); - - let thread_id = self.state.signed_response.decorators.thread.thid.clone(); - - self.send_message(wallet, &self.state.signed_response.clone().into(), transport) - .await?; - - let state = Responded::new(self.state.did_doc, thread_id); - - Ok(Connection { - state, - source_id: self.source_id, - pairwise_info: self.pairwise_info, - initiation_type: self.initiation_type, - }) + pub fn get_connection_response_msg(&self) -> Response { + self.state.signed_response.clone() } -} -impl InviterConnection { /// Acknowledges an invitee's connection by processing their first message /// and transitions to [`InviterConnection`]. /// @@ -277,7 +249,11 @@ impl InviterConnection { /// the ID of the thread context used in this connection. pub fn acknowledge_connection(self, msg: &AriesMessage) -> VcxResult> { verify_thread_id(self.state.thread_id(), msg)?; - let state = Completed::new(self.state.did_doc, self.state.thread_id, None); + let state = Completed::new( + self.state.did_doc, + self.state.signed_response.decorators.thread.thid, + None, + ); Ok(Connection { source_id: self.source_id, diff --git a/aries_vcx/src/protocols/connection/inviter/states/mod.rs b/aries_vcx/src/protocols/connection/inviter/states/mod.rs index 0cc0ecd220..b0953d0d5a 100644 --- a/aries_vcx/src/protocols/connection/inviter/states/mod.rs +++ b/aries_vcx/src/protocols/connection/inviter/states/mod.rs @@ -2,4 +2,3 @@ pub mod completed; pub mod initial; pub mod invited; pub mod requested; -pub mod responded; diff --git a/aries_vcx/src/protocols/connection/inviter/states/responded.rs b/aries_vcx/src/protocols/connection/inviter/states/responded.rs deleted file mode 100644 index 548581cd75..0000000000 --- a/aries_vcx/src/protocols/connection/inviter/states/responded.rs +++ /dev/null @@ -1,27 +0,0 @@ -use diddoc_legacy::aries::diddoc::AriesDidDoc; - -use crate::protocols::connection::trait_bounds::{TheirDidDoc, ThreadId}; - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -pub struct Responded { - pub(crate) did_doc: AriesDidDoc, - pub(crate) thread_id: String, -} - -impl Responded { - pub fn new(did_doc: AriesDidDoc, thread_id: String) -> Self { - Self { did_doc, thread_id } - } -} - -impl TheirDidDoc for Responded { - fn their_did_doc(&self) -> &AriesDidDoc { - &self.did_doc - } -} - -impl ThreadId for Responded { - fn thread_id(&self) -> &str { - &self.thread_id - } -} diff --git a/aries_vcx/src/protocols/connection/serializable.rs b/aries_vcx/src/protocols/connection/serializable.rs index ff696020ba..c4ce62bb6c 100644 --- a/aries_vcx/src/protocols/connection/serializable.rs +++ b/aries_vcx/src/protocols/connection/serializable.rs @@ -5,12 +5,10 @@ use crate::protocols::connection::{ invitee::states::{ completed::Completed as InviteeCompleted, initial::Initial as InviteeInitial, invited::Invited as InviteeInvited, requested::Requested as InviteeRequested, - responded::Responded as InviteeResponded, }, inviter::states::{ completed::Completed as InviterCompleted, initial::Initial as InviterInitial, invited::Invited as InviterInvited, requested::Requested as InviterRequested, - responded::Responded as InviterResponded, }, pairwise_info::PairwiseInfo, Connection, @@ -64,7 +62,6 @@ pub enum RefInviterState<'a> { Initial(&'a InviterInitial), Invited(&'a InviterInvited), Requested(&'a InviterRequested), - Responded(&'a InviterResponded), Completed(&'a InviterCompleted), } @@ -73,7 +70,6 @@ pub enum RefInviteeState<'a> { Initial(&'a InviteeInitial), Invited(&'a InviteeInvited), Requested(&'a InviteeRequested), - Responded(&'a InviteeResponded), Completed(&'a InviteeCompleted), } @@ -95,13 +91,11 @@ from_concrete_to_serializable!(Invitee, RefInviteeState, Invitee, RefState); from_concrete_to_serializable!(InviterInitial, Initial, RefInviterState); from_concrete_to_serializable!(InviterInvited, Invited, RefInviterState); from_concrete_to_serializable!(InviterRequested, Requested, RefInviterState); -from_concrete_to_serializable!(InviterResponded, Responded, RefInviterState); from_concrete_to_serializable!(InviterCompleted, Completed, RefInviterState); from_concrete_to_serializable!(InviteeInitial, Initial, RefInviteeState); from_concrete_to_serializable!(InviteeInvited, Invited, RefInviteeState); from_concrete_to_serializable!(InviteeRequested, Requested, RefInviteeState); -from_concrete_to_serializable!(InviteeResponded, Responded, RefInviteeState); from_concrete_to_serializable!(InviteeCompleted, Completed, RefInviteeState); impl<'a> SerializableConnection<'a> { diff --git a/libvcx_core/src/api_vcx/api_handle/connection.rs b/libvcx_core/src/api_vcx/api_handle/connection.rs index b2d1436e84..ca78573787 100644 --- a/libvcx_core/src/api_vcx/api_handle/connection.rs +++ b/libvcx_core/src/api_vcx/api_handle/connection.rs @@ -330,8 +330,9 @@ pub async fn send_response(handle: u32) -> LibvcxResult<()> { trace!("send_response >>>"); let con = get_cloned_connection(&handle)?; - let con = con.send_response(&get_main_wallet()?, &HttpClient).await?; - + let response = con.get_connection_response_msg(); + con.send_message(&get_main_wallet()?, &response.into(), &HttpClient) + .await?; insert_connection(handle, con) } @@ -339,14 +340,11 @@ pub async fn send_request(handle: u32, service_endpoint: String, routing_keys: V trace!("send_request >>>"); let con = get_cloned_connection(&handle)?; - let con = con - .send_request( - &get_main_wallet()?, - Url::from_str(&service_endpoint) - .map_err(|err| LibvcxError::from_msg(LibvcxErrorKind::InvalidUrl, err.to_string()))?, - routing_keys, - &HttpClient, - ) + let url = Url::from_str(&service_endpoint) + .map_err(|err| LibvcxError::from_msg(LibvcxErrorKind::InvalidUrl, err.to_string()))?; + let con = con.prepare_request(url, routing_keys).await?; + let request = con.get_request().clone(); + con.send_message(&get_main_wallet()?, &request.into(), &HttpClient) .await?; insert_connection(handle, con) @@ -356,9 +354,9 @@ pub async fn send_ack(handle: u32) -> LibvcxResult<()> { trace!("send_ack >>>"); let con = get_cloned_connection(&handle)?; - let con = con.send_ack(&get_main_wallet()?, &HttpClient).await?; - - insert_connection(handle, con) + con.send_message(&get_main_wallet()?, &con.get_ack().into(), &HttpClient) + .await?; + Ok(()) } pub async fn send_generic_message(handle: u32, content: String) -> LibvcxResult<()> { diff --git a/uniffi_aries_vcx/core/src/handlers/connection/connection.rs b/uniffi_aries_vcx/core/src/handlers/connection/connection.rs index 463fa7ea2c..ae4bb14f2a 100644 --- a/uniffi_aries_vcx/core/src/handlers/connection/connection.rs +++ b/uniffi_aries_vcx/core/src/handlers/connection/connection.rs @@ -134,11 +134,12 @@ impl Connection { .map_err(|err| AriesVcxError::from_msg(AriesVcxErrorKind::InvalidUrl, err.to_string()))?; block_on(async { - let new_conn = connection - .send_request(&profile.inner.inject_wallet(), url, routing_keys, &HttpClient) + let mut connection = connection.prepare_request(url, routing_keys).await?; + let request = connection.get_request().clone(); + connection + .send_message(&profile.inner.inject_wallet(), &request.into(), &HttpClient) .await?; - *handler = VcxGenericConnection::from(new_conn); - + *handler = VcxGenericConnection::from(connection); Ok(()) }) } @@ -149,11 +150,12 @@ impl Connection { let connection = VcxConnection::try_from(handler.clone())?; block_on(async { - let new_conn = connection - .send_response(&profile.inner.inject_wallet(), &HttpClient) + let response = connection.get_connection_response_msg(); + connection + .send_message(&profile.inner.inject_wallet(), &response.into(), &HttpClient) .await?; - *handler = VcxGenericConnection::from(new_conn); + *handler = VcxGenericConnection::from(connection); Ok(()) }) @@ -165,9 +167,13 @@ impl Connection { let connection = VcxConnection::try_from(handler.clone())?; block_on(async { - let new_conn = connection.send_ack(&profile.inner.inject_wallet(), &HttpClient).await?; - *handler = VcxGenericConnection::from(new_conn); - + connection + .send_message( + &profile.inner.inject_wallet(), + &connection.get_ack().into(), + &HttpClient, + ) + .await?; Ok(()) }) } diff --git a/wrappers/node/src/api/common.ts b/wrappers/node/src/api/common.ts index bb11d4f993..a746ef92ac 100644 --- a/wrappers/node/src/api/common.ts +++ b/wrappers/node/src/api/common.ts @@ -117,16 +117,23 @@ export enum VCXCode { UNIMPLEMENTED_FEATURE = 1117, LEDGER_ITEM_NOT_FOUND = 1118, } +export enum MediatedConnectionStateType { + Initial = 0, + Invited = 1, + Responded = 3, + Requested = 2, + Finished = 4, +} + export enum ConnectionStateType { Initial = 0, Invited = 1, Requested = 2, - Responded = 3, Finished = 4, } export enum HolderStateType { - Initial= 0, + Initial = 0, ProposalSent = 1, OfferReceived = 2, RequestSent = 3, @@ -162,7 +169,7 @@ export enum VerifierStateType { PresentationProposalReceived = 2, PresentationRequestSent = 3, Finished = 4, - Failed = 5 + Failed = 5, } export interface ISerializedData { diff --git a/wrappers/node/src/api/mediated-connection.ts b/wrappers/node/src/api/mediated-connection.ts index a9d3097676..ab6857667d 100644 --- a/wrappers/node/src/api/mediated-connection.ts +++ b/wrappers/node/src/api/mediated-connection.ts @@ -1,6 +1,6 @@ import * as ffiNapi from '@hyperledger/vcx-napi-rs'; import { VCXInternalError } from '../errors'; -import { ISerializedData, ConnectionStateType } from './common'; +import { ISerializedData, MediatedConnectionStateType } from './common'; import { VcxBaseWithState } from './vcx-base-with-state'; import { IPwInfo } from './utils'; @@ -14,7 +14,7 @@ export interface IConnectionData { endpoint: string; uuid: string; wallet: string; - state: ConnectionStateType; + state: MediatedConnectionStateType; } /** @@ -122,7 +122,7 @@ export function generatePublicInvite(public_did: string, label: string): string } } -export class Connection extends VcxBaseWithState { +export class Connection extends VcxBaseWithState { public static async create({ id }: IConnectionCreateData): Promise { try { const connection = new Connection(); diff --git a/wrappers/node/test/suite1/ariesvcx-connection.test.ts b/wrappers/node/test/suite1/ariesvcx-connection.test.ts index 89f7e7f0ee..bb78907e48 100644 --- a/wrappers/node/test/suite1/ariesvcx-connection.test.ts +++ b/wrappers/node/test/suite1/ariesvcx-connection.test.ts @@ -2,7 +2,7 @@ import '../module-resolver-helper'; import { assert, expect } from 'chai'; import { initVcxTestMode } from 'helpers/utils'; -import { ConnectionStateType } from 'src'; +import {ConnectionStateType } from 'src'; import { NonmediatedConnection } from 'src'; describe('Nonmediated connection:', () => { diff --git a/wrappers/node/test/suite1/ariesvcx-mediated-connection.test.ts b/wrappers/node/test/suite1/ariesvcx-mediated-connection.test.ts index d4a70c3d9a..6658a12b9e 100644 --- a/wrappers/node/test/suite1/ariesvcx-mediated-connection.test.ts +++ b/wrappers/node/test/suite1/ariesvcx-mediated-connection.test.ts @@ -9,8 +9,8 @@ import { dataConnectionCreate, } from 'helpers/entities'; import { initVcxTestMode, shouldThrow } from 'helpers/utils'; -import { Connection, ConnectionStateType, VCXCode } from 'src'; -import { ARIES_PING, ARIES_PING_RESPONSE, ARIES_UNKNOWN_TYPE } from '../helpers/mockdata'; +import { Connection, MediatedConnectionStateType, VCXCode } from 'src'; +import { ARIES_PING, ARIES_PING_RESPONSE } from '../helpers/mockdata'; describe('Connection:', () => { before(() => initVcxTestMode()); @@ -123,15 +123,15 @@ describe('Connection:', () => { assert.isNotNull(caught_error); }); - it(`returns ${ConnectionStateType.Initial}: not connected`, async () => { + it(`returns ${MediatedConnectionStateType.Initial}: not connected`, async () => { const connection = await connectionCreateInviterNull({ id: 'alice' }); await connection.updateState(); - assert.equal(await connection.getState(), ConnectionStateType.Initial); + assert.equal(await connection.getState(), MediatedConnectionStateType.Initial); }); - it(`returns ${ConnectionStateType.Finished}: mocked accepted`, async () => { + it(`returns ${MediatedConnectionStateType.Finished}: mocked accepted`, async () => { const connection = await createConnectionInviterFinished(); - assert.equal(await connection.getState(), ConnectionStateType.Finished); + assert.equal(await connection.getState(), MediatedConnectionStateType.Finished); }); });