@receptum/client
v0.2.1
Published
Buyer and agent client: pays HTTP 402 responses within per-agent spending limits and verifies receipts.
Maintainers
Readme
@receptum/client
Pay for agent work over x402 and only accept results that come with a valid receipt.
createReceptumFetch({ paidFetch, networks, allowedSellers }) wraps a paying fetch (e.g. @x402/fetch) and throws ReceiptError unless: the seller signature verifies, SHA-256 of the received bytes equals outputSha256, the receipt's payment.reference is the x402 settlement transaction, and the seller is on your allow-list. checkDelivery() runs the same checks on data you already have.
Pass requireBinding: true with bindingVerifiers: [evmBindingVerifier] (from @receptum/adapter-evm; Stellar is built in, XRPL has xrplBindingVerifier) to also require an account binding (SPEC §4.1) proving the seller controls the account you paid. Without a verifier for the payee's namespace the check fails closed. check.payeeBound reports the result either way.
networks is required: the CAIP-2 networks your paidFetch is registered to pay on (e.g. ["eip155:84532"]). A missing or empty list throws a TypeError at construction — without it a mainnet payment could not be refused before paidFetch pays.
See examples/agent-buyer.
Mainnet x402 networks (opt-in)
Register the mainnet scheme with your x402 client (e.g. @x402/fetch with network: "eip155:8453") and declare it to Receptum:
const buy = createReceptumFetch({
paidFetch,
networks: ["eip155:8453"], // the networks paidFetch pays on
allowMainnet: true, // or RECEPTUM_ALLOW_MAINNET=1
allowedSellers: [sellerDid],
expected: { network: "eip155:8453", asset: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" },
});createReceptumFetch throws MainnetNotAllowedError at construction — before any request is paid — when networks or expected.network names a mainnet (or unknown) network without the opt-in, throws a TypeError when expected.network is not one of the declared networks, and rejects receipts on networks outside the list. Pin expected.network so a testnet receipt can never stand in for a mainnet payment.
