bsv-x402
v0.7.0
Published
x402 payment protocol client — a fetch() wrapper that handles 402 payment flows transparently
Readme
bsv-x402
A JavaScript client library for the x402 payment protocol. Wraps fetch() to handle HTTP 402 payment flows transparently.
How It Works
import { x402Fetch } from 'bsv-x402'
const response = await x402Fetch('https://api.example.com/paid-endpoint')When the server responds with 402 Payment Required, the library:
- Parses the
X402-Challengeheader - Constructs a payment transaction via the browser wallet (BRC-100 /
window.CWI) - Broadcasts the transaction to the BSV network
- Retries the original request with an
X402-Proofheader
The app developer just uses x402Fetch in place of fetch. The browser wallet handles key management and signing.
Installation
npm install bsv-x402Development
npm install # Install dependencies
npm run build # Compile TypeScript → dist/
npm test # Run tests
npm run typecheck # Type-check without emittingStatus
Early development. The fetch wrapper and challenge parsing are in place; the BRC-100 wallet integration (constructProof) is not yet implemented.
