@ha_tecno/live-id-sdk 2.5.1 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/lib/commonjs/components/deviceNotFound/deviceNotFound.js.map +1 -1
  2. package/lib/commonjs/components/deviceNotFound/styles.js.map +1 -1
  3. package/lib/commonjs/components/recordButton/styles.js.map +1 -1
  4. package/lib/commonjs/index.js +6 -0
  5. package/lib/commonjs/index.js.map +1 -1
  6. package/lib/commonjs/screens/FingerAuth/FingerAuth.js +5 -4
  7. package/lib/commonjs/screens/FingerAuth/FingerAuth.js.map +1 -1
  8. package/lib/commonjs/screens/FingerRegister/FingerRegister.js +6 -5
  9. package/lib/commonjs/screens/FingerRegister/FingerRegister.js.map +1 -1
  10. package/lib/commonjs/screens/LifeCertificate/LifeCertificate.js +6 -4
  11. package/lib/commonjs/screens/LifeCertificate/LifeCertificate.js.map +1 -1
  12. package/lib/commonjs/screens/MultiFingerRegister/MultiFingerRegister.js +239 -0
  13. package/lib/commonjs/screens/MultiFingerRegister/MultiFingerRegister.js.map +1 -0
  14. package/lib/commonjs/screens/MultiFingerRegister/styles.js +60 -0
  15. package/lib/commonjs/screens/MultiFingerRegister/styles.js.map +1 -0
  16. package/lib/commonjs/screens/index.js +7 -0
  17. package/lib/commonjs/screens/index.js.map +1 -1
  18. package/lib/commonjs/services/services.js +2 -2
  19. package/lib/commonjs/services/services.js.map +1 -1
  20. package/lib/commonjs/services/types.js +18 -0
  21. package/lib/commonjs/services/types.js.map +1 -1
  22. package/lib/commonjs/store/modules/fingerAuth/slice.js +9 -1
  23. package/lib/commonjs/store/modules/fingerAuth/slice.js.map +1 -1
  24. package/lib/commonjs/store/modules/fingerRegister/slice.js +38 -4
  25. package/lib/commonjs/store/modules/fingerRegister/slice.js.map +1 -1
  26. package/lib/commonjs/store/modules/fingerRegister/types.js +18 -0
  27. package/lib/commonjs/store/modules/fingerRegister/types.js.map +1 -1
  28. package/lib/commonjs/store/modules/lifeCertificate/slice.js +11 -1
  29. package/lib/commonjs/store/modules/lifeCertificate/slice.js.map +1 -1
  30. package/lib/commonjs/utils/index.js +7 -0
  31. package/lib/commonjs/utils/index.js.map +1 -1
  32. package/lib/commonjs/utils/utils.js +11 -0
  33. package/lib/commonjs/utils/utils.js.map +1 -0
  34. package/lib/module/components/deviceNotFound/deviceNotFound.js.map +1 -1
  35. package/lib/module/components/deviceNotFound/styles.js.map +1 -1
  36. package/lib/module/components/recordButton/styles.js.map +1 -1
  37. package/lib/module/index.js +2 -2
  38. package/lib/module/index.js.map +1 -1
  39. package/lib/module/screens/FingerAuth/FingerAuth.js +5 -4
  40. package/lib/module/screens/FingerAuth/FingerAuth.js.map +1 -1
  41. package/lib/module/screens/FingerRegister/FingerRegister.js +6 -5
  42. package/lib/module/screens/FingerRegister/FingerRegister.js.map +1 -1
  43. package/lib/module/screens/LifeCertificate/LifeCertificate.js +6 -4
  44. package/lib/module/screens/LifeCertificate/LifeCertificate.js.map +1 -1
  45. package/lib/module/screens/MultiFingerRegister/MultiFingerRegister.js +230 -0
  46. package/lib/module/screens/MultiFingerRegister/MultiFingerRegister.js.map +1 -0
  47. package/lib/module/screens/MultiFingerRegister/styles.js +54 -0
  48. package/lib/module/screens/MultiFingerRegister/styles.js.map +1 -0
  49. package/lib/module/screens/index.js +2 -1
  50. package/lib/module/screens/index.js.map +1 -1
  51. package/lib/module/services/services.js +2 -2
  52. package/lib/module/services/services.js.map +1 -1
  53. package/lib/module/services/types.js +13 -1
  54. package/lib/module/services/types.js.map +1 -1
  55. package/lib/module/store/modules/fingerAuth/slice.js +9 -1
  56. package/lib/module/store/modules/fingerAuth/slice.js.map +1 -1
  57. package/lib/module/store/modules/fingerRegister/slice.js +38 -4
  58. package/lib/module/store/modules/fingerRegister/slice.js.map +1 -1
  59. package/lib/module/store/modules/fingerRegister/types.js +13 -1
  60. package/lib/module/store/modules/fingerRegister/types.js.map +1 -1
  61. package/lib/module/store/modules/lifeCertificate/slice.js +12 -2
  62. package/lib/module/store/modules/lifeCertificate/slice.js.map +1 -1
  63. package/lib/module/utils/index.js +2 -1
  64. package/lib/module/utils/index.js.map +1 -1
  65. package/lib/module/utils/utils.js +5 -0
  66. package/lib/module/utils/utils.js.map +1 -0
  67. package/lib/typescript/src/components/deviceNotFound/deviceNotFound.d.ts.map +1 -1
  68. package/lib/typescript/src/index.d.ts +2 -2
  69. package/lib/typescript/src/index.d.ts.map +1 -1
  70. package/lib/typescript/src/screens/FingerAuth/FingerAuth.d.ts +2 -1
  71. package/lib/typescript/src/screens/FingerAuth/FingerAuth.d.ts.map +1 -1
  72. package/lib/typescript/src/screens/FingerRegister/FingerRegister.d.ts +2 -1
  73. package/lib/typescript/src/screens/FingerRegister/FingerRegister.d.ts.map +1 -1
  74. package/lib/typescript/src/screens/LifeCertificate/LifeCertificate.d.ts +2 -1
  75. package/lib/typescript/src/screens/LifeCertificate/LifeCertificate.d.ts.map +1 -1
  76. package/lib/typescript/src/screens/MultiFingerRegister/MultiFingerRegister.d.ts +10 -0
  77. package/lib/typescript/src/screens/MultiFingerRegister/MultiFingerRegister.d.ts.map +1 -0
  78. package/lib/typescript/src/screens/MultiFingerRegister/styles.d.ts +50 -0
  79. package/lib/typescript/src/screens/MultiFingerRegister/styles.d.ts.map +1 -0
  80. package/lib/typescript/src/screens/index.d.ts +2 -1
  81. package/lib/typescript/src/screens/index.d.ts.map +1 -1
  82. package/lib/typescript/src/services/services.d.ts +1 -1
  83. package/lib/typescript/src/services/services.d.ts.map +1 -1
  84. package/lib/typescript/src/services/types.d.ts +13 -0
  85. package/lib/typescript/src/services/types.d.ts.map +1 -1
  86. package/lib/typescript/src/store/modules/fingerAuth/selectors.d.ts +1 -1
  87. package/lib/typescript/src/store/modules/fingerAuth/slice.d.ts.map +1 -1
  88. package/lib/typescript/src/store/modules/fingerAuth/type.d.ts +1 -1
  89. package/lib/typescript/src/store/modules/fingerAuth/type.d.ts.map +1 -1
  90. package/lib/typescript/src/store/modules/fingerRegister/selectors.d.ts +5 -1
  91. package/lib/typescript/src/store/modules/fingerRegister/selectors.d.ts.map +1 -1
  92. package/lib/typescript/src/store/modules/fingerRegister/slice.d.ts.map +1 -1
  93. package/lib/typescript/src/store/modules/fingerRegister/types.d.ts +17 -1
  94. package/lib/typescript/src/store/modules/fingerRegister/types.d.ts.map +1 -1
  95. package/lib/typescript/src/store/modules/lifeCertificate/slice.d.ts.map +1 -1
  96. package/lib/typescript/src/store/modules/lifeCertificate/types.d.ts +1 -0
  97. package/lib/typescript/src/store/modules/lifeCertificate/types.d.ts.map +1 -1
  98. package/lib/typescript/src/utils/index.d.ts +2 -1
  99. package/lib/typescript/src/utils/index.d.ts.map +1 -1
  100. package/lib/typescript/src/utils/utils.d.ts +3 -0
  101. package/lib/typescript/src/utils/utils.d.ts.map +1 -0
  102. package/package.json +3 -2
  103. package/src/components/deviceNotFound/deviceNotFound.tsx +10 -12
  104. package/src/components/deviceNotFound/styles.ts +26 -26
  105. package/src/components/recordButton/styles.ts +11 -11
  106. package/src/index.tsx +2 -2
  107. package/src/screens/FingerAuth/FingerAuth.tsx +5 -4
  108. package/src/screens/FingerRegister/FingerRegister.tsx +6 -5
  109. package/src/screens/LifeCertificate/LifeCertificate.tsx +6 -4
  110. package/src/screens/MultiFingerRegister/MultiFingerRegister.tsx +207 -0
  111. package/src/screens/MultiFingerRegister/styles.ts +49 -0
  112. package/src/screens/index.ts +2 -1
  113. package/src/services/services.ts +2 -2
  114. package/src/services/types.ts +14 -0
  115. package/src/store/modules/fingerAuth/slice.ts +9 -1
  116. package/src/store/modules/fingerAuth/type.ts +1 -1
  117. package/src/store/modules/fingerRegister/slice.ts +56 -5
  118. package/src/store/modules/fingerRegister/types.ts +18 -1
  119. package/src/store/modules/lifeCertificate/slice.ts +11 -2
  120. package/src/store/modules/lifeCertificate/types.ts +1 -0
  121. package/src/utils/index.ts +2 -1
  122. package/src/utils/utils.ts +5 -0
  123. package/lib/commonjs/utils/file.js +0 -38
  124. package/lib/commonjs/utils/file.js.map +0 -1
  125. package/lib/module/utils/file.js +0 -29
  126. package/lib/module/utils/file.js.map +0 -1
  127. package/lib/typescript/src/utils/file.d.ts +0 -3
  128. package/lib/typescript/src/utils/file.d.ts.map +0 -1
  129. package/src/utils/file.ts +0 -30
@@ -0,0 +1,207 @@
1
+ import React, { useCallback, useEffect, useRef, useState } from "react";
2
+ import { View, Modal, TouchableOpacity } from "react-native";
3
+ import { Camera, Point, useCameraDevice, useCameraFormat, useCameraPermission } from "react-native-vision-camera";
4
+ import Orientation from "react-native-orientation-locker";
5
+ import { Gesture, GestureDetector, GestureHandlerRootView } from "react-native-gesture-handler";
6
+ import { runOnJS } from "react-native-reanimated";
7
+ import Picker, { PickerStyle } from "react-native-picker-select";
8
+
9
+ import { CameraConfigInfo, CaptureButton, DeviceNotFound, Gabarito, ModalMessage } from "../../components";
10
+ import { styles } from "./styles";
11
+ import { useDispatch, useSelector } from "../../store/modules/fingerRegister";
12
+ import Icon from "../../components/icon/icon";
13
+ import { useIsForeground } from "../../utils";
14
+
15
+ enum Finger {
16
+ LEFT_THUMB = "LT",
17
+ LEFT_INDEX = "LI",
18
+ LEFT_MIDDLE = "LM",
19
+ LEFT_RING = "LR",
20
+ LEFT_PINKY = "LP",
21
+ RIGHT_THUMB = "RT",
22
+ RIGHT_INDEX = "RI",
23
+ RIGHT_MIDDLE = "RM",
24
+ RIGHT_RING = "RR",
25
+ RIGHT_PINKY = "RP"
26
+ }
27
+
28
+ type Props = {
29
+ UID: string;
30
+ onSuccess: (code: number) => void;
31
+ isFocused?: boolean;
32
+ mock?: boolean;
33
+ };
34
+
35
+ const MultiFingerRegister = ({ UID, onSuccess, isFocused, mock }: Props) => {
36
+ const [showModal, setShowModal] = useState(false);
37
+ const cameraRef = useRef<Camera>(null);
38
+ const isForeground = useIsForeground();
39
+ const isActive = isFocused !== undefined ? isForeground && isFocused : isForeground;
40
+ const { hasPermission, requestPermission } = useCameraPermission();
41
+ const device = useCameraDevice("back");
42
+ const state = useSelector();
43
+ const dispatch = useDispatch();
44
+
45
+ const containerCaptureStyled = [styles.containerCapture, { bottom: state.showButtonInfo ? 75 : 20 }];
46
+ const pickerStyled: PickerStyle = {
47
+ chevronDown: { display: "none" },
48
+ chevronUp: { display: "none" },
49
+ inputIOS: {
50
+ fontSize: 16,
51
+ color: "#000",
52
+ textAlign: "center"
53
+ },
54
+ inputAndroid: {
55
+ fontSize: 14,
56
+ color: "#000",
57
+ textAlign: "center"
58
+ }
59
+ };
60
+
61
+ const itemsPicker = [
62
+ { label: "Indicador Direito", value: Finger.RIGHT_INDEX },
63
+ { label: "Médio Direito", value: Finger.RIGHT_MIDDLE },
64
+ { label: "Anelar Direito", value: Finger.RIGHT_RING },
65
+ { label: "Mínimo Direito", value: Finger.RIGHT_PINKY },
66
+ { label: "Polegar Direito", value: Finger.RIGHT_THUMB },
67
+ { label: "Indicador Esquerdo", value: Finger.LEFT_INDEX },
68
+ { label: "Médio Esquerdo", value: Finger.LEFT_MIDDLE },
69
+ { label: "Anelar Esquerdo", value: Finger.LEFT_RING },
70
+ { label: "Mínimo Esquerdo", value: Finger.LEFT_PINKY },
71
+ { label: "Polegar Esquerdo", value: Finger.LEFT_THUMB }
72
+ ];
73
+
74
+ useEffect(() => {
75
+ Orientation.lockToPortrait();
76
+ return () => {
77
+ Orientation.unlockAllOrientations();
78
+ };
79
+ });
80
+
81
+ const cameraPermission = useCallback(async () => {
82
+ if (!hasPermission) {
83
+ await requestPermission();
84
+ }
85
+ }, [hasPermission, requestPermission]);
86
+
87
+ useEffect(() => {
88
+ cameraPermission();
89
+ dispatch.getConfig("finger");
90
+ }, [cameraPermission, dispatch.getConfig]);
91
+
92
+ const cameraFormat = useCameraFormat(device, [
93
+ {
94
+ photoResolution: {
95
+ width: 1280,
96
+ height: 720
97
+ }
98
+ }
99
+ ]);
100
+
101
+ useEffect(() => {
102
+ if (state.base64Images !== undefined && state.base64Images.length === 3) {
103
+ if (!UID) {
104
+ dispatch.setModal("Ocorreu um erro!", "Erro: UID não encontrado!");
105
+ }
106
+ dispatch.handleLoading();
107
+ dispatch.sendImages(state.base64Images, UID, mock, state.currentFinger);
108
+ }
109
+ }, [dispatch.sendImages, dispatch.handleLoading, state.base64Images, state.base64Images.length, mock]);
110
+
111
+ useEffect(() => {
112
+ if (state.code === 0) {
113
+ dispatch.setModal("Sucesso!", "Cadastro de digital realizado com sucesso!");
114
+ onSuccess && onSuccess?.(state.code);
115
+ mock === true ? setTimeout(() => dispatch.handleLoading(), 2000) : dispatch.handleLoading();
116
+ dispatch.handleFinger();
117
+ }
118
+ if (state.code !== 0 && state.code !== null) {
119
+ dispatch.setModal("Ocorreu um erro!", `Erro: ${state.message}`);
120
+ dispatch.handleLoading();
121
+ }
122
+ dispatch.resetState();
123
+ }, [state.code, state.message, dispatch.handleLoading, dispatch.resetState, dispatch.setModal, onSuccess, mock]);
124
+
125
+ const takePhoto = async () => {
126
+ const photo = await cameraRef.current?.takePhoto({
127
+ qualityPrioritization: "balanced"
128
+ });
129
+ if (photo != null) {
130
+ dispatch.setImagePath(photo.path);
131
+ }
132
+ };
133
+
134
+ const focus = useCallback((point: Point) => {
135
+ const camera = cameraRef.current;
136
+ if (camera != null) {
137
+ camera.focus(point);
138
+ }
139
+ }, []);
140
+
141
+ const gesture = Gesture.Tap().onBegin(({ x, y }) => {
142
+ runOnJS(focus)({ x, y });
143
+ });
144
+
145
+ const openModal = () => {
146
+ setShowModal(true);
147
+ };
148
+
149
+ const closeModel = () => {
150
+ setShowModal(false);
151
+ };
152
+
153
+ const handleCurrentFinger = (value: string) => {
154
+ dispatch.setCurrentFinger(value as Finger);
155
+ };
156
+
157
+ if (device == null || hasPermission === false)
158
+ return <DeviceNotFound hasPermission={hasPermission} cameraPermission={cameraPermission} />;
159
+
160
+ return (
161
+ <GestureHandlerRootView style={styles.root}>
162
+ <GestureDetector gesture={gesture}>
163
+ <View style={styles.cameraContainer}>
164
+ <Camera
165
+ ref={cameraRef}
166
+ style={styles.camera}
167
+ device={device}
168
+ format={cameraFormat}
169
+ isActive={isActive}
170
+ torch={isActive ? "on" : "off"}
171
+ exposure={state.exposure}
172
+ zoom={state.zoom}
173
+ photo
174
+ />
175
+ <Gabarito />
176
+ </View>
177
+ </GestureDetector>
178
+ <View style={styles.containerModalIcon}>
179
+ <TouchableOpacity onPress={openModal}>
180
+ <Icon name="cog" size={35} color="#fff" />
181
+ </TouchableOpacity>
182
+ </View>
183
+ <View style={containerCaptureStyled}>
184
+ <CaptureButton onPress={takePhoto} imagesCount={state.base64Images.length} />
185
+ </View>
186
+ {state.showButtonInfo && <CameraConfigInfo exposure={state.exposure} zoom={state.zoom} />}
187
+ <ModalMessage isLoading={state.loading} modal={state.modal} />
188
+ <Modal animationType="slide" transparent={true} visible={showModal} onRequestClose={closeModel}>
189
+ <View style={styles.containerModal}>
190
+ <View style={styles.modal}>
191
+ <Picker
192
+ style={pickerStyled}
193
+ useNativeAndroidPickerStyle={false}
194
+ placeholder={{}}
195
+ onDonePress={closeModel}
196
+ items={itemsPicker}
197
+ value={state.currentFinger}
198
+ onValueChange={handleCurrentFinger}
199
+ />
200
+ </View>
201
+ </View>
202
+ </Modal>
203
+ </GestureHandlerRootView>
204
+ );
205
+ };
206
+
207
+ export default MultiFingerRegister;
@@ -0,0 +1,49 @@
1
+ import { StyleSheet, Dimensions, Platform } from "react-native";
2
+
3
+ const { height } = Dimensions.get("window");
4
+
5
+ export const styles = StyleSheet.create({
6
+ container: {
7
+ flex: 1
8
+ },
9
+ root: {
10
+ flex: 1
11
+ },
12
+ cameraContainer: {
13
+ flex: 1,
14
+ justifyContent: "center"
15
+ },
16
+ camera: {
17
+ flex: 1,
18
+ paddingBottom: height * 0.2
19
+ },
20
+ containerCapture: {
21
+ position: "absolute",
22
+ width: "100%",
23
+ alignItems: "center"
24
+ },
25
+ cameraConfigs: {
26
+ alignItems: "center"
27
+ },
28
+ containerModalIcon: {
29
+ position: "absolute",
30
+ top: 10,
31
+ right: 10,
32
+ zIndex: 9999
33
+ },
34
+ containerModal: { flex: 1, justifyContent: "flex-end", marginBottom: "15%" },
35
+ modal: {
36
+ margin: 20,
37
+ backgroundColor: "white",
38
+ borderRadius: 20,
39
+ padding: Platform.OS === "ios" ? 35 : 20,
40
+ shadowColor: "#000",
41
+ shadowOffset: {
42
+ width: 0,
43
+ height: 2
44
+ },
45
+ shadowOpacity: 0.25,
46
+ shadowRadius: 4,
47
+ elevation: 5
48
+ }
49
+ });
@@ -1,5 +1,6 @@
1
1
  import FingerRegister from "./FingerRegister/FingerRegister";
2
2
  import LifeCertificate from "./LifeCertificate/LifeCertificate";
3
3
  import FingerAuth from "./FingerAuth/FingerAuth";
4
+ import MultiFingerRegister from "./MultiFingerRegister/MultiFingerRegister";
4
5
 
5
- export { FingerRegister, LifeCertificate, FingerAuth };
6
+ export { FingerRegister, LifeCertificate, FingerAuth, MultiFingerRegister };
@@ -32,10 +32,10 @@ export const getConfigsApi = async (): Promise<GetConfigApiResponse> => {
32
32
 
33
33
  export const registerFingerImages = async ({
34
34
  UID,
35
- images
35
+ images,
36
+ finger
36
37
  }: RegisterFingerImagesType): Promise<RegisterFingerResponse> => {
37
38
  try {
38
- const finger = "DI";
39
39
  const { data } = await axiosInstance.post(
40
40
  "/enroll-images",
41
41
  { UID, finger, images },
@@ -9,9 +9,23 @@ export type GetConfigApiResponse = {
9
9
  showButtonInfo: boolean;
10
10
  }[];
11
11
 
12
+ export enum Finger {
13
+ LEFT_THUMB = "LT",
14
+ LEFT_INDEX = "LI",
15
+ LEFT_MIDDLE = "LM",
16
+ LEFT_RING = "LR",
17
+ LEFT_PINKY = "LP",
18
+ RIGHT_THUMB = "RT",
19
+ RIGHT_INDEX = "RI",
20
+ RIGHT_MIDDLE = "RM",
21
+ RIGHT_RING = "RR",
22
+ RIGHT_PINKY = "RP"
23
+ }
24
+
12
25
  export type RegisterFingerImagesType = {
13
26
  UID: string;
14
27
  images: string[];
28
+ finger: Finger | undefined;
15
29
  };
16
30
 
17
31
  export type RegisterFingerResponse = {
@@ -50,9 +50,17 @@ const handleLoading = () => {
50
50
  }));
51
51
  };
52
52
 
53
- const sendImage = async (imagePath: string, UID: string) => {
53
+ const sendImage = async (imagePath: string, UID: string, mock?: boolean) => {
54
54
  try {
55
55
  handleLoading();
56
+ if (mock === true) {
57
+ return slice.setState((state) => ({
58
+ state: {
59
+ ...state.state,
60
+ code: 0
61
+ }
62
+ }));
63
+ }
56
64
  const convertedImage = await readFile(imagePath, "base64");
57
65
  const response = await authFinger({ UID, image: convertedImage });
58
66
  slice.setState((state) => ({
@@ -14,7 +14,7 @@ type State = {
14
14
  type Dispatch = {
15
15
  getConfig: (serviceType: "finger" | "liveness") => void;
16
16
  handleLoading: () => void;
17
- sendImage: (imagePath: string, UID: string) => void;
17
+ sendImage: (imagePath: string, UID: string, mock?: boolean) => void;
18
18
  resetState: () => void;
19
19
  setModal: (title: string, message: string) => void;
20
20
  };
@@ -1,9 +1,22 @@
1
1
  import { create } from "zustand";
2
2
  import { readFile } from "react-native-fs";
3
3
  import { registerFingerImages } from "../../../services/services";
4
- import { FingerRegisterState, InitialState } from "./types";
4
+ import { Finger, FingerRegisterState, InitialState } from "./types";
5
5
  import { getConfigCamera } from "../../../utils";
6
6
 
7
+ const fingerOrder = [
8
+ Finger.RIGHT_INDEX,
9
+ Finger.RIGHT_MIDDLE,
10
+ Finger.RIGHT_RING,
11
+ Finger.RIGHT_PINKY,
12
+ Finger.RIGHT_THUMB,
13
+ Finger.LEFT_INDEX,
14
+ Finger.LEFT_MIDDLE,
15
+ Finger.LEFT_RING,
16
+ Finger.LEFT_PINKY,
17
+ Finger.LEFT_THUMB
18
+ ];
19
+
7
20
  const initialState: InitialState = {
8
21
  state: {
9
22
  exposure: 0,
@@ -16,7 +29,9 @@ const initialState: InitialState = {
16
29
  modal: {
17
30
  title: "",
18
31
  message: ""
19
- }
32
+ },
33
+ currentFinger: fingerOrder[0] as Finger,
34
+ currentFingerIndex: 0
20
35
  }
21
36
  };
22
37
 
@@ -34,8 +49,21 @@ const setImagePath = async (imagePath: string) => {
34
49
  }
35
50
  };
36
51
 
37
- const sendImages = async (images: string[], UID: string) => {
38
- const response = await registerFingerImages({ images, UID });
52
+ const sendImages = async (images: string[], UID: string, mock?: boolean, finger?: Finger) => {
53
+ if (mock === true) {
54
+ return slice.setState((state) => ({
55
+ state: {
56
+ ...state.state,
57
+ code: 0
58
+ }
59
+ }));
60
+ }
61
+
62
+ const response = await registerFingerImages({
63
+ images,
64
+ UID,
65
+ finger: finger === undefined ? Finger.RIGHT_INDEX : finger
66
+ });
39
67
  slice.setState((state) => ({
40
68
  state: {
41
69
  ...state.state,
@@ -44,6 +72,27 @@ const sendImages = async (images: string[], UID: string) => {
44
72
  }));
45
73
  };
46
74
 
75
+ const setCurrentFinger = (finger: Finger) => {
76
+ slice.setState((state) => ({
77
+ state: {
78
+ ...state.state,
79
+ currentFingerIndex: fingerOrder.indexOf(finger),
80
+ currentFinger: finger
81
+ }
82
+ }));
83
+ };
84
+
85
+ const handleFinger = () => {
86
+ const nextIndex = (slice.getState().state.currentFingerIndex + 1) % fingerOrder.length;
87
+ slice.setState((state) => ({
88
+ state: {
89
+ ...state.state,
90
+ currentFingerIndex: nextIndex,
91
+ currentFinger: fingerOrder[nextIndex] as Finger
92
+ }
93
+ }));
94
+ };
95
+
47
96
  const handleLoading = () => {
48
97
  slice.setState((state) => ({
49
98
  state: {
@@ -94,7 +143,9 @@ const slice = create<FingerRegisterState>(() => ({
94
143
  setImagePath,
95
144
  sendImages,
96
145
  setModal,
97
- resetState
146
+ resetState,
147
+ handleFinger,
148
+ setCurrentFinger
98
149
  }
99
150
  }));
100
151
 
@@ -1,3 +1,16 @@
1
+ export enum Finger {
2
+ LEFT_THUMB = "LT",
3
+ LEFT_INDEX = "LI",
4
+ LEFT_MIDDLE = "LM",
5
+ LEFT_RING = "LR",
6
+ LEFT_PINKY = "LP",
7
+ RIGHT_THUMB = "RT",
8
+ RIGHT_INDEX = "RI",
9
+ RIGHT_MIDDLE = "RM",
10
+ RIGHT_RING = "RR",
11
+ RIGHT_PINKY = "RP"
12
+ }
13
+
1
14
  type State = {
2
15
  exposure: number;
3
16
  zoom: number;
@@ -10,14 +23,18 @@ type State = {
10
23
  title: string;
11
24
  message: string;
12
25
  };
26
+ currentFingerIndex: number;
27
+ currentFinger: Finger;
13
28
  };
14
29
  type Dispatch = {
15
30
  getConfig: (serviceType: "finger" | "liveness") => void;
16
31
  handleLoading: () => void;
17
32
  setImagePath: (imagePath: string) => void;
18
- sendImages: (images: string[], UID: string) => void;
33
+ sendImages: (images: string[], UID: string, mock?: boolean, finger?: Finger) => void;
19
34
  setModal: (title: string, message: string) => void;
20
35
  resetState: () => void;
36
+ handleFinger: () => void;
37
+ setCurrentFinger: (finger: Finger) => void;
21
38
  };
22
39
 
23
40
  export type InitialState = {
@@ -1,7 +1,7 @@
1
1
  import { create } from "zustand";
2
2
  import { InitialState, LifeCertificateState, SendLifeCertificateType } from "./types";
3
3
  import { lifeCertificate } from "../../../services";
4
- import { getConfigCamera } from "../../../utils";
4
+ import { getConfigCamera, randomHeartRate } from "../../../utils";
5
5
 
6
6
  const initialState: InitialState = {
7
7
  state: {
@@ -38,7 +38,16 @@ const setIsRecording = (recoding: boolean) => {
38
38
  }));
39
39
  };
40
40
 
41
- const sendLifeCertificate = async ({ videoFile, UID, exposure }: SendLifeCertificateType) => {
41
+ const sendLifeCertificate = async ({ videoFile, UID, exposure, mock }: SendLifeCertificateType) => {
42
+ if (mock === true) {
43
+ return slice.setState((state) => ({
44
+ state: {
45
+ ...state.state,
46
+ bpm: randomHeartRate(),
47
+ code: 0
48
+ }
49
+ }));
50
+ }
42
51
  const videoPath = videoFile.path;
43
52
  const response = await lifeCertificate({
44
53
  videoPath,
@@ -37,4 +37,5 @@ export type SendLifeCertificateType = {
37
37
  videoFile: VideoFile;
38
38
  UID: string;
39
39
  exposure: number;
40
+ mock?: boolean;
40
41
  };
@@ -1,4 +1,5 @@
1
1
  import getConfigCamera from "./getConfigCamera";
2
+ import randomHeartRate from "./utils";
2
3
  import { useIsForeground } from "./hooks/useIsForeground";
3
4
 
4
- export { getConfigCamera, useIsForeground };
5
+ export { getConfigCamera, useIsForeground, randomHeartRate };
@@ -0,0 +1,5 @@
1
+ const randomHeartRate = (): number => {
2
+ return Math.floor(Math.random() * (90 - 75 + 1) + 75);
3
+ };
4
+
5
+ export default randomHeartRate;
@@ -1,38 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.validarBase64 = exports.encodeImageToBase64 = void 0;
7
- var _reactNativeFs = _interopRequireDefault(require("react-native-fs"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- const encodeImageToBase64 = async imagePath => {
10
- try {
11
- const imageData = await _reactNativeFs.default.readFile(imagePath, "base64");
12
- return imageData;
13
- } catch (error) {
14
- return null;
15
- }
16
- };
17
- exports.encodeImageToBase64 = encodeImageToBase64;
18
- const validarBase64 = array => {
19
- // Verifica se o argumento é um array e tem exatamente 3 elementos
20
- if (!Array.isArray(array) || array.length !== 3) {
21
- return false;
22
- }
23
-
24
- // Regex para validar base64
25
- const base64Regex = /^[a-zA-Z0-9+/]*={0,2}$/;
26
-
27
- // Verifica se cada elemento do array é uma string válida em base64
28
- for (let i = 0; i < array.length; i++) {
29
- if (typeof array[i] !== "string" || !base64Regex.test(array[i])) {
30
- return false;
31
- }
32
- }
33
-
34
- // Se chegou até aqui, o array é válido
35
- return true;
36
- };
37
- exports.validarBase64 = validarBase64;
38
- //# sourceMappingURL=file.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_reactNativeFs","_interopRequireDefault","require","obj","__esModule","default","encodeImageToBase64","imagePath","imageData","RNFS","readFile","error","exports","validarBase64","array","Array","isArray","length","base64Regex","i","test"],"sourceRoot":"../../../src","sources":["utils/file.ts"],"mappings":";;;;;;AAAA,IAAAA,cAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAmC,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE5B,MAAMG,mBAAmB,GAAG,MAAOC,SAAiB,IAAK;EAC9D,IAAI;IACF,MAAMC,SAAS,GAAG,MAAMC,sBAAI,CAACC,QAAQ,CAACH,SAAS,EAAE,QAAQ,CAAC;IAC1D,OAAOC,SAAS;EAClB,CAAC,CAAC,OAAOG,KAAK,EAAE;IACd,OAAO,IAAI;EACb;AACF,CAAC;AAACC,OAAA,CAAAN,mBAAA,GAAAA,mBAAA;AAEK,MAAMO,aAAa,GAAIC,KAAqB,IAAK;EACtD;EACA,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC,IAAIA,KAAK,CAACG,MAAM,KAAK,CAAC,EAAE;IAC/C,OAAO,KAAK;EACd;;EAEA;EACA,MAAMC,WAAW,GAAG,wBAAwB;;EAE5C;EACA,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGL,KAAK,CAACG,MAAM,EAAEE,CAAC,EAAE,EAAE;IACrC,IAAI,OAAOL,KAAK,CAACK,CAAC,CAAC,KAAK,QAAQ,IAAI,CAACD,WAAW,CAACE,IAAI,CAACN,KAAK,CAACK,CAAC,CAAC,CAAC,EAAE;MAC/D,OAAO,KAAK;IACd;EACF;;EAEA;EACA,OAAO,IAAI;AACb,CAAC;AAACP,OAAA,CAAAC,aAAA,GAAAA,aAAA"}
@@ -1,29 +0,0 @@
1
- import RNFS from "react-native-fs";
2
- export const encodeImageToBase64 = async imagePath => {
3
- try {
4
- const imageData = await RNFS.readFile(imagePath, "base64");
5
- return imageData;
6
- } catch (error) {
7
- return null;
8
- }
9
- };
10
- export const validarBase64 = array => {
11
- // Verifica se o argumento é um array e tem exatamente 3 elementos
12
- if (!Array.isArray(array) || array.length !== 3) {
13
- return false;
14
- }
15
-
16
- // Regex para validar base64
17
- const base64Regex = /^[a-zA-Z0-9+/]*={0,2}$/;
18
-
19
- // Verifica se cada elemento do array é uma string válida em base64
20
- for (let i = 0; i < array.length; i++) {
21
- if (typeof array[i] !== "string" || !base64Regex.test(array[i])) {
22
- return false;
23
- }
24
- }
25
-
26
- // Se chegou até aqui, o array é válido
27
- return true;
28
- };
29
- //# sourceMappingURL=file.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["RNFS","encodeImageToBase64","imagePath","imageData","readFile","error","validarBase64","array","Array","isArray","length","base64Regex","i","test"],"sourceRoot":"../../../src","sources":["utils/file.ts"],"mappings":"AAAA,OAAOA,IAAI,MAAM,iBAAiB;AAElC,OAAO,MAAMC,mBAAmB,GAAG,MAAOC,SAAiB,IAAK;EAC9D,IAAI;IACF,MAAMC,SAAS,GAAG,MAAMH,IAAI,CAACI,QAAQ,CAACF,SAAS,EAAE,QAAQ,CAAC;IAC1D,OAAOC,SAAS;EAClB,CAAC,CAAC,OAAOE,KAAK,EAAE;IACd,OAAO,IAAI;EACb;AACF,CAAC;AAED,OAAO,MAAMC,aAAa,GAAIC,KAAqB,IAAK;EACtD;EACA,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC,IAAIA,KAAK,CAACG,MAAM,KAAK,CAAC,EAAE;IAC/C,OAAO,KAAK;EACd;;EAEA;EACA,MAAMC,WAAW,GAAG,wBAAwB;;EAE5C;EACA,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGL,KAAK,CAACG,MAAM,EAAEE,CAAC,EAAE,EAAE;IACrC,IAAI,OAAOL,KAAK,CAACK,CAAC,CAAC,KAAK,QAAQ,IAAI,CAACD,WAAW,CAACE,IAAI,CAACN,KAAK,CAACK,CAAC,CAAC,CAAC,EAAE;MAC/D,OAAO,KAAK;IACd;EACF;;EAEA;EACA,OAAO,IAAI;AACb,CAAC"}
@@ -1,3 +0,0 @@
1
- export declare const encodeImageToBase64: (imagePath: string) => Promise<string | null>;
2
- export declare const validarBase64: (array: string | any[]) => boolean;
3
- //# sourceMappingURL=file.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../../src/utils/file.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB,cAAqB,MAAM,2BAO1D,CAAC;AAEF,eAAO,MAAM,aAAa,UAAW,MAAM,GAAG,GAAG,EAAE,YAkBlD,CAAC"}
package/src/utils/file.ts DELETED
@@ -1,30 +0,0 @@
1
- import RNFS from "react-native-fs";
2
-
3
- export const encodeImageToBase64 = async (imagePath: string) => {
4
- try {
5
- const imageData = await RNFS.readFile(imagePath, "base64");
6
- return imageData;
7
- } catch (error) {
8
- return null;
9
- }
10
- };
11
-
12
- export const validarBase64 = (array: string | any[]) => {
13
- // Verifica se o argumento é um array e tem exatamente 3 elementos
14
- if (!Array.isArray(array) || array.length !== 3) {
15
- return false;
16
- }
17
-
18
- // Regex para validar base64
19
- const base64Regex = /^[a-zA-Z0-9+/]*={0,2}$/;
20
-
21
- // Verifica se cada elemento do array é uma string válida em base64
22
- for (let i = 0; i < array.length; i++) {
23
- if (typeof array[i] !== "string" || !base64Regex.test(array[i])) {
24
- return false;
25
- }
26
- }
27
-
28
- // Se chegou até aqui, o array é válido
29
- return true;
30
- };