DEV Community

Darlan Jr
Darlan Jr

Posted on

Basic KYC Implementation Guide using KYC_CHECK

๐Ÿ” KYC Implementation Guide

๐Ÿ“ Introduction

KYC (Know Your Customer) is an essential process for verifying user identity and preventing fraud. In this article, we'll explore how to implement a basic KYC system using the KYC_CHECK library.

๐ŸŽฏ Main Validations

The system implements two main validations:

  1. First Validation ๐Ÿ‘ค: Verifies if the person is the actual owner of the presented document
  2. Withdrawal Validation ๐Ÿ’ฐ: Verifies if it's the user attempting to make a significant withdrawal

๐Ÿš€ Implementation for New Users

For new users, we perform the first validation:

  • Process ๐Ÿ”„: Comparison between the document sent and the First Selfie

๐Ÿ”„ Subsequent Validations

For future validations, we keep the user's most recent photo updated:

  • Process ๐Ÿ“ธ: Comparison between Last Selfie and New Selfie
  • Monthly Validation ๐Ÿ“…: If the user hasn't added a new photo within 1 month, a new validation will be required

๐Ÿ’ป Implementation Example

Let's consider a scenario where a user wants to make a withdrawal greater than 70% of their balance and more than $100.

Note โ„น๏ธ: The $100 threshold is implemented to avoid unnecessary validations for small amounts. For example, it wouldn't make sense to request a new selfie to validate a $7 withdrawal from a $10 balance.

interface ValidationResult {
  isValid: boolean;
  message?: string;
}

function validateWithdrawal(amount: number, userBalance: number) {
    const percentageThreshold = 0.7; // 70%
    const amountThreshold = 10000; // $100

    if (userBalance > amountThreshold &&  amount > userBalance * amountThreshold ) {
        return performNewValidation();
    }
    return true;
}
Enter fullscreen mode Exit fullscreen mode

๐Ÿค– Face Similarity Calculation

The face similarity is calculated using the Euclidean distance between facial descriptors. Here's how it works:

๐Ÿ“Š Example Response:

{
  "threshold": 0.49,
  "rawDistance": 0.5034011876789618,
  "faceDetection1": {
    "score": 0.9882098436355591,
    "box": {
      "x": 95.0972925721421,
      "y": 76.55234995484352,
      "width": 124.7091704960397,
      "height": 140.45916613936424
    }
  },
  "faceDetection2": {
    "score": 0.9953930974006653,
    "box": {
      "x": 41.640078008340005,
      "y": 106.15492933988571,
      "width": 264.0857750636389,
      "height": 309.0272338986397
    }
  },
  "processingTimeMs": 291,
  "usingMockImplementation": false
}
Enter fullscreen mode Exit fullscreen mode

๐Ÿงฎ Understanding the Calculation:

Euclidean Distance (rawDistance) ๐Ÿ“: 0.5034011876789618

  • This is the mathematical measure of the difference between facial descriptors
  • Values close to 0 indicate identical faces
  • Values close to 1 or higher indicate completely different faces

Similarity Calculation ๐Ÿ”ข:

   similarity = 1 - euclideanDistance
Enter fullscreen mode Exit fullscreen mode
  • In this case: 1 - 0.5034 โ‰ˆ 0.4966 (approximately 50%)

Percentage Conversion ๐Ÿ“Š:

   percentage = similarity * 100
Enter fullscreen mode Exit fullscreen mode
  • In this case: 0.4966 * 100 โ‰ˆ 50%

Match Evaluation โœ…:

  • The threshold is set to 0.49 (49%)
  • Since the similarity (50%) is greater than the threshold (49%), the faces are considered a match

The facial descriptors are 128-dimensional vectors that represent facial characteristics. The Euclidean distance measures the difference between these vectors in multidimensional space.

A value of 50% represents a borderline match - not a very strong match, but it's above the configured minimum threshold.

๐ŸŽฏ Final Considerations

  • Percentage and amount thresholds should be adjusted according to specific business rules
  • It's important to maintain a history of performed validations
  • Consider implementing a notification system for users during the validation process

Top comments (0)