Skip to content

Commit

Permalink
[HV SDK] v5 (#33)
Browse files Browse the repository at this point in the history
* [V5] working.

* package

* [package] release version of types.
  • Loading branch information
rsmets authored Oct 11, 2022
1 parent 1d4e08e commit 422dc8c
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 88 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"@types/validator": "^13.1.3",
"@typescript-eslint/eslint-plugin": "^4.15.2",
"@typescript-eslint/parser": "^4.15.2",
"@unumid/id-verification-types": "git+ssh://[email protected]:UnumID/id-verification-types.git#v0.1.0",
"@unumid/id-verification-types": "git+ssh://[email protected]/UnumID/id-verification-types#v1.0.0",
"eslint": "^7.20.0",
"eslint-config-semistandard": "^16.0.0",
"eslint-config-standard": "^16.0.3",
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
-->
<title>Unum ID Verification</title>

<script src="https://hv-camera-web-sg.s3-ap-southeast-1.amazonaws.com/hyperverge-web-sdk@4.1.6/src/sdk.min.js"></script>
<script src="https://hv-camera-web-sg.s3-ap-southeast-1.amazonaws.com/hyperverge-web-sdk@5.2.4/src/sdk.min.js"></script>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
186 changes: 102 additions & 84 deletions src/components/Register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,33 @@ import { config } from '../config';
import { useSearchParams } from 'react-router-dom';
import { HvDocScanData } from '../types';

import { KYCData as _KYCData } from '@unumid/id-verification-types';

interface KYCData extends Omit<_KYCData, 'docImage' | 'fullFaceImage'> {
docImage?: string;
fullFaceImage?: string;

}
import { KYCData as _KYCData, HvClientResponse } from '@unumid/id-verification-types';

// export interface HVDetails {
// dateOfBirth: string;
// firstName: string;
// fullName: string;
// // eslint-disable-next-line camelcase
// id_back_imagePath: string;
// idNumber: string;
// lastName: string;
// middleName: string;
// }

// export interface HvResult {
// status: string;
// transactionId: string;
// details: HVDetails;
// }

// interface KYCData extends Omit<_KYCData, 'docImage' | 'fullFaceImage'> {
// docImage?: string;
// fullFaceImage?: string;
// }

// interface HvDocScanResult {
// status: string;
// }

// types for global variables added by the hyperverge sdk
declare global {
Expand All @@ -38,81 +58,76 @@ declare global {
}
}

const makeHvHandler = (callback: (data: KYCData) => void) => (HyperKycResult: any) => {
if (HyperKycResult.Cancelled) {
// user cancelled
console.log('hyperverge cancelled', HyperKycResult);
} else if (HyperKycResult.Failure) {
// fail
console.log('hyperverge failed', HyperKycResult);
} else if (HyperKycResult.Success) {
// success
console.log('hyperverge success', HyperKycResult);

const hvDocScanData: HvDocScanData = HyperKycResult.Success.data;
const docCountryId = hvDocScanData.selectedCountryId;

const faceMatchData = hvDocScanData.faceMatchData.responseResult.result.details.match;
const faceMatch = faceMatchData.value;
const faceMatchConfidence = faceMatchData.confidence;

const faceData = hvDocScanData.faceData;
// const fullFaceImage = faceData.fullFaceImagePath;
const liveFace = faceData.responseResult.result.details.liveFace.value;
const liveFaceConfidence = faceData.responseResult.result.details.liveFace.confidence;

const docData = hvDocScanData.docListData[0];
// const docImage = docData.docImagePath;
const docType = docData.documentId;
const { address, dateOfBirth, fullName, gender } = docData.responseResult.result.details[0].fieldsExtracted;
debugger;
/**
* Reformat the DOB from the HV document scan.
* dateOfBirthday was taking the format MM-DD-YYYY from HV, but as of 6/23 was updated to dD-mM-YYYY.
* and Prove needs it in the format YYYY-MM-DD, so just turning it in that here
*/
const proveDob = dateOfBirth.value.split('-');

// loop through the split data array and ensure all values have at least 2 digits
for (let i = 0; i < proveDob.length; i++) {
if (proveDob[i].length < 2) {
proveDob[i] = '0' + proveDob[i];
}
}

// shift values to fit desired format; this was working when HV was returning in format MM-DD-YYYY
// const hold = proveDob[2];
// proveDob[2] = proveDob[1];
// proveDob[1] = proveDob[0];
// proveDob[0] = hold;

// shift values to fit desired format; having to deal with new format of DD-MM-YYYY
const hold = proveDob[2];
proveDob[2] = proveDob[0];
proveDob[0] = hold;
const makeHvHandler = (callback: (data: HvClientResponse) => void) => (HyperKycResult: any) => {
switch (HyperKycResult.status) {
case 'user_cancelled':
// user cancelled
console.log('hyperverge cancelled', HyperKycResult);
break;
case 'error':
// failure
console.log('hyperverge error', HyperKycResult);
break;
case 'auto_approved':
case 'auto_declined':
case 'needs_review':
// workflow success
break;
}

// now should be in YYYY-MM-DD format
const dob = proveDob.join('-');
// const hvDocScanData: HvDocScanData = HyperKycResult.Success.data;
// const docCountryId = hvDocScanData.selectedCountryId;

// const faceMatchData = hvDocScanData.faceMatchData.responseResult.result.details.match;
// const faceMatch = faceMatchData.value;
// const faceMatchConfidence = faceMatchData.confidence;

// const faceData = hvDocScanData.faceData;
// // const fullFaceImage = faceData.fullFaceImagePath;
// const liveFace = faceData.responseResult.result.details.liveFace.value;
// const liveFaceConfidence = faceData.responseResult.result.details.liveFace.confidence;

// const docData = hvDocScanData.docListData[0];
// // const docImage = docData.docImagePath;
// const docType = docData.documentId;
// const { address, dateOfBirth, fullName, gender } = docData.responseResult.result.details[0].fieldsExtracted;
// debugger;
// /**
// * Reformat the DOB from the HV document scan.
// * dateOfBirthday was taking the format MM-DD-YYYY from HV, but as of 6/23 was updated to dD-mM-YYYY.
// * and Prove needs it in the format YYYY-MM-DD, so just turning it in that here
// */
// const proveDob = dateOfBirth.value.split('-');

// // loop through the split data array and ensure all values have at least 2 digits
// for (let i = 0; i < proveDob.length; i++) {
// if (proveDob[i].length < 2) {
// proveDob[i] = '0' + proveDob[i];
// }
// }

// // shift values to fit desired format; this was working when HV was returning in format MM-DD-YYYY
// // const hold = proveDob[2];
// // proveDob[2] = proveDob[1];
// // proveDob[1] = proveDob[0];
// // proveDob[0] = hold;

// // shift values to fit desired format; having to deal with new format of DD-MM-YYYY
// const hold = proveDob[2];
// proveDob[2] = proveDob[0];
// proveDob[0] = hold;

// // now should be in YYYY-MM-DD format
// const dob = proveDob.join('-');

debugger;
// eslint-disable-next-line node/no-callback-literal
callback({
address: address.value,
dob,
fullName: fullName.value,
gender: gender.value,
// docImage,
docType,
docCountryId,
// fullFaceImage,
liveFace,
liveFaceConfidence,
faceMatch,
faceMatchConfidence
});
debugger;
// eslint-disable-next-line node/no-callback-literal
callback(
HyperKycResult
);

console.log('success');
}
console.log('success');
// }
};

/**
Expand Down Expand Up @@ -208,7 +223,7 @@ const Register: FC = () => {
* calls the hvService to persist the data on a user entity for credential issuance later.
* the service creates a user and returns the userCode for linking to the prove prefill data
*/
const sendHvDocScanData = async (data: KYCData): Promise<string> => {
const sendHvDocScanData = async (data: HvClientResponse): Promise<string> => {
// TODO add auth with backend
const hvService = backendClient.service('hyperVerge');

Expand Down Expand Up @@ -258,16 +273,19 @@ const Register: FC = () => {
const transactionId = `${v1()}`;
const documentHv = new window.Document(true, defaultCountryId, defaultDocumentId);
const face = new window.Face();
const workflow = [documentHv, face];
const hyperKycConfig = new window.HyperKycConfig(accessToken, workflow, transactionId, defaultCountryId);
// const workflow = [documentHv, face];
// const workflowId = 'global_workflow';
const workflowId = 'USA_DL_Workflow';
const hyperKycConfig = new window.HyperKycConfig(accessToken, workflowId, transactionId);
// const hyperKycConfig = new window.HyperKycConfig(accessToken, workflow, transactionId, defaultCountryId);

const callback = async (data: KYCData) => {
const callback = async (data: HvClientResponse) => {
const userCode = await sendHvDocScanData(data);

debugger;
if (config.proveEnabled) {
// kick off Prove InstantLink sms
sendProveSms(userCode, data.dob);
// sendProveSms(userCode, data.dob);
} else {
// redirect to the deeplink router with the userCode and issuer did
redirectToDeeplinkRouter(userCode, config.hvIssuerDid);
Expand Down

0 comments on commit 422dc8c

Please sign in to comment.