@pagopa/io-react-native-wallet 0.24.1 → 0.26.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 (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
@@ -3,9 +3,25 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.WalletProviderResponseError = exports.WalletInstanceRevokedError = exports.WalletInstanceNotFoundError = exports.WalletInstanceIntegrityFailedError = exports.WalletInstanceCreationIntegrityError = exports.WalletInstanceCreationError = exports.WalletInstanceAttestationIssuingError = exports.ValidationFailed = exports.UnexpectedStatusCodeError = exports.StatusAttestationError = exports.PidMetadataError = exports.PidIssuingError = exports.OperationAbortedError = exports.NoSuitableKeysFoundInEntityConfiguration = exports.IoWalletError = exports.CredentialRequestError = exports.CredentialIssuingNotSynchronousError = exports.CredentialInvalidStatusError = exports.ClaimsNotFoundInToken = exports.ClaimsNotFoundBetweenDislosures = exports.AuthorizationIdpError = exports.AuthorizationError = exports.AuthRequestDecodeError = void 0;
6
+ exports.IssuerResponseError = exports.IoWalletError = void 0;
7
+ Object.defineProperty(exports, "IssuerResponseErrorCodes", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _errorCodes.IssuerResponseErrorCodes;
11
+ }
12
+ });
13
+ exports.WalletProviderResponseError = exports.ValidationFailed = exports.UnexpectedStatusCodeError = exports.ResponseErrorBuilder = void 0;
14
+ Object.defineProperty(exports, "WalletProviderResponseErrorCodes", {
15
+ enumerable: true,
16
+ get: function () {
17
+ return _errorCodes.WalletProviderResponseErrorCodes;
18
+ }
19
+ });
7
20
  exports.extractErrorMessageFromIssuerConf = extractErrorMessageFromIssuerConf;
8
- exports.serializeAttrs = void 0;
21
+ exports.serializeAttrs = exports.isWalletProviderResponseError = exports.isIssuerResponseError = void 0;
22
+ var _errorCodes = require("./error-codes");
23
+ // An error reason that supports both a string and a generic JSON object
24
+
9
25
  /**
10
26
  * utility to format a set of attributes into an error message string
11
27
  *
@@ -16,9 +32,14 @@ exports.serializeAttrs = void 0;
16
32
  * @param attrs A key value record set
17
33
  * @returns a human-readable serialization of the set
18
34
  */
19
- const serializeAttrs = attrs => Object.entries(attrs).map(_ref => {
20
- let [k, v] = _ref;
21
- return [k, Array.isArray(v) ? `(${v.join(", ")})` : v];
35
+ const serializeAttrs = attrs => Object.entries(attrs).filter(_ref => {
36
+ let [, v] = _ref;
37
+ return v !== undefined;
38
+ }).map(_ref2 => {
39
+ let [k, v] = _ref2;
40
+ if (Array.isArray(v)) return [k, `(${v.join(", ")})`];
41
+ if (typeof v !== "string") return [k, JSON.stringify(v)];
42
+ return [k, v];
22
43
  }).map(_ => _.join("=")).join(" ");
23
44
 
24
45
  /**
@@ -34,119 +55,32 @@ const serializeAttrs = attrs => Object.entries(attrs).map(_ref => {
34
55
  */
35
56
  exports.serializeAttrs = serializeAttrs;
36
57
  class IoWalletError extends Error {
37
- /** A unique error code for the particular error subclass. */
38
- static get code() {
39
- return "ERR_IO_WALLET_GENERIC";
40
- }
41
-
42
58
  /** A unique error code for the particular error subclass. */
43
59
  code = "ERR_IO_WALLET_GENERIC";
44
60
  constructor(message) {
45
- var _Error$captureStackTr;
46
61
  super(message);
47
62
  this.name = this.constructor.name;
48
- // @ts-ignore
49
- (_Error$captureStackTr = Error.captureStackTrace) === null || _Error$captureStackTr === void 0 ? void 0 : _Error$captureStackTr.call(Error, this, this.constructor);
50
63
  }
51
64
  }
52
65
 
53
- /**
54
- * An error subclass thrown when a Wallet Provider http request has a status code different from the one expected.
55
- */
56
- exports.IoWalletError = IoWalletError;
57
- class UnexpectedStatusCodeError extends IoWalletError {
58
- static get code() {
59
- return "ERR_UNEXPECTED_STATUS_CODE";
60
- }
61
- code = "ERR_UNEXPECTED_STATUS_CODE";
62
-
63
- /** HTTP status code */
64
-
65
- /** The stringified response body, useful to process the error response */
66
-
67
- constructor(message, statusCode, responseBody) {
68
- super(serializeAttrs({
69
- message,
70
- statusCode: statusCode.toString()
71
- }));
72
- this.statusCode = statusCode;
73
- this.responseBody = responseBody;
74
- }
75
- }
76
66
  /**
77
67
  * An error subclass thrown when validation fail
78
68
  *
79
69
  */
80
- exports.UnexpectedStatusCodeError = UnexpectedStatusCodeError;
70
+ exports.IoWalletError = IoWalletError;
81
71
  class ValidationFailed extends IoWalletError {
82
- static get code() {
83
- return "ERR_IO_WALLET_VALIDATION_FAILED";
84
- }
85
72
  code = "ERR_IO_WALLET_VALIDATION_FAILED";
86
73
 
87
74
  /** The Claim for which the validation failed. */
88
75
 
89
76
  /** Reason code for the validation failure. */
90
77
 
91
- constructor(message) {
92
- let claim = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "unspecified";
93
- let reason = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "unspecified";
94
- super(serializeAttrs({
95
- message,
96
- claim,
97
- reason
98
- }));
99
- this.claim = claim;
100
- this.reason = reason;
101
- }
102
- }
103
-
104
- /**
105
- * An error subclass thrown when validation fail
106
- *
107
- */
108
- exports.ValidationFailed = ValidationFailed;
109
- class WalletInstanceAttestationIssuingError extends IoWalletError {
110
- static get code() {
111
- return "ERR_IO_WALLET_INSTANCE_ATTESTATION_ISSUING_FAILED";
112
- }
113
- code = "ERR_IO_WALLET_INSTANCE_ATTESTATION_ISSUING_FAILED";
114
-
115
- /** The Claim for which the validation failed. */
116
-
117
- /** Reason code for the validation failure. */
118
-
119
- constructor(message) {
120
- let claim = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "unspecified";
121
- let reason = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "unspecified";
122
- super(serializeAttrs({
78
+ constructor(_ref3) {
79
+ let {
123
80
  message,
124
- claim,
125
- reason
126
- }));
127
- this.claim = claim;
128
- this.reason = reason;
129
- }
130
- }
131
-
132
- /**
133
- * An error subclass thrown when auth request decode fail
134
- *
135
- */
136
- exports.WalletInstanceAttestationIssuingError = WalletInstanceAttestationIssuingError;
137
- class AuthRequestDecodeError extends IoWalletError {
138
- static get code() {
139
- return "ERR_IO_WALLET_AUTHENTICATION_REQUEST_DECODE_FAILED";
140
- }
141
- code = "ERR_IO_WALLET_AUTHENTICATION_REQUEST_DECODE_FAILED";
142
-
143
- /** The Claim for which the validation failed. */
144
-
145
- /** Reason code for the validation failure. */
146
-
147
- constructor(message) {
148
- let claim = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "unspecified";
149
- let reason = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "unspecified";
81
+ claim = "unspecified",
82
+ reason = "unspecified"
83
+ } = _ref3;
150
84
  super(serializeAttrs({
151
85
  message,
152
86
  claim,
@@ -158,399 +92,70 @@ class AuthRequestDecodeError extends IoWalletError {
158
92
  }
159
93
 
160
94
  /**
161
- * An error subclass thrown when validation fail
162
- *
95
+ * An error subclass thrown when an HTTP request has a status code different from the one expected.
163
96
  */
164
- exports.AuthRequestDecodeError = AuthRequestDecodeError;
165
- class PidIssuingError extends IoWalletError {
166
- static get code() {
167
- return "ERR_IO_WALLET_PID_ISSUING_FAILED";
168
- }
169
- code = "ERR_IO_WALLET_PID_ISSUING_FAILED";
170
-
171
- /** The Claim for which the validation failed. */
172
-
173
- /** Reason code for the validation failure. */
174
-
175
- constructor(message) {
176
- let claim = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "unspecified";
177
- let reason = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "unspecified";
178
- super(serializeAttrs({
97
+ exports.ValidationFailed = ValidationFailed;
98
+ class UnexpectedStatusCodeError extends IoWalletError {
99
+ code = "ERR_UNEXPECTED_STATUS_CODE";
100
+ constructor(_ref4) {
101
+ let {
179
102
  message,
180
- claim,
181
- reason
182
- }));
183
- this.claim = claim;
184
- this.reason = reason;
185
- }
186
- }
187
-
188
- /**
189
- * When claims are requested but not found in the credential
190
- *
191
- */
192
- exports.PidIssuingError = PidIssuingError;
193
- class ClaimsNotFoundBetweenDislosures extends Error {
194
- static get code() {
195
- return "ERR_CLAIMS_NOT_FOUND";
196
- }
197
- code = "ERR_CLAIMS_NOT_FOUND";
198
-
199
- /** The Claims not found */
200
-
201
- constructor(claims) {
202
- const c = Array.isArray(claims) ? claims : [claims];
203
- const message = `Some requested claims are not present in the disclosurable values, claims: ${c.join(", ")}`;
204
- super(message);
205
- this.claims = c;
206
- }
207
- }
208
-
209
- /**
210
- * When the SD-JWT does not contain an hashed reference to a given set of claims
211
- */
212
- exports.ClaimsNotFoundBetweenDislosures = ClaimsNotFoundBetweenDislosures;
213
- class ClaimsNotFoundInToken extends Error {
214
- static get code() {
215
- return "ERR_CLAIMS_NOT_FOUND_IN_TOKEN";
216
- }
217
- code = "ERR_CLAIMS_NOT_FOUND_IN_TOKEN";
218
-
219
- /** The Claims not found */
220
-
221
- constructor(claims) {
222
- const c = Array.isArray(claims) ? claims : [claims];
223
- const message = `Some claims are not found in the given token, claims: ${c.join(", ")}`;
224
- super(message);
225
- this.claims = c;
226
- }
227
- }
228
-
229
- /**
230
- * When selecting a public key from an entity configuration, and no one meets the requirements for the scenario
231
- *
232
- */
233
- exports.ClaimsNotFoundInToken = ClaimsNotFoundInToken;
234
- class NoSuitableKeysFoundInEntityConfiguration extends Error {
235
- static get code() {
236
- return "ERR_NO_SUITABLE_KEYS_NOT_FOUND";
237
- }
238
- code = "ERR_NO_SUITABLE_KEYS_NOT_FOUND";
239
-
240
- /**
241
- * @param scenario describe the scenario in which the error arise
242
- */
243
- constructor(scenario) {
244
- const message = `Entity configuration do not provide any suitable keys (${scenario}).`;
245
- super(message);
246
- }
247
- }
248
-
249
- /**
250
- * When selecting a public key from an entity configuration, and no one meets the requirements for the scenario
251
- *
252
- */
253
- exports.NoSuitableKeysFoundInEntityConfiguration = NoSuitableKeysFoundInEntityConfiguration;
254
- class PidMetadataError extends Error {
255
- static get code() {
256
- return "PID_METADATA_ERROR";
257
- }
258
- constructor(message) {
259
- super(message);
260
- }
261
- }
262
-
263
- /**
264
- * An error subclass thrown when a Wallet Provider http request fail
265
- *
266
- */
267
- exports.PidMetadataError = PidMetadataError;
268
- class WalletProviderResponseError extends IoWalletError {
269
- static get code() {
270
- return "ERR_IO_WALLET_PROVIDER_RESPONSE_FAILED";
271
- }
272
- code = "ERR_IO_WALLET_PROVIDER_RESPONSE_FAILED";
273
-
274
- /** The Claim for which the validation failed. */
275
-
276
- /** Reason code for the validation failure. */
277
-
278
- /** HTTP status code */
279
-
280
- constructor(message) {
281
- let claim = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "unspecified";
282
- let reason = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "unspecified";
283
- let statusCode = arguments.length > 3 ? arguments[3] : undefined;
103
+ reason,
104
+ statusCode
105
+ } = _ref4;
284
106
  super(serializeAttrs({
285
107
  message,
286
- claim,
287
108
  reason,
288
- statusCode: statusCode.toString()
109
+ statusCode
289
110
  }));
290
- this.claim = claim;
291
111
  this.reason = reason;
292
112
  this.statusCode = statusCode;
293
113
  }
294
114
  }
295
- exports.WalletProviderResponseError = WalletProviderResponseError;
296
- class WalletInstanceRevokedError extends IoWalletError {
297
- static get code() {
298
- return "ERR_IO_WALLET_INSTANCE_REVOKED";
299
- }
300
- code = "ERR_IO_WALLET_INSTANCE_REVOKED";
301
- constructor(message, claim) {
302
- let reason = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "unspecified";
303
- super(serializeAttrs({
304
- message,
305
- claim,
306
- reason
307
- }));
308
- this.reason = reason;
309
- this.claim = claim;
310
- }
311
- }
312
- exports.WalletInstanceRevokedError = WalletInstanceRevokedError;
313
- class WalletInstanceNotFoundError extends IoWalletError {
314
- static get code() {
315
- return "ERR_IO_WALLET_INSTANCE_NOT_FOUND";
316
- }
317
- code = "ERR_IO_WALLET_INSTANCE_NOT_FOUND";
318
- constructor(message, claim) {
319
- let reason = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "unspecified";
320
- super(serializeAttrs({
321
- message,
322
- claim,
323
- reason
324
- }));
325
- this.reason = reason;
326
- this.claim = claim;
327
- }
328
- }
329
-
330
- /**
331
- * An error subclass thrown when obtaining a wallet instance attestation which fails due to the integrity.
332
- */
333
- exports.WalletInstanceNotFoundError = WalletInstanceNotFoundError;
334
- class WalletInstanceIntegrityFailedError extends IoWalletError {
335
- static get code() {
336
- return "ERR_IO_WALLET_INSTANCE_INTEGRITY_FAILED";
337
- }
338
- code = "ERR_IO_WALLET_INSTANCE_INTEGRITY_FAILED";
339
- constructor(message, claim) {
340
- let reason = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "unspecified";
341
- super(serializeAttrs({
342
- message,
343
- claim,
344
- reason
345
- }));
346
- this.reason = reason;
347
- this.claim = claim;
348
- }
349
- }
350
-
351
- /**
352
- * An error subclass thrown when an error occurs during the wallet instance creation process.
353
- */
354
- exports.WalletInstanceIntegrityFailedError = WalletInstanceIntegrityFailedError;
355
- class WalletInstanceCreationError extends IoWalletError {
356
- static get code() {
357
- return "ERR_IO_WALLET_INSTANCE_CREATION_ERROR";
358
- }
359
- code = "ERR_IO_WALLET_INSTANCE_CREATION_ERROR";
360
-
361
- /** The Claim for which the validation failed. */
362
-
363
- /** Reason code for the validation failure. */
364
-
365
- constructor(message) {
366
- let claim = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "unspecified";
367
- let reason = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "unspecified";
368
- super(serializeAttrs({
369
- message,
370
- claim,
371
- reason
372
- }));
373
- this.claim = claim;
374
- this.reason = reason;
375
- }
376
- }
377
-
378
- /**
379
- * An error subclass thrown when obtaining a wallet instance attestation which fails due to the integrity.
380
- */
381
- exports.WalletInstanceCreationError = WalletInstanceCreationError;
382
- class WalletInstanceCreationIntegrityError extends IoWalletError {
383
- static get code() {
384
- return "ERR_IO_WALLET_INSTANCE_CREATION_INTEGRITY_ERROR";
385
- }
386
- code = "ERR_IO_WALLET_INSTANCE_CREATION_INTEGRITY_ERROR";
387
- constructor(message, claim) {
388
- let reason = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "unspecified";
389
- super(serializeAttrs({
390
- message,
391
- claim,
392
- reason
393
- }));
394
- this.reason = reason;
395
- this.claim = claim;
396
- }
397
- }
398
-
399
- /**
400
- * An error subclass thrown when an error occurs during the authorization process.
401
- */
402
- exports.WalletInstanceCreationIntegrityError = WalletInstanceCreationIntegrityError;
403
- class AuthorizationError extends IoWalletError {
404
- static get code() {
405
- return "ERR_IO_WALLET_AUTHORIZATION_ERROR";
406
- }
407
- code = "ERR_IO_WALLET_AUTHORIZATION_ERROR";
408
- constructor(message) {
409
- super(message);
410
- }
411
- }
412
-
413
- /**
414
- * An error subclass thrown when an error occurs during the authorization process with the IDP.
415
- * It contains the error and error description returned by the IDP.
416
- */
417
- exports.AuthorizationError = AuthorizationError;
418
- class AuthorizationIdpError extends IoWalletError {
419
- static get code() {
420
- return "ERR_IO_WALLET_IDENTIFICATION_RESPONSE_ERROR";
421
- }
422
- code = "ERR_IO_WALLET_IDENTIFICATION_RESPONSE_PARSING_FAILED";
423
- constructor(error, errorDescription) {
424
- super(serializeAttrs(errorDescription ? {
425
- error,
426
- errorDescription
427
- } : {
428
- error
429
- }));
430
- this.error = error;
431
- this.errorDescription = errorDescription;
432
- }
433
- }
434
115
 
435
116
  /**
436
- * Error subclass thrown when an operation has been aborted.
437
- */
438
- exports.AuthorizationIdpError = AuthorizationIdpError;
439
- class OperationAbortedError extends IoWalletError {
440
- static get code() {
441
- return "ERR_IO_WALLET_OPERATION_ABORTED";
442
- }
443
- code = "ERR_IO_WALLET_OPERATION_ABORTED";
444
-
445
- /** The aborted operation */
446
-
447
- constructor(operation) {
448
- super(serializeAttrs({
449
- operation
450
- }));
451
- this.operation = operation;
452
- }
453
- }
454
-
455
- /**
456
- * Error subclass thrown when a credential status is invalid, either during issuance or when requesting a status attestation.
457
- */
458
- exports.OperationAbortedError = OperationAbortedError;
459
- class CredentialInvalidStatusError extends IoWalletError {
460
- static get code() {
461
- return "ERR_CREDENTIAL_INVALID_STATUS";
462
- }
463
- code = "ERR_CREDENTIAL_INVALID_STATUS";
464
-
465
- /**
466
- * The error code that should be mapped with one of the `issuance_errors_supported` in the EC.
467
- */
468
-
469
- constructor(message, errorCode) {
470
- let reason = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "unspecified";
471
- super(serializeAttrs({
472
- message,
473
- errorCode,
474
- reason
475
- }));
476
- this.errorCode = errorCode;
477
- this.reason = reason;
478
- }
479
- }
480
-
481
- /**
482
- * Error subclass thrown when an error occurs while obtaining a status attestation for a credential.
483
- */
484
- exports.CredentialInvalidStatusError = CredentialInvalidStatusError;
485
- class StatusAttestationError extends IoWalletError {
486
- static get code() {
487
- return "ERR_STATUS_ATTESTATION_ERROR";
488
- }
489
- code = "ERR_STATUS_ATTESTATION_ERROR";
490
- constructor(message) {
491
- let reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "unspecified";
492
- super(serializeAttrs({
493
- message,
494
- reason
495
- }));
496
- this.reason = reason;
497
- }
498
- }
499
-
500
- /**
501
- * Error subclass thrown when an error occurs while requesting a credential.
117
+ * An error subclass thrown when an Issuer HTTP request fails.
118
+ * The specific error can be found in the `code` property.
119
+ *
120
+ * The class is generic over the error code to narrow down the reason.
502
121
  */
503
- exports.StatusAttestationError = StatusAttestationError;
504
- class CredentialRequestError extends IoWalletError {
505
- static get code() {
506
- return "CREDENTIAL_REQUEST_ERROR";
507
- }
508
- code = "CREDENTIAL_REQUEST_ERROR";
509
- constructor(message) {
510
- let reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "unspecified";
511
- super(serializeAttrs({
512
- message,
513
- reason
514
- }));
515
- this.reason = reason;
122
+ exports.UnexpectedStatusCodeError = UnexpectedStatusCodeError;
123
+ class IssuerResponseError extends UnexpectedStatusCodeError {
124
+ constructor(params) {
125
+ super(params);
126
+ this.code = params.code ?? _errorCodes.IssuerResponseErrorCodes.IssuerGenericError;
516
127
  }
517
128
  }
518
129
 
519
130
  /**
520
- * Error subclass thrown when a credential cannot be issued immediately because it follows the async flow.
131
+ * An error subclass thrown when a Wallet Provider HTTP request fails.
132
+ * The specific error can be found in the `code` property.
521
133
  */
522
- exports.CredentialRequestError = CredentialRequestError;
523
- class CredentialIssuingNotSynchronousError extends IoWalletError {
524
- static get code() {
525
- return "CREDENTIAL_ISSUING_NOT_SYNCHRONOUS_ERROR";
526
- }
527
- code = "CREDENTIAL_ISSUING_NOT_SYNCHRONOUS_ERROR";
528
- constructor(message) {
529
- let reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "unspecified";
530
- super(serializeAttrs({
531
- message,
532
- reason
533
- }));
534
- this.reason = reason;
134
+ exports.IssuerResponseError = IssuerResponseError;
135
+ class WalletProviderResponseError extends UnexpectedStatusCodeError {
136
+ constructor(params) {
137
+ super(params);
138
+ this.reason = params.reason;
139
+ this.code = params.code ?? _errorCodes.WalletProviderResponseErrorCodes.WalletProviderGenericError;
535
140
  }
536
141
  }
537
- exports.CredentialIssuingNotSynchronousError = CredentialIssuingNotSynchronousError;
142
+ exports.WalletProviderResponseError = WalletProviderResponseError;
538
143
  /**
539
144
  * Function to extract the error message from the Entity Configuration's supported error codes.
540
145
  * @param errorCode The error code to map to a meaningful message
541
- * @param params.issuerConf The entity configuration for credentials
542
- * @param params.credentialType The type of credential the error belongs to
146
+ * @param issuerConf The entity configuration for credentials
147
+ * @param credentialType The type of credential the error belongs to
543
148
  * @returns A localized error {@link LocalizedIssuanceError} or undefined
544
- * @throws {Error} When no credential config is found
149
+ * @throws {IoWalletError} When no credential config is found
545
150
  */
546
- function extractErrorMessageFromIssuerConf(errorCode, _ref2) {
151
+ function extractErrorMessageFromIssuerConf(errorCode, _ref5) {
547
152
  let {
548
153
  issuerConf,
549
154
  credentialType
550
- } = _ref2;
155
+ } = _ref5;
551
156
  const credentialConfiguration = issuerConf.openid_credential_issuer.credential_configurations_supported[credentialType];
552
157
  if (!credentialConfiguration) {
553
- throw new Error(`No configuration found for ${credentialType} in the provided EC`);
158
+ throw new IoWalletError(`No configuration found for ${credentialType} in the provided EC`);
554
159
  }
555
160
  const {
556
161
  issuance_errors_supported
@@ -559,15 +164,66 @@ function extractErrorMessageFromIssuerConf(errorCode, _ref2) {
559
164
  return undefined;
560
165
  }
561
166
  const localesList = issuance_errors_supported[errorCode].display;
562
- return localesList.reduce((acc, _ref3) => {
167
+ return localesList.reduce((acc, _ref6) => {
563
168
  let {
564
169
  locale,
565
170
  ...rest
566
- } = _ref3;
171
+ } = _ref6;
567
172
  return {
568
173
  ...acc,
569
174
  [locale]: rest
570
175
  };
571
176
  }, {});
572
177
  }
178
+
179
+ /**
180
+ * Type guard for issuer errors.
181
+ * @param error The error to check
182
+ * @param code Optional code to narrow down the issuer error
183
+ */
184
+ const isIssuerResponseError = (error, code) => error instanceof IssuerResponseError && error.code === (code ?? error.code);
185
+
186
+ /**
187
+ * Type guard for wallet provider errors.
188
+ * @param error The error to check
189
+ * @param code Optional code to narrow down the wallet provider error
190
+ */
191
+ exports.isIssuerResponseError = isIssuerResponseError;
192
+ const isWalletProviderResponseError = (error, code) => error instanceof WalletProviderResponseError && error.code === (code ?? error.code);
193
+ exports.isWalletProviderResponseError = isWalletProviderResponseError;
194
+ /**
195
+ * Builder class used to create specialized errors from type {@link UnexpectedStatusCodeError} that handles multiple status codes.
196
+ *
197
+ * Chain multiple `handle` to add cases that depend on the status code, then call `buildFrom` when done.
198
+ *
199
+ * For example:
200
+ * ```
201
+ * new ResponseErrorBuilder(IssuerResponseError)
202
+ * .handle(403, { code: "ERROR_CODE_1", message: "Forbidden" })
203
+ * .handle(500, { code: "ERROR_CODE_2", message: "Unexpected error" })
204
+ * .handle("*", { code: "ERROR_CODE_3", message: "Fallback" })
205
+ * .buildFrom(baseError)
206
+ * ```
207
+ */
208
+ class ResponseErrorBuilder {
209
+ errorCases = {};
210
+ constructor(ErrorClass) {
211
+ this.ErrorClass = ErrorClass;
212
+ }
213
+ handle(status, params) {
214
+ this.errorCases[status] = params;
215
+ return this;
216
+ }
217
+ buildFrom(originalError) {
218
+ const params = this.errorCases[originalError.statusCode] ?? this.errorCases["*"];
219
+ if (params) {
220
+ return new this.ErrorClass({
221
+ ...originalError,
222
+ ...params
223
+ });
224
+ }
225
+ return originalError;
226
+ }
227
+ }
228
+ exports.ResponseErrorBuilder = ResponseErrorBuilder;
573
229
  //# sourceMappingURL=errors.js.map