@ha_tecno/react-native-sdk
Version:
React Native SDK for biometric authentication, liveness detection, and fingerprint recognition
82 lines (73 loc) • 2.09 kB
text/typescript
import { Platform } from 'react-native';
import { getModel } from 'react-native-device-info';
import { v4 as uuid } from 'uuid';
import { api } from '../http/api';
export type LifeCertificateParams = {
videoPath: string;
uid: string;
exposure: number;
exposureMax?: number;
exposureMin?: number;
exposureScaleZeroToOne?: number;
};
export type LifeCertificateResponse = {
code: number;
bpm?: number;
message?: string;
};
export const livenessService = {
lifeCertificate: async ({
videoPath,
uid,
exposure,
exposureMax,
exposureMin,
exposureScaleZeroToOne,
}: LifeCertificateParams): Promise<LifeCertificateResponse> => {
try {
const uuidv4 = uuid();
const deviceModel = getModel();
const formData = new FormData();
formData.append('video', {
uri: Platform.select({
ios: videoPath,
android: `file://${videoPath}`,
}),
type: 'video/mp4',
name: `${uid}_${uuidv4}.mp4`,
} as any);
formData.append('video_key', uuidv4);
formData.append('person_id', uid);
formData.append('device_model', deviceModel);
formData.append('exposure', exposure.toString());
if (exposureMax !== undefined) {
formData.append('exposureMax', exposureMax.toString());
}
if (exposureMin !== undefined) {
formData.append('exposureMin', exposureMin.toString());
}
if (exposureScaleZeroToOne !== undefined) {
formData.append(
'exposureScaleZeroToOne',
exposureScaleZeroToOne.toString()
);
}
const data = await api.postFormData<{
code: number;
bpm?: number;
message?: string;
}>('/v2/liveness', formData);
return {
code: data.code,
bpm: data.bpm,
message: data.message,
};
} catch (error: any) {
console.error('[LifeCertificate Error]:', error);
return {
code: error?.status || 400,
message: error?.message || 'Erro ao processar prova de vida',
};
}
},
};