@pagopa/io-react-native-wallet 0.28.0 → 0.28.2

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 (149) hide show
  1. package/lib/commonjs/credential/issuance/03-start-user-authorization.js +3 -0
  2. package/lib/commonjs/credential/issuance/03-start-user-authorization.js.map +1 -1
  3. package/lib/commonjs/credential/issuance/04-complete-user-authorization.js +5 -3
  4. package/lib/commonjs/credential/issuance/04-complete-user-authorization.js.map +1 -1
  5. package/lib/commonjs/credential/presentation/01-start-flow.js +12 -23
  6. package/lib/commonjs/credential/presentation/01-start-flow.js.map +1 -1
  7. package/lib/commonjs/credential/presentation/02-evaluate-rp-trust.js +4 -2
  8. package/lib/commonjs/credential/presentation/02-evaluate-rp-trust.js.map +1 -1
  9. package/lib/commonjs/credential/presentation/03-get-request-object.js +31 -43
  10. package/lib/commonjs/credential/presentation/03-get-request-object.js.map +1 -1
  11. package/lib/commonjs/credential/presentation/04-retrieve-rp-jwks.js +32 -0
  12. package/lib/commonjs/credential/presentation/04-retrieve-rp-jwks.js.map +1 -0
  13. package/lib/commonjs/credential/presentation/05-verify-request-object.js +60 -0
  14. package/lib/commonjs/credential/presentation/05-verify-request-object.js.map +1 -0
  15. package/lib/commonjs/credential/presentation/06-fetch-presentation-definition.js +39 -0
  16. package/lib/commonjs/credential/presentation/06-fetch-presentation-definition.js.map +1 -0
  17. package/lib/commonjs/credential/presentation/07-evaluate-dcql-query.js +134 -0
  18. package/lib/commonjs/credential/presentation/07-evaluate-dcql-query.js.map +1 -0
  19. package/lib/commonjs/credential/presentation/07-evaluate-input-descriptor.js +296 -0
  20. package/lib/commonjs/credential/presentation/07-evaluate-input-descriptor.js.map +1 -0
  21. package/lib/commonjs/credential/presentation/08-send-authorization-response.js +170 -0
  22. package/lib/commonjs/credential/presentation/08-send-authorization-response.js.map +1 -0
  23. package/lib/commonjs/credential/presentation/README.md +88 -2
  24. package/lib/commonjs/credential/presentation/errors.js +68 -1
  25. package/lib/commonjs/credential/presentation/errors.js.map +1 -1
  26. package/lib/commonjs/credential/presentation/index.js +54 -1
  27. package/lib/commonjs/credential/presentation/index.js.map +1 -1
  28. package/lib/commonjs/credential/presentation/types.js +125 -4
  29. package/lib/commonjs/credential/presentation/types.js.map +1 -1
  30. package/lib/commonjs/sd-jwt/index.js +41 -1
  31. package/lib/commonjs/sd-jwt/index.js.map +1 -1
  32. package/lib/commonjs/trust/chain.js.map +1 -1
  33. package/lib/commonjs/trust/types.js +26 -6
  34. package/lib/commonjs/trust/types.js.map +1 -1
  35. package/lib/commonjs/trust/utils.js +5 -0
  36. package/lib/commonjs/trust/utils.js.map +1 -1
  37. package/lib/commonjs/utils/jwk.js +5 -1
  38. package/lib/commonjs/utils/jwk.js.map +1 -1
  39. package/lib/module/credential/issuance/03-start-user-authorization.js +3 -0
  40. package/lib/module/credential/issuance/03-start-user-authorization.js.map +1 -1
  41. package/lib/module/credential/issuance/04-complete-user-authorization.js +5 -3
  42. package/lib/module/credential/issuance/04-complete-user-authorization.js.map +1 -1
  43. package/lib/module/credential/presentation/01-start-flow.js +13 -24
  44. package/lib/module/credential/presentation/01-start-flow.js.map +1 -1
  45. package/lib/module/credential/presentation/02-evaluate-rp-trust.js +4 -2
  46. package/lib/module/credential/presentation/02-evaluate-rp-trust.js.map +1 -1
  47. package/lib/module/credential/presentation/03-get-request-object.js +32 -44
  48. package/lib/module/credential/presentation/03-get-request-object.js.map +1 -1
  49. package/lib/module/credential/presentation/04-retrieve-rp-jwks.js +25 -0
  50. package/lib/module/credential/presentation/04-retrieve-rp-jwks.js.map +1 -0
  51. package/lib/module/credential/presentation/05-verify-request-object.js +53 -0
  52. package/lib/module/credential/presentation/05-verify-request-object.js.map +1 -0
  53. package/lib/module/credential/presentation/06-fetch-presentation-definition.js +32 -0
  54. package/lib/module/credential/presentation/06-fetch-presentation-definition.js.map +1 -0
  55. package/lib/module/credential/presentation/07-evaluate-dcql-query.js +127 -0
  56. package/lib/module/credential/presentation/07-evaluate-dcql-query.js.map +1 -0
  57. package/lib/module/credential/presentation/07-evaluate-input-descriptor.js +285 -0
  58. package/lib/module/credential/presentation/07-evaluate-input-descriptor.js.map +1 -0
  59. package/lib/module/credential/presentation/08-send-authorization-response.js +158 -0
  60. package/lib/module/credential/presentation/08-send-authorization-response.js.map +1 -0
  61. package/lib/module/credential/presentation/README.md +88 -2
  62. package/lib/module/credential/presentation/errors.js +63 -0
  63. package/lib/module/credential/presentation/errors.js.map +1 -1
  64. package/lib/module/credential/presentation/index.js +7 -2
  65. package/lib/module/credential/presentation/index.js.map +1 -1
  66. package/lib/module/credential/presentation/types.js +122 -3
  67. package/lib/module/credential/presentation/types.js.map +1 -1
  68. package/lib/module/sd-jwt/index.js +40 -1
  69. package/lib/module/sd-jwt/index.js.map +1 -1
  70. package/lib/module/trust/chain.js.map +1 -1
  71. package/lib/module/trust/types.js +26 -6
  72. package/lib/module/trust/types.js.map +1 -1
  73. package/lib/module/trust/utils.js +5 -0
  74. package/lib/module/trust/utils.js.map +1 -1
  75. package/lib/module/utils/jwk.js +3 -0
  76. package/lib/module/utils/jwk.js.map +1 -1
  77. package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts.map +1 -1
  78. package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts +2 -2
  79. package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts.map +1 -1
  80. package/lib/typescript/credential/presentation/01-start-flow.d.ts +23 -7
  81. package/lib/typescript/credential/presentation/01-start-flow.d.ts.map +1 -1
  82. package/lib/typescript/credential/presentation/02-evaluate-rp-trust.d.ts +1 -0
  83. package/lib/typescript/credential/presentation/02-evaluate-rp-trust.d.ts.map +1 -1
  84. package/lib/typescript/credential/presentation/03-get-request-object.d.ts +7 -11
  85. package/lib/typescript/credential/presentation/03-get-request-object.d.ts.map +1 -1
  86. package/lib/typescript/credential/presentation/04-retrieve-rp-jwks.d.ts +23 -0
  87. package/lib/typescript/credential/presentation/04-retrieve-rp-jwks.d.ts.map +1 -0
  88. package/lib/typescript/credential/presentation/05-verify-request-object.d.ts +20 -0
  89. package/lib/typescript/credential/presentation/05-verify-request-object.d.ts.map +1 -0
  90. package/lib/typescript/credential/presentation/06-fetch-presentation-definition.d.ts +21 -0
  91. package/lib/typescript/credential/presentation/06-fetch-presentation-definition.d.ts.map +1 -0
  92. package/lib/typescript/credential/presentation/07-evaluate-dcql-query.d.ts +28 -0
  93. package/lib/typescript/credential/presentation/07-evaluate-dcql-query.d.ts.map +1 -0
  94. package/lib/typescript/credential/presentation/07-evaluate-input-descriptor.d.ts +93 -0
  95. package/lib/typescript/credential/presentation/07-evaluate-input-descriptor.d.ts.map +1 -0
  96. package/lib/typescript/credential/presentation/08-send-authorization-response.d.ts +70 -0
  97. package/lib/typescript/credential/presentation/08-send-authorization-response.d.ts.map +1 -0
  98. package/lib/typescript/credential/presentation/errors.d.ts +43 -0
  99. package/lib/typescript/credential/presentation/errors.d.ts.map +1 -1
  100. package/lib/typescript/credential/presentation/index.d.ts +8 -3
  101. package/lib/typescript/credential/presentation/index.d.ts.map +1 -1
  102. package/lib/typescript/credential/presentation/types.d.ts +750 -13
  103. package/lib/typescript/credential/presentation/types.d.ts.map +1 -1
  104. package/lib/typescript/sd-jwt/index.d.ts +19 -0
  105. package/lib/typescript/sd-jwt/index.d.ts.map +1 -1
  106. package/lib/typescript/trust/index.d.ts +236 -8
  107. package/lib/typescript/trust/index.d.ts.map +1 -1
  108. package/lib/typescript/trust/types.d.ts +3046 -76
  109. package/lib/typescript/trust/types.d.ts.map +1 -1
  110. package/lib/typescript/trust/utils.d.ts +6 -6
  111. package/lib/typescript/trust/utils.d.ts.map +1 -1
  112. package/lib/typescript/utils/decoder.d.ts +1 -1
  113. package/lib/typescript/utils/decoder.d.ts.map +1 -1
  114. package/lib/typescript/utils/errors.d.ts.map +1 -1
  115. package/lib/typescript/utils/jwk.d.ts +137 -0
  116. package/lib/typescript/utils/jwk.d.ts.map +1 -1
  117. package/lib/typescript/utils/misc.d.ts.map +1 -1
  118. package/lib/typescript/wallet-instance-attestation/types.d.ts +16 -16
  119. package/package.json +15 -11
  120. package/src/credential/issuance/03-start-user-authorization.ts +3 -0
  121. package/src/credential/issuance/04-complete-user-authorization.ts +6 -3
  122. package/src/credential/presentation/01-start-flow.ts +18 -28
  123. package/src/credential/presentation/02-evaluate-rp-trust.ts +3 -2
  124. package/src/credential/presentation/03-get-request-object.ts +36 -60
  125. package/src/credential/presentation/04-retrieve-rp-jwks.ts +34 -0
  126. package/src/credential/presentation/05-verify-request-object.ts +63 -0
  127. package/src/credential/presentation/06-fetch-presentation-definition.ts +48 -0
  128. package/src/credential/presentation/07-evaluate-dcql-query.ts +174 -0
  129. package/src/credential/presentation/07-evaluate-input-descriptor.ts +393 -0
  130. package/src/credential/presentation/08-send-authorization-response.ts +222 -0
  131. package/src/credential/presentation/README.md +88 -2
  132. package/src/credential/presentation/errors.ts +64 -0
  133. package/src/credential/presentation/index.ts +40 -1
  134. package/src/credential/presentation/types.ts +135 -4
  135. package/src/sd-jwt/index.ts +49 -1
  136. package/src/trust/chain.ts +2 -2
  137. package/src/trust/types.ts +25 -5
  138. package/src/trust/utils.ts +6 -3
  139. package/src/utils/decoder.ts +1 -1
  140. package/src/utils/errors.ts +2 -2
  141. package/src/utils/jwk.ts +8 -1
  142. package/src/utils/misc.ts +2 -2
  143. package/lib/commonjs/credential/presentation/04-send-authorization-response.js +0 -138
  144. package/lib/commonjs/credential/presentation/04-send-authorization-response.js.map +0 -1
  145. package/lib/module/credential/presentation/04-send-authorization-response.js +0 -128
  146. package/lib/module/credential/presentation/04-send-authorization-response.js.map +0 -1
  147. package/lib/typescript/credential/presentation/04-send-authorization-response.d.ts +0 -34
  148. package/lib/typescript/credential/presentation/04-send-authorization-response.d.ts.map +0 -1
  149. package/src/credential/presentation/04-send-authorization-response.ts +0 -168
@@ -19,16 +19,18 @@ import { AuthorizationError, AuthorizationIdpError } from "./errors";
19
19
  * @param issuerRequestUri the URI of the issuer where the request is sent
20
20
  * @param clientId Identifies the current client across all the requests of the issuing flow returned by {@link startUserAuthorization}
21
21
  * @param issuerConf The issuer configuration returned by {@link evaluateIssuerTrust}
22
- * @param idpHint Unique identifier of the IDP selected by the user
22
+ * @param idpHint Unique identifier of the IDP selected by the user (optional)
23
23
  * @returns An object containing the authorization URL
24
24
  */
25
25
  export const buildAuthorizationUrl = async (issuerRequestUri, clientId, issuerConf, idpHint) => {
26
26
  const authzRequestEndpoint = issuerConf.oauth_authorization_server.authorization_endpoint;
27
27
  const params = new URLSearchParams({
28
28
  client_id: clientId,
29
- request_uri: issuerRequestUri,
30
- idphint: idpHint
29
+ request_uri: issuerRequestUri
31
30
  });
31
+ if (idpHint) {
32
+ params.append("idphint", idpHint);
33
+ }
32
34
  const authUrl = `${authzRequestEndpoint}?${params}`;
33
35
  return {
34
36
  authUrl
@@ -1 +1 @@
1
- {"version":3,"names":["AuthorizationErrorShape","AuthorizationResultShape","hasStatusOrThrow","parseUrl","IssuerResponseError","ValidationFailed","decode","encodeBase64","SignJWT","RequestObject","v4","uuidv4","ResponseUriResultShape","getJwtFromFormPost","AuthorizationError","AuthorizationIdpError","buildAuthorizationUrl","issuerRequestUri","clientId","issuerConf","idpHint","authzRequestEndpoint","oauth_authorization_server","authorization_endpoint","params","URLSearchParams","client_id","request_uri","idphint","authUrl","completeUserAuthorizationWithQueryMode","authRedirectUrl","query","parseAuthorizationResponse","getRequestedCredentialToBePresented","appFetch","arguments","length","undefined","fetch","requestObject","toString","method","then","res","text","jws","reqObj","safeParse","payload","success","message","reason","error","data","completeUserAuthorizationWithFormPostJwtMode","ctx","wiaCryptoContext","pidCryptoContext","pid","walletInstanceAttestation","wiaWpToken","setProtectedHeader","alg","typ","setPayload","vp","jti","nonce","setIssuedAt","setExpirationTime","setAudience","response_uri","sign","pidWpToken","presentationSubmission","definition_id","id","descriptor_map","path","format","authzResponsePayload","JSON","stringify","state","presentation_submission","vp_token","body","response","resUriRes","headers","reqUri","json","responseUri","redirect_uri","cbRes","decodedJwt","authRes","authResParsed","authErr","error_description"],"sourceRoot":"../../../../src","sources":["credential/issuance/04-complete-user-authorization.ts"],"mappings":"AAAA,SACEA,uBAAuB,EACvBC,wBAAwB,QAEnB,kBAAkB;AACzB,SAASC,gBAAgB,QAAkB,kBAAkB;AAE7D,OAAOC,QAAQ,MAAM,WAAW;AAChC,SAASC,mBAAmB,EAAEC,gBAAgB,QAAQ,oBAAoB;AAE1E,SACEC,MAAM,EACNC,YAAY,EACZC,OAAO,QAEF,6BAA6B;AACpC,SAASC,aAAa,QAAQ,uBAAuB;AACrD,SAASC,EAAE,IAAIC,MAAM,QAAQ,MAAM;AACnC,SAASC,sBAAsB,QAAQ,SAAS;AAChD,SAASC,kBAAkB,QAAQ,qBAAqB;AACxD,SAASC,kBAAkB,EAAEC,qBAAqB,QAAQ,UAAU;;AAEpE;AACA;AACA;;AAgCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,qBAA4C,GAAG,MAAAA,CAC1DC,gBAAgB,EAChBC,QAAQ,EACRC,UAAU,EACVC,OAAO,KACJ;EACH,MAAMC,oBAAoB,GACxBF,UAAU,CAACG,0BAA0B,CAACC,sBAAsB;EAE9D,MAAMC,MAAM,GAAG,IAAIC,eAAe,CAAC;IACjCC,SAAS,EAAER,QAAQ;IACnBS,WAAW,EAAEV,gBAAgB;IAC7BW,OAAO,EAAER;EACX,CAAC,CAAC;EAEF,MAAMS,OAAO,GAAI,GAAER,oBAAqB,IAAGG,MAAO,EAAC;EAEnD,OAAO;IAAEK;EAAQ,CAAC;AACpB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,sCAA8E,GACzF,MAAOC,eAAe,IAAK;EACzB,MAAMC,KAAK,GAAG7B,QAAQ,CAAC4B,eAAe,CAAC,CAACC,KAAK;EAE7C,OAAOC,0BAA0B,CAACD,KAAK,CAAC;AAC1C,CAAC;;AAEH;AACA;AACA;AACA;AAC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AAKA,GAAG,CAACC,IAAI,CAAC,CAAC,CAAC,CACzBF,IAAI,CAAC9B,kBAAkB,CAAC,CACxB8B,IAAI,CAAEoD,KAAK,IAAK9D,0BAA0B,CAAC8D,KAAK,CAACC,UAAU,CAAC/C,OAAO,CAAC,CAAC;AAC1E,CAAC;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMhB,0BAA0B,GACrCgE,OAAgB,IACQ;EACxB,MAAMC,aAAa,GAAGjG,wBAAwB,CAAC+C,SAAS,CAACiD,OAAO,CAAC;EACjE,IAAI,CAACC,aAAa,CAAChD,OAAO,EAAE;IAC1B,MAAMiD,OAAO,GAAGnG,uBAAuB,CAACgD,SAAS,CAACiD,OAAO,CAAC;IAC1D,IAAI,CAACE,OAAO,CAACjD,OAAO,EAAE;MACpB,MAAM,IAAIpC,kBAAkB,CAACoF,aAAa,CAAC7C,KAAK,CAACF,OAAO,CAAC,CAAC,CAAC;IAC7D;;IACA,MAAM,IAAIpC,qBAAqB,CAC7BoF,OAAO,CAAC7C,IAAI,CAACD,KAAK,EAClB8C,OAAO,CAAC7C,IAAI,CAAC8C,iBACf,CAAC;EACH;EACA,OAAOF,aAAa,CAAC5C,IAAI;AAC3B,CAAC"}
1
+ {"version":3,"names":["AuthorizationErrorShape","AuthorizationResultShape","hasStatusOrThrow","parseUrl","IssuerResponseError","ValidationFailed","decode","encodeBase64","SignJWT","RequestObject","v4","uuidv4","ResponseUriResultShape","getJwtFromFormPost","AuthorizationError","AuthorizationIdpError","buildAuthorizationUrl","issuerRequestUri","clientId","issuerConf","idpHint","authzRequestEndpoint","oauth_authorization_server","authorization_endpoint","params","URLSearchParams","client_id","request_uri","append","authUrl","completeUserAuthorizationWithQueryMode","authRedirectUrl","query","parseAuthorizationResponse","getRequestedCredentialToBePresented","appFetch","arguments","length","undefined","fetch","requestObject","toString","method","then","res","text","jws","reqObj","safeParse","payload","success","message","reason","error","data","completeUserAuthorizationWithFormPostJwtMode","ctx","wiaCryptoContext","pidCryptoContext","pid","walletInstanceAttestation","wiaWpToken","setProtectedHeader","alg","typ","setPayload","vp","jti","nonce","setIssuedAt","setExpirationTime","setAudience","response_uri","sign","pidWpToken","presentationSubmission","definition_id","id","descriptor_map","path","format","authzResponsePayload","JSON","stringify","state","presentation_submission","vp_token","body","response","resUriRes","headers","reqUri","json","responseUri","redirect_uri","cbRes","decodedJwt","authRes","authResParsed","authErr","error_description"],"sourceRoot":"../../../../src","sources":["credential/issuance/04-complete-user-authorization.ts"],"mappings":"AAAA,SACEA,uBAAuB,EACvBC,wBAAwB,QAEnB,kBAAkB;AACzB,SAASC,gBAAgB,QAAkB,kBAAkB;AAE7D,OAAOC,QAAQ,MAAM,WAAW;AAChC,SAASC,mBAAmB,EAAEC,gBAAgB,QAAQ,oBAAoB;AAE1E,SACEC,MAAM,EACNC,YAAY,EACZC,OAAO,QAEF,6BAA6B;AACpC,SAASC,aAAa,QAAQ,uBAAuB;AACrD,SAASC,EAAE,IAAIC,MAAM,QAAQ,MAAM;AACnC,SAASC,sBAAsB,QAAQ,SAAS;AAChD,SAASC,kBAAkB,QAAQ,qBAAqB;AACxD,SAASC,kBAAkB,EAAEC,qBAAqB,QAAQ,UAAU;;AAEpE;AACA;AACA;;AAgCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,qBAA4C,GAAG,MAAAA,CAC1DC,gBAAgB,EAChBC,QAAQ,EACRC,UAAU,EACVC,OAAO,KACJ;EACH,MAAMC,oBAAoB,GACxBF,UAAU,CAACG,0BAA0B,CAACC,sBAAsB;EAE9D,MAAMC,MAAM,GAAG,IAAIC,eAAe,CAAC;IACjCC,SAAS,EAAER,QAAQ;IACnBS,WAAW,EAAEV;EACf,CAAC,CAAC;EAEF,IAAIG,OAAO,EAAE;IACXI,MAAM,CAACI,MAAM,CAAC,SAAS,EAAER,OAAO,CAAC;EACnC;EAEA,MAAMS,OAAO,GAAI,GAAER,oBAAqB,IAAGG,MAAO,EA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,CAAC;MACzB8C,OAAO,EAAE,gCAAgC;MACzCC,MAAM,EAAEyC,WAAW,CAACxC,KAAK,CAACF;IAC5B,CAAC,CAAC;EACJ;EAEA,OAAO,MAAMhB,QAAQ,CAAC0D,WAAW,CAACvC,IAAI,CAACwC,YAAY,CAAC,CACjDnD,IAAI,CAACzC,gBAAgB,CAAC,GAAG,EAAEE,mBAAmB,CAAC,CAAC,CAChDuC,IAAI,CAAEC,GAAG,IAAKA,GAAG,CAACC,IAAI,CAAC,CAAC,CAAC,CACzBF,IAAI,CAAC9B,kBAAkB,CAAC,CACxB8B,IAAI,CAAEoD,KAAK,IAAK9D,0BAA0B,CAAC8D,KAAK,CAACC,UAAU,CAAC/C,OAAO,CAAC,CAAC;AAC1E,CAAC;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMhB,0BAA0B,GACrCgE,OAAgB,IACQ;EACxB,MAAMC,aAAa,GAAGjG,wBAAwB,CAAC+C,SAAS,CAACiD,OAAO,CAAC;EACjE,IAAI,CAACC,aAAa,CAAChD,OAAO,EAAE;IAC1B,MAAMiD,OAAO,GAAGnG,uBAAuB,CAACgD,SAAS,CAACiD,OAAO,CAAC;IAC1D,IAAI,CAACE,OAAO,CAACjD,OAAO,EAAE;MACpB,MAAM,IAAIpC,kBAAkB,CAACoF,aAAa,CAAC7C,KAAK,CAACF,OAAO,CAAC,CAAC,CAAC;IAC7D;;IACA,MAAM,IAAIpC,qBAAqB,CAC7BoF,OAAO,CAAC7C,IAAI,CAACD,KAAK,EAClB8C,OAAO,CAAC7C,IAAI,CAAC8C,iBACf,CAAC;EACH;EACA,OAAOF,aAAa,CAAC5C,IAAI;AAC3B,CAAC"}
@@ -1,46 +1,35 @@
1
1
  import * as z from "zod";
2
- import { decodeBase64 } from "@pagopa/io-react-native-jwt";
3
- import { AuthRequestDecodeError } from "./errors";
4
- const QRCodePayload = z.object({
5
- protocol: z.string(),
6
- resource: z.string(),
7
- // TODO: refine to known paths using literals
8
- clientId: z.string(),
9
- requestURI: z.string()
2
+ import { InvalidQRCodeError } from "./errors";
3
+ const PresentationParams = z.object({
4
+ clientId: z.string().nonempty(),
5
+ requestUri: z.string().url(),
6
+ requestUriMethod: z.enum(["get", "post"]),
7
+ state: z.string().optional()
10
8
  });
11
9
 
12
10
  /**
13
11
  * The beginning of the presentation flow.
14
12
  * To be implemented accordind to the user touchpoint
15
13
  *
16
- * @param Optional parameters, depending on the starting touchoint
14
+ * @param params Presentation parameters, depending on the starting touchoint
17
15
  * @returns The url for the Relying Party to connect with
18
16
  */
19
17
 
20
18
  /**
21
19
  * Start a presentation flow by decoding an incoming QR-code
22
20
  *
23
- * @param qrcode The encoded QR-code content
21
+ * @param params The encoded QR-code content
24
22
  * @returns The url for the Relying Party to connect with
25
23
  * @throws If the provided qr code fails to be decoded
26
24
  */
27
- export const startFlowFromQR = qrcode => {
28
- const decoded = decodeBase64(qrcode);
29
- const decodedUrl = new URL(decoded);
30
- const protocol = decodedUrl.protocol;
31
- const resource = decodedUrl.hostname;
32
- const requestURI = decodedUrl.searchParams.get("request_uri");
33
- const clientId = decodedUrl.searchParams.get("client_id");
34
- const result = QRCodePayload.safeParse({
35
- protocol,
36
- resource,
37
- requestURI,
38
- clientId
25
+ export const startFlowFromQR = params => {
26
+ const result = PresentationParams.safeParse({
27
+ ...params,
28
+ requestUriMethod: params.requestUriMethod ?? "get"
39
29
  });
40
30
  if (result.success) {
41
31
  return result.data;
42
- } else {
43
- throw new AuthRequestDecodeError(result.error.message, `${decodedUrl}`);
44
32
  }
33
+ throw new InvalidQRCodeError(result.error.message);
45
34
  };
46
35
  //# sourceMappingURL=01-start-flow.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["z","decodeBase64","AuthRequestDecodeError","QRCodePayload","object","protocol","string","resource","clientId","requestURI","startFlowFromQR","qrcode","decoded","decodedUrl","URL","hostname","searchParams","get","result","safeParse","success","data","error","message"],"sourceRoot":"../../../../src","sources":["credential/presentation/01-start-flow.ts"],"mappings":"AAAA,OAAO,KAAKA,CAAC,MAAM,KAAK;AACxB,SAASC,YAAY,QAAQ,6BAA6B;AAC1D,SAASC,sBAAsB,QAAQ,UAAU;AAEjD,MAAMC,aAAa,GAAGH,CAAC,CAACI,MAAM,CAAC;EAC7BC,QAAQ,EAAEL,CAAC,CAACM,MAAM,CAAC,CAAC;EACpBC,QAAQ,EAAEP,CAAC,CAACM,MAAM,CAAC,CAAC;EAAE;EACtBE,QAAQ,EAAER,CAAC,CAACM,MAAM,CAAC,CAAC;EACpBG,UAAU,EAAET,CAAC,CAACM,MAAM,CAAC;AACvB,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMI,eAAoC,GAAIC,MAAM,IAAK;EAC9D,MAAMC,OAAO,GAAGX,YAAY,CAACU,MAAM,CAAC;EACpC,MAAME,UAAU,GAAG,IAAIC,GAAG,CAACF,OAAO,CAAC;EACnC,MAAMP,QAAQ,GAAGQ,UAAU,CAACR,QAAQ;EACpC,MAAME,QAAQ,GAAGM,UAAU,CAACE,QAAQ;EACpC,MAAMN,UAAU,GAAGI,UAAU,CAACG,YAAY,CAACC,GAAG,CAAC,aAAa,CAAC;EAC7D,MAAMT,QAAQ,GAAGK,UAAU,CAACG,YAAY,CAACC,GAAG,CAAC,WAAW,CAAC;EAEzD,MAAMC,MAAM,GAAGf,aAAa,CAACgB,SAAS,CAAC;IACrCd,QAAQ;IACRE,QAAQ;IACRE,UAAU;IACVD;EACF,CAAC,CAAC;EAEF,IAAIU,MAAM,CAACE,OAAO,EAAE;IAClB,OAAOF,MAAM,CAACG,IAAI;EACpB,CAAC,MAAM;IACL,MAAM,IAAInB,sBAAsB,CAACgB,MAAM,CAACI,KAAK,CAACC,OAAO,EAAG,GAAEV,UAAW,EAAC,CAAC;EACzE;AACF,CAAC"}
1
+ {"version":3,"names":["z","InvalidQRCodeError","PresentationParams","object","clientId","string","nonempty","requestUri","url","requestUriMethod","enum","state","optional","startFlowFromQR","params","result","safeParse","success","data","error","message"],"sourceRoot":"../../../../src","sources":["credential/presentation/01-start-flow.ts"],"mappings":"AAAA,OAAO,KAAKA,CAAC,MAAM,KAAK;AACxB,SAASC,kBAAkB,QAAQ,UAAU;AAE7C,MAAMC,kBAAkB,GAAGF,CAAC,CAACG,MAAM,CAAC;EAClCC,QAAQ,EAAEJ,CAAC,CAACK,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;EAC/BC,UAAU,EAAEP,CAAC,CAACK,MAAM,CAAC,CAAC,CAACG,GAAG,CAAC,CAAC;EAC5BC,gBAAgB,EAAET,CAAC,CAACU,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;EACzCC,KAAK,EAAEX,CAAC,CAACK,MAAM,CAAC,CAAC,CAACO,QAAQ,CAAC;AAC7B,CAAC,CAAC;;AAGF;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,eAA0B,GAAIC,MAAM,IAAK;EACpD,MAAMC,MAAM,GAAGb,kBAAkB,CAACc,SAAS,CAAC;IAC1C,GAAGF,MAAM;IACTL,gBAAgB,EAAEK,MAAM,CAACL,gBAAgB,IAAI;EAC/C,CAAC,CAAC;EAEF,IAAIM,MAAM,CAACE,OAAO,EAAE;IAClB,OAAOF,MAAM,CAACG,IAAI;EACpB;EAEA,MAAM,IAAIjB,kBAAkB,CAACc,MAAM,CAACI,KAAK,CAACC,OAAO,CAAC;AACpD,CAAC"}
@@ -13,13 +13,15 @@ export const evaluateRelyingPartyTrust = async function (rpUrl) {
13
13
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
14
14
  const {
15
15
  payload: {
16
- metadata: rpConf
16
+ metadata: rpConf,
17
+ sub
17
18
  }
18
19
  } = await getRelyingPartyEntityConfiguration(rpUrl, {
19
20
  appFetch
20
21
  });
21
22
  return {
22
- rpConf
23
+ rpConf,
24
+ subject: sub
23
25
  };
24
26
  };
25
27
  //# sourceMappingURL=02-evaluate-rp-trust.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["getRelyingPartyEntityConfiguration","evaluateRelyingPartyTrust","rpUrl","appFetch","fetch","arguments","length","undefined","payload","metadata","rpConf"],"sourceRoot":"../../../../src","sources":["credential/presentation/02-evaluate-rp-trust.ts"],"mappings":"AAAA,SAASA,kCAAkC,QAAQ,aAAa;AAchE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,yBAAoD,GAAG,eAAAA,CAClEC,KAAK,EAEF;EAAA,IADH;IAAEC,QAAQ,GAAGC;EAAM,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAEzB,MAAM;IACJG,OAAO,EAAE;MAAEC,QAAQ,EAAEC;IAAO;EAC9B,CAAC,GAAG,MAAMV,kCAAkC,CAACE,KAAK,EAAE;IAClDC;EACF,CAAC,CAAC;EACF,OAAO;IAAEO;EAAO,CAAC;AACnB,CAAC"}
1
+ {"version":3,"names":["getRelyingPartyEntityConfiguration","evaluateRelyingPartyTrust","rpUrl","appFetch","fetch","arguments","length","undefined","payload","metadata","rpConf","sub","subject"],"sourceRoot":"../../../../src","sources":["credential/presentation/02-evaluate-rp-trust.ts"],"mappings":"AAAA,SAASA,kCAAkC,QAAQ,aAAa;AAehE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,yBAAoD,GAAG,eAAAA,CAClEC,KAAK,EAEF;EAAA,IADH;IAAEC,QAAQ,GAAGC;EAAM,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAEzB,MAAM;IACJG,OAAO,EAAE;MAAEC,QAAQ,EAAEC,MAAM;MAAEC;IAAI;EACnC,CAAC,GAAG,MAAMX,kCAAkC,CAACE,KAAK,EAAE;IAClDC;EACF,CAAC,CAAC;EACF,OAAO;IAAEO,MAAM;IAAEE,OAAO,EAAED;EAAI,CAAC;AACjC,CAAC"}
@@ -1,60 +1,48 @@
1
- import { v4 as uuidv4 } from "uuid";
2
- import { decode as decodeJwt, sha256ToBase64, verify } from "@pagopa/io-react-native-jwt";
3
- import { createDPopToken } from "../../utils/dpop";
4
- import { NoSuitableKeysFoundInEntityConfiguration } from "./errors";
5
1
  import { hasStatusOrThrow } from "../../utils/misc";
6
- import { RequestObject } from "./types";
2
+ import { RequestObjectWalletCapabilities } from "./types";
7
3
  /**
8
- * Obtain the Request Object for RP authentication
4
+ * Obtain the Request Object for RP authentication. Both the GET and POST `request_uri_method` are supported.
9
5
  * @see https://italia.github.io/eudi-wallet-it-docs/versione-corrente/en/relying-party-solution.html
10
6
  *
11
7
  * @param requestUri The url for the Relying Party to connect with
12
- * @param rpConf The Relying Party's configuration
13
- * @param context.wiaCryptoContext The context to access the key associated with the Wallet Instance Attestation
14
- * @param context.walletInstanceAttestation The Wallet Instance Attestation token
8
+ * @param rpConf The Relying Party's configuration * @param context.walletInstanceAttestation The Wallet Instance Attestation token
9
+ * @param context.walletCapabilities (optional) An object containing the wallet technical capabilities that will be sent with a POST request
15
10
  * @param context.appFetch (optional) fetch api implementation. Default: built-in fetch
16
11
  * @returns The Request Object that describes the presentation
17
12
  */
18
- export const getRequestObject = async (requestUri, rpConf, _ref) => {
13
+ export const getRequestObject = async function (requestUri) {
19
14
  let {
20
- wiaCryptoContext,
21
15
  appFetch = fetch,
22
- walletInstanceAttestation
23
- } = _ref;
24
- const signedWalletInstanceDPoP = await createDPopToken({
25
- jti: `${uuidv4()}`,
26
- htm: "GET",
27
- htu: requestUri,
28
- ath: await sha256ToBase64(walletInstanceAttestation)
29
- }, wiaCryptoContext);
30
- const responseEncodedJwt = await appFetch(requestUri, {
31
- method: "GET",
32
- headers: {
33
- Authorization: `DPoP ${walletInstanceAttestation}`,
34
- DPoP: signedWalletInstanceDPoP
35
- }
36
- }).then(hasStatusOrThrow(200)).then(res => res.json()).then(responseJson => responseJson.response);
37
- const responseJwt = decodeJwt(responseEncodedJwt);
38
-
39
- // verify token signature according to RP's entity configuration
40
- // to ensure the request object is authentic
41
- {
42
- const pubKey = rpConf.wallet_relying_party.jwks.keys.find(_ref2 => {
43
- let {
44
- kid
45
- } = _ref2;
46
- return kid === responseJwt.protectedHeader.kid;
16
+ walletCapabilities
17
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
18
+ if (walletCapabilities) {
19
+ // Validate external input
20
+ const {
21
+ wallet_metadata,
22
+ wallet_nonce
23
+ } = RequestObjectWalletCapabilities.parse(walletCapabilities);
24
+ const formUrlEncodedBody = new URLSearchParams({
25
+ wallet_metadata: JSON.stringify(wallet_metadata),
26
+ ...(wallet_nonce && {
27
+ wallet_nonce
28
+ })
47
29
  });
48
- if (!pubKey) {
49
- throw new NoSuitableKeysFoundInEntityConfiguration("Request Object signature verification");
50
- }
51
- await verify(responseEncodedJwt, pubKey);
30
+ const requestObjectEncodedJwt = await appFetch(requestUri, {
31
+ method: "POST",
32
+ headers: {
33
+ "Content-Type": "application/x-www-form-urlencoded"
34
+ },
35
+ body: formUrlEncodedBody.toString()
36
+ }).then(hasStatusOrThrow(200)).then(res => res.text());
37
+ return {
38
+ requestObjectEncodedJwt
39
+ };
52
40
  }
53
-
54
- // Ensure that the request object conforms to the expected specification.
55
- const requestObject = RequestObject.parse(responseJwt.payload);
41
+ const requestObjectEncodedJwt = await appFetch(requestUri, {
42
+ method: "GET"
43
+ }).then(hasStatusOrThrow(200)).then(res => res.text());
56
44
  return {
57
- requestObject
45
+ requestObjectEncodedJwt
58
46
  };
59
47
  };
60
48
  //# sourceMappingURL=03-get-request-object.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["v4","uuidv4","decode","decodeJwt","sha256ToBase64","verify","createDPopToken","NoSuitableKeysFoundInEntityConfiguration","hasStatusOrThrow","RequestObject","getRequestObject","requestUri","rpConf","_ref","wiaCryptoContext","appFetch","fetch","walletInstanceAttestation","signedWalletInstanceDPoP","jti","htm","htu","ath","responseEncodedJwt","method","headers","Authorization","DPoP","then","res","json","responseJson","response","responseJwt","pubKey","wallet_relying_party","jwks","keys","find","_ref2","kid","protectedHeader","requestObject","parse","payload"],"sourceRoot":"../../../../src","sources":["credential/presentation/03-get-request-object.ts"],"mappings":"AAAA,SAASA,EAAE,IAAIC,MAAM,QAAQ,MAAM;AACnC,SACEC,MAAM,IAAIC,SAAS,EACnBC,cAAc,EACdC,MAAM,QAED,6BAA6B;AAEpC,SAASC,eAAe,QAAQ,kBAAkB;AAClD,SAASC,wCAAwC,QAAQ,UAAU;AAEnE,SAASC,gBAAgB,QAAkB,kBAAkB;AAE7D,SAASC,aAAa,QAAQ,SAAS;AAYvC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,gBAAkC,GAAG,MAAAA,CAChDC,UAAU,EACVC,MAAM,EAAAC,IAAA,KAEH;EAAA,IADH;IAAEC,gBAAgB;IAAEC,QAAQ,GAAGC,KAAK;IAAEC;EAA0B,CAAC,GAAAJ,IAAA;EAEjE,MAAMK,wBAAwB,GAAG,MAAMZ,eAAe,CACpD;IACEa,GAAG,EAAG,GAAElB,MAAM,CAAC,CAAE,EAAC;IAClBmB,GAAG,EAAE,KAAK;IACVC,GAAG,EAAEV,UAAU;IACfW,GAAG,EAAE,MAAMlB,cAAc,CAACa,yBAAyB;EACrD,CAAC,EACDH,gBACF,CAAC;EAED,MAAMS,kBAAkB,GAAG,MAAMR,QAAQ,CAACJ,UAAU,EAAE;IACpDa,MAAM,EAAE,KAAK;IACbC,OAAO,EAAE;MACPC,aAAa,EAAG,QAAOT,yBAA0B,EAAC;MAClDU,IAAI,EAAET;IACR;EACF,CAAC,CAAC,CACCU,IAAI,CAACpB,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAC3BoB,IAAI,CAAEC,GAAG,IAAKA,GAAG,CAACC,IAAI,CAAC,CAAC,CAAC,CACzBF,IAAI,CAAEG,YAAY,IAAKA,YAAY,CAACC,QAAQ,CAAC;EAEhD,MAAMC,WAAW,GAAG9B,SAAS,CAACoB,kBAAkB,CAAC;;EAEjD;EACA;EACA;IACE,MAAMW,MAAM,GAAGtB,MAAM,CAACuB,oBAAoB,CAACC,IAAI,CAACC,IAAI,CAACC,IAAI,CACvDC,KAAA;MAAA,IAAC;QAAEC;MAAI,CAAC,GAAAD,KAAA;MAAA,OAAKC,GAAG,KAAKP,WAAW,CAACQ,eAAe,CAACD,GAAG;IAAA,CACtD,CAAC;IACD,IAAI,CAACN,MAAM,EAAE;MACX,MAAM,IAAI3B,wCAAwC,CAChD,uCACF,CAAC;IACH;IACA,MAAMF,MAAM,CAACkB,kBAAkB,EAAEW,MAAM,CAAC;EAC1C;;EAEA;EACA,MAAMQ,aAAa,GAAGjC,aAAa,CAACkC,KAAK,CAACV,WAAW,CAACW,OAAO,CAAC;EAE9D,OAAO;IACLF;EACF,CAAC;AACH,CAAC"}
1
+ {"version":3,"names":["hasStatusOrThrow","RequestObjectWalletCapabilities","getRequestObject","requestUri","appFetch","fetch","walletCapabilities","arguments","length","undefined","wallet_metadata","wallet_nonce","parse","formUrlEncodedBody","URLSearchParams","JSON","stringify","requestObjectEncodedJwt","method","headers","body","toString","then","res","text"],"sourceRoot":"../../../../src","sources":["credential/presentation/03-get-request-object.ts"],"mappings":"AAAA,SAASA,gBAAgB,QAAkB,kBAAkB;AAE7D,SAASC,+BAA+B,QAAQ,SAAS;AAUzD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,gBAAkC,GAAG,eAAAA,CAChDC,UAAU,EAEP;EAAA,IADH;IAAEC,QAAQ,GAAGC,KAAK;IAAEC;EAAmB,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAE7C,IAAID,kBAAkB,EAAE;IACtB;IACA,MAAM;MAAEI,eAAe;MAAEC;IAAa,CAAC,GACrCV,+BAA+B,CAACW,KAAK,CAACN,kBAAkB,CAAC;IAE3D,MAAMO,kBAAkB,GAAG,IAAIC,eAAe,CAAC;MAC7CJ,eAAe,EAAEK,IAAI,CAACC,SAAS,CAACN,eAAe,CAAC;MAChD,IAAIC,YAAY,IAAI;QAAEA;MAAa,CAAC;IACtC,CAAC,CAAC;IAEF,MAAMM,uBAAuB,GAAG,MAAMb,QAAQ,CAACD,UAAU,EAAE;MACzDe,MAAM,EAAE,MAAM;MACdC,OAAO,EAAE;QACP,cAAc,EAAE;MAClB,CAAC;MACDC,IAAI,EAAEP,kBAAkB,CAACQ,QAAQ,CAAC;IACpC,CAAC,CAAC,CACCC,IAAI,CAACtB,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAC3BsB,IAAI,CAAEC,GAAG,IAAKA,GAAG,CAACC,IAAI,CAAC,CAAC,CAAC;IAE5B,OAAO;MACLP;IACF,CAAC;EACH;EAEA,MAAMA,uBAAuB,GAAG,MAAMb,QAAQ,CAACD,UAAU,EAAE;IACzDe,MAAM,EAAE;EACV,CAAC,CAAC,CACCI,IAAI,CAACtB,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAC3BsB,IAAI,CAAEC,GAAG,IAAKA,GAAG,CAACC,IAAI,CAAC,CAAC,CAAC;EAE5B,OAAO;IACLP;EACF,CAAC;AACH,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Defines the signature for a function that retrieves JSON Web Key Sets (JWKS) from a client.
3
+ *
4
+ * @template T - The tuple type representing the function arguments.
5
+ * @param args - The arguments passed to the function.
6
+ * @returns A promise resolving to an object containing an array of JWKs.
7
+ */
8
+
9
+ /**
10
+ * Retrieves the JSON Web Key Set (JWKS) from a Relying Party's entity configuration.
11
+ *
12
+ * @param rpConfig - The configuration object of the Relying Party entity.
13
+ * @returns An object containing an array of JWKs.
14
+ * @throws Will throw an error if the configuration is invalid or if JWKS is not found.
15
+ */
16
+ export const getJwksFromConfig = rpConfig => {
17
+ const jwks = rpConfig.openid_credential_verifier.jwks;
18
+ if (!jwks || !Array.isArray(jwks.keys)) {
19
+ throw new Error("JWKS not found in Relying Party configuration.");
20
+ }
21
+ return {
22
+ keys: jwks.keys
23
+ };
24
+ };
25
+ //# sourceMappingURL=04-retrieve-rp-jwks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getJwksFromConfig","rpConfig","jwks","openid_credential_verifier","Array","isArray","keys","Error"],"sourceRoot":"../../../../src","sources":["credential/presentation/04-retrieve-rp-jwks.ts"],"mappings":"AAGA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,iBAEZ,GAAIC,QAAQ,IAAK;EAChB,MAAMC,IAAI,GAAGD,QAAQ,CAACE,0BAA0B,CAACD,IAAI;EAErD,IAAI,CAACA,IAAI,IAAI,CAACE,KAAK,CAACC,OAAO,CAACH,IAAI,CAACI,IAAI,CAAC,EAAE;IACtC,MAAM,IAAIC,KAAK,CAAC,gDAAgD,CAAC;EACnE;EAEA,OAAO;IACLD,IAAI,EAAEJ,IAAI,CAACI;EACb,CAAC;AACH,CAAC"}
@@ -0,0 +1,53 @@
1
+ import { decode as decodeJwt, verify } from "@pagopa/io-react-native-jwt";
2
+ import { UnverifiedEntityError } from "./errors";
3
+ import { RequestObject } from "./types";
4
+ import { getJwksFromConfig } from "./04-retrieve-rp-jwks";
5
+ /**
6
+ * Function to verify the Request Object's signature and the client ID.
7
+ * @param requestObjectEncodedJwt The Request Object in JWT format
8
+ * @param context.clientId The client ID to verify
9
+ * @param context.rpConf The Entity Configuration of the Relying Party
10
+ * @param context.state Optional state
11
+ * @returns The verified Request Object
12
+ */
13
+ export const verifyRequestObject = async (requestObjectEncodedJwt, _ref) => {
14
+ let {
15
+ clientId,
16
+ rpConf,
17
+ rpSubject,
18
+ state
19
+ } = _ref;
20
+ const requestObjectJwt = decodeJwt(requestObjectEncodedJwt);
21
+ const {
22
+ keys
23
+ } = getJwksFromConfig(rpConf);
24
+
25
+ // Verify token signature to ensure the request object is authentic
26
+ const pubKey = keys === null || keys === void 0 ? void 0 : keys.find(_ref2 => {
27
+ let {
28
+ kid
29
+ } = _ref2;
30
+ return kid === requestObjectJwt.protectedHeader.kid;
31
+ });
32
+ if (!pubKey) {
33
+ throw new UnverifiedEntityError("Request Object signature verification!");
34
+ }
35
+
36
+ // Standard claims are verified within `verify`
37
+ await verify(requestObjectEncodedJwt, pubKey, {
38
+ issuer: clientId
39
+ });
40
+ const requestObject = RequestObject.parse(requestObjectJwt.payload);
41
+ const isClientIdMatch = clientId === requestObject.client_id && clientId === rpSubject;
42
+ if (!isClientIdMatch) {
43
+ throw new UnverifiedEntityError("Client ID does not match Request Object or Entity Configuration");
44
+ }
45
+ const isStateMatch = state && requestObject.state ? state === requestObject.state : true;
46
+ if (!isStateMatch) {
47
+ throw new UnverifiedEntityError("State does not match Request Object");
48
+ }
49
+ return {
50
+ requestObject
51
+ };
52
+ };
53
+ //# sourceMappingURL=05-verify-request-object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["decode","decodeJwt","verify","UnverifiedEntityError","RequestObject","getJwksFromConfig","verifyRequestObject","requestObjectEncodedJwt","_ref","clientId","rpConf","rpSubject","state","requestObjectJwt","keys","pubKey","find","_ref2","kid","protectedHeader","issuer","requestObject","parse","payload","isClientIdMatch","client_id","isStateMatch"],"sourceRoot":"../../../../src","sources":["credential/presentation/05-verify-request-object.ts"],"mappings":"AAAA,SAASA,MAAM,IAAIC,SAAS,EAAEC,MAAM,QAAQ,6BAA6B;AAEzE,SAASC,qBAAqB,QAAQ,UAAU;AAChD,SAASC,aAAa,QAAQ,SAAS;AACvC,SAASC,iBAAiB,QAAQ,uBAAuB;AAYzD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,mBAAwC,GAAG,MAAAA,CACtDC,uBAAuB,EAAAC,IAAA,KAEpB;EAAA,IADH;IAAEC,QAAQ;IAAEC,MAAM;IAAEC,SAAS;IAAEC;EAAM,CAAC,GAAAJ,IAAA;EAEtC,MAAMK,gBAAgB,GAAGZ,SAAS,CAACM,uBAAuB,CAAC;EAC3D,MAAM;IAAEO;EAAK,CAAC,GAAGT,iBAAiB,CAACK,MAAM,CAAC;;EAE1C;EACA,MAAMK,MAAM,GAAGD,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEE,IAAI,CACvBC,KAAA;IAAA,IAAC;MAAEC;IAAI,CAAC,GAAAD,KAAA;IAAA,OAAKC,GAAG,KAAKL,gBAAgB,CAACM,eAAe,CAACD,GAAG;EAAA,CAC3D,CAAC;EAED,IAAI,CAACH,MAAM,EAAE;IACX,MAAM,IAAIZ,qBAAqB,CAAC,wCAAwC,CAAC;EAC3E;;EAEA;EACA,MAAMD,MAAM,CAACK,uBAAuB,EAAEQ,MAAM,EAAE;IAAEK,MAAM,EAAEX;EAAS,CAAC,CAAC;EAEnE,MAAMY,aAAa,GAAGjB,aAAa,CAACkB,KAAK,CAACT,gBAAgB,CAACU,OAAO,CAAC;EAEnE,MAAMC,eAAe,GACnBf,QAAQ,KAAKY,aAAa,CAACI,SAAS,IAAIhB,QAAQ,KAAKE,SAAS;EAEhE,IAAI,CAACa,eAAe,EAAE;IACpB,MAAM,IAAIrB,qBAAqB,CAC7B,iEACF,CAAC;EACH;EAEA,MAAMuB,YAAY,GAChBd,KAAK,IAAIS,aAAa,CAACT,KAAK,GAAGA,KAAK,KAAKS,aAAa,CAACT,KAAK,GAAG,IAAI;EAErE,IAAI,CAACc,YAAY,EAAE;IACjB,MAAM,IAAIvB,qBAAqB,CAAC,qCAAqC,CAAC;EACxE;EAEA,OAAO;IAAEkB;EAAc,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Retrieves a PresentationDefinition based on the given parameters.
3
+ *
4
+ * The method attempts the following strategies in order:
5
+ * 1. Checks if `presentation_definition` is directly available in the request object.
6
+ * 2. Uses a pre-configured `presentation_definition` from the relying party configuration if the `scope` is present in the request object.
7
+ *
8
+ * If none of the above conditions are met, the function throws an error indicating the definition could not be found. Note that `presentation_definition_uri` is not supported in 0.9.x.
9
+ *
10
+ * @param {RequestObject} requestObject - The request object containing the presentation definition or references to it.
11
+ * @param {RelyingPartyEntityConfiguration["payload"]["metadata"]} [rpConf] - Optional relying party configuration.
12
+ * @returns {Promise<{ presentationDefinition: PresentationDefinition }>} - Resolves with the presentation definition.
13
+ * @throws {Error} - Throws if the presentation definition cannot be found or fetched.
14
+ */
15
+ export const fetchPresentDefinition = async (requestObject, rpConf) => {
16
+ var _rpConf$openid_creden;
17
+ // Check if `presentation_definition` is directly available in the request object
18
+ if (requestObject.presentation_definition) {
19
+ return {
20
+ presentationDefinition: requestObject.presentation_definition
21
+ };
22
+ }
23
+
24
+ // Check if `scope` is present in the request object and a pre-configured presentation definition exists
25
+ if (requestObject.scope && rpConf !== null && rpConf !== void 0 && (_rpConf$openid_creden = rpConf.openid_credential_verifier) !== null && _rpConf$openid_creden !== void 0 && _rpConf$openid_creden.presentation_definition) {
26
+ return {
27
+ presentationDefinition: rpConf.openid_credential_verifier.presentation_definition
28
+ };
29
+ }
30
+ throw new Error("Presentation definition not found");
31
+ };
32
+ //# sourceMappingURL=06-fetch-presentation-definition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["fetchPresentDefinition","requestObject","rpConf","_rpConf$openid_creden","presentation_definition","presentationDefinition","scope","openid_credential_verifier","Error"],"sourceRoot":"../../../../src","sources":["credential/presentation/06-fetch-presentation-definition.ts"],"mappings":"AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,sBAAmD,GAAG,MAAAA,CACjEC,aAAa,EACbC,MAAM,KACH;EAAA,IAAAC,qBAAA;EACH;EACA,IAAIF,aAAa,CAACG,uBAAuB,EAAE;IACzC,OAAO;MACLC,sBAAsB,EAAEJ,aAAa,CAACG;IACxC,CAAC;EACH;;EAEA;EACA,IACEH,aAAa,CAACK,KAAK,IACnBJ,MAAM,aAANA,MAAM,gBAAAC,qBAAA,GAAND,MAAM,CAAEK,0BAA0B,cAAAJ,qBAAA,eAAlCA,qBAAA,CAAoCC,uBAAuB,EAC3D;IACA,OAAO;MACLC,sBAAsB,EACpBH,MAAM,CAACK,0BAA0B,CAACH;IACtC,CAAC;EACH;EAEA,MAAM,IAAII,KAAK,CAAC,mCAAmC,CAAC;AACtD,CAAC"}
@@ -0,0 +1,127 @@
1
+ import { DcqlQuery, DcqlError, DcqlCredentialSetError } from "dcql";
2
+ import { isValiError } from "valibot";
3
+ import { decode, prepareVpToken } from "../../sd-jwt";
4
+ import { ValidationFailed } from "../../utils/errors";
5
+ import { createCryptoContextFor } from "../../utils/crypto";
6
+
7
+ /**
8
+ * The purpose for the credential request by the RP.
9
+ */
10
+
11
+ /**
12
+ * Convert a credential in JWT format to an object with claims
13
+ * for correct parsing by the `dcql` library.
14
+ */
15
+ const mapCredentialToObject = jwt => {
16
+ const {
17
+ sdJwt,
18
+ disclosures
19
+ } = decode(jwt);
20
+ const credentialFormat = sdJwt.header.typ;
21
+
22
+ // TODO [SIW-2082]: support MDOC credentials
23
+ if (credentialFormat !== "vc+sd-jwt") {
24
+ throw new Error(`Unsupported credential format: ${credentialFormat}`);
25
+ }
26
+ return {
27
+ vct: sdJwt.payload.vct,
28
+ credential_format: credentialFormat,
29
+ claims: disclosures.reduce((acc, disclosure) => ({
30
+ ...acc,
31
+ [disclosure.decoded[1]]: disclosure.decoded
32
+ }), {})
33
+ };
34
+ };
35
+
36
+ /**
37
+ * Extract only successful matches from the DCQL query result.
38
+ */
39
+ const getDcqlQueryMatches = result => Object.entries(result.credential_matches).filter(_ref => {
40
+ let [, match] = _ref;
41
+ return match.success === true;
42
+ });
43
+ export const evaluateDcqlQuery = (credentialsSdJwt, query) => {
44
+ const credentials = credentialsSdJwt.map(_ref2 => {
45
+ let [, credential] = _ref2;
46
+ return mapCredentialToObject(credential);
47
+ });
48
+ try {
49
+ // Validate the query
50
+ const parsedQuery = DcqlQuery.parse(query);
51
+ DcqlQuery.validate(parsedQuery);
52
+ const queryResult = DcqlQuery.query(parsedQuery, credentials);
53
+ if (!queryResult.canBeSatisfied) {
54
+ throw new Error("No credential can satisfy the provided DCQL query");
55
+ }
56
+ // Build an object vct:credentialJwt to map matched credentials to their JWT
57
+ const credentialsSdJwtByVct = credentials.reduce((acc, c, i) => ({
58
+ ...acc,
59
+ [c.vct]: credentialsSdJwt[i]
60
+ }), {});
61
+ return getDcqlQueryMatches(queryResult).map(_ref3 => {
62
+ var _queryResult$credenti;
63
+ let [id, match] = _ref3;
64
+ if (match.output.credential_format !== "vc+sd-jwt") {
65
+ throw new Error("Unsupported format"); // TODO [SIW-2082]: support MDOC credentials
66
+ }
67
+
68
+ const {
69
+ vct,
70
+ claims
71
+ } = match.output;
72
+ const purposes = (_queryResult$credenti = queryResult.credential_sets) === null || _queryResult$credenti === void 0 || (_queryResult$credenti = _queryResult$credenti.filter(set => {
73
+ var _set$matching_options;
74
+ return (_set$matching_options = set.matching_options) === null || _set$matching_options === void 0 ? void 0 : _set$matching_options.flat().includes(id);
75
+ })) === null || _queryResult$credenti === void 0 ? void 0 : _queryResult$credenti.map(credentialSet => {
76
+ var _credentialSet$purpos;
77
+ return {
78
+ description: (_credentialSet$purpos = credentialSet.purpose) === null || _credentialSet$purpos === void 0 ? void 0 : _credentialSet$purpos.toString(),
79
+ required: Boolean(credentialSet.required)
80
+ };
81
+ });
82
+ const [keyTag, credential] = credentialsSdJwtByVct[vct];
83
+ const requiredDisclosures = Object.values(claims);
84
+ return {
85
+ id,
86
+ vct,
87
+ keyTag,
88
+ credential,
89
+ requiredDisclosures,
90
+ // When it is a match but no credential_sets are found, the credential is required by default
91
+ // See https://openid.net/specs/openid-4-verifiable-presentations-1_0-24.html#section-6.3.1.2-2.1
92
+ purposes: purposes ?? [{
93
+ required: true
94
+ }]
95
+ };
96
+ });
97
+ } catch (error) {
98
+ // Invalid DCQL query structure
99
+ if (isValiError(error)) {
100
+ throw new ValidationFailed({
101
+ message: "Invalid DCQL query",
102
+ reason: error.issues.map(issue => issue.message).join(", ")
103
+ });
104
+ }
105
+ if (error instanceof DcqlError) {
106
+ // TODO [SIW-2110]: handle invalid DQCL query or let the error propagate
107
+ }
108
+ if (error instanceof DcqlCredentialSetError) {
109
+ // TODO [SIW-2110]: handle missing credentials or let the error propagate
110
+ }
111
+ throw error;
112
+ }
113
+ };
114
+ export const prepareRemotePresentations = async (credentials, nonce, clientId) => {
115
+ return Promise.all(credentials.map(async item => {
116
+ const {
117
+ vp_token
118
+ } = await prepareVpToken(nonce, clientId, [item.credential, item.requestedClaims, createCryptoContextFor(item.keyTag)]);
119
+ return {
120
+ credentialId: item.id,
121
+ requestedClaims: item.requestedClaims,
122
+ vpToken: vp_token,
123
+ format: "vc+sd-jwt"
124
+ };
125
+ }));
126
+ };
127
+ //# sourceMappingURL=07-evaluate-dcql-query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DcqlQuery","DcqlError","DcqlCredentialSetError","isValiError","decode","prepareVpToken","ValidationFailed","createCryptoContextFor","mapCredentialToObject","jwt","sdJwt","disclosures","credentialFormat","header","typ","Error","vct","payload","credential_format","claims","reduce","acc","disclosure","decoded","getDcqlQueryMatches","result","Object","entries","credential_matches","filter","_ref","match","success","evaluateDcqlQuery","credentialsSdJwt","query","credentials","map","_ref2","credential","parsedQuery","parse","validate","queryResult","canBeSatisfied","credentialsSdJwtByVct","c","i","_ref3","_queryResult$credenti","id","output","purposes","credential_sets","set","_set$matching_options","matching_options","flat","includes","credentialSet","_credentialSet$purpos","description","purpose","toString","required","Boolean","keyTag","requiredDisclosures","values","error","message","reason","issues","issue","join","prepareRemotePresentations","nonce","clientId","Promise","all","item","vp_token","requestedClaims","credentialId","vpToken","format"],"sourceRoot":"../../../../src","sources":["credential/presentation/07-evaluate-dcql-query.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