@sphereon/ssi-sdk.uni-resolver-registrar-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/dist/index.cjs ADDED
@@ -0,0 +1,423 @@
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
+ DidWebServer: () => DidWebServer,
35
+ UniResolverApiServer: () => UniResolverApiServer,
36
+ createDidEndpoint: () => createDidEndpoint,
37
+ deactivateDidEndpoint: () => deactivateDidEndpoint,
38
+ deleteDidEndpoint: () => deleteDidEndpoint,
39
+ didWebDomainEndpoint: () => didWebDomainEndpoint,
40
+ getDidMethodsEndpoint: () => getDidMethodsEndpoint,
41
+ resolveDidEndpoint: () => resolveDidEndpoint
42
+ });
43
+ module.exports = __toCommonJS(index_exports);
44
+
45
+ // src/api-functions.ts
46
+ var import_ssi_sdk_ext = require("@sphereon/ssi-sdk-ext.did-utils");
47
+ var import_ssi_sdk_ext2 = require("@sphereon/ssi-sdk-ext.key-utils");
48
+ var import_ssi_express_support = require("@sphereon/ssi-express-support");
49
+ var import_ssi_types = require("@sphereon/ssi-types");
50
+ var import_uuid = require("uuid");
51
+ var import_debug = __toESM(require("debug"), 1);
52
+ var debug = (0, import_debug.default)("sphereon:ssi-sdk:uni-resolver-registrar");
53
+ function createDidEndpoint(router, context, opts) {
54
+ if (opts?.enabled === false) {
55
+ console.log(`create DID endpoint is disabled`);
56
+ return;
57
+ }
58
+ const path = opts?.path ?? "/identifiers";
59
+ router.post(path, (0, import_ssi_express_support.checkAuth)(opts?.endpoint), async (request, response) => {
60
+ try {
61
+ const createRequest = request.body;
62
+ if (!createRequest) {
63
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 400, "No DID create request present");
64
+ }
65
+ const did = createRequest.did;
66
+ const didMethod = request.query.method ?? (did ? (0, import_ssi_types.parseDid)(did).method : opts?.defaultMethod);
67
+ const allDidMethods = await (0, import_ssi_sdk_ext.getAgentDIDMethods)(context);
68
+ if (!didMethod) {
69
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 400, "No DID method supplied or deductible");
70
+ } else if (did && (0, import_ssi_types.parseDid)(did).method != didMethod) {
71
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 400, "DID method did not match method param");
72
+ } else if (!allDidMethods.includes(didMethod)) {
73
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 400, "DID method not supported");
74
+ }
75
+ const provider = `did:${didMethod}`;
76
+ const jobId = createRequest.jobId ?? (0, import_uuid.v4)();
77
+ let alias = void 0;
78
+ if (didMethod === "web") {
79
+ if (!did) {
80
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 400, 'Please provide a value for "did" in the request body when creating a DID web');
81
+ }
82
+ alias = (0, import_ssi_types.parseDid)(did).id;
83
+ if (!alias) {
84
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 400, "Could not determine alias from did:web DID value: " + did);
85
+ }
86
+ }
87
+ let identifier;
88
+ let state;
89
+ if (opts?.noErrorOnExistingDid && did) {
90
+ try {
91
+ identifier = await context.agent.didManagerGet({
92
+ did
93
+ });
94
+ state = "exists";
95
+ } catch (e) {
96
+ }
97
+ }
98
+ if (identifier === void 0) {
99
+ if (createRequest.options.storeSecrets === false) {
100
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 400, "Only storeSecrets mode is supported currently");
101
+ } else if (createRequest.options.storeSecrets || opts?.storeSecrets) {
102
+ identifier = await context.agent.didManagerCreate({
103
+ provider,
104
+ alias,
105
+ kms: opts?.kms
106
+ });
107
+ state = "finished";
108
+ } else {
109
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 400, "Only storeSecrets mode is supported currently");
110
+ }
111
+ }
112
+ if (!identifier || !state) {
113
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 400, "An identifier and did state should be present at this point");
114
+ }
115
+ const didDocument = (0, import_ssi_sdk_ext.toDidDocument)(identifier, {
116
+ did,
117
+ use: [
118
+ import_ssi_sdk_ext2.JwkKeyUse.Signature,
119
+ import_ssi_sdk_ext2.JwkKeyUse.Encryption
120
+ ]
121
+ });
122
+ const createState = {
123
+ jobId,
124
+ didState: {
125
+ did: identifier.did,
126
+ state,
127
+ didDocument
128
+ }
129
+ };
130
+ response.statusCode = 200;
131
+ return response.send(createState);
132
+ } catch (e) {
133
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 500, e.message, e);
134
+ }
135
+ });
136
+ }
137
+ __name(createDidEndpoint, "createDidEndpoint");
138
+ function getDidMethodsEndpoint(router, context, opts) {
139
+ if (opts?.enabled === false) {
140
+ console.log(`Get DID methods endpoint is disabled`);
141
+ return;
142
+ }
143
+ const path = opts?.path ?? "/methods";
144
+ router.get(path, (0, import_ssi_express_support.checkAuth)(opts?.endpoint), async (request, response) => {
145
+ try {
146
+ const methods = await (0, import_ssi_sdk_ext.getAgentDIDMethods)(context);
147
+ response.statusCode = 200;
148
+ return response.send(methods);
149
+ } catch (e) {
150
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 500, e.message, e);
151
+ }
152
+ });
153
+ }
154
+ __name(getDidMethodsEndpoint, "getDidMethodsEndpoint");
155
+ async function agentDidToResolutionResult(context, did) {
156
+ try {
157
+ const identifier = await context.agent.didManagerGet({
158
+ did
159
+ });
160
+ debug(JSON.stringify(identifier, null, 2));
161
+ return (0, import_ssi_sdk_ext.toDidResolutionResult)(identifier, {
162
+ did,
163
+ supportedMethods: await (0, import_ssi_sdk_ext.getAgentDIDMethods)(context)
164
+ });
165
+ } catch (error) {
166
+ console.log(JSON.stringify(error.message));
167
+ return {
168
+ didDocument: null,
169
+ didResolutionMetadata: {
170
+ error: "notFound"
171
+ },
172
+ didDocumentMetadata: {}
173
+ };
174
+ }
175
+ }
176
+ __name(agentDidToResolutionResult, "agentDidToResolutionResult");
177
+ function resolveDidEndpoint(router, context, opts) {
178
+ if (opts?.enabled === false) {
179
+ console.log(`Resolve DID endpoint is disabled`);
180
+ return;
181
+ }
182
+ const path = opts?.path ?? "/identifiers/:identifier";
183
+ router.get(path, (0, import_ssi_express_support.checkAuth)(opts?.endpoint), async (request, response) => {
184
+ try {
185
+ const did = request.params.identifier;
186
+ if (!did) {
187
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 400, "no identifier provided");
188
+ }
189
+ const mode = request.query.mode?.toString().toLowerCase() ?? opts?.mode?.toLowerCase() ?? "hybrid";
190
+ let resolutionResult;
191
+ if (mode === "local" || mode === "hybrid") {
192
+ resolutionResult = await agentDidToResolutionResult(context, did);
193
+ }
194
+ if (mode !== "local" && !resolutionResult?.didDocument) {
195
+ resolutionResult = await context.agent.resolveDid({
196
+ didUrl: did
197
+ });
198
+ }
199
+ response.statusCode = 200;
200
+ return response.send(resolutionResult);
201
+ } catch (e) {
202
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 500, e.message, e);
203
+ }
204
+ });
205
+ }
206
+ __name(resolveDidEndpoint, "resolveDidEndpoint");
207
+ function deleteDidEndpoint(router, context, opts) {
208
+ if (opts?.enabled === false) {
209
+ console.log(`Deactivate DID endpoint is disabled`);
210
+ return;
211
+ }
212
+ router.delete(opts?.path ?? "/identifiers/:identifier", (0, import_ssi_express_support.checkAuth)(opts?.endpoint), async (request, response) => {
213
+ try {
214
+ const did = request.params.identifier;
215
+ if (!did) {
216
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 400, "no DID provided");
217
+ }
218
+ const result = await context.agent.didManagerDelete({
219
+ did
220
+ });
221
+ if (!result) {
222
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 404, `id ${did} not found`);
223
+ }
224
+ response.statusCode = 200;
225
+ return response.send();
226
+ } catch (e) {
227
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 500, e.message, e);
228
+ }
229
+ });
230
+ }
231
+ __name(deleteDidEndpoint, "deleteDidEndpoint");
232
+ function deactivateDidEndpoint(router, context, opts) {
233
+ if (opts?.enabled === false) {
234
+ console.log("Deactivate DID endpoint is disabled");
235
+ return;
236
+ }
237
+ router.post(opts?.path ?? "/deactivate", (0, import_ssi_express_support.checkAuth)(opts?.endpoint), async (request, response) => {
238
+ try {
239
+ const deactivateRequest = request.body;
240
+ if (!deactivateRequest) {
241
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 400, "Invalid request body", {
242
+ state: "failed"
243
+ });
244
+ }
245
+ const { did, jobId = (0, import_uuid.v4)() } = deactivateRequest;
246
+ if (!did) {
247
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 400, "No DID provided", {
248
+ state: "failed"
249
+ });
250
+ }
251
+ const result = await context.agent.didManagerDelete({
252
+ did
253
+ });
254
+ if (!result) {
255
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 404, `DID ${did} not found`, {
256
+ state: "failed"
257
+ });
258
+ }
259
+ response.status(200).json({
260
+ state: "finished",
261
+ did,
262
+ jobId
263
+ });
264
+ return response.send();
265
+ } catch (e) {
266
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 500, e.message, {
267
+ state: "failed",
268
+ errorDetails: e
269
+ });
270
+ }
271
+ });
272
+ }
273
+ __name(deactivateDidEndpoint, "deactivateDidEndpoint");
274
+ function didWebDomainEndpoint(router, context, opts) {
275
+ if (opts?.enabled === false) {
276
+ console.log(`DID Web domain resolution endpoint is disabled`);
277
+ return;
278
+ }
279
+ router.get(opts?.path ?? ":path(*)/did.json", (0, import_ssi_express_support.checkAuth)(opts?.endpoint), async (request, response) => {
280
+ try {
281
+ const path = request.params.path;
282
+ if (!path || path.length === 0) {
283
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 404, "Not found");
284
+ }
285
+ let did;
286
+ did = `did:web:${opts?.hostname?.replace("https://", "")?.replace("http://", "") ?? request.hostname}`;
287
+ if (path !== "/.well-known") {
288
+ if (opts?.disableSubPaths) {
289
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 404, "Not found");
290
+ }
291
+ const suffix = path.replace(/\//g, ":").replace(/%2F/g, ":");
292
+ if (!suffix.startsWith(":")) {
293
+ did += ":";
294
+ }
295
+ did += suffix;
296
+ } else if (opts?.disableWellKnown) {
297
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 404, "Not found");
298
+ }
299
+ const resolutionResult = await agentDidToResolutionResult(context, did);
300
+ if (!resolutionResult || !resolutionResult.didDocument || resolutionResult?.didResolutionMetadata?.error === "notFound") {
301
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 404, "Not found");
302
+ }
303
+ response.statusCode = 200;
304
+ return response.send(resolutionResult.didDocument);
305
+ } catch (e) {
306
+ return (0, import_ssi_express_support.sendErrorResponse)(response, 500, e.message, e);
307
+ }
308
+ });
309
+ }
310
+ __name(didWebDomainEndpoint, "didWebDomainEndpoint");
311
+
312
+ // src/uni-resolver-api-server.ts
313
+ var import_ssi_sdk = require("@sphereon/ssi-sdk.core");
314
+ var import_ssi_express_support2 = require("@sphereon/ssi-express-support");
315
+ var import_express = __toESM(require("express"), 1);
316
+ var UniResolverApiServer = class {
317
+ static {
318
+ __name(this, "UniResolverApiServer");
319
+ }
320
+ get router() {
321
+ return this._router;
322
+ }
323
+ _express;
324
+ _agent;
325
+ _opts;
326
+ _router;
327
+ constructor(args) {
328
+ const { agent, opts } = args;
329
+ this._agent = agent;
330
+ (0, import_ssi_express_support2.copyGlobalAuthToEndpoints)({
331
+ opts,
332
+ keys: [
333
+ "getDidMethods",
334
+ "createDid",
335
+ "resolveDid",
336
+ "deactivateDid"
337
+ ]
338
+ });
339
+ this._opts = opts;
340
+ this._express = args.expressSupport.express;
341
+ this._router = import_express.default.Router();
342
+ const context = (0, import_ssi_sdk.agentContext)(agent);
343
+ const features = opts?.enableFeatures ?? [
344
+ "did-resolve",
345
+ "did-persist"
346
+ ];
347
+ console.log(`DID Uni Resolver and Registrar API enabled, with features: ${JSON.stringify(features)}}`);
348
+ if (features.includes("did-resolve")) {
349
+ resolveDidEndpoint(this.router, context, opts?.endpointOpts?.resolveDid);
350
+ getDidMethodsEndpoint(this.router, context, opts?.endpointOpts?.getDidMethods);
351
+ }
352
+ if (features.includes("did-persist")) {
353
+ createDidEndpoint(this.router, context, opts?.endpointOpts?.createDid);
354
+ deleteDidEndpoint(this.router, context, opts?.endpointOpts?.deactivateDid);
355
+ deactivateDidEndpoint(this.router, context, opts?.endpointOpts?.deactivateDid);
356
+ }
357
+ this._express.use(opts?.endpointOpts?.basePath ?? "", this.router);
358
+ }
359
+ get agent() {
360
+ return this._agent;
361
+ }
362
+ get opts() {
363
+ return this._opts;
364
+ }
365
+ get express() {
366
+ return this._express;
367
+ }
368
+ };
369
+
370
+ // src/did-web-server.ts
371
+ var import_ssi_sdk2 = require("@sphereon/ssi-sdk.core");
372
+ var import_express2 = __toESM(require("express"), 1);
373
+ var DidWebServer = class {
374
+ static {
375
+ __name(this, "DidWebServer");
376
+ }
377
+ get router() {
378
+ return this._router;
379
+ }
380
+ _express;
381
+ _agent;
382
+ _opts;
383
+ _router;
384
+ constructor(args) {
385
+ const { agent, opts } = args;
386
+ const features = opts?.enableFeatures ?? [];
387
+ if (!features.includes("did-web-global-resolution")) {
388
+ console.log("did:web hosting service NOT enabled");
389
+ return;
390
+ }
391
+ this._agent = agent;
392
+ if (opts?.globalAuth) {
393
+ copyGlobalAuthToEndpoint(opts, "endpointOpts");
394
+ }
395
+ this._opts = opts;
396
+ this._express = args.expressSupport.express;
397
+ this._router = import_express2.default.Router();
398
+ const context = (0, import_ssi_sdk2.agentContext)(agent);
399
+ console.log(`did:web hosting service enabled`);
400
+ didWebDomainEndpoint(this.router, context, opts?.endpointOpts);
401
+ this._express.use(this.router);
402
+ }
403
+ get agent() {
404
+ return this._agent;
405
+ }
406
+ get opts() {
407
+ return this._opts;
408
+ }
409
+ get express() {
410
+ return this._express;
411
+ }
412
+ };
413
+ function copyGlobalAuthToEndpoint(opts, key) {
414
+ if (opts?.globalAuth) {
415
+ opts[key] = {
416
+ ...opts?.globalAuth,
417
+ // @ts-ignore
418
+ ...opts[key]
419
+ };
420
+ }
421
+ }
422
+ __name(copyGlobalAuthToEndpoint, "copyGlobalAuthToEndpoint");
423
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/api-functions.ts","../src/uni-resolver-api-server.ts","../src/did-web-server.ts"],"sourcesContent":["/**\n * @public\n */\nexport * from './types'\nexport * from './api-functions'\nexport * from './uni-resolver-api-server'\nexport * from './did-web-server'\n","import { DIDResolutionResult } from '@sphereon/did-uni-client'\nimport { getAgentDIDMethods, toDidDocument, toDidResolutionResult } from '@sphereon/ssi-sdk-ext.did-utils'\nimport { JwkKeyUse } from '@sphereon/ssi-sdk-ext.key-utils'\nimport { checkAuth, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'\nimport { parseDid } from '@sphereon/ssi-types'\nimport { IIdentifier } from '@veramo/core'\nimport { Request, Response, Router } from 'express'\nimport { v4 } from 'uuid'\nimport {\n CreateState,\n DidRegistrationCreateRequest,\n DidRegistrationDeactivateRequest,\n DidStateValue,\n ICreateDidEndpointOpts,\n IGlobalDidWebEndpointOpts,\n IRequiredContext,\n IResolveEndpointOpts,\n} from './types'\nimport Debug from 'debug'\n\nconst debug = Debug('sphereon:ssi-sdk:uni-resolver-registrar')\n\nexport function createDidEndpoint(router: Router, context: IRequiredContext, opts?: ICreateDidEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`create DID endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/identifiers'\n\n router.post(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const createRequest: DidRegistrationCreateRequest = request.body\n if (!createRequest) {\n return sendErrorResponse(response, 400, 'No DID create request present')\n }\n const did = createRequest.did\n const didMethod = (request.query.method as string) ?? (did ? parseDid(did).method : opts?.defaultMethod)\n const allDidMethods = await getAgentDIDMethods(context)\n if (!didMethod) {\n return sendErrorResponse(response, 400, 'No DID method supplied or deductible')\n } else if (did && parseDid(did).method != didMethod) {\n return sendErrorResponse(response, 400, 'DID method did not match method param')\n } else if (!allDidMethods.includes(didMethod)) {\n return sendErrorResponse(response, 400, 'DID method not supported')\n }\n const provider = `did:${didMethod}`\n const jobId = createRequest.jobId ?? v4()\n let alias: string | undefined = undefined\n if (didMethod === 'web') {\n if (!did) {\n return sendErrorResponse(response, 400, 'Please provide a value for \"did\" in the request body when creating a DID web')\n }\n alias = parseDid(did).id\n if (!alias) {\n return sendErrorResponse(response, 400, 'Could not determine alias from did:web DID value: ' + did)\n }\n }\n\n let identifier: IIdentifier | undefined\n let state: DidStateValue | undefined\n if (opts?.noErrorOnExistingDid && did) {\n try {\n identifier = await context.agent.didManagerGet({ did })\n state = 'exists'\n } catch (e) {\n // Okay, since we will create a new one\n }\n }\n if (identifier === undefined) {\n if (createRequest.options.storeSecrets === false) {\n return sendErrorResponse(response, 400, 'Only storeSecrets mode is supported currently')\n /*const memoryKMS = new SphereonKeyManager({\n store: new MemoryKeyStore(),\n kms: {'mem': new KeyManagementSystem(new MemoryPrivateKeyStore())}\n })\n identifier = await memoryKMS..didManagerCreate({provider, alias, kms: opts?.kms})*/\n } else if (createRequest.options.storeSecrets || opts?.storeSecrets) {\n identifier = await context.agent.didManagerCreate({ provider, alias, kms: opts?.kms })\n state = 'finished'\n } else {\n return sendErrorResponse(response, 400, 'Only storeSecrets mode is supported currently')\n }\n }\n if (!identifier || !state) {\n return sendErrorResponse(response, 400, 'An identifier and did state should be present at this point')\n }\n\n const didDocument = toDidDocument(identifier, { did, use: [JwkKeyUse.Signature, JwkKeyUse.Encryption] })\n const createState: CreateState = {\n jobId,\n didState: {\n did: identifier.did,\n state,\n didDocument,\n },\n }\n response.statusCode = 200\n return response.send(createState)\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n\nexport function getDidMethodsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Get DID methods endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/methods'\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const methods = await getAgentDIDMethods(context) // these are already without the 'did:' prefix\n response.statusCode = 200\n return response.send(methods)\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n\nasync function agentDidToResolutionResult(context: IRequiredContext, did: string) {\n try {\n const identifier = await context.agent.didManagerGet({ did })\n debug(JSON.stringify(identifier, null, 2))\n return toDidResolutionResult(identifier, {\n did,\n supportedMethods: await getAgentDIDMethods(context),\n })\n } catch (error) {\n console.log(JSON.stringify(error.message))\n return {\n didDocument: null,\n didResolutionMetadata: {\n error: 'notFound',\n },\n didDocumentMetadata: {},\n }\n }\n}\n\nexport function resolveDidEndpoint(router: Router, context: IRequiredContext, opts?: IResolveEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Resolve DID endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/identifiers/:identifier'\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const did = request.params.identifier\n if (!did) {\n return sendErrorResponse(response, 400, 'no identifier provided')\n }\n const mode = request.query.mode?.toString().toLowerCase() ?? opts?.mode?.toLowerCase() ?? 'hybrid'\n let resolutionResult: DIDResolutionResult | undefined\n if (mode === 'local' || mode === 'hybrid') {\n resolutionResult = await agentDidToResolutionResult(context, did)\n }\n if (mode !== 'local' && !resolutionResult?.didDocument) {\n resolutionResult = await context.agent.resolveDid({ didUrl: did })\n }\n\n response.statusCode = 200\n return response.send(resolutionResult)\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n\n/**\n * @param router\n * @param context\n * @param opts\n */\nexport function deleteDidEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`Deactivate DID endpoint is disabled`)\n return\n }\n router.delete(opts?.path ?? '/identifiers/:identifier', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const did = request.params.identifier\n if (!did) {\n return sendErrorResponse(response, 400, 'no DID provided')\n }\n\n const result = await context.agent.didManagerDelete({ did })\n if (!result) {\n return sendErrorResponse(response, 404, `id ${did} not found`)\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\nexport function deactivateDidEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log('Deactivate DID endpoint is disabled')\n return\n }\n\n router.post(opts?.path ?? '/deactivate', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const deactivateRequest: DidRegistrationDeactivateRequest = request.body\n if (!deactivateRequest) {\n return sendErrorResponse(response, 400, 'Invalid request body', { state: 'failed' })\n }\n\n const { did, jobId = v4() } = deactivateRequest\n if (!did) {\n return sendErrorResponse(response, 400, 'No DID provided', { state: 'failed' })\n }\n\n const result = await context.agent.didManagerDelete({ did })\n if (!result) {\n return sendErrorResponse(response, 404, `DID ${did} not found`, { state: 'failed' })\n }\n\n response.status(200).json({\n state: 'finished',\n did,\n jobId,\n })\n return response.send()\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, { state: 'failed', errorDetails: e })\n }\n })\n}\n\n/**\n * Endpoint that eases DID web resolution, by mapping did-web paths to stored agent DIDs.\n *\n * Typically, you will have a reverse proxy or load balancer in front of this endpoint.\n *\n * Some examples of how did:web behaves:\n * did:web:example.com resolves to https://example.com/.well-known/did.json\n * did:web:example.com:sub:paths resolves to https://example.com/sub/paths/did.json\n *\n * This endpoint translate both forms by looking at the paths that end in /did.json.\n *\n * @param router\n * @param context\n * @param opts\n */\nexport function didWebDomainEndpoint(router: Router, context: IRequiredContext, opts?: IGlobalDidWebEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`DID Web domain resolution endpoint is disabled`)\n return\n }\n router.get(opts?.path ?? ':path(*)/did.json', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const path = request.params.path\n if (!path || path.length === 0) {\n return sendErrorResponse(response, 404, 'Not found')\n }\n let did: string\n did = `did:web:${opts?.hostname?.replace('https://', '')?.replace('http://', '') ?? request.hostname}`\n if (path !== '/.well-known') {\n if (opts?.disableSubPaths) {\n return sendErrorResponse(response, 404, 'Not found')\n }\n const suffix = path.replace(/\\//g, ':').replace(/%2F/g, ':')\n if (!suffix.startsWith(':')) {\n did += ':'\n }\n did += suffix\n } else if (opts?.disableWellKnown) {\n return sendErrorResponse(response, 404, 'Not found')\n }\n\n const resolutionResult = await agentDidToResolutionResult(context, did)\n if (!resolutionResult || !resolutionResult.didDocument || resolutionResult?.didResolutionMetadata?.error === 'notFound') {\n return sendErrorResponse(response, 404, 'Not found')\n }\n response.statusCode = 200\n return response.send(resolutionResult.didDocument)\n } catch (e) {\n return sendErrorResponse(response, 500, e.message as string, e)\n }\n })\n}\n","import { agentContext } from '@sphereon/ssi-sdk.core'\nimport { copyGlobalAuthToEndpoints, ExpressSupport } from '@sphereon/ssi-express-support'\nimport { TAgent } from '@veramo/core'\n\nimport express, { Express, Router } from 'express'\nimport { createDidEndpoint, deleteDidEndpoint, deactivateDidEndpoint, getDidMethodsEndpoint, resolveDidEndpoint } from './api-functions'\nimport { IDidAPIOpts, IRequiredPlugins } from './types'\n\nexport class UniResolverApiServer {\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?: IDidAPIOpts\n private readonly _router: Router\n\n constructor(args: { agent: TAgent<IRequiredPlugins>; expressSupport: ExpressSupport; opts?: IDidAPIOpts }) {\n const { agent, opts } = args\n this._agent = agent\n copyGlobalAuthToEndpoints({ opts, keys: ['getDidMethods', 'createDid', 'resolveDid', 'deactivateDid'] })\n this._opts = opts\n this._express = args.expressSupport.express\n this._router = express.Router()\n const context = agentContext(agent)\n const features = opts?.enableFeatures ?? ['did-resolve', 'did-persist']\n console.log(`DID Uni Resolver and Registrar API enabled, with features: ${JSON.stringify(features)}}`)\n\n // DID endpoints\n if (features.includes('did-resolve')) {\n resolveDidEndpoint(this.router, context, opts?.endpointOpts?.resolveDid)\n getDidMethodsEndpoint(this.router, context, opts?.endpointOpts?.getDidMethods)\n }\n if (features.includes('did-persist')) {\n createDidEndpoint(this.router, context, opts?.endpointOpts?.createDid)\n deleteDidEndpoint(this.router, context, opts?.endpointOpts?.deactivateDid) // not in spec.\n deactivateDidEndpoint(this.router, context, opts?.endpointOpts?.deactivateDid)\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(): IDidAPIOpts | undefined {\n return this._opts\n }\n\n get express(): Express {\n return this._express\n }\n}\n","import { agentContext } from '@sphereon/ssi-sdk.core'\nimport { ExpressSupport } from '@sphereon/ssi-express-support'\nimport { TAgent } from '@veramo/core'\n\nimport express, { Express, Router } from 'express'\nimport { didWebDomainEndpoint } from './api-functions'\nimport { IDidWebServiceOpts, IRequiredPlugins } from './types'\n\nexport class DidWebServer {\n get router(): express.Router | undefined {\n return this._router\n }\n\n private readonly _express: Express | undefined\n private readonly _agent: TAgent<IRequiredPlugins> | undefined\n private readonly _opts?: IDidWebServiceOpts\n private readonly _router: Router | undefined\n\n constructor(args: { agent: TAgent<IRequiredPlugins>; expressSupport: ExpressSupport; opts?: IDidWebServiceOpts }) {\n const { agent, opts } = args\n const features = opts?.enableFeatures ?? []\n if (!features.includes('did-web-global-resolution')) {\n console.log('did:web hosting service NOT enabled')\n return\n }\n\n this._agent = agent\n if (opts?.globalAuth) {\n copyGlobalAuthToEndpoint(opts, 'endpointOpts')\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 console.log(`did:web hosting service enabled`)\n\n didWebDomainEndpoint(this.router!, context, opts?.endpointOpts)\n this._express.use(this.router!)\n }\n\n get agent(): TAgent<IRequiredPlugins> | undefined {\n return this._agent\n }\n\n get opts(): IDidWebServiceOpts | undefined {\n return this._opts\n }\n\n get express(): Express | undefined {\n return this._express\n }\n}\n\nfunction copyGlobalAuthToEndpoint(opts: IDidWebServiceOpts, key: string) {\n if (opts?.globalAuth) {\n // @ts-ignore\n opts[key] = {\n ...opts?.globalAuth,\n // @ts-ignore\n ...opts[key],\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;ACCA,yBAAyE;AACzE,IAAAA,sBAA0B;AAC1B,iCAAkE;AAClE,uBAAyB;AAGzB,kBAAmB;AAWnB,mBAAkB;AAElB,IAAMC,YAAQC,aAAAA,SAAM,yCAAA;AAEb,SAASC,kBAAkB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D,WAAO,KAAKJ;EACd;EAEA,IAAIK,OAAuC;AACzC,WAAO,KAAKJ;EACd;EAEA,IAAIa,UAA+B;AACjC,WAAO,KAAKf;EACd;AACF;AAEA,SAASa,yBAAyBP,MAA0BgB,KAAW;AACrE,MAAIhB,MAAMM,YAAY;AAEpBN,SAAKgB,GAAAA,IAAO;MACV,GAAGhB,MAAMM;;MAET,GAAGN,KAAKgB,GAAAA;IACV;EACF;AACF;AATST;","names":["import_ssi_sdk_ext","debug","Debug","createDidEndpoint","router","context","opts","enabled","console","log","path","post","checkAuth","endpoint","request","response","createRequest","body","sendErrorResponse","did","didMethod","query","method","parseDid","defaultMethod","allDidMethods","getAgentDIDMethods","includes","provider","jobId","v4","alias","undefined","id","identifier","state","noErrorOnExistingDid","agent","didManagerGet","e","options","storeSecrets","didManagerCreate","kms","didDocument","toDidDocument","use","JwkKeyUse","Signature","Encryption","createState","didState","statusCode","send","message","getDidMethodsEndpoint","get","methods","agentDidToResolutionResult","JSON","stringify","toDidResolutionResult","supportedMethods","error","didResolutionMetadata","didDocumentMetadata","resolveDidEndpoint","params","mode","toString","toLowerCase","resolutionResult","resolveDid","didUrl","deleteDidEndpoint","delete","result","didManagerDelete","deactivateDidEndpoint","deactivateRequest","status","json","errorDetails","didWebDomainEndpoint","length","hostname","replace","disableSubPaths","suffix","startsWith","disableWellKnown","import_ssi_express_support","UniResolverApiServer","router","_router","_express","_agent","_opts","constructor","args","agent","opts","copyGlobalAuthToEndpoints","keys","expressSupport","express","Router","context","agentContext","features","enableFeatures","console","log","JSON","stringify","includes","resolveDidEndpoint","endpointOpts","resolveDid","getDidMethodsEndpoint","getDidMethods","createDidEndpoint","createDid","deleteDidEndpoint","deactivateDid","deactivateDidEndpoint","use","basePath","import_ssi_sdk","import_express","DidWebServer","router","_router","_express","_agent","_opts","constructor","args","agent","opts","features","enableFeatures","includes","console","log","globalAuth","copyGlobalAuthToEndpoint","expressSupport","express","Router","context","agentContext","didWebDomainEndpoint","endpointOpts","use","key"]}
@@ -0,0 +1,161 @@
1
+ import { DIDDocument } from '@sphereon/did-uni-client';
2
+ import { GenericAuthArgs, ISingleEndpointOpts, ExpressSupport } from '@sphereon/ssi-express-support';
3
+ import { JsonWebKey } from '@sphereon/ssi-types';
4
+ import { IDataStoreORM, IDIDManager, IKeyManager, IResolver, IAgentContext, TAgent } from '@veramo/core';
5
+ import { VerificationMethod } from 'did-resolver';
6
+ import express, { Router, Express } from 'express';
7
+
8
+ type IRequiredPlugins = IDataStoreORM & IDIDManager & IKeyManager & IResolver;
9
+ type IRequiredContext = IAgentContext<IRequiredPlugins>;
10
+ interface DidRegistrationCreateRequest {
11
+ did?: string;
12
+ jobId: string;
13
+ options: DidRegistrationOptions;
14
+ secret: DidRegistrationSecret;
15
+ didDocument?: DIDDocument;
16
+ }
17
+ interface DidRegistrationUpdateRequest {
18
+ did: string;
19
+ jobId: string;
20
+ options: DidRegistrationOptions;
21
+ secret: DidRegistrationSecret;
22
+ didDocumentOperation: DidDocumentOperation[];
23
+ didDocument?: DIDDocument[];
24
+ }
25
+ interface DidRegistrationDeactivateRequest {
26
+ did: string;
27
+ jobId?: string;
28
+ options?: DidRegistrationOptions;
29
+ secret?: DidRegistrationSecret;
30
+ }
31
+ type DidDocumentOperation = 'setDidDocument' | 'addToDidDocument' | 'removeFromDidDocument' | string;
32
+ interface DidRegistrationOptions {
33
+ network?: string;
34
+ storeSecrets?: boolean;
35
+ returnSecrets?: boolean;
36
+ [x: string]: any;
37
+ }
38
+ interface DidRegistrationSecret {
39
+ seed?: string;
40
+ verificationMethod?: CreateVerificationMethod[];
41
+ [x: string]: any;
42
+ }
43
+ interface CreateVerificationMethod extends VerificationMethod {
44
+ privateKeyBase58?: string;
45
+ privateKeyBase64?: string;
46
+ privateKeyJwk?: JsonWebKey;
47
+ privateKeyHex?: string;
48
+ privateKeyMultibase?: string;
49
+ purpose?: ('authentication' | 'assertionMethod' | 'capabilityDelegation' | 'capabilityInvocation')[];
50
+ }
51
+ interface CreateState {
52
+ jobId: string;
53
+ didState: DidState;
54
+ didRegistrationMetadata?: Record<string, any>;
55
+ didDocumentMetadata?: Record<string, any>;
56
+ }
57
+ type DidStateValue = 'finished' | 'failed' | 'action' | 'wait' | 'exists';
58
+ type DidStateAction = 'redirect' | 'getVerificationMethod' | 'signPayload' | 'decryptPayload';
59
+ interface DidState {
60
+ state: DidStateValue;
61
+ action?: DidStateAction;
62
+ wait?: string;
63
+ waitTime?: number;
64
+ did: string;
65
+ secret?: DidRegistrationSecret;
66
+ didDocument?: DIDDocument;
67
+ }
68
+ interface IDidWebServiceOpts {
69
+ globalAuth?: GenericAuthArgs;
70
+ endpointOpts?: IGlobalDidWebEndpointOpts;
71
+ enableFeatures?: DidWebServiceFeatures[];
72
+ }
73
+ interface IDidAPIOpts {
74
+ endpointOpts?: IDidAPIEndpointOpts;
75
+ enableFeatures?: DidApiFeatures[];
76
+ }
77
+ interface IDidAPIEndpointOpts {
78
+ basePath?: string;
79
+ globalAuth?: GenericAuthArgs;
80
+ createDid?: ICreateDidEndpointOpts;
81
+ resolveDid?: IResolveEndpointOpts;
82
+ deactivateDid?: ISingleEndpointOpts;
83
+ getDidMethods?: ISingleEndpointOpts;
84
+ }
85
+ interface IGlobalDidWebEndpointOpts extends ISingleEndpointOpts {
86
+ hostname?: string;
87
+ disableWellKnown?: boolean;
88
+ disableSubPaths?: boolean;
89
+ }
90
+ interface ICreateDidEndpointOpts extends ISingleEndpointOpts {
91
+ kms?: string;
92
+ storeSecrets?: boolean;
93
+ noErrorOnExistingDid?: boolean;
94
+ defaultMethod?: string;
95
+ }
96
+ interface IResolveEndpointOpts extends ISingleEndpointOpts {
97
+ mode?: 'local' | 'hybrid' | 'global';
98
+ }
99
+ type DidWebServiceFeatures = 'did-web-global-resolution';
100
+ type DidApiFeatures = 'did-resolve' | 'did-persist';
101
+
102
+ declare function createDidEndpoint(router: Router, context: IRequiredContext, opts?: ICreateDidEndpointOpts): void;
103
+ declare function getDidMethodsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
104
+ declare function resolveDidEndpoint(router: Router, context: IRequiredContext, opts?: IResolveEndpointOpts): void;
105
+ /**
106
+ * @param router
107
+ * @param context
108
+ * @param opts
109
+ */
110
+ declare function deleteDidEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
111
+ declare function deactivateDidEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
112
+ /**
113
+ * Endpoint that eases DID web resolution, by mapping did-web paths to stored agent DIDs.
114
+ *
115
+ * Typically, you will have a reverse proxy or load balancer in front of this endpoint.
116
+ *
117
+ * Some examples of how did:web behaves:
118
+ * did:web:example.com resolves to https://example.com/.well-known/did.json
119
+ * did:web:example.com:sub:paths resolves to https://example.com/sub/paths/did.json
120
+ *
121
+ * This endpoint translate both forms by looking at the paths that end in /did.json.
122
+ *
123
+ * @param router
124
+ * @param context
125
+ * @param opts
126
+ */
127
+ declare function didWebDomainEndpoint(router: Router, context: IRequiredContext, opts?: IGlobalDidWebEndpointOpts): void;
128
+
129
+ declare class UniResolverApiServer {
130
+ get router(): express.Router;
131
+ private readonly _express;
132
+ private readonly _agent;
133
+ private readonly _opts?;
134
+ private readonly _router;
135
+ constructor(args: {
136
+ agent: TAgent<IRequiredPlugins>;
137
+ expressSupport: ExpressSupport;
138
+ opts?: IDidAPIOpts;
139
+ });
140
+ get agent(): TAgent<IRequiredPlugins>;
141
+ get opts(): IDidAPIOpts | undefined;
142
+ get express(): Express;
143
+ }
144
+
145
+ declare class DidWebServer {
146
+ get router(): express.Router | undefined;
147
+ private readonly _express;
148
+ private readonly _agent;
149
+ private readonly _opts?;
150
+ private readonly _router;
151
+ constructor(args: {
152
+ agent: TAgent<IRequiredPlugins>;
153
+ expressSupport: ExpressSupport;
154
+ opts?: IDidWebServiceOpts;
155
+ });
156
+ get agent(): TAgent<IRequiredPlugins> | undefined;
157
+ get opts(): IDidWebServiceOpts | undefined;
158
+ get express(): Express | undefined;
159
+ }
160
+
161
+ export { type CreateState, type CreateVerificationMethod, type DidApiFeatures, type DidDocumentOperation, type DidRegistrationCreateRequest, type DidRegistrationDeactivateRequest, type DidRegistrationOptions, type DidRegistrationSecret, type DidRegistrationUpdateRequest, type DidState, type DidStateAction, type DidStateValue, DidWebServer, type DidWebServiceFeatures, type ICreateDidEndpointOpts, type IDidAPIEndpointOpts, type IDidAPIOpts, type IDidWebServiceOpts, type IGlobalDidWebEndpointOpts, type IRequiredContext, type IRequiredPlugins, type IResolveEndpointOpts, UniResolverApiServer, createDidEndpoint, deactivateDidEndpoint, deleteDidEndpoint, didWebDomainEndpoint, getDidMethodsEndpoint, resolveDidEndpoint };