Skip to content

feat: implement payment vault, account recovery, and multi-currency s… - #236

Merged
ScriptedBro merged 3 commits into
DelegoLabs:mainfrom
Hydrax117:feat/issues-112-109-110-payment-vault-recovery-multicurrency
Aug 31, 2026
Merged

feat: implement payment vault, account recovery, and multi-currency s…#236
ScriptedBro merged 3 commits into
DelegoLabs:mainfrom
Hydrax117:feat/issues-112-109-110-payment-vault-recovery-multicurrency

Conversation

@Hydrax117

Copy link
Copy Markdown
Contributor

feat: Payment Vault, Account Recovery & Multi-Currency Support

Issues

closes #112 — Multi-currency support for payments with automatic conversion and settlement
closes #109 — Account recovery mechanisms for wallet users
closes #110 — Secure payment method vault with tokenization
closes #111

Summary

This PR implements three major features across the gateway service and shared types package:

  1. Payment Method Vault ([Payments] Add multi-currency support with FX conversion #110) — PCI DSS SAQ A-EP compliant tokenization for card, bank account, wallet, and Stellar account payment methods.
  2. Account Recovery ([Wallet] Implement account recovery with social guardians #109) — Social recovery with guardians, time-delayed approval, emergency contacts, and hardware wallet support.
  3. Multi-Currency Payments ([Payments] Build payment method vault with tokenization #112) — Stellar path payments across 10+ assets, real-time FX rate oracle integration, exposure tracking, and daily settlement.

Changes

packages/types/src/

File Description
payment.ts (new) PaymentMethod, TokenizationRequest/Response, VerificationResult, ThreeDSecureRequest/Result, NetworkTokenizationRequest/Response, AuditLogEntry, PCIComplianceSnapshot
recovery.ts (new) RecoveryConfig, RecoveryRequest, RecoveryAudit, GuardianVerificationChallenge, all request/response types
multi-currency.ts (new) SupportedCurrency, FXRate, MultiCurrencyPayment, CurrencyExposure, CurrencySettlement, path/route types
index.ts (modified) Re-exports all three new type modules

apps/backend/gateway/src/models/

File Description
PaymentMethod.ts (new) Sequelize model — vault tokens, network tokens, 3DS fields, expiry
PaymentAuditLog.ts (new) Immutable audit log for all vault operations
RecoveryConfig.ts (new) Per-account guardian list, threshold, delay settings
RecoveryRequest.ts (new) Recovery attempts with guardian approval arrays
RecoveryAuditLog.ts (new) Immutable audit log for recovery actions
RecoveryChallenge.ts (new) Verification challenges with attempt tracking
SupportedCurrency.ts (new) Currency registry with FX provider and compliance flags
FXRate.ts (new) FX rate cache with bid/ask/mid and TTL
MultiCurrencyPayment.ts (new) Path payment record with conversion route
CurrencyExposure.ts (new) Per-currency VaR and hedge status
CurrencySettlement.ts (new) Daily netting and settlement tracking

apps/backend/gateway/src/payment/

File Description
validator.ts (new) Luhn algorithm, card/bank/wallet validation, fingerprint generation
service.ts (new) tokenizeCard, tokenizeBankAccount, tokenizeWallet, verifyPaymentMethod, listPaymentMethods, updatePaymentMethod, removePaymentMethod
routes.ts (new) Route handlers for all vault endpoints
middleware.ts (new) Ownership, active/verified/expiry checks

apps/backend/gateway/src/recovery/

File Description
service.ts (new) createRecoveryConfig, addGuardian, initiateRecovery, processGuardianApproval, rejectRecovery, completeRecovery, getRecoveryProgress, isRecoverable
routes.ts (new) Route handlers for all recovery endpoints

apps/backend/gateway/src/multi-currency/

File Description
fxService.ts (new) getFXRate, Dijkstra path-finding (findConversionPath), batch refresh
paymentService.ts (new) createMultiCurrencyPayment, executePathPayment, completeMultiCurrencyPayment, exposure/settlement updates
routes.ts (new) Route handlers for FX, payments, exposure

apps/backend/gateway/routes/

File Description
payment.ts (new) Registers 10 vault routes under /api/v1/payment-methods
recovery.ts (new) Registers 16 recovery routes under /api/v1/recovery
multi-currency.ts (new) Registers 12 multi-currency routes under /api/v1/fx and /api/v1/payments/multi-currency
index.ts (modified) Spreads all three new route groups into the master route list

apps/backend/gateway/src/errors.ts (modified)

Added success() and validationError() helpers to the shared error envelope, used by the new route handlers.


database/migrations/

File Description
021_payment_method_vault.sql (new) payment_methods, payment_audit_logs — unique indexes on token/fingerprint
021_payment_method_vault.down.sql (new) Rollback for migration 021
022_account_recovery.sql (new) recovery_configs, recovery_requests, recovery_audit_logs, recovery_challenges
022_account_recovery.down.sql (new) Rollback for migration 022
023_multi_currency.sql (new) supported_currencies, fx_rates, multi_currency_payments, currency_exposures, currency_settlements
023_multi_currency.down.sql (new) Rollback for migration 023
README.md (modified) Added migrations 021–023 to the tracking table

API Endpoints Added

Payment Vault (#110)

POST   /api/v1/payment-methods/card
POST   /api/v1/payment-methods/bank-account
POST   /api/v1/payment-methods/wallet
GET    /api/v1/payment-methods
GET    /api/v1/payment-methods/:paymentMethodId
POST   /api/v1/payment-methods/:paymentMethodId/verify
PATCH  /api/v1/payment-methods/:paymentMethodId
DELETE /api/v1/payment-methods/:paymentMethodId
POST   /api/v1/payment-methods/:paymentMethodId/used
GET    /api/v1/payment-methods/:paymentMethodId/usable

Account Recovery (#109)

GET    /api/v1/recovery/config
POST   /api/v1/recovery/config
PATCH  /api/v1/recovery/config
POST   /api/v1/recovery/guardians
DELETE /api/v1/recovery/guardians/:guardianId
PATCH  /api/v1/recovery/guardians/:guardianId/verify
POST   /api/v1/recovery/emergency-contacts
DELETE /api/v1/recovery/emergency-contacts/:contactId
POST   /api/v1/recovery/:accountId/initiate
POST   /api/v1/recovery/:recoveryId/approve
POST   /api/v1/recovery/:recoveryId/reject
POST   /api/v1/recovery/:recoveryId/cancel
POST   /api/v1/recovery/:recoveryId/complete
GET    /api/v1/recovery/:accountId/requests
GET    /api/v1/recovery/:accountId/progress
GET    /api/v1/recovery/:accountId/verifiable

Multi-Currency (#112)

GET    /api/v1/fx/rate
GET    /api/v1/fx/path
POST   /api/v1/fx/refresh
POST   /api/v1/payments/multi-currency
POST   /api/v1/payments/multi-currency/:paymentId/execute
POST   /api/v1/payments/multi-currency/:paymentId/complete
POST   /api/v1/payments/multi-currency/:paymentId/fail
GET    /api/v1/payments/multi-currency/:paymentId
GET    /api/v1/payments/multi-currency
GET    /api/v1/payments/multi-currency/route
GET    /api/v1/exposure/:accountId

Acceptance Criteria

#110 Payment Vault

  • Tokens replace raw PANs
  • PCI SAQ A-EP compliant — no plaintext card data stored
  • Network tokens for Visa / Mastercard / Amex / Discover
  • 3DS verification supported
  • Lifecycle managed via API (active → expired → removed)
  • Audit log immutable with actor/IP/timestamp

#109 Account Recovery

  • Social recovery with 3-of-5 guardians (configurable weight + threshold)
  • Time delay configurable (default 7 days)
  • Emergency contacts notified on initiation
  • Hardware wallet recovery supported
  • Full audit trail — initiated / approved / rejected / completed / cancelled
  • Recovery completes < 30 min after delay expires

#112 Multi-Currency

  • 10+ currencies supported via supported_currencies registry
  • Path payments auto-route via Dijkstra's algorithm
  • FX rates cache TTL 60 s — update < 1 min
  • Settlement in any supported currency
  • Risk metrics (VaR 95/99, hedge ratio, margin) calculated on every exposure update
  • Compliance flags per currency (KYC, AML, SANCTIONS, REPORTING)

Database Migrations

# Apply
pnpm db:migrate

# Verify
pnpm db:migrate:status

# Rollback (if needed)
pnpm db:migrate -- --direction down --target 20 --force

Testing

pnpm test --filter @delegolabs/gateway
pnpm typecheck --filter @delegolabs/gateway
pnpm typecheck --filter @delegolabs/types

Notes for Reviewers

  • pnpm-lock.yaml was updated during pnpm install after node_modules were missing — no new runtime dependencies were added.
  • FX rate provider URLs in fxService.ts are placeholder constants; the real oracle endpoints should be injected via environment variables before production deployment.
  • The Stellar path-payment execution (executePathPayment) wires up the status transition and transaction hash; the actual StellarSdk.PathPaymentStrictSend call should be integrated with the existing wallet service in a follow-up.

@drips-wave

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

@Hydrax117 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a002b974-0e81-49ab-8014-6c227a1fd66a


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ScriptedBro

Copy link
Copy Markdown
Contributor

Please fix conflicts

@Hydrax117

Copy link
Copy Markdown
Contributor Author

resolved

@ScriptedBro
ScriptedBro merged commit e500c31 into DelegoLabs:main Aug 31, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants