1.0.10 • Published 8 months ago

indian-identity-auth v1.0.10

Weekly downloads
-
License
-
Repository
-
Last release
8 months ago

Indian Identity Auth

npm version downloads license

A simple yet powerful package for validating Indian identity documents (PAN Card & Aadhaar) with face matching capabilities. Perfect for KYC implementations and identity verification systems.

Features

  • 🔍 PAN Card verification
  • 📋 Aadhaar Card verification
  • 👤 Face matching across documents
  • 🤳 Selfie verification with custom number validation
  • 🖼️ Automatic image preprocessing for better accuracy
  • ⚡ Works in browser and Node.js environments

Installation

npm install indian-identity-auth

Quick Start

import { verifyPAN, verifyAadhaar, verifyIdentity } from 'indian-identity-auth';

// 1. Simple PAN Card Verification
const verifyPANCard = async (panImageFile) => {
  const result = await verifyPAN(panImageFile);
  console.log(result);
  // Output: { 
  //   isValid: true, 
  //   confidence: 0.95,
  //   details: { 
  //     number: 'ABCDE1234F'
  //   }
  // }
};

// 2. Simple Aadhaar Verification
const verifyAadhaarCard = async (aadhaarImageFile) => {
  const result = await verifyAadhaar(aadhaarImageFile);
  console.log(result);
  // Output: {
  //   isValid: true,
  //   confidence: 0.92,
  //   details: {
  //     number: '1234 5678 9012'
  //   }
  // }
};

// 3. Complete Identity Verification
const verifyCompleteIdentity = async () => {
  // Generate a random number for verification
  const verificationNumber = Math.floor(Math.random() * 900000) + 100000;
  
  const result = await verifyIdentity(
    panImageFile,      // PAN Card image
    aadhaarImageFile,  // Aadhaar Card image
    selfieImageFile,   // Selfie with verification number
    verificationNumber.toString()
  );
  
  console.log(result);
  // Output: {
  //   pan: { isValid: true, confidence: 0.95, details: { number: 'ABCDE1234F' } },
  //   aadhaar: { isValid: true, confidence: 0.92, details: { number: '1234 5678 9012' } },
  //   faceMatch: { 
  //     isMatch: true, 
  //     confidence: 0.88,
  //     details: {
  //       numberDetected: '123456',
  //       expectedNumber: '123456'
  //     }
  //   },
  //   overallResult: true
  // }
};

React Example

Here's a simple React component using the package:

import { useState } from 'react';
import { verifyIdentity } from 'indian-identity-auth';

export default function IdentityVerification() {
  const [panFile, setPanFile] = useState(null);
  const [aadhaarFile, setAadhaarFile] = useState(null);
  const [selfieFile, setSelfieFile] = useState(null);
  const [result, setResult] = useState(null);
  const [loading, setLoading] = useState(false);
  
  const verificationNumber = '123456'; // Generate this randomly
  
  const handleVerification = async () => {
    try {
      setLoading(true);
      const result = await verifyIdentity(
        panFile,
        aadhaarFile,
        selfieFile,
        verificationNumber
      );
      setResult(result);
    } catch (error) {
      console.error(error);
    } finally {
      setLoading(false);
    }
  };
  
  return (
    <div>
      <input 
        type="file" 
        onChange={(e) => setPanFile(e.target.files[0])} 
      />
      <input 
        type="file" 
        onChange={(e) => setAadhaarFile(e.target.files[0])} 
      />
      <input 
        type="file" 
        onChange={(e) => setSelfieFile(e.target.files[0])} 
      />
      <button 
        onClick={handleVerification}
        disabled={loading}
      >
        {loading ? 'Verifying...' : 'Verify Identity'}
      </button>
      
      {result && (
        <div>
          <div>PAN Valid: {result.pan.isValid ? 'Yes' : 'No'}</div>
          <div>Aadhaar Valid: {result.aadhaar.isValid ? 'Yes' : 'No'}</div>
          <div>Face Match: {result.faceMatch.isMatch ? 'Yes' : 'No'}</div>
          <div>Overall: {result.overallResult ? 'Verified' : 'Not Verified'}</div>
        </div>
      )}
    </div>
  );
}

Next.js API Route Example

// pages/api/verify.ts
import type { NextApiRequest, NextApiResponse } from 'next';
import { verifyIdentity } from 'indian-identity-auth';

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
  if (req.method !== 'POST') {
    return res.status(405).json({ error: 'Method not allowed' });
  }

  try {
    const { panImage, aadhaarImage, selfieImage, verificationNumber } = req.body;
    
    const result = await verifyIdentity(
      panImage,
      aadhaarImage,
      selfieImage,
      verificationNumber
    );
    
    res.status(200).json(result);
  } catch (error) {
    res.status(500).json({ error: 'Verification failed' });
  }
}

API Reference

verifyPAN(image: Buffer | File): Promise

Verifies a PAN card image and extracts the PAN number.

verifyAadhaar(image: Buffer | File): Promise

Verifies an Aadhaar card image and extracts the Aadhaar number.

verifyIdentity(pan: Buffer | File, aadhaar: Buffer | File, selfie: Buffer | File, number: string): Promise

Performs complete identity verification including document validation and face matching.

Types

interface VerificationResult {
  isValid: boolean;
  confidence: number;
  details: {
    number?: string;
    error?: string;
  };
}

interface IdentityResult {
  pan: VerificationResult;
  aadhaar: VerificationResult;
  faceMatch: {
    isMatch: boolean;
    confidence: number;
    details: {
      numberDetected?: string;
      expectedNumber: string;
      error?: string;
    };
  };
  overallResult: boolean;
}

Notes

  • Image preprocessing is handled automatically
  • Supports both Buffer and File inputs
  • Works with common image formats (JPG, PNG)
  • Face matching requires clear, well-lit images
  • Verification number should be clearly visible in selfie

Security

This package processes all data locally in the browser or Node.js environment. No data is sent to external servers.

License

MIT

Support

Contributing

Contributions are welcome! Please read our contributing guidelines first.

1.0.10

8 months ago

1.0.9

8 months ago

1.0.8

8 months ago

1.0.7

8 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago