Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/shared/utils/util.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use our IBAN tools?

const { countryCode, bankIdentifier } = IbanTools.extractIBAN(iban)

Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,23 @@ export class Util {
return result || '0';
}

// --- IBAN --- //
static getBLZ(iban: string): string | undefined {
if (!iban) return undefined;

switch (Util.getIbanCountry(iban)) {
case 'DE':
return iban.substring(4, 12);

default:
return iban.length >= 10 ? iban.substring(4, 9) : undefined;
}
}

static getIbanCountry(iban: string): string {
return iban.substring(0, 2);
}

// --- ID GENERATION --- //
static randomId(): number {
return randomBytes(4).readUInt32BE();
Expand Down
72 changes: 46 additions & 26 deletions src/subdomains/core/aml/services/aml-helper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export class AmlHelperService {
(entity.bankTx || entity.checkoutTx) &&
entity.userData.phone &&
entity.userData.birthday &&
(!entity.userData.accountType || entity.userData.accountType === AccountType.PERSONAL) &&
entity.userData.isPersonalAccount &&
Util.yearsDiff(entity.userData.birthday) > 55
)
errors.push(AmlError.PHONE_VERIFICATION_NEEDED);
Expand Down Expand Up @@ -252,28 +252,43 @@ export class AmlHelperService {
)
errors.push(AmlError.BIC_BLACKLISTED);
if (
blacklist.some((b) =>
b.matches(
[
SpecialExternalAccountType.BANNED_IBAN,
SpecialExternalAccountType.BANNED_IBAN_BUY,
SpecialExternalAccountType.BANNED_IBAN_AML,
],
entity.bankTx.iban,
),
blacklist.some(
(b) =>
b.matches(
[
SpecialExternalAccountType.BANNED_IBAN,
SpecialExternalAccountType.BANNED_IBAN_BUY,
SpecialExternalAccountType.BANNED_IBAN_AML,
],
entity.bankTx.iban,
) ||
b.matches(
[
SpecialExternalAccountType.BANNED_BLZ,
SpecialExternalAccountType.BANNED_BLZ_BUY,
SpecialExternalAccountType.BANNED_BLZ_AML,
],
Util.getBLZ(entity.bankTx.iban),
),
)
)
errors.push(AmlError.IBAN_BLACKLISTED);

if (
!entity.userData.phoneCallCheckDate &&
entity.userData.isPersonalAccount &&
phoneCallList.some((b) =>
b.matches([SpecialExternalAccountType.AML_PHONE_CALL_NEEDED_BIC_BUY], entity.bankTx.bic),
)
)
errors.push(AmlError.BIC_PHONE_VERIFICATION_NEEDED);
if (
phoneCallList.some((b) =>
b.matches([SpecialExternalAccountType.AML_PHONE_CALL_NEEDED_IBAN_BUY], entity.bankTx.iban),
!entity.userData.phoneCallCheckDate &&
entity.userData.isPersonalAccount &&
phoneCallList.some(
(b) =>
b.matches([SpecialExternalAccountType.AML_PHONE_CALL_NEEDED_IBAN_BUY], entity.bankTx.iban) ||
b.matches([SpecialExternalAccountType.AML_PHONE_CALL_NEEDED_BLZ_BUY], Util.getBLZ(entity.bankTx.iban)),
)
)
errors.push(AmlError.IBAN_PHONE_VERIFICATION_NEEDED);
Expand Down Expand Up @@ -328,15 +343,24 @@ export class AmlHelperService {
if (entity.sell.fiat.name === 'CHF' && !Config.isDomesticIban(entity.sell.iban))
errors.push(AmlError.ABROAD_CHF_NOT_ALLOWED);
if (
blacklist.some((b) =>
b.matches(
[
SpecialExternalAccountType.BANNED_IBAN,
SpecialExternalAccountType.BANNED_IBAN_SELL,
SpecialExternalAccountType.BANNED_IBAN_AML,
],
entity.sell.iban,
),
blacklist.some(
(b) =>
b.matches(
[
SpecialExternalAccountType.BANNED_IBAN,
SpecialExternalAccountType.BANNED_IBAN_SELL,
SpecialExternalAccountType.BANNED_IBAN_AML,
],
entity.sell.iban,
) ||
b.matches(
[
SpecialExternalAccountType.BANNED_BLZ,
SpecialExternalAccountType.BANNED_BLZ_SELL,
SpecialExternalAccountType.BANNED_BLZ_AML,
],
Util.getBLZ(entity.sell.iban),
),
)
)
errors.push(AmlError.IBAN_BLACKLISTED);
Expand Down Expand Up @@ -438,11 +462,7 @@ export class AmlHelperService {
break;

case AmlRule.RULE_16:
if (
entity instanceof BuyCrypto &&
entity.userData.accountType === AccountType.PERSONAL &&
!entity.userData.phoneCallCheckDate
)
if (entity instanceof BuyCrypto && entity.userData.isPersonalAccount && !entity.userData.phoneCallCheckDate)
errors.push(AmlError.PHONE_VERIFICATION_NEEDED);
break;
}
Expand Down
13 changes: 11 additions & 2 deletions src/subdomains/core/transaction/transaction-util.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { BlockchainRegistryService } from 'src/integration/blockchain/shared/ser
import { TxValidationService } from 'src/integration/blockchain/shared/services/tx-validation.service';
import { CheckoutPaymentStatus } from 'src/integration/checkout/dto/checkout.dto';
import { AssetService } from 'src/shared/models/asset/asset.service';
import { Util } from 'src/shared/utils/util';
import { User } from 'src/subdomains/generic/user/models/user/user.entity';
import { BankTxReturn } from 'src/subdomains/supporting/bank-tx/bank-tx-return/bank-tx-return.entity';
import { BankAccountService } from 'src/subdomains/supporting/bank/bank-account/bank-account.service';
Expand Down Expand Up @@ -107,12 +108,20 @@ export class TransactionUtilService {
if (
blockedAccounts.some(
(b) =>
[
([
SpecialExternalAccountType.BANNED_IBAN,
SpecialExternalAccountType.BANNED_IBAN_BUY,
SpecialExternalAccountType.BANNED_IBAN_SELL,
SpecialExternalAccountType.BANNED_IBAN_AML,
].includes(b.type) && b.value === iban,
].includes(b.type) &&
b.value === iban) ||
([
SpecialExternalAccountType.BANNED_BLZ,
SpecialExternalAccountType.BANNED_BLZ_BUY,
SpecialExternalAccountType.BANNED_BLZ_SELL,
SpecialExternalAccountType.BANNED_BLZ_AML,
].includes(b.type) &&
b.value === Util.getBLZ(iban)),
)
)
throw new BadRequestException('Iban not allowed');
Expand Down
4 changes: 2 additions & 2 deletions src/subdomains/generic/kyc/services/kyc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export class KycService {
} else if (
errors.includes(KycError.VERIFIED_NAME_MISSING) &&
errors.length === 1 &&
entity.userData.accountType === AccountType.PERSONAL
entity.userData.isPersonalAccount
) {
await this.userDataService.updateUserDataInternal(entity.userData, {
verifiedName: `${entity.userData.firstname} ${entity.userData.surname}`,
Expand Down Expand Up @@ -1475,7 +1475,7 @@ export class KycService {
identStep.userData.verifiedCountry ??
identStep.userData.country;

if (identStep.userData.accountType === AccountType.PERSONAL) {
if (identStep.userData.isPersonalAccount) {
// Personal Account
if (!userCountry.dfxEnable) errors.push(KycError.COUNTRY_NOT_ALLOWED);
if (userCountry.manualReviewRequired) errors.push(KycError.MANUAL_REVIEW_REQUIRED);
Expand Down
3 changes: 1 addition & 2 deletions src/subdomains/generic/kyc/services/name-check.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Injectable, InternalServerErrorException, NotFoundException, OnModuleIn
import { Util } from 'src/shared/utils/util';
import { IsNull } from 'typeorm';
import { BankData, BankDataType } from '../../user/models/bank-data/bank-data.entity';
import { AccountType } from '../../user/models/user-data/account-type.enum';
import { UserData } from '../../user/models/user-data/user-data.entity';
import { UserDataService } from '../../user/models/user-data/user-data.service';
import { DilisenseApiData } from '../dto/input/dilisense-data.dto';
Expand Down Expand Up @@ -48,7 +47,7 @@ export class NameCheckService implements OnModuleInit {
// );

// Personal name check
if (!bankData.userData.accountType || bankData.userData.accountType === AccountType.PERSONAL) {
if (bankData.userData.isPersonalAccount) {
const { data, file } = await this.getRiskDataAndUploadPdf(
bankData.userData,
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { SpecialExternalAccountService } from 'src/subdomains/supporting/payment
import { FindOptionsRelations, FindOptionsWhere, IsNull, Like, Not } from 'typeorm';
import { AccountMerge, MergeReason } from '../account-merge/account-merge.entity';
import { AccountMergeService } from '../account-merge/account-merge.service';
import { AccountType } from '../user-data/account-type.enum';
import { KycType, UserDataStatus } from '../user-data/user-data.enum';
import { BankData, BankDataType, BankDataVerificationError } from './bank-data.entity';
import { UpdateBankDataDto } from './dto/update-bank-data.dto';
Expand Down Expand Up @@ -70,17 +69,14 @@ export class BankDataService {

async verifyBankData(entity: BankData): Promise<void> {
try {
if (
!entity.userData.verifiedName &&
(entity.userData.accountType === AccountType.PERSONAL || entity.type === BankDataType.BANK_IN)
)
if (!entity.userData.verifiedName && (entity.userData.isPersonalAccount || entity.type === BankDataType.BANK_IN))
await this.userDataRepo.update(...entity.userData.setVerifiedName(entity.name));

if (entity.type === BankDataType.USER) return;

if ([BankDataType.IDENT, BankDataType.NAME_CHECK].includes(entity.type)) {
if (
entity.userData.accountType === AccountType.PERSONAL ||
entity.userData.isPersonalAccount ||
entity.userData.hasCompletedStep(KycStepName.LEGAL_ENTITY) ||
entity.userData.hasCompletedStep(KycStepName.SOLE_PROPRIETORSHIP_CONFIRMATION)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,10 @@ export class UserData extends IEntity {

// --- KYC PROCESS --- //

get isPersonalAccount(): boolean {
return !this.accountType || this.accountType === AccountType.PERSONAL;
}

get hasSuspiciousMail(): boolean {
return (this.mail?.split('@')[0].match(/\d/g) ?? []).length > 2;
}
Expand Down Expand Up @@ -741,7 +745,7 @@ export class UserData extends IEntity {

get requiredKycFields(): string[] {
return ['accountType', 'mail', 'phone', 'firstname', 'surname', 'street', 'location', 'zip', 'country'].concat(
!this.accountType || this.accountType === AccountType.PERSONAL
this.isPersonalAccount
? []
: ['organizationName', 'organizationStreet', 'organizationLocation', 'organizationZip', 'organizationCountry'],
);
Expand All @@ -752,9 +756,7 @@ export class UserData extends IEntity {
}

get requiredInvoiceFields(): string[] {
return ['accountType'].concat(
!this.accountType || this.accountType === AccountType.PERSONAL ? ['firstname', 'surname'] : ['organizationName'],
);
return ['accountType'].concat(this.isPersonalAccount ? ['firstname', 'surname'] : ['organizationName']);
}

get isInvoiceDataComplete(): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from 'class-validator';
import * as IbanTools from 'ibantools';
import { Config } from 'src/config/config';
import { Util } from 'src/shared/utils/util';
import { SpecialExternalAccountType } from '../../payment/entities/special-external-account.entity';
import { SpecialExternalAccountService } from '../../payment/services/special-external-account.service';
import { Bank } from '../bank/bank.entity';
Expand All @@ -30,18 +31,31 @@ export class IsDfxIbanValidator implements ValidatorConstraintInterface {
) {}

private blockedIbans: string[] = [];
private blockedBLZs: string[] = [];
private blockedBICs: string[] = [];
private dfxBanks: Bank[] = [];
private currentBIC: string = undefined;

async validate(_: string, args: ValidationArguments) {
// blacklist types
const type = args.constraints[0];
const types = [SpecialExternalAccountType.BANNED_IBAN, SpecialExternalAccountType.BANNED_BIC];
const types = [
SpecialExternalAccountType.BANNED_IBAN,
SpecialExternalAccountType.BANNED_BLZ,
SpecialExternalAccountType.BANNED_BIC,
];
if ([IbanType.BUY, IbanType.BOTH].includes(type))
types.push(SpecialExternalAccountType.BANNED_IBAN_BUY, SpecialExternalAccountType.BANNED_BIC_BUY);
types.push(
SpecialExternalAccountType.BANNED_IBAN_BUY,
SpecialExternalAccountType.BANNED_BLZ_BUY,
SpecialExternalAccountType.BANNED_BIC_BUY,
);
if ([IbanType.SELL, IbanType.BOTH].includes(type))
types.push(SpecialExternalAccountType.BANNED_IBAN_SELL, SpecialExternalAccountType.BANNED_BIC_SELL);
types.push(
SpecialExternalAccountType.BANNED_IBAN_SELL,
SpecialExternalAccountType.BANNED_BLZ_SELL,
SpecialExternalAccountType.BANNED_BIC_SELL,
);

const blacklists = await this.specialExternalAccountService.getBlacklist(types);

Expand All @@ -56,6 +70,15 @@ export class IsDfxIbanValidator implements ValidatorConstraintInterface {
].includes(b.type),
)
.map((b) => b.value);
this.blockedBLZs = blacklists
.filter((b) =>
[
SpecialExternalAccountType.BANNED_BLZ,
SpecialExternalAccountType.BANNED_BLZ_BUY,
SpecialExternalAccountType.BANNED_BLZ_SELL,
].includes(b.type),
)
.map((b) => b.value);
this.blockedBICs = blacklists
.filter((b) =>
[
Expand Down Expand Up @@ -86,6 +109,8 @@ export class IsDfxIbanValidator implements ValidatorConstraintInterface {
const isBlocked = this.blockedIbans.some((i) => new RegExp(i.toLowerCase()).test(iban.toLowerCase()));
if (isBlocked) return `${args.property} not allowed`;

if (this.blockedBLZs.some((i) => new RegExp(i).test(Util.getBLZ(iban)))) return `${args.property} not allowed`;

if (this.blockedBICs.some((b) => new RegExp(b.toLowerCase()).test(this.currentBIC?.toLowerCase())))
return `${args.property} BIC not allowed`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ export enum SpecialExternalAccountType {
BANNED_BIC_BUY = 'BannedBicBuy',
BANNED_BIC_SELL = 'BannedBicSell',
BANNED_BIC_AML = 'BannedBicAml',
BANNED_BLZ = 'BannedBlz',
BANNED_BLZ_BUY = 'BannedBlzBuy',
BANNED_BLZ_SELL = 'BannedBlzSell',
BANNED_BLZ_AML = 'BannedBlzAml',
BANNED_MAIL = 'BannedMail',
BANNED_ACCOUNT_IBAN = 'BannedAccountIban',
AML_PHONE_CALL_NEEDED_BIC_BUY = 'AmlPhoneCallNeededBicBuy',
AML_PHONE_CALL_NEEDED_BLZ_BUY = 'AmlPhoneCallNeededBlzBuy',
AML_PHONE_CALL_NEEDED_IBAN_BUY = 'AmlPhoneCallNeededIbanBuy',
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class SpecialExternalAccountService {
type: In([
SpecialExternalAccountType.AML_PHONE_CALL_NEEDED_BIC_BUY,
SpecialExternalAccountType.AML_PHONE_CALL_NEEDED_IBAN_BUY,
SpecialExternalAccountType.AML_PHONE_CALL_NEEDED_BLZ_BUY,
]),
});
}
Expand All @@ -67,6 +68,10 @@ export class SpecialExternalAccountService {
SpecialExternalAccountType.BANNED_BIC_AML,
SpecialExternalAccountType.BANNED_MAIL,
SpecialExternalAccountType.BANNED_ACCOUNT_IBAN,
SpecialExternalAccountType.BANNED_BLZ,
SpecialExternalAccountType.BANNED_BLZ_BUY,
SpecialExternalAccountType.BANNED_BLZ_SELL,
SpecialExternalAccountType.BANNED_BLZ_AML,
],
),
});
Expand Down
Loading