import * as Domain from "../domain"; import { AgentOptions, EventCallback, InvitationType, ListenerKey } from "./types"; import { AgentBackup } from "./Agent.Backup"; import { ConnectionsManager } from "./connections/ConnectionsManager"; import { Task } from "../utils/tasks"; import { Startable } from "../domain/protocols/Startable"; import { PluginManager } from "../plugins"; import { EventsManager } from "./Agent.MessageEvents"; import { JobManager } from "./connections/JobManager"; import { RequestPresentation } from "../plugins/internal/oea/protocols/RequestPresentation"; import { Presentation } from "../plugins/internal/oea/protocols/Presentation"; import * as DIDComm from "../plugins/internal/didcomm"; /** * Edge agent implementation * * @export * @class Agent * @typedef {Agent} */ export default class Agent extends Startable.Controller { readonly apollo: Domain.Apollo; readonly castor: Domain.Castor; readonly pluto: Domain.Pluto; readonly mercury: Domain.Mercury; readonly seed: Domain.Seed; readonly api: Domain.Api; private readonly options?; backup: AgentBackup; readonly connections: ConnectionsManager; readonly events: EventsManager; readonly jobs: JobManager; readonly plugins: PluginManager; /** * Creates an instance of Agent. * * @constructor */ constructor(apollo: Domain.Apollo, castor: Domain.Castor, pluto: Domain.Pluto, mercury: Domain.Mercury, seed?: Domain.Seed, api?: Domain.Api, options?: AgentOptions | undefined); /** * Convenience initializer for Agent * allowing default instantiation, omitting all but the absolute necessary parameters * * @param {Object} params - dependencies object * @param {DID | string} params.mediatorDID - did of the mediator to be used * @param {Pluto} params.pluto - storage implementation * @param {Api} [params.api] * @param {Apollo} [params.apollo] * @param {Castor} [params.castor] * @param {Mercury} [params.mercury] * @param {Seed} [params.seed] * @returns {Agent} */ static initialize(params: { pluto: Domain.Pluto; mediatorDID?: Domain.DID | string; api?: Domain.Api; apollo?: Domain.Apollo; castor?: Domain.Castor; mercury?: Domain.Mercury; seed?: Domain.Seed; options?: AgentOptions; }): Agent; /** * Asyncronously start the agent * * @async * @returns {Promise} */ protected _start(): Promise; protected _stop(): Promise; /** * Add an event listener to get notified from an Event "MESSAGE" * * @param {ListenerKey} eventName * @param {EventCallback} callback */ addListener(eventName: T, callback: EventCallback): number; /** * Remove event listener, used by stop procedure * @date 20/06/2023 - 14:31:30 * * @param {ListenerKey} eventName * @param {EventCallback} callback */ removeListener(eventName: T, callback: EventCallback): void; /** * @deprecated * * Get current mediator DID if available or null * * @public * @readonly * @type {DID} */ get currentMediatorDID(): Domain.DID | undefined; /** * run the given Task * * @param task * @returns */ runTask(task: Task): Promise; /** * Asyncronously create a new PrismDID * * @async * @param {string} alias * @param {DIDDocumentService[]} [services=[]] * @param {?number} [keyPathIndex] * @returns {Promise} */ createNewPrismDID(alias: string, services?: Domain.DIDDocument.Service[], keyPathIndex?: number): Promise; /** * Asyncronously Create a new PeerDID * * @async * @param {DIDDocumentService[]} [services=[]] * @param {boolean} [updateMediator=true] * @returns {Promise} */ createNewPeerDID(services?: Domain.DIDDocument.Service[], updateMediator?: boolean): Promise; /** * Asyncronously sign a message with a DID * * @async * @param {DID} did * @param {Uint8Array} message * @returns {Promise} */ signWith(did: Domain.DID, message: Uint8Array): Promise; /** * Asyncronously parse an invitation from a valid json string * * @async * @param {string} str * @returns {Promise} */ parseInvitation(str: string): Promise; /** * Handle an invitation based on it's type * * - `PrismOnboardingInvitation`: creates a new connection * - `OutOfBandInvitation`: * - no Attachment: creates a new connection * - with Attachment: stores / emits the attached message * * @async * @param {InvitationType} invitation - an OOB or PrismOnboarding invitation * @returns {Promise} */ acceptInvitation(invitation: InvitationType, optionalAlias?: string): Promise; /** * Asyncronously parse a prismOnboarding invitation from a string * * @async * @param {string} str * @returns {Promise} */ parsePrismInvitation(str: string): Promise; /** * Asyncronously accept an onboarding invitation, used to onboard the current DID in the Cloud Agent. * * @async * @param {PrismOnboardingInvitation} invitation * @returns {Promise} */ private acceptPrismOnboardingInvitation; /** * Asyncronously parse an out of band invitation from a URI as the oob come in format of valid URL * * @async * @param {URL} url * @returns {Promise} */ parseOOBInvitation(url: URL): Promise; /** * Asyncronously accept a didcomm v2 invitation, will create a pair between the Agent * its connecting with and the current owner's did * * @deprecated - use `acceptInvitation` * @async * @param {OutOfBandInvitation} invitation * @returns {*} */ acceptDIDCommInvitation(invitation: DIDComm.OutOfBandInvitation, alias?: string): Promise; /** * Start the fetch messages long running job * * sends a PickupRequest to all mediator connections * * @param {number} iterationPeriod */ startFetchingMessages(period?: number): Promise; /** * Stop the fetch message long running job */ stopFetchingMessages(): void; /** * Asyncronously send a didcomm Message * * @deprecated use `send` instead * @param {Message} message * @returns {Promise} */ sendMessage(message: Domain.Message | Domain.ApiRequest): Promise; /** * Handle sending a Protocol * * @param {Message} message * @returns {Promise} */ send(message: Domain.ApiRequest): Promise; send(message: Domain.Message): Promise; /** * Find and execute a task registered for the given Message.piuri * * @param message * @returns */ handle(message: Domain.Message): Promise; /** * * @param credential * @returns */ isCredentialRevoked(credential: Domain.Credential): Promise; /** * @deprecated * * This method can be used by holders in order to disclose the value of a Credential * JWT are just encoded plainText * Anoncreds will really need to be disclosed as the fields are encoded. * * @param {Credential} credential * @returns {AttributeType} */ revealCredentialFields(credential: Domain.Credential, fields: string[], linkSecret: string): Promise<{}>; /** * Asyncronously get all verifiable credentials * * @returns {Promise} */ verifiableCredentials(): Promise; /** * Asyncronously prepare a request credential message from a valid offerCredential for now supporting w3c verifiable credentials offers. * * @async * @param {OfferCredential} offer * @returns {Promise} */ prepareRequestCredentialWithIssuer(offer: DIDComm.OfferCredential): Promise; /** * Extract the verifiableCredential object from the Issue credential message asyncronously * * @async * @param {IssueCredential} message * @returns {Promise} */ processIssuedCredentialMessage(issueCredential: DIDComm.IssueCredential): Promise; /** * Asyncronously create a verifiablePresentation from a valid stored verifiableCredential * This is used when the verified requests a specific verifiable credential, this will create the actual * instance of the presentation which we can share with the verifier. * * @async * @param {RequestPresentation} request * @param {VerifiableCredential} credential * @returns {Promise} */ createPresentationForRequestProof(request: RequestPresentation, credential: Domain.Credential): Promise; /** * Initiate a PresentationRequest from the SDK, to create oob Verification Requests * @param {Domain.CredentialType} type * @param {Domain.DID} toDID * @param {ProofTypes[]} proofTypes[] * @returns * * 1. Example use-case: Send a Presentation Request for a JWT credential issued by a specific issuer * ```ts * agent.initiatePresentationRequest( * Domain.CredentialType.JWT, * toDID, * { issuer: Domain.DID.fromString("did:peer:12345"), claims: {}} * ); * ``` * * 2. Example use-case: Send a Presentation Request for a JWT credential issued by a specific issuer and specific claims * ```ts * agent.initiatePresentationRequest( * Domain.CredentialType.JWT, * toDID, * { issuer: Domain.DID.fromString("did:peer:12345"), claims: {email: {type: 'string', pattern:'email@email.com'}}} * ); * ``` */ initiatePresentationRequest(type: T, toDID: Domain.DID, presentationClaims: Domain.PresentationClaims): Promise; /** * Initiate the Presentation and presentationSubmission * @param presentation */ handlePresentation(presentation: Presentation): Promise; }