UNPKG

@privateid/cryptonets-web-sdk-alpha

Version:
711 lines • 26.2 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { startRegistration, startAuthentication } from '@simplewebauthn/browser'; import { DLType } from './types'; import { apiUrl, orchestrationAPIUrl, apiKey } from './envUtils'; const rand = () => crypto.randomUUID(); export const postImages = (image) => fetch(`${apiUrl}/upload-img`, { method: 'POST', headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ image }), }); /** * @category Api * @param pramUuid UUID to delete * @param callback Callback called once the delete is completed */ export function deleteUuid(guid, callback) { return __awaiter(this, void 0, void 0, function* () { const myHeaders = new Headers(); myHeaders.append('Accept', 'application/json, text/plain, */*'); myHeaders.append('Accept-Encoding', 'gzip, deflate, br'); myHeaders.append('x-api-key', apiKey); const formdata = new FormData(); formdata.append('guid', guid); formdata.append('api_key', apiKey); const requestOptions = { method: 'POST', headers: myHeaders, body: formdata, mode: 'no-cors', }; try { yield fetch(`${apiUrl}/deleteUser`, requestOptions); callback(); } catch (e) { console.error(e); } }); } export function getPhrases() { return __awaiter(this, void 0, void 0, function* () { const requestOptions = { method: 'POST', }; const res = yield fetch(`${apiUrl}/getLivenessPhrases`, requestOptions); return res.json(); }); } export function sendOTP(phone_number) { return __awaiter(this, void 0, void 0, function* () { if (!phone_number) return ''; const token = rand() + rand(); const requestOptions = { method: 'POST', body: JSON.stringify({ phone_number, token, api_key: apiKey, hostURL: window.location.href, customerName: 'betmgm', }), }; const res = yield fetch(`${apiUrl}/sendOTP`, requestOptions); return res.json(); }); } export function verifyOTP(otp, token) { return __awaiter(this, void 0, void 0, function* () { const requestOptions = { method: 'POST', body: JSON.stringify({ token, otp, }), }; const res = yield fetch(`${apiUrl}/verifyOTP`, requestOptions); return res.json(); }); } export function createUser(payload) { return __awaiter(this, void 0, void 0, function* () { const userInfo = { token: payload.id, phone: payload.phone, phoneVerified: payload.phoneVerified, email: payload.email, emailVerified: payload.emailVerified, ssn: payload.ssn4, ssn4: payload.ssn4, ssn9: payload.ssn9, userConsent: payload.userConsent, userConsentDate: payload.userConsentDate, userFaceEnrollConsent: payload.userFaceEnrollConsent, consentVersion: payload.consentVersion, consentContent: payload.consentContent, }; const requestOptions = { method: 'POST', body: JSON.stringify(userInfo), headers: { 'x-api-key': apiKey, 'Content-Type': 'application/json', }, }; const res = yield fetch(`${apiUrl}/user/create`, requestOptions); return res.json(); }); } export function sendEmail(email, uuid, skin, customerName) { return __awaiter(this, void 0, void 0, function* () { const token = rand() + rand(); const requestOptions = { method: 'POST', body: JSON.stringify({ skin, customerName, alias: uuid, hostUrl: window.location.href, version: '1.0', api_key: apiKey, email_address: email, token, action: 'exact_url', }), headers: { 'Content-Type': 'application/json', 'x-api-key': apiKey, }, }; const res = yield fetch(`${apiUrl}/requestAuthLink`, requestOptions); return res.json(); }); } export function expandUri(shortUrl) { return __awaiter(this, void 0, void 0, function* () { const requestOptions = { method: 'POST', body: JSON.stringify({ shortUrl, api_key: apiKey, }), headers: { 'Content-Type': 'application/json', 'x-api-key': apiKey, }, }; const res = yield fetch(`${apiUrl}/expandUri`, requestOptions); return res.json(); }); } export function verifyToken({ code, type }) { return __awaiter(this, void 0, void 0, function* () { const requestOptions = { method: 'POST', body: JSON.stringify({ code, type }), headers: { 'Content-Type': 'application/json', 'x-api-key': apiKey, }, }; const res = yield fetch(`${apiUrl}/user/verif_code`, requestOptions); return res.json(); }); } export function sendSmsCode({ id, phone }) { return __awaiter(this, void 0, void 0, function* () { const requestOptions = { method: 'POST', body: JSON.stringify({ token: id, phone }), headers: { 'Content-Type': 'application/json', 'x-api-key': apiKey, }, }; const res = yield fetch(`${apiUrl}/user/send_code`, requestOptions); return res.json(); }); } export function sendEnrollSms({ id }) { return __awaiter(this, void 0, void 0, function* () { const requestOptions = { method: 'POST', body: JSON.stringify({ token: id }), headers: { 'Content-Type': 'application/json', 'x-api-key': apiKey, }, }; const res = yield fetch(`${apiUrl}/user/send_redirectSms`, requestOptions); return res.json(); }); } export function sendMessage({ id, type, endpoint, message, email, subject, phone, }) { return __awaiter(this, void 0, void 0, function* () { const requestOptions = { method: 'POST', body: JSON.stringify({ token: id, type, email, subject, phone, endpoint, message }), headers: { 'Content-Type': 'application/json', 'x-api-key': apiKey, }, }; const res = yield fetch(`${apiUrl}/user/sendMessage`, requestOptions); return res.json(); }); } export function uploadPortrait({ id, portrait }) { return __awaiter(this, void 0, void 0, function* () { const requestOptions = { method: 'POST', body: JSON.stringify({ token: id, portrait }), headers: { 'Content-Type': 'application/json', 'x-api-key': apiKey, }, }; const res = yield fetch(`${apiUrl}/user/upload/portrait`, requestOptions); return res.json(); }); } export function uploadDL({ id, type, image, barcode, process_ocr }) { return __awaiter(this, void 0, void 0, function* () { let payload; if (type === DLType.BARCODEJSON) { payload = { token: id, type, barcode, }; } else { payload = { token: id, type, image, process_ocr, }; } if (type === DLType.BARCODEJSON && !barcode) throw new Error("Barcode data is required for 'barcodeJson' type."); else if (type !== DLType.BARCODEJSON && !image) throw new Error('Image is required.'); const requestOptions = { method: 'POST', body: JSON.stringify(payload), headers: { 'Content-Type': 'application/json', 'x-api-key': apiKey, }, }; const res = yield fetch(`${apiUrl}/user/upload/dl`, requestOptions); return res.json(); }); } export function uploadHC({ id, type, image, processOcr }) { return __awaiter(this, void 0, void 0, function* () { const payload = { token: id, type, image, process_ocr: processOcr, }; const requestOptions = { method: 'POST', body: JSON.stringify(payload), headers: { 'Content-Type': 'application/json', 'x-api-key': apiKey, }, }; const res = yield fetch(`${apiUrl}/user/upload/hc`, requestOptions); return res.json(); }); } export function getUserStatus({ id }) { return __awaiter(this, void 0, void 0, function* () { const payload = { token: id }; const requestOptions = { method: 'POST', body: JSON.stringify(payload), headers: { 'Content-Type': 'application/json', 'x-api-key': apiKey, }, }; const res = yield fetch(`${apiUrl}/user/status`, requestOptions); return res.json(); }); } export function updateUser({ id, attributes }) { return __awaiter(this, void 0, void 0, function* () { const payload = { token: id, attributes }; const requestOptions = { method: 'POST', body: JSON.stringify(payload), headers: { 'Content-Type': 'application/json', 'x-api-key': apiKey, }, }; const res = yield fetch(`${apiUrl}/user/update`, requestOptions); return res.json(); }); } export function verifyUser({ id, apiValue, organizationApiKey, }) { return __awaiter(this, void 0, void 0, function* () { const payload = { token: id }; const requestOptions = { method: 'POST', body: JSON.stringify(payload), headers: { 'Content-Type': 'application/json', x_api_key: organizationApiKey, }, }; const res = yield fetch(`${orchestrationAPIUrl}/verify/${apiValue}`, requestOptions); return res.json(); }); } export function getProductGroups() { return __awaiter(this, void 0, void 0, function* () { const requestOptions = { method: 'GET', headers: { 'Content-Type': 'application/json', 'x-api-key': apiKey, }, }; const res = yield fetch(`${orchestrationAPIUrl}/product-group/list/prod`, requestOptions); return res.json(); }); } export function transmit({ id, url, sessionToken, final, apiToken, }) { return __awaiter(this, void 0, void 0, function* () { const payload = { token: id, url, sessionToken, apiToken, final }; const requestOptions = { method: 'POST', body: JSON.stringify(payload), headers: { 'Content-Type': 'application/json', 'x-api-key': apiKey, }, }; return fetch(`${orchestrationAPIUrl}/transmit`, requestOptions); }); } export function validateSecurityToken({ token, uuid }) { return __awaiter(this, void 0, void 0, function* () { const payload = { api_key: apiKey, uuid, securityToken: token, IAL: '1' }; const requestOptions = { method: 'POST', body: JSON.stringify(payload), headers: { 'Content-Type': 'application/json', 'x-api-key': apiKey, }, }; const result = yield (yield fetch(`${apiUrl}/isSecurityTokenValid`, requestOptions)).json(); return result; }); } export var VerificationType; (function (VerificationType) { VerificationType["IDENTITY"] = "IDENTITY"; VerificationType["AGE"] = "AGE"; })(VerificationType || (VerificationType = {})); export function createVerificationSession({ successUrl, failureUrl, type, productGroupId, }) { return __awaiter(this, void 0, void 0, function* () { const payload = { successUrl, failureUrl, type, productGroupId }; const requestOptions = { method: 'POST', body: JSON.stringify(payload), headers: { 'Content-Type': 'application/json', 'x-api-key': apiKey, }, }; const result = yield (yield fetch(`${orchestrationAPIUrl}/verification-session’`, requestOptions)).json(); return result; }); } // api v2 var SessionType; (function (SessionType) { SessionType["Identity"] = "IDENTITY"; SessionType["Age"] = "AGE"; })(SessionType || (SessionType = {})); export const createVerificationSessionV2 = ({ successUrl, failureUrl, type, productGroupId, customerIn, }) => __awaiter(void 0, void 0, void 0, function* () { try { const payload = { successUrl, failureUrl, type, productGroupId, customerIn, }; const requestOptions = { method: 'POST', body: JSON.stringify(payload), headers: { 'Content-Type': 'application/json', x_api_key: apiKey, }, }; const result = yield (yield fetch(`${orchestrationAPIUrl}/v2/verification-session`, requestOptions)).json(); return result; } catch (err) { console.error('Error in createVerificationSessionV2:', err); throw new Error('Verification session creation failed.'); } }); export const createUserWithSession = ({ sessionToken, ssn, email, phone }) => __awaiter(void 0, void 0, void 0, function* () { const payload = { ssn, email, phone }; const requestOptions = { method: 'POST', body: JSON.stringify(payload), headers: { 'Content-Type': 'application/json', x_api_key: apiKey, }, }; const result = yield (yield fetch(`${orchestrationAPIUrl}/v2/verification-session/${sessionToken}/user`, requestOptions)).json(); return result; }); export const updateUserManualInputWithSession = ({ sessionToken, firstName, lastName, dob, address, }) => __awaiter(void 0, void 0, void 0, function* () { const payload = Object.assign({ firstName, lastName, dob }, address); const requestOptions = { method: 'POST', body: JSON.stringify(payload), headers: { 'Content-Type': 'application/json', x_api_key: apiKey, }, }; const result = yield (yield fetch(`${orchestrationAPIUrl}/v2/verification-session/${sessionToken}/user/manual-input`, requestOptions)).json(); return result; }); export var createDocumentUploadIdTypeEnum; (function (createDocumentUploadIdTypeEnum) { createDocumentUploadIdTypeEnum["health_card"] = "health_card"; createDocumentUploadIdTypeEnum["passport"] = "passport"; createDocumentUploadIdTypeEnum["drivers_license"] = "drivers_license"; })(createDocumentUploadIdTypeEnum || (createDocumentUploadIdTypeEnum = {})); export const createDocumentUploadIdWithSession = ({ sessionToken, documentType, content, }) => __awaiter(void 0, void 0, void 0, function* () { const payload = { content }; const requestOptions = { method: 'POST', body: JSON.stringify(payload), headers: { 'Content-Type': 'application/json', x_api_key: apiKey, }, }; const result = yield (yield fetch(`${orchestrationAPIUrl}/v2/verification-session/${sessionToken}/document/${documentType} `, requestOptions)).json(); return result; }); export var documentImageTypeEnum; (function (documentImageTypeEnum) { documentImageTypeEnum["FRONT"] = "front"; documentImageTypeEnum["BACK"] = "back"; documentImageTypeEnum["FRONT_CROPPED_DOCUMENT"] = "front_cropped_document"; documentImageTypeEnum["BACK_CROPPED_DOCUMENT"] = "back_cropped_document"; documentImageTypeEnum["FRONT_MUGSHOT"] = "front_mugshot"; documentImageTypeEnum["BACK_BARCODE"] = "back_barcode"; })(documentImageTypeEnum || (documentImageTypeEnum = {})); export const uploadDocumentImageWithSession = ({ sessionToken, documentId, documentImageType, imageString, }) => __awaiter(void 0, void 0, void 0, function* () { const payload = { type: documentImageType, data: imageString }; const requestOptions = { method: 'POST', body: JSON.stringify(payload), headers: { 'Content-Type': 'application/json', x_api_key: apiKey, }, }; const result = yield (yield fetch(`${orchestrationAPIUrl}/v2/verification-session/${sessionToken}/${documentId}/img `, requestOptions)).json(); return result; }); export const updateDocumentContent = ({ sessionToken, documentId, content }) => __awaiter(void 0, void 0, void 0, function* () { const payload = { content }; const requestOptions = { method: 'PUT', body: JSON.stringify(payload), headers: { 'Content-Type': 'application/json', x_api_key: apiKey, }, }; const result = yield (yield fetch(`${orchestrationAPIUrl}/v2/verification-session/${sessionToken}/document/${documentId}`, requestOptions)).json(); return result; }); export const uploadEnrollImageWithSession = ({ sessionToken, imageString, }) => __awaiter(void 0, void 0, void 0, function* () { const payload = { data: imageString }; const requestOptions = { method: 'POST', body: JSON.stringify(payload), headers: { 'Content-Type': 'application/json', x_api_key: apiKey, }, }; const result = yield (yield fetch(`${orchestrationAPIUrl}/v2/verification-session/${sessionToken}/img`, requestOptions)).json(); return result; }); export var updateTypeEnum; (function (updateTypeEnum) { updateTypeEnum["enroll"] = "enroll"; updateTypeEnum["compare"] = "compare"; updateTypeEnum["personalDetails"] = "personalDetails"; })(updateTypeEnum || (updateTypeEnum = {})); export const updateUserWithSession = ({ sessionToken, guid, uuid, email, phone, ssn, portrait_conf_score, updateType, }) => __awaiter(void 0, void 0, void 0, function* () { let payload; if (updateType === updateTypeEnum.enroll) { payload = { guid, uuid, }; } else if (updateType === updateTypeEnum.compare) { payload = { portrait_conf_score, }; } else if (updateType === updateTypeEnum.personalDetails) { payload = { email, phone, ssn, }; } else { return; } const requestOptions = { method: 'POST', body: JSON.stringify(payload), headers: { 'Content-Type': 'application/json', x_api_key: apiKey, }, }; const result = yield (yield fetch(`${orchestrationAPIUrl}/v2/verification-session/${sessionToken}/user/update`, requestOptions)).json(); // eslint-disable-next-line consistent-return return result; }); export const verifyIdWithSession = ({ sessionToken }) => __awaiter(void 0, void 0, void 0, function* () { const requestOptions = { method: 'POST', headers: { 'Content-Type': 'application/json', x_api_key: apiKey, }, }; const result = yield (yield fetch(`${orchestrationAPIUrl}/v3/verify-id/${sessionToken}`, requestOptions)).json(); return result; }); export const verifySessionTokenV2 = ({ sessionToken }) => __awaiter(void 0, void 0, void 0, function* () { const requestOptions = { method: 'GET', headers: { 'Content-Type': 'application/json', x_api_key: apiKey, }, }; const result = yield (yield fetch(`${orchestrationAPIUrl}/v2/verification-session/${sessionToken}`, requestOptions)).json(); return result; }); export const createFederationHash = ({ sessionToken }) => __awaiter(void 0, void 0, void 0, function* () { const requestOptions = { method: 'POST', headers: { 'Content-Type': 'application/json', x_api_key: apiKey, }, }; const result = yield (yield fetch(`${orchestrationAPIUrl}/v2/verification-session/${sessionToken}/federation-hash`, requestOptions)).json(); return result; }); // UUID and Session export const generatePasskey = (sessionToken) => __awaiter(void 0, void 0, void 0, function* () { const response = yield fetch(`${orchestrationAPIUrl}/v2/verification-session/${sessionToken}/passkey/generate-registration-options`, { method: 'POST', headers: { 'Content-Type': 'application/json', x_api_key: apiKey, }, }); let attResp; try { const opts = yield response.json(); attResp = yield startRegistration(opts); } catch (error) { return; } const verificationResp = yield fetch(`${orchestrationAPIUrl}/v2/verification-session/${sessionToken}/passkey/verify-registration`, { method: 'POST', headers: { 'Content-Type': 'application/json', x_api_key: apiKey, }, body: JSON.stringify({ data: attResp }), }); const verificationJSON = yield verificationResp.json(); // eslint-disable-next-line consistent-return return verificationJSON === null || verificationJSON === void 0 ? void 0 : verificationJSON.verified; }); export const authenticatePasskey = (uuid) => __awaiter(void 0, void 0, void 0, function* () { let asseResp; try { const response = yield fetch(`${orchestrationAPIUrl}/v2/passkey/generate-authentication-options`, { method: 'POST', headers: { 'Content-Type': 'application/json', x_api_key: apiKey, }, body: JSON.stringify({ uuid }), // body data type must match "Content-Type" header }); const opts = yield response.json(); if (opts.success === false) { return opts; } asseResp = yield startAuthentication(opts); const verificationResp = yield fetch(`${orchestrationAPIUrl}/v2/passkey/verify-authentication`, { method: 'POST', headers: { 'Content-Type': 'application/json', x_api_key: apiKey, }, body: JSON.stringify({ data: asseResp, uuid }), }); const verificationJSON = yield verificationResp.json(); return verificationJSON === null || verificationJSON === void 0 ? void 0 : verificationJSON.verified; } catch (error) { return error; } }); export const deletePasskey = (uuid) => __awaiter(void 0, void 0, void 0, function* () { try { const response = yield fetch(`${orchestrationAPIUrl}/v2/passkey/delete-authentication`, { method: 'DELETE', headers: { 'Content-Type': 'application/json', x_api_key: apiKey, }, body: JSON.stringify({ uuid }), }); const result = yield response.json(); return result; } catch (error) { return error; } }); export const createAuthSession = ({ requiredAAL, productGroupId, requiredFAL, requiredIAL, actionFlow, interactionUID, }) => __awaiter(void 0, void 0, void 0, function* () { const payload = { requiredAAL, productGroupId, requiredFAL, requiredIAL, interactionUID, actionFlow }; const requestOptions = { method: 'POST', body: JSON.stringify(payload), headers: { 'Content-Type': 'application/json', x_api_key: apiKey, }, }; const result = yield (yield fetch(`${orchestrationAPIUrl}/v2/auth-session`, requestOptions)).json(); return result; }); export const generateAuthPasskeyOptions = ({ uuid, sessionToken }) => __awaiter(void 0, void 0, void 0, function* () { const payload = { uuid }; const requestOptions = { method: 'POST', body: JSON.stringify(payload), headers: { 'Content-Type': 'application/json', x_api_key: apiKey, }, }; const result = yield (yield fetch(`${orchestrationAPIUrl}/v2/auth/${sessionToken}/passkey/generate-authentication-options`, requestOptions)).json(); return result; }); export const verifyAuthPasskey = ({ uuid, sessionToken, data, // Generate passkey options }) => __awaiter(void 0, void 0, void 0, function* () { const payload = { uuid, data }; const requestOptions = { method: 'POST', body: JSON.stringify(payload), headers: { 'Content-Type': 'application/json', x_api_key: apiKey, }, }; const result = yield (yield fetch(`${orchestrationAPIUrl}/v2/auth-session/${sessionToken}/passkey/verify-authentication`, requestOptions)).json(); return result; }); //# sourceMappingURL=apiUtils.js.map