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

Multi creds credential endpoint #107

Merged
merged 3 commits into from
Sep 3, 2024
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# bedrock-vc-delivery ChangeLog

## 5.4.0 - 2024-09-dd

### Added
- Allow multiple credentials (if they are of the same type) to be returned
from a single OID4VCI exchange using the `credential` endpoint (not the
batch endpoint).

## 5.3.5 - 2024-08-27

### Fixed
Expand Down
43 changes: 24 additions & 19 deletions lib/oid4/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,28 +203,33 @@ export async function createRoutes({
return;
}

/* Note: The `/credential` route only supports sending a single VC;
assume here that this workflow is configured for a single VC and an
error code would have been sent to the client to use the batch
endpoint if there was more than one VC to deliver. */
const {response, format} = result;
const {verifiablePresentation: {verifiableCredential: [vc]}} = response;
// send VC(s)
const {
response: {verifiablePresentation: {verifiableCredential}},
format
} = result;
// FIXME: "format" doesn't seem to be in the spec anymore (draft 14+)...
const credentials = verifiableCredential.map(vc => {
// parse any enveloped VC
let credential;
if(vc.type === 'EnvelopedVerifiableCredential' &&
vc.id?.startsWith('data:application/jwt,')) {
credential = vc.id.slice('data:application/jwt,'.length);
} else {
credential = vc;
}
return credential;
});

// parse any enveloped VC
let credential;
if(vc.type === 'EnvelopedVerifiableCredential' &&
vc.id?.startsWith('data:application/jwt,')) {
credential = vc.id.slice('data:application/jwt,'.length);
} else {
credential = vc;
}
/* Note: The `/credential` route only supports sending VCs of the same
type, but there can be more than one of them. The above `isBatchRequest`
check will ensure that the workflow used here only allows a single
credential request, indicating a single type. */

// send OID4VCI response
res.json({
// FIXME: this doesn't seem to be in the spec anymore (draft 14+)...
format,
credential
});
const response = credentials.length === 1 ?
{format, credential: credentials[0]} : {format, credentials};
res.json(response);
}));

// a credential delivery server endpoint
Expand Down
2 changes: 1 addition & 1 deletion test/mocha/20-vcapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ describe('exchange w/ VC-API delivery', () => {
// wait for exchange to expire
now = new Date();
await new Promise(
r => setTimeout(r, expires.getTime() - now.getTime()));
r => setTimeout(r, expires.getTime() - now.getTime() + 1));
} catch(error) {
err = error;
}
Expand Down
Loading