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