Skip to content

feat(nextjs-agentic-payments-x402): crypto-abstracted agentic payments (Dynamic + x402) - #66

Open
avneesh0612 wants to merge 1 commit into
mainfrom
feat/nextjs-agentic-payments-x402
Open

feat(nextjs-agentic-payments-x402): crypto-abstracted agentic payments (Dynamic + x402)#66
avneesh0612 wants to merge 1 commit into
mainfrom
feat/nextjs-agentic-payments-x402

Conversation

@avneesh0612

Copy link
Copy Markdown
Contributor

What

A Next.js + Dynamic JS SDK example showing agentic payments with the crypto abstracted away: a user signs in with email, gets an embedded MPC wallet, authorizes an agent (delegated access), and "adds funds" in USD. An autonomous agent then pays for services via gasless x402 (EIP-3009 USDC) — every signature happens inside Dynamic's MPC, so no private key ever touches the agent.

Architecture

Piece Path
Web app app/, components/, lib/providers.tsx — email login → embedded EVM wallet (guarded creation) → delegateWaasKeyShares → USD funding page (light theme)
Delegation webhook app/api/webhooks/dynamic/, lib/dynamic/ — HMAC-verified; decrypts the share (RSA-OAEP + AES-GCM)
Encrypted store lib/shared/delegation-store.ts, supabase/ — re-encrypts shares (AES-256-GCM) into Supabase; derives a short account code per wallet; RLS on
Paid service + x402 gate middleware.ts, app/api/services/azure-compute/ — Coinbase facilitator on mainnet, public facilitator on testnet
Agent agent/pay-for-service.ts — resolves a user's wallet by account code and pays via x402; lib/shared/x402-account.ts bridges Dynamic MPC into the x402 signer

Verified end-to-end on Base Sepolia: authorize → webhook stores encrypted share → agent pays the x402 service gaslessly (balance debited).

Security

  • HMAC + constant-time webhook signature verification (length-checked).
  • AES-256-GCM encryption at rest; RLS-locked Supabase table; no raw keys in the agent.
  • Security headers (CSP frame-ancestors, X-Frame-Options, HSTS, nosniff, Referrer/Permissions-Policy).
  • Generic API error messages; .env*/.vercel gitignored — only .env.example placeholders tracked.
  • The two hex strings the secret scanner flags in lib/shared/constants.ts are the public USDC contract addresses on Base / Base Sepolia, not secrets.

Notes for reviewers

  • Uses the Dynamic JS SDK 1.8.0 line (needed for the MoonPay on-ramp helper) + @dynamic-labs-wallet 1.0.28. The pnpm-lock.yaml resolves these from the internal Dynamic registry; Vercel/CI builds need that registry's auth (e.g. an NPM_RC env var) since some 1.8.0 sub-packages (@dynamic-labs-sdk/metamask@1.8.0) aren't on public npm yet.
  • Follow-up still in progress: swap the funding page's on-ramp to the SDK getMoonPayUrl helper and drop the testnet/faucet branch.

🤖 Generated with Claude Code

…s (Dynamic + x402)

A Next.js + Dynamic JS SDK example where a user signs in with email, gets an
embedded MPC wallet, authorizes an agent (delegated access), funds in USD, and an
autonomous agent pays for services via gasless x402 (EIP-3009 USDC) — signed
inside Dynamic's MPC, so no private keys touch the agent.

- Web: email login -> embedded EVM wallet (guarded) -> delegateWaasKeyShares -> USD funding page.
- Webhook: HMAC-verified, decrypts the delegated share (RSA-OAEP + AES-GCM).
- Encrypted store: re-encrypts shares (AES-256-GCM) into Supabase; short account code per wallet (RLS on).
- Paid service + x402 gate (Coinbase facilitator on mainnet, public on testnet).
- Agent: resolves a user's wallet by account code, pays via x402; bridges Dynamic MPC into the x402 signer.

Note: the two hex strings the secret scanner flags in lib/shared/constants.ts are
public USDC token contract addresses on Base / Base Sepolia, not secrets.

Co-Authored-By: Claude Fable 5 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown

Deployment failed with the following error:

There is no GitHub account connected to this Vercel account.

@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
kamino Error Error Jun 10, 2026 5:24am
nextjs-agentic-payments-x402 Error Error Jun 10, 2026 5:24am
nextjs-iron-ramp Ready Ready Preview, Comment Jun 10, 2026 5:24am
predictions-market-demo Ready Ready Preview, Comment Jun 10, 2026 5:24am

Request Review

const privateKeyPem = getPrivateKey();

const shareKey = rsaOaepDecryptEk(privateKeyPem, share.ek);
const walletApiKeyKey = rsaOaepDecryptEk(privateKeyPem, apiKeyEnc.ek);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded sensitive data leaked

Semgrep has detected a leak of sensitive data in this code. This secret data could be used by internal or external malicious actors. We highly recommend you change, reset, or rotate the sensitive data.

A secret is hard-coded in the application. Secrets stored in source code, such as credentials, identifiers, and other types of sensitive data, can be leaked and used by internal or external malicious actors. It is recommended to rotate the secret and retrieve them from a secure secret vault or Hardware Security Module (HSM), alternatively environment variables can be used if allowed by your company policy.

💬 To ignore this, reply with:
/fp <comment> for false positive
/ar <comment> for acceptable risk
/other <comment> for all other reasons
Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by string.

@egoriklok

Copy link
Copy Markdown

Free public readiness snapshot for feat(nextjs-agentic-payments-x402): crypto-abstracted agentic payments (Dynamic + x402):

  • Public signal: Public GitHub candidate feat(nextjs-agentic-payments-x402): crypto-abstracted agentic payments (Dynamic + x402) #66: feat(nextjs-agentic-payments-x402): crypto-abstracted agentic payments (Dynamic + x402). Matched R1 terms: api, auth, messages, payment, service, services, verified, wallet.
  • R1 fit: api, auth, messages, payment, service, services, verified, wallet, x402.
  • Buyer-agent check I would add before autonomous spend: explicit price/cap unit, policy/version hash, receipt or charge-evidence reference, revocation/dispute path, and allow/caution/block preflight result.
  • This separates "interesting paid surface" from "safe for an agent wallet to use".

No invoice, no payment link, no delivery link, no private endpoint; this is only a free public snapshot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants