caelum0x 9a1cb7fa15 feat(qie): anchor QIE settlement receipts to Casper
Mirrors the Algorand route's existing anchoring pattern exactly
(api/algorand_receipt_anchor.ts): a settled QIE credit-score payment now
becomes the same Casper-rooted Universal Receipt Envelope used by every
other satellite chain, via a new api/qie_receipt_anchor.ts anchored
provisional (finalize: false) until reconcileQiePayment's own-RPC finality
check confirms it, then finalized or challenged exactly like Algorand's.

- api/qie_receipt_anchor.ts: anchorQieCreditScoreSettlement (idempotent on
  tx hash, refuses conflicting replays), finalizeQieExternalReceipt,
  challengeQieExternalReceipt, qieX402Usage.
- api/state.ts: wires the above through a qieAnchorContext(), reusing the
  existing chain-agnostic externalReceiptProof(receiptId) lookup.
- api/qie_x402_routes.ts: credit-score responses now carry
  external_receipt_id / external_receipt_url / casper_anchor_status;
  reconcileQiePayment finalizes/challenges the receipt alongside recording
  finality; the receipt proof is served by the existing chain-agnostic
  GET /v1/x402/external-receipts/:id route (unchanged, already shared).
- lib/x402/qie_payment_attempt_store.ts: StoredQieSettlement gained
  externalReceiptId, mirroring StoredAlgorandSettlement.

6 new tests (test/qie_receipt_anchor.test.ts) exercise the anchor function
directly against a real Ledger: idempotent replay, conflicting-replay
rejection, finalize/challenge transitions, and usage aggregation. Full
suite stays green: 408/408 tests, typecheck clean.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-19 12:53:48 +03:00
..
2026-06-16 02:50:52 +03:00
2026-06-16 02:50:52 +03:00
2026-06-16 02:50:52 +03:00
2026-06-16 02:50:52 +03:00