@sphereon/ssi-sdk.w3c-vc-api 0.13.1-unstable.9 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +175 -27
- package/dist/api-functions.d.ts +9 -0
- package/dist/api-functions.d.ts.map +1 -0
- package/dist/api-functions.js +150 -0
- package/dist/api-functions.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +63 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/vc-api-server.d.ts +20 -0
- package/dist/vc-api-server.d.ts.map +1 -0
- package/dist/vc-api-server.js +65 -0
- package/dist/vc-api-server.js.map +1 -0
- package/package.json +22 -25
- package/src/api-functions.ts +132 -0
- package/src/index.ts +2 -1
- package/src/types.ts +77 -2
- package/src/vc-api-server.ts +89 -0
- package/dist/VCAPIServer.d.ts +0 -78
- package/dist/VCAPIServer.d.ts.map +0 -1
- package/dist/VCAPIServer.js +0 -245
- package/dist/VCAPIServer.js.map +0 -1
- package/dist/request-agent-router.d.ts +0 -30
- package/dist/request-agent-router.d.ts.map +0 -1
- package/dist/request-agent-router.js +0 -41
- package/dist/request-agent-router.js.map +0 -1
- package/src/VCAPIServer.ts +0 -283
- package/src/request-agent-router.ts +0 -47
package/README.md
CHANGED
|
@@ -2,51 +2,199 @@
|
|
|
2
2
|
<h1 align="center">
|
|
3
3
|
<br>
|
|
4
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>
|
|
5
|
+
<br>W3C VC API
|
|
6
6
|
<br>
|
|
7
7
|
</h1>
|
|
8
8
|
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
**Warning: This package
|
|
11
|
+
**Warning: This package is in early development. Breaking changes without notice will happen at this point!**
|
|
12
12
|
|
|
13
13
|
---
|
|
14
14
|
|
|
15
|
-
|
|
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.
|
|
15
|
+
This module provides a W3C Verifiable Credential API, to allow issuance and verification of VCs and VPs.
|
|
19
16
|
|
|
20
|
-
|
|
17
|
+
# VC API
|
|
21
18
|
|
|
22
|
-
For more information about
|
|
19
|
+
For more information about the W3C VC API visit
|
|
20
|
+
the [W3C VC API Github](https://w3c-ccg.github.io/vc-api/).
|
|
21
|
+
This module allows you to issue, persist, retrieve and verify Verifiable Credentials (other endpoints are not supported yet)
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
There are 3 modes of resolution, controlled by a query parameter, when calling the resolution endpoint. You can also set
|
|
24
|
+
a default mode when no query parameter is being used.
|
|
25
|
+
|
|
26
|
+
The modes are:
|
|
27
|
+
|
|
28
|
+
- **local**: Only DIDs managed by the agent can be resolved. DID:web and it's keys are translated to DID documents
|
|
29
|
+
- **global**: Resolves DIDs by using the supported resolvers of the agent, allowing external DID resolution
|
|
30
|
+
- **hybrid** (default): Tries to resolve locally first. If not found it will fallback to the global mode
|
|
31
|
+
|
|
32
|
+
### Issuance example
|
|
33
|
+
|
|
34
|
+
The below example resolves the provided did:web DID using external resolution by looking up the domain from the provided
|
|
35
|
+
host at https://ddip.sphereon.com.
|
|
36
|
+
|
|
37
|
+
```shell
|
|
38
|
+
curl -X POST\
|
|
39
|
+
-H "Accept: application/json"\
|
|
40
|
+
"https://agent/credentials/issue"
|
|
41
|
+
-d '<json body below>'
|
|
42
|
+
```
|
|
43
|
+
Body:
|
|
44
|
+
```json
|
|
45
|
+
{
|
|
46
|
+
"verifiableCredential": {
|
|
47
|
+
"@context": [
|
|
48
|
+
"https://www.w3.org/2018/credentials/v1"
|
|
49
|
+
],
|
|
50
|
+
"id": "https://example.com/8790171",
|
|
51
|
+
"type": [
|
|
52
|
+
"VerifiableCredential",
|
|
53
|
+
"GS1CompanyPrefixLicenseCredential"
|
|
54
|
+
],
|
|
55
|
+
"issuer": "did:web:example.com",
|
|
56
|
+
"issuanceDate": "2023-06-22T00:00:00.000Z",
|
|
57
|
+
"validUntil": "2024-06-22T00:00:00.000Z",
|
|
58
|
+
"credentialSubject": {
|
|
59
|
+
"id": "did:web:subject.example.com",
|
|
60
|
+
"example": "value"
|
|
61
|
+
},
|
|
62
|
+
"proof": {
|
|
63
|
+
"type": "JsonWebSignature2020",
|
|
64
|
+
"created": "2023-06-29T22:20:27.000Z",
|
|
65
|
+
"proofPurpose": "assertionMethod",
|
|
66
|
+
"verificationMethod": "did:web:example.com#key-1",
|
|
67
|
+
"jws": "ey......."
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
|
|
76
|
+
}
|
|
77
|
+
```
|
|
25
78
|
|
|
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
79
|
|
|
28
|
-
##
|
|
80
|
+
## Configure API
|
|
29
81
|
|
|
30
|
-
|
|
82
|
+
You can configure and build the API in multiple ways. This module also exposes functions for every endpoint, so you are
|
|
83
|
+
able to create your own Express router and then use functions to enable certain endpoints in your solution. The more
|
|
84
|
+
easy route is to use the `VcApiServer` class. This class has configuration support, allowing to enable/disable
|
|
85
|
+
certain features, like for instance whether VCs can be created, persisted, and/or verified.
|
|
31
86
|
|
|
32
|
-
|
|
87
|
+
Note: You can have multiple instances of the VcApiServer, as long as you make sure that the basePaths differs
|
|
88
|
+
for each instance and that the same express is being used.
|
|
33
89
|
|
|
34
90
|
```typescript
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
91
|
+
// agent is a configured SSI-SDK/Veramo agent (see below for an example)
|
|
92
|
+
|
|
93
|
+
// Let's first build express to listen on port 5000
|
|
94
|
+
const expressBuilder = ExpressBuilder.fromServerOpts({
|
|
95
|
+
port: 5000,
|
|
96
|
+
hostname: '0.0.0.0',
|
|
97
|
+
}).withPassportAuth(false)
|
|
98
|
+
const expressArgs = expressBuilder.build({ startListening: true })
|
|
99
|
+
|
|
100
|
+
// Now create the VC PI, with VC issuance, persistence and verification enabled and authentication disabled
|
|
101
|
+
new VcApiServer({
|
|
102
|
+
opts: {
|
|
103
|
+
endpointOpts: {
|
|
104
|
+
globalAuth: {
|
|
105
|
+
authentication: {
|
|
106
|
+
enabled: false,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
issueCredentialOpts: {
|
|
111
|
+
enableFeatures: ['vc-issue', 'vc-persist', 'vc-verify'],
|
|
112
|
+
proofFormat: 'lds', // Issue JSON-LD VCs, can also be changed to `jwt`
|
|
113
|
+
fetchRemoteContexts: true, // Whether to allow fetching remote contexts, mainly used when verifying VCs
|
|
114
|
+
keyRef: '89a4661e446b46401325a38d3b20582d1dd277eb448a3181012a671b7ae15837', // The key to use when signing VCs
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
expressArgs,
|
|
118
|
+
agent,
|
|
119
|
+
})
|
|
120
|
+
// At this point you can execute the example above, as the VC API is now listening on port 5000
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Requirements
|
|
124
|
+
|
|
125
|
+
For this plugin a DID resolver is also required. A DID resolver can be added to the agent as plugin as seen in the
|
|
126
|
+
example below. You can find resolvers in the Veramo project and our
|
|
127
|
+
[SSI-SDK-crypto-extensions](https://github.com/Sphereon-Opensource/SSI-SDK-crypto-extensions.git)
|
|
128
|
+
|
|
129
|
+
### Agent setup
|
|
40
130
|
|
|
41
|
-
|
|
131
|
+
```typescript
|
|
132
|
+
export const resolver = new Resolver({
|
|
133
|
+
...getDidWebResolver(),
|
|
134
|
+
...getDidKeyResolver(),
|
|
135
|
+
...getDidJwkResolver(),
|
|
136
|
+
...getDidIonResolver(),
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
export const didProviders = {
|
|
140
|
+
[`did:web`]: new WebDIDProvider({
|
|
141
|
+
defaultKms: 'local',
|
|
142
|
+
}),
|
|
143
|
+
[`did:key`]: new KeyDIDProvider({
|
|
144
|
+
defaultKms: 'local',
|
|
145
|
+
}),
|
|
146
|
+
[`did:ion`]: new IonDIDProvider({
|
|
147
|
+
defaultKms: 'local',
|
|
148
|
+
}),
|
|
149
|
+
[`did:jwk`]: new JwkDIDProvider({
|
|
150
|
+
defaultKms: 'local',
|
|
151
|
+
}),
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const agent = createAgent<
|
|
155
|
+
IDIDManager &
|
|
156
|
+
IKeyManager &
|
|
157
|
+
IDataStore &
|
|
158
|
+
IDataStoreORM &
|
|
159
|
+
IResolver &
|
|
160
|
+
IPresentationExchange &
|
|
161
|
+
ICredentialVerifier &
|
|
162
|
+
ICredentialHandlerLDLocal &
|
|
163
|
+
ICredentialPlugin
|
|
164
|
+
>({
|
|
42
165
|
plugins: [
|
|
43
|
-
new
|
|
166
|
+
new DataStore(dbConnection),
|
|
167
|
+
new DataStoreORM(dbConnection),
|
|
168
|
+
new KeyManager({
|
|
169
|
+
store: new KeyStore(dbConnection),
|
|
170
|
+
kms: {
|
|
171
|
+
local: new KeyManagementSystem(privateKeyStore),
|
|
172
|
+
},
|
|
173
|
+
}),
|
|
174
|
+
new DIDManager({
|
|
175
|
+
store: new DIDStore(dbConnection),
|
|
176
|
+
defaultProvider: `${DID_PREFIX}:${SupportedDidMethodEnum.DID_JWK}`,
|
|
177
|
+
providers: didProviders,
|
|
178
|
+
}),
|
|
44
179
|
new DIDResolverPlugin({
|
|
45
|
-
resolver
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
180
|
+
resolver,
|
|
181
|
+
}),
|
|
182
|
+
new PresentationExchange(),
|
|
183
|
+
new CredentialPlugin(),
|
|
184
|
+
new CredentialHandlerLDLocal({
|
|
185
|
+
contextMaps: [LdDefaultContexts],
|
|
186
|
+
suites: [
|
|
187
|
+
new SphereonEd25519Signature2018(),
|
|
188
|
+
new SphereonEd25519Signature2020(),
|
|
189
|
+
new SphereonBbsBlsSignature2020(),
|
|
190
|
+
new SphereonJsonWebSignature2020(),
|
|
191
|
+
new SphereonEcdsaSecp256k1RecoverySignature2020(),
|
|
192
|
+
],
|
|
193
|
+
bindingOverrides: new Map([
|
|
194
|
+
['createVerifiableCredentialLD', MethodNames.createVerifiableCredentialLDLocal],
|
|
195
|
+
['createVerifiablePresentationLD', MethodNames.createVerifiablePresentationLDLocal],
|
|
196
|
+
]),
|
|
197
|
+
keyStore: privateKeyStore,
|
|
50
198
|
}),
|
|
51
199
|
],
|
|
52
200
|
})
|
|
@@ -55,11 +203,11 @@ const agent = createAgent<IDidAuthSiopOpAuthenticator & IResolver>({
|
|
|
55
203
|
## Installation
|
|
56
204
|
|
|
57
205
|
```shell
|
|
58
|
-
|
|
206
|
+
pnpm add @sphereon/ssi-sdk.w3c-vc-api
|
|
59
207
|
```
|
|
60
208
|
|
|
61
209
|
## Build
|
|
62
210
|
|
|
63
211
|
```shell
|
|
64
|
-
|
|
212
|
+
pnpm build
|
|
65
213
|
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ISingleEndpointOpts } from '@sphereon/ssi-sdk.express-support';
|
|
2
|
+
import { Router } from 'express';
|
|
3
|
+
import { IIssueCredentialEndpointOpts, IRequiredContext, IVerifyCredentialEndpointOpts } from './types';
|
|
4
|
+
export declare function issueCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IIssueCredentialEndpointOpts): void;
|
|
5
|
+
export declare function getCredentialsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
6
|
+
export declare function getCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
7
|
+
export declare function verifyCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IVerifyCredentialEndpointOpts): void;
|
|
8
|
+
export declare function deleteCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
9
|
+
//# 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":"AACA,OAAO,EAAa,mBAAmB,EAAqB,MAAM,mCAAmC,CAAA;AAGrG,OAAO,EAAqB,MAAM,EAAE,MAAM,SAAS,CAAA;AAEnD,OAAO,EAAE,4BAA4B,EAAE,gBAAgB,EAAmB,6BAA6B,EAAE,MAAM,SAAS,CAAA;AAExH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE,4BAA4B,QA6BrH;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE,mBAAmB,QAe3G;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE,mBAAmB,QAsB1G;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE,6BAA6B,QAwBvH;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE,mBAAmB,QAyB7G"}
|
|
@@ -0,0 +1,150 @@
|
|
|
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.deleteCredentialEndpoint = exports.verifyCredentialEndpoint = exports.getCredentialEndpoint = exports.getCredentialsEndpoint = exports.issueCredentialEndpoint = void 0;
|
|
13
|
+
const ssi_sdk_core_1 = require("@sphereon/ssi-sdk.core");
|
|
14
|
+
const ssi_sdk_express_support_1 = require("@sphereon/ssi-sdk.express-support");
|
|
15
|
+
const uuid_1 = require("uuid");
|
|
16
|
+
function issueCredentialEndpoint(router, context, opts) {
|
|
17
|
+
var _a;
|
|
18
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
19
|
+
console.log(`Issue credential endpoint is disabled`);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials/issue';
|
|
23
|
+
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* () {
|
|
24
|
+
var _b;
|
|
25
|
+
try {
|
|
26
|
+
const credential = request.body.credential;
|
|
27
|
+
if (!credential) {
|
|
28
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 400, 'No credential supplied');
|
|
29
|
+
}
|
|
30
|
+
if (!credential.id) {
|
|
31
|
+
credential.id = `urn:uuid:${(0, uuid_1.v4)()}`;
|
|
32
|
+
}
|
|
33
|
+
const issueOpts = opts === null || opts === void 0 ? void 0 : opts.issueCredentialOpts;
|
|
34
|
+
const vc = yield context.agent.createVerifiableCredential({
|
|
35
|
+
credential,
|
|
36
|
+
save: (opts === null || opts === void 0 ? void 0 : opts.persistIssuedCredentials) !== false,
|
|
37
|
+
proofFormat: (_b = issueOpts === null || issueOpts === void 0 ? void 0 : issueOpts.proofFormat) !== null && _b !== void 0 ? _b : 'lds',
|
|
38
|
+
fetchRemoteContexts: (issueOpts === null || issueOpts === void 0 ? void 0 : issueOpts.fetchRemoteContexts) !== false,
|
|
39
|
+
});
|
|
40
|
+
response.statusCode = 201;
|
|
41
|
+
return response.send({ verifiableCredential: vc });
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
45
|
+
}
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
exports.issueCredentialEndpoint = issueCredentialEndpoint;
|
|
49
|
+
function getCredentialsEndpoint(router, context, opts) {
|
|
50
|
+
var _a;
|
|
51
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
52
|
+
console.log(`Get credentials endpoint is disabled`);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials';
|
|
56
|
+
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* () {
|
|
57
|
+
try {
|
|
58
|
+
const uniqueVCs = yield context.agent.dataStoreORMGetVerifiableCredentials();
|
|
59
|
+
response.statusCode = 202;
|
|
60
|
+
return response.send(uniqueVCs.map((uVC) => uVC.verifiableCredential));
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
exports.getCredentialsEndpoint = getCredentialsEndpoint;
|
|
68
|
+
function getCredentialEndpoint(router, context, opts) {
|
|
69
|
+
var _a;
|
|
70
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
71
|
+
console.log(`Get credential endpoint is disabled`);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials/:id';
|
|
75
|
+
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* () {
|
|
76
|
+
try {
|
|
77
|
+
const id = request.params.id;
|
|
78
|
+
if (!id) {
|
|
79
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 400, 'no id provided');
|
|
80
|
+
}
|
|
81
|
+
let vcInfo = yield (0, ssi_sdk_core_1.getCredentialByIdOrHash)(context, id);
|
|
82
|
+
if (!vcInfo.vc) {
|
|
83
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 404, `id ${id} not found`);
|
|
84
|
+
}
|
|
85
|
+
response.statusCode = 200;
|
|
86
|
+
return response.send(vcInfo.vc);
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
90
|
+
}
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
exports.getCredentialEndpoint = getCredentialEndpoint;
|
|
94
|
+
function verifyCredentialEndpoint(router, context, opts) {
|
|
95
|
+
var _a;
|
|
96
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
97
|
+
console.log(`Verify credential endpoint is disabled`);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
router.post((_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials/verify', (0, ssi_sdk_express_support_1.checkAuth)(opts === null || opts === void 0 ? void 0 : opts.endpoint), (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
try {
|
|
102
|
+
console.log(request.body);
|
|
103
|
+
const credential = request.body.verifiableCredential;
|
|
104
|
+
// const options: IIssueOptionsPayload = request.body.options
|
|
105
|
+
if (!credential) {
|
|
106
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 400, 'No verifiable credential supplied');
|
|
107
|
+
}
|
|
108
|
+
const verifyResult = yield context.agent.verifyCredential({
|
|
109
|
+
credential,
|
|
110
|
+
fetchRemoteContexts: (opts === null || opts === void 0 ? void 0 : opts.fetchRemoteContexts) !== false,
|
|
111
|
+
});
|
|
112
|
+
response.statusCode = 200;
|
|
113
|
+
return response.send(verifyResult);
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
117
|
+
}
|
|
118
|
+
}));
|
|
119
|
+
}
|
|
120
|
+
exports.verifyCredentialEndpoint = verifyCredentialEndpoint;
|
|
121
|
+
function deleteCredentialEndpoint(router, context, opts) {
|
|
122
|
+
var _a;
|
|
123
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
124
|
+
console.log(`Delete credential endpoint is disabled`);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
router.delete((_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials/:id', (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* () {
|
|
128
|
+
try {
|
|
129
|
+
const id = request.params.id;
|
|
130
|
+
if (!id) {
|
|
131
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 400, 'no id provided');
|
|
132
|
+
}
|
|
133
|
+
let vcInfo = yield (0, ssi_sdk_core_1.getCredentialByIdOrHash)(context, id);
|
|
134
|
+
if (!vcInfo.vc || !vcInfo.hash) {
|
|
135
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 404, `id ${id} not found`);
|
|
136
|
+
}
|
|
137
|
+
const success = context.agent.dataStoreDeleteVerifiableCredential({ hash: vcInfo.hash });
|
|
138
|
+
if (!success) {
|
|
139
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 400, `Could not delete Verifiable Credential with id ${id}`);
|
|
140
|
+
}
|
|
141
|
+
response.statusCode = 200;
|
|
142
|
+
return response.send();
|
|
143
|
+
}
|
|
144
|
+
catch (e) {
|
|
145
|
+
return (0, ssi_sdk_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
146
|
+
}
|
|
147
|
+
}));
|
|
148
|
+
}
|
|
149
|
+
exports.deleteCredentialEndpoint = deleteCredentialEndpoint;
|
|
150
|
+
//# sourceMappingURL=api-functions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-functions.js","sourceRoot":"","sources":["../src/api-functions.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAAgE;AAChE,+EAAqG;AAIrG,+BAAyB;AAGzB,SAAgB,uBAAuB,CAAC,MAAc,EAAE,OAAyB,EAAE,IAAmC;;IACpH,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,MAAK,KAAK,EAAE;QAC3B,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAA;QACpD,OAAM;KACP;IACD,MAAM,IAAI,GAAG,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,mCAAI,oBAAoB,CAAA;IAE/C,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAA,mCAAS,EAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,QAAQ,CAAC,EAAE,CAAO,OAAgB,EAAE,QAAkB,EAAE,EAAE;;QAC1F,IAAI;YACF,MAAM,UAAU,GAAsB,OAAO,CAAC,IAAI,CAAC,U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E,EAAE,CAAC,CAAA;YACvD,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;gBAC9B,OAAO,IAAA,2CAAiB,EAAC,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,CAAA;aAC9D;YACD,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,mCAAmC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAA;YACxF,IAAI,CAAC,OAAO,EAAE;gBACZ,OAAO,IAAA,2CAAiB,EAAC,QAAQ,EAAE,GAAG,EAAE,kDAAkD,EAAE,EAAE,CAAC,CAAA;aAChG;YACD,QAAQ,CAAC,UAAU,GAAG,GAAG,CAAA;YACzB,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;SACvB;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,IAAA,2CAAiB,EAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC,OAAiB,EAAE,CAAC,CAAC,CAAA;SAChE;IACH,CAAC,CAAA,CAAC,CAAA;AACJ,CAAC;AAzBD,4DAyBC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,iBAAiB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
/**
|
|
18
18
|
* @public
|
|
19
19
|
*/
|
|
20
|
-
__exportStar(require("./
|
|
20
|
+
__exportStar(require("./vc-api-server"), exports);
|
|
21
21
|
__exportStar(require("./types"), exports);
|
|
22
|
+
__exportStar(require("./api-functions"), exports);
|
|
22
23
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,kDAA+B;AAC/B,0CAAuB;AACvB,kDAA+B"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,66 @@
|
|
|
1
|
+
import { GenericAuthArgs, ISingleEndpointOpts } from '@sphereon/ssi-sdk.express-support';
|
|
1
2
|
import { IAgentContext, ICredentialIssuer, ICredentialPlugin, ICredentialVerifier, IDataStore, IDataStoreORM, IDIDManager, IKeyManager, IResolver } from '@veramo/core';
|
|
2
|
-
import {
|
|
3
|
-
export type IRequiredPlugins = IDataStore & IDataStoreORM & IDIDManager & IKeyManager & ICredentialIssuer & ICredentialVerifier &
|
|
3
|
+
import { ProofFormat } from '@veramo/core/src/types/ICredentialIssuer';
|
|
4
|
+
export type IRequiredPlugins = IDataStore & IDataStoreORM & IDIDManager & IKeyManager & ICredentialIssuer & ICredentialVerifier & ICredentialPlugin & IResolver;
|
|
4
5
|
export type IRequiredContext = IAgentContext<IRequiredPlugins>;
|
|
6
|
+
export interface IVCAPIOpts {
|
|
7
|
+
endpointOpts?: IVCAPIEndpointOpts;
|
|
8
|
+
issueCredentialOpts?: IVCAPIIssueOpts;
|
|
9
|
+
}
|
|
10
|
+
export interface IVCAPIEndpointOpts {
|
|
11
|
+
basePath?: string;
|
|
12
|
+
globalAuth?: GenericAuthArgs;
|
|
13
|
+
issueCredential?: IIssueCredentialEndpointOpts;
|
|
14
|
+
getCredentials?: ISingleEndpointOpts;
|
|
15
|
+
getCredential?: ISingleEndpointOpts;
|
|
16
|
+
deleteCredential?: ISingleEndpointOpts;
|
|
17
|
+
verifyCredential?: IVerifyCredentialEndpointOpts;
|
|
18
|
+
verifyPresentation?: ISingleEndpointOpts;
|
|
19
|
+
}
|
|
20
|
+
export type vcApiFeatures = 'vc-verify' | 'vc-issue' | 'vc-persist';
|
|
21
|
+
export interface IVCAPIIssueOpts {
|
|
22
|
+
enableFeatures?: vcApiFeatures[];
|
|
23
|
+
persistIssuedCredentials?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* The desired format for the VerifiablePresentation to be created.
|
|
26
|
+
*/
|
|
27
|
+
proofFormat: ProofFormat;
|
|
28
|
+
/**
|
|
29
|
+
* Remove payload members during JWT-JSON transformation. Defaults to `true`.
|
|
30
|
+
* See https://www.w3.org/TR/vc-data-model/#jwt-encoding
|
|
31
|
+
*/
|
|
32
|
+
removeOriginalFields?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* [Optional] The ID of the key that should sign this credential.
|
|
35
|
+
* If this is not specified, the first matching key will be used.
|
|
36
|
+
*/
|
|
37
|
+
keyRef?: string;
|
|
38
|
+
/**
|
|
39
|
+
* When dealing with JSON-LD you also MUST provide the proper contexts.
|
|
40
|
+
* Set this to `true` ONLY if you want the `@context` URLs to be fetched in case they are not preloaded.
|
|
41
|
+
* The context definitions SHOULD rather be provided at startup instead of being fetched.
|
|
42
|
+
*
|
|
43
|
+
* Defaults to `false`
|
|
44
|
+
*/
|
|
45
|
+
fetchRemoteContexts?: boolean;
|
|
46
|
+
}
|
|
47
|
+
export interface IIssueCredentialEndpointOpts extends ISingleEndpointOpts {
|
|
48
|
+
issueCredentialOpts?: IVCAPIIssueOpts;
|
|
49
|
+
persistIssuedCredentials?: boolean;
|
|
50
|
+
}
|
|
51
|
+
export interface IVerifyCredentialEndpointOpts extends ISingleEndpointOpts {
|
|
52
|
+
fetchRemoteContexts?: boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface IIssueOptionsPayload {
|
|
55
|
+
created?: string;
|
|
56
|
+
challenge?: string;
|
|
57
|
+
domain?: string;
|
|
58
|
+
credentialStatus?: {
|
|
59
|
+
type: string;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export interface ChallengeOptsPayload {
|
|
63
|
+
challenge?: string;
|
|
64
|
+
domain?: string;
|
|
65
|
+
}
|
|
5
66
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,UAAU,EACV,aAAa,EACb,WAAW,EACX,WAAW,EACX,SAAS,EACV,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAA;AACxF,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,UAAU,EACV,aAAa,EACb,WAAW,EACX,WAAW,EACX,SAAS,EACV,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAA;AAEtE,MAAM,MAAM,gBAAgB,GAAG,UAAU,GACvC,aAAa,GACb,WAAW,GACX,WAAW,GACX,iBAAiB,GACjB,mBAAmB,GACnB,iBAAiB,GACjB,SAAS,CAAA;AACX,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAAC,gBAAgB,CAAC,CAAA;AAI9D,MAAM,WAAW,UAAU;IACzB,YAAY,CAAC,EAAE,kBAAkB,CAAA;IAEjC,mBAAmB,CAAC,EAAE,eAAe,CAAA;CACtC;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,U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sphereon/ssi-sdk.express-support';
|
|
2
|
+
import { TAgent } from '@veramo/core';
|
|
3
|
+
import express, { Express } from 'express';
|
|
4
|
+
import { IRequiredPlugins, IVCAPIOpts } from './types';
|
|
5
|
+
export declare class VcApiServer {
|
|
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?: IVCAPIOpts;
|
|
15
|
+
});
|
|
16
|
+
get agent(): TAgent<IRequiredPlugins>;
|
|
17
|
+
get opts(): IVCAPIOpts | undefined;
|
|
18
|
+
get express(): Express;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=vc-api-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vc-api-server.d.ts","sourceRoot":"","sources":["../src/vc-api-server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,OAAO,OAAO,EAAE,EAAE,OAAO,EAAU,MAAM,SAAS,CAAA;AAQlD,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEtD,qBAAa,WAAW;IACtB,IAAI,MAAM,IAAI,OAAO,CAAC,MAAM,CAE3B;IAED,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0B;IACjD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAY;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAQ;gBAEpB,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAAC,WAAW,EAAE,kBAAkB,CAAC;QAAC,IAAI,CAAC,EAAE,UAAU,CAAA;KAAE;IAyCzG,IAAI,KAAK,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAEpC;IAED,IAAI,IAAI,IAAI,UAAU,GAAG,SAAS,CAEjC;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;CACF"}
|
|
@@ -0,0 +1,65 @@
|
|
|
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.VcApiServer = 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
|
+
class VcApiServer {
|
|
11
|
+
get router() {
|
|
12
|
+
return this._router;
|
|
13
|
+
}
|
|
14
|
+
constructor(args) {
|
|
15
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
16
|
+
const { agent, opts } = args;
|
|
17
|
+
this._agent = agent;
|
|
18
|
+
if ((_a = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _a === void 0 ? void 0 : _a.globalAuth) {
|
|
19
|
+
copyGlobalAuthToEndpoint(opts, 'issueCredential');
|
|
20
|
+
copyGlobalAuthToEndpoint(opts, 'getCredential');
|
|
21
|
+
copyGlobalAuthToEndpoint(opts, 'getCredentials');
|
|
22
|
+
copyGlobalAuthToEndpoint(opts, 'deleteCredential');
|
|
23
|
+
copyGlobalAuthToEndpoint(opts, 'verifyCredential');
|
|
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.issueCredentialOpts) === null || _b === void 0 ? void 0 : _b.enableFeatures) !== null && _c !== void 0 ? _c : ['vc-issue', 'vc-persist', 'vc-verify'];
|
|
30
|
+
console.log(`VC API enabled, with features: ${JSON.stringify(features)}`);
|
|
31
|
+
// Credential endpoints
|
|
32
|
+
if (features.includes('vc-issue')) {
|
|
33
|
+
(0, api_functions_1.issueCredentialEndpoint)(this.router, context, Object.assign(Object.assign({}, (_d = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _d === void 0 ? void 0 : _d.issueCredential), { issueCredentialOpts: opts === null || opts === void 0 ? void 0 : opts.issueCredentialOpts }));
|
|
34
|
+
}
|
|
35
|
+
if (features.includes('vc-persist')) {
|
|
36
|
+
(0, api_functions_1.getCredentialEndpoint)(this.router, context, (_e = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _e === void 0 ? void 0 : _e.getCredential);
|
|
37
|
+
(0, api_functions_1.getCredentialsEndpoint)(this.router, context, (_f = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _f === void 0 ? void 0 : _f.getCredentials);
|
|
38
|
+
(0, api_functions_1.deleteCredentialEndpoint)(this.router, context, (_g = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _g === void 0 ? void 0 : _g.deleteCredential); // not in spec.
|
|
39
|
+
}
|
|
40
|
+
if (features.includes('vc-verify')) {
|
|
41
|
+
(0, api_functions_1.verifyCredentialEndpoint)(this.router, context, Object.assign(Object.assign({}, (_h = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _h === void 0 ? void 0 : _h.verifyCredential), { fetchRemoteContexts: (_j = opts === null || opts === void 0 ? void 0 : opts.issueCredentialOpts) === null || _j === void 0 ? void 0 : _j.fetchRemoteContexts }));
|
|
42
|
+
}
|
|
43
|
+
this._express.use((_l = (_k = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _k === void 0 ? void 0 : _k.basePath) !== null && _l !== void 0 ? _l : '', this.router);
|
|
44
|
+
}
|
|
45
|
+
get agent() {
|
|
46
|
+
return this._agent;
|
|
47
|
+
}
|
|
48
|
+
get opts() {
|
|
49
|
+
return this._opts;
|
|
50
|
+
}
|
|
51
|
+
get express() {
|
|
52
|
+
return this._express;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.VcApiServer = VcApiServer;
|
|
56
|
+
function copyGlobalAuthToEndpoint(opts, key) {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
if ((_a = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _a === void 0 ? void 0 : _a.globalAuth) {
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
opts.endpointOpts[key] = Object.assign(Object.assign({}, opts.endpointOpts[key]), {
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
endpoint: Object.assign(Object.assign({}, opts.endpointOpts.globalAuth), (_b = opts.endpointOpts[key]) === null || _b === void 0 ? void 0 : _b.endpoint) });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=vc-api-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vc-api-server.js","sourceRoot":"","sources":["../src/vc-api-server.ts"],"names":[],"mappings":";;;;;;AAAA,yDAAqD;AAIrD,sDAAkD;AAClD,mDAMwB;AAGxB,MAAa,WAAW;IACtB,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;IAOD,YAAY,IAA6F;;QACvG,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,CAAA;QAC5B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACnB,IAAI,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,YAAY,0CAAE,UAAU,EAAE;YAClC,wBAAwB,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAA;YACjD,wBAAwB,CAAC,IAAI,EAAE,eAAe,CAAC,CAAA;YAC/C,wBAAwB,CAAC,IAAI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