Skip to content

Commit

Permalink
feat: Add global web resolution provider. Add json error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Jul 30, 2023
1 parent 3f49911 commit f19d1d1
Show file tree
Hide file tree
Showing 21 changed files with 613 additions and 576 deletions.
6 changes: 5 additions & 1 deletion packages/express-support/src/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Application, ApplicationRequestHandler } from 'express-serve-static-cor
import session from 'express-session'
import passport, { InitializeOptions } from 'passport'
import { checkUserIsInRole } from './auth-utils'
import { env } from './functions'
import { env, jsonErrorHandler } from './functions'
import { ExpressBuildResult, IExpressServerOpts } from './types'
import * as dotenv from 'dotenv-flow'

Expand Down Expand Up @@ -194,6 +194,9 @@ export class ExpressBuilder {
if (this._corsConfigurer) {
this._corsConfigurer.configure({ existingExpress: app })
}

app.use(jsonErrorHandler)

// @ts-ignore
this._handlers && this._handlers.length > 0 && app.use(this._handlers)
// @ts-ignore
Expand Down Expand Up @@ -254,6 +257,7 @@ export class ExpressCorsConfigurer {
if (!express) {
throw Error('No express passed in during construction or configure')
}

const disableCorsEnv = env('CORS_DISABLE', this._envVarPrefix)
const corsDisabled = this._disableCors ?? (disableCorsEnv ? /true/.test(disableCorsEnv) : false)
if (corsDisabled) {
Expand Down
11 changes: 9 additions & 2 deletions packages/express-support/src/functions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import express from 'express'
import express, { NextFunction } from 'express'
import process from 'process'

export function env(key?: string, prefix?: string): string | undefined {
Expand All @@ -14,5 +14,12 @@ export function sendErrorResponse(response: express.Response, statusCode: number
console.log(error)
}
response.statusCode = statusCode
return response.status(statusCode).end(message)
return response.status(statusCode).json(message.startsWith('{') ? message : JSON.stringify(message, null, 2))
}

export const jsonErrorHandler = (err: any, req: express.Request, res: express.Response, next: NextFunction) => {
if (res.headersSent) {
return next(err)
}
return sendErrorResponse(res, 500, err.message, err)
}
2 changes: 1 addition & 1 deletion packages/express-support/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './auth-utils'
export * from './builders'
export * from './types'
export { sendErrorResponse } from './functions'
export { sendErrorResponse, jsonErrorHandler } from './functions'
8 changes: 4 additions & 4 deletions packages/oid4vci-issuer-rest-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
"@sphereon/did-uni-client": "^0.6.0",
"@sphereon/pex": "^2.0.1",
"@sphereon/pex-models": "^2.0.2",
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.12.2-next.5",
"@sphereon/ssi-sdk-ext.key-manager": "0.12.2-next.5",
"@sphereon/ssi-sdk-ext.key-utils": "0.12.2-next.5",
"@sphereon/ssi-sdk-ext.kms-local": "0.12.2-next.5",
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.12.2-next.12",
"@sphereon/ssi-sdk-ext.key-manager": "0.12.2-next.12",
"@sphereon/ssi-sdk-ext.key-utils": "0.12.2-next.12",
"@sphereon/ssi-sdk-ext.kms-local": "0.12.2-next.12",
"@sphereon/ssi-sdk.data-store": "workspace:*",
"@sphereon/ssi-sdk.vc-handler-ld-local": "workspace:*",
"@types/body-parser": "^1.19.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/oid4vci-issuer-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"dependencies": {
"@sphereon/oid4vci-common": "0.6.0",
"@sphereon/ssi-sdk-ext.did-utils": "0.12.2-next.5",
"@sphereon/ssi-sdk-ext.did-utils": "0.12.2-next.12",
"@sphereon/ssi-sdk.kv-store-temp": "workspace:*",
"@types/uuid": "^9.0.1",
"@veramo/core": "4.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/oid4vci-issuer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dependencies": {
"@sphereon/oid4vci-common": "0.6.0",
"@sphereon/oid4vci-issuer": "0.6.0",
"@sphereon/ssi-sdk-ext.did-utils": "0.12.2-next.5",
"@sphereon/ssi-sdk-ext.did-utils": "0.12.2-next.12",
"@sphereon/ssi-sdk.core": "workspace:*",
"@sphereon/ssi-sdk.kv-store-temp": "workspace:*",
"@sphereon/ssi-sdk.oid4vci-issuer-store": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/presentation-exchange/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dependencies": {
"@sphereon/pex": "2.0.1",
"@sphereon/pex-models": "^2.0.2",
"@sphereon/ssi-sdk-ext.did-utils": "0.12.2-next.5",
"@sphereon/ssi-sdk-ext.did-utils": "0.12.2-next.12",
"@sphereon/ssi-sdk.kv-store-temp": "workspace:*",
"@sphereon/ssi-types": "workspace:*",
"@veramo/core": "4.2.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/siopv2-oid4vp-op-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@sphereon/did-auth-siop": "0.3.2-unstable.6",
"@sphereon/pex": "2.0.1",
"@sphereon/pex-models": "2.0.2",
"@sphereon/ssi-sdk-ext.did-utils": "0.12.2-next.5",
"@sphereon/ssi-sdk-ext.did-utils": "0.12.2-next.12",
"@sphereon/ssi-sdk.core": "workspace:*",
"@sphereon/ssi-sdk.presentation-exchange": "workspace:*",
"@sphereon/ssi-types": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/siopv2-oid4vp-rp-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dependencies": {
"@sphereon/did-auth-siop": "0.3.2-unstable.6",
"@sphereon/pex": "2.0.1",
"@sphereon/ssi-sdk-ext.did-utils": "0.12.2-next.5",
"@sphereon/ssi-sdk-ext.did-utils": "0.12.2-next.12",
"@sphereon/ssi-sdk.core": "workspace:*",
"@sphereon/ssi-sdk.kv-store-temp": "workspace:*",
"@sphereon/ssi-sdk.presentation-exchange": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/siopv2-oid4vp-rp-rest-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@sphereon/did-uni-client": "^0.6.0",
"@sphereon/pex": "^2.0.1",
"@sphereon/pex-models": "^2.0.2",
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.12.2-next.5",
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.12.2-next.12",
"@sphereon/ssi-sdk.data-store": "workspace:*",
"@sphereon/ssi-sdk.vc-handler-ld-local": "workspace:*",
"@types/body-parser": "^1.19.2",
Expand Down
5 changes: 3 additions & 2 deletions packages/uni-resolver-registrar-api/__tests__/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export enum SupportedDidMethodEnum {

const PRIVATE_KEY_HEX =
'ea6aaeebe17557e0fe256bfce08e8224a412ea1e25a5ec8b5d69618a58bad89e89a4661e446b46401325a38d3b20582d1dd277eb448a3181012a671b7ae15837'
const PUBLIC_KEY_HEX = '89a4661e446b46401325a38d3b20582d1dd277eb448a3181012a671b7ae15837'
// const PUBLIC_KEY_HEX = '89a4661e446b46401325a38d3b20582d1dd277eb448a3181012a671b7ae15837'

export const resolver = new Resolver({
...getUniResolver('ethr', {
Expand Down Expand Up @@ -188,7 +188,7 @@ agent
.finally(() => {
const builder = ExpressBuilder.fromServerOpts({
port: 5000,
envVarPrefix: 'DID_API_',
// envVarPrefix: 'DID_API_',
hostname: '0.0.0.0',
}).withPassportAuth(false)
// .withSessionOptions({secret: '1234', name: 'oidc-session'})
Expand All @@ -199,6 +199,7 @@ agent

new UniResolverApiServer({
opts: {
enableFeatures: ['did-persist', 'did-resolve', 'did-web-global-resolution'],
endpointOpts: {
globalAuth: {
authentication: {
Expand Down
Binary file not shown.

This file was deleted.

10 changes: 5 additions & 5 deletions packages/uni-resolver-registrar-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"@sphereon/ssi-sdk.express-support": "workspace:*",
"@sphereon/ssi-sdk.core": "workspace:*",
"@sphereon/ssi-types": "workspace:*",
"@sphereon/ssi-sdk-ext.did-utils": "0.12.2-next.5",
"@sphereon/ssi-sdk-ext.key-utils": "0.12.2-next.5",
"@sphereon/ssi-sdk-ext.key-manager": "0.12.2-next.5",
"@sphereon/ssi-sdk-ext.did-utils": "0.12.2-next.12",
"@sphereon/ssi-sdk-ext.key-utils": "0.12.2-next.12",
"@sphereon/ssi-sdk-ext.key-manager": "0.12.2-next.12",
"casbin": "^5.26.1",
"@veramo/core": "4.2.0",
"body-parser": "^1.19.0",
Expand All @@ -34,8 +34,8 @@
"passport": "^0.6.0",
"passport-azure-ad": "^4.3.5",
"morgan": "^1.10.0",
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.12.2-next.5",
"@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.12.2-next.5",
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.12.2-next.12",
"@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.12.2-next.12",
"@sphereon/ssi-sdk.data-store": "workspace:*",
"@sphereon/ssi-sdk.vc-handler-ld-local": "workspace:*",
"@types/morgan": "^1.9.4",
Expand Down
Loading

0 comments on commit f19d1d1

Please sign in to comment.