Agent<Extras>
@hyperledger/identus-sdk v8.0.0
@hyperledger/identus-sdk / overview / Agent
Class: Agent<Extras>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:76
Edge agent implementation
The optional tuple type parameter Extras carries the concrete types of
any extra DID methods passed to Agent.initialize, so that
createDID, publishDID, updateDID and deactivateDID only accept
method names that are actually registered and infer their payload types
directly from the passed DID method instances.
Agent
Extends
Type Parameters
| Type Parameter | Default type |
|---|---|
Extras extends readonly DIDMethodInput[] | readonly [] |
Properties
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
api | readonly | Api | - | - | packages/lib/sdk/src/edge-agent/Agent.ts:91 |
apollo | readonly | Apollo | - | - | packages/lib/sdk/src/edge-agent/Agent.ts:86 |
backup | public | AgentBackup | - | - | packages/lib/sdk/src/edge-agent/Agent.ts:79 |
castor | readonly | Castor<Extras> | - | - | packages/lib/sdk/src/edge-agent/Agent.ts:87 |
connections | readonly | ConnectionsManager | - | - | packages/lib/sdk/src/edge-agent/Agent.ts:80 |
events | readonly | EventsManager | - | - | packages/lib/sdk/src/edge-agent/Agent.ts:81 |
jobs | readonly | JobManager | - | - | packages/lib/sdk/src/edge-agent/Agent.ts:82 |
mercury | readonly | Mercury | - | - | packages/lib/sdk/src/edge-agent/Agent.ts:89 |
plugins | readonly | PluginManager | - | - | packages/lib/sdk/src/edge-agent/Agent.ts:83 |
pluto | readonly | Pluto | - | - | packages/lib/sdk/src/edge-agent/Agent.ts:88 |
seed | readonly | SeedFunction | - | - | packages/lib/sdk/src/edge-agent/Agent.ts:90 |
state | public | State | current status of the entity | Controller.state | packages/shared/domain/build/index.d.ts:2330 |
Accessors
currentMediatorDID
Get Signature
get currentMediatorDID():
DID|undefined
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:223
Deprecated
Get current mediator DID if available or null
Returns
DID | undefined
runtimeContext
Get Signature
get runtimeContext():
AgentContext
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:229
Returns
Methods
acceptDIDCommInvitation()
acceptDIDCommInvitation(
invitation:OutOfBandInvitation,alias?:string):Promise<void>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:520
Asyncronously accept a didcomm v2 invitation, will create a pair between the Agent its connecting with and the current owner's did
Parameters
| Parameter | Type | Description |
|---|---|---|
invitation | OutOfBandInvitation | - |
alias? | string | - |
Returns
Promise<void>
Deprecated
- use
acceptInvitation
acceptInvitation()
acceptInvitation(
invitation:InvitationType,optionalAlias?:string):Promise<void>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:442
Handle an invitation based on it's type
PrismOnboardingInvitation: creates a new connectionOutOfBandInvitation:- no Attachment: creates a new connection
- with Attachment: stores / emits the attached message
Parameters
| Parameter | Type | Description |
|---|---|---|
invitation | InvitationType | an OOB or PrismOnboarding invitation |
optionalAlias? | string | - |
Returns
Promise<void>
addListener()
addListener<
T>(eventName:T,callback:EventCallback<T>):number
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:200
Add an event listener to get notified from an Event "MESSAGE"
Type Parameters
| Type Parameter |
|---|
T extends ListenerKey |
Parameters
| Parameter | Type | Description |
|---|---|---|
eventName | T | - |
callback | EventCallback<T> | - |
Returns
number
createDID()
createDID<
M>(method:M,opts:CreatePayloadOf<MethodMapOf<readonly [PrismDIDMethod,PeerDIDMethod,Extras]>[M]> & {alias?:string; }):Promise<DID>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:306
Create a new DID using the specified method, store it in Pluto, and (for peer DIDs) update the mediator key list.
The method name is statically checked against the DID methods actually
registered on this Agent (the built-in prism / peer plus any
custom ones supplied via Agent.initialize) and the payload
type is inferred directly from the matching DID method instance.
Type Parameters
| Type Parameter | Description |
|---|---|
M extends string | registered DID method name (e.g. "prism", "peer", or a custom method) |
Parameters
| Parameter | Type | Description |
|---|---|---|
method | M | the DID method to use |
opts | CreatePayloadOf<MethodMapOf<readonly [PrismDIDMethod, PeerDIDMethod, Extras]>[M]> & { alias?: string; } | method-specific creation options; may include an optional alias string that is persisted alongside the DID |
Returns
Promise<DID>
the newly created DID
Example
const prismDID = await agent.createDID('prism', {
keys: { MASTER_KEY: masterSK },
alias: 'my-issuer',
});
const peerDID = await agent.createDID('peer', {
keys: {
AUTHENTICATION_KEY: [authSK],
KEY_AGREEMENT_KEY: [agreementSK],
},
});
createPeerDID()
createPeerDID(
services?:Service[],updateMediator?:boolean):Promise<DID>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:397
Asyncronously Create a new PeerDID
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
services? | Service[] | [] | - |
updateMediator? | boolean | true | - |
Returns
Promise<DID>
createPresentationForRequestProof()
createPresentationForRequestProof(
request:RequestPresentation,credential:Credential):Promise<Presentation>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:677
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.
Parameters
| Parameter | Type | Description |
|---|---|---|
request | RequestPresentation | - |
credential | Credential | - |
Returns
Promise<Presentation>
createPrismDID()
createPrismDID(
alias:string,services?:Service[],keyPathIndex?:number):Promise<DID>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:381
Asyncronously create a new PrismDID
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
alias | string | undefined | - |
services? | Service[] | [] | - |
keyPathIndex? | number | undefined | - |
Returns
Promise<DID>
deactivateDID()
deactivateDID<
M>(method:M,opts:DeactivatePayloadOf<MethodMapOf<readonly [PrismDIDMethod,PeerDIDMethod,Extras]>[M]>):Promise<MetadataOf<MethodMapOf<readonly [PrismDIDMethod,PeerDIDMethod,Extras]>[M]>>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:366
Deactivate a DID via its registered method.
The method name and payload are statically checked against the DID methods registered on this Agent.
Type Parameters
| Type Parameter |
|---|
M extends string |
Parameters
| Parameter | Type |
|---|---|
method | M |
opts | DeactivatePayloadOf<MethodMapOf<readonly [PrismDIDMethod, PeerDIDMethod, Extras]>[M]> |
Returns
Promise<MetadataOf<MethodMapOf<readonly [PrismDIDMethod, PeerDIDMethod, Extras]>[M]>>
handle()
handle(
message:Message):Promise<any>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:580
Find and execute a task registered for the given Message.piuri
Parameters
| Parameter | Type | Description |
|---|---|---|
message | Message | - |
Returns
Promise<any>
handlePresentation()
handlePresentation(
presentation:Presentation):Promise<boolean>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:723
Initiate the Presentation and presentationSubmission
Parameters
| Parameter | Type | Description |
|---|---|---|
presentation | Presentation | - |
Returns
Promise<boolean>
initiatePresentationRequest()
initiatePresentationRequest<
T>(type:T,toDID:DID,presentationClaims:PresentationClaims<T>):Promise<RequestPresentation>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:710
Initiate a PresentationRequest from the SDK, to create oob Verification Requests
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends CredentialType | JWT |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | T | - |
toDID | DID | - |
presentationClaims | PresentationClaims<T> | - |
Returns
Promise<RequestPresentation>
- Example use-case: Send a Presentation Request for a JWT credential issued by a specific issuer
agent.initiatePresentationRequest(
Domain.CredentialType.JWT,
toDID,
{ issuer: Domain.DID.fromString("did:peer:12345"), claims: {}}
);
- Example use-case: Send a Presentation Request for a JWT credential issued by a specific issuer and specific claims
agent.initiatePresentationRequest(
Domain.CredentialType.JWT,
toDID,
{ issuer: Domain.DID.fromString("did:peer:12345"), claims: {email: {type: 'string', pattern:'email@email.com'}}}
);
isCredentialRevoked()
isCredentialRevoked(
credential:Credential):Promise<boolean>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:596
Parameters
| Parameter | Type | Description |
|---|---|---|
credential | Credential | - |
Returns
Promise<boolean>
parseInvitation()
parseInvitation(
str:string):Promise<InvitationType>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:425
Asyncronously parse an invitation from a valid json string
Parameters
| Parameter | Type | Description |
|---|---|---|
str | string | - |
Returns
Promise<InvitationType>
parseOOBInvitation()
parseOOBInvitation(
url:URL):Promise<OutOfBandInvitation>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:500
Asyncronously parse an out of band invitation from a URI as the oob come in format of valid URL
Parameters
| Parameter | Type | Description |
|---|---|---|
url | URL | - |
Returns
Promise<OutOfBandInvitation>
parsePrismInvitation()
parsePrismInvitation(
str:string):Promise<PrismOnboardingInvitation>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:461
Asyncronously parse a prismOnboarding invitation from a string
Parameters
| Parameter | Type | Description |
|---|---|---|
str | string | - |
Returns
Promise<PrismOnboardingInvitation>
prepareRequestCredentialWithIssuer()
prepareRequestCredentialWithIssuer(
offer:OfferCredential):Promise<RequestCredential>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:644
Asyncronously prepare a request credential message from a valid offerCredential for now supporting w3c verifiable credentials offers.
Parameters
| Parameter | Type | Description |
|---|---|---|
offer | OfferCredential | - |
Returns
Promise<RequestCredential>
processIssuedCredentialMessage()
processIssuedCredentialMessage(
issueCredential:IssueCredential):Promise<Credential>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:659
Extract the verifiableCredential object from the Issue credential message asyncronously
Parameters
| Parameter | Type | Description |
|---|---|---|
issueCredential | IssueCredential | - |
Returns
Promise<Credential>
publishDID()
publishDID<
M>(method:M,opts:PublishPayloadOf<MethodMapOf<readonly [PrismDIDMethod,PeerDIDMethod,Extras]>[M]>):Promise<MetadataOf<MethodMapOf<readonly [PrismDIDMethod,PeerDIDMethod,Extras]>[M]>>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:340
Publish a DID via its registered method.
The method name and payload are statically checked against the DID methods registered on this Agent; the return type is the metadata type declared by the matching DID method instance.
Type Parameters
| Type Parameter |
|---|
M extends string |
Parameters
| Parameter | Type |
|---|---|
method | M |
opts | PublishPayloadOf<MethodMapOf<readonly [PrismDIDMethod, PeerDIDMethod, Extras]>[M]> |
Returns
Promise<MetadataOf<MethodMapOf<readonly [PrismDIDMethod, PeerDIDMethod, Extras]>[M]>>
removeListener()
removeListener<
T>(eventName:T,callback:EventCallback<T>):void
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:210
Remove event listener, used by stop procedure
Type Parameters
| Type Parameter |
|---|
T extends ListenerKey |
Parameters
| Parameter | Type | Description |
|---|---|---|
eventName | T | - |
callback | EventCallback<T> | - |
Returns
void
revealCredentialFields()
revealCredentialFields(
credential:Credential,fields:string[]):Promise<{ }>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:620
Parameters
| Parameter | Type | Description |
|---|---|---|
credential | Credential | - |
fields | string[] | - |
Returns
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.
runTask()
runTask<
T>(task:Task<T>):Promise<T>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:256
run the given Task
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
task | Task<T> | - |
Returns
Promise<T>
send()
Call Signature
send(
message:ApiRequest):Promise<ApiResponse<unknown> |undefined>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:567
Handle sending a Protocol
Parameters
| Parameter | Type | Description |
|---|---|---|
message | ApiRequest | - |
Returns
Promise<ApiResponse<unknown> | undefined>
Call Signature
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:568
Handle sending a Protocol
Parameters
| Parameter | Type | Description |
|---|---|---|
message | Message | - |
Returns
Promise<Message | undefined>
sendMessage()
sendMessage(
message:Message|ApiRequest):Promise<Message|undefined>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:556
Asyncronously send a didcomm Message
Parameters
| Parameter | Type | Description |
|---|---|---|
message | Message | ApiRequest | - |
Returns
Promise<Message | undefined>
Deprecated
use send instead
signWith()
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:413
Asyncronously sign a message with a DID
Parameters
| Parameter | Type | Description |
|---|---|---|
did | DID | - |
message | Uint8Array | - |
Returns
Promise<Signature>
start()
start():
Promise<State>
Defined in: packages/shared/domain/build/index.d.ts:2347
handle the startup of an entity
updates state according to lifecycle
Returns
Promise<State>
Inherited from
startFetchingMessages()
startFetchingMessages(
period?:number):Promise<void>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:535
Start the fetch messages long running job
sends a PickupRequest to all mediator connections
Parameters
| Parameter | Type | Description |
|---|---|---|
period? | number | - |
Returns
Promise<void>
stop()
stop():
Promise<State>
Defined in: packages/shared/domain/build/index.d.ts:2348
handle the teardown of an entity
updates state according to lifecycle
Returns
Promise<State>
Inherited from
stopFetchingMessages()
stopFetchingMessages():
void
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:544
Stop the fetch message long running job
Returns
void
updateDID()
updateDID<
M>(method:M,opts:UpdatePayloadOf<MethodMapOf<readonly [PrismDIDMethod,PeerDIDMethod,Extras]>[M]>):Promise<MetadataOf<MethodMapOf<readonly [PrismDIDMethod,PeerDIDMethod,Extras]>[M]>>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:353
Update a DID via its registered method.
The method name and payload are statically checked against the DID methods registered on this Agent.
Type Parameters
| Type Parameter |
|---|
M extends string |
Parameters
| Parameter | Type |
|---|---|
method | M |
opts | UpdatePayloadOf<MethodMapOf<readonly [PrismDIDMethod, PeerDIDMethod, Extras]>[M]> |
Returns
Promise<MetadataOf<MethodMapOf<readonly [PrismDIDMethod, PeerDIDMethod, Extras]>[M]>>
verifiableCredentials()
verifiableCredentials():
Promise<Credential[]>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:633
Asyncronously get all verifiable credentials
Returns
Promise<Credential[]>
initialize()
staticinitialize<ExtraMethods>(params: {api?:Api;apollo?:Apollo;castor?:Castor<ExtraMethods>;didMethods?:ExtraMethods;mediatorDID?:string|DID;mercury?:Mercury;options?:AgentOptions;pluto:Pluto;seed?:SeedFunction; }):Agent<ExtraMethods>
Defined in: packages/lib/sdk/src/edge-agent/Agent.ts:127
Convenience initializer for Agent allowing default instantiation, omitting all but the absolute necessary parameters.
DID methods registered through the top-level didMethods param are
propagated through to the Agent's type parameter, so agent.createDID
and friends are fully typed against them (defaults "prism" | "peer"
plus any extras).
Type Parameters
| Type Parameter | Default type |
|---|---|
ExtraMethods extends readonly DIDMethodInput[] | readonly [] |
Parameters
| Parameter | Type | Description |
|---|---|---|
params | { api?: Api; apollo?: Apollo; castor?: Castor<ExtraMethods>; didMethods?: ExtraMethods; mediatorDID?: string | DID; mercury?: Mercury; options?: AgentOptions; pluto: Pluto; seed?: SeedFunction; } | dependencies object |
params.api? | Api | - |
params.apollo? | Apollo | - |
params.castor? | Castor<ExtraMethods> | - |
params.didMethods? | ExtraMethods | custom DID methods to register alongside the built-in prism/peer methods |
params.mediatorDID? | string | DID | did of the mediator to be used |
params.mercury? | Mercury | - |
params.options? | AgentOptions | - |
params.pluto | Pluto | storage implementation |
params.seed? | SeedFunction | - |
Returns
Agent<ExtraMethods>