Skip to content

feat(receipts): add standalone purchase receipt verifier (closes #238) - #250

Open
Ranjeet2063 wants to merge 1 commit into
Prompt-Hash-Stellar:mainfrom
Ranjeet2063:feat/issue-238-standalone-receipt-verifier
Open

feat(receipts): add standalone purchase receipt verifier (closes #238)#250
Ranjeet2063 wants to merge 1 commit into
Prompt-Hash-Stellar:mainfrom
Ranjeet2063:feat/issue-238-standalone-receipt-verifier

Conversation

@Ranjeet2063

Copy link
Copy Markdown

Summary

Closes #238

Implements a standalone purchase receipt verifier that works entirely without any hosted PromptHash application dependency. All verification checks run against the public Stellar Horizon API or use fully offline, deterministic SHA-256 fingerprint logic.

Changes

src/lib/receipts/receiptVerifier.ts (new)

  • verifyReceipt(receipt, network) — full on-chain verification via Stellar Horizon
    • Field presence validation (promptId, buyer, txHash, contractId, contentHash, purchasedAt, amountStroops)
    • contentHash format check (must be 64-character lowercase hex / SHA-256)
    • Fetches the Stellar transaction from Horizon; surfaces tx_not_found, tx_failed, and network error states
    • Source account vs receipt buyer equality check → buyer_mismatch status
    • Returns valid with deterministic fingerprint in details
  • verifyReceiptFromExport(exported, network) — accepts plain-JSON or base64-encoded export strings; surfaces corrupted/tampered exports gracefully
  • checkReceiptIntegrity(receipt, knownFingerprint) — fully offline tamper detection via SHA-256 over all canonical receipt fields; no network call needed

src/lib/receipts/receiptVerifier.test.ts (new)

14 test cases covering:

  • Valid receipt → valid status + correct explorerUrl + fingerprint
  • Mainnet vs testnet explorerUrl format
  • Buyer mismatch → buyer_mismatch
  • Malformed / shortened contentHash → tampered
  • Missing required fields → tampered
  • Horizon 404 → tx_not_found
  • Unsuccessful transaction → tx_failed
  • Network unreachable → error
  • Plain-JSON export parsing → valid
  • Base64-encoded export parsing → valid
  • Corrupted export → tampered
  • Fingerprint intact check (matching)
  • Fingerprint tamper detection (amountStroops mutation)
  • Fingerprint is 64-char hex

docs/integration-guide.md (updated)

New Standalone Purchase Receipt Verification section with:

  • Receipt fields reference table
  • Code examples (verify object / export string / offline fingerprint)
  • Verification status codes table
  • Tamper detection example
  • CLI usage example (Node.js, no hosted app required)

Acceptance Criteria

  • Receipt verification works from exported receipt data
  • Tampered receipt fields fail verification
  • Docs explain verification steps

…pt-Hash-Stellar#238)

- Add src/lib/receipts/receiptVerifier.ts with verifyReceipt(),
  verifyReceiptFromExport(), and checkReceiptIntegrity() utilities
- Works entirely from exported receipt data + Stellar Horizon public API;
  no hosted PromptHash app dependency required
- verifyReceipt() checks: field presence, contentHash format (64-char hex),
  Horizon tx existence, tx success status, and buyer/source-account match
- verifyReceiptFromExport() accepts plain-JSON or base64-encoded exports
- checkReceiptIntegrity() provides offline tamper detection via SHA-256
  fingerprint over all canonical receipt fields
- Add comprehensive test suite (receiptVerifier.test.ts): 14 cases covering
  valid receipts, tampered fields, tx_not_found, tx_failed, buyer_mismatch,
  network errors, export parsing, and offline fingerprint checks
- Update docs/integration-guide.md with Standalone Receipt Verification
  section: receipt fields table, status codes, CLI usage, offline mode
Copilot AI lite review requested due to automatic review settings September 8, 2026 01:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

Prompt purchase receipt verifier should run without hosted app dependencies

2 participants