@pagopa/io-wallet-oid-federation 0.1.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 +153 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
## @pagopa/io-wallet-oid-federation
|
|
2
|
+
|
|
3
|
+
This package provides a set of tools, schemas, and utilities to work with the **IT Wallet OpenID Federation** specification. It is designed to help developers create and validate artifacts such as Entity Configurations and Entity Statements in a compliant and secure manner.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
To install the package, use your preferred package manager:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# Using pnpm
|
|
11
|
+
pnpm add @pagopa/io-wallet-oid-federation
|
|
12
|
+
|
|
13
|
+
# Using yarn
|
|
14
|
+
yarn add @pagopa/io-wallet-oid-federation
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Core Concepts
|
|
18
|
+
|
|
19
|
+
OpenID Federation is a protocol that allows different entities (like Wallet Providers, Credential Issuers, and Verifiers) to establish trust with each other in a decentralized way. Instead of relying on a central authority, each entity publishes its own metadata in a self-signed JWT document called an Entity Configuration.
|
|
20
|
+
|
|
21
|
+
This package provides the necessary tools to:
|
|
22
|
+
|
|
23
|
+
- **Define Metadata**: Use pre-built Zod schemas to define the metadata for different entity types (wallet_provider, openid_credential_issuer, etc.).
|
|
24
|
+
|
|
25
|
+
- **Create Entity Configurations**: Generate a valid, signed JWT that represents your entity's configuration, which can then be published for other entities to discover and trust.
|
|
26
|
+
|
|
27
|
+
- **Validate Artifacts**: Ensure that incoming federation documents are correctly structured and compliant with the IT Wallet specification.
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
### Creating an Entity Configuration
|
|
32
|
+
|
|
33
|
+
The primary function of this package is `createItWalletEntityConfiguration`. It takes your entity's claims and a signing callback to produce a signed JWT.
|
|
34
|
+
|
|
35
|
+
Here is an example of how to create an Entity Configuration for a Credential Issuer:
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
38
|
+
import { createItWalletEntityConfiguration } from "@pagopa/io-wallet-oid-federation";
|
|
39
|
+
import { JWK, SignCallback } from "@openid-federation/core";
|
|
40
|
+
|
|
41
|
+
// Define your entity's base URL and JWKS repository
|
|
42
|
+
const baseURL = "https://issuer.example.it";
|
|
43
|
+
const jwksRepository = {
|
|
44
|
+
/* your JWKS implementation */
|
|
45
|
+
};
|
|
46
|
+
const jwk = jwksRepository.get();
|
|
47
|
+
|
|
48
|
+
// Define a signing callback that uses your private key
|
|
49
|
+
const signJwtCallback: SignCallback = async ({ toBeSigned, jwk }) => {
|
|
50
|
+
// Your signing logic here.
|
|
51
|
+
...
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// Create the Entity Configuration JWT
|
|
55
|
+
const entityConfigurationJwt = await createItWalletEntityConfiguration({
|
|
56
|
+
header: {
|
|
57
|
+
alg: "ES256",
|
|
58
|
+
kid: jwk.public.kid,
|
|
59
|
+
typ: "entity-statement+jwt",
|
|
60
|
+
},
|
|
61
|
+
claims: {
|
|
62
|
+
iss: baseURL,
|
|
63
|
+
sub: baseURL,
|
|
64
|
+
exp: Math.floor(Date.now() / 1000) + 3600, // Expires in 1 hour
|
|
65
|
+
iat: Math.floor(Date.now() / 1000),
|
|
66
|
+
jwks: {
|
|
67
|
+
keys: [jwk.public],
|
|
68
|
+
},
|
|
69
|
+
authority_hints: [`${baseURL}/trust_anchor`],
|
|
70
|
+
metadata: {
|
|
71
|
+
federation_entity: {
|
|
72
|
+
organization_name: "PagoPa S.p.A.",
|
|
73
|
+
homepage_uri: "https://io.italia.it",
|
|
74
|
+
policy_uri: "https://io.italia.it/privacy-policy",
|
|
75
|
+
logo_uri: "https://io.italia.it/assets/img/io-it-logo-blue.svg",
|
|
76
|
+
contacts: ["info@pagopa.it"],
|
|
77
|
+
federation_resolve_endpoint: `${baseURL}/resolve`,
|
|
78
|
+
},
|
|
79
|
+
openid_credential_issuer: {
|
|
80
|
+
// ... your issuer-specific metadata
|
|
81
|
+
},
|
|
82
|
+
oauth_authorization_server: {
|
|
83
|
+
// ... your authorization server metadata
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
signJwtCallback,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
console.log(entityConfigurationJwt);
|
|
91
|
+
// This JWT can now be served at `https://issuer.example.it/.well-known/openid-federation`
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Parsing and Validating an Entity Configuration
|
|
95
|
+
|
|
96
|
+
After fetching an entity's configuration and decoding the JWT payload, you can use the exported Zod schemas to parse and validate its contents. The parseWithErrorHandling utility simplifies this process by providing clear error messages upon validation failure.
|
|
97
|
+
|
|
98
|
+
```javascript
|
|
99
|
+
import {
|
|
100
|
+
itWalletEntityConfigurationClaimsSchema,
|
|
101
|
+
parseWithErrorHandling,
|
|
102
|
+
} from "@pagopa/io-wallet-oid-federation";
|
|
103
|
+
|
|
104
|
+
// Assume `federationResponsePayload` is the decoded payload of an Entity Configuration JWT
|
|
105
|
+
const federationResponsePayload = {
|
|
106
|
+
/* ... decoded claims ... */
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
const federationEntity = parseWithErrorHandling(
|
|
111
|
+
itWalletEntityConfigurationClaimsSchema,
|
|
112
|
+
federationResponsePayload,
|
|
113
|
+
"invalid Federation Entity provided",
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
console.log("Validation successful:", federationEntity);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error("Validation failed:", error.message);
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## API Reference
|
|
123
|
+
|
|
124
|
+
### Functions
|
|
125
|
+
|
|
126
|
+
`createItWalletEntityConfiguration(options)`: Creates and signs an Entity Configuration JWT.
|
|
127
|
+
|
|
128
|
+
`parseWithErrorHandling(schema, data, message)`: Parses data against a Zod schema and throws a formatted ValidationError on failure.
|
|
129
|
+
|
|
130
|
+
### Zod Schemas
|
|
131
|
+
|
|
132
|
+
This package exports a comprehensive set of Zod schemas to validate all parts of the federation artifacts.
|
|
133
|
+
|
|
134
|
+
- JWK Schemas:
|
|
135
|
+
- `JWK`: Validates a single JSON Web Key.
|
|
136
|
+
|
|
137
|
+
- `JWKS`: Validates a JSON Web Key Set.
|
|
138
|
+
|
|
139
|
+
- Metadata Schemas:
|
|
140
|
+
- `itWalletFederationEntityMetadata`: For `federation_entity` metadata.
|
|
141
|
+
|
|
142
|
+
- `itWalletProviderEntityMetadata`: For `wallet_provider` metadata.
|
|
143
|
+
|
|
144
|
+
- `itWalletCredentialIssuerMetadata`: For `openid_credential_issuer` metadata.
|
|
145
|
+
|
|
146
|
+
- `itWalletCredentialVerifierMetadata`: For `openid_credential_verifier` metadata.
|
|
147
|
+
|
|
148
|
+
- `itWalletAuthorizationServerMetadata`: For `oauth_authorization_server` metadata.
|
|
149
|
+
|
|
150
|
+
- Claims Schemas:
|
|
151
|
+
- `itWalletEntityStatementClaimsSchema`: Validates the claims within an Entity Statement.
|
|
152
|
+
|
|
153
|
+
- `itWalletEntityConfigurationClaimsSchema`: Validates the claims for an Entity Configuration (where iss must equal sub).
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pagopa/io-wallet-oid-federation",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"files": [
|
|
5
|
+
"dist"
|
|
6
|
+
],
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./package.json": "./package.json"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/pagopa/io-wallet-sdk/tree/main/packages/oid-federation",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/pagopa/io-wallet-sdk",
|
|
20
|
+
"directory": "packages/oid-federation"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@openid-federation/core": "^0.2.0",
|
|
24
|
+
"@openid4vc/utils": "^0.2.0",
|
|
25
|
+
"zod": "^3.24.2"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"js-base64": "^3.7.8"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean --sourcemap"
|
|
32
|
+
},
|
|
33
|
+
"main": "./dist/index.js",
|
|
34
|
+
"module": "./dist/index.mjs",
|
|
35
|
+
"types": "./dist/index.d.ts"
|
|
36
|
+
}
|