Skip to content

Commit be2aa3c

Browse files
committed
Add includeCredentials option.
1 parent c214cdb commit be2aa3c

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @digitalbazaar/vc ChangeLog
22

3+
## 7.2.0 - 2025-mm-dd
4+
5+
### Added
6+
- Add `includeCredentials` option to be passed to `verify()` to include
7+
each `credential` in `credentialResults` when verifying a presentation.
8+
39
## 7.1.2 - 2025-03-17
410

511
### Changed

lib/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @author David I. Lehn
66
*
77
* @license BSD 3-Clause License
8-
* Copyright (c) 2017-2023 Digital Bazaar, Inc.
8+
* Copyright (c) 2017-2025 Digital Bazaar, Inc.
99
* All rights reserved.
1010
*
1111
* Redistribution and use in source and binary forms, with or without
@@ -229,6 +229,8 @@ export async function derive({
229229
* that clocks may be skewed when checking capability expiration date-times
230230
* against `date` and when comparing invocation proof creation time against
231231
* delegation proof creation time.
232+
* @param {boolean} [options.includeCredentials=false] - Set to `true` to
233+
* include the credentials in the credential results.
232234
*
233235
* @returns {Promise<VerifyPresentationResult>} The verification result.
234236
*/
@@ -488,7 +490,7 @@ export async function signPresentation(options = {}) {
488490
* @returns {Promise<VerifyPresentationResult>} The verification result.
489491
*/
490492
async function _verifyPresentation(options = {}) {
491-
const {presentation, unsignedPresentation} = options;
493+
const {presentation, unsignedPresentation, includeCredentials} = options;
492494

493495
_checkPresentation(presentation);
494496

@@ -508,7 +510,11 @@ async function _verifyPresentation(options = {}) {
508510
}));
509511

510512
for(const [i, credentialResult] of credentialResults.entries()) {
511-
credentialResult.credentialId = credentials[i].id;
513+
const credential = credentials[i];
514+
credentialResult.credentialId = credential.id;
515+
if(includeCredentials) {
516+
credentialResult.credential = credential;
517+
}
512518
}
513519

514520
const allCredentialsVerified = credentialResults.every(r => r.verified);

test/10-verify.spec.js

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Copyright (c) 2019-2024 Digital Bazaar, Inc. All rights reserved.
2+
* Copyright (c) 2019-2025 Digital Bazaar, Inc. All rights reserved.
33
*/
44
import * as bbs2023Cryptosuite from '@digitalbazaar/bbs-2023-cryptosuite';
55
import * as Bls12381Multikey from '@digitalbazaar/bls12-381-multikey';
@@ -806,6 +806,30 @@ for(const [version, mockCredential] of versionedCredentials) {
806806
result.verified.should.be.a('boolean');
807807
result.verified.should.be.true;
808808
});
809+
it('includes credentials in verification results', async () => {
810+
const challenge = uuid();
811+
812+
const {presentation, suite, documentLoader} =
813+
await _generatePresentation({challenge, mockCredential, version});
814+
815+
const result = await vc.verify({
816+
challenge,
817+
suite,
818+
documentLoader,
819+
presentation,
820+
includeCredentials: true
821+
});
822+
823+
if(result.error) {
824+
const firstError = [].concat(result.error)[0];
825+
throw firstError;
826+
}
827+
result.verified.should.be.a('boolean');
828+
result.verified.should.be.true;
829+
result.credentialResults.length.should.equal(1);
830+
result.credentialResults[0].credential.should.deep.equal(
831+
presentation.verifiableCredential[0]);
832+
});
809833
it('verifies an unsigned presentation', async () => {
810834
const {
811835
presentation,
@@ -831,6 +855,35 @@ for(const [version, mockCredential] of versionedCredentials) {
831855
result.verified.should.be.a('boolean');
832856
result.verified.should.be.true;
833857
});
858+
it('includes credentials in unsigned presentation results', async () => {
859+
const {
860+
presentation,
861+
suite: vcSuite,
862+
documentLoader,
863+
} = await _generatePresentation({
864+
unsigned: true,
865+
mockCredential,
866+
version
867+
});
868+
869+
const result = await vc.verify({
870+
documentLoader,
871+
presentation,
872+
suite: vcSuite,
873+
unsignedPresentation: true,
874+
includeCredentials: true
875+
});
876+
877+
if(result.error) {
878+
const firstError = [].concat(result.error)[0];
879+
throw firstError;
880+
}
881+
result.verified.should.be.a('boolean');
882+
result.verified.should.be.true;
883+
result.credentialResults.length.should.equal(1);
884+
result.credentialResults[0].credential.should.deep.equal(
885+
presentation.verifiableCredential[0]);
886+
});
834887
});
835888

836889
describe(`VerifiablePresentations Version ${version} w/ multiple VCs`,

0 commit comments

Comments
 (0)