Skip to content

Commit

Permalink
Start adding VC-JWT exchange support.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Aug 5, 2024
1 parent 138a2ab commit a0d9c5f
Show file tree
Hide file tree
Showing 6 changed files with 556 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Added
- Add support for ECDSA keys (with `ES256` and `ES384` algs) for
DID JWT proofs.
- Add support for VC 2.0 contexts in JSON schemas.

### Fixed
- Fix JSON schema to allow VCs with only a single type.
Expand Down
28 changes: 28 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import * as bedrock from '@bedrock/core';
import {decodeId, generateId} from 'bnid';
import {decodeJwt} from 'jose';
import {Ed25519Signature2020} from '@digitalbazaar/ed25519-signature-2020';
import {httpsAgent} from '@bedrock/https-agent';
import jsonata from 'jsonata';
Expand Down Expand Up @@ -102,3 +103,30 @@ export function decodeLocalId({localId} = {}) {
expectedSize: 16
}));
}

export async function unenvelopeCredential({envelopedCredential} = {}) {
let credential;
const {id} = envelopedCredential;
if(id?.startsWith('data:application/jwt,')) {
const format = 'application/jwt';
const jwt = id.slice('data:application/jwt,'.length);
const claimset = decodeJwt(jwt);
// FIXME: perform various field mappings as needed
console.log('VC-JWT claimset', credential);
return {credential: claimset.vc, format};
}
throw new Error('Not implemented.');
}

export async function unenvelopePresentation({envelopedPresentation} = {}) {
const {id} = envelopedPresentation;
if(id?.startsWith('data:application/jwt,')) {
const format = 'application/jwt';
const jwt = id.slice('data:application/jwt,'.length);
const claimset = decodeJwt(jwt);
// FIXME: perform various field mappings as needed
console.log('VC-JWT claimset', claimset);
return {presentation: claimset.vp, format};
}
throw new Error('Not implemented.');
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
},
"homepage": "https://github.com/digitalbazaar/bedrock-vc-delivery",
"dependencies": {
"@digitalbazaar/ecdsa-multikey": "^1.7.0",
"@digitalbazaar/ed25519-multikey": "^1.1.0",
"@digitalbazaar/ed25519-signature-2020": "^5.2.0",
"@digitalbazaar/ezcap": "^4.0.0",
Expand Down
1 change: 0 additions & 1 deletion test/mocha/36-oid4vci-vc-jwt.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ describe('exchange w/OID4VCI delivery of VC-JWT', () => {
should.exist(result);
result.should.include.keys(['format', 'credential']);
result.format.should.equal(credentialFormat);
result.format.should.equal(credentialFormat);
result.credential.should.be.a('string');
// FIXME: add additional assertions after parsing JWT
// // ensure credential subject ID matches static DID
Expand Down
Loading

0 comments on commit a0d9c5f

Please sign in to comment.