@pagopa/io-react-native-wallet 1.7.1 → 2.0.0-next.1

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 (443) hide show
  1. package/README.md +47 -1
  2. package/lib/commonjs/client/generated/wallet-provider.js +49 -20
  3. package/lib/commonjs/client/generated/wallet-provider.js.map +1 -1
  4. package/lib/commonjs/credential/index.js +5 -1
  5. package/lib/commonjs/credential/index.js.map +1 -1
  6. package/lib/commonjs/credential/issuance/02-evaluate-issuer-trust.js +27 -0
  7. package/lib/commonjs/credential/issuance/02-evaluate-issuer-trust.js.map +1 -0
  8. package/lib/commonjs/credential/issuance/03-start-user-authorization.js +25 -16
  9. package/lib/commonjs/credential/issuance/03-start-user-authorization.js.map +1 -1
  10. package/lib/commonjs/credential/issuance/04-complete-user-authorization.js +30 -18
  11. package/lib/commonjs/credential/issuance/04-complete-user-authorization.js.map +1 -1
  12. package/lib/commonjs/credential/issuance/05-authorize-access.js +17 -12
  13. package/lib/commonjs/credential/issuance/05-authorize-access.js.map +1 -1
  14. package/lib/commonjs/credential/issuance/06-obtain-credential.js +36 -29
  15. package/lib/commonjs/credential/issuance/06-obtain-credential.js.map +1 -1
  16. package/lib/commonjs/credential/issuance/07-verify-and-parse-credential.js +27 -207
  17. package/lib/commonjs/credential/issuance/07-verify-and-parse-credential.js.map +1 -1
  18. package/lib/commonjs/credential/issuance/README.md +23 -20
  19. package/lib/commonjs/credential/issuance/const.js +1 -1
  20. package/lib/commonjs/credential/issuance/const.js.map +1 -1
  21. package/lib/commonjs/credential/issuance/index.js +3 -3
  22. package/lib/commonjs/credential/issuance/index.js.map +1 -1
  23. package/lib/commonjs/credential/presentation/01-start-flow.js +14 -15
  24. package/lib/commonjs/credential/presentation/01-start-flow.js.map +1 -1
  25. package/lib/commonjs/credential/presentation/02-evaluate-rp-trust.js +6 -4
  26. package/lib/commonjs/credential/presentation/02-evaluate-rp-trust.js.map +1 -1
  27. package/lib/commonjs/credential/presentation/03-get-request-object.js +34 -7
  28. package/lib/commonjs/credential/presentation/03-get-request-object.js.map +1 -1
  29. package/lib/commonjs/credential/presentation/04-retrieve-rp-jwks.js +4 -126
  30. package/lib/commonjs/credential/presentation/04-retrieve-rp-jwks.js.map +1 -1
  31. package/lib/commonjs/credential/presentation/05-verify-request-object.js +80 -25
  32. package/lib/commonjs/credential/presentation/05-verify-request-object.js.map +1 -1
  33. package/lib/commonjs/credential/presentation/06-fetch-presentation-definition.js +6 -30
  34. package/lib/commonjs/credential/presentation/06-fetch-presentation-definition.js.map +1 -1
  35. package/lib/commonjs/credential/presentation/07-evaluate-dcql-query.js +97 -117
  36. package/lib/commonjs/credential/presentation/07-evaluate-dcql-query.js.map +1 -1
  37. package/lib/commonjs/credential/presentation/07-evaluate-input-descriptor.js +86 -191
  38. package/lib/commonjs/credential/presentation/07-evaluate-input-descriptor.js.map +1 -1
  39. package/lib/commonjs/credential/presentation/08-send-authorization-response.js +112 -176
  40. package/lib/commonjs/credential/presentation/08-send-authorization-response.js.map +1 -1
  41. package/lib/commonjs/credential/presentation/README.md +74 -79
  42. package/lib/commonjs/credential/presentation/errors.js +42 -21
  43. package/lib/commonjs/credential/presentation/errors.js.map +1 -1
  44. package/lib/commonjs/credential/presentation/index.js +13 -13
  45. package/lib/commonjs/credential/presentation/index.js.map +1 -1
  46. package/lib/commonjs/credential/presentation/types.js +53 -29
  47. package/lib/commonjs/credential/presentation/types.js.map +1 -1
  48. package/lib/commonjs/credential/status/01-start-flow.js +2 -0
  49. package/lib/commonjs/credential/status/01-start-flow.js.map +1 -0
  50. package/lib/commonjs/credential/status/02-status-attestation.js +73 -0
  51. package/lib/commonjs/credential/status/02-status-attestation.js.map +1 -0
  52. package/lib/commonjs/credential/status/03-verify-and-parse-status-attestation.js +55 -0
  53. package/lib/commonjs/credential/status/03-verify-and-parse-status-attestation.js.map +1 -0
  54. package/lib/commonjs/credential/status/README.md +67 -0
  55. package/lib/commonjs/credential/status/index.js +27 -0
  56. package/lib/commonjs/credential/status/index.js.map +1 -0
  57. package/lib/commonjs/credential/status/types.js +48 -0
  58. package/lib/commonjs/credential/status/types.js.map +1 -0
  59. package/lib/commonjs/credential/trustmark/README.md +62 -0
  60. package/lib/commonjs/credential/trustmark/get-credential-trustmark.js +86 -0
  61. package/lib/commonjs/credential/trustmark/get-credential-trustmark.js.map +1 -0
  62. package/lib/commonjs/credential/trustmark/index.js +13 -0
  63. package/lib/commonjs/credential/trustmark/index.js.map +1 -0
  64. package/lib/commonjs/index.js +5 -1
  65. package/lib/commonjs/index.js.map +1 -1
  66. package/lib/commonjs/pid/sd-jwt/types.js +18 -2
  67. package/lib/commonjs/pid/sd-jwt/types.js.map +1 -1
  68. package/lib/commonjs/sd-jwt/__test__/index.test.js +22 -34
  69. package/lib/commonjs/sd-jwt/__test__/index.test.js.map +1 -1
  70. package/lib/commonjs/sd-jwt/__test__/types.test.js +11 -23
  71. package/lib/commonjs/sd-jwt/__test__/types.test.js.map +1 -1
  72. package/lib/commonjs/sd-jwt/index.js +1 -7
  73. package/lib/commonjs/sd-jwt/index.js.map +1 -1
  74. package/lib/commonjs/sd-jwt/types.js +5 -21
  75. package/lib/commonjs/sd-jwt/types.js.map +1 -1
  76. package/lib/commonjs/trust/README.md +147 -0
  77. package/lib/commonjs/trust/chain.js +153 -0
  78. package/lib/commonjs/trust/chain.js.map +1 -0
  79. package/lib/commonjs/trust/errors.js +133 -0
  80. package/lib/commonjs/trust/errors.js.map +1 -0
  81. package/lib/commonjs/trust/index.js +288 -0
  82. package/lib/commonjs/trust/index.js.map +1 -0
  83. package/lib/commonjs/{entity/trust → trust}/types.js +27 -47
  84. package/lib/commonjs/trust/types.js.map +1 -0
  85. package/lib/commonjs/trust/utils.js +70 -0
  86. package/lib/commonjs/trust/utils.js.map +1 -0
  87. package/lib/commonjs/utils/crypto.js +5 -112
  88. package/lib/commonjs/utils/crypto.js.map +1 -1
  89. package/lib/commonjs/utils/decoder.js +2 -0
  90. package/lib/commonjs/utils/decoder.js.map +1 -1
  91. package/lib/commonjs/utils/error-codes.js +22 -2
  92. package/lib/commonjs/utils/error-codes.js.map +1 -1
  93. package/lib/commonjs/utils/errors.js +72 -4
  94. package/lib/commonjs/utils/errors.js.map +1 -1
  95. package/lib/commonjs/utils/logging.js +68 -0
  96. package/lib/commonjs/utils/logging.js.map +1 -0
  97. package/lib/commonjs/utils/misc.js +2 -0
  98. package/lib/commonjs/utils/misc.js.map +1 -1
  99. package/lib/commonjs/utils/par.js +17 -10
  100. package/lib/commonjs/utils/par.js.map +1 -1
  101. package/lib/commonjs/utils/string.js +1 -12
  102. package/lib/commonjs/utils/string.js.map +1 -1
  103. package/lib/commonjs/wallet-instance/index.js +14 -0
  104. package/lib/commonjs/wallet-instance/index.js.map +1 -1
  105. package/lib/commonjs/wallet-instance-attestation/README.md +8 -3
  106. package/lib/commonjs/wallet-instance-attestation/issuing.js +15 -8
  107. package/lib/commonjs/wallet-instance-attestation/issuing.js.map +1 -1
  108. package/lib/commonjs/wallet-instance-attestation/types.js +16 -20
  109. package/lib/commonjs/wallet-instance-attestation/types.js.map +1 -1
  110. package/lib/module/client/generated/wallet-provider.js +40 -15
  111. package/lib/module/client/generated/wallet-provider.js.map +1 -1
  112. package/lib/module/credential/index.js +3 -1
  113. package/lib/module/credential/index.js.map +1 -1
  114. package/lib/module/credential/issuance/02-evaluate-issuer-trust.js +20 -0
  115. package/lib/module/credential/issuance/02-evaluate-issuer-trust.js.map +1 -0
  116. package/lib/module/credential/issuance/03-start-user-authorization.js +25 -16
  117. package/lib/module/credential/issuance/03-start-user-authorization.js.map +1 -1
  118. package/lib/module/credential/issuance/04-complete-user-authorization.js +30 -18
  119. package/lib/module/credential/issuance/04-complete-user-authorization.js.map +1 -1
  120. package/lib/module/credential/issuance/05-authorize-access.js +17 -11
  121. package/lib/module/credential/issuance/05-authorize-access.js.map +1 -1
  122. package/lib/module/credential/issuance/06-obtain-credential.js +36 -28
  123. package/lib/module/credential/issuance/06-obtain-credential.js.map +1 -1
  124. package/lib/module/credential/issuance/07-verify-and-parse-credential.js +27 -205
  125. package/lib/module/credential/issuance/07-verify-and-parse-credential.js.map +1 -1
  126. package/lib/module/credential/issuance/README.md +23 -20
  127. package/lib/module/credential/issuance/const.js +1 -1
  128. package/lib/module/credential/issuance/const.js.map +1 -1
  129. package/lib/module/credential/issuance/index.js +2 -2
  130. package/lib/module/credential/issuance/index.js.map +1 -1
  131. package/lib/module/credential/presentation/01-start-flow.js +14 -15
  132. package/lib/module/credential/presentation/01-start-flow.js.map +1 -1
  133. package/lib/module/credential/presentation/02-evaluate-rp-trust.js +5 -3
  134. package/lib/module/credential/presentation/02-evaluate-rp-trust.js.map +1 -1
  135. package/lib/module/credential/presentation/03-get-request-object.js +34 -7
  136. package/lib/module/credential/presentation/03-get-request-object.js.map +1 -1
  137. package/lib/module/credential/presentation/04-retrieve-rp-jwks.js +2 -124
  138. package/lib/module/credential/presentation/04-retrieve-rp-jwks.js.map +1 -1
  139. package/lib/module/credential/presentation/05-verify-request-object.js +78 -23
  140. package/lib/module/credential/presentation/05-verify-request-object.js.map +1 -1
  141. package/lib/module/credential/presentation/06-fetch-presentation-definition.js +6 -30
  142. package/lib/module/credential/presentation/06-fetch-presentation-definition.js.map +1 -1
  143. package/lib/module/credential/presentation/07-evaluate-dcql-query.js +97 -118
  144. package/lib/module/credential/presentation/07-evaluate-dcql-query.js.map +1 -1
  145. package/lib/module/credential/presentation/07-evaluate-input-descriptor.js +83 -186
  146. package/lib/module/credential/presentation/07-evaluate-input-descriptor.js.map +1 -1
  147. package/lib/module/credential/presentation/08-send-authorization-response.js +107 -170
  148. package/lib/module/credential/presentation/08-send-authorization-response.js.map +1 -1
  149. package/lib/module/credential/presentation/README.md +74 -79
  150. package/lib/module/credential/presentation/errors.js +30 -17
  151. package/lib/module/credential/presentation/errors.js.map +1 -1
  152. package/lib/module/credential/presentation/index.js +6 -6
  153. package/lib/module/credential/presentation/index.js.map +1 -1
  154. package/lib/module/credential/presentation/types.js +49 -27
  155. package/lib/module/credential/presentation/types.js.map +1 -1
  156. package/lib/module/credential/status/01-start-flow.js +2 -0
  157. package/lib/module/credential/status/01-start-flow.js.map +1 -0
  158. package/lib/module/credential/status/02-status-attestation.js +66 -0
  159. package/lib/module/credential/status/02-status-attestation.js.map +1 -0
  160. package/lib/module/credential/status/03-verify-and-parse-status-attestation.js +49 -0
  161. package/lib/module/credential/status/03-verify-and-parse-status-attestation.js.map +1 -0
  162. package/lib/module/credential/status/README.md +67 -0
  163. package/lib/module/credential/status/index.js +5 -0
  164. package/lib/module/credential/status/index.js.map +1 -0
  165. package/lib/module/credential/status/types.js +40 -0
  166. package/lib/module/credential/status/types.js.map +1 -0
  167. package/lib/module/credential/trustmark/README.md +62 -0
  168. package/lib/module/credential/trustmark/get-credential-trustmark.js +77 -0
  169. package/lib/module/credential/trustmark/get-credential-trustmark.js.map +1 -0
  170. package/lib/module/credential/trustmark/index.js +3 -0
  171. package/lib/module/credential/trustmark/index.js.map +1 -0
  172. package/lib/module/index.js +3 -1
  173. package/lib/module/index.js.map +1 -1
  174. package/lib/module/pid/sd-jwt/types.js +16 -1
  175. package/lib/module/pid/sd-jwt/types.js.map +1 -1
  176. package/lib/module/sd-jwt/__test__/index.test.js +22 -34
  177. package/lib/module/sd-jwt/__test__/index.test.js.map +1 -1
  178. package/lib/module/sd-jwt/__test__/types.test.js +11 -23
  179. package/lib/module/sd-jwt/__test__/types.test.js.map +1 -1
  180. package/lib/module/sd-jwt/index.js +1 -7
  181. package/lib/module/sd-jwt/index.js.map +1 -1
  182. package/lib/module/sd-jwt/types.js +4 -19
  183. package/lib/module/sd-jwt/types.js.map +1 -1
  184. package/lib/module/trust/README.md +147 -0
  185. package/lib/module/trust/chain.js +145 -0
  186. package/lib/module/trust/chain.js.map +1 -0
  187. package/lib/module/trust/errors.js +115 -0
  188. package/lib/module/trust/errors.js.map +1 -0
  189. package/lib/module/trust/index.js +269 -0
  190. package/lib/module/trust/index.js.map +1 -0
  191. package/lib/module/{entity/trust → trust}/types.js +25 -46
  192. package/lib/module/trust/types.js.map +1 -0
  193. package/lib/module/trust/utils.js +60 -0
  194. package/lib/module/trust/utils.js.map +1 -0
  195. package/lib/module/utils/crypto.js +4 -107
  196. package/lib/module/utils/crypto.js.map +1 -1
  197. package/lib/module/utils/decoder.js +3 -0
  198. package/lib/module/utils/decoder.js.map +1 -1
  199. package/lib/module/utils/error-codes.js +20 -1
  200. package/lib/module/utils/error-codes.js.map +1 -1
  201. package/lib/module/utils/errors.js +61 -4
  202. package/lib/module/utils/errors.js.map +1 -1
  203. package/lib/module/utils/logging.js +62 -0
  204. package/lib/module/utils/logging.js.map +1 -0
  205. package/lib/module/utils/misc.js +2 -0
  206. package/lib/module/utils/misc.js.map +1 -1
  207. package/lib/module/utils/par.js +17 -9
  208. package/lib/module/utils/par.js.map +1 -1
  209. package/lib/module/utils/string.js +0 -10
  210. package/lib/module/utils/string.js.map +1 -1
  211. package/lib/module/wallet-instance/index.js +13 -0
  212. package/lib/module/wallet-instance/index.js.map +1 -1
  213. package/lib/module/wallet-instance-attestation/README.md +8 -3
  214. package/lib/module/wallet-instance-attestation/index.js +2 -2
  215. package/lib/module/wallet-instance-attestation/index.js.map +1 -1
  216. package/lib/module/wallet-instance-attestation/issuing.js +16 -9
  217. package/lib/module/wallet-instance-attestation/issuing.js.map +1 -1
  218. package/lib/module/wallet-instance-attestation/types.js +14 -18
  219. package/lib/module/wallet-instance-attestation/types.js.map +1 -1
  220. package/lib/typescript/client/generated/wallet-provider.d.ts +206 -51
  221. package/lib/typescript/client/generated/wallet-provider.d.ts.map +1 -1
  222. package/lib/typescript/credential/index.d.ts +3 -1
  223. package/lib/typescript/credential/index.d.ts.map +1 -1
  224. package/lib/typescript/credential/issuance/01-start-flow.d.ts +1 -1
  225. package/lib/typescript/credential/issuance/02-evaluate-issuer-trust.d.ts +19 -0
  226. package/lib/typescript/credential/issuance/02-evaluate-issuer-trust.d.ts.map +1 -0
  227. package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts +3 -3
  228. package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts.map +1 -1
  229. package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts +9 -9
  230. package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts.map +1 -1
  231. package/lib/typescript/credential/issuance/05-authorize-access.d.ts +3 -3
  232. package/lib/typescript/credential/issuance/05-authorize-access.d.ts.map +1 -1
  233. package/lib/typescript/credential/issuance/06-obtain-credential.d.ts +4 -4
  234. package/lib/typescript/credential/issuance/06-obtain-credential.d.ts.map +1 -1
  235. package/lib/typescript/credential/issuance/07-verify-and-parse-credential.d.ts +3 -15
  236. package/lib/typescript/credential/issuance/07-verify-and-parse-credential.d.ts.map +1 -1
  237. package/lib/typescript/credential/issuance/const.d.ts +1 -1
  238. package/lib/typescript/credential/issuance/const.d.ts.map +1 -1
  239. package/lib/typescript/credential/issuance/index.d.ts +3 -3
  240. package/lib/typescript/credential/issuance/index.d.ts.map +1 -1
  241. package/lib/typescript/credential/issuance/types.d.ts +8 -3
  242. package/lib/typescript/credential/issuance/types.d.ts.map +1 -1
  243. package/lib/typescript/credential/presentation/01-start-flow.d.ts +28 -9
  244. package/lib/typescript/credential/presentation/01-start-flow.d.ts.map +1 -1
  245. package/lib/typescript/credential/presentation/02-evaluate-rp-trust.d.ts +2 -1
  246. package/lib/typescript/credential/presentation/02-evaluate-rp-trust.d.ts.map +1 -1
  247. package/lib/typescript/credential/presentation/03-get-request-object.d.ts +7 -5
  248. package/lib/typescript/credential/presentation/03-get-request-object.d.ts.map +1 -1
  249. package/lib/typescript/credential/presentation/04-retrieve-rp-jwks.d.ts +4 -30
  250. package/lib/typescript/credential/presentation/04-retrieve-rp-jwks.d.ts.map +1 -1
  251. package/lib/typescript/credential/presentation/05-verify-request-object.d.ts +17 -4
  252. package/lib/typescript/credential/presentation/05-verify-request-object.d.ts.map +1 -1
  253. package/lib/typescript/credential/presentation/06-fetch-presentation-definition.d.ts +4 -9
  254. package/lib/typescript/credential/presentation/06-fetch-presentation-definition.d.ts.map +1 -1
  255. package/lib/typescript/credential/presentation/07-evaluate-dcql-query.d.ts +13 -12
  256. package/lib/typescript/credential/presentation/07-evaluate-dcql-query.d.ts.map +1 -1
  257. package/lib/typescript/credential/presentation/07-evaluate-input-descriptor.d.ts +40 -42
  258. package/lib/typescript/credential/presentation/07-evaluate-input-descriptor.d.ts.map +1 -1
  259. package/lib/typescript/credential/presentation/08-send-authorization-response.d.ts +30 -43
  260. package/lib/typescript/credential/presentation/08-send-authorization-response.d.ts.map +1 -1
  261. package/lib/typescript/credential/presentation/errors.d.ts +25 -10
  262. package/lib/typescript/credential/presentation/errors.d.ts.map +1 -1
  263. package/lib/typescript/credential/presentation/index.d.ts +7 -8
  264. package/lib/typescript/credential/presentation/index.d.ts.map +1 -1
  265. package/lib/typescript/credential/presentation/types.d.ts +137 -307
  266. package/lib/typescript/credential/presentation/types.d.ts.map +1 -1
  267. package/lib/typescript/credential/status/01-start-flow.d.ts +10 -0
  268. package/lib/typescript/credential/status/01-start-flow.d.ts.map +1 -0
  269. package/lib/typescript/credential/status/02-status-attestation.d.ts +19 -0
  270. package/lib/typescript/credential/status/02-status-attestation.d.ts.map +1 -0
  271. package/lib/typescript/credential/status/03-verify-and-parse-status-attestation.d.ts +24 -0
  272. package/lib/typescript/credential/status/03-verify-and-parse-status-attestation.d.ts.map +1 -0
  273. package/lib/typescript/credential/status/index.d.ts +7 -0
  274. package/lib/typescript/credential/status/index.d.ts.map +1 -0
  275. package/lib/typescript/credential/status/types.d.ts +305 -0
  276. package/lib/typescript/credential/status/types.d.ts.map +1 -0
  277. package/lib/typescript/credential/trustmark/get-credential-trustmark.d.ts +52 -0
  278. package/lib/typescript/credential/trustmark/get-credential-trustmark.d.ts.map +1 -0
  279. package/lib/typescript/credential/trustmark/index.d.ts +4 -0
  280. package/lib/typescript/credential/trustmark/index.d.ts.map +1 -0
  281. package/lib/typescript/index.d.ts +3 -1
  282. package/lib/typescript/index.d.ts.map +1 -1
  283. package/lib/typescript/pid/sd-jwt/types.d.ts +103 -25
  284. package/lib/typescript/pid/sd-jwt/types.d.ts.map +1 -1
  285. package/lib/typescript/sd-jwt/index.d.ts +20 -72
  286. package/lib/typescript/sd-jwt/index.d.ts.map +1 -1
  287. package/lib/typescript/sd-jwt/types.d.ts +24 -129
  288. package/lib/typescript/sd-jwt/types.d.ts.map +1 -1
  289. package/lib/typescript/trust/chain.d.ts +23 -0
  290. package/lib/typescript/trust/chain.d.ts.map +1 -0
  291. package/lib/typescript/trust/errors.d.ts +102 -0
  292. package/lib/typescript/trust/errors.d.ts.map +1 -0
  293. package/lib/typescript/{entity/trust → trust}/index.d.ts +308 -281
  294. package/lib/typescript/trust/index.d.ts.map +1 -0
  295. package/lib/typescript/{entity/trust → trust}/types.d.ts +1714 -1301
  296. package/lib/typescript/{entity/trust → trust}/types.d.ts.map +1 -1
  297. package/lib/typescript/trust/utils.d.ts +22 -0
  298. package/lib/typescript/trust/utils.d.ts.map +1 -0
  299. package/lib/typescript/utils/crypto.d.ts +0 -32
  300. package/lib/typescript/utils/crypto.d.ts.map +1 -1
  301. package/lib/typescript/utils/decoder.d.ts.map +1 -1
  302. package/lib/typescript/utils/error-codes.d.ts +20 -0
  303. package/lib/typescript/utils/error-codes.d.ts.map +1 -1
  304. package/lib/typescript/utils/errors.d.ts +55 -10
  305. package/lib/typescript/utils/errors.d.ts.map +1 -1
  306. package/lib/typescript/utils/logging.d.ts +35 -0
  307. package/lib/typescript/utils/logging.d.ts.map +1 -0
  308. package/lib/typescript/utils/misc.d.ts.map +1 -1
  309. package/lib/typescript/utils/par.d.ts +8 -1
  310. package/lib/typescript/utils/par.d.ts.map +1 -1
  311. package/lib/typescript/utils/string.d.ts +0 -7
  312. package/lib/typescript/utils/string.d.ts.map +1 -1
  313. package/lib/typescript/wallet-instance/index.d.ts +8 -0
  314. package/lib/typescript/wallet-instance/index.d.ts.map +1 -1
  315. package/lib/typescript/wallet-instance-attestation/index.d.ts +1 -2
  316. package/lib/typescript/wallet-instance-attestation/index.d.ts.map +1 -1
  317. package/lib/typescript/wallet-instance-attestation/issuing.d.ts +4 -2
  318. package/lib/typescript/wallet-instance-attestation/issuing.d.ts.map +1 -1
  319. package/lib/typescript/wallet-instance-attestation/types.d.ts +60 -102
  320. package/lib/typescript/wallet-instance-attestation/types.d.ts.map +1 -1
  321. package/package.json +9 -10
  322. package/src/client/generated/wallet-provider.ts +52 -17
  323. package/src/credential/index.ts +4 -1
  324. package/src/credential/issuance/01-start-flow.ts +1 -1
  325. package/src/credential/issuance/02-evaluate-issuer-trust.ts +32 -0
  326. package/src/credential/issuance/03-start-user-authorization.ts +48 -22
  327. package/src/credential/issuance/04-complete-user-authorization.ts +74 -18
  328. package/src/credential/issuance/05-authorize-access.ts +29 -11
  329. package/src/credential/issuance/06-obtain-credential.ts +61 -36
  330. package/src/credential/issuance/07-verify-and-parse-credential.ts +37 -264
  331. package/src/credential/issuance/README.md +23 -20
  332. package/src/credential/issuance/const.ts +1 -1
  333. package/src/credential/issuance/index.ts +6 -3
  334. package/src/credential/presentation/01-start-flow.ts +19 -22
  335. package/src/credential/presentation/02-evaluate-rp-trust.ts +5 -4
  336. package/src/credential/presentation/03-get-request-object.ts +36 -8
  337. package/src/credential/presentation/04-retrieve-rp-jwks.ts +6 -148
  338. package/src/credential/presentation/05-verify-request-object.ts +115 -30
  339. package/src/credential/presentation/06-fetch-presentation-definition.ts +5 -35
  340. package/src/credential/presentation/07-evaluate-dcql-query.ts +132 -161
  341. package/src/credential/presentation/07-evaluate-input-descriptor.ts +136 -254
  342. package/src/credential/presentation/08-send-authorization-response.ts +178 -260
  343. package/src/credential/presentation/README.md +74 -79
  344. package/src/credential/presentation/errors.ts +38 -15
  345. package/src/credential/presentation/index.ts +18 -19
  346. package/src/credential/presentation/types.ts +67 -64
  347. package/src/credential/status/01-start-flow.ts +9 -0
  348. package/src/credential/status/02-status-attestation.ts +105 -0
  349. package/src/credential/status/03-verify-and-parse-status-attestation.ts +70 -0
  350. package/src/credential/status/README.md +67 -0
  351. package/src/credential/status/index.ts +22 -0
  352. package/src/credential/status/types.ts +43 -0
  353. package/src/credential/trustmark/README.md +62 -0
  354. package/src/credential/trustmark/get-credential-trustmark.ts +139 -0
  355. package/src/credential/trustmark/index.ts +8 -0
  356. package/src/index.ts +4 -0
  357. package/src/pid/sd-jwt/types.ts +18 -1
  358. package/src/sd-jwt/__test__/index.test.ts +36 -55
  359. package/src/sd-jwt/__test__/types.test.ts +16 -29
  360. package/src/sd-jwt/index.ts +1 -5
  361. package/src/sd-jwt/types.ts +2 -19
  362. package/src/trust/README.md +147 -0
  363. package/src/trust/chain.ts +227 -0
  364. package/src/trust/errors.ts +136 -0
  365. package/src/{entity/trust → trust}/index.ts +207 -25
  366. package/src/{entity/trust → trust}/types.ts +24 -37
  367. package/src/trust/utils.ts +70 -0
  368. package/src/utils/crypto.ts +4 -106
  369. package/src/utils/decoder.ts +6 -1
  370. package/src/utils/error-codes.ts +23 -0
  371. package/src/utils/errors.ts +119 -15
  372. package/src/utils/logging.ts +68 -0
  373. package/src/utils/misc.ts +5 -0
  374. package/src/utils/par.ts +19 -6
  375. package/src/utils/string.ts +0 -10
  376. package/src/wallet-instance/index.ts +30 -1
  377. package/src/wallet-instance-attestation/README.md +8 -3
  378. package/src/wallet-instance-attestation/index.ts +2 -2
  379. package/src/wallet-instance-attestation/issuing.ts +33 -12
  380. package/src/wallet-instance-attestation/types.ts +18 -22
  381. package/lib/commonjs/credential/issuance/02-get-issuer-config.js +0 -48
  382. package/lib/commonjs/credential/issuance/02-get-issuer-config.js.map +0 -1
  383. package/lib/commonjs/entity/openid-connect/issuer/index.js +0 -25
  384. package/lib/commonjs/entity/openid-connect/issuer/index.js.map +0 -1
  385. package/lib/commonjs/entity/openid-connect/issuer/types.js +0 -64
  386. package/lib/commonjs/entity/openid-connect/issuer/types.js.map +0 -1
  387. package/lib/commonjs/entity/trust/chain.js +0 -122
  388. package/lib/commonjs/entity/trust/chain.js.map +0 -1
  389. package/lib/commonjs/entity/trust/index.js +0 -148
  390. package/lib/commonjs/entity/trust/index.js.map +0 -1
  391. package/lib/commonjs/entity/trust/types.js.map +0 -1
  392. package/lib/commonjs/mdoc/converters.js +0 -26
  393. package/lib/commonjs/mdoc/converters.js.map +0 -1
  394. package/lib/commonjs/mdoc/index.js +0 -68
  395. package/lib/commonjs/mdoc/index.js.map +0 -1
  396. package/lib/commonjs/utils/credential/issuance/07-verify-and-parse-credentials-inputs.js +0 -469
  397. package/lib/commonjs/utils/credential/issuance/07-verify-and-parse-credentials-inputs.js.map +0 -1
  398. package/lib/commonjs/utils/credential/issuance/07-verify-and-parse-credentials-utils.js +0 -90
  399. package/lib/commonjs/utils/credential/issuance/07-verify-and-parse-credentials-utils.js.map +0 -1
  400. package/lib/module/credential/issuance/02-get-issuer-config.js +0 -42
  401. package/lib/module/credential/issuance/02-get-issuer-config.js.map +0 -1
  402. package/lib/module/entity/openid-connect/issuer/index.js +0 -20
  403. package/lib/module/entity/openid-connect/issuer/index.js.map +0 -1
  404. package/lib/module/entity/openid-connect/issuer/types.js +0 -48
  405. package/lib/module/entity/openid-connect/issuer/types.js.map +0 -1
  406. package/lib/module/entity/trust/chain.js +0 -113
  407. package/lib/module/entity/trust/chain.js.map +0 -1
  408. package/lib/module/entity/trust/index.js +0 -131
  409. package/lib/module/entity/trust/index.js.map +0 -1
  410. package/lib/module/entity/trust/types.js.map +0 -1
  411. package/lib/module/mdoc/converters.js +0 -20
  412. package/lib/module/mdoc/converters.js.map +0 -1
  413. package/lib/module/mdoc/index.js +0 -60
  414. package/lib/module/mdoc/index.js.map +0 -1
  415. package/lib/module/utils/credential/issuance/07-verify-and-parse-credentials-inputs.js +0 -462
  416. package/lib/module/utils/credential/issuance/07-verify-and-parse-credentials-inputs.js.map +0 -1
  417. package/lib/module/utils/credential/issuance/07-verify-and-parse-credentials-utils.js +0 -83
  418. package/lib/module/utils/credential/issuance/07-verify-and-parse-credentials-utils.js.map +0 -1
  419. package/lib/typescript/credential/issuance/02-get-issuer-config.d.ts +0 -32
  420. package/lib/typescript/credential/issuance/02-get-issuer-config.d.ts.map +0 -1
  421. package/lib/typescript/entity/openid-connect/issuer/index.d.ts +0 -12
  422. package/lib/typescript/entity/openid-connect/issuer/index.d.ts.map +0 -1
  423. package/lib/typescript/entity/openid-connect/issuer/types.d.ts +0 -777
  424. package/lib/typescript/entity/openid-connect/issuer/types.d.ts.map +0 -1
  425. package/lib/typescript/entity/trust/chain.d.ts +0 -26
  426. package/lib/typescript/entity/trust/chain.d.ts.map +0 -1
  427. package/lib/typescript/entity/trust/index.d.ts.map +0 -1
  428. package/lib/typescript/mdoc/converters.d.ts +0 -8
  429. package/lib/typescript/mdoc/converters.d.ts.map +0 -1
  430. package/lib/typescript/mdoc/index.d.ts +0 -10
  431. package/lib/typescript/mdoc/index.d.ts.map +0 -1
  432. package/lib/typescript/utils/credential/issuance/07-verify-and-parse-credentials-inputs.d.ts +0 -3
  433. package/lib/typescript/utils/credential/issuance/07-verify-and-parse-credentials-inputs.d.ts.map +0 -1
  434. package/lib/typescript/utils/credential/issuance/07-verify-and-parse-credentials-utils.d.ts +0 -42
  435. package/lib/typescript/utils/credential/issuance/07-verify-and-parse-credentials-utils.d.ts.map +0 -1
  436. package/src/credential/issuance/02-get-issuer-config.ts +0 -67
  437. package/src/entity/openid-connect/issuer/index.ts +0 -27
  438. package/src/entity/openid-connect/issuer/types.ts +0 -76
  439. package/src/entity/trust/chain.ts +0 -154
  440. package/src/mdoc/converters.ts +0 -26
  441. package/src/mdoc/index.ts +0 -95
  442. package/src/utils/credential/issuance/07-verify-and-parse-credentials-inputs.ts +0 -615
  443. package/src/utils/credential/issuance/07-verify-and-parse-credentials-utils.ts +0 -171
@@ -1,26 +1,24 @@
1
1
  import { EncryptJwe } from "@pagopa/io-react-native-jwt";
2
2
  import uuid from "react-native-uuid";
3
- import type { FetchJwks } from "./04-retrieve-rp-jwks";
4
- import type { VerifyRequestObjectSignature } from "./05-verify-request-object";
5
- import {
6
- NoSuitableKeysFoundInEntityConfiguration,
7
- CredentialNotFoundError,
8
- } from "./errors";
3
+ import { getJwksFromConfig, type FetchJwks } from "./04-retrieve-rp-jwks";
4
+ import type { VerifyRequestObject } from "./05-verify-request-object";
5
+ import { NoSuitableKeysFoundInEntityConfiguration } from "./errors";
9
6
  import { hasStatusOrThrow, type Out } from "../../utils/misc";
10
7
  import {
8
+ type RemotePresentation,
11
9
  DirectAuthorizationBodyPayload,
12
10
  ErrorResponse,
13
- type RemotePresentation,
14
- type PrepareRemotePresentations,
11
+ type LegacyRemotePresentation,
15
12
  } from "./types";
16
13
  import * as z from "zod";
17
14
  import type { JWK } from "../../utils/jwk";
18
- import { Base64 } from "js-base64";
19
-
20
- import { prepareVpTokenMdoc } from "../../mdoc";
21
- import { generateRandomAlphaNumericString } from "../../utils/misc";
22
- import { createCryptoContextFor } from "../../utils/crypto";
23
- import { prepareVpToken } from "../../sd-jwt";
15
+ import type { RelyingPartyEntityConfiguration } from "../../trust";
16
+ import {
17
+ RelyingPartyResponseError,
18
+ ResponseErrorBuilder,
19
+ UnexpectedStatusCodeError,
20
+ RelyingPartyResponseErrorCodes,
21
+ } from "../../utils/errors";
24
22
 
25
23
  export type AuthorizationResponse = z.infer<typeof AuthorizationResponse>;
26
24
  export const AuthorizationResponse = z.object({
@@ -39,9 +37,6 @@ export const AuthorizationResponse = z.object({
39
37
  * Selects a public key (with `use = enc`) from the set of JWK keys
40
38
  * offered by the Relying Party (RP) for encryption.
41
39
  *
42
- * Preference is given to EC keys (P-256 or P-384), followed by RSA keys,
43
- * based on compatibility and common usage for encryption.
44
- *
45
40
  * @param rpJwkKeys - The array of JWKs retrieved from the RP entity configuration.
46
41
  * @returns The first suitable public key found in the list.
47
42
  * @throws {NoSuitableKeysFoundInEntityConfiguration} If no suitable encryption key is found.
@@ -49,18 +44,7 @@ export const AuthorizationResponse = z.object({
49
44
  export const choosePublicKeyToEncrypt = (
50
45
  rpJwkKeys: Out<FetchJwks>["keys"]
51
46
  ): JWK => {
52
- // First try to find RSA keys which are more commonly used for encryption
53
- const encKeys = rpJwkKeys.filter((jwk) => jwk.use === "enc");
54
-
55
- // Prioritize EC keys first, then fall back to RSA keys if needed
56
- // io-react-native-jwt support only EC keys with P-256 or P-384 curves
57
- const ecEncKeys = encKeys.filter(
58
- (jwk) => jwk.kty === "EC" && (jwk.crv === "P-256" || jwk.crv === "P-384")
59
- );
60
- const rsaEncKeys = encKeys.filter((jwk) => jwk.kty === "RSA");
61
-
62
- // Select the first available key based on priority
63
- const encKey = ecEncKeys[0] || rsaEncKeys[0] || encKeys[0];
47
+ const encKey = rpJwkKeys.find((jwk) => jwk.use === "enc");
64
48
 
65
49
  if (encKey) {
66
50
  return encKey;
@@ -72,72 +56,44 @@ export const choosePublicKeyToEncrypt = (
72
56
  );
73
57
  };
74
58
 
75
- /**
76
- * Builds a URL-encoded form body for a direct POST response without encryption.
77
- *
78
- * @param requestObject - Contains state, nonce, and other relevant info.
79
- * @param payload - Object that contains either the VP token to encrypt and the stringified mapping of the credential disclosures or the error code
80
- * @returns A URL-encoded string suitable for an `application/x-www-form-urlencoded` POST body.
81
- */
82
- export const buildDirectPostBody = async (
83
- requestObject: Out<VerifyRequestObjectSignature>["requestObject"],
84
- payload: DirectAuthorizationBodyPayload
85
- ): Promise<string> => {
86
- const formUrlEncodedBody = new URLSearchParams({
87
- ...(requestObject.state ? { state: requestObject.state } : {}),
88
- ...Object.fromEntries(
89
- Object.entries(payload).map(([key, value]) => {
90
- return [
91
- key,
92
- Array.isArray(value) || typeof value === "object"
93
- ? JSON.stringify(value)
94
- : value,
95
- ];
96
- })
97
- ),
98
- });
99
-
100
- return formUrlEncodedBody.toString();
101
- };
102
-
103
59
  /**
104
60
  * Builds a URL-encoded form body for a direct POST response using JWT encryption.
105
61
  *
106
62
  * @param jwkKeys - Array of JWKs from the Relying Party for encryption.
107
63
  * @param requestObject - Contains state, nonce, and other relevant info.
108
- * @param payload - Object that contains either the VP token to encrypt and the mapping of the credential disclosures or the error code
109
- * @param generatedNonce - Optional nonce for the `apu` claim in the JWE header, it is used during ISO 18013-7.
110
- * @returns A URL-encoded string for an `application/x-www-form-urlencoded` POST body,
111
- * where `response` contains the encrypted JWE.
64
+ * @param payload - Object that contains the VP token to encrypt and the mapping of the credential disclosures
65
+ * @returns A URL-encoded string for an `application/x-www-form-urlencoded` POST body, where `response` contains the encrypted JWE.
112
66
  */
113
67
  export const buildDirectPostJwtBody = async (
114
- jwkKeys: Out<FetchJwks>["keys"],
115
- requestObject: Out<VerifyRequestObjectSignature>["requestObject"],
116
- payload: DirectAuthorizationBodyPayload,
117
- generatedNonce?: string
68
+ requestObject: Out<VerifyRequestObject>["requestObject"],
69
+ rpConf: RelyingPartyEntityConfiguration["payload"]["metadata"],
70
+ payload: DirectAuthorizationBodyPayload
118
71
  ): Promise<string> => {
72
+ type Jwe = ConstructorParameters<typeof EncryptJwe>[1];
73
+
119
74
  // Prepare the authorization response payload to be encrypted
120
75
  const authzResponsePayload = JSON.stringify({
121
76
  state: requestObject.state,
122
77
  ...payload,
123
78
  });
79
+ // Choose a suitable public key for encryption
80
+ const { keys } = getJwksFromConfig(rpConf);
81
+ const encPublicJwk = choosePublicKeyToEncrypt(keys);
124
82
 
125
- const encPublicJwk = choosePublicKeyToEncrypt(jwkKeys);
126
83
  // Encrypt the authorization payload
127
- const { client_metadata } = requestObject;
84
+ const {
85
+ authorization_encrypted_response_alg,
86
+ authorization_encrypted_response_enc,
87
+ } = rpConf.openid_credential_verifier;
88
+
89
+ const defaultAlg: Jwe["alg"] =
90
+ encPublicJwk.kty === "EC" ? "ECDH-ES" : "RSA-OAEP-256";
91
+
128
92
  const encryptedResponse = await new EncryptJwe(authzResponsePayload, {
129
- alg:
130
- (client_metadata?.authorization_encrypted_response_alg as
131
- | "RSA-OAEP-256"
132
- | "RSA-OAEP") || "RSA-OAEP-256",
93
+ alg: (authorization_encrypted_response_alg as Jwe["alg"]) || defaultAlg,
133
94
  enc:
134
- (client_metadata?.authorization_encrypted_response_enc as
135
- | "A256CBC-HS512"
136
- | "A128CBC-HS256") || "A256CBC-HS512",
95
+ (authorization_encrypted_response_enc as Jwe["enc"]) || "A256CBC-HS512",
137
96
  kid: encPublicJwk.kid,
138
- /* ISO 18013-7 */
139
- apv: Base64.encodeURI(requestObject.nonce),
140
- ...(generatedNonce ? { apu: Base64.encodeURI(generatedNonce) } : {}),
141
97
  }).encrypt(encPublicJwk);
142
98
 
143
99
  // Build the x-www-form-urlencoded form body
@@ -149,27 +105,44 @@ export const buildDirectPostJwtBody = async (
149
105
  };
150
106
 
151
107
  /**
152
- * Type definition for the function that sends the authorization response
153
- * to the Relying Party, completing the presentation flow.
108
+ * Builds a URL-encoded form body for a direct POST response without encryption.
109
+ *
110
+ * @param requestObject - Contains state, nonce, and other relevant info.
111
+ * @param payload - Object that contains either the VP token to encrypt and the stringified mapping of the credential disclosures or the error code
112
+ * @returns A URL-encoded string suitable for an `application/x-www-form-urlencoded` POST body.
154
113
  */
155
- export type SendAuthorizationResponse = (
156
- requestObject: Out<VerifyRequestObjectSignature>["requestObject"],
157
- presentationDefinitionId: string,
158
- jwkKeys: Out<FetchJwks>["keys"],
159
- remotePresentation: RemotePresentation,
160
- context?: {
161
- appFetch?: GlobalFetch["fetch"];
162
- }
163
- ) => Promise<AuthorizationResponse>;
114
+ export const buildDirectPostBody = async (
115
+ requestObject: Out<VerifyRequestObject>["requestObject"],
116
+ payload: DirectAuthorizationBodyPayload
117
+ ): Promise<string> => {
118
+ const formUrlEncodedBody = new URLSearchParams({
119
+ ...(requestObject.state && { state: requestObject.state }),
120
+ ...Object.entries(payload).reduce(
121
+ (acc, [key, value]) => ({
122
+ ...acc,
123
+ [key]:
124
+ Array.isArray(value) || typeof value === "object"
125
+ ? JSON.stringify(value)
126
+ : value,
127
+ }),
128
+ {} as Record<string, string>
129
+ ),
130
+ });
131
+
132
+ return formUrlEncodedBody.toString();
133
+ };
164
134
 
165
135
  /**
166
136
  * Type definition for the function that sends the authorization response
167
137
  * to the Relying Party, completing the presentation flow.
138
+ * Use with `presentation_definition`.
139
+ * @deprecated Use `sendAuthorizationResponse`
168
140
  */
169
- export type SendAuthorizationResponseDcql = (
170
- requestObject: Out<VerifyRequestObjectSignature>["requestObject"],
171
- jwkKeys: Out<FetchJwks>["keys"],
172
- remotePresentation: RemotePresentation,
141
+ export type SendLegacyAuthorizationResponse = (
142
+ requestObject: Out<VerifyRequestObject>["requestObject"],
143
+ presentationDefinitionId: string,
144
+ remotePresentations: LegacyRemotePresentation[],
145
+ rpConf: RelyingPartyEntityConfiguration["payload"]["metadata"],
173
146
  context?: {
174
147
  appFetch?: GlobalFetch["fetch"];
175
148
  }
@@ -186,55 +159,91 @@ export type SendAuthorizationResponseDcql = (
186
159
  * @param context - Contains optional custom fetch implementation.
187
160
  * @returns Parsed and validated authorization response from the Relying Party.
188
161
  */
189
- export const sendAuthorizationResponse: SendAuthorizationResponse = async (
190
- requestObject,
191
- presentationDefinitionId,
192
- jwkKeys,
193
- remotePresentation,
194
- { appFetch = fetch } = {}
195
- ): Promise<AuthorizationResponse> => {
196
- const { generatedNonce, presentations } = remotePresentation;
197
- /**
198
- * 1. Prepare the VP token and presentation submission
199
- * If there is only one credential, `vpToken` is a single string.
200
- * If there are multiple credential, `vpToken` is an array of string.
201
- **/
202
- const vp_token =
203
- presentations?.length === 1
204
- ? presentations[0]?.vpToken
205
- : presentations.map((presentation) => presentation.vpToken);
162
+ export const sendLegacyAuthorizationResponse: SendLegacyAuthorizationResponse =
163
+ async (
164
+ requestObject,
165
+ presentationDefinitionId,
166
+ remotePresentations,
167
+ rpConf,
168
+ { appFetch = fetch } = {}
169
+ ): Promise<AuthorizationResponse> => {
170
+ /**
171
+ * 1. Prepare the VP token and presentation submission
172
+ * If there is only one credential, `vpToken` is a single string.
173
+ * If there are multiple credential, `vpToken` is an array of string.
174
+ **/
175
+ const vp_token =
176
+ remotePresentations?.length === 1
177
+ ? remotePresentations[0]?.vpToken
178
+ : remotePresentations.map(
179
+ (remotePresentation) => remotePresentation.vpToken
180
+ );
181
+
182
+ const descriptor_map = remotePresentations.map(
183
+ (remotePresentation, index) => ({
184
+ id: remotePresentation.inputDescriptor.id,
185
+ path: remotePresentations.length === 1 ? `$` : `$[${index}]`,
186
+ format: remotePresentation.format,
187
+ })
188
+ );
206
189
 
207
- const descriptor_map = presentations.map((presentation, index) => ({
208
- id: presentation.credentialId,
209
- path: presentations?.length === 1 ? `$` : `$[${index}]`,
210
- format: presentation.format,
211
- }));
190
+ const presentation_submission = {
191
+ id: uuid.v4(),
192
+ definition_id: presentationDefinitionId,
193
+ descriptor_map,
194
+ };
212
195
 
213
- const presentation_submission = {
214
- id: uuid.v4(),
215
- definition_id: presentationDefinitionId,
216
- descriptor_map,
196
+ const requestBody = await buildDirectPostJwtBody(requestObject, rpConf, {
197
+ vp_token,
198
+ presentation_submission,
199
+ });
200
+
201
+ // 3. Send the authorization response via HTTP POST and validate the response
202
+ return await appFetch(requestObject.response_uri, {
203
+ method: "POST",
204
+ headers: {
205
+ "Content-Type": "application/x-www-form-urlencoded",
206
+ },
207
+ body: requestBody,
208
+ })
209
+ .then(hasStatusOrThrow(200))
210
+ .then((res) => res.json())
211
+ .then(AuthorizationResponse.parse);
217
212
  };
218
213
 
219
- // 2. Choose the appropriate request body builder based on response mode
220
- const requestBody =
221
- requestObject.response_mode === "direct_post.jwt"
222
- ? await buildDirectPostJwtBody(
223
- jwkKeys,
224
- requestObject,
225
- {
226
- vp_token,
227
- presentation_submission,
228
- },
229
- generatedNonce
230
- )
231
- : await buildDirectPostBody(requestObject, {
232
- vp_token,
233
- presentation_submission: presentation_submission,
234
- });
214
+ /**
215
+ * Type definition for the function that sends the authorization response
216
+ * to the Relying Party, completing the presentation flow.
217
+ * Use with DCQL queries.
218
+ */
219
+ export type SendAuthorizationResponse = (
220
+ requestObject: Out<VerifyRequestObject>["requestObject"],
221
+ remotePresentations: RemotePresentation[],
222
+ rpConf: RelyingPartyEntityConfiguration["payload"]["metadata"],
223
+ context?: {
224
+ appFetch?: GlobalFetch["fetch"];
225
+ }
226
+ ) => Promise<AuthorizationResponse>;
235
227
 
236
- // 3. Send the authorization response via HTTP POST and validate the response
237
- const authResponse = await appFetch(requestObject.response_uri, {
228
+ export const sendAuthorizationResponse: SendAuthorizationResponse = async (
229
+ requestObject,
230
+ remotePresentations,
231
+ rpConf,
232
+ { appFetch = fetch } = {}
233
+ ): Promise<AuthorizationResponse> => {
234
+ // 1. Prepare the VP token as a JSON object with keys corresponding to the DCQL query credential IDs
235
+ const requestBody = await buildDirectPostJwtBody(requestObject, rpConf, {
236
+ vp_token: remotePresentations.reduce(
237
+ (acc, presentation) => ({
238
+ ...acc,
239
+ [presentation.credentialId]: presentation.vpToken,
240
+ }),
241
+ {} as Record<string, string>
242
+ ),
243
+ });
244
+
245
+ // 2. Send the authorization response via HTTP POST and validate the response
246
+ return await appFetch(requestObject.response_uri, {
238
247
  method: "POST",
239
248
  headers: {
240
249
  "Content-Type": "application/x-www-form-urlencoded",
@@ -243,10 +252,8 @@ export const sendAuthorizationResponse: SendAuthorizationResponse = async (
243
252
  })
244
253
  .then(hasStatusOrThrow(200))
245
254
  .then((res) => res.json())
246
- .then(AuthorizationResponse.safeParse);
247
-
248
- // Some Relying Parties may return an empty body.
249
- return authResponse.success ? authResponse.data : {};
255
+ .then(AuthorizationResponse.parse)
256
+ .catch(handleAuthorizationResponseError);
250
257
  };
251
258
 
252
259
  /**
@@ -254,9 +261,8 @@ export const sendAuthorizationResponse: SendAuthorizationResponse = async (
254
261
  * to the Relying Party, completing the presentation flow.
255
262
  */
256
263
  export type SendAuthorizationErrorResponse = (
257
- requestObject: Out<VerifyRequestObjectSignature>["requestObject"],
258
- error: ErrorResponse,
259
- jwkKeys: Out<FetchJwks>["keys"],
264
+ requestObject: Out<VerifyRequestObject>["requestObject"],
265
+ error: { error: ErrorResponse; errorDescription: string },
260
266
  context?: {
261
267
  appFetch?: GlobalFetch["fetch"];
262
268
  }
@@ -267,61 +273,21 @@ export type SendAuthorizationErrorResponse = (
267
273
  * This function completes the presentation flow in an OpenID 4 Verifiable Presentations scenario.
268
274
  *
269
275
  * @param requestObject - The request details, including presentation requirements.
270
- * @param error - The response error value
271
- * @param jwkKeys - Array of JWKs from the Relying Party for optional encryption.
276
+ * @param error - The response error value, with description
272
277
  * @param context - Contains optional custom fetch implementation.
273
278
  * @returns Parsed and validated authorization response from the Relying Party.
274
279
  */
275
280
  export const sendAuthorizationErrorResponse: SendAuthorizationErrorResponse =
276
281
  async (
277
282
  requestObject,
278
- error,
279
- jwkKeys,
283
+ { error, errorDescription },
280
284
  { appFetch = fetch } = {}
281
285
  ): Promise<AuthorizationResponse> => {
282
- // 2. Choose the appropriate request body builder based on response mode
283
- const requestBody =
284
- requestObject.response_mode === "direct_post.jwt"
285
- ? await buildDirectPostJwtBody(jwkKeys, requestObject, { error })
286
- : await buildDirectPostBody(requestObject, { error });
287
- // 3. Send the authorization error response via HTTP POST and validate the response
288
- return await appFetch(requestObject.response_uri, {
289
- method: "POST",
290
- headers: {
291
- "Content-Type": "application/x-www-form-urlencoded",
292
- },
293
- body: requestBody,
294
- })
295
- .then(hasStatusOrThrow(200))
296
- .then((res) => res.json())
297
- .then(AuthorizationResponse.parse);
298
- };
286
+ const requestBody = await buildDirectPostBody(requestObject, {
287
+ error,
288
+ error_description: errorDescription,
289
+ });
299
290
 
300
- export const sendAuthorizationResponseDcql: SendAuthorizationResponseDcql =
301
- async (
302
- requestObject,
303
- jwkKeys,
304
- remotePresentation,
305
- { appFetch = fetch } = {}
306
- ): Promise<AuthorizationResponse> => {
307
- const { generatedNonce, presentations } = remotePresentation;
308
- // 1. Prepare the VP token as a JSON object with keys corresponding to the DCQL query credential IDs
309
- const requestBody = await buildDirectPostJwtBody(
310
- jwkKeys,
311
- requestObject,
312
- {
313
- vp_token: presentations.reduce(
314
- (acc, presentation) => ({
315
- ...acc,
316
- [presentation.credentialId]: presentation.vpToken,
317
- }),
318
- {} as Record<string, string>
319
- ),
320
- },
321
- generatedNonce
322
- );
323
-
324
- // 2. Send the authorization response via HTTP POST and validate the response
325
291
  return await appFetch(requestObject.response_uri, {
326
292
  method: "POST",
327
293
  headers: {
@@ -329,83 +295,35 @@ export const sendAuthorizationResponseDcql: SendAuthorizationResponseDcql =
329
295
  },
330
296
  body: requestBody,
331
297
  })
332
- .then(hasStatusOrThrow(200))
298
+ .then(hasStatusOrThrow(200, RelyingPartyResponseError))
333
299
  .then((res) => res.json())
334
300
  .then(AuthorizationResponse.parse);
335
301
  };
336
302
 
337
303
  /**
338
- * Prepares remote presentations for a set of credentials.
339
- *
340
- * For each credential, this function:
341
- * - Validates the credential format (currently supports 'mso_mdoc' and 'vc+sd-jwt').
342
- * - Generates a verifiable presentation token (vpToken) using the appropriate method.
343
- * - For ISO 18013-7, generates a special nonce with minimum entropy of 16.
344
- *
345
- * @param credentials - An array of credential items containing format, credential data, requested claims, and key information.
346
- * @param authRequestObject - The authentication request object containing nonce, clientId, and responseUri.
347
- * @returns A promise that resolves to an object containing an array of presentations and the generated nonce.
348
- * @throws {CredentialNotFoundError} When the credential format is unsupported.
304
+ * Handle the the presentation error by mapping it to a custom exception.
305
+ * If the error is not an instance of {@link UnexpectedStatusCodeError}, it is thrown as is.
306
+ * @param e - The error to be handled
307
+ * @throws {RelyingPartyResponseError} with a specific code for more context
349
308
  */
350
- export const prepareRemotePresentations: PrepareRemotePresentations = async (
351
- credentials,
352
- authRequestObject
353
- ) => {
354
- /* In case of ISO 18013-7 we need a nonce, it shall have a minimum entropy of 16 */
355
- const generatedNonce = generateRandomAlphaNumericString(16);
356
-
357
- const presentations = await Promise.all(
358
- credentials.map(async (item) => {
359
- const { credentialInputId, format } = item;
360
-
361
- if (format === "mso_mdoc") {
362
- const { vp_token } = await prepareVpTokenMdoc(
363
- authRequestObject.nonce,
364
- generatedNonce,
365
- authRequestObject.clientId,
366
- authRequestObject.responseUri,
367
- item.doctype,
368
- item.keyTag,
369
- [
370
- item.credential,
371
- item.requestedClaims,
372
- createCryptoContextFor(item.keyTag),
373
- ]
374
- );
375
-
376
- return {
377
- requestedClaims: [...item.requestedClaims.map(({ name }) => name)],
378
- credentialId: credentialInputId,
379
- vpToken: vp_token,
380
- format: "mso_mdoc",
381
- };
382
- }
383
-
384
- if (format === "vc+sd-jwt") {
385
- const { vp_token } = await prepareVpToken(
386
- authRequestObject.nonce,
387
- authRequestObject.clientId,
388
- [
389
- item.credential,
390
- item.requestedClaims,
391
- createCryptoContextFor(item.keyTag),
392
- ]
393
- );
394
-
395
- return {
396
- requestedClaims: [...item.requestedClaims.map(({ name }) => name)],
397
- credentialId: credentialInputId,
398
- vpToken: vp_token,
399
- format: "vc+sd-jwt",
400
- };
401
- }
309
+ const handleAuthorizationResponseError = (e: unknown) => {
310
+ if (!(e instanceof UnexpectedStatusCodeError)) {
311
+ throw e;
312
+ }
402
313
 
403
- throw new CredentialNotFoundError(`${format} format is not supported.`);
314
+ throw new ResponseErrorBuilder(RelyingPartyResponseError)
315
+ .handle(400, {
316
+ code: RelyingPartyResponseErrorCodes.InvalidAuthorizationResponse,
317
+ message:
318
+ "The Authorization Response contains invalid parameters or it is malformed",
404
319
  })
405
- );
406
-
407
- return {
408
- presentations,
409
- generatedNonce,
410
- };
320
+ .handle(403, {
321
+ code: RelyingPartyResponseErrorCodes.InvalidAuthorizationResponse,
322
+ message: "The Authorization Response was forbidden",
323
+ })
324
+ .handle("*", {
325
+ code: RelyingPartyResponseErrorCodes.RelyingPartyGenericError,
326
+ message: "Unable to successfully send the Authorization Response",
327
+ })
328
+ .buildFrom(e);
411
329
  };