feat: implement x402 payment evidence pipeline#14
Conversation
|
@Favourof is attempting to deploy a commit to the emrekayat's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@Favourof 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! 🚀 |
|
Thanks for the contribution. I reviewed this against issue #3 and did not merge it yet because the settlement correlation is not reliable: the x402 onAfterSettle hook tries to read x-payment-attempt-id / x-payment-trace-id from transport response headers before the protected route creates and sets those IDs, so authoritative settlement updates can remain unlinked and payment evidence stays at verified. There is also a demo-mode edge case where a payment-response header alone can pass the demo middleware but be persisted as verified rather than demo-paid. Please rework the evidence pipeline so the verified attempt is created/correlated before settlement and forged/demo headers cannot create trusted evidence. |
|
@emrekayat okay |
|
@emrekayat, I've just pushed a fix that completely addresses both issues. |
|
Thanks for the update. I cannot merge this yet because the required verification is still failing. Current blockers:
|
|
@emrekayat fixed |
|
Thanks for the update. The latest commit now passes local verification on my side:
I still cannot merge this yet because issue #3 is not fully satisfied. The settlement hook updates only the payment attempt ( There is also no failed settlement persistence yet: Please wire settlement/failure updates through to persisted usage analytics as well, and add tests that exercise the actual x402 lifecycle behavior rather than manually calling both persistence update helpers. Once those paths are covered, I can re-review for merge. |
|
Okay |
|
@emrekayat |
|
Re-reviewed this after the latest update. I still cannot merge it yet. Current blockers:
Local verification on the PR branch:
Please rebase on |
|
@emrekayat check again |
|
Thanks for the work here. I reviewed this against #3 again, but I cannot merge this PR in its current shape. The issue has now been resolved on A few blockers I saw in this PR:
Since #3 is covered by #18, please rebase/retarget only if you want to propose a smaller follow-up on top of the new evidence pipeline. |
Description
Closes #3
This PR implements a robust two-phase payment evidence pipeline. Instead of blindly trusting raw HTTP headers to mark requests as settled, the system now enforces an authoritative settlement confirmation step through
@x402/coreResource Server lifecycle hooks.What's Changed
transactionHashandpaymentResponseHeaderwith a structuredPaymentEvidencemodel in@query402/sharedthat tracks exact payment states:demo-paid,verified,settled, andfailed.updatePaymentAttemptEvidenceandupdateUsageEventEvidence) in the persistence layer.verified(ordemo-paid) rather than settled.onAfterSettlehooks inx402.ts. The backend now waits for authoritative facilitator confirmation and updates the database state tosettledusing the specific transport context identifiers.node:testsuite for thex402.tssettlement pipeline to ensure correctness across state transitions.Verification
npm run testinapps/api)npm run typecheckacross the entire monorepodemo-paid, valid payments flag assettledupon hook execution)