From ed11f5520e3f99a622eabf88a80ae6066fd6a017 Mon Sep 17 00:00:00 2001 From: vstudio79 Date: Thu, 28 May 2026 19:32:52 +0100 Subject: [PATCH] Add checkKycStatus function - Create KycStatusResponse interface with pending|approved|rejected status - Implement checkKycStatus(accountId) with SEP-12 customer lookup - Add linkAccount() to associate Stellar accounts with customer records - Handle missing KYC data gracefully with descriptive message --- packages/anchor-service/src/anchor.service.ts | 61 +++++++++++++++++++ packages/anchor-service/src/index.ts | 1 + .../src/interfaces/kyc.interface.ts | 7 +++ 3 files changed, 69 insertions(+) create mode 100644 packages/anchor-service/src/interfaces/kyc.interface.ts diff --git a/packages/anchor-service/src/anchor.service.ts b/packages/anchor-service/src/anchor.service.ts index 6e9de31..16cb2cb 100644 --- a/packages/anchor-service/src/anchor.service.ts +++ b/packages/anchor-service/src/anchor.service.ts @@ -14,6 +14,7 @@ import type { CustomerStatus, IdentityDocument, } from './interfaces/customer.interface'; +import type { KycStatusResponse } from './interfaces/kyc.interface'; interface CustomerRecord { customerId: string; @@ -43,6 +44,7 @@ export class AnchorService { private readonly payments = new Map(); private readonly transactions = new Map(); private readonly customers = new Map(); + private readonly accountLinks = new Map(); // --------------------------------------------------------------------------- // SEP-31 Direct Payment @@ -303,6 +305,65 @@ export class AnchorService { return Array.from(this.customers.values()); } + // --------------------------------------------------------------------------- + // SEP-12 KYC Status + // --------------------------------------------------------------------------- + + linkAccount(accountId: string, customerId: string): void { + this.accountLinks.set(accountId, customerId); + } + + async checkKycStatus(accountId: string): Promise { + const customerId = this.accountLinks.get(accountId); + + if (!customerId) { + return { + accountId, + status: 'pending', + message: 'No KYC data found for this account. Please submit customer info first.', + checkedAt: new Date().toISOString(), + }; + } + + const customer = this.customers.get(customerId); + + if (!customer) { + this.accountLinks.delete(accountId); + return { + accountId, + status: 'pending', + message: 'Customer record not found. Please resubmit customer info.', + checkedAt: new Date().toISOString(), + }; + } + + let status: KycStatusResponse['status']; + switch (customer.status) { + case 'APPROVED': + status = 'approved'; + break; + case 'REJECTED': + status = 'rejected'; + break; + default: + status = 'pending'; + break; + } + + return { + accountId, + status, + customerId: customer.customerId, + message: + status === 'approved' + ? 'KYC approved' + : status === 'rejected' + ? 'KYC rejected' + : 'KYC is still being processed', + checkedAt: new Date().toISOString(), + }; + } + private validateRequiredFields(data: CustomerData, isUpdate: boolean): string[] { const missing: string[] = []; diff --git a/packages/anchor-service/src/index.ts b/packages/anchor-service/src/index.ts index 7f700c4..a25be4f 100644 --- a/packages/anchor-service/src/index.ts +++ b/packages/anchor-service/src/index.ts @@ -17,3 +17,4 @@ export type { IdentityDocument, FileContent, } from './interfaces/customer.interface'; +export type { KycStatusResponse } from './interfaces/kyc.interface'; diff --git a/packages/anchor-service/src/interfaces/kyc.interface.ts b/packages/anchor-service/src/interfaces/kyc.interface.ts new file mode 100644 index 0000000..51e3785 --- /dev/null +++ b/packages/anchor-service/src/interfaces/kyc.interface.ts @@ -0,0 +1,7 @@ +export interface KycStatusResponse { + accountId: string; + status: 'pending' | 'approved' | 'rejected'; + customerId?: string; + message?: string; + checkedAt: string; +}