import type { AgentContext } from '../../../agent'; import type { AgentMessage } from '../../../agent/AgentMessage'; import type { InboundMessageContext } from '../../../agent/models/InboundMessageContext'; import type { Query } from '../../../storage/StorageService'; import type { AckMessage } from '../../common'; import type { OutOfBandRecord } from '../../oob/repository'; import type { ConnectionProblemReportMessage } from '../messages'; import type { ConnectionType } from '../models'; import type { ConnectionRecordProps } from '../repository/ConnectionRecord'; import { EventEmitter } from '../../../agent/EventEmitter'; import { Key } from '../../../crypto'; import { Logger } from '../../../logger'; import { DidRepository } from '../../dids/repository'; import { ConnectionRequestMessage, ConnectionResponseMessage, TrustPingMessage } from '../messages'; import { DidExchangeRole, DidExchangeState } from '../models'; import { ConnectionRecord } from '../repository/ConnectionRecord'; import { ConnectionRepository } from '../repository/ConnectionRepository'; export interface ConnectionRequestParams { label?: string; imageUrl?: string; alias?: string; routing: Routing; autoAcceptConnection?: boolean; } export declare class ConnectionService { private connectionRepository; private didRepository; private eventEmitter; private logger; constructor(logger: Logger, connectionRepository: ConnectionRepository, didRepository: DidRepository, eventEmitter: EventEmitter); /** * Create a connection request message for a given out-of-band. * * @param outOfBandRecord out-of-band record for which to create a connection request * @param config config for creation of connection request * @returns outbound message containing connection request */ createRequest(agentContext: AgentContext, outOfBandRecord: OutOfBandRecord, config: ConnectionRequestParams): Promise>; processRequest(messageContext: InboundMessageContext, outOfBandRecord: OutOfBandRecord): Promise; /** * Create a connection response message for the connection with the specified connection id. * * @param connectionRecord the connection for which to create a connection response * @returns outbound message containing connection response */ createResponse(agentContext: AgentContext, connectionRecord: ConnectionRecord, outOfBandRecord: OutOfBandRecord, routing?: Routing): Promise>; /** * Process a received connection response message. This will not accept the connection request * or send a connection acknowledgement message. It will only update the existing connection record * with all the new information from the connection response message. Use {@link ConnectionService.createTrustPing} * after calling this function to create a trust ping message. * * @param messageContext the message context containing a connection response message * @returns updated connection record */ processResponse(messageContext: InboundMessageContext, outOfBandRecord: OutOfBandRecord): Promise; /** * Create a trust ping message for the connection with the specified connection id. * * By default a trust ping message should elicit a response. If this is not desired the * `config.responseRequested` property can be set to `false`. * * @param connectionRecord the connection for which to create a trust ping message * @param config the config for the trust ping message * @returns outbound message containing trust ping message */ createTrustPing(agentContext: AgentContext, connectionRecord: ConnectionRecord, config?: { responseRequested?: boolean; comment?: string; }): Promise>; /** * Process a received ack message. This will update the state of the connection * to Completed if this is not already the case. * * @param messageContext the message context containing an ack message * @returns updated connection record */ processAck(messageContext: InboundMessageContext): Promise; /** * Process a received {@link ProblemReportMessage}. * * @param messageContext The message context containing a connection problem report message * @returns connection record associated with the connection problem report message * */ processProblemReport(messageContext: InboundMessageContext): Promise; /** * Assert that an inbound message either has a connection associated with it, * or has everything correctly set up for connection-less exchange (optionally with out of band) * * @param messageContext - the inbound message context */ assertConnectionOrOutOfBandExchange(messageContext: InboundMessageContext, { lastSentMessage, lastReceivedMessage, }?: { lastSentMessage?: AgentMessage | null; lastReceivedMessage?: AgentMessage | null; }): Promise; /** * If knownConnectionId is passed, it will compare the incoming connection id with the knownConnectionId, and skip the other validation. * * If no known connection id is passed, it asserts that the incoming message is in response to an attached request message to an out of band invitation. * If is the case, and the state of the out of band record is still await response, the state will be updated to done * */ matchIncomingMessageToRequestMessageInOutOfBandExchange(messageContext: InboundMessageContext, { expectedConnectionId }: { expectedConnectionId?: string; }): Promise; updateState(agentContext: AgentContext, connectionRecord: ConnectionRecord, newState: DidExchangeState): Promise; private emitStateChangedEvent; update(agentContext: AgentContext, connectionRecord: ConnectionRecord): Promise; /** * Retrieve all connections records * * @returns List containing all connection records */ getAll(agentContext: AgentContext): Promise; /** * Retrieve a connection record by id * * @param connectionId The connection record id * @throws {RecordNotFoundError} If no record is found * @return The connection record * */ getById(agentContext: AgentContext, connectionId: string): Promise; /** * Find a connection record by id * * @param connectionId the connection record id * @returns The connection record or null if not found */ findById(agentContext: AgentContext, connectionId: string): Promise; /** * Delete a connection record by id * * @param connectionId the connection record id */ deleteById(agentContext: AgentContext, connectionId: string): Promise; findByDids(agentContext: AgentContext, query: { ourDid: string; theirDid: string; }): Promise; /** * Retrieve a connection record by thread id * * @param threadId The thread id * @throws {RecordNotFoundError} If no record is found * @throws {RecordDuplicateError} If multiple records are found * @returns The connection record */ getByThreadId(agentContext: AgentContext, threadId: string): Promise; getByRoleAndThreadId(agentContext: AgentContext, role: DidExchangeRole, threadId: string): Promise; findByTheirDid(agentContext: AgentContext, theirDid: string): Promise; findByOurDid(agentContext: AgentContext, ourDid: string): Promise; findAllByOutOfBandId(agentContext: AgentContext, outOfBandId: string): Promise; findAllByConnectionTypes(agentContext: AgentContext, connectionTypes: Array): Promise; findByInvitationDid(agentContext: AgentContext, invitationDid: string): Promise; findByKeys(agentContext: AgentContext, { senderKey, recipientKey }: { senderKey: Key; recipientKey: Key; }): Promise; findAllByQuery(agentContext: AgentContext, query: Query): Promise; createConnection(agentContext: AgentContext, options: ConnectionRecordProps): Promise; addConnectionType(agentContext: AgentContext, connectionRecord: ConnectionRecord, type: string): Promise; removeConnectionType(agentContext: AgentContext, connectionRecord: ConnectionRecord, type: string): Promise; getConnectionTypes(connectionRecord: ConnectionRecord): Promise; private createDid; private createDidDoc; private createDidDocFromOutOfBandDidCommServices; returnWhenIsConnected(agentContext: AgentContext, connectionId: string, timeoutMs?: number): Promise; } export interface Routing { endpoints: string[]; recipientKey: Key; routingKeys: Key[]; mediatorId?: string; } export interface ConnectionProtocolMsgReturnType { message: MessageType; connectionRecord: ConnectionRecord; }