Skip to content

Commit

Permalink
feat: add waiting state (#78)
Browse files Browse the repository at this point in the history
Co-authored-by: Ariel Gentile <gentilester@gmail.com>
  • Loading branch information
lotharking and genaris authored Feb 10, 2025
1 parent 4a55200 commit 3b69e6b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/service-agent-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ When the presentation flow is completed (either successfully or not), Service Ag
Possible values for PresentationStatus are:

- 'ok'
- 'connected'
- 'refused'
- 'no-compatible-credentials'
- 'verification-error'
Expand Down
1 change: 1 addition & 0 deletions packages/main/src/events/CallbackEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TsLogger } from '../utils/logger'

export enum PresentationStatus {
OK = 'ok',
CONNECTED = 'connected',
REFUSED = 'refused',
NO_COMPATIBLE_CREDENTIALS = 'no-compatible-credentials',
VERIFICATION_ERROR = 'verification-error',
Expand Down
28 changes: 28 additions & 0 deletions packages/main/src/events/ConnectionEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {

import { ServiceAgent } from '../utils/ServiceAgent'

import { PresentationStatus, sendPresentationCallbackEvent } from './CallbackEvent'
import { sendWebhookEvent } from './WebhookEvent'

export const connectionEvents = async (agent: ServiceAgent, config: ServerConfig) => {
Expand Down Expand Up @@ -46,6 +47,33 @@ export const connectionEvents = async (agent: ServiceAgent, config: ServerConfig
})
}

// If an out-of-band ID exists, use the invitation to find the thread IDs
// and identify the invitation that created the connection to update its state.
if (record.outOfBandId) {
const invitationRecord = await agent.oob.findById(record.outOfBandId)
const threadIds = invitationRecord?.getTag('invitationRequestsThreadIds') as string[] | undefined
threadIds?.map(async threadId => {
const proofRecord = await agent.proofs.getByThreadAndConnectionId(threadId)
const callbackParameters = proofRecord.metadata.get('_2060/callbackParameters') as
| { ref?: string; callbackUrl?: string }
| undefined

if (
callbackParameters &&
callbackParameters.callbackUrl &&
record.state === DidExchangeState.RequestReceived
) {
await sendPresentationCallbackEvent({
proofExchangeId: proofRecord.id,
callbackUrl: callbackParameters.callbackUrl,
status: PresentationStatus.CONNECTED,
logger: config.logger,
ref: callbackParameters.ref,
})
}
})
}

// If discovery is enabled, send an empty 'completed' state so that the recipient knows to expect async features.
const body = new ConnectionStateUpdated({
connectionId: record.id,
Expand Down

0 comments on commit 3b69e6b

Please sign in to comment.