Packages
1. Client setup
client/numpayZKClient.ts
2. Generate a private payment proof
client/generateProof.ts
3. Protect an API with x402 middleware
When a request has no validx-payment-proof header, the middleware answers 402:
- the proof is valid;
- the amount is within range (10% tolerance);
- the recipient matches the merchant;
- the proof is less than 5 minutes old.
4. Example server
server/app.ts
MERCHANT_PHONE, MERCHANT_WALLET, PORT.
5. Client that pays automatically
X402ZKPaymentClient.makePrivateRequest(endpoint, options):
- Calls the endpoint.
- On
402, generates a proof. POST /verify, thenPOST /settle.- Retries the original request with
X-Payment-Proof.
sendPrivatePayment(recipientPhone, amount, memo?) sends a private payment without an API call.
