rfc: x402 protocol support for Hathor Network#109
Conversation
Add design specification for integrating the x402 payment protocol with Hathor using nano contract escrow. Covers architecture, blueprint design, facilitator plugin, client SDK, and server middleware. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Server can accept multiple tokens via multiple accepts entries - Renamed tokenUid to asset to match x402 spec - Added example showing HTR + custom token acceptance - Clarified token-agnostic nature of the escrow blueprint Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add two new RFC documents for the x402 implementation: - 0002-x402-client-sdk.md: Design for @hathor/x402-client npm package. A fetch() wrapper that transparently handles 402 -> escrow -> retry. Supports headless wallet and wallet-lib backends, multi-token selection, amount limits, and payment callbacks. - 0003-x402-server-middleware.md: Design for @hathor/x402-server npm package. Express/Fastify/Hono middleware that gates routes with x402 payments. Declarative route pricing, multi-token support, async settlement, facilitator auto-discovery, and dynamic pricing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Added: SDK Design RFCsTwo new RFC documents added to the x402 project: 0002-x402-client-sdk.md —
|
Add the three x402 design documents to the Open RFCs table: - x402-1: Protocol support (nano contract escrow) - x402-2: Client SDK (@hathor/x402-client) - x402-3: Server middleware (@hathor/x402-server) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Pre-funded nano contract channels that allow multiple x402 payments from a single deposit. Client deposits once, facilitator calls spend(amount, seller) per request. Eliminates per-request latency after initial channel setup. Includes X402Channel blueprint design, protocol flow, comparison with escrow mode, and trust model analysis. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| | Refund on timeout | Impossible without timelock hacks | **Built-in** — contract refunds automatically | | ||
| | Trust model | Must trust facilitator won't hold tx | **Trustless** — contract enforces rules | | ||
| | Multi-party | Hard | **Native** — contract tracks all parties | | ||
|
|
There was a problem hiding this comment.
I think the UX with nano contracts will be super slow. From what I understand, every payment depends on deploying a contract, which will be slow and probably more expensive.
But this has a fundamental flaw: the client can double-spend the UTXOs before the facilitator settles.
If we wait just for one block confirmation, which is as fast a nano tx, we don't have this problem. And it could be up to the facilitator. I imagine most txs are micropayments, so it should be ok not to wait for block confirmation. That's not possible with nanos, as execution always happen when a block arrives.
Another positive of using a regular transaction instead of nanos is the upcoming privacy solution. That won't be available for nanos, at least not initially.
|
|
||
| ### 3.4 Why This Blueprint Design | ||
|
|
||
| **One escrow per payment.** Each x402 request creates a new nano contract instance. This is clean because: |
There was a problem hiding this comment.
Why do we need one blueprint per payment? Can't we achieve all the features below with a single x402 contract? Or one contract per facilitator or per resource? One contract per payment seems cumbersome and probably more expensive (need to deploy multiple nano contracts).
|
|
||
| ### 1.2 Why Nano Contracts (Not Pre-Signed Transactions) | ||
|
|
||
| The naive approach for UTXO chains is pre-signed transactions. But this has a fundamental flaw: **the client can double-spend the UTXOs before the facilitator settles**. On EVM chains this is solved by EIP-3009 nonces; on Solana by recent blockhash expiry. Hathor has neither. |
There was a problem hiding this comment.
How does EIP3009 prevent this? From what I understand, it allows for gas payment by the receiver (or a third-party), but it does not guarantee settlement.
Update 0001 to use x402Version: 2, base64-encoded PAYMENT-SIGNATURE and PAYMENT-RESPONSE headers, price field (replacing amount), and x-payment fallback for V1 clients. Adds idempotency cache and health check to the facilitator plugin. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Investigates replacing nano contract escrow with regular Hathor transactions so x402 payments can eventually benefit from confidential transactions. Surveys Hathor's tx-layer constraints (no SIGHASH variants, no OP_IF, data outputs, mempool visibility) and evaluates three candidate schemes. Recommends adding 'hathor-direct' alongside 'hathor-escrow' via the x402 accepts[] mechanism, gated on a trust-model decision. Marked as research, not an RFC — meant to drive the debate Yan flagged in the x402 initiative about whether nano contracts should settle every x402 payment. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
|
||
| ### 3.1 No SIGHASH variants | ||
|
|
||
| Hathor has exactly one signing mode: `sighash_all` (`hathorlib/hathorlib/transaction.py:178`). The digest commits to every input, every output, parents, weight, timestamp, and nano headers. |
There was a problem hiding this comment.
SIGHASH_BITMASK would solve this.
| The two redeem templates in the wild are: | ||
| - **P2PKH (+ optional timelock prefix):** `<timelock> OP_GREATERTHAN_TIMESTAMP OP_DUP OP_HASH160 <pkh> OP_EQUALVERIFY OP_CHECKSIG` | ||
| - **P2SH MultiSig (+ optional timelock prefix):** `<timelock> OP_GREATERTHAN_TIMESTAMP <M> <pk1>…<pkN> <N> OP_CHECKMULTISIG` (wrapped in P2SH) | ||
|
|
There was a problem hiding this comment.
What does this solve?
On the EVM scheme, server can request payment, receive the signed data and not deliver the resource.
|
|
||
| **What's in the wire protocol:** | ||
|
|
||
| `PAYMENT-REQUIRED` adds a server-generated `requestHash` (random 32 bytes) and a short `deadline` (seconds). Client's payment tx must include both the value output to `payTo` and a data output containing `requestHash`. The data output binds this payment to this request, and prevents the client from reusing one payment for two resources. |
There was a problem hiding this comment.
Do we need to store the requestHash on the transaction? That would make it more expensive.
Summary
@hathor/x402-client) and server middleware (@hathor/x402-server) for programmatic integrationRendered
📄 View rendered RFC
Test plan
🤖 Generated with Claude Code