@sphereon/ssi-sdk.oid4vci-issuer-rest-api 0.11.1-next.112
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 +201 -0
- package/README.md +65 -0
- package/dist/OID4VCIRestAPI.d.ts +32 -0
- package/dist/OID4VCIRestAPI.d.ts.map +1 -0
- package/dist/OID4VCIRestAPI.js +139 -0
- package/dist/OID4VCIRestAPI.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/request-agent-router.d.ts +30 -0
- package/dist/request-agent-router.d.ts.map +1 -0
- package/dist/request-agent-router.js +41 -0
- package/dist/request-agent-router.js.map +1 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +94 -0
- package/src/OID4VCIRestAPI.ts +144 -0
- package/src/index.ts +5 -0
- package/src/request-agent-router.ts +47 -0
- package/src/types.ts +15 -0
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,32 @@
|
|
|
1
|
+
import { CredentialDataSupplier, VcIssuer } from '@sphereon/oid4vci-issuer';
|
|
2
|
+
import { OID4VCIServer } from '@sphereon/oid4vci-issuer-server';
|
|
3
|
+
import { IOID4VCIServerOpts } from '@sphereon/oid4vci-issuer-server/lib/OID4VCIServer';
|
|
4
|
+
import { IIssuerInstanceArgs, IssuerInstance } from '@sphereon/ssi-sdk.oid4vci-issuer';
|
|
5
|
+
import { Express } from 'express';
|
|
6
|
+
import { IRequiredContext } from './types';
|
|
7
|
+
export interface IOID4VCIRestAPIOpts extends IOID4VCIServerOpts {
|
|
8
|
+
}
|
|
9
|
+
export declare class OID4VCIRestAPI {
|
|
10
|
+
private readonly _express;
|
|
11
|
+
private readonly _context;
|
|
12
|
+
private readonly _opts?;
|
|
13
|
+
private readonly _restApi;
|
|
14
|
+
private readonly _instance;
|
|
15
|
+
private readonly _issuer;
|
|
16
|
+
static init(args: {
|
|
17
|
+
context: IRequiredContext;
|
|
18
|
+
issuerInstanceArgs: IIssuerInstanceArgs;
|
|
19
|
+
credentialDataSupplier?: CredentialDataSupplier;
|
|
20
|
+
express?: Express;
|
|
21
|
+
opts?: IOID4VCIRestAPIOpts;
|
|
22
|
+
}): Promise<OID4VCIRestAPI>;
|
|
23
|
+
private constructor();
|
|
24
|
+
static setupExpress(opts: IOID4VCIServerOpts): Express;
|
|
25
|
+
get express(): Express;
|
|
26
|
+
get context(): IRequiredContext;
|
|
27
|
+
get opts(): IOID4VCIRestAPIOpts | undefined;
|
|
28
|
+
get restApi(): OID4VCIServer;
|
|
29
|
+
get instance(): IssuerInstance;
|
|
30
|
+
get issuer(): VcIssuer;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=OID4VCIRestAPI.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OID4VCIRestAPI.d.ts","sourceRoot":"","sources":["../src/OID4VCIRestAPI.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAA;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mDAAmD,CAAA;AACtF,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAA;AAItF,OAAgB,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE1C,MAAM,WAAW,mBAAoB,SAAQ,kBAAkB;CAAG;AAElE,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkB;IAC3C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAqB;IAC5C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;IACxC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgB;IAC1C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;WAErB,IAAI,CAAC,IAAI,EAAE;QACtB,OAAO,EAAE,gBAAgB,CAAA;QACzB,kBAAkB,EAAE,mBAAmB,CAAA;QACvC,sBAAsB,CAAC,EAAE,sBAAsB,CAAA;QAC/C,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,IAAI,CAAC,EAAE,mBAAmB,CAAA;KAC3B,GAAG,OAAO,CAAC,cAAc,CAAC;IAoC3B,OAAO;WAsBO,YAAY,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO;IAkC7D,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,OAAO,IAAI,gBAAgB,CAE9B;IAED,IAAI,IAAI,IAAI,mBAAmB,GAAG,SAAS,CAE1C;IAED,IAAI,OAAO,IAAI,aAAa,CAE3B;IAED,IAAI,QAAQ,IAAI,cAAc,CAE7B;IAED,IAAI,MAAM,IAAI,QAAQ,CAErB;CACF"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// noinspection JSUnusedGlobalSymbols
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
27
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
28
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
29
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
30
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
31
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
32
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.OID4VCIRestAPI = void 0;
|
|
40
|
+
const oid4vci_issuer_server_1 = require("@sphereon/oid4vci-issuer-server");
|
|
41
|
+
const ssi_sdk_oid4vci_issuer_1 = require("@sphereon/ssi-sdk.oid4vci-issuer");
|
|
42
|
+
const body_parser_1 = __importDefault(require("body-parser"));
|
|
43
|
+
const dotenv = __importStar(require("dotenv-flow"));
|
|
44
|
+
const express_1 = __importDefault(require("express"));
|
|
45
|
+
class OID4VCIRestAPI {
|
|
46
|
+
static init(args) {
|
|
47
|
+
var _a, _b, _c, _d, _e;
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const { issuerInstanceArgs, express, context } = args;
|
|
50
|
+
const instance = yield context.agent.oid4vciGetInstance(args.issuerInstanceArgs);
|
|
51
|
+
const issuer = yield instance.get({ context, credentialDataSupplier: args.credentialDataSupplier });
|
|
52
|
+
const opts = (_a = args.opts) !== null && _a !== void 0 ? _a : {};
|
|
53
|
+
if (!opts.tokenEndpointOpts) {
|
|
54
|
+
opts.tokenEndpointOpts = { accessTokenIssuer: (_b = instance.metadataOptions.credentialIssuer) !== null && _b !== void 0 ? _b : issuer.issuerMetadata.credential_issuer };
|
|
55
|
+
}
|
|
56
|
+
if (((_c = opts === null || opts === void 0 ? void 0 : opts.tokenEndpointOpts) === null || _c === void 0 ? void 0 : _c.tokenEndpointDisabled) !== true && typeof ((_d = opts === null || opts === void 0 ? void 0 : opts.tokenEndpointOpts) === null || _d === void 0 ? void 0 : _d.accessTokenSignerCallback) !== 'function') {
|
|
57
|
+
let keyRef;
|
|
58
|
+
const tokenOpts = {
|
|
59
|
+
iss: (_e = opts.tokenEndpointOpts.accessTokenIssuer) !== null && _e !== void 0 ? _e : instance.metadataOptions.credentialIssuer,
|
|
60
|
+
didOpts: instance.issuerOptions.didOpts,
|
|
61
|
+
};
|
|
62
|
+
if (!tokenOpts.didOpts.identifierOpts.kid || tokenOpts.didOpts.identifierOpts.kid.startsWith('did:')) {
|
|
63
|
+
keyRef = yield (0, ssi_sdk_oid4vci_issuer_1.getAccessTokenKeyRef)(tokenOpts, context);
|
|
64
|
+
}
|
|
65
|
+
opts.tokenEndpointOpts.accessTokenSignerCallback = (0, ssi_sdk_oid4vci_issuer_1.getAccessTokenSignerCallback)(Object.assign(Object.assign({}, tokenOpts), { keyRef }), args.context);
|
|
66
|
+
}
|
|
67
|
+
if (!opts.serverOpts) {
|
|
68
|
+
opts.serverOpts = {
|
|
69
|
+
port: 5000,
|
|
70
|
+
host: '0.0.0.0',
|
|
71
|
+
app: args.express,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return new OID4VCIRestAPI({ context, issuerInstanceArgs, express, opts, instance, issuer });
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
constructor(args) {
|
|
78
|
+
const { context, opts } = args;
|
|
79
|
+
this._context = context;
|
|
80
|
+
this._opts = opts !== null && opts !== void 0 ? opts : {};
|
|
81
|
+
this._express = OID4VCIRestAPI.setupExpress(opts);
|
|
82
|
+
this._issuer = args.issuer;
|
|
83
|
+
this._instance = args.instance;
|
|
84
|
+
this._opts.serverOpts = Object.assign(Object.assign({}, opts.serverOpts), { app: this._express });
|
|
85
|
+
this._restApi = new oid4vci_issuer_server_1.OID4VCIServer(Object.assign(Object.assign({}, opts), { issuer: this._issuer }));
|
|
86
|
+
}
|
|
87
|
+
static setupExpress(opts) {
|
|
88
|
+
var _a, _b, _c, _d, _e;
|
|
89
|
+
dotenv.config();
|
|
90
|
+
const existingExpress = !!((_a = opts.serverOpts) === null || _a === void 0 ? void 0 : _a.app);
|
|
91
|
+
const app = (_c = (_b = opts.serverOpts) === null || _b === void 0 ? void 0 : _b.app) !== null && _c !== void 0 ? _c : (0, express_1.default)();
|
|
92
|
+
if (!existingExpress) {
|
|
93
|
+
const port = ((_d = opts.serverOpts) === null || _d === void 0 ? void 0 : _d.port) || process.env.PORT || 5000;
|
|
94
|
+
const hostname = ((_e = opts.serverOpts) === null || _e === void 0 ? void 0 : _e.host) || '0.0.0.0';
|
|
95
|
+
app.use((req, res, next) => {
|
|
96
|
+
res.header('Access-Control-Allow-Origin', '*');
|
|
97
|
+
// Request methods you wish to allow
|
|
98
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
|
|
99
|
+
// Request headers you wish to allow
|
|
100
|
+
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
|
|
101
|
+
// Set to true if you need the website to include cookies in the requests sent
|
|
102
|
+
// to the API (e.g. in case you use sessions)
|
|
103
|
+
res.setHeader('Access-Control-Allow-Credentials', 'true');
|
|
104
|
+
next();
|
|
105
|
+
});
|
|
106
|
+
// this.express.use(cors({ credentials: true }));
|
|
107
|
+
// this.express.use('/proxy', proxy('www.gssoogle.com'));
|
|
108
|
+
app.use(body_parser_1.default.urlencoded({ extended: true }));
|
|
109
|
+
app.use(body_parser_1.default.json());
|
|
110
|
+
app.listen(port, hostname, () => console.log(`Listening on ${hostname}, port ${port}`));
|
|
111
|
+
if (!opts.serverOpts) {
|
|
112
|
+
opts.serverOpts = {};
|
|
113
|
+
}
|
|
114
|
+
// make sure that if these opts are passed on to another instance, it uses the existing app
|
|
115
|
+
opts.serverOpts.app = app;
|
|
116
|
+
}
|
|
117
|
+
return app;
|
|
118
|
+
}
|
|
119
|
+
get express() {
|
|
120
|
+
return this._express;
|
|
121
|
+
}
|
|
122
|
+
get context() {
|
|
123
|
+
return this._context;
|
|
124
|
+
}
|
|
125
|
+
get opts() {
|
|
126
|
+
return this._opts;
|
|
127
|
+
}
|
|
128
|
+
get restApi() {
|
|
129
|
+
return this._restApi;
|
|
130
|
+
}
|
|
131
|
+
get instance() {
|
|
132
|
+
return this._instance;
|
|
133
|
+
}
|
|
134
|
+
get issuer() {
|
|
135
|
+
return this._issuer;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.OID4VCIRestAPI = OID4VCIRestAPI;
|
|
139
|
+
//# sourceMappingURL=OID4VCIRestAPI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OID4VCIRestAPI.js","sourceRoot":"","sources":["../src/OID4VCIRestAPI.ts"],"names":[],"mappings":";AAAA,qCAAqC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGrC,2EAA+D;AAG/D,6EAAqG;AACrG,8DAAoC;AACpC,oDAAqC;AACrC,sDAA0C;AAK1C,MAAa,cAAc;IAQzB,MAAM,CAAO,IAAI,CAAC,IAMjB;;;YACC,MAAM,EAAE,kBAAkB,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;YACrD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;YAChF,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,sBAAsB,EAAE,IAAI,CAAC,sB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CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAA;IACtB,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAA;IACvB,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;CACF;AAjID,wCAiIC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,kBAAkB,CAAA;AAChC,cAAc,SAAS,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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("./OID4VCIRestAPI"), exports);
|
|
21
|
+
__exportStar(require("./types"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,mDAAgC;AAChC,0CAAuB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { IAgent } from '@veramo/core';
|
|
2
|
+
import { Request, Router } from 'express';
|
|
3
|
+
export interface RequestWithAgent extends Request {
|
|
4
|
+
agent?: IAgent;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface RequestWithAgentRouterOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Optional. Pre-configured agent
|
|
12
|
+
*/
|
|
13
|
+
agent?: IAgent;
|
|
14
|
+
/**
|
|
15
|
+
* Optional. Function that returns a Promise that resolves to a configured agent for specific request
|
|
16
|
+
*/
|
|
17
|
+
getAgentForRequest?: (req: Request) => Promise<IAgent>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates an expressjs router that adds a Veramo agent to the request object.
|
|
21
|
+
*
|
|
22
|
+
* This is needed by all other routers provided by this package to be able to perform their functions.
|
|
23
|
+
*
|
|
24
|
+
* @param options - Initialization option
|
|
25
|
+
* @returns Expressjs router
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export declare const RequestWithAgentRouter: (options: RequestWithAgentRouterOptions) => Router;
|
|
30
|
+
//# sourceMappingURL=request-agent-router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-agent-router.d.ts","sourceRoot":"","sources":["../src/request-agent-router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAEzC,MAAM,WAAW,gBAAiB,SAAQ,OAAO;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,kBAAkB,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CACvD;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,YAAa,6BAA6B,KAAG,MAc/E,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.RequestWithAgentRouter = void 0;
|
|
13
|
+
const express_1 = require("express");
|
|
14
|
+
/**
|
|
15
|
+
* Creates an expressjs router that adds a Veramo agent to the request object.
|
|
16
|
+
*
|
|
17
|
+
* This is needed by all other routers provided by this package to be able to perform their functions.
|
|
18
|
+
*
|
|
19
|
+
* @param options - Initialization option
|
|
20
|
+
* @returns Expressjs router
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
const RequestWithAgentRouter = (options) => {
|
|
25
|
+
const router = (0, express_1.Router)();
|
|
26
|
+
router.use((req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
if (options.agent) {
|
|
28
|
+
req.agent = options.agent;
|
|
29
|
+
}
|
|
30
|
+
else if (options.getAgentForRequest) {
|
|
31
|
+
req.agent = yield options.getAgentForRequest(req);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
throw Error('[RequestWithAgentRouter] agent or getAgentForRequest is required');
|
|
35
|
+
}
|
|
36
|
+
next();
|
|
37
|
+
}));
|
|
38
|
+
return router;
|
|
39
|
+
};
|
|
40
|
+
exports.RequestWithAgentRouter = RequestWithAgentRouter;
|
|
41
|
+
//# sourceMappingURL=request-agent-router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-agent-router.js","sourceRoot":"","sources":["../src/request-agent-router.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qCAAyC;AAqBzC;;;;;;;;;GASG;AACI,MAAM,sBAAsB,GAAG,CAAC,OAAsC,EAAU,EAAE;IACvF,MAAM,MAAM,GAAG,IAAA,gBAAM,GAAE,CAAA;IACvB,MAAM,CAAC,GAAG,CAAC,CAAO,GAAqB,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACpD,IAAI,OAAO,CAAC,KAAK,EAAE;YACjB,GAAG,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;SAC1B;aAAM,IAAI,OAAO,CAAC,kBAAkB,EAAE;YACrC,GAAG,CAAC,KAAK,GAAG,MAAM,OAAO,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAA;SAClD;aAAM;YACL,MAAM,KAAK,CAAC,kEAAkE,CAAC,CAAA;SAChF;QACD,IAAI,EAAE,CAAA;IACR,CAAC,CAAA,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAdY,QAAA,sBAAsB,0BAclC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IOID4VCIIssuer } from '@sphereon/ssi-sdk.oid4vci-issuer';
|
|
2
|
+
import { IOID4VCIStore } from '@sphereon/ssi-sdk.oid4vci-issuer-store';
|
|
3
|
+
import { IAgentContext, ICredentialIssuer, ICredentialVerifier, IDataStore, IDataStoreORM, IDIDManager, IKeyManager, IResolver } from '@veramo/core';
|
|
4
|
+
export type IRequiredContext = IAgentContext<IPlugins>;
|
|
5
|
+
export type IPlugins = IDIDManager & IKeyManager & IDataStore & IDataStoreORM & IResolver & IOID4VCIStore & IOID4VCIIssuer & ICredentialVerifier & ICredentialIssuer;
|
|
6
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAA;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AACtE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAEpJ,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAA;AAEtD,MAAM,MAAM,QAAQ,GAAG,WAAW,GAChC,WAAW,GACX,UAAU,GACV,aAAa,GACb,SAAS,GACT,aAAa,GACb,cAAc,GACd,mBAAmB,GACnB,iBAAiB,CAAA"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sphereon/ssi-sdk.oid4vci-issuer-rest-api",
|
|
3
|
+
"version": "0.11.1-next.112+0ac00fe",
|
|
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__/RestAPI.ts"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@sphereon/oid4vci-common": "0.4.1-unstable.286",
|
|
15
|
+
"@sphereon/oid4vci-issuer": "0.4.1-unstable.286",
|
|
16
|
+
"@sphereon/oid4vci-issuer-server": "0.4.1-unstable.286",
|
|
17
|
+
"@sphereon/ssi-sdk.kv-store-temp": "0.11.1-next.112+0ac00fe",
|
|
18
|
+
"@sphereon/ssi-sdk.oid4vci-issuer": "0.11.1-next.112+0ac00fe",
|
|
19
|
+
"@sphereon/ssi-sdk.oid4vci-issuer-store": "0.11.1-next.112+0ac00fe",
|
|
20
|
+
"@sphereon/ssi-types": "0.11.1-next.112+0ac00fe",
|
|
21
|
+
"@types/uuid": "^9.0.1",
|
|
22
|
+
"@veramo/core": "4.2.0",
|
|
23
|
+
"@veramo/credential-w3c": "4.2.0",
|
|
24
|
+
"body-parser": "^1.19.0",
|
|
25
|
+
"cookie-parser": "^1.4.5",
|
|
26
|
+
"cors": "^2.8.5",
|
|
27
|
+
"cross-fetch": "^3.1.5",
|
|
28
|
+
"dotenv-flow": "^3.2.0",
|
|
29
|
+
"express": "^4.18.2",
|
|
30
|
+
"short-uuid": "^4.2.2",
|
|
31
|
+
"uuid": "^8.3.2"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@decentralized-identity/ion-sdk": "^0.6.0",
|
|
35
|
+
"@sphereon/did-uni-client": "^0.6.0",
|
|
36
|
+
"@sphereon/pex": "^2.0.1",
|
|
37
|
+
"@sphereon/pex-models": "^2.0.2",
|
|
38
|
+
"@sphereon/ssi-sdk-ext.did-provider-jwk": "^0.12.0",
|
|
39
|
+
"@sphereon/ssi-sdk-ext.key-utils": "^0.12.0",
|
|
40
|
+
"@sphereon/ssi-sdk.data-store": "0.11.1-next.112+0ac00fe",
|
|
41
|
+
"@sphereon/ssi-sdk.vc-handler-ld-local": "0.11.1-next.112+0ac00fe",
|
|
42
|
+
"@types/body-parser": "^1.19.2",
|
|
43
|
+
"@types/cookie-parser": "^1.4.3",
|
|
44
|
+
"@types/cors": "^2.8.13",
|
|
45
|
+
"@types/debug": "^4.1.7",
|
|
46
|
+
"@types/dotenv-flow": "^3.2.0",
|
|
47
|
+
"@types/express": "^4.17.13",
|
|
48
|
+
"@types/express-http-proxy": "^1.6.3",
|
|
49
|
+
"@types/node": "^18.15.0",
|
|
50
|
+
"@veramo/data-store": "4.2.0",
|
|
51
|
+
"@veramo/did-manager": "4.2.0",
|
|
52
|
+
"@veramo/did-provider-ethr": "4.2.0",
|
|
53
|
+
"@veramo/did-provider-ion": "4.2.0",
|
|
54
|
+
"@veramo/did-provider-key": "4.2.0",
|
|
55
|
+
"@veramo/did-provider-web": "4.2.0",
|
|
56
|
+
"@veramo/did-resolver": "4.2.0",
|
|
57
|
+
"@veramo/key-manager": "4.2.0",
|
|
58
|
+
"@veramo/kms-local": "4.2.0",
|
|
59
|
+
"@veramo/utils": "4.2.0",
|
|
60
|
+
"did-resolver": "^4.1.0",
|
|
61
|
+
"nock": "^13.2.1",
|
|
62
|
+
"ts-node": "^10.9.1",
|
|
63
|
+
"typeorm": "^0.3.12",
|
|
64
|
+
"web-did-resolver": "^2.0.24"
|
|
65
|
+
},
|
|
66
|
+
"files": [
|
|
67
|
+
".yalc/**/*",
|
|
68
|
+
"dist/**/*",
|
|
69
|
+
"src/**/*",
|
|
70
|
+
"README.md",
|
|
71
|
+
"plugin.schema.json",
|
|
72
|
+
"LICENSE"
|
|
73
|
+
],
|
|
74
|
+
"private": false,
|
|
75
|
+
"publishConfig": {
|
|
76
|
+
"access": "public"
|
|
77
|
+
},
|
|
78
|
+
"repository": "git@github.com:Sphereon-Opensource/SSI-SDK.git",
|
|
79
|
+
"author": "Sphereon <dev@sphereon.com>",
|
|
80
|
+
"license": "Apache-2.0",
|
|
81
|
+
"keywords": [
|
|
82
|
+
"Sphereon",
|
|
83
|
+
"SSI",
|
|
84
|
+
"Veramo",
|
|
85
|
+
"DID",
|
|
86
|
+
"SIOP",
|
|
87
|
+
"SIOPv2",
|
|
88
|
+
"OIDC4VP",
|
|
89
|
+
"Presentation Exchange",
|
|
90
|
+
"OpenID Connect",
|
|
91
|
+
"Authenticator"
|
|
92
|
+
],
|
|
93
|
+
"gitHead": "0ac00fe02a48ce2a14c61adb3a3430c79d7b8243"
|
|
94
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// noinspection JSUnusedGlobalSymbols
|
|
2
|
+
|
|
3
|
+
import { CredentialDataSupplier, VcIssuer } from '@sphereon/oid4vci-issuer'
|
|
4
|
+
import { OID4VCIServer } from '@sphereon/oid4vci-issuer-server'
|
|
5
|
+
import { IOID4VCIServerOpts } from '@sphereon/oid4vci-issuer-server/lib/OID4VCIServer'
|
|
6
|
+
import { IIssuerInstanceArgs, IssuerInstance } from '@sphereon/ssi-sdk.oid4vci-issuer'
|
|
7
|
+
import { getAccessTokenKeyRef, getAccessTokenSignerCallback } from '@sphereon/ssi-sdk.oid4vci-issuer'
|
|
8
|
+
import bodyParser from 'body-parser'
|
|
9
|
+
import * as dotenv from 'dotenv-flow'
|
|
10
|
+
import express, { Express } from 'express'
|
|
11
|
+
import { IRequiredContext } from './types'
|
|
12
|
+
|
|
13
|
+
export interface IOID4VCIRestAPIOpts extends IOID4VCIServerOpts {}
|
|
14
|
+
|
|
15
|
+
export class OID4VCIRestAPI {
|
|
16
|
+
private readonly _express: Express
|
|
17
|
+
private readonly _context: IRequiredContext
|
|
18
|
+
private readonly _opts?: IOID4VCIRestAPIOpts
|
|
19
|
+
private readonly _restApi: OID4VCIServer
|
|
20
|
+
private readonly _instance: IssuerInstance
|
|
21
|
+
private readonly _issuer: VcIssuer
|
|
22
|
+
|
|
23
|
+
static async init(args: {
|
|
24
|
+
context: IRequiredContext
|
|
25
|
+
issuerInstanceArgs: IIssuerInstanceArgs
|
|
26
|
+
credentialDataSupplier?: CredentialDataSupplier
|
|
27
|
+
express?: Express
|
|
28
|
+
opts?: IOID4VCIRestAPIOpts
|
|
29
|
+
}): Promise<OID4VCIRestAPI> {
|
|
30
|
+
const { issuerInstanceArgs, express, context } = args
|
|
31
|
+
const instance = await context.agent.oid4vciGetInstance(args.issuerInstanceArgs)
|
|
32
|
+
const issuer = await instance.get({ context, credentialDataSupplier: args.credentialDataSupplier })
|
|
33
|
+
const opts = args.opts ?? {}
|
|
34
|
+
if (!opts.tokenEndpointOpts) {
|
|
35
|
+
opts.tokenEndpointOpts = { accessTokenIssuer: instance.metadataOptions.credentialIssuer ?? issuer.issuerMetadata.credential_issuer }
|
|
36
|
+
}
|
|
37
|
+
if (opts?.tokenEndpointOpts?.tokenEndpointDisabled !== true && typeof opts?.tokenEndpointOpts?.accessTokenSignerCallback !== 'function') {
|
|
38
|
+
let keyRef: string | undefined
|
|
39
|
+
const tokenOpts = {
|
|
40
|
+
iss: opts.tokenEndpointOpts.accessTokenIssuer ?? instance.metadataOptions.credentialIssuer,
|
|
41
|
+
didOpts: instance.issuerOptions.didOpts,
|
|
42
|
+
}
|
|
43
|
+
if (!tokenOpts.didOpts.identifierOpts.kid || tokenOpts.didOpts.identifierOpts.kid.startsWith('did:')) {
|
|
44
|
+
keyRef = await getAccessTokenKeyRef(tokenOpts, context)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
opts.tokenEndpointOpts.accessTokenSignerCallback = getAccessTokenSignerCallback(
|
|
48
|
+
{
|
|
49
|
+
...tokenOpts,
|
|
50
|
+
keyRef,
|
|
51
|
+
},
|
|
52
|
+
args.context
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
if (!opts.serverOpts) {
|
|
56
|
+
opts.serverOpts = {
|
|
57
|
+
port: 5000,
|
|
58
|
+
host: '0.0.0.0',
|
|
59
|
+
app: args.express,
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return new OID4VCIRestAPI({ context, issuerInstanceArgs, express, opts, instance, issuer })
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private constructor(args: {
|
|
66
|
+
issuer: VcIssuer
|
|
67
|
+
instance: IssuerInstance
|
|
68
|
+
context: IRequiredContext
|
|
69
|
+
issuerInstanceArgs: IIssuerInstanceArgs
|
|
70
|
+
express?: Express
|
|
71
|
+
opts: IOID4VCIRestAPIOpts
|
|
72
|
+
}) {
|
|
73
|
+
const { context, opts } = args
|
|
74
|
+
this._context = context
|
|
75
|
+
this._opts = opts ?? {}
|
|
76
|
+
this._express = OID4VCIRestAPI.setupExpress(opts)
|
|
77
|
+
this._issuer = args.issuer
|
|
78
|
+
this._instance = args.instance
|
|
79
|
+
|
|
80
|
+
this._opts.serverOpts = {
|
|
81
|
+
...opts.serverOpts,
|
|
82
|
+
app: this._express,
|
|
83
|
+
}
|
|
84
|
+
this._restApi = new OID4VCIServer({ ...opts, issuer: this._issuer })
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public static setupExpress(opts: IOID4VCIServerOpts): Express {
|
|
88
|
+
dotenv.config()
|
|
89
|
+
const existingExpress = !!opts.serverOpts?.app
|
|
90
|
+
const app = opts.serverOpts?.app ?? express()
|
|
91
|
+
if (!existingExpress) {
|
|
92
|
+
const port = opts.serverOpts?.port || process.env.PORT || 5000
|
|
93
|
+
const hostname = opts.serverOpts?.host || '0.0.0.0'
|
|
94
|
+
app.use((req, res, next) => {
|
|
95
|
+
res.header('Access-Control-Allow-Origin', '*')
|
|
96
|
+
// Request methods you wish to allow
|
|
97
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE')
|
|
98
|
+
|
|
99
|
+
// Request headers you wish to allow
|
|
100
|
+
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type')
|
|
101
|
+
|
|
102
|
+
// Set to true if you need the website to include cookies in the requests sent
|
|
103
|
+
// to the API (e.g. in case you use sessions)
|
|
104
|
+
res.setHeader('Access-Control-Allow-Credentials', 'true')
|
|
105
|
+
next()
|
|
106
|
+
})
|
|
107
|
+
// this.express.use(cors({ credentials: true }));
|
|
108
|
+
// this.express.use('/proxy', proxy('www.gssoogle.com'));
|
|
109
|
+
app.use(bodyParser.urlencoded({ extended: true }))
|
|
110
|
+
app.use(bodyParser.json())
|
|
111
|
+
app.listen(port as number, hostname, () => console.log(`Listening on ${hostname}, port ${port}`))
|
|
112
|
+
if (!opts.serverOpts) {
|
|
113
|
+
opts.serverOpts = {}
|
|
114
|
+
}
|
|
115
|
+
// make sure that if these opts are passed on to another instance, it uses the existing app
|
|
116
|
+
opts.serverOpts.app = app
|
|
117
|
+
}
|
|
118
|
+
return app
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
get express(): Express {
|
|
122
|
+
return this._express
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
get context(): IRequiredContext {
|
|
126
|
+
return this._context
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
get opts(): IOID4VCIRestAPIOpts | undefined {
|
|
130
|
+
return this._opts
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
get restApi(): OID4VCIServer {
|
|
134
|
+
return this._restApi
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
get instance(): IssuerInstance {
|
|
138
|
+
return this._instance
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
get issuer(): VcIssuer {
|
|
142
|
+
return this._issuer
|
|
143
|
+
}
|
|
144
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { IAgent } from '@veramo/core'
|
|
2
|
+
import { Request, Router } from 'express'
|
|
3
|
+
|
|
4
|
+
export interface RequestWithAgent extends Request {
|
|
5
|
+
agent?: IAgent
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export interface RequestWithAgentRouterOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Optional. Pre-configured agent
|
|
14
|
+
*/
|
|
15
|
+
agent?: IAgent
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Optional. Function that returns a Promise that resolves to a configured agent for specific request
|
|
19
|
+
*/
|
|
20
|
+
getAgentForRequest?: (req: Request) => Promise<IAgent>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Creates an expressjs router that adds a Veramo agent to the request object.
|
|
25
|
+
*
|
|
26
|
+
* This is needed by all other routers provided by this package to be able to perform their functions.
|
|
27
|
+
*
|
|
28
|
+
* @param options - Initialization option
|
|
29
|
+
* @returns Expressjs router
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export const RequestWithAgentRouter = (options: RequestWithAgentRouterOptions): Router => {
|
|
34
|
+
const router = Router()
|
|
35
|
+
router.use(async (req: RequestWithAgent, res, next) => {
|
|
36
|
+
if (options.agent) {
|
|
37
|
+
req.agent = options.agent
|
|
38
|
+
} else if (options.getAgentForRequest) {
|
|
39
|
+
req.agent = await options.getAgentForRequest(req)
|
|
40
|
+
} else {
|
|
41
|
+
throw Error('[RequestWithAgentRouter] agent or getAgentForRequest is required')
|
|
42
|
+
}
|
|
43
|
+
next()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
return router
|
|
47
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IOID4VCIIssuer } from '@sphereon/ssi-sdk.oid4vci-issuer'
|
|
2
|
+
import { IOID4VCIStore } from '@sphereon/ssi-sdk.oid4vci-issuer-store'
|
|
3
|
+
import { IAgentContext, ICredentialIssuer, ICredentialVerifier, IDataStore, IDataStoreORM, IDIDManager, IKeyManager, IResolver } from '@veramo/core'
|
|
4
|
+
|
|
5
|
+
export type IRequiredContext = IAgentContext<IPlugins>
|
|
6
|
+
|
|
7
|
+
export type IPlugins = IDIDManager &
|
|
8
|
+
IKeyManager &
|
|
9
|
+
IDataStore &
|
|
10
|
+
IDataStoreORM &
|
|
11
|
+
IResolver &
|
|
12
|
+
IOID4VCIStore &
|
|
13
|
+
IOID4VCIIssuer &
|
|
14
|
+
ICredentialVerifier &
|
|
15
|
+
ICredentialIssuer
|