@pagopa/io-react-native-iso18013 0.2.0 → 0.4.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 (95) hide show
  1. package/android/build.gradle +1 -1
  2. package/android/src/main/java/com/ioreactnativeiso18013/IoReactNativeCborModule.kt +67 -164
  3. package/android/src/main/java/com/ioreactnativeiso18013/IoReactNativeIso18013Module.kt +102 -146
  4. package/ios/Base64Utils.swift +10 -3
  5. package/ios/IoReactNativeCbor.swift +55 -125
  6. package/ios/IoReactNativeIso18013.swift +88 -117
  7. package/lib/module/cbor/cbor/README.md +37 -5
  8. package/lib/module/cbor/cbor/error.js +15 -0
  9. package/lib/module/cbor/cbor/error.js.map +1 -0
  10. package/lib/module/cbor/cbor/index.js +1 -0
  11. package/lib/module/cbor/cbor/index.js.map +1 -1
  12. package/lib/module/cbor/cose/README.md +39 -9
  13. package/lib/module/cbor/cose/error.js +17 -0
  14. package/lib/module/cbor/cose/error.js.map +1 -0
  15. package/lib/module/cbor/cose/index.js +1 -0
  16. package/lib/module/cbor/cose/index.js.map +1 -1
  17. package/lib/module/cbor/index.js +1 -1
  18. package/lib/module/cbor/index.js.map +1 -1
  19. package/lib/module/iso18013/index.js +2 -3
  20. package/lib/module/iso18013/index.js.map +1 -1
  21. package/lib/module/iso18013/iso18013-5/README.md +52 -16
  22. package/lib/module/iso18013/iso18013-5/error.js +25 -0
  23. package/lib/module/iso18013/iso18013-5/error.js.map +1 -0
  24. package/lib/module/iso18013/iso18013-5/index.js +3 -2
  25. package/lib/module/iso18013/iso18013-5/index.js.map +1 -1
  26. package/lib/module/iso18013/iso18013-5/proximity.js +10 -18
  27. package/lib/module/iso18013/iso18013-5/proximity.js.map +1 -1
  28. package/lib/module/iso18013/iso18013-5/{schema.js → request.js} +1 -20
  29. package/lib/module/iso18013/iso18013-5/request.js.map +1 -0
  30. package/lib/module/iso18013/iso18013-7/README.md +38 -9
  31. package/lib/module/iso18013/iso18013-7/error.js +15 -0
  32. package/lib/module/iso18013/iso18013-7/error.js.map +1 -0
  33. package/lib/module/iso18013/iso18013-7/index.js +1 -0
  34. package/lib/module/iso18013/iso18013-7/index.js.map +1 -1
  35. package/lib/module/iso18013/iso18013-7/remote.js +2 -14
  36. package/lib/module/iso18013/iso18013-7/remote.js.map +1 -1
  37. package/lib/module/schema.js +46 -0
  38. package/lib/module/schema.js.map +1 -0
  39. package/lib/typescript/src/cbor/cbor/error.d.ts +68 -0
  40. package/lib/typescript/src/cbor/cbor/error.d.ts.map +1 -0
  41. package/lib/typescript/src/cbor/cbor/index.d.ts +1 -1
  42. package/lib/typescript/src/cbor/cbor/index.d.ts.map +1 -1
  43. package/lib/typescript/src/cbor/cose/error.d.ts +68 -0
  44. package/lib/typescript/src/cbor/cose/error.d.ts.map +1 -0
  45. package/lib/typescript/src/cbor/cose/index.d.ts +1 -1
  46. package/lib/typescript/src/cbor/cose/index.d.ts.map +1 -1
  47. package/lib/typescript/src/iso18013/index.d.ts +1 -2
  48. package/lib/typescript/src/iso18013/index.d.ts.map +1 -1
  49. package/lib/typescript/src/iso18013/iso18013-5/error.d.ts +73 -0
  50. package/lib/typescript/src/iso18013/iso18013-5/error.d.ts.map +1 -0
  51. package/lib/typescript/src/iso18013/iso18013-5/index.d.ts +3 -2
  52. package/lib/typescript/src/iso18013/iso18013-5/index.d.ts.map +1 -1
  53. package/lib/typescript/src/iso18013/iso18013-5/proximity.d.ts +2 -7
  54. package/lib/typescript/src/iso18013/iso18013-5/proximity.d.ts.map +1 -1
  55. package/lib/typescript/src/iso18013/iso18013-5/{schema.d.ts → request.d.ts} +1 -16
  56. package/lib/typescript/src/iso18013/iso18013-5/request.d.ts.map +1 -0
  57. package/lib/typescript/src/iso18013/iso18013-7/error.d.ts +68 -0
  58. package/lib/typescript/src/iso18013/iso18013-7/error.d.ts.map +1 -0
  59. package/lib/typescript/src/iso18013/iso18013-7/index.d.ts +2 -1
  60. package/lib/typescript/src/iso18013/iso18013-7/index.d.ts.map +1 -1
  61. package/lib/typescript/src/iso18013/iso18013-7/remote.d.ts +0 -14
  62. package/lib/typescript/src/iso18013/iso18013-7/remote.d.ts.map +1 -1
  63. package/lib/typescript/src/schema.d.ts +76 -0
  64. package/lib/typescript/src/schema.d.ts.map +1 -0
  65. package/package.json +1 -1
  66. package/src/cbor/cbor/README.md +37 -5
  67. package/src/cbor/cbor/error.ts +23 -0
  68. package/src/cbor/cbor/index.ts +5 -1
  69. package/src/cbor/cose/README.md +39 -9
  70. package/src/cbor/cose/error.ts +23 -0
  71. package/src/cbor/cose/index.ts +5 -1
  72. package/src/cbor/index.ts +1 -1
  73. package/src/iso18013/index.ts +2 -9
  74. package/src/iso18013/iso18013-5/README.md +52 -16
  75. package/src/iso18013/iso18013-5/error.ts +35 -0
  76. package/src/iso18013/iso18013-5/index.ts +9 -4
  77. package/src/iso18013/iso18013-5/proximity.ts +11 -19
  78. package/src/iso18013/iso18013-5/{schema.ts → request.ts} +0 -20
  79. package/src/iso18013/iso18013-7/README.md +38 -9
  80. package/src/iso18013/iso18013-7/error.ts +21 -0
  81. package/src/iso18013/iso18013-7/index.ts +5 -4
  82. package/src/iso18013/iso18013-7/remote.ts +2 -22
  83. package/src/schema.ts +55 -0
  84. package/lib/module/cbor/cbor/failure.js +0 -2
  85. package/lib/module/cbor/cbor/failure.js.map +0 -1
  86. package/lib/module/cbor/cose/failure.js +0 -2
  87. package/lib/module/cbor/cose/failure.js.map +0 -1
  88. package/lib/module/iso18013/iso18013-5/schema.js.map +0 -1
  89. package/lib/typescript/src/cbor/cbor/failure.d.ts +0 -15
  90. package/lib/typescript/src/cbor/cbor/failure.d.ts.map +0 -1
  91. package/lib/typescript/src/cbor/cose/failure.d.ts +0 -15
  92. package/lib/typescript/src/cbor/cose/failure.d.ts.map +0 -1
  93. package/lib/typescript/src/iso18013/iso18013-5/schema.d.ts.map +0 -1
  94. package/src/cbor/cbor/failure.ts +0 -18
  95. package/src/cbor/cose/failure.ts +0 -20
@@ -42,12 +42,42 @@ try {
42
42
  }
43
43
  ```
44
44
 
45
- ### Error Codes
46
-
47
- | Type | Platform | Description |
48
- | -------------------- | ----------- | -------------------------------------------------- |
49
- | PUBLIC_KEY_NOT_FOUND | Android/iOS | The public key is missing for the specified keyTag |
50
- | INVALID_ENCODING | Android/iOS | Provided payload has incorrect encoding |
51
- | UNABLE_TO_SIGN | Android/iOS | It was not possible to sign the given string |
52
- | THREADING_ERROR | iOS | Unexpected failure |
53
- | UNKNOWN_EXCEPTION | Android/iOS | Unexpected failure |
45
+ ### Error
46
+
47
+ This table contains the list of error codes that can be thrown by the `COSE` module which are mapped via the `ModuleErrorCodes` type:
48
+ | Type | Platform | Description |
49
+ | -------------------------- | ----------- | ------------------------------------------------------------ |
50
+ | SIGN_ERROR | Android/iOS | An error occurred while signing the data |
51
+ | VERIFY_ERROR | Android/iOS | An error occurred while verifying the signature |
52
+ | THREADING_ERROR | iOS | An error occurred while performing the sign operation in background |
53
+
54
+ An error can be parsed using the `ModuleErrorSchema` with type `ModuleErrorCodes` exposed by the `COSE` module. The error can be parsed as follows:
55
+
56
+ ```typescript
57
+ import { COSE } from '@pagopa/io-react-native-iso18013';
58
+ try {
59
+ await COSE.func();
60
+ } catch (error) {
61
+ const parsedError = COSE.ModuleErrorSchema.parse(error); // Or ModuleErrorSchema.safeParse(error) for safe parsing
62
+ console.log(JSON.stringify(parsedError, null, 2));
63
+ }
64
+ ```
65
+
66
+ The parsed object will contain properties from both iOS and Android platforms:
67
+
68
+ ```typescript
69
+ {
70
+ code: string; // Defined in ModuleErrorCodes
71
+ message: string;
72
+ name: string;
73
+ userInfo?: Record<string, any> | null;
74
+ nativeStackAndroid?: Array<{
75
+ lineNumber: number;
76
+ file: string;
77
+ methodName: string;
78
+ class: string;
79
+ }>;
80
+ domain?: string;
81
+ nativeStackIOS?: Array<string>;
82
+ };
83
+ ```
@@ -0,0 +1,23 @@
1
+ import z from 'zod';
2
+ import { GenericModuleErrorSchema } from '../../schema';
3
+
4
+ /**
5
+ * Error codes which the COSE module uses to reject a promise.
6
+ */
7
+ const ModuleErrorCodesSchema = z.enum([
8
+ 'SIGN_ERROR',
9
+ 'VERIFY_ERROR',
10
+ 'THREADING_ERROR', // iOS only
11
+ 'EUNSPECIFIED', // Android only default when no other error is specified
12
+ ]);
13
+
14
+ export type ModuleErrorCodes = z.infer<typeof ModuleErrorCodesSchema>;
15
+
16
+ /**
17
+ * Schema which can be used to parse a rejected promise error by the COSE module.
18
+ */
19
+ export const ModuleErrorSchema = GenericModuleErrorSchema(
20
+ ModuleErrorCodesSchema
21
+ );
22
+
23
+ export type ModuleError = z.infer<typeof ModuleErrorSchema>;
@@ -1,2 +1,6 @@
1
1
  export { sign, verify } from './sign';
2
- export { type CoseFailure, type CoseFailureCodes } from './failure';
2
+ export {
3
+ type ModuleErrorCodes,
4
+ type ModuleError,
5
+ ModuleErrorSchema,
6
+ } from './error';
package/src/cbor/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { NativeModules, Platform } from 'react-native';
2
2
 
3
3
  const LINKING_ERROR =
4
- `The package '@pagopa/io-react-native-cbor' doesn't seem to be linked. Make sure: \n\n` +
4
+ `The package '@pagopa/io-react-native-iso18013' (IoReactNativeCbor) doesn't seem to be linked. Make sure: \n\n` +
5
5
  Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
6
6
  '- You rebuilt the app after installing the package\n' +
7
7
  '- You are not using Expo Go\n';
@@ -1,19 +1,12 @@
1
1
  import { NativeModules, Platform } from 'react-native';
2
- export {
3
- type AcceptedFields,
4
- type EventError,
5
- type VerifierRequest,
6
- parseEventError,
7
- parseVerifierRequest,
8
- } from './iso18013-5/schema';
9
2
 
10
3
  const LINKING_ERROR =
11
- `The package '@pagopa/io-react-native-proximity' doesn't seem to be linked. Make sure: \n\n` +
4
+ `The package '@pagopa/io-react-native-iso18013' (IoReactNativeIso18013) doesn't seem to be linked. Make sure: \n\n` +
12
5
  Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
13
6
  '- You rebuilt the app after installing the package\n' +
14
7
  '- You are not using Expo Go\n';
15
8
 
16
- export const IoReactNativeProximity = NativeModules.IoReactNativeIso18013
9
+ export const IoReactNativeIso18013 = NativeModules.IoReactNativeIso18013
17
10
  ? NativeModules.IoReactNativeIso18013
18
11
  : new Proxy(
19
12
  {},
@@ -18,14 +18,16 @@ This library emits the following events:
18
18
  | onDeviceDisconnected | `undefined` | Event dispatched when the verifier app disconnects. |
19
19
  | onError | `{ error: string } \| undefined` | Event dispatched when an error occurs which is contained in the error payload. It can be parsed via the `parseError` provided [here](src/schema.ts). |
20
20
 
21
- Listeners can be added using the `addListener` method and removed using the `removeListener` method.
21
+ Listeners can be added using the `addListener` method and removed by using the returned reference by calling the `remove` method.
22
22
 
23
23
  ```typescript
24
24
  import { ISO18013_5 } from '@pagopa/io-react-native-iso18013';
25
25
 
26
- ISO18013_5.addListener('event', () => console.log('event occurred'));
26
+ const listener = ISO18013_5.addListener('event', () =>
27
+ console.log('event occurred')
28
+ );
27
29
 
28
- ISO18013_5.removeListener('event');
30
+ listener.remove();
29
31
  ```
30
32
 
31
33
  #### `onDeviceConnecting`
@@ -173,7 +175,7 @@ await ISO18013_5.sendErrorResponse({
173
175
 
174
176
  Closes the QR engagement by releasing the resources allocated during the `start` method.
175
177
  Before starting a new flow, it is necessary to call this method to ensure that the previous flow is properly closed.
176
- The listeners can be removed using the `removeListener` method.
178
+ Listeners can be added using the `addListener` method and removed using the `removeListener` method.
177
179
 
178
180
  ```typescript
179
181
  import { ISO18013_5 } from '@pagopa/io-react-native-iso18013';
@@ -220,15 +222,49 @@ sequenceDiagram
220
222
  proximity->>+app: Calls the onDeviceDisconnected callback
221
223
  ```
222
224
 
223
- ## Error Codes
224
-
225
- | Type | Platform | Description |
226
- | ------------------------------- | ----------- | ---------------------------------------------------------------------------- |
227
- | DRH_NOT_DEFINED | Android | The device retrieval helper hasn't been initialized, call the `start` method |
228
- | QR_ENGAGEMENT_NOT_DEFINED_ERROR | Android | The QR engagement hasn't been initialized, call the `start` method |
229
- | START_ERROR | Android/iOS | An error occurred while initializing the required resources |
230
- | GET_QR_CODE_ERROR | Android/iOS | An error occurred while generating the engagement QR code |
231
- | GENERATE_RESPONSE_ERROR | Android/iOS | An error occurred while generating the response for the verifier app |
232
- | SEND_RESPONSE_ERROR | Android/iOS | An error occurred while sending the response to the verifier app |
233
- | SEND_ERROR_RESPONSE_ERROR | Android/iOS | An error occurred while sending the error response to the verifier app |
234
- | CLOSE_ERROR | Android | An error occured while closing the required resources |
225
+ ## Errors
226
+
227
+ This table contains the list of error codes that can be thrown by the `ISO18013_5` module which are mapped via the `ModuleErrorCodes` type:
228
+
229
+ | Type | Platform | Description |
230
+ | ------------------------- | ----------- | ---------------------------------------------------------------------------- |
231
+ | DRH_NOT_DEFINED | Android | The device retrieval helper hasn't been initialized, call the `start` method |
232
+ | QR_ENGAGEMENT_NOT_DEFINED | Android | The QR engagement hasn't been initialized, call the `start` method |
233
+ | START_ERROR | Android/iOS | An error occurred while initializing the required resources |
234
+ | GET_QR_CODE_ERROR | Android/iOS | An error occurred while generating the engagement QR code |
235
+ | SEND_RESPONSE_ERROR | Android/iOS | An error occurred while sending the response for the verifier app |
236
+ | SEND_ERROR_RESPONSE_ERROR | Android/iOS | An error occurred while sending the error response to the verifier app |
237
+ | GENERATE_RESPONSE_ERROR | Android/iOS | An error occurred while generating the response for the verifier app |
238
+ | CLOSE_ERROR | Android | An error occured while closing the required resources |
239
+ | EUNSPECIFIED | Android | Default error when no other error is specified |
240
+
241
+ An error can be parsed using the `ModuleErrorSchema` with type `ModuleErrorCodes` exposed by the `ISO18013_5` module. The error can be parsed as follows:
242
+
243
+ ```typescript
244
+ import { ISO18013_5 } from '@pagopa/io-react-native-iso18013';
245
+ try {
246
+ await ISO18013_5.func();
247
+ } catch (error) {
248
+ const parsedError = ISO18013_5.ModuleErrorSchema.parse(error); // Or ModuleErrorSchema.safeParse(error) for safe parsing
249
+ console.log(JSON.stringify(parsedError, null, 2));
250
+ }
251
+ ```
252
+
253
+ The parsed object will contain properties from both iOS and Android platforms:
254
+
255
+ ```typescript
256
+ {
257
+ code: string; // Defined in ModuleErrorCodes
258
+ message: string;
259
+ name: string;
260
+ userInfo?: Record<string, any> | null;
261
+ nativeStackAndroid?: Array<{
262
+ lineNumber: number;
263
+ file: string;
264
+ methodName: string;
265
+ class: string;
266
+ }>;
267
+ domain?: string;
268
+ nativeStackIOS?: Array<string>;
269
+ };
270
+ ```
@@ -0,0 +1,35 @@
1
+ import z from 'zod';
2
+ import { GenericModuleErrorSchema } from '../../schema';
3
+
4
+ /**
5
+ * Schema for parsing the payload returned by the `onError` event in Proximity `Events`, along with its type definition.
6
+ */
7
+ export const OnErrorPayloadSchema = z.string().catch('Unknown error');
8
+
9
+ export type OnErrorPayload = z.infer<typeof OnErrorPayloadSchema>;
10
+
11
+ /**
12
+ * Error codes which the ISO18013_5 module uses to reject a promise.
13
+ */
14
+ const ModuleErrorCodesSchema = z.enum([
15
+ 'DRH_NOT_DEFINED', // Android only
16
+ 'QR_ENGAGEMENT_NOT_DEFINED', // Android only
17
+ 'START_ERROR',
18
+ 'GET_QR_CODE_ERROR',
19
+ 'SEND_RESPONSE_ERROR',
20
+ 'SEND_ERROR_RESPONSE_ERROR',
21
+ 'GENERATE_RESPONSE_ERROR',
22
+ 'CLOSE_ERROR', // Android only
23
+ 'EUNSPECIFIED', // Android only default when no other error is specified
24
+ ]);
25
+
26
+ export type ModuleErrorCodes = z.infer<typeof ModuleErrorCodesSchema>;
27
+
28
+ /**
29
+ * Schema which can be used to parse a rejected promise error by the ISO18013_5 module.
30
+ */
31
+ export const ModuleErrorSchema = GenericModuleErrorSchema(
32
+ ModuleErrorCodesSchema
33
+ );
34
+
35
+ export type ModuleError = z.infer<typeof ModuleErrorSchema>;
@@ -1,10 +1,16 @@
1
1
  export {
2
2
  type AcceptedFields,
3
- type EventError,
4
3
  type VerifierRequest,
5
- parseEventError,
6
4
  parseVerifierRequest,
7
- } from './schema';
5
+ } from './request';
6
+
7
+ export {
8
+ type OnErrorPayload,
9
+ OnErrorPayloadSchema,
10
+ ModuleErrorSchema,
11
+ type ModuleErrorCodes,
12
+ type ModuleError,
13
+ } from './error';
8
14
 
9
15
  export {
10
16
  ErrorCode,
@@ -14,7 +20,6 @@ export {
14
20
  close,
15
21
  generateResponse,
16
22
  getQrCodeString,
17
- removeListener,
18
23
  sendErrorResponse,
19
24
  sendResponse,
20
25
  start,
@@ -1,9 +1,9 @@
1
1
  import { NativeEventEmitter, Platform } from 'react-native';
2
- import { IoReactNativeProximity } from '..';
3
- import type { AcceptedFields } from './schema';
2
+ import type { AcceptedFields } from './request';
3
+ import { IoReactNativeIso18013 } from '..';
4
4
  import type { RequestedDocument } from '../types';
5
5
 
6
- const eventEmitter = new NativeEventEmitter(IoReactNativeProximity);
6
+ const eventEmitter = new NativeEventEmitter(IoReactNativeIso18013);
7
7
 
8
8
  /**
9
9
  * Events emitted by the native module:
@@ -56,9 +56,9 @@ export function start(
56
56
  const { peripheralMode, centralClientMode, clearBleCache, certificates } =
57
57
  config;
58
58
  if (Platform.OS === 'ios') {
59
- return IoReactNativeProximity.start(certificates ? certificates : []);
59
+ return IoReactNativeIso18013.start(certificates ? certificates : []);
60
60
  } else {
61
- return IoReactNativeProximity.start(
61
+ return IoReactNativeIso18013.start(
62
62
  peripheralMode ? peripheralMode : true,
63
63
  centralClientMode ? centralClientMode : false,
64
64
  clearBleCache ? clearBleCache : true,
@@ -71,14 +71,14 @@ export function start(
71
71
  * Gets the QR code string this method is responsible for initializing the connection and retrieving the QR code string
72
72
  */
73
73
  export function getQrCodeString(): Promise<string> {
74
- return IoReactNativeProximity.getQrCodeString();
74
+ return IoReactNativeIso18013.getQrCodeString();
75
75
  }
76
76
 
77
77
  /**
78
78
  * Closes the QR engagement
79
79
  */
80
80
  export function close(): Promise<boolean> {
81
- return IoReactNativeProximity.close();
81
+ return IoReactNativeIso18013.close();
82
82
  }
83
83
 
84
84
  /**
@@ -87,7 +87,7 @@ export function close(): Promise<boolean> {
87
87
  * @param code - The error code to be sent to the verifier app.
88
88
  */
89
89
  export function sendErrorResponse(code: ErrorCode): Promise<boolean> {
90
- return IoReactNativeProximity.sendErrorResponse(code);
90
+ return IoReactNativeIso18013.sendErrorResponse(code);
91
91
  }
92
92
 
93
93
  /**
@@ -100,7 +100,7 @@ export function generateResponse(
100
100
  documents: Array<RequestedDocument>,
101
101
  acceptedFields: AcceptedFields
102
102
  ): Promise<string> {
103
- return IoReactNativeProximity.generateResponse(documents, acceptedFields);
103
+ return IoReactNativeIso18013.generateResponse(documents, acceptedFields);
104
104
  }
105
105
 
106
106
  /**
@@ -109,7 +109,7 @@ export function generateResponse(
109
109
  * @param response - The base64 encoded response to be sent to the verifier app.
110
110
  */
111
111
  export function sendResponse(response: string): Promise<boolean> {
112
- return IoReactNativeProximity.sendResponse(response);
112
+ return IoReactNativeIso18013.sendResponse(response);
113
113
  }
114
114
 
115
115
  /**
@@ -122,13 +122,5 @@ export function addListener<E extends Events>(
122
122
  event: E,
123
123
  callback: (data: EventsPayload[E]) => void
124
124
  ) {
125
- eventEmitter.addListener(event, callback);
126
- }
127
-
128
- /**
129
- * Removes a listener for a `QrEngagementEvents` event.
130
- * @param event - The event to remove the listener for. The available events are defined in the `QrEngagementEvents` type.
131
- */
132
- export function removeListener(event: Events) {
133
- eventEmitter.removeAllListeners(event);
125
+ return eventEmitter.addListener(event, callback);
134
126
  }
@@ -44,26 +44,6 @@ export const parseVerifierRequest = (input: unknown): VerifierRequest => {
44
44
  return VerifierRequest.parse(input);
45
45
  };
46
46
 
47
- /**
48
- * Zod schema for the type returned by the `onError` event in Proximity `Events`.
49
- */
50
- const EventError = z.string().catch('Unknown error');
51
-
52
- /**
53
- * Error type returned by the `onError` event in Proximity `Events`.
54
- */
55
- export type EventError = z.infer<typeof EventError>;
56
-
57
- /**
58
- * Parses the input to an Error object.
59
- * This function is used to parse the error received from the verifier app via the `onError` event.
60
- * @param input - The input to be parsed
61
- * @returns The parsed Error object or a default error message if parsing fails
62
- */
63
- export const parseEventError = (input: unknown): EventError => {
64
- return EventError.parse(input);
65
- };
66
-
67
47
  /**
68
48
  * This is the type definition for the accepted fields that will be presented to the verifier app.
69
49
  * It contains of a nested object structure, where the outermost key represents the credential doctype.
@@ -48,12 +48,41 @@ export const generateOID4VPDeviceResponse = async (
48
48
  ) : Promise<string> => {...};
49
49
  ```
50
50
 
51
- ### Error Codes
52
-
53
- | Type | Platform | Description |
54
- | --------------------------------- | ----------- | ------------------------------------------------------------------ |
55
- | UNABLE_TO_GENERATE_RESPONSE | Android/iOS | Failure during the generation of a response |
56
- | DOC_REQUESTED_PARSING_EXCEPTION | Android/iOS | The passed documents where in a bad format or contained wrong data |
57
- | REQUESTED_ITEMS_PARSING_EXCEPTION | iOS | The passed items where in a bad format |
58
- | UNABLE_TO_GENERATE_TRANSCRIPT | Android | There has been an error generating the session transcript |
59
- | UNKNOWN_EXCEPTION | Android/iOS | Unexpected failure |
51
+ ## Errors
52
+
53
+ This table contains the list of error codes that can be thrown by the `ISO18013_7` module which are mapped via the `ModuleErrorCodes` type:
54
+
55
+ | Type | Platform | Description |
56
+ | ------------------------------ | ----------- | ----------------------------------------------- |
57
+ | GENERATE_OID4VP_RESPONSE_ERROR | Android/iOS | An error occurred while generating the response |
58
+
59
+ An error can be parsed using the `ModuleErrorSchema` with type `ModuleErrorCodes` exposed by the `ISO18013_5` module. The error can be parsed as follows:
60
+
61
+ ```typescript
62
+ import { ISO18013_7 } from '@pagopa/io-react-native-iso18013';
63
+ try {
64
+ await ISO18013_7.func();
65
+ } catch (error) {
66
+ const parsedError = ISO18013_7.ModuleErrorSchema.parse(error); // Or ModuleErrorSchema.safeParse(error) for safe parsing
67
+ console.log(JSON.stringify(parsedError, null, 2));
68
+ }
69
+ ```
70
+
71
+ The parsed object will contain properties from both iOS and Android platforms:
72
+
73
+ ```typescript
74
+ {
75
+ code: string; // Defined in ModuleErrorCodes
76
+ message: string;
77
+ name: string;
78
+ userInfo?: Record<string, any> | null;
79
+ nativeStackAndroid?: Array<{
80
+ lineNumber: number;
81
+ file: string;
82
+ methodName: string;
83
+ class: string;
84
+ }>;
85
+ domain?: string;
86
+ nativeStackIOS?: Array<string>;
87
+ };
88
+ ```
@@ -0,0 +1,21 @@
1
+ import z from 'zod';
2
+ import { GenericModuleErrorSchema } from '../../schema';
3
+
4
+ /**
5
+ * Error codes which the ISO18013_7 module uses to reject a promise.
6
+ */
7
+ const ModuleErrorCodesSchema = z.enum([
8
+ 'GENERATE_OID4VP_RESPONSE_ERROR',
9
+ 'EUNSPECIFIED', // Android only default when no other error is specified
10
+ ]);
11
+
12
+ export type ModuleErrorCodes = z.infer<typeof ModuleErrorCodesSchema>;
13
+
14
+ /**
15
+ * Schema which can be used to parse a rejected promise error by the ISO18013_7 module.
16
+ */
17
+ export const ModuleErrorSchema = GenericModuleErrorSchema(
18
+ ModuleErrorCodesSchema
19
+ );
20
+
21
+ export type ModuleError = z.infer<typeof ModuleErrorSchema>;
@@ -1,7 +1,8 @@
1
+ export { generateOID4VPDeviceResponse } from './remote';
1
2
  export {
2
- generateOID4VPDeviceResponse,
3
- type OID4VPFailure,
4
- type OID4VPFailureCodes,
5
- } from './remote';
3
+ ModuleErrorSchema,
4
+ type ModuleError,
5
+ type ModuleErrorCodes,
6
+ } from './error';
6
7
 
7
8
  export { type RequestedDocument } from '../types';
@@ -1,26 +1,6 @@
1
- import { IoReactNativeProximity } from '..';
1
+ import { IoReactNativeIso18013 } from '..';
2
2
  import type { RequestedDocument } from '../types';
3
3
 
4
- /**
5
- * All error codes that the module could return.
6
- */
7
- export type OID4VPFailureCodes =
8
- | 'UNABLE_TO_GENERATE_RESPONSE'
9
- | 'UNABLE_TO_GENERATE_TRANSCRIPT'
10
- | 'INVALID_DOC_REQUESTED'
11
- | 'GENERATE_OID4VP_DEVICE_RESPONSE_FAILED';
12
-
13
- /**
14
- * Error type returned by a rejected promise.
15
- *
16
- * If additional error information are available,
17
- * they are stored in the {@link OID4VPFailure["userInfo"]} field.
18
- */
19
- export type OID4VPFailure = {
20
- message: OID4VPFailureCodes;
21
- userInfo: Record<string, string>;
22
- };
23
-
24
4
  /**
25
5
  *
26
6
  * @param clientId extracted from OID4VP session
@@ -41,7 +21,7 @@ export const generateOID4VPDeviceResponse = async (
41
21
  documents: Array<RequestedDocument>,
42
22
  fieldRequestedAndAccepted: Record<string, any> | string
43
23
  ): Promise<string> => {
44
- return await IoReactNativeProximity.generateOID4VPDeviceResponse(
24
+ return await IoReactNativeIso18013.generateOID4VPDeviceResponse(
45
25
  clientId,
46
26
  responseUri,
47
27
  authorizationRequestNonce,
package/src/schema.ts ADDED
@@ -0,0 +1,55 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Schema for parsing a nativeStackAndroid object of a rejected promise error in an Android native module.
5
+ */
6
+ const StackTraceElementSchema = z.object({
7
+ lineNumber: z.number(),
8
+ file: z.string(),
9
+ methodName: z.string(),
10
+ class: z.string(),
11
+ });
12
+
13
+ /**
14
+ * Schema for parsing specific parameters of a rejected promise error in an Android native module.
15
+ * It's defined as partial to allow merging with the common schema and it must be checked at runtime.
16
+ */
17
+ const ModuleErrorAndroidSchema = z
18
+ .object({
19
+ nativeStackAndroid: z.array(StackTraceElementSchema),
20
+ })
21
+ .partial();
22
+
23
+ /**
24
+ * Schema for parsing specific parameters of a rejected promise error in an iOS native module.
25
+ * It's defined as partial to allow merging with the common schema and it must be checked at runtime.
26
+ */
27
+ const ModuleErrorIosSchema = z
28
+ .object({
29
+ domain: z.string(),
30
+ nativeStackIOS: z.array(z.string()),
31
+ })
32
+ .partial();
33
+
34
+ /**
35
+ * Schema for parsing common parameters of a rejected promise error in a native module.
36
+ * This schema contains the common parameters that are shared across both Android and iOS native modules.
37
+ * Parameters which are platform specific are defined as optional and must be checked at runtime.
38
+ * It accepts a generic code schema to allow for different error codes which can be defined in each module.
39
+ * @param codeSchema - The Zod schema for the error codes used by the module.
40
+ * @returns A schema for the common parameters of a rejected promise error in a native module.
41
+ */
42
+ export const GenericModuleErrorSchema = <
43
+ CodeType extends z.ZodEnum<[string, ...string[]]>,
44
+ >(
45
+ codeSchema: CodeType
46
+ ) =>
47
+ z
48
+ .object({
49
+ code: codeSchema,
50
+ message: z.string(),
51
+ name: z.string(),
52
+ userInfo: z.record(z.string(), z.any()).optional().or(z.null()),
53
+ })
54
+ .and(ModuleErrorAndroidSchema)
55
+ .and(ModuleErrorIosSchema);
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=failure.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../../src","sources":["cbor/cbor/failure.ts"],"mappings":"","ignoreList":[]}
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=failure.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../../src","sources":["cbor/cose/failure.ts"],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":["z","booleanFieldGroup","record","boolean","credentialEntrySchema","object","isAuthenticated","catchall","VerifierRequest","request","parseVerifierRequest","input","parse","EventError","string","catch","parseEventError"],"sourceRoot":"../../../../src","sources":["iso18013/iso18013-5/schema.ts"],"mappings":";;AAAA,SAASA,CAAC,QAAQ,KAAK;;AAEvB;AACA,MAAMC,iBAAiB,GAAGD,CAAC,CAACE,MAAM,CAACF,CAAC,CAACG,OAAO,CAAC,CAAC,CAAC;AAE/C,MAAMC,qBAAqB,GAAGJ,CAAC,CAC5BK,MAAM,CAAC;EACNC,eAAe,EAAEN,CAAC,CAACG,OAAO,CAAC;AAC7B,CAAC,CAAC,CACDI,QAAQ,CAACN,iBAAiB,CAAC;AAE9B,MAAMO,eAAe,GAAGR,CAAC,CAACK,MAAM,CAAC;EAC/BI,OAAO,EAAET,CAAC,CAACE,MAAM,CAACE,qBAAqB;AACzC,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMM,oBAAoB,GAAIC,KAAc,IAAsB;EACvE,OAAOH,eAAe,CAACI,KAAK,CAACD,KAAK,CAAC;AACrC,CAAC;;AAED;AACA;AACA;AACA,MAAME,UAAU,GAAGb,CAAC,CAACc,MAAM,CAAC,CAAC,CAACC,KAAK,CAAC,eAAe,CAAC;;AAEpD;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,eAAe,GAAIL,KAAc,IAAiB;EAC7D,OAAOE,UAAU,CAACD,KAAK,CAACD,KAAK,CAAC;AAChC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -1,15 +0,0 @@
1
- /**
2
- * All error codes that the module could return.
3
- */
4
- export type CborFailureCodes = 'UNABLE_TO_DECODE' | 'INVALID_ENCODING' | 'UNKNOWN_EXCEPTION';
5
- /**
6
- * Error type returned by a rejected promise.
7
- *
8
- * If additional error information are available,
9
- * they are stored in the {@link CborFailure["userInfo"]} field.
10
- */
11
- export type CborFailure = {
12
- message: CborFailureCodes;
13
- userInfo: Record<string, string>;
14
- };
15
- //# sourceMappingURL=failure.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"failure.d.ts","sourceRoot":"","sources":["../../../../../src/cbor/cbor/failure.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACxB,kBAAkB,GAClB,kBAAkB,GAClB,mBAAmB,CAAC;AAExB;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CAAC"}
@@ -1,15 +0,0 @@
1
- /**
2
- * All error codes that the module could return.
3
- */
4
- export type CoseFailureCodes = 'PUBLIC_KEY_NOT_FOUND' | 'UNABLE_TO_SIGN' | 'INVALID_ENCODING' | 'THREADING_ERROR' | 'UNKNOWN_EXCEPTION';
5
- /**
6
- * Error type returned by a rejected promise.
7
- *
8
- * If additional error information are available,
9
- * they are stored in the {@link CoseError["userInfo"]} field.
10
- */
11
- export type CoseFailure = {
12
- message: CoseFailureCodes;
13
- userInfo: Record<string, string>;
14
- };
15
- //# sourceMappingURL=failure.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"failure.d.ts","sourceRoot":"","sources":["../../../../../src/cbor/cose/failure.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACxB,sBAAsB,GACtB,gBAAgB,GAChB,kBAAkB,GAClB,iBAAiB,GACjB,mBAAmB,CAAC;AAExB;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../../src/iso18013/iso18013-5/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAWxB,QAAA,MAAM,eAAe;;;;;;;;;;;;;;;;EAEnB,CAAC;AAEH;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAE9D;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAAI,OAAO,OAAO,KAAG,eAErD,CAAC;AAEF;;GAEG;AACH,QAAA,MAAM,UAAU,yBAAoC,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,KAAG,UAEhD,CAAC;AAEF;;;;;;;;;;;;;;;IAeI;AACJ,MAAM,MAAM,cAAc,GAAG;IAC3B,CAAC,UAAU,EAAE,MAAM,GAAG;QACpB,CAAC,SAAS,EAAE,MAAM,GAAG;YAAE,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAA;SAAE,CAAC;KACnD,CAAC;CACH,CAAC"}
@@ -1,18 +0,0 @@
1
- /**
2
- * All error codes that the module could return.
3
- */
4
- export type CborFailureCodes =
5
- | 'UNABLE_TO_DECODE'
6
- | 'INVALID_ENCODING'
7
- | 'UNKNOWN_EXCEPTION';
8
-
9
- /**
10
- * Error type returned by a rejected promise.
11
- *
12
- * If additional error information are available,
13
- * they are stored in the {@link CborFailure["userInfo"]} field.
14
- */
15
- export type CborFailure = {
16
- message: CborFailureCodes;
17
- userInfo: Record<string, string>;
18
- };