Skip to content

Commit

Permalink
fix: check proof state before fetch (#1313)
Browse files Browse the repository at this point in the history
Signed-off-by: Jason C. Leach <[email protected]>
jleach authored Nov 12, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 8900029 commit 6fcd666
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions packages/legacy/core/App/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -693,12 +693,20 @@ export const retrieveCredentialsForProof = async (
t: TFunction<'translation', undefined>,
groupByReferent?: boolean
) => {
// This is the only valid state to retrieve credentials for a proof
// `getCredentialsForRequest` will fail otherwise.
if (proof.state !== ProofState.RequestReceived) {
return
}

try {
const format = await agent.proofs.getFormatData(proof.id)
const hasPresentationExchange = format.request?.presentationExchange !== undefined
const hasAnonCreds = format.request?.anoncreds !== undefined
const hasIndy = format.request?.indy !== undefined
const credentialsPromise = agent.proofs.getCredentialsForRequest({

// Will fail if credential not in state 'request-received'
const credentialsAsPromise = agent.proofs.getCredentialsForRequest({
proofRecordId: proof.id,
proofFormats: {
// FIXME: Credo will try to use the format, even if the value is undefined (but the key is present)
@@ -728,7 +736,9 @@ export const retrieveCredentialsForProof = async (
...(hasPresentationExchange ? { presentationExchange: {} } : {}),
},
})
const credentialsWithRevokedPromise = agent.proofs.getCredentialsForRequest({

// Will fail if credential not in state 'request-received'
const credentialsWithRevokedAsPromise = agent.proofs.getCredentialsForRequest({
proofRecordId: proof.id,
proofFormats: {
// FIXME: Credo will try to use the format, even if the value is undefined (but the key is present)
@@ -758,9 +768,14 @@ export const retrieveCredentialsForProof = async (
...(hasPresentationExchange ? { presentationExchange: {} } : {}),
},
})
const [credentials, credentialsWithRevoked] = await Promise.all([credentialsPromise, credentialsWithRevokedPromise])

// in the case where there are only revoked credentials to satisfy a proof, include them for errors on the proof screen, otherwise leave them out
const [credentials, credentialsWithRevoked] = await Promise.all([
credentialsAsPromise,
credentialsWithRevokedAsPromise,
])

// In the case where there are only revoked credentials to satisfy a proof,
// include them for errors on the proof screen, otherwise leave them out
const addRevokedCredsIfNeeded = (proofFormat: 'indy' | 'anoncreds', proofItem: 'attributes' | 'predicates') => {
if (credentials.proofFormats[proofFormat] && credentialsWithRevoked.proofFormats[proofFormat]) {
Object.keys(credentials.proofFormats[proofFormat]?.[proofItem] ?? {}).forEach((key) => {

0 comments on commit 6fcd666

Please sign in to comment.