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 public agent #715

Merged
merged 9 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 0 additions & 9 deletions agents/node/vcxagent-core/src/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ 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 { createServicePublicAgents } = require('./services/service-public-agents')
const { createServiceOutOfBand } = require('./services/service-out-of-band')
const { createServiceLedgerRevocationRegistry } = require('./services/service-revocation-registry')
const { provisionAgentInAgency } = require('./utils/vcx-workflows')
Expand Down Expand Up @@ -130,11 +129,6 @@ async function createVcxAgent ({ agentName, genesisPath, agencyUrl, seed, wallet
loadProof: storageService.loadProof,
listProofIds: storageService.listProofKeys
})
const servicePublicAgents = createServicePublicAgents({
logger,
saveAgent: storageService.saveAgent,
loadAgent: storageService.loadAgent
})
const serviceOutOfBand = createServiceOutOfBand({
logger,
saveConnection: storageService.saveConnection,
Expand Down Expand Up @@ -165,9 +159,6 @@ async function createVcxAgent ({ agentName, genesisPath, agencyUrl, seed, wallet
serviceProver,
serviceVerifier,

// agents
servicePublicAgents,

// out of band
serviceOutOfBand
}
Expand Down
7 changes: 0 additions & 7 deletions agents/node/vcxagent-core/src/services/service-out-of-band.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ module.exports.createServiceOutOfBand = function createServiceOutOfBand ({ logge
return oob
}

async function createOobMessageWithService (message, label, service) {
const oobSender = await _createOobSender(message, label)
await oobSender.appendService(service)
return await oobSender.toMessage()
}

async function createOobMessageWithDid (message, label, publicDid) {
const oobSender = await _createOobSender(message, label)
await oobSender.appendServiceDid(publicDid)
Expand Down Expand Up @@ -58,7 +52,6 @@ module.exports.createServiceOutOfBand = function createServiceOutOfBand ({ logge
}

return {
createOobMessageWithService,
createOobMessageWithDid,
createConnectionFromOobMsg,
connectionExists,
Expand Down
24 changes: 0 additions & 24 deletions agents/node/vcxagent-core/src/services/service-public-agents.js

This file was deleted.

18 changes: 0 additions & 18 deletions agents/node/vcxagent-core/src/storage/storage-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const {
Schema,
DisclosedProof,
Proof,
PublicAgent
} = require('@hyperledger/node-vcx-wrapper')

async function createStorageService (agentName) {
Expand All @@ -28,7 +27,6 @@ async function createStorageService (agentName) {
const storageCredentialDefinitons = await createFileStorage(`storage-credentialDefinitions/${agentName}`)
const storageRevocationRegistries = await createFileStorage(`storage-revocationRegistries/${agentName}`)
const storageSchemas = await createFileStorage(`storage-schemas/${agentName}`)
const storageAgents = await createFileStorage(`storage-agents/${agentName}`)

async function agentProvisionExists () {
return storageAgentProvisions.hasKey('agent-provision')
Expand Down Expand Up @@ -146,19 +144,6 @@ async function createStorageService (agentName) {
return Proof.deserialize(serialized)
}

async function saveAgent (name, agent) {
const serialized = await agent.serialize()
await storageAgents.set(name, serialized)
}

async function loadAgent (name) {
const serialized = await storageAgents.get(name)
if (!serialized) {
throw Error(`PublicAgent ${name} was not found.`)
}
return PublicAgent.deserialize(serialized)
}

async function listConnectionKeys () {
return storageConnections.keys()
}
Expand Down Expand Up @@ -220,9 +205,6 @@ async function createStorageService (agentName) {
saveProof,
loadProof,

saveAgent,
loadAgent,

listConnectionKeys,
listSchemaKeys,
listCredentialDefinitionKeys,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('test connecting via unmediated endpoint', () => {
it('Establish connection via public nonmediated endpoint, exchange messages', async () => {
let server
try {
const port = 5421
const port = 5422
const path = '/msg'
const endpoint = `http://127.0.0.1:${port}${path}`

Expand Down
12 changes: 4 additions & 8 deletions agents/node/vcxagent-core/test/out-of-band.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@ beforeAll(async () => {
})

describe('test out of band communication', () => {
it('Faber establishes connection with Alice via service OOB message ', async () => {
await createPairedAliceAndFaberViaOobMsg(false)
})

it('Faber establishes connection with Alice via DID OOB message ', async () => {
await createPairedAliceAndFaberViaOobMsg(true)
it('Faber establishes connection with Alice via DID OOB message', async () => {
await createPairedAliceAndFaberViaOobMsg()
})

it('Faber establishes connection with Alice via OOB message and they exchange messages', async () => {
const { alice, faber } = await createPairedAliceAndFaberViaOobMsg(true)
const { alice, faber } = await createPairedAliceAndFaberViaOobMsg()

await alice.sendMessage('Hello Faber')
const msgsFaber = await faber.downloadReceivedMessagesV2()
Expand All @@ -46,7 +42,7 @@ describe('test out of band communication', () => {
})

it('Alice reuses a connection already established by Faber', async () => {
const { alice, faber } = await createPairedAliceAndFaberViaOobMsg(true)
const { alice, faber } = await createPairedAliceAndFaberViaOobMsg()
const msg = await faber.createOobMessageWithDid()
const reused = await alice.createOrReuseConnectionUsingOobMsg(msg)
expect(reused).toBe(true)
Expand Down
46 changes: 7 additions & 39 deletions agents/node/vcxagent-core/test/utils/faber.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ module.exports.createFaber = async function createFaber () {
const vcxAgent = await createVcxAgent(faberAgentConfig)
const institutionDid = vcxAgent.getInstitutionDid()
await vcxAgent.agentInitVcx()
const agent = await vcxAgent.servicePublicAgents.publicAgentCreate(agentId, institutionDid)
await vcxAgent.agentShutdownVcx()

async function createInvite () {
Expand All @@ -49,10 +48,8 @@ module.exports.createFaber = async function createFaber () {
await vcxAgent.agentInitVcx()

const institutionDid = vcxAgent.getInstitutionDid()
logger.info(`Faber creating public agent ${agentId}`)
await vcxAgent.servicePublicAgents.publicAgentCreate(agentId, institutionDid)
logger.info(`Faber creating public invitation for did ${institutionDid}`)
const publicInvitation = await generatePublicInvite(institutionDid, 'Faber')
const publicInvitation = generatePublicInvite(institutionDid, 'Faber')
logger.info(`Faber generated public invite:\n${publicInvitation}`)

await vcxAgent.agentShutdownVcx()
Expand Down Expand Up @@ -96,18 +93,6 @@ module.exports.createFaber = async function createFaber () {
return { message, senderVerkey }
}

async function createOobMessageWithService (wrappedMessage) {
logger.info('Faber is going to generate out of band message')
await vcxAgent.agentInitVcx()

const service = await agent.getService()
const oobMsg = await vcxAgent.serviceOutOfBand.createOobMessageWithService(wrappedMessage, 'faber-oob-msg', service)

await vcxAgent.agentShutdownVcx()

return oobMsg
}

async function createOobMessageWithDid (wrappedMessage) {
logger.info('Faber is going to generate out of band message')
await vcxAgent.agentInitVcx()
Expand All @@ -120,19 +105,15 @@ module.exports.createFaber = async function createFaber () {
return oobMsg
}

async function createOobCredOffer (usePublicDid = true) {
async function createOobCredOffer () {
await vcxAgent.agentInitVcx()
const schemaAttrs = getAliceSchemaAttrs()
const credOfferMsg = await vcxAgent.serviceCredIssuer.buildOfferAndMarkAsSent(issuerCredId, credDefId, revRegId, schemaAttrs)
await vcxAgent.agentShutdownVcx()
if (usePublicDid) {
return await createOobMessageWithDid(credOfferMsg)
} else {
return await createOobMessageWithService(credOfferMsg)
}
return await createOobMessageWithDid(credOfferMsg)
}

async function createOobProofRequest (usePublicDid = true) {
async function createOobProofRequest () {
await vcxAgent.agentInitVcx()

const issuerDid = vcxAgent.getInstitutionDid()
Expand All @@ -141,11 +122,7 @@ module.exports.createFaber = async function createFaber () {
const presentationRequestMsg = await vcxAgent.serviceVerifier.buildProofReqAndMarkAsSent(proofId, proofData)

await vcxAgent.agentShutdownVcx()
if (usePublicDid) {
return await createOobMessageWithDid(presentationRequestMsg)
} else {
return await createOobMessageWithService(presentationRequestMsg)
}
return await createOobMessageWithDid(presentationRequestMsg)
}

async function sendConnectionResponse () {
Expand Down Expand Up @@ -290,19 +267,11 @@ module.exports.createFaber = async function createFaber () {
return agencyMessages
}

async function _downloadConnectionRequests () {
logger.info('Faber is going to download connection requests')
const connectionRequests = await vcxAgent.servicePublicAgents.downloadConnectionRequests(agentId)
logger.info(`Downloaded connection requests: ${connectionRequests}`)
return JSON.parse(connectionRequests)
}

async function createConnectionFromReceivedRequest () {
async function createConnectionFromReceivedRequest (request) {
logger.info('Faber is going to download connection requests')
await vcxAgent.agentInitVcx()

const requests = await _downloadConnectionRequests()
await vcxAgent.serviceConnections.inviterConnectionCreateFromRequest(connectionId, agentId, JSON.stringify(requests[0]))
await vcxAgent.serviceConnections.inviterConnectionCreateFromRequest(connectionId, agentId, JSON.stringify(request))
expect(await vcxAgent.serviceConnections.connectionUpdate(connectionId)).toBe(ConnectionStateType.Responded)

await vcxAgent.agentShutdownVcx()
Expand Down Expand Up @@ -382,7 +351,6 @@ module.exports.createFaber = async function createFaber () {
createInvite,
createPublicInvite,
createOobMessageWithDid,
createOobMessageWithService,
createOobProofRequest,
createConnectionFromReceivedRequest,
createConnectionFromReceivedRequestV2,
Expand Down
111 changes: 83 additions & 28 deletions agents/node/vcxagent-core/test/utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
const bodyParser = require('body-parser')
const sleep = require('sleep-promise')
const express = require('express')
const { createFaber } = require('./faber')
const { createAlice } = require('./alice')
const { ConnectionStateType } = require('@hyperledger/node-vcx-wrapper')

module.exports.createAliceAndFaber = async function createAliceAndFaber () {
module.exports.createAliceAndFaber = async function createAliceAndFaber() {
const alice = await createAlice()
const faber = await createFaber()
return { alice, faber }
}

module.exports.createPairedAliceAndFaber = async function createPairedAliceAndFaber () {
module.exports.createPairedAliceAndFaber = async function createPairedAliceAndFaber() {
const alice = await createAlice()
const faber = await createFaber()
const invite = await faber.createInvite()
Expand All @@ -19,34 +22,86 @@ module.exports.createPairedAliceAndFaber = async function createPairedAliceAndFa
return { alice, faber }
}

module.exports.createPairedAliceAndFaberViaPublicInvite = async function createPairedAliceAndFaberViaPublicInvite () {
const alice = await createAlice()
const faber = await createFaber()
const invite = await faber.createPublicInvite()
await alice.acceptInvite(invite)
await faber.createConnectionFromReceivedRequest()
await alice.updateConnection(ConnectionStateType.Finished)
await faber.updateConnection(ConnectionStateType.Finished)
return { alice, faber }
async function executeFunctionWithServer(f1, f2) {
let server
try {
const port = 5419
const path = '/msg'
const endpoint = `http://127.0.0.1:${port}${path}`

let encryptedMsg
const app = express()
app.use(bodyParser.raw({ type: '*/*' }))
app.post(path, (req, res) => {
encryptedMsg = req.body
res.status(200).send()
})
server = app.listen(port)

const { alice, faber, pwInfo } = await f1(endpoint)
const { message } = await faber.unpackMsg(encryptedMsg)
return await f2(alice, faber, pwInfo, message)
} catch (err) {
console.error(`err = ${err.message} stack = ${err.stack}`)
await sleep(2000)
throw Error(err)
} finally {
if (server) {
server.close()
await sleep(3000)
}
}
}

module.exports.createPairedAliceAndFaberViaOobMsg = async function createPairedAliceAndFaberViaOobMsg (usePublicDid) {
const alice = await createAlice()
const faber = await createFaber()
const msg = (usePublicDid) ? await faber.createOobMessageWithDid() : await faber.createOobMessageWithService()
await alice.createConnectionUsingOobMessage(msg)
await alice.updateConnection(ConnectionStateType.Requested)
await faber.createConnectionFromReceivedRequest()
await alice.updateConnection(ConnectionStateType.Finished)
await faber.updateConnection(ConnectionStateType.Finished)
return { alice, faber }
module.exports.createPairedAliceAndFaberViaPublicInvite = async function createPairedAliceAndFaberViaPublicInvite() {
const f1 = async (endpoint) => {
const alice = await createAlice()
const faber = await createFaber()
const pwInfo = await faber.publishService(endpoint)
const invite = await faber.createPublicInvite()
await alice.acceptInvite(invite)
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)
return { alice, faber }
}
return await executeFunctionWithServer(f1, f2)
}

module.exports.connectViaOobMessage = async function connectViaOobMessage (alice, faber, msg) {
await alice.createConnectionUsingOobMessage(msg)
await alice.updateConnection(ConnectionStateType.Requested)
await faber.createConnectionFromReceivedRequest()
await alice.updateConnection(ConnectionStateType.Finished)
await faber.updateConnection(ConnectionStateType.Finished)
return { alice, faber }
module.exports.createPairedAliceAndFaberViaOobMsg = async function createPairedAliceAndFaberViaOobMsg() {
const f1 = async (endpoint) => {
const alice = await createAlice()
const faber = await createFaber()
const pwInfo = await faber.publishService(endpoint)
const msg = await faber.createOobMessageWithDid()
await alice.createConnectionUsingOobMessage(msg)
await alice.updateConnection(ConnectionStateType.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)
return { alice, faber }
}
return await executeFunctionWithServer(f1, f2)
}

module.exports.connectViaOobMessage = async function connectViaOobMessage(alice, faber, msg) {
const f1 = async (endpoint) => {
const pwInfo = await faber.publishService(endpoint)
await alice.createConnectionUsingOobMessage(msg)
await alice.updateConnection(ConnectionStateType.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)
return { alice, faber }
}
return await executeFunctionWithServer(f1, f2)
}
Loading