-
Notifications
You must be signed in to change notification settings - Fork 1
/
componentMap.ts
171 lines (165 loc) · 6.15 KB
/
componentMap.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import AgencyQR from "./preBuilt/AgencyQR";
import RegistrationForm from "./preBuilt/RegistrationForm";
import SearchMenu from "./preBuilt/SearchMenu";
import ScanFingerprintScreen from "./preBuilt/ScanFingerprintScreen";
import CredentialIssuance from "./preBuilt/CredentialIssuance";
import EmailScreen from "./preBuilt/EmailScreen";
import SMSOTPScreen from "./preBuilt/SMSOTPScreen";
import WebcamCaptureTool from "./preBuilt/WebcamCaptureTool";
import FingerprintRegistration from "./preBuilt/FingerprintRegistration";
import KivaVerifier from "./examples/agents/KivaVerifier";
import KivaIssuer from "./examples/agents/KivaIssuer";
import { GuardianSDK } from "@kiva/ssirius-react";
import config_constants from "./constants";
import { FPErrorHandler } from "./examples/errorHandlers/FPErrorHandler";
import { SMSErrorHandler } from "./examples/errorHandlers/SMSErrorHandler";
import axios from "axios";
import { FingerprintMap, FpIndex } from "./preBuilt/FingerprintRegistration/interfaces/FingerprintRegistrationInterfaces";
import FPScanner from "./helpers/FPScanner";
import getPostBody from "./helpers/getPostBody";
const phoneIntls = {
only: false,
countries: ['us']
};
const component_map = {
agency_qr: {
component: AgencyQR,
props: {
agent: new KivaVerifier(config_constants.auth_token)
}
},
email_input: {
component: EmailScreen,
props: {}
},
smsotp: {
component: SMSOTPScreen,
props: {
phoneIntls,
email_step: 'email_input',
guardianSDK: GuardianSDK.init({
url: 'https://sandbox-gateway.protocol-prod.kiva.org/v2/kyc/sms',
token: config_constants.auth_token,
errorHandler: SMSErrorHandler
})
}
},
searchMenu: {
component: SearchMenu,
props: {
dropdownConfig: {
companyEmail: {
name: 'Email',
errorMsg: 'Please enter a valid email',
validation: (input: string) => {
return input.length > 0 && document.querySelector(':invalid') === null;
},
type: 'email'
},
nationalId: {
name: 'NIN',
errorMsg:
'National ID must be eight characters long (capital letters and numbers only)',
validation: (input: string) => {
const parsed = input.match(/[A-Z0-9]/g);
return (
!!parsed &&
parsed.length === 8 &&
input.length === 8
);
}
},
voterId: {
name: 'Voter ID',
errorMsg: 'Voter ID must be seven digits',
validation: (input: string) => {
const voterIdDigits: string[] = input.split('');
return (
voterIdDigits.length === 7 &&
voterIdDigits.every(
(n: string) => !isNaN(Number(n))
)
);
}
}
}
}
},
registrationForm: {
component: RegistrationForm,
props: { phoneIntls }
},
webcam: {
component: WebcamCaptureTool,
props: {}
},
issue: {
component: CredentialIssuance,
props: {
agent: new KivaIssuer('employee.proof.request.json', config_constants.auth_token),
dependencies: {
registrationForm: ['registrationFormData'],
webcam: ['photo~attach']
}
}
},
fpScan: {
component: ScanFingerprintScreen,
props: {
guardianSDK: GuardianSDK.init({
url: 'http://localhost:8080/v2/kiva/api/guardian/verify',
token: config_constants.auth_token,
errorHandler: FPErrorHandler
}),
scanner: FPScanner.init('http://localhost:9907'),
getPostBody,
defaultFinger: 'right_thumb'
}
},
fpRegistration: {
component: FingerprintRegistration,
props: {
getFingerprint: async function() {
const {data} = await axios.get('http://localhost:9907/EKYC/Fingerprint');
return data.ImageBase64;
},
register: async function(fingerprints: FingerprintMap, dependencyData: any) {
const params = [];
const headers: any = {};
if (config_constants.auth_token) {
headers.Authorization = `Bearer ${config_constants.auth_token}`;
}
for (const i in fingerprints) {
const idx: FpIndex = i as unknown as FpIndex; // this is terrible
if (!!fingerprints[idx].image) {
params.push({
image: fingerprints[idx].image,
capture_date: fingerprints[idx].captured,
position: parseInt(i),
missing_code: null,
type_id: '1'
});
}
}
return axios.post('http://localhost:8080/v2/kiva/api/guardian/onboard', {
profile: 'employee.cred.def.json',
guardianData: [{
pluginType: 'FINGERPRINT',
filters: {
externalIds: {
companyEmail: dependencyData.companyEmail
}
},
params
}],
entityData: dependencyData
}, {headers});
},
dependencies: {
registrationForm: ['registrationFormData'],
webcam: ['photo~attach']
}
}
}
};
export default component_map;