@pagopa/io-react-native-wallet 2.2.0 → 2.3.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.
Files changed (91) hide show
  1. package/README.md +4 -3
  2. package/lib/commonjs/credential/index.js +3 -1
  3. package/lib/commonjs/credential/index.js.map +1 -1
  4. package/lib/commonjs/credential/offer/01-start-flow.js +75 -0
  5. package/lib/commonjs/credential/offer/01-start-flow.js.map +1 -0
  6. package/lib/commonjs/credential/offer/02-fetch-credential-offer.js +45 -0
  7. package/lib/commonjs/credential/offer/02-fetch-credential-offer.js.map +1 -0
  8. package/lib/commonjs/credential/offer/README.md +174 -0
  9. package/lib/commonjs/credential/offer/errors.js +22 -0
  10. package/lib/commonjs/credential/offer/errors.js.map +1 -0
  11. package/lib/commonjs/credential/offer/index.js +25 -0
  12. package/lib/commonjs/credential/offer/index.js.map +1 -0
  13. package/lib/commonjs/credential/offer/types.js +51 -0
  14. package/lib/commonjs/credential/offer/types.js.map +1 -0
  15. package/lib/commonjs/credential/presentation/01-start-flow.js +1 -1
  16. package/lib/commonjs/credentials-catalogue/README.md +15 -0
  17. package/lib/commonjs/credentials-catalogue/fetch-and-parse-catalogue.js +42 -0
  18. package/lib/commonjs/credentials-catalogue/fetch-and-parse-catalogue.js.map +1 -0
  19. package/lib/commonjs/credentials-catalogue/index.js +13 -0
  20. package/lib/commonjs/credentials-catalogue/index.js.map +1 -0
  21. package/lib/commonjs/credentials-catalogue/types.js +99 -0
  22. package/lib/commonjs/credentials-catalogue/types.js.map +1 -0
  23. package/lib/commonjs/index.js +3 -1
  24. package/lib/commonjs/index.js.map +1 -1
  25. package/lib/commonjs/utils/zod.js +28 -0
  26. package/lib/commonjs/utils/zod.js.map +1 -0
  27. package/lib/module/credential/index.js +2 -1
  28. package/lib/module/credential/index.js.map +1 -1
  29. package/lib/module/credential/offer/01-start-flow.js +66 -0
  30. package/lib/module/credential/offer/01-start-flow.js.map +1 -0
  31. package/lib/module/credential/offer/02-fetch-credential-offer.js +38 -0
  32. package/lib/module/credential/offer/02-fetch-credential-offer.js.map +1 -0
  33. package/lib/module/credential/offer/README.md +174 -0
  34. package/lib/module/credential/offer/errors.js +14 -0
  35. package/lib/module/credential/offer/errors.js.map +1 -0
  36. package/lib/module/credential/offer/index.js +5 -0
  37. package/lib/module/credential/offer/index.js.map +1 -0
  38. package/lib/module/credential/offer/types.js +41 -0
  39. package/lib/module/credential/offer/types.js.map +1 -0
  40. package/lib/module/credential/presentation/01-start-flow.js +1 -1
  41. package/lib/module/credentials-catalogue/README.md +15 -0
  42. package/lib/module/credentials-catalogue/fetch-and-parse-catalogue.js +35 -0
  43. package/lib/module/credentials-catalogue/fetch-and-parse-catalogue.js.map +1 -0
  44. package/lib/module/credentials-catalogue/index.js +2 -0
  45. package/lib/module/credentials-catalogue/index.js.map +1 -0
  46. package/lib/module/credentials-catalogue/types.js +89 -0
  47. package/lib/module/credentials-catalogue/types.js.map +1 -0
  48. package/lib/module/index.js +2 -1
  49. package/lib/module/index.js.map +1 -1
  50. package/lib/module/utils/zod.js +20 -0
  51. package/lib/module/utils/zod.js.map +1 -0
  52. package/lib/typescript/credential/index.d.ts +2 -1
  53. package/lib/typescript/credential/index.d.ts.map +1 -1
  54. package/lib/typescript/credential/issuance/01-start-flow.d.ts +1 -1
  55. package/lib/typescript/credential/offer/01-start-flow.d.ts +172 -0
  56. package/lib/typescript/credential/offer/01-start-flow.d.ts.map +1 -0
  57. package/lib/typescript/credential/offer/02-fetch-credential-offer.d.ts +20 -0
  58. package/lib/typescript/credential/offer/02-fetch-credential-offer.d.ts.map +1 -0
  59. package/lib/typescript/credential/offer/errors.d.ts +10 -0
  60. package/lib/typescript/credential/offer/errors.d.ts.map +1 -0
  61. package/lib/typescript/credential/offer/index.d.ts +7 -0
  62. package/lib/typescript/credential/offer/index.d.ts.map +1 -0
  63. package/lib/typescript/credential/offer/types.d.ts +264 -0
  64. package/lib/typescript/credential/offer/types.d.ts.map +1 -0
  65. package/lib/typescript/credential/presentation/01-start-flow.d.ts +1 -1
  66. package/lib/typescript/credentials-catalogue/fetch-and-parse-catalogue.d.ts +15 -0
  67. package/lib/typescript/credentials-catalogue/fetch-and-parse-catalogue.d.ts.map +1 -0
  68. package/lib/typescript/credentials-catalogue/index.d.ts +3 -0
  69. package/lib/typescript/credentials-catalogue/index.d.ts.map +1 -0
  70. package/lib/typescript/credentials-catalogue/types.d.ts +844 -0
  71. package/lib/typescript/credentials-catalogue/types.d.ts.map +1 -0
  72. package/lib/typescript/index.d.ts +2 -1
  73. package/lib/typescript/index.d.ts.map +1 -1
  74. package/lib/typescript/utils/zod.d.ts +15 -0
  75. package/lib/typescript/utils/zod.d.ts.map +1 -0
  76. package/package.json +21 -2
  77. package/src/credential/index.ts +2 -1
  78. package/src/credential/issuance/01-start-flow.ts +1 -1
  79. package/src/credential/offer/01-start-flow.ts +89 -0
  80. package/src/credential/offer/02-fetch-credential-offer.ts +54 -0
  81. package/src/credential/offer/README.md +174 -0
  82. package/src/credential/offer/errors.ts +17 -0
  83. package/src/credential/offer/index.ts +16 -0
  84. package/src/credential/offer/types.ts +59 -0
  85. package/src/credential/presentation/01-start-flow.ts +1 -1
  86. package/src/credentials-catalogue/README.md +15 -0
  87. package/src/credentials-catalogue/fetch-and-parse-catalogue.ts +54 -0
  88. package/src/credentials-catalogue/index.ts +2 -0
  89. package/src/credentials-catalogue/types.ts +97 -0
  90. package/src/index.ts +2 -0
  91. package/src/utils/zod.ts +28 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/credentials-catalogue/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAmDzB,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqB5B,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAatC,CAAC;AACH,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAC/C,OAAO,2BAA2B,CACnC,CAAC"}
@@ -2,6 +2,7 @@ import type { AuthorizationContext } from "./utils/auth";
2
2
  import { fixBase64EncodingOnKey } from "./utils/jwk";
3
3
  import "react-native-url-polyfill/auto";
4
4
  import * as Credential from "./credential";
5
+ import * as CredentialsCatalogue from "./credentials-catalogue";
5
6
  import * as PID from "./pid";
6
7
  import * as SdJwt from "./sd-jwt";
7
8
  import * as Mdoc from "./mdoc";
@@ -13,6 +14,6 @@ import * as Logging from "./utils/logging";
13
14
  import { AuthorizationDetail, AuthorizationDetails } from "./utils/par";
14
15
  import { createCryptoContextFor } from "./utils/crypto";
15
16
  import type { IntegrityContext } from "./utils/integrity";
16
- export { SdJwt, Mdoc, PID, Credential, WalletInstanceAttestation, WalletInstance, Errors, Trust, createCryptoContextFor, AuthorizationDetail, AuthorizationDetails, fixBase64EncodingOnKey, Logging, };
17
+ export { SdJwt, Mdoc, PID, Credential, CredentialsCatalogue, WalletInstanceAttestation, WalletInstance, Errors, Trust, createCryptoContextFor, AuthorizationDetail, AuthorizationDetails, fixBase64EncodingOnKey, Logging, };
17
18
  export type { IntegrityContext, AuthorizationContext };
18
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAGrD,OAAO,gCAAgC,CAAC;AAExC,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,UAAU,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAC;AACzC,OAAO,KAAK,yBAAyB,MAAM,+BAA+B,CAAC;AAC3E,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,cAAc,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,EACL,KAAK,EACL,IAAI,EACJ,GAAG,EACH,UAAU,EACV,yBAAyB,EACzB,cAAc,EACd,MAAM,EACN,KAAK,EACL,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,OAAO,GACR,CAAC;AAEF,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAGrD,OAAO,gCAAgC,CAAC;AAExC,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,oBAAoB,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,UAAU,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAC;AACzC,OAAO,KAAK,yBAAyB,MAAM,+BAA+B,CAAC;AAC3E,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,cAAc,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,EACL,KAAK,EACL,IAAI,EACJ,GAAG,EACH,UAAU,EACV,oBAAoB,EACpB,yBAAyB,EACzB,cAAc,EACd,MAAM,EACN,KAAK,EACL,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,OAAO,GACR,CAAC;AAEF,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @see https://github.com/JacobWeisenburger/zod_utilz/blob/main/src/stringToJSON.ts
3
+ */
4
+ import { z } from "zod";
5
+ declare const literalSchema: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
6
+ type Literal = z.infer<typeof literalSchema>;
7
+ type Json = Literal | {
8
+ [key: string]: Json;
9
+ } | Json[];
10
+ export declare const json: () => z.ZodType<Json, z.ZodTypeDef, Json>;
11
+ export declare const stringToJSONSchema: z.ZodEffects<z.ZodString, string | number | boolean | {
12
+ [key: string]: Json;
13
+ } | Json[] | null, string>;
14
+ export {};
15
+ //# sourceMappingURL=zod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../../src/utils/zod.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,QAAA,MAAM,aAAa,iEAA2D,CAAC;AAE/E,KAAK,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAE7C,KAAK,IAAI,GAAG,OAAO,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,IAAI,EAAE,CAAC;AAMvD,eAAO,MAAM,IAAI,2CAAmB,CAAC;AAErC,eAAO,MAAM,kBAAkB;;0BAS3B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagopa/io-react-native-wallet",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Provide data structures, helpers and API for IO Wallet",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -64,6 +64,7 @@
64
64
  "@types/react": "^19.0.0",
65
65
  "@types/react-native": "0.70.0",
66
66
  "@types/url-parse": "^1.4.11",
67
+ "auto-changelog": "^2.5.0",
67
68
  "del-cli": "^5.0.0",
68
69
  "eslint": "^8.4.1",
69
70
  "eslint-plugin-prettier": "^5.2.3",
@@ -73,12 +74,13 @@
73
74
  "react": "19.0.0",
74
75
  "react-native": "0.78.3",
75
76
  "react-native-builder-bob": "^0.20.0",
77
+ "release-it": "^15.0.0",
76
78
  "typed-openapi": "^0.4.1",
77
79
  "typescript": "5.0.4"
78
80
  },
79
81
  "peerDependencies": {
80
- "@pagopa/io-react-native-iso18013": "*",
81
82
  "@pagopa/io-react-native-crypto": "*",
83
+ "@pagopa/io-react-native-iso18013": "*",
82
84
  "@pagopa/io-react-native-jwt": "*",
83
85
  "react": "*",
84
86
  "react-native": "*"
@@ -87,6 +89,23 @@
87
89
  "node": ">= 16.0.0"
88
90
  },
89
91
  "packageManager": "yarn@1.22.19",
92
+ "release-it": {
93
+ "git": {
94
+ "commitMessage": "chore: release version ${version}",
95
+ "tagName": "v${version}",
96
+ "changelog": "yarn auto-changelog --stdout --commit-limit false -u --template https://raw.githubusercontent.com/release-it/release-it/master/templates/changelog-compact.hbs"
97
+ },
98
+ "hooks": {
99
+ "after:bump": "yarn auto-changelog -p && git add ."
100
+ },
101
+ "npm": {
102
+ "publish": false
103
+ },
104
+ "github": {
105
+ "release": true
106
+ },
107
+ "plugins": {}
108
+ },
90
109
  "jest": {
91
110
  "preset": "react-native",
92
111
  "modulePathIgnorePatterns": [
@@ -2,5 +2,6 @@ import * as Issuance from "./issuance";
2
2
  import * as Presentation from "./presentation";
3
3
  import * as Status from "./status";
4
4
  import * as Trustmark from "./trustmark";
5
+ import * as Offer from "./offer";
5
6
 
6
- export { Issuance, Presentation, Status, Trustmark };
7
+ export { Issuance, Presentation, Status, Trustmark, Offer };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * WARNING: This is the first function to be called in the issuing flow. The next function to be called is {@link evaluateIssuerTrust}.
3
3
  * The beginning of the issuing flow.
4
- * To be implemented accordind to the user touchpoint
4
+ * To be implemented according to the user touchpoint
5
5
  *
6
6
  * @returns The configuration ID of the Credential to be issued and the url of the Issuer
7
7
  */
@@ -0,0 +1,89 @@
1
+ import * as z from "zod";
2
+ import { Logger, LogLevel } from "../../utils/logging";
3
+ import { stringToJSONSchema } from "../../utils/zod";
4
+ import { InvalidQRCodeError } from "./errors";
5
+ import { CredentialOfferSchema } from "./types";
6
+
7
+ const CREDENTIAL_OFFER_SCHEMES = ["openid-credential-offer://", "haip://"];
8
+ const CREDENTIAL_OFFER_PARAM = "credential_offer";
9
+ const CREDENTIAL_OFFER_URI_PARAM = "credential_offer_uri";
10
+
11
+ const CredentialOfferParams = z.union([
12
+ z.object({
13
+ credential_offer: stringToJSONSchema.pipe(CredentialOfferSchema),
14
+ credential_offer_uri: z.undefined(),
15
+ }),
16
+ z.object({
17
+ credential_offer: z.undefined(),
18
+ credential_offer_uri: z.string().url(),
19
+ }),
20
+ ]);
21
+ type CredentialOfferParams = z.infer<typeof CredentialOfferParams>;
22
+
23
+ /**
24
+ * The beginning of the credential offer flow.
25
+ * To be implemented according to the user touchpoint
26
+ *
27
+ * @param params Credential offer encoded url
28
+ * @returns Object containing the credential offer by reference or by value
29
+ */
30
+ export type StartFlow = (encodedUrl: string) => CredentialOfferParams;
31
+
32
+ /**
33
+ * Start a credential offer flow by validating and parse an encoded url
34
+ * extracted from a QR code or a deep link.
35
+ *
36
+ * @param params The encoded url to be validated and parsed
37
+ * @returns Object containing the credential offer by reference or by value
38
+ * @throws If the provided encoded url is not valid
39
+ */
40
+ export const startFlowFromQR: StartFlow = (encodedUrl) => {
41
+ const hasValidScheme = CREDENTIAL_OFFER_SCHEMES.some((prefix) =>
42
+ encodedUrl.startsWith(prefix)
43
+ );
44
+
45
+ if (!hasValidScheme) {
46
+ throw new InvalidQRCodeError("Url must have one of the supported schemes");
47
+ }
48
+
49
+ const url = new URL(encodedUrl);
50
+ const offerParam = url.searchParams.get(CREDENTIAL_OFFER_PARAM);
51
+ const offerUriParam = url.searchParams.get(CREDENTIAL_OFFER_URI_PARAM);
52
+
53
+ if (offerParam) {
54
+ const decoded = decodeURIComponent(offerParam);
55
+ const result = CredentialOfferParams.safeParse({
56
+ credential_offer: decoded,
57
+ });
58
+
59
+ if (result.success) {
60
+ return result.data;
61
+ }
62
+
63
+ Logger.log(
64
+ LogLevel.ERROR,
65
+ `Invalid credential offer object found in QR Code: ${result.error.message}`
66
+ );
67
+ throw new InvalidQRCodeError(result.error.message);
68
+ }
69
+
70
+ if (offerUriParam) {
71
+ const decoded = decodeURIComponent(offerUriParam);
72
+ const result = CredentialOfferParams.safeParse({
73
+ credential_offer_uri: decoded,
74
+ });
75
+
76
+ if (result.success) {
77
+ return result.data;
78
+ }
79
+
80
+ Logger.log(
81
+ LogLevel.ERROR,
82
+ `Invalid credential offer URI found in QR Code: ${result.error.message}`
83
+ );
84
+ throw new InvalidQRCodeError(result.error.message);
85
+ }
86
+
87
+ Logger.log(LogLevel.ERROR, `Invalid credential offer QR Code:`);
88
+ throw new InvalidQRCodeError("QR Code does not contain valid params");
89
+ };
@@ -0,0 +1,54 @@
1
+ import { IssuerResponseError } from "../../utils/errors";
2
+ import { Logger, LogLevel } from "../../utils/logging";
3
+ import { hasStatusOrThrow } from "../../utils/misc";
4
+ import { InvalidCredentialOfferError } from "./errors";
5
+ import type { CredentialOffer } from "./types";
6
+ import { CredentialOfferSchema } from "./types";
7
+
8
+ export type GetCredentialOffer = (
9
+ credentialOfferUri: string,
10
+ context: {
11
+ appFetch?: GlobalFetch["fetch"];
12
+ }
13
+ ) => Promise<CredentialOffer>;
14
+
15
+ /**
16
+ * Fetches and validates a credential offer from a given URI.
17
+ *
18
+ * This function performs an HTTP GET request to the specified `credentialOfferUri`,
19
+ * expecting a JSON response that matches the `CredentialOfferSchema`. If the response
20
+ * is invalid or does not conform to the schema, an error is logged and an
21
+ * `InvalidCredentialOfferError` is thrown.
22
+ *
23
+ * @param credentialOfferUri - The URI from which to fetch the credential offer.
24
+ * @param context - Optional context object that may provide a custom `appFetch` implementation.
25
+ * @returns The validated credential offer data.
26
+ * @throws {IssuerResponseError} If the HTTP response status is not 200.
27
+ * @throws {InvalidCredentialOfferError} If the response does not match the expected schema.
28
+ */
29
+ export const fetchCredentialOffer: GetCredentialOffer = async (
30
+ uri: string,
31
+ context = {}
32
+ ) => {
33
+ const { appFetch = fetch } = context;
34
+
35
+ const response = await appFetch(uri, {
36
+ method: "GET",
37
+ headers: { Accept: "application/json" },
38
+ })
39
+ .then(hasStatusOrThrow(200, IssuerResponseError))
40
+ .then((reqUri) => reqUri.json());
41
+
42
+ const credentialOffer = CredentialOfferSchema.safeParse(response);
43
+ if (!credentialOffer.success) {
44
+ Logger.log(
45
+ LogLevel.ERROR,
46
+ `Invalid credential offer fetched from URI: ${uri} - ${credentialOffer.error.message}`
47
+ );
48
+ throw new InvalidCredentialOfferError(
49
+ `Invalid credential offer fetched from URI: ${uri} - ${credentialOffer.error.message}`
50
+ );
51
+ }
52
+
53
+ return credentialOffer.data;
54
+ };
@@ -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 accordind to the user touchpoint
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,2 @@
1
+ export { fetchAndParseCatalogue } from "./fetch-and-parse-catalogue";
2
+ export { type DigitalCredentialsCatalogue } from "./types";