@sphereon/ssi-sdk.w3c-vc-api 0.33.1-next.68 → 0.33.1-next.73
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 +15 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/package.json +16 -16
- package/src/api-functions.ts +31 -12
package/dist/index.cjs
CHANGED
|
@@ -46,14 +46,14 @@ 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_sdk_ext = require("@sphereon/ssi-sdk-ext.identifier-resolution");
|
|
49
50
|
var import_ssi_sdk = require("@sphereon/ssi-sdk.agent-config");
|
|
50
|
-
var import_uuid = require("uuid");
|
|
51
|
-
var import_debug = __toESM(require("debug"), 1);
|
|
52
51
|
var import_ssi_sdk2 = require("@sphereon/ssi-sdk.credential-store");
|
|
53
|
-
var import_ssi_sdk3 = require("@sphereon/ssi-sdk.
|
|
52
|
+
var import_ssi_sdk3 = require("@sphereon/ssi-sdk.credential-vcdm");
|
|
53
|
+
var import_ssi_sdk4 = require("@sphereon/ssi-sdk.data-store");
|
|
54
54
|
var import_ssi_types = require("@sphereon/ssi-types");
|
|
55
|
-
var
|
|
56
|
-
var
|
|
55
|
+
var import_debug = __toESM(require("debug"), 1);
|
|
56
|
+
var import_uuid = require("uuid");
|
|
57
57
|
var debug = (0, import_debug.default)("sphereon:ssi-sdk:w3c-vc-api");
|
|
58
58
|
function issueCredentialEndpoint(router, context, opts) {
|
|
59
59
|
if (opts?.enabled === false) {
|
|
@@ -109,7 +109,7 @@ function issueCredentialEndpoint(router, context, opts) {
|
|
|
109
109
|
const rawDocument = import_ssi_types.CredentialMapper.storedCredentialToOriginalFormat(vc);
|
|
110
110
|
const save = opts?.persistIssuedCredentials;
|
|
111
111
|
if (save) {
|
|
112
|
-
const issuer = (0,
|
|
112
|
+
const issuer = (0, import_ssi_sdk3.extractIssuer)(credential);
|
|
113
113
|
const identifier = await context.agent.identifierManagedGet({
|
|
114
114
|
identifier: issuer,
|
|
115
115
|
issuer,
|
|
@@ -134,7 +134,7 @@ function issueCredentialEndpoint(router, context, opts) {
|
|
|
134
134
|
}
|
|
135
135
|
const dc = {
|
|
136
136
|
credential: {
|
|
137
|
-
credentialRole:
|
|
137
|
+
credentialRole: import_ssi_sdk4.CredentialRole.HOLDER,
|
|
138
138
|
// tenantId: 'test-tenant',
|
|
139
139
|
kmsKeyRef: identifier.kmsKeyRef,
|
|
140
140
|
identifierMethod: identifier.method,
|
|
@@ -164,8 +164,8 @@ function getCredentialsEndpoint(router, context, opts) {
|
|
|
164
164
|
const path = opts?.path ?? "/credentials";
|
|
165
165
|
router.get(path, (0, import_ssi_express_support.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
166
166
|
try {
|
|
167
|
-
const credentialRole = request.query.credentialRole ||
|
|
168
|
-
if (!Object.values(
|
|
167
|
+
const credentialRole = request.query.credentialRole || import_ssi_sdk4.CredentialRole.HOLDER;
|
|
168
|
+
if (!Object.values(import_ssi_sdk4.CredentialRole).includes(credentialRole)) {
|
|
169
169
|
return (0, import_ssi_express_support.sendErrorResponse)(response, 400, `Invalid credentialRole: ${credentialRole}`);
|
|
170
170
|
}
|
|
171
171
|
const documentType = request.query.documentType || import_ssi_sdk2.DocumentType.VC;
|
|
@@ -201,8 +201,8 @@ function getCredentialEndpoint(router, context, opts) {
|
|
|
201
201
|
if (!id) {
|
|
202
202
|
return (0, import_ssi_express_support.sendErrorResponse)(response, 400, "no id provided");
|
|
203
203
|
}
|
|
204
|
-
const credentialRole = request.query.credentialRole ||
|
|
205
|
-
if (!Object.values(
|
|
204
|
+
const credentialRole = request.query.credentialRole || import_ssi_sdk4.CredentialRole.HOLDER;
|
|
205
|
+
if (!Object.values(import_ssi_sdk4.CredentialRole).includes(credentialRole)) {
|
|
206
206
|
return (0, import_ssi_express_support.sendErrorResponse)(response, 400, `Invalid credentialRole: ${credentialRole}`);
|
|
207
207
|
}
|
|
208
208
|
const vcInfo = await context.agent.crsGetUniqueCredentialByIdOrHash({
|
|
@@ -229,12 +229,15 @@ function verifyCredentialEndpoint(router, context, opts) {
|
|
|
229
229
|
try {
|
|
230
230
|
debug(JSON.stringify(request.body, null, 2));
|
|
231
231
|
const credential = request.body.verifiableCredential;
|
|
232
|
+
const options = request.body.options;
|
|
232
233
|
if (!credential) {
|
|
233
234
|
return (0, import_ssi_express_support.sendErrorResponse)(response, 400, "No verifiable credential supplied");
|
|
234
235
|
}
|
|
235
236
|
const verifyResult = await context.agent.verifyCredential({
|
|
237
|
+
...options,
|
|
236
238
|
credential,
|
|
237
239
|
policies: {
|
|
240
|
+
...options?.policies,
|
|
238
241
|
credentialStatus: false
|
|
239
242
|
},
|
|
240
243
|
fetchRemoteContexts: opts?.fetchRemoteContexts !== false
|
|
@@ -262,7 +265,7 @@ function deleteCredentialEndpoint(router, context, opts) {
|
|
|
262
265
|
if (credentialRole === void 0) {
|
|
263
266
|
return (0, import_ssi_express_support.sendErrorResponse)(response, 400, "credentialRole query parameter is missing");
|
|
264
267
|
}
|
|
265
|
-
if (!Object.values(
|
|
268
|
+
if (!Object.values(import_ssi_sdk4.CredentialRole).includes(credentialRole)) {
|
|
266
269
|
return (0, import_ssi_express_support.sendErrorResponse)(response, 400, `Invalid credentialRole: ${credentialRole}`);
|
|
267
270
|
}
|
|
268
271
|
const vcInfo = await context.agent.crsGetUniqueCredentialByIdOrHash({
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/vc-api-server.ts","../src/api-functions.ts"],"sourcesContent":["/**\n * @public\n */\nexport * from './vc-api-server'\nexport * from './types'\nexport * from './api-functions'\n","import { agentContext } from '@sphereon/ssi-sdk.core'\nimport type { ExpressSupport } from '@sphereon/ssi-express-support'\nimport type { TAgent } from '@veramo/core'\n\nimport express, { type Express, Router } from 'express'\nimport {\n deleteCredentialEndpoint,\n getCredentialEndpoint,\n getCredentialsEndpoint,\n issueCredentialEndpoint,\n verifyCredentialEndpoint,\n} from './api-functions'\nimport type { IRequiredPlugins, IVCAPIOpts } from './types'\n\nexport class VcApiServer {\n get router(): express.Router {\n return this._router\n }\n\n private readonly _express: Express\n private readonly _agent: TAgent<IRequiredPlugins>\n private readonly _opts?: IVCAPIOpts\n private readonly _router: Router\n\n constructor(args: { agent: TAgent<IRequiredPlugins>; expressSupport: ExpressSupport; opts?: IVCAPIOpts }) {\n const { agent, opts } = args\n this._agent = agent\n if (opts?.endpointOpts?.globalAuth) {\n copyGlobalAuthToEndpoint(opts, 'issueCredential')\n copyGlobalAuthToEndpoint(opts, 'getCredential')\n copyGlobalAuthToEndpoint(opts, 'getCredentials')\n copyGlobalAuthToEndpoint(opts, 'deleteCredential')\n copyGlobalAuthToEndpoint(opts, 'verifyCredential')\n }\n\n this._opts = opts\n this._express = args.expressSupport.express\n this._router = express.Router()\n\n const context = agentContext(agent)\n\n const features = opts?.issueCredentialOpts?.enableFeatures ?? ['vc-issue', 'vc-persist', 'vc-verify']\n console.log(`VC API enabled, with features: ${JSON.stringify(features)}`)\n\n // Credential endpoints\n if (features.includes('vc-issue')) {\n issueCredentialEndpoint(this.router, context, {\n ...opts?.endpointOpts?.issueCredential,\n issueCredentialOpts: opts?.issueCredentialOpts,\n })\n }\n if (features.includes('vc-persist')) {\n getCredentialEndpoint(this.router, context, opts?.endpointOpts?.getCredential)\n getCredentialsEndpoint(this.router, context, opts?.endpointOpts?.getCredentials)\n deleteCredentialEndpoint(this.router, context, opts?.endpointOpts?.deleteCredential) // not in spec.\n }\n if (features.includes('vc-verify')) {\n verifyCredentialEndpoint(this.router, context, {\n ...opts?.endpointOpts?.verifyCredential,\n fetchRemoteContexts: opts?.issueCredentialOpts?.fetchRemoteContexts,\n })\n }\n this._express.use(opts?.endpointOpts?.basePath ?? '', this.router)\n }\n\n get agent(): TAgent<IRequiredPlugins> {\n return this._agent\n }\n\n get opts(): IVCAPIOpts | undefined {\n return this._opts\n }\n\n get express(): Express {\n return this._express\n }\n}\n\nfunction copyGlobalAuthToEndpoint(opts: IVCAPIOpts, key: string) {\n if (opts?.endpointOpts?.globalAuth) {\n // @ts-ignore\n opts.endpointOpts[key] = {\n // @ts-ignore\n ...opts.endpointOpts[key],\n // @ts-ignore\n endpoint: { ...opts.endpointOpts.globalAuth, ...opts.endpointOpts[key]?.endpoint },\n }\n }\n}\n","import { checkAuth, type ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'\nimport { contextHasPlugin } from '@sphereon/ssi-sdk.agent-config'\nimport type { CredentialPayload, ProofFormat } from '@veramo/core'\nimport { type Request, type Response, Router } from 'express'\nimport { v4 } from 'uuid'\nimport type { IIssueCredentialEndpointOpts, IRequiredContext, IVCAPIIssueOpts, IVerifyCredentialEndpointOpts } from './types'\nimport Debug from 'debug'\nimport { AddCredentialArgs, CredentialCorrelationType, DocumentType, type FindDigitalCredentialArgs } from '@sphereon/ssi-sdk.credential-store'\nimport type { IStatusListPlugin } from '@sphereon/ssi-sdk.vc-status-list'\nimport { CredentialRole } from '@sphereon/ssi-sdk.data-store'\nimport { CredentialMapper, CredentialProofFormat, isVcdm2Credential, OriginalVerifiableCredential } from '@sphereon/ssi-types'\nimport { extractIssuer } from '@sphereon/ssi-sdk.credential-vcdm'\nimport { isDidIdentifier, isIIdentifier } from '@sphereon/ssi-sdk-ext.identifier-resolution'\nimport type { VerifiableCredentialSP } from '@sphereon/ssi-sdk.core'\n\nconst debug = Debug('sphereon:ssi-sdk:w3c-vc-api')\n\nexport function issueCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IIssueCredentialEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Issue credential endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/credentials/issue'\n\n router.post(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const credential: CredentialPayload = request.body.credential\n const reqOpts = request.body.options ?? {}\n const inputFormat = reqOpts.proofFormat?.toLocaleLowerCase()\n let proofFormat: CredentialProofFormat | undefined = undefined\n if (inputFormat) {\n if (inputFormat === 'jwt') {\n proofFormat = 'jwt'\n } else if (inputFormat?.includes('jose') || inputFormat?.includes('vc+jwt')) {\n proofFormat = 'vc+jwt'\n } else if (inputFormat?.includes('ld')) {\n proofFormat = 'lds'\n }\n }\n if (proofFormat === undefined && opts?.issueCredentialOpts?.proofFormat) {\n proofFormat = opts.issueCredentialOpts.proofFormat.toLocaleLowerCase() as CredentialProofFormat\n }\n if (proofFormat === undefined) {\n if (isVcdm2Credential(credential)) {\n proofFormat = 'vc+jwt'\n } else {\n proofFormat = 'lds'\n }\n }\n\n if (!credential) {\n return sendErrorResponse(response, 400, 'No credential supplied')\n }\n if (!credential.id) {\n credential.id = `urn:uuid:${v4()}`\n }\n if (contextHasPlugin<IStatusListPlugin>(context, 'slAddStatusToCredential')) {\n // Add status list if enabled (and when the input has a credentialStatus object (can be empty))\n const credentialStatusVC = await context.agent.slAddStatusToCredential({ credential })\n if (credential.credentialStatus && !credential.credentialStatus.statusListCredential) {\n credential.credentialStatus = credentialStatusVC.credentialStatus\n }\n }\n\n const issueOpts: IVCAPIIssueOpts | undefined = opts?.issueCredentialOpts\n const vc = await context.agent.createVerifiableCredential({\n credential,\n proofFormat: proofFormat as ProofFormat,\n fetchRemoteContexts: issueOpts?.fetchRemoteContexts !== false,\n })\n const rawDocument = CredentialMapper.storedCredentialToOriginalFormat(vc as OriginalVerifiableCredential)\n const save = opts?.persistIssuedCredentials\n if (save) {\n const issuer = extractIssuer(credential)\n const identifier = await context.agent.identifierManagedGet({ identifier: issuer, issuer: issuer, vmRelationship: 'assertionMethod' })\n\n let issuerCorrelationId: string | undefined = identifier.issuer\n if (!issuerCorrelationId && isDidIdentifier(identifier.identifier)) {\n if (isIIdentifier(identifier.identifier)) {\n issuerCorrelationId = identifier.identifier.did\n } else if (typeof identifier.identifier === 'string') {\n issuerCorrelationId = identifier.identifier\n }\n }\n if (!issuerCorrelationId) {\n if (typeof vc.issuer === 'string') {\n issuerCorrelationId = vc.issuer\n } else if (typeof vc.issuer?.id === 'string') {\n issuerCorrelationId = vc.issuer.id\n } else {\n issuerCorrelationId = 'unknown'\n }\n }\n\n const dc: AddCredentialArgs = {\n credential: {\n credentialRole: CredentialRole.HOLDER,\n // tenantId: 'test-tenant',\n kmsKeyRef: identifier.kmsKeyRef,\n identifierMethod: identifier.method,\n issuerCorrelationId: issuerCorrelationId,\n issuerCorrelationType: CredentialCorrelationType.DID,\n rawDocument: typeof rawDocument === 'string' ? rawDocument : JSON.stringify(rawDocument),\n },\n }\n await context.agent.crsAddCredential(dc)\n }\n response.statusCode = 201\n return response.send({ verifiableCredential: rawDocument, uniformCredential: CredentialMapper.toUniformCredential(vc as OriginalVerifiableCredential) })\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n\nexport function getCredentialsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Get credentials endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/credentials'\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const credentialRole = (request.query.credentialRole as CredentialRole) || CredentialRole.HOLDER\n if (!Object.values(CredentialRole).includes(credentialRole)) {\n return sendErrorResponse(response, 400, `Invalid credentialRole: ${credentialRole}`)\n }\n\n const documentType = (request.query.documentType as DocumentType) || DocumentType.VC\n if (!Object.values(DocumentType).includes(documentType)) {\n return sendErrorResponse(response, 400, `Invalid documentType: ${documentType}`)\n }\n\n const filter: FindDigitalCredentialArgs = [\n {\n documentType: documentType,\n credentialRole: credentialRole,\n },\n ]\n const uniqueVCs = await context.agent.crsGetUniqueCredentials({ filter })\n response.statusCode = 202\n return response.send(uniqueVCs.map((uVC) => uVC.uniformVerifiableCredential))\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n\nexport function getCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Get credential endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/credentials/:id'\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const id = request.params.id\n if (!id) {\n return sendErrorResponse(response, 400, 'no id provided')\n }\n const credentialRole = (request.query.credentialRole as CredentialRole) || CredentialRole.HOLDER\n if (!Object.values(CredentialRole).includes(credentialRole)) {\n return sendErrorResponse(response, 400, `Invalid credentialRole: ${credentialRole}`)\n }\n\n const vcInfo = await context.agent.crsGetUniqueCredentialByIdOrHash({\n credentialRole: credentialRole,\n idOrHash: id,\n })\n if (!vcInfo) {\n return sendErrorResponse(response, 403, `id ${id} not found`)\n }\n response.statusCode = 200\n return response.send(vcInfo.uniformVerifiableCredential)\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n\nexport function verifyCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IVerifyCredentialEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Verify credential endpoint is disabled`)\n return\n }\n router.post(opts?.path ?? '/credentials/verify', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n debug(JSON.stringify(request.body, null, 2))\n const credential: VerifiableCredentialSP = request.body.verifiableCredential\n // const options: IIssueOptionsPayload = request.body.options\n if (!credential) {\n return sendErrorResponse(response, 400, 'No verifiable credential supplied')\n }\n const verifyResult = await context.agent.verifyCredential({\n credential,\n policies: {\n credentialStatus: false, // Do not use built-in. We have our own statusList implementations\n },\n fetchRemoteContexts: opts?.fetchRemoteContexts !== false,\n })\n\n response.statusCode = 200\n return response.send(verifyResult)\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n\nexport function deleteCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Delete credential endpoint is disabled`)\n return\n }\n router.delete(opts?.path ?? '/credentials/:id', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const id = request.params.id\n if (!id) {\n return sendErrorResponse(response, 400, 'no id provided')\n }\n const credentialRole = request.query.credentialRole as CredentialRole\n if (credentialRole === undefined) {\n return sendErrorResponse(response, 400, 'credentialRole query parameter is missing')\n }\n if (!Object.values(CredentialRole).includes(credentialRole)) {\n return sendErrorResponse(response, 400, `Invalid credentialRole: ${credentialRole}`)\n }\n\n const vcInfo = await context.agent.crsGetUniqueCredentialByIdOrHash({\n credentialRole: credentialRole,\n idOrHash: id,\n })\n if (!vcInfo) {\n return sendErrorResponse(response, 404, `id ${id} not found`)\n }\n const success = await context.agent.crsDeleteCredentials({ filter: [{ hash: vcInfo.hash }] })\n if (success === 0) {\n return sendErrorResponse(response, 400, `Could not delete Verifiable Credential with id ${id}`)\n }\n response.statusCode = 200\n return response.send()\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;ACAA,IAAAA,kBAA6B;AAI7B,qBAA8C;;;ACJ9C,iCAAuE;AACvE,qBAAiC;AAGjC,kBAAmB;AAEnB,mBAAkB;AAClB,IAAAC,kBAA2G;AAE3G,IAAAA,kBAA+B;AAC/B,uBAAyG;AACzG,IAAAA,kBAA8B;AAC9B,yBAA+C;AAG/C,IAAMC,YAAQC,aAAAA,SAAM,6BAAA;AAEb,SAASC,wBAAwBC,QAAgBC,SAA2BC,MAAmC;AACpH,MAAIA,MAAMC,YAAY,OAAO;AAC3BC,YAAQC,IAAI,uCAAuC;AACnD;EACF;AACA,QAAMC,OAAOJ,MAAMI,QAAQ;AAE3BN,SAAOO,KAAKD,UAAME,sCAAUN,MAAMO,QAAAA,GAAW,OAAOC,SAAkBC,aAAAA;AACpE,QAAI;AACF,YAAMC,aAAgCF,QAAQG,K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;AACpC,WAAO,KAAKJ;EACd;EAEA,IAAIK,OAA+B;AACjC,WAAO,KAAKJ;EACd;EAEA,IAAIS,UAAmB;AACrB,WAAO,KAAKX;EACd;AACF;AAEA,SAASS,yBAAyBH,MAAkB8B,KAAW;AAC7D,MAAI9B,MAAMC,cAAcC,YAAY;AAElCF,SAAKC,aAAa6B,GAAAA,IAAO;;MAEvB,GAAG9B,KAAKC,aAAa6B,GAAAA;;MAErBC,UAAU;QAAE,GAAG/B,KAAKC,aAAaC;QAAY,GAAGF,KAAKC,aAAa6B,GAAAA,GAAMC;MAAS;IACnF;EACF;AACF;AAVS5B;","names":["import_ssi_sdk","import_ssi_sdk","debug","Debug","issueCredentialEndpoint","router","context","opts","enabled","console","log","path","post","checkAuth","endpoint","request","response","credential","body","reqOpts","options","inputFormat","proofFormat","toLocaleLowerCase","undefined","includes","issueCredentialOpts","isVcdm2Credential","sendErrorResponse","id","v4","contextHasPlugin","credentialStatusVC","agent","slAddStatusToCredential","credentialStatus","statusListCredential","issueOpts","vc","createVerifiableCredential","fetchRemoteContexts","rawDocument","CredentialMapper","storedCredentialToOriginalFormat","save","persistIssuedCredentials","issuer","extractIssuer","identifier","identifierManagedGet","vmRelationship","issuerCorrelationId","isDidIdentifier","isIIdentifier","did","dc","credentialRole","CredentialRole","HOLDER","kmsKeyRef","identifierMethod","method","issuerCorrelationType","CredentialCorrelationType","DID","JSON","stringify","crsAddCredential","statusCode","send","verifiableCredential","uniformCredential","toUniformCredential","e","message","getCredentialsEndpoint","get","query","Object","values","documentType","DocumentType","VC","filter","uniqueVCs","crsGetUniqueCredentials","map","uVC","uniformVerifiableCredential","getCredentialEndpoint","params","vcInfo","crsGetUniqueCredentialByIdOrHash","idOrHash","verifyCredentialEndpoint","verifyResult","verifyCredential","policies","deleteCredentialEndpoint","delete","success","crsDeleteCredentials","hash","VcApiServer","router","_router","_express","_agent","_opts","constructor","args","agent","opts","endpointOpts","globalAuth","copyGlobalAuthToEndpoint","expressSupport","express","Router","context","agentContext","features","issueCredentialOpts","enableFeatures","console","log","JSON","stringify","includes","issueCredentialEndpoint","issueCredential","getCredentialEndpoint","getCredential","getCredentialsEndpoint","getCredentials","deleteCredentialEndpoint","deleteCredential","verifyCredentialEndpoint","verifyCredential","fetchRemoteContexts","use","basePath","key","endpoint"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/vc-api-server.ts","../src/api-functions.ts"],"sourcesContent":["/**\n * @public\n */\nexport * from './vc-api-server'\nexport * from './types'\nexport * from './api-functions'\n","import { agentContext } from '@sphereon/ssi-sdk.core'\nimport type { ExpressSupport } from '@sphereon/ssi-express-support'\nimport type { TAgent } from '@veramo/core'\n\nimport express, { type Express, Router } from 'express'\nimport {\n deleteCredentialEndpoint,\n getCredentialEndpoint,\n getCredentialsEndpoint,\n issueCredentialEndpoint,\n verifyCredentialEndpoint,\n} from './api-functions'\nimport type { IRequiredPlugins, IVCAPIOpts } from './types'\n\nexport class VcApiServer {\n get router(): express.Router {\n return this._router\n }\n\n private readonly _express: Express\n private readonly _agent: TAgent<IRequiredPlugins>\n private readonly _opts?: IVCAPIOpts\n private readonly _router: Router\n\n constructor(args: { agent: TAgent<IRequiredPlugins>; expressSupport: ExpressSupport; opts?: IVCAPIOpts }) {\n const { agent, opts } = args\n this._agent = agent\n if (opts?.endpointOpts?.globalAuth) {\n copyGlobalAuthToEndpoint(opts, 'issueCredential')\n copyGlobalAuthToEndpoint(opts, 'getCredential')\n copyGlobalAuthToEndpoint(opts, 'getCredentials')\n copyGlobalAuthToEndpoint(opts, 'deleteCredential')\n copyGlobalAuthToEndpoint(opts, 'verifyCredential')\n }\n\n this._opts = opts\n this._express = args.expressSupport.express\n this._router = express.Router()\n\n const context = agentContext(agent)\n\n const features = opts?.issueCredentialOpts?.enableFeatures ?? ['vc-issue', 'vc-persist', 'vc-verify']\n console.log(`VC API enabled, with features: ${JSON.stringify(features)}`)\n\n // Credential endpoints\n if (features.includes('vc-issue')) {\n issueCredentialEndpoint(this.router, context, {\n ...opts?.endpointOpts?.issueCredential,\n issueCredentialOpts: opts?.issueCredentialOpts,\n })\n }\n if (features.includes('vc-persist')) {\n getCredentialEndpoint(this.router, context, opts?.endpointOpts?.getCredential)\n getCredentialsEndpoint(this.router, context, opts?.endpointOpts?.getCredentials)\n deleteCredentialEndpoint(this.router, context, opts?.endpointOpts?.deleteCredential) // not in spec.\n }\n if (features.includes('vc-verify')) {\n verifyCredentialEndpoint(this.router, context, {\n ...opts?.endpointOpts?.verifyCredential,\n fetchRemoteContexts: opts?.issueCredentialOpts?.fetchRemoteContexts,\n })\n }\n this._express.use(opts?.endpointOpts?.basePath ?? '', this.router)\n }\n\n get agent(): TAgent<IRequiredPlugins> {\n return this._agent\n }\n\n get opts(): IVCAPIOpts | undefined {\n return this._opts\n }\n\n get express(): Express {\n return this._express\n }\n}\n\nfunction copyGlobalAuthToEndpoint(opts: IVCAPIOpts, key: string) {\n if (opts?.endpointOpts?.globalAuth) {\n // @ts-ignore\n opts.endpointOpts[key] = {\n // @ts-ignore\n ...opts.endpointOpts[key],\n // @ts-ignore\n endpoint: { ...opts.endpointOpts.globalAuth, ...opts.endpointOpts[key]?.endpoint },\n }\n }\n}\n","import { checkAuth, type ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'\nimport { isDidIdentifier, isIIdentifier } from '@sphereon/ssi-sdk-ext.identifier-resolution'\nimport { contextHasPlugin } from '@sphereon/ssi-sdk.agent-config'\nimport {\n AddCredentialArgs,\n CredentialCorrelationType,\n DocumentType,\n type FindDigitalCredentialArgs\n} from '@sphereon/ssi-sdk.credential-store'\nimport { extractIssuer } from '@sphereon/ssi-sdk.credential-vcdm'\nimport { CredentialRole } from '@sphereon/ssi-sdk.data-store'\nimport type { IStatusListPlugin } from '@sphereon/ssi-sdk.vc-status-list'\nimport {\n CredentialMapper,\n CredentialProofFormat,\n isVcdm2Credential,\n OriginalVerifiableCredential\n} from '@sphereon/ssi-types'\nimport type { CredentialPayload, ProofFormat } from '@veramo/core'\nimport Debug from 'debug'\nimport { type Request, type Response, Router } from 'express'\nimport { v4 } from 'uuid'\nimport type {\n IIssueCredentialEndpointOpts,\n IRequiredContext,\n IVCAPIIssueOpts,\n IVerifyCredentialEndpointOpts\n} from './types'\n\nconst debug = Debug('sphereon:ssi-sdk:w3c-vc-api')\n\nexport function issueCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IIssueCredentialEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Issue credential endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/credentials/issue'\n\n router.post(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const credential: CredentialPayload = request.body.credential\n const reqOpts = request.body.options ?? {}\n const inputFormat = reqOpts.proofFormat?.toLocaleLowerCase()\n let proofFormat: CredentialProofFormat | undefined = undefined\n if (inputFormat) {\n if (inputFormat === 'jwt') {\n proofFormat = 'jwt'\n } else if (inputFormat?.includes('jose') || inputFormat?.includes('vc+jwt')) {\n proofFormat = 'vc+jwt'\n } else if (inputFormat?.includes('ld')) {\n proofFormat = 'lds'\n }\n }\n if (proofFormat === undefined && opts?.issueCredentialOpts?.proofFormat) {\n proofFormat = opts.issueCredentialOpts.proofFormat.toLocaleLowerCase() as CredentialProofFormat\n }\n if (proofFormat === undefined) {\n if (isVcdm2Credential(credential)) {\n proofFormat = 'vc+jwt'\n } else {\n proofFormat = 'lds'\n }\n }\n\n if (!credential) {\n return sendErrorResponse(response, 400, 'No credential supplied')\n }\n if (!credential.id) {\n credential.id = `urn:uuid:${v4()}`\n }\n if (contextHasPlugin<IStatusListPlugin>(context, 'slAddStatusToCredential')) {\n // Add status list if enabled (and when the input has a credentialStatus object (can be empty))\n const credentialStatusVC = await context.agent.slAddStatusToCredential({ credential })\n if (credential.credentialStatus && !credential.credentialStatus.statusListCredential) {\n credential.credentialStatus = credentialStatusVC.credentialStatus\n }\n }\n\n const issueOpts: IVCAPIIssueOpts | undefined = opts?.issueCredentialOpts\n const vc = await context.agent.createVerifiableCredential({\n credential,\n proofFormat: proofFormat as ProofFormat,\n fetchRemoteContexts: issueOpts?.fetchRemoteContexts !== false,\n })\n const rawDocument = CredentialMapper.storedCredentialToOriginalFormat(vc as OriginalVerifiableCredential)\n const save = opts?.persistIssuedCredentials\n if (save) {\n const issuer = extractIssuer(credential)\n const identifier = await context.agent.identifierManagedGet({ identifier: issuer, issuer: issuer, vmRelationship: 'assertionMethod' })\n\n let issuerCorrelationId: string | undefined = identifier.issuer\n if (!issuerCorrelationId && isDidIdentifier(identifier.identifier)) {\n if (isIIdentifier(identifier.identifier)) {\n issuerCorrelationId = identifier.identifier.did\n } else if (typeof identifier.identifier === 'string') {\n issuerCorrelationId = identifier.identifier\n }\n }\n if (!issuerCorrelationId) {\n if (typeof vc.issuer === 'string') {\n issuerCorrelationId = vc.issuer\n } else if (typeof vc.issuer?.id === 'string') {\n issuerCorrelationId = vc.issuer.id\n } else {\n issuerCorrelationId = 'unknown'\n }\n }\n\n const dc: AddCredentialArgs = {\n credential: {\n credentialRole: CredentialRole.HOLDER,\n // tenantId: 'test-tenant',\n kmsKeyRef: identifier.kmsKeyRef,\n identifierMethod: identifier.method,\n issuerCorrelationId: issuerCorrelationId,\n issuerCorrelationType: CredentialCorrelationType.DID,\n rawDocument: typeof rawDocument === 'string' ? rawDocument : JSON.stringify(rawDocument),\n },\n }\n await context.agent.crsAddCredential(dc)\n }\n response.statusCode = 201\n return response.send({\n verifiableCredential: rawDocument,\n uniformCredential: CredentialMapper.toUniformCredential(vc as OriginalVerifiableCredential),\n })\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n\nexport function getCredentialsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Get credentials endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/credentials'\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const credentialRole = (request.query.credentialRole as CredentialRole) || CredentialRole.HOLDER\n if (!Object.values(CredentialRole).includes(credentialRole)) {\n return sendErrorResponse(response, 400, `Invalid credentialRole: ${credentialRole}`)\n }\n\n const documentType = (request.query.documentType as DocumentType) || DocumentType.VC\n if (!Object.values(DocumentType).includes(documentType)) {\n return sendErrorResponse(response, 400, `Invalid documentType: ${documentType}`)\n }\n\n const filter: FindDigitalCredentialArgs = [\n {\n documentType: documentType,\n credentialRole: credentialRole,\n },\n ]\n const uniqueVCs = await context.agent.crsGetUniqueCredentials({ filter })\n response.statusCode = 202\n return response.send(uniqueVCs.map((uVC) => uVC.uniformVerifiableCredential))\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n\nexport function getCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Get credential endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/credentials/:id'\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const id = request.params.id\n if (!id) {\n return sendErrorResponse(response, 400, 'no id provided')\n }\n const credentialRole = (request.query.credentialRole as CredentialRole) || CredentialRole.HOLDER\n if (!Object.values(CredentialRole).includes(credentialRole)) {\n return sendErrorResponse(response, 400, `Invalid credentialRole: ${credentialRole}`)\n }\n\n const vcInfo = await context.agent.crsGetUniqueCredentialByIdOrHash({\n credentialRole: credentialRole,\n idOrHash: id,\n })\n if (!vcInfo) {\n return sendErrorResponse(response, 403, `id ${id} not found`)\n }\n response.statusCode = 200\n return response.send(vcInfo.uniformVerifiableCredential)\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n\nexport function verifyCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IVerifyCredentialEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Verify credential endpoint is disabled`)\n return\n }\n router.post(opts?.path ?? '/credentials/verify', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n debug(JSON.stringify(request.body, null, 2))\n const credential: OriginalVerifiableCredential = request.body.verifiableCredential\n const options = request.body.options\n if (!credential) {\n return sendErrorResponse(response, 400, 'No verifiable credential supplied')\n }\n const verifyResult = await context.agent.verifyCredential({\n ...options,\n credential,\n policies: {\n ...options?.policies,\n credentialStatus: false, // Do not use built-in. We have our own statusList implementations\n },\n fetchRemoteContexts: opts?.fetchRemoteContexts !== false,\n })\n\n response.statusCode = 200\n return response.send(verifyResult)\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n\nexport function deleteCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Delete credential endpoint is disabled`)\n return\n }\n router.delete(opts?.path ?? '/credentials/:id', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const id = request.params.id\n if (!id) {\n return sendErrorResponse(response, 400, 'no id provided')\n }\n const credentialRole = request.query.credentialRole as CredentialRole\n if (credentialRole === undefined) {\n return sendErrorResponse(response, 400, 'credentialRole query parameter is missing')\n }\n if (!Object.values(CredentialRole).includes(credentialRole)) {\n return sendErrorResponse(response, 400, `Invalid credentialRole: ${credentialRole}`)\n }\n\n const vcInfo = await context.agent.crsGetUniqueCredentialByIdOrHash({\n credentialRole: credentialRole,\n idOrHash: id,\n })\n if (!vcInfo) {\n return sendErrorResponse(response, 404, `id ${id} not found`)\n }\n const success = await context.agent.crsDeleteCredentials({ filter: [{ hash: vcInfo.hash }] })\n if (success === 0) {\n return sendErrorResponse(response, 400, `Could not delete Verifiable Credential with id ${id}`)\n }\n response.statusCode = 200\n return response.send()\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;ACAA,IAAAA,kBAA6B;AAI7B,qBAA8C;;;ACJ9C,iCAAuE;AACvE,yBAA+C;AAC/C,qBAAiC;AACjC,IAAAC,kBAKO;AAC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,QAAID,SAASO,SAAS,YAAA,GAAe;AACnCG,4BAAsB,KAAK3B,QAAQe,SAASP,MAAMC,cAAcmB,aAAAA;AAChEC,6BAAuB,KAAK7B,QAAQe,SAASP,MAAMC,cAAcqB,cAAAA;AACjEC,+BAAyB,KAAK/B,QAAQe,SAASP,MAAMC,cAAcuB,gBAAAA;IACrE;AACA,QAAIf,SAASO,SAAS,WAAA,GAAc;AAClCS,+BAAyB,KAAKjC,QAAQe,SAAS;QAC7C,GAAGP,MAAMC,cAAcyB;QACvBC,qBAAqB3B,MAAMU,qBAAqBiB;MAClD,CAAA;IACF;AACA,SAAKjC,SAASkC,IAAI5B,MAAMC,cAAc4B,YAAY,IAAI,KAAKrC,MAAM;EACnE;EAEA,IAAIO,QAAkC;AACpC,WAAO,KAAKJ;EACd;EAEA,IAAIK,OAA+B;AACjC,WAAO,KAAKJ;EACd;EAEA,IAAIS,UAAmB;AACrB,WAAO,KAAKX;EACd;AACF;AAEA,SAASS,yBAAyBH,MAAkB8B,KAAW;AAC7D,MAAI9B,MAAMC,cAAcC,YAAY;AAElCF,SAAKC,aAAa6B,GAAAA,IAAO;;MAEvB,GAAG9B,KAAKC,aAAa6B,GAAAA;;MAErBC,UAAU;QAAE,GAAG/B,KAAKC,aAAaC;QAAY,GAAGF,KAAKC,aAAa6B,GAAAA,GAAMC;MAAS;IACnF;EACF;AACF;AAVS5B;","names":["import_ssi_sdk","import_ssi_sdk","debug","Debug","issueCredentialEndpoint","router","context","opts","enabled","console","log","path","post","checkAuth","endpoint","request","response","credential","body","reqOpts","options","inputFormat","proofFormat","toLocaleLowerCase","undefined","includes","issueCredentialOpts","isVcdm2Credential","sendErrorResponse","id","v4","contextHasPlugin","credentialStatusVC","agent","slAddStatusToCredential","credentialStatus","statusListCredential","issueOpts","vc","createVerifiableCredential","fetchRemoteContexts","rawDocument","CredentialMapper","storedCredentialToOriginalFormat","save","persistIssuedCredentials","issuer","extractIssuer","identifier","identifierManagedGet","vmRelationship","issuerCorrelationId","isDidIdentifier","isIIdentifier","did","dc","credentialRole","CredentialRole","HOLDER","kmsKeyRef","identifierMethod","method","issuerCorrelationType","CredentialCorrelationType","DID","JSON","stringify","crsAddCredential","statusCode","send","verifiableCredential","uniformCredential","toUniformCredential","e","message","getCredentialsEndpoint","get","query","Object","values","documentType","DocumentType","VC","filter","uniqueVCs","crsGetUniqueCredentials","map","uVC","uniformVerifiableCredential","getCredentialEndpoint","params","vcInfo","crsGetUniqueCredentialByIdOrHash","idOrHash","verifyCredentialEndpoint","verifyResult","verifyCredential","policies","deleteCredentialEndpoint","delete","success","crsDeleteCredentials","hash","VcApiServer","router","_router","_express","_agent","_opts","constructor","args","agent","opts","endpointOpts","globalAuth","copyGlobalAuthToEndpoint","expressSupport","express","Router","context","agentContext","features","issueCredentialOpts","enableFeatures","console","log","JSON","stringify","includes","issueCredentialEndpoint","issueCredential","getCredentialEndpoint","getCredential","getCredentialsEndpoint","getCredentials","deleteCredentialEndpoint","deleteCredential","verifyCredentialEndpoint","verifyCredential","fetchRemoteContexts","use","basePath","key","endpoint"]}
|
package/dist/index.js
CHANGED
|
@@ -7,14 +7,14 @@ import express from "express";
|
|
|
7
7
|
|
|
8
8
|
// src/api-functions.ts
|
|
9
9
|
import { checkAuth, sendErrorResponse } from "@sphereon/ssi-express-support";
|
|
10
|
+
import { isDidIdentifier, isIIdentifier } from "@sphereon/ssi-sdk-ext.identifier-resolution";
|
|
10
11
|
import { contextHasPlugin } from "@sphereon/ssi-sdk.agent-config";
|
|
11
|
-
import { v4 } from "uuid";
|
|
12
|
-
import Debug from "debug";
|
|
13
12
|
import { CredentialCorrelationType, DocumentType } from "@sphereon/ssi-sdk.credential-store";
|
|
13
|
+
import { extractIssuer } from "@sphereon/ssi-sdk.credential-vcdm";
|
|
14
14
|
import { CredentialRole } from "@sphereon/ssi-sdk.data-store";
|
|
15
15
|
import { CredentialMapper, isVcdm2Credential } from "@sphereon/ssi-types";
|
|
16
|
-
import
|
|
17
|
-
import {
|
|
16
|
+
import Debug from "debug";
|
|
17
|
+
import { v4 } from "uuid";
|
|
18
18
|
var debug = Debug("sphereon:ssi-sdk:w3c-vc-api");
|
|
19
19
|
function issueCredentialEndpoint(router, context, opts) {
|
|
20
20
|
if (opts?.enabled === false) {
|
|
@@ -190,12 +190,15 @@ function verifyCredentialEndpoint(router, context, opts) {
|
|
|
190
190
|
try {
|
|
191
191
|
debug(JSON.stringify(request.body, null, 2));
|
|
192
192
|
const credential = request.body.verifiableCredential;
|
|
193
|
+
const options = request.body.options;
|
|
193
194
|
if (!credential) {
|
|
194
195
|
return sendErrorResponse(response, 400, "No verifiable credential supplied");
|
|
195
196
|
}
|
|
196
197
|
const verifyResult = await context.agent.verifyCredential({
|
|
198
|
+
...options,
|
|
197
199
|
credential,
|
|
198
200
|
policies: {
|
|
201
|
+
...options?.policies,
|
|
199
202
|
credentialStatus: false
|
|
200
203
|
},
|
|
201
204
|
fetchRemoteContexts: opts?.fetchRemoteContexts !== false
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/vc-api-server.ts","../src/api-functions.ts"],"sourcesContent":["import { agentContext } from '@sphereon/ssi-sdk.core'\nimport type { ExpressSupport } from '@sphereon/ssi-express-support'\nimport type { TAgent } from '@veramo/core'\n\nimport express, { type Express, Router } from 'express'\nimport {\n deleteCredentialEndpoint,\n getCredentialEndpoint,\n getCredentialsEndpoint,\n issueCredentialEndpoint,\n verifyCredentialEndpoint,\n} from './api-functions'\nimport type { IRequiredPlugins, IVCAPIOpts } from './types'\n\nexport class VcApiServer {\n get router(): express.Router {\n return this._router\n }\n\n private readonly _express: Express\n private readonly _agent: TAgent<IRequiredPlugins>\n private readonly _opts?: IVCAPIOpts\n private readonly _router: Router\n\n constructor(args: { agent: TAgent<IRequiredPlugins>; expressSupport: ExpressSupport; opts?: IVCAPIOpts }) {\n const { agent, opts } = args\n this._agent = agent\n if (opts?.endpointOpts?.globalAuth) {\n copyGlobalAuthToEndpoint(opts, 'issueCredential')\n copyGlobalAuthToEndpoint(opts, 'getCredential')\n copyGlobalAuthToEndpoint(opts, 'getCredentials')\n copyGlobalAuthToEndpoint(opts, 'deleteCredential')\n copyGlobalAuthToEndpoint(opts, 'verifyCredential')\n }\n\n this._opts = opts\n this._express = args.expressSupport.express\n this._router = express.Router()\n\n const context = agentContext(agent)\n\n const features = opts?.issueCredentialOpts?.enableFeatures ?? ['vc-issue', 'vc-persist', 'vc-verify']\n console.log(`VC API enabled, with features: ${JSON.stringify(features)}`)\n\n // Credential endpoints\n if (features.includes('vc-issue')) {\n issueCredentialEndpoint(this.router, context, {\n ...opts?.endpointOpts?.issueCredential,\n issueCredentialOpts: opts?.issueCredentialOpts,\n })\n }\n if (features.includes('vc-persist')) {\n getCredentialEndpoint(this.router, context, opts?.endpointOpts?.getCredential)\n getCredentialsEndpoint(this.router, context, opts?.endpointOpts?.getCredentials)\n deleteCredentialEndpoint(this.router, context, opts?.endpointOpts?.deleteCredential) // not in spec.\n }\n if (features.includes('vc-verify')) {\n verifyCredentialEndpoint(this.router, context, {\n ...opts?.endpointOpts?.verifyCredential,\n fetchRemoteContexts: opts?.issueCredentialOpts?.fetchRemoteContexts,\n })\n }\n this._express.use(opts?.endpointOpts?.basePath ?? '', this.router)\n }\n\n get agent(): TAgent<IRequiredPlugins> {\n return this._agent\n }\n\n get opts(): IVCAPIOpts | undefined {\n return this._opts\n }\n\n get express(): Express {\n return this._express\n }\n}\n\nfunction copyGlobalAuthToEndpoint(opts: IVCAPIOpts, key: string) {\n if (opts?.endpointOpts?.globalAuth) {\n // @ts-ignore\n opts.endpointOpts[key] = {\n // @ts-ignore\n ...opts.endpointOpts[key],\n // @ts-ignore\n endpoint: { ...opts.endpointOpts.globalAuth, ...opts.endpointOpts[key]?.endpoint },\n }\n }\n}\n","import { checkAuth, type ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'\nimport { contextHasPlugin } from '@sphereon/ssi-sdk.agent-config'\nimport type { CredentialPayload, ProofFormat } from '@veramo/core'\nimport { type Request, type Response, Router } from 'express'\nimport { v4 } from 'uuid'\nimport type { IIssueCredentialEndpointOpts, IRequiredContext, IVCAPIIssueOpts, IVerifyCredentialEndpointOpts } from './types'\nimport Debug from 'debug'\nimport { AddCredentialArgs, CredentialCorrelationType, DocumentType, type FindDigitalCredentialArgs } from '@sphereon/ssi-sdk.credential-store'\nimport type { IStatusListPlugin } from '@sphereon/ssi-sdk.vc-status-list'\nimport { CredentialRole } from '@sphereon/ssi-sdk.data-store'\nimport { CredentialMapper, CredentialProofFormat, isVcdm2Credential, OriginalVerifiableCredential } from '@sphereon/ssi-types'\nimport { extractIssuer } from '@sphereon/ssi-sdk.credential-vcdm'\nimport { isDidIdentifier, isIIdentifier } from '@sphereon/ssi-sdk-ext.identifier-resolution'\nimport type { VerifiableCredentialSP } from '@sphereon/ssi-sdk.core'\n\nconst debug = Debug('sphereon:ssi-sdk:w3c-vc-api')\n\nexport function issueCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IIssueCredentialEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Issue credential endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/credentials/issue'\n\n router.post(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const credential: CredentialPayload = request.body.credential\n const reqOpts = request.body.options ?? {}\n const inputFormat = reqOpts.proofFormat?.toLocaleLowerCase()\n let proofFormat: CredentialProofFormat | undefined = undefined\n if (inputFormat) {\n if (inputFormat === 'jwt') {\n proofFormat = 'jwt'\n } else if (inputFormat?.includes('jose') || inputFormat?.includes('vc+jwt')) {\n proofFormat = 'vc+jwt'\n } else if (inputFormat?.includes('ld')) {\n proofFormat = 'lds'\n }\n }\n if (proofFormat === undefined && opts?.issueCredentialOpts?.proofFormat) {\n proofFormat = opts.issueCredentialOpts.proofFormat.toLocaleLowerCase() as CredentialProofFormat\n }\n if (proofFormat === undefined) {\n if (isVcdm2Credential(credential)) {\n proofFormat = 'vc+jwt'\n } else {\n proofFormat = 'lds'\n }\n }\n\n if (!credential) {\n return sendErrorResponse(response, 400, 'No credential supplied')\n }\n if (!credential.id) {\n credential.id = `urn:uuid:${v4()}`\n }\n if (contextHasPlugin<IStatusListPlugin>(context, 'slAddStatusToCredential')) {\n // Add status list if enabled (and when the input has a credentialStatus object (can be empty))\n const credentialStatusVC = await context.agent.slAddStatusToCredential({ credential })\n if (credential.credentialStatus && !credential.credentialStatus.statusListCredential) {\n credential.credentialStatus = credentialStatusVC.credentialStatus\n }\n }\n\n const issueOpts: IVCAPIIssueOpts | undefined = opts?.issueCredentialOpts\n const vc = await context.agent.createVerifiableCredential({\n credential,\n proofFormat: proofFormat as ProofFormat,\n fetchRemoteContexts: issueOpts?.fetchRemoteContexts !== false,\n })\n const rawDocument = CredentialMapper.storedCredentialToOriginalFormat(vc as OriginalVerifiableCredential)\n const save = opts?.persistIssuedCredentials\n if (save) {\n const issuer = extractIssuer(credential)\n const identifier = await context.agent.identifierManagedGet({ identifier: issuer, issuer: issuer, vmRelationship: 'assertionMethod' })\n\n let issuerCorrelationId: string | undefined = identifier.issuer\n if (!issuerCorrelationId && isDidIdentifier(identifier.identifier)) {\n if (isIIdentifier(identifier.identifier)) {\n issuerCorrelationId = identifier.identifier.did\n } else if (typeof identifier.identifier === 'string') {\n issuerCorrelationId = identifier.identifier\n }\n }\n if (!issuerCorrelationId) {\n if (typeof vc.issuer === 'string') {\n issuerCorrelationId = vc.issuer\n } else if (typeof vc.issuer?.id === 'string') {\n issuerCorrelationId = vc.issuer.id\n } else {\n issuerCorrelationId = 'unknown'\n }\n }\n\n const dc: AddCredentialArgs = {\n credential: {\n credentialRole: CredentialRole.HOLDER,\n // tenantId: 'test-tenant',\n kmsKeyRef: identifier.kmsKeyRef,\n identifierMethod: identifier.method,\n issuerCorrelationId: issuerCorrelationId,\n issuerCorrelationType: CredentialCorrelationType.DID,\n rawDocument: typeof rawDocument === 'string' ? rawDocument : JSON.stringify(rawDocument),\n },\n }\n await context.agent.crsAddCredential(dc)\n }\n response.statusCode = 201\n return response.send({ verifiableCredential: rawDocument, uniformCredential: CredentialMapper.toUniformCredential(vc as OriginalVerifiableCredential) })\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n\nexport function getCredentialsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Get credentials endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/credentials'\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const credentialRole = (request.query.credentialRole as CredentialRole) || CredentialRole.HOLDER\n if (!Object.values(CredentialRole).includes(credentialRole)) {\n return sendErrorResponse(response, 400, `Invalid credentialRole: ${credentialRole}`)\n }\n\n const documentType = (request.query.documentType as DocumentType) || DocumentType.VC\n if (!Object.values(DocumentType).includes(documentType)) {\n return sendErrorResponse(response, 400, `Invalid documentType: ${documentType}`)\n }\n\n const filter: FindDigitalCredentialArgs = [\n {\n documentType: documentType,\n credentialRole: credentialRole,\n },\n ]\n const uniqueVCs = await context.agent.crsGetUniqueCredentials({ filter })\n response.statusCode = 202\n return response.send(uniqueVCs.map((uVC) => uVC.uniformVerifiableCredential))\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n\nexport function getCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Get credential endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/credentials/:id'\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const id = request.params.id\n if (!id) {\n return sendErrorResponse(response, 400, 'no id provided')\n }\n const credentialRole = (request.query.credentialRole as CredentialRole) || CredentialRole.HOLDER\n if (!Object.values(CredentialRole).includes(credentialRole)) {\n return sendErrorResponse(response, 400, `Invalid credentialRole: ${credentialRole}`)\n }\n\n const vcInfo = await context.agent.crsGetUniqueCredentialByIdOrHash({\n credentialRole: credentialRole,\n idOrHash: id,\n })\n if (!vcInfo) {\n return sendErrorResponse(response, 403, `id ${id} not found`)\n }\n response.statusCode = 200\n return response.send(vcInfo.uniformVerifiableCredential)\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n\nexport function verifyCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IVerifyCredentialEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Verify credential endpoint is disabled`)\n return\n }\n router.post(opts?.path ?? '/credentials/verify', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n debug(JSON.stringify(request.body, null, 2))\n const credential: VerifiableCredentialSP = request.body.verifiableCredential\n // const options: IIssueOptionsPayload = request.body.options\n if (!credential) {\n return sendErrorResponse(response, 400, 'No verifiable credential supplied')\n }\n const verifyResult = await context.agent.verifyCredential({\n credential,\n policies: {\n credentialStatus: false, // Do not use built-in. We have our own statusList implementations\n },\n fetchRemoteContexts: opts?.fetchRemoteContexts !== false,\n })\n\n response.statusCode = 200\n return response.send(verifyResult)\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n\nexport function deleteCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Delete credential endpoint is disabled`)\n return\n }\n router.delete(opts?.path ?? '/credentials/:id', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const id = request.params.id\n if (!id) {\n return sendErrorResponse(response, 400, 'no id provided')\n }\n const credentialRole = request.query.credentialRole as CredentialRole\n if (credentialRole === undefined) {\n return sendErrorResponse(response, 400, 'credentialRole query parameter is missing')\n }\n if (!Object.values(CredentialRole).includes(credentialRole)) {\n return sendErrorResponse(response, 400, `Invalid credentialRole: ${credentialRole}`)\n }\n\n const vcInfo = await context.agent.crsGetUniqueCredentialByIdOrHash({\n credentialRole: credentialRole,\n idOrHash: id,\n })\n if (!vcInfo) {\n return sendErrorResponse(response, 404, `id ${id} not found`)\n }\n const success = await context.agent.crsDeleteCredentials({ filter: [{ hash: vcInfo.hash }] })\n if (success === 0) {\n return sendErrorResponse(response, 400, `Could not delete Verifiable Credential with id ${id}`)\n }\n response.statusCode = 200\n return response.send()\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n"],"mappings":";;;;AAAA,SAASA,oBAAoB;AAI7B,OAAOC,aAAuC;;;ACJ9C,SAASC,WAAqCC,yBAAyB;AACvE,SAASC,wBAAwB;AAGjC,SAASC,UAAU;AAEnB,OAAOC,WAAW;AAClB,SAA4BC,2BAA2BC,oBAAoD;AAE3G,SAASC,sBAAsB;AAC/B,SAASC,kBAAyCC,yBAAuD;AACzG,SAASC,qBAAqB;AAC9B,SAASC,iBAAiBC,qBAAqB;AAG/C,IAAMC,QAAQC,MAAM,6BAAA;AAEb,SAASC,wBAAwBC,QAAgBC,SAA2BC,MAAmC;AACpH,MAAIA,MAAMC,YAAY,OAAO;AAC3BC,YAAQC,IAAI,uCAAuC;AACnD;EACF;AACA,QAAMC,OAAOJ,MAAMI,QAAQ;AAE3BN,SAAOO,KAAKD,MAAME,UAAUN,MAAMO,QAAAA,GAAW,OAAOC,SAAkBC,aAAAA;AACpE,QAAI;AACF,YAAMC,aAAgCF,QAAQG,KAAKD;AACnD,YAAME,UAAUJ,QAAQG,KAAKE,WAAW,CAAC;AACzC,YAAMC,cAAcF,QAAQG,aAAaC,kBAAAA;AACzC,UAAID,cAAiDE;AACrD,UAAIH,aAAa;AACf,YAAIA,gBAAgB,OAAO;AACzBC,wBAAc;QAChB,WAAWD,aAAaI,SAAS,MAAA,KAAWJ,aAAaI,SAAS,QAAA,GAAW;AAC3EH,wBAAc;QAChB,WAAWD,aAAaI,SAAS,IAAA,GAAO;AACtCH,wBAAc;QAChB;MACF;AACA,UAAIA,gBAAgBE,UAAajB,MAAMmB,qBAAqBJ,aAAa;AACvEA,sBAAcf,KAAKmB,oBAAoBJ,YAAYC,kBAAiB;MAC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AE7B,UAAMU,WAAWT,MAAMU,qBAAqBC,kBAAkB;MAAC;MAAY;MAAc;;AACzFC,YAAQC,IAAI,kCAAkCC,KAAKC,UAAUN,QAAAA,CAAAA,EAAW;AAGxE,QAAIA,SAASO,SAAS,UAAA,GAAa;AACjCC,8BAAwB,KAAKzB,QAAQe,SAAS;QAC5C,GAAGP,MAAMC,cAAciB;QACvBR,qBAAqBV,MAAMU;MAC7B,CAAA;IACF;AACA,QAAID,SAASO,SAAS,YAAA,GAAe;AACnCG,4BAAsB,KAAK3B,QAAQe,SAASP,MAAMC,cAAcmB,aAAAA;AAChEC,6BAAuB,KAAK7B,QAAQe,SAASP,MAAMC,cAAcqB,cAAAA;AACjEC,+BAAyB,KAAK/B,QAAQe,SAASP,MAAMC,cAAcuB,gBAAAA;IACrE;AACA,QAAIf,SAASO,SAAS,WAAA,GAAc;AAClCS,+BAAyB,KAAKjC,QAAQe,SAAS;QAC7C,GAAGP,MAAMC,cAAcyB;QACvBC,qBAAqB3B,MAAMU,qBAAqBiB;MAClD,CAAA;IACF;AACA,SAAKjC,SAASkC,IAAI5B,MAAMC,cAAc4B,YAAY,IAAI,KAAKrC,MAAM;EACnE;EAEA,IAAIO,QAAkC;AACpC,WAAO,KAAKJ;EACd;EAEA,IAAIK,OAA+B;AACjC,WAAO,KAAKJ;EACd;EAEA,IAAIS,UAAmB;AACrB,WAAO,KAAKX;EACd;AACF;AAEA,SAASS,yBAAyBH,MAAkB8B,KAAW;AAC7D,MAAI9B,MAAMC,cAAcC,YAAY;AAElCF,SAAKC,aAAa6B,GAAAA,IAAO;;MAEvB,GAAG9B,KAAKC,aAAa6B,GAAAA;;MAErBC,UAAU;QAAE,GAAG/B,KAAKC,aAAaC;QAAY,GAAGF,KAAKC,aAAa6B,GAAAA,GAAMC;MAAS;IACnF;EACF;AACF;AAVS5B;","names":["agentContext","express","checkAuth","sendErrorResponse","contextHasPlugin","v4","Debug","CredentialCorrelationType","DocumentType","CredentialRole","CredentialMapper","isVcdm2Credential","extractIssuer","isDidIdentifier","isIIdentifier","debug","Debug","issueCredentialEndpoint","router","context","opts","enabled","console","log","path","post","checkAuth","endpoint","request","response","credential","body","reqOpts","options","inputFormat","proofFormat","toLocaleLowerCase","undefined","includes","issueCredentialOpts","isVcdm2Credential","sendErrorResponse","id","v4","contextHasPlugin","credentialStatusVC","agent","slAddStatusToCredential","credentialStatus","statusListCredential","issueOpts","vc","createVerifiableCredential","fetchRemoteContexts","rawDocument","CredentialMapper","storedCredentialToOriginalFormat","save","persistIssuedCredentials","issuer","extractIssuer","identifier","identifierManagedGet","vmRelationship","issuerCorrelationId","isDidIdentifier","isIIdentifier","did","dc","credentialRole","CredentialRole","HOLDER","kmsKeyRef","identifierMethod","method","issuerCorrelationType","CredentialCorrelationType","DID","JSON","stringify","crsAddCredential","statusCode","send","verifiableCredential","uniformCredential","toUniformCredential","e","message","getCredentialsEndpoint","get","query","Object","values","documentType","DocumentType","VC","filter","uniqueVCs","crsGetUniqueCredentials","map","uVC","uniformVerifiableCredential","getCredentialEndpoint","params","vcInfo","crsGetUniqueCredentialByIdOrHash","idOrHash","verifyCredentialEndpoint","verifyResult","verifyCredential","policies","deleteCredentialEndpoint","delete","success","crsDeleteCredentials","hash","VcApiServer","router","_router","_express","_agent","_opts","constructor","args","agent","opts","endpointOpts","globalAuth","copyGlobalAuthToEndpoint","expressSupport","express","Router","context","agentContext","features","issueCredentialOpts","enableFeatures","console","log","JSON","stringify","includes","issueCredentialEndpoint","issueCredential","getCredentialEndpoint","getCredential","getCredentialsEndpoint","getCredentials","deleteCredentialEndpoint","deleteCredential","verifyCredentialEndpoint","verifyCredential","fetchRemoteContexts","use","basePath","key","endpoint"]}
|
|
1
|
+
{"version":3,"sources":["../src/vc-api-server.ts","../src/api-functions.ts"],"sourcesContent":["import { agentContext } from '@sphereon/ssi-sdk.core'\nimport type { ExpressSupport } from '@sphereon/ssi-express-support'\nimport type { TAgent } from '@veramo/core'\n\nimport express, { type Express, Router } from 'express'\nimport {\n deleteCredentialEndpoint,\n getCredentialEndpoint,\n getCredentialsEndpoint,\n issueCredentialEndpoint,\n verifyCredentialEndpoint,\n} from './api-functions'\nimport type { IRequiredPlugins, IVCAPIOpts } from './types'\n\nexport class VcApiServer {\n get router(): express.Router {\n return this._router\n }\n\n private readonly _express: Express\n private readonly _agent: TAgent<IRequiredPlugins>\n private readonly _opts?: IVCAPIOpts\n private readonly _router: Router\n\n constructor(args: { agent: TAgent<IRequiredPlugins>; expressSupport: ExpressSupport; opts?: IVCAPIOpts }) {\n const { agent, opts } = args\n this._agent = agent\n if (opts?.endpointOpts?.globalAuth) {\n copyGlobalAuthToEndpoint(opts, 'issueCredential')\n copyGlobalAuthToEndpoint(opts, 'getCredential')\n copyGlobalAuthToEndpoint(opts, 'getCredentials')\n copyGlobalAuthToEndpoint(opts, 'deleteCredential')\n copyGlobalAuthToEndpoint(opts, 'verifyCredential')\n }\n\n this._opts = opts\n this._express = args.expressSupport.express\n this._router = express.Router()\n\n const context = agentContext(agent)\n\n const features = opts?.issueCredentialOpts?.enableFeatures ?? ['vc-issue', 'vc-persist', 'vc-verify']\n console.log(`VC API enabled, with features: ${JSON.stringify(features)}`)\n\n // Credential endpoints\n if (features.includes('vc-issue')) {\n issueCredentialEndpoint(this.router, context, {\n ...opts?.endpointOpts?.issueCredential,\n issueCredentialOpts: opts?.issueCredentialOpts,\n })\n }\n if (features.includes('vc-persist')) {\n getCredentialEndpoint(this.router, context, opts?.endpointOpts?.getCredential)\n getCredentialsEndpoint(this.router, context, opts?.endpointOpts?.getCredentials)\n deleteCredentialEndpoint(this.router, context, opts?.endpointOpts?.deleteCredential) // not in spec.\n }\n if (features.includes('vc-verify')) {\n verifyCredentialEndpoint(this.router, context, {\n ...opts?.endpointOpts?.verifyCredential,\n fetchRemoteContexts: opts?.issueCredentialOpts?.fetchRemoteContexts,\n })\n }\n this._express.use(opts?.endpointOpts?.basePath ?? '', this.router)\n }\n\n get agent(): TAgent<IRequiredPlugins> {\n return this._agent\n }\n\n get opts(): IVCAPIOpts | undefined {\n return this._opts\n }\n\n get express(): Express {\n return this._express\n }\n}\n\nfunction copyGlobalAuthToEndpoint(opts: IVCAPIOpts, key: string) {\n if (opts?.endpointOpts?.globalAuth) {\n // @ts-ignore\n opts.endpointOpts[key] = {\n // @ts-ignore\n ...opts.endpointOpts[key],\n // @ts-ignore\n endpoint: { ...opts.endpointOpts.globalAuth, ...opts.endpointOpts[key]?.endpoint },\n }\n }\n}\n","import { checkAuth, type ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'\nimport { isDidIdentifier, isIIdentifier } from '@sphereon/ssi-sdk-ext.identifier-resolution'\nimport { contextHasPlugin } from '@sphereon/ssi-sdk.agent-config'\nimport {\n AddCredentialArgs,\n CredentialCorrelationType,\n DocumentType,\n type FindDigitalCredentialArgs\n} from '@sphereon/ssi-sdk.credential-store'\nimport { extractIssuer } from '@sphereon/ssi-sdk.credential-vcdm'\nimport { CredentialRole } from '@sphereon/ssi-sdk.data-store'\nimport type { IStatusListPlugin } from '@sphereon/ssi-sdk.vc-status-list'\nimport {\n CredentialMapper,\n CredentialProofFormat,\n isVcdm2Credential,\n OriginalVerifiableCredential\n} from '@sphereon/ssi-types'\nimport type { CredentialPayload, ProofFormat } from '@veramo/core'\nimport Debug from 'debug'\nimport { type Request, type Response, Router } from 'express'\nimport { v4 } from 'uuid'\nimport type {\n IIssueCredentialEndpointOpts,\n IRequiredContext,\n IVCAPIIssueOpts,\n IVerifyCredentialEndpointOpts\n} from './types'\n\nconst debug = Debug('sphereon:ssi-sdk:w3c-vc-api')\n\nexport function issueCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IIssueCredentialEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Issue credential endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/credentials/issue'\n\n router.post(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const credential: CredentialPayload = request.body.credential\n const reqOpts = request.body.options ?? {}\n const inputFormat = reqOpts.proofFormat?.toLocaleLowerCase()\n let proofFormat: CredentialProofFormat | undefined = undefined\n if (inputFormat) {\n if (inputFormat === 'jwt') {\n proofFormat = 'jwt'\n } else if (inputFormat?.includes('jose') || inputFormat?.includes('vc+jwt')) {\n proofFormat = 'vc+jwt'\n } else if (inputFormat?.includes('ld')) {\n proofFormat = 'lds'\n }\n }\n if (proofFormat === undefined && opts?.issueCredentialOpts?.proofFormat) {\n proofFormat = opts.issueCredentialOpts.proofFormat.toLocaleLowerCase() as CredentialProofFormat\n }\n if (proofFormat === undefined) {\n if (isVcdm2Credential(credential)) {\n proofFormat = 'vc+jwt'\n } else {\n proofFormat = 'lds'\n }\n }\n\n if (!credential) {\n return sendErrorResponse(response, 400, 'No credential supplied')\n }\n if (!credential.id) {\n credential.id = `urn:uuid:${v4()}`\n }\n if (contextHasPlugin<IStatusListPlugin>(context, 'slAddStatusToCredential')) {\n // Add status list if enabled (and when the input has a credentialStatus object (can be empty))\n const credentialStatusVC = await context.agent.slAddStatusToCredential({ credential })\n if (credential.credentialStatus && !credential.credentialStatus.statusListCredential) {\n credential.credentialStatus = credentialStatusVC.credentialStatus\n }\n }\n\n const issueOpts: IVCAPIIssueOpts | undefined = opts?.issueCredentialOpts\n const vc = await context.agent.createVerifiableCredential({\n credential,\n proofFormat: proofFormat as ProofFormat,\n fetchRemoteContexts: issueOpts?.fetchRemoteContexts !== false,\n })\n const rawDocument = CredentialMapper.storedCredentialToOriginalFormat(vc as OriginalVerifiableCredential)\n const save = opts?.persistIssuedCredentials\n if (save) {\n const issuer = extractIssuer(credential)\n const identifier = await context.agent.identifierManagedGet({ identifier: issuer, issuer: issuer, vmRelationship: 'assertionMethod' })\n\n let issuerCorrelationId: string | undefined = identifier.issuer\n if (!issuerCorrelationId && isDidIdentifier(identifier.identifier)) {\n if (isIIdentifier(identifier.identifier)) {\n issuerCorrelationId = identifier.identifier.did\n } else if (typeof identifier.identifier === 'string') {\n issuerCorrelationId = identifier.identifier\n }\n }\n if (!issuerCorrelationId) {\n if (typeof vc.issuer === 'string') {\n issuerCorrelationId = vc.issuer\n } else if (typeof vc.issuer?.id === 'string') {\n issuerCorrelationId = vc.issuer.id\n } else {\n issuerCorrelationId = 'unknown'\n }\n }\n\n const dc: AddCredentialArgs = {\n credential: {\n credentialRole: CredentialRole.HOLDER,\n // tenantId: 'test-tenant',\n kmsKeyRef: identifier.kmsKeyRef,\n identifierMethod: identifier.method,\n issuerCorrelationId: issuerCorrelationId,\n issuerCorrelationType: CredentialCorrelationType.DID,\n rawDocument: typeof rawDocument === 'string' ? rawDocument : JSON.stringify(rawDocument),\n },\n }\n await context.agent.crsAddCredential(dc)\n }\n response.statusCode = 201\n return response.send({\n verifiableCredential: rawDocument,\n uniformCredential: CredentialMapper.toUniformCredential(vc as OriginalVerifiableCredential),\n })\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n\nexport function getCredentialsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Get credentials endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/credentials'\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const credentialRole = (request.query.credentialRole as CredentialRole) || CredentialRole.HOLDER\n if (!Object.values(CredentialRole).includes(credentialRole)) {\n return sendErrorResponse(response, 400, `Invalid credentialRole: ${credentialRole}`)\n }\n\n const documentType = (request.query.documentType as DocumentType) || DocumentType.VC\n if (!Object.values(DocumentType).includes(documentType)) {\n return sendErrorResponse(response, 400, `Invalid documentType: ${documentType}`)\n }\n\n const filter: FindDigitalCredentialArgs = [\n {\n documentType: documentType,\n credentialRole: credentialRole,\n },\n ]\n const uniqueVCs = await context.agent.crsGetUniqueCredentials({ filter })\n response.statusCode = 202\n return response.send(uniqueVCs.map((uVC) => uVC.uniformVerifiableCredential))\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n\nexport function getCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Get credential endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/credentials/:id'\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const id = request.params.id\n if (!id) {\n return sendErrorResponse(response, 400, 'no id provided')\n }\n const credentialRole = (request.query.credentialRole as CredentialRole) || CredentialRole.HOLDER\n if (!Object.values(CredentialRole).includes(credentialRole)) {\n return sendErrorResponse(response, 400, `Invalid credentialRole: ${credentialRole}`)\n }\n\n const vcInfo = await context.agent.crsGetUniqueCredentialByIdOrHash({\n credentialRole: credentialRole,\n idOrHash: id,\n })\n if (!vcInfo) {\n return sendErrorResponse(response, 403, `id ${id} not found`)\n }\n response.statusCode = 200\n return response.send(vcInfo.uniformVerifiableCredential)\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n\nexport function verifyCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IVerifyCredentialEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Verify credential endpoint is disabled`)\n return\n }\n router.post(opts?.path ?? '/credentials/verify', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n debug(JSON.stringify(request.body, null, 2))\n const credential: OriginalVerifiableCredential = request.body.verifiableCredential\n const options = request.body.options\n if (!credential) {\n return sendErrorResponse(response, 400, 'No verifiable credential supplied')\n }\n const verifyResult = await context.agent.verifyCredential({\n ...options,\n credential,\n policies: {\n ...options?.policies,\n credentialStatus: false, // Do not use built-in. We have our own statusList implementations\n },\n fetchRemoteContexts: opts?.fetchRemoteContexts !== false,\n })\n\n response.statusCode = 200\n return response.send(verifyResult)\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n\nexport function deleteCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Delete credential endpoint is disabled`)\n return\n }\n router.delete(opts?.path ?? '/credentials/:id', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const id = request.params.id\n if (!id) {\n return sendErrorResponse(response, 400, 'no id provided')\n }\n const credentialRole = request.query.credentialRole as CredentialRole\n if (credentialRole === undefined) {\n return sendErrorResponse(response, 400, 'credentialRole query parameter is missing')\n }\n if (!Object.values(CredentialRole).includes(credentialRole)) {\n return sendErrorResponse(response, 400, `Invalid credentialRole: ${credentialRole}`)\n }\n\n const vcInfo = await context.agent.crsGetUniqueCredentialByIdOrHash({\n credentialRole: credentialRole,\n idOrHash: id,\n })\n if (!vcInfo) {\n return sendErrorResponse(response, 404, `id ${id} not found`)\n }\n const success = await context.agent.crsDeleteCredentials({ filter: [{ hash: vcInfo.hash }] })\n if (success === 0) {\n return sendErrorResponse(response, 400, `Could not delete Verifiable Credential with id ${id}`)\n }\n response.statusCode = 200\n return response.send()\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n"],"mappings":";;;;AAAA,SAASA,oBAAoB;AAI7B,OAAOC,aAAuC;;;ACJ9C,SAASC,WAAqCC,yBAAyB;AACvE,SAASC,iBAAiBC,qBAAqB;AAC/C,SAASC,wBAAwB;AACjC,SAEEC,2BACAC,oBAEK;AACP,SAASC,qBAAqB;AAC9B,SAASC,sBAAsB;AAE/B,SACEC,kBAEAC,yBAEK;AAEP,OAAOC,WAAW;AAElB,SAASC,UAAU;AAQnB,IAAMC,QAAQC,MAAM,6BAAA;AAEb,SAASC,wBAAwBC,QAAgBC,SAA2BC,MAAmC;AACpH,MAAIA,MAAMC,YAAY,OAAO;AAC3BC,YAAQC,IAAI,uCAAuC;AACnD;EACF;AACA,QAAMC,OAAOJ,MAAMI,QAAQ;AAE3BN,SAAOO,KAAKD,MAAME,UAAUN,MAAMO,QAAAA,GAAW,OAAOC,SAAkBC,aAAAA;AACpE,QAAI;AACF,YAAMC,aAAgCF,QAAQG,KAAKD;AACnD,YAAME,UAAUJ,QAAQG,KA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KJ;EACd;EAEA,IAAIK,OAA+B;AACjC,WAAO,KAAKJ;EACd;EAEA,IAAIS,UAAmB;AACrB,WAAO,KAAKX;EACd;AACF;AAEA,SAASS,yBAAyBH,MAAkB8B,KAAW;AAC7D,MAAI9B,MAAMC,cAAcC,YAAY;AAElCF,SAAKC,aAAa6B,GAAAA,IAAO;;MAEvB,GAAG9B,KAAKC,aAAa6B,GAAAA;;MAErBC,UAAU;QAAE,GAAG/B,KAAKC,aAAaC;QAAY,GAAGF,KAAKC,aAAa6B,GAAAA,GAAMC;MAAS;IACnF;EACF;AACF;AAVS5B;","names":["agentContext","express","checkAuth","sendErrorResponse","isDidIdentifier","isIIdentifier","contextHasPlugin","CredentialCorrelationType","DocumentType","extractIssuer","CredentialRole","CredentialMapper","isVcdm2Credential","Debug","v4","debug","Debug","issueCredentialEndpoint","router","context","opts","enabled","console","log","path","post","checkAuth","endpoint","request","response","credential","body","reqOpts","options","inputFormat","proofFormat","toLocaleLowerCase","undefined","includes","issueCredentialOpts","isVcdm2Credential","sendErrorResponse","id","v4","contextHasPlugin","credentialStatusVC","agent","slAddStatusToCredential","credentialStatus","statusListCredential","issueOpts","vc","createVerifiableCredential","fetchRemoteContexts","rawDocument","CredentialMapper","storedCredentialToOriginalFormat","save","persistIssuedCredentials","issuer","extractIssuer","identifier","identifierManagedGet","vmRelationship","issuerCorrelationId","isDidIdentifier","isIIdentifier","did","dc","credentialRole","CredentialRole","HOLDER","kmsKeyRef","identifierMethod","method","issuerCorrelationType","CredentialCorrelationType","DID","JSON","stringify","crsAddCredential","statusCode","send","verifiableCredential","uniformCredential","toUniformCredential","e","message","getCredentialsEndpoint","get","query","Object","values","documentType","DocumentType","VC","filter","uniqueVCs","crsGetUniqueCredentials","map","uVC","uniformVerifiableCredential","getCredentialEndpoint","params","vcInfo","crsGetUniqueCredentialByIdOrHash","idOrHash","verifyCredentialEndpoint","verifyResult","verifyCredential","policies","deleteCredentialEndpoint","delete","success","crsDeleteCredentials","hash","VcApiServer","router","_router","_express","_agent","_opts","constructor","args","agent","opts","endpointOpts","globalAuth","copyGlobalAuthToEndpoint","expressSupport","express","Router","context","agentContext","features","issueCredentialOpts","enableFeatures","console","log","JSON","stringify","includes","issueCredentialEndpoint","issueCredential","getCredentialEndpoint","getCredential","getCredentialsEndpoint","getCredentials","deleteCredentialEndpoint","deleteCredential","verifyCredentialEndpoint","verifyCredential","fetchRemoteContexts","use","basePath","key","endpoint"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.w3c-vc-api",
|
|
3
|
-
"version": "0.33.1-next.
|
|
3
|
+
"version": "0.33.1-next.73+be17b2cb",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -24,18 +24,18 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@sphereon/did-auth-siop": "0.17.1-next.39",
|
|
27
|
-
"@sphereon/ssi-express-support": "0.33.1-next.
|
|
27
|
+
"@sphereon/ssi-express-support": "0.33.1-next.73+be17b2cb",
|
|
28
28
|
"@sphereon/ssi-sdk-ext.identifier-resolution": "0.28.1-next.53",
|
|
29
29
|
"@sphereon/ssi-sdk-ext.jwt-service": "0.28.1-next.53",
|
|
30
|
-
"@sphereon/ssi-sdk.agent-config": "0.33.1-next.
|
|
31
|
-
"@sphereon/ssi-sdk.core": "0.33.1-next.
|
|
32
|
-
"@sphereon/ssi-sdk.credential-store": "0.33.1-next.
|
|
33
|
-
"@sphereon/ssi-sdk.credential-vcdm": "0.33.1-next.
|
|
34
|
-
"@sphereon/ssi-sdk.kv-store-temp": "0.33.1-next.
|
|
35
|
-
"@sphereon/ssi-sdk.presentation-exchange": "0.33.1-next.
|
|
36
|
-
"@sphereon/ssi-sdk.vc-status-list": "0.33.1-next.
|
|
37
|
-
"@sphereon/ssi-sdk.vc-status-list-issuer": "0.33.1-next.
|
|
38
|
-
"@sphereon/ssi-types": "0.33.1-next.
|
|
30
|
+
"@sphereon/ssi-sdk.agent-config": "0.33.1-next.73+be17b2cb",
|
|
31
|
+
"@sphereon/ssi-sdk.core": "0.33.1-next.73+be17b2cb",
|
|
32
|
+
"@sphereon/ssi-sdk.credential-store": "0.33.1-next.73+be17b2cb",
|
|
33
|
+
"@sphereon/ssi-sdk.credential-vcdm": "0.33.1-next.73+be17b2cb",
|
|
34
|
+
"@sphereon/ssi-sdk.kv-store-temp": "0.33.1-next.73+be17b2cb",
|
|
35
|
+
"@sphereon/ssi-sdk.presentation-exchange": "0.33.1-next.73+be17b2cb",
|
|
36
|
+
"@sphereon/ssi-sdk.vc-status-list": "0.33.1-next.73+be17b2cb",
|
|
37
|
+
"@sphereon/ssi-sdk.vc-status-list-issuer": "0.33.1-next.73+be17b2cb",
|
|
38
|
+
"@sphereon/ssi-types": "0.33.1-next.73+be17b2cb",
|
|
39
39
|
"@veramo/core": "4.2.0",
|
|
40
40
|
"body-parser": "^1.20.2",
|
|
41
41
|
"casbin": "^5.30.0",
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
"uuid": "^9.0.1"
|
|
50
50
|
},
|
|
51
51
|
"optionalDependencies": {
|
|
52
|
-
"@sphereon/ssi-sdk.credential-vcdm-jsonld-provider": "0.33.1-next.
|
|
53
|
-
"@sphereon/ssi-sdk.credential-vcdm1-jwt-provider": "0.33.1-next.
|
|
54
|
-
"@sphereon/ssi-sdk.credential-vcdm2-jose-provider": "0.33.1-next.
|
|
52
|
+
"@sphereon/ssi-sdk.credential-vcdm-jsonld-provider": "0.33.1-next.73+be17b2cb",
|
|
53
|
+
"@sphereon/ssi-sdk.credential-vcdm1-jwt-provider": "0.33.1-next.73+be17b2cb",
|
|
54
|
+
"@sphereon/ssi-sdk.credential-vcdm2-jose-provider": "0.33.1-next.73+be17b2cb"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@sphereon/did-provider-oyd": "0.28.1-next.53",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"@sphereon/ssi-sdk.credential-vcdm-jsonld-provider": "workspace:*",
|
|
65
65
|
"@sphereon/ssi-sdk.credential-vcdm1-jwt-provider": "workspace:*",
|
|
66
66
|
"@sphereon/ssi-sdk.credential-vcdm2-jose-provider": "workspace:*",
|
|
67
|
-
"@sphereon/ssi-sdk.data-store": "0.33.1-next.
|
|
67
|
+
"@sphereon/ssi-sdk.data-store": "0.33.1-next.73+be17b2cb",
|
|
68
68
|
"@types/body-parser": "^1.19.5",
|
|
69
69
|
"@types/cookie-parser": "^1.4.7",
|
|
70
70
|
"@types/cors": "^2.8.17",
|
|
@@ -116,5 +116,5 @@
|
|
|
116
116
|
"W3C",
|
|
117
117
|
"VC API"
|
|
118
118
|
],
|
|
119
|
-
"gitHead": "
|
|
119
|
+
"gitHead": "be17b2cb752a6e5368119259e89a1f2a99f56848"
|
|
120
120
|
}
|
package/src/api-functions.ts
CHANGED
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
import { checkAuth, type ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'
|
|
2
|
+
import { isDidIdentifier, isIIdentifier } from '@sphereon/ssi-sdk-ext.identifier-resolution'
|
|
2
3
|
import { contextHasPlugin } from '@sphereon/ssi-sdk.agent-config'
|
|
4
|
+
import {
|
|
5
|
+
AddCredentialArgs,
|
|
6
|
+
CredentialCorrelationType,
|
|
7
|
+
DocumentType,
|
|
8
|
+
type FindDigitalCredentialArgs
|
|
9
|
+
} from '@sphereon/ssi-sdk.credential-store'
|
|
10
|
+
import { extractIssuer } from '@sphereon/ssi-sdk.credential-vcdm'
|
|
11
|
+
import { CredentialRole } from '@sphereon/ssi-sdk.data-store'
|
|
12
|
+
import type { IStatusListPlugin } from '@sphereon/ssi-sdk.vc-status-list'
|
|
13
|
+
import {
|
|
14
|
+
CredentialMapper,
|
|
15
|
+
CredentialProofFormat,
|
|
16
|
+
isVcdm2Credential,
|
|
17
|
+
OriginalVerifiableCredential
|
|
18
|
+
} from '@sphereon/ssi-types'
|
|
3
19
|
import type { CredentialPayload, ProofFormat } from '@veramo/core'
|
|
20
|
+
import Debug from 'debug'
|
|
4
21
|
import { type Request, type Response, Router } from 'express'
|
|
5
22
|
import { v4 } from 'uuid'
|
|
6
|
-
import type {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import { extractIssuer } from '@sphereon/ssi-sdk.credential-vcdm'
|
|
13
|
-
import { isDidIdentifier, isIIdentifier } from '@sphereon/ssi-sdk-ext.identifier-resolution'
|
|
14
|
-
import type { VerifiableCredentialSP } from '@sphereon/ssi-sdk.core'
|
|
23
|
+
import type {
|
|
24
|
+
IIssueCredentialEndpointOpts,
|
|
25
|
+
IRequiredContext,
|
|
26
|
+
IVCAPIIssueOpts,
|
|
27
|
+
IVerifyCredentialEndpointOpts
|
|
28
|
+
} from './types'
|
|
15
29
|
|
|
16
30
|
const debug = Debug('sphereon:ssi-sdk:w3c-vc-api')
|
|
17
31
|
|
|
@@ -106,7 +120,10 @@ export function issueCredentialEndpoint(router: Router, context: IRequiredContex
|
|
|
106
120
|
await context.agent.crsAddCredential(dc)
|
|
107
121
|
}
|
|
108
122
|
response.statusCode = 201
|
|
109
|
-
return response.send({
|
|
123
|
+
return response.send({
|
|
124
|
+
verifiableCredential: rawDocument,
|
|
125
|
+
uniformCredential: CredentialMapper.toUniformCredential(vc as OriginalVerifiableCredential),
|
|
126
|
+
})
|
|
110
127
|
} catch (e) {
|
|
111
128
|
return sendErrorResponse(response, 500, e.message as string, e)
|
|
112
129
|
}
|
|
@@ -186,14 +203,16 @@ export function verifyCredentialEndpoint(router: Router, context: IRequiredConte
|
|
|
186
203
|
router.post(opts?.path ?? '/credentials/verify', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
187
204
|
try {
|
|
188
205
|
debug(JSON.stringify(request.body, null, 2))
|
|
189
|
-
const credential:
|
|
190
|
-
|
|
206
|
+
const credential: OriginalVerifiableCredential = request.body.verifiableCredential
|
|
207
|
+
const options = request.body.options
|
|
191
208
|
if (!credential) {
|
|
192
209
|
return sendErrorResponse(response, 400, 'No verifiable credential supplied')
|
|
193
210
|
}
|
|
194
211
|
const verifyResult = await context.agent.verifyCredential({
|
|
212
|
+
...options,
|
|
195
213
|
credential,
|
|
196
214
|
policies: {
|
|
215
|
+
...options?.policies,
|
|
197
216
|
credentialStatus: false, // Do not use built-in. We have our own statusList implementations
|
|
198
217
|
},
|
|
199
218
|
fetchRemoteContexts: opts?.fetchRemoteContexts !== false,
|