@pagopa/io-react-native-wallet 2.0.0-next.1 → 2.0.0-next.2

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.
Files changed (58) hide show
  1. package/lib/commonjs/credential/issuance/02-evaluate-issuer-trust.js +2 -2
  2. package/lib/commonjs/credential/issuance/02-evaluate-issuer-trust.js.map +1 -1
  3. package/lib/commonjs/credential/presentation/02-evaluate-rp-trust.js +2 -2
  4. package/lib/commonjs/credential/presentation/02-evaluate-rp-trust.js.map +1 -1
  5. package/lib/commonjs/credential/presentation/05-verify-request-object.js.map +1 -1
  6. package/lib/commonjs/credential/presentation/08-send-authorization-response.js.map +1 -1
  7. package/lib/commonjs/trust/build-chain.js +252 -0
  8. package/lib/commonjs/trust/build-chain.js.map +1 -0
  9. package/lib/commonjs/trust/index.js +11 -282
  10. package/lib/commonjs/trust/index.js.map +1 -1
  11. package/lib/commonjs/trust/{chain.js → verify-chain.js} +40 -5
  12. package/lib/commonjs/trust/verify-chain.js.map +1 -0
  13. package/lib/commonjs/utils/errors.js.map +1 -1
  14. package/lib/module/credential/issuance/02-evaluate-issuer-trust.js +1 -1
  15. package/lib/module/credential/issuance/02-evaluate-issuer-trust.js.map +1 -1
  16. package/lib/module/credential/presentation/02-evaluate-rp-trust.js +1 -1
  17. package/lib/module/credential/presentation/02-evaluate-rp-trust.js.map +1 -1
  18. package/lib/module/credential/presentation/05-verify-request-object.js.map +1 -1
  19. package/lib/module/credential/presentation/08-send-authorization-response.js +1 -1
  20. package/lib/module/credential/presentation/08-send-authorization-response.js.map +1 -1
  21. package/lib/module/trust/build-chain.js +235 -0
  22. package/lib/module/trust/build-chain.js.map +1 -0
  23. package/lib/module/trust/index.js +5 -268
  24. package/lib/module/trust/index.js.map +1 -1
  25. package/lib/module/trust/{chain.js → verify-chain.js} +36 -2
  26. package/lib/module/trust/verify-chain.js.map +1 -0
  27. package/lib/module/utils/errors.js +1 -1
  28. package/lib/module/utils/errors.js.map +1 -1
  29. package/lib/typescript/client/generated/wallet-provider.d.ts +12 -12
  30. package/lib/typescript/credential/issuance/02-evaluate-issuer-trust.d.ts.map +1 -1
  31. package/lib/typescript/credential/presentation/02-evaluate-rp-trust.d.ts.map +1 -1
  32. package/lib/typescript/credential/presentation/05-verify-request-object.d.ts +1 -1
  33. package/lib/typescript/credential/presentation/05-verify-request-object.d.ts.map +1 -1
  34. package/lib/typescript/credential/presentation/08-send-authorization-response.d.ts +2 -2
  35. package/lib/typescript/credential/presentation/08-send-authorization-response.d.ts.map +1 -1
  36. package/lib/typescript/credential/presentation/types.d.ts +4 -4
  37. package/lib/typescript/trust/build-chain.d.ts +1284 -0
  38. package/lib/typescript/trust/build-chain.d.ts.map +1 -0
  39. package/lib/typescript/trust/index.d.ts +5 -1301
  40. package/lib/typescript/trust/index.d.ts.map +1 -1
  41. package/lib/typescript/trust/types.d.ts +506 -506
  42. package/lib/typescript/trust/{chain.d.ts → verify-chain.d.ts} +17 -1
  43. package/lib/typescript/trust/verify-chain.d.ts.map +1 -0
  44. package/lib/typescript/utils/errors.d.ts +2 -2
  45. package/lib/typescript/utils/errors.d.ts.map +1 -1
  46. package/lib/typescript/wallet-instance-attestation/types.d.ts +4 -4
  47. package/package.json +1 -1
  48. package/src/credential/issuance/02-evaluate-issuer-trust.ts +1 -1
  49. package/src/credential/presentation/02-evaluate-rp-trust.ts +1 -1
  50. package/src/credential/presentation/05-verify-request-object.ts +1 -1
  51. package/src/credential/presentation/08-send-authorization-response.ts +4 -4
  52. package/src/trust/build-chain.ts +395 -0
  53. package/src/trust/index.ts +5 -442
  54. package/src/trust/{chain.ts → verify-chain.ts} +41 -1
  55. package/src/utils/errors.ts +4 -4
  56. package/lib/commonjs/trust/chain.js.map +0 -1
  57. package/lib/module/trust/chain.js.map +0 -1
  58. package/lib/typescript/trust/chain.d.ts.map +0 -1
@@ -20,4 +20,20 @@ export declare function validateTrustChain(trustAnchorEntity: TrustAnchorEntityC
20
20
  * @throws {FederationError} If the chain is not valid
21
21
  */
22
22
  export declare function renewTrustChain(chain: string[], appFetch?: GlobalFetch["fetch"]): Promise<string[]>;
23
- //# sourceMappingURL=chain.d.ts.map
23
+ /**
24
+ * Verify a given trust chain is actually valid.
25
+ * It can handle fast chain renewal, which means we try to fetch a fresh version of each statement.
26
+ *
27
+ * @param trustAnchorEntity The entity configuration of the known trust anchor
28
+ * @param chain The chain of statements to be validated
29
+ * @param x509Options Options for the verification process
30
+ * @param appFetch (optional) fetch api implementation
31
+ * @param renewOnFail Whether to attempt to renew the trust chain if the initial validation fails
32
+ * @returns The result of the chain validation
33
+ * @throws {FederationError} If the chain is not valid
34
+ */
35
+ export declare function verifyTrustChain(trustAnchorEntity: TrustAnchorEntityConfiguration, chain: string[], x509Options?: X509CertificateOptions, { appFetch, renewOnFail, }?: {
36
+ appFetch?: GlobalFetch["fetch"];
37
+ renewOnFail?: boolean;
38
+ }): Promise<ReturnType<typeof validateTrustChain>>;
39
+ //# sourceMappingURL=verify-chain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify-chain.d.ts","sourceRoot":"","sources":["../../../src/trust/verify-chain.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,8BAA8B,EAC/B,MAAM,SAAS,CAAC;AAGjB,OAAO,EAGL,KAAK,WAAW,EAEjB,MAAM,SAAS,CAAC;AAUjB,OAAO,EAGL,KAAK,sBAAsB,EAC5B,MAAM,gCAAgC,CAAC;AAiBxC;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CACtC,iBAAiB,EAAE,8BAA8B,EACjD,KAAK,EAAE,MAAM,EAAE,EACf,WAAW,EAAE,sBAAsB,GAClC,OAAO,CAAC,WAAW,EAAE,CAAC,CAkHxB;AAED;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,MAAM,EAAE,EACf,QAAQ,GAAE,WAAW,CAAC,OAAO,CAAS,GACrC,OAAO,CAAC,MAAM,EAAE,CAAC,CA8CnB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,gBAAgB,CACpC,iBAAiB,EAAE,8BAA8B,EACjD,KAAK,EAAE,MAAM,EAAE,EACf,WAAW,GAAE,sBAIZ,EACD,EACE,QAAgB,EAChB,WAAkB,GACnB,GAAE;IAAE,QAAQ,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAO,GACjE,OAAO,CAAC,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC,CAWhD"}
@@ -1,6 +1,6 @@
1
1
  import type { ProblemDetail } from "../client/generated/wallet-provider";
2
- import type { CredentialIssuerEntityConfiguration } from "../trust";
3
- import { IssuerResponseErrorCodes, WalletProviderResponseErrorCodes, RelyingPartyResponseErrorCodes, type IssuerResponseErrorCode, type WalletProviderResponseErrorCode, type RelyingPartyResponseErrorCode } from "./error-codes";
2
+ import { type IssuerResponseErrorCode, IssuerResponseErrorCodes, type RelyingPartyResponseErrorCode, RelyingPartyResponseErrorCodes, type WalletProviderResponseErrorCode, WalletProviderResponseErrorCodes } from "./error-codes";
3
+ import type { CredentialIssuerEntityConfiguration } from "../trust/types";
4
4
  export { IssuerResponseErrorCodes, WalletProviderResponseErrorCodes, RelyingPartyResponseErrorCodes, };
5
5
  type GenericErrorReason = string | Record<string, unknown>;
6
6
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/utils/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,EACL,wBAAwB,EACxB,gCAAgC,EAChC,8BAA8B,EAC9B,KAAK,uBAAuB,EAC5B,KAAK,+BAA+B,EACpC,KAAK,6BAA6B,EACnC,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,wBAAwB,EACxB,gCAAgC,EAChC,8BAA8B,GAC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KAAK,gBAAgB,CAAC,CAAC,IAAI,OAAO,CAAC,YAAY,EAAE;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtE,KAAK,SAAS,CAAC,CAAC,IAAI;IAClB,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,kBAAkB,CAAC;CAC7B,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,qBAAa,oBAAoB,CAAC,CAAC,SAAS,OAAO,yBAAyB;IAK9D,OAAO,CAAC,UAAU;IAJ9B,OAAO,CAAC,UAAU,CAEX;gBAEa,UAAU,EAAE,CAAC;IAEjC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;IAKjD,SAAS,CAAC,aAAa,EAAE,yBAAyB;CAUnD"}
@@ -695,21 +695,21 @@ export declare const WalletAttestationResponse: z.ZodObject<{
695
695
  wallet_attestation: z.ZodString;
696
696
  format: z.ZodEnum<["jwt", "dc+sd-jwt", "mso_mdoc"]>;
697
697
  }, "strip", z.ZodTypeAny, {
698
- wallet_attestation: string;
699
698
  format: "jwt" | "dc+sd-jwt" | "mso_mdoc";
700
- }, {
701
699
  wallet_attestation: string;
700
+ }, {
702
701
  format: "jwt" | "dc+sd-jwt" | "mso_mdoc";
702
+ wallet_attestation: string;
703
703
  }>, "many">;
704
704
  }, "strip", z.ZodTypeAny, {
705
705
  wallet_attestations: {
706
- wallet_attestation: string;
707
706
  format: "jwt" | "dc+sd-jwt" | "mso_mdoc";
707
+ wallet_attestation: string;
708
708
  }[];
709
709
  }, {
710
710
  wallet_attestations: {
711
- wallet_attestation: string;
712
711
  format: "jwt" | "dc+sd-jwt" | "mso_mdoc";
712
+ wallet_attestation: string;
713
713
  }[];
714
714
  }>;
715
715
  //# sourceMappingURL=types.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagopa/io-react-native-wallet",
3
- "version": "2.0.0-next.1",
3
+ "version": "2.0.0-next.2",
4
4
  "description": "Provide data structures, helpers and API for IO Wallet",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -1,7 +1,7 @@
1
- import { getCredentialIssuerEntityConfiguration } from "../../trust";
2
1
  import { CredentialIssuerEntityConfiguration } from "../../trust/types";
3
2
  import type { StartFlow } from "./01-start-flow";
4
3
  import type { Out } from "../../utils/misc";
4
+ import { getCredentialIssuerEntityConfiguration } from "../../trust/build-chain";
5
5
 
6
6
  export type EvaluateIssuerTrust = (
7
7
  issuerUrl: Out<StartFlow>["issuerUrl"],
@@ -1,7 +1,7 @@
1
- import { getRelyingPartyEntityConfiguration } from "../../trust";
2
1
  import { RelyingPartyEntityConfiguration } from "../../trust/types";
3
2
  import type { StartFlow } from "../issuance/01-start-flow";
4
3
  import type { Out } from "../../utils/misc";
4
+ import { getRelyingPartyEntityConfiguration } from "../../trust/build-chain";
5
5
 
6
6
  export type EvaluateRelyingPartyTrust = (
7
7
  rpUrl: Out<StartFlow>["issuerUrl"],
@@ -1,8 +1,8 @@
1
1
  import { decode as decodeJwt, verify } from "@pagopa/io-react-native-jwt";
2
- import type { RelyingPartyEntityConfiguration } from "../../trust";
3
2
  import { InvalidRequestObjectError } from "./errors";
4
3
  import { RequestObject } from "./types";
5
4
  import { getJwksFromConfig } from "./04-retrieve-rp-jwks";
5
+ import type { RelyingPartyEntityConfiguration } from "../../trust/types";
6
6
 
7
7
  export type VerifyRequestObject = (
8
8
  requestObjectEncodedJwt: string,
@@ -1,24 +1,24 @@
1
1
  import { EncryptJwe } from "@pagopa/io-react-native-jwt";
2
2
  import uuid from "react-native-uuid";
3
- import { getJwksFromConfig, type FetchJwks } from "./04-retrieve-rp-jwks";
3
+ import { type FetchJwks, getJwksFromConfig } from "./04-retrieve-rp-jwks";
4
4
  import type { VerifyRequestObject } from "./05-verify-request-object";
5
5
  import { NoSuitableKeysFoundInEntityConfiguration } from "./errors";
6
6
  import { hasStatusOrThrow, type Out } from "../../utils/misc";
7
7
  import {
8
- type RemotePresentation,
9
8
  DirectAuthorizationBodyPayload,
10
9
  ErrorResponse,
11
10
  type LegacyRemotePresentation,
11
+ type RemotePresentation,
12
12
  } from "./types";
13
13
  import * as z from "zod";
14
14
  import type { JWK } from "../../utils/jwk";
15
- import type { RelyingPartyEntityConfiguration } from "../../trust";
16
15
  import {
17
16
  RelyingPartyResponseError,
17
+ RelyingPartyResponseErrorCodes,
18
18
  ResponseErrorBuilder,
19
19
  UnexpectedStatusCodeError,
20
- RelyingPartyResponseErrorCodes,
21
20
  } from "../../utils/errors";
21
+ import type { RelyingPartyEntityConfiguration } from "../../trust/types";
22
22
 
23
23
  export type AuthorizationResponse = z.infer<typeof AuthorizationResponse>;
24
24
  export const AuthorizationResponse = z.object({
@@ -0,0 +1,395 @@
1
+ import type { JWK } from "../utils/jwk";
2
+ import {
3
+ BuildTrustChainError,
4
+ FederationListParseError,
5
+ MissingFederationFetchEndpointError,
6
+ RelyingPartyNotAuthorizedError,
7
+ TrustAnchorKidMissingError,
8
+ } from "./errors";
9
+ import { decode, verify } from "./utils";
10
+ import {
11
+ CredentialIssuerEntityConfiguration,
12
+ EntityConfiguration,
13
+ EntityStatement,
14
+ FederationListResponse,
15
+ RelyingPartyEntityConfiguration,
16
+ TrustAnchorEntityConfiguration,
17
+ WalletProviderEntityConfiguration,
18
+ } from "./types";
19
+ import { hasStatusOrThrow } from "../utils/misc";
20
+ import { decode as decodeJwt } from "@pagopa/io-react-native-jwt";
21
+
22
+ /**
23
+ * Fetch and parse the entity configuration document for a given federation entity.
24
+ * This is an inner method to serve public interfaces.
25
+ *
26
+ * To add another entity configuration type (example: Foo entity type):
27
+ * - create its zod schema and type by inherit from the base type (example: FooEntityConfiguration = BaseEntityConfiguration.and(...))
28
+ * - add such type to EntityConfiguration union
29
+ * - add an overload to this function
30
+ * - create a public function which use such type (example: getFooEntityConfiguration = (url, options) => Promise<FooEntityConfiguration>)
31
+ *
32
+ * @param entityBaseUrl The base url of the entity.
33
+ * @param schema The expected schema of the entity configuration, according to the kind of entity we are fetching from.
34
+ * @param options An optional object with additional options.
35
+ * @param options.appFetch An optional instance of the http client to be used.
36
+ * @returns The parsed entity configuration object
37
+ * @throws {IoWalletError} If the http request fails
38
+ * @throws Parse error if the document is not in the expected shape.
39
+ */
40
+ async function fetchAndParseEntityConfiguration(
41
+ entityBaseUrl: string,
42
+ schema: typeof WalletProviderEntityConfiguration,
43
+ options?: {
44
+ appFetch?: GlobalFetch["fetch"];
45
+ }
46
+ ): Promise<WalletProviderEntityConfiguration>;
47
+ async function fetchAndParseEntityConfiguration(
48
+ entityBaseUrl: string,
49
+ schema: typeof RelyingPartyEntityConfiguration,
50
+ options?: {
51
+ appFetch?: GlobalFetch["fetch"];
52
+ }
53
+ ): Promise<RelyingPartyEntityConfiguration>;
54
+ async function fetchAndParseEntityConfiguration(
55
+ entityBaseUrl: string,
56
+ schema: typeof TrustAnchorEntityConfiguration,
57
+ options?: {
58
+ appFetch?: GlobalFetch["fetch"];
59
+ }
60
+ ): Promise<TrustAnchorEntityConfiguration>;
61
+ async function fetchAndParseEntityConfiguration(
62
+ entityBaseUrl: string,
63
+ schema: typeof CredentialIssuerEntityConfiguration,
64
+ options?: {
65
+ appFetch?: GlobalFetch["fetch"];
66
+ }
67
+ ): Promise<CredentialIssuerEntityConfiguration>;
68
+ async function fetchAndParseEntityConfiguration(
69
+ entityBaseUrl: string,
70
+ schema: typeof EntityConfiguration,
71
+ options?: {
72
+ appFetch?: GlobalFetch["fetch"];
73
+ }
74
+ ): Promise<EntityConfiguration>;
75
+ async function fetchAndParseEntityConfiguration(
76
+ entityBaseUrl: string,
77
+ schema: /* FIXME: why is it different from "typeof EntityConfiguration"? */
78
+ | typeof CredentialIssuerEntityConfiguration
79
+ | typeof WalletProviderEntityConfiguration
80
+ | typeof RelyingPartyEntityConfiguration
81
+ | typeof TrustAnchorEntityConfiguration
82
+ | typeof EntityConfiguration,
83
+ {
84
+ appFetch = fetch,
85
+ }: {
86
+ appFetch?: GlobalFetch["fetch"];
87
+ } = {}
88
+ ) {
89
+ const responseText = await getSignedEntityConfiguration(entityBaseUrl, {
90
+ appFetch,
91
+ });
92
+
93
+ const responseJwt = decodeJwt(responseText);
94
+ return schema.parse({
95
+ header: responseJwt.protectedHeader,
96
+ payload: responseJwt.payload,
97
+ });
98
+ }
99
+
100
+ export const getWalletProviderEntityConfiguration = (
101
+ entityBaseUrl: Parameters<typeof fetchAndParseEntityConfiguration>[0],
102
+ options?: Parameters<typeof fetchAndParseEntityConfiguration>[2]
103
+ ) =>
104
+ fetchAndParseEntityConfiguration(
105
+ entityBaseUrl,
106
+ WalletProviderEntityConfiguration,
107
+ options
108
+ );
109
+
110
+ export const getCredentialIssuerEntityConfiguration = (
111
+ entityBaseUrl: Parameters<typeof fetchAndParseEntityConfiguration>[0],
112
+ options?: Parameters<typeof fetchAndParseEntityConfiguration>[2]
113
+ ) =>
114
+ fetchAndParseEntityConfiguration(
115
+ entityBaseUrl,
116
+ CredentialIssuerEntityConfiguration,
117
+ options
118
+ );
119
+
120
+ export const getTrustAnchorEntityConfiguration = (
121
+ entityBaseUrl: Parameters<typeof fetchAndParseEntityConfiguration>[0],
122
+ options?: Parameters<typeof fetchAndParseEntityConfiguration>[2]
123
+ ) =>
124
+ fetchAndParseEntityConfiguration(
125
+ entityBaseUrl,
126
+ TrustAnchorEntityConfiguration,
127
+ options
128
+ );
129
+
130
+ export const getRelyingPartyEntityConfiguration = (
131
+ entityBaseUrl: Parameters<typeof fetchAndParseEntityConfiguration>[0],
132
+ options?: Parameters<typeof fetchAndParseEntityConfiguration>[2]
133
+ ) =>
134
+ fetchAndParseEntityConfiguration(
135
+ entityBaseUrl,
136
+ RelyingPartyEntityConfiguration,
137
+ options
138
+ );
139
+
140
+ export const getEntityConfiguration = (
141
+ entityBaseUrl: Parameters<typeof fetchAndParseEntityConfiguration>[0],
142
+ options?: Parameters<typeof fetchAndParseEntityConfiguration>[2]
143
+ ) =>
144
+ fetchAndParseEntityConfiguration(entityBaseUrl, EntityConfiguration, options);
145
+
146
+ /**
147
+ * Fetch and parse the entity statement document for a given federation entity.
148
+ *
149
+ * @param accreditationBodyBaseUrl The base url of the accreditation body which holds and signs the required entity statement
150
+ * @param subordinatedEntityBaseUrl The url that identifies the subordinate entity
151
+ * @param appFetch An optional instance of the http client to be used.
152
+ * @returns The parsed entity configuration object
153
+ * @throws {IoWalletError} If the http request fails
154
+ */
155
+ export async function getEntityStatement(
156
+ accreditationBodyBaseUrl: string,
157
+ subordinatedEntityBaseUrl: string,
158
+ {
159
+ appFetch = fetch,
160
+ }: {
161
+ appFetch?: GlobalFetch["fetch"];
162
+ } = {}
163
+ ) {
164
+ const responseText = await getSignedEntityStatement(
165
+ accreditationBodyBaseUrl,
166
+ subordinatedEntityBaseUrl,
167
+ {
168
+ appFetch,
169
+ }
170
+ );
171
+
172
+ const responseJwt = decodeJwt(responseText);
173
+ return EntityStatement.parse({
174
+ header: responseJwt.protectedHeader,
175
+ payload: responseJwt.payload,
176
+ });
177
+ }
178
+
179
+ /**
180
+ * Fetch the signed entity configuration token for an entity
181
+ *
182
+ * @param entityBaseUrl The url of the entity to fetch
183
+ * @param appFetch (optional) fetch api implementation
184
+ * @returns The signed Entity Configuration token
185
+ */
186
+ export async function getSignedEntityConfiguration(
187
+ entityBaseUrl: string,
188
+ {
189
+ appFetch = fetch,
190
+ }: {
191
+ appFetch?: GlobalFetch["fetch"];
192
+ } = {}
193
+ ): Promise<string> {
194
+ const wellKnownUrl = `${entityBaseUrl}/.well-known/openid-federation`;
195
+
196
+ return await appFetch(wellKnownUrl, {
197
+ method: "GET",
198
+ })
199
+ .then(hasStatusOrThrow(200))
200
+ .then((res) => res.text());
201
+ }
202
+
203
+ /**
204
+ * Fetch the entity statement document for a given federation entity.
205
+ *
206
+ * @param federationFetchEndpoint The exact endpoint provided by the parent EC's metadata.
207
+ * @param subordinatedEntityBaseUrl The url that identifies the subordinate entity.
208
+ * @param appFetch An optional instance of the http client to be used.
209
+ * @returns The signed entity statement token.
210
+ * @throws {IoWalletError} If the http request fails.
211
+ */
212
+ export async function getSignedEntityStatement(
213
+ federationFetchEndpoint: string,
214
+ subordinatedEntityBaseUrl: string,
215
+ {
216
+ appFetch = fetch,
217
+ }: {
218
+ appFetch?: GlobalFetch["fetch"];
219
+ } = {}
220
+ ) {
221
+ const url = new URL(federationFetchEndpoint);
222
+ url.searchParams.set("sub", subordinatedEntityBaseUrl);
223
+
224
+ return await appFetch(url.toString(), {
225
+ method: "GET",
226
+ })
227
+ .then(hasStatusOrThrow(200))
228
+ .then((res) => res.text());
229
+ }
230
+
231
+ /**
232
+ * Fetch the federation list document from a given endpoint.
233
+ *
234
+ * @param federationListEndpoint The URL of the federation list endpoint.
235
+ * @param appFetch An optional instance of the http client to be used.
236
+ * @returns The federation list as an array of strings.
237
+ * @throws {IoWalletError} If the HTTP request fails.
238
+ * @throws {FederationError} If the result is not in the expected format.
239
+ */
240
+ export async function getFederationList(
241
+ federationListEndpoint: string,
242
+ {
243
+ appFetch = fetch,
244
+ }: {
245
+ appFetch?: GlobalFetch["fetch"];
246
+ } = {}
247
+ ): Promise<string[]> {
248
+ return await appFetch(federationListEndpoint, {
249
+ method: "GET",
250
+ })
251
+ .then(hasStatusOrThrow(200))
252
+ .then((res) => res.json())
253
+ .then((json) => {
254
+ const result = FederationListResponse.safeParse(json);
255
+ if (!result.success) {
256
+ throw new FederationListParseError(
257
+ `Invalid federation list format received from ${federationListEndpoint}. Error: ${result.error.message}`,
258
+ { url: federationListEndpoint, parseError: result.error.toString() }
259
+ );
260
+ }
261
+ return result.data;
262
+ });
263
+ }
264
+
265
+ /**
266
+ * Build a not-verified trust chain for a given Relying Party (RP) entity.
267
+ *
268
+ * @param relyingPartyEntityBaseUrl The base URL of the RP entity
269
+ * @param trustAnchorKey The public key of the Trust Anchor (TA) entity
270
+ * @param appFetch An optional instance of the http client to be used.
271
+ * @returns A list of signed tokens that represent the trust chain, in the order of the chain (from the RP to the Trust Anchor)
272
+ * @throws {FederationError} When an element of the chain fails to parse or other build steps fail.
273
+ */
274
+ export async function buildTrustChain(
275
+ relyingPartyEntityBaseUrl: string,
276
+ trustAnchorKey: JWK,
277
+ appFetch: GlobalFetch["fetch"] = fetch
278
+ ): Promise<string[]> {
279
+ // 1: Recursively gather the trust chain from the RP up to the Trust Anchor
280
+ const trustChain = await gatherTrustChain(
281
+ relyingPartyEntityBaseUrl,
282
+ appFetch
283
+ );
284
+
285
+ // 2: Trust Anchor signature verification
286
+ const trustAnchorJwt = trustChain[trustChain.length - 1];
287
+ if (!trustAnchorJwt) {
288
+ throw new BuildTrustChainError(
289
+ "Cannot verify trust anchor: missing entity configuration in gathered chain.",
290
+ { relyingPartyUrl: relyingPartyEntityBaseUrl }
291
+ );
292
+ }
293
+
294
+ if (!trustAnchorKey.kid) {
295
+ throw new TrustAnchorKidMissingError();
296
+ }
297
+
298
+ await verify(trustAnchorJwt, trustAnchorKey.kid, [trustAnchorKey]);
299
+
300
+ // 3: Check the federation list
301
+ const trustAnchorConfig = EntityConfiguration.parse(decode(trustAnchorJwt));
302
+ const federationListEndpoint =
303
+ trustAnchorConfig.payload.metadata.federation_entity
304
+ .federation_list_endpoint;
305
+
306
+ if (federationListEndpoint) {
307
+ const federationList = await getFederationList(federationListEndpoint, {
308
+ appFetch,
309
+ });
310
+
311
+ if (!federationList.includes(relyingPartyEntityBaseUrl)) {
312
+ throw new RelyingPartyNotAuthorizedError(
313
+ "Relying Party entity base URL is not authorized by the Trust Anchor's federation list.",
314
+ { relyingPartyUrl: relyingPartyEntityBaseUrl, federationListEndpoint }
315
+ );
316
+ }
317
+ }
318
+
319
+ return trustChain;
320
+ }
321
+
322
+ /**
323
+ * Recursively gather the trust chain for an entity and all its superiors.
324
+ * @param entityBaseUrl The base URL of the entity for which to gather the chain.
325
+ * @param appFetch An optional instance of the http client to be used.
326
+ * @param isLeaf Whether the current entity is the leaf of the chain.
327
+ * @returns A full ordered list of JWTs (ECs and ESs) forming the trust chain.
328
+ * @throws {FederationError} If any of the fetched documents fail to parse or other errors occur during the gathering process.
329
+ */
330
+ async function gatherTrustChain(
331
+ entityBaseUrl: string,
332
+ appFetch: GlobalFetch["fetch"],
333
+ isLeaf: boolean = true
334
+ ): Promise<string[]> {
335
+ const chain: string[] = [];
336
+
337
+ // Fetch self-signed EC (only needed for the leaf)
338
+ const entityECJwt = await getSignedEntityConfiguration(entityBaseUrl, {
339
+ appFetch,
340
+ });
341
+ const entityEC = EntityConfiguration.parse(decode(entityECJwt));
342
+
343
+ if (isLeaf) {
344
+ // Only push EC for the leaf
345
+ chain.push(entityECJwt);
346
+ }
347
+
348
+ // Find authority_hints (parent, if any)
349
+ const authorityHints = entityEC.payload.authority_hints ?? [];
350
+ if (authorityHints.length === 0) {
351
+ // This is the Trust Anchor (no parent)
352
+ if (!isLeaf) {
353
+ chain.push(entityECJwt);
354
+ }
355
+ return chain;
356
+ }
357
+
358
+ const parentEntityBaseUrl = authorityHints[0]!;
359
+
360
+ // Fetch parent EC
361
+ const parentECJwt = await getSignedEntityConfiguration(parentEntityBaseUrl, {
362
+ appFetch,
363
+ });
364
+ const parentEC = EntityConfiguration.parse(decode(parentECJwt));
365
+
366
+ // Fetch ES
367
+ const federationFetchEndpoint =
368
+ parentEC.payload.metadata.federation_entity.federation_fetch_endpoint;
369
+ if (!federationFetchEndpoint) {
370
+ throw new MissingFederationFetchEndpointError(
371
+ `Missing federation_fetch_endpoint in parent's (${parentEntityBaseUrl}) configuration when gathering chain for ${entityBaseUrl}.`,
372
+ { entityBaseUrl, missingInEntityUrl: parentEntityBaseUrl }
373
+ );
374
+ }
375
+
376
+ const entityStatementJwt = await getSignedEntityStatement(
377
+ federationFetchEndpoint,
378
+ entityBaseUrl,
379
+ { appFetch }
380
+ );
381
+ // Validate the ES
382
+ EntityStatement.parse(decode(entityStatementJwt));
383
+
384
+ // Push this ES into the chain
385
+ chain.push(entityStatementJwt);
386
+
387
+ // Recurse into the parent
388
+ const parentChain = await gatherTrustChain(
389
+ parentEntityBaseUrl,
390
+ appFetch,
391
+ false
392
+ );
393
+
394
+ return chain.concat(parentChain);
395
+ }