From 2d5cd5ad429aa5bf7a1864ce6a09bf2196e37d63 Mon Sep 17 00:00:00 2001 From: Niels Klomp Date: Thu, 21 Dec 2023 21:05:01 +0100 Subject: [PATCH 1/2] feat: Add static bearer token callback function option --- packages/agent-config/CHANGELOG.md | 4 - .../contact-manager-rest-api/CHANGELOG.md | 4 - packages/contact-manager/CHANGELOG.md | 4 - packages/data-store/CHANGELOG.md | 4 - packages/data-store/tsconfig.json | 3 +- packages/dev/CHANGELOG.md | 4 - packages/issuance-branding/CHANGELOG.md | 4 - packages/kv-store/CHANGELOG.md | 4 - packages/ms-authenticator/CHANGELOG.md | 4 - packages/ms-request-api/CHANGELOG.md | 4 - packages/oid4vci-issuer-rest-api/CHANGELOG.md | 4 - .../oid4vci-issuer-rest-client/CHANGELOG.md | 4 - .../src/agent/OID4VCIRestClient.ts | 4 +- .../src/types/IOID4VCIRestClient.ts | 2 +- packages/oid4vci-issuer-store/CHANGELOG.md | 4 - packages/oid4vci-issuer/CHANGELOG.md | 4 - packages/presentation-exchange/CHANGELOG.md | 4 - packages/qr-code-generator/CHANGELOG.md | 4 - packages/siopv2-oid4vp-common/CHANGELOG.md | 4 - packages/siopv2-oid4vp-op-auth/CHANGELOG.md | 4 - packages/siopv2-oid4vp-rp-auth/CHANGELOG.md | 4 - .../siopv2-oid4vp-rp-rest-api/CHANGELOG.md | 4 - .../siopv2-oid4vp-rp-rest-client/CHANGELOG.md | 4 - .../src/agent/SIOPv2OID4VPRPRestClient.ts | 4 +- .../src/types/ISIOPv2OID4VPRPRestClient.ts | 2 +- packages/ssi-express-support/CHANGELOG.md | 4 - .../ssi-express-support/src/express-utils.ts | 29 +- packages/ssi-sdk-core/CHANGELOG.md | 4 - packages/ssi-sdk-core/src/utils/database.ts | 4 +- packages/ssi-types/CHANGELOG.md | 4 - .../uni-resolver-registrar-api/CHANGELOG.md | 4 - packages/vc-handler-ld-local/CHANGELOG.md | 4 - .../CHANGELOG.md | 4 - .../CHANGELOG.md | 4 - packages/vc-status-list/CHANGELOG.md | 4 - .../CHANGELOG.md | 4 - .../CHANGELOG.md | 4 - packages/w3c-vc-api/CHANGELOG.md | 4 - packages/w3c-vc-api/__tests__/jwt.test.ts | 454 ++++++++++++++++++ packages/w3c-vc-api/package.json | 1 + packages/web3-provider-headless/CHANGELOG.md | 4 - .../web3-provider-headless/src/rpc-server.ts | 2 +- packages/wellknown-did-issuer/CHANGELOG.md | 4 - packages/wellknown-did-verifier/CHANGELOG.md | 4 - pnpm-lock.yaml | 7 + 45 files changed, 491 insertions(+), 157 deletions(-) create mode 100644 packages/w3c-vc-api/__tests__/jwt.test.ts diff --git a/packages/agent-config/CHANGELOG.md b/packages/agent-config/CHANGELOG.md index ef877e9a0..be66ba4b3 100644 --- a/packages/agent-config/CHANGELOG.md +++ b/packages/agent-config/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.agent-config - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.agent-config diff --git a/packages/contact-manager-rest-api/CHANGELOG.md b/packages/contact-manager-rest-api/CHANGELOG.md index 5d7b51b20..e65731a54 100644 --- a/packages/contact-manager-rest-api/CHANGELOG.md +++ b/packages/contact-manager-rest-api/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.contact-manager-rest-api - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.contact-manager-rest-api diff --git a/packages/contact-manager/CHANGELOG.md b/packages/contact-manager/CHANGELOG.md index dc389e5a8..5562f5d1a 100644 --- a/packages/contact-manager/CHANGELOG.md +++ b/packages/contact-manager/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.contact-manager - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.contact-manager diff --git a/packages/data-store/CHANGELOG.md b/packages/data-store/CHANGELOG.md index 392eb32a1..683ba6177 100644 --- a/packages/data-store/CHANGELOG.md +++ b/packages/data-store/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.data-store - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.data-store diff --git a/packages/data-store/tsconfig.json b/packages/data-store/tsconfig.json index 42efb4cff..c489f0f11 100644 --- a/packages/data-store/tsconfig.json +++ b/packages/data-store/tsconfig.json @@ -11,7 +11,8 @@ "references": [ { "path": "../ssi-sdk-core" - }, { + }, + { "path": "../ssi-types" } ] diff --git a/packages/dev/CHANGELOG.md b/packages/dev/CHANGELOG.md index 35f50bb39..1388bbed1 100644 --- a/packages/dev/CHANGELOG.md +++ b/packages/dev/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.dev - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.dev diff --git a/packages/issuance-branding/CHANGELOG.md b/packages/issuance-branding/CHANGELOG.md index 1f1263ea0..04809f031 100644 --- a/packages/issuance-branding/CHANGELOG.md +++ b/packages/issuance-branding/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.issuance-branding - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.issuance-branding diff --git a/packages/kv-store/CHANGELOG.md b/packages/kv-store/CHANGELOG.md index 2c706136c..b52ffbb9a 100644 --- a/packages/kv-store/CHANGELOG.md +++ b/packages/kv-store/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.kv-store-temp - - - - ## [0.17.4](https://github.com/uport-project/veramo/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.kv-store-temp diff --git a/packages/ms-authenticator/CHANGELOG.md b/packages/ms-authenticator/CHANGELOG.md index a24f51e2d..71de42a8e 100644 --- a/packages/ms-authenticator/CHANGELOG.md +++ b/packages/ms-authenticator/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.ms-authenticator - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.ms-authenticator diff --git a/packages/ms-request-api/CHANGELOG.md b/packages/ms-request-api/CHANGELOG.md index 62ba945c5..7b54a79b4 100644 --- a/packages/ms-request-api/CHANGELOG.md +++ b/packages/ms-request-api/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.ms-request-api - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.ms-request-api diff --git a/packages/oid4vci-issuer-rest-api/CHANGELOG.md b/packages/oid4vci-issuer-rest-api/CHANGELOG.md index 3fbd4b37b..63e1dad51 100644 --- a/packages/oid4vci-issuer-rest-api/CHANGELOG.md +++ b/packages/oid4vci-issuer-rest-api/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.oid4vci-issuer-rest-api - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.oid4vci-issuer-rest-api diff --git a/packages/oid4vci-issuer-rest-client/CHANGELOG.md b/packages/oid4vci-issuer-rest-client/CHANGELOG.md index df3cddaaf..5db2966ff 100644 --- a/packages/oid4vci-issuer-rest-client/CHANGELOG.md +++ b/packages/oid4vci-issuer-rest-client/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.oid4vci-issuer-rest-client - - - - ## [0.17.4](https://github.com/Sphereon-OpenSource/ssi-sdk/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.oid4vci-issuer-rest-client diff --git a/packages/oid4vci-issuer-rest-client/src/agent/OID4VCIRestClient.ts b/packages/oid4vci-issuer-rest-client/src/agent/OID4VCIRestClient.ts index 5659094b7..463288b1c 100644 --- a/packages/oid4vci-issuer-rest-client/src/agent/OID4VCIRestClient.ts +++ b/packages/oid4vci-issuer-rest-client/src/agent/OID4VCIRestClient.ts @@ -37,10 +37,10 @@ export class OID4VCIRestClient implements IAgentPlugin { Accept: 'application/json', } if (this.authOpts?.enabled === true) { - if (!this.authOpts.staticBearerToken) { + if (!this.authOpts.bearerToken) { throw Error(`Cannot have authentication enabled, whilst not enabling static bearer tokens at this point`) } - headers.Authorization = `Bearer ${this.authOpts.staticBearerToken}` + headers.Authorization = `Bearer ${this.authOpts.bearerToken}` } return headers } diff --git a/packages/oid4vci-issuer-rest-client/src/types/IOID4VCIRestClient.ts b/packages/oid4vci-issuer-rest-client/src/types/IOID4VCIRestClient.ts index 833dfdd44..45d1f043d 100644 --- a/packages/oid4vci-issuer-rest-client/src/types/IOID4VCIRestClient.ts +++ b/packages/oid4vci-issuer-rest-client/src/types/IOID4VCIRestClient.ts @@ -18,7 +18,7 @@ export interface IOID4VCIClientCreateOfferUriRequestArgs extends IOID4VCIClientC export interface IRestClientAuthenticationOpts { enabled?: boolean - staticBearerToken?: string + bearerToken?: () => Promise | string } export interface IOID4VCIClientGetIssueStatusArgs { diff --git a/packages/oid4vci-issuer-store/CHANGELOG.md b/packages/oid4vci-issuer-store/CHANGELOG.md index 75f04ec9b..a1b217663 100644 --- a/packages/oid4vci-issuer-store/CHANGELOG.md +++ b/packages/oid4vci-issuer-store/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.oid4vci-issuer-store - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.oid4vci-issuer-store diff --git a/packages/oid4vci-issuer/CHANGELOG.md b/packages/oid4vci-issuer/CHANGELOG.md index 0468aa69b..acb4b0fe5 100644 --- a/packages/oid4vci-issuer/CHANGELOG.md +++ b/packages/oid4vci-issuer/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.oid4vci-issuer - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.oid4vci-issuer diff --git a/packages/presentation-exchange/CHANGELOG.md b/packages/presentation-exchange/CHANGELOG.md index b902dd7bb..5c685a626 100644 --- a/packages/presentation-exchange/CHANGELOG.md +++ b/packages/presentation-exchange/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.presentation-exchange - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.presentation-exchange diff --git a/packages/qr-code-generator/CHANGELOG.md b/packages/qr-code-generator/CHANGELOG.md index c9873d1a7..cf6d91126 100644 --- a/packages/qr-code-generator/CHANGELOG.md +++ b/packages/qr-code-generator/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.qr-code-generator - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.qr-code-generator diff --git a/packages/siopv2-oid4vp-common/CHANGELOG.md b/packages/siopv2-oid4vp-common/CHANGELOG.md index 5549a5ac6..9d4857c30 100644 --- a/packages/siopv2-oid4vp-common/CHANGELOG.md +++ b/packages/siopv2-oid4vp-common/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.siopv2-oid4vp-common - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.siopv2-oid4vp-common diff --git a/packages/siopv2-oid4vp-op-auth/CHANGELOG.md b/packages/siopv2-oid4vp-op-auth/CHANGELOG.md index 889a3c850..39a10bb8c 100644 --- a/packages/siopv2-oid4vp-op-auth/CHANGELOG.md +++ b/packages/siopv2-oid4vp-op-auth/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.siopv2-oid4vp-op-auth - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.siopv2-oid4vp-op-auth diff --git a/packages/siopv2-oid4vp-rp-auth/CHANGELOG.md b/packages/siopv2-oid4vp-rp-auth/CHANGELOG.md index 26b91369f..e16203b30 100644 --- a/packages/siopv2-oid4vp-rp-auth/CHANGELOG.md +++ b/packages/siopv2-oid4vp-rp-auth/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.siopv2-oid4vp-rp-auth - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.siopv2-oid4vp-rp-auth diff --git a/packages/siopv2-oid4vp-rp-rest-api/CHANGELOG.md b/packages/siopv2-oid4vp-rp-rest-api/CHANGELOG.md index d146e4e35..8ed97c110 100644 --- a/packages/siopv2-oid4vp-rp-rest-api/CHANGELOG.md +++ b/packages/siopv2-oid4vp-rp-rest-api/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.siopv2-oid4vp-rp-rest-api - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.siopv2-oid4vp-rp-rest-api diff --git a/packages/siopv2-oid4vp-rp-rest-client/CHANGELOG.md b/packages/siopv2-oid4vp-rp-rest-client/CHANGELOG.md index 55e5c2938..1f62c98d4 100644 --- a/packages/siopv2-oid4vp-rp-rest-client/CHANGELOG.md +++ b/packages/siopv2-oid4vp-rp-rest-client/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.siopv2-oid4vp-rp-rest-client - - - - ## [0.17.4](https://github.com/Sphereon-OpenSource/ssi-sdk/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.siopv2-oid4vp-rp-rest-client diff --git a/packages/siopv2-oid4vp-rp-rest-client/src/agent/SIOPv2OID4VPRPRestClient.ts b/packages/siopv2-oid4vp-rp-rest-client/src/agent/SIOPv2OID4VPRPRestClient.ts index 247a06ba8..e08f54604 100644 --- a/packages/siopv2-oid4vp-rp-rest-client/src/agent/SIOPv2OID4VPRPRestClient.ts +++ b/packages/siopv2-oid4vp-rp-rest-client/src/agent/SIOPv2OID4VPRPRestClient.ts @@ -39,10 +39,10 @@ export class SIOPv2OID4VPRPRestClient implements IAgentPlugin { Accept: 'application/json', } if (this.authOpts?.enabled === true) { - if (!this.authOpts.staticBearerToken) { + if (!this.authOpts.bearerToken) { throw Error(`Cannot have authentication enabled, whilst not enabling static bearer tokens at this point`) } - headers.Authorization = `Bearer ${this.authOpts.staticBearerToken}` + headers.Authorization = `Bearer ${this.authOpts.bearerToken}` } return headers } diff --git a/packages/siopv2-oid4vp-rp-rest-client/src/types/ISIOPv2OID4VPRPRestClient.ts b/packages/siopv2-oid4vp-rp-rest-client/src/types/ISIOPv2OID4VPRPRestClient.ts index bc57a215a..f4f3b6a64 100644 --- a/packages/siopv2-oid4vp-rp-rest-client/src/types/ISIOPv2OID4VPRPRestClient.ts +++ b/packages/siopv2-oid4vp-rp-rest-client/src/types/ISIOPv2OID4VPRPRestClient.ts @@ -29,7 +29,7 @@ export interface ISiopClientGetAuthStatusArgs { export interface Siopv2RestClientAuthenticationOpts { enabled?: boolean - staticBearerToken?: string + bearerToken?: () => Promise | string } export interface Siopv2RestClientOpts { diff --git a/packages/ssi-express-support/CHANGELOG.md b/packages/ssi-express-support/CHANGELOG.md index ee8c02710..08a4d0c8e 100644 --- a/packages/ssi-express-support/CHANGELOG.md +++ b/packages/ssi-express-support/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-express-support - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-express-support diff --git a/packages/ssi-express-support/src/express-utils.ts b/packages/ssi-express-support/src/express-utils.ts index c70227a48..6c1e54aca 100644 --- a/packages/ssi-express-support/src/express-utils.ts +++ b/packages/ssi-express-support/src/express-utils.ts @@ -1,16 +1,20 @@ import express, { NextFunction } from 'express' export function sendErrorResponse(response: express.Response, statusCode: number, message: string | object, error?: any) { - if (!message) { + let msg = message + if (!msg) { console.error('Message was null when calling sendErrorResponse. This should not happen') - message = 'An unexpected error occurred' + msg = 'An unexpected error occurred' statusCode = 500 } else { - console.error(`sendErrorResponse: ${typeof message === 'string' ? message : JSON.stringify(message)}`) + console.error(`sendErrorResponse: ${typeof msg === 'string' ? msg : JSON.stringify(msg)}`) } if (error) { - console.error(JSON.stringify(error)) + if (error instanceof Error) { + console.error(error.message) + } + console.error(`error: ${JSON.stringify(error)}`) } - if(statusCode == 500) { + if (statusCode === 500) { console.error(Error().stack) } if (response.headersSent) { @@ -18,19 +22,22 @@ export function sendErrorResponse(response: express.Response, statusCode: number return response } response.statusCode = statusCode - if (typeof message === 'string' && !message.startsWith('{')) { - message = { error: message } + if (typeof msg === 'string' && !msg.startsWith('{')) { + msg = { error: msg } } - if (typeof message === 'string' && message.startsWith('{')) { + if (typeof msg === 'string' && msg.startsWith('{')) { response.header('Content-Type', 'application/json') - return response.status(statusCode).end(message) + return response.status(statusCode).end(msg) } - return response.status(statusCode).json(message) + return response.status(statusCode).json(msg) } export const jsonErrorHandler = (err: any, req: express.Request, res: express.Response, next: NextFunction) => { const statusCode: number = 'statusCode' in err ? err.statusCode : 500 - const errorMsg = typeof err === 'string' ? err : err.message ?? err + let errorMsg = typeof err === 'string' ? err : err.message ?? err + if (typeof errorMsg !== 'string') { + errorMsg = JSON.stringify(errorMsg) + } if (res.headersSent) { console.log('Headers already sent, when calling error handler. Will defer to next error handler') console.log(`Error was: ${JSON.stringify(err)}`) diff --git a/packages/ssi-sdk-core/CHANGELOG.md b/packages/ssi-sdk-core/CHANGELOG.md index d84bcc76b..e11f96d0d 100644 --- a/packages/ssi-sdk-core/CHANGELOG.md +++ b/packages/ssi-sdk-core/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.core - - - - ## [0.17.4](https://github.com/Sphereon-OpenSource/ssi-sdk/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.core diff --git a/packages/ssi-sdk-core/src/utils/database.ts b/packages/ssi-sdk-core/src/utils/database.ts index 68e1db58d..fb5e35863 100644 --- a/packages/ssi-sdk-core/src/utils/database.ts +++ b/packages/ssi-sdk-core/src/utils/database.ts @@ -3,8 +3,8 @@ export const flattenArray = (args: { items: Array> }): Array export const flattenMigrations = (args: { migrations: Array> }): Array => args.migrations.flat() as Array type QueryRunnerType = { - query(query: string, parameters: any[] | undefined, useStructuredResult: true): Promise - query(query: string, parameters?: any[]): Promise + query(query: string, parameters: any[] | undefined, useStructuredResult: true): Promise + query(query: string, parameters?: any[]): Promise } /** diff --git a/packages/ssi-types/CHANGELOG.md b/packages/ssi-types/CHANGELOG.md index 0b5d1f57e..dab383986 100644 --- a/packages/ssi-types/CHANGELOG.md +++ b/packages/ssi-types/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-types - - - - ## [0.17.4](https://github.com/Sphereon-OpenSource/ssi-sdk/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-types diff --git a/packages/uni-resolver-registrar-api/CHANGELOG.md b/packages/uni-resolver-registrar-api/CHANGELOG.md index 6dc8df798..3c96b7e79 100644 --- a/packages/uni-resolver-registrar-api/CHANGELOG.md +++ b/packages/uni-resolver-registrar-api/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.uni-resolver-registrar-api - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.uni-resolver-registrar-api diff --git a/packages/vc-handler-ld-local/CHANGELOG.md b/packages/vc-handler-ld-local/CHANGELOG.md index f454aebc4..4e6534f2f 100644 --- a/packages/vc-handler-ld-local/CHANGELOG.md +++ b/packages/vc-handler-ld-local/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.vc-handler-ld-local - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.vc-handler-ld-local diff --git a/packages/vc-status-list-issuer-drivers/CHANGELOG.md b/packages/vc-status-list-issuer-drivers/CHANGELOG.md index 11695b307..779dc0891 100644 --- a/packages/vc-status-list-issuer-drivers/CHANGELOG.md +++ b/packages/vc-status-list-issuer-drivers/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.vc-status-list-issuer-drivers - - - - ## [0.17.4](https://github.com/Sphereon-OpenSource/ssi-sdk/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.vc-status-list-issuer-drivers diff --git a/packages/vc-status-list-issuer-rest-api/CHANGELOG.md b/packages/vc-status-list-issuer-rest-api/CHANGELOG.md index c74725a4e..3d2353f40 100644 --- a/packages/vc-status-list-issuer-rest-api/CHANGELOG.md +++ b/packages/vc-status-list-issuer-rest-api/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.vc-status-list-issuer-rest-api - - - - ## [0.17.4](https://github.com/Sphereon-OpenSource/ssi-sdk/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.vc-status-list-issuer-rest-api diff --git a/packages/vc-status-list/CHANGELOG.md b/packages/vc-status-list/CHANGELOG.md index 97acb7d7f..2adcb5790 100644 --- a/packages/vc-status-list/CHANGELOG.md +++ b/packages/vc-status-list/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.vc-status-list - - - - ## [0.17.4](https://github.com/Sphereon-OpenSource/ssi-sdk/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.vc-status-list diff --git a/packages/w3c-vc-api-issuer-rest-client/CHANGELOG.md b/packages/w3c-vc-api-issuer-rest-client/CHANGELOG.md index 0e2b114b1..42d99ce1f 100644 --- a/packages/w3c-vc-api-issuer-rest-client/CHANGELOG.md +++ b/packages/w3c-vc-api-issuer-rest-client/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.w3c-vc-api-issuer-rest-client - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.w3c-vc-api-issuer-rest-client diff --git a/packages/w3c-vc-api-verifier-rest-client/CHANGELOG.md b/packages/w3c-vc-api-verifier-rest-client/CHANGELOG.md index ef7588592..eb865e3ac 100644 --- a/packages/w3c-vc-api-verifier-rest-client/CHANGELOG.md +++ b/packages/w3c-vc-api-verifier-rest-client/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.w3c-vc-api-verifier-rest-client - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.w3c-vc-api-verifier-rest-client diff --git a/packages/w3c-vc-api/CHANGELOG.md b/packages/w3c-vc-api/CHANGELOG.md index 7fc2fcc6b..77a0b2cd0 100644 --- a/packages/w3c-vc-api/CHANGELOG.md +++ b/packages/w3c-vc-api/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.w3c-vc-api - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.w3c-vc-api diff --git a/packages/w3c-vc-api/__tests__/jwt.test.ts b/packages/w3c-vc-api/__tests__/jwt.test.ts new file mode 100644 index 000000000..6edd4309a --- /dev/null +++ b/packages/w3c-vc-api/__tests__/jwt.test.ts @@ -0,0 +1,454 @@ +import * as jose from 'jose' + +const JWT_VC = + 'eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIseyJAdm9jYWIiOiJodHRwOi8vc2NoZW1hLmd0aS5lbmVyZ3kvIn1dLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIl0sImNyZWRlbnRpYWxTdWJqZWN0Ijp7Ik10cmVwb3J0Ijp7IlpOdW1iZXIiOiJBUEkgRGVjaXNpb24gTmVlZGVkIiwiUGlwZU51bWJlciI6IkFQSSBEZWNpc2lvbiBOZWVkZWQiLCJTZXJpYWxOdW1iZXIiOlsiTG9yZW0iLCJMb3JlbSJdLCJIZWF0TnVtYmVyIjoiMjMyNzk2IiwiTXRyTnVtYmVySWRlbnRpZmllciI6IjE1NTYiLCJEYXRlT2ZDZXJ0aWZpY2F0aW9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5TaXplVXNlZCI6IjAiLCJDdm5TaGVhckFyZWExKCUpIjowLCJDdm5TaGVhckFyZWEyKCUpIjowLCJDdm5TaGVhckFyZWEzKCUpIjowLCJDdm5BdmVyYWdlU2hlYXJBcmVhKCUpIjowLCJDdm5TaGVhckFyZWFBY2NlcHRhbmNlQ3JpdGVyaWFGb3JTcGVjaW1lblNpemVVc2VkIjowfX19fX0sInZhbGlkVW50aWwiOiIyMDI0LTEwLTMxVDAwOjAwOjAwWiIsImp0aSI6Imh0dHBzOi8vdmVyaWZpY2F0aW9uLmd0aS5lbmVyZ3kvdmMvMTU1NiIsIm5iZiI6MTY5ODcxMDQwMCwiaXNzIjoiZGlkOmp3azpleUpoYkdjaU9pSkZVekkxTmlJc0luVnpaU0k2SW5OcFp5SXNJbXQwZVNJNklrVkRJaXdpWTNKMklqb2lVQzB5TlRZaUxDSjRJam9pZWpoVFRsTllUVmd4VWpabFZFdDZTa2R0TFVFM1pXcEJaa1pzZFVSc2FVaEtkVzluVDJGUWMwUkVVU0lzSW5raU9pSkxVVXRCVFdWd1RVNTZkSEpzZVRCNk9ESTNNVGcwZERSUWRrRnVVMGxVTFcxTU1GRnNhVWcxZW5VMEluMCJ9.KXi3MEydDL9YgNQkMts47IsIQ23PYNwOnVoLaNOU0Jt6RE0HLjdOXe7B_fNDcRbyd_P_CbeTRcinOiOdXNwdow' +const PUB_KEY_JWK = { + alg: 'ES256', + use: 'sig', + kty: 'EC', + crv: 'P-256', + x: 'z8SNSXMX1R6eTKzJGm-A7ejAfFluDliHJuogOaPsDDQ', + y: 'KQKAMepMNztrly0z827184t4PvAnSIT-mL0QliH5zu4', +} + +describe('JWT Verifiable Credential, should be', () => { + let publickKey: jose.KeyLike | Uint8Array + beforeAll(async () => { + publickKey = await jose.importJWK(PUB_KEY_JWK) + }) + + it('verifiable using a regular JWT library', async () => { + // The verify function would throw an exception if it did not verify (see next test) + const result = await jose.jwtVerify(JWT_VC, publickKey) + + expect(result).toBeDefined() + expect(result.protectedHeader).toEqual({ + alg: 'ES256', + typ: 'JWT', + }) + expect(result.payload).toEqual({ + iss: 'did:jwk:eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoiejhTTlNYTVgxUjZlVEt6SkdtLUE3ZWpBZkZsdURsaUhKdW9nT2FQc0REUSIsInkiOiJLUUtBTWVwTU56dHJseTB6ODI3MTg0dDRQdkFuU0lULW1MMFFsaUg1enU0In0', + jti: 'https://verification.gti.energy/vc/1556', + nbf: 1698710400, + validUntil: '2024-10-31T00:00:00Z', + vc: { + '@context': [ + 'https://www.w3.org/2018/credentials/v1', + { + '@vocab': 'http://schema.gti.energy/', + }, + ], + credentialSubject: { + Mtreport: { + AnnexApplicability: { + AnnexF: false, + AnnexG: false, + AnnexI: false, + AnnexM: false, + AnnexO: false, + }, + 'CertificatePipeManufacturer’sFacility': '5L-0126', + Charpyextra: { + Charpyvnotch1: { + CvnAbsorbedEnergy1: 194, + CvnAbsorbedEnergy2: 194, + CvnAbsorbedEnergy3: 164, + CvnAbsorbedEnergyAcceptanceCriteriaForSpecimenSizeUsed: '25', + CvnAbsorbedEnergyUnits: 'Ft-lbf', + CvnAverageAbsorbedEnergy: 184, + 'CvnAverageShearArea(%)': 100, + 'CvnShearArea1(%)': 100, + 'CvnShearArea2(%)': 100, + 'CvnShearArea3(%)': 100, + CvnShearAreaAcceptanceCriteriaForSpecimenSizeUsed: 85, + CvnTestLocation: 'Weld Line', + CvnTestOrientation: 'T90', + CvnTestSpecification: 'ASTM A370', + CvnTestSpecimenSize: 0.75, + 'CvnTestStatus-type': 'INT', + CvnTestTemperature: -20, + CvnTestTemperatureUnits: 'F', + }, + Charpyvnotch2: { + CvnAbsorbedEnergy1: 196, + CvnAbsorbedEnergy2: 182, + CvnAbsorbedEnergy3: 187, + CvnAbsorbedEnergyAcceptanceCriteriaForSpecimenSizeUsed: '15', + CvnAbsorbedEnergyUnits: 'Ft-lbf', + CvnAverageAbsorbedEnergy: 182, + 'CvnAverageShearArea(%)': 100, + 'CvnShearArea1(%)': 100, + 'CvnShearArea2(%)': 100, + 'CvnShearArea3(%)': 100, + CvnShearAreaAcceptanceCriteriaForSpecimenSizeUsed: 85, + CvnTestLocation: 'HAZ', + CvnTestOrientation: 'T90', + CvnTestSpecification: 'ASTM A370', + CvnTestSpecimenSize: 0.75, + 'CvnTestStatus-type': 'INT', + CvnTestTemperature: -20, + CvnTestTemperatureUnits: 'F', + }, + Charpyvnotch3: { + CvnAbsorbedEnergy1: 194, + CvnAbsorbedEnergy2: 197, + CvnAbsorbedEnergy3: 179, + CvnAbsorbedEnergyAcceptanceCriteriaForSpecimenSizeUsed: '15', + CvnAbsorbedEnergyUnits: 'Ft-lbf', + CvnAverageAbsorbedEnergy: 190, + 'CvnAverageShearArea(%)': 100, + 'CvnShearArea1(%)': 100, + 'CvnShearArea2(%)': 100, + 'CvnShearArea3(%)': 100, + CvnShearAreaAcceptanceCriteriaForSpecimenSizeUsed: 85, + CvnTestLocation: 'Weld Line', + CvnTestOrientation: 'T90', + CvnTestSpecification: 'ASTM A370', + CvnTestSpecimenSize: 0.75, + 'CvnTestStatus-type': 'INT', + CvnTestTemperature: -20, + CvnTestTemperatureUnits: 'F', + }, + Charpyvnotch4: { + CvnAbsorbedEnergy1: 191, + CvnAbsorbedEnergy2: 195, + CvnAbsorbedEnergy3: 190, + CvnAbsorbedEnergyAcceptanceCriteriaForSpecimenSizeUsed: '25', + CvnAbsorbedEnergyUnits: 'Ft-lbf', + CvnAverageAbsorbedEnergy: 192, + 'CvnAverageShearArea(%)': 100, + 'CvnShearArea1(%)': 100, + 'CvnShearArea2(%)': 100, + 'CvnShearArea3(%)': 100, + CvnShearAreaAcceptanceCriteriaForSpecimenSizeUsed: 85, + CvnTestLocation: 'HAZ', + CvnTestOrientation: 'T90', + CvnTestSpecification: 'ASTM A370', + CvnTestSpecimenSize: 0.75, + 'CvnTestStatus-type': 'INT', + CvnTestTemperature: -20, + CvnTestTemperatureUnits: 'F', + }, + Charpyvnotch5: { + CvnAbsorbedEnergy1: 0, + CvnAbsorbedEnergy2: 0, + CvnAbsorbedEnergy3: 0, + CvnAbsorbedEnergyAcceptanceCriteriaForSpecimenSizeUsed: '0', + CvnAbsorbedEnergyUnits: 'Ft-lbf', + CvnAverageAbsorbedEnergy: 0, + 'CvnAverageShearArea(%)': 0, + 'CvnShearArea1(%)': 0, + 'CvnShearArea2(%)': 0, + 'CvnShearArea3(%)': 0, + CvnShearAreaAcceptanceCriteriaForSpecimenSizeUsed: 0, + CvnTestLocation: '', + CvnTestOrientation: 'T90', + CvnTestSpecification: 'ASTM A370', + CvnTestSpecimenSize: 0.75, + 'CvnTestStatus-type': '', + CvnTestTemperature: 32, + CvnTestTemperatureUnits: 'F', + }, + }, + Charpyproduction: { + Charpyvnotch1: { + CvnAbsorbedEnergy1: 111, + CvnAbsorbedEnergy2: 92, + CvnAbsorbedEnergy3: 112, + CvnAbsorbedEnergyAcceptanceCriteriaForSpecimenSizeUsed: '25', + CvnAbsorbedEnergyUnits: 'Ft-lbf', + CvnAverageAbsorbedEnergy: 105, + 'CvnAverageShearArea(%)': 100, + 'CvnShearArea1(%)': 100, + 'CvnShearArea2(%)': 100, + 'CvnShearArea3(%)': 100, + CvnShearAreaAcceptanceCriteriaForSpecimenSizeUsed: 85, + CvnTestLocation: 'Body', + CvnTestOrientation: 'T90', + CvnTestSpecification: 'ASTM A370', + CvnTestSpecimenSize: 0.75, + 'CvnTestStatus-type': 'INT', + CvnTestTemperature: -20, + CvnTestTemperatureUnits: 'F', + }, + Charpyvnotch2: { + CvnAbsorbedEnergy1: 151, + CvnAbsorbedEnergy2: 136, + CvnAbsorbedEnergy3: 103, + CvnAbsorbedEnergyAcceptanceCriteriaForSpecimenSizeUsed: '15', + CvnAbsorbedEnergyUnits: 'Ft-lbf', + CvnAverageAbsorbedEnergy: 130, + 'CvnAverageShearArea(%)': 100, + 'CvnShearArea1(%)': 100, + 'CvnShearArea2(%)': 100, + 'CvnShearArea3(%)': 100, + CvnShearAreaAcceptanceCriteriaForSpecimenSizeUsed: 85, + CvnTestLocation: 'Body', + CvnTestOrientation: 'T90', + CvnTestSpecification: 'ASTM A370', + CvnTestSpecimenSize: 0.75, + 'CvnTestStatus-type': 'INT', + CvnTestTemperature: -20, + CvnTestTemperatureUnits: 'F', + }, + }, + Chemicalmodel: { + Chemistrymodelh: { + Alaluminum: 0.049, + Bboron: 0.0001, + Cacalcium: 0.0016, + Ccarbon: 0.064, + Ceiiwacceptancecriteria: 0.25, + Ceiiwcarbonequivalent: 0, + Cepcmacceptancecriteria: 0.25, + Cepcmcarbon: 0.107, + Chemistryteststatustypec: 'INIT', + Crchromium: 0.021, + Cucopper: 0.009, + Mnmanganese: 0.771, + Momolybdenum: 0.002, + Nbniobium: 0.043, + Ninickel: 0.005, + Nnitrogen: 0.0064, + Pphosphorus: -5, + Sampleid: '11/23', + Samplesource: 'Coil', + Sisilicon: 0.069, + Ssulfur: 0.002, + Tititanium: 0.001, + Vvanadium: 0.001, + }, + Chemistrymodelp1: { + Alaluminum: 0.051, + Bboron: 0, + Cacalcium: 0.0033, + Ccarbon: 0.079, + Ceiiwacceptancecriteria: 0.25, + Ceiiwcarbonequivalent: 0, + Cepcmacceptancecriteria: 0.25, + Cepcmcarbon: 0.123, + Chemistryteststatustypec: 'INIT', + Crchromium: 0.026, + Cucopper: 0.014, + Mnmanganese: 0.757, + Momolybdenum: 0.007, + Nbniobium: 0.052, + Ninickel: 0.035, + Nnitrogen: 0.0062, + Pphosphorus: 0.008, + Sampleid: '0058', + Samplesource: 'Pipe', + Sisilicon: 0.09, + Ssulfur: 0.004, + Tititanium: 0.001, + Vvanadium: 0.002, + }, + Chemistrymodelp2: { + Alaluminum: 0.031, + Bboron: 0, + Cacalcium: 0.0033, + Ccarbon: 0.072, + Ceiiwacceptancecriteria: 0.25, + Ceiiwcarbonequivalent: 0, + Cepcmacceptancecriteria: 0.25, + Cepcmcarbon: 0.117, + Chemistryteststatustypec: 'INIT', + Crchromium: 0.031, + Cucopper: 0.015, + Mnmanganese: 0.766, + Momolybdenum: 0.007, + Nbniobium: 0.05, + Ninickel: 0.035, + Nnitrogen: 0.0052, + Pphosphorus: 0.01, + Sampleid: '0061', + Samplesource: 'Pipe', + Sisilicon: 0.103, + Ssulfur: 0.004, + Tititanium: 0.002, + Vvanadium: 0.003, + }, + }, + CustomerAddress: 'ACCOUNTS PAYABLE PO BOX 513 CHARLESTON, WV 25322', + CustomerName: 'MRC GLOBAL INC', + CustomerOrder: 'S 7A7 521746 ', + DateOfCertification: '2020-03-03T15:06:21.595Z', + HeatNumber: '232796', + InspectionDocumentSpecification: ' ISO 10474 :1991/EN 10204 :2004', + Mechanicalmodel1: { + Bendtests: { + Bendtestspecification: 'Lorem', + Processbendtestpassfail: true, + }, + Deadweighttest: { + 'Dwttaveragesheararea%': 96, + Dwttnotchtype: 'Lorem', + 'Dwttsheararea1%': 91, + 'Dwttsheararea2%': -73, + Dwttspecimensize: 'Lorem', + Dwttstandardused: 'Lorem', + Dwtttestpipenumber: 'Lorem', + Dwttteststatustype: 'Lorem', + Dwtttesttemperature: 'Lorem', + Dwtttesttemperatureunits: 'Lorem', + }, + Hardness: { + Hardnesstestspecification: 'Lorem', + Hardnessteststatustype: 'HRB', + Hardnesstestunits: 'kgf', + Maxhardnessrecordedbody: 90, + Maxhardnessrecordedhaz: 0, + Maxhardnessrecordedweld: 0, + }, + Hydrostatictest: { + Hydrostatictestresult: true, + Specifiedminimumhydrostatictestpressureduration: 10, + Specifiedminimumhydrostatictestpressurevalue: 1960, + Testdurationunits: 'Sec', + Testpressureunits: 'psi', + }, + Ndtstatement: 'NDT tested using an Ultrasonic test method calibrated ID & OD N-10 NOTCHES', + Processflatteningtests: true, + Processguidedbendtest: true, + Sampleid: '0058', + Samplesource: 'Pipe', + Tensiletests: { + TensileSpecimenGageLength: 2, + TensileTestYieldMeasurementPoint: 'Lorem', + TensileTestYieldStrengthUnits: 'ksi', + Tensilespecimengagelengthunits: 'in', + TestLocation: 'Body', + TestOrientation: 'Transverse', + TestSpecification: 'ASTM A370', + TestSpecimenSize: '1-1/2 in X 2 in', + TestSpecimenType: 'full section', + TestStatus: 'INIT', + 'TestTotal%ElongationAtFracture': 32.5, + TestYieldStrength: 61.7, + TestYieldToTensileRatio: 0.79, + Testtensilestrengthpipebody: 77.8, + Testtensilestrengthpipebodyunits: 'ksi', + Testtensilestrengthunits: 'ksi', + Testtensilestrengthweld: 72.1, + }, + }, + Mechanicalmodel2: { + Bendtests: { + Bendtestspecification: 'Lorem', + Processbendtestpassfail: true, + }, + Deadweighttest: { + 'Dwttaveragesheararea%': 11, + Dwttnotchtype: 'Lorem', + 'Dwttsheararea1%': -42, + 'Dwttsheararea2%': -64, + Dwttspecimensize: 'Lorem', + Dwttstandardused: 'Lorem', + Dwtttestpipenumber: 'Lorem', + Dwttteststatustype: 'Lorem', + Dwtttesttemperature: 'Lorem', + Dwtttesttemperatureunits: 'Lorem', + }, + Hardness: { + Hardnesstestspecification: 'Lorem', + Hardnessteststatustype: 'HRB', + Hardnesstestunits: 'kgf', + Maxhardnessrecordedbody: 86, + Maxhardnessrecordedhaz: 0, + Maxhardnessrecordedweld: 0, + }, + Hydrostatictest: { + Hydrostatictestresult: true, + Specifiedminimumhydrostatictestpressureduration: 10, + Specifiedminimumhydrostatictestpressurevalue: 1960, + Testdurationunits: 'sec', + Testpressureunits: 'psi', + }, + Ndtstatement: 'NDT tested using an Ultrasonic test method calibrated ID & OD N-10 NOTCHES', + Processflatteningtests: true, + Processguidedbendtest: true, + Sampleid: '0061', + Samplesource: 'Coil', + Tensiletests: { + TensileSpecimenGageLength: 2, + TensileTestYieldMeasurementPoint: 'Lorem', + TensileTestYieldStrengthUnits: 'ksi', + Tensilespecimengagelengthunits: 'in', + TestLocation: 'Body', + TestOrientation: 'Transverse', + TestSpecification: 'ASTM A370', + TestSpecimenSize: '1-1/2 in X 2 in', + TestSpecimenType: 'full section', + TestStatus: 'INIT', + 'TestTotal%ElongationAtFracture': 39.5, + TestYieldStrength: 62.1, + TestYieldToTensileRatio: 0.81, + Testtensilestrengthpipebody: 76.9, + Testtensilestrengthpipebodyunits: 'ksi', + Testtensilestrengthunits: 'ksi', + Testtensilestrengthweld: 72.4, + }, + }, + MeltingVendor: '(G) Cleveland Cliffs, Indiana Harbor', + MeltingVendorAddress: '3210 Watling Street East Chicago, IN 46312 USA', + MtrNumberIdentifier: '1556', + PipeDescription: { + Api5lEditionNumber: '45 - 7/1/2013, 46 - 5/1/2019', + PipeAdditionalDescription: 'API Line Pipe', + PipeGrade: 'X52M', + PipeNominalOutsideDiameter: 20, + PipeNominalOutsideDiameterUnits: 'in', + PipeNominalWallThickness: 0.375, + PipeNominalWallThicknessUnits: 'in', + PipeType: 'HFW', + ProductSpecificationLevel: '2', + Specifications: 'API 5L', + }, + PipeNumber: 'API Decision Needed', + ProcessControls: { + 'MinimumTemperatureForHeatTreatment,WeldSeamHfwOnly': 1600, + 'MinimumTemperatureUnitsForHeatTreatment,WeldSeam(hfwOnly)': 'F', + }, + ProducerAddress: '1501 31st Avenue North, Birmingham, AL 35207', + ProducerName: 'American Cast Iron Pipe Co', + ReportType: '3.1', + SerialNumber: ['Lorem', 'Lorem'], + SpecialNotes: + "HARDNESS IS 22 HRC MAX. THIS ORDER WILL ALSO MEET ASTM A53 GRADE BAND ASME SA 53 GRADE B. PIPE WERE MANUFACTURED IN ACCORDANCE WITH MRC 'STANDARD FOR PURCHASE OF LINE PIPE FOR MRC GLOBAL INVENTORY' DOCUMENT NUMBER STD-LPOl REV 6, REV. DATE 11 2020-09-23 11 • NDT tested using an Ultrasonic test method calibrated ID & OD N-10 NOTCHES. Hydrostatic test duration 10 seconds. Max allowable C.E. PCM .25. Minimum weld seam anneal temperature 16 00 degrees F for all pipe. Charpy acceptance criteria Min. Energy 15/Heat. Min. shear area 85/Heat.", + SteelSupplierAddress: '3210 Watling St. / East Chicago, IN 46312 1 AM/NS Way / Calvert, AL 36513 ', + SteelSupplierName: 'Arcelor - Mittal Steel (I.H. West) , AM/NS- Calvert (Roll) ', + TestComments: + "All tests are from the body of the pipe in the transverse direction unless otherwise noted. Standard flat tensile gage length 1-1/2' x 2'. Pipe body test location: Tensile 180; CVN T90. Coils used for this order were melted and manufactured in the USA. We hereby certify that the above figures are correct as contained in the records of this company, and that the pipe were manufactured, tested, and inspected in compliance with the Latest edition of the applicable Specification at American Steel Pipe (ASP) located at 1500 32nd Avenue North, Birmingham, AL 35207 (USA). ", + ZNumber: 'API Decision Needed', + }, + }, + type: ['VerifiableCredential'], + }, + }) + }) + + it('throw an error in case the signature is invalid', async () => { + await expect(jose.jwtVerify(JWT_VC.replace('OdXNwdow', '1dXNwdow'), publickKey)).rejects.toThrow() + }) + it('throw an error in case the header is invalid', async () => { + await expect(jose.jwtVerify(JWT_VC.replace('kpXVCJ9', 'kpXVCJ8'), publickKey)).rejects.toThrow() + }) + it('throw an error in case the payload is invalid', async () => { + await expect(jose.jwtVerify(JWT_VC.replace('JAY29ud', 'JAY29uc'), publickKey)).rejects.toThrow() + }) + it('throw an error in case the JWK key is not the public key of the signed JWT', async () => { + await expect( + jose.jwtVerify( + JWT_VC, + await jose.importJWK({ + kty: 'EC', + use: 'sig', + crv: 'P-256', + x: 'xNCU9OyorlgxWmolagucwuWyKrKxBnEmEUY6TPEF7kY', + y: 'rmiUJLLX3BX5OVf0PEJdz8nS3aX3ylw9s7Nn_wxb22Y', + alg: 'ES256', + }) + ) + ).rejects.toThrow() + }) +}) diff --git a/packages/w3c-vc-api/package.json b/packages/w3c-vc-api/package.json index 04be7f8f9..3d0376721 100644 --- a/packages/w3c-vc-api/package.json +++ b/packages/w3c-vc-api/package.json @@ -61,6 +61,7 @@ "@veramo/utils": "4.2.0", "did-resolver": "^4.1.0", "morgan": "^1.10.0", + "jose": "^5.1.3", "nock": "^13.2.1", "passport": "^0.6.0", "passport-azure-ad": "^4.3.5", diff --git a/packages/web3-provider-headless/CHANGELOG.md b/packages/web3-provider-headless/CHANGELOG.md index 2dff6b82c..3b47260c4 100644 --- a/packages/web3-provider-headless/CHANGELOG.md +++ b/packages/web3-provider-headless/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk-web3.headless-provider - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk-web3.headless-provider diff --git a/packages/web3-provider-headless/src/rpc-server.ts b/packages/web3-provider-headless/src/rpc-server.ts index 17e0a2235..642603206 100644 --- a/packages/web3-provider-headless/src/rpc-server.ts +++ b/packages/web3-provider-headless/src/rpc-server.ts @@ -70,7 +70,7 @@ export function createRpcServer( return next() } ) - express.use(opts.basePath ?? '', router) + express.use(opts?.basePath ?? '', router) } export function createServiceMethod(method: string, service: Record, provider: EthersHeadlessProvider) { diff --git a/packages/wellknown-did-issuer/CHANGELOG.md b/packages/wellknown-did-issuer/CHANGELOG.md index e0e8d524d..c4c6af203 100644 --- a/packages/wellknown-did-issuer/CHANGELOG.md +++ b/packages/wellknown-did-issuer/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.wellknown-did-issuer - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.wellknown-did-issuer diff --git a/packages/wellknown-did-verifier/CHANGELOG.md b/packages/wellknown-did-verifier/CHANGELOG.md index e0a4a4324..c2147f554 100644 --- a/packages/wellknown-did-verifier/CHANGELOG.md +++ b/packages/wellknown-did-verifier/CHANGELOG.md @@ -7,10 +7,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline **Note:** Version bump only for package @sphereon/ssi-sdk.wellknown-did-verifier - - - - ## [0.17.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.3...v0.17.4) (2023-10-01) **Note:** Version bump only for package @sphereon/ssi-sdk.wellknown-did-verifier diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7d54c6237..9623ce1cc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2264,6 +2264,9 @@ importers: did-resolver: specifier: ^4.1.0 version: 4.1.0 + jose: + specifier: ^5.1.3 + version: 5.1.3 morgan: specifier: ^1.10.0 version: 1.10.0 @@ -15239,6 +15242,10 @@ packages: /jose@4.14.6: resolution: {integrity: sha512-EqJPEUlZD0/CSUMubKtMaYUOtWe91tZXTWMJZoKSbLk+KtdhNdcvppH8lA9XwVu2V4Ailvsj0GBZJ2ZwDjfesQ==} + /jose@5.1.3: + resolution: {integrity: sha512-GPExOkcMsCLBTi1YetY2LmkoY559fss0+0KVa6kOfb2YFe84nAM7Nm/XzuZozah4iHgmBGrCOHL5/cy670SBRw==} + dev: true + /js-sha256@0.9.0: resolution: {integrity: sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA==} dev: true From 4528881563104ac00b9af8d9615479c76af8a3be Mon Sep 17 00:00:00 2001 From: Niels Klomp Date: Thu, 21 Dec 2023 21:48:49 +0100 Subject: [PATCH 2/2] feat: Add bearer token support using callback function --- .../__tests__/eventLogger.entities.test.ts | 13 +----- .../src/__tests__/eventLogger.store.test.ts | 19 ++++---- .../entities/eventLogger/AuditEventEntity.ts | 29 +++++------- .../eventLogger/AbstractEventLoggerStore.ts | 1 - .../src/eventLogger/EventLoggerStore.ts | 18 ++++---- packages/data-store/src/index.ts | 9 ++-- .../src/migrations/generic/index.ts | 4 +- .../1701634812183-CreateAuditEvents.ts | 12 +++-- .../sqlite/1701634819487-CreateAuditEvents.ts | 4 +- packages/event-logger/README.md | 45 ++++++++----------- .../__tests__/shared/eventLoggerAgentLogic.ts | 21 ++++----- .../event-logger/src/agent/EventLogger.ts | 23 ++++------ .../event-logger/src/types/IEventLogger.ts | 10 +---- .../oid4vci-issuer-rest-client/package.json | 1 + .../src/agent/OID4VCIRestClient.ts | 10 +++-- .../src/types/IOID4VCIRestClient.ts | 3 +- .../oid4vci-issuer-rest-client/tsconfig.json | 7 ++- .../siopv2-oid4vp-rp-rest-client/package.json | 1 + .../src/types/ISIOPv2OID4VPRPRestClient.ts | 3 +- .../tsconfig.json | 9 +++- packages/ssi-sdk-core/src/index.ts | 5 +-- .../src/loggers/eventLogger/EventLogger.ts | 25 +++-------- .../loggers/eventLogger/EventLoggerBuilder.ts | 27 ++++++----- packages/ssi-sdk-core/src/types/events.ts | 12 ++--- .../ssi-sdk-core/src/utils/bearer-token.ts | 15 +++++++ packages/ssi-sdk-core/src/utils/index.ts | 1 + packages/ssi-types/src/types/generic.ts | 2 + pnpm-lock.yaml | 8 +++- 28 files changed, 162 insertions(+), 175 deletions(-) create mode 100644 packages/ssi-sdk-core/src/utils/bearer-token.ts diff --git a/packages/data-store/src/__tests__/eventLogger.entities.test.ts b/packages/data-store/src/__tests__/eventLogger.entities.test.ts index 2c911dcec..cf4181446 100644 --- a/packages/data-store/src/__tests__/eventLogger.entities.test.ts +++ b/packages/data-store/src/__tests__/eventLogger.entities.test.ts @@ -1,15 +1,7 @@ import { DataSource } from 'typeorm' import { DataStoreEventLoggerEntities } from '../index' import { DataStoreEventLoggerMigrations } from '../migrations/generic' -import { - ActionType, - InitiatorType, - LogLevel, - PartyCorrelationType, - SubSystem, - System, - SystemCorrelationIdType -} from '@sphereon/ssi-sdk.core' +import { ActionType, InitiatorType, LogLevel, PartyCorrelationType, SubSystem, System, SystemCorrelationIdType } from '@sphereon/ssi-sdk.core' import { auditEventEntityFrom, AuditEventEntity } from '../entities/eventLogger/AuditEventEntity' import { NonPersistedAuditLoggingEvent } from '../types' @@ -52,7 +44,7 @@ describe('Database entities tests', (): void => { partyAlias: 'test_alias', description: 'test_description', data: 'test_data_string', - diagnosticData: { data: 'test_data_string'} + diagnosticData: { data: 'test_data_string' }, } const auditEventEntity: AuditEventEntity = auditEventEntityFrom(auditEvent) @@ -78,5 +70,4 @@ describe('Database entities tests', (): void => { expect(fromDb?.data).toEqual(JSON.stringify(auditEvent.data)) expect(fromDb?.diagnosticData).toEqual(JSON.stringify(auditEvent.diagnosticData)) }) - }) diff --git a/packages/data-store/src/__tests__/eventLogger.store.test.ts b/packages/data-store/src/__tests__/eventLogger.store.test.ts index c3f1e333e..e99d539fd 100644 --- a/packages/data-store/src/__tests__/eventLogger.store.test.ts +++ b/packages/data-store/src/__tests__/eventLogger.store.test.ts @@ -9,7 +9,7 @@ import { PartyCorrelationType, SubSystem, System, - SystemCorrelationIdType + SystemCorrelationIdType, } from '@sphereon/ssi-sdk.core' import { EventLoggerStore } from '../eventLogger/EventLoggerStore' import { GetAuditEventsArgs, NonPersistedAuditLoggingEvent } from '../types' @@ -55,10 +55,10 @@ describe('Database entities tests', (): void => { partyAlias: 'test_alias', description: 'test_description', data: 'test_data_string', - diagnosticData: { data: 'test_data_string'} + diagnosticData: { data: 'test_data_string' }, } - const savedAuditEvent: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({event: auditEvent}) + const savedAuditEvent: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({ event: auditEvent }) expect(savedAuditEvent).toBeDefined() }) @@ -80,13 +80,13 @@ describe('Database entities tests', (): void => { partyAlias: 'test_alias', description: 'test_description', data: 'test_data_string', - diagnosticData: { data: 'test_data_string'} + diagnosticData: { data: 'test_data_string' }, } - const auditEvent1: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({event: auditEvent}) + const auditEvent1: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({ event: auditEvent }) expect(auditEvent1).toBeDefined() - const auditEvent2: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({event: auditEvent}) + const auditEvent2: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({ event: auditEvent }) expect(auditEvent2).toBeDefined() const result: Array = await eventLoggerStore.getAuditEvents() @@ -111,10 +111,10 @@ describe('Database entities tests', (): void => { partyAlias: 'test_alias', description: 'test_description', data: 'test_data_string', - diagnosticData: { data: 'test_data_string'} + diagnosticData: { data: 'test_data_string' }, } - const savedAuditEvent: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({event: auditEvent}) + const savedAuditEvent: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({ event: auditEvent }) expect(savedAuditEvent).toBeDefined() const args: GetAuditEventsArgs = { @@ -127,11 +127,10 @@ describe('Database entities tests', (): void => { it('should return no audit events if filter does not match', async (): Promise => { const args: GetAuditEventsArgs = { - filter: [{ correlationId: 'unknown_id'}], + filter: [{ correlationId: 'unknown_id' }], } const result: Array = await eventLoggerStore.getAuditEvents(args) expect(result.length).toEqual(0) }) - }) diff --git a/packages/data-store/src/entities/eventLogger/AuditEventEntity.ts b/packages/data-store/src/entities/eventLogger/AuditEventEntity.ts index 84d35868c..3061cb751 100644 --- a/packages/data-store/src/entities/eventLogger/AuditEventEntity.ts +++ b/packages/data-store/src/entities/eventLogger/AuditEventEntity.ts @@ -1,11 +1,4 @@ -import { - BaseEntity, - Column, - CreateDateColumn, - Entity, - PrimaryGeneratedColumn, - UpdateDateColumn -} from 'typeorm' +import { BaseEntity, Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm' import { ActionType, InitiatorType, @@ -14,7 +7,7 @@ import { SubSystem, System, SystemCorrelationIdType, - ActionSubType + ActionSubType, } from '@sphereon/ssi-sdk.core' import { NonPersistedAuditLoggingEvent } from '../../types' @@ -23,13 +16,13 @@ export class AuditEventEntity extends BaseEntity { @PrimaryGeneratedColumn('uuid') id!: string - @Column({ name: 'timestamp', nullable: false, unique: false}) + @Column({ name: 'timestamp', nullable: false, unique: false }) timestamp!: Date @Column('simple-enum', { name: 'level', enum: LogLevel, nullable: false, unique: false }) level!: LogLevel - @Column({ name: 'correlationId', nullable: false, unique: false}) + @Column({ name: 'correlationId', nullable: false, unique: false }) correlationId!: string @Column('simple-enum', { name: 'system', enum: System, nullable: false, unique: false }) @@ -50,28 +43,28 @@ export class AuditEventEntity extends BaseEntity { @Column('simple-enum', { name: 'systemCorrelationIdType', enum: SystemCorrelationIdType, nullable: true, unique: false }) systemCorrelationIdType?: SystemCorrelationIdType - @Column({ name: 'systemCorrelationId', nullable: true, unique: false}) + @Column({ name: 'systemCorrelationId', nullable: true, unique: false }) systemCorrelationId?: string - @Column({ name: 'systemAlias', nullable: false, unique: false}) + @Column({ name: 'systemAlias', nullable: false, unique: false }) systemAlias?: string @Column('simple-enum', { name: 'partyCorrelationType', enum: PartyCorrelationType, nullable: true, unique: false }) partyCorrelationType?: PartyCorrelationType - @Column({ name: 'partyCorrelationId', nullable: true, unique: false}) + @Column({ name: 'partyCorrelationId', nullable: true, unique: false }) partyCorrelationId?: string - @Column({ name: 'partyAlias', nullable: true, unique: false}) + @Column({ name: 'partyAlias', nullable: true, unique: false }) partyAlias?: string - @Column({ name: 'description', nullable: false, unique: false}) + @Column({ name: 'description', nullable: false, unique: false }) description!: string - @Column({ name: 'data', nullable: true, unique: false}) + @Column({ name: 'data', nullable: true, unique: false }) data?: string - @Column({ name: 'diagnosticData', nullable: true, unique: false}) + @Column({ name: 'diagnosticData', nullable: true, unique: false }) diagnosticData?: string @CreateDateColumn({ name: 'created_at', nullable: false }) diff --git a/packages/data-store/src/eventLogger/AbstractEventLoggerStore.ts b/packages/data-store/src/eventLogger/AbstractEventLoggerStore.ts index d7e3715fe..42d324f2e 100644 --- a/packages/data-store/src/eventLogger/AbstractEventLoggerStore.ts +++ b/packages/data-store/src/eventLogger/AbstractEventLoggerStore.ts @@ -5,4 +5,3 @@ export abstract class AbstractEventLoggerStore { abstract getAuditEvents(args: GetAuditEventsArgs): Promise> abstract storeAuditEvent(args: StoreAuditEventArgs): Promise } - diff --git a/packages/data-store/src/eventLogger/EventLoggerStore.ts b/packages/data-store/src/eventLogger/EventLoggerStore.ts index db23c671e..5aed175bd 100644 --- a/packages/data-store/src/eventLogger/EventLoggerStore.ts +++ b/packages/data-store/src/eventLogger/EventLoggerStore.ts @@ -1,10 +1,10 @@ -import Debug, {Debugger} from 'debug' -import {DataSource} from 'typeorm' -import {AuditLoggingEvent} from '@sphereon/ssi-sdk.core' -import {OrPromise} from '@sphereon/ssi-types' -import {AbstractEventLoggerStore} from './AbstractEventLoggerStore' -import {AuditEventEntity, auditEventEntityFrom} from '../entities/eventLogger/AuditEventEntity' -import {GetAuditEventsArgs, StoreAuditEventArgs} from '../types' +import Debug, { Debugger } from 'debug' +import { DataSource } from 'typeorm' +import { AuditLoggingEvent } from '@sphereon/ssi-sdk.core' +import { OrPromise } from '@sphereon/ssi-types' +import { AbstractEventLoggerStore } from './AbstractEventLoggerStore' +import { AuditEventEntity, auditEventEntityFrom } from '../entities/eventLogger/AuditEventEntity' +import { GetAuditEventsArgs, StoreAuditEventArgs } from '../types' const debug: Debugger = Debug('sphereon:ssi-sdk:event-store') @@ -55,8 +55,8 @@ export class EventLoggerStore extends AbstractEventLoggerStore { systemAlias: event.systemAlias, systemCorrelationId: event.systemCorrelationId, systemCorrelationIdType: event.systemCorrelationIdType, - ...(event.data && {data: JSON.parse(event.data)}), - ...(event.diagnosticData && {diagnosticData: JSON.parse(event.diagnosticData)}), + ...(event.data && { data: JSON.parse(event.data) }), + ...(event.diagnosticData && { diagnosticData: JSON.parse(event.diagnosticData) }), } } } diff --git a/packages/data-store/src/index.ts b/packages/data-store/src/index.ts index 1fd15e260..8b829c365 100644 --- a/packages/data-store/src/index.ts +++ b/packages/data-store/src/index.ts @@ -67,17 +67,14 @@ export const DataStoreIssuanceBrandingEntities = [ export const DataStoreStatusListEntities = [StatusListEntity, StatusListEntryEntity] -export const DataStoreEventLoggerEntities = [ - AuditEventEntity -] - +export const DataStoreEventLoggerEntities = [AuditEventEntity] // All entities combined if a party wants to enable them all at once export const DataStoreEntities = [ ...DataStoreContactEntities, ...DataStoreIssuanceBrandingEntities, ...DataStoreStatusListEntities, - ...DataStoreEventLoggerEntities + ...DataStoreEventLoggerEntities, ] export { @@ -112,5 +109,5 @@ export { StatusListEntity, StatusListEntryEntity, AuditEventEntity, - auditEventEntityFrom + auditEventEntityFrom, } diff --git a/packages/data-store/src/migrations/generic/index.ts b/packages/data-store/src/migrations/generic/index.ts index 723366b81..27cc68d40 100644 --- a/packages/data-store/src/migrations/generic/index.ts +++ b/packages/data-store/src/migrations/generic/index.ts @@ -16,12 +16,12 @@ import { CreateAuditEvents1701635835330 } from './5-CreateAuditEvents' export const DataStoreContactMigrations = [CreateContacts1659463079429, CreateContacts1690925872318] export const DataStoreIssuanceBrandingMigrations = [CreateIssuanceBranding1659463079429] export const DataStoreStatusListMigrations = [CreateStatusList1693866470000] -export const DataStoreEventLoggerMigrations= [CreateAuditEvents1701635835330] +export const DataStoreEventLoggerMigrations = [CreateAuditEvents1701635835330] // All migrations together export const DataStoreMigrations = [ ...DataStoreContactMigrations, ...DataStoreIssuanceBrandingMigrations, ...DataStoreStatusListMigrations, - ...DataStoreEventLoggerMigrations + ...DataStoreEventLoggerMigrations, ] diff --git a/packages/data-store/src/migrations/postgres/1701634812183-CreateAuditEvents.ts b/packages/data-store/src/migrations/postgres/1701634812183-CreateAuditEvents.ts index b00835442..a6c2768c5 100644 --- a/packages/data-store/src/migrations/postgres/1701634812183-CreateAuditEvents.ts +++ b/packages/data-store/src/migrations/postgres/1701634812183-CreateAuditEvents.ts @@ -5,13 +5,19 @@ export class CreateAuditEvents1701634812183 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { await queryRunner.query(`CREATE TYPE "public"."Level_enum" AS ENUM('0', '1', '2', '3')`) - await queryRunner.query(`CREATE TYPE "public"."System_enum" AS ENUM('general', 'kms', 'identity', 'oid4vci', 'credentials', 'web3', 'profile', 'contact')`) - await queryRunner.query(`CREATE TYPE "public"."Subsystem_type_enum" AS ENUM('key', 'did_provider', 'did_resolver', 'oid4vp_op', 'oid4vci_client', 'siopv2_op', 'contact_manager', 'vc_issuer', 'vc_verifier', 'vc_persistence', 'transport', 'profile')`) + await queryRunner.query( + `CREATE TYPE "public"."System_enum" AS ENUM('general', 'kms', 'identity', 'oid4vci', 'credentials', 'web3', 'profile', 'contact')` + ) + await queryRunner.query( + `CREATE TYPE "public"."Subsystem_type_enum" AS ENUM('key', 'did_provider', 'did_resolver', 'oid4vp_op', 'oid4vci_client', 'siopv2_op', 'contact_manager', 'vc_issuer', 'vc_verifier', 'vc_persistence', 'transport', 'profile')` + ) await queryRunner.query(`CREATE TYPE "public"."Action_type_enum" AS ENUM('create', 'read', 'update', 'delete', 'execute')`) await queryRunner.query(`CREATE TYPE "public"."Initiator_type_enum" AS ENUM('user', 'system', 'external')`) await queryRunner.query(`CREATE TYPE "public"."System_correlation_id_type_enum" AS ENUM('did', 'email', 'hostname', 'phone', 'user')`) await queryRunner.query(`CREATE TYPE "public"."Party_correlation_type_enum" AS ENUM('did', 'email', 'hostname', 'phone')`) - await queryRunner.query(`CREATE TABLE "AuditEvents" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "timestamp" TIMESTAMP NOT NULL, "level" "public"."Level_enum" NOT NULL, "correlationId" TEXT NOT NULL, "system" "public"."System_enum" NOT NULL, "subSystemType" "public"."Subsystem_type_enum" NOT NULL, "actionType" "public"."Action_type_enum" NOT NULL, "actionSubType" TEXT NOT NULL, "initiatorType" "public"."Initiator_type_enum" NOT NULL, "systemCorrelationIdType" "public"."System_correlation_id_type_enum", "systemCorrelationId" TEXT, "systemAlias" TEXT NOT NULL, "partyCorrelationType" "public"."Party_correlation_type_enum", "partyCorrelationId" TEXT, "partyAlias" TEXT, "description" TEXT NOT NULL, "data" TEXT, "diagnosticData" TEXT, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_AuditEvents_id" PRIMARY KEY ("id"))`) + await queryRunner.query( + `CREATE TABLE "AuditEvents" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "timestamp" TIMESTAMP NOT NULL, "level" "public"."Level_enum" NOT NULL, "correlationId" TEXT NOT NULL, "system" "public"."System_enum" NOT NULL, "subSystemType" "public"."Subsystem_type_enum" NOT NULL, "actionType" "public"."Action_type_enum" NOT NULL, "actionSubType" TEXT NOT NULL, "initiatorType" "public"."Initiator_type_enum" NOT NULL, "systemCorrelationIdType" "public"."System_correlation_id_type_enum", "systemCorrelationId" TEXT, "systemAlias" TEXT NOT NULL, "partyCorrelationType" "public"."Party_correlation_type_enum", "partyCorrelationId" TEXT, "partyAlias" TEXT, "description" TEXT NOT NULL, "data" TEXT, "diagnosticData" TEXT, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_AuditEvents_id" PRIMARY KEY ("id"))` + ) } public async down(queryRunner: QueryRunner): Promise { diff --git a/packages/data-store/src/migrations/sqlite/1701634819487-CreateAuditEvents.ts b/packages/data-store/src/migrations/sqlite/1701634819487-CreateAuditEvents.ts index cb52212df..4326aa5ea 100644 --- a/packages/data-store/src/migrations/sqlite/1701634819487-CreateAuditEvents.ts +++ b/packages/data-store/src/migrations/sqlite/1701634819487-CreateAuditEvents.ts @@ -4,7 +4,9 @@ export class CreateAuditEvents1701634819487 implements MigrationInterface { name = 'CreateAuditEvents1701634819487' public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`CREATE TABLE "AuditEvents" ("id" varchar PRIMARY KEY NOT NULL, "timestamp" datetime NOT NULL, "level" varchar CHECK( "level" IN ('0','1','2','3') ) NOT NULL, "correlationId" varchar NOT NULL, "system" varchar CHECK( "system" IN ('general','kms','identity','oid4vci','credentials','web3','profile','contact') ) NOT NULL, "subSystemType" varchar CHECK( "subSystemType" IN ('key','did_provider','did_resolver','oid4vp_op','oid4vci_client','siopv2_op','contact_manager','vc_issuer','vc_verifier','vc_persistence','transport','profile') ) NOT NULL, "actionType" varchar CHECK( "actionType" IN ('create','read','update','delete','execute') ) NOT NULL, "actionSubType" varchar NOT NULL, "initiatorType" varchar CHECK( "initiatorType" IN ('user','system','external') ) NOT NULL, "systemCorrelationIdType" varchar CHECK( "systemCorrelationIdType" IN ('did','email','hostname','phone','user') ), "systemCorrelationId" varchar, "systemAlias" varchar NOT NULL, "partyCorrelationType" varchar CHECK( "partyCorrelationType" IN ('did','email','hostname','phone') ), "partyCorrelationId" varchar, "partyAlias" varchar, "description" varchar NOT NULL, "data" varchar, "diagnosticData" varchar, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')))`) + await queryRunner.query( + `CREATE TABLE "AuditEvents" ("id" varchar PRIMARY KEY NOT NULL, "timestamp" datetime NOT NULL, "level" varchar CHECK( "level" IN ('0','1','2','3') ) NOT NULL, "correlationId" varchar NOT NULL, "system" varchar CHECK( "system" IN ('general','kms','identity','oid4vci','credentials','web3','profile','contact') ) NOT NULL, "subSystemType" varchar CHECK( "subSystemType" IN ('key','did_provider','did_resolver','oid4vp_op','oid4vci_client','siopv2_op','contact_manager','vc_issuer','vc_verifier','vc_persistence','transport','profile') ) NOT NULL, "actionType" varchar CHECK( "actionType" IN ('create','read','update','delete','execute') ) NOT NULL, "actionSubType" varchar NOT NULL, "initiatorType" varchar CHECK( "initiatorType" IN ('user','system','external') ) NOT NULL, "systemCorrelationIdType" varchar CHECK( "systemCorrelationIdType" IN ('did','email','hostname','phone','user') ), "systemCorrelationId" varchar, "systemAlias" varchar NOT NULL, "partyCorrelationType" varchar CHECK( "partyCorrelationType" IN ('did','email','hostname','phone') ), "partyCorrelationId" varchar, "partyAlias" varchar, "description" varchar NOT NULL, "data" varchar, "diagnosticData" varchar, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')))` + ) } public async down(queryRunner: QueryRunner): Promise { diff --git a/packages/event-logger/README.md b/packages/event-logger/README.md index 1e56a2ce7..c003715dd 100644 --- a/packages/event-logger/README.md +++ b/packages/event-logger/README.md @@ -12,13 +12,14 @@ --- -A Veramo event logger plugin. This plugin allows for listening to events and to persist them into a database. +A Veramo event logger plugin. This plugin allows for listening to events and to persist them into a database. There are also functions that can be manually called to persist events. Current, only audit events are supported that can be used to create an audit log. -Ideally this plugin should be used in combination with the event logger from our core package. This event logger will also default debug the events. +Ideally this plugin should be used in combination with the event logger from our core package. This event logger will also default debug the events. This is mainly as a fallback for when no listener is present within the agent. ## Available functions + - loggerGetAuditEvents - loggerStoreAuditEvent @@ -29,12 +30,7 @@ This is mainly as a fallback for when no listener is present within the agent. ```typescript import { migrations, Entities } from '@veramo/data-store' import { EventLogger, IEventLogger } from '@sphereon/ssi-sdk.event-logger' -import { - EventLoggerStore, - DataStoreMigrations, - DataStoreEventLoggerEntities, - LoggingEventType -} from '@sphereon/ssi-sdk.data-store' +import { EventLoggerStore, DataStoreMigrations, DataStoreEventLoggerEntities, LoggingEventType } from '@sphereon/ssi-sdk.data-store' const dbConnection = createConnection({ type: 'react-native', @@ -60,24 +56,21 @@ const agent = createAgent({ ### Log event using event listener: ```typescript -import { - EventLogger, - EventLoggerBuilder, - LoggingEventType , +import { + EventLogger, + EventLoggerBuilder, + LoggingEventType, LogLevel, System, SubSystem, ActionType, InitiatorType, SystemCorrelationIdType, - PartyCorrelationType -} from '@sphereon/ssi-sdk.core'; + PartyCorrelationType, +} from '@sphereon/ssi-sdk.core' const agentContext = { agent } -const logger: EventLogger = new EventLoggerBuilder() - .withContext(agentContext) - .withNamespace('custom_namespace') - .build() +const logger: EventLogger = new EventLoggerBuilder().withContext(agentContext).withNamespace('custom_namespace').build() await logger.logEvent({ type: LoggingEventType.AUDIT, @@ -97,8 +90,8 @@ await logger.logEvent({ partyAlias: 'test_alias', description: 'test_description', data: 'test_data_string', - diagnosticData: { data: 'test_data_string'} - } + diagnosticData: { data: 'test_data_string' }, + }, }) ``` @@ -113,7 +106,7 @@ import { ActionType, InitiatorType, SystemCorrelationIdType, - PartyCorrelationType + PartyCorrelationType, } from '@sphereon/ssi-sdk.core' import { GetAuditEventsArgs, NonPersistedAuditLoggingEvent } from '@sphereon/ssi-sdk.event-logger' @@ -133,10 +126,10 @@ const auditEvent: NonPersistedAuditLoggingEvent = { partyAlias: 'test_alias', description: 'test_description', data: 'test_data_string', - diagnosticData: { data: 'test_data_string'} + diagnosticData: { data: 'test_data_string' }, } -const result: AuditLoggingEvent = await agent.loggerLogAuditEvent({event: auditEvent}) +const result: AuditLoggingEvent = await agent.loggerLogAuditEvent({ event: auditEvent }) ``` ### Retrieve audit events: @@ -150,7 +143,7 @@ import { ActionType, InitiatorType, SystemCorrelationIdType, - PartyCorrelationType + PartyCorrelationType, } from '@sphereon/ssi-sdk.core' import { GetAuditEventsArgs, NonPersistedAuditLoggingEvent } from '@sphereon/ssi-sdk.event-logger' @@ -170,10 +163,10 @@ const auditEvent: NonPersistedAuditLoggingEvent = { partyAlias: 'test_alias', description: 'test_description', data: 'test_data_string', - diagnosticData: { data: 'test_data_string'} + diagnosticData: { data: 'test_data_string' }, } -await agent.loggerLogAuditEvent({event: auditEvent}) +await agent.loggerLogAuditEvent({ event: auditEvent }) const getAuditEventArgs: GetAuditEventsArgs = { filter: [{ correlationId: auditEvent.correlationId }], } diff --git a/packages/event-logger/__tests__/shared/eventLoggerAgentLogic.ts b/packages/event-logger/__tests__/shared/eventLoggerAgentLogic.ts index 7c596c634..457c4d4b8 100644 --- a/packages/event-logger/__tests__/shared/eventLoggerAgentLogic.ts +++ b/packages/event-logger/__tests__/shared/eventLoggerAgentLogic.ts @@ -7,17 +7,13 @@ import { PartyCorrelationType, SubSystem, System, - SystemCorrelationIdType + SystemCorrelationIdType, } from '@sphereon/ssi-sdk.core' import { GetAuditEventsArgs, IEventLogger, NonPersistedAuditLoggingEvent } from '../../src' type ConfiguredAgent = TAgent -export default (testContext: { - getAgent: () => ConfiguredAgent - setup: () => Promise - tearDown: () => Promise -}): void => { +export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Promise; tearDown: () => Promise }): void => { describe('Event Logger Agent Plugin', (): void => { let agent: ConfiguredAgent @@ -45,10 +41,10 @@ export default (testContext: { partyAlias: 'test_alias', description: 'test_description', data: 'test_data_string', - diagnosticData: { data: 'test_data_string'} + diagnosticData: { data: 'test_data_string' }, } - const result: AuditLoggingEvent = await agent.loggerLogAuditEvent({event: auditEvent}) + const result: AuditLoggingEvent = await agent.loggerLogAuditEvent({ event: auditEvent }) expect(result).toBeDefined() expect(result?.id).toBeDefined() @@ -88,10 +84,10 @@ export default (testContext: { partyAlias: 'test_alias', description: 'test_description', data: 'test_data_string', - diagnosticData: { data: 'test_data_string'} + diagnosticData: { data: 'test_data_string' }, } - await agent.loggerLogAuditEvent({event: auditEvent}) + await agent.loggerLogAuditEvent({ event: auditEvent }) const result: Array = await agent.loggerGetAuditEvents() expect(result).toBeDefined() @@ -115,10 +111,10 @@ export default (testContext: { partyAlias: 'test_alias', description: 'test_description', data: 'test_data_string', - diagnosticData: { data: 'test_data_string'} + diagnosticData: { data: 'test_data_string' }, } - await agent.loggerLogAuditEvent({event: auditEvent}) + await agent.loggerLogAuditEvent({ event: auditEvent }) const args: GetAuditEventsArgs = { filter: [{ correlationId: auditEvent.correlationId }], } @@ -127,6 +123,5 @@ export default (testContext: { expect(result).toBeDefined() expect(result?.length).toEqual(1) }) - }) } diff --git a/packages/event-logger/src/agent/EventLogger.ts b/packages/event-logger/src/agent/EventLogger.ts index d3e3514c9..1634b2075 100644 --- a/packages/event-logger/src/agent/EventLogger.ts +++ b/packages/event-logger/src/agent/EventLogger.ts @@ -3,14 +3,7 @@ import { AbstractEventLoggerStore } from '@sphereon/ssi-sdk.data-store' import { AuditLoggingEvent, LoggingEventType, LogLevel } from '@sphereon/ssi-sdk.core' import { v4 as uuidv4 } from 'uuid' import { schema } from '../index' -import { - EventLoggerOptions, - GetAuditEventsArgs, - IEventLogger, - RequiredContext, - LogAuditEventArgs, - LoggingEvent -} from '../types/IEventLogger' +import { EventLoggerOptions, GetAuditEventsArgs, IEventLogger, RequiredContext, LogAuditEventArgs, LoggingEvent } from '../types/IEventLogger' /** * {@inheritDoc IEventLogger} @@ -28,16 +21,16 @@ export class EventLogger implements IAgentPlugin { private readonly store: AbstractEventLoggerStore constructor(options: EventLoggerOptions) { - const {store, eventTypes} = options + const { store, eventTypes } = options this.store = store this.eventTypes = eventTypes } public async onEvent(event: LoggingEvent, context: RequiredContext): Promise { - switch(event.type) { + switch (event.type) { case LoggingEventType.AUDIT: await this.loggerLogAuditEvent({ event: event.data }, context) - break; + break default: return Promise.reject(Error('Event type not supported')) } @@ -52,15 +45,15 @@ export class EventLogger implements IAgentPlugin { private async loggerLogAuditEvent(args: LogAuditEventArgs, context: RequiredContext): Promise { const { event } = args - return this.store.storeAuditEvent({ event: { + return this.store.storeAuditEvent({ + event: { ...event, system: event.system, subSystemType: event.subSystemType, level: event.level ?? LogLevel.INFO, correlationId: event.correlationId ?? uuidv4(), - timestamp: new Date() - } + timestamp: new Date(), + }, }) } - } diff --git a/packages/event-logger/src/types/IEventLogger.ts b/packages/event-logger/src/types/IEventLogger.ts index 3c4e5287d..f8d30bce9 100644 --- a/packages/event-logger/src/types/IEventLogger.ts +++ b/packages/event-logger/src/types/IEventLogger.ts @@ -1,11 +1,5 @@ import { IAgentContext, IPluginMethodMap } from '@veramo/core' -import { - AuditLoggingEvent, - NonPersistedAuditLoggingEvent as NPAuditLoggingEvent, - LoggingEventType, - SubSystem, - System -} from '@sphereon/ssi-sdk.core' +import { AuditLoggingEvent, NonPersistedAuditLoggingEvent as NPAuditLoggingEvent, LoggingEventType, SubSystem, System } from '@sphereon/ssi-sdk.core' import { AbstractEventLoggerStore, FindAuditLoggingEventArgs } from '@sphereon/ssi-sdk.data-store' export interface IEventLogger extends IPluginMethodMap { @@ -32,7 +26,7 @@ export type NonPersistedAuditLoggingEvent = Omit): HeadersInit { + private async createHeaders(existing?: Record): Promise { const headers: HeadersInit = { ...existing, Accept: 'application/json', @@ -40,7 +40,9 @@ export class OID4VCIRestClient implements IAgentPlugin { if (!this.authOpts.bearerToken) { throw Error(`Cannot have authentication enabled, whilst not enabling static bearer tokens at this point`) } - headers.Authorization = `Bearer ${this.authOpts.bearerToken}` + headers.Authorization = `Bearer ${ + typeof this.authOpts.bearerToken === 'string' ? this.authOpts.bearerToken : await this.authOpts.bearerToken() + }` } return headers } @@ -61,7 +63,7 @@ export class OID4VCIRestClient implements IAgentPlugin { try { const origResponse = await fetch(url, { method: 'POST', - headers: this.createHeaders({ 'Content-Type': 'application/json' }), + headers: await this.createHeaders({ 'Content-Type': 'application/json' }), body: JSON.stringify(request), }) if (!origResponse.ok) { @@ -79,7 +81,7 @@ export class OID4VCIRestClient implements IAgentPlugin { const url = OID4VCIRestClient.urlWithBase('/webapp/credential-offer-status', baseUrl) const statusResponse = await fetch(url, { method: 'POST', - headers: this.createHeaders({ 'Content-Type': 'application/json' }), + headers: await this.createHeaders({ 'Content-Type': 'application/json' }), body: JSON.stringify({ id: args.id, }), diff --git a/packages/oid4vci-issuer-rest-client/src/types/IOID4VCIRestClient.ts b/packages/oid4vci-issuer-rest-client/src/types/IOID4VCIRestClient.ts index 45d1f043d..a354210b3 100644 --- a/packages/oid4vci-issuer-rest-client/src/types/IOID4VCIRestClient.ts +++ b/packages/oid4vci-issuer-rest-client/src/types/IOID4VCIRestClient.ts @@ -1,3 +1,4 @@ +import { BearerTokenArg } from '@sphereon/ssi-types' import { IAgentContext, IPluginMethodMap } from '@veramo/core' import { CredentialOfferFormat, @@ -18,7 +19,7 @@ export interface IOID4VCIClientCreateOfferUriRequestArgs extends IOID4VCIClientC export interface IRestClientAuthenticationOpts { enabled?: boolean - bearerToken?: () => Promise | string + bearerToken?: BearerTokenArg } export interface IOID4VCIClientGetIssueStatusArgs { diff --git a/packages/oid4vci-issuer-rest-client/tsconfig.json b/packages/oid4vci-issuer-rest-client/tsconfig.json index e9ca4d76a..b36610e5f 100644 --- a/packages/oid4vci-issuer-rest-client/tsconfig.json +++ b/packages/oid4vci-issuer-rest-client/tsconfig.json @@ -4,5 +4,10 @@ "esModuleInterop": true, "rootDir": "src", "outDir": "dist" - } + }, + "references": [ + { + "path": "../ssi-types" + } + ] } diff --git a/packages/siopv2-oid4vp-rp-rest-client/package.json b/packages/siopv2-oid4vp-rp-rest-client/package.json index 830d75c8d..143e31605 100644 --- a/packages/siopv2-oid4vp-rp-rest-client/package.json +++ b/packages/siopv2-oid4vp-rp-rest-client/package.json @@ -16,6 +16,7 @@ }, "dependencies": { "@sphereon/ssi-sdk.siopv2-oid4vp-common": "workspace:*", + "@sphereon/ssi-types": "workspace:*", "@veramo/core": "4.2.0", "cross-fetch": "^3.1.8" }, diff --git a/packages/siopv2-oid4vp-rp-rest-client/src/types/ISIOPv2OID4VPRPRestClient.ts b/packages/siopv2-oid4vp-rp-rest-client/src/types/ISIOPv2OID4VPRPRestClient.ts index f4f3b6a64..9a2873503 100644 --- a/packages/siopv2-oid4vp-rp-rest-client/src/types/ISIOPv2OID4VPRPRestClient.ts +++ b/packages/siopv2-oid4vp-rp-rest-client/src/types/ISIOPv2OID4VPRPRestClient.ts @@ -1,3 +1,4 @@ +import {BearerTokenArg} from "@sphereon/ssi-types"; import { IAgentContext, IPluginMethodMap } from '@veramo/core' import { AuthStatusResponse, GenerateAuthRequestURIResponse } from '@sphereon/ssi-sdk.siopv2-oid4vp-common' @@ -29,7 +30,7 @@ export interface ISiopClientGetAuthStatusArgs { export interface Siopv2RestClientAuthenticationOpts { enabled?: boolean - bearerToken?: () => Promise | string + bearerToken?: BearerTokenArg } export interface Siopv2RestClientOpts { diff --git a/packages/siopv2-oid4vp-rp-rest-client/tsconfig.json b/packages/siopv2-oid4vp-rp-rest-client/tsconfig.json index 948844d7b..14a5d4ee2 100644 --- a/packages/siopv2-oid4vp-rp-rest-client/tsconfig.json +++ b/packages/siopv2-oid4vp-rp-rest-client/tsconfig.json @@ -5,5 +5,12 @@ "rootDir": "src", "outDir": "dist" }, - "references": [{ "path": "../siopv2-oid4vp-common" }] + "references": [ + { + "path": "../ssi-types" + }, + { + "path": "../siopv2-oid4vp-common" + } + ] } diff --git a/packages/ssi-sdk-core/src/index.ts b/packages/ssi-sdk-core/src/index.ts index 0dafca5e5..e88cb7fc2 100644 --- a/packages/ssi-sdk-core/src/index.ts +++ b/packages/ssi-sdk-core/src/index.ts @@ -5,7 +5,4 @@ export * from './utils' export * from './types' export { KeyAlgo, SuppliedSigner } from './signers' -export { - EventLogger, - EventLoggerBuilder -} +export { EventLogger, EventLoggerBuilder } diff --git a/packages/ssi-sdk-core/src/loggers/eventLogger/EventLogger.ts b/packages/ssi-sdk-core/src/loggers/eventLogger/EventLogger.ts index f0947f3f6..2d938ad8f 100644 --- a/packages/ssi-sdk-core/src/loggers/eventLogger/EventLogger.ts +++ b/packages/ssi-sdk-core/src/loggers/eventLogger/EventLogger.ts @@ -1,16 +1,9 @@ import { IAgentContext } from '@veramo/core' -import { - NonPersistedAuditLoggingEvent, - EventLoggerArgs, - LoggingEvent, - LogLevel, - SubSystem, - System -} from '../../types' +import { NonPersistedAuditLoggingEvent, EventLoggerArgs, LoggingEvent, LogLevel, SubSystem, System } from '../../types' import Debug, { Debugger } from 'debug' class EventLogger { - private readonly context?: IAgentContext; + private readonly context?: IAgentContext private readonly namespace?: string private readonly system?: System private readonly subSystemType?: SubSystem @@ -18,13 +11,7 @@ class EventLogger { private readonly debug: Debugger constructor(args: EventLoggerArgs) { - const { - context, - namespace = 'sphereon:ssi-sdk:EventLogger', - system, - subSystem, - logLevel = LogLevel.INFO - } = args + const { context, namespace = 'sphereon:ssi-sdk:EventLogger', system, subSystem, logLevel = LogLevel.INFO } = args this.context = context this.namespace = namespace @@ -47,15 +34,15 @@ class EventLogger { ...event.data, ...(!event.data.level && { level: this.logLevel }), ...(!event.data.system && { system: this.system }), - ...(!event.data.subSystemType && { subSystemType: this.subSystemType }) + ...(!event.data.subSystemType && { subSystemType: this.subSystemType }), } // TODO make default behaviour more configurable once we have a logger registry - this.debug('logging event:', event); + this.debug('logging event:', event) if (this.context?.agent) { await this.context.agent.emit(event.type, eventData) } } } -export default EventLogger; +export default EventLogger diff --git a/packages/ssi-sdk-core/src/loggers/eventLogger/EventLoggerBuilder.ts b/packages/ssi-sdk-core/src/loggers/eventLogger/EventLoggerBuilder.ts index fbf426198..85f24f685 100644 --- a/packages/ssi-sdk-core/src/loggers/eventLogger/EventLoggerBuilder.ts +++ b/packages/ssi-sdk-core/src/loggers/eventLogger/EventLoggerBuilder.ts @@ -3,35 +3,35 @@ import EventLogger from './EventLogger' import { LogLevel, SubSystem, System } from '../../types' class EventLoggerBuilder { - private context?: IAgentContext; + private context?: IAgentContext private namespace?: string private system?: System private subSystem?: SubSystem private logLevel?: LogLevel withContext(context: IAgentContext): this { - this.context = context; - return this; + this.context = context + return this } withNamespace(namespace: string): this { - this.namespace = namespace; - return this; + this.namespace = namespace + return this } withSystem(system: System): this { - this.system = system; - return this; + this.system = system + return this } withSubSystem(subSystem: SubSystem): this { - this.subSystem = subSystem; - return this; + this.subSystem = subSystem + return this } withLogLevel(logLevel: LogLevel): this { - this.logLevel = logLevel; - return this; + this.logLevel = logLevel + return this } public build(): EventLogger { @@ -40,10 +40,9 @@ class EventLoggerBuilder { namespace: this.namespace, system: this.system, subSystem: this.subSystem, - logLevel: this.logLevel + logLevel: this.logLevel, }) } - } -export default EventLoggerBuilder; +export default EventLoggerBuilder diff --git a/packages/ssi-sdk-core/src/types/events.ts b/packages/ssi-sdk-core/src/types/events.ts index 811e09a34..6e0a378f6 100644 --- a/packages/ssi-sdk-core/src/types/events.ts +++ b/packages/ssi-sdk-core/src/types/events.ts @@ -4,7 +4,7 @@ export enum LogLevel { DEBUG = 0, INFO, WARNING, - ERROR + ERROR, } export enum System { @@ -38,7 +38,7 @@ export enum ActionType { READ = 'read', UPDATE = 'update', DELETE = 'delete', - EXECUTE = 'execute' + EXECUTE = 'execute', } export enum DefaultActionSubType { @@ -58,7 +58,7 @@ export type ActionSubType = DefaultActionSubType | string export enum InitiatorType { USER = 'user', SYSTEM = 'system', - EXTERNAL = 'external' + EXTERNAL = 'external', } export enum SystemCorrelationIdType { @@ -66,14 +66,14 @@ export enum SystemCorrelationIdType { EMAIL = 'email', HOSTNAME = 'hostname', PHONE = 'phone', - USER = 'user' + USER = 'user', } export enum PartyCorrelationType { DID = 'did', EMAIL = 'email', HOSTNAME = 'hostname', - PHONE = 'phone' + PHONE = 'phone', } export enum LoggingEventType { @@ -110,7 +110,7 @@ export type NonPersistedAuditLoggingEvent = Omit => { + const bearer = typeof token === 'string' ? token : await token() + + if (opts?.includeBearerHeader) { + return `Bearer ${bearer}` + } + return bearer +} diff --git a/packages/ssi-sdk-core/src/utils/index.ts b/packages/ssi-sdk-core/src/utils/index.ts index 25af8c5c0..d606aeeee 100644 --- a/packages/ssi-sdk-core/src/utils/index.ts +++ b/packages/ssi-sdk-core/src/utils/index.ts @@ -1,4 +1,5 @@ export * from './encoding' +export * from './bearer-token' export { enablePostgresUuidExtension, flattenArray, flattenMigrations } from './database' export { getImageMediaType, getImageDimensions, downloadImage } from './image' export * from './vc' diff --git a/packages/ssi-types/src/types/generic.ts b/packages/ssi-types/src/types/generic.ts index 5218e9702..511ec0d28 100644 --- a/packages/ssi-types/src/types/generic.ts +++ b/packages/ssi-types/src/types/generic.ts @@ -4,3 +4,5 @@ * @internal */ export type OrPromise = T | Promise + +export type BearerTokenArg = (() => Promise) | string diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 405ec1c75..a407ac1df 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,4 +1,4 @@ -lockfileVersion: '6.1' +lockfileVersion: '6.0' settings: autoInstallPeers: true @@ -882,6 +882,9 @@ importers: '@sphereon/oid4vci-common': specifier: 0.7.3 version: 0.7.3 + '@sphereon/ssi-types': + specifier: workspace:* + version: link:../ssi-types '@veramo/core': specifier: 4.2.0 version: 4.2.0(patch_hash=c5oempznsz4br5w3tcuk2i2mau) @@ -1388,6 +1391,9 @@ importers: '@sphereon/ssi-sdk.siopv2-oid4vp-common': specifier: workspace:* version: link:../siopv2-oid4vp-common + '@sphereon/ssi-types': + specifier: workspace:* + version: link:../ssi-types '@veramo/core': specifier: 4.2.0 version: 4.2.0(patch_hash=c5oempznsz4br5w3tcuk2i2mau)