@pagopa/io-react-native-wallet 0.28.0 → 0.28.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 (132) 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/presentation/01-start-flow.js +14 -24
  4. package/lib/commonjs/credential/presentation/01-start-flow.js.map +1 -1
  5. package/lib/commonjs/credential/presentation/03-get-request-object.js +30 -42
  6. package/lib/commonjs/credential/presentation/03-get-request-object.js.map +1 -1
  7. package/lib/commonjs/credential/presentation/04-retrieve-rp-jwks.js +32 -0
  8. package/lib/commonjs/credential/presentation/04-retrieve-rp-jwks.js.map +1 -0
  9. package/lib/commonjs/credential/presentation/05-verify-request-object.js +53 -0
  10. package/lib/commonjs/credential/presentation/05-verify-request-object.js.map +1 -0
  11. package/lib/commonjs/credential/presentation/06-fetch-presentation-definition.js +39 -0
  12. package/lib/commonjs/credential/presentation/06-fetch-presentation-definition.js.map +1 -0
  13. package/lib/commonjs/credential/presentation/07-evaluate-dcql-query.js +125 -0
  14. package/lib/commonjs/credential/presentation/07-evaluate-dcql-query.js.map +1 -0
  15. package/lib/commonjs/credential/presentation/07-evaluate-input-descriptor.js +289 -0
  16. package/lib/commonjs/credential/presentation/07-evaluate-input-descriptor.js.map +1 -0
  17. package/lib/commonjs/credential/presentation/08-send-authorization-response.js +170 -0
  18. package/lib/commonjs/credential/presentation/08-send-authorization-response.js.map +1 -0
  19. package/lib/commonjs/credential/presentation/errors.js +69 -1
  20. package/lib/commonjs/credential/presentation/errors.js.map +1 -1
  21. package/lib/commonjs/credential/presentation/index.js +29 -1
  22. package/lib/commonjs/credential/presentation/index.js.map +1 -1
  23. package/lib/commonjs/credential/presentation/types.js +124 -3
  24. package/lib/commonjs/credential/presentation/types.js.map +1 -1
  25. package/lib/commonjs/sd-jwt/index.js +41 -1
  26. package/lib/commonjs/sd-jwt/index.js.map +1 -1
  27. package/lib/commonjs/trust/chain.js.map +1 -1
  28. package/lib/commonjs/trust/types.js +26 -6
  29. package/lib/commonjs/trust/types.js.map +1 -1
  30. package/lib/commonjs/trust/utils.js +5 -0
  31. package/lib/commonjs/trust/utils.js.map +1 -1
  32. package/lib/commonjs/utils/jwk.js +5 -1
  33. package/lib/commonjs/utils/jwk.js.map +1 -1
  34. package/lib/module/credential/issuance/03-start-user-authorization.js +3 -0
  35. package/lib/module/credential/issuance/03-start-user-authorization.js.map +1 -1
  36. package/lib/module/credential/presentation/01-start-flow.js +14 -24
  37. package/lib/module/credential/presentation/01-start-flow.js.map +1 -1
  38. package/lib/module/credential/presentation/03-get-request-object.js +31 -43
  39. package/lib/module/credential/presentation/03-get-request-object.js.map +1 -1
  40. package/lib/module/credential/presentation/04-retrieve-rp-jwks.js +25 -0
  41. package/lib/module/credential/presentation/04-retrieve-rp-jwks.js.map +1 -0
  42. package/lib/module/credential/presentation/05-verify-request-object.js +46 -0
  43. package/lib/module/credential/presentation/05-verify-request-object.js.map +1 -0
  44. package/lib/module/credential/presentation/06-fetch-presentation-definition.js +32 -0
  45. package/lib/module/credential/presentation/06-fetch-presentation-definition.js.map +1 -0
  46. package/lib/module/credential/presentation/07-evaluate-dcql-query.js +117 -0
  47. package/lib/module/credential/presentation/07-evaluate-dcql-query.js.map +1 -0
  48. package/lib/module/credential/presentation/07-evaluate-input-descriptor.js +278 -0
  49. package/lib/module/credential/presentation/07-evaluate-input-descriptor.js.map +1 -0
  50. package/lib/module/credential/presentation/08-send-authorization-response.js +158 -0
  51. package/lib/module/credential/presentation/08-send-authorization-response.js.map +1 -0
  52. package/lib/module/credential/presentation/errors.js +64 -0
  53. package/lib/module/credential/presentation/errors.js.map +1 -1
  54. package/lib/module/credential/presentation/index.js +6 -2
  55. package/lib/module/credential/presentation/index.js.map +1 -1
  56. package/lib/module/credential/presentation/types.js +121 -2
  57. package/lib/module/credential/presentation/types.js.map +1 -1
  58. package/lib/module/sd-jwt/index.js +40 -1
  59. package/lib/module/sd-jwt/index.js.map +1 -1
  60. package/lib/module/trust/chain.js.map +1 -1
  61. package/lib/module/trust/types.js +26 -6
  62. package/lib/module/trust/types.js.map +1 -1
  63. package/lib/module/trust/utils.js +5 -0
  64. package/lib/module/trust/utils.js.map +1 -1
  65. package/lib/module/utils/jwk.js +3 -0
  66. package/lib/module/utils/jwk.js.map +1 -1
  67. package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts.map +1 -1
  68. package/lib/typescript/credential/presentation/01-start-flow.d.ts +26 -5
  69. package/lib/typescript/credential/presentation/01-start-flow.d.ts.map +1 -1
  70. package/lib/typescript/credential/presentation/03-get-request-object.d.ts +7 -10
  71. package/lib/typescript/credential/presentation/03-get-request-object.d.ts.map +1 -1
  72. package/lib/typescript/credential/presentation/04-retrieve-rp-jwks.d.ts +23 -0
  73. package/lib/typescript/credential/presentation/04-retrieve-rp-jwks.d.ts.map +1 -0
  74. package/lib/typescript/credential/presentation/05-verify-request-object.d.ts +18 -0
  75. package/lib/typescript/credential/presentation/05-verify-request-object.d.ts.map +1 -0
  76. package/lib/typescript/credential/presentation/06-fetch-presentation-definition.d.ts +21 -0
  77. package/lib/typescript/credential/presentation/06-fetch-presentation-definition.d.ts.map +1 -0
  78. package/lib/typescript/credential/presentation/07-evaluate-dcql-query.d.ts +20 -0
  79. package/lib/typescript/credential/presentation/07-evaluate-dcql-query.d.ts.map +1 -0
  80. package/lib/typescript/credential/presentation/07-evaluate-input-descriptor.d.ts +88 -0
  81. package/lib/typescript/credential/presentation/07-evaluate-input-descriptor.d.ts.map +1 -0
  82. package/lib/typescript/credential/presentation/08-send-authorization-response.d.ts +70 -0
  83. package/lib/typescript/credential/presentation/08-send-authorization-response.d.ts.map +1 -0
  84. package/lib/typescript/credential/presentation/errors.d.ts +44 -0
  85. package/lib/typescript/credential/presentation/errors.d.ts.map +1 -1
  86. package/lib/typescript/credential/presentation/index.d.ts +7 -3
  87. package/lib/typescript/credential/presentation/index.d.ts.map +1 -1
  88. package/lib/typescript/credential/presentation/types.d.ts +747 -10
  89. package/lib/typescript/credential/presentation/types.d.ts.map +1 -1
  90. package/lib/typescript/sd-jwt/index.d.ts +19 -0
  91. package/lib/typescript/sd-jwt/index.d.ts.map +1 -1
  92. package/lib/typescript/trust/index.d.ts +236 -8
  93. package/lib/typescript/trust/index.d.ts.map +1 -1
  94. package/lib/typescript/trust/types.d.ts +3046 -76
  95. package/lib/typescript/trust/types.d.ts.map +1 -1
  96. package/lib/typescript/trust/utils.d.ts +6 -6
  97. package/lib/typescript/trust/utils.d.ts.map +1 -1
  98. package/lib/typescript/utils/decoder.d.ts +1 -1
  99. package/lib/typescript/utils/decoder.d.ts.map +1 -1
  100. package/lib/typescript/utils/errors.d.ts.map +1 -1
  101. package/lib/typescript/utils/jwk.d.ts +137 -0
  102. package/lib/typescript/utils/jwk.d.ts.map +1 -1
  103. package/lib/typescript/utils/misc.d.ts.map +1 -1
  104. package/lib/typescript/wallet-instance-attestation/types.d.ts +16 -16
  105. package/package.json +15 -11
  106. package/src/credential/issuance/03-start-user-authorization.ts +3 -0
  107. package/src/credential/presentation/01-start-flow.ts +19 -26
  108. package/src/credential/presentation/03-get-request-object.ts +35 -58
  109. package/src/credential/presentation/04-retrieve-rp-jwks.ts +34 -0
  110. package/src/credential/presentation/05-verify-request-object.ts +52 -0
  111. package/src/credential/presentation/06-fetch-presentation-definition.ts +48 -0
  112. package/src/credential/presentation/07-evaluate-dcql-query.ts +166 -0
  113. package/src/credential/presentation/07-evaluate-input-descriptor.ts +391 -0
  114. package/src/credential/presentation/08-send-authorization-response.ts +220 -0
  115. package/src/credential/presentation/errors.ts +64 -0
  116. package/src/credential/presentation/index.ts +22 -1
  117. package/src/credential/presentation/types.ts +134 -3
  118. package/src/sd-jwt/index.ts +49 -1
  119. package/src/trust/chain.ts +2 -2
  120. package/src/trust/types.ts +25 -5
  121. package/src/trust/utils.ts +6 -3
  122. package/src/utils/decoder.ts +1 -1
  123. package/src/utils/errors.ts +2 -2
  124. package/src/utils/jwk.ts +8 -1
  125. package/src/utils/misc.ts +2 -2
  126. package/lib/commonjs/credential/presentation/04-send-authorization-response.js +0 -138
  127. package/lib/commonjs/credential/presentation/04-send-authorization-response.js.map +0 -1
  128. package/lib/module/credential/presentation/04-send-authorization-response.js +0 -128
  129. package/lib/module/credential/presentation/04-send-authorization-response.js.map +0 -1
  130. package/lib/typescript/credential/presentation/04-send-authorization-response.d.ts +0 -34
  131. package/lib/typescript/credential/presentation/04-send-authorization-response.d.ts.map +0 -1
  132. package/src/credential/presentation/04-send-authorization-response.ts +0 -168
package/src/utils/misc.ts CHANGED
@@ -37,8 +37,8 @@ export const parseRawHttpResponse = <T extends Record<string, unknown>>(
37
37
  export type Out<FN> = FN extends (...args: any[]) => Promise<any>
38
38
  ? Awaited<ReturnType<FN>>
39
39
  : FN extends (...args: any[]) => any
40
- ? ReturnType<FN>
41
- : never;
40
+ ? ReturnType<FN>
41
+ : never;
42
42
 
43
43
  /**
44
44
  * TODO [SIW-1310]: replace this function with a cryptographically secure one.
@@ -1,138 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.sendAuthorizationResponse = exports.AuthorizationResponse = void 0;
7
- var _ioReactNativeJwt = require("@pagopa/io-react-native-jwt");
8
- var _uuid = require("uuid");
9
- var WalletInstanceAttestation = _interopRequireWildcard(require("../../wallet-instance-attestation"));
10
- var _errors = require("./errors");
11
- var _misc = require("../../utils/misc");
12
- var _sdJwt = require("../../sd-jwt");
13
- var z = _interopRequireWildcard(require("zod"));
14
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
16
- const AuthorizationResponse = z.object({
17
- status: z.string(),
18
- response_code: z.string() /**
19
- FIXME: [SIW-627] we expect this value from every RP implementation
20
- Actually some RP does not return the value
21
- We make it optional to not break the flow.
22
- */.optional()
23
- });
24
-
25
- /**
26
- * Choose an RSA public key from those offered by the RP for encryption.
27
- *
28
- * @param entity The RP entity configuration
29
- * @returns A suitable public key with its compatible encryption algorithm
30
- * @throws {NoSuitableKeysFoundInEntityConfiguration} If entity do not contain any public key suitable for encrypting
31
- */
32
- exports.AuthorizationResponse = AuthorizationResponse;
33
- const chooseRSAPublicKeyToEncrypt = entity => {
34
- const [usingRsa256] = entity.wallet_relying_party.jwks.keys.filter(jwk => jwk.use === "enc" && jwk.kty === "RSA");
35
- if (usingRsa256) {
36
- return usingRsa256;
37
- }
38
-
39
- // No suitable key has been found
40
- throw new _errors.NoSuitableKeysFoundInEntityConfiguration("Encrypt with RP public key");
41
- };
42
-
43
- /**
44
- * Generate a Verified Presentation token for a received request object within the context of an authorization request flow.
45
- * The presentation is created by revealing data from the provided credentials based on the requested claims.
46
- * Each Verified Credential is accompanied by the claims that the user consents to disclose from it.
47
- *
48
- * @todo: Allow for handling more than one Verified Credential.
49
- */
50
- const prepareVpToken = async (requestObject, walletInstanceAttestation, _ref) => {
51
- let [vc, claims, cryptoCtx] = _ref;
52
- // this throws if vc cannot satisfy all the requested claims
53
- const {
54
- token: vp,
55
- paths
56
- } = await (0, _sdJwt.disclose)(vc, claims);
57
-
58
- // obtain issuer from Wallet Instance
59
- const {
60
- payload: {
61
- iss
62
- }
63
- } = WalletInstanceAttestation.decode(walletInstanceAttestation);
64
- const pidKid = await cryptoCtx.getPublicKey().then(_ => _.kid);
65
-
66
- // TODO: [SIW-359] check all requeste claims of the requestedObj are satisfied
67
- const vp_token = await new _ioReactNativeJwt.SignJWT(cryptoCtx).setProtectedHeader({
68
- typ: "JWT",
69
- kid: pidKid
70
- }).setPayload({
71
- vp: vp,
72
- jti: `${(0, _uuid.v4)()}`,
73
- iss,
74
- nonce: requestObject.nonce
75
- }).setAudience(requestObject.response_uri).setIssuedAt().setExpirationTime("1h").sign();
76
- const vc_scope = requestObject.scope;
77
- const presentation_submission = {
78
- definition_id: `${(0, _uuid.v4)()}`,
79
- id: `${(0, _uuid.v4)()}`,
80
- descriptor_map: paths.map(p => ({
81
- id: vc_scope,
82
- path: `$.vp_token.${p.path}`,
83
- format: "vc+sd-jwt"
84
- }))
85
- };
86
- return {
87
- vp_token,
88
- presentation_submission
89
- };
90
- };
91
- /**
92
- * Complete the presentation flow by sending the authorization response to the Relying Party
93
- *
94
- * @param requestObject The Request Object that describes the presentation
95
- * @param rpConf The Relying Party's configuration
96
- * @param presentation The presentation tuple consisting in the signed credential,
97
- * the list of claims to be disclosed, and the context to access the key that proves the holder binding
98
- * @param context.walletInstanceAttestation The Wallet Instance Attestation token
99
- * @param context.appFetch (optional) fetch api implementation. Default: built-in fetch
100
- * @returns The result of the presentation flow
101
- */
102
- const sendAuthorizationResponse = async (requestObject, rpConf, presentation, _ref2) => {
103
- let {
104
- appFetch = fetch,
105
- walletInstanceAttestation
106
- } = _ref2;
107
- // the request is an unsigned jws without iss, aud, exp
108
- // https://openid.net/specs/openid-4-verifiable-presentations-1_0.html#name-signed-and-encrypted-respon
109
- const rsaPublicJwk = chooseRSAPublicKeyToEncrypt(rpConf);
110
- const {
111
- vp_token,
112
- presentation_submission
113
- } = await prepareVpToken(requestObject, walletInstanceAttestation, presentation);
114
- const authzResponsePayload = JSON.stringify({
115
- state: requestObject.state,
116
- presentation_submission,
117
- nonce: requestObject.nonce,
118
- vp_token
119
- });
120
- const encrypted = await new _ioReactNativeJwt.EncryptJwe(authzResponsePayload, {
121
- alg: "RSA-OAEP-256",
122
- enc: "A256CBC-HS512",
123
- kid: rsaPublicJwk.kid
124
- }).encrypt(rsaPublicJwk);
125
- const formBody = new URLSearchParams({
126
- response: encrypted
127
- });
128
- const body = formBody.toString();
129
- return appFetch(requestObject.response_uri, {
130
- method: "POST",
131
- headers: {
132
- "Content-Type": "application/x-www-form-urlencoded"
133
- },
134
- body
135
- }).then((0, _misc.hasStatusOrThrow)(200)).then(res => res.json()).then(AuthorizationResponse.parse);
136
- };
137
- exports.sendAuthorizationResponse = sendAuthorizationResponse;
138
- //# sourceMappingURL=04-send-authorization-response.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_ioReactNativeJwt","require","_uuid","WalletInstanceAttestation","_interopRequireWildcard","_errors","_misc","_sdJwt","z","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","AuthorizationResponse","object","status","string","response_code","optional","exports","chooseRSAPublicKeyToEncrypt","entity","usingRsa256","wallet_relying_party","jwks","keys","filter","jwk","use","kty","NoSuitableKeysFoundInEntityConfiguration","prepareVpToken","requestObject","walletInstanceAttestation","_ref","vc","claims","cryptoCtx","token","vp","paths","disclose","payload","iss","decode","pidKid","getPublicKey","then","_","kid","vp_token","SignJWT","setProtectedHeader","typ","setPayload","jti","uuidv4","nonce","setAudience","response_uri","setIssuedAt","setExpirationTime","sign","vc_scope","scope","presentation_submission","definition_id","id","descriptor_map","map","p","path","format","sendAuthorizationResponse","rpConf","presentation","_ref2","appFetch","fetch","rsaPublicJwk","authzResponsePayload","JSON","stringify","state","encrypted","EncryptJwe","alg","enc","encrypt","formBody","URLSearchParams","response","body","toString","method","headers","hasStatusOrThrow","res","json","parse"],"sourceRoot":"../../../../src","sources":["credential/presentation/04-send-authorization-response.ts"],"mappings":";;;;;;AAAA,IAAAA,iBAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,yBAAA,GAAAC,uBAAA,CAAAH,OAAA;AAEA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AAEA,IAAAM,MAAA,GAAAN,OAAA;AAGA,IAAAO,CAAA,GAAAJ,uBAAA,CAAAH,OAAA;AAAyB,SAAAQ,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAN,wBAAAU,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KA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AA,GAAAA,yBAAA"}
@@ -1,128 +0,0 @@
1
- import { EncryptJwe, SignJWT } from "@pagopa/io-react-native-jwt";
2
- import { v4 as uuidv4 } from "uuid";
3
- import * as WalletInstanceAttestation from "../../wallet-instance-attestation";
4
- import { NoSuitableKeysFoundInEntityConfiguration } from "./errors";
5
- import { hasStatusOrThrow } from "../../utils/misc";
6
- import { disclose } from "../../sd-jwt";
7
- import * as z from "zod";
8
- export const AuthorizationResponse = z.object({
9
- status: z.string(),
10
- response_code: z.string() /**
11
- FIXME: [SIW-627] we expect this value from every RP implementation
12
- Actually some RP does not return the value
13
- We make it optional to not break the flow.
14
- */.optional()
15
- });
16
-
17
- /**
18
- * Choose an RSA public key from those offered by the RP for encryption.
19
- *
20
- * @param entity The RP entity configuration
21
- * @returns A suitable public key with its compatible encryption algorithm
22
- * @throws {NoSuitableKeysFoundInEntityConfiguration} If entity do not contain any public key suitable for encrypting
23
- */
24
- const chooseRSAPublicKeyToEncrypt = entity => {
25
- const [usingRsa256] = entity.wallet_relying_party.jwks.keys.filter(jwk => jwk.use === "enc" && jwk.kty === "RSA");
26
- if (usingRsa256) {
27
- return usingRsa256;
28
- }
29
-
30
- // No suitable key has been found
31
- throw new NoSuitableKeysFoundInEntityConfiguration("Encrypt with RP public key");
32
- };
33
-
34
- /**
35
- * Generate a Verified Presentation token for a received request object within the context of an authorization request flow.
36
- * The presentation is created by revealing data from the provided credentials based on the requested claims.
37
- * Each Verified Credential is accompanied by the claims that the user consents to disclose from it.
38
- *
39
- * @todo: Allow for handling more than one Verified Credential.
40
- */
41
- const prepareVpToken = async (requestObject, walletInstanceAttestation, _ref) => {
42
- let [vc, claims, cryptoCtx] = _ref;
43
- // this throws if vc cannot satisfy all the requested claims
44
- const {
45
- token: vp,
46
- paths
47
- } = await disclose(vc, claims);
48
-
49
- // obtain issuer from Wallet Instance
50
- const {
51
- payload: {
52
- iss
53
- }
54
- } = WalletInstanceAttestation.decode(walletInstanceAttestation);
55
- const pidKid = await cryptoCtx.getPublicKey().then(_ => _.kid);
56
-
57
- // TODO: [SIW-359] check all requeste claims of the requestedObj are satisfied
58
- const vp_token = await new SignJWT(cryptoCtx).setProtectedHeader({
59
- typ: "JWT",
60
- kid: pidKid
61
- }).setPayload({
62
- vp: vp,
63
- jti: `${uuidv4()}`,
64
- iss,
65
- nonce: requestObject.nonce
66
- }).setAudience(requestObject.response_uri).setIssuedAt().setExpirationTime("1h").sign();
67
- const vc_scope = requestObject.scope;
68
- const presentation_submission = {
69
- definition_id: `${uuidv4()}`,
70
- id: `${uuidv4()}`,
71
- descriptor_map: paths.map(p => ({
72
- id: vc_scope,
73
- path: `$.vp_token.${p.path}`,
74
- format: "vc+sd-jwt"
75
- }))
76
- };
77
- return {
78
- vp_token,
79
- presentation_submission
80
- };
81
- };
82
- /**
83
- * Complete the presentation flow by sending the authorization response to the Relying Party
84
- *
85
- * @param requestObject The Request Object that describes the presentation
86
- * @param rpConf The Relying Party's configuration
87
- * @param presentation The presentation tuple consisting in the signed credential,
88
- * the list of claims to be disclosed, and the context to access the key that proves the holder binding
89
- * @param context.walletInstanceAttestation The Wallet Instance Attestation token
90
- * @param context.appFetch (optional) fetch api implementation. Default: built-in fetch
91
- * @returns The result of the presentation flow
92
- */
93
- export const sendAuthorizationResponse = async (requestObject, rpConf, presentation, _ref2) => {
94
- let {
95
- appFetch = fetch,
96
- walletInstanceAttestation
97
- } = _ref2;
98
- // the request is an unsigned jws without iss, aud, exp
99
- // https://openid.net/specs/openid-4-verifiable-presentations-1_0.html#name-signed-and-encrypted-respon
100
- const rsaPublicJwk = chooseRSAPublicKeyToEncrypt(rpConf);
101
- const {
102
- vp_token,
103
- presentation_submission
104
- } = await prepareVpToken(requestObject, walletInstanceAttestation, presentation);
105
- const authzResponsePayload = JSON.stringify({
106
- state: requestObject.state,
107
- presentation_submission,
108
- nonce: requestObject.nonce,
109
- vp_token
110
- });
111
- const encrypted = await new EncryptJwe(authzResponsePayload, {
112
- alg: "RSA-OAEP-256",
113
- enc: "A256CBC-HS512",
114
- kid: rsaPublicJwk.kid
115
- }).encrypt(rsaPublicJwk);
116
- const formBody = new URLSearchParams({
117
- response: encrypted
118
- });
119
- const body = formBody.toString();
120
- return appFetch(requestObject.response_uri, {
121
- method: "POST",
122
- headers: {
123
- "Content-Type": "application/x-www-form-urlencoded"
124
- },
125
- body
126
- }).then(hasStatusOrThrow(200)).then(res => res.json()).then(AuthorizationResponse.parse);
127
- };
128
- //# sourceMappingURL=04-send-authorization-response.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["EncryptJwe","SignJWT","v4","uuidv4","WalletInstanceAttestation","NoSuitableKeysFoundInEntityConfiguration","hasStatusOrThrow","disclose","z","AuthorizationResponse","object","status","string","response_code","optional","chooseRSAPublicKeyToEncrypt","entity","usingRsa256","wallet_relying_party","jwks","keys","filter","jwk","use","kty","prepareVpToken","requestObject","walletInstanceAttestation","_ref","vc","claims","cryptoCtx","token","vp","paths","payload","iss","decode","pidKid","getPublicKey","then","_","kid","vp_token","setProtectedHeader","typ","setPayload","jti","nonce","setAudience","response_uri","setIssuedAt","setExpirationTime","sign","vc_scope","scope","presentation_submission","definition_id","id","descriptor_map","map","p","path","format","sendAuthorizationResponse","rpConf","presentation","_ref2","appFetch","fetch","rsaPublicJwk","authzResponsePayload","JSON","stringify","state","encrypted","alg","enc","encrypt","formBody","URLSearchParams","response","body","toString","method","headers","res","json","parse"],"sourceRoot":"../../../../src","sources":["credential/presentation/04-send-authorization-response.ts"],"mappings":"AAAA,SAASA,UAAU,EAAEC,OAAO,QAAQ,6BAA6B;AACjE,SAASC,EAAE,IAAIC,MAAM,QAAQ,MAAM;AACnC,OAAO,KAAKC,yBAAyB,MAAM,mCAAmC;AAE9E,SAASC,wCAAwC,QAAQ,UAAU;AACnE,SAASC,gBAAgB,QAAkB,kBAAkB;AAE7D,SAASC,QAAQ,QAAQ,cAAc;AAGvC,OAAO,KAAKC,CAAC,MAAM,KAAK;AAGxB,OAAO,MAAMC,qBAAqB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S,CAAC;IAC1CC,KAAK,EAAEhD,aAAa,CAACgD,KAAK;IAC1BlB,uBAAuB;IACvBR,KAAK,EAAEtB,aAAa,CAACsB,KAAK;IAC1BL;EACF,CAAC,CAAC;EAEF,MAAMgC,SAAS,GAAG,MAAM,IAAI3E,UAAU,CAACuE,oBAAoB,EAAE;IAC3DK,GAAG,EAAE,cAAc;IACnBC,GAAG,EAAE,eAAe;IACpBnC,GAAG,EAAE4B,YAAY,CAAC5B;EACpB,CAAC,CAAC,CAACoC,OAAO,CAACR,YAAY,CAAC;EAExB,MAAMS,QAAQ,GAAG,IAAIC,eAAe,CAAC;IAAEC,QAAQ,EAAEN;EAAU,CAAC,CAAC;EAC7D,MAAMO,IAAI,GAAGH,QAAQ,CAACI,QAAQ,CAAC,CAAC;EAEhC,OAAOf,QAAQ,CAAC1C,aAAa,CAACwB,YAAY,EAAE;IAC1CkC,MAAM,EAAE,MAAM;IACdC,OAAO,EAAE;MACP,cAAc,EAAE;IAClB,CAAC;IACDH;EACF,CAAC,CAAC,CACC1C,IAAI,CAAClC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAC3BkC,IAAI,CAAE8C,GAAG,IAAKA,GAAG,CAACC,IAAI,CAAC,CAAC,CAAC,CACzB/C,IAAI,CAAC/B,qBAAqB,CAAC+E,KAAK,CAAC;AACtC,CAAC"}
@@ -1,34 +0,0 @@
1
- import { type Out } from "../../utils/misc";
2
- import type { GetRequestObject } from "./03-get-request-object";
3
- import type { EvaluateRelyingPartyTrust } from "./02-evaluate-rp-trust";
4
- import { type Presentation } from "./types";
5
- import * as z from "zod";
6
- export type AuthorizationResponse = z.infer<typeof AuthorizationResponse>;
7
- export declare const AuthorizationResponse: z.ZodObject<{
8
- status: z.ZodString;
9
- response_code: z.ZodOptional<z.ZodString>;
10
- }, "strip", z.ZodTypeAny, {
11
- status: string;
12
- response_code?: string | undefined;
13
- }, {
14
- status: string;
15
- response_code?: string | undefined;
16
- }>;
17
- export type SendAuthorizationResponse = (requestObject: Out<GetRequestObject>["requestObject"], rpConf: Out<EvaluateRelyingPartyTrust>["rpConf"], presentation: Presentation, // TODO: [SIW-353] support multiple presentations
18
- context: {
19
- walletInstanceAttestation: string;
20
- appFetch?: GlobalFetch["fetch"];
21
- }) => Promise<AuthorizationResponse>;
22
- /**
23
- * Complete the presentation flow by sending the authorization response to the Relying Party
24
- *
25
- * @param requestObject The Request Object that describes the presentation
26
- * @param rpConf The Relying Party's configuration
27
- * @param presentation The presentation tuple consisting in the signed credential,
28
- * the list of claims to be disclosed, and the context to access the key that proves the holder binding
29
- * @param context.walletInstanceAttestation The Wallet Instance Attestation token
30
- * @param context.appFetch (optional) fetch api implementation. Default: built-in fetch
31
- * @returns The result of the presentation flow
32
- */
33
- export declare const sendAuthorizationResponse: SendAuthorizationResponse;
34
- //# sourceMappingURL=04-send-authorization-response.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"04-send-authorization-response.d.ts","sourceRoot":"","sources":["../../../../src/credential/presentation/04-send-authorization-response.ts"],"names":[],"mappings":"AAKA,OAAO,EAAoB,KAAK,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAC1E,eAAO,MAAM,qBAAqB;;;;;;;;;EAShC,CAAC;AAkFH,MAAM,MAAM,yBAAyB,GAAG,CACtC,aAAa,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC,eAAe,CAAC,EACrD,MAAM,EAAE,GAAG,CAAC,yBAAyB,CAAC,CAAC,QAAQ,CAAC,EAChD,YAAY,EAAE,YAAY,EAAE,iDAAiD;AAC7E,OAAO,EAAE;IACP,yBAAyB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;CACjC,KACE,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAEpC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,yBAAyB,EAAE,yBA0CvC,CAAC"}
@@ -1,168 +0,0 @@
1
- import { EncryptJwe, SignJWT } from "@pagopa/io-react-native-jwt";
2
- import { v4 as uuidv4 } from "uuid";
3
- import * as WalletInstanceAttestation from "../../wallet-instance-attestation";
4
- import type { JWK } from "@pagopa/io-react-native-jwt/lib/typescript/types";
5
- import { NoSuitableKeysFoundInEntityConfiguration } from "./errors";
6
- import { hasStatusOrThrow, type Out } from "../../utils/misc";
7
- import type { GetRequestObject } from "./03-get-request-object";
8
- import { disclose } from "../../sd-jwt";
9
- import type { EvaluateRelyingPartyTrust } from "./02-evaluate-rp-trust";
10
- import { type Presentation } from "./types";
11
- import * as z from "zod";
12
-
13
- export type AuthorizationResponse = z.infer<typeof AuthorizationResponse>;
14
- export const AuthorizationResponse = z.object({
15
- status: z.string(),
16
- response_code: z
17
- .string() /**
18
- FIXME: [SIW-627] we expect this value from every RP implementation
19
- Actually some RP does not return the value
20
- We make it optional to not break the flow.
21
- */
22
- .optional(),
23
- });
24
-
25
- /**
26
- * Choose an RSA public key from those offered by the RP for encryption.
27
- *
28
- * @param entity The RP entity configuration
29
- * @returns A suitable public key with its compatible encryption algorithm
30
- * @throws {NoSuitableKeysFoundInEntityConfiguration} If entity do not contain any public key suitable for encrypting
31
- */
32
- const chooseRSAPublicKeyToEncrypt = (
33
- entity: Out<EvaluateRelyingPartyTrust>["rpConf"]
34
- ): JWK => {
35
- const [usingRsa256] = entity.wallet_relying_party.jwks.keys.filter(
36
- (jwk) => jwk.use === "enc" && jwk.kty === "RSA"
37
- );
38
-
39
- if (usingRsa256) {
40
- return usingRsa256;
41
- }
42
-
43
- // No suitable key has been found
44
- throw new NoSuitableKeysFoundInEntityConfiguration(
45
- "Encrypt with RP public key"
46
- );
47
- };
48
-
49
- /**
50
- * Generate a Verified Presentation token for a received request object within the context of an authorization request flow.
51
- * The presentation is created by revealing data from the provided credentials based on the requested claims.
52
- * Each Verified Credential is accompanied by the claims that the user consents to disclose from it.
53
- *
54
- * @todo: Allow for handling more than one Verified Credential.
55
- */
56
- const prepareVpToken = async (
57
- requestObject: Out<GetRequestObject>["requestObject"],
58
- walletInstanceAttestation: string,
59
- [vc, claims, cryptoCtx]: Presentation // TODO: [SIW-353] support multiple presentations,
60
- ): Promise<{
61
- vp_token: string;
62
- presentation_submission: Record<string, unknown>;
63
- }> => {
64
- // this throws if vc cannot satisfy all the requested claims
65
- const { token: vp, paths } = await disclose(vc, claims);
66
-
67
- // obtain issuer from Wallet Instance
68
- const {
69
- payload: { iss },
70
- } = WalletInstanceAttestation.decode(walletInstanceAttestation);
71
-
72
- const pidKid = await cryptoCtx.getPublicKey().then((_) => _.kid);
73
-
74
- // TODO: [SIW-359] check all requeste claims of the requestedObj are satisfied
75
- const vp_token = await new SignJWT(cryptoCtx)
76
- .setProtectedHeader({
77
- typ: "JWT",
78
- kid: pidKid,
79
- })
80
- .setPayload({
81
- vp: vp,
82
- jti: `${uuidv4()}`,
83
- iss,
84
- nonce: requestObject.nonce,
85
- })
86
- .setAudience(requestObject.response_uri)
87
- .setIssuedAt()
88
- .setExpirationTime("1h")
89
- .sign();
90
-
91
- const vc_scope = requestObject.scope;
92
- const presentation_submission = {
93
- definition_id: `${uuidv4()}`,
94
- id: `${uuidv4()}`,
95
- descriptor_map: paths.map((p) => ({
96
- id: vc_scope,
97
- path: `$.vp_token.${p.path}`,
98
- format: "vc+sd-jwt",
99
- })),
100
- };
101
-
102
- return { vp_token, presentation_submission };
103
- };
104
-
105
- export type SendAuthorizationResponse = (
106
- requestObject: Out<GetRequestObject>["requestObject"],
107
- rpConf: Out<EvaluateRelyingPartyTrust>["rpConf"],
108
- presentation: Presentation, // TODO: [SIW-353] support multiple presentations
109
- context: {
110
- walletInstanceAttestation: string;
111
- appFetch?: GlobalFetch["fetch"];
112
- }
113
- ) => Promise<AuthorizationResponse>;
114
-
115
- /**
116
- * Complete the presentation flow by sending the authorization response to the Relying Party
117
- *
118
- * @param requestObject The Request Object that describes the presentation
119
- * @param rpConf The Relying Party's configuration
120
- * @param presentation The presentation tuple consisting in the signed credential,
121
- * the list of claims to be disclosed, and the context to access the key that proves the holder binding
122
- * @param context.walletInstanceAttestation The Wallet Instance Attestation token
123
- * @param context.appFetch (optional) fetch api implementation. Default: built-in fetch
124
- * @returns The result of the presentation flow
125
- */
126
- export const sendAuthorizationResponse: SendAuthorizationResponse = async (
127
- requestObject,
128
- rpConf,
129
- presentation,
130
- { appFetch = fetch, walletInstanceAttestation }
131
- ): Promise<AuthorizationResponse> => {
132
- // the request is an unsigned jws without iss, aud, exp
133
- // https://openid.net/specs/openid-4-verifiable-presentations-1_0.html#name-signed-and-encrypted-respon
134
- const rsaPublicJwk = chooseRSAPublicKeyToEncrypt(rpConf);
135
-
136
- const { vp_token, presentation_submission } = await prepareVpToken(
137
- requestObject,
138
- walletInstanceAttestation,
139
- presentation
140
- );
141
-
142
- const authzResponsePayload = JSON.stringify({
143
- state: requestObject.state,
144
- presentation_submission,
145
- nonce: requestObject.nonce,
146
- vp_token,
147
- });
148
-
149
- const encrypted = await new EncryptJwe(authzResponsePayload, {
150
- alg: "RSA-OAEP-256",
151
- enc: "A256CBC-HS512",
152
- kid: rsaPublicJwk.kid,
153
- }).encrypt(rsaPublicJwk);
154
-
155
- const formBody = new URLSearchParams({ response: encrypted });
156
- const body = formBody.toString();
157
-
158
- return appFetch(requestObject.response_uri, {
159
- method: "POST",
160
- headers: {
161
- "Content-Type": "application/x-www-form-urlencoded",
162
- },
163
- body,
164
- })
165
- .then(hasStatusOrThrow(200))
166
- .then((res) => res.json())
167
- .then(AuthorizationResponse.parse);
168
- };