Skip to content
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
3 changes: 3 additions & 0 deletions src/cliAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
X509Module,
JwkDidRegistrar,
JwkDidResolver,
PeerDidNumAlgo,
} from '@credo-ts/core'
import {
DidCommHttpOutboundTransport,
Expand Down Expand Up @@ -209,6 +210,8 @@ const getModules = (
basicMessages: true,
connections: {
autoAcceptConnections: autoAcceptConnections || true,
peerNumAlgoForDidExchangeRequests: PeerDidNumAlgo.GenesisDoc,
peerNumAlgoForDidRotation: PeerDidNumAlgo.ShortFormAndLongForm,
},
proofs: {
autoAcceptProofs: autoAcceptProofs || DidCommAutoAcceptProof.ContentApproved,
Expand Down
29 changes: 26 additions & 3 deletions src/events/CredentialEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,44 @@ export const credentialEvents = async (agent: Agent, config: ServerConfig) => {
DidCommCredentialEventTypes.DidCommCredentialStateChanged,
async (event: DidCommCredentialStateChangedEvent) => {
const record = event.payload.credentialExchangeRecord
const tenantId = (!event.metadata.contextCorrelationId || event.metadata.contextCorrelationId === 'default') ? event.metadata.contextCorrelationId : event.metadata.contextCorrelationId.split('tenant-')[1]

const body: Record<string, unknown> = {
...record.toJSON(),
...event.metadata,
contextCorrelationId: tenantId,
outOfBandId: null,
credentialData: null,
}

if (record?.connectionId) {
const connectionRecord = await agent.modules.connections.findById(record.connectionId!)
let connectionRecord
if (tenantId && tenantId !== 'default') {
await (agent as Agent<RestMultiTenantAgentModules>).modules.tenants.withTenantAgent(
{ tenantId: body.contextCorrelationId as string },
async (tenantAgent) => {
connectionRecord = await tenantAgent.modules.didcomm.connections.findById(record.connectionId ? record.connectionId : '')
},
)
} else {
connectionRecord = await agent.modules.didcomm.connections.findById(record.connectionId)
}
body.outOfBandId = connectionRecord?.outOfBandId
Comment thread
GHkrishna marked this conversation as resolved.
}

const data = await agent.modules.credentials.getFormatData(record.id)
body.credentialData = data
let formatData = null
if (tenantId && tenantId !== 'default') {
await (agent as Agent<RestMultiTenantAgentModules>).modules.tenants.withTenantAgent(
{ tenantId: body.contextCorrelationId as string },
async (tenantAgent) => {
formatData = await tenantAgent.modules.didcomm.credentials.getFormatData(record.id)
},
)
} else {
formatData = await agent.modules.didcomm.credentials.getFormatData(record.id)
}

body.credentialData = formatData

if (config.webhookUrl) {
await sendWebhookEvent(config.webhookUrl + '/credentials', body, agent.config.logger)
Expand Down
8 changes: 4 additions & 4 deletions src/events/ProofEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ export const proofEvents = async (agent: Agent, config: ServerConfig) => {
agent.events.on(DidCommProofEventTypes.ProofStateChanged, async (event: DidCommProofStateChangedEvent) => {
const record = event.payload.proofRecord
const body = { ...record.toJSON(), ...event.metadata } as { proofData?: any }
if (event.metadata.contextCorrelationId !== 'default') {
if (event.metadata.contextCorrelationId && event.metadata.contextCorrelationId !== 'default') {
const tenantAgent = await agent.modules.tenants.getTenantAgent({
tenantId: event.metadata.contextCorrelationId,
tenantId: event.metadata.contextCorrelationId.split('tenant-')[1],
})
const data = await tenantAgent.proofs.getFormatData(record.id)
const data = await tenantAgent.modules.didcomm.proofs.getFormatData(record.id)
body.proofData = data
}

//Emit webhook for dedicated agent
if (event.metadata.contextCorrelationId === 'default') {
const data = await agent.modules.proofs.getFormatData(record.id)
const data = await agent.modules.didcomm.proofs.getFormatData(record.id)
body.proofData = data
}

Expand Down