@pagopa/io-react-native-wallet 2.2.0 → 2.4.0
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.
- package/README.md +4 -3
- package/lib/commonjs/credential/index.js +3 -1
- package/lib/commonjs/credential/index.js.map +1 -1
- package/lib/commonjs/credential/issuance/03-start-user-authorization.js +24 -6
- package/lib/commonjs/credential/issuance/03-start-user-authorization.js.map +1 -1
- package/lib/commonjs/credential/issuance/04-complete-user-authorization.js +26 -2
- package/lib/commonjs/credential/issuance/04-complete-user-authorization.js.map +1 -1
- package/lib/commonjs/credential/issuance/README.md +155 -18
- package/lib/commonjs/credential/issuance/index.js +9 -1
- package/lib/commonjs/credential/issuance/index.js.map +1 -1
- package/lib/commonjs/credential/issuance/mrtd-pop/01-verify-and-parse-challenge-info.js +57 -0
- package/lib/commonjs/credential/issuance/mrtd-pop/01-verify-and-parse-challenge-info.js.map +1 -0
- package/lib/commonjs/credential/issuance/mrtd-pop/02-init-challenge.js +61 -0
- package/lib/commonjs/credential/issuance/mrtd-pop/02-init-challenge.js.map +1 -0
- package/lib/commonjs/credential/issuance/mrtd-pop/03-validate-challenge.js +95 -0
- package/lib/commonjs/credential/issuance/mrtd-pop/03-validate-challenge.js.map +1 -0
- package/lib/commonjs/credential/issuance/mrtd-pop/README.md +92 -0
- package/lib/commonjs/credential/issuance/mrtd-pop/index.js +33 -0
- package/lib/commonjs/credential/issuance/mrtd-pop/index.js.map +1 -0
- package/lib/commonjs/credential/issuance/mrtd-pop/types.js +57 -0
- package/lib/commonjs/credential/issuance/mrtd-pop/types.js.map +1 -0
- package/lib/commonjs/credential/offer/01-start-flow.js +75 -0
- package/lib/commonjs/credential/offer/01-start-flow.js.map +1 -0
- package/lib/commonjs/credential/offer/02-fetch-credential-offer.js +45 -0
- package/lib/commonjs/credential/offer/02-fetch-credential-offer.js.map +1 -0
- package/lib/commonjs/credential/offer/README.md +174 -0
- package/lib/commonjs/credential/offer/errors.js +22 -0
- package/lib/commonjs/credential/offer/errors.js.map +1 -0
- package/lib/commonjs/credential/offer/index.js +25 -0
- package/lib/commonjs/credential/offer/index.js.map +1 -0
- package/lib/commonjs/credential/offer/types.js +51 -0
- package/lib/commonjs/credential/offer/types.js.map +1 -0
- package/lib/commonjs/credential/presentation/01-start-flow.js +1 -1
- package/lib/commonjs/credentials-catalogue/README.md +15 -0
- package/lib/commonjs/credentials-catalogue/fetch-and-parse-catalogue.js +42 -0
- package/lib/commonjs/credentials-catalogue/fetch-and-parse-catalogue.js.map +1 -0
- package/lib/commonjs/credentials-catalogue/index.js +13 -0
- package/lib/commonjs/credentials-catalogue/index.js.map +1 -0
- package/lib/commonjs/credentials-catalogue/types.js +99 -0
- package/lib/commonjs/credentials-catalogue/types.js.map +1 -0
- package/lib/commonjs/index.js +3 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/auth.js +9 -1
- package/lib/commonjs/utils/auth.js.map +1 -1
- package/lib/commonjs/utils/par.js +7 -2
- package/lib/commonjs/utils/par.js.map +1 -1
- package/lib/commonjs/utils/zod.js +28 -0
- package/lib/commonjs/utils/zod.js.map +1 -0
- package/lib/module/credential/index.js +2 -1
- package/lib/module/credential/index.js.map +1 -1
- package/lib/module/credential/issuance/03-start-user-authorization.js +24 -6
- package/lib/module/credential/issuance/03-start-user-authorization.js.map +1 -1
- package/lib/module/credential/issuance/04-complete-user-authorization.js +25 -2
- package/lib/module/credential/issuance/04-complete-user-authorization.js.map +1 -1
- package/lib/module/credential/issuance/README.md +155 -18
- package/lib/module/credential/issuance/index.js +3 -2
- package/lib/module/credential/issuance/index.js.map +1 -1
- package/lib/module/credential/issuance/mrtd-pop/01-verify-and-parse-challenge-info.js +50 -0
- package/lib/module/credential/issuance/mrtd-pop/01-verify-and-parse-challenge-info.js.map +1 -0
- package/lib/module/credential/issuance/mrtd-pop/02-init-challenge.js +52 -0
- package/lib/module/credential/issuance/mrtd-pop/02-init-challenge.js.map +1 -0
- package/lib/module/credential/issuance/mrtd-pop/03-validate-challenge.js +85 -0
- package/lib/module/credential/issuance/mrtd-pop/03-validate-challenge.js.map +1 -0
- package/lib/module/credential/issuance/mrtd-pop/README.md +92 -0
- package/lib/module/credential/issuance/mrtd-pop/index.js +5 -0
- package/lib/module/credential/issuance/mrtd-pop/index.js.map +1 -0
- package/lib/module/credential/issuance/mrtd-pop/types.js +46 -0
- package/lib/module/credential/issuance/mrtd-pop/types.js.map +1 -0
- package/lib/module/credential/offer/01-start-flow.js +66 -0
- package/lib/module/credential/offer/01-start-flow.js.map +1 -0
- package/lib/module/credential/offer/02-fetch-credential-offer.js +38 -0
- package/lib/module/credential/offer/02-fetch-credential-offer.js.map +1 -0
- package/lib/module/credential/offer/README.md +174 -0
- package/lib/module/credential/offer/errors.js +14 -0
- package/lib/module/credential/offer/errors.js.map +1 -0
- package/lib/module/credential/offer/index.js +5 -0
- package/lib/module/credential/offer/index.js.map +1 -0
- package/lib/module/credential/offer/types.js +41 -0
- package/lib/module/credential/offer/types.js.map +1 -0
- package/lib/module/credential/presentation/01-start-flow.js +1 -1
- package/lib/module/credentials-catalogue/README.md +15 -0
- package/lib/module/credentials-catalogue/fetch-and-parse-catalogue.js +35 -0
- package/lib/module/credentials-catalogue/fetch-and-parse-catalogue.js.map +1 -0
- package/lib/module/credentials-catalogue/index.js +2 -0
- package/lib/module/credentials-catalogue/index.js.map +1 -0
- package/lib/module/credentials-catalogue/types.js +89 -0
- package/lib/module/credentials-catalogue/types.js.map +1 -0
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/auth.js +8 -0
- package/lib/module/utils/auth.js.map +1 -1
- package/lib/module/utils/par.js +7 -2
- package/lib/module/utils/par.js.map +1 -1
- package/lib/module/utils/zod.js +20 -0
- package/lib/module/utils/zod.js.map +1 -0
- package/lib/typescript/credential/index.d.ts +2 -1
- package/lib/typescript/credential/index.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/01-start-flow.d.ts +1 -1
- package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts +14 -4
- package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts +9 -1
- package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/index.d.ts +4 -3
- package/lib/typescript/credential/issuance/index.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/mrtd-pop/01-verify-and-parse-challenge-info.d.ts +25 -0
- package/lib/typescript/credential/issuance/mrtd-pop/01-verify-and-parse-challenge-info.d.ts.map +1 -0
- package/lib/typescript/credential/issuance/mrtd-pop/02-init-challenge.d.ts +23 -0
- package/lib/typescript/credential/issuance/mrtd-pop/02-init-challenge.d.ts.map +1 -0
- package/lib/typescript/credential/issuance/mrtd-pop/03-validate-challenge.d.ts +39 -0
- package/lib/typescript/credential/issuance/mrtd-pop/03-validate-challenge.d.ts.map +1 -0
- package/lib/typescript/credential/issuance/mrtd-pop/index.d.ts +7 -0
- package/lib/typescript/credential/issuance/mrtd-pop/index.d.ts.map +1 -0
- package/lib/typescript/credential/issuance/mrtd-pop/types.d.ts +201 -0
- package/lib/typescript/credential/issuance/mrtd-pop/types.d.ts.map +1 -0
- package/lib/typescript/credential/offer/01-start-flow.d.ts +172 -0
- package/lib/typescript/credential/offer/01-start-flow.d.ts.map +1 -0
- package/lib/typescript/credential/offer/02-fetch-credential-offer.d.ts +20 -0
- package/lib/typescript/credential/offer/02-fetch-credential-offer.d.ts.map +1 -0
- package/lib/typescript/credential/offer/errors.d.ts +10 -0
- package/lib/typescript/credential/offer/errors.d.ts.map +1 -0
- package/lib/typescript/credential/offer/index.d.ts +7 -0
- package/lib/typescript/credential/offer/index.d.ts.map +1 -0
- package/lib/typescript/credential/offer/types.d.ts +264 -0
- package/lib/typescript/credential/offer/types.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/01-start-flow.d.ts +1 -1
- package/lib/typescript/credentials-catalogue/fetch-and-parse-catalogue.d.ts +15 -0
- package/lib/typescript/credentials-catalogue/fetch-and-parse-catalogue.d.ts.map +1 -0
- package/lib/typescript/credentials-catalogue/index.d.ts +3 -0
- package/lib/typescript/credentials-catalogue/index.d.ts.map +1 -0
- package/lib/typescript/credentials-catalogue/types.d.ts +844 -0
- package/lib/typescript/credentials-catalogue/types.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +2 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/utils/auth.d.ts +11 -0
- package/lib/typescript/utils/auth.d.ts.map +1 -1
- package/lib/typescript/utils/par.d.ts +34 -4
- package/lib/typescript/utils/par.d.ts.map +1 -1
- package/lib/typescript/utils/zod.d.ts +15 -0
- package/lib/typescript/utils/zod.d.ts.map +1 -0
- package/package.json +21 -2
- package/src/credential/index.ts +2 -1
- package/src/credential/issuance/01-start-flow.ts +1 -1
- package/src/credential/issuance/03-start-user-authorization.ts +30 -7
- package/src/credential/issuance/04-complete-user-authorization.ts +43 -1
- package/src/credential/issuance/README.md +155 -18
- package/src/credential/issuance/index.ts +7 -1
- package/src/credential/issuance/mrtd-pop/01-verify-and-parse-challenge-info.ts +70 -0
- package/src/credential/issuance/mrtd-pop/02-init-challenge.ts +82 -0
- package/src/credential/issuance/mrtd-pop/03-validate-challenge.ts +140 -0
- package/src/credential/issuance/mrtd-pop/README.md +92 -0
- package/src/credential/issuance/mrtd-pop/index.ts +27 -0
- package/src/credential/issuance/mrtd-pop/types.ts +65 -0
- package/src/credential/offer/01-start-flow.ts +89 -0
- package/src/credential/offer/02-fetch-credential-offer.ts +54 -0
- package/src/credential/offer/README.md +174 -0
- package/src/credential/offer/errors.ts +17 -0
- package/src/credential/offer/index.ts +16 -0
- package/src/credential/offer/types.ts +59 -0
- package/src/credential/presentation/01-start-flow.ts +1 -1
- package/src/credentials-catalogue/README.md +15 -0
- package/src/credentials-catalogue/fetch-and-parse-catalogue.ts +54 -0
- package/src/credentials-catalogue/index.ts +2 -0
- package/src/credentials-catalogue/types.ts +97 -0
- package/src/index.ts +2 -0
- package/src/utils/auth.ts +12 -0
- package/src/utils/par.ts +12 -4
- package/src/utils/zod.ts +28 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# Credential Offer
|
|
2
|
+
|
|
3
|
+
This flow handles the initial step of credential issuance by processing Credential Offers from Credential Issuers. The Credential Offer contains information about what credentials are available and how they can be obtained. Each step in the flow is imported from the related file which is named with a sequential number.
|
|
4
|
+
|
|
5
|
+
A Credential Offer can be received by the Wallet in two ways: **by value** (complete offer embedded in the URL) or **by reference** (URL pointing to the offer endpoint). The offer specifies which credentials are available and what authorization flows are supported by the issuer.
|
|
6
|
+
|
|
7
|
+
The implementation follows the [OpenID for Verifiable Credential Issuance 1.0](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html#name-credential-offer-endpoint) specification and supports both Authorization Code flow and Pre-Authorized Code flow.
|
|
8
|
+
|
|
9
|
+
## Sequence Diagram
|
|
10
|
+
|
|
11
|
+
```mermaid
|
|
12
|
+
sequenceDiagram
|
|
13
|
+
autonumber
|
|
14
|
+
participant U as User
|
|
15
|
+
participant W as Wallet
|
|
16
|
+
participant CI as Credential Issuer
|
|
17
|
+
|
|
18
|
+
CI->>U: QR Code / Deep Link with Credential Offer
|
|
19
|
+
U->>W: Scan QR / Click Link
|
|
20
|
+
W->>W: startFlowFromQR: Parse offer parameters
|
|
21
|
+
alt Credential Offer by Reference
|
|
22
|
+
W->>CI: fetchCredentialOffer: Fetch offer from URI
|
|
23
|
+
CI->>W: Return Credential Offer JSON
|
|
24
|
+
end
|
|
25
|
+
W->>W: Validate Credential Offer schema
|
|
26
|
+
W->>W: Determine available grant types
|
|
27
|
+
Note over W: Flow continues with credential issuance
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Grant Types
|
|
31
|
+
|
|
32
|
+
The Credential Offer supports two OAuth 2.0 grant types that determine how authorization is handled:
|
|
33
|
+
|
|
34
|
+
### Authorization Code Flow
|
|
35
|
+
|
|
36
|
+
Used for interactive flows where user authentication and consent are required at the Authorization Server.
|
|
37
|
+
|
|
38
|
+
- **`issuer_state`** (optional): Binds the authorization request to a specific issuer context
|
|
39
|
+
- **`authorization_server`** (optional): Identifies which authorization server to use when multiple are available
|
|
40
|
+
|
|
41
|
+
### Pre-Authorized Code Flow
|
|
42
|
+
|
|
43
|
+
Used when the user has already been authenticated and authorized out-of-band. The issuer provides a pre-authorized code that can be exchanged directly for credentials.
|
|
44
|
+
|
|
45
|
+
- **`pre-authorized_code`**: Short-lived single-use authorization code
|
|
46
|
+
- **`tx_code`** (optional): Additional transaction code requirements for security
|
|
47
|
+
- **`authorization_server`** (optional): Identifies which authorization server to use
|
|
48
|
+
|
|
49
|
+
## Transaction Code Requirements
|
|
50
|
+
|
|
51
|
+
When a transaction code is required for Pre-Authorized Code flow, the following parameters control the user experience:
|
|
52
|
+
|
|
53
|
+
| Parameter | Type | Description |
|
|
54
|
+
| ------------- | ----------------------- | ---------------------------------------------------- |
|
|
55
|
+
| `input_mode` | `"numeric"` \| `"text"` | Character set for the code (default: `"numeric"`) |
|
|
56
|
+
| `length` | number | Expected code length to optimize input UI |
|
|
57
|
+
| `description` | string | User guidance (max 300 chars) for obtaining the code |
|
|
58
|
+
|
|
59
|
+
## Credential Offer Transmission
|
|
60
|
+
|
|
61
|
+
### By Value
|
|
62
|
+
|
|
63
|
+
The complete Credential Offer is embedded in the URL parameter:
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
openid-credential-offer://?credential_offer=%7B%22credential_issuer%22...
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### By Reference
|
|
70
|
+
|
|
71
|
+
A URL points to an endpoint serving the Credential Offer:
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
openid-credential-offer://?credential_offer_uri=https%3A%2F%2Fserver.example.com%2Foffer
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
When using by reference, the Wallet fetches the offer via HTTP GET with `Accept: application/json`.
|
|
78
|
+
|
|
79
|
+
## Mapped Results
|
|
80
|
+
|
|
81
|
+
The following errors are mapped during credential offer processing:
|
|
82
|
+
|
|
83
|
+
| Error | Description |
|
|
84
|
+
| ----------------------------- | ---------------------------------------------------------------------------------- |
|
|
85
|
+
| `InvalidQRCodeError` | The QR code format is invalid or doesn't contain valid credential offer parameters |
|
|
86
|
+
| `InvalidCredentialOfferError` | The credential offer schema validation failed or contains invalid data |
|
|
87
|
+
|
|
88
|
+
## Examples
|
|
89
|
+
|
|
90
|
+
<details>
|
|
91
|
+
<summary>Credential Offer processing flow</summary>
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
// Parse QR code or deep link
|
|
95
|
+
const qrCode =
|
|
96
|
+
"openid-credential-offer://?credential_offer_uri=https%3A%2F%2Fissuer.example.com%2Foffer";
|
|
97
|
+
const { credential_offer_uri } = startFlowFromQR(qrCode);
|
|
98
|
+
|
|
99
|
+
// Fetch the credential offer if by reference
|
|
100
|
+
const offer = await fetchCredentialOffer(credential_offer_uri, { appFetch });
|
|
101
|
+
|
|
102
|
+
console.log(offer);
|
|
103
|
+
// {
|
|
104
|
+
// credential_issuer: "https://issuer.example.com",
|
|
105
|
+
// credential_configuration_ids: ["UniversityDegree", "DriverLicense"],
|
|
106
|
+
// grants: {
|
|
107
|
+
// authorization_code: {
|
|
108
|
+
// issuer_state: "xyz123"
|
|
109
|
+
// },
|
|
110
|
+
// "urn:ietf:params:oauth:grant-type:pre-authorized_code": {
|
|
111
|
+
// "pre-authorized_code": "SplxlOBeZQQYbYS6WxSbIA",
|
|
112
|
+
// tx_code: {
|
|
113
|
+
// length: 6,
|
|
114
|
+
// input_mode: "numeric",
|
|
115
|
+
// description: "Enter the code sent to your email"
|
|
116
|
+
// }
|
|
117
|
+
// }
|
|
118
|
+
// }
|
|
119
|
+
// }
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
</details>
|
|
123
|
+
|
|
124
|
+
<details>
|
|
125
|
+
<summary>Pre-Authorized Code with Transaction Code</summary>
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
const offer: CredentialOffer = {
|
|
129
|
+
credential_issuer: "https://university.example.edu",
|
|
130
|
+
credential_configuration_ids: ["DiplomaCredential"],
|
|
131
|
+
grants: {
|
|
132
|
+
"urn:ietf:params:oauth:grant-type:pre-authorized_code": {
|
|
133
|
+
"pre-authorized_code": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9",
|
|
134
|
+
tx_code: {
|
|
135
|
+
length: 4,
|
|
136
|
+
input_mode: "numeric",
|
|
137
|
+
description: "Check your email for the verification code",
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// The user would need to:
|
|
144
|
+
// 1. Check their email for a 4-digit numeric code
|
|
145
|
+
// 2. Enter it in the wallet when prompted
|
|
146
|
+
// 3. The wallet uses both pre-authorized_code and tx_code in the token request
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
</details>
|
|
150
|
+
|
|
151
|
+
<details>
|
|
152
|
+
<summary>Authorization Code Flow</summary>
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
const offer: CredentialOffer = {
|
|
156
|
+
credential_issuer: "https://dmv.example.gov",
|
|
157
|
+
credential_configuration_ids: ["org.iso.18013.5.1.mDL"],
|
|
158
|
+
grants: {
|
|
159
|
+
authorization_code: {
|
|
160
|
+
issuer_state: "af0ifjsldkj",
|
|
161
|
+
authorization_server: "https://auth.dmv.example.gov",
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// This would lead to:
|
|
167
|
+
// 1. User authentication at the authorization server
|
|
168
|
+
// 2. User consent for credential issuance
|
|
169
|
+
// 3. Authorization code returned to wallet
|
|
170
|
+
// 4. Wallet exchanges code for access token
|
|
171
|
+
// 5. Wallet uses access token to request credential
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
</details>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { IoWalletError } from "../../utils/errors";
|
|
2
|
+
|
|
3
|
+
export class InvalidCredentialOfferError extends IoWalletError {
|
|
4
|
+
code = "ERR_INVALID_CREDENTIAL_OFFER";
|
|
5
|
+
|
|
6
|
+
constructor(message?: string) {
|
|
7
|
+
super(message);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class InvalidQRCodeError extends IoWalletError {
|
|
12
|
+
code = "ERR_INVALID_QR_CODE";
|
|
13
|
+
|
|
14
|
+
constructor(message?: string) {
|
|
15
|
+
super(message);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { startFlowFromQR, type StartFlow } from "./01-start-flow";
|
|
2
|
+
import {
|
|
3
|
+
fetchCredentialOffer,
|
|
4
|
+
type GetCredentialOffer,
|
|
5
|
+
} from "./02-fetch-credential-offer";
|
|
6
|
+
import * as Errors from "./errors";
|
|
7
|
+
export type {
|
|
8
|
+
CredentialOffer,
|
|
9
|
+
Grants,
|
|
10
|
+
AuthorizationCodeGrant,
|
|
11
|
+
PreAuthorizedCodeGrant,
|
|
12
|
+
TransactionCode,
|
|
13
|
+
} from "./types";
|
|
14
|
+
|
|
15
|
+
export { Errors, fetchCredentialOffer, startFlowFromQR };
|
|
16
|
+
export type { GetCredentialOffer, StartFlow };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* OAuth 2.0 Authorization Code flow parameters.
|
|
5
|
+
*/
|
|
6
|
+
export const AuthorizationCodeGrantSchema = z.object({
|
|
7
|
+
issuer_state: z.string().optional(),
|
|
8
|
+
authorization_server: z.string().url().optional(),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export type AuthorizationCodeGrant = z.infer<
|
|
12
|
+
typeof AuthorizationCodeGrantSchema
|
|
13
|
+
>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Transaction Code requirements for Pre-Authorized Code flow.
|
|
17
|
+
*/
|
|
18
|
+
export const TransactionCodeSchema = z.object({
|
|
19
|
+
input_mode: z.enum(["numeric", "text"]).optional(),
|
|
20
|
+
length: z.number().int().positive().optional(),
|
|
21
|
+
description: z.string().max(300).optional(),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export type TransactionCode = z.infer<typeof TransactionCodeSchema>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Pre-Authorized Code flow parameters.
|
|
28
|
+
*/
|
|
29
|
+
export const PreAuthorizedCodeGrantSchema = z.object({
|
|
30
|
+
"pre-authorized_code": z.string(),
|
|
31
|
+
tx_code: TransactionCodeSchema.optional(),
|
|
32
|
+
authorization_server: z.string().url().optional(),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export type PreAuthorizedCodeGrant = z.infer<
|
|
36
|
+
typeof PreAuthorizedCodeGrantSchema
|
|
37
|
+
>;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Supported grant types for Credential Offer.
|
|
41
|
+
*/
|
|
42
|
+
export const GrantsSchema = z.object({
|
|
43
|
+
authorization_code: AuthorizationCodeGrantSchema.optional(),
|
|
44
|
+
"urn:ietf:params:oauth:grant-type:pre-authorized_code":
|
|
45
|
+
PreAuthorizedCodeGrantSchema.optional(),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
export type Grants = z.infer<typeof GrantsSchema>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Credential Offer object as defined in OpenID4VCI Section 4.1.1.
|
|
52
|
+
*/
|
|
53
|
+
export const CredentialOfferSchema = z.object({
|
|
54
|
+
credential_issuer: z.string().url(),
|
|
55
|
+
credential_configuration_ids: z.array(z.string()).min(1),
|
|
56
|
+
grants: GrantsSchema.optional(),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export type CredentialOffer = z.infer<typeof CredentialOfferSchema>;
|
|
@@ -11,7 +11,7 @@ export type PresentationParams = z.infer<typeof PresentationParams>;
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* The beginning of the presentation flow.
|
|
14
|
-
* To be implemented
|
|
14
|
+
* To be implemented according to the user touchpoint
|
|
15
15
|
*
|
|
16
16
|
* @param params Presentation parameters, depending on the starting touchpoint
|
|
17
17
|
* @returns The url for the Relying Party to connect with
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Digital Credentials Catalogue
|
|
2
|
+
|
|
3
|
+
Module that manages the [**Digital Credentials Catalogue**](https://italia.github.io/eid-wallet-it-docs/releases/1.1.0/en/registry-catalogue.html) published by the Trust Anchor.
|
|
4
|
+
|
|
5
|
+
The module allows:
|
|
6
|
+
- Fetching, verifying and parsing the catalogue's JWT.
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
// Fetch the catalogue
|
|
12
|
+
const TRUST_ANCHOR_BASE_URL = "https://pre.ta.wallet.ipzs.it";
|
|
13
|
+
const credentialsCatalogue =
|
|
14
|
+
await CredentialsCatalogue.fetchAndParseCatalogue(TRUST_ANCHOR_BASE_URL);
|
|
15
|
+
```
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { decode as decodeJwt, verify } from "@pagopa/io-react-native-jwt";
|
|
2
|
+
import { hasStatusOrThrow } from "../utils/misc";
|
|
3
|
+
import { IoWalletError } from "../utils/errors";
|
|
4
|
+
import { DigitalCredentialsCatalogue } from "./types";
|
|
5
|
+
import { getTrustAnchorEntityConfiguration } from "../trust/build-chain";
|
|
6
|
+
|
|
7
|
+
type GetCatalogueContext = {
|
|
8
|
+
appFetch?: GlobalFetch["fetch"];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Fetch and parse the Digital Credential Catalogue from the Trust Anchor.
|
|
13
|
+
* The catalogue's JWT signature is verified against the Trust Anchor's JWKs.
|
|
14
|
+
*
|
|
15
|
+
* @param trustAnchorUrl Base URL of the Trust Anchor
|
|
16
|
+
* @param context.appFetch (optional) fetch API implementation. Default: built-in fetch
|
|
17
|
+
* @returns The Digital Credential Catalogue payload
|
|
18
|
+
*/
|
|
19
|
+
export const fetchAndParseCatalogue = async (
|
|
20
|
+
trustAnchorBaseUrl: string,
|
|
21
|
+
{ appFetch = fetch }: GetCatalogueContext = {}
|
|
22
|
+
): Promise<DigitalCredentialsCatalogue["payload"]> => {
|
|
23
|
+
const trustAnchorConfig =
|
|
24
|
+
await getTrustAnchorEntityConfiguration(trustAnchorBaseUrl);
|
|
25
|
+
|
|
26
|
+
const responseText = await appFetch(
|
|
27
|
+
`${trustAnchorConfig.payload.sub}/.well-known/credential-catalogue`,
|
|
28
|
+
{ method: "GET" }
|
|
29
|
+
)
|
|
30
|
+
.then(hasStatusOrThrow(200))
|
|
31
|
+
.then((res) => res.text());
|
|
32
|
+
|
|
33
|
+
const responseJwt = decodeJwt(responseText);
|
|
34
|
+
const catalogueKid = responseJwt.protectedHeader.kid;
|
|
35
|
+
|
|
36
|
+
const trustAnchorJwk = trustAnchorConfig.payload.jwks.keys.find(
|
|
37
|
+
(jwk) => jwk.kid === catalogueKid
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
if (!trustAnchorJwk) {
|
|
41
|
+
throw new IoWalletError(
|
|
42
|
+
`Could not find JWK with kid ${catalogueKid} in Trust Anchor's Entity Configuration`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
await verify(responseText, trustAnchorJwk);
|
|
47
|
+
|
|
48
|
+
const parsedDigitalCredentialsCatalogue = DigitalCredentialsCatalogue.parse({
|
|
49
|
+
header: responseJwt.protectedHeader,
|
|
50
|
+
payload: responseJwt.payload,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return parsedDigitalCredentialsCatalogue.payload;
|
|
54
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { UnixTime } from "../sd-jwt/types";
|
|
3
|
+
|
|
4
|
+
const CredentialPurpose = z.object({
|
|
5
|
+
id: z.string(),
|
|
6
|
+
description: z.string(),
|
|
7
|
+
category: z.string(),
|
|
8
|
+
subcategory: z.string(),
|
|
9
|
+
claims_required: z.array(z.string()),
|
|
10
|
+
claim_recommended: z.array(z.string()),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const CredentialIssuer = z.object({
|
|
14
|
+
id: z.string(),
|
|
15
|
+
organization_name: z.string(),
|
|
16
|
+
organization_code: z.string(),
|
|
17
|
+
organization_country: z.string(),
|
|
18
|
+
contacts: z.array(z.string()).optional(),
|
|
19
|
+
homepage_uri: z.string().optional(),
|
|
20
|
+
logo_uri: z.string().optional(),
|
|
21
|
+
policy_uri: z.string().optional(),
|
|
22
|
+
tos_uri: z.string().optional(),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const AuthenticSource = z.object({
|
|
26
|
+
id: z.string(),
|
|
27
|
+
organization_name: z.string(),
|
|
28
|
+
organization_code: z.string(),
|
|
29
|
+
organization_country: z.string(),
|
|
30
|
+
source_type: z.enum(["public", "private"]),
|
|
31
|
+
contacts: z.array(z.string()).optional(),
|
|
32
|
+
homepage_uri: z.string().optional(),
|
|
33
|
+
logo_uri: z.string().optional(),
|
|
34
|
+
user_information: z.string().optional(),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const CredentialFormat = z.object({
|
|
38
|
+
configuration_id: z.string(),
|
|
39
|
+
format: z.enum(["dc+sd-jwt", "mso_mdoc"]),
|
|
40
|
+
vct: z.string().url().optional(),
|
|
41
|
+
docType: z.string().optional(),
|
|
42
|
+
schema_uri: z.string().url().optional(),
|
|
43
|
+
"schema_uri#integrity": z.string().optional(),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const Claim = z.object({
|
|
47
|
+
name: z.string(),
|
|
48
|
+
taxonomy_ref: z.string(),
|
|
49
|
+
display_name: z.string(),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export const DigitalCredential = z.object({
|
|
53
|
+
version: z.string(),
|
|
54
|
+
credential_type: z.string(),
|
|
55
|
+
legal_type: z.string(),
|
|
56
|
+
name: z.string(),
|
|
57
|
+
description: z.string(),
|
|
58
|
+
validity_info: z.object({
|
|
59
|
+
max_validity_days: z.number(),
|
|
60
|
+
status_methods: z.array(z.string()),
|
|
61
|
+
allowed_states: z.array(z.string()),
|
|
62
|
+
}),
|
|
63
|
+
authentication: z.object({
|
|
64
|
+
user_auth_required: z.boolean(),
|
|
65
|
+
min_loa: z.string(),
|
|
66
|
+
supported_eid_schemes: z.array(z.string()),
|
|
67
|
+
}),
|
|
68
|
+
purposes: z.array(CredentialPurpose),
|
|
69
|
+
issuers: z.array(CredentialIssuer),
|
|
70
|
+
authentic_sources: z.array(AuthenticSource),
|
|
71
|
+
formats: z.array(CredentialFormat),
|
|
72
|
+
claims: z.array(Claim),
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The Digital Credentials Catalogue published by the Trust Anchor
|
|
77
|
+
*
|
|
78
|
+
* @version 1.1.0
|
|
79
|
+
* @see https://italia.github.io/eid-wallet-it-docs/releases/1.1.0/en/registry-catalogue.html
|
|
80
|
+
*/
|
|
81
|
+
export const DigitalCredentialsCatalogue = z.object({
|
|
82
|
+
header: z.object({
|
|
83
|
+
typ: z.string(),
|
|
84
|
+
alg: z.string(),
|
|
85
|
+
kid: z.string(),
|
|
86
|
+
}),
|
|
87
|
+
payload: z.object({
|
|
88
|
+
catalog_version: z.string(),
|
|
89
|
+
taxonomy_uri: z.string().url(),
|
|
90
|
+
credentials: z.array(DigitalCredential),
|
|
91
|
+
iat: UnixTime,
|
|
92
|
+
exp: UnixTime,
|
|
93
|
+
}),
|
|
94
|
+
});
|
|
95
|
+
export type DigitalCredentialsCatalogue = z.infer<
|
|
96
|
+
typeof DigitalCredentialsCatalogue
|
|
97
|
+
>;
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { fixBase64EncodingOnKey } from "./utils/jwk";
|
|
|
5
5
|
import "react-native-url-polyfill/auto";
|
|
6
6
|
|
|
7
7
|
import * as Credential from "./credential";
|
|
8
|
+
import * as CredentialsCatalogue from "./credentials-catalogue";
|
|
8
9
|
import * as PID from "./pid";
|
|
9
10
|
import * as SdJwt from "./sd-jwt";
|
|
10
11
|
import * as Mdoc from "./mdoc";
|
|
@@ -22,6 +23,7 @@ export {
|
|
|
22
23
|
Mdoc,
|
|
23
24
|
PID,
|
|
24
25
|
Credential,
|
|
26
|
+
CredentialsCatalogue,
|
|
25
27
|
WalletInstanceAttestation,
|
|
26
28
|
WalletInstance,
|
|
27
29
|
Errors,
|
package/src/utils/auth.ts
CHANGED
|
@@ -35,3 +35,15 @@ export const AuthorizationErrorShape = z.object({
|
|
|
35
35
|
* Type of the identification result.
|
|
36
36
|
*/
|
|
37
37
|
export type AuthorizationResult = z.infer<typeof AuthorizationResultShape>;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* MRTD PoP Challenge Info response structure
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
export const AuthorizationChallengeResultShape = z.object({
|
|
44
|
+
challenge_info: z.string(),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export type AuthorizationChallengeResult = z.infer<
|
|
48
|
+
typeof AuthorizationChallengeResultShape
|
|
49
|
+
>;
|
package/src/utils/par.ts
CHANGED
|
@@ -12,10 +12,18 @@ import { IssuerResponseError } from "./errors";
|
|
|
12
12
|
import { LogLevel, Logger } from "./logging";
|
|
13
13
|
|
|
14
14
|
export type AuthorizationDetail = z.infer<typeof AuthorizationDetail>;
|
|
15
|
-
export const AuthorizationDetail = z.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
export const AuthorizationDetail = z.union([
|
|
16
|
+
z.object({
|
|
17
|
+
type: z.literal("openid_credential"),
|
|
18
|
+
credential_configuration_id: z.string(),
|
|
19
|
+
}),
|
|
20
|
+
z.object({
|
|
21
|
+
type: z.literal("it_l2+document_proof"),
|
|
22
|
+
idphinting: z.string(),
|
|
23
|
+
challenge_method: z.literal("mrtd+ias"),
|
|
24
|
+
challenge_redirect_uri: z.string(),
|
|
25
|
+
}),
|
|
26
|
+
]);
|
|
19
27
|
|
|
20
28
|
export type AuthorizationDetails = z.infer<typeof AuthorizationDetails>;
|
|
21
29
|
export const AuthorizationDetails = z.array(AuthorizationDetail);
|
package/src/utils/zod.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @see https://github.com/JacobWeisenburger/zod_utilz/blob/main/src/stringToJSON.ts
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
|
|
7
|
+
const literalSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]);
|
|
8
|
+
|
|
9
|
+
type Literal = z.infer<typeof literalSchema>;
|
|
10
|
+
|
|
11
|
+
type Json = Literal | { [key: string]: Json } | Json[];
|
|
12
|
+
|
|
13
|
+
const jsonSchema: z.ZodType<Json> = z.lazy(() =>
|
|
14
|
+
z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)])
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
export const json = () => jsonSchema;
|
|
18
|
+
|
|
19
|
+
export const stringToJSONSchema = z
|
|
20
|
+
.string()
|
|
21
|
+
.transform((str, ctx): z.infer<ReturnType<typeof json>> => {
|
|
22
|
+
try {
|
|
23
|
+
return JSON.parse(str);
|
|
24
|
+
} catch (e) {
|
|
25
|
+
ctx.addIssue({ code: "custom", message: "Invalid JSON" });
|
|
26
|
+
return z.NEVER;
|
|
27
|
+
}
|
|
28
|
+
});
|