@sphereon/ssi-sdk.w3c-vc-api 0.13.1-next.3 → 0.13.1-next.32
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/api-functions.d.ts +9 -0
- package/dist/api-functions.d.ts.map +1 -0
- package/dist/api-functions.js +150 -0
- package/dist/api-functions.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +67 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/vc-api-server.d.ts +20 -0
- package/dist/vc-api-server.d.ts.map +1 -0
- package/dist/vc-api-server.js +65 -0
- package/dist/vc-api-server.js.map +1 -0
- package/package.json +22 -25
- package/src/api-functions.ts +132 -0
- package/src/index.ts +2 -1
- package/src/types.ts +77 -2
- package/src/vc-api-server.ts +89 -0
- package/dist/VCAPIServer.d.ts +0 -78
- package/dist/VCAPIServer.d.ts.map +0 -1
- package/dist/VCAPIServer.js +0 -245
- package/dist/VCAPIServer.js.map +0 -1
- package/dist/request-agent-router.d.ts +0 -30
- package/dist/request-agent-router.d.ts.map +0 -1
- package/dist/request-agent-router.js +0 -41
- package/dist/request-agent-router.js.map +0 -1
- package/src/VCAPIServer.ts +0 -283
- package/src/request-agent-router.ts +0 -47
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ISingleEndpointOpts } from '@sphereon/ssi-sdk.express-support';
|
|
2
|
+
import { Router } from 'express';
|
|
3
|
+
import { IIssueCredentialEndpointOpts, IRequiredContext, IVerifyCredentialEndpointOpts } from './types';
|
|
4
|
+
export declare function issueCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IIssueCredentialEndpointOpts): void;
|
|
5
|
+
export declare function getCredentialsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
6
|
+
export declare function getCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
7
|
+
export declare function verifyCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IVerifyCredentialEndpointOpts): void;
|
|
8
|
+
export declare function deleteCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
9
|
+
//# sourceMappingURL=api-functions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-functions.d.ts","sourceRoot":"","sources":["../src/api-functions.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,mBAAmB,EAAqB,MAAM,mCAAmC,CAAA;AAGrG,OAAO,EAAqB,MAAM,EAAE,MAAM,SAAS,CAAA;AAEnD,OAAO,EAAE,4BAA4B,EAAE,gBAAgB,EAAmB,6BAA6B,EAAE,MAAM,SAAS,CAAA;AAExH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE,4BAA4B,QA6BrH;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE,mBAAmB,QAe3G;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE,mBAAmB,QAsB1G;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE,6BAA6B,QAwBvH;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE,mBAAmB,QAyB7G"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.deleteCredentialEndpoint = exports.verifyCredentialEndpoint = exports.getCredentialEndpoint = exports.getCredentialsEndpoint = exports.issueCredentialEndpoint = void 0;
|
|
13
|
+
const ssi_sdk_core_1 = require("@sphereon/ssi-sdk.core");
|
|
14
|
+
const ssi_sdk_express_support_1 = require("@sphereon/ssi-sdk.express-support");
|
|
15
|
+
const uuid_1 = require("uuid");
|
|
16
|
+
function issueCredentialEndpoint(router, context, opts) {
|
|
17
|
+
var _a;
|
|
18
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
19
|
+
console.log(`Issue credential endpoint is disabled`);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials/issue';
|
|
23
|
+
router.post(path, (0, ssi_sdk_express_support_1.checkAuth)(opts === null || opts === void 0 ? void 0 : opts.endpoint), (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
var _b;
|
|
25
|
+
try {
|
|
26
|
+
const credential = request.body.credential;
|
|
27
|
+
if (!credential) {
|
|
28
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 400, 'No credential supplied');
|
|
29
|
+
}
|
|
30
|
+
if (!credential.id) {
|
|
31
|
+
credential.id = `urn:uuid:${(0, uuid_1.v4)()}`;
|
|
32
|
+
}
|
|
33
|
+
const issueOpts = opts === null || opts === void 0 ? void 0 : opts.issueCredentialOpts;
|
|
34
|
+
const vc = yield context.agent.createVerifiableCredential({
|
|
35
|
+
credential,
|
|
36
|
+
save: (opts === null || opts === void 0 ? void 0 : opts.persistIssuedCredentials) !== false,
|
|
37
|
+
proofFormat: (_b = issueOpts === null || issueOpts === void 0 ? void 0 : issueOpts.proofFormat) !== null && _b !== void 0 ? _b : 'lds',
|
|
38
|
+
fetchRemoteContexts: (issueOpts === null || issueOpts === void 0 ? void 0 : issueOpts.fetchRemoteContexts) !== false,
|
|
39
|
+
});
|
|
40
|
+
response.statusCode = 201;
|
|
41
|
+
return response.send({ verifiableCredential: vc });
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
45
|
+
}
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
exports.issueCredentialEndpoint = issueCredentialEndpoint;
|
|
49
|
+
function getCredentialsEndpoint(router, context, opts) {
|
|
50
|
+
var _a;
|
|
51
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
52
|
+
console.log(`Get credentials endpoint is disabled`);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials';
|
|
56
|
+
router.get(path, (0, ssi_sdk_express_support_1.checkAuth)(opts === null || opts === void 0 ? void 0 : opts.endpoint), (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
try {
|
|
58
|
+
const uniqueVCs = yield context.agent.dataStoreORMGetVerifiableCredentials();
|
|
59
|
+
response.statusCode = 202;
|
|
60
|
+
return response.send(uniqueVCs.map((uVC) => uVC.verifiableCredential));
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
exports.getCredentialsEndpoint = getCredentialsEndpoint;
|
|
68
|
+
function getCredentialEndpoint(router, context, opts) {
|
|
69
|
+
var _a;
|
|
70
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
71
|
+
console.log(`Get credential endpoint is disabled`);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials/:id';
|
|
75
|
+
router.get(path, (0, ssi_sdk_express_support_1.checkAuth)(opts === null || opts === void 0 ? void 0 : opts.endpoint), (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
try {
|
|
77
|
+
const id = request.params.id;
|
|
78
|
+
if (!id) {
|
|
79
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 400, 'no id provided');
|
|
80
|
+
}
|
|
81
|
+
let vcInfo = yield (0, ssi_sdk_core_1.getCredentialByIdOrHash)(context, id);
|
|
82
|
+
if (!vcInfo.vc) {
|
|
83
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 404, `id ${id} not found`);
|
|
84
|
+
}
|
|
85
|
+
response.statusCode = 200;
|
|
86
|
+
return response.send(vcInfo.vc);
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
90
|
+
}
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
exports.getCredentialEndpoint = getCredentialEndpoint;
|
|
94
|
+
function verifyCredentialEndpoint(router, context, opts) {
|
|
95
|
+
var _a;
|
|
96
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
97
|
+
console.log(`Verify credential endpoint is disabled`);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
router.post((_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials/verify', (0, ssi_sdk_express_support_1.checkAuth)(opts === null || opts === void 0 ? void 0 : opts.endpoint), (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
try {
|
|
102
|
+
console.log(request.body);
|
|
103
|
+
const credential = request.body.verifiableCredential;
|
|
104
|
+
// const options: IIssueOptionsPayload = request.body.options
|
|
105
|
+
if (!credential) {
|
|
106
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 400, 'No verifiable credential supplied');
|
|
107
|
+
}
|
|
108
|
+
const verifyResult = yield context.agent.verifyCredential({
|
|
109
|
+
credential,
|
|
110
|
+
fetchRemoteContexts: (opts === null || opts === void 0 ? void 0 : opts.fetchRemoteContexts) !== false,
|
|
111
|
+
});
|
|
112
|
+
response.statusCode = 200;
|
|
113
|
+
return response.send(verifyResult);
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
117
|
+
}
|
|
118
|
+
}));
|
|
119
|
+
}
|
|
120
|
+
exports.verifyCredentialEndpoint = verifyCredentialEndpoint;
|
|
121
|
+
function deleteCredentialEndpoint(router, context, opts) {
|
|
122
|
+
var _a;
|
|
123
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
124
|
+
console.log(`Delete credential endpoint is disabled`);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
router.delete((_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials/:id', (0, ssi_sdk_express_support_1.checkAuth)(opts === null || opts === void 0 ? void 0 : opts.endpoint), (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
try {
|
|
129
|
+
const id = request.params.id;
|
|
130
|
+
if (!id) {
|
|
131
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 400, 'no id provided');
|
|
132
|
+
}
|
|
133
|
+
let vcInfo = yield (0, ssi_sdk_core_1.getCredentialByIdOrHash)(context, id);
|
|
134
|
+
if (!vcInfo.vc || !vcInfo.hash) {
|
|
135
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 404, `id ${id} not found`);
|
|
136
|
+
}
|
|
137
|
+
const success = context.agent.dataStoreDeleteVerifiableCredential({ hash: vcInfo.hash });
|
|
138
|
+
if (!success) {
|
|
139
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 400, `Could not delete Verifiable Credential with id ${id}`);
|
|
140
|
+
}
|
|
141
|
+
response.statusCode = 200;
|
|
142
|
+
return response.send();
|
|
143
|
+
}
|
|
144
|
+
catch (e) {
|
|
145
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
146
|
+
}
|
|
147
|
+
}));
|
|
148
|
+
}
|
|
149
|
+
exports.deleteCredentialEndpoint = deleteCredentialEndpoint;
|
|
150
|
+
//# sourceMappingURL=api-functions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-functions.js","sourceRoot":"","sources":["../src/api-functions.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAAgE;AAChE,+EAAqG;AAIrG,+BAAyB;AAGzB,SAAgB,uBAAuB,CAAC,MAAc,EAAE,OAAyB,EAAE,IAAmC;;IACpH,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,MAAK,KAAK,EAAE;QAC3B,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAA;QACpD,OAAM;KACP;IACD,MAAM,IAAI,GAAG,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,mCAAI,oBAAoB,CAAA;IAE/C,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAA,mCAAS,EAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,QAAQ,CAAC,EAAE,CAAO,OAAgB,EAAE,QAAkB,EAAE,EAAE;;QAC1F,IAAI;YACF,MAAM,UAAU,GAAsB,OAAO,CAAC,IAAI,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AO,EAAE,EAAE,CAAC,CAAA;YACvD,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;gBAC9B,OAAO,IAAA,2CAAiB,EAAC,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,CAAA;aAC9D;YACD,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,mCAAmC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAA;YACxF,IAAI,CAAC,OAAO,EAAE;gBACZ,OAAO,IAAA,2CAAiB,EAAC,QAAQ,EAAE,GAAG,EAAE,kDAAkD,EAAE,EAAE,CAAC,CAAA;aAChG;YACD,QAAQ,CAAC,UAAU,GAAG,GAAG,CAAA;YACzB,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;SACvB;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,IAAA,2CAAiB,EAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC,OAAiB,EAAE,CAAC,CAAC,CAAA;SAChE;IACH,CAAC,CAAA,CAAC,CAAA;AACJ,CAAC;AAzBD,4DAyBC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,iBAAiB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
/**
|
|
18
18
|
* @public
|
|
19
19
|
*/
|
|
20
|
-
__exportStar(require("./
|
|
20
|
+
__exportStar(require("./vc-api-server"), exports);
|
|
21
21
|
__exportStar(require("./types"), exports);
|
|
22
|
+
__exportStar(require("./api-functions"), exports);
|
|
22
23
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,kDAA+B;AAC/B,0CAAuB;AACvB,kDAA+B"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,70 @@
|
|
|
1
|
+
import { GenericAuthArgs, ISingleEndpointOpts } from '@sphereon/ssi-sdk.express-support';
|
|
1
2
|
import { IAgentContext, ICredentialIssuer, ICredentialPlugin, ICredentialVerifier, IDataStore, IDataStoreORM, IDIDManager, IKeyManager, IResolver } from '@veramo/core';
|
|
2
|
-
import {
|
|
3
|
-
export type IRequiredPlugins = IDataStore & IDataStoreORM & IDIDManager & IKeyManager & ICredentialIssuer & ICredentialVerifier &
|
|
3
|
+
import { ProofFormat } from '@veramo/core/src/types/ICredentialIssuer';
|
|
4
|
+
export type IRequiredPlugins = IDataStore & IDataStoreORM & IDIDManager & IKeyManager & ICredentialIssuer & ICredentialVerifier & ICredentialPlugin & IResolver;
|
|
4
5
|
export type IRequiredContext = IAgentContext<IRequiredPlugins>;
|
|
6
|
+
interface IVCAPISecurityOpts {
|
|
7
|
+
}
|
|
8
|
+
export interface IVCAPIOpts {
|
|
9
|
+
endpointOpts?: IVCAPIEndpointOpts;
|
|
10
|
+
securityOpts?: IVCAPISecurityOpts;
|
|
11
|
+
issueCredentialOpts?: IVCAPIIssueOpts;
|
|
12
|
+
}
|
|
13
|
+
export interface IVCAPIEndpointOpts {
|
|
14
|
+
basePath?: string;
|
|
15
|
+
globalAuth?: GenericAuthArgs;
|
|
16
|
+
issueCredential?: IIssueCredentialEndpointOpts;
|
|
17
|
+
getCredentials?: ISingleEndpointOpts;
|
|
18
|
+
getCredential?: ISingleEndpointOpts;
|
|
19
|
+
deleteCredential?: ISingleEndpointOpts;
|
|
20
|
+
verifyCredential?: IVerifyCredentialEndpointOpts;
|
|
21
|
+
verifyPresentation?: ISingleEndpointOpts;
|
|
22
|
+
}
|
|
23
|
+
export type vcApiFeatures = 'vc-verify' | 'vc-issue' | 'vc-persist';
|
|
24
|
+
export interface IVCAPIIssueOpts {
|
|
25
|
+
enableFeatures?: vcApiFeatures[];
|
|
26
|
+
persistIssuedCredentials?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The desired format for the VerifiablePresentation to be created.
|
|
29
|
+
*/
|
|
30
|
+
proofFormat: ProofFormat;
|
|
31
|
+
/**
|
|
32
|
+
* Remove payload members during JWT-JSON transformation. Defaults to `true`.
|
|
33
|
+
* See https://www.w3.org/TR/vc-data-model/#jwt-encoding
|
|
34
|
+
*/
|
|
35
|
+
removeOriginalFields?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* [Optional] The ID of the key that should sign this credential.
|
|
38
|
+
* If this is not specified, the first matching key will be used.
|
|
39
|
+
*/
|
|
40
|
+
keyRef?: string;
|
|
41
|
+
/**
|
|
42
|
+
* When dealing with JSON-LD you also MUST provide the proper contexts.
|
|
43
|
+
* Set this to `true` ONLY if you want the `@context` URLs to be fetched in case they are not preloaded.
|
|
44
|
+
* The context definitions SHOULD rather be provided at startup instead of being fetched.
|
|
45
|
+
*
|
|
46
|
+
* Defaults to `false`
|
|
47
|
+
*/
|
|
48
|
+
fetchRemoteContexts?: boolean;
|
|
49
|
+
}
|
|
50
|
+
export interface IIssueCredentialEndpointOpts extends ISingleEndpointOpts {
|
|
51
|
+
issueCredentialOpts?: IVCAPIIssueOpts;
|
|
52
|
+
persistIssuedCredentials?: boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface IVerifyCredentialEndpointOpts extends ISingleEndpointOpts {
|
|
55
|
+
fetchRemoteContexts?: boolean;
|
|
56
|
+
}
|
|
57
|
+
export interface IIssueOptionsPayload {
|
|
58
|
+
created?: string;
|
|
59
|
+
challenge?: string;
|
|
60
|
+
domain?: string;
|
|
61
|
+
credentialStatus?: {
|
|
62
|
+
type: string;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export interface ChallengeOptsPayload {
|
|
66
|
+
challenge?: string;
|
|
67
|
+
domain?: string;
|
|
68
|
+
}
|
|
69
|
+
export {};
|
|
5
70
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,UAAU,EACV,aAAa,EACb,WAAW,EACX,WAAW,EACX,SAAS,EACV,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAA;AACxF,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,UAAU,EACV,aAAa,EACb,WAAW,EACX,WAAW,EACX,SAAS,EACV,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAA;AAEtE,MAAM,MAAM,gBAAgB,GAAG,UAAU,GACvC,aAAa,GACb,WAAW,GACX,WAAW,GACX,iBAAiB,GACjB,mBAAmB,GACnB,iBAAiB,GACjB,SAAS,CAAA;AACX,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAAC,gBAAgB,CAAC,CAAA;AAE9D,UAAU,kBAAkB;CAAG;AAE/B,MAAM,WAAW,UAAU;IACzB,YAAY,CAAC,E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AAA;CACF;AAED,MAAM,WAAW,oBAAoB;IACnC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ExpressBuildResult } from '@sphereon/ssi-sdk.express-support';
|
|
2
|
+
import { TAgent } from '@veramo/core';
|
|
3
|
+
import express, { Express } from 'express';
|
|
4
|
+
import { IRequiredPlugins, IVCAPIOpts } from './types';
|
|
5
|
+
export declare class VcApiServer {
|
|
6
|
+
get router(): express.Router;
|
|
7
|
+
private readonly _express;
|
|
8
|
+
private readonly _agent;
|
|
9
|
+
private readonly _opts?;
|
|
10
|
+
private readonly _router;
|
|
11
|
+
constructor(args: {
|
|
12
|
+
agent: TAgent<IRequiredPlugins>;
|
|
13
|
+
expressArgs: ExpressBuildResult;
|
|
14
|
+
opts?: IVCAPIOpts;
|
|
15
|
+
});
|
|
16
|
+
get agent(): TAgent<IRequiredPlugins>;
|
|
17
|
+
get opts(): IVCAPIOpts | undefined;
|
|
18
|
+
get express(): Express;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=vc-api-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vc-api-server.d.ts","sourceRoot":"","sources":["../src/vc-api-server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,OAAO,OAAO,EAAE,EAAE,OAAO,EAAU,MAAM,SAAS,CAAA;AAQlD,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEtD,qBAAa,WAAW;IACtB,IAAI,MAAM,IAAI,OAAO,CAAC,MAAM,CAE3B;IAED,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0B;IACjD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAY;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAQ;gBAEpB,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAAC,WAAW,EAAE,kBAAkB,CAAC;QAAC,IAAI,CAAC,EAAE,UAAU,CAAA;KAAE;IAyCzG,IAAI,KAAK,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAEpC;IAED,IAAI,IAAI,IAAI,UAAU,GAAG,SAAS,CAEjC;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;CACF"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.VcApiServer = void 0;
|
|
7
|
+
const ssi_sdk_core_1 = require("@sphereon/ssi-sdk.core");
|
|
8
|
+
const express_1 = __importDefault(require("express"));
|
|
9
|
+
const api_functions_1 = require("./api-functions");
|
|
10
|
+
class VcApiServer {
|
|
11
|
+
get router() {
|
|
12
|
+
return this._router;
|
|
13
|
+
}
|
|
14
|
+
constructor(args) {
|
|
15
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
16
|
+
const { agent, opts } = args;
|
|
17
|
+
this._agent = agent;
|
|
18
|
+
if ((_a = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _a === void 0 ? void 0 : _a.globalAuth) {
|
|
19
|
+
copyGlobalAuthToEndpoint(opts, 'issueCredential');
|
|
20
|
+
copyGlobalAuthToEndpoint(opts, 'getCredential');
|
|
21
|
+
copyGlobalAuthToEndpoint(opts, 'getCredentials');
|
|
22
|
+
copyGlobalAuthToEndpoint(opts, 'deleteCredential');
|
|
23
|
+
copyGlobalAuthToEndpoint(opts, 'verifyCredential');
|
|
24
|
+
}
|
|
25
|
+
this._opts = opts;
|
|
26
|
+
this._express = args.expressArgs.express;
|
|
27
|
+
this._router = express_1.default.Router();
|
|
28
|
+
const context = (0, ssi_sdk_core_1.agentContext)(agent);
|
|
29
|
+
const features = (_c = (_b = opts === null || opts === void 0 ? void 0 : opts.issueCredentialOpts) === null || _b === void 0 ? void 0 : _b.enableFeatures) !== null && _c !== void 0 ? _c : ['vc-issue', 'vc-persist', 'vc-verify'];
|
|
30
|
+
console.log(`VC API enabled, with features: ${JSON.stringify(features)}`);
|
|
31
|
+
// Credential endpoints
|
|
32
|
+
if (features.includes('vc-issue')) {
|
|
33
|
+
(0, api_functions_1.issueCredentialEndpoint)(this.router, context, Object.assign(Object.assign({}, (_d = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _d === void 0 ? void 0 : _d.issueCredential), { issueCredentialOpts: opts === null || opts === void 0 ? void 0 : opts.issueCredentialOpts }));
|
|
34
|
+
}
|
|
35
|
+
if (features.includes('vc-persist')) {
|
|
36
|
+
(0, api_functions_1.getCredentialEndpoint)(this.router, context, (_e = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _e === void 0 ? void 0 : _e.getCredential);
|
|
37
|
+
(0, api_functions_1.getCredentialsEndpoint)(this.router, context, (_f = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _f === void 0 ? void 0 : _f.getCredentials);
|
|
38
|
+
(0, api_functions_1.deleteCredentialEndpoint)(this.router, context, (_g = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _g === void 0 ? void 0 : _g.deleteCredential); // not in spec.
|
|
39
|
+
}
|
|
40
|
+
if (features.includes('vc-verify')) {
|
|
41
|
+
(0, api_functions_1.verifyCredentialEndpoint)(this.router, context, Object.assign(Object.assign({}, (_h = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _h === void 0 ? void 0 : _h.verifyCredential), { fetchRemoteContexts: (_j = opts === null || opts === void 0 ? void 0 : opts.issueCredentialOpts) === null || _j === void 0 ? void 0 : _j.fetchRemoteContexts }));
|
|
42
|
+
}
|
|
43
|
+
this._express.use((_l = (_k = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _k === void 0 ? void 0 : _k.basePath) !== null && _l !== void 0 ? _l : '', this.router);
|
|
44
|
+
}
|
|
45
|
+
get agent() {
|
|
46
|
+
return this._agent;
|
|
47
|
+
}
|
|
48
|
+
get opts() {
|
|
49
|
+
return this._opts;
|
|
50
|
+
}
|
|
51
|
+
get express() {
|
|
52
|
+
return this._express;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.VcApiServer = VcApiServer;
|
|
56
|
+
function copyGlobalAuthToEndpoint(opts, key) {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
if ((_a = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _a === void 0 ? void 0 : _a.globalAuth) {
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
opts.endpointOpts[key] = Object.assign(Object.assign({}, opts.endpointOpts[key]), {
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
endpoint: Object.assign(Object.assign({}, opts.endpointOpts.globalAuth), (_b = opts.endpointOpts[key]) === null || _b === void 0 ? void 0 : _b.endpoint) });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=vc-api-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vc-api-server.js","sourceRoot":"","sources":["../src/vc-api-server.ts"],"names":[],"mappings":";;;;;;AAAA,yDAAqD;AAIrD,sDAAkD;AAClD,mDAMwB;AAGxB,MAAa,WAAW;IACtB,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;IAOD,YAAY,IAA6F;;QACvG,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,CAAA;QAC5B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACnB,IAAI,MAAA,IAAI,aAAJ,IAAI,uBA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AY,CAAC,GAAG,CAAC;YACzB,aAAa;YACb,QAAQ,kCAAO,IAAI,CAAC,YAAY,CAAC,UAAU,GAAK,MAAA,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,0CAAE,QAAQ,IACjF,CAAA;KACF;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.w3c-vc-api",
|
|
3
|
-
"version": "0.13.1-next.
|
|
3
|
+
"version": "0.13.1-next.32+ba897de",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,17 +8,20 @@
|
|
|
8
8
|
"build": "tsc --build",
|
|
9
9
|
"build:clean": "tsc --build --clean && tsc --build",
|
|
10
10
|
"start:prod": "node build/index.js",
|
|
11
|
-
"start:dev": "ts-node __tests__/
|
|
11
|
+
"start:dev": "ts-node __tests__/agent.ts"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@sphereon/did-auth-siop": "0.3.2-unstable.
|
|
15
|
-
"@sphereon/ssi-sdk.
|
|
16
|
-
"@sphereon/ssi-sdk.
|
|
17
|
-
"@sphereon/ssi-
|
|
14
|
+
"@sphereon/did-auth-siop": "0.3.2-unstable.7",
|
|
15
|
+
"@sphereon/ssi-sdk.core": "0.13.1-next.32+ba897de",
|
|
16
|
+
"@sphereon/ssi-sdk.express-support": "0.13.1-next.32+ba897de",
|
|
17
|
+
"@sphereon/ssi-sdk.kv-store-temp": "0.13.1-next.32+ba897de",
|
|
18
|
+
"@sphereon/ssi-sdk.presentation-exchange": "0.13.1-next.32+ba897de",
|
|
19
|
+
"@sphereon/ssi-types": "0.13.1-next.32+ba897de",
|
|
18
20
|
"@types/uuid": "^9.0.1",
|
|
19
21
|
"@veramo/core": "4.2.0",
|
|
20
22
|
"@veramo/credential-w3c": "4.2.0",
|
|
21
23
|
"body-parser": "^1.19.0",
|
|
24
|
+
"casbin": "^5.26.1",
|
|
22
25
|
"cookie-parser": "^1.4.5",
|
|
23
26
|
"cors": "^2.8.5",
|
|
24
27
|
"cross-fetch": "^3.1.5",
|
|
@@ -28,14 +31,11 @@
|
|
|
28
31
|
"uuid": "^8.3.2"
|
|
29
32
|
},
|
|
30
33
|
"devDependencies": {
|
|
31
|
-
"@decentralized-identity/ion-sdk": "^0.6.0",
|
|
32
34
|
"@sphereon/did-uni-client": "^0.6.0",
|
|
33
|
-
"@sphereon/
|
|
34
|
-
"@sphereon/
|
|
35
|
-
"@sphereon/ssi-sdk
|
|
36
|
-
"@sphereon/ssi-sdk
|
|
37
|
-
"@sphereon/ssi-sdk.data-store": "0.13.1-next.3+cf98046",
|
|
38
|
-
"@sphereon/ssi-sdk.vc-handler-ld-local": "0.13.1-next.3+cf98046",
|
|
35
|
+
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.12.2-next.12",
|
|
36
|
+
"@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.12.2-next.12",
|
|
37
|
+
"@sphereon/ssi-sdk.data-store": "0.13.1-next.32+ba897de",
|
|
38
|
+
"@sphereon/ssi-sdk.vc-handler-ld-local": "0.13.1-next.32+ba897de",
|
|
39
39
|
"@types/body-parser": "^1.19.2",
|
|
40
40
|
"@types/cookie-parser": "^1.4.3",
|
|
41
41
|
"@types/cors": "^2.8.13",
|
|
@@ -43,7 +43,10 @@
|
|
|
43
43
|
"@types/dotenv-flow": "^3.2.0",
|
|
44
44
|
"@types/express": "^4.17.13",
|
|
45
45
|
"@types/express-http-proxy": "^1.6.3",
|
|
46
|
+
"@types/morgan": "^1.9.4",
|
|
46
47
|
"@types/node": "^18.15.0",
|
|
48
|
+
"@types/passport": "^1.0.12",
|
|
49
|
+
"@types/passport-azure-ad": "^4.3.1",
|
|
47
50
|
"@veramo/data-store": "4.2.0",
|
|
48
51
|
"@veramo/did-manager": "4.2.0",
|
|
49
52
|
"@veramo/did-provider-ethr": "4.2.0",
|
|
@@ -55,7 +58,10 @@
|
|
|
55
58
|
"@veramo/kms-local": "4.2.0",
|
|
56
59
|
"@veramo/utils": "4.2.0",
|
|
57
60
|
"did-resolver": "^4.1.0",
|
|
61
|
+
"morgan": "^1.10.0",
|
|
58
62
|
"nock": "^13.2.1",
|
|
63
|
+
"passport": "^0.6.0",
|
|
64
|
+
"passport-azure-ad": "^4.3.5",
|
|
59
65
|
"ts-node": "^10.9.1",
|
|
60
66
|
"typeorm": "^0.3.12"
|
|
61
67
|
},
|
|
@@ -71,23 +77,14 @@
|
|
|
71
77
|
"publishConfig": {
|
|
72
78
|
"access": "public"
|
|
73
79
|
},
|
|
74
|
-
"resolutions": {
|
|
75
|
-
"did-jwt": "6.11.6"
|
|
76
|
-
},
|
|
77
80
|
"repository": "git@github.com:Sphereon-Opensource/SSI-SDK.git",
|
|
78
81
|
"author": "Sphereon <dev@sphereon.com>",
|
|
79
82
|
"license": "Apache-2.0",
|
|
80
83
|
"keywords": [
|
|
81
84
|
"Sphereon",
|
|
82
85
|
"SSI",
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"SIOP",
|
|
86
|
-
"SIOPv2",
|
|
87
|
-
"OIDC4VP",
|
|
88
|
-
"Presentation Exchange",
|
|
89
|
-
"OpenID Connect",
|
|
90
|
-
"Authenticator"
|
|
86
|
+
"W3C",
|
|
87
|
+
"VC API"
|
|
91
88
|
],
|
|
92
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "ba897ded1b092dd7d21634cfb0de396a59d2e0d5"
|
|
93
90
|
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { getCredentialByIdOrHash } from '@sphereon/ssi-sdk.core'
|
|
2
|
+
import { checkAuth, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-sdk.express-support'
|
|
3
|
+
import { CredentialPayload } from '@veramo/core'
|
|
4
|
+
import { W3CVerifiableCredential } from '@veramo/core/src/types/vc-data-model'
|
|
5
|
+
import { Request, Response, Router } from 'express'
|
|
6
|
+
import { v4 } from 'uuid'
|
|
7
|
+
import { IIssueCredentialEndpointOpts, IRequiredContext, IVCAPIIssueOpts, IVerifyCredentialEndpointOpts } from './types'
|
|
8
|
+
|
|
9
|
+
export function issueCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IIssueCredentialEndpointOpts) {
|
|
10
|
+
if (opts?.enabled === false) {
|
|
11
|
+
console.log(`Issue credential endpoint is disabled`)
|
|
12
|
+
return
|
|
13
|
+
}
|
|
14
|
+
const path = opts?.path ?? '/credentials/issue'
|
|
15
|
+
|
|
16
|
+
router.post(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
17
|
+
try {
|
|
18
|
+
const credential: CredentialPayload = request.body.credential
|
|
19
|
+
if (!credential) {
|
|
20
|
+
return sendErrorResponse(response, 400, 'No credential supplied')
|
|
21
|
+
}
|
|
22
|
+
if (!credential.id) {
|
|
23
|
+
credential.id = `urn:uuid:${v4()}`
|
|
24
|
+
}
|
|
25
|
+
const issueOpts: IVCAPIIssueOpts | undefined = opts?.issueCredentialOpts
|
|
26
|
+
const vc = await context.agent.createVerifiableCredential({
|
|
27
|
+
credential,
|
|
28
|
+
save: opts?.persistIssuedCredentials !== false,
|
|
29
|
+
proofFormat: issueOpts?.proofFormat ?? 'lds',
|
|
30
|
+
fetchRemoteContexts: issueOpts?.fetchRemoteContexts !== false,
|
|
31
|
+
})
|
|
32
|
+
response.statusCode = 201
|
|
33
|
+
return response.send({ verifiableCredential: vc })
|
|
34
|
+
} catch (e) {
|
|
35
|
+
return sendErrorResponse(response, 500, e.message as string, e)
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function getCredentialsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {
|
|
41
|
+
if (opts?.enabled === false) {
|
|
42
|
+
console.log(`Get credentials endpoint is disabled`)
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
const path = opts?.path ?? '/credentials'
|
|
46
|
+
router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
47
|
+
try {
|
|
48
|
+
const uniqueVCs = await context.agent.dataStoreORMGetVerifiableCredentials()
|
|
49
|
+
response.statusCode = 202
|
|
50
|
+
return response.send(uniqueVCs.map((uVC) => uVC.verifiableCredential))
|
|
51
|
+
} catch (e) {
|
|
52
|
+
return sendErrorResponse(response, 500, e.message as string, e)
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function getCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {
|
|
58
|
+
if (opts?.enabled === false) {
|
|
59
|
+
console.log(`Get credential endpoint is disabled`)
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
const path = opts?.path ?? '/credentials/:id'
|
|
63
|
+
router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
64
|
+
try {
|
|
65
|
+
const id = request.params.id
|
|
66
|
+
if (!id) {
|
|
67
|
+
return sendErrorResponse(response, 400, 'no id provided')
|
|
68
|
+
}
|
|
69
|
+
let vcInfo = await getCredentialByIdOrHash(context, id)
|
|
70
|
+
if (!vcInfo.vc) {
|
|
71
|
+
return sendErrorResponse(response, 404, `id ${id} not found`)
|
|
72
|
+
}
|
|
73
|
+
response.statusCode = 200
|
|
74
|
+
return response.send(vcInfo.vc)
|
|
75
|
+
} catch (e) {
|
|
76
|
+
return sendErrorResponse(response, 500, e.message as string, e)
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function verifyCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IVerifyCredentialEndpointOpts) {
|
|
82
|
+
if (opts?.enabled === false) {
|
|
83
|
+
console.log(`Verify credential endpoint is disabled`)
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
router.post(opts?.path ?? '/credentials/verify', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
87
|
+
try {
|
|
88
|
+
console.log(request.body)
|
|
89
|
+
const credential: W3CVerifiableCredential = request.body.verifiableCredential
|
|
90
|
+
// const options: IIssueOptionsPayload = request.body.options
|
|
91
|
+
if (!credential) {
|
|
92
|
+
return sendErrorResponse(response, 400, 'No verifiable credential supplied')
|
|
93
|
+
}
|
|
94
|
+
const verifyResult = await context.agent.verifyCredential({
|
|
95
|
+
credential,
|
|
96
|
+
fetchRemoteContexts: opts?.fetchRemoteContexts !== false,
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
response.statusCode = 200
|
|
100
|
+
return response.send(verifyResult)
|
|
101
|
+
} catch (e) {
|
|
102
|
+
return sendErrorResponse(response, 500, e.message as string, e)
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function deleteCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {
|
|
108
|
+
if (opts?.enabled === false) {
|
|
109
|
+
console.log(`Delete credential endpoint is disabled`)
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
router.delete(opts?.path ?? '/credentials/:id', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
113
|
+
try {
|
|
114
|
+
const id = request.params.id
|
|
115
|
+
if (!id) {
|
|
116
|
+
return sendErrorResponse(response, 400, 'no id provided')
|
|
117
|
+
}
|
|
118
|
+
let vcInfo = await getCredentialByIdOrHash(context, id)
|
|
119
|
+
if (!vcInfo.vc || !vcInfo.hash) {
|
|
120
|
+
return sendErrorResponse(response, 404, `id ${id} not found`)
|
|
121
|
+
}
|
|
122
|
+
const success = context.agent.dataStoreDeleteVerifiableCredential({ hash: vcInfo.hash })
|
|
123
|
+
if (!success) {
|
|
124
|
+
return sendErrorResponse(response, 400, `Could not delete Verifiable Credential with id ${id}`)
|
|
125
|
+
}
|
|
126
|
+
response.statusCode = 200
|
|
127
|
+
return response.send()
|
|
128
|
+
} catch (e) {
|
|
129
|
+
return sendErrorResponse(response, 500, e.message as string, e)
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
}
|