@ftptech/x402-canton-client
v0.1.4
Published
Canton x402 client SDK — payer side. ExactCantonScheme + signer abstractions for autonomous agents.
Maintainers
Readme
@ftptech/x402-canton-client
Payer-side SDK for Canton x402. Lets an autonomous agent pay for
x402-gated HTTP resources using a CantonSigner that submits a CIP-56
TransferFactory_Transfer from the agent's Canton participant.
Install
npm i @ftptech/x402-canton-clientNote: the
@ftpnpm scope is not final — it may change before the first public release (seedocs/PUBLISHING.md). Pin the version you install and check the README for the current package name.
What's in here
CantonSignerinterface — abstracts how a CIP-56 transfer is signed and submitted (real participant viaCip56KeyfileSigner, mock for tests, hosted-party variants).Cip56KeyfileSigner+makeCip56KeyfileSigner(config)— production signer that loads an Ed25519 key from a PEM file (or env-var PEM string) and drives the participant's interactive-submission prepare/sign/execute flow forTransferFactory_Transfer.ExactCantonScheme— builds x402 v2 PaymentPayload envelopes from PaymentRequirements + a signer.wrapFetchWithCantonPayment(fetch, signer)— drop-in fetch replacement that detects 402, decodesPAYMENT-REQUIRED, calls the signer, retries withPAYMENT-SIGNATURE, throwsX402PaymentErrorwith a stablecodefield on failure.readPaymentResponseHeader(response)— decodes the v2PAYMENT-RESPONSEsettlement header.
Quick example
import {
wrapFetchWithCantonPayment,
readPaymentResponseHeader,
makeCip56KeyfileSigner,
} from "@ftptech/x402-canton-client";
const signer = makeCip56KeyfileSigner({
participantUrl: "https://your-participant/ledger-api",
participantToken: "<bearer>",
scanUrl: "https://scan.your-sv/api/scan",
party: "agent_party::1220...",
keyPath: "/run/secrets/agent.pem",
});
const fetchWithPay = wrapFetchWithCantonPayment(fetch, signer);
const res = await fetchWithPay("https://api.example.com/data");
const settle = readPaymentResponseHeader(res);See docs/quickstart.md
for the full demo flow and examples/agent-buyer/ for a runnable
agent.
