@sphereon/ssi-sdk.w3c-vc-api 0.33.1-next.3 → 0.33.1-next.68
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/README.md +3 -3
- package/dist/index.cjs +369 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +95 -0
- package/dist/index.d.ts +95 -7
- package/dist/index.js +336 -21
- package/dist/index.js.map +1 -1
- package/package.json +49 -30
- package/src/api-functions.ts +72 -17
- package/src/types.ts +11 -17
- package/src/vc-api-server.ts +4 -4
- package/dist/api-functions.d.ts +0 -9
- package/dist/api-functions.d.ts.map +0 -1
- package/dist/api-functions.js +0 -207
- package/dist/api-functions.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/types.d.ts +0 -67
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -3
- package/dist/types.js.map +0 -1
- package/dist/vc-api-server.d.ts +0 -20
- package/dist/vc-api-server.d.ts.map +0 -1
- package/dist/vc-api-server.js +0 -65
- package/dist/vc-api-server.js.map +0 -1
package/README.md
CHANGED
|
@@ -175,7 +175,7 @@ const agent = createAgent<
|
|
|
175
175
|
}),
|
|
176
176
|
new PresentationExchange(),
|
|
177
177
|
new CredentialPlugin(),
|
|
178
|
-
new
|
|
178
|
+
new CredentialProviderVcdm2Jose({
|
|
179
179
|
contextMaps: [LdDefaultContexts],
|
|
180
180
|
suites: [
|
|
181
181
|
new SphereonEd25519Signature2018(),
|
|
@@ -185,8 +185,8 @@ const agent = createAgent<
|
|
|
185
185
|
new SphereonEcdsaSecp256k1RecoverySignature2020(),
|
|
186
186
|
],
|
|
187
187
|
bindingOverrides: new Map([
|
|
188
|
-
['createVerifiableCredentialLD', MethodNames.
|
|
189
|
-
['createVerifiablePresentationLD', MethodNames.
|
|
188
|
+
['createVerifiableCredentialLD', MethodNames.createVerifiableCredential],
|
|
189
|
+
['createVerifiablePresentationLD', MethodNames.createVerifiablePresentation],
|
|
190
190
|
]),
|
|
191
191
|
keyStore: privateKeyStore,
|
|
192
192
|
}),
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/index.ts
|
|
32
|
+
var index_exports = {};
|
|
33
|
+
__export(index_exports, {
|
|
34
|
+
VcApiServer: () => VcApiServer,
|
|
35
|
+
deleteCredentialEndpoint: () => deleteCredentialEndpoint,
|
|
36
|
+
getCredentialEndpoint: () => getCredentialEndpoint,
|
|
37
|
+
getCredentialsEndpoint: () => getCredentialsEndpoint,
|
|
38
|
+
issueCredentialEndpoint: () => issueCredentialEndpoint,
|
|
39
|
+
verifyCredentialEndpoint: () => verifyCredentialEndpoint
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(index_exports);
|
|
42
|
+
|
|
43
|
+
// src/vc-api-server.ts
|
|
44
|
+
var import_ssi_sdk5 = require("@sphereon/ssi-sdk.core");
|
|
45
|
+
var import_express = __toESM(require("express"), 1);
|
|
46
|
+
|
|
47
|
+
// src/api-functions.ts
|
|
48
|
+
var import_ssi_express_support = require("@sphereon/ssi-express-support");
|
|
49
|
+
var import_ssi_sdk = require("@sphereon/ssi-sdk.agent-config");
|
|
50
|
+
var import_uuid = require("uuid");
|
|
51
|
+
var import_debug = __toESM(require("debug"), 1);
|
|
52
|
+
var import_ssi_sdk2 = require("@sphereon/ssi-sdk.credential-store");
|
|
53
|
+
var import_ssi_sdk3 = require("@sphereon/ssi-sdk.data-store");
|
|
54
|
+
var import_ssi_types = require("@sphereon/ssi-types");
|
|
55
|
+
var import_ssi_sdk4 = require("@sphereon/ssi-sdk.credential-vcdm");
|
|
56
|
+
var import_ssi_sdk_ext = require("@sphereon/ssi-sdk-ext.identifier-resolution");
|
|
57
|
+
var debug = (0, import_debug.default)("sphereon:ssi-sdk:w3c-vc-api");
|
|
58
|
+
function issueCredentialEndpoint(router, context, opts) {
|
|
59
|
+
if (opts?.enabled === false) {
|
|
60
|
+
console.log(`Issue credential endpoint is disabled`);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const path = opts?.path ?? "/credentials/issue";
|
|
64
|
+
router.post(path, (0, import_ssi_express_support.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
65
|
+
try {
|
|
66
|
+
const credential = request.body.credential;
|
|
67
|
+
const reqOpts = request.body.options ?? {};
|
|
68
|
+
const inputFormat = reqOpts.proofFormat?.toLocaleLowerCase();
|
|
69
|
+
let proofFormat = void 0;
|
|
70
|
+
if (inputFormat) {
|
|
71
|
+
if (inputFormat === "jwt") {
|
|
72
|
+
proofFormat = "jwt";
|
|
73
|
+
} else if (inputFormat?.includes("jose") || inputFormat?.includes("vc+jwt")) {
|
|
74
|
+
proofFormat = "vc+jwt";
|
|
75
|
+
} else if (inputFormat?.includes("ld")) {
|
|
76
|
+
proofFormat = "lds";
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (proofFormat === void 0 && opts?.issueCredentialOpts?.proofFormat) {
|
|
80
|
+
proofFormat = opts.issueCredentialOpts.proofFormat.toLocaleLowerCase();
|
|
81
|
+
}
|
|
82
|
+
if (proofFormat === void 0) {
|
|
83
|
+
if ((0, import_ssi_types.isVcdm2Credential)(credential)) {
|
|
84
|
+
proofFormat = "vc+jwt";
|
|
85
|
+
} else {
|
|
86
|
+
proofFormat = "lds";
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (!credential) {
|
|
90
|
+
return (0, import_ssi_express_support.sendErrorResponse)(response, 400, "No credential supplied");
|
|
91
|
+
}
|
|
92
|
+
if (!credential.id) {
|
|
93
|
+
credential.id = `urn:uuid:${(0, import_uuid.v4)()}`;
|
|
94
|
+
}
|
|
95
|
+
if ((0, import_ssi_sdk.contextHasPlugin)(context, "slAddStatusToCredential")) {
|
|
96
|
+
const credentialStatusVC = await context.agent.slAddStatusToCredential({
|
|
97
|
+
credential
|
|
98
|
+
});
|
|
99
|
+
if (credential.credentialStatus && !credential.credentialStatus.statusListCredential) {
|
|
100
|
+
credential.credentialStatus = credentialStatusVC.credentialStatus;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const issueOpts = opts?.issueCredentialOpts;
|
|
104
|
+
const vc = await context.agent.createVerifiableCredential({
|
|
105
|
+
credential,
|
|
106
|
+
proofFormat,
|
|
107
|
+
fetchRemoteContexts: issueOpts?.fetchRemoteContexts !== false
|
|
108
|
+
});
|
|
109
|
+
const rawDocument = import_ssi_types.CredentialMapper.storedCredentialToOriginalFormat(vc);
|
|
110
|
+
const save = opts?.persistIssuedCredentials;
|
|
111
|
+
if (save) {
|
|
112
|
+
const issuer = (0, import_ssi_sdk4.extractIssuer)(credential);
|
|
113
|
+
const identifier = await context.agent.identifierManagedGet({
|
|
114
|
+
identifier: issuer,
|
|
115
|
+
issuer,
|
|
116
|
+
vmRelationship: "assertionMethod"
|
|
117
|
+
});
|
|
118
|
+
let issuerCorrelationId = identifier.issuer;
|
|
119
|
+
if (!issuerCorrelationId && (0, import_ssi_sdk_ext.isDidIdentifier)(identifier.identifier)) {
|
|
120
|
+
if ((0, import_ssi_sdk_ext.isIIdentifier)(identifier.identifier)) {
|
|
121
|
+
issuerCorrelationId = identifier.identifier.did;
|
|
122
|
+
} else if (typeof identifier.identifier === "string") {
|
|
123
|
+
issuerCorrelationId = identifier.identifier;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (!issuerCorrelationId) {
|
|
127
|
+
if (typeof vc.issuer === "string") {
|
|
128
|
+
issuerCorrelationId = vc.issuer;
|
|
129
|
+
} else if (typeof vc.issuer?.id === "string") {
|
|
130
|
+
issuerCorrelationId = vc.issuer.id;
|
|
131
|
+
} else {
|
|
132
|
+
issuerCorrelationId = "unknown";
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const dc = {
|
|
136
|
+
credential: {
|
|
137
|
+
credentialRole: import_ssi_sdk3.CredentialRole.HOLDER,
|
|
138
|
+
// tenantId: 'test-tenant',
|
|
139
|
+
kmsKeyRef: identifier.kmsKeyRef,
|
|
140
|
+
identifierMethod: identifier.method,
|
|
141
|
+
issuerCorrelationId,
|
|
142
|
+
issuerCorrelationType: import_ssi_sdk2.CredentialCorrelationType.DID,
|
|
143
|
+
rawDocument: typeof rawDocument === "string" ? rawDocument : JSON.stringify(rawDocument)
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
await context.agent.crsAddCredential(dc);
|
|
147
|
+
}
|
|
148
|
+
response.statusCode = 201;
|
|
149
|
+
return response.send({
|
|
150
|
+
verifiableCredential: rawDocument,
|
|
151
|
+
uniformCredential: import_ssi_types.CredentialMapper.toUniformCredential(vc)
|
|
152
|
+
});
|
|
153
|
+
} catch (e) {
|
|
154
|
+
return (0, import_ssi_express_support.sendErrorResponse)(response, 500, e.message, e);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
__name(issueCredentialEndpoint, "issueCredentialEndpoint");
|
|
159
|
+
function getCredentialsEndpoint(router, context, opts) {
|
|
160
|
+
if (opts?.enabled === false) {
|
|
161
|
+
console.log(`Get credentials endpoint is disabled`);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const path = opts?.path ?? "/credentials";
|
|
165
|
+
router.get(path, (0, import_ssi_express_support.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
166
|
+
try {
|
|
167
|
+
const credentialRole = request.query.credentialRole || import_ssi_sdk3.CredentialRole.HOLDER;
|
|
168
|
+
if (!Object.values(import_ssi_sdk3.CredentialRole).includes(credentialRole)) {
|
|
169
|
+
return (0, import_ssi_express_support.sendErrorResponse)(response, 400, `Invalid credentialRole: ${credentialRole}`);
|
|
170
|
+
}
|
|
171
|
+
const documentType = request.query.documentType || import_ssi_sdk2.DocumentType.VC;
|
|
172
|
+
if (!Object.values(import_ssi_sdk2.DocumentType).includes(documentType)) {
|
|
173
|
+
return (0, import_ssi_express_support.sendErrorResponse)(response, 400, `Invalid documentType: ${documentType}`);
|
|
174
|
+
}
|
|
175
|
+
const filter = [
|
|
176
|
+
{
|
|
177
|
+
documentType,
|
|
178
|
+
credentialRole
|
|
179
|
+
}
|
|
180
|
+
];
|
|
181
|
+
const uniqueVCs = await context.agent.crsGetUniqueCredentials({
|
|
182
|
+
filter
|
|
183
|
+
});
|
|
184
|
+
response.statusCode = 202;
|
|
185
|
+
return response.send(uniqueVCs.map((uVC) => uVC.uniformVerifiableCredential));
|
|
186
|
+
} catch (e) {
|
|
187
|
+
return (0, import_ssi_express_support.sendErrorResponse)(response, 500, e.message, e);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
__name(getCredentialsEndpoint, "getCredentialsEndpoint");
|
|
192
|
+
function getCredentialEndpoint(router, context, opts) {
|
|
193
|
+
if (opts?.enabled === false) {
|
|
194
|
+
console.log(`Get credential endpoint is disabled`);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const path = opts?.path ?? "/credentials/:id";
|
|
198
|
+
router.get(path, (0, import_ssi_express_support.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
199
|
+
try {
|
|
200
|
+
const id = request.params.id;
|
|
201
|
+
if (!id) {
|
|
202
|
+
return (0, import_ssi_express_support.sendErrorResponse)(response, 400, "no id provided");
|
|
203
|
+
}
|
|
204
|
+
const credentialRole = request.query.credentialRole || import_ssi_sdk3.CredentialRole.HOLDER;
|
|
205
|
+
if (!Object.values(import_ssi_sdk3.CredentialRole).includes(credentialRole)) {
|
|
206
|
+
return (0, import_ssi_express_support.sendErrorResponse)(response, 400, `Invalid credentialRole: ${credentialRole}`);
|
|
207
|
+
}
|
|
208
|
+
const vcInfo = await context.agent.crsGetUniqueCredentialByIdOrHash({
|
|
209
|
+
credentialRole,
|
|
210
|
+
idOrHash: id
|
|
211
|
+
});
|
|
212
|
+
if (!vcInfo) {
|
|
213
|
+
return (0, import_ssi_express_support.sendErrorResponse)(response, 403, `id ${id} not found`);
|
|
214
|
+
}
|
|
215
|
+
response.statusCode = 200;
|
|
216
|
+
return response.send(vcInfo.uniformVerifiableCredential);
|
|
217
|
+
} catch (e) {
|
|
218
|
+
return (0, import_ssi_express_support.sendErrorResponse)(response, 500, e.message, e);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
__name(getCredentialEndpoint, "getCredentialEndpoint");
|
|
223
|
+
function verifyCredentialEndpoint(router, context, opts) {
|
|
224
|
+
if (opts?.enabled === false) {
|
|
225
|
+
console.log(`Verify credential endpoint is disabled`);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
router.post(opts?.path ?? "/credentials/verify", (0, import_ssi_express_support.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
229
|
+
try {
|
|
230
|
+
debug(JSON.stringify(request.body, null, 2));
|
|
231
|
+
const credential = request.body.verifiableCredential;
|
|
232
|
+
if (!credential) {
|
|
233
|
+
return (0, import_ssi_express_support.sendErrorResponse)(response, 400, "No verifiable credential supplied");
|
|
234
|
+
}
|
|
235
|
+
const verifyResult = await context.agent.verifyCredential({
|
|
236
|
+
credential,
|
|
237
|
+
policies: {
|
|
238
|
+
credentialStatus: false
|
|
239
|
+
},
|
|
240
|
+
fetchRemoteContexts: opts?.fetchRemoteContexts !== false
|
|
241
|
+
});
|
|
242
|
+
response.statusCode = 200;
|
|
243
|
+
return response.send(verifyResult);
|
|
244
|
+
} catch (e) {
|
|
245
|
+
return (0, import_ssi_express_support.sendErrorResponse)(response, 500, e.message, e);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
__name(verifyCredentialEndpoint, "verifyCredentialEndpoint");
|
|
250
|
+
function deleteCredentialEndpoint(router, context, opts) {
|
|
251
|
+
if (opts?.enabled === false) {
|
|
252
|
+
console.log(`Delete credential endpoint is disabled`);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
router.delete(opts?.path ?? "/credentials/:id", (0, import_ssi_express_support.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
256
|
+
try {
|
|
257
|
+
const id = request.params.id;
|
|
258
|
+
if (!id) {
|
|
259
|
+
return (0, import_ssi_express_support.sendErrorResponse)(response, 400, "no id provided");
|
|
260
|
+
}
|
|
261
|
+
const credentialRole = request.query.credentialRole;
|
|
262
|
+
if (credentialRole === void 0) {
|
|
263
|
+
return (0, import_ssi_express_support.sendErrorResponse)(response, 400, "credentialRole query parameter is missing");
|
|
264
|
+
}
|
|
265
|
+
if (!Object.values(import_ssi_sdk3.CredentialRole).includes(credentialRole)) {
|
|
266
|
+
return (0, import_ssi_express_support.sendErrorResponse)(response, 400, `Invalid credentialRole: ${credentialRole}`);
|
|
267
|
+
}
|
|
268
|
+
const vcInfo = await context.agent.crsGetUniqueCredentialByIdOrHash({
|
|
269
|
+
credentialRole,
|
|
270
|
+
idOrHash: id
|
|
271
|
+
});
|
|
272
|
+
if (!vcInfo) {
|
|
273
|
+
return (0, import_ssi_express_support.sendErrorResponse)(response, 404, `id ${id} not found`);
|
|
274
|
+
}
|
|
275
|
+
const success = await context.agent.crsDeleteCredentials({
|
|
276
|
+
filter: [
|
|
277
|
+
{
|
|
278
|
+
hash: vcInfo.hash
|
|
279
|
+
}
|
|
280
|
+
]
|
|
281
|
+
});
|
|
282
|
+
if (success === 0) {
|
|
283
|
+
return (0, import_ssi_express_support.sendErrorResponse)(response, 400, `Could not delete Verifiable Credential with id ${id}`);
|
|
284
|
+
}
|
|
285
|
+
response.statusCode = 200;
|
|
286
|
+
return response.send();
|
|
287
|
+
} catch (e) {
|
|
288
|
+
return (0, import_ssi_express_support.sendErrorResponse)(response, 500, e.message, e);
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
__name(deleteCredentialEndpoint, "deleteCredentialEndpoint");
|
|
293
|
+
|
|
294
|
+
// src/vc-api-server.ts
|
|
295
|
+
var VcApiServer = class {
|
|
296
|
+
static {
|
|
297
|
+
__name(this, "VcApiServer");
|
|
298
|
+
}
|
|
299
|
+
get router() {
|
|
300
|
+
return this._router;
|
|
301
|
+
}
|
|
302
|
+
_express;
|
|
303
|
+
_agent;
|
|
304
|
+
_opts;
|
|
305
|
+
_router;
|
|
306
|
+
constructor(args) {
|
|
307
|
+
const { agent, opts } = args;
|
|
308
|
+
this._agent = agent;
|
|
309
|
+
if (opts?.endpointOpts?.globalAuth) {
|
|
310
|
+
copyGlobalAuthToEndpoint(opts, "issueCredential");
|
|
311
|
+
copyGlobalAuthToEndpoint(opts, "getCredential");
|
|
312
|
+
copyGlobalAuthToEndpoint(opts, "getCredentials");
|
|
313
|
+
copyGlobalAuthToEndpoint(opts, "deleteCredential");
|
|
314
|
+
copyGlobalAuthToEndpoint(opts, "verifyCredential");
|
|
315
|
+
}
|
|
316
|
+
this._opts = opts;
|
|
317
|
+
this._express = args.expressSupport.express;
|
|
318
|
+
this._router = import_express.default.Router();
|
|
319
|
+
const context = (0, import_ssi_sdk5.agentContext)(agent);
|
|
320
|
+
const features = opts?.issueCredentialOpts?.enableFeatures ?? [
|
|
321
|
+
"vc-issue",
|
|
322
|
+
"vc-persist",
|
|
323
|
+
"vc-verify"
|
|
324
|
+
];
|
|
325
|
+
console.log(`VC API enabled, with features: ${JSON.stringify(features)}`);
|
|
326
|
+
if (features.includes("vc-issue")) {
|
|
327
|
+
issueCredentialEndpoint(this.router, context, {
|
|
328
|
+
...opts?.endpointOpts?.issueCredential,
|
|
329
|
+
issueCredentialOpts: opts?.issueCredentialOpts
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
if (features.includes("vc-persist")) {
|
|
333
|
+
getCredentialEndpoint(this.router, context, opts?.endpointOpts?.getCredential);
|
|
334
|
+
getCredentialsEndpoint(this.router, context, opts?.endpointOpts?.getCredentials);
|
|
335
|
+
deleteCredentialEndpoint(this.router, context, opts?.endpointOpts?.deleteCredential);
|
|
336
|
+
}
|
|
337
|
+
if (features.includes("vc-verify")) {
|
|
338
|
+
verifyCredentialEndpoint(this.router, context, {
|
|
339
|
+
...opts?.endpointOpts?.verifyCredential,
|
|
340
|
+
fetchRemoteContexts: opts?.issueCredentialOpts?.fetchRemoteContexts
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
this._express.use(opts?.endpointOpts?.basePath ?? "", this.router);
|
|
344
|
+
}
|
|
345
|
+
get agent() {
|
|
346
|
+
return this._agent;
|
|
347
|
+
}
|
|
348
|
+
get opts() {
|
|
349
|
+
return this._opts;
|
|
350
|
+
}
|
|
351
|
+
get express() {
|
|
352
|
+
return this._express;
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
function copyGlobalAuthToEndpoint(opts, key) {
|
|
356
|
+
if (opts?.endpointOpts?.globalAuth) {
|
|
357
|
+
opts.endpointOpts[key] = {
|
|
358
|
+
// @ts-ignore
|
|
359
|
+
...opts.endpointOpts[key],
|
|
360
|
+
// @ts-ignore
|
|
361
|
+
endpoint: {
|
|
362
|
+
...opts.endpointOpts.globalAuth,
|
|
363
|
+
...opts.endpointOpts[key]?.endpoint
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
__name(copyGlobalAuthToEndpoint, "copyGlobalAuthToEndpoint");
|
|
369
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/vc-api-server.ts","../src/api-functions.ts"],"sourcesContent":["/**\n * @public\n */\nexport * from './vc-api-server'\nexport * from './types'\nexport * from './api-functions'\n","import { agentContext } from '@sphereon/ssi-sdk.core'\nimport type { ExpressSupport } from '@sphereon/ssi-express-support'\nimport type { TAgent } from '@veramo/core'\n\nimport express, { type Express, Router } from 'express'\nimport {\n deleteCredentialEndpoint,\n getCredentialEndpoint,\n getCredentialsEndpoint,\n issueCredentialEndpoint,\n verifyCredentialEndpoint,\n} from './api-functions'\nimport type { IRequiredPlugins, IVCAPIOpts } from './types'\n\nexport class VcApiServer {\n get router(): express.Router {\n return this._router\n }\n\n private readonly _express: Express\n private readonly _agent: TAgent<IRequiredPlugins>\n private readonly _opts?: IVCAPIOpts\n private readonly _router: Router\n\n constructor(args: { agent: TAgent<IRequiredPlugins>; expressSupport: ExpressSupport; opts?: IVCAPIOpts }) {\n const { agent, opts } = args\n this._agent = agent\n if (opts?.endpointOpts?.globalAuth) {\n copyGlobalAuthToEndpoint(opts, 'issueCredential')\n copyGlobalAuthToEndpoint(opts, 'getCredential')\n copyGlobalAuthToEndpoint(opts, 'getCredentials')\n copyGlobalAuthToEndpoint(opts, 'deleteCredential')\n copyGlobalAuthToEndpoint(opts, 'verifyCredential')\n }\n\n this._opts = opts\n this._express = args.expressSupport.express\n this._router = express.Router()\n\n const context = agentContext(agent)\n\n const features = opts?.issueCredentialOpts?.enableFeatures ?? ['vc-issue', 'vc-persist', 'vc-verify']\n console.log(`VC API enabled, with features: ${JSON.stringify(features)}`)\n\n // Credential endpoints\n if (features.includes('vc-issue')) {\n issueCredentialEndpoint(this.router, context, {\n ...opts?.endpointOpts?.issueCredential,\n issueCredentialOpts: opts?.issueCredentialOpts,\n })\n }\n if (features.includes('vc-persist')) {\n getCredentialEndpoint(this.router, context, opts?.endpointOpts?.getCredential)\n getCredentialsEndpoint(this.router, context, opts?.endpointOpts?.getCredentials)\n deleteCredentialEndpoint(this.router, context, opts?.endpointOpts?.deleteCredential) // not in spec.\n }\n if (features.includes('vc-verify')) {\n verifyCredentialEndpoint(this.router, context, {\n ...opts?.endpointOpts?.verifyCredential,\n fetchRemoteContexts: opts?.issueCredentialOpts?.fetchRemoteContexts,\n })\n }\n this._express.use(opts?.endpointOpts?.basePath ?? '', this.router)\n }\n\n get agent(): TAgent<IRequiredPlugins> {\n return this._agent\n }\n\n get opts(): IVCAPIOpts | undefined {\n return this._opts\n }\n\n get express(): Express {\n return this._express\n }\n}\n\nfunction copyGlobalAuthToEndpoint(opts: IVCAPIOpts, key: string) {\n if (opts?.endpointOpts?.globalAuth) {\n // @ts-ignore\n opts.endpointOpts[key] = {\n // @ts-ignore\n ...opts.endpointOpts[key],\n // @ts-ignore\n endpoint: { ...opts.endpointOpts.globalAuth, ...opts.endpointOpts[key]?.endpoint },\n }\n }\n}\n","import { checkAuth, type ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'\nimport { contextHasPlugin } from '@sphereon/ssi-sdk.agent-config'\nimport type { CredentialPayload, ProofFormat } from '@veramo/core'\nimport { type Request, type Response, Router } from 'express'\nimport { v4 } from 'uuid'\nimport type { IIssueCredentialEndpointOpts, IRequiredContext, IVCAPIIssueOpts, IVerifyCredentialEndpointOpts } from './types'\nimport Debug from 'debug'\nimport { AddCredentialArgs, CredentialCorrelationType, DocumentType, type FindDigitalCredentialArgs } from '@sphereon/ssi-sdk.credential-store'\nimport type { IStatusListPlugin } from '@sphereon/ssi-sdk.vc-status-list'\nimport { CredentialRole } from '@sphereon/ssi-sdk.data-store'\nimport { CredentialMapper, CredentialProofFormat, isVcdm2Credential, OriginalVerifiableCredential } from '@sphereon/ssi-types'\nimport { extractIssuer } from '@sphereon/ssi-sdk.credential-vcdm'\nimport { isDidIdentifier, isIIdentifier } from '@sphereon/ssi-sdk-ext.identifier-resolution'\nimport type { VerifiableCredentialSP } from '@sphereon/ssi-sdk.core'\n\nconst debug = Debug('sphereon:ssi-sdk:w3c-vc-api')\n\nexport function issueCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IIssueCredentialEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Issue credential endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/credentials/issue'\n\n router.post(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const credential: CredentialPayload = request.body.credential\n const reqOpts = request.body.options ?? {}\n const inputFormat = reqOpts.proofFormat?.toLocaleLowerCase()\n let proofFormat: CredentialProofFormat | undefined = undefined\n if (inputFormat) {\n if (inputFormat === 'jwt') {\n proofFormat = 'jwt'\n } else if (inputFormat?.includes('jose') || inputFormat?.includes('vc+jwt')) {\n proofFormat = 'vc+jwt'\n } else if (inputFormat?.includes('ld')) {\n proofFormat = 'lds'\n }\n }\n if (proofFormat === undefined && opts?.issueCredentialOpts?.proofFormat) {\n proofFormat = opts.issueCredentialOpts.proofFormat.toLocaleLowerCase() as CredentialProofFormat\n }\n if (proofFormat === undefined) {\n if (isVcdm2Credential(credential)) {\n proofFormat = 'vc+jwt'\n } else {\n proofFormat = 'lds'\n }\n }\n\n if (!credential) {\n return sendErrorResponse(response, 400, 'No credential supplied')\n }\n if (!credential.id) {\n credential.id = `urn:uuid:${v4()}`\n }\n if (contextHasPlugin<IStatusListPlugin>(context, 'slAddStatusToCredential')) {\n // Add status list if enabled (and when the input has a credentialStatus object (can be empty))\n const credentialStatusVC = await context.agent.slAddStatusToCredential({ credential })\n if (credential.credentialStatus && !credential.credentialStatus.statusListCredential) {\n credential.credentialStatus = credentialStatusVC.credentialStatus\n }\n }\n\n const issueOpts: IVCAPIIssueOpts | undefined = opts?.issueCredentialOpts\n const vc = await context.agent.createVerifiableCredential({\n credential,\n proofFormat: proofFormat as ProofFormat,\n fetchRemoteContexts: issueOpts?.fetchRemoteContexts !== false,\n })\n const rawDocument = CredentialMapper.storedCredentialToOriginalFormat(vc as OriginalVerifiableCredential)\n const save = opts?.persistIssuedCredentials\n if (save) {\n const issuer = extractIssuer(credential)\n const identifier = await context.agent.identifierManagedGet({ identifier: issuer, issuer: issuer, vmRelationship: 'assertionMethod' })\n\n let issuerCorrelationId: string | undefined = identifier.issuer\n if (!issuerCorrelationId && isDidIdentifier(identifier.identifier)) {\n if (isIIdentifier(identifier.identifier)) {\n issuerCorrelationId = identifier.identifier.did\n } else if (typeof identifier.identifier === 'string') {\n issuerCorrelationId = identifier.identifier\n }\n }\n if (!issuerCorrelationId) {\n if (typeof vc.issuer === 'string') {\n issuerCorrelationId = vc.issuer\n } else if (typeof vc.issuer?.id === 'string') {\n issuerCorrelationId = vc.issuer.id\n } else {\n issuerCorrelationId = 'unknown'\n }\n }\n\n const dc: AddCredentialArgs = {\n credential: {\n credentialRole: CredentialRole.HOLDER,\n // tenantId: 'test-tenant',\n kmsKeyRef: identifier.kmsKeyRef,\n identifierMethod: identifier.method,\n issuerCorrelationId: issuerCorrelationId,\n issuerCorrelationType: CredentialCorrelationType.DID,\n rawDocument: typeof rawDocument === 'string' ? rawDocument : JSON.stringify(rawDocument),\n },\n }\n await context.agent.crsAddCredential(dc)\n }\n response.statusCode = 201\n return response.send({ verifiableCredential: rawDocument, uniformCredential: CredentialMapper.toUniformCredential(vc as OriginalVerifiableCredential) })\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n\nexport function getCredentialsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Get credentials endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/credentials'\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const credentialRole = (request.query.credentialRole as CredentialRole) || CredentialRole.HOLDER\n if (!Object.values(CredentialRole).includes(credentialRole)) {\n return sendErrorResponse(response, 400, `Invalid credentialRole: ${credentialRole}`)\n }\n\n const documentType = (request.query.documentType as DocumentType) || DocumentType.VC\n if (!Object.values(DocumentType).includes(documentType)) {\n return sendErrorResponse(response, 400, `Invalid documentType: ${documentType}`)\n }\n\n const filter: FindDigitalCredentialArgs = [\n {\n documentType: documentType,\n credentialRole: credentialRole,\n },\n ]\n const uniqueVCs = await context.agent.crsGetUniqueCredentials({ filter })\n response.statusCode = 202\n return response.send(uniqueVCs.map((uVC) => uVC.uniformVerifiableCredential))\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n\nexport function getCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Get credential endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/credentials/:id'\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const id = request.params.id\n if (!id) {\n return sendErrorResponse(response, 400, 'no id provided')\n }\n const credentialRole = (request.query.credentialRole as CredentialRole) || CredentialRole.HOLDER\n if (!Object.values(CredentialRole).includes(credentialRole)) {\n return sendErrorResponse(response, 400, `Invalid credentialRole: ${credentialRole}`)\n }\n\n const vcInfo = await context.agent.crsGetUniqueCredentialByIdOrHash({\n credentialRole: credentialRole,\n idOrHash: id,\n })\n if (!vcInfo) {\n return sendErrorResponse(response, 403, `id ${id} not found`)\n }\n response.statusCode = 200\n return response.send(vcInfo.uniformVerifiableCredential)\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n\nexport function verifyCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IVerifyCredentialEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Verify credential endpoint is disabled`)\n return\n }\n router.post(opts?.path ?? '/credentials/verify', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n debug(JSON.stringify(request.body, null, 2))\n const credential: VerifiableCredentialSP = request.body.verifiableCredential\n // const options: IIssueOptionsPayload = request.body.options\n if (!credential) {\n return sendErrorResponse(response, 400, 'No verifiable credential supplied')\n }\n const verifyResult = await context.agent.verifyCredential({\n credential,\n policies: {\n credentialStatus: false, // Do not use built-in. We have our own statusList implementations\n },\n fetchRemoteContexts: opts?.fetchRemoteContexts !== false,\n })\n\n response.statusCode = 200\n return response.send(verifyResult)\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n\nexport function deleteCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Delete credential endpoint is disabled`)\n return\n }\n router.delete(opts?.path ?? '/credentials/:id', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const id = request.params.id\n if (!id) {\n return sendErrorResponse(response, 400, 'no id provided')\n }\n const credentialRole = request.query.credentialRole as CredentialRole\n if (credentialRole === undefined) {\n return sendErrorResponse(response, 400, 'credentialRole query parameter is missing')\n }\n if (!Object.values(CredentialRole).includes(credentialRole)) {\n return sendErrorResponse(response, 400, `Invalid credentialRole: ${credentialRole}`)\n }\n\n const vcInfo = await context.agent.crsGetUniqueCredentialByIdOrHash({\n credentialRole: credentialRole,\n idOrHash: id,\n })\n if (!vcInfo) {\n return sendErrorResponse(response, 404, `id ${id} not found`)\n }\n const success = await context.agent.crsDeleteCredentials({ filter: [{ hash: vcInfo.hash }] })\n if (success === 0) {\n return sendErrorResponse(response, 400, `Could not delete Verifiable Credential with id ${id}`)\n }\n response.statusCode = 200\n return response.send()\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;ACAA,IAAAA,kBAA6B;AAI7B,qBAA8C;;;ACJ9C,iCAAuE;AACvE,qBAAiC;AAGjC,kBAAmB;AAEnB,mBAAkB;AAClB,IAAAC,kBAA2G;AAE3G,IAAAA,kBAA+B;AAC/B,uBAAyG;AACzG,IAAAA,kBAA8B;AAC9B,yBAA+C;AAG/C,IAAMC,YAAQC,aAAAA,SAAM,6BAAA;AAEb,SAASC,wBAAwBC,QAAgBC,SAA2BC,MAAmC;AACpH,MAAIA,MAAMC,YAAY,OAAO;AAC3BC,YAAQC,IAAI,uCAAuC;AACnD;EACF;AACA,QAAMC,OAAOJ,MAAMI,QAAQ;AAE3BN,SAAOO,KAAKD,UAAME,sCAAUN,MAAMO,QAAAA,GAAW,OAAOC,SAAkBC,aAAAA;AACpE,QAAI;AACF,YAAMC,aAAgCF,QAAQG,KAAKD;AACnD,YAAME,UAAUJ,QAAQG,KAAKE,WAAW,CAAC;AACzC,YAAMC,cAAcF,QAAQG,aAAaC,kBAAAA;AACzC,UAAID,cAAiDE;AACrD,UAAIH,aAAa;AACf,YAAIA,gBAAgB,OAAO;AACzBC,wBAAc;QAChB,WAAWD,aAAaI,SAAS,MAAA,KAAWJ,aAAaI,SAAS,QAAA,GAAW;AAC3EH,wBAAc;QAChB,WAAWD,aAAaI,SAAS,IAAA,GAAO;AACtCH,wBAAc;QAChB;MACF;AACA,UAAIA,gBAAgBE,UAAajB,MAAMmB,qBAAqBJ,aAAa;AACvEA,sBAAcf,KAAKmB,oBAAoBJ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_sdk","debug","Debug","issueCredentialEndpoint","router","context","opts","enabled","console","log","path","post","checkAuth","endpoint","request","response","credential","body","reqOpts","options","inputFormat","proofFormat","toLocaleLowerCase","undefined","includes","issueCredentialOpts","isVcdm2Credential","sendErrorResponse","id","v4","contextHasPlugin","credentialStatusVC","agent","slAddStatusToCredential","credentialStatus","statusListCredential","issueOpts","vc","createVerifiableCredential","fetchRemoteContexts","rawDocument","CredentialMapper","storedCredentialToOriginalFormat","save","persistIssuedCredentials","issuer","extractIssuer","identifier","identifierManagedGet","vmRelationship","issuerCorrelationId","isDidIdentifier","isIIdentifier","did","dc","credentialRole","CredentialRole","HOLDER","kmsKeyRef","identifierMethod","method","issuerCorrelationType","CredentialCorrelationType","DID","JSON","stringify","crsAddCredential","statusCode","send","verifiableCredential","uniformCredential","toUniformCredential","e","message","getCredentialsEndpoint","get","query","Object","values","documentType","DocumentType","VC","filter","uniqueVCs","crsGetUniqueCredentials","map","uVC","uniformVerifiableCredential","getCredentialEndpoint","params","vcInfo","crsGetUniqueCredentialByIdOrHash","idOrHash","verifyCredentialEndpoint","verifyResult","verifyCredential","policies","deleteCredentialEndpoint","delete","success","crsDeleteCredentials","hash","VcApiServer","router","_router","_express","_agent","_opts","constructor","args","agent","opts","endpointOpts","globalAuth","copyGlobalAuthToEndpoint","expressSupport","express","Router","context","agentContext","features","issueCredentialOpts","enableFeatures","console","log","JSON","stringify","includes","issueCredentialEndpoint","issueCredential","getCredentialEndpoint","getCredential","getCredentialsEndpoint","getCredentials","deleteCredentialEndpoint","deleteCredential","verifyCredentialEndpoint","verifyCredential","fetchRemoteContexts","use","basePath","key","endpoint"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { GenericAuthArgs, ISingleEndpointOpts, ExpressSupport } from '@sphereon/ssi-express-support';
|
|
2
|
+
import { IDataStoreORM, IDIDManager, IKeyManager, IResolver, IAgentContext, TAgent } from '@veramo/core';
|
|
3
|
+
import express, { Express, Router } from 'express';
|
|
4
|
+
import { ICredentialStore } from '@sphereon/ssi-sdk.credential-store';
|
|
5
|
+
import { CredentialProofFormat } from '@sphereon/ssi-types';
|
|
6
|
+
import { IVcdmCredentialPlugin } from '@sphereon/ssi-sdk.credential-vcdm';
|
|
7
|
+
import { IJwtService } from '@sphereon/ssi-sdk-ext.jwt-service';
|
|
8
|
+
import { IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution';
|
|
9
|
+
|
|
10
|
+
type IRequiredPlugins = IDataStoreORM & IDIDManager & IKeyManager & IVcdmCredentialPlugin & IJwtService & IIdentifierResolution & ICredentialStore & IResolver;
|
|
11
|
+
type IRequiredContext = IAgentContext<IRequiredPlugins>;
|
|
12
|
+
interface IVCAPIOpts {
|
|
13
|
+
endpointOpts?: IVCAPIEndpointOpts;
|
|
14
|
+
issueCredentialOpts?: IVCAPIIssueOpts;
|
|
15
|
+
}
|
|
16
|
+
interface IVCAPIEndpointOpts {
|
|
17
|
+
basePath?: string;
|
|
18
|
+
globalAuth?: GenericAuthArgs;
|
|
19
|
+
issueCredential?: IIssueCredentialEndpointOpts;
|
|
20
|
+
getCredentials?: ISingleEndpointOpts;
|
|
21
|
+
getCredential?: ISingleEndpointOpts;
|
|
22
|
+
deleteCredential?: ISingleEndpointOpts;
|
|
23
|
+
verifyCredential?: IVerifyCredentialEndpointOpts;
|
|
24
|
+
verifyPresentation?: ISingleEndpointOpts;
|
|
25
|
+
}
|
|
26
|
+
type vcApiFeatures = 'vc-verify' | 'vc-issue' | 'vc-persist';
|
|
27
|
+
interface IVCAPIIssueOpts {
|
|
28
|
+
enableFeatures?: vcApiFeatures[];
|
|
29
|
+
persistIssuedCredentials?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* The desired format for the VerifiablePresentation to be created.
|
|
32
|
+
*/
|
|
33
|
+
proofFormat?: CredentialProofFormat;
|
|
34
|
+
/**
|
|
35
|
+
* Remove payload members during JWT-JSON transformation. Defaults to `true`.
|
|
36
|
+
* See https://www.w3.org/TR/vc-data-model/#jwt-encoding
|
|
37
|
+
*/
|
|
38
|
+
removeOriginalFields?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* [Optional] The ID of the key that should sign this credential.
|
|
41
|
+
* If this is not specified, the first matching key will be used.
|
|
42
|
+
*/
|
|
43
|
+
keyRef?: string;
|
|
44
|
+
/**
|
|
45
|
+
* When dealing with JSON-LD you also MUST provide the proper contexts.
|
|
46
|
+
* Set this to `true` ONLY if you want the `@context` URLs to be fetched in case they are not preloaded.
|
|
47
|
+
* The context definitions SHOULD rather be provided at startup instead of being fetched.
|
|
48
|
+
*
|
|
49
|
+
* Defaults to `false`
|
|
50
|
+
*/
|
|
51
|
+
fetchRemoteContexts?: boolean;
|
|
52
|
+
}
|
|
53
|
+
interface IIssueCredentialEndpointOpts extends ISingleEndpointOpts {
|
|
54
|
+
issueCredentialOpts?: IVCAPIIssueOpts;
|
|
55
|
+
persistIssuedCredentials?: boolean;
|
|
56
|
+
}
|
|
57
|
+
interface IVerifyCredentialEndpointOpts extends ISingleEndpointOpts {
|
|
58
|
+
fetchRemoteContexts?: boolean;
|
|
59
|
+
}
|
|
60
|
+
interface IIssueOptionsPayload {
|
|
61
|
+
created?: string;
|
|
62
|
+
challenge?: string;
|
|
63
|
+
domain?: string;
|
|
64
|
+
credentialStatus?: {
|
|
65
|
+
type: string;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
interface ChallengeOptsPayload {
|
|
69
|
+
challenge?: string;
|
|
70
|
+
domain?: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
declare class VcApiServer {
|
|
74
|
+
get router(): express.Router;
|
|
75
|
+
private readonly _express;
|
|
76
|
+
private readonly _agent;
|
|
77
|
+
private readonly _opts?;
|
|
78
|
+
private readonly _router;
|
|
79
|
+
constructor(args: {
|
|
80
|
+
agent: TAgent<IRequiredPlugins>;
|
|
81
|
+
expressSupport: ExpressSupport;
|
|
82
|
+
opts?: IVCAPIOpts;
|
|
83
|
+
});
|
|
84
|
+
get agent(): TAgent<IRequiredPlugins>;
|
|
85
|
+
get opts(): IVCAPIOpts | undefined;
|
|
86
|
+
get express(): Express;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
declare function issueCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IIssueCredentialEndpointOpts): void;
|
|
90
|
+
declare function getCredentialsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
91
|
+
declare function getCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
92
|
+
declare function verifyCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IVerifyCredentialEndpointOpts): void;
|
|
93
|
+
declare function deleteCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
94
|
+
|
|
95
|
+
export { type ChallengeOptsPayload, type IIssueCredentialEndpointOpts, type IIssueOptionsPayload, type IRequiredContext, type IRequiredPlugins, type IVCAPIEndpointOpts, type IVCAPIIssueOpts, type IVCAPIOpts, type IVerifyCredentialEndpointOpts, VcApiServer, deleteCredentialEndpoint, getCredentialEndpoint, getCredentialsEndpoint, issueCredentialEndpoint, type vcApiFeatures, verifyCredentialEndpoint };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { GenericAuthArgs, ISingleEndpointOpts, ExpressSupport } from '@sphereon/ssi-express-support';
|
|
2
|
+
import { IDataStoreORM, IDIDManager, IKeyManager, IResolver, IAgentContext, TAgent } from '@veramo/core';
|
|
3
|
+
import express, { Express, Router } from 'express';
|
|
4
|
+
import { ICredentialStore } from '@sphereon/ssi-sdk.credential-store';
|
|
5
|
+
import { CredentialProofFormat } from '@sphereon/ssi-types';
|
|
6
|
+
import { IVcdmCredentialPlugin } from '@sphereon/ssi-sdk.credential-vcdm';
|
|
7
|
+
import { IJwtService } from '@sphereon/ssi-sdk-ext.jwt-service';
|
|
8
|
+
import { IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution';
|
|
9
|
+
|
|
10
|
+
type IRequiredPlugins = IDataStoreORM & IDIDManager & IKeyManager & IVcdmCredentialPlugin & IJwtService & IIdentifierResolution & ICredentialStore & IResolver;
|
|
11
|
+
type IRequiredContext = IAgentContext<IRequiredPlugins>;
|
|
12
|
+
interface IVCAPIOpts {
|
|
13
|
+
endpointOpts?: IVCAPIEndpointOpts;
|
|
14
|
+
issueCredentialOpts?: IVCAPIIssueOpts;
|
|
15
|
+
}
|
|
16
|
+
interface IVCAPIEndpointOpts {
|
|
17
|
+
basePath?: string;
|
|
18
|
+
globalAuth?: GenericAuthArgs;
|
|
19
|
+
issueCredential?: IIssueCredentialEndpointOpts;
|
|
20
|
+
getCredentials?: ISingleEndpointOpts;
|
|
21
|
+
getCredential?: ISingleEndpointOpts;
|
|
22
|
+
deleteCredential?: ISingleEndpointOpts;
|
|
23
|
+
verifyCredential?: IVerifyCredentialEndpointOpts;
|
|
24
|
+
verifyPresentation?: ISingleEndpointOpts;
|
|
25
|
+
}
|
|
26
|
+
type vcApiFeatures = 'vc-verify' | 'vc-issue' | 'vc-persist';
|
|
27
|
+
interface IVCAPIIssueOpts {
|
|
28
|
+
enableFeatures?: vcApiFeatures[];
|
|
29
|
+
persistIssuedCredentials?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* The desired format for the VerifiablePresentation to be created.
|
|
32
|
+
*/
|
|
33
|
+
proofFormat?: CredentialProofFormat;
|
|
34
|
+
/**
|
|
35
|
+
* Remove payload members during JWT-JSON transformation. Defaults to `true`.
|
|
36
|
+
* See https://www.w3.org/TR/vc-data-model/#jwt-encoding
|
|
37
|
+
*/
|
|
38
|
+
removeOriginalFields?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* [Optional] The ID of the key that should sign this credential.
|
|
41
|
+
* If this is not specified, the first matching key will be used.
|
|
42
|
+
*/
|
|
43
|
+
keyRef?: string;
|
|
44
|
+
/**
|
|
45
|
+
* When dealing with JSON-LD you also MUST provide the proper contexts.
|
|
46
|
+
* Set this to `true` ONLY if you want the `@context` URLs to be fetched in case they are not preloaded.
|
|
47
|
+
* The context definitions SHOULD rather be provided at startup instead of being fetched.
|
|
48
|
+
*
|
|
49
|
+
* Defaults to `false`
|
|
50
|
+
*/
|
|
51
|
+
fetchRemoteContexts?: boolean;
|
|
52
|
+
}
|
|
53
|
+
interface IIssueCredentialEndpointOpts extends ISingleEndpointOpts {
|
|
54
|
+
issueCredentialOpts?: IVCAPIIssueOpts;
|
|
55
|
+
persistIssuedCredentials?: boolean;
|
|
56
|
+
}
|
|
57
|
+
interface IVerifyCredentialEndpointOpts extends ISingleEndpointOpts {
|
|
58
|
+
fetchRemoteContexts?: boolean;
|
|
59
|
+
}
|
|
60
|
+
interface IIssueOptionsPayload {
|
|
61
|
+
created?: string;
|
|
62
|
+
challenge?: string;
|
|
63
|
+
domain?: string;
|
|
64
|
+
credentialStatus?: {
|
|
65
|
+
type: string;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
interface ChallengeOptsPayload {
|
|
69
|
+
challenge?: string;
|
|
70
|
+
domain?: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
declare class VcApiServer {
|
|
74
|
+
get router(): express.Router;
|
|
75
|
+
private readonly _express;
|
|
76
|
+
private readonly _agent;
|
|
77
|
+
private readonly _opts?;
|
|
78
|
+
private readonly _router;
|
|
79
|
+
constructor(args: {
|
|
80
|
+
agent: TAgent<IRequiredPlugins>;
|
|
81
|
+
expressSupport: ExpressSupport;
|
|
82
|
+
opts?: IVCAPIOpts;
|
|
83
|
+
});
|
|
84
|
+
get agent(): TAgent<IRequiredPlugins>;
|
|
85
|
+
get opts(): IVCAPIOpts | undefined;
|
|
86
|
+
get express(): Express;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
declare function issueCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IIssueCredentialEndpointOpts): void;
|
|
90
|
+
declare function getCredentialsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
91
|
+
declare function getCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
92
|
+
declare function verifyCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IVerifyCredentialEndpointOpts): void;
|
|
93
|
+
declare function deleteCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
94
|
+
|
|
95
|
+
export { type ChallengeOptsPayload, type IIssueCredentialEndpointOpts, type IIssueOptionsPayload, type IRequiredContext, type IRequiredPlugins, type IVCAPIEndpointOpts, type IVCAPIIssueOpts, type IVCAPIOpts, type IVerifyCredentialEndpointOpts, VcApiServer, deleteCredentialEndpoint, getCredentialEndpoint, getCredentialsEndpoint, issueCredentialEndpoint, type vcApiFeatures, verifyCredentialEndpoint };
|