x402 icon indicating copy to clipboard operation
x402 copied to clipboard

Add x402-middy package for AWS Lambda integration

Open junbeomlee opened this issue 2 months ago • 2 comments

Implement Middy middleware for AWS Lambda functions following x402 Payment Protocol:

  • Support both EVM and Solana (SVM) networks
  • Payment verification and settlement flow
  • Coinbase Onramp session token integration
  • Comprehensive test coverage (29 tests)
  • Follow x402-express conventions

Description

This PR adds a new x402-middy package that provides Middy middleware for integrating the x402 Payment Protocol with AWS Lambda functions.

The implementation follows the same conventions and patterns as the existing x402-express package, adapted for the AWS Lambda/Middy ecosystem.

Key Features:

  • Middy middleware for AWS Lambda functions (APIGatewayProxyEvent/APIGatewayProxyResult)
  • Support for both EVM networks (Ethereum, Base, etc.) and Solana networks (SVM)
  • Complete payment verification and settlement flow using x402 facilitator
  • Optional Coinbase Onramp integration for session token generation
  • Comprehensive documentation with Serverless Framework and AWS SAM examples

Files Added:

  • typescript/packages/x402-middy/src/index.ts - Main Middy middleware
  • typescript/packages/x402-middy/src/session-token.ts - Lambda handler for Coinbase Onramp session tokens
  • typescript/packages/x402-middy/src/index.test.ts - Middleware tests (15 tests)
  • typescript/packages/x402-middy/src/session-token.test.ts - Session token tests (14 tests)
  • typescript/packages/x402-middy/README.md - Complete documentation with examples

Tests

All tests pass (29/29):

$ cd typescript/packages/x402-middy && pnpm test

 ✓ src/session-token.test.ts (14 tests)
 ✓ src/index.test.ts (15 tests)

 Test Files  2 passed (2)
      Tests  29 passed (29)

Test Coverage:

  • Payment verification and settlement flow
  • Error handling (verification errors, settlement failures)
  • EVM and Solana network support
  • Session token integration
  • Browser paywall HTML rendering
  • Edge cases (missing headers, invalid payments, unsuccessful settlements)

Checklist

  • [x] I have formatted and linted my code
  • [x] All new and existing tests pass
  • [x] My commits are signed (required for merge)

junbeomlee avatar Oct 12 '25 14:10 junbeomlee

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

cb-heimdall avatar Oct 12 '25 14:10 cb-heimdall

@junbeomlee is attempting to deploy a commit to the Coinbase Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Oct 12 '25 14:10 vercel[bot]