@pagopa/io-react-native-wallet 0.4.3 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. package/README.md +128 -19
  2. package/lib/commonjs/index.js +16 -23
  3. package/lib/commonjs/index.js.map +1 -1
  4. package/lib/commonjs/pid/index.js +3 -8
  5. package/lib/commonjs/pid/index.js.map +1 -1
  6. package/lib/commonjs/pid/issuing.js +153 -176
  7. package/lib/commonjs/pid/issuing.js.map +1 -1
  8. package/lib/commonjs/rp/__test__/index.test.js +7 -5
  9. package/lib/commonjs/rp/__test__/index.test.js.map +1 -1
  10. package/lib/commonjs/rp/index.js +145 -155
  11. package/lib/commonjs/rp/index.js.map +1 -1
  12. package/lib/commonjs/rp/types.js +1 -21
  13. package/lib/commonjs/rp/types.js.map +1 -1
  14. package/lib/commonjs/trust/index.js +24 -5
  15. package/lib/commonjs/trust/index.js.map +1 -1
  16. package/lib/commonjs/trust/types.js +102 -9
  17. package/lib/commonjs/trust/types.js.map +1 -1
  18. package/lib/commonjs/utils/crypto.js +46 -0
  19. package/lib/commonjs/utils/crypto.js.map +1 -0
  20. package/lib/commonjs/utils/dpop.js +14 -7
  21. package/lib/commonjs/utils/dpop.js.map +1 -1
  22. package/lib/commonjs/wallet-instance-attestation/index.js +3 -3
  23. package/lib/commonjs/wallet-instance-attestation/issuing.js +42 -60
  24. package/lib/commonjs/wallet-instance-attestation/issuing.js.map +1 -1
  25. package/lib/module/index.js +4 -6
  26. package/lib/module/index.js.map +1 -1
  27. package/lib/module/pid/index.js +1 -1
  28. package/lib/module/pid/index.js.map +1 -1
  29. package/lib/module/pid/issuing.js +152 -180
  30. package/lib/module/pid/issuing.js.map +1 -1
  31. package/lib/module/rp/__test__/index.test.js +3 -3
  32. package/lib/module/rp/__test__/index.test.js.map +1 -1
  33. package/lib/module/rp/index.js +141 -154
  34. package/lib/module/rp/index.js.map +1 -1
  35. package/lib/module/rp/types.js +0 -20
  36. package/lib/module/rp/types.js.map +1 -1
  37. package/lib/module/trust/index.js +19 -5
  38. package/lib/module/trust/index.js.map +1 -1
  39. package/lib/module/trust/types.js +100 -7
  40. package/lib/module/trust/types.js.map +1 -1
  41. package/lib/module/utils/crypto.js +40 -0
  42. package/lib/module/utils/crypto.js.map +1 -0
  43. package/lib/module/utils/dpop.js +13 -5
  44. package/lib/module/utils/dpop.js.map +1 -1
  45. package/lib/module/wallet-instance-attestation/index.js +2 -2
  46. package/lib/module/wallet-instance-attestation/index.js.map +1 -1
  47. package/lib/module/wallet-instance-attestation/issuing.js +40 -58
  48. package/lib/module/wallet-instance-attestation/issuing.js.map +1 -1
  49. package/lib/typescript/index.d.ts +4 -6
  50. package/lib/typescript/index.d.ts.map +1 -1
  51. package/lib/typescript/pid/index.d.ts +1 -1
  52. package/lib/typescript/pid/index.d.ts.map +1 -1
  53. package/lib/typescript/pid/issuing.d.ts +43 -88
  54. package/lib/typescript/pid/issuing.d.ts.map +1 -1
  55. package/lib/typescript/rp/index.d.ts +41 -87
  56. package/lib/typescript/rp/index.d.ts.map +1 -1
  57. package/lib/typescript/rp/types.d.ts +10 -906
  58. package/lib/typescript/rp/types.d.ts.map +1 -1
  59. package/lib/typescript/sd-jwt/index.d.ts +1 -1
  60. package/lib/typescript/sd-jwt/index.d.ts.map +1 -1
  61. package/lib/typescript/trust/index.d.ts +806 -3
  62. package/lib/typescript/trust/index.d.ts.map +1 -1
  63. package/lib/typescript/trust/types.d.ts +9655 -297
  64. package/lib/typescript/trust/types.d.ts.map +1 -1
  65. package/lib/typescript/utils/crypto.d.ts +10 -0
  66. package/lib/typescript/utils/crypto.d.ts.map +1 -0
  67. package/lib/typescript/utils/dpop.d.ts +10 -2
  68. package/lib/typescript/utils/dpop.d.ts.map +1 -1
  69. package/lib/typescript/wallet-instance-attestation/index.d.ts +2 -2
  70. package/lib/typescript/wallet-instance-attestation/index.d.ts.map +1 -1
  71. package/lib/typescript/wallet-instance-attestation/issuing.d.ts +18 -31
  72. package/lib/typescript/wallet-instance-attestation/issuing.d.ts.map +1 -1
  73. package/lib/typescript/wallet-instance-attestation/types.d.ts +4 -4
  74. package/package.json +2 -2
  75. package/src/index.ts +14 -13
  76. package/src/pid/index.ts +1 -1
  77. package/src/pid/issuing.ts +233 -232
  78. package/src/rp/__test__/index.test.ts +3 -3
  79. package/src/rp/index.ts +172 -194
  80. package/src/rp/types.ts +0 -24
  81. package/src/sd-jwt/index.ts +1 -1
  82. package/src/trust/index.ts +106 -5
  83. package/src/trust/types.ts +152 -34
  84. package/src/utils/crypto.ts +41 -0
  85. package/src/utils/dpop.ts +17 -7
  86. package/src/wallet-instance-attestation/index.ts +2 -2
  87. package/src/wallet-instance-attestation/issuing.ts +51 -63
  88. package/lib/commonjs/pid/metadata.js +0 -49
  89. package/lib/commonjs/pid/metadata.js.map +0 -1
  90. package/lib/module/pid/metadata.js +0 -41
  91. package/lib/module/pid/metadata.js.map +0 -1
  92. package/lib/typescript/pid/metadata.d.ts +0 -482
  93. package/lib/typescript/pid/metadata.d.ts.map +0 -1
  94. package/src/pid/metadata.ts +0 -46
@@ -1,83 +1,75 @@
1
1
  import { AuthRequestDecodeError, IoWalletError, NoSuitableKeysFoundInEntityConfiguration } from "../utils/errors";
2
2
  import { decode as decodeJwt, decodeBase64, sha256ToBase64, SignJWT, EncryptJwe, verify } from "@pagopa/io-react-native-jwt";
3
- import { QRCodePayload, RequestObject, RpEntityConfiguration } from "./types";
3
+ import { QRCodePayload, RequestObject } from "./types";
4
4
  import uuid from "react-native-uuid";
5
5
  import { disclose } from "../sd-jwt";
6
- import { getEntityConfiguration } from "../trust";
7
- export class RelyingPartySolution {
8
- constructor(relyingPartyBaseUrl, walletInstanceAttestation) {
9
- let appFetch = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : fetch;
10
- this.relyingPartyBaseUrl = relyingPartyBaseUrl;
11
- this.walletInstanceAttestation = walletInstanceAttestation;
12
- this.appFetch = appFetch;
6
+ import { createDPopToken } from "../utils/dpop";
7
+ import * as WalletInstanceAttestation from "../wallet-instance-attestation";
8
+
9
+ /**
10
+ * Select a RSA public key from those provided by the RP to encrypt.
11
+ *
12
+ * @param entity The RP entity configuration
13
+ * @returns A suitable public key with its compatible encryption algorithm
14
+ * @throws {NoSuitableKeysFoundInEntityConfiguration} If entity do not contain any public key suitable for encrypting
15
+ */
16
+ const chooseRSAPublicKeyToEncrypt = entity => {
17
+ const [usingRsa256] = entity.payload.metadata.wallet_relying_party.jwks.filter(jwk => jwk.use === "enc" && jwk.kty === "RSA");
18
+ if (usingRsa256) {
19
+ return usingRsa256;
13
20
  }
14
21
 
15
- /**
16
- * Decode a QR code content to an authentication request url.
17
- * @function
18
- * @param qrcode QR code content
19
- *
20
- * @returns The authentication request url
21
- *
22
- */
23
- static decodeAuthRequestQR(qrcode) {
24
- const decoded = decodeBase64(qrcode);
25
- const decodedUrl = new URL(decoded);
26
- const protocol = decodedUrl.protocol;
27
- const resource = decodedUrl.hostname;
28
- const requestURI = decodedUrl.searchParams.get("request_uri");
29
- const clientId = decodedUrl.searchParams.get("client_id");
30
- const result = QRCodePayload.safeParse({
31
- protocol,
32
- resource,
33
- requestURI,
34
- clientId
35
- });
36
- if (result.success) {
37
- return result.data;
38
- } else {
39
- throw new AuthRequestDecodeError(result.error.message, `${decodedUrl}`);
40
- }
22
+ // No suitable key has been found
23
+ throw new NoSuitableKeysFoundInEntityConfiguration("Encrypt with RP public key");
24
+ };
25
+
26
+ /**
27
+ * Decode a QR code content to an authentication request url.
28
+ * @function
29
+ * @param qrcode QR code content
30
+ *
31
+ * @returns The authentication request url
32
+ *
33
+ */
34
+ export const decodeAuthRequestQR = qrcode => {
35
+ const decoded = decodeBase64(qrcode);
36
+ const decodedUrl = new URL(decoded);
37
+ const protocol = decodedUrl.protocol;
38
+ const resource = decodedUrl.hostname;
39
+ const requestURI = decodedUrl.searchParams.get("request_uri");
40
+ const clientId = decodedUrl.searchParams.get("client_id");
41
+ const result = QRCodePayload.safeParse({
42
+ protocol,
43
+ resource,
44
+ requestURI,
45
+ clientId
46
+ });
47
+ if (result.success) {
48
+ return result.data;
49
+ } else {
50
+ throw new AuthRequestDecodeError(result.error.message, `${decodedUrl}`);
41
51
  }
42
- /**
43
- * Obtain the unsigned wallet instance DPoP for authentication request
44
- *
45
- * @function
46
- * @param walletInstanceAttestationJwk JWT of the Wallet Instance Attestation
47
- * @param authRequestUrl authentication request url
48
- *
49
- * @returns The unsigned wallet instance DPoP
50
- *
51
- */
52
- async getUnsignedWalletInstanceDPoP(walletInstanceAttestationJwk, authRequestUrl) {
53
- return await new SignJWT({
52
+ };
53
+ /**
54
+ * Obtain the Request Object for RP authentication
55
+ * @see https://italia.github.io/eudi-wallet-it-docs/versione-corrente/en/relying-party-solution.html
56
+ */
57
+ export const getRequestObject = _ref => {
58
+ let {
59
+ wiaCryptoContext,
60
+ appFetch = fetch
61
+ } = _ref;
62
+ return async (walletInstanceAttestation, requestUri, rpEntityConfiguration) => {
63
+ const signedWalletInstanceDPoP = await createDPopToken({
54
64
  jti: `${uuid.v4()}`,
55
65
  htm: "GET",
56
- htu: authRequestUrl,
57
- ath: await sha256ToBase64(this.walletInstanceAttestation)
58
- }).setProtectedHeader({
59
- alg: "ES256",
60
- jwk: walletInstanceAttestationJwk,
61
- typ: "dpop+jwt"
62
- }).setIssuedAt().setExpirationTime("1h").toSign();
63
- }
64
-
65
- /**
66
- * Obtain the Request Object for RP authentication
67
- * @see https://italia.github.io/eudi-wallet-it-docs/versione-corrente/en/relying-party-solution.html
68
- *
69
- * @async @function
70
- * @param signedWalletInstanceDPoP JWT of the Wallet Instance Attestation DPoP
71
- *
72
- * @returns The Request Object JWT
73
- * @throws {NoSuitableKeysFoundInEntityConfiguration} When the Request Object is signed with a key not listed in RP's entity configuration
74
- *
75
- */
76
- async getRequestObject(signedWalletInstanceDPoP, requestUri, entity) {
77
- const response = await this.appFetch(requestUri, {
66
+ htu: requestUri,
67
+ ath: await sha256ToBase64(walletInstanceAttestation)
68
+ }, wiaCryptoContext);
69
+ const response = await appFetch(requestUri, {
78
70
  method: "GET",
79
71
  headers: {
80
- Authorization: `DPoP ${this.walletInstanceAttestation}`,
72
+ Authorization: `DPoP ${walletInstanceAttestation}`,
81
73
  DPoP: signedWalletInstanceDPoP
82
74
  }
83
75
  });
@@ -89,10 +81,10 @@ export class RelyingPartySolution {
89
81
  // verify token signature according to RP's entity configuration
90
82
  // to ensure the request object is authentic
91
83
  {
92
- const pubKey = entity.payload.metadata.wallet_relying_party.jwks.find(_ref => {
84
+ const pubKey = rpEntityConfiguration.payload.metadata.wallet_relying_party.jwks.find(_ref2 => {
93
85
  let {
94
86
  kid
95
- } = _ref;
87
+ } = _ref2;
96
88
  return kid === responseJwt.protectedHeader.kid;
97
89
  });
98
90
  if (!pubKey) {
@@ -102,55 +94,63 @@ export class RelyingPartySolution {
102
94
  }
103
95
 
104
96
  // parse request object it has the expected shape by specification
105
- const requestObj = RequestObject.parse({
97
+ const requestObject = RequestObject.parse({
106
98
  header: responseJwt.protectedHeader,
107
99
  payload: responseJwt.payload
108
100
  });
109
- return requestObj;
101
+ return {
102
+ requestObject,
103
+ rpEntityConfiguration,
104
+ walletInstanceAttestation
105
+ };
110
106
  }
111
- throw new IoWalletError(`Unable to obtain Request Object. Response code: ${response.status}`);
112
- }
107
+ throw new IoWalletError(`Unable to obtain Request Object. Response code: ${response.status}
108
+ ${await response.text()}`);
109
+ };
110
+ };
113
111
 
114
- /**
115
- * Prepare the Verified Presentation token for a received request object in the context of an authorization request flow.
116
- * The presentation is prepared by disclosing data from provided credentials, according to requested claims
117
- * Each Verified Credential come along with the claims the user accepts to disclose from it.
118
- *
119
- * The returned token is unsigned (sign should be apply by the caller).
120
- *
121
- * @todo accept more than a Verified Credential
122
- *
123
- * @param requestObj The incoming request object, which the requirements for the requested authorization
124
- * @param walletInstanceIdentifier The identifies of the wallt instance that is presenting
125
- * @param presentation The Verified Credential containing user data along with the list of claims to be disclosed.
126
- * @param signKeyId The kid of the key that will be used to sign
127
- * @returns The unsigned Verified Presentation token
128
- * @throws {ClaimsNotFoundBetweenDislosures} If the Verified Credential does not contain one or more requested claims.
129
- *
130
- */
131
- async prepareVpToken(requestObj, walletInstanceIdentifier, _ref2,
132
- // TODO: [SIW-353] support multiple presentations,
133
- signKeyId) {
134
- let [vc, claims] = _ref2;
112
+ /**
113
+ * Prepare the Verified Presentation token for a received request object in the context of an authorization request flow.
114
+ * The presentation is prepared by disclosing data from provided credentials, according to requested claims
115
+ * Each Verified Credential come along with the claims the user accepts to disclose from it.
116
+ *
117
+ * @todo accept more than a Verified Credential
118
+ */
119
+ const prepareVpToken = _ref3 => {
120
+ let {
121
+ pidCryptoContext
122
+ } = _ref3;
123
+ return async (_ref4, _ref5) => {
124
+ let {
125
+ requestObject,
126
+ walletInstanceAttestation
127
+ } = _ref4;
128
+ let [vc, claims] = _ref5;
135
129
  // this throws if vc cannot satisfy all the requested claims
136
130
  const {
137
131
  token: vp,
138
132
  paths
139
133
  } = await disclose(vc, claims);
140
134
 
141
- // TODO: [SIW-359] check all requeste claims of the requestedObj are satisfied
135
+ // obtain issuer from Wallet Instance
136
+ const {
137
+ payload: {
138
+ iss
139
+ }
140
+ } = WalletInstanceAttestation.decode(walletInstanceAttestation);
141
+ const pidKid = await pidCryptoContext.getPublicKey().then(_ => _.kid);
142
142
 
143
- const vp_token = new SignJWT({
143
+ // TODO: [SIW-359] check all requeste claims of the requestedObj are satisfied
144
+ const vp_token = await new SignJWT(pidCryptoContext).setProtectedHeader({
145
+ typ: "JWT",
146
+ kid: pidKid
147
+ }).setPayload({
144
148
  vp: vp,
145
149
  jti: `${uuid.v4()}`,
146
- iss: walletInstanceIdentifier,
147
- nonce: requestObj.payload.nonce
148
- }).setAudience(requestObj.payload.response_uri).setIssuedAt().setExpirationTime("1h").setProtectedHeader({
149
- typ: "JWT",
150
- alg: "ES256",
151
- kid: signKeyId
152
- }).toSign();
153
- const vc_scope = requestObj.payload.scope;
150
+ iss,
151
+ nonce: requestObject.payload.nonce
152
+ }).setAudience(requestObject.payload.response_uri).setIssuedAt().setExpirationTime("1h").sign();
153
+ const vc_scope = requestObject.payload.scope;
154
154
  const presentation_submission = {
155
155
  definition_id: `${uuid.v4()}`,
156
156
  id: `${uuid.v4()}`,
@@ -164,30 +164,43 @@ export class RelyingPartySolution {
164
164
  vp_token,
165
165
  presentation_submission
166
166
  };
167
- }
167
+ };
168
+ };
168
169
 
169
- /**
170
- * Compose and send an Authorization Response in the context of an authorization request flow.
171
- *
172
- * @todo MUST add presentation_submission
173
- *
174
- * @param requestObj The incoming request object, which the requirements for the requested authorization
175
- * @param vp_token The signed Verified Presentation token with data to send.
176
- * @param presentation_submission
177
- * @param entity The RP entity configuration
178
- * @returns The response from the RP
179
- * @throws {IoWalletError} if the submission fails.
180
- * @throws {NoSuitableKeysFoundInEntityConfiguration} If entity do not contain any public key
181
- *
182
- */
183
- async sendAuthorizationResponse(requestObj, vp_token, presentation_submission, entity) {
170
+ /**
171
+ * Compose and send an Authorization Response in the context of an authorization request flow.
172
+ *
173
+ * @todo MUST add presentation_submission
174
+ *
175
+ */
176
+ export const sendAuthorizationResponse = _ref6 => {
177
+ let {
178
+ pidCryptoContext,
179
+ appFetch = fetch
180
+ } = _ref6;
181
+ return async (_ref7, presentation) => {
182
+ let {
183
+ requestObject,
184
+ rpEntityConfiguration,
185
+ walletInstanceAttestation
186
+ } = _ref7;
184
187
  // the request is an unsigned jws without iss, aud, exp
185
188
  // https://openid.net/specs/openid-4-verifiable-presentations-1_0.html#name-signed-and-encrypted-respon
186
- const jwk = this.chooseRSAPublicKeyToEncrypt(entity);
189
+ const jwk = chooseRSAPublicKeyToEncrypt(rpEntityConfiguration);
190
+ const {
191
+ vp_token,
192
+ presentation_submission
193
+ } = await prepareVpToken({
194
+ pidCryptoContext
195
+ })({
196
+ requestObject,
197
+ rpEntityConfiguration,
198
+ walletInstanceAttestation
199
+ }, presentation);
187
200
  const authzResponsePayload = JSON.stringify({
188
- state: requestObj.payload.state,
201
+ state: requestObject.payload.state,
189
202
  presentation_submission,
190
- nonce: requestObj.payload.nonce,
203
+ nonce: requestObject.payload.nonce,
191
204
  vp_token
192
205
  });
193
206
  const encrypted = await new EncryptJwe(authzResponsePayload, {
@@ -199,7 +212,7 @@ export class RelyingPartySolution {
199
212
  response: encrypted
200
213
  });
201
214
  const body = formBody.toString();
202
- const response = await this.appFetch(requestObj.payload.response_uri, {
215
+ const response = await appFetch(requestObject.payload.response_uri, {
203
216
  method: "POST",
204
217
  headers: {
205
218
  "Content-Type": "application/x-www-form-urlencoded"
@@ -210,32 +223,6 @@ export class RelyingPartySolution {
210
223
  return await response.json();
211
224
  }
212
225
  throw new IoWalletError(`Unable to send Authorization Response. Response: ${await response.text()} with code: ${response.status}`);
213
- }
214
-
215
- /**
216
- * Select a RSA public key from those provided by the RP to encrypt.
217
- *
218
- * @param entity The RP entity configuration
219
- * @returns A suitable public key with its compatible encryption algorithm
220
- * @throws {NoSuitableKeysFoundInEntityConfiguration} If entity do not contain any public key suitable for encrypting
221
- */
222
- chooseRSAPublicKeyToEncrypt(entity) {
223
- const [usingRsa256] = entity.payload.metadata.wallet_relying_party.jwks.filter(jwk => jwk.use === "enc" && jwk.kty === "RSA");
224
- if (usingRsa256) {
225
- return usingRsa256;
226
- }
227
-
228
- // No suitable key has been found
229
- throw new NoSuitableKeysFoundInEntityConfiguration("Encrypt with RP public key");
230
- }
231
-
232
- /**
233
- * Obtain the relying party entity configuration.
234
- */
235
- async getEntityConfiguration() {
236
- return getEntityConfiguration(this.relyingPartyBaseUrl, {
237
- appFetch: this.appFetch
238
- }).then(RpEntityConfiguration.parse);
239
- }
240
- }
226
+ };
227
+ };
241
228
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["AuthRequestDecodeError","IoWalletError","NoSuitableKeysFoundInEntityConfiguration","decode","decodeJwt","decodeBase64","sha256ToBase64","SignJWT","EncryptJwe","verify","QRCodePayload","RequestObject","RpEntityConfiguration","uuid","disclose","getEntityConfiguration","RelyingPartySolution","constructor","relyingPartyBaseUrl","walletInstanceAttestation","appFetch","arguments","length","undefined","fetch","decodeAuthRequestQR","qrcode","decoded","decodedUrl","URL","protocol","resource","hostname","requestURI","searchParams","get","clientId","result","safeParse","success","data","error","message","getUnsignedWalletInstanceDPoP","walletInstanceAttestationJwk","authRequestUrl","jti","v4","htm","htu","ath","setProtectedHeader","alg","jwk","typ","setIssuedAt","setExpirationTime","toSign","getRequestObject","signedWalletInstanceDPoP","requestUri","entity","response","method","headers","Authorization","DPoP","status","responseJson","json","responseEncodedJwt","responseJwt","pubKey","payload","metadata","wallet_relying_party","jwks","find","_ref","kid","protectedHeader","requestObj","parse","header","prepareVpToken","walletInstanceIdentifier","_ref2","signKeyId","vc","claims","token","vp","paths","vp_token","iss","nonce","setAudience","response_uri","vc_scope","scope","presentation_submission","definition_id","id","descriptor_map","map","p","path","format","sendAuthorizationResponse","chooseRSAPublicKeyToEncrypt","authzResponsePayload","JSON","stringify","state","encrypted","enc","encrypt","formBody","URLSearchParams","body","toString","text","usingRsa256","filter","use","kty","then"],"sourceRoot":"../../../src","sources":["rp/index.ts"],"mappings":"AAAA,SACEA,sBAAsB,EACtBC,aAAa,EACbC,wCAAwC,QACnC,iBAAiB;AACxB,SACEC,MAAM,IAAIC,SAAS,EACnBC,YAAY,EACZC,cAAc,EACdC,OAAO,EACPC,UAAU,EACVC,MAAM,QACD,6BAA6B;AACpC,SACEC,aAAa,EACbC,aAAa,EACbC,qBAAqB,QAEhB,SAAS;AAEhB,OAAOC,IAAI,MAAM,mBAAmB;AAEpC,SAASC,QAAQ,QAAQ,WAAW;AACpC,SAASC,sBAAsB,QAAQ,UAAU;AAEjD,OAAO,MAAMC,oBAAoB,CAAC;EAKhCC,WAAWA,CACTC,mBAA2B,EAC3BC,yBAAiC,EAEjC;IAAA,IADAC,QAA8B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGG,KAAK;IAEtC,IAAI,CAACN,mBAAmB,GAAGA,mBAAmB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,EAAE;MAC3B,OAAO,MAAML,QAAQ,CAACO,IAAI,CAAC,CAAC;IAC9B;IAEA,MAAM,IAAIpE,aAAa,CACpB,oDAAmD,MAAM6D,QAAQ,CAAC2D,IAAI,CAAC,CAAE,eACxE3D,QAAQ,CAACK,MACV,EACH,CAAC;EACH;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACU0C,2BAA2BA,CAAChD,MAA6B,EAAO;IACtE,MAAM,CAAC6D,WAAW,CAAC,GACjB7D,MAAM,CAACY,OAAO,CAACC,QAAQ,CAACC,oBAAoB,CAACC,IAAI,CAAC+C,MAAM,CACrDtE,GAAG,IAAKA,GAAG,CAACuE,GAAG,KAAK,KAAK,IAAIvE,GAAG,CAACwE,GAAG,KAAK,KAC5C,CAAC;IAEH,IAAIH,WAAW,EAAE;MACf,OAAOA,WAAW;IACpB;;IAEA;IACA,MAAM,IAAIxH,wCAAwC,CAChD,4BACF,CAAC;EACH;;EAEA;AACF;AACA;EACE,MAAMa,sBAAsBA,CAAA,EAAmC;IAC7D,OAAOA,sBAAsB,CAAC,IAAI,CAACG,mBAAmB,EAAE;MACtDE,QAAQ,EAAE,IAAI,CAACA;IACjB,CAAC,CAAC,CAAC0G,IAAI,CAAClH,qBAAqB,CAACsE,KAAK,CAAC;EACtC;AACF"}
1
+ {"version":3,"names":["AuthRequestDecodeError","IoWalletError","NoSuitableKeysFoundInEntityConfiguration","decode","decodeJwt","decodeBase64","sha256ToBase64","SignJWT","EncryptJwe","verify","QRCodePayload","RequestObject","uuid","disclose","createDPopToken","WalletInstanceAttestation","chooseRSAPublicKeyToEncrypt","entity","usingRsa256","payload","metadata","wallet_relying_party","jwks","filter","jwk","use","kty","decodeAuthRequestQR","qrcode","decoded","decodedUrl","URL","protocol","resource","hostname","requestURI","searchParams","get","clientId","result","safeParse","success","data","error","message","getRequestObject","_ref","wiaCryptoContext","appFetch","fetch","walletInstanceAttestation","requestUri","rpEntityConfiguration","signedWalletInstanceDPoP","jti","v4","htm","htu","ath","response","method","headers","Authorization","DPoP","status","responseJson","json","responseEncodedJwt","responseJwt","pubKey","find","_ref2","kid","protectedHeader","requestObject","parse","header","text","prepareVpToken","_ref3","pidCryptoContext","_ref4","_ref5","vc","claims","token","vp","paths","iss","pidKid","getPublicKey","then","_","vp_token","setProtectedHeader","typ","setPayload","nonce","setAudience","response_uri","setIssuedAt","setExpirationTime","sign","vc_scope","scope","presentation_submission","definition_id","id","descriptor_map","map","p","path","format","sendAuthorizationResponse","_ref6","_ref7","presentation","authzResponsePayload","JSON","stringify","state","encrypted","alg","enc","encrypt","formBody","URLSearchParams","body","toString"],"sourceRoot":"../../../src","sources":["rp/index.ts"],"mappings":"AAAA,SACEA,sBAAsB,EACtBC,aAAa,EACbC,wCAAwC,QACnC,iBAAiB;AACxB,SACEC,MAAM,IAAIC,SAAS,EACnBC,YAAY,EACZC,cAAc,EACdC,OAAO,EACPC,UAAU,EACVC,MAAM,QAED,6BAA6B;AACpC,SAASC,aAAa,EAAEC,aAAa,QAA2B,SAAS;AAEzE,OAAOC,IAAI,MAAM,mBAAmB;AAEpC,SAASC,QAAQ,QAAQ,WAAW;AACpC,SAASC,eAAe,QAAQ,eAAe;AAE/C,OAAO,KAAKC,yBAAyB,MAAM,gCAAgC;;AAE3E;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,2BAA2B,GAC/BC,MAAuC,IAC/B;EACR,MAAM,CAACC,WAAW,CAAC,GACjBD,MAAM,CAACE,OAAO,CAACC,QAAQ,CAACC,oBAAoB,CAACC,IAAI,CAACC,MAAM,CACrDC,GAAG,IAAKA,GAAG,CAACC,GAAG,KAAK,KAAK,IAAID,GAAG,CAACE,GAAG,KAAK,KAC5C,CAAC;EAEH,IAAIR,WAAW,EAAE;IACf,OAAOA,WAAW;EACpB;;EAEA;EACA,MAAM,IAAIhB,wCAAwC,CAChD,4BACF,CAAC;AACH,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMyB,mBA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AAGF,QAAQ,CAACG,QAAQ,CAAC,CAAC;IAEhC,MAAMrE,QAAQ,GAAG,MAAMX,QAAQ,CAAC0B,aAAa,CAACvD,OAAO,CAACgF,YAAY,EAAE;MAClEvC,MAAM,EAAE,MAAM;MACdC,OAAO,EAAE;QACP,cAAc,EAAE;MAClB,CAAC;MACDkE;IACF,CAAC,CAAC;IAEF,IAAIpE,QAAQ,CAACK,MAAM,KAAK,GAAG,EAAE;MAC3B,OAAO,MAAML,QAAQ,CAACO,IAAI,CAAC,CAAC;IAC9B;IAEA,MAAM,IAAIjE,aAAa,CACpB,oDAAmD,MAAM0D,QAAQ,CAACkB,IAAI,CAAC,CAAE,eACxElB,QAAQ,CAACK,MACV,EACH,CAAC;EACH,CAAC;AAAA"}
@@ -1,7 +1,5 @@
1
- import { JWK } from "../utils/jwk";
2
1
  import { UnixTime } from "../sd-jwt/types";
3
2
  import * as z from "zod";
4
- import { EntityConfiguration } from "../trust/types";
5
3
  export const RequestObject = z.object({
6
4
  header: z.object({
7
5
  // FIXME: SIW-421 type field must be either required or omitted, optional isn't useful
@@ -24,24 +22,6 @@ export const RequestObject = z.object({
24
22
  scope: z.string()
25
23
  })
26
24
  });
27
-
28
- /**
29
- * EntityConfiguration plus the metadata specific for a Relying Party entity.
30
- */
31
-
32
- export const RpEntityConfiguration = EntityConfiguration.and(z.object({
33
- payload: z.object({
34
- metadata: z.object({
35
- wallet_relying_party: z.object({
36
- application_type: z.string().optional(),
37
- client_id: z.string().optional(),
38
- client_name: z.string().optional(),
39
- jwks: z.array(JWK),
40
- contacts: z.array(z.string()).optional()
41
- }).passthrough()
42
- })
43
- })
44
- }));
45
25
  export const QRCodePayload = z.object({
46
26
  protocol: z.string(),
47
27
  resource: z.string(),
@@ -1 +1 @@
1
- {"version":3,"names":["JWK","UnixTime","z","EntityConfiguration","RequestObject","object","header","typ","literal","optional","alg","string","kid","trust_chain","array","payload","iss","iat","exp","state","nonce","response_uri","response_type","response_mode","client_id","client_id_scheme","scope","RpEntityConfiguration","and","metadata","wallet_relying_party","application_type","client_name","jwks","contacts","passthrough","QRCodePayload","protocol","resource","clientId","requestURI"],"sourceRoot":"../../../src","sources":["rp/types.ts"],"mappings":"AAAA,SAASA,GAAG,QAAQ,cAAc;AAClC,SAASC,QAAQ,QAAQ,iBAAiB;AAC1C,OAAO,KAAKC,CAAC,MAAM,KAAK;AACxB,SAASC,mBAAmB,QAAQ,gBAAgB;AAGpD,OAAO,MAAMC,aAAa,GAAGF,CAAC,CAACG,MAAM,CAAC;EACpCC,MAAM,EAAEJ,CAAC,CAACG,MAAM,CAAC;IACf;IACAE,GAAG,EAAEL,CAAC,CAACM,OAAO,CAAC,KAAK,CAAC,CAACC,QAAQ,CAAC,CAAC;IAChCC,GAAG,EAAER,CAAC,CAACS,MAAM,CAAC,CAAC;IACfC,GAAG,EAAEV,CAAC,CAACS,MAAM,CAAC,CAAC;IACfE,WAAW,EAAEX,CAAC,CAACY,KAAK,CAACZ,CAAC,CAACS,MAAM,CAAC,CAAC;EACjC,CAAC,CAAC;EACFI,OAAO,EAAEb,CAAC,CAACG,MAAM,CAAC;IAChBW,GAAG,EAAEd,CAAC,CAACS,MAAM,CAAC,CAAC;IACfM,GAAG,EAAEhB,QAAQ;IACbiB,GAAG,EAAEjB,QAAQ;IACbkB,KAAK,EAAEjB,CAAC,CAACS,MAAM,CAAC,CAAC;IACjBS,KAAK,EAAElB,CAAC,CAACS,MAAM,CAAC,CAAC;IACjBU,YAAY,EAAEnB,CAAC,CAACS,MAAM,CAAC,CAAC;IACxBW,aAAa,EAAEpB,CAAC,CAACM,OAAO,CAAC,UAAU,CAAC;IACpCe,aAAa,EAAErB,CAAC,CAACM,OAAO,CAAC,iBAAiB,CAAC;IAC3CgB,SAAS,EAAEtB,CAAC,CAACS,MAAM,CAAC,CAAC;IACrBc,gBAAgB,EAAEvB,CAAC,CAACM,OAAO,CAAC,WAAW,CAAC;IACxCkB,KAAK,EAAExB,CAAC,CAACS,MAAM,CAAC;EAClB,CAAC;AACH,CAAC,CAAC;;AAEF;AACA;AACA;;AAEA,OAAO,MAAMgB,qBAAqB,GAAGxB,mBAAmB,CAACyB,GAAG,CAC1D1B,CAAC,CAACG,MAAM,CAAC;EACPU,OAAO,EAAEb,CAAC,CAACG,MAAM,CAAC;IAChBwB,QAAQ,EAAE3B,CAAC,CAACG,MAAM,CAAC;MACjByB,oBAAoB,EAAE5B,CAAC,CACpBG,MAAM,CAAC;QACN0B,gBAAgB,EAAE7B,CAAC,CAACS,MAAM,CAAC,CAAC,CAACF,QAAQ,CAAC,CAAC;QACvCe,SAAS,EAAEtB,CAAC,CAACS,MAAM,CAAC,CAAC,CAACF,QAAQ,CAAC,CAAC;QAChCuB,WAAW,EAAE9B,CAAC,CAACS,MAAM,CAAC,CAAC,CAACF,QAAQ,CAAC,CAAC;QAClCwB,IAAI,EAAE/B,CAAC,CAACY,KAAK,CAACd,GAAG,CAAC;QAClBkC,QAAQ,EAAEhC,CAAC,CAACY,KAAK,CAACZ,CAAC,CAACS,MAAM,CAAC,CAAC,CAAC,CAACF,QAAQ,CAAC;MACzC,CAAC,CAAC,CACD0B,WAAW,CAAC;IACjB,CAAC;EACH,CAAC;AACH,CAAC,CACH,CAAC;AAGD,OAAO,MAAMC,aAAa,GAAGlC,CAAC,CAACG,MAAM,CAAC;EACpCgC,QAAQ,EAAEnC,CAAC,CAACS,MAAM,CAAC,CAAC;EACpB2B,QAAQ,EAAEpC,CAAC,CAACS,MAAM,CAAC,CAAC;EAAE;EACtB4B,QAAQ,EAAErC,CAAC,CAACS,MAAM,CAAC,CAAC;EACpB6B,UAAU,EAAEtC,CAAC,CAACS,MAAM,CAAC;AACvB,CAAC,CAAC;;AAEF;AACA;AACA"}
1
+ {"version":3,"names":["UnixTime","z","RequestObject","object","header","typ","literal","optional","alg","string","kid","trust_chain","array","payload","iss","iat","exp","state","nonce","response_uri","response_type","response_mode","client_id","client_id_scheme","scope","QRCodePayload","protocol","resource","clientId","requestURI"],"sourceRoot":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,EAAE1B,CAAC,CAACQ,MAAM,CAAC,CAAC;EAAE;EACtBmB,QAAQ,EAAE3B,CAAC,CAACQ,MAAM,CAAC,CAAC;EACpBoB,UAAU,EAAE5B,CAAC,CAACQ,MAAM,CAAC;AACvB,CAAC,CAAC;;AAEF;AACA;AACA"}
@@ -1,22 +1,31 @@
1
1
  import { decode as decodeJwt } from "@pagopa/io-react-native-jwt";
2
- import { EntityConfiguration } from "./types";
2
+ import { WalletProviderEntityConfiguration, TrustAnchorEntityConfiguration, CredentialIssuerEntityConfiguration, RelyingPartyEntityConfiguration, EntityConfiguration } from "./types";
3
3
  import { IoWalletError } from "../utils/errors";
4
4
  import { verifyTrustChain } from "./chain";
5
5
  export { verifyTrustChain };
6
6
 
7
7
  /**
8
- * Fetch and parse teh entity configuration document for a given federation entity
8
+ * Fetch and parse the entity configuration document for a given federation entity.
9
+ * This is an inner method to serve public interfaces.
10
+ *
11
+ * To add another entity configuration type (example: Foo entity type):
12
+ * - create its zod schema and type by inherit from the base type (example: FooEntityConfiguration = BaseEntityConfiguration.and(...))
13
+ * - add such type to EntityConfiguration union
14
+ * - add an overload to this function
15
+ * - create a public function which use such type (example: getFooEntityConfiguration = (url, options) => Promise<FooEntityConfiguration>)
9
16
  *
10
17
  * @param entityBaseUrl The base url of the entity.
18
+ * @param schema The expected schema of the entity configuration, according to the kind of entity we are fetching from.
11
19
  * @param options.appFetch An optional instance of the http client to be used.
12
20
  * @returns The parsed entity configuration object
13
21
  * @throws {IoWalletError} If the http request fails
14
22
  * @throws Parse error if the document is not in the expected shape.
15
23
  */
16
- export async function getEntityConfiguration(entityBaseUrl) {
24
+
25
+ async function fetchAndParseEntityConfiguration(entityBaseUrl, schema) {
17
26
  let {
18
27
  appFetch = fetch
19
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
28
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
20
29
  const wellKnownUrl = `${entityBaseUrl}/.well-known/openid-federation`;
21
30
  const response = await appFetch(wellKnownUrl, {
22
31
  method: "GET"
@@ -24,11 +33,16 @@ export async function getEntityConfiguration(entityBaseUrl) {
24
33
  if (response.status === 200) {
25
34
  const responseText = await response.text();
26
35
  const responseJwt = decodeJwt(responseText);
27
- return EntityConfiguration.parse({
36
+ return schema.parse({
28
37
  header: responseJwt.protectedHeader,
29
38
  payload: responseJwt.payload
30
39
  });
31
40
  }
32
41
  throw new IoWalletError(`Unable to obtain Entity Configuration at ${wellKnownUrl}. Response code: ${response.status}`);
33
42
  }
43
+ export const getWalletProviderEntityConfiguration = (entityBaseUrl, options) => fetchAndParseEntityConfiguration(entityBaseUrl, WalletProviderEntityConfiguration, options);
44
+ export const getCredentialIssuerEntityConfiguration = (entityBaseUrl, options) => fetchAndParseEntityConfiguration(entityBaseUrl, CredentialIssuerEntityConfiguration, options);
45
+ export const getTrustAnchorEntityConfiguration = (entityBaseUrl, options) => fetchAndParseEntityConfiguration(entityBaseUrl, TrustAnchorEntityConfiguration, options);
46
+ export const getRelyingPartyEntityConfiguration = (entityBaseUrl, options) => fetchAndParseEntityConfiguration(entityBaseUrl, RelyingPartyEntityConfiguration, options);
47
+ export const getEntityConfiguration = (entityBaseUrl, options) => fetchAndParseEntityConfiguration(entityBaseUrl, EntityConfiguration, options);
34
48
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["decode","decodeJwt","EntityConfiguration","IoWalletError","verifyTrustChain","getEntityConfiguration","entityBaseUrl","appFetch","fetch","arguments","length","undefined","wellKnownUrl","response","method","status","responseText","text","responseJwt","parse","header","protectedHeader","payload"],"sourceRoot":"../../../src","sources":["trust/index.ts"],"mappings":"AAAA,SAASA,MAAM,IAAIC,SAAS,QAAQ,6BAA6B;AACjE,SAASC,mBAAmB,QAAQ,SAAS;AAC7C,SAASC,aAAa,QAAQ,iBAAiB;AAC/C,SAASC,gBAAgB,QAAQ,SAAS;AAE1C,SAASA,gBAAgB;;AAEzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,sBAAsBA,CAC1CC,aAAqB,EAMS;EAAA,IAL9B;IACEC,QAAQ,GAAGC;EAGb,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAEN,MAAMG,YAAY,GAAI,GAAEN,aAAc,gCAA+B;EAErE,MAAMO,QAAQ,GAAG,MAAMN,QAAQ,CAACK,YAAY,EAAE;IAC5CE,MAAM,EAAE;EACV,CAAC,CAAC;EAEF,IAAID,QAAQ,CAACE,MAAM,KAAK,GAAG,EAAE;IAC3B,MAAMC,YAAY,GAAG,MAAMH,QAAQ,CAACI,IAAI,CAAC,CAAC;IAC1C,MAAMC,WAAW,GAAGjB,SAAS,CAACe,YAAY,CAAC;IAC3C,OAAOd,mBAAmB,CAACiB,KAAK,CAAC;MAC/BC,MAAM,EAAEF,WAAW,CAACG,eAAe;MACnCC,OAAO,EAAEJ,WAAW,CAACI;IACvB,CAAC,CAAC;EACJ;EAEA,MAAM,IAAInB,aAAa,CACpB,4CAA2CS,YAAa,oBAAmBC,QAAQ,CAACE,MAAO,EAC9F,CAAC;AACH"}
1
+ {"version":3,"names":["decode","decodeJwt","WalletProviderEntityConfiguration","TrustAnchorEntityConfiguration","CredentialIssuerEntityConfiguration","RelyingPartyEntityConfiguration","EntityConfiguration","IoWalletError","verifyTrustChain","fetchAndParseEntityConfiguration","entityBaseUrl","schema","appFetch","fetch","arguments","length","undefined","wellKnownUrl","response","method","status","responseText","text","responseJwt","parse","header","protectedHeader","payload","getWalletProviderEntityConfiguration","options","getCredentialIssuerEntityConfiguration","getTrustAnchorEntityConfiguration","getRelyingPartyEntityConfiguration","getEntityConfiguration"],"sourceRoot":"../../../src","sources":["trust/index.ts"],"mappings":"AAAA,SAASA,MAAM,IAAIC,SAAS,QAAQ,6BAA6B;AACjE,SACEC,iCAAiC,EACjCC,8BAA8B,EAC9BC,mCAAmC,EACnCC,+BAA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