Skip to content

Commit

Permalink
Add BitstringStatusList credential status checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Nov 6, 2024
1 parent a87567e commit 7037ec0
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 293 deletions.
16 changes: 8 additions & 8 deletions lib/di.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@
* Copyright (c) 2018-2024 Digital Bazaar, Inc. All rights reserved.
*/
import * as vc from '@digitalbazaar/vc';
import {checkStatus} from './status.js';
import {checkStatus as _checkStatus} from './status.js';
import {createDocumentLoader} from './documentLoader.js';
import {createSuites} from './suites.js';

export async function verifyCredential({config, credential, checks} = {}) {
const documentLoader = await createDocumentLoader({config});
const suite = createSuites();

// only check credential status when option is set
const checkStatus = checks.includes('credentialStatus') ?
_checkStatus : undefined;

const result = await vc.verifyCredential({
credential,
documentLoader,
suite,
// only check credential status when option is set
checkStatus: checks.includes('credentialStatus') ?
checkStatus : () => ({verified: true})
checkStatus
});
// if proof should have been checked but wasn't due to an error,
// try to run the check again using the VC's issuance date
Expand All @@ -28,9 +30,7 @@ export async function verifyCredential({config, credential, checks} = {}) {
documentLoader,
suite,
now: new Date(credential.issuanceDate),
// only check credential status when option is set
checkStatus: checks.includes('credentialStatus') ?
checkStatus : () => ({verified: true})
checkStatus
});
if(proofResult.verified) {
// overlay original (failed) results on top of proof results
Expand All @@ -57,7 +57,7 @@ export async function verifyPresentation({
documentLoader: await createDocumentLoader({config}),
suite: createSuites(),
unsignedPresentation: !checks.includes('proof'),
checkStatus
checkStatus: _checkStatus
};
return vc.verify(verifyOptions);
}
18 changes: 13 additions & 5 deletions lib/status.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
/*!
* Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
* Copyright (c) 2019-2024 Digital Bazaar, Inc. All rights reserved.
*/
import {
checkStatus as bitstringStatusListCheckStatus,
statusTypeMatches as bitstringStatusListStatusTypeMatches
} from '@digitalbazaar/vc-bitstring-status-list';
import {
checkStatus as revocationListCheckStatus,
statusTypeMatches as revocationListStatusTypeMatches
} from '@digitalbazaar/vc-revocation-list';
import {
checkStatus as statusListCheckStatus,
statusTypeMatches as statusListStatusTypeMatches
checkStatus as statusList2020CheckStatus,
statusTypeMatches as statusList2020StatusTypeMatches
} from '@digitalbazaar/vc-status-list';
import assert from 'assert-plus';

const handlerMap = new Map();
handlerMap.set('BitstringStatusListEntry', {
checkStatus: bitstringStatusListCheckStatus,
statusTypeMatches: bitstringStatusListStatusTypeMatches
});
handlerMap.set('RevocationList2020Status', {
checkStatus: revocationListCheckStatus,
statusTypeMatches: revocationListStatusTypeMatches
});
handlerMap.set('StatusList2021Entry', {
checkStatus: statusListCheckStatus,
statusTypeMatches: statusListStatusTypeMatches
checkStatus: statusList2020CheckStatus,
statusTypeMatches: statusList2020StatusTypeMatches
});

export async function checkStatus(options = {}) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@digitalbazaar/eddsa-2022-cryptosuite": "^1.0.0",
"@digitalbazaar/eddsa-rdfc-2022-cryptosuite": "^1.1.0",
"@digitalbazaar/vc": "^7.0.0",
"@digitalbazaar/vc-bitstring-status-list": "^2.0.0",
"@digitalbazaar/vc-revocation-list": "^7.0.0",
"@digitalbazaar/vc-status-list": "^8.0.0",
"assert-plus": "^1.0.0",
Expand Down
Loading

0 comments on commit 7037ec0

Please sign in to comment.