Skip to content

Commit

Permalink
Ci (#2)
Browse files Browse the repository at this point in the history
* Add CI
  • Loading branch information
nklomp authored Aug 8, 2022
1 parent 52ae654 commit 9ce891e
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 178 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
"rules": {
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/ban-ts-comment": [
"error",
{"ts-ignore": "allow-with-description"}
],
"eslint-comments/disable-enable-pair": [
"error",
{ "allowWholeFile": true }
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI

on:
push:
pull_request:

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
build:
name: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: install node v14
uses: actions/setup-node@v3
with:
node-version: 14
- name: yarn install
run: yarn install
- name: yarn test
run: yarn test
- name: yarn build
run: yarn build
- name: codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
name: codecov # optional
flags: unittest
fail_ci_if_error: true # optional (default = false)
#directory: ./coverage/reports/
#files: ./coverage1.xml,./coverage2.xml
verbose: true # optional (default = false)
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# Release Notes

The well-known DIDs client typescript library is still in an alpha state at this point. Please note that the interfaces might still change a bit as the software still is in active development.

## v0.1.0 - 2022-08-08

Initial release

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<br>
</h1>

[![CI](https://github.com/Sphereon-Opensource/wellknown-dids-client/actions/workflows/main.yml/badge.svg)](https://github.com/Sphereon-Opensource/wellknown-dids-client/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/wellknown-dids-client/branch/develop/graph/badge.svg?token=9P1JGUYA35)](https://codecov.io/gh/Sphereon-Opensource/wellknown-dids-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/wellknown-dids-client.svg)](https://npm.im/@sphereon/wellknown-dids-client)
[![CI](https://github.com/Sphereon-Opensource/wellknown-dids-client/actions/workflows/main.yaml/badge.svg)](https://github.com/Sphereon-Opensource/wellknown-dids-client/actions/workflows/main.yaml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/wellknown-dids-client/branch/develop/graph/badge.svg?token=9P1JGUYA35)](https://codecov.io/gh/Sphereon-Opensource/wellknown-dids-client) [![NPM Version](https://img.shields.io/npm/v/@sphereon/wellknown-dids-client.svg)](https://npm.im/@sphereon/wellknown-dids-client)

### Wellknown-dids client
The wellknown-dids-client is a library to create DID configuration resources and domain linkage credentials and to be able to verify these.
The wellknown-dids-client is a library to create DID configuration resources and domain linkage credentials and to be able to verify these conforming to the DIF [spec for well-known DID Configurations](https://identity.foundation/.well-known/resources/did-configuration/)
It is written in Typescript and can be compiled to any target JavaScript version.

### Supported actions
Expand Down
2 changes: 2 additions & 0 deletions lib/issuer/WellKnownDidIssuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export class WellKnownDidIssuer {

return (args.issueCallback)
? await args.issueCallback({ credential, proofFormat: args.options.proofFormat })
// @ts-ignore: We know for sure the config is present
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
: await this.config!.issueCallback({ credential, proofFormat: args.options.proofFormat })
}

Expand Down
2 changes: 1 addition & 1 deletion lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export interface IVerifyDomainLinkageCredentialArgs {
verifySignatureCallback?: (args: IVerifyCallbackArgs) => Promise<IVerifyCredentialResult>
}

export type StrictPropertyCheck<T, TExpected, TError> = Exclude<keyof T, keyof TExpected> extends never ? {} : TError;
export type StrictPropertyCheck<T, TExpected, TError> = Exclude<keyof T, keyof TExpected> extends never ? unknown : TError;

export interface ICredentialValidation {
status: ValidationStatusEnum;
Expand Down
22 changes: 15 additions & 7 deletions lib/verifier/WellKnownDidVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class WellKnownDidVerifier {
.then((didConfigurationResource: IDidConfigurationResource) =>
this.verifyResource({
configuration: didConfigurationResource,
did: (this.config!.onlyVerifyServiceDid || args.onlyVerifyServiceDid)
did: (this.config?.onlyVerifyServiceDid || args.onlyVerifyServiceDid)
? args.descriptor.id
: undefined, verifySignatureCallback: args.verifySignatureCallback
}))
Expand Down Expand Up @@ -135,8 +135,12 @@ export class WellKnownDidVerifier {
if (new URL(args.origin).protocol !== 'https:') return Promise.reject('origin is not secure')
}

const didConfigurationResource: IDidConfigurationResource = (args.configuration)
const didConfigurationResource: IDidConfigurationResource = args.configuration
// @ts-ignore: We know for sure the config is present
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
? await verifyResourceStructure(args.configuration).then(() => args.configuration!)
// @ts-ignore: We know for sure the origin is present
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
: await fetchWellKnownDidConfiguration(args.origin!)


Expand Down Expand Up @@ -174,7 +178,7 @@ export class WellKnownDidVerifier {
/**
* Verifies the domain linkage credential.
*
* @param credential The domain linkage credential. Types can be JWT or JSONLD.
* @param args The domain linkage credential. Types can be JWT or JSONLD.
* @return {ICredentialValidation}, The validation result.
*/
public async verifyDomainLinkageCredential(args: IVerifyDomainLinkageCredentialArgs): Promise<ICredentialValidation> {
Expand All @@ -185,8 +189,10 @@ export class WellKnownDidVerifier {
if (typeof args.credential === 'string') {
return this.verifyJsonWebTokenProofFormat(args.credential)
.then(() => this.verifyDomainLinkageCredentialStructure((decodeToken(args.credential as string, false) as IJsonWebTokenProofPayload).vc))
.then(() => (args.verifySignatureCallback)
.then(() => args.verifySignatureCallback
? args.verifySignatureCallback({ credential: args.credential, proofFormat: ProofFormatTypesEnum.JSON_WEB_TOKEN })
// @ts-ignore: We know for sure the config is present
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
: this.config!.verifySignatureCallback({ credential: args.credential, proofFormat: ProofFormatTypesEnum.JSON_WEB_TOKEN }))
.then((verificationResult: IVerifyCredentialResult) => {
if (!verificationResult.verified) return Promise.reject({ status: ValidationStatusEnum.INVALID, message: 'Signature is invalid'})
Expand All @@ -196,8 +202,10 @@ export class WellKnownDidVerifier {
}

return this.verifyDomainLinkageCredentialStructure(args.credential as ISignedDomainLinkageCredential)
.then(() => (args.verifySignatureCallback)
.then(() => args.verifySignatureCallback
? args.verifySignatureCallback({ credential: args.credential, proofFormat: ProofFormatTypesEnum.JSON_LD })
// @ts-ignore: We know for sure the config is present
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
: this.config!.verifySignatureCallback({ credential: args.credential, proofFormat: ProofFormatTypesEnum.JSON_LD }))
.then((verificationResult: IVerifyCredentialResult) => {
if (!verificationResult.verified) return Promise.reject({ status: ValidationStatusEnum.INVALID, message: 'Signature is invalid'})
Expand Down Expand Up @@ -331,14 +339,14 @@ export class WellKnownDidVerifier {
if (!credential.issuanceDate) return Promise.reject({ status: ValidationStatusEnum.INVALID, message: 'Property issuanceDate is not present within the credential' })

// Property issuanceDate MUST be a valid date.
if (typeof credential.issuanceDate === 'string' && isNaN(Date.parse(credential.issuanceDate)))
if (/*typeof credential.issuanceDate === 'string' && */isNaN(Date.parse(credential.issuanceDate)))
return Promise.reject({ status: ValidationStatusEnum.INVALID, message: 'Property issuanceDate is not a valid date' })

// Property expirationDate MUST be present.
if (!credential.expirationDate) return Promise.reject({ status: ValidationStatusEnum.INVALID, message: 'Property expirationDate is not present within the credential' })

// Property expirationDate MUST be a valid date.
if (typeof credential.expirationDate === 'string' && isNaN(Date.parse(credential.expirationDate)))
if (/*typeof credential.expirationDate === 'string' && */isNaN(Date.parse(credential.expirationDate)))
return Promise.reject({ status: ValidationStatusEnum.INVALID, message: 'Property expirationDate is not a valid date' })

// Property credentialSubject MUST be present.
Expand Down
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@sphereon/wellknown-dids-client",
"version": "0.1.0",
"description": "",
"description": "Well-known DID client allows to create and verify DID Domain configuration resources",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"license": "Apache-2.0",
Expand All @@ -25,6 +25,7 @@
},
"keywords": [
"DID",
"Well-known DID",
"Domain Linkage",
"DID Configuration Resource"
],
Expand All @@ -36,24 +37,24 @@
"devDependencies": {
"@digitalcredentials/ed25519-signature-2020": "^3.0.2",
"@digitalcredentials/ed25519-verification-key-2020": "^3.2.2",
"@digitalcredentials/jsonld-signatures": "^9.3.1",
"@digitalcredentials/vc": "^4.1.1",
"@types/jest": "^28.1.6",
"@types/node": "^18.6.3",
"did-resolver": "^4.0.0",
"typescript": "^4.6.4",
"ts-node": "^10.9.1",
"@types/node": "^14.18.23",
"@typescript-eslint/eslint-plugin": "^5.31.0",
"@typescript-eslint/parser": "^5.31.0",
"did-resolver": "^4.0.0",
"eslint": "^8.21.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.26.0",
"@types/jest": "^28.1.6",
"ts-jest": "^28.0.7",
"jest": "^28.1.3",
"jsonld-signatures": "^10.0.0",
"nock": "^13.2.9",
"npm-run-all": "^4.1.5",
"prettier": "^2.7.1",
"ts-jest": "^28.0.7",
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
"prettier": "^2.7.1"
},
"prettier": {
"singleQuote": true,
Expand Down
24 changes: 11 additions & 13 deletions test/resources/DocumentLoader.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import fetch from 'cross-fetch';

const { extendContextLoader } = require('@digitalcredentials/jsonld-signatures');
const vc = require('@digitalcredentials/vc');
const { extendContextLoader } = require('jsonld-signatures');

export class DocumentLoader {
getLoader() {
return extendContextLoader(async (url: string) => {
try {
const response = await fetch(url);
if (response.status === 200) {
const document = await response.json();
return {
contextUrl: null,
documentUrl: url,
document,
};
}
} catch (error: any) {
throw new Error(error);
const response = await fetch(url);
if (response.status === 200) {
const document = await response.json();
return {
contextUrl: null,
documentUrl: url,
document,
};
}

const { defaultDocumentLoader } = vc;
Expand Down
5 changes: 1 addition & 4 deletions test/resources/issuers/VcJsIssuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { Ed25519Signature2020 } from '@digitalcredentials/ed25519-signature-2020
// @ts-ignore
import { Ed25519VerificationKey2020 } from '@digitalcredentials/ed25519-verification-key-2020';

import {
IIssueCallbackArgs,
ISignedDomainLinkageCredential
} from '../../../lib/types';
import { IIssueCallbackArgs, ISignedDomainLinkageCredential } from '../../../lib/types';
import { DocumentLoader } from '../DocumentLoader';

const vc = require('@digitalcredentials/vc');
Expand Down
6 changes: 1 addition & 5 deletions test/resources/verifiers/VcJsVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import { Ed25519Signature2020 } from '@digitalcredentials/ed25519-signature-2020
// @ts-ignore
import { Ed25519VerificationKey2020 } from '@digitalcredentials/ed25519-verification-key-2020';

import {
ISignedDomainLinkageCredential,
IVerifyCallbackArgs,
IVerifyCredentialResult
} from '../../../lib/types';
import { ISignedDomainLinkageCredential, IVerifyCallbackArgs, IVerifyCredentialResult } from '../../../lib/types';
import { DocumentLoader } from '../DocumentLoader';

const vc = require('@digitalcredentials/vc');
Expand Down
52 changes: 21 additions & 31 deletions test/verifier.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import nock from 'nock';

import { CONTEXT_URLS } from '../lib/constants';
import {
IVerifyCallbackArgs,
IVerifyCredentialResult,
ServiceTypesEnum,
ValidationStatusEnum
} from '../lib/types';
import { IVerifyCallbackArgs, IVerifyCredentialResult, ServiceTypesEnum, ValidationStatusEnum } from '../lib/types';
import { WellKnownDidVerifier } from '../lib/verifier/WellKnownDidVerifier';

import { VcJsVerifier } from './resources/verifiers/VcJsVerifier';
Expand Down Expand Up @@ -380,34 +375,29 @@ describe('Domain Linkage Verifier', () => {
});

const signedCredential = {
'@context': [
'https://www.w3.org/2018/credentials/v1',
'https://identity.foundation/.well-known/did-configuration/v1'
],
'issuer': 'did:key:z6MkoTHsgNNrby8JzCNQ1iRLyW5QQ6R8Xuu6AA8igGrMVPUM',
'issuanceDate': '2020-12-04T14:08:28-06:00',
'expirationDate': '2025-12-04T14:08:28-06:00',
'type': [
'VerifiableCredential',
'DomainLinkageCredential'
],
'credentialSubject': {
'id': 'did:key:z6MkoTHsgNNrby8JzCNQ1iRLyW5QQ6R8Xuu6AA8igGrMVPUM',
'origin': 'https://identity.foundation'
'@context': ['https://www.w3.org/2018/credentials/v1', 'https://identity.foundation/.well-known/did-configuration/v1'],
issuer: 'did:key:z6MkoTHsgNNrby8JzCNQ1iRLyW5QQ6R8Xuu6AA8igGrMVPUM',
issuanceDate: '2020-12-04T14:08:28-06:00',
expirationDate: '2025-12-04T14:08:28-06:00',
type: ['VerifiableCredential', 'DomainLinkageCredential'],
credentialSubject: {
id: 'did:key:z6MkoTHsgNNrby8JzCNQ1iRLyW5QQ6R8Xuu6AA8igGrMVPUM',
origin: 'https://identity.foundation',
},
'proof': {
'type': 'Ed25519Signature2018',
'created': '2020-12-04T20:08:28.540Z',
'jws': 'eyJhbGciOiJFZERTQSIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19..D0eDhglCMEjxDV9f_SNxsuU-r3ZB9GR4vaM9TYbyV7yzs1WfdUyYO8rFZdedHbwQafYy8YOpJ1iJlkSmB4JaDQ',
'proofPurpose': 'assertionMethod',
'verificationMethod': 'did:key:z6MkoTHsgNNrby8JzCNQ1iRLyW5QQ6R8Xuu6AA8igGrMVPUM#z6MkoTHsgNNrby8JzCNQ1iRLyW5QQ6R8Xuu6AA8igGrMVPUM'
}
}
proof: {
type: 'Ed25519Signature2018',
created: '2020-12-04T20:08:28.540Z',
jws: 'eyJhbGciOiJFZERTQSIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19..D0eDhglCMEjxDV9f_SNxsuU-r3ZB9GR4vaM9TYbyV7yzs1WfdUyYO8rFZdedHbwQafYy8YOpJ1iJlkSmB4JaDQ',
proofPurpose: 'assertionMethod',
verificationMethod: 'did:key:z6MkoTHsgNNrby8JzCNQ1iRLyW5QQ6R8Xuu6AA8igGrMVPUM#z6MkoTHsgNNrby8JzCNQ1iRLyW5QQ6R8Xuu6AA8igGrMVPUM',
},
};

// Will throw signature is invalid as this is just a test to check the integration
await expect(
verifier.verifyDomainLinkageCredential({ credential: signedCredential })
).rejects.toEqual({ status: ValidationStatusEnum.INVALID, message: 'Signature is invalid' });
await expect(verifier.verifyDomainLinkageCredential({ credential: signedCredential })).rejects.toEqual({
status: ValidationStatusEnum.INVALID,
message: 'Signature is invalid',
});
});
});
});
6 changes: 5 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
/* Print names of files part of the compilation. */,
"pretty": true,

"types": ["jest", "node"]
"types": ["jest", "node"],
"lib": [
"es6",
"es2020.promise"
]
},

"include": [
Expand Down
Loading

0 comments on commit 9ce891e

Please sign in to comment.