Present a Verifiable Credential
Present a JSON-LD Verifiable Credential, signed by a did:cheqd Decentralized Identifier (DID), using Credo.
Prerequisites
Step 1: Create a Connection with Holder
Step 2: Register Proof Event Listeners
import { ProofEventTypes, ProofState } from '@credo-ts/core'
const setupProofListener = (agent: Agent) => {
agent.events.on(ProofEventTypes.ProofStateChanged, async ({ payload }) => {
const { proofRecord } = payload
switch (proofRecord.state) {
case ProofState.RequestReceived:
console.log('Holder: Proof request received, creating presentation...')
const requestedCredentials = await agent.proofs.selectCredentialsForRequest({
proofRecordId: proofRecord.id,
})
await agent.proofs.acceptRequest({
proofRecordId: proofRecord.id,
proofFormats: {
presentationExchange: {
credentials: requestedCredentials.proofFormats['presentation-exchange']?.credentials || {},
},
},
})
break
case ProofState.PresentationReceived:
console.log('Issuer: Presentation received, verifying...')
await agent.proofs.acceptPresentation({
proofRecordId: proofRecord.id,
})
break
case ProofState.Done:
console.log('Proof verification completed!')
const proof = await agent.proofs.getById(proofRecord.id)
console.log('Proof is valid:', proof.isVerified)
break
}
})
}Next Steps
Last updated
Was this helpful?