@sphereon/ssi-sdk.uni-resolver-registrar-api 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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [2021] [Sphereon BV]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,65 @@
1
+ <!--suppress HtmlDeprecatedAttribute -->
2
+ <h1 align="center">
3
+ <br>
4
+ <a href="https://www.sphereon.com"><img src="https://sphereon.com/content/themes/sphereon/assets/img/logo.svg" alt="Sphereon" width="400"></a>
5
+ <br>SIOPv2 and OpenID4VP Relying Party REST endpoints
6
+ <br>
7
+ </h1>
8
+
9
+ ---
10
+
11
+ **Warning: This package still is in very early development. Breaking changes without notice will happen at this point!**
12
+
13
+ ---
14
+
15
+ An authentication plugin using the [Self Issued OpenID Provider v2 (SIOP)](https://github.com/Sphereon-Opensource/did-auth-siop) authentication library for having Relying Parties conforming to
16
+ the [Self Issued OpenID Provider v2 (SIOPv2)](https://openid.net/specs/openid-connect-self-issued-v2-1_0.html)
17
+ and [OpenID Connect for Verifiable Presentations (OIDC4VP)](https://openid.net/specs/openid-connect-4-verifiable-presentations-1_0.html)
18
+ as specified in the OpenID Connect working group.
19
+
20
+ ## Self Issued OpenID Provider v2 (SIOPv2)
21
+
22
+ For more information about [Self Issued OpenID Provider v2 (SIOP)](https://github.com/Sphereon-Opensource/did-auth-siop#introduction), see the documentation in the readme.
23
+
24
+ ## Requirements
25
+
26
+ For this plugin a DID resolver is also required. A DID resolver can be added to the agent as plugin as seen in the example below.
27
+
28
+ ## Available functions
29
+
30
+ ## Usage
31
+
32
+ ### Adding the plugin to an agent:
33
+
34
+ ```typescript
35
+ import { IDidAuthSiopOpAuthenticator } from '@sphereon/ssi-sdk-did-auth-siop-authenticator'
36
+ import { Resolver } from 'did-resolver'
37
+ import { getDidKeyResolver } from '@veramo/did-provider-key'
38
+ import { DIDResolverPlugin } from '@veramo/did-resolver'
39
+ import { getUniResolver } from '@sphereon/did-uni-client'
40
+
41
+ const agent = createAgent<IDidAuthSiopOpAuthenticator & IResolver>({
42
+ plugins: [
43
+ new DidAuthSiopOpAuthenticator(),
44
+ new DIDResolverPlugin({
45
+ resolver: new Resolver({
46
+ ...getDidKeyResolver(),
47
+ ...getUniResolver('web'),
48
+ ...getUniResolver('jwk'),
49
+ }),
50
+ }),
51
+ ],
52
+ })
53
+ ```
54
+
55
+ ## Installation
56
+
57
+ ```shell
58
+ yarn add @sphereon/ssi-sdk-siopv2-openid4vp-rp
59
+ ```
60
+
61
+ ## Build
62
+
63
+ ```shell
64
+ yarn build
65
+ ```
@@ -0,0 +1,12 @@
1
+ import { ISingleEndpointOpts } from '@sphereon/ssi-sdk.express-support';
2
+ import { Router } from 'express';
3
+ import { IRequiredContext } from './types';
4
+ export declare function createDidEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts & {
5
+ kms?: string;
6
+ }): void;
7
+ export declare function getDidMethodsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
8
+ export declare function resolveDidEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts & {
9
+ mode?: 'local' | 'resolve';
10
+ }): void;
11
+ export declare function deactivateDidEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
12
+ //# sourceMappingURL=api-functions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-functions.d.ts","sourceRoot":"","sources":["../src/api-functions.ts"],"names":[],"mappings":"AAGA,OAAO,EAAa,mBAAmB,EAAqB,MAAM,mCAAmC,CAAA;AAGrG,OAAO,EAAqB,MAAM,EAAE,MAAM,SAAS,CAAA;AAEnD,OAAO,EAA6C,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAErF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE,mBAAmB,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,QA+DzH;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE,mBAAmB,QAe1G;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE,mBAAmB,GAAG;IAAE,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAAE,QA0CxI;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE,mBAAmB,QAsB1G"}
@@ -0,0 +1,177 @@
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.deactivateDidEndpoint = exports.resolveDidEndpoint = exports.getDidMethodsEndpoint = exports.createDidEndpoint = void 0;
13
+ const ssi_sdk_ext_did_utils_1 = require("@sphereon/ssi-sdk-ext.did-utils");
14
+ const ssi_sdk_ext_key_utils_1 = require("@sphereon/ssi-sdk-ext.key-utils");
15
+ const ssi_sdk_express_support_1 = require("@sphereon/ssi-sdk.express-support");
16
+ const ssi_types_1 = require("@sphereon/ssi-types");
17
+ const uuid_1 = require("uuid");
18
+ function createDidEndpoint(router, context, opts) {
19
+ var _a;
20
+ if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
21
+ console.log(`create DID endpoint is disabled`);
22
+ return;
23
+ }
24
+ const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/identifiers';
25
+ router.post(path, (0, ssi_sdk_express_support_1.checkAuth)(opts === null || opts === void 0 ? void 0 : opts.endpoint), (request, response) => __awaiter(this, void 0, void 0, function* () {
26
+ var _b, _c;
27
+ try {
28
+ const createRequest = request.body;
29
+ if (!createRequest) {
30
+ return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 400, 'No DID create request present');
31
+ }
32
+ const did = createRequest.did;
33
+ const didMethod = (_b = request.query.method) !== null && _b !== void 0 ? _b : (did ? (0, ssi_types_1.parseDid)(did).method : undefined);
34
+ const allDidMethods = yield (0, ssi_sdk_ext_did_utils_1.getAgentDIDMethods)(context);
35
+ if (!didMethod) {
36
+ return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 400, 'No DID method supplied or deductible');
37
+ }
38
+ else if (did && (0, ssi_types_1.parseDid)(did).method != didMethod) {
39
+ return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 400, 'DID method did not match method param');
40
+ }
41
+ else if (!allDidMethods.includes(didMethod)) {
42
+ return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 400, 'DID method not supported');
43
+ }
44
+ const provider = `did:${didMethod}`;
45
+ const jobId = (_c = createRequest.jobId) !== null && _c !== void 0 ? _c : `urn:uuid:${(0, uuid_1.v4)()}`;
46
+ let alias = undefined;
47
+ if (didMethod === 'web') {
48
+ if (!did) {
49
+ throw Error('Please provide a value for "did" in the request body when creating a DID web');
50
+ }
51
+ alias = (0, ssi_types_1.parseDid)(did).id;
52
+ if (!alias) {
53
+ throw Error('Could not determine alias from did:web DID value: ' + did);
54
+ }
55
+ }
56
+ let identifier;
57
+ if (createRequest.options.storeSecrets === false) {
58
+ throw Error('Not storing secrets mode is not support yet');
59
+ /*const memoryKMS = new SphereonKeyManager({
60
+ store: new MemoryKeyStore(),
61
+ kms: {'mem': new KeyManagementSystem(new MemoryPrivateKeyStore())}
62
+ })
63
+ identifier = await memoryKMS..didManagerCreate({provider, alias, kms: opts?.kms})*/
64
+ }
65
+ else {
66
+ identifier = yield context.agent.didManagerCreate({ provider, alias, kms: opts === null || opts === void 0 ? void 0 : opts.kms });
67
+ }
68
+ const didDocument = (0, ssi_sdk_ext_did_utils_1.toDidDocument)(identifier, { did, use: [ssi_sdk_ext_key_utils_1.JwkKeyUse.Signature, ssi_sdk_ext_key_utils_1.JwkKeyUse.Encryption] });
69
+ const createState = {
70
+ jobId,
71
+ didState: {
72
+ did: identifier.did,
73
+ state: 'finished',
74
+ didDocument,
75
+ },
76
+ };
77
+ response.statusCode = 200;
78
+ return response.send(createState);
79
+ }
80
+ catch (e) {
81
+ return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 500, e.message, e);
82
+ }
83
+ }));
84
+ }
85
+ exports.createDidEndpoint = createDidEndpoint;
86
+ function getDidMethodsEndpoint(router, context, opts) {
87
+ var _a;
88
+ if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
89
+ console.log(`Get DID methods endpoint is disabled`);
90
+ return;
91
+ }
92
+ const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/methods';
93
+ 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* () {
94
+ try {
95
+ const methods = yield (0, ssi_sdk_ext_did_utils_1.getAgentDIDMethods)(context); // these are already without the 'did:' prefix
96
+ response.statusCode = 200;
97
+ return response.send(methods);
98
+ }
99
+ catch (e) {
100
+ return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 500, e.message, e);
101
+ }
102
+ }));
103
+ }
104
+ exports.getDidMethodsEndpoint = getDidMethodsEndpoint;
105
+ function resolveDidEndpoint(router, context, opts) {
106
+ var _a;
107
+ if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
108
+ console.log(`Resolve DID endpoint is disabled`);
109
+ return;
110
+ }
111
+ const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/identifiers/:identifier';
112
+ 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* () {
113
+ var _b, _c, _d;
114
+ try {
115
+ const did = request.params.identifier;
116
+ if (!did) {
117
+ return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 400, 'no identifier provided');
118
+ }
119
+ const mode = (_c = (_b = request.query.mode) === null || _b === void 0 ? void 0 : _b.toString().toLowerCase()) !== null && _c !== void 0 ? _c : (_d = opts === null || opts === void 0 ? void 0 : opts.mode) === null || _d === void 0 ? void 0 : _d.toLowerCase();
120
+ let resolutionResult;
121
+ if (mode === 'local' || mode === 'hybrid') {
122
+ try {
123
+ const identifier = yield context.agent.didManagerGet({ did });
124
+ console.log(JSON.stringify(identifier, null, 2));
125
+ resolutionResult = (0, ssi_sdk_ext_did_utils_1.toDidResolutionResult)(identifier, {
126
+ did,
127
+ supportedMethod: yield (0, ssi_sdk_ext_did_utils_1.getAgentDIDMethods)(context),
128
+ });
129
+ }
130
+ catch (error) {
131
+ resolutionResult = {
132
+ didDocument: null,
133
+ didResolutionMetadata: {
134
+ error: 'notFound',
135
+ },
136
+ didDocumentMetadata: {},
137
+ };
138
+ }
139
+ }
140
+ if (mode !== 'local' && !(resolutionResult === null || resolutionResult === void 0 ? void 0 : resolutionResult.didDocument)) {
141
+ resolutionResult = yield context.agent.resolveDid({ didUrl: did });
142
+ }
143
+ response.statusCode = 200;
144
+ return response.send(resolutionResult);
145
+ }
146
+ catch (e) {
147
+ return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 500, e.message, e);
148
+ }
149
+ }));
150
+ }
151
+ exports.resolveDidEndpoint = resolveDidEndpoint;
152
+ function deactivateDidEndpoint(router, context, opts) {
153
+ var _a;
154
+ if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
155
+ console.log(`Deactivate DID endpoint is disabled`);
156
+ return;
157
+ }
158
+ router.delete((_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/identifiers/:identifier', (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* () {
159
+ try {
160
+ const did = request.params.identifier;
161
+ if (!did) {
162
+ return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 400, 'no DID provided');
163
+ }
164
+ const result = yield context.agent.didManagerDelete({ did });
165
+ if (!result) {
166
+ return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 404, `id ${did} not found`);
167
+ }
168
+ response.statusCode = 200;
169
+ return response.send();
170
+ }
171
+ catch (e) {
172
+ return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 500, e.message, e);
173
+ }
174
+ }));
175
+ }
176
+ exports.deactivateDidEndpoint = deactivateDidEndpoint;
177
+ //# sourceMappingURL=api-functions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-functions.js","sourceRoot":"","sources":["../src/api-functions.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,2EAA0G;AAC1G,2EAA2D;AAC3D,+EAAqG;AACrG,mDAA8C;AAG9C,+BAAyB;AAGzB,SAAgB,iBAAiB,CAAC,MAAc,EAAE,OAAyB,EAAE,IAA6C;;IACxH,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,MAAK,KAAK,EAAE;QAC3B,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAA;QAC9C,OAAM;KACP;IACD,MAAM,IAAI,GAAG,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,mCAAI,cAAc,CAAA;IAEzC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAA,mCAAS,EAAC,IAAI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A;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;AAtBD,sDAsBC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @public
3
+ */
4
+ export * from './uni-resolver-api-server';
5
+ export * from './types';
6
+ export * from './api-functions';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,2BAA2B,CAAA;AACzC,cAAc,SAAS,CAAA;AACvB,cAAc,iBAAiB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /**
18
+ * @public
19
+ */
20
+ __exportStar(require("./uni-resolver-api-server"), exports);
21
+ __exportStar(require("./types"), exports);
22
+ __exportStar(require("./api-functions"), exports);
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,4DAAyC;AACzC,0CAAuB;AACvB,kDAA+B"}
@@ -0,0 +1,106 @@
1
+ import { DIDDocument } from '@sphereon/did-uni-client';
2
+ import { GenericAuthArgs, ISingleEndpointOpts } from '@sphereon/ssi-sdk.express-support';
3
+ import { IAgentContext, IDataStore, IDataStoreORM, IDIDManager, IKeyManager, IResolver } from '@veramo/core';
4
+ import { ProofFormat } from '@veramo/core/src/types/ICredentialIssuer';
5
+ import { VerificationMethod } from 'did-resolver';
6
+ export type IRequiredPlugins = IDataStore & IDataStoreORM & IDIDManager & IKeyManager & IResolver;
7
+ export type IRequiredContext = IAgentContext<IRequiredPlugins>;
8
+ export interface DidRegistrationCreateRequest {
9
+ did?: string;
10
+ jobId: string;
11
+ options: DidRegistrationOptions;
12
+ secret: DidRegistrationSecret;
13
+ didDocument?: DIDDocument;
14
+ }
15
+ export interface DidRegistrationUpdateRequest {
16
+ did: string;
17
+ jobId: string;
18
+ options: DidRegistrationOptions;
19
+ secret: DidRegistrationSecret;
20
+ didDocumentOperation: DidDocumentOperation[];
21
+ didDocument?: DIDDocument[];
22
+ }
23
+ export interface DidRegistrationDeactivateRequest {
24
+ did: string;
25
+ jobId: string;
26
+ options: DidRegistrationOptions;
27
+ secret: DidRegistrationSecret;
28
+ }
29
+ export type DidDocumentOperation = 'setDidDocument' | 'addToDidDocument' | 'removeFromDidDocument' | string;
30
+ export interface DidRegistrationOptions {
31
+ network?: string;
32
+ storeSecrets?: boolean;
33
+ returnSecrets?: boolean;
34
+ [x: string]: any;
35
+ }
36
+ export interface DidRegistrationSecret {
37
+ seed?: string;
38
+ verificationMethod?: CreateVerificationMethod[];
39
+ [x: string]: any;
40
+ }
41
+ export interface CreateVerificationMethod extends VerificationMethod {
42
+ privateKeyBase58?: string;
43
+ privateKeyBase64?: string;
44
+ privateKeyJwk?: JsonWebKey;
45
+ privateKeyHex?: string;
46
+ privateKeyMultibase?: string;
47
+ purpose?: ('authentication' | 'assertionMethod' | 'capabilityDelegation' | 'capabilityInvocation')[];
48
+ }
49
+ export interface CreateState {
50
+ jobId: string;
51
+ didState: DidState;
52
+ didRegistrationMetadata?: Record<string, any>;
53
+ didDocumentMetadata?: Record<string, any>;
54
+ }
55
+ export interface DidState {
56
+ state: 'finished' | 'failed' | 'action' | 'wait';
57
+ action?: 'redirect' | 'getVerificationMethod' | 'signPayload' | 'decryptPayload';
58
+ wait?: string;
59
+ waitTime?: number;
60
+ did: string;
61
+ secret?: DidRegistrationSecret;
62
+ didDocument?: DIDDocument;
63
+ }
64
+ export interface IDidAPIOpts {
65
+ endpointOpts?: IDidAPIEndpointOpts;
66
+ didOpts?: IVCAPIIssueOpts;
67
+ }
68
+ export interface IDidAPIEndpointOpts {
69
+ basePath?: string;
70
+ globalAuth?: GenericAuthArgs;
71
+ createDid?: ISingleEndpointOpts;
72
+ resolveDid?: ISingleEndpointOpts;
73
+ deactivateDid?: ISingleEndpointOpts;
74
+ getDidMethods?: ISingleEndpointOpts;
75
+ }
76
+ export declare enum IVCIApiFeatures {
77
+ DID_RESOLVE = "did-resolve",
78
+ DID_PERSISTENCE = "did-persist"
79
+ }
80
+ export interface IVCAPIIssueOpts {
81
+ enableFeatures?: IVCIApiFeatures[];
82
+ persistIssuedCredentials?: boolean;
83
+ /**
84
+ * The desired format for the VerifiablePresentation to be created.
85
+ */
86
+ proofFormat: ProofFormat;
87
+ /**
88
+ * Remove payload members during JWT-JSON transformation. Defaults to `true`.
89
+ * See https://www.w3.org/TR/vc-data-model/#jwt-encoding
90
+ */
91
+ removeOriginalFields?: boolean;
92
+ /**
93
+ * [Optional] The ID of the key that should sign this credential.
94
+ * If this is not specified, the first matching key will be used.
95
+ */
96
+ keyRef?: string;
97
+ /**
98
+ * When dealing with JSON-LD you also MUST provide the proper contexts.
99
+ * Set this to `true` ONLY if you want the `@context` URLs to be fetched in case they are not preloaded.
100
+ * The context definitions SHOULD rather be provided at startup instead of being fetched.
101
+ *
102
+ * Defaults to `false`
103
+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AC,EAAE,MAAM,CAAA;IACjB,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,CAAC,EAAE,qBAAqB,CAAA;IAC9B,WAAW,CAAC,EAAE,WAAW,CAAA;CAC1B;AAED,MAAM,WAAW,WAAW;IAC1B,YAAY,CAAC,EAAE,mBAAmB,CAAA;IAClC,OAAO,CAAC,EAAE,eAAe,CAAA;CAC1B;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,eAAe,CAAA;IAC5B,SAAS,CAAC,EAAE,mBAAmB,CAAA;IAC/B,UAAU,CAAC,EAAE,mBAAmB,CAAA;IAChC,aAAa,CAAC,EAAE,mBAAmB,CAAA;IACnC,aAAa,CAAC,EAAE,mBAAmB,CAAA;CACpC;AAED,oBAAY,eAAe;IACzB,WAAW,gBAAgB;IAC3B,eAAe,gBAAgB;CAChC;AAED,MAAM,WAAW,eAAe;IAC9B,cAAc,CAAC,EAAE,eAAe,EAAE,CAAA;IAClC,wBAAwB,CAAC,EAAE,OAAO,CAAA;IAElC;;OAEG;IACH,WAAW,EAAE,WAAW,CAAA;IAExB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAE9B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf;;;;;;OAMG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAC9B"}
package/dist/types.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IVCIApiFeatures = void 0;
4
+ var IVCIApiFeatures;
5
+ (function (IVCIApiFeatures) {
6
+ IVCIApiFeatures["DID_RESOLVE"] = "did-resolve";
7
+ IVCIApiFeatures["DID_PERSISTENCE"] = "did-persist";
8
+ })(IVCIApiFeatures = exports.IVCIApiFeatures || (exports.IVCIApiFeatures = {}));
9
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AA0FA,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,8CAA2B,CAAA;IAC3B,kDAA+B,CAAA;AACjC,CAAC,EAHW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAG1B"}
@@ -0,0 +1,20 @@
1
+ import { ExpressBuildResult } from '@sphereon/ssi-sdk.express-support';
2
+ import { TAgent } from '@veramo/core';
3
+ import express, { Express } from 'express';
4
+ import { IDidAPIOpts, IRequiredPlugins } from './types';
5
+ export declare class UniResolverApiServer {
6
+ get router(): express.Router;
7
+ private readonly _express;
8
+ private readonly _agent;
9
+ private readonly _opts?;
10
+ private readonly _router;
11
+ constructor(args: {
12
+ agent: TAgent<IRequiredPlugins>;
13
+ expressArgs: ExpressBuildResult;
14
+ opts?: IDidAPIOpts;
15
+ });
16
+ get agent(): TAgent<IRequiredPlugins>;
17
+ get opts(): IDidAPIOpts | undefined;
18
+ get express(): Express;
19
+ }
20
+ //# sourceMappingURL=uni-resolver-api-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uni-resolver-api-server.d.ts","sourceRoot":"","sources":["../src/uni-resolver-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;AAElD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAmB,MAAM,SAAS,CAAA;AAExE,qBAAa,oBAAoB;IAC/B,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,CAAa;IACpC,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,WAAW,CAAA;KAAE;IA+B1G,IAAI,KAAK,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAEpC;IAED,IAAI,IAAI,IAAI,WAAW,GAAG,SAAS,CAElC;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;CACF"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.UniResolverApiServer = void 0;
7
+ const ssi_sdk_core_1 = require("@sphereon/ssi-sdk.core");
8
+ const express_1 = __importDefault(require("express"));
9
+ const api_functions_1 = require("./api-functions");
10
+ const types_1 = require("./types");
11
+ class UniResolverApiServer {
12
+ get router() {
13
+ return this._router;
14
+ }
15
+ constructor(args) {
16
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
17
+ const { agent, opts } = args;
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, 'getDidMethods');
21
+ copyGlobalAuthToEndpoint(opts, 'createDid');
22
+ copyGlobalAuthToEndpoint(opts, 'resolveDid');
23
+ copyGlobalAuthToEndpoint(opts, 'deactivateDid');
24
+ }
25
+ this._opts = opts;
26
+ this._express = args.expressArgs.express;
27
+ this._router = express_1.default.Router();
28
+ const context = (0, ssi_sdk_core_1.agentContext)(agent);
29
+ const features = (_c = (_b = opts === null || opts === void 0 ? void 0 : opts.didOpts) === null || _b === void 0 ? void 0 : _b.enableFeatures) !== null && _c !== void 0 ? _c : [types_1.IVCIApiFeatures.DID_RESOLVE, types_1.IVCIApiFeatures.DID_PERSISTENCE];
30
+ console.log(`DID UniResolver API enabled, with features: ${JSON.stringify(features)}`);
31
+ // DID endpoints
32
+ if (features.includes(types_1.IVCIApiFeatures.DID_RESOLVE)) {
33
+ (0, api_functions_1.resolveDidEndpoint)(this.router, context, (_d = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _d === void 0 ? void 0 : _d.resolveDid);
34
+ (0, api_functions_1.getDidMethodsEndpoint)(this.router, context, (_e = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _e === void 0 ? void 0 : _e.getDidMethods);
35
+ }
36
+ if (features.includes(types_1.IVCIApiFeatures.DID_RESOLVE)) {
37
+ (0, api_functions_1.createDidEndpoint)(this.router, context, (_f = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _f === void 0 ? void 0 : _f.createDid);
38
+ (0, api_functions_1.deactivateDidEndpoint)(this.router, context, (_g = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _g === void 0 ? void 0 : _g.deactivateDid); // not in spec.
39
+ }
40
+ this._express.use((_j = (_h = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _h === void 0 ? void 0 : _h.basePath) !== null && _j !== void 0 ? _j : '', this.router);
41
+ }
42
+ get agent() {
43
+ return this._agent;
44
+ }
45
+ get opts() {
46
+ return this._opts;
47
+ }
48
+ get express() {
49
+ return this._express;
50
+ }
51
+ }
52
+ exports.UniResolverApiServer = UniResolverApiServer;
53
+ function copyGlobalAuthToEndpoint(opts, key) {
54
+ var _a, _b;
55
+ if ((_a = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _a === void 0 ? void 0 : _a.globalAuth) {
56
+ // @ts-ignore
57
+ opts.endpointOpts[key] = Object.assign(Object.assign({}, opts.endpointOpts[key]), {
58
+ // @ts-ignore
59
+ endpoint: Object.assign(Object.assign({}, opts.endpointOpts.globalAuth), (_b = opts.endpointOpts[key]) === null || _b === void 0 ? void 0 : _b.endpoint) });
60
+ }
61
+ }
62
+ //# sourceMappingURL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AC,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 ADDED
@@ -0,0 +1,93 @@
1
+ {
2
+ "name": "@sphereon/ssi-sdk.uni-resolver-registrar-api",
3
+ "version": "0.13.1-next.23+6c616f9",
4
+ "source": "src/index.ts",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc --build",
9
+ "build:clean": "tsc --build --clean && tsc --build",
10
+ "start:prod": "node build/index.js",
11
+ "start:dev": "ts-node __tests__/agent.ts"
12
+ },
13
+ "dependencies": {
14
+ "@sphereon/ssi-sdk-ext.did-utils": "0.12.2-next.5",
15
+ "@sphereon/ssi-sdk-ext.key-manager": "0.12.2-next.5",
16
+ "@sphereon/ssi-sdk-ext.key-utils": "0.12.2-next.5",
17
+ "@sphereon/ssi-sdk.core": "0.13.1-next.23+6c616f9",
18
+ "@sphereon/ssi-sdk.express-support": "0.13.1-next.23+6c616f9",
19
+ "@sphereon/ssi-types": "0.13.1-next.23+6c616f9",
20
+ "@veramo/core": "4.2.0",
21
+ "body-parser": "^1.19.0",
22
+ "casbin": "^5.26.1",
23
+ "cookie-parser": "^1.4.5",
24
+ "cors": "^2.8.5",
25
+ "cross-fetch": "^3.1.5",
26
+ "dotenv-flow": "^3.2.0",
27
+ "express": "^4.18.2",
28
+ "short-uuid": "^4.2.2",
29
+ "uuid": "^8.3.2"
30
+ },
31
+ "devDependencies": {
32
+ "@sphereon/did-uni-client": "^0.6.0",
33
+ "@sphereon/ssi-sdk-ext.did-provider-jwk": "0.12.2-next.5",
34
+ "@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.12.2-next.5",
35
+ "@sphereon/ssi-sdk.data-store": "0.13.1-next.23+6c616f9",
36
+ "@sphereon/ssi-sdk.vc-handler-ld-local": "0.13.1-next.23+6c616f9",
37
+ "@types/body-parser": "^1.19.2",
38
+ "@types/cookie-parser": "^1.4.3",
39
+ "@types/cors": "^2.8.13",
40
+ "@types/debug": "^4.1.7",
41
+ "@types/dotenv-flow": "^3.2.0",
42
+ "@types/express": "^4.17.13",
43
+ "@types/express-http-proxy": "^1.6.3",
44
+ "@types/morgan": "^1.9.4",
45
+ "@types/node": "^18.15.0",
46
+ "@types/passport": "^1.0.12",
47
+ "@types/passport-azure-ad": "^4.3.1",
48
+ "@types/uuid": "^9.0.1",
49
+ "@veramo/data-store": "4.2.0",
50
+ "@veramo/did-manager": "4.2.0",
51
+ "@veramo/did-provider-ethr": "4.2.0",
52
+ "@veramo/did-provider-ion": "4.2.0",
53
+ "@veramo/did-provider-key": "4.2.0",
54
+ "@veramo/did-provider-web": "4.2.0",
55
+ "@veramo/did-resolver": "4.2.0",
56
+ "@veramo/key-manager": "4.2.0",
57
+ "@veramo/kms-local": "4.2.0",
58
+ "@veramo/utils": "4.2.0",
59
+ "did-resolver": "^4.1.0",
60
+ "morgan": "^1.10.0",
61
+ "nock": "^13.2.1",
62
+ "passport": "^0.6.0",
63
+ "passport-azure-ad": "^4.3.5",
64
+ "ts-node": "^10.9.1",
65
+ "typeorm": "^0.3.12",
66
+ "web-did-resolver": "^2.0.27"
67
+ },
68
+ "files": [
69
+ ".yalc/**/*",
70
+ "dist/**/*",
71
+ "src/**/*",
72
+ "README.md",
73
+ "plugin.schema.json",
74
+ "LICENSE"
75
+ ],
76
+ "private": false,
77
+ "publishConfig": {
78
+ "access": "public"
79
+ },
80
+ "repository": "git@github.com:Sphereon-Opensource/SSI-SDK.git",
81
+ "author": "Sphereon <dev@sphereon.com>",
82
+ "license": "Apache-2.0",
83
+ "keywords": [
84
+ "Sphereon",
85
+ "SSI",
86
+ "Veramo",
87
+ "DID",
88
+ "Universal Resolver",
89
+ "Inversal Registrar",
90
+ "DIF"
91
+ ],
92
+ "gitHead": "6c616f988be6a5d891c771bb59faa50d3160aa75"
93
+ }
@@ -0,0 +1,159 @@
1
+ import { DIDResolutionResult } from '@sphereon/did-uni-client'
2
+ import { getAgentDIDMethods, toDidDocument, toDidResolutionResult } from '@sphereon/ssi-sdk-ext.did-utils'
3
+ import { JwkKeyUse } from '@sphereon/ssi-sdk-ext.key-utils'
4
+ import { checkAuth, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-sdk.express-support'
5
+ import { parseDid } from '@sphereon/ssi-types'
6
+ import { IIdentifier } from '@veramo/core'
7
+ import { Request, Response, Router } from 'express'
8
+ import { v4 } from 'uuid'
9
+ import { CreateState, DidRegistrationCreateRequest, IRequiredContext } from './types'
10
+
11
+ export function createDidEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts & { kms?: string }) {
12
+ if (opts?.enabled === false) {
13
+ console.log(`create DID endpoint is disabled`)
14
+ return
15
+ }
16
+ const path = opts?.path ?? '/identifiers'
17
+
18
+ router.post(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
19
+ try {
20
+ const createRequest: DidRegistrationCreateRequest = request.body
21
+ if (!createRequest) {
22
+ return sendErrorResponse(response, 400, 'No DID create request present')
23
+ }
24
+ const did = createRequest.did
25
+ const didMethod = (request.query.method as string) ?? (did ? parseDid(did).method : undefined)
26
+ const allDidMethods = await getAgentDIDMethods(context)
27
+ if (!didMethod) {
28
+ return sendErrorResponse(response, 400, 'No DID method supplied or deductible')
29
+ } else if (did && parseDid(did).method != didMethod) {
30
+ return sendErrorResponse(response, 400, 'DID method did not match method param')
31
+ } else if (!allDidMethods.includes(didMethod)) {
32
+ return sendErrorResponse(response, 400, 'DID method not supported')
33
+ }
34
+ const provider = `did:${didMethod}`
35
+ const jobId = createRequest.jobId ?? `urn:uuid:${v4()}`
36
+ let alias: string | undefined = undefined
37
+ if (didMethod === 'web') {
38
+ if (!did) {
39
+ throw Error('Please provide a value for "did" in the request body when creating a DID web')
40
+ }
41
+ alias = parseDid(did).id
42
+ if (!alias) {
43
+ throw Error('Could not determine alias from did:web DID value: ' + did)
44
+ }
45
+ }
46
+
47
+ let identifier: IIdentifier
48
+ if (createRequest.options.storeSecrets === false) {
49
+ throw Error('Not storing secrets mode is not support yet')
50
+ /*const memoryKMS = new SphereonKeyManager({
51
+ store: new MemoryKeyStore(),
52
+ kms: {'mem': new KeyManagementSystem(new MemoryPrivateKeyStore())}
53
+ })
54
+ identifier = await memoryKMS..didManagerCreate({provider, alias, kms: opts?.kms})*/
55
+ } else {
56
+ identifier = await context.agent.didManagerCreate({ provider, alias, kms: opts?.kms })
57
+ }
58
+
59
+ const didDocument = toDidDocument(identifier, { did, use: [JwkKeyUse.Signature, JwkKeyUse.Encryption] })
60
+ const createState: CreateState = {
61
+ jobId,
62
+ didState: {
63
+ did: identifier.did,
64
+ state: 'finished',
65
+ didDocument,
66
+ },
67
+ }
68
+ response.statusCode = 200
69
+ return response.send(createState)
70
+ } catch (e) {
71
+ return sendErrorResponse(response, 500, e.message as string, e)
72
+ }
73
+ })
74
+ }
75
+
76
+ export function getDidMethodsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {
77
+ if (opts?.enabled === false) {
78
+ console.log(`Get DID methods endpoint is disabled`)
79
+ return
80
+ }
81
+ const path = opts?.path ?? '/methods'
82
+ router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
83
+ try {
84
+ const methods = await getAgentDIDMethods(context) // these are already without the 'did:' prefix
85
+ response.statusCode = 200
86
+ return response.send(methods)
87
+ } catch (e) {
88
+ return sendErrorResponse(response, 500, e.message as string, e)
89
+ }
90
+ })
91
+ }
92
+
93
+ export function resolveDidEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts & { mode?: 'local' | 'resolve' }) {
94
+ if (opts?.enabled === false) {
95
+ console.log(`Resolve DID endpoint is disabled`)
96
+ return
97
+ }
98
+ const path = opts?.path ?? '/identifiers/:identifier'
99
+ router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
100
+ try {
101
+ const did = request.params.identifier
102
+ if (!did) {
103
+ return sendErrorResponse(response, 400, 'no identifier provided')
104
+ }
105
+ const mode = request.query.mode?.toString().toLowerCase() ?? opts?.mode?.toLowerCase()
106
+ let resolutionResult: DIDResolutionResult | undefined
107
+ if (mode === 'local' || mode === 'hybrid') {
108
+ try {
109
+ const identifier = await context.agent.didManagerGet({ did })
110
+ console.log(JSON.stringify(identifier, null, 2))
111
+ resolutionResult = toDidResolutionResult(identifier, {
112
+ did,
113
+ supportedMethod: await getAgentDIDMethods(context),
114
+ })
115
+ } catch (error) {
116
+ resolutionResult = {
117
+ didDocument: null,
118
+ didResolutionMetadata: {
119
+ error: 'notFound',
120
+ },
121
+ didDocumentMetadata: {},
122
+ }
123
+ }
124
+ }
125
+ if (mode !== 'local' && !resolutionResult?.didDocument) {
126
+ resolutionResult = await context.agent.resolveDid({ didUrl: did })
127
+ }
128
+
129
+ response.statusCode = 200
130
+ return response.send(resolutionResult)
131
+ } catch (e) {
132
+ return sendErrorResponse(response, 500, e.message as string, e)
133
+ }
134
+ })
135
+ }
136
+
137
+ export function deactivateDidEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {
138
+ if (opts?.enabled === false) {
139
+ console.log(`Deactivate DID endpoint is disabled`)
140
+ return
141
+ }
142
+ router.delete(opts?.path ?? '/identifiers/:identifier', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
143
+ try {
144
+ const did = request.params.identifier
145
+ if (!did) {
146
+ return sendErrorResponse(response, 400, 'no DID provided')
147
+ }
148
+
149
+ const result = await context.agent.didManagerDelete({ did })
150
+ if (!result) {
151
+ return sendErrorResponse(response, 404, `id ${did} not found`)
152
+ }
153
+ response.statusCode = 200
154
+ return response.send()
155
+ } catch (e) {
156
+ return sendErrorResponse(response, 500, e.message as string, e)
157
+ }
158
+ })
159
+ }
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @public
3
+ */
4
+ export * from './uni-resolver-api-server'
5
+ export * from './types'
6
+ export * from './api-functions'
package/src/types.ts ADDED
@@ -0,0 +1,125 @@
1
+ import { DIDDocument } from '@sphereon/did-uni-client'
2
+ import { GenericAuthArgs, ISingleEndpointOpts } from '@sphereon/ssi-sdk.express-support'
3
+ import { IAgentContext, IDataStore, IDataStoreORM, IDIDManager, IKeyManager, IResolver } from '@veramo/core'
4
+ import { ProofFormat } from '@veramo/core/src/types/ICredentialIssuer'
5
+ import { VerificationMethod } from 'did-resolver'
6
+
7
+ export type IRequiredPlugins = IDataStore & IDataStoreORM & IDIDManager & IKeyManager & IResolver
8
+ export type IRequiredContext = IAgentContext<IRequiredPlugins>
9
+
10
+ export interface DidRegistrationCreateRequest {
11
+ did?: string
12
+ jobId: string
13
+ options: DidRegistrationOptions
14
+ secret: DidRegistrationSecret
15
+ didDocument?: DIDDocument
16
+ }
17
+
18
+ export interface DidRegistrationUpdateRequest {
19
+ did: string
20
+ jobId: string
21
+ options: DidRegistrationOptions
22
+ secret: DidRegistrationSecret
23
+ didDocumentOperation: DidDocumentOperation[]
24
+ didDocument?: DIDDocument[]
25
+ }
26
+
27
+ export interface DidRegistrationDeactivateRequest {
28
+ did: string
29
+ jobId: string
30
+ options: DidRegistrationOptions
31
+ secret: DidRegistrationSecret
32
+ }
33
+
34
+ export type DidDocumentOperation = 'setDidDocument' | 'addToDidDocument' | 'removeFromDidDocument' | string
35
+
36
+ export interface DidRegistrationOptions {
37
+ network?: string
38
+ storeSecrets?: boolean
39
+ returnSecrets?: boolean
40
+
41
+ [x: string]: any
42
+ }
43
+
44
+ export interface DidRegistrationSecret {
45
+ seed?: string
46
+ verificationMethod?: CreateVerificationMethod[]
47
+
48
+ [x: string]: any
49
+ }
50
+
51
+ export interface CreateVerificationMethod extends VerificationMethod {
52
+ privateKeyBase58?: string
53
+ privateKeyBase64?: string
54
+ privateKeyJwk?: JsonWebKey
55
+ privateKeyHex?: string
56
+ privateKeyMultibase?: string
57
+ purpose?: ('authentication' | 'assertionMethod' | 'capabilityDelegation' | 'capabilityInvocation')[]
58
+ }
59
+
60
+ export interface CreateState {
61
+ jobId: string
62
+ didState: DidState
63
+ didRegistrationMetadata?: Record<string, any>
64
+ didDocumentMetadata?: Record<string, any>
65
+ }
66
+
67
+ export interface DidState {
68
+ state: 'finished' | 'failed' | 'action' | 'wait'
69
+ action?: 'redirect' | 'getVerificationMethod' | 'signPayload' | 'decryptPayload'
70
+ wait?: string
71
+ waitTime?: number
72
+ did: string
73
+ secret?: DidRegistrationSecret
74
+ didDocument?: DIDDocument
75
+ }
76
+
77
+ export interface IDidAPIOpts {
78
+ endpointOpts?: IDidAPIEndpointOpts
79
+ didOpts?: IVCAPIIssueOpts
80
+ }
81
+
82
+ export interface IDidAPIEndpointOpts {
83
+ basePath?: string
84
+ globalAuth?: GenericAuthArgs
85
+ createDid?: ISingleEndpointOpts
86
+ resolveDid?: ISingleEndpointOpts
87
+ deactivateDid?: ISingleEndpointOpts
88
+ getDidMethods?: ISingleEndpointOpts
89
+ }
90
+
91
+ export enum IVCIApiFeatures {
92
+ DID_RESOLVE = 'did-resolve',
93
+ DID_PERSISTENCE = 'did-persist',
94
+ }
95
+
96
+ export interface IVCAPIIssueOpts {
97
+ enableFeatures?: IVCIApiFeatures[] // Feature to enable. If not defined or empty, all features will be enabled
98
+ persistIssuedCredentials?: boolean // Whether the issuer persists issued credentials or not. Defaults to VC_PERSISTENCE feature flag being present or not
99
+
100
+ /**
101
+ * The desired format for the VerifiablePresentation to be created.
102
+ */
103
+ proofFormat: ProofFormat
104
+
105
+ /**
106
+ * Remove payload members during JWT-JSON transformation. Defaults to `true`.
107
+ * See https://www.w3.org/TR/vc-data-model/#jwt-encoding
108
+ */
109
+ removeOriginalFields?: boolean
110
+
111
+ /**
112
+ * [Optional] The ID of the key that should sign this credential.
113
+ * If this is not specified, the first matching key will be used.
114
+ */
115
+ keyRef?: string
116
+
117
+ /**
118
+ * When dealing with JSON-LD you also MUST provide the proper contexts.
119
+ * Set this to `true` ONLY if you want the `@context` URLs to be fetched in case they are not preloaded.
120
+ * The context definitions SHOULD rather be provided at startup instead of being fetched.
121
+ *
122
+ * Defaults to `false`
123
+ */
124
+ fetchRemoteContexts?: boolean
125
+ }
@@ -0,0 +1,73 @@
1
+ import { agentContext } from '@sphereon/ssi-sdk.core'
2
+ import { ExpressBuildResult } from '@sphereon/ssi-sdk.express-support'
3
+ import { TAgent } from '@veramo/core'
4
+
5
+ import express, { Express, Router } from 'express'
6
+ import { createDidEndpoint, deactivateDidEndpoint, getDidMethodsEndpoint, resolveDidEndpoint } from './api-functions'
7
+ import { IDidAPIOpts, IRequiredPlugins, IVCIApiFeatures } from './types'
8
+
9
+ export class UniResolverApiServer {
10
+ get router(): express.Router {
11
+ return this._router
12
+ }
13
+
14
+ private readonly _express: Express
15
+ private readonly _agent: TAgent<IRequiredPlugins>
16
+ private readonly _opts?: IDidAPIOpts
17
+ private readonly _router: Router
18
+
19
+ constructor(args: { agent: TAgent<IRequiredPlugins>; expressArgs: ExpressBuildResult; opts?: IDidAPIOpts }) {
20
+ const { agent, opts } = args
21
+ this._agent = agent
22
+ if (opts?.endpointOpts?.globalAuth) {
23
+ copyGlobalAuthToEndpoint(opts, 'getDidMethods')
24
+ copyGlobalAuthToEndpoint(opts, 'createDid')
25
+ copyGlobalAuthToEndpoint(opts, 'resolveDid')
26
+ copyGlobalAuthToEndpoint(opts, 'deactivateDid')
27
+ }
28
+
29
+ this._opts = opts
30
+ this._express = args.expressArgs.express
31
+ this._router = express.Router()
32
+
33
+ const context = agentContext(agent)
34
+
35
+ const features = opts?.didOpts?.enableFeatures ?? [IVCIApiFeatures.DID_RESOLVE, IVCIApiFeatures.DID_PERSISTENCE]
36
+ console.log(`DID UniResolver API enabled, with features: ${JSON.stringify(features)}`)
37
+
38
+ // DID endpoints
39
+ if (features.includes(IVCIApiFeatures.DID_RESOLVE)) {
40
+ resolveDidEndpoint(this.router, context, opts?.endpointOpts?.resolveDid)
41
+ getDidMethodsEndpoint(this.router, context, opts?.endpointOpts?.getDidMethods)
42
+ }
43
+ if (features.includes(IVCIApiFeatures.DID_RESOLVE)) {
44
+ createDidEndpoint(this.router, context, opts?.endpointOpts?.createDid)
45
+ deactivateDidEndpoint(this.router, context, opts?.endpointOpts?.deactivateDid) // not in spec.
46
+ }
47
+ this._express.use(opts?.endpointOpts?.basePath ?? '', this.router)
48
+ }
49
+
50
+ get agent(): TAgent<IRequiredPlugins> {
51
+ return this._agent
52
+ }
53
+
54
+ get opts(): IDidAPIOpts | undefined {
55
+ return this._opts
56
+ }
57
+
58
+ get express(): Express {
59
+ return this._express
60
+ }
61
+ }
62
+
63
+ function copyGlobalAuthToEndpoint(opts: IDidAPIOpts, key: string) {
64
+ if (opts?.endpointOpts?.globalAuth) {
65
+ // @ts-ignore
66
+ opts.endpointOpts[key] = {
67
+ // @ts-ignore
68
+ ...opts.endpointOpts[key],
69
+ // @ts-ignore
70
+ endpoint: { ...opts.endpointOpts.globalAuth, ...opts.endpointOpts[key]?.endpoint },
71
+ }
72
+ }
73
+ }