Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
SIWX — Sign-In-With-X re-entry
SIWX ("Sign-In-With-X", standardized as CAIP-122) lets a wallet that already paid for an endpoint get back in by signing a challenge instead of paying again. It is the difference between a one-time purchase and being charged on every page load.
This package implements the client side of SIWX. The server endpoint must issue the challenge and verify the signed proof — see Server responsibilities.
For the overall flow, see architecture.
Why it matters
x402 charges per call. Without SIWX, a user who paid for /premium would pay
again the next time they hit it. With SIWX, the merchant can recognize a wallet
that has an active entitlement: the wallet proves ownership with a cheap,
gasless, off-chain signature, and the merchant grants access without a new
payment.
How the server advertises SIWX
When the endpoint returns its HTTP 402 challenge, it advertises SIWX support by including an extension entry in the challenge body:
{
"x402Version": 2,
"accepts": [
{
"network": "base",
"asset": "0xUSDC...synthetic",
"maxAmountRequired": "50000",
"payTo": "0xMerchant...synthetic",
"extensions": {
"sign-in-with-x": {
"domain": "api.example.com",
"statement": "Sign in to re-enter your paid session.",
"nonce": "synthetic-nonce-abc123"
}
}
}
]
}
The exact challenge fields are defined by the x402 SIWX spec; the modal only
needs extensions['sign-in-with-x'] to be present to offer sign-in.
How the client submits proof
When the user signs the challenge, the modal sends the signed CAIP-122 proof back
to the endpoint as a base64-encoded JSON value in the SIGN-IN-WITH-X
request header, then retries the original request. If the merchant accepts the
proof, it returns the result with no payment required.
Modal behavior
The modal adapts its layout to what the challenge offers:
- SIWX advertised + a compatible wallet present — the modal leads with
"Sign in with wallet" as the primary (
.x402-pay-btn) action and demotes pay to secondary (.x402-pay-secondary). Signing in is cheaper, so it's the default. - User signs in — on success the modal resolves
PayResultwith thesiwxfield populated ({ address, network }) and nopaymentfield, and fires thex402:siwx-signedevent. - Sign-in rejected (
siwx_not_paid) — if the server answers the SIWX attempt with a401/402carrying asiwx_not_paidreason (the wallet has no active entitlement), the modal falls back to the normal pay flow and shows a notice explaining that payment is required. - SIWX not advertised — the modal behaves as a plain pay modal; nothing changes.
The x402:siwx-signed event
A successful SIWX re-entry dispatches a bubbling x402:siwx-signed
CustomEvent on the clicked element:
const btn = document.querySelector('[data-x402-endpoint]');
btn.addEventListener('x402:siwx-signed', (e) => {
const { address, network } = e.detail;
console.log(`re-entered as ${address} on ${network}`);
});
You also get the same data programmatically from the resolved result:
const res = await pay({ endpoint: 'https://api.example.com/premium' });
if (res.siwx) {
console.log('re-entered via SIWX:', res.siwx.address);
} else if (res.payment) {
console.log('paid:', res.payment.transaction);
}
Server responsibilities
This package does not store entitlements or verify signatures. Your endpoint must:
- Advertise the SIWX extension in the 402 challenge (see above).
- Verify the CAIP-122 proof from the
SIGN-IN-WITH-Xheader — check the nonce, domain, expiry, and signature against the claimed address. - Authorize the request if that address has an active paid entitlement;
otherwise respond
401/402withsiwx_not_paidso the client falls back to paying.
Implement these against the x402 SIWX specification. The modal handles everything on the browser side: detecting the offer, prompting the signature, encoding the header, retrying, and falling back.