Skip to content

Commit

Permalink
JWK resolver, JWT test
Browse files Browse the repository at this point in the history
  • Loading branch information
cykoder committed Nov 11, 2024
1 parent d2cab44 commit 542ce8b
Show file tree
Hide file tree
Showing 5 changed files with 1,120 additions and 28 deletions.
1 change: 1 addition & 0 deletions packages/credential-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@digitalcredentials/vc-status-list": "^8.0.0",
"@docknetwork/crypto-wasm-ts": "^0.63.0",
"@juanelas/base64": "^1.1.5",
"@sphereon/ssi-sdk-ext.did-resolver-jwk": "^0.25.0",
"@stablelib/ed25519": "^1.0.0",
"@subsquid/ss58-codec": "latest",
"@transmute/json-web-signature": "^0.7.0-unstable.82",
Expand Down
25 changes: 25 additions & 0 deletions packages/credential-sdk/src/resolver/did/did-jwk-resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { getDidJwkResolver } from '@sphereon/ssi-sdk-ext.did-resolver-jwk';
import { Resolver } from '../generic';

const jwkResolver = getDidJwkResolver();

/**
* Resolves `DID` keys with identifier `did:jwk:*`.
*/
export default class DIDJWKResolver extends Resolver {
prefix = 'did';

method = 'jwk';

constructor() {
super(void 0);
}

async resolve(did) {
const { didDocument } = await jwkResolver.jwk(did);
return {
'@context': 'https://www.w3.org/ns/did/v1',
...didDocument,
};
}
}
1 change: 1 addition & 0 deletions packages/credential-sdk/src/resolver/did/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as DIDKeyResolver } from './did-key-resolver';
export { default as DIDJWKResolver } from './did-jwk-resolver';
export { default as DIDResolver } from './did-resolver';
export { default as UniversalResolver } from './universal-resolver';
40 changes: 40 additions & 0 deletions packages/credential-sdk/tests/jwt-vc.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Mock fetch
import mockFetch from './mocks/fetch';

import DIDJWKResolver from '../src/resolver/did/did-jwk-resolver';
import { verifyCredential } from '../src/vc/credentials';
import { verifyPresentation } from '../src/vc/pres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NGM0luMCIsImp0aSI6InVybjp1dWlkOmNiOWUzYzZhLTZjOTYtNGFiYS1iNWY0LWFiM2RmMDM4Y2MyMiIsIm5iZiI6MTcyMjk3NDM5OSwiaXNzIjoiZGlkOmp3azpleUpoYkdjaU9pSkZVekkxTmlJc0luVnpaU0k2SW5OcFp5SXNJbXQwZVNJNklrVkRJaXdpWTNKMklqb2lVQzB5TlRZaUxDSjRJam9pUkZWak1FcDFTbkYxTWxVeVNXRjVTek15TjBSc1YxOW9OVXByT0c5alJsUm1VbEJLUVRsTU1FcEJVU0lzSW5raU9pSXdNakpQVjJOSGJrbzRSRVJmZG5oRkxWOVJXVEpoVEVGUGVGUnVZVFYxWm5kaVlqZDFTRUZ4UjNGM0luMCJ9.Y9CBYHA_sgfA_V40i69SYrqsAK1OZ6rUW8NlrZwavbPxcVS_LX3tFvRRU0jkslUbuf7rColxf2f8zo-YMan-_w';

// Test constants
const vpId = 'https://example.com/credentials/12345';
const vpHolder = 'https://example.com/credentials/1234567890';
function getSamplePres(presentationCredentials) {
return {
'@context': ['https://www.w3.org/2018/credentials/v1'],
type: ['VerifiablePresentation'],
verifiableCredential: presentationCredentials,
id: vpId,
holder: vpHolder,
};
}

describe('Static JWT-VC verification', () => {
const resolver = new DIDJWKResolver();
test('Sphereon ID credential', async () => {
const result = await verifyCredential(SPHEREON_ID_JWT_CREDENTIAL, {
resolver,
});
expect(result.verified).toBe(true);
});
test('Sphereon ID credential in presentation', async () => {
const result = await verifyPresentation(getSamplePres([SPHEREON_ID_JWT_CREDENTIAL]), {
resolver,
unsignedPresentation: true,
});
expect(result.verified).toBe(true);
});
});
Loading

0 comments on commit 542ce8b

Please sign in to comment.