@spherity/aries-rfcs-veramo-plugin
v1.0.0
Published
# Aries RFCs Veramo Plugin
Downloads
3
Keywords
Readme
Documentation Aries Plugin
Aries RFCs Veramo Plugin
A DIDComm MessageHandlerPlugin
plugin for the Veramo agent enabling it to send and handle DIDComm messages using the Hyperledger AriesRFCs
workflows.@spherity/aries-rfcs-veramo-plugin
contain message handlers that are based on aries flows and also contains methods that allow the initiation of those Aries Flows.
Supported Flows
- Did Exchange 0023
- Issue Credential v2 0453
- Present Proof v2 0454
Setup
Install this plugin
npm install --save @spherity/aries-rfcs-veramo-plugin @veramo/message-handler
Add the plugin to your agent
import { MessageHandler } from '@veramo/message-handler'; import { IssueCredential0453MessageHandler, PresentProof0454MessageHandler, DidExchange0023MessageHandler } from 'aries-rfcs-veramo-plugin'; export const veramoAgent = createAgent<VeramoAgent>({ plugins: [ new MessageHandler({ messageHandlers: [ new DIDCommMessageHandler(), new DidExchange0023MessageHandler(trustResolver), new IssueCredential0453MessageHandler( CreateCredentialCallback(), ReceiveCredentialCallback() ), new PresentProof0454MessageHandler( CreatePresentationCallback(), VerifyPresentationCallback() ), ], }), ], });
Usage
MessageHandlers
DidExchange0023MessageHandler
The
DidExchange0023MessageHandler
supports theAries RFC 0023
flows. It allows the user to send and handle messages within that specific protocol, it requires atrustresolver
instance with a method ofcheckTrustStatus
as a parameter.Sample TrustResolver
export class TrustResolver { const trusted = [...] async checkTrustStatus(did: string): Promise<boolean> { try { const trustStatus = trusted.includes(did) return trustStatus } catch (e) { return false; } } }
IssueCredential0453MessageHandler The
IssueCredential0453MessageHandler
supports theAries RFC 0453
flows. It allows the user to send and handle messages within that specific protocol, it requires callback functions, for Creating a Credential and Receiving a Credential. Create Credential Callback The parameters for the callback forcreateCredential
arecredentialData
,issuerDid
,recipientDid
,veramoAgent
. The response from thecreateCredential
callback should be aVeramo CreateVerifiableCredential
Response. Samplepublic async createCredential( credentialData: any, issuerDid: string, recipientDid: string, veramoAgent: VeramoAgent ) { const createdAt = new Date(); const expiresAt = credentialData.expirationDate ? new Date(credentialData.expirationDate) : new Date(createdAt.getTime() + 1000 * 60 * 60 * 24 * 365); const credentialPayload: CredentialPayload = { id: credentialData.credentialId, issuer: issuerDid, '@context': [...], expirationDate: expiresAt.toISOString(), issuanceDate: issuesAt.toISOString(), credentialSubject: { id: recipientDid, ...credentialData.data, }, }; vc = await veramoAgent.createVerifiableCredential( { credential: credentialPayload, proofFormat: 'lds', now: nowOverride, }, { agent: veramoAgent.agent } as any, ); return vc; }
ReceiveCredentialCallback
The parameters for the callback for
receiveCredential
arefromDid
,credential
,message
(contains the credential offer message sent by the issuer to receiver). There is no expected response from thereceiveCredential
.Sample
private async receiveCredential(fromDid: string, credential: any, message: any) { const recipientIdentifier = await identifier.findFirst({ where: { did: fromDid, }, }); if (!recipientIdentifier) { throw new Error(`Identifier with did<${fromDid}> is not found`); } // save credential in the database }
PresentProof0454MessageHandler The
PresentProof0454MessageHandler
supports theAries RFC 0454
flows. It allows the user to send messages within that specific protocol, it requires callback functions for Creating a Presentation and Verifying a Presentation. Create Presentation Callback The parameters for the callback forcreatePresentation
areholderDid
,veramoAgent
,credentialType
. The response from thecreatePresentation
callback can be anything from thepresentation
to thejwt
as long .Sample
private async createPresentation( holderDid: string, credentialType: CredentialType, veramoAgent: VeramoAgent ) { const credential = // retrieve credential from the database const presentation = await veramoAgent.createVerifiablePresentation( { presentation: { verifiableCredential: [credential as W3CVerifiableCredential], holder: holderDid, }, proofFormat: 'jwt', }, {} as any, ); return presentation; }
Verify Presentation Callback The parameters for the callback for
verifyPresentation
areverifiablePresentation
,veramoAgent
. The response from theverifyPresentation
needs to be aboolean
otherwise aProblem Report
will be sent to the other party. Sampleprivate async verifyPresentation(verifiablePresentation: any, veramoAgent: VeramoAgent) { const verificationResponse = await veramoAgent.verifyPresentation( { presentation: verifiablePresentation, // We only want to check the signature and its general validity // The rest we handle manually to throw the correct OCI error codes policies: { issuanceDate: false, expirationDate: false, aud: false, }, }, {} as any, ); return verificationResponse; }
Sending Messages
- Send0023 (Invitation)
The method
send0023
method of theAriesRFCsPlugin
can be used to initiate theAries RFC 0023
Protocol. It requires an object of typeSend0023MessageAttr
andIContext
(Veramo Context) and returns an an object of typeSendRFCsResponse
. Sampleimport { AriesRFCsPlugin } from 'aries-rfcs-veramo-plugin'; const ariesPlugin = new AriesRFCsPlugin; await ariesPlugin.send0023( { to: //Receiver DID from: // Sender DID }, { VeramoContext } );
- Send0453 (Issue Credential)
The method
send0453
method of theAriesRFCsPlugin
can be used to initiate theAries RFC 0453
Protocol. It requires an object of typeSend0453MessageAttr
andIContext
(Veramo Context) and returns an an object of typeSendRFCsResponse
. Sampleimport { AriesRFCsPlugin, MESSAGE_TYPES_0453, DIDCommMessagePacking } from 'aries-rfcs-veramo-plugin'; const ariesPlugin = new AriesRFCsPlugin; await ariesPlugin.send0453( { to: //Receiver DID from: // Sender DID type: // MESSAGE_TYPES_0453 packingType: // DIDCommMessagePacking message: { '@type': // MESSAGE_TYPE_0453 credentialBody: {...} } }, { VeramoContext } );
- Send0454 (Present Proof)
The method
send0454
method of theAriesRFCsPlugin
can be used to initiate theAries RFC 0454
Protocol. It requires an object of typeSend0454MessageAttr
andIContext
(Veramo Context) and returns an an object of typeSendRFCsResponse
. Sampleimport { AriesRFCsPlugin, MESSAGE_TYPES_0454, DIDCommMessagePacking } from 'aries-rfcs-veramo-plugin'; const ariesPlugin = new AriesRFCsPlugin; await ariesPlugin.send0454( { to: //Receiver DID from: // Sender DID type: // MESSAGE_TYPES_0454 packingType: // DIDCommMessagePacking message: { '@type': // MESSAGE_TYPE_0454 } }, { VeramoContext } );