@pagopa/io-wallet-oid-federation 0.4.2 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -35,27 +35,33 @@ The primary function of this package is `createItWalletEntityConfiguration`. It
35
35
  Here is an example of how to create an Entity Configuration for a Credential Issuer:
36
36
 
37
37
  ```javascript
38
- import { createItWalletEntityConfiguration } from "@pagopa/io-wallet-oid-federation";
39
- import { JWK, SignCallback } from "@openid-federation/core";
38
+ import {
39
+ createItWalletEntityConfiguration,
40
+ SignCallback,
41
+ } from "@pagopa/io-wallet-oid-federation";
40
42
 
41
- // Define your entity's base URL and JWKS repository
43
+ // Define your entity's base URL and public JWK
42
44
  const baseURL = "https://issuer.example.it";
43
- const jwksRepository = {
44
- /* your JWKS implementation */
45
+ const publicJwk = {
46
+ kty: "EC",
47
+ crv: "P-256",
48
+ x: "...",
49
+ y: "...",
50
+ kid: "key-1",
45
51
  };
46
- const jwk = jwksRepository.get();
47
52
 
48
53
  // Define a signing callback that uses your private key
49
54
  const signJwtCallback: SignCallback = async ({ toBeSigned, jwk }) => {
50
- // Your signing logic here.
51
- ...
55
+ // Your signing logic here using the jwk parameter
56
+ // Return the signature as Uint8Array
57
+ // ...
52
58
  };
53
59
 
54
60
  // Create the Entity Configuration JWT
55
61
  const entityConfigurationJwt = await createItWalletEntityConfiguration({
56
62
  header: {
57
63
  alg: "ES256",
58
- kid: jwk.public.kid,
64
+ kid: publicJwk.kid,
59
65
  typ: "entity-statement+jwt",
60
66
  },
61
67
  claims: {
@@ -64,7 +70,7 @@ const entityConfigurationJwt = await createItWalletEntityConfiguration({
64
70
  exp: Math.floor(Date.now() / 1000) + 3600, // Expires in 1 hour
65
71
  iat: Math.floor(Date.now() / 1000),
66
72
  jwks: {
67
- keys: [jwk.public],
73
+ keys: [publicJwk],
68
74
  },
69
75
  authority_hints: [`${baseURL}/trust_anchor`],
70
76
  metadata: {
@@ -91,63 +97,60 @@ console.log(entityConfigurationJwt);
91
97
  // This JWT can now be served at `https://issuer.example.it/.well-known/openid-federation`
92
98
  ```
93
99
 
94
- ### Parsing and Validating an Entity Configuration
100
+ ## API Reference
95
101
 
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.
102
+ ### Functions
97
103
 
98
- ```javascript
99
- import {
100
- itWalletEntityConfigurationClaimsSchema,
101
- parseWithErrorHandling,
102
- } from "@pagopa/io-wallet-oid-federation";
104
+ - **`createItWalletEntityConfiguration(options)`**: Creates and signs an Entity Configuration JWT.
105
+ - **Parameters**:
106
+ - `options.header`: JWT header with algorithm, key id, and type
107
+ - `options.claims`: Entity configuration claims (issuer, subject, metadata, etc.)
108
+ - `options.signJwtCallback`: Callback function to sign the JWT
109
+ - **Returns**: A signed JWT string
103
110
 
104
- // Assume `federationResponsePayload` is the decoded payload of an Entity Configuration JWT
105
- const federationResponsePayload = {
106
- /* ... decoded claims ... */
107
- };
111
+ ### Types
108
112
 
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
- ```
113
+ - **`SignCallback`**: Function type for signing JWT tokens
114
+ ```typescript
115
+ type SignCallback = (options: {
116
+ jwk: JsonWebKey;
117
+ toBeSigned: Uint8Array;
118
+ }) => Promise<Uint8Array>;
119
+ ```
121
120
 
122
- ## API Reference
121
+ - **`JsonWebKey`**: Type for JSON Web Key objects
123
122
 
124
- ### Functions
123
+ - **`ItWalletEntityConfigurationClaimsOptions`**: Input type for entity configuration claims
124
+
125
+ - **`ItWalletEntityConfigurationClaims`**: Output type for entity configuration claims
125
126
 
126
- `createItWalletEntityConfiguration(options)`: Creates and signs an Entity Configuration JWT.
127
+ - **`ItWalletEntityStatementClaimsOptions`**: Input type for entity statement claims
127
128
 
128
- `parseWithErrorHandling(schema, data, message)`: Parses data against a Zod schema and throws a formatted ValidationError on failure.
129
+ - **`ItWalletEntityStatementClaims`**: Output type for entity statement claims
129
130
 
130
131
  ### Zod Schemas
131
132
 
132
133
  This package exports a comprehensive set of Zod schemas to validate all parts of the federation artifacts.
133
134
 
134
- - JWK Schemas:
135
- - `JWK`: Validates a single JSON Web Key.
135
+ #### JWK Schemas:
136
+ - **`jsonWebKeySchema`**: Validates a single JSON Web Key (includes support for x5c certificate chain)
137
+
138
+ - **`jsonWebKeySetSchema`**: Validates a JSON Web Key Set
136
139
 
137
- - `JWKS`: Validates a JSON Web Key Set.
140
+ #### Metadata Schemas:
141
+ - **`itWalletFederationEntityMetadata`**: For `federation_entity` metadata
138
142
 
139
- - Metadata Schemas:
140
- - `itWalletFederationEntityMetadata`: For `federation_entity` metadata.
143
+ - **`itWalletProviderEntityMetadata`**: For `wallet_provider` metadata
141
144
 
142
- - `itWalletProviderEntityMetadata`: For `wallet_provider` metadata.
145
+ - **`itWalletCredentialIssuerMetadata`**: For `openid_credential_issuer` metadata
143
146
 
144
- - `itWalletCredentialIssuerMetadata`: For `openid_credential_issuer` metadata.
147
+ - **`itWalletCredentialVerifierMetadata`**: For `openid_credential_verifier` metadata
145
148
 
146
- - `itWalletCredentialVerifierMetadata`: For `openid_credential_verifier` metadata.
149
+ - **`itWalletAuthorizationServerMetadata`**: For `oauth_authorization_server` metadata
147
150
 
148
- - `itWalletAuthorizationServerMetadata`: For `oauth_authorization_server` metadata.
151
+ - **`itWalletMetadataSchema`**: Combined metadata schema for all entity types
149
152
 
150
- - Claims Schemas:
151
- - `itWalletEntityStatementClaimsSchema`: Validates the claims within an Entity Statement.
153
+ #### Claims Schemas:
154
+ - **`itWalletEntityStatementClaimsSchema`**: Validates the claims within an Entity Statement
152
155
 
153
- - `itWalletEntityConfigurationClaimsSchema`: Validates the claims for an Entity Configuration (where iss must equal sub).
156
+ - **`itWalletEntityConfigurationClaimsSchema`**: Validates the claims for an Entity Configuration (where iss must equal sub)