Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nhestrompia/shielded-x402/llms.txt
Use this file to discover all available pages before exploring further.
Verification Flow
The SDK performs comprehensive verification of shielded payments:Verification Steps
TheverifyShieldedPayment method performs these checks:
Header Validation
Validates the
PAYMENT-SIGNATURE header is present and well-formed.Failure reason: 'missing payment headers' or 'invalid PAYMENT-SIGNATURE header'Requirement Matching
Ensures the accepted requirement matches merchant configuration:
- Rail matches (
'shielded-usdc') - Price matches exactly
- Merchant public key matches
- Verifying contract matches
'accepted requirement does not match merchant config'Challenge Validation
Verifies the challenge nonce is active and not expired.Failure reasons:
'unknown challenge nonce' or 'challenge expired'Payload Shape Validation
Validates the payment response structure:
- Exactly 6 public inputs
- Proof hex length within limits (< 262144 bytes)
Challenge Hash Verification
Recomputes and verifies the challenge hash:Failure reason:
'challenge hash mismatch'Amount Verification
Extracts amount from
publicInputs[5] and verifies it matches the price.Failure reasons: 'invalid amount encoding' or 'amount mismatch'Nullifier Check
Calls
hooks.isNullifierUsed() to prevent replay attacks.Failure reason: 'nullifier already used'Proof Verification
Calls
hooks.verifyProof() to verify the zero-knowledge proof on-chain.Failure reason: 'proof verification failed'VerifyResult Type
The verification result has this structure:Success Response
Failure Response
Verifier Adapters
On-Chain Verifier
The production verifier checks proofs against deployed contracts:src/lib/verifier.ts
- Calls
isKnownRoot(root)on the shielded pool contract - Calls
verify(proof, publicInputs)on the ultra verifier contract - Calls
isNullifierUsed(nullifier)to check for double-spending
Allow-All Verifier (Dev Only)
- Accepts any proof starting with
'0x' - Tracks nullifiers in-memory to prevent double-use within the same session
- Does not verify cryptographic proofs
Settlement Adapters
On-Chain Settlement
Submits payments to the shielded pool contract:src/lib/settlement.ts
Submit spend transaction
Calls
submitSpend(proof, nullifier, root, merchantCommitment, changeCommitment, challengeHash, amount).No-Op Settlement (Dev Only)
{ alreadySettled: false } without performing any on-chain action.
Confirming Settlement
After successful on-chain settlement, update SDK state:Withdrawal Support
The SDK can encode withdrawal calldata for contract interactions:WithdrawResult Type
Error Handling
Handle verification failures gracefully:Security Best Practices
Always verify proofs on-chain in production
Always verify proofs on-chain in production
Use
createOnchainVerifier() connected to a trusted RPC endpoint. Never use createAllowAllVerifier() in production.Set appropriate challenge TTL
Set appropriate challenge TTL
Use a short TTL (2-5 minutes) to minimize the window for challenge reuse attacks. The default of 180000ms (3 minutes) is recommended.
Protect relayer private keys
Protect relayer private keys
Store
RELAYER_PRIVATE_KEY securely using environment variables or secret management. Never commit keys to source control.Validate nullifiers before settling
Validate nullifiers before settling
Always check
isNullifierUsed() before attempting on-chain settlement to avoid wasted gas on reverted transactions.Monitor settlement transactions
Monitor settlement transactions
Log settlement transaction hashes and monitor for failures. Implement retry logic for transient RPC errors.
Rate limit payment endpoints
Rate limit payment endpoints
Apply rate limiting to prevent DoS attacks via repeated invalid payment attempts.
TypeScript Reference
Key types from@shielded-x402/merchant:
@shielded-x402/shared-types:
Next Steps
Integration Guide
Return to the integration guide for implementation examples