@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.
- package/README.md +128 -19
- package/lib/commonjs/index.js +16 -23
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/pid/index.js +3 -8
- package/lib/commonjs/pid/index.js.map +1 -1
- package/lib/commonjs/pid/issuing.js +153 -176
- package/lib/commonjs/pid/issuing.js.map +1 -1
- package/lib/commonjs/rp/__test__/index.test.js +7 -5
- package/lib/commonjs/rp/__test__/index.test.js.map +1 -1
- package/lib/commonjs/rp/index.js +145 -155
- package/lib/commonjs/rp/index.js.map +1 -1
- package/lib/commonjs/rp/types.js +1 -21
- package/lib/commonjs/rp/types.js.map +1 -1
- package/lib/commonjs/trust/index.js +24 -5
- package/lib/commonjs/trust/index.js.map +1 -1
- package/lib/commonjs/trust/types.js +102 -9
- package/lib/commonjs/trust/types.js.map +1 -1
- package/lib/commonjs/utils/crypto.js +46 -0
- package/lib/commonjs/utils/crypto.js.map +1 -0
- package/lib/commonjs/utils/dpop.js +14 -7
- package/lib/commonjs/utils/dpop.js.map +1 -1
- package/lib/commonjs/wallet-instance-attestation/index.js +3 -3
- package/lib/commonjs/wallet-instance-attestation/issuing.js +42 -60
- package/lib/commonjs/wallet-instance-attestation/issuing.js.map +1 -1
- package/lib/module/index.js +4 -6
- package/lib/module/index.js.map +1 -1
- package/lib/module/pid/index.js +1 -1
- package/lib/module/pid/index.js.map +1 -1
- package/lib/module/pid/issuing.js +152 -180
- package/lib/module/pid/issuing.js.map +1 -1
- package/lib/module/rp/__test__/index.test.js +3 -3
- package/lib/module/rp/__test__/index.test.js.map +1 -1
- package/lib/module/rp/index.js +141 -154
- package/lib/module/rp/index.js.map +1 -1
- package/lib/module/rp/types.js +0 -20
- package/lib/module/rp/types.js.map +1 -1
- package/lib/module/trust/index.js +19 -5
- package/lib/module/trust/index.js.map +1 -1
- package/lib/module/trust/types.js +100 -7
- package/lib/module/trust/types.js.map +1 -1
- package/lib/module/utils/crypto.js +40 -0
- package/lib/module/utils/crypto.js.map +1 -0
- package/lib/module/utils/dpop.js +13 -5
- package/lib/module/utils/dpop.js.map +1 -1
- package/lib/module/wallet-instance-attestation/index.js +2 -2
- package/lib/module/wallet-instance-attestation/index.js.map +1 -1
- package/lib/module/wallet-instance-attestation/issuing.js +40 -58
- package/lib/module/wallet-instance-attestation/issuing.js.map +1 -1
- package/lib/typescript/index.d.ts +4 -6
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/pid/index.d.ts +1 -1
- package/lib/typescript/pid/index.d.ts.map +1 -1
- package/lib/typescript/pid/issuing.d.ts +43 -88
- package/lib/typescript/pid/issuing.d.ts.map +1 -1
- package/lib/typescript/rp/index.d.ts +41 -87
- package/lib/typescript/rp/index.d.ts.map +1 -1
- package/lib/typescript/rp/types.d.ts +10 -906
- package/lib/typescript/rp/types.d.ts.map +1 -1
- package/lib/typescript/sd-jwt/index.d.ts +1 -1
- package/lib/typescript/sd-jwt/index.d.ts.map +1 -1
- package/lib/typescript/trust/index.d.ts +806 -3
- package/lib/typescript/trust/index.d.ts.map +1 -1
- package/lib/typescript/trust/types.d.ts +9655 -297
- package/lib/typescript/trust/types.d.ts.map +1 -1
- package/lib/typescript/utils/crypto.d.ts +10 -0
- package/lib/typescript/utils/crypto.d.ts.map +1 -0
- package/lib/typescript/utils/dpop.d.ts +10 -2
- package/lib/typescript/utils/dpop.d.ts.map +1 -1
- package/lib/typescript/wallet-instance-attestation/index.d.ts +2 -2
- package/lib/typescript/wallet-instance-attestation/index.d.ts.map +1 -1
- package/lib/typescript/wallet-instance-attestation/issuing.d.ts +18 -31
- package/lib/typescript/wallet-instance-attestation/issuing.d.ts.map +1 -1
- package/lib/typescript/wallet-instance-attestation/types.d.ts +4 -4
- package/package.json +2 -2
- package/src/index.ts +14 -13
- package/src/pid/index.ts +1 -1
- package/src/pid/issuing.ts +233 -232
- package/src/rp/__test__/index.test.ts +3 -3
- package/src/rp/index.ts +172 -194
- package/src/rp/types.ts +0 -24
- package/src/sd-jwt/index.ts +1 -1
- package/src/trust/index.ts +106 -5
- package/src/trust/types.ts +152 -34
- package/src/utils/crypto.ts +41 -0
- package/src/utils/dpop.ts +17 -7
- package/src/wallet-instance-attestation/index.ts +2 -2
- package/src/wallet-instance-attestation/issuing.ts +51 -63
- package/lib/commonjs/pid/metadata.js +0 -49
- package/lib/commonjs/pid/metadata.js.map +0 -1
- package/lib/module/pid/metadata.js +0 -41
- package/lib/module/pid/metadata.js.map +0 -1
- package/lib/typescript/pid/metadata.d.ts +0 -482
- package/lib/typescript/pid/metadata.d.ts.map +0 -1
- package/src/pid/metadata.ts +0 -46
package/lib/module/rp/index.js
CHANGED
@@ -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
|
3
|
+
import { QRCodePayload, RequestObject } from "./types";
|
4
4
|
import uuid from "react-native-uuid";
|
5
5
|
import { disclose } from "../sd-jwt";
|
6
|
-
import {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
async
|
53
|
-
|
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:
|
57
|
-
ath: await sha256ToBase64(
|
58
|
-
})
|
59
|
-
|
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 ${
|
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 =
|
84
|
+
const pubKey = rpEntityConfiguration.payload.metadata.wallet_relying_party.jwks.find(_ref2 => {
|
93
85
|
let {
|
94
86
|
kid
|
95
|
-
} =
|
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
|
97
|
+
const requestObject = RequestObject.parse({
|
106
98
|
header: responseJwt.protectedHeader,
|
107
99
|
payload: responseJwt.payload
|
108
100
|
});
|
109
|
-
return
|
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
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
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
|
-
//
|
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
|
-
|
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
|
147
|
-
nonce:
|
148
|
-
}).setAudience(
|
149
|
-
|
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
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
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 =
|
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:
|
201
|
+
state: requestObject.payload.state,
|
189
202
|
presentation_submission,
|
190
|
-
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
|
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","
|
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,IAA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AAE;MAC3DK,GAAG,EAAE,cAAc;MACnBC,GAAG,EAAE,eAAe;MACpBnD,GAAG,EAAEhD,GAAG,CAACgD;IACX,CAAC,CAAC,CAACoD,OAAO,CAACpG,GAAG,CAAC;IAEf,MAAMqG,QAAQ,GAAG,IAAIC,eAAe,CAAC;MAAEnE,QAAQ,EAAE8D;IAAU,CAAC,CAAC;IAC7D,MAAMM,IAAI,GAAGF,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"}
|
package/lib/module/rp/types.js
CHANGED
@@ -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":["
|
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":"../../../src","sources":["rp/types.ts"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,iBAAiB;AAC1C,OAAO,KAAKC,CAAC,MAAM,KAAK;AAGxB,OAAO,MAAMC,aAAa,GAAGD,CAAC,CAACE,MAAM,CAAC;EACpCC,MAAM,EAAEH,CAAC,CAACE,MAAM,CAAC;IACf;IACAE,GAAG,EAAEJ,CAAC,CAACK,OAAO,CAAC,KAAK,CAAC,CAACC,QAAQ,CAAC,CAAC;IAChCC,GAAG,EAAEP,CAAC,CAACQ,MAAM,CAAC,CAAC;IACfC,GAAG,EAAET,CAAC,CAACQ,MAAM,CAAC,CAAC;IACfE,WAAW,EAAEV,CAAC,CAACW,KAAK,CAACX,CAAC,CAACQ,MAAM,CAAC,CAAC;EACjC,CAAC,CAAC;EACFI,OAAO,EAAEZ,CAAC,CAACE,MAAM,CAAC;IAChBW,GAAG,EAAEb,CAAC,CAACQ,MAAM,CAAC,CAAC;IACfM,GAAG,EAAEf,QAAQ;IACbgB,GAAG,EAAEhB,QAAQ;IACbiB,KAAK,EAAEhB,CAAC,CAACQ,MAAM,CAAC,CAAC;IACjBS,KAAK,EAAEjB,CAAC,CAACQ,MAAM,CAAC,CAAC;IACjBU,YAAY,EAAElB,CAAC,CAACQ,MAAM,CAAC,CAAC;IACxBW,aAAa,EAAEnB,CAAC,CAACK,OAAO,CAAC,UAAU,CAAC;IACpCe,aAAa,EAAEpB,CAAC,CAACK,OAAO,CAAC,iBAAiB,CAAC;IAC3CgB,SAAS,EAAErB,CAAC,CAACQ,MAAM,CAAC,CAAC;IACrBc,gBAAgB,EAAEtB,CAAC,CAACK,OAAO,CAAC,WAAW,CAAC;IACxCkB,KAAK,EAAEvB,CAAC,CAACQ,MAAM,CAAC;EAClB,CAAC;AACH,CAAC,CAAC;AAGF,OAAO,MAAMgB,aAAa,GAAGxB,CAAC,CAACE,MAAM,CAAC;EACpCuB,QAAQ,EAAEzB,CAAC,CAACQ,MAAM,CAAC,CAAC;EACpBkB,QAAQ,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
|
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
|
-
|
24
|
+
|
25
|
+
async function fetchAndParseEntityConfiguration(entityBaseUrl, schema) {
|
17
26
|
let {
|
18
27
|
appFetch = fetch
|
19
|
-
} = arguments.length >
|
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
|
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","
|
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+B,EAC/BC,mBAAmB,QACd,SAAS;AAChB,SAASC,aAAa,QAAQ,iBAAiB;AAC/C,SAASC,gBAAgB,QAAQ,SAAS;AAE1C,SAASA,gBAAgB;;AAEzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAoCA,eAAeC,gCAAgCA,CAC7CC,aAAqB,EACrBC,MAK8B,EAM9B;EAAA,IALA;IACEC,QAAQ,GAAGC;EAGb,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAEN,MAAMG,YAAY,GAAI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