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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. package/README.md +1 -3
  2. package/lib/commonjs/credential/issuance/05-authorize-access.js +1 -0
  3. package/lib/commonjs/credential/issuance/05-authorize-access.js.map +1 -1
  4. package/lib/commonjs/credential/issuance/06-obtain-credential.js +1 -2
  5. package/lib/commonjs/credential/issuance/06-obtain-credential.js.map +1 -1
  6. package/lib/commonjs/credential/issuance/errors.js +1 -18
  7. package/lib/commonjs/credential/issuance/errors.js.map +1 -1
  8. package/lib/commonjs/credential/status/02-status-attestation.js +2 -4
  9. package/lib/commonjs/credential/status/02-status-attestation.js.map +1 -1
  10. package/lib/commonjs/index.js +1 -3
  11. package/lib/commonjs/index.js.map +1 -1
  12. package/lib/commonjs/wallet-instance-attestation/issuing.js +1 -2
  13. package/lib/commonjs/wallet-instance-attestation/issuing.js.map +1 -1
  14. package/lib/module/credential/issuance/05-authorize-access.js +1 -0
  15. package/lib/module/credential/issuance/05-authorize-access.js.map +1 -1
  16. package/lib/module/credential/issuance/06-obtain-credential.js +1 -2
  17. package/lib/module/credential/issuance/06-obtain-credential.js.map +1 -1
  18. package/lib/module/credential/issuance/errors.js +0 -16
  19. package/lib/module/credential/issuance/errors.js.map +1 -1
  20. package/lib/module/credential/status/02-status-attestation.js +2 -4
  21. package/lib/module/credential/status/02-status-attestation.js.map +1 -1
  22. package/lib/module/index.js +1 -2
  23. package/lib/module/index.js.map +1 -1
  24. package/lib/module/wallet-instance-attestation/issuing.js +1 -2
  25. package/lib/module/wallet-instance-attestation/issuing.js.map +1 -1
  26. package/lib/typescript/credential/issuance/05-authorize-access.d.ts +1 -0
  27. package/lib/typescript/credential/issuance/05-authorize-access.d.ts.map +1 -1
  28. package/lib/typescript/credential/issuance/errors.d.ts +0 -9
  29. package/lib/typescript/credential/issuance/errors.d.ts.map +1 -1
  30. package/lib/typescript/credential/status/02-status-attestation.d.ts +1 -2
  31. package/lib/typescript/credential/status/02-status-attestation.d.ts.map +1 -1
  32. package/lib/typescript/index.d.ts +1 -2
  33. package/lib/typescript/index.d.ts.map +1 -1
  34. package/lib/typescript/wallet-instance-attestation/issuing.d.ts +2 -2
  35. package/lib/typescript/wallet-instance-attestation/issuing.d.ts.map +1 -1
  36. package/package.json +2 -6
  37. package/src/credential/issuance/05-authorize-access.ts +1 -0
  38. package/src/credential/issuance/06-obtain-credential.ts +1 -2
  39. package/src/credential/issuance/errors.ts +0 -15
  40. package/src/credential/status/02-status-attestation.ts +2 -4
  41. package/src/index.ts +0 -2
  42. package/src/wallet-instance-attestation/issuing.ts +1 -2
  43. package/lib/commonjs/cie/README.md +0 -6
  44. package/lib/commonjs/cie/component.js +0 -182
  45. package/lib/commonjs/cie/component.js.map +0 -1
  46. package/lib/commonjs/cie/error.js +0 -44
  47. package/lib/commonjs/cie/error.js.map +0 -1
  48. package/lib/commonjs/cie/index.js +0 -32
  49. package/lib/commonjs/cie/index.js.map +0 -1
  50. package/lib/commonjs/cie/manager.js +0 -142
  51. package/lib/commonjs/cie/manager.js.map +0 -1
  52. package/lib/module/cie/README.md +0 -6
  53. package/lib/module/cie/component.js +0 -172
  54. package/lib/module/cie/component.js.map +0 -1
  55. package/lib/module/cie/error.js +0 -36
  56. package/lib/module/cie/error.js.map +0 -1
  57. package/lib/module/cie/index.js +0 -4
  58. package/lib/module/cie/index.js.map +0 -1
  59. package/lib/module/cie/manager.js +0 -133
  60. package/lib/module/cie/manager.js.map +0 -1
  61. package/lib/typescript/cie/component.d.ts +0 -46
  62. package/lib/typescript/cie/component.d.ts.map +0 -1
  63. package/lib/typescript/cie/error.d.ts +0 -31
  64. package/lib/typescript/cie/error.d.ts.map +0 -1
  65. package/lib/typescript/cie/index.d.ts +0 -4
  66. package/lib/typescript/cie/index.d.ts.map +0 -1
  67. package/lib/typescript/cie/manager.d.ts +0 -5
  68. package/lib/typescript/cie/manager.d.ts.map +0 -1
  69. package/src/cie/README.md +0 -6
  70. package/src/cie/component.tsx +0 -218
  71. package/src/cie/error.ts +0 -58
  72. package/src/cie/index.ts +0 -4
  73. package/src/cie/manager.ts +0 -183
@@ -1,218 +0,0 @@
1
- import React, { createRef } from "react";
2
- import { Platform } from "react-native";
3
- import { WebView } from "react-native-webview";
4
-
5
- import type {
6
- WebViewErrorEvent,
7
- WebViewNavigationEvent,
8
- WebViewMessageEvent,
9
- WebViewNavigation,
10
- WebViewHttpErrorEvent,
11
- } from "react-native-webview/lib/WebViewTypes";
12
- import { startCieAndroid, startCieiOS, type ContinueWithUrl } from "./manager";
13
- import { CieError, CieErrorType } from "./error";
14
-
15
- const AUTH_LINK_PATTERN = "lettura carta";
16
-
17
- /* To obtain the authentication URL on CIE L3 it is necessary to take the
18
- * link contained in the "Entra con lettura carta CIE" button.
19
- * This link can then be used on CieManager.
20
- * This javascript code takes the link in question and sends it to the react native function via postMessage
21
- */
22
- const injectedJavaScript = `
23
- (function() {
24
- function sendDocumentContent() {
25
- const idpAuthUrl = [...document.querySelectorAll("a")]
26
- .filter(a => a.textContent.toLowerCase().includes("${AUTH_LINK_PATTERN}"))
27
- .map(a=>a.href)[0];
28
-
29
- if(idpAuthUrl) {
30
- window.ReactNativeWebView.postMessage(idpAuthUrl);
31
- }
32
- }
33
- if (document.readyState === 'complete') {
34
- sendDocumentContent();
35
- } else {
36
- window.addEventListener('load', sendDocumentContent);
37
- }
38
- })();
39
- true;
40
- `;
41
- export type OnSuccess = (url: string) => void;
42
- export type OnError = (e: CieError) => void;
43
- export type OnCieEvent = (e: CieEvent) => void;
44
- export enum CieEvent {
45
- "reading" = "reading",
46
- "completed" = "completed",
47
- "waiting_card" = "waiting_card",
48
- }
49
-
50
- type CIEParams = {
51
- authUrl: string;
52
- onSuccess: OnSuccess;
53
- onError: OnError;
54
- pin: string;
55
- useUat: boolean;
56
- redirectUrl: string;
57
- onEvent: OnCieEvent;
58
- };
59
-
60
- /*
61
- * To make sure the server recognizes the client as valid iPhone device (iOS only) we use a custom header
62
- * on Android it is not required.
63
- */
64
- const iOSUserAgent =
65
- "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1";
66
- const defaultUserAgent = Platform.select({
67
- ios: iOSUserAgent,
68
- default: undefined,
69
- });
70
-
71
- const webView = createRef<WebView>();
72
-
73
- /**
74
- * WebViewComponent
75
- *
76
- * Component that manages authentication via CIE L3 (NFC+PIN) based on WebView (react-native-webview).
77
- * In particular, once rendered, it makes a series of calls to the authUrl in the WebView,
78
- * extrapolates the authentication URL necessary for CieManager to sign via certificate
79
- * and calls the CIE SDK which is responsible for starting card reading via NFC.
80
- * At the end of the reading, a redirect is made in the WebView towards the page that asks
81
- * the user for consent to send the data to the Service Provider. This moment can be captured
82
- * via the onUserInteraction parameter. When the user allows or denies their consent,
83
- * a redirect is made to the URL set by the Service Provider.
84
- * This url can be configured using the redirectUrl parameter which allows you to close the WebView.
85
- * The event can then be captured via the onSuccess parameter.
86
- *
87
- * @param {CIEParams} params - Parameters required by the component.
88
- * @param {string} params.authUrl -The authentication URL of the Service Provider to which to authenticate.
89
- * @param {boolean} params.useUat - If set to true it uses the CIE testing environment.
90
- * @param {string} params.pin - CIE pin for use with NFC reading.
91
- * @param {Function} params.onError - Callback function in case of error. The function is passed the Error parameter.
92
- * @param {Function} params.onSuccess - Callback at the end of authentication to which the redirect URL including parameters is passed.
93
- * @param {string} params.redirectUrl - Redirect URL set by the Service Provider. It is used to stop the flow and return to the calling function via onSuccess.
94
- * @param {Function} params.onEvent - Callback function that is called whenever there is a new CieEvent from the CIE reader.
95
- * @returns {JSX.Element} - The configured component with WebView.
96
- */
97
- export const WebViewComponent = (params: CIEParams) => {
98
- const [webViewUrl, setWebViewUrl] = React.useState(params.authUrl);
99
- const [isCardReadingFinished, setCardReadingFinished] = React.useState(false);
100
-
101
- /*
102
- * Once the reading of the card with NFC is finished, it is necessary
103
- * to change the URL of the WebView by redirecting to the URL returned by
104
- * CieManager to allow the user to continue with the consent authorization
105
- * */
106
- const continueWithUrl: ContinueWithUrl = (callbackUrl: string) => {
107
- setCardReadingFinished(true);
108
- setWebViewUrl(callbackUrl);
109
- };
110
-
111
- // This function is called from the injected javascript code (postMessage). Which receives the authentication URL
112
- const handleMessage = async (event: WebViewMessageEvent) => {
113
- const cieAuthorizationUri = event.nativeEvent.data;
114
- const startCie = Platform.select({
115
- ios: startCieiOS,
116
- default: startCieAndroid,
117
- });
118
- await startCie(
119
- params.useUat,
120
- params.pin,
121
- params.onError,
122
- params.onEvent,
123
- cieAuthorizationUri,
124
- continueWithUrl
125
- );
126
- };
127
-
128
- //This function is called when authentication with CIE ends and the SP URL containing code and state is returned
129
- const handleShouldStartLoading =
130
- (onSuccess: OnSuccess, redirectUrl: string) =>
131
- (event: WebViewNavigation): boolean => {
132
- if (isCardReadingFinished && event.url.includes(redirectUrl)) {
133
- onSuccess(event.url);
134
- return false;
135
- } else {
136
- return true;
137
- }
138
- };
139
-
140
- const handleOnLoadEnd =
141
- (onError: OnError, onCieEvent: OnCieEvent) =>
142
- (e: WebViewNavigationEvent | WebViewErrorEvent) => {
143
- const eventTitle = e.nativeEvent.title.toLowerCase();
144
- if (
145
- eventTitle === "pagina web non disponibile" ||
146
- // On Android, if we attempt to access the idp URL twice,
147
- // we are presented with an error page titled "ERROR".
148
- eventTitle === "errore"
149
- ) {
150
- handleOnError(onError)(new Error(eventTitle));
151
- }
152
-
153
- /* At the end of loading the page, if the card has already been read
154
- * then the WebView has loaded the page to ask the user for consent,
155
- * so send the completed event
156
- * */
157
- if (isCardReadingFinished) {
158
- onCieEvent(CieEvent.completed);
159
- }
160
- };
161
-
162
- const handleOnError =
163
- (onError: OnError) =>
164
- (e: WebViewErrorEvent | WebViewHttpErrorEvent | Error): void => {
165
- const error = e as Error;
166
- const webViewError = e as WebViewErrorEvent;
167
- const webViewHttpError = e as WebViewHttpErrorEvent;
168
- if (webViewHttpError.nativeEvent.statusCode) {
169
- const { description, statusCode } = webViewHttpError.nativeEvent;
170
- onError(
171
- new CieError({
172
- message: `WebView http error: ${description} with status code: ${statusCode}`,
173
- type: CieErrorType.WEB_VIEW_ERROR,
174
- })
175
- );
176
- } else if (webViewError.nativeEvent) {
177
- const { code, description } = webViewError.nativeEvent;
178
- onError(
179
- new CieError({
180
- message: `WebView error: ${description} with code: ${code}`,
181
- type: CieErrorType.WEB_VIEW_ERROR,
182
- })
183
- );
184
- } else if (error.message !== undefined) {
185
- onError(
186
- new CieError({
187
- message: `${error.message}`,
188
- type: CieErrorType.WEB_VIEW_ERROR,
189
- })
190
- );
191
- } else {
192
- onError(
193
- new CieError({
194
- message: "An error occurred in the WebView",
195
- type: CieErrorType.WEB_VIEW_ERROR,
196
- })
197
- );
198
- }
199
- };
200
-
201
- return (
202
- <WebView
203
- ref={webView}
204
- userAgent={defaultUserAgent}
205
- javaScriptEnabled={true}
206
- source={{ uri: webViewUrl }}
207
- onLoadEnd={handleOnLoadEnd(params.onError, params.onEvent)}
208
- onError={handleOnError(params.onError)}
209
- onHttpError={handleOnError(params.onError)}
210
- injectedJavaScript={injectedJavaScript}
211
- onShouldStartLoadWithRequest={handleShouldStartLoading(
212
- params.onSuccess,
213
- params.redirectUrl
214
- )}
215
- onMessage={handleMessage}
216
- />
217
- );
218
- };
package/src/cie/error.ts DELETED
@@ -1,58 +0,0 @@
1
- export enum CieErrorType {
2
- GENERIC,
3
- TAG_NOT_VALID,
4
- WEB_VIEW_ERROR,
5
- NFC_ERROR,
6
- AUTHENTICATION_ERROR,
7
- PIN_ERROR,
8
- PIN_LOCKED,
9
- CERTIFICATE_ERROR,
10
- }
11
-
12
- interface BaseCieError {
13
- message: string;
14
- type?: CieErrorType;
15
- }
16
-
17
- interface PinErrorOptions extends BaseCieError {
18
- type: CieErrorType.PIN_ERROR;
19
- attemptsLeft: number;
20
- }
21
-
22
- interface NonPinErrorOptions extends BaseCieError {
23
- type?: Exclude<CieErrorType, CieErrorType.PIN_ERROR>;
24
- attemptsLeft?: number;
25
- }
26
-
27
- type ErrorOptions = PinErrorOptions | NonPinErrorOptions;
28
-
29
- export class CieError extends Error {
30
- public type: CieErrorType;
31
- public attemptsLeft?: number;
32
- constructor(options: ErrorOptions) {
33
- super(options.message);
34
-
35
- if (options.type) {
36
- this.type = options.type;
37
- } else {
38
- this.type = CieErrorType.GENERIC;
39
- }
40
-
41
- if (this.type === CieErrorType.PIN_ERROR) {
42
- this.attemptsLeft = options.attemptsLeft;
43
- } else if (this.type === CieErrorType.PIN_LOCKED) {
44
- this.attemptsLeft = 0;
45
- }
46
-
47
- this.name = this.constructor.name;
48
- }
49
-
50
- toString(): string {
51
- return JSON.stringify({
52
- name: this.name,
53
- type: CieErrorType[this.type],
54
- message: this.message,
55
- attemptsLeft: this.attemptsLeft,
56
- });
57
- }
58
- }
package/src/cie/index.ts DELETED
@@ -1,4 +0,0 @@
1
- import { CieEvent, WebViewComponent } from "./component";
2
- import { CieError, CieErrorType } from "./error";
3
-
4
- export { WebViewComponent, CieError, CieErrorType, CieEvent };
@@ -1,183 +0,0 @@
1
- import cieManager, { type Event as CEvent } from "@pagopa/react-native-cie";
2
- import { Platform } from "react-native";
3
- import { CieEvent, type OnCieEvent, type OnError } from "./component";
4
- import { CieError, CieErrorType } from "./error";
5
-
6
- const BASE_UAT_URL = "https://collaudo.idserver.servizicie.interno.gov.it/idp/";
7
-
8
- export type ContinueWithUrl = (callbackUrl: string) => void;
9
-
10
- export const startCieAndroid = (
11
- useCieUat: boolean,
12
- ciePin: string,
13
- onError: OnError,
14
- onEvent: OnCieEvent,
15
- cieAuthorizationUri: string,
16
- continueWithUrl: ContinueWithUrl
17
- ) => {
18
- try {
19
- cieManager.removeAllListeners();
20
- cieManager
21
- .start()
22
- .then(async () => {
23
- cieManager.onEvent(handleCieEvent(onError, onEvent));
24
- cieManager.onError((e: Error) => {
25
- console.error(e);
26
- return onError(new CieError({ message: e.message }));
27
- });
28
- cieManager.onSuccess(handleCieSuccess(continueWithUrl));
29
- await cieManager.setPin(ciePin);
30
- cieManager.setAuthenticationUrl(cieAuthorizationUri);
31
- cieManager.enableLog(useCieUat);
32
- cieManager.setCustomIdpUrl(useCieUat ? getCieUatEndpoint() : null);
33
- await cieManager.startListeningNFC();
34
- onEvent(CieEvent.waiting_card);
35
- })
36
- .catch(onError);
37
- } catch (e) {
38
- onError(
39
- new CieError({
40
- message: `Unable to start CIE NFC manager on Android: ${e}`,
41
- type: CieErrorType.NFC_ERROR,
42
- })
43
- );
44
- }
45
- };
46
-
47
- export const startCieiOS = async (
48
- useCieUat: boolean,
49
- ciePin: string,
50
- onError: OnError,
51
- onEvent: OnCieEvent,
52
- cieAuthorizationUri: string,
53
- continueWithUrl: ContinueWithUrl
54
- ) => {
55
- try {
56
- cieManager.removeAllListeners();
57
- cieManager.onEvent(handleCieEvent(onError, onEvent));
58
- cieManager.onError((e: Error) =>
59
- onError(new CieError({ message: e.message }))
60
- );
61
- cieManager.onSuccess(handleCieSuccess(continueWithUrl));
62
- cieManager.enableLog(useCieUat);
63
- cieManager.setCustomIdpUrl(useCieUat ? getCieUatEndpoint() : null);
64
- await cieManager.setPin(ciePin);
65
- cieManager.setAuthenticationUrl(cieAuthorizationUri);
66
- cieManager
67
- .start()
68
- .then(async () => {
69
- await cieManager.startListeningNFC();
70
- onEvent(CieEvent.waiting_card);
71
- })
72
- .catch(onError);
73
- } catch (e) {
74
- onError(
75
- new CieError({
76
- message: `Unable to start CIE NFC manager on iOS: ${e}`,
77
- type: CieErrorType.NFC_ERROR,
78
- })
79
- );
80
- }
81
- };
82
-
83
- const handleCieEvent =
84
- (onError: OnError, onEvent: OnCieEvent) => (event: CEvent) => {
85
- switch (event.event) {
86
- // Reading starts
87
- case "ON_TAG_DISCOVERED":
88
- onEvent(CieEvent.reading);
89
- break;
90
- // "Function not supported" seems to be TAG_ERROR_NFC_NOT_SUPPORTED
91
- // for the iOS SDK
92
- case "Function not supported" as unknown:
93
- case "TAG_ERROR_NFC_NOT_SUPPORTED":
94
- case "ON_TAG_DISCOVERED_NOT_CIE":
95
- onError(
96
- new CieError({
97
- message: `Invalid CIE card: ${event.event}`,
98
- type: CieErrorType.TAG_NOT_VALID,
99
- })
100
- );
101
- break;
102
- case "AUTHENTICATION_ERROR":
103
- case "ON_NO_INTERNET_CONNECTION":
104
- onError(
105
- new CieError({
106
- message: `Authentication error or no internet connection`,
107
- type: CieErrorType.AUTHENTICATION_ERROR,
108
- })
109
- );
110
- break;
111
- case "EXTENDED_APDU_NOT_SUPPORTED":
112
- onError(
113
- new CieError({
114
- message: `APDU not supported`,
115
- type: CieErrorType.NFC_ERROR,
116
- })
117
- );
118
- break;
119
- case "Transmission Error":
120
- case "ON_TAG_LOST":
121
- onError(
122
- new CieError({
123
- message: `Trasmission error`,
124
- type: CieErrorType.NFC_ERROR,
125
- })
126
- );
127
- break;
128
-
129
- // The card is temporarily locked. Unlock is available by CieID app
130
- case "PIN Locked":
131
- case "ON_CARD_PIN_LOCKED":
132
- onError(
133
- new CieError({
134
- message: `PIN locked`,
135
- type: CieErrorType.PIN_LOCKED,
136
- })
137
- );
138
- break;
139
- case "ON_PIN_ERROR":
140
- onError(
141
- new CieError({
142
- message: `PIN locked`,
143
- type: CieErrorType.PIN_ERROR,
144
- attemptsLeft: event.attemptsLeft,
145
- })
146
- );
147
- break;
148
-
149
- // CIE is Expired or Revoked
150
- case "CERTIFICATE_EXPIRED":
151
- onError(
152
- new CieError({
153
- message: `Certificate expired`,
154
- type: CieErrorType.CERTIFICATE_ERROR,
155
- })
156
- );
157
- break;
158
- case "CERTIFICATE_REVOKED":
159
- onError(
160
- new CieError({
161
- message: `Certificate revoked`,
162
- type: CieErrorType.CERTIFICATE_ERROR,
163
- })
164
- );
165
-
166
- break;
167
-
168
- default:
169
- break;
170
- }
171
- };
172
-
173
- const handleCieSuccess =
174
- (continueWithUrl: ContinueWithUrl) => (url: string) => {
175
- continueWithUrl(decodeURIComponent(url));
176
- };
177
-
178
- const getCieUatEndpoint = () =>
179
- Platform.select({
180
- ios: `${BASE_UAT_URL}Authn/SSL/Login2`,
181
- android: BASE_UAT_URL,
182
- default: null,
183
- });