@sphereon/ssi-sdk.w3c-vc-api 0.13.1-next.18 → 0.13.1-next.23
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 +7 -25
- package/dist/api-functions.d.ts.map +1 -1
- package/dist/api-functions.js +53 -62
- package/dist/api-functions.js.map +1 -1
- package/dist/types.d.ts +23 -14
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -1
- package/dist/vc-api-server.d.ts +5 -3
- package/dist/vc-api-server.d.ts.map +1 -1
- package/dist/vc-api-server.js +41 -69
- package/dist/vc-api-server.js.map +1 -1
- package/package.json +21 -25
- package/src/api-functions.ts +36 -86
- package/src/types.ts +26 -16
- package/src/vc-api-server.ts +55 -47
- 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/request-agent-router.ts +0 -47
package/dist/api-functions.d.ts
CHANGED
|
@@ -1,27 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ISingleEndpointOpts } from '@sphereon/ssi-sdk.express-support';
|
|
2
2
|
import { Router } from 'express';
|
|
3
|
-
import { IRequiredContext,
|
|
4
|
-
export declare function issueCredentialEndpoint(router: Router, context: IRequiredContext, opts?:
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export declare function getCredentialsEndpoint(router: Router, context: IRequiredContext, opts?: {
|
|
10
|
-
getCredentialsPath?: string;
|
|
11
|
-
}): void;
|
|
12
|
-
export declare function getCredentialEndpoint(router: Router, context: IRequiredContext, opts?: {
|
|
13
|
-
getCredentialPath?: string;
|
|
14
|
-
}): void;
|
|
15
|
-
export declare function verifyCredentialEndpoint(router: Router, context: IRequiredContext, opts?: {
|
|
16
|
-
verifyCredentialPath?: string;
|
|
17
|
-
fetchRemoteContexts?: boolean;
|
|
18
|
-
}): void;
|
|
19
|
-
export declare function deleteCredentialEndpoint(router: Router, context: IRequiredContext, opts?: {
|
|
20
|
-
deleteCredentialsPath?: string;
|
|
21
|
-
}): void;
|
|
22
|
-
export declare function getCredentialByIdOrHash(context: IRequiredContext, idOrHash: string): Promise<{
|
|
23
|
-
id: string;
|
|
24
|
-
hash?: string;
|
|
25
|
-
vc?: VerifiableCredential;
|
|
26
|
-
}>;
|
|
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;
|
|
27
9
|
//# sourceMappingURL=api-functions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-functions.d.ts","sourceRoot":"","sources":["../src/api-functions.ts"],"names":[],"mappings":"
|
|
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;AAGnD,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"}
|
package/dist/api-functions.js
CHANGED
|
@@ -8,17 +8,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
15
|
+
exports.deleteCredentialEndpoint = exports.verifyCredentialEndpoint = exports.getCredentialEndpoint = exports.getCredentialsEndpoint = exports.issueCredentialEndpoint = void 0;
|
|
16
|
+
const ssi_sdk_core_1 = require("@sphereon/ssi-sdk.core");
|
|
17
|
+
const ssi_sdk_express_support_1 = require("@sphereon/ssi-sdk.express-support");
|
|
18
|
+
const passport_1 = __importDefault(require("passport"));
|
|
13
19
|
const uuid_1 = require("uuid");
|
|
14
20
|
function issueCredentialEndpoint(router, context, opts) {
|
|
15
21
|
var _a;
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
23
|
+
console.log(`Issue credential endpoint is disabled`);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials/issue';
|
|
27
|
+
router.post(path, passport_1.default.authenticate('oauth-bearer'), (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* () {
|
|
28
|
+
var _b;
|
|
18
29
|
try {
|
|
19
30
|
const credential = request.body.credential;
|
|
20
31
|
if (!credential) {
|
|
21
|
-
return sendErrorResponse(response, 400, 'No credential supplied');
|
|
32
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 400, 'No credential supplied');
|
|
22
33
|
}
|
|
23
34
|
if (!credential.id) {
|
|
24
35
|
credential.id = `urn:uuid:${(0, uuid_1.v4)()}`;
|
|
@@ -26,63 +37,77 @@ function issueCredentialEndpoint(router, context, opts) {
|
|
|
26
37
|
const issueOpts = opts === null || opts === void 0 ? void 0 : opts.issueCredentialOpts;
|
|
27
38
|
const vc = yield context.agent.createVerifiableCredential({
|
|
28
39
|
credential,
|
|
29
|
-
save: (
|
|
30
|
-
proofFormat: (
|
|
31
|
-
fetchRemoteContexts: (issueOpts === null || issueOpts === void 0 ? void 0 : issueOpts.fetchRemoteContexts)
|
|
40
|
+
save: (opts === null || opts === void 0 ? void 0 : opts.persistIssuedCredentials) !== false,
|
|
41
|
+
proofFormat: (_b = issueOpts === null || issueOpts === void 0 ? void 0 : issueOpts.proofFormat) !== null && _b !== void 0 ? _b : 'lds',
|
|
42
|
+
fetchRemoteContexts: (issueOpts === null || issueOpts === void 0 ? void 0 : issueOpts.fetchRemoteContexts) !== false,
|
|
32
43
|
});
|
|
33
44
|
response.statusCode = 201;
|
|
34
45
|
return response.send({ verifiableCredential: vc });
|
|
35
46
|
}
|
|
36
47
|
catch (e) {
|
|
37
|
-
return sendErrorResponse(response, 500, e.message, e);
|
|
48
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
38
49
|
}
|
|
39
50
|
}));
|
|
40
51
|
}
|
|
41
52
|
exports.issueCredentialEndpoint = issueCredentialEndpoint;
|
|
42
53
|
function getCredentialsEndpoint(router, context, opts) {
|
|
43
54
|
var _a;
|
|
44
|
-
|
|
55
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
56
|
+
console.log(`Get credentials endpoint is disabled`);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials';
|
|
60
|
+
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* () {
|
|
45
61
|
try {
|
|
46
62
|
const uniqueVCs = yield context.agent.dataStoreORMGetVerifiableCredentials();
|
|
47
63
|
response.statusCode = 202;
|
|
48
64
|
return response.send(uniqueVCs.map((uVC) => uVC.verifiableCredential));
|
|
49
65
|
}
|
|
50
66
|
catch (e) {
|
|
51
|
-
return sendErrorResponse(response, 500, e.message, e);
|
|
67
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
52
68
|
}
|
|
53
69
|
}));
|
|
54
70
|
}
|
|
55
71
|
exports.getCredentialsEndpoint = getCredentialsEndpoint;
|
|
56
72
|
function getCredentialEndpoint(router, context, opts) {
|
|
57
73
|
var _a;
|
|
58
|
-
|
|
74
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
75
|
+
console.log(`Get credential endpoint is disabled`);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials/:id';
|
|
79
|
+
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* () {
|
|
59
80
|
try {
|
|
60
81
|
const id = request.params.id;
|
|
61
82
|
if (!id) {
|
|
62
|
-
return sendErrorResponse(response, 400, 'no id provided');
|
|
83
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 400, 'no id provided');
|
|
63
84
|
}
|
|
64
|
-
let vcInfo = yield getCredentialByIdOrHash(context, id);
|
|
85
|
+
let vcInfo = yield (0, ssi_sdk_core_1.getCredentialByIdOrHash)(context, id);
|
|
65
86
|
if (!vcInfo.vc) {
|
|
66
|
-
return sendErrorResponse(response, 404, `id ${id} not found`);
|
|
87
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 404, `id ${id} not found`);
|
|
67
88
|
}
|
|
68
89
|
response.statusCode = 200;
|
|
69
90
|
return response.send(vcInfo.vc);
|
|
70
91
|
}
|
|
71
92
|
catch (e) {
|
|
72
|
-
return sendErrorResponse(response, 500, e.message, e);
|
|
93
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
73
94
|
}
|
|
74
95
|
}));
|
|
75
96
|
}
|
|
76
97
|
exports.getCredentialEndpoint = getCredentialEndpoint;
|
|
77
98
|
function verifyCredentialEndpoint(router, context, opts) {
|
|
78
99
|
var _a;
|
|
79
|
-
|
|
100
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
101
|
+
console.log(`Verify credential endpoint is disabled`);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
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* () {
|
|
80
105
|
try {
|
|
81
106
|
console.log(request.body);
|
|
82
107
|
const credential = request.body.verifiableCredential;
|
|
83
108
|
// const options: IIssueOptionsPayload = request.body.options
|
|
84
109
|
if (!credential) {
|
|
85
|
-
return sendErrorResponse(response, 400, 'No verifiable credential supplied');
|
|
110
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 400, 'No verifiable credential supplied');
|
|
86
111
|
}
|
|
87
112
|
const verifyResult = yield context.agent.verifyCredential({
|
|
88
113
|
credential,
|
|
@@ -92,72 +117,38 @@ function verifyCredentialEndpoint(router, context, opts) {
|
|
|
92
117
|
return response.send(verifyResult);
|
|
93
118
|
}
|
|
94
119
|
catch (e) {
|
|
95
|
-
return sendErrorResponse(response, 500, e.message, e);
|
|
120
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
96
121
|
}
|
|
97
122
|
}));
|
|
98
123
|
}
|
|
99
124
|
exports.verifyCredentialEndpoint = verifyCredentialEndpoint;
|
|
100
125
|
function deleteCredentialEndpoint(router, context, opts) {
|
|
101
126
|
var _a;
|
|
102
|
-
|
|
127
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
128
|
+
console.log(`Delete credential endpoint is disabled`);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
router.delete((_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials/:id', (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
103
132
|
try {
|
|
104
133
|
const id = request.params.id;
|
|
105
134
|
if (!id) {
|
|
106
|
-
return sendErrorResponse(response, 400, 'no id provided');
|
|
135
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 400, 'no id provided');
|
|
107
136
|
}
|
|
108
|
-
let vcInfo = yield getCredentialByIdOrHash(context, id);
|
|
137
|
+
let vcInfo = yield (0, ssi_sdk_core_1.getCredentialByIdOrHash)(context, id);
|
|
109
138
|
if (!vcInfo.vc || !vcInfo.hash) {
|
|
110
|
-
return sendErrorResponse(response, 404, `id ${id} not found`);
|
|
139
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 404, `id ${id} not found`);
|
|
111
140
|
}
|
|
112
141
|
const success = context.agent.dataStoreDeleteVerifiableCredential({ hash: vcInfo.hash });
|
|
113
142
|
if (!success) {
|
|
114
|
-
return sendErrorResponse(response, 400, `Could not delete Verifiable Credential with id ${id}`);
|
|
143
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 400, `Could not delete Verifiable Credential with id ${id}`);
|
|
115
144
|
}
|
|
116
145
|
response.statusCode = 200;
|
|
117
146
|
return response.send();
|
|
118
147
|
}
|
|
119
148
|
catch (e) {
|
|
120
|
-
return sendErrorResponse(response, 500, e.message, e);
|
|
149
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
121
150
|
}
|
|
122
151
|
}));
|
|
123
152
|
}
|
|
124
153
|
exports.deleteCredentialEndpoint = deleteCredentialEndpoint;
|
|
125
|
-
function sendErrorResponse(response, statusCode, message, error) {
|
|
126
|
-
console.log(message);
|
|
127
|
-
if (error) {
|
|
128
|
-
console.log(error);
|
|
129
|
-
}
|
|
130
|
-
response.statusCode = statusCode;
|
|
131
|
-
return response.status(statusCode).send(message);
|
|
132
|
-
}
|
|
133
|
-
function getCredentialByIdOrHash(context, idOrHash) {
|
|
134
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
let vc;
|
|
136
|
-
let hash;
|
|
137
|
-
const uniqueVCs = yield context.agent.dataStoreORMGetVerifiableCredentials({
|
|
138
|
-
where: [
|
|
139
|
-
{
|
|
140
|
-
column: 'id',
|
|
141
|
-
value: [idOrHash],
|
|
142
|
-
op: 'Equal',
|
|
143
|
-
},
|
|
144
|
-
],
|
|
145
|
-
});
|
|
146
|
-
if (uniqueVCs.length === 0) {
|
|
147
|
-
hash = idOrHash;
|
|
148
|
-
vc = yield context.agent.dataStoreGetVerifiableCredential({ hash });
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
const uniqueVC = uniqueVCs[0];
|
|
152
|
-
hash = uniqueVC.hash;
|
|
153
|
-
vc = uniqueVC.verifiableCredential;
|
|
154
|
-
}
|
|
155
|
-
return {
|
|
156
|
-
vc,
|
|
157
|
-
id: idOrHash,
|
|
158
|
-
hash,
|
|
159
|
-
};
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
exports.getCredentialByIdOrHash = getCredentialByIdOrHash;
|
|
163
154
|
//# sourceMappingURL=api-functions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-functions.js","sourceRoot":"","sources":["../src/api-functions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api-functions.js","sourceRoot":"","sources":["../src/api-functions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,yDAAgE;AAChE,+EAAqG;AAIrG,wDAA+B;AAC/B,+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,kBAAQ,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,IAAA,mCAAS,EAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,QAAQ,CAAC,EAAE,CAAO,OAAgB,EAAE,QAAkB,EAAE,EAAE;;QACjI,IAAI;YACF,MAAM,UAAU,GAAsB,OAAO,CAAC,IAAI,CAAC,UAAU,CAAA;YAC7D,IAAI,CAAC,UAAU,EAAE;gBACf,OAAO,IAAA,2CAAiB,EAAC,QAAQ,EAAE,GAAG,EAAE,wBAAwB,CAAC,CAAA;aAClE;YACD,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE;gBAClB,UA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AE,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/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
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
3
|
import { IPresentationExchange } from '@sphereon/ssi-sdk.presentation-exchange';
|
|
3
4
|
import { ProofFormat } from '@veramo/core/src/types/ICredentialIssuer';
|
|
@@ -6,26 +7,27 @@ export type IRequiredContext = IAgentContext<IRequiredPlugins>;
|
|
|
6
7
|
interface IVCAPISecurityOpts {
|
|
7
8
|
}
|
|
8
9
|
export interface IVCAPIOpts {
|
|
9
|
-
|
|
10
|
+
endpointOpts?: IVCAPIEndpointOpts;
|
|
10
11
|
securityOpts?: IVCAPISecurityOpts;
|
|
11
12
|
issueCredentialOpts?: IVCAPIIssueOpts;
|
|
12
|
-
serverOpts?: IServerOpts;
|
|
13
13
|
}
|
|
14
|
-
export interface
|
|
15
|
-
port?: number;
|
|
16
|
-
cookieSigningKey?: string;
|
|
17
|
-
hostname?: string;
|
|
18
|
-
}
|
|
19
|
-
export interface IVCAPIPathOpts {
|
|
14
|
+
export interface IVCAPIEndpointOpts {
|
|
20
15
|
basePath?: string;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
globalAuth?: GenericAuthArgs;
|
|
17
|
+
issueCredential?: IIssueCredentialEndpointOpts;
|
|
18
|
+
getCredentials?: ISingleEndpointOpts;
|
|
19
|
+
getCredential?: ISingleEndpointOpts;
|
|
20
|
+
deleteCredential?: ISingleEndpointOpts;
|
|
21
|
+
verifyCredential?: IVerifyCredentialEndpointOpts;
|
|
22
|
+
verifyPresentation?: ISingleEndpointOpts;
|
|
23
|
+
}
|
|
24
|
+
export declare enum IVCIApiFeatures {
|
|
25
|
+
VC_VERIFY = "vc-verify",
|
|
26
|
+
VC_ISSUE = "vc-issue",
|
|
27
|
+
VC_PERSISTENCE = "vc-persist"
|
|
27
28
|
}
|
|
28
29
|
export interface IVCAPIIssueOpts {
|
|
30
|
+
enableFeatures?: IVCIApiFeatures[];
|
|
29
31
|
persistIssuedCredentials?: boolean;
|
|
30
32
|
/**
|
|
31
33
|
* The desired format for the VerifiablePresentation to be created.
|
|
@@ -50,6 +52,13 @@ export interface IVCAPIIssueOpts {
|
|
|
50
52
|
*/
|
|
51
53
|
fetchRemoteContexts?: boolean;
|
|
52
54
|
}
|
|
55
|
+
export interface IIssueCredentialEndpointOpts extends ISingleEndpointOpts {
|
|
56
|
+
issueCredentialOpts?: IVCAPIIssueOpts;
|
|
57
|
+
persistIssuedCredentials?: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface IVerifyCredentialEndpointOpts extends ISingleEndpointOpts {
|
|
60
|
+
fetchRemoteContexts?: boolean;
|
|
61
|
+
}
|
|
53
62
|
export interface IIssueOptionsPayload {
|
|
54
63
|
created?: string;
|
|
55
64
|
challenge?: string;
|
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,qBAAqB,EAAE,MAAM,yCAAyC,CAAA;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAA;AAEtE,MAAM,MAAM,gBAAgB,GAAG,UAAU,GACvC,aAAa,GACb,WAAW,GACX,WAAW,GACX,iBAAiB,GACjB,mBAAmB,GACnB,qBAAqB,GACrB,iBAAiB,GACjB,SAAS,CAAA;AACX,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAAC,gBAAgB,CAAC,CAAA;AAE9D,UAAU,kBAAkB;CAAG;AAE/B,MAAM,WAAW,UAAU;IACzB,
|
|
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,qBAAqB,EAAE,MAAM,yCAAyC,CAAA;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAA;AAEtE,MAAM,MAAM,gBAAgB,GAAG,UAAU,GACvC,aAAa,GACb,WAAW,GACX,WAAW,GACX,iBAAiB,GACjB,mBAAmB,GACnB,qBAAqB,GACrB,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,EAAE,kBAAkB,CAAA;IAC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;AAED,MAAM,WAAW,oBAAoB;IACnC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB"}
|
package/dist/types.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IVCIApiFeatures = void 0;
|
|
4
|
+
var IVCIApiFeatures;
|
|
5
|
+
(function (IVCIApiFeatures) {
|
|
6
|
+
IVCIApiFeatures["VC_VERIFY"] = "vc-verify";
|
|
7
|
+
IVCIApiFeatures["VC_ISSUE"] = "vc-issue";
|
|
8
|
+
IVCIApiFeatures["VC_PERSISTENCE"] = "vc-persist";
|
|
9
|
+
})(IVCIApiFeatures = exports.IVCIApiFeatures || (exports.IVCIApiFeatures = {}));
|
|
3
10
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AA6CA,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,0CAAuB,CAAA;IACvB,wCAAqB,CAAA;IACrB,gDAA6B,CAAA;AAC/B,CAAC,EAJW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAI1B"}
|
package/dist/vc-api-server.d.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
+
import { ExpressBuildResult } from '@sphereon/ssi-sdk.express-support';
|
|
1
2
|
import { TAgent } from '@veramo/core';
|
|
2
|
-
import { Express } from 'express';
|
|
3
|
+
import express, { Express } from 'express';
|
|
3
4
|
import { IRequiredPlugins, IVCAPIOpts } from './types';
|
|
4
5
|
export declare class VcApiServer {
|
|
6
|
+
get router(): express.Router;
|
|
5
7
|
private readonly _express;
|
|
6
8
|
private readonly _agent;
|
|
7
9
|
private readonly _opts?;
|
|
10
|
+
private readonly _router;
|
|
8
11
|
constructor(args: {
|
|
9
12
|
agent: TAgent<IRequiredPlugins>;
|
|
10
|
-
|
|
13
|
+
expressArgs: ExpressBuildResult;
|
|
11
14
|
opts?: IVCAPIOpts;
|
|
12
15
|
});
|
|
13
16
|
get agent(): TAgent<IRequiredPlugins>;
|
|
14
17
|
get opts(): IVCAPIOpts | undefined;
|
|
15
18
|
get express(): Express;
|
|
16
|
-
private setupExpress;
|
|
17
19
|
}
|
|
18
20
|
//# sourceMappingURL=vc-api-server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vc-api-server.d.ts","sourceRoot":"","sources":["../src/vc-api-server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;
|
|
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,EAAmB,MAAM,SAAS,CAAA;AAEvE,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;IA6CzG,IAAI,KAAK,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAEpC;IAED,IAAI,IAAI,IAAI,UAAU,GAAG,SAAS,CAEjC;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;CACF"}
|
package/dist/vc-api-server.js
CHANGED
|
@@ -1,62 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
28
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
6
|
exports.VcApiServer = void 0;
|
|
30
7
|
const ssi_sdk_core_1 = require("@sphereon/ssi-sdk.core");
|
|
31
|
-
const body_parser_1 = __importDefault(require("body-parser"));
|
|
32
|
-
const cookie_parser_1 = __importDefault(require("cookie-parser"));
|
|
33
|
-
const dotenv = __importStar(require("dotenv-flow"));
|
|
34
8
|
const express_1 = __importDefault(require("express"));
|
|
35
9
|
const api_functions_1 = require("./api-functions");
|
|
10
|
+
const types_1 = require("./types");
|
|
36
11
|
class VcApiServer {
|
|
12
|
+
get router() {
|
|
13
|
+
return this._router;
|
|
14
|
+
}
|
|
37
15
|
constructor(args) {
|
|
38
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
16
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
39
17
|
const { agent, opts } = args;
|
|
40
18
|
this._agent = agent;
|
|
19
|
+
if ((_a = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _a === void 0 ? void 0 : _a.globalAuth) {
|
|
20
|
+
copyGlobalAuthToEndpoint(opts, 'issueCredential');
|
|
21
|
+
copyGlobalAuthToEndpoint(opts, 'getCredential');
|
|
22
|
+
copyGlobalAuthToEndpoint(opts, 'getCredentials');
|
|
23
|
+
copyGlobalAuthToEndpoint(opts, 'deleteCredential');
|
|
24
|
+
copyGlobalAuthToEndpoint(opts, 'verifyCredential');
|
|
25
|
+
}
|
|
41
26
|
this._opts = opts;
|
|
42
|
-
|
|
43
|
-
this.
|
|
44
|
-
this.setupExpress(existingExpress);
|
|
45
|
-
const router = express_1.default.Router();
|
|
27
|
+
this._express = args.expressArgs.express;
|
|
28
|
+
this._router = express_1.default.Router();
|
|
46
29
|
const context = (0, ssi_sdk_core_1.agentContext)(agent);
|
|
30
|
+
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 : [
|
|
31
|
+
types_1.IVCIApiFeatures.VC_ISSUE,
|
|
32
|
+
types_1.IVCIApiFeatures.VC_PERSISTENCE,
|
|
33
|
+
types_1.IVCIApiFeatures.VC_VERIFY,
|
|
34
|
+
];
|
|
35
|
+
console.log(`VC API enabled, with features: ${JSON.stringify(features)}`);
|
|
47
36
|
// Credential endpoints
|
|
48
|
-
(
|
|
49
|
-
issueCredentialOpts: opts === null || opts === void 0 ? void 0 : opts.issueCredentialOpts
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
fetchRemoteContexts: (
|
|
58
|
-
}
|
|
59
|
-
this._express.use((
|
|
37
|
+
if (features.includes(types_1.IVCIApiFeatures.VC_ISSUE)) {
|
|
38
|
+
(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 }));
|
|
39
|
+
}
|
|
40
|
+
if (features.includes(types_1.IVCIApiFeatures.VC_PERSISTENCE)) {
|
|
41
|
+
(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);
|
|
42
|
+
(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);
|
|
43
|
+
(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.
|
|
44
|
+
}
|
|
45
|
+
if (features.includes(types_1.IVCIApiFeatures.VC_VERIFY)) {
|
|
46
|
+
(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 }));
|
|
47
|
+
}
|
|
48
|
+
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);
|
|
60
49
|
}
|
|
61
50
|
get agent() {
|
|
62
51
|
return this._agent;
|
|
@@ -67,32 +56,15 @@ class VcApiServer {
|
|
|
67
56
|
get express() {
|
|
68
57
|
return this._express;
|
|
69
58
|
}
|
|
70
|
-
setupExpress(existingExpress) {
|
|
71
|
-
var _a, _b, _c, _d, _e, _f;
|
|
72
|
-
dotenv.config();
|
|
73
|
-
if (!existingExpress) {
|
|
74
|
-
const port = ((_b = (_a = this.opts) === null || _a === void 0 ? void 0 : _a.serverOpts) === null || _b === void 0 ? void 0 : _b.port) || process.env.PORT || 5000;
|
|
75
|
-
const secret = ((_d = (_c = this.opts) === null || _c === void 0 ? void 0 : _c.serverOpts) === null || _d === void 0 ? void 0 : _d.cookieSigningKey) || process.env.COOKIE_SIGNING_KEY;
|
|
76
|
-
const hostname = ((_f = (_e = this.opts) === null || _e === void 0 ? void 0 : _e.serverOpts) === null || _f === void 0 ? void 0 : _f.hostname) || '0.0.0.0';
|
|
77
|
-
this._express.use((req, res, next) => {
|
|
78
|
-
res.header('Access-Control-Allow-Origin', '*');
|
|
79
|
-
// Request methods you wish to allow
|
|
80
|
-
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
|
|
81
|
-
// Request headers you wish to allow
|
|
82
|
-
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
|
|
83
|
-
// Set to true if you need the website to include cookies in the requests sent
|
|
84
|
-
// to the API (e.g. in case you use sessions)
|
|
85
|
-
res.setHeader('Access-Control-Allow-Credentials', 'true');
|
|
86
|
-
next();
|
|
87
|
-
});
|
|
88
|
-
// this.express.use(cors({ credentials: true }));
|
|
89
|
-
// this.express.use('/proxy', proxy('www.gssoogle.com'));
|
|
90
|
-
this._express.use(body_parser_1.default.urlencoded({ extended: true }));
|
|
91
|
-
this._express.use(body_parser_1.default.json());
|
|
92
|
-
this._express.use((0, cookie_parser_1.default)(secret));
|
|
93
|
-
this._express.listen(port, hostname, () => console.log(`Listening on ${hostname}, port ${port}`));
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
59
|
}
|
|
97
60
|
exports.VcApiServer = VcApiServer;
|
|
61
|
+
function copyGlobalAuthToEndpoint(opts, key) {
|
|
62
|
+
var _a, _b;
|
|
63
|
+
if ((_a = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _a === void 0 ? void 0 : _a.globalAuth) {
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
opts.endpointOpts[key] = Object.assign(Object.assign({}, opts.endpointOpts[key]), {
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
endpoint: Object.assign(Object.assign({}, opts.endpointOpts.globalAuth), (_b = opts.endpointOpts[key]) === null || _b === void 0 ? void 0 : _b.endpoint) });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
98
70
|
//# sourceMappingURL=vc-api-server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vc-api-server.js","sourceRoot":"","sources":["../src/vc-api-server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vc-api-server.js","sourceRoot":"","sources":["../src/vc-api-server.ts"],"names":[],"mappings":";;;;;;AAAA,yDAAqD;AAIrD,sDAAkD;AAClD,mDAMwB;AACxB,mCAAuE;AAEvE,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,MAA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I,CAAE,YAAY,0CAAE,UAAU,EAAE;QAClC,aAAa;QACb,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,mCAEjB,IAAI,CAAC,YAAY,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.23+6c616f9",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,15 +11,17 @@
|
|
|
11
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.core": "0.13.1-next.
|
|
16
|
-
"@sphereon/ssi-sdk.
|
|
17
|
-
"@sphereon/ssi-sdk.
|
|
18
|
-
"@sphereon/ssi-
|
|
14
|
+
"@sphereon/did-auth-siop": "0.3.2-unstable.7",
|
|
15
|
+
"@sphereon/ssi-sdk.core": "0.13.1-next.23+6c616f9",
|
|
16
|
+
"@sphereon/ssi-sdk.express-support": "0.13.1-next.23+6c616f9",
|
|
17
|
+
"@sphereon/ssi-sdk.kv-store-temp": "0.13.1-next.23+6c616f9",
|
|
18
|
+
"@sphereon/ssi-sdk.presentation-exchange": "0.13.1-next.23+6c616f9",
|
|
19
|
+
"@sphereon/ssi-types": "0.13.1-next.23+6c616f9",
|
|
19
20
|
"@types/uuid": "^9.0.1",
|
|
20
21
|
"@veramo/core": "4.2.0",
|
|
21
22
|
"@veramo/credential-w3c": "4.2.0",
|
|
22
23
|
"body-parser": "^1.19.0",
|
|
24
|
+
"casbin": "^5.26.1",
|
|
23
25
|
"cookie-parser": "^1.4.5",
|
|
24
26
|
"cors": "^2.8.5",
|
|
25
27
|
"cross-fetch": "^3.1.5",
|
|
@@ -29,14 +31,11 @@
|
|
|
29
31
|
"uuid": "^8.3.2"
|
|
30
32
|
},
|
|
31
33
|
"devDependencies": {
|
|
32
|
-
"@decentralized-identity/ion-sdk": "^0.6.0",
|
|
33
34
|
"@sphereon/did-uni-client": "^0.6.0",
|
|
34
|
-
"@sphereon/
|
|
35
|
-
"@sphereon/
|
|
36
|
-
"@sphereon/ssi-sdk
|
|
37
|
-
"@sphereon/ssi-sdk
|
|
38
|
-
"@sphereon/ssi-sdk.data-store": "0.13.1-next.18+61bdfaf",
|
|
39
|
-
"@sphereon/ssi-sdk.vc-handler-ld-local": "0.13.1-next.18+61bdfaf",
|
|
35
|
+
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.12.2-next.5",
|
|
36
|
+
"@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.12.2-next.5",
|
|
37
|
+
"@sphereon/ssi-sdk.data-store": "0.13.1-next.23+6c616f9",
|
|
38
|
+
"@sphereon/ssi-sdk.vc-handler-ld-local": "0.13.1-next.23+6c616f9",
|
|
40
39
|
"@types/body-parser": "^1.19.2",
|
|
41
40
|
"@types/cookie-parser": "^1.4.3",
|
|
42
41
|
"@types/cors": "^2.8.13",
|
|
@@ -44,7 +43,10 @@
|
|
|
44
43
|
"@types/dotenv-flow": "^3.2.0",
|
|
45
44
|
"@types/express": "^4.17.13",
|
|
46
45
|
"@types/express-http-proxy": "^1.6.3",
|
|
46
|
+
"@types/morgan": "^1.9.4",
|
|
47
47
|
"@types/node": "^18.15.0",
|
|
48
|
+
"@types/passport": "^1.0.12",
|
|
49
|
+
"@types/passport-azure-ad": "^4.3.1",
|
|
48
50
|
"@veramo/data-store": "4.2.0",
|
|
49
51
|
"@veramo/did-manager": "4.2.0",
|
|
50
52
|
"@veramo/did-provider-ethr": "4.2.0",
|
|
@@ -56,7 +58,10 @@
|
|
|
56
58
|
"@veramo/kms-local": "4.2.0",
|
|
57
59
|
"@veramo/utils": "4.2.0",
|
|
58
60
|
"did-resolver": "^4.1.0",
|
|
61
|
+
"morgan": "^1.10.0",
|
|
59
62
|
"nock": "^13.2.1",
|
|
63
|
+
"passport": "^0.6.0",
|
|
64
|
+
"passport-azure-ad": "^4.3.5",
|
|
60
65
|
"ts-node": "^10.9.1",
|
|
61
66
|
"typeorm": "^0.3.12"
|
|
62
67
|
},
|
|
@@ -72,23 +77,14 @@
|
|
|
72
77
|
"publishConfig": {
|
|
73
78
|
"access": "public"
|
|
74
79
|
},
|
|
75
|
-
"resolutions": {
|
|
76
|
-
"did-jwt": "6.11.6"
|
|
77
|
-
},
|
|
78
80
|
"repository": "git@github.com:Sphereon-Opensource/SSI-SDK.git",
|
|
79
81
|
"author": "Sphereon <dev@sphereon.com>",
|
|
80
82
|
"license": "Apache-2.0",
|
|
81
83
|
"keywords": [
|
|
82
84
|
"Sphereon",
|
|
83
85
|
"SSI",
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"SIOP",
|
|
87
|
-
"SIOPv2",
|
|
88
|
-
"OIDC4VP",
|
|
89
|
-
"Presentation Exchange",
|
|
90
|
-
"OpenID Connect",
|
|
91
|
-
"Authenticator"
|
|
86
|
+
"W3C",
|
|
87
|
+
"VC API"
|
|
92
88
|
],
|
|
93
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "6c616f988be6a5d891c771bb59faa50d3160aa75"
|
|
94
90
|
}
|
package/src/api-functions.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import {
|
|
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'
|
|
2
4
|
import { W3CVerifiableCredential } from '@veramo/core/src/types/vc-data-model'
|
|
3
5
|
import { Request, Response, Router } from 'express'
|
|
6
|
+
import passport from 'passport'
|
|
4
7
|
import { v4 } from 'uuid'
|
|
5
|
-
import { IRequiredContext, IVCAPIIssueOpts } from './types'
|
|
8
|
+
import { IIssueCredentialEndpointOpts, IRequiredContext, IVCAPIIssueOpts, IVerifyCredentialEndpointOpts } from './types'
|
|
6
9
|
|
|
7
|
-
export function issueCredentialEndpoint(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
issueCredentialOpts?: IVCAPIIssueOpts
|
|
12
|
-
issueCredentialPath?: string
|
|
13
|
-
persistIssuedCredentials?: boolean
|
|
10
|
+
export function issueCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IIssueCredentialEndpointOpts) {
|
|
11
|
+
if (opts?.enabled === false) {
|
|
12
|
+
console.log(`Issue credential endpoint is disabled`)
|
|
13
|
+
return
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const path = opts?.path ?? '/credentials/issue'
|
|
16
|
+
|
|
17
|
+
router.post(path, passport.authenticate('oauth-bearer'), checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
17
18
|
try {
|
|
18
19
|
const credential: CredentialPayload = request.body.credential
|
|
19
20
|
if (!credential) {
|
|
@@ -25,9 +26,9 @@ export function issueCredentialEndpoint(
|
|
|
25
26
|
const issueOpts: IVCAPIIssueOpts | undefined = opts?.issueCredentialOpts
|
|
26
27
|
const vc = await context.agent.createVerifiableCredential({
|
|
27
28
|
credential,
|
|
28
|
-
save: opts?.persistIssuedCredentials
|
|
29
|
+
save: opts?.persistIssuedCredentials !== false,
|
|
29
30
|
proofFormat: issueOpts?.proofFormat ?? 'lds',
|
|
30
|
-
fetchRemoteContexts: issueOpts?.fetchRemoteContexts
|
|
31
|
+
fetchRemoteContexts: issueOpts?.fetchRemoteContexts !== false,
|
|
31
32
|
})
|
|
32
33
|
response.statusCode = 201
|
|
33
34
|
return response.send({ verifiableCredential: vc })
|
|
@@ -37,14 +38,13 @@ export function issueCredentialEndpoint(
|
|
|
37
38
|
})
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
export function getCredentialsEndpoint(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
getCredentialsPath?: string
|
|
41
|
+
export function getCredentialsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {
|
|
42
|
+
if (opts?.enabled === false) {
|
|
43
|
+
console.log(`Get credentials endpoint is disabled`)
|
|
44
|
+
return
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
router.get(opts?.
|
|
46
|
+
const path = opts?.path ?? '/credentials'
|
|
47
|
+
router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
48
48
|
try {
|
|
49
49
|
const uniqueVCs = await context.agent.dataStoreORMGetVerifiableCredentials()
|
|
50
50
|
response.statusCode = 202
|
|
@@ -55,14 +55,13 @@ export function getCredentialsEndpoint(
|
|
|
55
55
|
})
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
export function getCredentialEndpoint(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
getCredentialPath?: string
|
|
58
|
+
export function getCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {
|
|
59
|
+
if (opts?.enabled === false) {
|
|
60
|
+
console.log(`Get credential endpoint is disabled`)
|
|
61
|
+
return
|
|
63
62
|
}
|
|
64
|
-
|
|
65
|
-
router.get(opts?.
|
|
63
|
+
const path = opts?.path ?? '/credentials/:id'
|
|
64
|
+
router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
66
65
|
try {
|
|
67
66
|
const id = request.params.id
|
|
68
67
|
if (!id) {
|
|
@@ -80,15 +79,12 @@ export function getCredentialEndpoint(
|
|
|
80
79
|
})
|
|
81
80
|
}
|
|
82
81
|
|
|
83
|
-
export function verifyCredentialEndpoint(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
verifyCredentialPath?: string
|
|
88
|
-
fetchRemoteContexts?: boolean
|
|
82
|
+
export function verifyCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IVerifyCredentialEndpointOpts) {
|
|
83
|
+
if (opts?.enabled === false) {
|
|
84
|
+
console.log(`Verify credential endpoint is disabled`)
|
|
85
|
+
return
|
|
89
86
|
}
|
|
90
|
-
) {
|
|
91
|
-
router.post(opts?.verifyCredentialPath ?? '/credentials/verify', async (request: Request, response: Response) => {
|
|
87
|
+
router.post(opts?.path ?? '/credentials/verify', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
92
88
|
try {
|
|
93
89
|
console.log(request.body)
|
|
94
90
|
const credential: W3CVerifiableCredential = request.body.verifiableCredential
|
|
@@ -109,14 +105,12 @@ export function verifyCredentialEndpoint(
|
|
|
109
105
|
})
|
|
110
106
|
}
|
|
111
107
|
|
|
112
|
-
export function deleteCredentialEndpoint(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
deleteCredentialsPath?: string
|
|
108
|
+
export function deleteCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {
|
|
109
|
+
if (opts?.enabled === false) {
|
|
110
|
+
console.log(`Delete credential endpoint is disabled`)
|
|
111
|
+
return
|
|
117
112
|
}
|
|
118
|
-
) {
|
|
119
|
-
router.delete(opts?.deleteCredentialsPath ?? '/credentials/:id', async (request: Request, response: Response) => {
|
|
113
|
+
router.delete(opts?.path ?? '/credentials/:id', async (request: Request, response: Response) => {
|
|
120
114
|
try {
|
|
121
115
|
const id = request.params.id
|
|
122
116
|
if (!id) {
|
|
@@ -137,47 +131,3 @@ export function deleteCredentialEndpoint(
|
|
|
137
131
|
}
|
|
138
132
|
})
|
|
139
133
|
}
|
|
140
|
-
|
|
141
|
-
function sendErrorResponse(response: Response, statusCode: number, message: string, error?: Error) {
|
|
142
|
-
console.log(message)
|
|
143
|
-
if (error) {
|
|
144
|
-
console.log(error)
|
|
145
|
-
}
|
|
146
|
-
response.statusCode = statusCode
|
|
147
|
-
return response.status(statusCode).send(message)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export async function getCredentialByIdOrHash(
|
|
151
|
-
context: IRequiredContext,
|
|
152
|
-
idOrHash: string
|
|
153
|
-
): Promise<{
|
|
154
|
-
id: string
|
|
155
|
-
hash?: string
|
|
156
|
-
vc?: VerifiableCredential
|
|
157
|
-
}> {
|
|
158
|
-
let vc: VerifiableCredential
|
|
159
|
-
let hash: string
|
|
160
|
-
const uniqueVCs = await context.agent.dataStoreORMGetVerifiableCredentials({
|
|
161
|
-
where: [
|
|
162
|
-
{
|
|
163
|
-
column: 'id',
|
|
164
|
-
value: [idOrHash],
|
|
165
|
-
op: 'Equal',
|
|
166
|
-
},
|
|
167
|
-
],
|
|
168
|
-
})
|
|
169
|
-
if (uniqueVCs.length === 0) {
|
|
170
|
-
hash = idOrHash
|
|
171
|
-
vc = await context.agent.dataStoreGetVerifiableCredential({ hash })
|
|
172
|
-
} else {
|
|
173
|
-
const uniqueVC = uniqueVCs[0]
|
|
174
|
-
hash = uniqueVC.hash
|
|
175
|
-
vc = uniqueVC.verifiableCredential
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return {
|
|
179
|
-
vc,
|
|
180
|
-
id: idOrHash,
|
|
181
|
-
hash,
|
|
182
|
-
}
|
|
183
|
-
}
|
package/src/types.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { GenericAuthArgs, ISingleEndpointOpts } from '@sphereon/ssi-sdk.express-support'
|
|
1
2
|
import {
|
|
2
3
|
IAgentContext,
|
|
3
4
|
ICredentialIssuer,
|
|
@@ -26,31 +27,31 @@ export type IRequiredContext = IAgentContext<IRequiredPlugins>
|
|
|
26
27
|
interface IVCAPISecurityOpts {}
|
|
27
28
|
|
|
28
29
|
export interface IVCAPIOpts {
|
|
29
|
-
|
|
30
|
+
endpointOpts?: IVCAPIEndpointOpts
|
|
30
31
|
securityOpts?: IVCAPISecurityOpts
|
|
31
32
|
issueCredentialOpts?: IVCAPIIssueOpts
|
|
32
|
-
|
|
33
|
-
serverOpts?: IServerOpts
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
export interface
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
export interface IVCAPIEndpointOpts {
|
|
36
|
+
basePath?: string
|
|
37
|
+
globalAuth?: GenericAuthArgs
|
|
38
|
+
issueCredential?: IIssueCredentialEndpointOpts
|
|
39
|
+
getCredentials?: ISingleEndpointOpts
|
|
40
|
+
getCredential?: ISingleEndpointOpts
|
|
41
|
+
deleteCredential?: ISingleEndpointOpts
|
|
42
|
+
verifyCredential?: IVerifyCredentialEndpointOpts
|
|
43
|
+
verifyPresentation?: ISingleEndpointOpts
|
|
40
44
|
}
|
|
41
45
|
|
|
42
|
-
export
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
getCredentialPath?: string
|
|
47
|
-
deleteCredentialPath?: string
|
|
48
|
-
verifyCredentialPath?: string
|
|
49
|
-
verifyPresentationPath?: string
|
|
46
|
+
export enum IVCIApiFeatures {
|
|
47
|
+
VC_VERIFY = 'vc-verify',
|
|
48
|
+
VC_ISSUE = 'vc-issue',
|
|
49
|
+
VC_PERSISTENCE = 'vc-persist',
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
export interface IVCAPIIssueOpts {
|
|
53
|
-
|
|
53
|
+
enableFeatures?: IVCIApiFeatures[] // Feature to enable. If not defined or empty, all features will be enabled
|
|
54
|
+
persistIssuedCredentials?: boolean // Whether the issuer persists issued credentials or not. Defaults to VC_PERSISTENCE feature flag being present or not
|
|
54
55
|
|
|
55
56
|
/**
|
|
56
57
|
* The desired format for the VerifiablePresentation to be created.
|
|
@@ -79,6 +80,15 @@ export interface IVCAPIIssueOpts {
|
|
|
79
80
|
fetchRemoteContexts?: boolean
|
|
80
81
|
}
|
|
81
82
|
|
|
83
|
+
export interface IIssueCredentialEndpointOpts extends ISingleEndpointOpts {
|
|
84
|
+
issueCredentialOpts?: IVCAPIIssueOpts
|
|
85
|
+
persistIssuedCredentials?: boolean
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface IVerifyCredentialEndpointOpts extends ISingleEndpointOpts {
|
|
89
|
+
fetchRemoteContexts?: boolean
|
|
90
|
+
}
|
|
91
|
+
|
|
82
92
|
export interface IIssueOptionsPayload {
|
|
83
93
|
created?: string
|
|
84
94
|
challenge?: string
|
package/src/vc-api-server.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { agentContext } from '@sphereon/ssi-sdk.core'
|
|
2
|
+
import { ExpressBuildResult } from '@sphereon/ssi-sdk.express-support'
|
|
2
3
|
import { TAgent } from '@veramo/core'
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import * as dotenv from 'dotenv-flow'
|
|
6
|
-
import express, { Express } from 'express'
|
|
4
|
+
|
|
5
|
+
import express, { Express, Router } from 'express'
|
|
7
6
|
import {
|
|
8
7
|
deleteCredentialEndpoint,
|
|
9
8
|
getCredentialEndpoint,
|
|
@@ -11,36 +10,61 @@ import {
|
|
|
11
10
|
issueCredentialEndpoint,
|
|
12
11
|
verifyCredentialEndpoint,
|
|
13
12
|
} from './api-functions'
|
|
14
|
-
import { IRequiredPlugins, IVCAPIOpts } from './types'
|
|
13
|
+
import { IRequiredPlugins, IVCAPIOpts, IVCIApiFeatures } from './types'
|
|
15
14
|
|
|
16
15
|
export class VcApiServer {
|
|
16
|
+
get router(): express.Router {
|
|
17
|
+
return this._router
|
|
18
|
+
}
|
|
19
|
+
|
|
17
20
|
private readonly _express: Express
|
|
18
21
|
private readonly _agent: TAgent<IRequiredPlugins>
|
|
19
22
|
private readonly _opts?: IVCAPIOpts
|
|
23
|
+
private readonly _router: Router
|
|
20
24
|
|
|
21
|
-
constructor(args: { agent: TAgent<IRequiredPlugins>;
|
|
25
|
+
constructor(args: { agent: TAgent<IRequiredPlugins>; expressArgs: ExpressBuildResult; opts?: IVCAPIOpts }) {
|
|
22
26
|
const { agent, opts } = args
|
|
23
27
|
this._agent = agent
|
|
28
|
+
if (opts?.endpointOpts?.globalAuth) {
|
|
29
|
+
copyGlobalAuthToEndpoint(opts, 'issueCredential')
|
|
30
|
+
copyGlobalAuthToEndpoint(opts, 'getCredential')
|
|
31
|
+
copyGlobalAuthToEndpoint(opts, 'getCredentials')
|
|
32
|
+
copyGlobalAuthToEndpoint(opts, 'deleteCredential')
|
|
33
|
+
copyGlobalAuthToEndpoint(opts, 'verifyCredential')
|
|
34
|
+
}
|
|
35
|
+
|
|
24
36
|
this._opts = opts
|
|
25
|
-
|
|
26
|
-
this.
|
|
27
|
-
|
|
28
|
-
const router = express.Router()
|
|
37
|
+
this._express = args.expressArgs.express
|
|
38
|
+
this._router = express.Router()
|
|
39
|
+
|
|
29
40
|
const context = agentContext(agent)
|
|
30
41
|
|
|
42
|
+
const features = opts?.issueCredentialOpts?.enableFeatures ?? [
|
|
43
|
+
IVCIApiFeatures.VC_ISSUE,
|
|
44
|
+
IVCIApiFeatures.VC_PERSISTENCE,
|
|
45
|
+
IVCIApiFeatures.VC_VERIFY,
|
|
46
|
+
]
|
|
47
|
+
console.log(`VC API enabled, with features: ${JSON.stringify(features)}`)
|
|
48
|
+
|
|
31
49
|
// Credential endpoints
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
50
|
+
if (features.includes(IVCIApiFeatures.VC_ISSUE)) {
|
|
51
|
+
issueCredentialEndpoint(this.router, context, {
|
|
52
|
+
...opts?.endpointOpts?.issueCredential,
|
|
53
|
+
issueCredentialOpts: opts?.issueCredentialOpts,
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
if (features.includes(IVCIApiFeatures.VC_PERSISTENCE)) {
|
|
57
|
+
getCredentialEndpoint(this.router, context, opts?.endpointOpts?.getCredential)
|
|
58
|
+
getCredentialsEndpoint(this.router, context, opts?.endpointOpts?.getCredentials)
|
|
59
|
+
deleteCredentialEndpoint(this.router, context, opts?.endpointOpts?.deleteCredential) // not in spec.
|
|
60
|
+
}
|
|
61
|
+
if (features.includes(IVCIApiFeatures.VC_VERIFY)) {
|
|
62
|
+
verifyCredentialEndpoint(this.router, context, {
|
|
63
|
+
...opts?.endpointOpts?.verifyCredential,
|
|
64
|
+
fetchRemoteContexts: opts?.issueCredentialOpts?.fetchRemoteContexts,
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
this._express.use(opts?.endpointOpts?.basePath ?? '', this.router)
|
|
44
68
|
}
|
|
45
69
|
|
|
46
70
|
get agent(): TAgent<IRequiredPlugins> {
|
|
@@ -54,32 +78,16 @@ export class VcApiServer {
|
|
|
54
78
|
get express(): Express {
|
|
55
79
|
return this._express
|
|
56
80
|
}
|
|
81
|
+
}
|
|
57
82
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// Request methods you wish to allow
|
|
67
|
-
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE')
|
|
68
|
-
|
|
69
|
-
// Request headers you wish to allow
|
|
70
|
-
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type')
|
|
71
|
-
|
|
72
|
-
// Set to true if you need the website to include cookies in the requests sent
|
|
73
|
-
// to the API (e.g. in case you use sessions)
|
|
74
|
-
res.setHeader('Access-Control-Allow-Credentials', 'true')
|
|
75
|
-
next()
|
|
76
|
-
})
|
|
77
|
-
// this.express.use(cors({ credentials: true }));
|
|
78
|
-
// this.express.use('/proxy', proxy('www.gssoogle.com'));
|
|
79
|
-
this._express.use(bodyParser.urlencoded({ extended: true }))
|
|
80
|
-
this._express.use(bodyParser.json())
|
|
81
|
-
this._express.use(cookieParser(secret))
|
|
82
|
-
this._express.listen(port as number, hostname, () => console.log(`Listening on ${hostname}, port ${port}`))
|
|
83
|
+
function copyGlobalAuthToEndpoint(opts: IVCAPIOpts, key: string) {
|
|
84
|
+
if (opts?.endpointOpts?.globalAuth) {
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
opts.endpointOpts[key] = {
|
|
87
|
+
// @ts-ignore
|
|
88
|
+
...opts.endpointOpts[key],
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
endpoint: { ...opts.endpointOpts.globalAuth, ...opts.endpointOpts[key]?.endpoint },
|
|
83
91
|
}
|
|
84
92
|
}
|
|
85
93
|
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { IAgent } from '@veramo/core';
|
|
2
|
-
import { Request, Router } from 'express';
|
|
3
|
-
export interface RequestWithAgent extends Request {
|
|
4
|
-
agent?: IAgent;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
export interface RequestWithAgentRouterOptions {
|
|
10
|
-
/**
|
|
11
|
-
* Optional. Pre-configured agent
|
|
12
|
-
*/
|
|
13
|
-
agent?: IAgent;
|
|
14
|
-
/**
|
|
15
|
-
* Optional. Function that returns a Promise that resolves to a configured agent for specific request
|
|
16
|
-
*/
|
|
17
|
-
getAgentForRequest?: (req: Request) => Promise<IAgent>;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Creates an expressjs router that adds a Veramo agent to the request object.
|
|
21
|
-
*
|
|
22
|
-
* This is needed by all other routers provided by this package to be able to perform their functions.
|
|
23
|
-
*
|
|
24
|
-
* @param options - Initialization option
|
|
25
|
-
* @returns Expressjs router
|
|
26
|
-
*
|
|
27
|
-
* @public
|
|
28
|
-
*/
|
|
29
|
-
export declare const RequestWithAgentRouter: (options: RequestWithAgentRouterOptions) => Router;
|
|
30
|
-
//# sourceMappingURL=request-agent-router.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request-agent-router.d.ts","sourceRoot":"","sources":["../src/request-agent-router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAEzC,MAAM,WAAW,gBAAiB,SAAQ,OAAO;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,kBAAkB,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CACvD;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,YAAa,6BAA6B,KAAG,MAc/E,CAAA"}
|
|
@@ -1,41 +0,0 @@
|
|
|
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.RequestWithAgentRouter = void 0;
|
|
13
|
-
const express_1 = require("express");
|
|
14
|
-
/**
|
|
15
|
-
* Creates an expressjs router that adds a Veramo agent to the request object.
|
|
16
|
-
*
|
|
17
|
-
* This is needed by all other routers provided by this package to be able to perform their functions.
|
|
18
|
-
*
|
|
19
|
-
* @param options - Initialization option
|
|
20
|
-
* @returns Expressjs router
|
|
21
|
-
*
|
|
22
|
-
* @public
|
|
23
|
-
*/
|
|
24
|
-
const RequestWithAgentRouter = (options) => {
|
|
25
|
-
const router = (0, express_1.Router)();
|
|
26
|
-
router.use((req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
-
if (options.agent) {
|
|
28
|
-
req.agent = options.agent;
|
|
29
|
-
}
|
|
30
|
-
else if (options.getAgentForRequest) {
|
|
31
|
-
req.agent = yield options.getAgentForRequest(req);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
throw Error('[RequestWithAgentRouter] agent or getAgentForRequest is required');
|
|
35
|
-
}
|
|
36
|
-
next();
|
|
37
|
-
}));
|
|
38
|
-
return router;
|
|
39
|
-
};
|
|
40
|
-
exports.RequestWithAgentRouter = RequestWithAgentRouter;
|
|
41
|
-
//# sourceMappingURL=request-agent-router.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request-agent-router.js","sourceRoot":"","sources":["../src/request-agent-router.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qCAAyC;AAqBzC;;;;;;;;;GASG;AACI,MAAM,sBAAsB,GAAG,CAAC,OAAsC,EAAU,EAAE;IACvF,MAAM,MAAM,GAAG,IAAA,gBAAM,GAAE,CAAA;IACvB,MAAM,CAAC,GAAG,CAAC,CAAO,GAAqB,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACpD,IAAI,OAAO,CAAC,KAAK,EAAE;YACjB,GAAG,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;SAC1B;aAAM,IAAI,OAAO,CAAC,kBAAkB,EAAE;YACrC,GAAG,CAAC,KAAK,GAAG,MAAM,OAAO,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAA;SAClD;aAAM;YACL,MAAM,KAAK,CAAC,kEAAkE,CAAC,CAAA;SAChF;QACD,IAAI,EAAE,CAAA;IACR,CAAC,CAAA,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAdY,QAAA,sBAAsB,0BAclC"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { IAgent } from '@veramo/core'
|
|
2
|
-
import { Request, Router } from 'express'
|
|
3
|
-
|
|
4
|
-
export interface RequestWithAgent extends Request {
|
|
5
|
-
agent?: IAgent
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @public
|
|
10
|
-
*/
|
|
11
|
-
export interface RequestWithAgentRouterOptions {
|
|
12
|
-
/**
|
|
13
|
-
* Optional. Pre-configured agent
|
|
14
|
-
*/
|
|
15
|
-
agent?: IAgent
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Optional. Function that returns a Promise that resolves to a configured agent for specific request
|
|
19
|
-
*/
|
|
20
|
-
getAgentForRequest?: (req: Request) => Promise<IAgent>
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Creates an expressjs router that adds a Veramo agent to the request object.
|
|
25
|
-
*
|
|
26
|
-
* This is needed by all other routers provided by this package to be able to perform their functions.
|
|
27
|
-
*
|
|
28
|
-
* @param options - Initialization option
|
|
29
|
-
* @returns Expressjs router
|
|
30
|
-
*
|
|
31
|
-
* @public
|
|
32
|
-
*/
|
|
33
|
-
export const RequestWithAgentRouter = (options: RequestWithAgentRouterOptions): Router => {
|
|
34
|
-
const router = Router()
|
|
35
|
-
router.use(async (req: RequestWithAgent, res, next) => {
|
|
36
|
-
if (options.agent) {
|
|
37
|
-
req.agent = options.agent
|
|
38
|
-
} else if (options.getAgentForRequest) {
|
|
39
|
-
req.agent = await options.getAgentForRequest(req)
|
|
40
|
-
} else {
|
|
41
|
-
throw Error('[RequestWithAgentRouter] agent or getAgentForRequest is required')
|
|
42
|
-
}
|
|
43
|
-
next()
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
return router
|
|
47
|
-
}
|