Skip to content

Commit

Permalink
feat: sped up lookup for revocation registries (#1605)
Browse files Browse the repository at this point in the history
Signed-off-by: wadeking98 <[email protected]>
  • Loading branch information
wadeking98 authored Oct 12, 2023
1 parent a1942f8 commit 32ef8c5
Showing 1 changed file with 53 additions and 43 deletions.
96 changes: 53 additions & 43 deletions packages/anoncreds/src/utils/getRevocationRegistries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export async function getRevocationRegistriesForRequest(
})
}

const revocationRegistryPromises = []
for (const { referent, selectedCredential, nonRevoked, type } of referentCredentials) {
if (!selectedCredential.credentialInfo) {
throw new AriesFrameworkError(
Expand Down Expand Up @@ -76,29 +77,33 @@ export async function getRevocationRegistriesForRequest(
.resolve(AnonCredsRegistryService)
.getRegistryForIdentifier(agentContext, revocationRegistryId)

// Fetch revocation registry definition if not in revocation registries list yet
if (!revocationRegistries[revocationRegistryId]) {
const { revocationRegistryDefinition, resolutionMetadata } = await registry.getRevocationRegistryDefinition(
agentContext,
revocationRegistryId
)
if (!revocationRegistryDefinition) {
throw new AriesFrameworkError(
`Could not retrieve revocation registry definition for revocation registry ${revocationRegistryId}: ${resolutionMetadata.message}`
const getRevocationRegistry = async () => {
// Fetch revocation registry definition if not in revocation registries list yet
if (!revocationRegistries[revocationRegistryId]) {
const { revocationRegistryDefinition, resolutionMetadata } = await registry.getRevocationRegistryDefinition(
agentContext,
revocationRegistryId
)
}
if (!revocationRegistryDefinition) {
throw new AriesFrameworkError(
`Could not retrieve revocation registry definition for revocation registry ${revocationRegistryId}: ${resolutionMetadata.message}`
)
}

const { tailsLocation, tailsHash } = revocationRegistryDefinition.value
const { tailsFilePath } = await downloadTailsFile(agentContext, tailsLocation, tailsHash)
const { tailsLocation, tailsHash } = revocationRegistryDefinition.value
const { tailsFilePath } = await downloadTailsFile(agentContext, tailsLocation, tailsHash)

// const tails = await this.indyUtilitiesService.downloadTails(tailsHash, tailsLocation)
revocationRegistries[revocationRegistryId] = {
definition: revocationRegistryDefinition,
tailsFilePath,
revocationStatusLists: {},
// const tails = await this.indyUtilitiesService.downloadTails(tailsHash, tailsLocation)
revocationRegistries[revocationRegistryId] = {
definition: revocationRegistryDefinition,
tailsFilePath,
revocationStatusLists: {},
}
}
}

revocationRegistryPromises.push(getRevocationRegistry())

// In most cases we will have a timestamp, but if it's not defined, we use the nonRevoked.to value
const timestampToFetch = timestamp ?? nonRevoked.to

Expand Down Expand Up @@ -133,7 +138,8 @@ export async function getRevocationRegistriesForRequest(
}
}
}

// await all revocation registry statuses asynchronously
await Promise.all(revocationRegistryPromises)
agentContext.config.logger.debug(`Retrieved revocation registries for proof request`, {
revocationRegistries,
})
Expand All @@ -153,6 +159,7 @@ export async function getRevocationRegistriesForRequest(
export async function getRevocationRegistriesForProof(agentContext: AgentContext, proof: AnonCredsProof) {
const revocationRegistries: VerifyProofOptions['revocationRegistries'] = {}

const revocationRegistryPromises = []
for (const identifier of proof.identifiers) {
const revocationRegistryId = identifier.rev_reg_id
const timestamp = identifier.timestamp
Expand All @@ -164,38 +171,41 @@ export async function getRevocationRegistriesForProof(agentContext: AgentContext
.resolve(AnonCredsRegistryService)
.getRegistryForIdentifier(agentContext, revocationRegistryId)

// Fetch revocation registry definition if not already fetched
if (!revocationRegistries[revocationRegistryId]) {
const { revocationRegistryDefinition, resolutionMetadata } = await registry.getRevocationRegistryDefinition(
agentContext,
revocationRegistryId
)
if (!revocationRegistryDefinition) {
throw new AriesFrameworkError(
`Could not retrieve revocation registry definition for revocation registry ${revocationRegistryId}: ${resolutionMetadata.message}`
const getRevocationRegistry = async () => {
// Fetch revocation registry definition if not already fetched
if (!revocationRegistries[revocationRegistryId]) {
const { revocationRegistryDefinition, resolutionMetadata } = await registry.getRevocationRegistryDefinition(
agentContext,
revocationRegistryId
)
}
if (!revocationRegistryDefinition) {
throw new AriesFrameworkError(
`Could not retrieve revocation registry definition for revocation registry ${revocationRegistryId}: ${resolutionMetadata.message}`
)
}

revocationRegistries[revocationRegistryId] = {
definition: revocationRegistryDefinition,
revocationStatusLists: {},
revocationRegistries[revocationRegistryId] = {
definition: revocationRegistryDefinition,
revocationStatusLists: {},
}
}
}

// Fetch revocation status list by timestamp if not already fetched
if (!revocationRegistries[revocationRegistryId].revocationStatusLists[timestamp]) {
const { revocationStatusList, resolutionMetadata: statusListResolutionMetadata } =
await registry.getRevocationStatusList(agentContext, revocationRegistryId, timestamp)
// Fetch revocation status list by timestamp if not already fetched
if (!revocationRegistries[revocationRegistryId].revocationStatusLists[timestamp]) {
const { revocationStatusList, resolutionMetadata: statusListResolutionMetadata } =
await registry.getRevocationStatusList(agentContext, revocationRegistryId, timestamp)

if (!revocationStatusList) {
throw new AriesFrameworkError(
`Could not retrieve revocation status list for revocation registry ${revocationRegistryId}: ${statusListResolutionMetadata.message}`
)
}
if (!revocationStatusList) {
throw new AriesFrameworkError(
`Could not retrieve revocation status list for revocation registry ${revocationRegistryId}: ${statusListResolutionMetadata.message}`
)
}

revocationRegistries[revocationRegistryId].revocationStatusLists[timestamp] = revocationStatusList
revocationRegistries[revocationRegistryId].revocationStatusLists[timestamp] = revocationStatusList
}
}
revocationRegistryPromises.push(getRevocationRegistry())
}

await Promise.all(revocationRegistryPromises)
return revocationRegistries
}

0 comments on commit 32ef8c5

Please sign in to comment.