@sphereon/ssi-sdk.linked-vp-rest-api 0.34.1-feature.SSISDK.82.linkedVP.326 → 0.34.1-feature.SSISDK.82.linkedVP.327
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +38 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +38 -2
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/src/api-functions.ts +47 -2
package/dist/index.cjs
CHANGED
|
@@ -46,6 +46,7 @@ var import_express = __toESM(require("express"), 1);
|
|
|
46
46
|
|
|
47
47
|
// src/api-functions.ts
|
|
48
48
|
var import_ssi_express_support = require("@sphereon/ssi-express-support");
|
|
49
|
+
var import_ssi_types = require("@sphereon/ssi-types");
|
|
49
50
|
var operation = "/linked-vp";
|
|
50
51
|
function publishCredentialEndpoint(router, context, opts) {
|
|
51
52
|
if (opts?.enabled === false) {
|
|
@@ -139,17 +140,52 @@ function generatePresentationEndpoint(router, context, opts) {
|
|
|
139
140
|
router.get(`${path}/:linkedVpId`, (0, import_ssi_express_support.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
140
141
|
try {
|
|
141
142
|
const linkedVpId = request.params.linkedVpId;
|
|
142
|
-
const
|
|
143
|
+
const linkedVPPresentation = await context.agent.lvpGeneratePresentation({
|
|
143
144
|
linkedVpId
|
|
144
145
|
});
|
|
145
146
|
response.statusCode = 200;
|
|
146
|
-
|
|
147
|
+
response.contentType(contentTypeFromDocumentFormat(linkedVPPresentation.documentFormat));
|
|
148
|
+
response.setHeader("Content-Disposition", `attachment; filename="${linkedVpId}${extensionFromDocumentFormat(linkedVPPresentation.documentFormat)}"`);
|
|
149
|
+
if (typeof linkedVPPresentation.presentationPayload === "string") {
|
|
150
|
+
return response.send(linkedVPPresentation.presentationPayload);
|
|
151
|
+
}
|
|
152
|
+
return response.json(linkedVPPresentation.presentationPayload);
|
|
147
153
|
} catch (error) {
|
|
148
154
|
return (0, import_ssi_express_support.sendErrorResponse)(response, 500, error.message, error);
|
|
149
155
|
}
|
|
150
156
|
});
|
|
151
157
|
}
|
|
152
158
|
__name(generatePresentationEndpoint, "generatePresentationEndpoint");
|
|
159
|
+
var contentTypeFromDocumentFormat = /* @__PURE__ */ __name((documentFormat) => {
|
|
160
|
+
switch (documentFormat) {
|
|
161
|
+
case import_ssi_types.DocumentFormat.JSONLD:
|
|
162
|
+
return "application/vp+ld+json";
|
|
163
|
+
case import_ssi_types.DocumentFormat.EIP712:
|
|
164
|
+
return "application/eip712+json";
|
|
165
|
+
case import_ssi_types.DocumentFormat.SD_JWT_VC:
|
|
166
|
+
return "application/sd-jwt";
|
|
167
|
+
case import_ssi_types.DocumentFormat.MSO_MDOC:
|
|
168
|
+
return "application/mso+cbor";
|
|
169
|
+
case import_ssi_types.DocumentFormat.JWT:
|
|
170
|
+
return "application/jwt";
|
|
171
|
+
}
|
|
172
|
+
}, "contentTypeFromDocumentFormat");
|
|
173
|
+
var extensionFromDocumentFormat = /* @__PURE__ */ __name((format) => {
|
|
174
|
+
switch (format) {
|
|
175
|
+
case import_ssi_types.DocumentFormat.JSONLD:
|
|
176
|
+
return ".jsonld";
|
|
177
|
+
case import_ssi_types.DocumentFormat.EIP712:
|
|
178
|
+
return ".eip712.json";
|
|
179
|
+
case import_ssi_types.DocumentFormat.SD_JWT_VC:
|
|
180
|
+
return ".sd-jwt";
|
|
181
|
+
case import_ssi_types.DocumentFormat.MSO_MDOC:
|
|
182
|
+
return ".cbor";
|
|
183
|
+
case import_ssi_types.DocumentFormat.JWT:
|
|
184
|
+
return ".jwt";
|
|
185
|
+
default:
|
|
186
|
+
return "";
|
|
187
|
+
}
|
|
188
|
+
}, "extensionFromDocumentFormat");
|
|
153
189
|
|
|
154
190
|
// src/linked-vp-api-server.ts
|
|
155
191
|
var import_ssi_express_support2 = require("@sphereon/ssi-express-support");
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/linked-vp-api-server.ts","../src/api-functions.ts"],"sourcesContent":["export * from './types'\nexport * from './linked-vp-api-server'\nexport * from './api-functions'\n\nexport type {\n PublishCredentialArgs,\n UnpublishCredentialArgs,\n HasLinkedVPEntryArgs,\n GetServiceEntriesArgs,\n GeneratePresentationArgs,\n LinkedVPEntry,\n LinkedVPServiceEntry,\n LinkedVPPresentation,\n} from '@sphereon/ssi-sdk.linked-vp'\n","import { agentContext } from '@sphereon/ssi-sdk.core'\nimport { TAgent } from '@veramo/core'\n\nimport express, { Express, Router } from 'express'\nimport { ILinkedVPManagerAPIEndpointOpts, IRequiredPlugins } from './types'\nimport {\n publishCredentialEndpoint,\n unpublishCredentialEndpoint,\n hasEntryEndpoint,\n getServiceEntriesEndpoint,\n generatePresentationEndpoint,\n} from './api-functions'\nimport { copyGlobalAuthToEndpoints, ExpressSupport } from '@sphereon/ssi-express-support'\n\nexport type LinkedVPManagerApiServerArgs = {\n agent: TAgent<IRequiredPlugins>\n expressSupport: ExpressSupport\n opts?: ILinkedVPManagerAPIEndpointOpts\n}\n\nexport class LinkedVpApiServer {\n private readonly _express: Express\n private readonly _agent: TAgent<IRequiredPlugins>\n private readonly _opts?: ILinkedVPManagerAPIEndpointOpts\n private readonly _router: Router\n\n constructor(args: LinkedVPManagerApiServerArgs) {\n const { agent, opts } = args\n this._agent = agent\n\n if (opts?.endpointOpts?.globalAuth?.secureLinkedVPManagerEndpoints) {\n copyGlobalAuthToEndpoints({\n opts,\n keys: ['publishManagement', 'serviceEntries', 'generatePresentation'],\n })\n }\n\n this._opts = opts\n this._express = args.expressSupport.express\n this._router = express.Router()\n const context = agentContext(agent)\n const features = opts?.enableFeatures ?? ['publish-management', 'service-entries', 'generate-presentation']\n console.log(`Linked VP API enabled, with features: ${JSON.stringify(features)}`)\n\n // Publish Management Endpoints\n if (features.includes('publish-management')) {\n publishCredentialEndpoint(this.router, context, this._opts?.endpointOpts?.publishManagement)\n unpublishCredentialEndpoint(this.router, context, this._opts?.endpointOpts?.publishManagement)\n hasEntryEndpoint(this.router, context, this._opts?.endpointOpts?.publishManagement)\n }\n\n // Service Entries Endpoint\n if (features.includes('service-entries')) {\n getServiceEntriesEndpoint(this.router, context, this._opts?.endpointOpts?.serviceEntries)\n }\n\n // Generate Presentation Endpoint\n if (features.includes('generate-presentation')) {\n generatePresentationEndpoint(this.router, context, this._opts?.endpointOpts?.generatePresentation)\n }\n\n this._express.use(opts?.endpointOpts?.basePath ?? '', this.router)\n }\n\n get express(): Express {\n return this._express\n }\n\n get router(): Router {\n return this._router\n }\n\n get agent(): TAgent<IRequiredPlugins> {\n return this._agent\n }\n\n get opts(): ILinkedVPManagerAPIEndpointOpts | undefined {\n return this._opts\n }\n}\n","import { checkAuth, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'\nimport {\n GeneratePresentationArgs,\n GetServiceEntriesArgs,\n HasLinkedVPEntryArgs,\n PublishCredentialArgs,\n UnpublishCredentialArgs,\n} from '@sphereon/ssi-sdk.linked-vp'\nimport { Request, Response, Router } from 'express'\nimport { IRequiredContext } from './types'\n\nconst operation = '/linked-vp'\n\n// Publish Management Endpoints\nexport function publishCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`\"publishCredentialEndpoint\" Endpoint is disabled`)\n return\n }\n const path = opts?.path ?? operation\n router.post(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const args = request.body as PublishCredentialArgs\n const entry = await context.agent.lvpPublishCredential(args)\n response.statusCode = 201\n return response.json(entry)\n } catch (error) {\n console.error(error)\n return sendErrorResponse(response, 500, error.message, error)\n }\n })\n}\n\nexport function unpublishCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`\"unpublishCredentialEndpoint\" Endpoint is disabled`)\n return\n }\n const path = opts?.path ?? operation\n router.delete(`${path}/:linkedVpId`, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const linkedVpId = request.params.linkedVpId\n const result = await context.agent.lvpUnpublishCredential({ linkedVpId } as UnpublishCredentialArgs)\n response.statusCode = 200\n return response.json({ success: result })\n } catch (error) {\n return sendErrorResponse(response, 500, error.message, error)\n }\n })\n}\n\nexport function hasEntryEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`\"hasEntryEndpoint\" Endpoint is disabled`)\n return\n }\n const path = opts?.path ?? operation\n router.get(`${path}/:linkedVpId/exists`, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const linkedVpId = request.params.linkedVpId\n const result = await context.agent.lvpHasEntry({ linkedVpId } as HasLinkedVPEntryArgs)\n response.statusCode = 200\n return response.json({ exists: result })\n } catch (error) {\n return sendErrorResponse(response, 500, error.message as string, error)\n }\n })\n}\n\n// Service Entries Endpoint\nexport function getServiceEntriesEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`\"getServiceEntriesEndpoint\" Endpoint is disabled`)\n return\n }\n const path = opts?.path ?? `${operation}/service-entries`\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const tenantId = request.query.tenantId as string | undefined\n const entries = await context.agent.lvpGetServiceEntries({ tenantId } as GetServiceEntriesArgs)\n response.statusCode = 200\n return response.json(entries)\n } catch (error) {\n return sendErrorResponse(response, 500, error.message as string, error)\n }\n })\n}\n\n// Generate Presentation Endpoint\nexport function generatePresentationEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`\"generatePresentationEndpoint\" Endpoint is disabled`)\n return\n }\n const path = opts?.path ?? operation\n router.get(`${path}/:linkedVpId`, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const linkedVpId = request.params.linkedVpId\n const presentation = await context.agent.lvpGeneratePresentation({ linkedVpId } as GeneratePresentationArgs)\n response.statusCode = 200\n return response.json(presentation)\n } catch (error) {\n return sendErrorResponse(response, 500, error.message as string, error)\n }\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;ACAA,qBAA6B;AAG7B,qBAAyC;;;ACHzC,iCAAkE;AAWlE,IAAMA,YAAY;AAGX,SAASC,0BAA0BC,QAAgBC,SAA2BC,MAA0B;AAC7G,MAAIA,MAAMC,YAAY,OAAO;AAC3BC,YAAQC,IAAI,kDAAkD;AAC9D;EACF;AACA,QAAMC,OAAOJ,MAAMI,QAAQR;AAC3BE,SAAOO,KAAKD,UAAME,sCAAUN,MAAMO,QAAAA,GAAW,OAAOC,SAAkBC,aAAAA;AACpE,QAAI;AACF,YAAMC,OAAOF,QAAQG;AACrB,YAAMC,QAAQ,MAAMb,QAAQc,MAAMC,qBAAqBJ,IAAAA;AACvDD,eAASM,aAAa;AACtB,aAAON,SAASO,KAAKJ,KAAAA;IACvB,SAASK,OAAO;AACdf,cAAQe,MAAMA,KAAAA;AACd,iBAAOC,8CAAkBT,UAAU,KAAKQ,MAAME,SAASF,KAAAA;IACzD;EACF,CAAA;AACF;AAjBgBpB;AAmBT,SAASuB,4BAA4BtB,QAAgBC,SAA2BC,MAA0B;AAC/G,MAAIA,MAAMC,YAAY,OAAO;AAC3BC,YAAQC,IAAI,oDAAoD;AAChE;EACF;AACA,QAAMC,OAAOJ,MAAMI,QAAQR;AAC3BE,SAAOuB,OAAO,GAAGjB,IAAAA,oBAAoBE,sCAAUN,MAAMO,QAAAA,GAAW,OAAOC,SAAkBC,aAAAA;AACvF,QAAI;AACF,YAAMa,aAAad,QAAQe,OAAOD;AAClC,YAAME,SAAS,MAAMzB,QAAQc,MAAMY,uBAAuB;QAAEH;MAAW,CAAA;AACvEb,eAASM,aAAa;AACtB,aAAON,SAASO,KAAK;QAAEU,SAASF;MAAO,CAAA;IACzC,SAASP,OAAO;AACd,iBAAOC,8CAAkBT,UAAU,KAA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K,cAAcmB,iBAAAA;IACnE;AAGA,QAAIT,SAASM,SAAS,iBAAA,GAAoB;AACxCM,gCAA0B,KAAKJ,QAAQV,SAAS,KAAKb,OAAOK,cAAcuB,cAAAA;IAC5E;AAGA,QAAIb,SAASM,SAAS,uBAAA,GAA0B;AAC9CQ,mCAA6B,KAAKN,QAAQV,SAAS,KAAKb,OAAOK,cAAcyB,oBAAAA;IAC/E;AAEA,SAAKhC,SAASiC,IAAI3B,MAAMC,cAAc2B,YAAY,IAAI,KAAKT,MAAM;EACnE;EAEA,IAAIZ,UAAmB;AACrB,WAAO,KAAKb;EACd;EAEA,IAAIyB,SAAiB;AACnB,WAAO,KAAKtB;EACd;EAEA,IAAIE,QAAkC;AACpC,WAAO,KAAKJ;EACd;EAEA,IAAIK,OAAoD;AACtD,WAAO,KAAKJ;EACd;AACF;","names":["operation","publishCredentialEndpoint","router","context","opts","enabled","console","log","path","post","checkAuth","endpoint","request","response","args","body","entry","agent","lvpPublishCredential","statusCode","json","error","sendErrorResponse","message","unpublishCredentialEndpoint","delete","linkedVpId","params","result","lvpUnpublishCredential","success","hasEntryEndpoint","get","lvpHasEntry","exists","getServiceEntriesEndpoint","tenantId","query","entries","lvpGetServiceEntries","generatePresentationEndpoint","presentation","lvpGeneratePresentation","import_ssi_express_support","LinkedVpApiServer","_express","_agent","_opts","_router","args","agent","opts","endpointOpts","globalAuth","secureLinkedVPManagerEndpoints","copyGlobalAuthToEndpoints","keys","expressSupport","express","Router","context","agentContext","features","enableFeatures","console","log","JSON","stringify","includes","publishCredentialEndpoint","router","publishManagement","unpublishCredentialEndpoint","hasEntryEndpoint","getServiceEntriesEndpoint","serviceEntries","generatePresentationEndpoint","generatePresentation","use","basePath"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/linked-vp-api-server.ts","../src/api-functions.ts"],"sourcesContent":["export * from './types'\nexport * from './linked-vp-api-server'\nexport * from './api-functions'\n\nexport type {\n PublishCredentialArgs,\n UnpublishCredentialArgs,\n HasLinkedVPEntryArgs,\n GetServiceEntriesArgs,\n GeneratePresentationArgs,\n LinkedVPEntry,\n LinkedVPServiceEntry,\n LinkedVPPresentation,\n} from '@sphereon/ssi-sdk.linked-vp'\n","import { agentContext } from '@sphereon/ssi-sdk.core'\nimport { TAgent } from '@veramo/core'\n\nimport express, { Express, Router } from 'express'\nimport { ILinkedVPManagerAPIEndpointOpts, IRequiredPlugins } from './types'\nimport {\n publishCredentialEndpoint,\n unpublishCredentialEndpoint,\n hasEntryEndpoint,\n getServiceEntriesEndpoint,\n generatePresentationEndpoint,\n} from './api-functions'\nimport { copyGlobalAuthToEndpoints, ExpressSupport } from '@sphereon/ssi-express-support'\n\nexport type LinkedVPManagerApiServerArgs = {\n agent: TAgent<IRequiredPlugins>\n expressSupport: ExpressSupport\n opts?: ILinkedVPManagerAPIEndpointOpts\n}\n\nexport class LinkedVpApiServer {\n private readonly _express: Express\n private readonly _agent: TAgent<IRequiredPlugins>\n private readonly _opts?: ILinkedVPManagerAPIEndpointOpts\n private readonly _router: Router\n\n constructor(args: LinkedVPManagerApiServerArgs) {\n const { agent, opts } = args\n this._agent = agent\n\n if (opts?.endpointOpts?.globalAuth?.secureLinkedVPManagerEndpoints) {\n copyGlobalAuthToEndpoints({\n opts,\n keys: ['publishManagement', 'serviceEntries', 'generatePresentation'],\n })\n }\n\n this._opts = opts\n this._express = args.expressSupport.express\n this._router = express.Router()\n const context = agentContext(agent)\n const features = opts?.enableFeatures ?? ['publish-management', 'service-entries', 'generate-presentation']\n console.log(`Linked VP API enabled, with features: ${JSON.stringify(features)}`)\n\n // Publish Management Endpoints\n if (features.includes('publish-management')) {\n publishCredentialEndpoint(this.router, context, this._opts?.endpointOpts?.publishManagement)\n unpublishCredentialEndpoint(this.router, context, this._opts?.endpointOpts?.publishManagement)\n hasEntryEndpoint(this.router, context, this._opts?.endpointOpts?.publishManagement)\n }\n\n // Service Entries Endpoint\n if (features.includes('service-entries')) {\n getServiceEntriesEndpoint(this.router, context, this._opts?.endpointOpts?.serviceEntries)\n }\n\n // Generate Presentation Endpoint\n if (features.includes('generate-presentation')) {\n generatePresentationEndpoint(this.router, context, this._opts?.endpointOpts?.generatePresentation)\n }\n\n this._express.use(opts?.endpointOpts?.basePath ?? '', this.router)\n }\n\n get express(): Express {\n return this._express\n }\n\n get router(): Router {\n return this._router\n }\n\n get agent(): TAgent<IRequiredPlugins> {\n return this._agent\n }\n\n get opts(): ILinkedVPManagerAPIEndpointOpts | undefined {\n return this._opts\n }\n}\n","import { checkAuth, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'\nimport {\n GeneratePresentationArgs,\n GetServiceEntriesArgs,\n HasLinkedVPEntryArgs,\n PublishCredentialArgs,\n UnpublishCredentialArgs,\n} from '@sphereon/ssi-sdk.linked-vp'\nimport { DocumentFormat } from '@sphereon/ssi-types'\nimport { Request, Response, Router } from 'express'\nimport { IRequiredContext } from './types'\n\nconst operation = '/linked-vp'\n\n// Publish Management Endpoints\nexport function publishCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`\"publishCredentialEndpoint\" Endpoint is disabled`)\n return\n }\n const path = opts?.path ?? operation\n router.post(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const args = request.body as PublishCredentialArgs\n const entry = await context.agent.lvpPublishCredential(args)\n response.statusCode = 201\n return response.json(entry)\n } catch (error) {\n console.error(error)\n return sendErrorResponse(response, 500, error.message, error)\n }\n })\n}\n\nexport function unpublishCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`\"unpublishCredentialEndpoint\" Endpoint is disabled`)\n return\n }\n const path = opts?.path ?? operation\n router.delete(`${path}/:linkedVpId`, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const linkedVpId = request.params.linkedVpId\n const result = await context.agent.lvpUnpublishCredential({ linkedVpId } as UnpublishCredentialArgs)\n response.statusCode = 200\n return response.json({ success: result })\n } catch (error) {\n return sendErrorResponse(response, 500, error.message, error)\n }\n })\n}\n\nexport function hasEntryEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`\"hasEntryEndpoint\" Endpoint is disabled`)\n return\n }\n const path = opts?.path ?? operation\n router.get(`${path}/:linkedVpId/exists`, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const linkedVpId = request.params.linkedVpId\n const result = await context.agent.lvpHasEntry({ linkedVpId } as HasLinkedVPEntryArgs)\n response.statusCode = 200\n return response.json({ exists: result })\n } catch (error) {\n return sendErrorResponse(response, 500, error.message as string, error)\n }\n })\n}\n\n// Service Entries Endpoint\nexport function getServiceEntriesEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`\"getServiceEntriesEndpoint\" Endpoint is disabled`)\n return\n }\n const path = opts?.path ?? `${operation}/service-entries`\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const tenantId = request.query.tenantId as string | undefined\n const entries = await context.agent.lvpGetServiceEntries({ tenantId } as GetServiceEntriesArgs)\n response.statusCode = 200\n return response.json(entries)\n } catch (error) {\n return sendErrorResponse(response, 500, error.message as string, error)\n }\n })\n}\n\n// Generate Presentation Endpoint\nexport function generatePresentationEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`\"generatePresentationEndpoint\" Endpoint is disabled`)\n return\n }\n const path = opts?.path ?? operation\n router.get(`${path}/:linkedVpId`, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const linkedVpId = request.params.linkedVpId\n const linkedVPPresentation = await context.agent.lvpGeneratePresentation({ linkedVpId } as GeneratePresentationArgs)\n response.statusCode = 200\n response.contentType(contentTypeFromDocumentFormat(linkedVPPresentation.documentFormat))\n response.setHeader(\n 'Content-Disposition',\n `attachment; filename=\"${linkedVpId}${extensionFromDocumentFormat(linkedVPPresentation.documentFormat)}\"`,\n )\n if (typeof linkedVPPresentation.presentationPayload === 'string') {\n return response.send(linkedVPPresentation.presentationPayload)\n }\n return response.json(linkedVPPresentation.presentationPayload)\n } catch (error) {\n return sendErrorResponse(response, 500, error.message as string, error)\n }\n })\n}\n\nconst contentTypeFromDocumentFormat = (documentFormat: DocumentFormat): string => {\n switch (documentFormat) {\n case DocumentFormat.JSONLD:\n return 'application/vp+ld+json'\n\n case DocumentFormat.EIP712:\n return 'application/eip712+json'\n\n case DocumentFormat.SD_JWT_VC:\n return 'application/sd-jwt'\n\n case DocumentFormat.MSO_MDOC:\n return 'application/mso+cbor'\n\n case DocumentFormat.JWT:\n return 'application/jwt'\n }\n}\n\nconst extensionFromDocumentFormat = (format: DocumentFormat): string => {\n switch (format) {\n case DocumentFormat.JSONLD:\n return '.jsonld'\n case DocumentFormat.EIP712:\n return '.eip712.json'\n case DocumentFormat.SD_JWT_VC:\n return '.sd-jwt'\n case DocumentFormat.MSO_MDOC:\n return '.cbor'\n case DocumentFormat.JWT:\n return '.jwt'\n default:\n return ''\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;ACAA,qBAA6B;AAG7B,qBAAyC;;;ACHzC,iCAAkE;AAQlE,uBAA+B;AAI/B,IAAMA,YAAY;AAGX,SAASC,0BAA0BC,QAAgBC,SAA2BC,MAA0B;AAC7G,MAAIA,MAAMC,YAAY,OAAO;AAC3BC,YAAQC,IAAI,kDAAkD;AAC9D;EACF;AACA,QAAMC,OAAOJ,MAAMI,QAAQR;AAC3BE,SAAOO,KAAKD,UAAME,sCAAUN,MAAMO,QAAAA,GAAW,OAAOC,SAAkBC,aAAAA;AACpE,QAAI;AACF,YAAMC,OAAOF,QAAQG;AACrB,YAAMC,QAAQ,MAAMb,QAAQc,MAAMC,qBAAqBJ,IAAAA;AACvDD,eAASM,aAAa;AACtB,aAAON,SAASO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AKC,QAAQV,SAAS,KAAKb,OAAOK,cAAcmB,iBAAAA;AAC1EC,kCAA4B,KAAKF,QAAQV,SAAS,KAAKb,OAAOK,cAAcmB,iBAAAA;AAC5EE,uBAAiB,KAAKH,QAAQV,SAAS,KAAKb,OAAOK,cAAcmB,iBAAAA;IACnE;AAGA,QAAIT,SAASM,SAAS,iBAAA,GAAoB;AACxCM,gCAA0B,KAAKJ,QAAQV,SAAS,KAAKb,OAAOK,cAAcuB,cAAAA;IAC5E;AAGA,QAAIb,SAASM,SAAS,uBAAA,GAA0B;AAC9CQ,mCAA6B,KAAKN,QAAQV,SAAS,KAAKb,OAAOK,cAAcyB,oBAAAA;IAC/E;AAEA,SAAKhC,SAASiC,IAAI3B,MAAMC,cAAc2B,YAAY,IAAI,KAAKT,MAAM;EACnE;EAEA,IAAIZ,UAAmB;AACrB,WAAO,KAAKb;EACd;EAEA,IAAIyB,SAAiB;AACnB,WAAO,KAAKtB;EACd;EAEA,IAAIE,QAAkC;AACpC,WAAO,KAAKJ;EACd;EAEA,IAAIK,OAAoD;AACtD,WAAO,KAAKJ;EACd;AACF;","names":["operation","publishCredentialEndpoint","router","context","opts","enabled","console","log","path","post","checkAuth","endpoint","request","response","args","body","entry","agent","lvpPublishCredential","statusCode","json","error","sendErrorResponse","message","unpublishCredentialEndpoint","delete","linkedVpId","params","result","lvpUnpublishCredential","success","hasEntryEndpoint","get","lvpHasEntry","exists","getServiceEntriesEndpoint","tenantId","query","entries","lvpGetServiceEntries","generatePresentationEndpoint","linkedVPPresentation","lvpGeneratePresentation","contentType","contentTypeFromDocumentFormat","documentFormat","setHeader","extensionFromDocumentFormat","presentationPayload","send","DocumentFormat","JSONLD","EIP712","SD_JWT_VC","MSO_MDOC","JWT","format","import_ssi_express_support","LinkedVpApiServer","_express","_agent","_opts","_router","args","agent","opts","endpointOpts","globalAuth","secureLinkedVPManagerEndpoints","copyGlobalAuthToEndpoints","keys","expressSupport","express","Router","context","agentContext","features","enableFeatures","console","log","JSON","stringify","includes","publishCredentialEndpoint","router","publishManagement","unpublishCredentialEndpoint","hasEntryEndpoint","getServiceEntriesEndpoint","serviceEntries","generatePresentationEndpoint","generatePresentation","use","basePath"]}
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import express from "express";
|
|
|
7
7
|
|
|
8
8
|
// src/api-functions.ts
|
|
9
9
|
import { checkAuth, sendErrorResponse } from "@sphereon/ssi-express-support";
|
|
10
|
+
import { DocumentFormat } from "@sphereon/ssi-types";
|
|
10
11
|
var operation = "/linked-vp";
|
|
11
12
|
function publishCredentialEndpoint(router, context, opts) {
|
|
12
13
|
if (opts?.enabled === false) {
|
|
@@ -100,17 +101,52 @@ function generatePresentationEndpoint(router, context, opts) {
|
|
|
100
101
|
router.get(`${path}/:linkedVpId`, checkAuth(opts?.endpoint), async (request, response) => {
|
|
101
102
|
try {
|
|
102
103
|
const linkedVpId = request.params.linkedVpId;
|
|
103
|
-
const
|
|
104
|
+
const linkedVPPresentation = await context.agent.lvpGeneratePresentation({
|
|
104
105
|
linkedVpId
|
|
105
106
|
});
|
|
106
107
|
response.statusCode = 200;
|
|
107
|
-
|
|
108
|
+
response.contentType(contentTypeFromDocumentFormat(linkedVPPresentation.documentFormat));
|
|
109
|
+
response.setHeader("Content-Disposition", `attachment; filename="${linkedVpId}${extensionFromDocumentFormat(linkedVPPresentation.documentFormat)}"`);
|
|
110
|
+
if (typeof linkedVPPresentation.presentationPayload === "string") {
|
|
111
|
+
return response.send(linkedVPPresentation.presentationPayload);
|
|
112
|
+
}
|
|
113
|
+
return response.json(linkedVPPresentation.presentationPayload);
|
|
108
114
|
} catch (error) {
|
|
109
115
|
return sendErrorResponse(response, 500, error.message, error);
|
|
110
116
|
}
|
|
111
117
|
});
|
|
112
118
|
}
|
|
113
119
|
__name(generatePresentationEndpoint, "generatePresentationEndpoint");
|
|
120
|
+
var contentTypeFromDocumentFormat = /* @__PURE__ */ __name((documentFormat) => {
|
|
121
|
+
switch (documentFormat) {
|
|
122
|
+
case DocumentFormat.JSONLD:
|
|
123
|
+
return "application/vp+ld+json";
|
|
124
|
+
case DocumentFormat.EIP712:
|
|
125
|
+
return "application/eip712+json";
|
|
126
|
+
case DocumentFormat.SD_JWT_VC:
|
|
127
|
+
return "application/sd-jwt";
|
|
128
|
+
case DocumentFormat.MSO_MDOC:
|
|
129
|
+
return "application/mso+cbor";
|
|
130
|
+
case DocumentFormat.JWT:
|
|
131
|
+
return "application/jwt";
|
|
132
|
+
}
|
|
133
|
+
}, "contentTypeFromDocumentFormat");
|
|
134
|
+
var extensionFromDocumentFormat = /* @__PURE__ */ __name((format) => {
|
|
135
|
+
switch (format) {
|
|
136
|
+
case DocumentFormat.JSONLD:
|
|
137
|
+
return ".jsonld";
|
|
138
|
+
case DocumentFormat.EIP712:
|
|
139
|
+
return ".eip712.json";
|
|
140
|
+
case DocumentFormat.SD_JWT_VC:
|
|
141
|
+
return ".sd-jwt";
|
|
142
|
+
case DocumentFormat.MSO_MDOC:
|
|
143
|
+
return ".cbor";
|
|
144
|
+
case DocumentFormat.JWT:
|
|
145
|
+
return ".jwt";
|
|
146
|
+
default:
|
|
147
|
+
return "";
|
|
148
|
+
}
|
|
149
|
+
}, "extensionFromDocumentFormat");
|
|
114
150
|
|
|
115
151
|
// src/linked-vp-api-server.ts
|
|
116
152
|
import { copyGlobalAuthToEndpoints } from "@sphereon/ssi-express-support";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/linked-vp-api-server.ts","../src/api-functions.ts"],"sourcesContent":["import { agentContext } from '@sphereon/ssi-sdk.core'\nimport { TAgent } from '@veramo/core'\n\nimport express, { Express, Router } from 'express'\nimport { ILinkedVPManagerAPIEndpointOpts, IRequiredPlugins } from './types'\nimport {\n publishCredentialEndpoint,\n unpublishCredentialEndpoint,\n hasEntryEndpoint,\n getServiceEntriesEndpoint,\n generatePresentationEndpoint,\n} from './api-functions'\nimport { copyGlobalAuthToEndpoints, ExpressSupport } from '@sphereon/ssi-express-support'\n\nexport type LinkedVPManagerApiServerArgs = {\n agent: TAgent<IRequiredPlugins>\n expressSupport: ExpressSupport\n opts?: ILinkedVPManagerAPIEndpointOpts\n}\n\nexport class LinkedVpApiServer {\n private readonly _express: Express\n private readonly _agent: TAgent<IRequiredPlugins>\n private readonly _opts?: ILinkedVPManagerAPIEndpointOpts\n private readonly _router: Router\n\n constructor(args: LinkedVPManagerApiServerArgs) {\n const { agent, opts } = args\n this._agent = agent\n\n if (opts?.endpointOpts?.globalAuth?.secureLinkedVPManagerEndpoints) {\n copyGlobalAuthToEndpoints({\n opts,\n keys: ['publishManagement', 'serviceEntries', 'generatePresentation'],\n })\n }\n\n this._opts = opts\n this._express = args.expressSupport.express\n this._router = express.Router()\n const context = agentContext(agent)\n const features = opts?.enableFeatures ?? ['publish-management', 'service-entries', 'generate-presentation']\n console.log(`Linked VP API enabled, with features: ${JSON.stringify(features)}`)\n\n // Publish Management Endpoints\n if (features.includes('publish-management')) {\n publishCredentialEndpoint(this.router, context, this._opts?.endpointOpts?.publishManagement)\n unpublishCredentialEndpoint(this.router, context, this._opts?.endpointOpts?.publishManagement)\n hasEntryEndpoint(this.router, context, this._opts?.endpointOpts?.publishManagement)\n }\n\n // Service Entries Endpoint\n if (features.includes('service-entries')) {\n getServiceEntriesEndpoint(this.router, context, this._opts?.endpointOpts?.serviceEntries)\n }\n\n // Generate Presentation Endpoint\n if (features.includes('generate-presentation')) {\n generatePresentationEndpoint(this.router, context, this._opts?.endpointOpts?.generatePresentation)\n }\n\n this._express.use(opts?.endpointOpts?.basePath ?? '', this.router)\n }\n\n get express(): Express {\n return this._express\n }\n\n get router(): Router {\n return this._router\n }\n\n get agent(): TAgent<IRequiredPlugins> {\n return this._agent\n }\n\n get opts(): ILinkedVPManagerAPIEndpointOpts | undefined {\n return this._opts\n }\n}\n","import { checkAuth, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'\nimport {\n GeneratePresentationArgs,\n GetServiceEntriesArgs,\n HasLinkedVPEntryArgs,\n PublishCredentialArgs,\n UnpublishCredentialArgs,\n} from '@sphereon/ssi-sdk.linked-vp'\nimport { Request, Response, Router } from 'express'\nimport { IRequiredContext } from './types'\n\nconst operation = '/linked-vp'\n\n// Publish Management Endpoints\nexport function publishCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`\"publishCredentialEndpoint\" Endpoint is disabled`)\n return\n }\n const path = opts?.path ?? operation\n router.post(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const args = request.body as PublishCredentialArgs\n const entry = await context.agent.lvpPublishCredential(args)\n response.statusCode = 201\n return response.json(entry)\n } catch (error) {\n console.error(error)\n return sendErrorResponse(response, 500, error.message, error)\n }\n })\n}\n\nexport function unpublishCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`\"unpublishCredentialEndpoint\" Endpoint is disabled`)\n return\n }\n const path = opts?.path ?? operation\n router.delete(`${path}/:linkedVpId`, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const linkedVpId = request.params.linkedVpId\n const result = await context.agent.lvpUnpublishCredential({ linkedVpId } as UnpublishCredentialArgs)\n response.statusCode = 200\n return response.json({ success: result })\n } catch (error) {\n return sendErrorResponse(response, 500, error.message, error)\n }\n })\n}\n\nexport function hasEntryEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`\"hasEntryEndpoint\" Endpoint is disabled`)\n return\n }\n const path = opts?.path ?? operation\n router.get(`${path}/:linkedVpId/exists`, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const linkedVpId = request.params.linkedVpId\n const result = await context.agent.lvpHasEntry({ linkedVpId } as HasLinkedVPEntryArgs)\n response.statusCode = 200\n return response.json({ exists: result })\n } catch (error) {\n return sendErrorResponse(response, 500, error.message as string, error)\n }\n })\n}\n\n// Service Entries Endpoint\nexport function getServiceEntriesEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`\"getServiceEntriesEndpoint\" Endpoint is disabled`)\n return\n }\n const path = opts?.path ?? `${operation}/service-entries`\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const tenantId = request.query.tenantId as string | undefined\n const entries = await context.agent.lvpGetServiceEntries({ tenantId } as GetServiceEntriesArgs)\n response.statusCode = 200\n return response.json(entries)\n } catch (error) {\n return sendErrorResponse(response, 500, error.message as string, error)\n }\n })\n}\n\n// Generate Presentation Endpoint\nexport function generatePresentationEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`\"generatePresentationEndpoint\" Endpoint is disabled`)\n return\n }\n const path = opts?.path ?? operation\n router.get(`${path}/:linkedVpId`, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const linkedVpId = request.params.linkedVpId\n const presentation = await context.agent.lvpGeneratePresentation({ linkedVpId } as GeneratePresentationArgs)\n response.statusCode = 200\n return response.json(presentation)\n } catch (error) {\n return sendErrorResponse(response, 500, error.message as string, error)\n }\n })\n}\n"],"mappings":";;;;AAAA,SAASA,oBAAoB;AAG7B,OAAOC,aAAkC;;;ACHzC,SAASC,WAAgCC,yBAAyB;AAWlE,IAAMC,YAAY;AAGX,SAASC,0BAA0BC,QAAgBC,SAA2BC,MAA0B;AAC7G,MAAIA,MAAMC,YAAY,OAAO;AAC3BC,YAAQC,IAAI,kDAAkD;AAC9D;EACF;AACA,QAAMC,OAAOJ,MAAMI,QAAQR;AAC3BE,SAAOO,KAAKD,MAAME,UAAUN,MAAMO,QAAAA,GAAW,OAAOC,SAAkBC,aAAAA;AACpE,QAAI;AACF,YAAMC,OAAOF,QAAQG;AACrB,YAAMC,QAAQ,MAAMb,QAAQc,MAAMC,qBAAqBJ,IAAAA;AACvDD,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9C,UAAM,EAAEC,OAAOC,KAAI,IAAKF;AACxB,SAAKH,SAASI;AAEd,QAAIC,MAAMC,cAAcC,YAAYC,gCAAgC;AAClEC,gCAA0B;QACxBJ;QACAK,MAAM;UAAC;UAAqB;UAAkB;;MAChD,CAAA;IACF;AAEA,SAAKT,QAAQI;AACb,SAAKN,WAAWI,KAAKQ,eAAeC;AACpC,SAAKV,UAAUU,QAAQC,OAAM;AAC7B,UAAMC,UAAUC,aAAaX,KAAAA;AAC7B,UAAMY,WAAWX,MAAMY,kBAAkB;MAAC;MAAsB;MAAmB;;AACnFC,YAAQC,IAAI,yCAAyCC,KAAKC,UAAUL,QAAAA,CAAAA,EAAW;AAG/E,QAAIA,SAASM,SAAS,oBAAA,GAAuB;AAC3CC,gCAA0B,KAAKC,QAAQV,SAAS,KAAKb,OAAOK,cAAcmB,iBAAAA;AAC1EC,kCAA4B,KAAKF,QAAQV,SAAS,KAAKb,OAAOK,cAAcmB,iBAAAA;AAC5EE,uBAAiB,KAAKH,QAAQV,SAAS,KAAKb,OAAOK,cAAcmB,iBAAAA;IACnE;AAGA,QAAIT,SAASM,SAAS,iBAAA,GAAoB;AACxCM,gCAA0B,KAAKJ,QAAQV,SAAS,KAAKb,OAAOK,cAAcuB,cAAAA;IAC5E;AAGA,QAAIb,SAASM,SAAS,uBAAA,GAA0B;AAC9CQ,mCAA6B,KAAKN,QAAQV,SAAS,KAAKb,OAAOK,cAAcyB,oBAAAA;IAC/E;AAEA,SAAKhC,SAASiC,IAAI3B,MAAMC,cAAc2B,YAAY,IAAI,KAAKT,MAAM;EACnE;EAEA,IAAIZ,UAAmB;AACrB,WAAO,KAAKb;EACd;EAEA,IAAIyB,SAAiB;AACnB,WAAO,KAAKtB;EACd;EAEA,IAAIE,QAAkC;AACpC,WAAO,KAAKJ;EACd;EAEA,IAAIK,OAAoD;AACtD,WAAO,KAAKJ;EACd;AACF;","names":["agentContext","express","checkAuth","sendErrorResponse","operation","publishCredentialEndpoint","router","context","opts","enabled","console","log","path","post","checkAuth","endpoint","request","response","args","body","entry","agent","lvpPublishCredential","statusCode","json","error","sendErrorResponse","message","unpublishCredentialEndpoint","delete","linkedVpId","params","result","lvpUnpublishCredential","success","hasEntryEndpoint","get","lvpHasEntry","exists","getServiceEntriesEndpoint","tenantId","query","entries","lvpGetServiceEntries","generatePresentationEndpoint","presentation","lvpGeneratePresentation","copyGlobalAuthToEndpoints","LinkedVpApiServer","_express","_agent","_opts","_router","args","agent","opts","endpointOpts","globalAuth","secureLinkedVPManagerEndpoints","copyGlobalAuthToEndpoints","keys","expressSupport","express","Router","context","agentContext","features","enableFeatures","console","log","JSON","stringify","includes","publishCredentialEndpoint","router","publishManagement","unpublishCredentialEndpoint","hasEntryEndpoint","getServiceEntriesEndpoint","serviceEntries","generatePresentationEndpoint","generatePresentation","use","basePath"]}
|
|
1
|
+
{"version":3,"sources":["../src/linked-vp-api-server.ts","../src/api-functions.ts"],"sourcesContent":["import { agentContext } from '@sphereon/ssi-sdk.core'\nimport { TAgent } from '@veramo/core'\n\nimport express, { Express, Router } from 'express'\nimport { ILinkedVPManagerAPIEndpointOpts, IRequiredPlugins } from './types'\nimport {\n publishCredentialEndpoint,\n unpublishCredentialEndpoint,\n hasEntryEndpoint,\n getServiceEntriesEndpoint,\n generatePresentationEndpoint,\n} from './api-functions'\nimport { copyGlobalAuthToEndpoints, ExpressSupport } from '@sphereon/ssi-express-support'\n\nexport type LinkedVPManagerApiServerArgs = {\n agent: TAgent<IRequiredPlugins>\n expressSupport: ExpressSupport\n opts?: ILinkedVPManagerAPIEndpointOpts\n}\n\nexport class LinkedVpApiServer {\n private readonly _express: Express\n private readonly _agent: TAgent<IRequiredPlugins>\n private readonly _opts?: ILinkedVPManagerAPIEndpointOpts\n private readonly _router: Router\n\n constructor(args: LinkedVPManagerApiServerArgs) {\n const { agent, opts } = args\n this._agent = agent\n\n if (opts?.endpointOpts?.globalAuth?.secureLinkedVPManagerEndpoints) {\n copyGlobalAuthToEndpoints({\n opts,\n keys: ['publishManagement', 'serviceEntries', 'generatePresentation'],\n })\n }\n\n this._opts = opts\n this._express = args.expressSupport.express\n this._router = express.Router()\n const context = agentContext(agent)\n const features = opts?.enableFeatures ?? ['publish-management', 'service-entries', 'generate-presentation']\n console.log(`Linked VP API enabled, with features: ${JSON.stringify(features)}`)\n\n // Publish Management Endpoints\n if (features.includes('publish-management')) {\n publishCredentialEndpoint(this.router, context, this._opts?.endpointOpts?.publishManagement)\n unpublishCredentialEndpoint(this.router, context, this._opts?.endpointOpts?.publishManagement)\n hasEntryEndpoint(this.router, context, this._opts?.endpointOpts?.publishManagement)\n }\n\n // Service Entries Endpoint\n if (features.includes('service-entries')) {\n getServiceEntriesEndpoint(this.router, context, this._opts?.endpointOpts?.serviceEntries)\n }\n\n // Generate Presentation Endpoint\n if (features.includes('generate-presentation')) {\n generatePresentationEndpoint(this.router, context, this._opts?.endpointOpts?.generatePresentation)\n }\n\n this._express.use(opts?.endpointOpts?.basePath ?? '', this.router)\n }\n\n get express(): Express {\n return this._express\n }\n\n get router(): Router {\n return this._router\n }\n\n get agent(): TAgent<IRequiredPlugins> {\n return this._agent\n }\n\n get opts(): ILinkedVPManagerAPIEndpointOpts | undefined {\n return this._opts\n }\n}\n","import { checkAuth, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'\nimport {\n GeneratePresentationArgs,\n GetServiceEntriesArgs,\n HasLinkedVPEntryArgs,\n PublishCredentialArgs,\n UnpublishCredentialArgs,\n} from '@sphereon/ssi-sdk.linked-vp'\nimport { DocumentFormat } from '@sphereon/ssi-types'\nimport { Request, Response, Router } from 'express'\nimport { IRequiredContext } from './types'\n\nconst operation = '/linked-vp'\n\n// Publish Management Endpoints\nexport function publishCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`\"publishCredentialEndpoint\" Endpoint is disabled`)\n return\n }\n const path = opts?.path ?? operation\n router.post(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const args = request.body as PublishCredentialArgs\n const entry = await context.agent.lvpPublishCredential(args)\n response.statusCode = 201\n return response.json(entry)\n } catch (error) {\n console.error(error)\n return sendErrorResponse(response, 500, error.message, error)\n }\n })\n}\n\nexport function unpublishCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`\"unpublishCredentialEndpoint\" Endpoint is disabled`)\n return\n }\n const path = opts?.path ?? operation\n router.delete(`${path}/:linkedVpId`, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const linkedVpId = request.params.linkedVpId\n const result = await context.agent.lvpUnpublishCredential({ linkedVpId } as UnpublishCredentialArgs)\n response.statusCode = 200\n return response.json({ success: result })\n } catch (error) {\n return sendErrorResponse(response, 500, error.message, error)\n }\n })\n}\n\nexport function hasEntryEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`\"hasEntryEndpoint\" Endpoint is disabled`)\n return\n }\n const path = opts?.path ?? operation\n router.get(`${path}/:linkedVpId/exists`, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const linkedVpId = request.params.linkedVpId\n const result = await context.agent.lvpHasEntry({ linkedVpId } as HasLinkedVPEntryArgs)\n response.statusCode = 200\n return response.json({ exists: result })\n } catch (error) {\n return sendErrorResponse(response, 500, error.message as string, error)\n }\n })\n}\n\n// Service Entries Endpoint\nexport function getServiceEntriesEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`\"getServiceEntriesEndpoint\" Endpoint is disabled`)\n return\n }\n const path = opts?.path ?? `${operation}/service-entries`\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const tenantId = request.query.tenantId as string | undefined\n const entries = await context.agent.lvpGetServiceEntries({ tenantId } as GetServiceEntriesArgs)\n response.statusCode = 200\n return response.json(entries)\n } catch (error) {\n return sendErrorResponse(response, 500, error.message as string, error)\n }\n })\n}\n\n// Generate Presentation Endpoint\nexport function generatePresentationEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`\"generatePresentationEndpoint\" Endpoint is disabled`)\n return\n }\n const path = opts?.path ?? operation\n router.get(`${path}/:linkedVpId`, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const linkedVpId = request.params.linkedVpId\n const linkedVPPresentation = await context.agent.lvpGeneratePresentation({ linkedVpId } as GeneratePresentationArgs)\n response.statusCode = 200\n response.contentType(contentTypeFromDocumentFormat(linkedVPPresentation.documentFormat))\n response.setHeader(\n 'Content-Disposition',\n `attachment; filename=\"${linkedVpId}${extensionFromDocumentFormat(linkedVPPresentation.documentFormat)}\"`,\n )\n if (typeof linkedVPPresentation.presentationPayload === 'string') {\n return response.send(linkedVPPresentation.presentationPayload)\n }\n return response.json(linkedVPPresentation.presentationPayload)\n } catch (error) {\n return sendErrorResponse(response, 500, error.message as string, error)\n }\n })\n}\n\nconst contentTypeFromDocumentFormat = (documentFormat: DocumentFormat): string => {\n switch (documentFormat) {\n case DocumentFormat.JSONLD:\n return 'application/vp+ld+json'\n\n case DocumentFormat.EIP712:\n return 'application/eip712+json'\n\n case DocumentFormat.SD_JWT_VC:\n return 'application/sd-jwt'\n\n case DocumentFormat.MSO_MDOC:\n return 'application/mso+cbor'\n\n case DocumentFormat.JWT:\n return 'application/jwt'\n }\n}\n\nconst extensionFromDocumentFormat = (format: DocumentFormat): string => {\n switch (format) {\n case DocumentFormat.JSONLD:\n return '.jsonld'\n case DocumentFormat.EIP712:\n return '.eip712.json'\n case DocumentFormat.SD_JWT_VC:\n return '.sd-jwt'\n case DocumentFormat.MSO_MDOC:\n return '.cbor'\n case DocumentFormat.JWT:\n return '.jwt'\n default:\n return ''\n }\n}\n"],"mappings":";;;;AAAA,SAASA,oBAAoB;AAG7B,OAAOC,aAAkC;;;ACHzC,SAAS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YAAYC,gCAAgC;AAClEC,gCAA0B;QACxBJ;QACAK,MAAM;UAAC;UAAqB;UAAkB;;MAChD,CAAA;IACF;AAEA,SAAKT,QAAQI;AACb,SAAKN,WAAWI,KAAKQ,eAAeC;AACpC,SAAKV,UAAUU,QAAQC,OAAM;AAC7B,UAAMC,UAAUC,aAAaX,KAAAA;AAC7B,UAAMY,WAAWX,MAAMY,kBAAkB;MAAC;MAAsB;MAAmB;;AACnFC,YAAQC,IAAI,yCAAyCC,KAAKC,UAAUL,QAAAA,CAAAA,EAAW;AAG/E,QAAIA,SAASM,SAAS,oBAAA,GAAuB;AAC3CC,gCAA0B,KAAKC,QAAQV,SAAS,KAAKb,OAAOK,cAAcmB,iBAAAA;AAC1EC,kCAA4B,KAAKF,QAAQV,SAAS,KAAKb,OAAOK,cAAcmB,iBAAAA;AAC5EE,uBAAiB,KAAKH,QAAQV,SAAS,KAAKb,OAAOK,cAAcmB,iBAAAA;IACnE;AAGA,QAAIT,SAASM,SAAS,iBAAA,GAAoB;AACxCM,gCAA0B,KAAKJ,QAAQV,SAAS,KAAKb,OAAOK,cAAcuB,cAAAA;IAC5E;AAGA,QAAIb,SAASM,SAAS,uBAAA,GAA0B;AAC9CQ,mCAA6B,KAAKN,QAAQV,SAAS,KAAKb,OAAOK,cAAcyB,oBAAAA;IAC/E;AAEA,SAAKhC,SAASiC,IAAI3B,MAAMC,cAAc2B,YAAY,IAAI,KAAKT,MAAM;EACnE;EAEA,IAAIZ,UAAmB;AACrB,WAAO,KAAKb;EACd;EAEA,IAAIyB,SAAiB;AACnB,WAAO,KAAKtB;EACd;EAEA,IAAIE,QAAkC;AACpC,WAAO,KAAKJ;EACd;EAEA,IAAIK,OAAoD;AACtD,WAAO,KAAKJ;EACd;AACF;","names":["agentContext","express","checkAuth","sendErrorResponse","DocumentFormat","operation","publishCredentialEndpoint","router","context","opts","enabled","console","log","path","post","checkAuth","endpoint","request","response","args","body","entry","agent","lvpPublishCredential","statusCode","json","error","sendErrorResponse","message","unpublishCredentialEndpoint","delete","linkedVpId","params","result","lvpUnpublishCredential","success","hasEntryEndpoint","get","lvpHasEntry","exists","getServiceEntriesEndpoint","tenantId","query","entries","lvpGetServiceEntries","generatePresentationEndpoint","linkedVPPresentation","lvpGeneratePresentation","contentType","contentTypeFromDocumentFormat","documentFormat","setHeader","extensionFromDocumentFormat","presentationPayload","send","DocumentFormat","JSONLD","EIP712","SD_JWT_VC","MSO_MDOC","JWT","format","copyGlobalAuthToEndpoints","LinkedVpApiServer","_express","_agent","_opts","_router","args","agent","opts","endpointOpts","globalAuth","secureLinkedVPManagerEndpoints","copyGlobalAuthToEndpoints","keys","expressSupport","express","Router","context","agentContext","features","enableFeatures","console","log","JSON","stringify","includes","publishCredentialEndpoint","router","publishManagement","unpublishCredentialEndpoint","hasEntryEndpoint","getServiceEntriesEndpoint","serviceEntries","generatePresentationEndpoint","generatePresentation","use","basePath"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.linked-vp-rest-api",
|
|
3
|
-
"version": "0.34.1-feature.SSISDK.82.linkedVP.
|
|
3
|
+
"version": "0.34.1-feature.SSISDK.82.linkedVP.327+81517113",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"build": "tsup --config ../../tsup.config.ts --tsconfig ../../tsconfig.tsup.json"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@sphereon/ssi-express-support": "0.34.1-feature.SSISDK.82.linkedVP.
|
|
25
|
-
"@sphereon/ssi-sdk.core": "0.34.1-feature.SSISDK.82.linkedVP.
|
|
26
|
-
"@sphereon/ssi-sdk.data-store": "0.34.1-feature.SSISDK.82.linkedVP.
|
|
27
|
-
"@sphereon/ssi-sdk.data-store-types": "0.34.1-feature.SSISDK.82.linkedVP.
|
|
28
|
-
"@sphereon/ssi-sdk.linked-vp": "0.34.1-feature.SSISDK.82.linkedVP.
|
|
29
|
-
"@sphereon/ssi-types": "0.34.1-feature.SSISDK.82.linkedVP.
|
|
24
|
+
"@sphereon/ssi-express-support": "0.34.1-feature.SSISDK.82.linkedVP.327+81517113",
|
|
25
|
+
"@sphereon/ssi-sdk.core": "0.34.1-feature.SSISDK.82.linkedVP.327+81517113",
|
|
26
|
+
"@sphereon/ssi-sdk.data-store": "0.34.1-feature.SSISDK.82.linkedVP.327+81517113",
|
|
27
|
+
"@sphereon/ssi-sdk.data-store-types": "0.34.1-feature.SSISDK.82.linkedVP.327+81517113",
|
|
28
|
+
"@sphereon/ssi-sdk.linked-vp": "0.34.1-feature.SSISDK.82.linkedVP.327+81517113",
|
|
29
|
+
"@sphereon/ssi-types": "0.34.1-feature.SSISDK.82.linkedVP.327+81517113",
|
|
30
30
|
"@veramo/core": "4.2.0",
|
|
31
31
|
"body-parser": "^1.20.2",
|
|
32
32
|
"casbin": "^5.30.0",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@decentralized-identity/ion-sdk": "^0.6.0",
|
|
43
|
-
"@sphereon/ssi-sdk.agent-config": "0.34.1-feature.SSISDK.82.linkedVP.
|
|
43
|
+
"@sphereon/ssi-sdk.agent-config": "0.34.1-feature.SSISDK.82.linkedVP.327+81517113",
|
|
44
44
|
"@types/body-parser": "^1.19.5",
|
|
45
45
|
"@types/cookie-parser": "^1.4.7",
|
|
46
46
|
"@types/cors": "^2.8.17",
|
|
@@ -88,5 +88,5 @@
|
|
|
88
88
|
"pd-management",
|
|
89
89
|
"presentation-definition-management"
|
|
90
90
|
],
|
|
91
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "81517113906547b895df06ba83f283604b52ab2e"
|
|
92
92
|
}
|
package/src/api-functions.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
PublishCredentialArgs,
|
|
7
7
|
UnpublishCredentialArgs,
|
|
8
8
|
} from '@sphereon/ssi-sdk.linked-vp'
|
|
9
|
+
import { DocumentFormat } from '@sphereon/ssi-types'
|
|
9
10
|
import { Request, Response, Router } from 'express'
|
|
10
11
|
import { IRequiredContext } from './types'
|
|
11
12
|
|
|
@@ -96,11 +97,55 @@ export function generatePresentationEndpoint(router: Router, context: IRequiredC
|
|
|
96
97
|
router.get(`${path}/:linkedVpId`, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
97
98
|
try {
|
|
98
99
|
const linkedVpId = request.params.linkedVpId
|
|
99
|
-
const
|
|
100
|
+
const linkedVPPresentation = await context.agent.lvpGeneratePresentation({ linkedVpId } as GeneratePresentationArgs)
|
|
100
101
|
response.statusCode = 200
|
|
101
|
-
|
|
102
|
+
response.contentType(contentTypeFromDocumentFormat(linkedVPPresentation.documentFormat))
|
|
103
|
+
response.setHeader(
|
|
104
|
+
'Content-Disposition',
|
|
105
|
+
`attachment; filename="${linkedVpId}${extensionFromDocumentFormat(linkedVPPresentation.documentFormat)}"`,
|
|
106
|
+
)
|
|
107
|
+
if (typeof linkedVPPresentation.presentationPayload === 'string') {
|
|
108
|
+
return response.send(linkedVPPresentation.presentationPayload)
|
|
109
|
+
}
|
|
110
|
+
return response.json(linkedVPPresentation.presentationPayload)
|
|
102
111
|
} catch (error) {
|
|
103
112
|
return sendErrorResponse(response, 500, error.message as string, error)
|
|
104
113
|
}
|
|
105
114
|
})
|
|
106
115
|
}
|
|
116
|
+
|
|
117
|
+
const contentTypeFromDocumentFormat = (documentFormat: DocumentFormat): string => {
|
|
118
|
+
switch (documentFormat) {
|
|
119
|
+
case DocumentFormat.JSONLD:
|
|
120
|
+
return 'application/vp+ld+json'
|
|
121
|
+
|
|
122
|
+
case DocumentFormat.EIP712:
|
|
123
|
+
return 'application/eip712+json'
|
|
124
|
+
|
|
125
|
+
case DocumentFormat.SD_JWT_VC:
|
|
126
|
+
return 'application/sd-jwt'
|
|
127
|
+
|
|
128
|
+
case DocumentFormat.MSO_MDOC:
|
|
129
|
+
return 'application/mso+cbor'
|
|
130
|
+
|
|
131
|
+
case DocumentFormat.JWT:
|
|
132
|
+
return 'application/jwt'
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const extensionFromDocumentFormat = (format: DocumentFormat): string => {
|
|
137
|
+
switch (format) {
|
|
138
|
+
case DocumentFormat.JSONLD:
|
|
139
|
+
return '.jsonld'
|
|
140
|
+
case DocumentFormat.EIP712:
|
|
141
|
+
return '.eip712.json'
|
|
142
|
+
case DocumentFormat.SD_JWT_VC:
|
|
143
|
+
return '.sd-jwt'
|
|
144
|
+
case DocumentFormat.MSO_MDOC:
|
|
145
|
+
return '.cbor'
|
|
146
|
+
case DocumentFormat.JWT:
|
|
147
|
+
return '.jwt'
|
|
148
|
+
default:
|
|
149
|
+
return ''
|
|
150
|
+
}
|
|
151
|
+
}
|