Skip to content

Commit

Permalink
Remove msg-sending IO from Connection protocol (#937)
Browse files Browse the repository at this point in the history
* Remove msg-sending IO from Connection protocol (#937)

Signed-off-by: Patrik Stas <[email protected]>
  • Loading branch information
Patrik-Stas authored Aug 31, 2023
1 parent 313db9f commit 1990fbc
Show file tree
Hide file tree
Showing 25 changed files with 112 additions and 263 deletions.
6 changes: 3 additions & 3 deletions agents/node/vcxagent-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion agents/node/vcxagent-core/src/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
8 changes: 4 additions & 4 deletions agents/node/vcxagent-core/test/utils/faber.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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()
}
Expand All @@ -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()
}
Expand All @@ -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()
}
Expand Down
20 changes: 10 additions & 10 deletions agents/node/vcxagent-core/test/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } = {}) {
Expand All @@ -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 }
}

Expand Down Expand Up @@ -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 }
}
Expand All @@ -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 }
}
Expand All @@ -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)
Expand Down
20 changes: 9 additions & 11 deletions agents/rust/aries-vcx-agent/src/services/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down Expand Up @@ -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())?;
Expand All @@ -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())?;

Expand Down
6 changes: 0 additions & 6 deletions aries_vcx/src/protocols/connection/generic/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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 ----------------------------
Expand All @@ -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);
Loading

0 comments on commit 1990fbc

Please sign in to comment.