async init(investor: Investor): Promise<KycInitResult> { const id = investor.id.toHexString(); const hash = base64encode(bcrypt.hashSync(id + config.kyc.apiSecret)); const kycOptions = { baseUrl: this.baseUrl, method: 'POST', auth: { user: this.apiToken, password: this.apiSecret }, headers: { 'User-Agent': 'JINCOR ICO/1.0.0' }, body: { merchantIdScanReference: uuid.v4(), successUrl: `${ config.app.apiUrl }/kyc/uploaded/${ id }/${ hash }`, errorUrl: `${ config.app.frontendUrl }/dashboard/verification/failure`, callbackUrl: `${ config.app.apiUrl }/kyc/callback`, customerId: investor.email, authorizationTokenLifetime: this.defaultTokenLifetime } }; return await request.json<KycInitResult>('/initiateNetverify', kycOptions); }
async validateVerification(method: string, id: string, input: ValidateVerificationInput): Promise<ValidationResult> { try { return await request.json<ValidationResult>(`/methods/${ method }/verifiers/${ id }/actions/validate`, { baseUrl: this.baseUrl, auth: { bearer: this.tenantToken }, method: 'POST', body: input }); } catch (e) { if (e.statusCode === 422) { if (e.response.body.data.attempts >= config.verify.maxAttempts) { await this.invalidateVerification(method, id); throw new MaxVerificationsAttemptsReached('You have used all attempts to enter code'); } throw new NotCorrectVerificationCode('Not correct code'); } if (e.statusCode === 404) { throw new VerificationIsNotFound('Code was expired or not found. Please retry'); } throw e; } }
return new Promise<LandingsdataByLandingdate[]>((resolve, reject) => { const url = (window.location.origin + '/api/landingsdata'); WebRequest.json<LandingsdataResponse>(url + params) .then(response => { resolve(transformLandingsdatoReponse(response)) }) .catch(rejection => reject(rejection)); });
async deleteUser(login: string): Promise<void> { return await request.json<void>(`/user/${ login }`, { baseUrl: this.baseUrl, method: 'DELETE', headers: { 'authorization': `Bearer ${ this.tenantToken }` } }); }
async logoutTenant(token: string): Promise<void> { await request.json<TenantVerificationResult>('/tenant/logout', { baseUrl: this.baseUrl, method: 'POST', body: { token } }); }
async verifyTenantToken(token: string): Promise<TenantVerificationResult> { return (await request.json<TenantVerificationResponse>('/tenant/verify', { baseUrl: this.baseUrl, method: 'POST', body: { token } })).decoded; }
async invalidateVerification(method: string, id: string): Promise<void> { await request.json<Result>(`/methods/${ method }/verifiers/${ id }`, { baseUrl: this.baseUrl, auth: { bearer: this.tenantToken }, method: 'DELETE' }); }
async verifyUserToken(token: string): Promise<UserVerificationResult> { return (await request.json<UserVerificationResponse>('/auth/verify', { baseUrl: this.baseUrl, method: 'POST', headers: { 'authorization': `Bearer ${ this.tenantToken }` }, body: { token } })).decoded; }
async loginUser(data: UserLoginData): Promise<AccessTokenResponse> { return await request.json<AccessTokenResponse>('/auth', { baseUrl: this.baseUrl, method: 'POST', headers: { 'authorization': `Bearer ${ this.tenantToken }` }, body: data }); }
async loginTenant(email: string, password: string): Promise<AccessTokenResponse> { return await request.json<AccessTokenResponse>('/tenant/login', { baseUrl: this.baseUrl, method: 'POST', body: { email, password } }); }