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

Credo Backchannel AIP 2 Support #895

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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: 7 additions & 2 deletions .devcontainer/Credo-ts-container/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [9020],
"forwardPorts": [9020, 9021],

"runArgs": [
"--network=aath_network",
"--name=acme_agent_dev"
"--name=credo_agent_dev"
],

// Use 'postCreateCommand' to run commands after the container is created.
Expand All @@ -52,6 +52,11 @@
add-apt-repository -y \"deb http://security.ubuntu.com/ubuntu bionic-security main\" && \
apt-get install -y --allow-unauthenticated libindy",

// Add environment variables
"containerEnv": {
"RUN_MODE": "docker"
},

// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-harness-acapy-credo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
with:
BUILD_AGENTS: "-a acapy-main -a credo"
TEST_AGENTS: "-d acapy-main -b credo"
TEST_SCOPE: "-t @AcceptanceTest -t @AIP10,@RFC0441,@RFC0211,@T001-RFC0453 -t ~@wip -t ~@DIDExchangeConnection -t ~@T004-RFC0211 -t ~@QualifiedDIDs -t ~@T001-RFC0183"
TEST_SCOPE: "-t @AcceptanceTest -t @AIP10,@RFC0441,@RFC0211,@T001-RFC0453,@RFC0023 -t ~@wip -t ~@T004-RFC0211 -t ~@QualifiedDIDs -t ~@T001-RFC0183"
REPORT_PROJECT: acapy-b-credo
- name: run-send-gen-test-results-secure
if: ${{ steps.run_test_harness.conclusion == 'success' }}
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/test-harness-credo-acapy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ name: test-harness-credo-acapy
# Current
#
# All AIP10 tests are currently running.
# OOB & DID Exchange Tests are running.
#
# *Status Note Updated: 2024.09.06*
# *Status Note Updated: 2024.10.29*
#
# End
on:
Expand Down Expand Up @@ -42,7 +43,7 @@ jobs:
with:
BUILD_AGENTS: "-a credo -a acapy-main"
TEST_AGENTS: "-d credo -b acapy-main"
TEST_SCOPE: "-t @AcceptanceTest -t ~@wip -t @AIP10,@RFC0211,@T001-RFC0453 -t ~@Transport_NoHttpOutbound -t ~@DIDExchangeConnection -t ~@QualifiedDIDs"
TEST_SCOPE: "-t @AcceptanceTest -t ~@wip -t @AIP10,@RFC0211,@T001-RFC0453,@RFC0023 -t ~@Transport_NoHttpOutbound -t ~@QualifiedDIDs"
REPORT_PROJECT: credo-b-acapy
- name: run-send-gen-test-results-secure
if: ${{ steps.run_test_harness.conclusion == 'success' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-harness-credo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
with:
BUILD_AGENTS: "-a credo"
TEST_AGENTS: "-d credo"
TEST_SCOPE: "-t @AcceptanceTest -t ~@wip -t @AIP10,@RFC0211 -t ~@DIDExchangeConnection -t ~@QualifiedDIDs"
TEST_SCOPE: "-t @AcceptanceTest -t ~@wip -t @AIP10,@RFC0211 -t ~@QualifiedDIDs"
REPORT_PROJECT: credo
- name: run-send-gen-test-results-secure
if: ${{ steps.run_test_harness.conclusion == 'success' }}
Expand Down
2 changes: 1 addition & 1 deletion aries-backchannels/credo-ts/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"env": {
"LEDGER_URL": "http://test.bcovrin.vonx.io",
"TAILS_SERVER_URL": "http://tails.bcovrin.vonx.io",
"DOCKERHOST": "acme_agent_dev"
"DOCKERHOST": "credo_agent_dev"
},
"args": [
"ts-node",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ export class AgentStatusController extends BaseController {

@Post('/agent/start')
async restartAgent(@BodyParams('data') data: StartAgentData) {
this.agent.config.logger.debug('stopping agent')
await this.testHarnessConfig.stopAgent()

this.agent.config.logger.debug('restarting agent')
await this.testHarnessConfig.startAgent({
inboundTransports: data.parameters.inbound_transports ?? ['http'],
outboundTransports: data.parameters.outbound_transports ?? ['http'],
})

this.agent.config.logger.debug('agent startup')
await this.testHarnessConfig.agentStartup()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { Controller, Get, PathParams, Post, BodyParams } from '@tsed/common'
import { NotFound } from '@tsed/exceptions'
import {
OutOfBandRecord,
OutOfBandInvitation,
ConnectionInvitationMessage,
ConnectionRecord,
JsonTransformer,
AgentConfig,
OutOfBandEventTypes,
OutOfBandStateChangedEvent,
OutOfBandState,
CredoError,
DidExchangeState,
ReceiveOutOfBandImplicitInvitationConfig,
} from '@credo-ts/core'

import { filter, firstValueFrom, ReplaySubject, tap, timeout } from 'rxjs'
import { BaseController } from '../BaseController'
import { TestHarnessConfig } from '../TestHarnessConfig'
import { ConnectionUtils } from '../utils/ConnectionUtils'

@Controller('/agent/command/did-exchange')
export class DIDExchangeController extends BaseController {
private subject = new ReplaySubject<OutOfBandStateChangedEvent>()

public constructor(testHarnessConfig: TestHarnessConfig) {
super(testHarnessConfig)
}

onStartup = () => {
this.subject = new ReplaySubject<OutOfBandStateChangedEvent>()
// Catch all events in replay subject for later use
this.agent.events
.observable<OutOfBandStateChangedEvent>(OutOfBandEventTypes.OutOfBandStateChanged)
.subscribe(this.subject)
}

@Get('/:id')
async getConnectionById(@PathParams('id') id: string) {
const connection = await ConnectionUtils.getConnectionByConnectionIdOrOutOfBandId(this.agent, id)

if (!connection) throw new NotFound(`Connection with id ${id} not found`)

return connection
}

@Post('/create-request-resolvable-did')
async createRequestResolvableDID(@BodyParams() data: { data: { their_public_did: string } }) {
const { their_public_did } = data.data;

const { outOfBandRecord, connectionRecord } = await this.agent.oob.receiveImplicitInvitation({ did: their_public_did } as ReceiveOutOfBandImplicitInvitationConfig);

// Add the two records to the response and move the state from the connectionRecord to the root of connectionRecords.
const connectionRecords = {
...(connectionRecord && { connectionRecord }),
...(outOfBandRecord && { outOfBandRecord }),
...(connectionRecord && { state: connectionRecord.state }),
...(connectionRecord && { connection_id: connectionRecord.outOfBandId })
}

return connectionRecords
}

// Implementing this method just to satisfy AATH. This will not call credo and just set the state that was set in the previous step of receive invitation.
@Post('/send-request')
async sendRequest(@BodyParams('id') id: string) {
const connection = await ConnectionUtils.getConnectionByConnectionIdOrOutOfBandId(this.agent, id)

if (!connection) {
throw new CredoError('Connection not found')
}

//connection.state = DidExchangeState.RequestSent

return connection
}

// Implementing this method just to satisfy AATH. This will not call credo and just set the state that was set in the previous step of receive invitation.
@Post('/send-response')
//async sendResponse(@BodyParams('id') id: string) {
//async sendResponse(@PathParams('id') id: string, @BodyParams('mediator_connection_id') mediatorConnectionId: string) {
async sendResponse(@BodyParams('id') id: string, @BodyParams('mediator_connection_id') mediatorConnectionId: string) {
//const { mediator_connection_id, ...invitationJson } = data

// If we have a mediator connection id, we need to find the mediator id
if (mediatorConnectionId) {
const id = await this.mediatorIdFromMediatorConnectionId(mediatorConnectionId)
}

const connection = await ConnectionUtils.getConnectionByConnectionIdOrOutOfBandId(this.agent, id)

return connection
}

private async mediatorIdFromMediatorConnectionId(mediatorConnectionId?: string): Promise<string | undefined> {
if (!mediatorConnectionId) return undefined

// Find mediator id if mediator connection id is provided
const mediator = await this.agent.mediationRecipient.findByConnectionId(mediatorConnectionId)

return mediator?.id
}
}

@Controller('/agent/response/did-exchange')
export class DIDExchangeResponseController extends BaseController {
public constructor(testHarnessConfig: TestHarnessConfig) {
super(testHarnessConfig)
}

@Get('/:id')
async getDidExchangeResponse(@PathParams('id') id: string) {
const connection = await ConnectionUtils.getConnectionByConnectionIdOrOutOfBandId(this.agent, id)

if (!connection) throw new NotFound(`Connection with id ${id} not found`)

return connection
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Controller, Get } from '@tsed/common'
import { BaseController } from '../BaseController'
import { TestHarnessConfig } from '../TestHarnessConfig'
import { CredoError } from '@credo-ts/core'

@Controller('/agent/command/did')
export class DidController extends BaseController {
Expand All @@ -10,7 +11,18 @@ export class DidController extends BaseController {

@Get()
async getPublicDid() {
//const publicDidInfoRecord = await this.agent.genericRecords.findById('_INFO')
const publicDidInfoRecord = await this.agent.genericRecords.findById('PUBLIC_DID_INFO')
return publicDidInfoRecord ? publicDidInfoRecord.content.didInfo : {}

if (!publicDidInfoRecord) {
throw new CredoError('Public DID Info Record not found')
}

//return publicDidInfoRecord ? publicDidInfoRecord.content.didInfo : {}
//return (publicDidInfoRecord.content as { 'did-info': { did: string } })['did-info'].did
const content = publicDidInfoRecord.content as { didInfo: { did: string } }
const did = 'did:indy:bcovrin:test:' + content.didInfo.did
//return content.didInfo.did
return did
}
}
}
Loading