Skip to content

Commit

Permalink
chore: working towards strict mode enabled for SIOP
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Jan 22, 2024
1 parent 8b7d14b commit 7fba932
Show file tree
Hide file tree
Showing 71 changed files with 544 additions and 384 deletions.
38 changes: 38 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
moduleNameMapper: {
"^jose/(.*)$": "<rootDir>/node_modules/.pnpm/[email protected]/node_modules/jose/dist/node/cjs/$1",
},
rootDir: ".",
// roots: ["<rootDir>/src/", "<rootDir>/test/"],
testMatch: ["**/?(*.)+(spec|test).+(ts|tsx|js)"],
transform: {
"^.+\\.(ts|tsx)?$": "ts-jest",
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json"],
coverageDirectory: "./coverage/",
collectCoverageFrom: [
"packages/**/src/**/*.ts",
"packages/**/lib/**/*.ts",
"!**/examples/**",
"!packages/cli/**",
"!**/types/**",
"!**/dist/**",
"!**/coverage/**",
"!**/node_modules/**/__tests__/**",
"!**/node_modules/**/*.test.ts",
"!**/node_modules/**",
"!**/packages/**/index.ts",
"!**/src/schemas/**",
"!**/src/**/*.d.ts",
"!jest.config.cjs",
"!**/generator/**",
"!index.ts",

],
collectCoverage: true,
reporters: ["default", ["jest-junit", { outputDirectory: "./coverage" }]],
"automock": false,
"verbose": true
};
1 change: 1 addition & 0 deletions jest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"preset": "ts-jest",
"moduleFileExtensions": [
"js",
"ts",
"tsx",
"js",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"build": "pnpm -r --stream build",
"build:clean": "lerna clean -y && pnpm install && lerna run build:clean --concurrency 1",
"test:ci": "jest --config=jest.json",
"test": "jest --verbose --config=jest.json --coverage=true --detectOpenHandles",
"test": "jest --verbose --config=jest.json --coverage=true --detectOpenHandles --maxWorkers=1",
"clean": "rimraf --glob **/dist **/coverage **/pnpm-lock.yaml packages/**/node_modules node_modules packages/**/tsconfig.tsbuildinfo",
"publish:latest": "lerna publish --conventional-commits --include-merged-tags --create-release github --yes --dist-tag latest --registry https://registry.npmjs.org",
"publish:next": "lerna publish --conventional-prerelease --force-publish --canary --no-git-tag-version --include-merged-tags --preid next --pre-dist-tag next --yes --registry https://registry.npmjs.org",
Expand Down
12 changes: 6 additions & 6 deletions packages/callback-example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
"compilerOptions": {
"rootDir": "./lib",
"outDir": "./dist",
"declarationDir": "./dist"
"declarationDir": "./dist",
},
"references": [
{
"path": "../common"
"path": "../common",
},
{
"path": "../client"
"path": "../client",
},
{
"path": "../issuer"
}
]
"path": "../issuer",
},
],
}
4 changes: 2 additions & 2 deletions packages/client/lib/AccessTokenClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ export class AccessTokenClient {
metadata: metadata
? metadata
: issuerOpts?.fetchMetadata
? await MetadataClient.retrieveAllMetadata(issuerOpts.issuer, { errorOnNotFound: false })
: undefined,
? await MetadataClient.retrieveAllMetadata(issuerOpts.issuer, { errorOnNotFound: false })
: undefined,
});

return this.sendAuthCode(requestTokenURL, accessTokenRequest);
Expand Down
4 changes: 2 additions & 2 deletions packages/client/lib/CredentialOfferClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ export class CredentialOfferClient {
uriTypeProperties: isUri
? ['credential_offer_uri']
: version >= OpenId4VCIVersion.VER_1_0_11
? ['credential_issuer', 'credential_type']
: ['issuer', 'credential_type'],
? ['credential_issuer', 'credential_type']
: ['issuer', 'credential_type'],
param,
version,
});
Expand Down
10 changes: 6 additions & 4 deletions packages/client/lib/OpenID4VCIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,9 @@ export class OpenID4VCIClient {
} else if (!response.successBody) {
debug(`Access token error. No success body`);
throw Error(
`Retrieving an access token from ${this._endpointMetadata
?.token_endpoint} for issuer ${this.getIssuer()} failed as there was no success response body`,
`Retrieving an access token from ${
this._endpointMetadata?.token_endpoint
} for issuer ${this.getIssuer()} failed as there was no success response body`,
);
}
this._accessTokenResponse = response.successBody;
Expand Down Expand Up @@ -459,8 +460,9 @@ export class OpenID4VCIClient {
} else if (!response.successBody) {
debug(`Credential request error. No success body`);
throw Error(
`Retrieving a credential from ${this._endpointMetadata
?.credential_endpoint} for issuer ${this.getIssuer()} failed as there was no success response body`,
`Retrieving a credential from ${
this._endpointMetadata?.credential_endpoint
} for issuer ${this.getIssuer()} failed as there was no success response body`,
);
}
return response.successBody;
Expand Down
2 changes: 1 addition & 1 deletion packages/client/lib/__tests__/AuthzFlowType.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AuthzFlowType, CredentialOfferPayload } from '@sphereon/oid4vc-common';
import { AuthzFlowType, CredentialOfferPayload } from '../../../common/lib';

//todo: this file is just testing v9, we probably want to add v11 tests here as well
describe('Authorization Flow Type determination', () => {
Expand Down
14 changes: 7 additions & 7 deletions packages/client/lib/__tests__/CredentialRequestClient.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { KeyObject } from 'crypto';

import * as jose from 'jose';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import nock from 'nock';

import { CredentialRequestClientBuilder, MetadataClient, ProofOfPossessionBuilder } from '..';
import {
Alg,
EndpointMetadata,
Expand All @@ -10,13 +16,7 @@ import {
ProofOfPossession,
URL_NOT_VALID,
WellKnownEndpoints,
} from '@sphereon/oid4vc-common';
import * as jose from 'jose';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import nock from 'nock';

import { CredentialRequestClientBuilder, MetadataClient, ProofOfPossessionBuilder } from '..';
} from '../../../common/lib';
import { CredentialOfferClient } from '../CredentialOfferClient';

import { IDENTIPROOF_ISSUER_URL, IDENTIPROOF_OID4VCI_METADATA, INITIATION_TEST, WALT_OID4VCI_METADATA } from './MetadataMocks';
Expand Down
4 changes: 1 addition & 3 deletions packages/client/lib/__tests__/MetadataClient.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { getIssuerFromCredentialOfferPayload, WellKnownEndpoints } from '@sphereon/oid4vc-common';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import nock from 'nock';

import { getIssuerFromCredentialOfferPayload, WellKnownEndpoints } from '../../../common/lib';
import { CredentialOfferClient } from '../CredentialOfferClient';
import { MetadataClient } from '../MetadataClient';

Expand Down
8 changes: 4 additions & 4 deletions packages/client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"declarationDir": "dist",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "Node"
"moduleResolution": "Node",
},
"references": [
{
"path": "../common"
}
]
"path": "../common",
},
],
}
4 changes: 2 additions & 2 deletions packages/common/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"outDir": "./dist",
"declarationDir": "./dist",
"esModuleInterop": true,
"moduleResolution": "Node"
}
"moduleResolution": "Node",
},
}
13 changes: 9 additions & 4 deletions packages/issuer-rest/lib/IssuerTokenEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,15 @@ export const verifyTokenRequest = <T extends object>({
})
} catch (error) {
if (error instanceof TokenError) {
return sendErrorResponse(response, error.statusCode, {
error: error.responseError,
error_description: error.getDescription(),
})
return sendErrorResponse(
response,
error.statusCode,
{
error: error.responseError,
error_description: error.getDescription(),
},
error,
)
} else {
return sendErrorResponse(response, 400, { error: TokenErrorResponse.invalid_request, error_description: (error as Error).message }, error)
}
Expand Down
20 changes: 10 additions & 10 deletions packages/issuer-rest/lib/__tests__/ClientIssuerIT.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { KeyObject } from 'crypto'

import * as didKeyDriver from '@digitalcredentials/did-method-key'
import { VcIssuer } from '@sphereon/oid4vci-issuer/dist/VcIssuer'
import { CredentialSupportedBuilderV1_11, VcIssuerBuilder } from '@sphereon/oid4vci-issuer/dist/builder'
import { MemoryStates } from '@sphereon/oid4vci-issuer/dist/state-manager'
import { ExpressBuilder, ExpressSupport } from '@sphereon/ssi-express-support'
import { IProofPurpose, IProofType } from '@sphereon/ssi-types'
import { DIDDocument } from 'did-resolver'
import * as jose from 'jose'

import { OpenID4VCIClient } from '../../../client/lib'
import {
AccessTokenResponse,
Alg,
Expand All @@ -11,16 +20,7 @@ import {
JWTHeader,
JWTPayload,
OpenId4VCIVersion,
} from '@sphereon/oid4vc-common'
import { OpenID4VCIClient } from '@sphereon/oid4vci-client'
import { VcIssuer } from '@sphereon/oid4vci-issuer/dist/VcIssuer'
import { CredentialSupportedBuilderV1_11, VcIssuerBuilder } from '@sphereon/oid4vci-issuer/dist/builder'
import { MemoryStates } from '@sphereon/oid4vci-issuer/dist/state-manager'
import { ExpressBuilder, ExpressSupport } from '@sphereon/ssi-express-support'
import { IProofPurpose, IProofType } from '@sphereon/ssi-types'
import { DIDDocument } from 'did-resolver'
import * as jose from 'jose'

} from '../../../common/lib'
import { OID4VCIServer } from '../OID4VCIServer'

const ISSUER_URL = 'http://localhost:3456/test'
Expand Down
10 changes: 5 additions & 5 deletions packages/issuer-rest/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"rootDir": "./lib",
"outDir": "./dist",
"declarationDir": "./dist",
"esModuleInterop": true
"esModuleInterop": true,
},
"references": [
{
"path": "../common"
"path": "../common",
},
{
"path": "../issuer"
}
]
"path": "../issuer",
},
],
}
2 changes: 2 additions & 0 deletions packages/issuer/lib/functions/CredentialOfferUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export function createCredentialOfferObject(
if (opts?.credentialOffer) {
credential_offer = {
...opts.credentialOffer,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
credentials: opts.credentialOffer?.credentials ?? issuerMetadata?.credentials_supported,
}
} else {
Expand Down
8 changes: 4 additions & 4 deletions packages/issuer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"compilerOptions": {
"rootDir": "./lib",
"outDir": "./dist",
"declarationDir": "./dist"
"declarationDir": "./dist",
},
"references": [
{
"path": "../common"
}
]
"path": "../common",
},
],
}
2 changes: 1 addition & 1 deletion packages/siopv2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ const op = OP.builder()
scopesSupported: [Scope.OPENID_DIDAUTHN, Scope.OPENID],
subjectTypesSupported: [SubjectType.PAIRWISE],
subjectSyntaxTypesSupported: ['did:ethr'],
passBy: PassBy.VALUE,
requestPassBy: PassBy.VALUE,
})
.build();
```
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IPresentationDefinition, SdJwtDecodedVerifiableCredentialWithKbJwtInput
import { OriginalVerifiableCredential } from '@sphereon/ssi-types';
import { IVerifyCallbackArgs, IVerifyCredentialResult } from '@sphereon/wellknown-dids-client';

import { ResponseType } from '../../common/lib';
import {
OP,
PassBy,
Expand All @@ -13,7 +14,6 @@ import {
PresentationVerificationCallback,
PropertyTarget,
ResponseIss,
ResponseType,
RevocationVerification,
RP,
Scope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import jwt_decode from 'jwt-decode';
import moment from 'moment';
import { v4 as uuidv4 } from 'uuid';

import { ResponseType } from '../../common/lib';
import {
assertValidMetadata,
base64ToHexString,
DiscoveryMetadataPayload,
KeyCurve,
KeyType,
ResponseIss,
ResponseType,
RPRegistrationMetadataPayload,
Scope,
SigningAlgo,
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { KeyLike } from 'jose';
import nock from 'nock';
import * as u8a from 'uint8arrays';

import { ResponseType } from '../../../common/lib';
import {
AuthorizationRequest,
AuthorizationResponse,
Expand All @@ -19,7 +20,6 @@ import {
PresentationVerificationCallback,
PropertyTarget,
ResponseMode,
ResponseType,
RevocationVerification,
RP,
SigningAlgo,
Expand Down
27 changes: 0 additions & 27 deletions packages/siopv2/jest.config.cjs

This file was deleted.

Loading

0 comments on commit 7fba932

Please sign in to comment.