@pagopa/io-react-native-cie 1.0.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/IoReactNativeCie.podspec +28 -0
- package/LICENSE +201 -0
- package/README.md +406 -0
- package/android/build.gradle +83 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/pagopa/ioreactnativecie/IoReactNativeCieModule.kt +302 -0
- package/android/src/main/java/com/pagopa/ioreactnativecie/IoReactNativeCiePackage.kt +17 -0
- package/android/src/main/java/com/pagopa/ioreactnativecie/cie/Atr.kt +39 -0
- package/android/src/main/java/com/pagopa/ioreactnativecie/cie/CieType.kt +157 -0
- package/ios/CIEType.swift +81 -0
- package/ios/IoReactNativeCie-Bridging-Header.h +2 -0
- package/ios/IoReactNativeCie.mm +43 -0
- package/ios/IoReactNativeCie.swift +227 -0
- package/lib/module/errors.js +2 -0
- package/lib/module/errors.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/manager/index.js +149 -0
- package/lib/module/manager/index.js.map +1 -0
- package/lib/module/manager/types.js +50 -0
- package/lib/module/manager/types.js.map +1 -0
- package/lib/module/native.js +13 -0
- package/lib/module/native.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/utils/index.js +45 -0
- package/lib/module/utils/index.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/errors.d.ts +24 -0
- package/lib/typescript/src/errors.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +6 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/manager/index.d.ts +113 -0
- package/lib/typescript/src/manager/index.d.ts.map +1 -0
- package/lib/typescript/src/manager/types.d.ts +83 -0
- package/lib/typescript/src/manager/types.d.ts.map +1 -0
- package/lib/typescript/src/native.d.ts +2 -0
- package/lib/typescript/src/native.d.ts.map +1 -0
- package/lib/typescript/src/utils/index.d.ts +30 -0
- package/lib/typescript/src/utils/index.d.ts.map +1 -0
- package/package.json +158 -0
- package/src/errors.ts +32 -0
- package/src/index.ts +14 -0
- package/src/manager/index.ts +167 -0
- package/src/manager/types.ts +94 -0
- package/src/native.ts +18 -0
- package/src/utils/index.ts +42 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "IoReactNativeCie"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
14
|
+
s.source = { :git => "https://github.com/pagopa/io-react-native-cie.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
17
|
+
|
|
18
|
+
# CieSDK dependency
|
|
19
|
+
s.dependency "CieSDK", "~> 0.1.11"
|
|
20
|
+
|
|
21
|
+
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
|
22
|
+
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|
|
23
|
+
if respond_to?(:install_modules_dependencies, true)
|
|
24
|
+
install_modules_dependencies(s)
|
|
25
|
+
else
|
|
26
|
+
s.dependency "React-Core"
|
|
27
|
+
end
|
|
28
|
+
end
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
[](https://www.npmjs.com/package/@pagopa/io-react-native-cie) [](LICENSE)
|
|
2
|
+
|
|
3
|
+
# @pagopa/io-react-native-cie
|
|
4
|
+
|
|
5
|
+
Module to handle CIE (Electronic Identity Card) operations natively in React Native apps.
|
|
6
|
+
|
|
7
|
+
> [!CAUTION]
|
|
8
|
+
> If you are migrating from `io-cie-sdk` please read the [migration guide](/docs/migrate-from-io-cie-sdk.md) carefully
|
|
9
|
+
|
|
10
|
+
## Table of Contents
|
|
11
|
+
|
|
12
|
+
- [Installation](#installation)
|
|
13
|
+
- [Setup](#setup)
|
|
14
|
+
- [Example App](#example-app)
|
|
15
|
+
- [API](#api)
|
|
16
|
+
- [Usage](#usage)
|
|
17
|
+
- [Check NFC Status](#check-nfc-status)
|
|
18
|
+
- [Reading CIE Data](#reading-cie-data)
|
|
19
|
+
- [Reading Attributes](#reading-attributes)
|
|
20
|
+
- [Authentication](#authentication)
|
|
21
|
+
- [Event System](#event-system)
|
|
22
|
+
- [Event Listeners](#event-listeners)
|
|
23
|
+
- [Example Usage](#example-usage)
|
|
24
|
+
- [NFC read events](#nfc-read-events)
|
|
25
|
+
- [NFC error events](#nfc-error-events)
|
|
26
|
+
- [Alert Messages](#alert-messages)
|
|
27
|
+
- [Available Alert Messages](#available-alert-messages)
|
|
28
|
+
- [NFC Events](#nfc-events)
|
|
29
|
+
- [iOS](#ios)
|
|
30
|
+
- [Android](#android)
|
|
31
|
+
- [NFC Errors](#nfc-errors)
|
|
32
|
+
- [iOS](#ios-1)
|
|
33
|
+
- [Android](#android-1)
|
|
34
|
+
- [Types](#types)
|
|
35
|
+
- [Errors](#errors)
|
|
36
|
+
- [Contributing](#contributing)
|
|
37
|
+
- [License](#license)
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
npm install @pagopa/io-react-native-cie
|
|
43
|
+
# or
|
|
44
|
+
yarn add @pagopa/io-react-native-cie
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### iOS
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
cd ios && bundle exec pod install && cd ..
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Setup
|
|
54
|
+
|
|
55
|
+
### Android
|
|
56
|
+
|
|
57
|
+
On Android you need to declare the following permission into your `AndroidManifest.xml`.
|
|
58
|
+
More info in the [official Android documentation](https://developer.android.com/develop/connectivity/nfc/nfc):
|
|
59
|
+
|
|
60
|
+
```xml
|
|
61
|
+
<!-- Required to access NFC hardware -->
|
|
62
|
+
<uses-permission android:name="android.permission.NFC" />
|
|
63
|
+
<!-- Required for authentication process -->
|
|
64
|
+
<uses-permission android:name="android.permission.INTERNET" />
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### iOS
|
|
68
|
+
|
|
69
|
+
1. In Apple developer site, enable capability for NFC.
|
|
70
|
+
2. Add `NFCReaderUsageDescription` into your `info.plist`, for example:
|
|
71
|
+
```xml
|
|
72
|
+
<key>NFCReaderUsageDescription</key>
|
|
73
|
+
<string>We need to use NFC</string>
|
|
74
|
+
```
|
|
75
|
+
[More info on Apple's doc](https://developer.apple.com/documentation/bundleresources/information-property-list/nfcreaderusagedescription?language=objc)
|
|
76
|
+
3. Add the required ISO7816 identifiers into your `info.plist`
|
|
77
|
+
```xml
|
|
78
|
+
<key>com.apple.developer.nfc.readersession.iso7816.select-identifiers</key>
|
|
79
|
+
<array>
|
|
80
|
+
<string>A0000000308000000009816001</string>
|
|
81
|
+
<string>A00000000039</string>
|
|
82
|
+
<string>A0000002471001</string>
|
|
83
|
+
<string>00000000000000</string>
|
|
84
|
+
</array>
|
|
85
|
+
```
|
|
86
|
+
[More info on Apple's doc](https://developer.apple.com/documentation/corenfc/nfciso7816tag).
|
|
87
|
+
4. In Xcode's **Signing & Capabilities** tab, make sure **Near Field Communication Tag Reading** capability had been added.
|
|
88
|
+
[More info on Apple's doc](https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_nfc_readersession_formats?language=objc).
|
|
89
|
+
|
|
90
|
+
## Example App
|
|
91
|
+
|
|
92
|
+
A fully working example app demonstrating how to use this package is available in the [example](./example) directory.
|
|
93
|
+
|
|
94
|
+
To run the example app, follow the instructions in [example/README.md](./example/README.md).
|
|
95
|
+
|
|
96
|
+
## API
|
|
97
|
+
|
|
98
|
+
List of available functions
|
|
99
|
+
|
|
100
|
+
| Function | Return | Descrizione |
|
|
101
|
+
| :---------------------------------------------------------------------------- | :----------------- | :------------------------------------------------------------ |
|
|
102
|
+
| `hasNFCFeature()` | `Promise<boolean>` | (Android) Checks if the device supports NFC feature |
|
|
103
|
+
| `isNfcEnabled()` | `Promise<boolean>` | (Android) Checks if the NFC is currently enabled |
|
|
104
|
+
| `isCieAuthenticationSupported()` | `Promise<boolean>` | (Android) Checks if the device supports CIE autentication |
|
|
105
|
+
| `openNfcSettings()` | `Promise<void>` | (Android) Opens NFC system settings page |
|
|
106
|
+
| `addListener(event: CieEvent, listener: CieEventHandlers)` | `() => void` | Adds a NFC event listener and returns a function to unsubscribe from the event |
|
|
107
|
+
| `removeListener(event: CieEvent)` | `void` | Removes all listeners for the specified event |
|
|
108
|
+
| `removeAllListeners()` | `void` | Removes all registered listeners |
|
|
109
|
+
| `setCustomIdpUrl(url: string)` | `void` | Updates IDP url |
|
|
110
|
+
| `setAlertMessage(key: AlertMessageKey, value: string)` | `void` | (iOS) Updates iOS NFC modal alert message |
|
|
111
|
+
| `setCurrentAlertMessage(value: string)` | `void` | (iOS) Updates currently displayed iOS NFC modal alert message |
|
|
112
|
+
| `startReadingAttributes(timeout: number)` | `Promise<void` | Start the CIE attributes reading process |
|
|
113
|
+
| `startReading(pin: string, authenticationUrl: string, timeout: number)` | `Promise<void` | Start the CIE reading process fro authentication |
|
|
114
|
+
| `stopReading()` | `Promise<void` | (Android) Stops all reading process |
|
|
115
|
+
|
|
116
|
+
## Usage
|
|
117
|
+
|
|
118
|
+
The package is split into two modules:
|
|
119
|
+
|
|
120
|
+
- [CieUtils](/src/utils): Provides functions to check the NFC status of the device.
|
|
121
|
+
- [CieManager](/src/manager): Provides CIE read and authentication capabilities.
|
|
122
|
+
|
|
123
|
+
### Check NFC Status
|
|
124
|
+
|
|
125
|
+
**Note:** These methods are applicable only for Android devices, as iOS devices always have NFC available.
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import { CieUtils } from '@pagopa/io-react-native-cie';
|
|
129
|
+
|
|
130
|
+
// Check if the device has NFC
|
|
131
|
+
await CieUtils.hasNfcFeature();
|
|
132
|
+
// Check if NFC is enabled
|
|
133
|
+
await CieUtils.isNfcEnabled();
|
|
134
|
+
// Convenient method to check if CIE authentication is supported
|
|
135
|
+
await CieUtils.isCieAuthenticationSupported();
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Reading CIE Data
|
|
139
|
+
|
|
140
|
+
#### Reading Attributes
|
|
141
|
+
|
|
142
|
+
Read CIE attributes (card type and base64-encoded data) with optional timeout (Android only)
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
import { CieManager } from '@pagopa/io-react-native-cie';
|
|
146
|
+
|
|
147
|
+
CieManager.startReadingAttributes()
|
|
148
|
+
.then(() => console.log('Reading started'))
|
|
149
|
+
.catch((error) => console.error('Error:', error));
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
#### Authentication
|
|
153
|
+
|
|
154
|
+
Start the CIE authentication process:
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
CieManager.startReading('12345678', 'https//auth-url.it')
|
|
158
|
+
.then(() => console.log('Authentication started'))
|
|
159
|
+
.catch((error) => console.error('Error:', error));
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Event System
|
|
163
|
+
|
|
164
|
+
The library uses an event-driven approach for NFC operations and read results. Events are emitted to notify your application about progress, success, or failure. Each listener method returns a cleanup function that should be called when the operation is complete or when your component unmounts.
|
|
165
|
+
|
|
166
|
+
#### Available events
|
|
167
|
+
|
|
168
|
+
| Listener Type | Description |
|
|
169
|
+
| -------------------- | ------------------------------------------------------------------------------------- |
|
|
170
|
+
| `onEvent` | NFC events emitted during the reading process which indicates the reading progression |
|
|
171
|
+
| `onError` | NFC error events emitted if the reading process fails |
|
|
172
|
+
| `onSuccess` | Authentication success event |
|
|
173
|
+
| `onAttributeSuccess` | Successful attribute reads |
|
|
174
|
+
|
|
175
|
+
#### Listening for events
|
|
176
|
+
|
|
177
|
+
You can register an event listiner with CieManager.addListener and remove it with the returned unregister function or by using CieManager.removeListener
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
const unsubscribe = CieManager.addListener('onEvent', (event) => {
|
|
181
|
+
console.log(event);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// remove the listener with
|
|
185
|
+
unsubscribe()
|
|
186
|
+
// or
|
|
187
|
+
CieManager.removeListener("onEvent);
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
#### Example Usage
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
import { CieManager } from '@pagopa/io-react-native-cie';
|
|
194
|
+
import { useEffect } from 'react';
|
|
195
|
+
|
|
196
|
+
// ...
|
|
197
|
+
|
|
198
|
+
useEffect(() => {
|
|
199
|
+
// Register all event listeners
|
|
200
|
+
const cleanup = [
|
|
201
|
+
CieManager.addListener('onEvent', (event) => {
|
|
202
|
+
console.info('NFC Event', event);
|
|
203
|
+
}),
|
|
204
|
+
CieManager.addListener('onError', (error) => {
|
|
205
|
+
console.error('NFC Error', error);
|
|
206
|
+
}),
|
|
207
|
+
CieManager.addListener('onSuccess', (url) => {
|
|
208
|
+
console.log('Auth url:', url);
|
|
209
|
+
}),
|
|
210
|
+
];
|
|
211
|
+
|
|
212
|
+
// Cleanup all listeners on unmount
|
|
213
|
+
return () => cleanup.forEach((remove) => remove());
|
|
214
|
+
}, []);
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
To remove all listeners at once:
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
CieManager.removeAllListeners();
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
#### NFC read events
|
|
224
|
+
|
|
225
|
+
List of events that are emitted during CIE reading process. Event names may differs based on the platform
|
|
226
|
+
|
|
227
|
+
<details>
|
|
228
|
+
<summary>iOS</summary>
|
|
229
|
+
|
|
230
|
+
| Event | Description |
|
|
231
|
+
| --------------------------- | ---------------------------------------------------------- |
|
|
232
|
+
| ON_TAG_DISCOVERED | Tag has been discovered |
|
|
233
|
+
| ON_TAG_DISCOVERED_NOT_CIE | Discovered tag is not a CIE |
|
|
234
|
+
| CONNECTED | Connected to tag |
|
|
235
|
+
| GET_SERVICE_ID | Get CIE serviceId |
|
|
236
|
+
| SELECT_IAS | Select IAS Application |
|
|
237
|
+
| SELECT_CIE | Select CIE Application |
|
|
238
|
+
| DH_INIT_GET_G | Get DiffieHellman G parameter |
|
|
239
|
+
| DH_INIT_GET_P | Get DiffieHellman P parameter |
|
|
240
|
+
| DH_INIT_GET_Q | Get DiffieHellman Q parameter |
|
|
241
|
+
| READ_CHIP_PUBLIC_KEY | Retrive internal authentication key |
|
|
242
|
+
| SELECT_FOR_READ_FILE | Select file |
|
|
243
|
+
| READ_FILE | Read file |
|
|
244
|
+
| GET_D_H_EXTERNAL_PARAMETERS | Retrive Diffie Hellman external authenticationl parameters |
|
|
245
|
+
| SET_D_H_PUBLIC_KEY | Set Diffie Hellman internal key |
|
|
246
|
+
| GET_ICC_PUBLIC_KEY | Retrive ICC Public Key |
|
|
247
|
+
| CHIP_SET_KEY | Select key for certificate validation |
|
|
248
|
+
| CHIP_VERIFY_CERTIFICATE | Certificate validation |
|
|
249
|
+
| CHIP_SET_CAR | Select key for external authentication |
|
|
250
|
+
| CHIP_GET_CHALLENGE | Get challenge for external authentication |
|
|
251
|
+
| CHIP_ANSWER_CHALLENGE | Responds to challenge for external authentication |
|
|
252
|
+
| SELECT_KEY | Select key |
|
|
253
|
+
| VERIFY_PIN | Verify CIE Pin |
|
|
254
|
+
| SIGN | Sign data |
|
|
255
|
+
| READ_CERTIFICATE | Read CIE User Certificate |
|
|
256
|
+
| SELECT_ROOT | Select Root Application |
|
|
257
|
+
|
|
258
|
+
</details>
|
|
259
|
+
|
|
260
|
+
<details>
|
|
261
|
+
|
|
262
|
+
<summary>Android</summary>
|
|
263
|
+
|
|
264
|
+
| Event | Description |
|
|
265
|
+
| ----------------------------- | ------------------------------------------------------ |
|
|
266
|
+
| ON_TAG_DISCOVERED | Tag has been discovered |
|
|
267
|
+
| ON_TAG_DISCOVERED_NOT_CIE | Discovered tag is not a CIE |
|
|
268
|
+
| CONNECTED | Connected to tag |
|
|
269
|
+
| SELECT_IAS_SERVICE_ID | Selects internal authentication service for service ID |
|
|
270
|
+
| SELECT_CIE_SERVICE_ID | Selects CIE service ID |
|
|
271
|
+
| SELECT_READ_FILE_SERVICE_ID | Selects read file service ID |
|
|
272
|
+
| READ_FILE_SERVICE_ID_RESPONSE | Reads file service ID response |
|
|
273
|
+
| SELECT_IAS | Selects internal authentication service |
|
|
274
|
+
| SELECT_CIE | Selects CIE application |
|
|
275
|
+
| DH_INIT_GET_G | Gets G for Diffie-Hellman initialization |
|
|
276
|
+
| DH_INIT_GET_P | Gets P for Diffie-Hellman initialization |
|
|
277
|
+
| DH_INIT_GET_Q | Gets Q for Diffie-Hellman initialization |
|
|
278
|
+
| SELECT_FOR_READ_FILE | Selects for reading a file |
|
|
279
|
+
| READ_FILE | Reads a file |
|
|
280
|
+
| INIT_EXTERNAL_AUTHENTICATION | Initializes external authentication |
|
|
281
|
+
| SET_MSE | Sets MSE |
|
|
282
|
+
| D_H_KEY_EXCHANGE_GET_DATA | Exchanges Diffie-Hellman data |
|
|
283
|
+
| SIGN1_SELECT | Selects SIGN1 message |
|
|
284
|
+
| SIGN1_VERIFY_CERT | Verifies SIGN1 certificate |
|
|
285
|
+
| SET_CHALLENGE_RESPONSE | Sets challenge response |
|
|
286
|
+
| GET_CHALLENGE_RESPONSE | Gets challenge response |
|
|
287
|
+
| EXTERNAL_AUTHENTICATION | Performs external authentication |
|
|
288
|
+
| INTERNAL_AUTHENTICATION | Performs internal authentication |
|
|
289
|
+
| GIVE_RANDOM | Provides random data |
|
|
290
|
+
| VERIFY_PIN | Verifies PIN |
|
|
291
|
+
| READ_FILE_SM | Reads file with secure messaging |
|
|
292
|
+
| SIGN | Signs data |
|
|
293
|
+
| SIGN_WITH_CIPHER | Signs with cipher |
|
|
294
|
+
| SELECT_ROOT | Selects root |
|
|
295
|
+
|
|
296
|
+
</details>
|
|
297
|
+
|
|
298
|
+
#### NFC error events
|
|
299
|
+
|
|
300
|
+
List of error event that may be emitted during CIE reading process
|
|
301
|
+
|
|
302
|
+
| Error | Description |
|
|
303
|
+
| ---------------------- | -------------------------------------- |
|
|
304
|
+
| NOT_A_CIE | Discovered tag is not a CIE |
|
|
305
|
+
| TAG_LOST | Tag was lost during read operation |
|
|
306
|
+
| CANCELLED_BY_USER | (iOS only) Read was cancelled by user |
|
|
307
|
+
| APDU_ERROR | Protocol error or not supported |
|
|
308
|
+
| CARD_BLOCKED | Too many PIN attempts, card is blocked |
|
|
309
|
+
| WRONG_PIN | Wrong PIN |
|
|
310
|
+
| NO_INTERNET_CONNECTION | Missing internet connection |
|
|
311
|
+
| CERTIFICATE_EXPIRED | CIE expired |
|
|
312
|
+
| CERTIFICATE_REVOKED | CIE revoked |
|
|
313
|
+
| AUTHENTICATION_ERROR | unable to complete authentication |
|
|
314
|
+
| GENERIC_ERROR | Unmapped or unexpected error |
|
|
315
|
+
|
|
316
|
+
### Alert Messages
|
|
317
|
+
|
|
318
|
+
**Note:** This feature is iOS-only; Android does not support alert messages.
|
|
319
|
+
|
|
320
|
+
<img src="https://github.com/user-attachments/assets/eaebf481-f5db-476e-977e-25653606ab8f" width="200" />
|
|
321
|
+
<img src="https://github.com/user-attachments/assets/dc7c5a81-954e-43dc-a468-6a2c17620eb1" width="200" />
|
|
322
|
+
<img src="https://github.com/user-attachments/assets/f473b67f-c5a5-4954-9e85-f2b414db53f2" width="200" />
|
|
323
|
+
|
|
324
|
+
Customize the NFC dialog messages using `CieManager.setAlertMessage(key, value)`:
|
|
325
|
+
|
|
326
|
+
```typescript
|
|
327
|
+
CieManager.setAlertMessage(
|
|
328
|
+
'readingInstructions',
|
|
329
|
+
'Hold your iPhone near your CIE card to begin scanning.'
|
|
330
|
+
);
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
You can update the currently displayed alert message (for example, during the reading process) using `CieManager.setCurrentAlertMessage(value)`:
|
|
334
|
+
|
|
335
|
+
```typescript
|
|
336
|
+
CieManager.setCurrentAlertMessage('Reading in progress, 80% completed');
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
#### Available Alert Messages
|
|
340
|
+
|
|
341
|
+
| Key | Description | Default Message |
|
|
342
|
+
| ---------------------- | ------------------------ | ------------------------------------------------------------------------------------------------- |
|
|
343
|
+
| `readingInstructions` | Pre-scan instructions | "Tieni la tua carta d'identità elettronica sul retro dell'iPhone, nella parte in alto." |
|
|
344
|
+
| `moreTags` | Multiple tags detected | "Sono stati individuate più carte NFC. Per favore avvicina una carta alla volta." |
|
|
345
|
+
| `readingInProgress` | Reading status | "Lettura in corso, tieni ferma la carta ancora per qualche secondo..." |
|
|
346
|
+
| `readingSuccess` | Success message | "Lettura avvenuta con successo. Puoi rimuovere la carta mentre completiamo la verifica dei dati." |
|
|
347
|
+
| `invalidCard` | Invalid card error | "La carta utilizzata non sembra essere una Carta di Identità Elettronica (CIE)." |
|
|
348
|
+
| `tagLost` | Card removed error | "Hai rimosso la carta troppo presto." |
|
|
349
|
+
| `cardLocked` | Card locked error | "Carta CIE bloccata" |
|
|
350
|
+
| `wrongPin1AttemptLeft` | PIN warning (1 attempt) | "PIN errato, hai ancora 1 tentativo" |
|
|
351
|
+
| `wrongPin2AttemptLeft` | PIN warning (2 attempts) | "PIN errato, hai ancora 2 tentativi" |
|
|
352
|
+
| `genericError` | Generic error | "Qualcosa è andato storto" |
|
|
353
|
+
|
|
354
|
+
## Types
|
|
355
|
+
|
|
356
|
+
```typescript
|
|
357
|
+
type CieAttributes = {
|
|
358
|
+
type: string;
|
|
359
|
+
base64: string;
|
|
360
|
+
};
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
Contains the CIE type (NFC manufacturer) and the attributres in base64 encoded string format.
|
|
364
|
+
CIE type can be one of the following: `NXP`, `GEMALTO`, `GEMALTO_2`, `ACTALIS`, `ST`, `UNKNOWN`
|
|
365
|
+
|
|
366
|
+
```typescript
|
|
367
|
+
type NfcEvent = {
|
|
368
|
+
name: string;
|
|
369
|
+
progress: number;
|
|
370
|
+
};
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
Event sent during the CIE reading process. Contains the name of the event and the progress associated. Event names and order may vary based on the platform.
|
|
374
|
+
|
|
375
|
+
```typescript
|
|
376
|
+
type NfcError = {
|
|
377
|
+
name: NfcErrorName;
|
|
378
|
+
message?: string;
|
|
379
|
+
};
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
Error event that may be sent during the CIE reading process. Contains the name of the error and an optional message. Error names and order may vary based on the platform.
|
|
383
|
+
|
|
384
|
+
## Errors
|
|
385
|
+
|
|
386
|
+
The CIE reading function may throw exceptions if the reading process cannot be initiated. These exceptions indicate issues with input validation or system compatibility.
|
|
387
|
+
Below is a comprehensive list of possible exceptions that may be thrown during initialization:
|
|
388
|
+
|
|
389
|
+
| Error Code | Platform | Description |
|
|
390
|
+
| --------------------- | ----------- | ----------------------- |
|
|
391
|
+
| `PIN_REGEX_NOT_VALID` | ios/Android | Invalid PIN format |
|
|
392
|
+
| `INVALID_AUTH_URL` | ios/Android | Invalid auth url format |
|
|
393
|
+
| `THREADING_ERROR` | iOS | Unexpected error |
|
|
394
|
+
| `UNKNOWN_EXCEPTION` | iOS/Android | Unexpected error |
|
|
395
|
+
|
|
396
|
+
## Contributing
|
|
397
|
+
|
|
398
|
+
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
|
399
|
+
|
|
400
|
+
## License
|
|
401
|
+
|
|
402
|
+
MIT
|
|
403
|
+
|
|
404
|
+
---
|
|
405
|
+
|
|
406
|
+
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
|