Skip to content

fix(receipts): verify locally stored payment receipts against Horizon… - #412

Merged
Emmy123222 merged 2 commits into
Emmy123222:mainfrom
Anadudev:fix/136-verify-receipts-horizon
Sep 3, 2026
Merged

fix(receipts): verify locally stored payment receipts against Horizon…#412
Emmy123222 merged 2 commits into
Emmy123222:mainfrom
Anadudev:fix/136-verify-receipts-horizon

Conversation

@Anadudev

@Anadudev Anadudev commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Closes #136

Overview

Previously, payment receipts stored in browser localStorage were trusted implicitly and displayed as confirmed in the Dashboard without verifying transaction existence, ledger confirmation, or on-chain settlement parameters against Stellar Horizon.

This PR introduces an on-chain Horizon verification engine that checks the network, transaction hash, asset, amount, and destination receiving address for each receipt. Receipts in the Dashboard are now displayed with distinct visual statuses (unverified, pending, confirmed, and mismatched), with granular discrepancy diagnostic banners and manual re-verification capabilities.


Key Changes

  1. Horizon Receipt Verification Engine (src/lib/receiptVerification.ts):

    • verifyReceiptAgainstHorizon(receipt, options): Queries the Stellar Horizon ledger endpoint for the given transaction hash and operations.
    • Validates that:
      • The transaction exists and has successful: true on the ledger.
      • Payment operations match the expected asset (USDC or XLM), amount (normalized float comparison), and destination receiving address.
      • Soroban contract invocations (invoke_host_function) for x402 payments are verified.
      • Network identifiers (stellar:mainnet vs stellar:testnet) match.
    • verifyReceiptsAgainstHorizon(receipts, options): Batch verification utility.
    • getHorizonUrlForNetwork(network): Network URL resolution.
  2. Distinct Verification States & Dashboard UI (src/pages/DashboardPage.tsx):

    • Added verification state tracking (verificationMap) and status badges for each receipt:
      • Confirmed: Neon-green glowing dot, green CONFIRMED #<ledger> badge with check icon.
      • Pending: Pulsing cyan dot, VERIFYING... badge with animated loader.
      • Mismatched: Red glowing dot, red MISMATCHED badge with alert icon, diagnostic banner displaying specific discrepancy details (e.g., amount, asset, or destination mismatch), and a Re-verify button.
      • Unverified: Subtle gray dot, UNVERIFIED badge with help icon, and a Re-verify button.
    • Added header summary counters showing confirmed, mismatched, and unverified receipt counts.
    • Added VERIFY ALL action button to trigger parallel on-chain re-verification.
    • Added DOWNLOAD BUNDLE action button to export cryptographic receipt bundles.
  3. Receipt Storage & Integrity Enrichment (src/hooks/useSearch.ts):

    • Enriched receipt persistence in stellarsearch_receipts localStorage to store asset, destination, amount, network, and status: 'unverified'.
  4. Online Bundle Verification (src/lib/receiptBundle.ts):

    • Added verifyBundleOnline(bundle, options) to perform both offline cryptographic SHA-256 proof checks and on-chain Horizon ledger verification for all included receipts.
  5. Type System Updates (src/types/index.ts):

    • Added ReceiptVerificationStatus ('unverified' | 'pending' | 'confirmed' | 'mismatched').
    • Added ReceiptVerificationDetail with ledger sequence, timestamp, and mismatch details.
    • Extended SearchReceipt and SearchResponse with asset, destination, and verification status.

Verification & Testing

  • Receipt Verification Unit Tests (src/lib/receiptVerification.test.ts):
    • 16 tests covering confirmed payments, Soroban contract invocations, 404 not found, failed transactions, amount mismatches, asset mismatches, destination mismatches, network mismatches, Horizon 500 errors, and batch lookups.
  • Dashboard UI Tests (src/pages/DashboardPage.test.tsx):
    • 4 tests covering empty audit log state, automatic verification on mount, distinct visual badges, manual re-verification, and bundle download.
  • Hook Tests (src/hooks/useSearch.test.ts):
    • Verified receipt persistence with complete metadata.
  • Receipt Bundle Tests (src/lib/receiptBundle.test.ts):
    • 24 tests covering offline proof validation and online Horizon verification.
  • Full Test Suite:
    • Ran npm test: all 37 test suites and 376 tests passed.
  • Typecheck & Build:
    • npx tsc --noEmit and npm run build passed with zero errors.

…Emmy123222#136)

- Add Horizon receipt verification engine validating network, txHash, asset, amount, and destination
- Distinguish unverified, pending, confirmed, and mismatched receipt states with distinct badges and diagnostics
- Enrich receipt persistence in useSearch with asset, destination, and verification metadata
- Add verifyBundleOnline for end-to-end ledger verification of receipt bundles
- Add comprehensive unit and integration tests across receipt verification and Dashboard audit log
@drips-wave

drips-wave Bot commented Sep 2, 2026

Copy link
Copy Markdown

@Anadudev 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

@vercel

vercel Bot commented Sep 2, 2026

Copy link
Copy Markdown

@Anadudev is attempting to deploy a commit to the Emmanuel's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Emmy123222
Emmy123222 merged commit fc70b39 into Emmy123222:main Sep 3, 2026
0 of 2 checks 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

Development

Successfully merging this pull request may close these issues.

Verify locally stored payment receipts against Horizon

2 participants