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

JWK resolver, JWT test #474

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 9 additions & 0 deletions examples/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @docknetwork/sdk-examples

## 0.4.2

### Patch Changes

- Updated dependencies
- @docknetwork/credential-sdk@0.7.0
- @docknetwork/dock-blockchain-api@0.4.2
- @docknetwork/dock-blockchain-modules@0.5.2

## 0.4.1

### Patch Changes
Expand Down
8 changes: 4 additions & 4 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@docknetwork/sdk-examples",
"private": true,
"type": "module",
"version": "0.4.1",
"version": "0.4.2",
"scripts": {
"bbs-dock-example": "babel-node ./bbs-dock.js",
"claim-deduction-example": "babel-node ./claim-deduction.js",
Expand All @@ -19,9 +19,9 @@
"lint": "eslint \"*.js\""
},
"dependencies": {
"@docknetwork/credential-sdk": "0.6.0",
"@docknetwork/dock-blockchain-api": "0.4.1",
"@docknetwork/dock-blockchain-modules": "0.5.1"
"@docknetwork/credential-sdk": "0.7.0",
"@docknetwork/dock-blockchain-api": "0.4.2",
"@docknetwork/dock-blockchain-modules": "0.5.2"
},
"devDependencies": {
"babel-eslint": "^10.1.0",
Expand Down
7 changes: 7 additions & 0 deletions packages/cheqd-blockchain-modules/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @docknetwork/cheqd-blockchain-modules

## 0.5.2

### Patch Changes

- Updated dependencies
- @docknetwork/credential-sdk@0.7.0

## 0.5.1

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/cheqd-blockchain-modules/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@docknetwork/cheqd-blockchain-modules",
"version": "0.5.1",
"version": "0.5.2",
"type": "module",
"license": "MIT",
"main": "./dist/esm/index.js",
Expand Down Expand Up @@ -33,7 +33,7 @@
"node": ">=18.0.0"
},
"dependencies": {
"@docknetwork/credential-sdk": "0.6.0"
"@docknetwork/credential-sdk": "0.7.0"
},
"devDependencies": {
"@babel/cli": "^7.24.1",
Expand Down
6 changes: 6 additions & 0 deletions packages/credential-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @docknetwork/credential-sdk

## 0.7.0

### Minor Changes

- JWT fixes

## 0.6.0

### Minor Changes
Expand Down
3 changes: 2 additions & 1 deletion packages/credential-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@docknetwork/credential-sdk",
"version": "0.6.0",
"version": "0.7.0",
"license": "MIT",
"type": "module",
"files": [
Expand Down 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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The empty constructor is no longer needed.

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/presentations';

mockFetch();

const SPHEREON_ID_JWT_CREDENTIAL = 'eyJraWQiOiJkaWQ6andrOmV5SmhiR2NpT2lKRlV6STFOaUlzSW5WelpTSTZJbk5wWnlJc0ltdDBlU0k2SWtWRElpd2lZM0oySWpvaVVDMHlOVFlpTENKNElqb2lSRlZqTUVwMVNuRjFNbFV5U1dGNVN6TXlOMFJzVjE5b05VcHJPRzlqUmxSbVVsQktRVGxNTUVwQlVTSXNJbmtpT2lJd01qSlBWMk5IYmtvNFJFUmZkbmhGTFY5UldUSmhURUZQZUZSdVlUVjFabmRpWWpkMVNFRnhSM0YzSW4wIzAiLCJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vc3BoZXJlb24tb3BlbnNvdXJjZS5naXRodWIuaW8vc3NpLW1vYmlsZS13YWxsZXQvY29udGV4dC9zcGhlcmVvbi13YWxsZXQtaWRlbnRpdHktdjEuanNvbmxkIl0sInR5cGUiOlsiVmVyaWZpYWJsZUNyZWRlbnRpYWwiLCJTcGhlcmVvbldhbGxldElkZW50aXR5Q3JlZGVudGlhbCJdLCJjcmVkZW50aWFsU3ViamVjdCI6eyJmaXJzdE5hbWUiOiJUZXN0IiwibGFzdE5hbWUiOiJUZXN0IiwiZW1haWxBZGRyZXNzIjoidGVzdEB0ZXN0LmNvbSJ9fSwic3ViIjoiZGlkOmp3azpleUpoYkdjaU9pSkZVekkxTmlJc0luVnpaU0k2SW5OcFp5SXNJbXQwZVNJNklrVkRJaXdpWTNKMklqb2lVQzB5TlRZaUxDSjRJam9pUkZWak1FcDFTbkYxTWxVeVNXRjVTek15TjBSc1YxOW9OVXByT0c5alJsUm1VbEJLUVRsTU1FcEJVU0lzSW5raU9pSXdNakpQVjJOSGJrbzRSRVJmZG5oRkxWOVJXVEpoVEVGUGVGUnVZVFYxWm5kaVlqZDFTRUZ4UjNGM0luMCIsImp0aSI6InVybjp1dWlkOmNiOWUzYzZhLTZjOTYtNGFiYS1iNWY0LWFiM2RmMDM4Y2MyMiIsIm5iZiI6MTcyMjk3NDM5OSwiaXNzIjoiZGlkOmp3azpleUpoYkdjaU9pSkZVekkxTmlJc0luVnpaU0k2SW5OcFp5SXNJbXQwZVNJNklrVkRJaXdpWTNKMklqb2lVQzB5TlRZaUxDSjRJam9pUkZWak1FcDFTbkYxTWxVeVNXRjVTek15TjBSc1YxOW9OVXByT0c5alJsUm1VbEJLUVRsTU1FcEJVU0lzSW5raU9pSXdNakpQVjJOSGJrbzRSRVJmZG5oRkxWOVJXVEpoVEVGUGVGUnVZVFYxWm5kaVlqZDFTRUZ4UjNGM0luMCJ9.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);
});
});
7 changes: 7 additions & 0 deletions packages/dock-blockchain-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @docknetwork/dock-blockchain-api

## 0.4.2

### Patch Changes

- Updated dependencies
- @docknetwork/credential-sdk@0.7.0

## 0.4.1

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/dock-blockchain-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@docknetwork/dock-blockchain-api",
"version": "0.4.1",
"version": "0.4.2",
"license": "MIT",
"main": "./dist/esm/index.js",
"type": "module",
Expand Down Expand Up @@ -89,7 +89,7 @@
"@polkadot/api": "10.12.4"
},
"dependencies": {
"@docknetwork/credential-sdk": "0.6.0",
"@docknetwork/credential-sdk": "0.7.0",
"@docknetwork/node-types": "^0.17.0",
"@juanelas/base64": "^1.0.5",
"@polkadot/api": "10.12.4",
Expand Down
7 changes: 7 additions & 0 deletions packages/dock-blockchain-modules/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @docknetwork/dock-blockchain-modules

## 0.5.2

### Patch Changes

- Updated dependencies
- @docknetwork/credential-sdk@0.7.0

## 0.5.1

### Patch Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/dock-blockchain-modules/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@docknetwork/dock-blockchain-modules",
"version": "0.5.1",
"version": "0.5.2",
"license": "MIT",
"type": "module",
"main": "./dist/esm/index.js",
Expand Down Expand Up @@ -33,7 +33,7 @@
"node": ">=18.0.0"
},
"dependencies": {
"@docknetwork/credential-sdk": "0.6.0"
"@docknetwork/credential-sdk": "0.7.0"
},
"devDependencies": {
"@babel/cli": "^7.24.1",
Expand All @@ -42,7 +42,7 @@
"@babel/plugin-syntax-import-attributes": "^7.25.6",
"@babel/plugin-transform-modules-commonjs": "^7.24.1",
"@babel/preset-env": "^7.24.3",
"@docknetwork/dock-blockchain-api": "0.4.1",
"@docknetwork/dock-blockchain-api": "0.4.2",
"@rollup/plugin-alias": "^4.0.2",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^24.0.0",
Expand Down
Loading
Loading