@pagopa/io-react-native-wallet 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. package/lib/commonjs/cie/component.js +180 -0
  2. package/lib/commonjs/cie/component.js.map +1 -0
  3. package/lib/commonjs/cie/error.js +44 -0
  4. package/lib/commonjs/cie/error.js.map +1 -0
  5. package/lib/commonjs/cie/index.js +32 -0
  6. package/lib/commonjs/cie/index.js.map +1 -0
  7. package/lib/commonjs/cie/manager.js +142 -0
  8. package/lib/commonjs/cie/manager.js.map +1 -0
  9. package/lib/commonjs/client/index.js +5 -2
  10. package/lib/commonjs/client/index.js.map +1 -1
  11. package/lib/commonjs/credential/issuance/03-start-user-authorization.js +2 -2
  12. package/lib/commonjs/credential/issuance/03-start-user-authorization.js.map +1 -1
  13. package/lib/commonjs/credential/issuance/04-complete-user-authorization.js +7 -3
  14. package/lib/commonjs/credential/issuance/04-complete-user-authorization.js.map +1 -1
  15. package/lib/commonjs/credential/issuance/05-authorize-access.js +5 -5
  16. package/lib/commonjs/credential/issuance/05-authorize-access.js.map +1 -1
  17. package/lib/commonjs/credential/issuance/06-obtain-credential.js +2 -2
  18. package/lib/commonjs/credential/issuance/index.js +6 -0
  19. package/lib/commonjs/credential/issuance/index.js.map +1 -1
  20. package/lib/commonjs/index.js +3 -1
  21. package/lib/commonjs/index.js.map +1 -1
  22. package/lib/module/cie/component.js +171 -0
  23. package/lib/module/cie/component.js.map +1 -0
  24. package/lib/module/cie/error.js +36 -0
  25. package/lib/module/cie/error.js.map +1 -0
  26. package/lib/module/cie/index.js +4 -0
  27. package/lib/module/cie/index.js.map +1 -0
  28. package/lib/module/cie/manager.js +133 -0
  29. package/lib/module/cie/manager.js.map +1 -0
  30. package/lib/module/client/index.js +5 -2
  31. package/lib/module/client/index.js.map +1 -1
  32. package/lib/module/credential/issuance/03-start-user-authorization.js +2 -2
  33. package/lib/module/credential/issuance/03-start-user-authorization.js.map +1 -1
  34. package/lib/module/credential/issuance/04-complete-user-authorization.js +4 -1
  35. package/lib/module/credential/issuance/04-complete-user-authorization.js.map +1 -1
  36. package/lib/module/credential/issuance/05-authorize-access.js +5 -5
  37. package/lib/module/credential/issuance/05-authorize-access.js.map +1 -1
  38. package/lib/module/credential/issuance/06-obtain-credential.js +2 -2
  39. package/lib/module/credential/issuance/06-obtain-credential.js.map +1 -1
  40. package/lib/module/credential/issuance/index.js +2 -2
  41. package/lib/module/credential/issuance/index.js.map +1 -1
  42. package/lib/module/index.js +2 -1
  43. package/lib/module/index.js.map +1 -1
  44. package/lib/typescript/cie/component.d.ts +46 -0
  45. package/lib/typescript/cie/component.d.ts.map +1 -0
  46. package/lib/typescript/cie/error.d.ts +31 -0
  47. package/lib/typescript/cie/error.d.ts.map +1 -0
  48. package/lib/typescript/cie/index.d.ts +4 -0
  49. package/lib/typescript/cie/index.d.ts.map +1 -0
  50. package/lib/typescript/cie/manager.d.ts +5 -0
  51. package/lib/typescript/cie/manager.d.ts.map +1 -0
  52. package/lib/typescript/client/index.d.ts.map +1 -1
  53. package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts +2 -2
  54. package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts.map +1 -1
  55. package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts +6 -1
  56. package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts.map +1 -1
  57. package/lib/typescript/credential/issuance/05-authorize-access.d.ts +1 -1
  58. package/lib/typescript/credential/issuance/05-authorize-access.d.ts.map +1 -1
  59. package/lib/typescript/credential/issuance/06-obtain-credential.d.ts +1 -1
  60. package/lib/typescript/credential/issuance/06-obtain-credential.d.ts.map +1 -1
  61. package/lib/typescript/credential/issuance/index.d.ts +2 -2
  62. package/lib/typescript/credential/issuance/index.d.ts.map +1 -1
  63. package/lib/typescript/index.d.ts +2 -1
  64. package/lib/typescript/index.d.ts.map +1 -1
  65. package/package.json +6 -2
  66. package/src/cie/component.tsx +216 -0
  67. package/src/cie/error.ts +58 -0
  68. package/src/cie/index.ts +4 -0
  69. package/src/cie/manager.ts +183 -0
  70. package/src/client/index.ts +4 -1
  71. package/src/credential/issuance/03-start-user-authorization.ts +2 -6
  72. package/src/credential/issuance/04-complete-user-authorization.ts +17 -14
  73. package/src/credential/issuance/05-authorize-access.ts +5 -5
  74. package/src/credential/issuance/06-obtain-credential.ts +2 -2
  75. package/src/credential/issuance/index.ts +2 -0
  76. package/src/index.ts +2 -0
  77. package/lib/commonjs/credential/issuance/03-start-credential-issuance.js +0 -287
  78. package/lib/commonjs/credential/issuance/03-start-credential-issuance.js.map +0 -1
  79. package/lib/module/credential/issuance/03-start-credential-issuance.js +0 -276
  80. package/lib/module/credential/issuance/03-start-credential-issuance.js.map +0 -1
  81. package/lib/typescript/credential/issuance/03-start-credential-issuance.d.ts +0 -41
  82. package/lib/typescript/credential/issuance/03-start-credential-issuance.d.ts.map +0 -1
  83. package/src/credential/issuance/03-start-credential-issuance.ts +0 -407
@@ -0,0 +1,46 @@
1
+ import React from "react";
2
+ import { CieError } from "./error";
3
+ export type OnSuccess = (url: string) => void;
4
+ export type OnError = (e: CieError) => void;
5
+ export type OnCieEvent = (e: CieEvent) => void;
6
+ export declare enum CieEvent {
7
+ "reading" = "reading",
8
+ "completed" = "completed",
9
+ "waiting_card" = "waiting_card"
10
+ }
11
+ type CIEParams = {
12
+ authUrl: string;
13
+ onSuccess: OnSuccess;
14
+ onError: OnError;
15
+ pin: string;
16
+ useUat: boolean;
17
+ redirectUrl: string;
18
+ onEvent: OnCieEvent;
19
+ };
20
+ /**
21
+ * WebViewComponent
22
+ *
23
+ * Component that manages authentication via CIE L3 (NFC+PIN) based on WebView (react-native-webview).
24
+ * In particular, once rendered, it makes a series of calls to the authUrl in the WebView,
25
+ * extrapolates the authentication URL necessary for CieManager to sign via certificate
26
+ * and calls the CIE SDK which is responsible for starting card reading via NFC.
27
+ * At the end of the reading, a redirect is made in the WebView towards the page that asks
28
+ * the user for consent to send the data to the Service Provider. This moment can be captured
29
+ * via the onUserInteraction parameter. When the user allows or denies their consent,
30
+ * a redirect is made to the URL set by the Service Provider.
31
+ * This url can be configured using the redirectUrl parameter which allows you to close the WebView.
32
+ * The event can then be captured via the onSuccess parameter.
33
+ *
34
+ * @param {CIEParams} params - Parameters required by the component.
35
+ * @param {string} params.authUrl -The authentication URL of the Service Provider to which to authenticate.
36
+ * @param {boolean} params.useUat - If set to true it uses the CIE testing environment.
37
+ * @param {string} params.pin - CIE pin for use with NFC reading.
38
+ * @param {Function} params.onError - Callback function in case of error. The function is passed the Error parameter.
39
+ * @param {Function} params.onSuccess - Callback at the end of authentication to which the redirect URL including parameters is passed.
40
+ * @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.
41
+ * @param {Function} params.onEvent - Callback function that is called whenever there is a new CieEvent from the CIE reader.
42
+ * @returns {JSX.Element} - The configured component with WebView.
43
+ */
44
+ export declare const WebViewComponent: (params: CIEParams) => React.JSX.Element;
45
+ export {};
46
+ //# sourceMappingURL=component.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../src/cie/component.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAYzC,OAAO,EAAE,QAAQ,EAAgB,MAAM,SAAS,CAAC;AA0BjD,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;AAC9C,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,EAAE,QAAQ,KAAK,IAAI,CAAC;AAC5C,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,EAAE,QAAQ,KAAK,IAAI,CAAC;AAC/C,oBAAY,QAAQ;IAClB,SAAS,YAAY;IACrB,WAAW,cAAc;IACzB,cAAc,iBAAiB;CAChC;AAED,KAAK,SAAS,GAAG;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,SAAS,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,UAAU,CAAC;CACrB,CAAC;AAeF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,gBAAgB,WAAY,SAAS,sBAyHjD,CAAC"}
@@ -0,0 +1,31 @@
1
+ export declare enum CieErrorType {
2
+ GENERIC = 0,
3
+ TAG_NOT_VALID = 1,
4
+ WEB_VIEW_ERROR = 2,
5
+ NFC_ERROR = 3,
6
+ AUTHENTICATION_ERROR = 4,
7
+ PIN_ERROR = 5,
8
+ PIN_LOCKED = 6,
9
+ CERTIFICATE_ERROR = 7
10
+ }
11
+ interface BaseCieError {
12
+ message: string;
13
+ type?: CieErrorType;
14
+ }
15
+ interface PinErrorOptions extends BaseCieError {
16
+ type: CieErrorType.PIN_ERROR;
17
+ attemptsLeft: number;
18
+ }
19
+ interface NonPinErrorOptions extends BaseCieError {
20
+ type?: Exclude<CieErrorType, CieErrorType.PIN_ERROR>;
21
+ attemptsLeft?: number;
22
+ }
23
+ type ErrorOptions = PinErrorOptions | NonPinErrorOptions;
24
+ export declare class CieError extends Error {
25
+ type: CieErrorType;
26
+ attemptsLeft?: number;
27
+ constructor(options: ErrorOptions);
28
+ toString(): string;
29
+ }
30
+ export {};
31
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../src/cie/error.ts"],"names":[],"mappings":"AAAA,oBAAY,YAAY;IACtB,OAAO,IAAA;IACP,aAAa,IAAA;IACb,cAAc,IAAA;IACd,SAAS,IAAA;IACT,oBAAoB,IAAA;IACpB,SAAS,IAAA;IACT,UAAU,IAAA;IACV,iBAAiB,IAAA;CAClB;AAED,UAAU,YAAY;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,YAAY,CAAC;CACrB;AAED,UAAU,eAAgB,SAAQ,YAAY;IAC5C,IAAI,EAAE,YAAY,CAAC,SAAS,CAAC;IAC7B,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,UAAU,kBAAmB,SAAQ,YAAY;IAC/C,IAAI,CAAC,EAAE,OAAO,CAAC,YAAY,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACrD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,KAAK,YAAY,GAAG,eAAe,GAAG,kBAAkB,CAAC;AAEzD,qBAAa,QAAS,SAAQ,KAAK;IAC1B,IAAI,EAAE,YAAY,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;gBACjB,OAAO,EAAE,YAAY;IAkBjC,QAAQ,IAAI,MAAM;CAQnB"}
@@ -0,0 +1,4 @@
1
+ import { CieEvent, WebViewComponent } from "./component";
2
+ import { CieError, CieErrorType } from "./error";
3
+ export { WebViewComponent, CieError, CieErrorType, CieEvent };
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cie/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEjD,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { type OnCieEvent, type OnError } from "./component";
2
+ export type ContinueWithUrl = (callbackUrl: string) => void;
3
+ export declare const startCieAndroid: (useCieUat: boolean, ciePin: string, onError: OnError, onEvent: OnCieEvent, cieAuthorizationUri: string, continueWithUrl: ContinueWithUrl) => void;
4
+ export declare const startCieiOS: (useCieUat: boolean, ciePin: string, onError: OnError, onEvent: OnCieEvent, cieAuthorizationUri: string, continueWithUrl: ContinueWithUrl) => Promise<void>;
5
+ //# sourceMappingURL=manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/cie/manager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,KAAK,UAAU,EAAE,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AAKtE,MAAM,MAAM,eAAe,GAAG,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;AAE5D,eAAO,MAAM,eAAe,cACf,OAAO,UACV,MAAM,WACL,OAAO,WACP,UAAU,uBACE,MAAM,mBACV,eAAe,SA6BjC,CAAC;AAEF,eAAO,MAAM,WAAW,cACX,OAAO,UACV,MAAM,WACL,OAAO,WACP,UAAU,uBACE,MAAM,mBACV,eAAe,kBA4BjC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,IAAI,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEnF,MAAM,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;AAuB3D,eAAO,MAAM,uBAAuB,YAAa;IAC/C,qBAAqB,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;CACjC,4BAmBA,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,IAAI,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEnF,MAAM,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;AAuB3D,eAAO,MAAM,uBAAuB,YAAa;IAC/C,qBAAqB,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;CACjC,4BAsBA,CAAC"}
@@ -1,8 +1,8 @@
1
1
  import type { CryptoContext } from "@pagopa/io-react-native-jwt";
2
- import { type Out } from "../../../src/utils/misc";
2
+ import { type Out } from "../../utils/misc";
3
3
  import type { EvaluateIssuerTrust } from "./02-evaluate-issuer-trust";
4
4
  import type { StartFlow } from "./01-start-flow";
5
- import { AuthorizationDetail } from "../../../src/utils/par";
5
+ import { AuthorizationDetail } from "../../utils/par";
6
6
  export type StartUserAuthorization = (issuerConf: Out<EvaluateIssuerTrust>["issuerConf"], credentialType: Out<StartFlow>["credentialType"], context: {
7
7
  wiaCryptoContext: CryptoContext;
8
8
  walletInstanceAttestation: string;
@@ -1 +1 @@
1
- {"version":3,"file":"03-start-user-authorization.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/03-start-user-authorization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAEjE,OAAO,EAEL,KAAK,GAAG,EACT,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAkB,MAAM,wBAAwB,CAAC;AAG7E,MAAM,MAAM,sBAAsB,GAAG,CACnC,UAAU,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAC,YAAY,CAAC,EAClD,cAAc,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC,gBAAgB,CAAC,EAChD,OAAO,EAAE;IACP,gBAAgB,EAAE,aAAa,CAAC;IAChC,yBAAyB,EAAE,MAAM,CAAC;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;CACjC,KACE,OAAO,CAAC;IACX,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,mBAAmB,CAAC;CAC3C,CAAC,CAAC;AAyDH;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,sBAAsB,EAAE,sBAmCpC,CAAC"}
1
+ {"version":3,"file":"03-start-user-authorization.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/03-start-user-authorization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAEjE,OAAO,EAAoC,KAAK,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAkB,MAAM,iBAAiB,CAAC;AAGtE,MAAM,MAAM,sBAAsB,GAAG,CACnC,UAAU,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAC,YAAY,CAAC,EAClD,cAAc,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC,gBAAgB,CAAC,EAChD,OAAO,EAAE;IACP,gBAAgB,EAAE,aAAa,CAAC;IAChC,yBAAyB,EAAE,MAAM,CAAC;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;CACjC,KACE,OAAO,CAAC;IACX,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,mBAAmB,CAAC;CAC3C,CAAC,CAAC;AAyDH;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,sBAAsB,EAAE,sBAmCpC,CAAC"}
@@ -1,4 +1,4 @@
1
- import { type AuthorizationContext, type AuthorizationResult } from "../../../src/utils/auth";
1
+ import { type AuthorizationContext, type AuthorizationResult } from "../../utils/auth";
2
2
  import { type Out } from "../../utils/misc";
3
3
  import type { StartUserAuthorization } from "./03-start-user-authorization";
4
4
  import type { EvaluateIssuerTrust } from "./02-evaluate-issuer-trust";
@@ -24,5 +24,10 @@ export type CompleteUserAuthorizationWithQueryMode = (issuerRequestUri: Out<Star
24
24
  * @returns the authorization response which contains code, state and iss
25
25
  */
26
26
  export declare const completeUserAuthorizationWithQueryMode: CompleteUserAuthorizationWithQueryMode;
27
+ export declare const parseAuthRedirectUrl: (authRedirectUrl: string) => {
28
+ code: string;
29
+ state: string;
30
+ iss?: string | undefined;
31
+ };
27
32
  export declare const completeUserAuthorizationWithFormPostJwtMode: () => never;
28
33
  //# sourceMappingURL=04-complete-user-authorization.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"04-complete-user-authorization.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/04-complete-user-authorization.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAS,KAAK,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAG5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAGtE;;GAEG;AACH,MAAM,MAAM,sCAAsC,GAAG,CACnD,gBAAgB,EAAE,GAAG,CAAC,sBAAsB,CAAC,CAAC,kBAAkB,CAAC,EACjE,QAAQ,EAAE,GAAG,CAAC,sBAAsB,CAAC,CAAC,UAAU,CAAC,EACjD,UAAU,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAC,YAAY,CAAC,EAClD,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,oBAAoB,CAAC,EAAE,oBAAoB,KACxC,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAElC;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,sCAAsC,EAAE,sCAsElD,CAAC;AAGJ,eAAO,MAAM,4CAA4C,aAExD,CAAC"}
1
+ {"version":3,"file":"04-complete-user-authorization.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/04-complete-user-authorization.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAS,KAAK,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAG5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAGtE;;GAEG;AACH,MAAM,MAAM,sCAAsC,GAAG,CACnD,gBAAgB,EAAE,GAAG,CAAC,sBAAsB,CAAC,CAAC,kBAAkB,CAAC,EACjE,QAAQ,EAAE,GAAG,CAAC,sBAAsB,CAAC,CAAC,UAAU,CAAC,EACjD,UAAU,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAC,YAAY,CAAC,EAClD,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,oBAAoB,CAAC,EAAE,oBAAoB,KACxC,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAElC;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,sCAAsC,EAAE,sCAyDlD,CAAC;AAEJ,eAAO,MAAM,oBAAoB,oBAAqB,MAAM;;;;CAc3D,CAAC;AAGF,eAAO,MAAM,4CAA4C,aAExD,CAAC"}
@@ -1,4 +1,4 @@
1
- import { type Out } from "../../../src/utils/misc";
1
+ import { type Out } from "../../utils/misc";
2
2
  import type { EvaluateIssuerTrust } from "./02-evaluate-issuer-trust";
3
3
  import type { StartUserAuthorization } from "./03-start-user-authorization";
4
4
  import type { CryptoContext } from "@pagopa/io-react-native-jwt";
@@ -1 +1 @@
1
- {"version":3,"file":"05-authorize-access.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/05-authorize-access.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,GAAG,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAM5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAEjE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,KAAK,EAAE,sCAAsC,EAAE,MAAM,kCAAkC,CAAC;AAE/F,MAAM,MAAM,eAAe,GAAG,CAC5B,UAAU,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAC,YAAY,CAAC,EAClD,IAAI,EAAE,GAAG,CAAC,sCAAsC,CAAC,CAAC,MAAM,CAAC,EACzD,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,GAAG,CAAC,sBAAsB,CAAC,CAAC,UAAU,CAAC,EACjD,YAAY,EAAE,GAAG,CAAC,sBAAsB,CAAC,CAAC,cAAc,CAAC,EACzD,OAAO,EAAE;IACP,yBAAyB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAChC,gBAAgB,EAAE,aAAa,CAAC;CACjC,KACE,OAAO,CAAC;IAAE,WAAW,EAAE,aAAa,CAAC;IAAC,sBAAsB,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAE7E;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,eAAe,EAAE,eAyE7B,CAAC"}
1
+ {"version":3,"file":"05-authorize-access.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/05-authorize-access.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAM5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAEjE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,KAAK,EAAE,sCAAsC,EAAE,MAAM,kCAAkC,CAAC;AAE/F,MAAM,MAAM,eAAe,GAAG,CAC5B,UAAU,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAC,YAAY,CAAC,EAClD,IAAI,EAAE,GAAG,CAAC,sCAAsC,CAAC,CAAC,MAAM,CAAC,EACzD,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,GAAG,CAAC,sBAAsB,CAAC,CAAC,UAAU,CAAC,EACjD,YAAY,EAAE,GAAG,CAAC,sBAAsB,CAAC,CAAC,cAAc,CAAC,EACzD,OAAO,EAAE;IACP,yBAAyB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAChC,gBAAgB,EAAE,aAAa,CAAC;CACjC,KACE,OAAO,CAAC;IAAE,WAAW,EAAE,aAAa,CAAC;IAAC,sBAAsB,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAE7E;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,eAAe,EAAE,eAyE7B,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { type CryptoContext } from "@pagopa/io-react-native-jwt";
2
2
  import type { AuthorizeAccess } from "./05-authorize-access";
3
3
  import type { EvaluateIssuerTrust } from "./02-evaluate-issuer-trust";
4
- import { type Out } from "../../../src/utils/misc";
4
+ import { type Out } from "../../utils/misc";
5
5
  import type { StartUserAuthorization } from "./03-start-user-authorization";
6
6
  import { CredentialResponse } from "./types";
7
7
  export type ObtainCredential = (issuerConf: Out<EvaluateIssuerTrust>["issuerConf"], accessToken: Out<AuthorizeAccess>["accessToken"], clientId: Out<StartUserAuthorization>["clientId"], credentialDefinition: Out<StartUserAuthorization>["credentialDefinition"], tokenRequestSignedDPop: Out<AuthorizeAccess>["tokenRequestSignedDPop"], context: {
@@ -1 +1 @@
1
- {"version":3,"file":"06-obtain-credential.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/06-obtain-credential.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAa,KAAK,GAAG,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAE5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C,MAAM,MAAM,gBAAgB,GAAG,CAC7B,UAAU,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAC,YAAY,CAAC,EAClD,WAAW,EAAE,GAAG,CAAC,eAAe,CAAC,CAAC,aAAa,CAAC,EAChD,QAAQ,EAAE,GAAG,CAAC,sBAAsB,CAAC,CAAC,UAAU,CAAC,EACjD,oBAAoB,EAAE,GAAG,CAAC,sBAAsB,CAAC,CAAC,sBAAsB,CAAC,EACzE,sBAAsB,EAAE,GAAG,CAAC,eAAe,CAAC,CAAC,wBAAwB,CAAC,EACtE,OAAO,EAAE;IACP,uBAAuB,EAAE,aAAa,CAAC;IACvC,QAAQ,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;CACjC,KACE,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAEjC,eAAO,MAAM,gBAAgB,UACpB,MAAM,UACL,MAAM,YACJ,MAAM,OACX,aAAa,KACjB,QAAQ,MAAM,CAehB,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,EAAE,gBAqE9B,CAAC"}
1
+ {"version":3,"file":"06-obtain-credential.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/06-obtain-credential.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAa,KAAK,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAE5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C,MAAM,MAAM,gBAAgB,GAAG,CAC7B,UAAU,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAC,YAAY,CAAC,EAClD,WAAW,EAAE,GAAG,CAAC,eAAe,CAAC,CAAC,aAAa,CAAC,EAChD,QAAQ,EAAE,GAAG,CAAC,sBAAsB,CAAC,CAAC,UAAU,CAAC,EACjD,oBAAoB,EAAE,GAAG,CAAC,sBAAsB,CAAC,CAAC,sBAAsB,CAAC,EACzE,sBAAsB,EAAE,GAAG,CAAC,eAAe,CAAC,CAAC,wBAAwB,CAAC,EACtE,OAAO,EAAE;IACP,uBAAuB,EAAE,aAAa,CAAC;IACvC,QAAQ,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;CACjC,KACE,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAEjC,eAAO,MAAM,gBAAgB,UACpB,MAAM,UACL,MAAM,YACJ,MAAM,OACX,aAAa,KACjB,QAAQ,MAAM,CAehB,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,EAAE,gBAqE9B,CAAC"}
@@ -1,10 +1,10 @@
1
1
  import { type StartFlow } from "./01-start-flow";
2
2
  import { evaluateIssuerTrust, type EvaluateIssuerTrust } from "./02-evaluate-issuer-trust";
3
3
  import { startUserAuthorization, type StartUserAuthorization } from "./03-start-user-authorization";
4
- import { completeUserAuthorizationWithQueryMode, type CompleteUserAuthorizationWithQueryMode } from "./04-complete-user-authorization";
4
+ import { completeUserAuthorizationWithQueryMode, parseAuthRedirectUrl, type CompleteUserAuthorizationWithQueryMode } from "./04-complete-user-authorization";
5
5
  import { authorizeAccess, type AuthorizeAccess } from "./05-authorize-access";
6
6
  import { obtainCredential, type ObtainCredential } from "./06-obtain-credential";
7
7
  import { verifyAndParseCredential, type VerifyAndParseCredential } from "./07-verify-and-parse-credential";
8
- export { evaluateIssuerTrust, startUserAuthorization, completeUserAuthorizationWithQueryMode, authorizeAccess, obtainCredential, verifyAndParseCredential, };
8
+ export { evaluateIssuerTrust, startUserAuthorization, completeUserAuthorizationWithQueryMode, authorizeAccess, obtainCredential, verifyAndParseCredential, parseAuthRedirectUrl, };
9
9
  export type { StartFlow, EvaluateIssuerTrust, StartUserAuthorization, CompleteUserAuthorizationWithQueryMode, AuthorizeAccess, ObtainCredential, VerifyAndParseCredential, };
10
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,mBAAmB,EACnB,KAAK,mBAAmB,EACzB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,sBAAsB,EACtB,KAAK,sBAAsB,EAC5B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,sCAAsC,EACtC,KAAK,sCAAsC,EAC5C,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC9E,OAAO,EACL,gBAAgB,EAChB,KAAK,gBAAgB,EACtB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,wBAAwB,EACxB,KAAK,wBAAwB,EAC9B,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,sCAAsC,EACtC,eAAe,EACf,gBAAgB,EAChB,wBAAwB,GACzB,CAAC;AACF,YAAY,EACV,SAAS,EACT,mBAAmB,EACnB,sBAAsB,EACtB,sCAAsC,EACtC,eAAe,EACf,gBAAgB,EAChB,wBAAwB,GACzB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,mBAAmB,EACnB,KAAK,mBAAmB,EACzB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,sBAAsB,EACtB,KAAK,sBAAsB,EAC5B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,sCAAsC,EACtC,oBAAoB,EACpB,KAAK,sCAAsC,EAC5C,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC9E,OAAO,EACL,gBAAgB,EAChB,KAAK,gBAAgB,EACtB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,wBAAwB,EACxB,KAAK,wBAAwB,EAC9B,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,sCAAsC,EACtC,eAAe,EACf,gBAAgB,EAChB,wBAAwB,EACxB,oBAAoB,GACrB,CAAC;AACF,YAAY,EACV,SAAS,EACT,mBAAmB,EACnB,sBAAsB,EACtB,sCAAsC,EACtC,eAAe,EACf,gBAAgB,EAChB,wBAAwB,GACzB,CAAC"}
@@ -8,9 +8,10 @@ import * as Errors from "./utils/errors";
8
8
  import * as WalletInstanceAttestation from "./wallet-instance-attestation";
9
9
  import * as Trust from "./trust";
10
10
  import * as WalletInstance from "./wallet-instance";
11
+ import * as Cie from "./cie";
11
12
  import { AuthorizationDetail, AuthorizationDetails } from "./utils/par";
12
13
  import { createCryptoContextFor } from "./utils/crypto";
13
14
  import type { IntegrityContext } from "./utils/integrity";
14
- export { SdJwt, PID, Credential, WalletInstanceAttestation, WalletInstance, Errors, Trust, createCryptoContextFor, AuthorizationDetail, AuthorizationDetails, fixBase64EncodingOnKey, };
15
+ export { SdJwt, PID, Credential, WalletInstanceAttestation, WalletInstance, Errors, Trust, createCryptoContextFor, AuthorizationDetail, AuthorizationDetails, fixBase64EncodingOnKey, Cie, };
15
16
  export type { IntegrityContext, AuthorizationContext };
16
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAGrD,OAAO,gCAAgC,CAAC;AAExC,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,UAAU,CAAC;AAClC,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAC;AACzC,OAAO,KAAK,yBAAyB,MAAM,+BAA+B,CAAC;AAC3E,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,cAAc,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,EACL,KAAK,EACL,GAAG,EACH,UAAU,EACV,yBAAyB,EACzB,cAAc,EACd,MAAM,EACN,KAAK,EACL,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,GACvB,CAAC;AAEF,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAGrD,OAAO,gCAAgC,CAAC;AAExC,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,UAAU,CAAC;AAClC,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAC;AACzC,OAAO,KAAK,yBAAyB,MAAM,+BAA+B,CAAC;AAC3E,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,cAAc,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,EACL,KAAK,EACL,GAAG,EACH,UAAU,EACV,yBAAyB,EACzB,cAAc,EACd,MAAM,EACN,KAAK,EACL,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,GAAG,GACJ,CAAC;AAEF,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagopa/io-react-native-wallet",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "Provide data structures, helpers and API for IO Wallet",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -56,6 +56,7 @@
56
56
  "@pagopa/eslint-config": "^3.0.0",
57
57
  "@pagopa/io-react-native-crypto": "^0.2.3",
58
58
  "@pagopa/io-react-native-jwt": "^1.2.0",
59
+ "@pagopa/react-native-cie": "^1.3.0",
59
60
  "@react-native/eslint-config": "^0.72.2",
60
61
  "@rushstack/eslint-patch": "^1.3.2",
61
62
  "@types/jest": "^28.1.2",
@@ -70,6 +71,7 @@
70
71
  "react": "18.2.0",
71
72
  "react-native": "0.72.14",
72
73
  "react-native-builder-bob": "^0.20.0",
74
+ "react-native-webview": "^13.10.5",
73
75
  "typed-openapi": "^0.4.1",
74
76
  "typescript": "^5.0.2"
75
77
  },
@@ -79,8 +81,10 @@
79
81
  "peerDependencies": {
80
82
  "@pagopa/io-react-native-crypto": "*",
81
83
  "@pagopa/io-react-native-jwt": "*",
84
+ "@pagopa/react-native-cie": "*",
82
85
  "react": "*",
83
- "react-native": "*"
86
+ "react-native": "*",
87
+ "react-native-webview": "*"
84
88
  },
85
89
  "engines": {
86
90
  "node": ">= 16.0.0"
@@ -0,0 +1,216 @@
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
+ /* To obtain the authentication URL on CIE L3 it is necessary to take the
16
+ * link contained in the "Entra con lettura carta CIE" button.
17
+ * This link can then be used on CieManager.
18
+ * This javascript code takes the link in question and sends it to the react native function via postMessage
19
+ */
20
+ const injectedJavaScript = `
21
+ (function() {
22
+ function sendDocumentContent() {
23
+ const idpAuthUrl = [...document.querySelectorAll("a")]
24
+ .filter(a => a.textContent.includes("lettura carta CIE"))
25
+ .map(a=>a.href)[0];
26
+
27
+ if(idpAuthUrl) {
28
+ window.ReactNativeWebView.postMessage(idpAuthUrl);
29
+ }
30
+ }
31
+ if (document.readyState === 'complete') {
32
+ sendDocumentContent();
33
+ } else {
34
+ window.addEventListener('load', sendDocumentContent);
35
+ }
36
+ })();
37
+ true;
38
+ `;
39
+ export type OnSuccess = (url: string) => void;
40
+ export type OnError = (e: CieError) => void;
41
+ export type OnCieEvent = (e: CieEvent) => void;
42
+ export enum CieEvent {
43
+ "reading" = "reading",
44
+ "completed" = "completed",
45
+ "waiting_card" = "waiting_card",
46
+ }
47
+
48
+ type CIEParams = {
49
+ authUrl: string;
50
+ onSuccess: OnSuccess;
51
+ onError: OnError;
52
+ pin: string;
53
+ useUat: boolean;
54
+ redirectUrl: string;
55
+ onEvent: OnCieEvent;
56
+ };
57
+
58
+ /*
59
+ * To make sure the server recognizes the client as valid iPhone device (iOS only) we use a custom header
60
+ * on Android it is not required.
61
+ */
62
+ const iOSUserAgent =
63
+ "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";
64
+ const defaultUserAgent = Platform.select({
65
+ ios: iOSUserAgent,
66
+ default: undefined,
67
+ });
68
+
69
+ const webView = createRef<WebView>();
70
+
71
+ /**
72
+ * WebViewComponent
73
+ *
74
+ * Component that manages authentication via CIE L3 (NFC+PIN) based on WebView (react-native-webview).
75
+ * In particular, once rendered, it makes a series of calls to the authUrl in the WebView,
76
+ * extrapolates the authentication URL necessary for CieManager to sign via certificate
77
+ * and calls the CIE SDK which is responsible for starting card reading via NFC.
78
+ * At the end of the reading, a redirect is made in the WebView towards the page that asks
79
+ * the user for consent to send the data to the Service Provider. This moment can be captured
80
+ * via the onUserInteraction parameter. When the user allows or denies their consent,
81
+ * a redirect is made to the URL set by the Service Provider.
82
+ * This url can be configured using the redirectUrl parameter which allows you to close the WebView.
83
+ * The event can then be captured via the onSuccess parameter.
84
+ *
85
+ * @param {CIEParams} params - Parameters required by the component.
86
+ * @param {string} params.authUrl -The authentication URL of the Service Provider to which to authenticate.
87
+ * @param {boolean} params.useUat - If set to true it uses the CIE testing environment.
88
+ * @param {string} params.pin - CIE pin for use with NFC reading.
89
+ * @param {Function} params.onError - Callback function in case of error. The function is passed the Error parameter.
90
+ * @param {Function} params.onSuccess - Callback at the end of authentication to which the redirect URL including parameters is passed.
91
+ * @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.
92
+ * @param {Function} params.onEvent - Callback function that is called whenever there is a new CieEvent from the CIE reader.
93
+ * @returns {JSX.Element} - The configured component with WebView.
94
+ */
95
+ export const WebViewComponent = (params: CIEParams) => {
96
+ const [webViewUrl, setWebViewUrl] = React.useState(params.authUrl);
97
+ const [isCardReadingFinished, setCardReadingFinished] = React.useState(false);
98
+
99
+ /*
100
+ * Once the reading of the card with NFC is finished, it is necessary
101
+ * to change the URL of the WebView by redirecting to the URL returned by
102
+ * CieManager to allow the user to continue with the consent authorization
103
+ * */
104
+ const continueWithUrl: ContinueWithUrl = (callbackUrl: string) => {
105
+ setCardReadingFinished(true);
106
+ setWebViewUrl(callbackUrl);
107
+ };
108
+
109
+ // This function is called from the injected javascript code (postMessage). Which receives the authentication URL
110
+ const handleMessage = async (event: WebViewMessageEvent) => {
111
+ const cieAuthorizationUri = event.nativeEvent.data;
112
+ const startCie = Platform.select({
113
+ ios: startCieiOS,
114
+ default: startCieAndroid,
115
+ });
116
+ await startCie(
117
+ params.useUat,
118
+ params.pin,
119
+ params.onError,
120
+ params.onEvent,
121
+ cieAuthorizationUri,
122
+ continueWithUrl
123
+ );
124
+ };
125
+
126
+ //This function is called when authentication with CIE ends and the SP URL containing code and state is returned
127
+ const handleShouldStartLoading =
128
+ (onSuccess: OnSuccess, redirectUrl: string) =>
129
+ (event: WebViewNavigation): boolean => {
130
+ if (isCardReadingFinished && event.url.includes(redirectUrl)) {
131
+ onSuccess(event.url);
132
+ return false;
133
+ } else {
134
+ return true;
135
+ }
136
+ };
137
+
138
+ const handleOnLoadEnd =
139
+ (onError: OnError, onCieEvent: OnCieEvent) =>
140
+ (e: WebViewNavigationEvent | WebViewErrorEvent) => {
141
+ const eventTitle = e.nativeEvent.title.toLowerCase();
142
+ if (
143
+ eventTitle === "pagina web non disponibile" ||
144
+ // On Android, if we attempt to access the idp URL twice,
145
+ // we are presented with an error page titled "ERROR".
146
+ eventTitle === "errore"
147
+ ) {
148
+ handleOnError(onError)(new Error(eventTitle));
149
+ }
150
+
151
+ /* At the end of loading the page, if the card has already been read
152
+ * then the WebView has loaded the page to ask the user for consent,
153
+ * so send the completed event
154
+ * */
155
+ if (isCardReadingFinished) {
156
+ onCieEvent(CieEvent.completed);
157
+ }
158
+ };
159
+
160
+ const handleOnError =
161
+ (onError: OnError) =>
162
+ (e: WebViewErrorEvent | WebViewHttpErrorEvent | Error): void => {
163
+ const error = e as Error;
164
+ const webViewError = e as WebViewErrorEvent;
165
+ const webViewHttpError = e as WebViewHttpErrorEvent;
166
+ if (webViewHttpError.nativeEvent.statusCode) {
167
+ const { description, statusCode } = webViewHttpError.nativeEvent;
168
+ onError(
169
+ new CieError({
170
+ message: `WebView http error: ${description} with status code: ${statusCode}`,
171
+ type: CieErrorType.WEB_VIEW_ERROR,
172
+ })
173
+ );
174
+ } else if (webViewError.nativeEvent) {
175
+ const { code, description } = webViewError.nativeEvent;
176
+ onError(
177
+ new CieError({
178
+ message: `WebView error: ${description} with code: ${code}`,
179
+ type: CieErrorType.WEB_VIEW_ERROR,
180
+ })
181
+ );
182
+ } else if (error.message !== undefined) {
183
+ onError(
184
+ new CieError({
185
+ message: `${error.message}`,
186
+ type: CieErrorType.WEB_VIEW_ERROR,
187
+ })
188
+ );
189
+ } else {
190
+ onError(
191
+ new CieError({
192
+ message: "An error occurred in the WebView",
193
+ type: CieErrorType.WEB_VIEW_ERROR,
194
+ })
195
+ );
196
+ }
197
+ };
198
+
199
+ return (
200
+ <WebView
201
+ ref={webView}
202
+ userAgent={defaultUserAgent}
203
+ javaScriptEnabled={true}
204
+ source={{ uri: webViewUrl }}
205
+ onLoadEnd={handleOnLoadEnd(params.onError, params.onEvent)}
206
+ onError={handleOnError(params.onError)}
207
+ onHttpError={handleOnError(params.onError)}
208
+ injectedJavaScript={injectedJavaScript}
209
+ onShouldStartLoadWithRequest={handleShouldStartLoading(
210
+ params.onSuccess,
211
+ params.redirectUrl
212
+ )}
213
+ onMessage={handleMessage}
214
+ />
215
+ );
216
+ };
@@ -0,0 +1,58 @@
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
+ }
@@ -0,0 +1,4 @@
1
+ import { CieEvent, WebViewComponent } from "./component";
2
+ import { CieError, CieErrorType } from "./error";
3
+
4
+ export { WebViewComponent, CieError, CieErrorType, CieEvent };