Proofs
1
Auto Accepting
Kotlin
// Gets the first proof event received, blocks whatever thread it is ran on.
val proofEvent = agent.events.getProofEvents().first()
try {
agent.proofs.autoAcceptProof(proofEvent.proofRecord.id, proofEvent.didExchangeId)
} catch (e: Throwable) {
println("An error occurred auto-accepting proof, message: ${e.message}")
}React Native
const removeProofHandler = agent.events.registerProofHandler(
(event) => {
try {
if (event.proofRecord.state === ProofState.REQUEST_RECEIVED) {
await agent.proofs.autoAcceptProof(
event.proofRecord.id,
event.exchangeId
);
}
} catch (error) {
console.log(`An error ocurred auto-accepting proof, message ${error.message}`)
}
}
)2
Manual Acceptance
Kotlin
val proofEvent = agent.events.getProofEvents().first()
// Returns a list of pairs containing first the proof and then the credential(s) selected
val proofAttributes: SelectedCredentialsForProof = agent.proofs.autoSelectCredentialsForProof(
proofEvent.proofRecord.id,
proofEvent.didExchangeId,
nonRevoked = false
) // nonRevoked indicates if you care if the credentials selected are revoked or not
// Or
// Returns a similar object but can potentially contain multiple credentials that need to be selected from
val proofAttributes: SelectedCredentials = agent.proofs.getCredentialsForProofRequest(
proofEvent.proofRecord.id,
proofEvent.didExchangeId,
nonRevoked = false
)React Native
const removeProofHandler = agent.events.registerProofHandler(async (event) => {
const proofAttributes = await agent.proofs.autoSelectCredentialsForProof(
event.proofRecord.id,
event.didExchangeId,
false
)
// Or
const proofAttributes = await agent.proofs.getCredentialsForProofRequest(
event.proofRecord.id,
event.didExchangeId,
false
)
})Auto selection flow (processing returned PresentationData)
val proofData = agent.proofs.autoSelectCredentialsForProof(
proofEvent.proofRecord.id,
proofEvent.didExchangeId,
nonRevoked = false
)
// Check if there are any required self-attested attributes
val selfAttested = proofData.getRequiredSelfAttested()
if(selftAttested.size != 0){
selfAttested.forEach{ referent ->
referent.selfAttestedValue = "Data from somewhere else"
}
}
// Supply the originally returned object that has been modified in place
agent.proofs.acceptProofs(proofData)const proofData = await agent.proofs.autoSelectCredentialsForProof(
event.proofRecord.id,
event.didExchangeId,
false
)
const selfAttested = proofData.getRequiredSelfAttested()
if(selfAttested.size != 0) {
selfAttested.forEach((referent) => {
referent.selfAttestedValue = "Data from somewhere else"
})
}
await agent.proofs.acceptProofs(proofData)Manual Selection
val proofData = agent.proofs.getCredentialsForProofRequest(
proofEvent.proofRecord.id,
proofEvent.didExchangeId,
nonRevoked = false
)
// Goes through all attributes and picks the first credential that matches
proofData.attributes.forEach{ attribute =>
attribute.selectCredential(0)
}
proofData.predicates.forEach{ predicate =>
predicate.selectCredential(0)
}
agent.proofs.acceptProofs(proofData)const proofData = await agent.proofs.getCredentialsForProofRequest(
proofEvent.proofRecord.id,
proofEvent.didExchangeId,
nonRevoked = false
)
proofData.attributes.forEach((attribute) => {
attribute.selectCredential(0)
})
proofData.predicates.forEach((predicate) => {
predicate.selectCredential(0)
})
await agent.proofs.acceptProofs(proofData)Last updated
Was this helpful?