Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: async revocation registry lookup #1548

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 134 additions & 16 deletions .yarn/patches/@aries-framework-anoncreds-npm-0.4.0-4d3b4e769d.patch
Original file line number Diff line number Diff line change
@@ -1,18 +1,136 @@
diff --git a/build/utils/revocationInterval.js b/build/utils/revocationInterval.js
index 728732d5119b879a2a2399eab6e6430b62796106..5c69ea0731c0fbdc0ff4820891d67773c7105b3b 100644
--- a/build/utils/revocationInterval.js
+++ b/build/utils/revocationInterval.js
@@ -7,9 +7,9 @@ function assertBestPracticeRevocationInterval(revocationInterval) {
if (!revocationInterval.to) {
throw new core_1.AriesFrameworkError(`Presentation requests proof of non-revocation with no 'to' value specified`);
diff --git a/build/utils/getRevocationRegistries.js b/build/utils/getRevocationRegistries.js
index 659e85e5d206ae9ba291383325403f922b2e9e1d..533750be7cfc1d04a9e6eb3edc8771e37b743b02 100644
--- a/build/utils/getRevocationRegistries.js
+++ b/build/utils/getRevocationRegistries.js
@@ -33,6 +33,7 @@ async function getRevocationRegistriesForRequest(agentContext, proofRequest, sel
nonRevoked: (_b = proofRequest.requested_predicates[referent].non_revoked) !== null && _b !== void 0 ? _b : proofRequest.non_revoked,
});
}
+ const revocationRegistryPromises = []
for (const { referent, selectedCredential, nonRevoked, type } of referentCredentials) {
if (!selectedCredential.credentialInfo) {
throw new core_1.AriesFrameworkError(`Credential for referent '${referent} does not have credential info for revocation state creation`);
@@ -55,38 +56,43 @@ async function getRevocationRegistriesForRequest(agentContext, proofRequest, sel
.resolve(services_1.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 core_1.AriesFrameworkError(`Could not retrieve revocation registry definition for revocation registry ${revocationRegistryId}: ${resolutionMetadata.message}`);
+ const getRevocationRegistry = async () => {
+ if (!revocationRegistries[revocationRegistryId]) {
+ const { revocationRegistryDefinition, resolutionMetadata } = await registry.getRevocationRegistryDefinition(agentContext, revocationRegistryId);
+ if (!revocationRegistryDefinition) {
+ throw new core_1.AriesFrameworkError(`Could not retrieve revocation registry definition for revocation registry ${revocationRegistryId}: ${resolutionMetadata.message}`);
+ }
+ const { tailsLocation, tailsHash } = revocationRegistryDefinition.value;
+ const { tailsFilePath } = await (0, tails_1.downloadTailsFile)(agentContext, tailsLocation, tailsHash);
+ // const tails = await this.indyUtilitiesService.downloadTails(tailsHash, tailsLocation)
+ revocationRegistries[revocationRegistryId] = {
+ definition: revocationRegistryDefinition,
+ tailsFilePath,
+ revocationStatusLists: {},
+ };
}
- const { tailsLocation, tailsHash } = revocationRegistryDefinition.value;
- const { tailsFilePath } = await (0, tails_1.downloadTailsFile)(agentContext, tailsLocation, tailsHash);
- // const tails = await this.indyUtilitiesService.downloadTails(tailsHash, tailsLocation)
- revocationRegistries[revocationRegistryId] = {
- definition: revocationRegistryDefinition,
- tailsFilePath,
- revocationStatusLists: {},
- };
- }
- // In most cases we will have a timestamp, but if it's not defined, we use the nonRevoked.to value
- const timestampToFetch = timestamp !== null && timestamp !== void 0 ? timestamp : nonRevoked.to;
- // Fetch revocation status list if we don't already have a revocation status list for the given timestamp
- if (!revocationRegistries[revocationRegistryId].revocationStatusLists[timestampToFetch]) {
- const { revocationStatusList, resolutionMetadata: statusListResolutionMetadata } = await registry.getRevocationStatusList(agentContext, revocationRegistryId, timestampToFetch);
- if (!revocationStatusList) {
- throw new core_1.AriesFrameworkError(`Could not retrieve revocation status list for revocation registry ${revocationRegistryId}: ${statusListResolutionMetadata.message}`);
- }
- revocationRegistries[revocationRegistryId].revocationStatusLists[revocationStatusList.timestamp] =
- revocationStatusList;
- // If we don't have a timestamp on the selected credential, we set it to the timestamp of the revocation status list
- // this way we know which revocation status list to use when creating the proof.
- if (!timestamp) {
- updatedSelectedCredentials = Object.assign(Object.assign({}, updatedSelectedCredentials), { [type]: Object.assign(Object.assign({}, updatedSelectedCredentials[type]), { [referent]: Object.assign(Object.assign({}, updatedSelectedCredentials[type][referent]), { timestamp: revocationStatusList.timestamp }) }) });
+ // In most cases we will have a timestamp, but if it's not defined, we use the nonRevoked.to value
+ const timestampToFetch = timestamp !== null && timestamp !== void 0 ? timestamp : nonRevoked.to;
+ // Fetch revocation status list if we don't already have a revocation status list for the given timestamp
+ if (!revocationRegistries[revocationRegistryId].revocationStatusLists[timestampToFetch]) {
+ const { revocationStatusList, resolutionMetadata: statusListResolutionMetadata } = await registry.getRevocationStatusList(agentContext, revocationRegistryId, timestampToFetch);
+ if (!revocationStatusList) {
+ throw new core_1.AriesFrameworkError(`Could not retrieve revocation status list for revocation registry ${revocationRegistryId}: ${statusListResolutionMetadata.message}`);
+ }
+ revocationRegistries[revocationRegistryId].revocationStatusLists[revocationStatusList.timestamp] =
+ revocationStatusList;
+ // If we don't have a timestamp on the selected credential, we set it to the timestamp of the revocation status list
+ // this way we know which revocation status list to use when creating the proof.
+ if (!timestamp) {
+ updatedSelectedCredentials = Object.assign(Object.assign({}, updatedSelectedCredentials), { [type]: Object.assign(Object.assign({}, updatedSelectedCredentials[type]), { [referent]: Object.assign(Object.assign({}, updatedSelectedCredentials[type][referent]), { timestamp: revocationStatusList.timestamp }) }) });
+ }
}
}
+ revocationRegistryPromises.push(getRevocationRegistry())
}
}
+ // await all revocation registry statuses asynchronously
+ await Promise.all(revocationRegistryPromises)
agentContext.config.logger.debug(`Retrieved revocation registries for proof request`, {
revocationRegistries,
});
@@ -104,6 +110,7 @@ async function getRevocationRegistriesForRequest(agentContext, proofRequest, sel
exports.getRevocationRegistriesForRequest = getRevocationRegistriesForRequest;
async function getRevocationRegistriesForProof(agentContext, proof) {
const revocationRegistries = {};
+ const revocationRegistryPromises = [];
for (const identifier of proof.identifiers) {
const revocationRegistryId = identifier.rev_reg_id;
const timestamp = identifier.timestamp;
@@ -114,25 +121,29 @@ async function getRevocationRegistriesForProof(agentContext, proof) {
.resolve(services_1.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 core_1.AriesFrameworkError(`Could not retrieve revocation registry definition for revocation registry ${revocationRegistryId}: ${resolutionMetadata.message}`);
+ const getRevocationRegistry = async () => {
+ if (!revocationRegistries[revocationRegistryId]) {
+ const { revocationRegistryDefinition, resolutionMetadata } = await registry.getRevocationRegistryDefinition(agentContext, revocationRegistryId);
+ if (!revocationRegistryDefinition) {
+ throw new core_1.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);
- if (!revocationStatusList) {
- throw new core_1.AriesFrameworkError(`Could not retrieve revocation status list for revocation registry ${revocationRegistryId}: ${statusListResolutionMetadata.message}`);
+ // 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 core_1.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())
}
- if ((revocationInterval.from || revocationInterval.from === 0) && revocationInterval.to !== revocationInterval.from) {
- throw new core_1.AriesFrameworkError(`Presentation requests proof of non-revocation with an interval from: '${revocationInterval.from}' that does not match the interval to: '${revocationInterval.to}', as specified in Aries RFC 0441`);
- }
+ // if ((revocationInterval.from || revocationInterval.from === 0) && revocationInterval.to !== revocationInterval.from) {
+ // throw new core_1.AriesFrameworkError(`Presentation requests proof of non-revocation with an interval from: '${revocationInterval.from}' that does not match the interval to: '${revocationInterval.to}', as specified in Aries RFC 0441`);
+ // }
+ await Promise.all(revocationRegistryPromises)
return revocationRegistries;
}
exports.assertBestPracticeRevocationInterval = assertBestPracticeRevocationInterval;
//# sourceMappingURL=revocationInterval.js.map
\ No newline at end of file
exports.getRevocationRegistriesForProof = getRevocationRegistriesForProof;
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ __metadata:

"@aries-framework/anoncreds@patch:@aries-framework/anoncreds@npm%3A0.4.0#./.yarn/patches/@aries-framework-anoncreds-npm-0.4.0-4d3b4e769d.patch::locator=bc-wallet-mobile%40workspace%3A.":
version: 0.4.0
resolution: "@aries-framework/anoncreds@patch:@aries-framework/anoncreds@npm%3A0.4.0#./.yarn/patches/@aries-framework-anoncreds-npm-0.4.0-4d3b4e769d.patch::version=0.4.0&hash=effd16&locator=bc-wallet-mobile%40workspace%3A."
resolution: "@aries-framework/anoncreds@patch:@aries-framework/anoncreds@npm%3A0.4.0#./.yarn/patches/@aries-framework-anoncreds-npm-0.4.0-4d3b4e769d.patch::version=0.4.0&hash=c6c7d3&locator=bc-wallet-mobile%40workspace%3A."
dependencies:
"@aries-framework/core": 0.4.0
bn.js: ^5.2.1
class-transformer: 0.5.1
class-validator: 0.14.0
reflect-metadata: ^0.1.13
checksum: 7f4d2e15f86ce64a402c65436f05d9a9a66e7b8dcaf50b9206985f8e5a4544ca1a4a1bbda0a6c953fc683859e2ba270464ece54b0f323fc6c10498cadc67f610
checksum: 64d2c17e308e6fcbea6da97d0f337af5f5d0e37ba5b9e1e458eb59dec0252a85b20ba11fa876d8bb1d279e2a69ebe1a77cc117d3062a7f14dff063e2c9d34aba
languageName: node
linkType: hard

Expand Down
Loading