@cef-ebsi/cli 0.0.0-alpha.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/LICENSE +190 -0
- package/README.md +32 -0
- package/bin/cli.js +13 -0
- package/dist/abi/pilot/DidRegistry-old.json +2192 -0
- package/dist/abi/pilot/DidRegistry.json +1081 -0
- package/dist/abi/pilot/DidRegistryV3.json +1081 -0
- package/dist/abi/pilot/SchemaSCRegistry.json +972 -0
- package/dist/abi/pilot/SchemaSCRegistryV2.json +473 -0
- package/dist/abi/pilot/Tar.json +1394 -0
- package/dist/abi/pilot/TarV3.json +1107 -0
- package/dist/abi/pilot/Timestamp.json +1091 -0
- package/dist/abi/pilot/TimestampV2.json +1127 -0
- package/dist/abi/pilot/Tir.json +896 -0
- package/dist/abi/pilot/TirV3.json +495 -0
- package/dist/abi/pilot/Tpr.json +1267 -0
- package/dist/abi/pilot/TprV2.json +888 -0
- package/dist/abi/test/DidRegistry-old.json +2192 -0
- package/dist/abi/test/DidRegistry.json +1081 -0
- package/dist/abi/test/DidRegistryV3.json +1088 -0
- package/dist/abi/test/SchemaSCRegistry.json +972 -0
- package/dist/abi/test/SchemaSCRegistryV2.json +473 -0
- package/dist/abi/test/Tar.json +1394 -0
- package/dist/abi/test/TarV3.json +1107 -0
- package/dist/abi/test/Timestamp.json +1091 -0
- package/dist/abi/test/TimestampV2.json +1127 -0
- package/dist/abi/test/Tir.json +896 -0
- package/dist/abi/test/TirV3.json +495 -0
- package/dist/abi/test/Tpr.json +1267 -0
- package/dist/abi/test/TprV2.json +888 -0
- package/dist/app.js +1205 -0
- package/dist/app.js.map +1 -0
- package/dist/buildParam/did.js +355 -0
- package/dist/buildParam/did.js.map +1 -0
- package/dist/buildParam/didOld.js +275 -0
- package/dist/buildParam/didOld.js.map +1 -0
- package/dist/buildParam/didV3.js +353 -0
- package/dist/buildParam/didV3.js.map +1 -0
- package/dist/buildParam/index.js +54 -0
- package/dist/buildParam/index.js.map +1 -0
- package/dist/buildParam/tar.js +240 -0
- package/dist/buildParam/tar.js.map +1 -0
- package/dist/buildParam/tarV3.js +193 -0
- package/dist/buildParam/tarV3.js.map +1 -0
- package/dist/buildParam/timestamp.js +323 -0
- package/dist/buildParam/timestamp.js.map +1 -0
- package/dist/buildParam/timestampV2.js +317 -0
- package/dist/buildParam/timestampV2.js.map +1 -0
- package/dist/buildParam/tir.js +200 -0
- package/dist/buildParam/tir.js.map +1 -0
- package/dist/buildParam/tirV3.js +104 -0
- package/dist/buildParam/tirV3.js.map +1 -0
- package/dist/buildParam/tpr.js +167 -0
- package/dist/buildParam/tpr.js.map +1 -0
- package/dist/buildParam/tprV2.js +82 -0
- package/dist/buildParam/tprV2.js.map +1 -0
- package/dist/buildParam/tsr.js +149 -0
- package/dist/buildParam/tsr.js.map +1 -0
- package/dist/buildParam/tsrV2.js +110 -0
- package/dist/buildParam/tsrV2.js.map +1 -0
- package/dist/cli.js +10 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/authorisation-v3.js +98 -0
- package/dist/commands/authorisation-v3.js.map +1 -0
- package/dist/commands/authorisation-v4.js +221 -0
- package/dist/commands/authorisation-v4.js.map +1 -0
- package/dist/commands/compute.js +374 -0
- package/dist/commands/compute.js.map +1 -0
- package/dist/commands/conformance-v3.js +745 -0
- package/dist/commands/conformance-v3.js.map +1 -0
- package/dist/commands/conformance-v4.js +767 -0
- package/dist/commands/conformance-v4.js.map +1 -0
- package/dist/commands/index.js +9 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/ledger-v3.js +189 -0
- package/dist/commands/ledger-v3.js.map +1 -0
- package/dist/commands/ledger-v4.js +188 -0
- package/dist/commands/ledger-v4.js.map +1 -0
- package/dist/commands/view.js +62 -0
- package/dist/commands/view.js.map +1 -0
- package/dist/config.js +910 -0
- package/dist/config.js.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/authorisation/authorisation.interface.js +2 -0
- package/dist/interfaces/authorisation/authorisation.interface.js.map +1 -0
- package/dist/interfaces/authorisation/index.js +2 -0
- package/dist/interfaces/authorisation/index.js.map +1 -0
- package/dist/interfaces/context.js +2 -0
- package/dist/interfaces/context.js.map +1 -0
- package/dist/interfaces/index.js +10 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/ledger/besu.interface.js +2 -0
- package/dist/interfaces/ledger/besu.interface.js.map +1 -0
- package/dist/interfaces/ledger/index.js +2 -0
- package/dist/interfaces/ledger/index.js.map +1 -0
- package/dist/interfaces/notifications/index.js +2 -0
- package/dist/interfaces/notifications/index.js.map +1 -0
- package/dist/interfaces/notifications/notifications.interface.js +2 -0
- package/dist/interfaces/notifications/notifications.interface.js.map +1 -0
- package/dist/interfaces/proxy-data-hub/attributes.interface.js +2 -0
- package/dist/interfaces/proxy-data-hub/attributes.interface.js.map +1 -0
- package/dist/interfaces/proxy-data-hub/index.js +2 -0
- package/dist/interfaces/proxy-data-hub/index.js.map +1 -0
- package/dist/interfaces/shared/index.js +5 -0
- package/dist/interfaces/shared/index.js.map +1 -0
- package/dist/interfaces/shared/jsonrpc.interface.js +2 -0
- package/dist/interfaces/shared/jsonrpc.interface.js.map +1 -0
- package/dist/interfaces/shared/paginated-list.interface.js +2 -0
- package/dist/interfaces/shared/paginated-list.interface.js.map +1 -0
- package/dist/interfaces/shared/unsigned-transaction.interface.js +2 -0
- package/dist/interfaces/shared/unsigned-transaction.interface.js.map +1 -0
- package/dist/interfaces/shared/utils.interface.js +2 -0
- package/dist/interfaces/shared/utils.interface.js.map +1 -0
- package/dist/interfaces/timestamp/hash-algorithms.interface.js +2 -0
- package/dist/interfaces/timestamp/hash-algorithms.interface.js.map +1 -0
- package/dist/interfaces/timestamp/index.js +4 -0
- package/dist/interfaces/timestamp/index.js.map +1 -0
- package/dist/interfaces/timestamp/records.interface.js +2 -0
- package/dist/interfaces/timestamp/records.interface.js.map +1 -0
- package/dist/interfaces/timestamp/timestamps.interface.js +2 -0
- package/dist/interfaces/timestamp/timestamps.interface.js.map +1 -0
- package/dist/interfaces/trusted-apps-registry/apps.interface.js +2 -0
- package/dist/interfaces/trusted-apps-registry/apps.interface.js.map +1 -0
- package/dist/interfaces/trusted-apps-registry/index.js +3 -0
- package/dist/interfaces/trusted-apps-registry/index.js.map +1 -0
- package/dist/interfaces/trusted-apps-registry/policies.interface.js +2 -0
- package/dist/interfaces/trusted-apps-registry/policies.interface.js.map +1 -0
- package/dist/interfaces/trusted-issuers-registry/index.js +2 -0
- package/dist/interfaces/trusted-issuers-registry/index.js.map +1 -0
- package/dist/interfaces/trusted-issuers-registry/issuers.interface.js +2 -0
- package/dist/interfaces/trusted-issuers-registry/issuers.interface.js.map +1 -0
- package/dist/interfaces/users-onboarding/authentication.js +2 -0
- package/dist/interfaces/users-onboarding/authentication.js.map +1 -0
- package/dist/interfaces/users-onboarding/index.js +2 -0
- package/dist/interfaces/users-onboarding/index.js.map +1 -0
- package/dist/programs/appRegistration.js +65 -0
- package/dist/programs/appRegistration.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utils/Client.js +176 -0
- package/dist/utils/Client.js.map +1 -0
- package/dist/utils/authorisation.js +118 -0
- package/dist/utils/authorisation.js.map +1 -0
- package/dist/utils/http.js +128 -0
- package/dist/utils/http.js.map +1 -0
- package/dist/utils/index.js +10 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/jsonrpc.js +33 -0
- package/dist/utils/jsonrpc.js.map +1 -0
- package/dist/utils/notification.js +51 -0
- package/dist/utils/notification.js.map +1 -0
- package/dist/utils/print.js +57 -0
- package/dist/utils/print.js.map +1 -0
- package/dist/utils/storage.js +97 -0
- package/dist/utils/storage.js.map +1 -0
- package/dist/utils/utils.js +161 -0
- package/dist/utils/utils.js.map +1 -0
- package/dist/utils/verifiablePresentation.js +43 -0
- package/dist/utils/verifiablePresentation.js.map +1 -0
- package/package.json +113 -0
|
@@ -0,0 +1,767 @@
|
|
|
1
|
+
import { randomUUID, randomBytes, createHash } from "node:crypto";
|
|
2
|
+
import { URLSearchParams } from "node:url";
|
|
3
|
+
import Joi from "joi";
|
|
4
|
+
import qs from "qs";
|
|
5
|
+
import { base64url } from "multiformats/bases/base64";
|
|
6
|
+
import { importJWK, SignJWT } from "jose";
|
|
7
|
+
import { compute, getUserPin } from "./compute.js";
|
|
8
|
+
import { httpCall, red } from "../utils/index.js";
|
|
9
|
+
function stringify(obj, fields) {
|
|
10
|
+
if (typeof obj !== "object")
|
|
11
|
+
throw new Error("not an object");
|
|
12
|
+
const newObj = {};
|
|
13
|
+
fields.forEach((f) => {
|
|
14
|
+
if (obj[f])
|
|
15
|
+
newObj[f] = obj[f];
|
|
16
|
+
});
|
|
17
|
+
return JSON.stringify(newObj);
|
|
18
|
+
}
|
|
19
|
+
export async function conformanceGet(inputs, context) {
|
|
20
|
+
const apiUrl = context.config.api["conformance-new"].url;
|
|
21
|
+
const urlPath = inputs.join("");
|
|
22
|
+
const url = urlPath.startsWith("http") ? urlPath : `${apiUrl}${urlPath}`;
|
|
23
|
+
const response = await httpCall.get(url, context.httpOpts);
|
|
24
|
+
return response.data;
|
|
25
|
+
}
|
|
26
|
+
export async function clientMockInitiate(context) {
|
|
27
|
+
const apiUrl = context.config.api["conformance-new"].url;
|
|
28
|
+
const { accreditationUrl, proxyId, issuerState } = context.rtVars.user;
|
|
29
|
+
const response = await httpCall.post(`${apiUrl}/client-mock/initiate`, {
|
|
30
|
+
did: context.client.did,
|
|
31
|
+
keys: Object.keys(context.client.keys).map((keyName) => {
|
|
32
|
+
const key = context.client.keys[keyName];
|
|
33
|
+
return {
|
|
34
|
+
...key.privateKeyJwk,
|
|
35
|
+
kid: key.id,
|
|
36
|
+
};
|
|
37
|
+
}),
|
|
38
|
+
...(accreditationUrl && { attributeUrl: accreditationUrl }),
|
|
39
|
+
...(proxyId && { proxyId }),
|
|
40
|
+
...(issuerState && { issuerState }),
|
|
41
|
+
});
|
|
42
|
+
context.client.clientId = `${apiUrl}/client-mock/${context.client.did}`;
|
|
43
|
+
context.rtVars.user.clientId =
|
|
44
|
+
context.client.clientId;
|
|
45
|
+
return response.data;
|
|
46
|
+
}
|
|
47
|
+
export async function clientMockUpdateList(inputs, context) {
|
|
48
|
+
const [statusIndex, statusListIndex, value] = inputs;
|
|
49
|
+
const apiUrl = context.config.api["conformance-new"].url;
|
|
50
|
+
const response = await httpCall.post(`${apiUrl}/client-mock/updateList`, {
|
|
51
|
+
did: context.client.did,
|
|
52
|
+
id: statusIndex,
|
|
53
|
+
position: Number(statusListIndex),
|
|
54
|
+
value: Number(value),
|
|
55
|
+
});
|
|
56
|
+
return response.data;
|
|
57
|
+
}
|
|
58
|
+
export async function authMockAuthorize(inputs, context) {
|
|
59
|
+
const [openIdCredentialIssuer, openIdConfiguration, requestedTypes, inputAlg, codeVerifier, issuerState,] = inputs;
|
|
60
|
+
const alg = inputAlg || "ES256";
|
|
61
|
+
Joi.assert(requestedTypes, Joi.array());
|
|
62
|
+
Joi.assert(alg, Joi.string().valid("ES256K", "ES256", "EdDSA", "RS256"));
|
|
63
|
+
const isPKCEChallenge = !!codeVerifier;
|
|
64
|
+
const authorizationServer = openIdCredentialIssuer.authorization_server ??
|
|
65
|
+
openIdCredentialIssuer.credential_issuer;
|
|
66
|
+
const clientId = context.client.didVersion === 1
|
|
67
|
+
? context.client.clientId
|
|
68
|
+
: context.client.did;
|
|
69
|
+
let codeChallenge = "";
|
|
70
|
+
if (isPKCEChallenge) {
|
|
71
|
+
codeChallenge = base64url.baseEncode(createHash("sha256").update(codeVerifier).digest());
|
|
72
|
+
}
|
|
73
|
+
const clientMetadata = isPKCEChallenge
|
|
74
|
+
? {
|
|
75
|
+
authorization_endpoint: "openid:",
|
|
76
|
+
}
|
|
77
|
+
: {
|
|
78
|
+
redirect_uris: [`${context.client.clientId}/code-cb`],
|
|
79
|
+
jwks_uri: `${context.client.clientId}/jwks`,
|
|
80
|
+
authorization_endpoint: `${context.client.clientId}/authorize`,
|
|
81
|
+
};
|
|
82
|
+
const authorizationDetails = [
|
|
83
|
+
{
|
|
84
|
+
type: "openid_credential",
|
|
85
|
+
format: "jwt_vc",
|
|
86
|
+
locations: [openIdCredentialIssuer.credential_issuer],
|
|
87
|
+
types: requestedTypes,
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
const queryParams = {
|
|
91
|
+
scope: "openid",
|
|
92
|
+
client_id: clientId,
|
|
93
|
+
client_metadata: JSON.stringify(clientMetadata),
|
|
94
|
+
redirect_uri: isPKCEChallenge
|
|
95
|
+
? "openid://callback"
|
|
96
|
+
: `${context.client.clientId}/code-cb`,
|
|
97
|
+
response_type: "code",
|
|
98
|
+
state: randomUUID(),
|
|
99
|
+
...(isPKCEChallenge && {
|
|
100
|
+
code_challenge: codeChallenge,
|
|
101
|
+
code_challenge_method: "S256",
|
|
102
|
+
}),
|
|
103
|
+
...(issuerState && { issuer_state: issuerState }),
|
|
104
|
+
authorization_details: JSON.stringify(authorizationDetails),
|
|
105
|
+
};
|
|
106
|
+
const jwtPayload = {
|
|
107
|
+
...queryParams,
|
|
108
|
+
client_metadata: clientMetadata,
|
|
109
|
+
authorization_details: authorizationDetails,
|
|
110
|
+
};
|
|
111
|
+
const clientPrivateKey = await importJWK(context.client.keys[alg].privateKeyJwk, alg);
|
|
112
|
+
const requestParam = await new SignJWT(jwtPayload)
|
|
113
|
+
.setProtectedHeader({
|
|
114
|
+
typ: "JWT",
|
|
115
|
+
alg,
|
|
116
|
+
kid: isPKCEChallenge
|
|
117
|
+
? context.client.keys[alg].kid
|
|
118
|
+
: context.client.keys[alg].id,
|
|
119
|
+
})
|
|
120
|
+
.setIssuer(clientId)
|
|
121
|
+
.setAudience(authorizationServer)
|
|
122
|
+
.sign(clientPrivateKey);
|
|
123
|
+
const responseAuthorize = await httpCall.get(`${openIdConfiguration.authorization_endpoint}?${new URLSearchParams({
|
|
124
|
+
...queryParams,
|
|
125
|
+
request: requestParam,
|
|
126
|
+
}).toString()}`);
|
|
127
|
+
const { location } = responseAuthorize.headers;
|
|
128
|
+
const locationUrl = new URL(location);
|
|
129
|
+
if (locationUrl.searchParams.get("error"))
|
|
130
|
+
throw new Error(locationUrl.searchParams.toString());
|
|
131
|
+
const responseQueryParams = qs.parse(locationUrl.search.substring(1));
|
|
132
|
+
return responseQueryParams;
|
|
133
|
+
}
|
|
134
|
+
export async function authMockDirectPostIdToken(inputs, context) {
|
|
135
|
+
const [openIdCredentialIssuer, openIdConfiguration, issuerRequest, inputAlg] = inputs;
|
|
136
|
+
const alg = inputAlg || "ES256";
|
|
137
|
+
Joi.assert(alg, Joi.string().valid("ES256K", "ES256", "EdDSA", "RS256"));
|
|
138
|
+
const authorizationServer = openIdCredentialIssuer.authorization_server ??
|
|
139
|
+
openIdCredentialIssuer.credential_issuer;
|
|
140
|
+
const { state, nonce } = issuerRequest;
|
|
141
|
+
const clientPrivateKey = await importJWK(context.client.keys[alg].privateKeyJwk, alg);
|
|
142
|
+
const idTokenDirectPost = await new SignJWT({
|
|
143
|
+
nonce,
|
|
144
|
+
sub: context.client.did,
|
|
145
|
+
})
|
|
146
|
+
.setProtectedHeader({
|
|
147
|
+
typ: "JWT",
|
|
148
|
+
alg,
|
|
149
|
+
kid: context.client.keys[alg].kid,
|
|
150
|
+
})
|
|
151
|
+
.setIssuer(context.client.did)
|
|
152
|
+
.setAudience(authorizationServer)
|
|
153
|
+
.setIssuedAt()
|
|
154
|
+
.setExpirationTime("5m")
|
|
155
|
+
.sign(clientPrivateKey);
|
|
156
|
+
const responseDirectPost = await httpCall.post(openIdConfiguration.redirect_uris[0], new URLSearchParams({
|
|
157
|
+
id_token: idTokenDirectPost,
|
|
158
|
+
state,
|
|
159
|
+
}).toString(), {
|
|
160
|
+
headers: {
|
|
161
|
+
"content-type": "application/x-www-form-urlencoded",
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
const { location } = responseDirectPost.headers;
|
|
165
|
+
const locationUrl = new URL(location);
|
|
166
|
+
if (locationUrl.searchParams.get("error"))
|
|
167
|
+
throw new Error(locationUrl.searchParams.toString());
|
|
168
|
+
const responseQueryParams = qs.parse(locationUrl.search.substring(1));
|
|
169
|
+
return responseQueryParams;
|
|
170
|
+
}
|
|
171
|
+
export async function authMockDirectPostVpToken(inputs) {
|
|
172
|
+
const [openIdConfiguration, issuerRequest, vpJwt, type] = inputs;
|
|
173
|
+
const { state } = issuerRequest;
|
|
174
|
+
const presentationSubmission = type === "holder"
|
|
175
|
+
? {
|
|
176
|
+
id: randomUUID(),
|
|
177
|
+
definition_id: "holder-wallet-qualification-presentation",
|
|
178
|
+
descriptor_map: [
|
|
179
|
+
{
|
|
180
|
+
id: "same-device-authorised-in-time-credential",
|
|
181
|
+
path: "$",
|
|
182
|
+
format: "jwt_vp",
|
|
183
|
+
path_nested: {
|
|
184
|
+
id: "same-device-authorised-in-time-credential",
|
|
185
|
+
format: "jwt_vc",
|
|
186
|
+
path: "$.verifiableCredential[0]",
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
id: "cross-device-authorised-in-time-credential",
|
|
191
|
+
path: "$",
|
|
192
|
+
format: "jwt_vp",
|
|
193
|
+
path_nested: {
|
|
194
|
+
id: "cross-device-authorised-in-time-credential",
|
|
195
|
+
format: "jwt_vc",
|
|
196
|
+
path: "$.verifiableCredential[1]",
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
id: "same-device-authorised-deferred-credential",
|
|
201
|
+
path: "$",
|
|
202
|
+
format: "jwt_vp",
|
|
203
|
+
path_nested: {
|
|
204
|
+
id: "same-device-authorised-deferred-credential",
|
|
205
|
+
format: "jwt_vc",
|
|
206
|
+
path: "$.verifiableCredential[2]",
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
id: "cross-device-authorised-deferred-credential",
|
|
211
|
+
path: "$",
|
|
212
|
+
format: "jwt_vp",
|
|
213
|
+
path_nested: {
|
|
214
|
+
id: "cross-device-authorised-deferred-credential",
|
|
215
|
+
format: "jwt_vc",
|
|
216
|
+
path: "$.verifiableCredential[3]",
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
id: "same-device-pre-authorised-in-time-credential",
|
|
221
|
+
path: "$",
|
|
222
|
+
format: "jwt_vp",
|
|
223
|
+
path_nested: {
|
|
224
|
+
id: "same-device-pre-authorised-in-time-credential",
|
|
225
|
+
format: "jwt_vc",
|
|
226
|
+
path: "$.verifiableCredential[4]",
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
id: "cross-device-pre-authorised-in-time-credential",
|
|
231
|
+
path: "$",
|
|
232
|
+
format: "jwt_vp",
|
|
233
|
+
path_nested: {
|
|
234
|
+
id: "cross-device-pre-authorised-in-time-credential",
|
|
235
|
+
format: "jwt_vc",
|
|
236
|
+
path: "$.verifiableCredential[5]",
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
id: "same-device-pre-authorised-deferred-credential",
|
|
241
|
+
path: "$",
|
|
242
|
+
format: "jwt_vp",
|
|
243
|
+
path_nested: {
|
|
244
|
+
id: "same-device-pre-authorised-deferred-credential",
|
|
245
|
+
format: "jwt_vc",
|
|
246
|
+
path: "$.verifiableCredential[6]",
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
id: "cross-device-pre-authorised-deferred-credential",
|
|
251
|
+
path: "$",
|
|
252
|
+
format: "jwt_vp",
|
|
253
|
+
path_nested: {
|
|
254
|
+
id: "cross-device-pre-authorised-deferred-credential",
|
|
255
|
+
format: "jwt_vc",
|
|
256
|
+
path: "$.verifiableCredential[7]",
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
}
|
|
261
|
+
: {
|
|
262
|
+
id: randomUUID(),
|
|
263
|
+
definition_id: "va-to-onboard-presentation",
|
|
264
|
+
descriptor_map: [
|
|
265
|
+
{
|
|
266
|
+
id: "verifiable-authorisation-to-onboard",
|
|
267
|
+
format: "jwt_vp",
|
|
268
|
+
path: "$",
|
|
269
|
+
path_nested: {
|
|
270
|
+
id: "verifiable-authorisation-to-onboard",
|
|
271
|
+
format: "jwt_vc",
|
|
272
|
+
path: "$.verifiableCredential[0]",
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
],
|
|
276
|
+
};
|
|
277
|
+
const responseDirectPost = await httpCall.post(openIdConfiguration.redirect_uris[0], new URLSearchParams({
|
|
278
|
+
vp_token: vpJwt,
|
|
279
|
+
state,
|
|
280
|
+
presentation_submission: JSON.stringify(presentationSubmission),
|
|
281
|
+
}).toString(), {
|
|
282
|
+
headers: {
|
|
283
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
284
|
+
},
|
|
285
|
+
});
|
|
286
|
+
const { location } = responseDirectPost.headers;
|
|
287
|
+
const locationUrl = new URL(location);
|
|
288
|
+
if (locationUrl.searchParams.get("error"))
|
|
289
|
+
throw new Error(locationUrl.searchParams.toString());
|
|
290
|
+
const responseQueryParams = qs.parse(locationUrl.search.substring(1));
|
|
291
|
+
return responseQueryParams;
|
|
292
|
+
}
|
|
293
|
+
export async function authMockToken(inputs, context) {
|
|
294
|
+
const [openIdCredentialIssuer, openIdConfiguration, code, inputAlg, codeVerifier, type,] = inputs;
|
|
295
|
+
const alg = inputAlg || "ES256";
|
|
296
|
+
const isPKCEChallenge = !!codeVerifier;
|
|
297
|
+
const authorizationServer = openIdCredentialIssuer.authorization_server ??
|
|
298
|
+
openIdCredentialIssuer.credential_issuer;
|
|
299
|
+
let queryParams;
|
|
300
|
+
if (type === "preAuthorised") {
|
|
301
|
+
queryParams = {
|
|
302
|
+
grant_type: "urn:ietf:params:oauth:grant-type:pre-authorized_code",
|
|
303
|
+
"pre-authorized_code": code,
|
|
304
|
+
user_pin: getUserPin(context.client.did),
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
queryParams = {
|
|
309
|
+
grant_type: "authorization_code",
|
|
310
|
+
code,
|
|
311
|
+
client_id: isPKCEChallenge ? context.client.did : context.client.clientId,
|
|
312
|
+
...(!isPKCEChallenge && {
|
|
313
|
+
client_assertion_type: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
|
|
314
|
+
}),
|
|
315
|
+
...(isPKCEChallenge && {
|
|
316
|
+
code_verifier: codeVerifier,
|
|
317
|
+
}),
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
const jwtPayload = {
|
|
321
|
+
...queryParams,
|
|
322
|
+
};
|
|
323
|
+
const clientPrivateKey = await importJWK(context.client.keys[alg].privateKeyJwk, alg);
|
|
324
|
+
const clientAssertion = await new SignJWT(jwtPayload)
|
|
325
|
+
.setProtectedHeader({
|
|
326
|
+
typ: "JWT",
|
|
327
|
+
alg,
|
|
328
|
+
kid: context.client.keys[alg].id,
|
|
329
|
+
})
|
|
330
|
+
.setIssuer(context.client.clientId)
|
|
331
|
+
.setAudience(authorizationServer)
|
|
332
|
+
.setSubject(context.client.clientId)
|
|
333
|
+
.setIssuedAt()
|
|
334
|
+
.setExpirationTime("5m")
|
|
335
|
+
.sign(clientPrivateKey);
|
|
336
|
+
const responseToken = await httpCall.post(openIdConfiguration.token_endpoint, new URLSearchParams({
|
|
337
|
+
...queryParams,
|
|
338
|
+
client_assertion: clientAssertion,
|
|
339
|
+
}).toString(), {
|
|
340
|
+
headers: {
|
|
341
|
+
"content-type": "application/x-www-form-urlencoded",
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
return responseToken.data;
|
|
345
|
+
}
|
|
346
|
+
export async function issuerMockCredential(inputs, context) {
|
|
347
|
+
const [openIdCredentialIssuer, nonce, requestedTypes, inputAlg] = inputs;
|
|
348
|
+
const alg = inputAlg || "ES256";
|
|
349
|
+
const clientId = context.client.didVersion === 1
|
|
350
|
+
? context.client.clientId
|
|
351
|
+
: context.client.did;
|
|
352
|
+
const clientPrivateKey = await importJWK(context.client.keys[alg].privateKeyJwk, alg);
|
|
353
|
+
const proofJwt = await new SignJWT({ nonce })
|
|
354
|
+
.setProtectedHeader({
|
|
355
|
+
typ: "openid4vci-proof+jwt",
|
|
356
|
+
alg,
|
|
357
|
+
kid: context.client.keys[alg].kid,
|
|
358
|
+
})
|
|
359
|
+
.setIssuer(clientId)
|
|
360
|
+
.setAudience(openIdCredentialIssuer.credential_issuer)
|
|
361
|
+
.setIssuedAt()
|
|
362
|
+
.setExpirationTime("5m")
|
|
363
|
+
.sign(clientPrivateKey);
|
|
364
|
+
const responseCredential = await httpCall.post(`${openIdCredentialIssuer.credential_issuer}/credential`, {
|
|
365
|
+
types: requestedTypes,
|
|
366
|
+
format: "jwt_vc",
|
|
367
|
+
proof: {
|
|
368
|
+
proof_type: "jwt",
|
|
369
|
+
jwt: proofJwt,
|
|
370
|
+
},
|
|
371
|
+
}, context.httpOpts);
|
|
372
|
+
return responseCredential.data;
|
|
373
|
+
}
|
|
374
|
+
export async function issuerMockDeferred(inputs) {
|
|
375
|
+
const [openIdCredentialIssuer, acceptanceToken] = inputs;
|
|
376
|
+
const response = await httpCall.post(openIdCredentialIssuer.deferred_credential_endpoint, undefined, {
|
|
377
|
+
headers: {
|
|
378
|
+
authorization: `Bearer ${acceptanceToken}`,
|
|
379
|
+
},
|
|
380
|
+
});
|
|
381
|
+
return response.data;
|
|
382
|
+
}
|
|
383
|
+
export async function issuerMockInitiateCredentialOffer(inputs, context) {
|
|
384
|
+
const [initiateCredentialOfferEndpoint, credentialType] = inputs;
|
|
385
|
+
const requestParams = {
|
|
386
|
+
credential_type: credentialType,
|
|
387
|
+
credential_offer_endpoint: "openid-credential-offer://",
|
|
388
|
+
client_id: context.client.did,
|
|
389
|
+
};
|
|
390
|
+
let response = await httpCall.get(`${initiateCredentialOfferEndpoint}?${qs.stringify(requestParams)}`);
|
|
391
|
+
let search;
|
|
392
|
+
if (credentialType.startsWith("CTWalletSame")) {
|
|
393
|
+
search = new URL(response.headers.location)
|
|
394
|
+
.search;
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
search = new URL(response.data).search;
|
|
398
|
+
}
|
|
399
|
+
const parsedCredentialOffer = qs.parse(search.slice(1));
|
|
400
|
+
if (parsedCredentialOffer.credential_offer_uri) {
|
|
401
|
+
response = await httpCall.get(parsedCredentialOffer.credential_offer_uri);
|
|
402
|
+
return response.data;
|
|
403
|
+
}
|
|
404
|
+
return qs.parse(parsedCredentialOffer.credential_offer);
|
|
405
|
+
}
|
|
406
|
+
export async function getCredential(inputs, context) {
|
|
407
|
+
const [type, inputAlg, vc, inputIssuer] = inputs;
|
|
408
|
+
const alg = inputAlg || "ES256";
|
|
409
|
+
const openIdCredentialIssuerUrl = inputIssuer
|
|
410
|
+
? `/client-mock/${inputIssuer}/.well-known/openid-credential-issuer`
|
|
411
|
+
: "/issuer-mock/.well-known/openid-credential-issuer";
|
|
412
|
+
let requestedTypes;
|
|
413
|
+
switch (type) {
|
|
414
|
+
case "onboard": {
|
|
415
|
+
requestedTypes = [
|
|
416
|
+
"VerifiableCredential",
|
|
417
|
+
"VerifiableAttestation",
|
|
418
|
+
"VerifiableAuthorisationToOnboard",
|
|
419
|
+
];
|
|
420
|
+
break;
|
|
421
|
+
}
|
|
422
|
+
case "ti": {
|
|
423
|
+
requestedTypes = [
|
|
424
|
+
"VerifiableCredential",
|
|
425
|
+
"VerifiableAttestation",
|
|
426
|
+
"VerifiableAccreditation",
|
|
427
|
+
"VerifiableAccreditationToAttest",
|
|
428
|
+
];
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
431
|
+
case "tao": {
|
|
432
|
+
requestedTypes = [
|
|
433
|
+
"VerifiableCredential",
|
|
434
|
+
"VerifiableAttestation",
|
|
435
|
+
"VerifiableAccreditation",
|
|
436
|
+
"VerifiableAccreditationToAccredit",
|
|
437
|
+
];
|
|
438
|
+
break;
|
|
439
|
+
}
|
|
440
|
+
case "roottao": {
|
|
441
|
+
requestedTypes = [
|
|
442
|
+
"VerifiableCredential",
|
|
443
|
+
"VerifiableAttestation",
|
|
444
|
+
"VerifiableAuthorisationForTrustChain",
|
|
445
|
+
];
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
case "ctrevocable": {
|
|
449
|
+
requestedTypes = [
|
|
450
|
+
"VerifiableCredential",
|
|
451
|
+
"VerifiableAttestation",
|
|
452
|
+
"CTRevocable",
|
|
453
|
+
];
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
case "qualification": {
|
|
457
|
+
requestedTypes = [
|
|
458
|
+
"VerifiableCredential",
|
|
459
|
+
"VerifiableAttestation",
|
|
460
|
+
"CTAAQualificationCredential",
|
|
461
|
+
];
|
|
462
|
+
break;
|
|
463
|
+
}
|
|
464
|
+
default:
|
|
465
|
+
throw new Error(`type ${type} is not supported`);
|
|
466
|
+
}
|
|
467
|
+
// conformance-new clientMockInitiate
|
|
468
|
+
console.log("==> conformance-new clientMockInitiate");
|
|
469
|
+
await clientMockInitiate(context);
|
|
470
|
+
// opIssuer: conformance-new get /issuer-mock/.well-known/openid-credential-issuer
|
|
471
|
+
console.log(`==> conformance-new get ${openIdCredentialIssuerUrl}`);
|
|
472
|
+
const opIssuer = (await conformanceGet([openIdCredentialIssuerUrl], context));
|
|
473
|
+
const authorizationServer = opIssuer.authorization_server ?? opIssuer.credential_issuer;
|
|
474
|
+
// opConf: conformance-new get opIssuer.authorization_server /.well-known/openid-configuration
|
|
475
|
+
console.log(`==> conformance-new get ${authorizationServer}/.well-known/openid-configuration`);
|
|
476
|
+
const opConf = (await conformanceGet([authorizationServer, "/.well-known/openid-configuration"], context));
|
|
477
|
+
// respAuthorize: conformance-new authMockAuthorize opIssuer opConf requestedTypes ES256
|
|
478
|
+
console.log(`==> conformance-new authMockAuthorize ${stringify(opIssuer, [
|
|
479
|
+
"authorization_server",
|
|
480
|
+
"credential_issuer",
|
|
481
|
+
])} ${stringify(opConf, ["authorization_endpoint"])} ${JSON.stringify(requestedTypes)} ${alg}`);
|
|
482
|
+
const respAuthorize = await authMockAuthorize([opIssuer, opConf, requestedTypes, alg], context);
|
|
483
|
+
let code;
|
|
484
|
+
if (type === "roottao") {
|
|
485
|
+
// vpJwt: compute createPresentationJwt vc alg opConf.issuer
|
|
486
|
+
console.log(`==> compute createPresentationJwt ${vc || "empty"} ${alg} ${opConf.issuer}`);
|
|
487
|
+
const vpJwt = (await compute("createPresentationJwt", [vc || "empty", alg, opConf.issuer], context));
|
|
488
|
+
// respDirectPost: conformance-new authMockDirectPostVpToken opIssuer opConf respAuthorize ES256
|
|
489
|
+
console.log(`==> conformance-new authMockDirectPostVpToken ${stringify(opConf, [
|
|
490
|
+
"redirect_uris",
|
|
491
|
+
])} ${JSON.stringify(respAuthorize)} ${vpJwt}`);
|
|
492
|
+
const respDirectPost = (await authMockDirectPostVpToken([
|
|
493
|
+
opConf,
|
|
494
|
+
respAuthorize,
|
|
495
|
+
vpJwt,
|
|
496
|
+
]));
|
|
497
|
+
code = respDirectPost.code;
|
|
498
|
+
}
|
|
499
|
+
else {
|
|
500
|
+
// respDirectPost: conformance-new authMockDirectPostIdToken opIssuer opConf respAuthorize ES256
|
|
501
|
+
console.log(`==> conformance-new authMockDirectPostIdToken ${stringify(opIssuer, [
|
|
502
|
+
"authorization_server",
|
|
503
|
+
"credential_issuer",
|
|
504
|
+
])} ${stringify(opConf, ["redirect_uris"])} ${JSON.stringify(respAuthorize)} ${alg}`);
|
|
505
|
+
const respDirectPost = (await authMockDirectPostIdToken([opIssuer, opConf, respAuthorize, alg], context));
|
|
506
|
+
code = respDirectPost.code;
|
|
507
|
+
}
|
|
508
|
+
// resToken: conformance-new authMockToken opIssuer opConf respDirectPost.code ES256
|
|
509
|
+
console.log(`==> conformance-new authMockToken ${stringify(opIssuer, [
|
|
510
|
+
"authorization_server",
|
|
511
|
+
"credential_issuer",
|
|
512
|
+
])} ${stringify(opConf, ["token_endpoint"])} ${code} ${alg}`);
|
|
513
|
+
const respToken = (await authMockToken([opIssuer, opConf, code, alg], context));
|
|
514
|
+
// using token resToken.access_token
|
|
515
|
+
console.log(`==> using token ${respToken.access_token}`);
|
|
516
|
+
context.httpOpts = {
|
|
517
|
+
headers: {
|
|
518
|
+
authorization: `Bearer ${respToken.access_token}`,
|
|
519
|
+
},
|
|
520
|
+
};
|
|
521
|
+
// resCredential: conformance-new issuerMockCredential opIssuer resToken.c_nonce requestedTypes ES256
|
|
522
|
+
console.log(`==> conformance-new issuerMockCredential ${stringify(opIssuer, [
|
|
523
|
+
"credential_issuer",
|
|
524
|
+
])} ${respToken.c_nonce} ${JSON.stringify(requestedTypes)} ${alg}`);
|
|
525
|
+
const respCredential = (await issuerMockCredential([opIssuer, respToken.c_nonce, requestedTypes, alg], context));
|
|
526
|
+
let credential;
|
|
527
|
+
if (type === "roottao") {
|
|
528
|
+
console.log(`waiting 5.5 seconds...`);
|
|
529
|
+
await new Promise((r) => {
|
|
530
|
+
setTimeout(r, 5500);
|
|
531
|
+
});
|
|
532
|
+
// respDeferred: conformance-new issuerMockDeferred respDirectPost.acceptance_token
|
|
533
|
+
console.log(`==> conformance-new issuerMockDeferred ${stringify(opIssuer, [
|
|
534
|
+
"deferred_credential_endpoint",
|
|
535
|
+
])} ${respCredential.acceptance_token}`);
|
|
536
|
+
const respDeferred = (await issuerMockDeferred([
|
|
537
|
+
opIssuer,
|
|
538
|
+
respCredential.acceptance_token,
|
|
539
|
+
]));
|
|
540
|
+
credential = respDeferred.credential;
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
credential = respCredential.credential;
|
|
544
|
+
}
|
|
545
|
+
// decodedCredential: compute decodeJWT resCredential.credential
|
|
546
|
+
console.log(`==> compute decodeJWT ${credential}`);
|
|
547
|
+
const decodedCredential = (await compute("decodeJWT", [credential], context));
|
|
548
|
+
let reservedAttributeId = "";
|
|
549
|
+
if (decodedCredential.payload.vc &&
|
|
550
|
+
decodedCredential.payload.vc.credentialSubject &&
|
|
551
|
+
decodedCredential.payload.vc.credentialSubject.reservedAttributeId) {
|
|
552
|
+
reservedAttributeId =
|
|
553
|
+
decodedCredential.payload.vc.credentialSubject.reservedAttributeId;
|
|
554
|
+
}
|
|
555
|
+
return {
|
|
556
|
+
vc: credential,
|
|
557
|
+
reservedAttributeId,
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
export async function holder(inputs, context) {
|
|
561
|
+
const apiUrl = context.config.api["conformance-new"].url;
|
|
562
|
+
const [credentialType, communicationType, inputAlg, vc, typeCredentialOffer, inputIssuer,] = inputs;
|
|
563
|
+
const alg = inputAlg || "ES256";
|
|
564
|
+
const codeVerifier = randomBytes(50).toString("base64url");
|
|
565
|
+
const requestedTypes = [
|
|
566
|
+
"VerifiableCredential",
|
|
567
|
+
"VerifiableAttestation",
|
|
568
|
+
credentialType,
|
|
569
|
+
];
|
|
570
|
+
const openIdCredentialIssuerUrl = inputIssuer
|
|
571
|
+
? `/client-mock/${inputIssuer}/.well-known/openid-credential-issuer`
|
|
572
|
+
: "/issuer-mock/.well-known/openid-credential-issuer";
|
|
573
|
+
const initiateCredentialOfferEndpoint = inputIssuer
|
|
574
|
+
? `${apiUrl}/client-mock/${inputIssuer}/initiate-credential-offer`
|
|
575
|
+
: `${apiUrl}/issuer-mock/initiate-credential-offer`;
|
|
576
|
+
// credentialOffer: conformance-new issuerMockInitiateCredentialOffer initiateCredentialOfferEndpoint
|
|
577
|
+
console.log(`==> conformance-new issuerMockInitiateCredentialOffer ${initiateCredentialOfferEndpoint} ${credentialType}`);
|
|
578
|
+
let credentialOffer;
|
|
579
|
+
const validTypesIssuerState = [
|
|
580
|
+
"use-credential-offer",
|
|
581
|
+
"skip-credential-offer",
|
|
582
|
+
];
|
|
583
|
+
if (typeCredentialOffer &&
|
|
584
|
+
!validTypesIssuerState.includes(typeCredentialOffer)) {
|
|
585
|
+
throw new Error(`invalid command for typeCredentialOffer. valid types: ${validTypesIssuerState.join(", ")}`);
|
|
586
|
+
}
|
|
587
|
+
const useCredentialOffer = typeCredentialOffer !== "skip-credential-offer";
|
|
588
|
+
const isPreauthorised = communicationType
|
|
589
|
+
.toLowerCase()
|
|
590
|
+
.startsWith("preauthorised");
|
|
591
|
+
if (!useCredentialOffer) {
|
|
592
|
+
if (isPreauthorised)
|
|
593
|
+
throw new Error("For preauthorised credentials set use-credential-offer");
|
|
594
|
+
}
|
|
595
|
+
else {
|
|
596
|
+
credentialOffer = await issuerMockInitiateCredentialOffer([initiateCredentialOfferEndpoint, credentialType], context);
|
|
597
|
+
}
|
|
598
|
+
// opIssuer: conformance-new get /issuer-mock/.well-known/openid-credential-issuer
|
|
599
|
+
console.log(`==> conformance-new get ${openIdCredentialIssuerUrl}`);
|
|
600
|
+
const opIssuer = (await conformanceGet([openIdCredentialIssuerUrl], context));
|
|
601
|
+
const authorizationServer = opIssuer.authorization_server ?? opIssuer.credential_issuer;
|
|
602
|
+
// opConf: conformance-new get opIssuer.authorization_server /.well-known/openid-configuration
|
|
603
|
+
console.log(`==> conformance-new get ${authorizationServer}/.well-known/openid-configuration`);
|
|
604
|
+
const opConf = (await conformanceGet([authorizationServer, "/.well-known/openid-configuration"], context));
|
|
605
|
+
let code;
|
|
606
|
+
if (isPreauthorised) {
|
|
607
|
+
code =
|
|
608
|
+
credentialOffer.grants["urn:ietf:params:oauth:grant-type:pre-authorized_code"]?.["pre-authorized_code"];
|
|
609
|
+
}
|
|
610
|
+
else {
|
|
611
|
+
// respAuthorize: conformance-new authMockAuthorize opIssuer opConf requestedTypes ES256
|
|
612
|
+
let issuerState = "";
|
|
613
|
+
if (useCredentialOffer)
|
|
614
|
+
issuerState = credentialOffer.grants.authorization_code
|
|
615
|
+
? credentialOffer.grants.authorization_code.issuer_state
|
|
616
|
+
: "";
|
|
617
|
+
console.log(`==> conformance-new authMockAuthorize ${stringify(opIssuer, [
|
|
618
|
+
"authorization_server",
|
|
619
|
+
"credential_issuer",
|
|
620
|
+
])} ${stringify(opConf, ["authorization_endpoint"])} ${JSON.stringify(requestedTypes)} ${alg} ${codeVerifier} ${issuerState}`);
|
|
621
|
+
const respAuthorize = await authMockAuthorize([opIssuer, opConf, requestedTypes, alg, codeVerifier, issuerState], context);
|
|
622
|
+
if (credentialType === "CTWalletQualificationCredential") {
|
|
623
|
+
// vpJwt: compute createPresentationJwt vc alg opConf.issuer
|
|
624
|
+
console.log(`==> compute createPresentationJwt ${vc || "empty"} ${alg} ${opConf.issuer}`);
|
|
625
|
+
const vpJwt = (await compute("createPresentationJwt", [vc || "empty", alg, opConf.issuer], context));
|
|
626
|
+
// respDirectPost: conformance-new authMockDirectPostVpToken opIssuer opConf respAuthorize ES256
|
|
627
|
+
console.log(`==> conformance-new authMockDirectPostVpToken ${stringify(opConf, [
|
|
628
|
+
"redirect_uris",
|
|
629
|
+
])} ${JSON.stringify(respAuthorize)} ${vpJwt} holder`);
|
|
630
|
+
const respDirectPost = (await authMockDirectPostVpToken([
|
|
631
|
+
opConf,
|
|
632
|
+
respAuthorize,
|
|
633
|
+
vpJwt,
|
|
634
|
+
"holder",
|
|
635
|
+
]));
|
|
636
|
+
code = respDirectPost.code;
|
|
637
|
+
}
|
|
638
|
+
else {
|
|
639
|
+
// respDirectPost: conformance-new authMockDirectPostIdToken opIssuer opConf respAuthorize ES256
|
|
640
|
+
console.log(`==> conformance-new authMockDirectPostIdToken ${stringify(opIssuer, [
|
|
641
|
+
"authorization_server",
|
|
642
|
+
"credential_issuer",
|
|
643
|
+
])} ${stringify(opConf, ["redirect_uris"])} ${JSON.stringify(respAuthorize)} ${alg}`);
|
|
644
|
+
const respDirectPost = (await authMockDirectPostIdToken([opIssuer, opConf, respAuthorize, alg], context));
|
|
645
|
+
code = respDirectPost.code;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
// resToken: conformance-new authMockToken opIssuer opConf respDirectPost.code ES256
|
|
649
|
+
console.log(`==> conformance-new authMockToken ${stringify(opIssuer, [
|
|
650
|
+
"authorization_server",
|
|
651
|
+
"credential_issuer",
|
|
652
|
+
])} ${stringify(opConf, ["token_endpoint"])} ${code} ${alg} ${codeVerifier}`);
|
|
653
|
+
const respToken = (await authMockToken([
|
|
654
|
+
opIssuer,
|
|
655
|
+
opConf,
|
|
656
|
+
code,
|
|
657
|
+
alg,
|
|
658
|
+
codeVerifier,
|
|
659
|
+
isPreauthorised ? "preAuthorised" : "",
|
|
660
|
+
], context));
|
|
661
|
+
// using token resToken.access_token
|
|
662
|
+
console.log(`==> using token ${respToken.access_token}`);
|
|
663
|
+
context.httpOpts = {
|
|
664
|
+
headers: {
|
|
665
|
+
authorization: `Bearer ${respToken.access_token}`,
|
|
666
|
+
},
|
|
667
|
+
};
|
|
668
|
+
// resCredential: conformance-new issuerMockCredential opIssuer resToken.c_nonce requestedTypes ES256
|
|
669
|
+
console.log(`==> conformance-new issuerMockCredential ${stringify(opIssuer, [
|
|
670
|
+
"credential_issuer",
|
|
671
|
+
])} ${respToken.c_nonce} ${JSON.stringify(requestedTypes)} ${alg}`);
|
|
672
|
+
const respCredential = (await issuerMockCredential([opIssuer, respToken.c_nonce, requestedTypes, alg], context));
|
|
673
|
+
let credential;
|
|
674
|
+
const isDeferred = communicationType.toLowerCase().endsWith("deferred");
|
|
675
|
+
if (isDeferred) {
|
|
676
|
+
console.log(`waiting 5.5 seconds...`);
|
|
677
|
+
await new Promise((r) => {
|
|
678
|
+
setTimeout(r, 5500);
|
|
679
|
+
});
|
|
680
|
+
// respDeferred: conformance-new issuerMockDeferred respDirectPost.acceptance_token
|
|
681
|
+
console.log(`==> conformance-new issuerMockDeferred ${stringify(opIssuer, [
|
|
682
|
+
"deferred_credential_endpoint",
|
|
683
|
+
])} ${respCredential.acceptance_token}`);
|
|
684
|
+
const respDeferred = (await issuerMockDeferred([
|
|
685
|
+
opIssuer,
|
|
686
|
+
respCredential.acceptance_token,
|
|
687
|
+
]));
|
|
688
|
+
credential = respDeferred.credential;
|
|
689
|
+
}
|
|
690
|
+
else {
|
|
691
|
+
credential = respCredential.credential;
|
|
692
|
+
}
|
|
693
|
+
return credential;
|
|
694
|
+
}
|
|
695
|
+
export async function check(inputs, context) {
|
|
696
|
+
const [intent, preAuthorizedCode, userPin] = inputs;
|
|
697
|
+
const apiUrl = context.config.api["conformance-new"].url;
|
|
698
|
+
const response = await httpCall.post(`${apiUrl}/check`, {
|
|
699
|
+
data: {
|
|
700
|
+
clientId: context.client.clientId,
|
|
701
|
+
did: context.client.did,
|
|
702
|
+
credentialIssuer: context.client.clientId,
|
|
703
|
+
credentialIssuerDid: context.client.did,
|
|
704
|
+
issuerState: context.client.issuerState,
|
|
705
|
+
...(preAuthorizedCode && {
|
|
706
|
+
preAuthorizedCode,
|
|
707
|
+
userPin,
|
|
708
|
+
}),
|
|
709
|
+
},
|
|
710
|
+
intent,
|
|
711
|
+
});
|
|
712
|
+
if (!response.data.success) {
|
|
713
|
+
red(response.data.errors);
|
|
714
|
+
throw new Error(`check ${intent} failed: ${response.data.errors
|
|
715
|
+
? JSON.stringify(response.data.errors)
|
|
716
|
+
: "unknown error"}`);
|
|
717
|
+
}
|
|
718
|
+
return response.data;
|
|
719
|
+
}
|
|
720
|
+
export async function conformanceV4(method, inputs, context) {
|
|
721
|
+
switch (method) {
|
|
722
|
+
case "get": {
|
|
723
|
+
return conformanceGet(inputs, context);
|
|
724
|
+
}
|
|
725
|
+
case "clientMockInitiate": {
|
|
726
|
+
return clientMockInitiate(context);
|
|
727
|
+
}
|
|
728
|
+
case "clientMockUpdateList": {
|
|
729
|
+
return clientMockUpdateList(inputs, context);
|
|
730
|
+
}
|
|
731
|
+
case "authMockAuthorize": {
|
|
732
|
+
return authMockAuthorize(inputs, context);
|
|
733
|
+
}
|
|
734
|
+
case "authMockDirectPostIdToken": {
|
|
735
|
+
return authMockDirectPostIdToken(inputs, context);
|
|
736
|
+
}
|
|
737
|
+
case "authMockDirectPostVpToken": {
|
|
738
|
+
return authMockDirectPostVpToken(inputs);
|
|
739
|
+
}
|
|
740
|
+
case "authMockToken": {
|
|
741
|
+
return authMockToken(inputs, context);
|
|
742
|
+
}
|
|
743
|
+
case "issuerMockCredential": {
|
|
744
|
+
return issuerMockCredential(inputs, context);
|
|
745
|
+
}
|
|
746
|
+
case "issuerMockDeferred": {
|
|
747
|
+
return issuerMockDeferred(inputs);
|
|
748
|
+
}
|
|
749
|
+
case "issuerMockInitiateCredentialOffer": {
|
|
750
|
+
return issuerMockInitiateCredentialOffer(inputs, context);
|
|
751
|
+
}
|
|
752
|
+
case "getCredential": {
|
|
753
|
+
return getCredential(inputs, context);
|
|
754
|
+
}
|
|
755
|
+
case "holder": {
|
|
756
|
+
return holder(inputs, context);
|
|
757
|
+
}
|
|
758
|
+
case "check": {
|
|
759
|
+
return check(inputs, context);
|
|
760
|
+
}
|
|
761
|
+
default:
|
|
762
|
+
red(`Invalid method '${method}'`);
|
|
763
|
+
return 0;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
export default conformanceV4;
|
|
767
|
+
//# sourceMappingURL=conformance-v4.js.map
|