@pagopa/io-react-native-iso18013 0.6.0 → 0.8.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.
- package/IoReactNativeIso18013.podspec +1 -1
- package/README.md +1 -1
- package/android/build.gradle +3 -2
- package/android/src/main/AndroidManifest.xml +17 -0
- package/android/src/main/AndroidManifestNew.xml +17 -0
- package/android/src/main/java/com/ioreactnativeiso18013/Enums.kt +42 -0
- package/android/src/main/java/com/ioreactnativeiso18013/IoNfcEngagementService.kt +17 -0
- package/android/src/main/java/com/ioreactnativeiso18013/IoReactNativeIso18013Module.kt +329 -137
- package/android/src/main/res/values/strings.xml +5 -0
- package/android/src/main/res/xml/nfc_engagement_apdu_service.xml +9 -0
- package/android/src/test/java/com/ioreactnativeiso18013/IoReactNativeIso18013Test.kt +11 -13
- package/ios/IoReactNativeIso18013.mm +8 -9
- package/ios/IoReactNativeIso18013.swift +264 -191
- package/lib/module/cbor/cbor/README.md +2 -1
- package/lib/module/cbor/cose/README.md +6 -4
- package/lib/module/iso18013/iso18013-5/README.md +161 -41
- package/lib/module/iso18013/iso18013-5/error.js +1 -3
- package/lib/module/iso18013/iso18013-5/error.js.map +1 -1
- package/lib/module/iso18013/iso18013-5/index.js +1 -1
- package/lib/module/iso18013/iso18013-5/index.js.map +1 -1
- package/lib/module/iso18013/iso18013-5/proximity.js +29 -19
- package/lib/module/iso18013/iso18013-5/proximity.js.map +1 -1
- package/lib/module/iso18013/iso18013-7/README.md +1 -1
- package/lib/typescript/src/iso18013/iso18013-5/error.d.ts +4 -4
- package/lib/typescript/src/iso18013/iso18013-5/error.d.ts.map +1 -1
- package/lib/typescript/src/iso18013/iso18013-5/index.d.ts +1 -1
- package/lib/typescript/src/iso18013/iso18013-5/index.d.ts.map +1 -1
- package/lib/typescript/src/iso18013/iso18013-5/proximity.d.ts +32 -13
- package/lib/typescript/src/iso18013/iso18013-5/proximity.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cbor/cbor/README.md +2 -1
- package/src/cbor/cose/README.md +6 -4
- package/src/iso18013/iso18013-5/README.md +161 -41
- package/src/iso18013/iso18013-5/error.ts +0 -2
- package/src/iso18013/iso18013-5/index.ts +3 -2
- package/src/iso18013/iso18013-5/proximity.ts +52 -23
- package/src/iso18013/iso18013-7/README.md +1 -1
package/src/cbor/cose/README.md
CHANGED
|
@@ -11,20 +11,21 @@ import { COSE } from '@pagopa/io-react-native-iso18013';
|
|
|
11
11
|
#### `sign`
|
|
12
12
|
|
|
13
13
|
Signs base64 encoded data using COSE (CBOR Object Signing and Encryption).
|
|
14
|
-
Returns a `Promise` which resolves to a `string` containing the COSE-Sign1 object in base64 encoding or rejects with
|
|
14
|
+
Returns a `Promise` which resolves to a `string` containing the COSE-Sign1 object in base64 encoding or rejects with a `ModuleError` in case of failures.
|
|
15
15
|
|
|
16
16
|
```typescript
|
|
17
17
|
try {
|
|
18
18
|
const coseSign1 = await COSE.sign('base64EncodedData', 'keyTag');
|
|
19
19
|
} catch (e) {
|
|
20
|
-
const
|
|
20
|
+
const parsedError = COSE.ModuleErrorSchema.parse(e);
|
|
21
|
+
console.log(parsedError.code, parsedError.message);
|
|
21
22
|
}
|
|
22
23
|
```
|
|
23
24
|
|
|
24
25
|
#### `verify`
|
|
25
26
|
|
|
26
27
|
Verifies a COSE-Sign1 object using the provided public key.
|
|
27
|
-
Returns a `Promise` which resolves to a `boolean` indicating if the signature is valid or rejects with
|
|
28
|
+
Returns a `Promise` which resolves to a `boolean` indicating if the signature is valid or rejects with a `ModuleError` in case of failures.
|
|
28
29
|
|
|
29
30
|
```typescript
|
|
30
31
|
// public key in JWK format
|
|
@@ -38,7 +39,8 @@ const publicKey = {
|
|
|
38
39
|
try {
|
|
39
40
|
const isValid = await COSE.verify('coseSign1Base64Data', publicKey);
|
|
40
41
|
} catch (e) {
|
|
41
|
-
const
|
|
42
|
+
const parsedError = COSE.ModuleErrorSchema.parse(e);
|
|
43
|
+
console.log(parsedError.code, parsedError.message);
|
|
42
44
|
}
|
|
43
45
|
```
|
|
44
46
|
|
|
@@ -9,27 +9,78 @@ yarn add @pagopa/io-react-native-iso18013
|
|
|
9
9
|
cd ios && bundle exec pod install && cd ..
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
+
## Permission
|
|
13
|
+
|
|
14
|
+
This library uses Bluetooth capabilities in order to implement the proximity flow defined in the ISO 18013-5 standard. Thus, Bluetooth permissions must be added to the native projects.
|
|
15
|
+
|
|
16
|
+
### Android
|
|
17
|
+
|
|
18
|
+
Add the following permissions to your `AndroidManifest.xml`:
|
|
19
|
+
|
|
20
|
+
```xml
|
|
21
|
+
<!-- Required for Bluetooth on Android >=12 or SDK >=31 -->
|
|
22
|
+
|
|
23
|
+
<!-- We defined the neverForLocation flag as we do not derive it from the Bluetooth -->
|
|
24
|
+
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation"/>
|
|
25
|
+
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
|
26
|
+
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
|
|
27
|
+
|
|
28
|
+
<!-- Required for Bluetooth on Android <=11 SDK <= 30 -->
|
|
29
|
+
<uses-permission android:name="android.permission.BLUETOOTH"
|
|
30
|
+
android:maxSdkVersion="30" />
|
|
31
|
+
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
|
|
32
|
+
android:maxSdkVersion="30" />
|
|
33
|
+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30"/>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Please note that the `neverForLocation` flag of `BLUETOOTH_SCAN` indicates that the app does not derive location information from Bluetooth scans. However, you still need to include the `ACCESS_FINE_LOCATION` permission for Android versions <=11 (SDK <=30) to enable Bluetooth scanning.
|
|
37
|
+
|
|
38
|
+
### iOS
|
|
39
|
+
|
|
40
|
+
Add the following keys to your `Info.plist`:
|
|
41
|
+
|
|
42
|
+
```xml
|
|
43
|
+
<!-- Required for Bluetooth usage -->
|
|
44
|
+
<key>NSBluetoothAlwaysUsageDescription</key>
|
|
45
|
+
<string>$(PRODUCT_NAME) needs access BLE.</string>
|
|
46
|
+
<key>NSBluetoothPeripheralUsageDescription</key>
|
|
47
|
+
<string>$(PRODUCT_NAME) needs access BLE.</string>
|
|
48
|
+
<key>NSBluetoothScanUsageDescription</key>
|
|
49
|
+
<string>$(PRODUCT_NAME) needs access to scan for nearby Bluetooth devices.</string>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
More info can be found in the [official Android documentation](https://developer.android.com/develop/connectivity/bluetooth/bt-permissions).
|
|
53
|
+
|
|
12
54
|
## Events
|
|
13
55
|
|
|
14
56
|
This library emits the following events:
|
|
15
57
|
| Event | Payload | Description |
|
|
16
|
-
|
|
17
|
-
|
|
|
58
|
+
|---------------------------|---------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------|
|
|
59
|
+
| onQrCodeString | `{ data: string }` | Event dispatched when the QR Code payload is generated. Contains the QR code string to display. |
|
|
60
|
+
| onNfcStarted | `undefined` | Event dispatched when NFC starts successfully. |
|
|
61
|
+
| onNfcStopped | `undefined` | Event dispatched when NFC stops successfully. |
|
|
62
|
+
| onDeviceConnecting | `undefined` | Event dispatched when the verifier app is connecting. |
|
|
18
63
|
| onDeviceConnected | `undefined` | Event dispatched when the verifier app is connected. |
|
|
19
|
-
| onDocumentRequestReceived | `{ data: string
|
|
64
|
+
| onDocumentRequestReceived | `{ data: string; retrievalMethod: RetrievalMethod }` | Event dispatched when the consumer app receives a new request. The `data` payload can be parsed via the `parseVerifierRequest` function. The `retrievalMethod` indicates whether BLE or NFC was used. |
|
|
20
65
|
| onDeviceDisconnected | `undefined` | Event dispatched when the verifier app disconnects by sending the END (0x02) flag. |
|
|
21
|
-
| onError | `{ error
|
|
66
|
+
| onError | `{ error?: string } \| undefined` | Event dispatched when an error occurs which is contained in the error payload. It can be parsed with `ISO18013_5.OnErrorPayloadSchema`. |
|
|
22
67
|
|
|
23
|
-
|
|
68
|
+
Where `RetrievalMethod` is defined as `'ble' | 'nfc'`.
|
|
69
|
+
|
|
70
|
+
### QR Code engagement flow
|
|
71
|
+
|
|
72
|
+
The events flow for QR Code engagement is described in the following diagram:
|
|
24
73
|
|
|
25
74
|
```mermaid
|
|
26
75
|
flowchart LR
|
|
27
|
-
|
|
76
|
+
onQrCodeString["onQrCodeString"]
|
|
77
|
+
onDeviceConnecting["onDeviceConnecting"]
|
|
28
78
|
onDeviceConnected["onDeviceConnected"]
|
|
29
79
|
onDocumentRequestReceived["onDocumentRequestReceived"]
|
|
30
80
|
onDeviceDisconnected["onDeviceDisconnected"]
|
|
31
81
|
onError["onError"]
|
|
32
82
|
|
|
83
|
+
onQrCodeString -- "Verifier scan the QR Code" --> onDeviceConnecting
|
|
33
84
|
onDeviceConnecting -- "Verifier app connects" --> onDeviceConnected
|
|
34
85
|
|
|
35
86
|
onDeviceConnected -- "Verifier app sends request" --> onDocumentRequestReceived
|
|
@@ -40,6 +91,36 @@ flowchart LR
|
|
|
40
91
|
onDocumentRequestReceived -- "Error status or abrupt disconnection" --> onError
|
|
41
92
|
```
|
|
42
93
|
|
|
94
|
+
### NFC engagement flow
|
|
95
|
+
|
|
96
|
+
The events flow for NFC engagement is described in the following diagram:
|
|
97
|
+
|
|
98
|
+
```mermaid
|
|
99
|
+
flowchart LR
|
|
100
|
+
onNfcStarted["onNfcStarted"]
|
|
101
|
+
onNfcStopped["onNfcStopped"]
|
|
102
|
+
onDeviceConnecting["onDeviceConnecting"]
|
|
103
|
+
onDeviceConnected["onDeviceConnected"]
|
|
104
|
+
onDocumentRequestReceived["onDocumentRequestReceived"]
|
|
105
|
+
onDeviceDisconnected["onDeviceDisconnected"]
|
|
106
|
+
onError["onError"]
|
|
107
|
+
|
|
108
|
+
onNfcStarted -- "Verifier taps NFC" --> onDeviceConnecting
|
|
109
|
+
onDeviceConnecting -- "Verifier app connects" --> onDeviceConnected
|
|
110
|
+
|
|
111
|
+
onDeviceConnected -- "Verifier app sends request" --> onDocumentRequestReceived
|
|
112
|
+
onDeviceConnected -- "Verifier sends END (0x02)" --> onDeviceDisconnected
|
|
113
|
+
onDeviceConnected -- "Error status or abrupt disconnection" --> onError
|
|
114
|
+
|
|
115
|
+
onDocumentRequestReceived -- "Verifier sends END (0x02)" --> onDeviceDisconnected
|
|
116
|
+
onDocumentRequestReceived -- "Error status or abrupt disconnection" --> onError
|
|
117
|
+
|
|
118
|
+
onError --> onNfcStopped
|
|
119
|
+
onDeviceDisconnected --> onNfcStopped
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Listen for events
|
|
123
|
+
|
|
43
124
|
Listeners can be added using the `addListener` method and removed by using the returned reference by calling the `remove` method.
|
|
44
125
|
|
|
45
126
|
```typescript
|
|
@@ -52,6 +133,39 @@ const listener = ISO18013_5.addListener('event', () =>
|
|
|
52
133
|
listener.remove();
|
|
53
134
|
```
|
|
54
135
|
|
|
136
|
+
#### `onQrCodeString`
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
import { ISO18013_5 } from '@pagopa/io-react-native-iso18013';
|
|
140
|
+
|
|
141
|
+
ISO18013_5.addListener(
|
|
142
|
+
'onQrCodeString',
|
|
143
|
+
(payload: ISO18013_5.EventsPayload['onQrCodeString']) => {
|
|
144
|
+
console.log('QR Code payload received: ', payload.data);
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
#### `onNfcStarted`
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
import { ISO18013_5 } from '@pagopa/io-react-native-iso18013';
|
|
153
|
+
|
|
154
|
+
ISO18013_5.addListener('onNfcStarted', () => {
|
|
155
|
+
console.log('NFC started and ready for engagement');
|
|
156
|
+
});
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
#### `onNfcStopped`
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
import { ISO18013_5 } from '@pagopa/io-react-native-iso18013';
|
|
163
|
+
|
|
164
|
+
ISO18013_5.addListener('onNfcStopped', () => {
|
|
165
|
+
console.log('NFC stopped');
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
55
169
|
#### `onDeviceConnecting`
|
|
56
170
|
|
|
57
171
|
```typescript
|
|
@@ -117,13 +231,13 @@ ISO18013_5.addListener(
|
|
|
117
231
|
if (!data || !data.error) {
|
|
118
232
|
throw new Error('No error data received');
|
|
119
233
|
}
|
|
120
|
-
const parsedError =
|
|
234
|
+
const parsedError = ISO18013_5.OnErrorPayloadSchema.parse(data.error);
|
|
121
235
|
console.error(`onError: ${parsedError}`);
|
|
122
236
|
} catch (e) {
|
|
123
237
|
console.error('Error parsing onError data:', e);
|
|
124
238
|
} finally {
|
|
125
239
|
// Close the flow on error
|
|
126
|
-
await
|
|
240
|
+
await ISO18013_5.close();
|
|
127
241
|
}
|
|
128
242
|
}
|
|
129
243
|
);
|
|
@@ -131,27 +245,37 @@ ISO18013_5.addListener(
|
|
|
131
245
|
|
|
132
246
|
## Methods
|
|
133
247
|
|
|
134
|
-
#### `
|
|
248
|
+
#### `startEngagement`
|
|
249
|
+
|
|
250
|
+
Starts the proximity flow with the specified engagement and retrieval modes. By default enables both QR code and NFC engagement with both BLE and NFC retrieval. NFC engagement requires iOS 17.4+ on iOS and HCE support on Android.
|
|
135
251
|
|
|
136
|
-
|
|
137
|
-
|
|
252
|
+
| Parameter | Platform | Default | Description |
|
|
253
|
+
| ------------------- | ----------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------- |
|
|
254
|
+
| `peripheralMode` | Android | `true` | Whether the device is in peripheral mode |
|
|
255
|
+
| `centralClientMode` | Android | `false` | Whether the device is in central client mode |
|
|
256
|
+
| `clearBleCache` | Android | `true` | Whether the BLE cache should be cleared |
|
|
257
|
+
| `certificates` | Android/iOS | `[]` | Two-dimensional array of base64 strings representing DER encoded X.509 certificates used to authenticate the verifier app |
|
|
258
|
+
| `engagementModes` | Android/iOS | `['qrcode', 'nfc']` | Array of engagement modes to activate (`'qrcode'` and/or `'nfc'`) |
|
|
259
|
+
| `retrievalMethods` | Android/iOS | `['ble', 'nfc']` | Array of supported retrieval methods (`'ble'` and/or `'nfc'`) |
|
|
138
260
|
|
|
139
261
|
```typescript
|
|
140
262
|
import { ISO18013_5 } from '@pagopa/io-react-native-iso18013';
|
|
141
263
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
#### `getQrCodeString`
|
|
264
|
+
// Starts both QR and NFC engagement with BLE and NFC retrieval (defaults)
|
|
265
|
+
await ISO18013_5.startEngagement();
|
|
146
266
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
267
|
+
// QR code engagement only (BLE retrieval)
|
|
268
|
+
await ISO18013_5.startEngagement({
|
|
269
|
+
engagementModes: ['qrcode'],
|
|
270
|
+
retrievalMethods: ['ble'],
|
|
271
|
+
});
|
|
152
272
|
|
|
153
|
-
|
|
154
|
-
|
|
273
|
+
// NFC engagement only, with both retrieval methods
|
|
274
|
+
await ISO18013_5.startEngagement({
|
|
275
|
+
engagementModes: ['nfc'],
|
|
276
|
+
retrievalMethods: ['ble', 'nfc'],
|
|
277
|
+
certificates: [['base64DerCert1']],
|
|
278
|
+
});
|
|
155
279
|
```
|
|
156
280
|
|
|
157
281
|
#### `generateResponse`
|
|
@@ -199,16 +323,15 @@ await ISO18013_5.sendResponse(response);
|
|
|
199
323
|
Sends an error response to the verifier app. The supported error codes are defined in the Table 20 of the ISO 18013-5 standard and are coded in the `ErrorCode` enum.
|
|
200
324
|
|
|
201
325
|
```typescript
|
|
202
|
-
import { ISO18013_5
|
|
326
|
+
import { ISO18013_5 } from '@pagopa/io-react-native-iso18013';
|
|
203
327
|
|
|
204
|
-
await ISO18013_5.sendErrorResponse(ErrorCode.SESSION_ENCRYPTION);
|
|
328
|
+
await ISO18013_5.sendErrorResponse(ISO18013_5.ErrorCode.SESSION_ENCRYPTION);
|
|
205
329
|
```
|
|
206
330
|
|
|
207
331
|
#### `close`
|
|
208
332
|
|
|
209
|
-
Closes the QR engagement by releasing the
|
|
333
|
+
Closes the QR/NFC engagement by releasing the bluetooth connection and clearing any allocated resources.
|
|
210
334
|
Before starting a new flow, it is necessary to call this method to ensure that the previous flow is properly closed.
|
|
211
|
-
Listeners can be added using the `addListener` method and removed using the `removeListener` method.
|
|
212
335
|
|
|
213
336
|
```typescript
|
|
214
337
|
import { ISO18013_5 } from '@pagopa/io-react-native-iso18013';
|
|
@@ -218,7 +341,7 @@ await ISO18013_5.close();
|
|
|
218
341
|
|
|
219
342
|
## Proximity Sequence Diagram
|
|
220
343
|
|
|
221
|
-
This section describes a high level overview of the happy flow interactions between an app implementing the `io-react-native-
|
|
344
|
+
This section describes a high level overview of the happy flow interactions between an app implementing the `io-react-native-iso18013` library and a verifier app.
|
|
222
345
|
|
|
223
346
|
```mermaid
|
|
224
347
|
sequenceDiagram
|
|
@@ -227,9 +350,8 @@ sequenceDiagram
|
|
|
227
350
|
participant verifier as Verifier App
|
|
228
351
|
|
|
229
352
|
Note over proximity, verifier: If an error occurs during the flow, the onError callback is triggered
|
|
230
|
-
app->>+proximity: Calls
|
|
231
|
-
app
|
|
232
|
-
proximity-->>+app: QR code string
|
|
353
|
+
app->>+proximity: Calls startEngagement()
|
|
354
|
+
proximity->>+app: Triggers the onQrCodeString callback with QR code data
|
|
233
355
|
app->>+app: Renders the QR code string
|
|
234
356
|
verifier->>+app: Scans the QR code
|
|
235
357
|
proximity->>+app: Triggers the onDeviceConnecting callback
|
|
@@ -266,17 +388,15 @@ sequenceDiagram
|
|
|
266
388
|
|
|
267
389
|
This table contains the list of error codes that can be thrown by the `ISO18013_5` module which are mapped via the `ModuleErrorCodes` type:
|
|
268
390
|
|
|
269
|
-
| Type | Platform | Description
|
|
270
|
-
| ------------------------- | ----------- |
|
|
271
|
-
| DRH_NOT_DEFINED | Android | The device retrieval helper hasn't been initialized
|
|
272
|
-
|
|
|
273
|
-
|
|
|
274
|
-
|
|
|
275
|
-
|
|
|
276
|
-
|
|
|
277
|
-
|
|
|
278
|
-
| CLOSE_ERROR | Android | An error occured while closing the required resources |
|
|
279
|
-
| EUNSPECIFIED | Android | Default error when no other error is specified |
|
|
391
|
+
| Type | Platform | Description |
|
|
392
|
+
| ------------------------- | ----------- | ---------------------------------------------------------------------- |
|
|
393
|
+
| DRH_NOT_DEFINED | Android | The device retrieval helper hasn't been initialized |
|
|
394
|
+
| START_ERROR | Android/iOS | An error occurred while starting the engagement |
|
|
395
|
+
| SEND_RESPONSE_ERROR | Android/iOS | An error occurred while sending the response for the verifier app |
|
|
396
|
+
| SEND_ERROR_RESPONSE_ERROR | Android/iOS | An error occurred while sending the error response to the verifier app |
|
|
397
|
+
| GENERATE_RESPONSE_ERROR | Android/iOS | An error occurred while generating the response for the verifier app |
|
|
398
|
+
| CLOSE_ERROR | Android | An error occurred while closing the required resources |
|
|
399
|
+
| EUNSPECIFIED | Android | Default error when no other error is specified |
|
|
280
400
|
|
|
281
401
|
An error can be parsed using the `ModuleErrorSchema` with type `ModuleErrorCodes` exposed by the `ISO18013_5` module. The error can be parsed as follows:
|
|
282
402
|
|
|
@@ -13,9 +13,7 @@ export type OnErrorPayload = z.infer<typeof OnErrorPayloadSchema>;
|
|
|
13
13
|
*/
|
|
14
14
|
const ModuleErrorCodesSchema = z.enum([
|
|
15
15
|
'DRH_NOT_DEFINED', // Android only
|
|
16
|
-
'QR_ENGAGEMENT_NOT_DEFINED', // Android only
|
|
17
16
|
'START_ERROR',
|
|
18
|
-
'GET_QR_CODE_ERROR',
|
|
19
17
|
'SEND_RESPONSE_ERROR',
|
|
20
18
|
'SEND_ERROR_RESPONSE_ERROR',
|
|
21
19
|
'GENERATE_RESPONSE_ERROR',
|
|
@@ -12,13 +12,14 @@ export {
|
|
|
12
12
|
ErrorCode,
|
|
13
13
|
type Events,
|
|
14
14
|
type EventsPayload,
|
|
15
|
+
type EngagementMode,
|
|
16
|
+
type RetrievalMethod,
|
|
15
17
|
addListener,
|
|
18
|
+
startEngagement,
|
|
16
19
|
close,
|
|
17
20
|
generateResponse,
|
|
18
|
-
getQrCodeString,
|
|
19
21
|
sendErrorResponse,
|
|
20
22
|
sendResponse,
|
|
21
|
-
start,
|
|
22
23
|
} from './proximity';
|
|
23
24
|
|
|
24
25
|
export { type RequestedDocument, type AcceptedFields } from '../types';
|
|
@@ -6,17 +6,24 @@ const eventEmitter = new NativeEventEmitter(IoReactNativeIso18013);
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Events emitted by the native module:
|
|
9
|
-
* - `
|
|
9
|
+
* - `onQrCodeString`: Emitted when the QR Code payload is generated.
|
|
10
|
+
* - `onNfcStarted`: Emitted when NFC starts successfully.
|
|
11
|
+
* - `onNfcStopped`: Emitted when NFC stops successfully.
|
|
12
|
+
* - `onDeviceConnecting`: Emitted when the device is connecting to the verifier app (QR and NFC flows on both iOS and Android).
|
|
10
13
|
* - `onDeviceConnected`: Emitted when the device is connected to the verifier app.
|
|
11
|
-
* - `onDocumentRequestReceived`: Emitted when a document request is received from the verifier app. Carries a payload containing the request data.
|
|
14
|
+
* - `onDocumentRequestReceived`: Emitted when a document request is received from the verifier app. Carries a payload containing the request data and the retrieval method.
|
|
12
15
|
* - `onDeviceDisconnected`: Emitted when the device is disconnected from the verifier app.
|
|
13
16
|
* - `onError`: Emitted when an error occurs. Carries a payload containing the error data.
|
|
14
17
|
*/
|
|
15
18
|
export type EventsPayload = {
|
|
19
|
+
onQrCodeString: { data: string };
|
|
20
|
+
onNfcStarted: undefined;
|
|
21
|
+
onNfcStopped: undefined;
|
|
16
22
|
onDeviceConnecting: undefined;
|
|
17
23
|
onDeviceConnected: undefined;
|
|
18
24
|
// The message payload is a JSON string that can be parsed into a `VerifierRequest` structure via `parseVerifierRequest`.
|
|
19
|
-
|
|
25
|
+
// When the request cannot be parsed, `data` may be an empty string.
|
|
26
|
+
onDocumentRequestReceived: { data: string; retrievalMethod: RetrievalMethod };
|
|
20
27
|
onDeviceDisconnected: undefined;
|
|
21
28
|
onError: { error?: string } | undefined;
|
|
22
29
|
};
|
|
@@ -38,45 +45,67 @@ export enum ErrorCode {
|
|
|
38
45
|
}
|
|
39
46
|
|
|
40
47
|
/**
|
|
41
|
-
*
|
|
48
|
+
* Supported engagement modes for initiating the presentation session.
|
|
49
|
+
* - qrcode: the presentation session is initiated by scanning a QR code generated by the verifier app. The requested data is then retrieved via BLE communication between the user device and the verifier app.
|
|
50
|
+
* - nfc: the presentation session is initiated by tapping the user device on an NFC tag of the verifier app. The requested data is then retrieved via NFC or BLE communication between the user device and the verifier app.
|
|
51
|
+
*/
|
|
52
|
+
export type EngagementMode = 'qrcode' | 'nfc';
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Supported methods for retrieving the requested data from the user device.
|
|
56
|
+
* - ble: the requested data is retrieved via Bluetooth Low Energy communication between the user device and the verifier app.
|
|
57
|
+
* - nfc: the requested data is retrieved via NFC communication between the user device and the verifier app.
|
|
58
|
+
*/
|
|
59
|
+
export type RetrievalMethod = 'ble' | 'nfc';
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Starts proximity engagement with caller-controlled retrieval methods.
|
|
42
63
|
* Resolves to true or rejects in case of error.
|
|
43
64
|
* @param config.peripheralMode (Android only) - Whether the device is in peripheral mode. Defaults to true
|
|
44
65
|
* @param config.centralClientMode (Android only) - Whether the device is in central client mode. Defaults to false
|
|
45
66
|
* @param config.clearBleCache (Android only) - Whether the BLE cache should be cleared. Defaults to true
|
|
46
67
|
* @param config.certificates - Two-dimensional array of base64 strings representing DER encoded X.509 certificate which are used to authenticate the verifier app
|
|
68
|
+
* @param config.engagementMethods - Array of engagements methods initiated. Defaults to ['qr', 'nfc']
|
|
69
|
+
* @param config.retrievalMethods - Array of supported retrieval methods. Defaults to ['ble', 'nfc']
|
|
47
70
|
* @throws {ModuleError} in case of error which can be parsed with {@link ModuleErrorSchema}
|
|
48
71
|
*/
|
|
49
|
-
export function
|
|
72
|
+
export function startEngagement(
|
|
50
73
|
config: {
|
|
51
74
|
peripheralMode?: boolean;
|
|
52
75
|
centralClientMode?: boolean;
|
|
53
76
|
clearBleCache?: boolean;
|
|
54
|
-
certificates?:
|
|
77
|
+
certificates?: ReadonlyArray<ReadonlyArray<string>>;
|
|
78
|
+
engagementModes?: ReadonlyArray<EngagementMode>;
|
|
79
|
+
retrievalMethods?: ReadonlyArray<RetrievalMethod>;
|
|
55
80
|
} = {}
|
|
56
81
|
): Promise<boolean> {
|
|
57
|
-
const {
|
|
58
|
-
|
|
82
|
+
const {
|
|
83
|
+
peripheralMode = true,
|
|
84
|
+
centralClientMode = false,
|
|
85
|
+
clearBleCache = true,
|
|
86
|
+
certificates = [],
|
|
87
|
+
engagementModes = ['qrcode', 'nfc'],
|
|
88
|
+
retrievalMethods = ['ble', 'nfc'],
|
|
89
|
+
} = config;
|
|
90
|
+
|
|
59
91
|
if (Platform.OS === 'ios') {
|
|
60
|
-
return IoReactNativeIso18013.
|
|
92
|
+
return IoReactNativeIso18013.startEngagement(
|
|
93
|
+
certificates,
|
|
94
|
+
engagementModes,
|
|
95
|
+
retrievalMethods
|
|
96
|
+
);
|
|
61
97
|
} else {
|
|
62
|
-
return IoReactNativeIso18013.
|
|
63
|
-
peripheralMode
|
|
64
|
-
centralClientMode
|
|
65
|
-
clearBleCache
|
|
66
|
-
certificates
|
|
98
|
+
return IoReactNativeIso18013.startEngagement(
|
|
99
|
+
peripheralMode,
|
|
100
|
+
centralClientMode,
|
|
101
|
+
clearBleCache,
|
|
102
|
+
certificates,
|
|
103
|
+
engagementModes,
|
|
104
|
+
retrievalMethods
|
|
67
105
|
);
|
|
68
106
|
}
|
|
69
107
|
}
|
|
70
108
|
|
|
71
|
-
/**
|
|
72
|
-
* Creates a QR code to be scanned in order to initialize the presentation.
|
|
73
|
-
* Resolves with a string containing the QR code or rejects in case of error.
|
|
74
|
-
* @throws {ModuleError} in case of error which can be parsed with {@link ModuleErrorSchema}
|
|
75
|
-
*/
|
|
76
|
-
export function getQrCodeString(): Promise<string> {
|
|
77
|
-
return IoReactNativeIso18013.getQrCodeString();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
109
|
/**
|
|
81
110
|
* Closes the bluetooth connection and clears any resource.
|
|
82
111
|
* Resolves to true after closing the connection or rejects in case of error.
|
|
@@ -52,7 +52,7 @@ This table contains the list of error codes that can be thrown by the `ISO18013_
|
|
|
52
52
|
| ------------------------------ | ----------- | ----------------------------------------------- |
|
|
53
53
|
| GENERATE_OID4VP_RESPONSE_ERROR | Android/iOS | An error occurred while generating the response |
|
|
54
54
|
|
|
55
|
-
An error can be parsed using the `ModuleErrorSchema` with type `ModuleErrorCodes` exposed by the `
|
|
55
|
+
An error can be parsed using the `ModuleErrorSchema` with type `ModuleErrorCodes` exposed by the `ISO18013_7` module. The error can be parsed as follows:
|
|
56
56
|
|
|
57
57
|
```typescript
|
|
58
58
|
import { ISO18013_7 } from '@pagopa/io-react-native-iso18013';
|