@pagopa/io-react-native-wallet 0.24.1 → 0.26.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. package/README.md +0 -32
  2. package/lib/commonjs/client/generated/wallet-provider.js +39 -16
  3. package/lib/commonjs/client/generated/wallet-provider.js.map +1 -1
  4. package/lib/commonjs/client/index.js +25 -10
  5. package/lib/commonjs/client/index.js.map +1 -1
  6. package/lib/commonjs/credential/issuance/03-start-user-authorization.js +2 -2
  7. package/lib/commonjs/credential/issuance/04-complete-user-authorization.js +36 -67
  8. package/lib/commonjs/credential/issuance/04-complete-user-authorization.js.map +1 -1
  9. package/lib/commonjs/credential/issuance/05-authorize-access.js +5 -2
  10. package/lib/commonjs/credential/issuance/05-authorize-access.js.map +1 -1
  11. package/lib/commonjs/credential/issuance/06-obtain-credential.js +26 -17
  12. package/lib/commonjs/credential/issuance/06-obtain-credential.js.map +1 -1
  13. package/lib/commonjs/credential/issuance/README.md +8 -14
  14. package/lib/commonjs/credential/issuance/errors.js +52 -0
  15. package/lib/commonjs/credential/issuance/errors.js.map +1 -0
  16. package/lib/commonjs/credential/issuance/index.js +13 -2
  17. package/lib/commonjs/credential/issuance/index.js.map +1 -1
  18. package/lib/commonjs/credential/issuance/types.js +1 -5
  19. package/lib/commonjs/credential/issuance/types.js.map +1 -1
  20. package/lib/commonjs/credential/presentation/01-start-flow.js +1 -1
  21. package/lib/commonjs/credential/presentation/01-start-flow.js.map +1 -1
  22. package/lib/commonjs/credential/presentation/03-get-request-object.js +2 -2
  23. package/lib/commonjs/credential/presentation/03-get-request-object.js.map +1 -1
  24. package/lib/commonjs/credential/presentation/04-send-authorization-response.js +2 -2
  25. package/lib/commonjs/credential/presentation/04-send-authorization-response.js.map +1 -1
  26. package/lib/commonjs/credential/presentation/errors.js +49 -0
  27. package/lib/commonjs/credential/presentation/errors.js.map +1 -0
  28. package/lib/commonjs/credential/presentation/index.js +5 -0
  29. package/lib/commonjs/credential/presentation/index.js.map +1 -1
  30. package/lib/commonjs/credential/status/02-status-attestation.js +8 -6
  31. package/lib/commonjs/credential/status/02-status-attestation.js.map +1 -1
  32. package/lib/commonjs/credential/status/README.md +5 -2
  33. package/lib/commonjs/credential/status/types.js +1 -14
  34. package/lib/commonjs/credential/status/types.js.map +1 -1
  35. package/lib/commonjs/sd-jwt/errors.js +40 -0
  36. package/lib/commonjs/sd-jwt/errors.js.map +1 -0
  37. package/lib/commonjs/sd-jwt/index.js +8 -4
  38. package/lib/commonjs/sd-jwt/index.js.map +1 -1
  39. package/lib/commonjs/sd-jwt/verifier.js +5 -1
  40. package/lib/commonjs/sd-jwt/verifier.js.map +1 -1
  41. package/lib/commonjs/trust/index.js +2 -2
  42. package/lib/commonjs/trust/index.js.map +1 -1
  43. package/lib/commonjs/utils/decoder.js +3 -1
  44. package/lib/commonjs/utils/decoder.js.map +1 -1
  45. package/lib/commonjs/utils/error-codes.js +51 -0
  46. package/lib/commonjs/utils/error-codes.js.map +1 -0
  47. package/lib/commonjs/utils/errors.js +119 -463
  48. package/lib/commonjs/utils/errors.js.map +1 -1
  49. package/lib/commonjs/utils/misc.js +23 -55
  50. package/lib/commonjs/utils/misc.js.map +1 -1
  51. package/lib/commonjs/utils/par.js +2 -1
  52. package/lib/commonjs/utils/par.js.map +1 -1
  53. package/lib/commonjs/wallet-instance/README.md +26 -5
  54. package/lib/commonjs/wallet-instance/index.js +33 -7
  55. package/lib/commonjs/wallet-instance/index.js.map +1 -1
  56. package/lib/commonjs/wallet-instance-attestation/README.md +8 -2
  57. package/lib/commonjs/wallet-instance-attestation/issuing.js +13 -10
  58. package/lib/commonjs/wallet-instance-attestation/issuing.js.map +1 -1
  59. package/lib/module/client/generated/wallet-provider.js +31 -11
  60. package/lib/module/client/generated/wallet-provider.js.map +1 -1
  61. package/lib/module/client/index.js +22 -8
  62. package/lib/module/client/index.js.map +1 -1
  63. package/lib/module/credential/issuance/03-start-user-authorization.js +2 -2
  64. package/lib/module/credential/issuance/04-complete-user-authorization.js +33 -65
  65. package/lib/module/credential/issuance/04-complete-user-authorization.js.map +1 -1
  66. package/lib/module/credential/issuance/05-authorize-access.js +7 -4
  67. package/lib/module/credential/issuance/05-authorize-access.js.map +1 -1
  68. package/lib/module/credential/issuance/06-obtain-credential.js +29 -20
  69. package/lib/module/credential/issuance/06-obtain-credential.js.map +1 -1
  70. package/lib/module/credential/issuance/README.md +8 -14
  71. package/lib/module/credential/issuance/errors.js +44 -0
  72. package/lib/module/credential/issuance/errors.js.map +1 -0
  73. package/lib/module/credential/issuance/index.js +3 -2
  74. package/lib/module/credential/issuance/index.js.map +1 -1
  75. package/lib/module/credential/issuance/types.js +0 -3
  76. package/lib/module/credential/issuance/types.js.map +1 -1
  77. package/lib/module/credential/presentation/01-start-flow.js +1 -1
  78. package/lib/module/credential/presentation/01-start-flow.js.map +1 -1
  79. package/lib/module/credential/presentation/03-get-request-object.js +3 -3
  80. package/lib/module/credential/presentation/03-get-request-object.js.map +1 -1
  81. package/lib/module/credential/presentation/04-send-authorization-response.js +3 -3
  82. package/lib/module/credential/presentation/04-send-authorization-response.js.map +1 -1
  83. package/lib/module/credential/presentation/errors.js +42 -0
  84. package/lib/module/credential/presentation/errors.js.map +1 -0
  85. package/lib/module/credential/presentation/index.js +2 -1
  86. package/lib/module/credential/presentation/index.js.map +1 -1
  87. package/lib/module/credential/status/02-status-attestation.js +11 -9
  88. package/lib/module/credential/status/02-status-attestation.js.map +1 -1
  89. package/lib/module/credential/status/README.md +5 -2
  90. package/lib/module/credential/status/types.js +0 -12
  91. package/lib/module/credential/status/types.js.map +1 -1
  92. package/lib/module/sd-jwt/errors.js +32 -0
  93. package/lib/module/sd-jwt/errors.js.map +1 -0
  94. package/lib/module/sd-jwt/index.js +5 -5
  95. package/lib/module/sd-jwt/index.js.map +1 -1
  96. package/lib/module/sd-jwt/verifier.js +5 -1
  97. package/lib/module/sd-jwt/verifier.js.map +1 -1
  98. package/lib/module/trust/index.js +3 -3
  99. package/lib/module/trust/index.js.map +1 -1
  100. package/lib/module/utils/decoder.js +3 -1
  101. package/lib/module/utils/decoder.js.map +1 -1
  102. package/lib/module/utils/error-codes.js +43 -0
  103. package/lib/module/utils/error-codes.js.map +1 -0
  104. package/lib/module/utils/errors.js +98 -438
  105. package/lib/module/utils/errors.js.map +1 -1
  106. package/lib/module/utils/misc.js +19 -49
  107. package/lib/module/utils/misc.js.map +1 -1
  108. package/lib/module/utils/par.js +3 -2
  109. package/lib/module/utils/par.js.map +1 -1
  110. package/lib/module/wallet-instance/README.md +26 -5
  111. package/lib/module/wallet-instance/index.js +32 -7
  112. package/lib/module/wallet-instance/index.js.map +1 -1
  113. package/lib/module/wallet-instance-attestation/README.md +8 -2
  114. package/lib/module/wallet-instance-attestation/issuing.js +15 -12
  115. package/lib/module/wallet-instance-attestation/issuing.js.map +1 -1
  116. package/lib/typescript/client/generated/wallet-provider.d.ts +138 -27
  117. package/lib/typescript/client/generated/wallet-provider.d.ts.map +1 -1
  118. package/lib/typescript/client/index.d.ts +7 -1
  119. package/lib/typescript/client/index.d.ts.map +1 -1
  120. package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts +2 -2
  121. package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts +17 -16
  122. package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts.map +1 -1
  123. package/lib/typescript/credential/issuance/05-authorize-access.d.ts.map +1 -1
  124. package/lib/typescript/credential/issuance/06-obtain-credential.d.ts.map +1 -1
  125. package/lib/typescript/credential/issuance/errors.d.ts +28 -0
  126. package/lib/typescript/credential/issuance/errors.d.ts.map +1 -0
  127. package/lib/typescript/credential/issuance/index.d.ts +4 -3
  128. package/lib/typescript/credential/issuance/index.d.ts.map +1 -1
  129. package/lib/typescript/credential/issuance/types.d.ts +0 -8
  130. package/lib/typescript/credential/issuance/types.d.ts.map +1 -1
  131. package/lib/typescript/credential/presentation/03-get-request-object.d.ts.map +1 -1
  132. package/lib/typescript/credential/presentation/04-send-authorization-response.d.ts.map +1 -1
  133. package/lib/typescript/credential/presentation/errors.d.ts +25 -0
  134. package/lib/typescript/credential/presentation/errors.d.ts.map +1 -0
  135. package/lib/typescript/credential/presentation/index.d.ts +2 -1
  136. package/lib/typescript/credential/presentation/index.d.ts.map +1 -1
  137. package/lib/typescript/credential/status/02-status-attestation.d.ts.map +1 -1
  138. package/lib/typescript/credential/status/types.d.ts +0 -15
  139. package/lib/typescript/credential/status/types.d.ts.map +1 -1
  140. package/lib/typescript/sd-jwt/errors.d.ts +20 -0
  141. package/lib/typescript/sd-jwt/errors.d.ts.map +1 -0
  142. package/lib/typescript/sd-jwt/index.d.ts +3 -2
  143. package/lib/typescript/sd-jwt/index.d.ts.map +1 -1
  144. package/lib/typescript/utils/error-codes.d.ts +45 -0
  145. package/lib/typescript/utils/error-codes.d.ts.map +1 -0
  146. package/lib/typescript/utils/errors.d.ts +88 -225
  147. package/lib/typescript/utils/errors.d.ts.map +1 -1
  148. package/lib/typescript/utils/misc.d.ts +9 -24
  149. package/lib/typescript/utils/misc.d.ts.map +1 -1
  150. package/lib/typescript/utils/par.d.ts.map +1 -1
  151. package/lib/typescript/wallet-instance/index.d.ts +17 -1
  152. package/lib/typescript/wallet-instance/index.d.ts.map +1 -1
  153. package/lib/typescript/wallet-instance-attestation/issuing.d.ts.map +1 -1
  154. package/lib/typescript/wallet-instance-attestation/types.d.ts +4 -4
  155. package/package.json +1 -1
  156. package/src/client/generated/wallet-provider.ts +43 -13
  157. package/src/client/index.ts +28 -15
  158. package/src/credential/issuance/03-start-user-authorization.ts +2 -2
  159. package/src/credential/issuance/04-complete-user-authorization.ts +57 -118
  160. package/src/credential/issuance/05-authorize-access.ts +7 -4
  161. package/src/credential/issuance/06-obtain-credential.ts +39 -39
  162. package/src/credential/issuance/README.md +8 -14
  163. package/src/credential/issuance/errors.ts +44 -0
  164. package/src/credential/issuance/index.ts +8 -2
  165. package/src/credential/issuance/types.ts +0 -8
  166. package/src/credential/presentation/01-start-flow.ts +1 -1
  167. package/src/credential/presentation/03-get-request-object.ts +3 -3
  168. package/src/credential/presentation/04-send-authorization-response.ts +3 -3
  169. package/src/credential/presentation/errors.ts +41 -0
  170. package/src/credential/presentation/index.ts +2 -0
  171. package/src/credential/status/02-status-attestation.ts +17 -25
  172. package/src/credential/status/README.md +5 -2
  173. package/src/credential/status/types.ts +0 -15
  174. package/src/sd-jwt/errors.ts +39 -0
  175. package/src/sd-jwt/index.ts +5 -8
  176. package/src/sd-jwt/verifier.ts +5 -5
  177. package/src/trust/index.ts +3 -3
  178. package/src/utils/decoder.ts +3 -3
  179. package/src/utils/error-codes.ts +50 -0
  180. package/src/utils/errors.ts +152 -476
  181. package/src/utils/misc.ts +21 -65
  182. package/src/utils/par.ts +3 -2
  183. package/src/wallet-instance/README.md +26 -5
  184. package/src/wallet-instance/index.ts +40 -18
  185. package/src/wallet-instance-attestation/README.md +8 -2
  186. package/src/wallet-instance-attestation/issuing.ts +28 -36
@@ -7,9 +7,9 @@ import {
7
7
  } from "@pagopa/io-react-native-jwt";
8
8
 
9
9
  import { createDPopToken } from "../../utils/dpop";
10
- import { NoSuitableKeysFoundInEntityConfiguration } from "../../utils/errors";
10
+ import { NoSuitableKeysFoundInEntityConfiguration } from "./errors";
11
11
  import type { EvaluateRelyingPartyTrust } from "./02-evaluate-rp-trust";
12
- import { hasStatus, type Out } from "../../utils/misc";
12
+ import { hasStatusOrThrow, type Out } from "../../utils/misc";
13
13
  import type { StartFlow } from "./01-start-flow";
14
14
  import { RequestObject } from "./types";
15
15
 
@@ -56,7 +56,7 @@ export const getRequestObject: GetRequestObject = async (
56
56
  DPoP: signedWalletInstanceDPoP,
57
57
  },
58
58
  })
59
- .then(hasStatus(200))
59
+ .then(hasStatusOrThrow(200))
60
60
  .then((res) => res.json())
61
61
  .then((responseJson) => responseJson.response);
62
62
 
@@ -2,8 +2,8 @@ import { EncryptJwe, SignJWT } from "@pagopa/io-react-native-jwt";
2
2
  import uuid from "react-native-uuid";
3
3
  import * as WalletInstanceAttestation from "../../wallet-instance-attestation";
4
4
  import type { JWK } from "@pagopa/io-react-native-jwt/lib/typescript/types";
5
- import { NoSuitableKeysFoundInEntityConfiguration } from "../../utils/errors";
6
- import { hasStatus, type Out } from "../../utils/misc";
5
+ import { NoSuitableKeysFoundInEntityConfiguration } from "./errors";
6
+ import { hasStatusOrThrow, type Out } from "../../utils/misc";
7
7
  import type { GetRequestObject } from "./03-get-request-object";
8
8
  import { disclose } from "../../sd-jwt";
9
9
  import type { EvaluateRelyingPartyTrust } from "./02-evaluate-rp-trust";
@@ -162,7 +162,7 @@ export const sendAuthorizationResponse: SendAuthorizationResponse = async (
162
162
  },
163
163
  body,
164
164
  })
165
- .then(hasStatus(200))
165
+ .then(hasStatusOrThrow(200))
166
166
  .then((res) => res.json())
167
167
  .then(AuthorizationResponse.parse);
168
168
  };
@@ -0,0 +1,41 @@
1
+ import { IoWalletError, serializeAttrs } from "../../utils/errors";
2
+
3
+ /**
4
+ * An error subclass thrown when auth request decode fail
5
+ *
6
+ */
7
+ export class AuthRequestDecodeError extends IoWalletError {
8
+ code = "ERR_IO_WALLET_AUTHENTICATION_REQUEST_DECODE_FAILED";
9
+
10
+ /** The Claim for which the validation failed. */
11
+ claim: string;
12
+
13
+ /** Reason code for the validation failure. */
14
+ reason: string;
15
+
16
+ constructor(
17
+ message: string,
18
+ claim: string = "unspecified",
19
+ reason: string = "unspecified"
20
+ ) {
21
+ super(serializeAttrs({ message, claim, reason }));
22
+ this.claim = claim;
23
+ this.reason = reason;
24
+ }
25
+ }
26
+
27
+ /**
28
+ * When selecting a public key from an entity configuration, and no one meets the requirements for the scenario
29
+ *
30
+ */
31
+ export class NoSuitableKeysFoundInEntityConfiguration extends IoWalletError {
32
+ code = "ERR_NO_SUITABLE_KEYS_NOT_FOUND";
33
+
34
+ /**
35
+ * @param scenario describe the scenario in which the error arise
36
+ */
37
+ constructor(scenario: string) {
38
+ const message = `Entity configuration do not provide any suitable keys (${scenario}).`;
39
+ super(message);
40
+ }
41
+ }
@@ -11,12 +11,14 @@ import {
11
11
  sendAuthorizationResponse,
12
12
  type SendAuthorizationResponse,
13
13
  } from "./04-send-authorization-response";
14
+ import * as Errors from "./errors";
14
15
 
15
16
  export {
16
17
  startFlowFromQR,
17
18
  evaluateRelyingPartyTrust,
18
19
  getRequestObject,
19
20
  sendAuthorizationResponse,
21
+ Errors,
20
22
  };
21
23
  export type {
22
24
  StartFlow,
@@ -1,19 +1,16 @@
1
1
  import {
2
2
  getCredentialHashWithouDiscloures,
3
- hasStatus,
4
- safeJsonParse,
3
+ hasStatusOrThrow,
5
4
  type Out,
6
5
  } from "../../utils/misc";
7
6
  import type { EvaluateIssuerTrust, ObtainCredential } from "../issuance";
8
- import { SignJWT, type CryptoContext } from "@pagopa/io-react-native-jwt";
7
+ import { type CryptoContext, SignJWT } from "@pagopa/io-react-native-jwt";
9
8
  import uuid from "react-native-uuid";
9
+ import { StatusAttestationResponse } from "./types";
10
10
  import {
11
- InvalidStatusAttestationResponse,
12
- StatusAttestationResponse,
13
- } from "./types";
14
- import {
15
- StatusAttestationError,
16
- CredentialInvalidStatusError,
11
+ IssuerResponseError,
12
+ IssuerResponseErrorCodes,
13
+ ResponseErrorBuilder,
17
14
  UnexpectedStatusCodeError,
18
15
  } from "../../utils/errors";
19
16
 
@@ -74,7 +71,7 @@ export const statusAttestation: StatusAttestation = async (
74
71
  },
75
72
  body: JSON.stringify(body),
76
73
  })
77
- .then(hasStatus(201))
74
+ .then(hasStatusOrThrow(201))
78
75
  .then((raw) => raw.json())
79
76
  .then((json) => StatusAttestationResponse.parse(json))
80
77
  .catch(handleStatusAttestationError);
@@ -94,19 +91,14 @@ const handleStatusAttestationError = (e: unknown) => {
94
91
  throw e;
95
92
  }
96
93
 
97
- if (e.statusCode === 404) {
98
- const maybeError = InvalidStatusAttestationResponse.safeParse(
99
- safeJsonParse(e.responseBody)
100
- );
101
- throw new CredentialInvalidStatusError(
102
- "Invalid status found for the given credential",
103
- maybeError.success ? maybeError.data.error : "unknown",
104
- e.message
105
- );
106
- }
107
-
108
- throw new StatusAttestationError(
109
- `Unable to obtain the status attestation for the given credential [response status code: ${e.statusCode}]`,
110
- e.message
111
- );
94
+ throw new ResponseErrorBuilder(IssuerResponseError)
95
+ .handle(404, {
96
+ code: IssuerResponseErrorCodes.CredentialInvalidStatus,
97
+ message: "Invalid status found for the given credential",
98
+ })
99
+ .handle("*", {
100
+ code: IssuerResponseErrorCodes.StatusAttestationRequestFailed,
101
+ message: `Unable to obtain the status attestation for the given credential`,
102
+ })
103
+ .buildFrom(e);
112
104
  };
@@ -16,11 +16,14 @@ graph TD;
16
16
  1 --> 2
17
17
  ```
18
18
 
19
+
19
20
  ## Mapped results
20
21
 
21
- ### 404 Not Found (CredentialInvalidStatusError)
22
+ The following errors are mapped to a `IssuerResponseError` with specific codes.
22
23
 
23
- A `404 Not Found` response is returned by the credential issuer when the status attestation is invalid.
24
+ |HTTP Status|Error Code|Description|
25
+ |-----------|----------|-----------|
26
+ |`404 Not Found`|`ERR_CREDENTIAL_INVALID_STATUS`|This response is returned by the credential issuer when the status attestation is invalid. It might contain more details in the `reason` property.|
24
27
 
25
28
  ## Example
26
29
 
@@ -41,18 +41,3 @@ export const ParsedStatusAttestation = z.object({
41
41
  iat: UnixTime,
42
42
  }),
43
43
  });
44
-
45
- /**
46
- * Shape from parsing a status attestation response in case of error.
47
- */
48
- export const InvalidStatusAttestationResponse = z.object({
49
- error: z.string(),
50
- });
51
-
52
- /**
53
- * Type from parsing a status attestation response in case of error.
54
- * Inferred from {@link InvalidStatusAttestationResponse}.
55
- */
56
- export type InvalidStatusAttestationResponse = z.infer<
57
- typeof InvalidStatusAttestationResponse
58
- >;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * When claims are requested but not found in the credential
3
+ *
4
+ */
5
+ export class ClaimsNotFoundBetweenDisclosures extends Error {
6
+ code = "ERR_CLAIMS_NOT_FOUND";
7
+
8
+ /** The Claims not found */
9
+ claims: string[];
10
+
11
+ constructor(claims: string | string[]) {
12
+ const c = Array.isArray(claims) ? claims : [claims];
13
+ const message = `Some requested claims are not present in the disclosurable values, claims: ${c.join(
14
+ ", "
15
+ )}`;
16
+ super(message);
17
+ this.claims = c;
18
+ }
19
+ }
20
+
21
+ /**
22
+ * When the SD-JWT does not contain an hashed reference to a given set of claims
23
+ */
24
+ export class ClaimsNotFoundInToken extends Error {
25
+ code = "ERR_CLAIMS_NOT_FOUND_IN_TOKEN";
26
+
27
+ /** The Claims not found */
28
+ claims: string[];
29
+
30
+ constructor(claims: string | string[]) {
31
+ const claimsArray = Array.isArray(claims) ? claims : [claims];
32
+ super(
33
+ `Some requested claims are not present in the disclosurable values: ${claimsArray.join(
34
+ ", "
35
+ )}`
36
+ );
37
+ this.claims = claimsArray;
38
+ }
39
+ }
@@ -6,10 +6,7 @@ import { sha256ToBase64 } from "@pagopa/io-react-native-jwt";
6
6
  import { Disclosure, SdJwt4VC, type DisclosureWithEncoded } from "./types";
7
7
  import { verifyDisclosure } from "./verifier";
8
8
  import type { JWK } from "../utils/jwk";
9
- import {
10
- ClaimsNotFoundBetweenDislosures,
11
- ClaimsNotFoundInToken,
12
- } from "../utils/errors";
9
+ import * as Errors from "./errors";
13
10
  import { Base64 } from "js-base64";
14
11
 
15
12
  const decodeDisclosure = (encoded: string): DisclosureWithEncoded => {
@@ -73,7 +70,7 @@ export const decode = <S extends z.ZodType<SdJwt4VC>>(
73
70
  * @param token The encoded token that represents a valid sd-jwt for verifiable credentials
74
71
  * @param claims The list of claims to be disclosed
75
72
  *
76
- * @throws {ClaimsNotFoundBetweenDislosures} When one or more claims does not relate to any discloure.
73
+ * @throws {ClaimsNotFoundBetweenDisclosures} When one or more claims does not relate to any discloure.
77
74
  * @throws {ClaimsNotFoundInToken} When one or more claims are not contained in the SD-JWT token.
78
75
  * @returns The encoded token with only the requested disclosures, along with the path each claim can be found on the SD-JWT token
79
76
  *
@@ -94,7 +91,7 @@ export const disclose = async (
94
91
 
95
92
  // check every claim represents a known disclosure
96
93
  if (!disclosure) {
97
- throw new ClaimsNotFoundBetweenDislosures(claim);
94
+ throw new Errors.ClaimsNotFoundBetweenDisclosures(claim);
98
95
  }
99
96
 
100
97
  const hash = await sha256ToBase64(disclosure.encoded);
@@ -106,7 +103,7 @@ export const disclose = async (
106
103
  return { claim, path: `verified_claims.claims._sd[${index}]` };
107
104
  }
108
105
 
109
- throw new ClaimsNotFoundInToken(claim);
106
+ throw new Errors.ClaimsNotFoundInToken(claim);
110
107
  })
111
108
  );
112
109
 
@@ -166,4 +163,4 @@ export const verify = async <S extends z.ZodType<SdJwt4VC>>(
166
163
  };
167
164
  };
168
165
 
169
- export { SdJwt4VC };
166
+ export { SdJwt4VC, Errors };
@@ -9,10 +9,10 @@ export const verifyDisclosure = async (
9
9
  ) => {
10
10
  let hash = await sha256ToBase64(encoded);
11
11
  if (!claims.includes(hash)) {
12
- throw new ValidationFailed(
13
- "Validation of disclosure failed",
14
- `${decoded}`,
15
- "Disclosure hash not found in claims"
16
- );
12
+ throw new ValidationFailed({
13
+ message: "Validation of disclosure failed",
14
+ claim: `${decoded}`,
15
+ reason: "Disclosure hash not found in claims",
16
+ });
17
17
  }
18
18
  };
@@ -8,7 +8,7 @@ import {
8
8
  EntityStatement,
9
9
  } from "./types";
10
10
  import { validateTrustChain, renewTrustChain } from "./chain";
11
- import { hasStatus } from "../utils/misc";
11
+ import { hasStatusOrThrow } from "../utils/misc";
12
12
 
13
13
  export type {
14
14
  WalletProviderEntityConfiguration,
@@ -70,7 +70,7 @@ export async function getSignedEntityConfiguration(
70
70
  return await appFetch(wellKnownUrl, {
71
71
  method: "GET",
72
72
  })
73
- .then(hasStatus(200))
73
+ .then(hasStatusOrThrow(200))
74
74
  .then((res) => res.text());
75
75
  }
76
76
 
@@ -256,6 +256,6 @@ export async function getSignedEntityStatement(
256
256
  return await appFetch(url, {
257
257
  method: "GET",
258
258
  })
259
- .then(hasStatus(200))
259
+ .then(hasStatusOrThrow(200))
260
260
  .then((res) => res.text());
261
261
  }
@@ -47,7 +47,7 @@ export const getJwtFromFormPost = async (
47
47
  }
48
48
  }
49
49
 
50
- throw new ValidationFailed(
51
- `Unable to obtain JWT from form_post.jwt. Form data: ${formData}`
52
- );
50
+ throw new ValidationFailed({
51
+ message: `Unable to obtain JWT from form_post.jwt. Form data: ${formData}`,
52
+ });
53
53
  };
@@ -0,0 +1,50 @@
1
+ export const IssuerResponseErrorCodes = {
2
+ IssuerGenericError: "ERR_ISSUER_GENERIC_ERROR",
3
+ /**
4
+ * Error code thrown when a credential cannot be issued immediately because it follows the async flow.
5
+ */
6
+ CredentialIssuingNotSynchronous: "ERR_CREDENTIAL_ISSUING_NOT_SYNCHRONOUS",
7
+ /**
8
+ * Error code thrown when an error occurs while requesting a credential.
9
+ */
10
+ CredentialRequestFailed: "ERR_CREDENTIAL_REQUEST_FAILED",
11
+ /**
12
+ * Error code thrown when a credential status is invalid, either during issuance or when requesting a status attestation.
13
+ */
14
+ CredentialInvalidStatus: "ERR_CREDENTIAL_INVALID_STATUS",
15
+ /**
16
+ * Error code thrown when an error occurs while obtaining a status attestation for a credential.
17
+ */
18
+ StatusAttestationRequestFailed: "ERR_STATUS_ATTESTATION_REQUEST_FAILED",
19
+ } as const;
20
+
21
+ export const WalletProviderResponseErrorCodes = {
22
+ WalletProviderGenericError: "ERR_IO_WALLET_PROVIDER_GENERIC_ERROR",
23
+ /**
24
+ * An error code thrown when an error occurs during the wallet instance creation process.
25
+ */
26
+ WalletInstanceCreationFailed: "ERR_IO_WALLET_INSTANCE_CREATION_FAILED",
27
+ /**
28
+ * An error code thrown when validation fail
29
+ */
30
+ WalletInstanceAttestationIssuingFailed:
31
+ "ERR_IO_WALLET_INSTANCE_ATTESTATION_ISSUING_FAILED",
32
+ /**
33
+ * An error code thrown when the requester does not pass the integrity checks when interacting with the Wallet Provider.
34
+ */
35
+ WalletInstanceIntegrityFailed: "ERR_IO_WALLET_INSTANCE_INTEGRITY_FAILED",
36
+ /**
37
+ * An error code thrown when obtaining a wallet instance attestation but the wallet instance is revoked.
38
+ */
39
+ WalletInstanceRevoked: "ERR_IO_WALLET_INSTANCE_REVOKED",
40
+ /**
41
+ * An error code thrown when obtaining a wallet instance attestation but the wallet instance is not found.
42
+ */
43
+ WalletInstanceNotFound: "ERR_IO_WALLET_INSTANCE_NOT_FOUND",
44
+ } as const;
45
+
46
+ export type IssuerResponseErrorCode =
47
+ (typeof IssuerResponseErrorCodes)[keyof typeof IssuerResponseErrorCodes];
48
+
49
+ export type WalletProviderResponseErrorCode =
50
+ (typeof WalletProviderResponseErrorCodes)[keyof typeof WalletProviderResponseErrorCodes];