Skip to content

Introduce BaseAccount#4

Merged
badjer merged 15 commits intomainfrom
dnr/base-payment-maker
Aug 19, 2025
Merged

Introduce BaseAccount#4
badjer merged 15 commits intomainfrom
dnr/base-payment-maker

Conversation

@napoleond
Copy link
Copy Markdown
Contributor

@napoleond napoleond commented Aug 19, 2025

The equivalent of SolanaAccount—a BYO-keys unregistered account—but for Base.

To test:

  • npm run dev:resource - this will start a demo MCP server locally that uses auth.atxp.ai for OAuth/payments.
  • npm run dev:cli - this will run an MCP client locally that uses a BaseAccount in it's atxpClient (using env vars to load the Base wallet's private key and RPC endpoint), connect to the resource server above, and auth and pay

@badjer badjer changed the title [wip] Introduce BaseAccount Introduce BaseAccount Aug 19, 2025
@badjer badjer merged commit 4664b24 into main Aug 19, 2025
1 check passed
@badjer badjer deleted the dnr/base-payment-maker branch August 19, 2025 20:33
badjer pushed a commit that referenced this pull request Mar 31, 2026
Critical:
- Fix native currency to Ether/ETH (matches auth repo)
- Fix response body double-consumption bug in MPPProtocolHandler
- Add TempoModerato to ChainEnum for testnet support

Major:
- Decompose handlePaymentChallenge into extractChallenge,
  buildProspectivePayment, authorizeAndRetry helpers
- Decompose makePayment into checkBalance, classifyError helpers
- Remove dead SSE check in canHandle

Minor:
- Lower JWT log level from info to debug
- Add testnet support to TempoAccount via chainId parameter
- Add vitest.config.ts to atxp-tempo and atxp-mpp packages
- Fix unused variable lint error in tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
badjer pushed a commit that referenced this pull request Mar 31, 2026
- Extract makePayment helpers (encodeTransferData, sendAndConfirm) to bring
  method under 50-line limit
- Consolidate duplicated onPaymentFailure patterns into reportFailure helper
  in MPP handler
- Fix reconstructResponse to preserve original response headers and statusText,
  matching X402 handler behavior
- Remove unused @atxp/common and bignumber.js deps from @atxp/mpp package.json
- Add tests for reconstructResponse header preservation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
badjer pushed a commit that referenced this pull request Mar 31, 2026
- Remove unused FetchLike import from mppProtocolHandler.ts
- Remove unused ProspectivePayment and PaymentFailureContext imports from protocolHandler.test.ts
- Replace duplicated MCP error detection in canHandle() with hasMPPMCPError()
- Fix unsafe type assertions in classifyError() using instanceof checks

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
badjer added a commit that referenced this pull request Mar 31, 2026
…3.3 + 3.6)

feat: Tempo chain support + MPP protocol handler (Tasks 3.3 + 3.6)
badjer added a commit that referenced this pull request Mar 31, 2026
…e 1) (#143)

* feat: add multi-protocol support with feature flags and strategy pattern

Task 1.5: Add PaymentProtocol, ProtocolFlag, and ChainFlag types to @atxp/common.
Task 1.6: Refactor ATXPFetcher with strategy pattern for protocol handlers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add Tempo chain support and MPP protocol handler (Tasks 3.3 + 3.6)

Task 3.3 — Tempo chain support in SDK:
- Add 'tempo' to Chain/Network types in @atxp/common
- New @atxp/tempo package: TempoAccount, TempoPaymentMaker
- pathUSD token (TIP-20, 6 decimals) with transferWithMemo support
- Chain ID 4217 (mainnet), 42431 (testnet/Moderato)

Task 3.6 — MPP protocol handler:
- New @atxp/mpp package: MPP challenge parsing, MCP error -32042 detection
- MPPProtocolHandler in @atxp/client: detects WWW-Authenticate: Payment
  header and MCP -32042 errors, calls /authorize/mpp, retries with
  Authorization: Payment credential
- protocolFlag='mpp' selects MPP handler from omni-challenge
- Graceful fallback when /authorize/mpp is unavailable

All 228 tests passing across atxp-common, atxp-tempo, atxp-mpp, atxp-client.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: address Carol's review feedback on PR #4

Critical:
- Fix native currency to Ether/ETH (matches auth repo)
- Fix response body double-consumption bug in MPPProtocolHandler
- Add TempoModerato to ChainEnum for testnet support

Major:
- Decompose handlePaymentChallenge into extractChallenge,
  buildProspectivePayment, authorizeAndRetry helpers
- Decompose makePayment into checkBalance, classifyError helpers
- Remove dead SSE check in canHandle

Minor:
- Lower JWT log level from info to debug
- Add testnet support to TempoAccount via chainId parameter
- Add vitest.config.ts to atxp-tempo and atxp-mpp packages
- Fix unused variable lint error in tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: address Carol's re-review feedback on PR #4

- Extract makePayment helpers (encodeTransferData, sendAndConfirm) to bring
  method under 50-line limit
- Consolidate duplicated onPaymentFailure patterns into reportFailure helper
  in MPP handler
- Fix reconstructResponse to preserve original response headers and statusText,
  matching X402 handler behavior
- Remove unused @atxp/common and bignumber.js deps from @atxp/mpp package.json
- Add tests for reconstructResponse header preservation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: address Carol's round 3 review feedback on PR #4

- Remove unused FetchLike import from mppProtocolHandler.ts
- Remove unused ProspectivePayment and PaymentFailureContext imports from protocolHandler.test.ts
- Replace duplicated MCP error detection in canHandle() with hasMPPMCPError()
- Fix unsafe type assertions in classifyError() using instanceof checks

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: replace remaining unsafe type assertion in authorizeAndRetry catch block

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: remove unused LocalAccount import in x402-client.d.ts

Fixes ESLint no-unused-vars error blocking CI on PR #2.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: use ATXPAccount with connection string for dev resource server

AccountIdDestination doesn't carry a connection token, so server
registration was rejected by auth's developerAccountVerifier middleware
(missing X-ATXP-TOKEN). Revert to ATXPAccount which provides the token.
Also point server at localhost:3010 for local testing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: address PR #2 review feedback on protocol handlers

- Fix double response body consumption in MPPProtocolHandler by reading
  body once upfront in extractChallenge
- Fix ATXPProtocolHandler to return null instead of throwing, consistent
  with the ProtocolHandler strategy pattern contract
- Add runtime validation for /authorize/x402 and /authorize/mpp responses
  to catch missing paymentHeader/credential fields
- Replace unsafe `as` casts with type guards for account.origin/token
- Add 30s timeout on /authorize/* calls via AbortController
- Add tests for invalid auth responses, malformed headers, and ATXP
  handler strategy pattern compliance

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: correct x402/mpp protocol handler integration with accounts service

- Fix /authorize/x402 request body: send selectedPaymentRequirements as
  single object (not the full accepts array) to match accounts Zod schema
- Add auth headers (Basic auth with connection token) to /authorize/x402
  and /authorize/mpp calls so they pass accounts privyAuth middleware
- Don't hardcode 'base' network in selectPaymentRequirements — let x402
  library pick the best match from available options
- Fix MPP extractChallenge() double body consumption: clone response
  before reading so both header and MCP-body paths can read independently
- Update test mock to handle undefined network parameter

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat(server): add omni-challenge emission and protocol detection for multi-protocol support

Implements Task 1.7 of the multi-protocol integration plan:
- Server emits omni-challenges containing both ATXP-MCP and X402 payment data
- Credential detection: X-PAYMENT header → X402, ATXP JWT → ATXP-MCP
- ProtocolSettlement routes verify/settle to auth /verify/{protocol} and /settle/{protocol}
- Express middleware: verify at request start, settle at request end
- Omni-challenge formats: HTTP 402 with X402 body + X-ATXP-Payment-Request header (HTTP),
  MCP error -30402 with combined data (MCP SSE)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: correct server-side protocol detection and settlement contracts

- ProtocolSettlement now builds protocol-specific request bodies:
  X402 sends { payload, paymentRequirements }, ATXP sends
  { sourceAccountId, destinationAccountId, sourceAccountToken, options }
  to match auth service Zod schemas
- detectProtocol no longer misidentifies Bearer JWTs as ATXP payment
  credentials — Bearer tokens in non-MCP requests are OAuth tokens.
  Only X-PAYMENT header is detected (ATXP-MCP flows through MCP path)
- Settlement only fires on successful responses (2xx status codes),
  preventing users from being charged when request handlers error
- Add SettlementContext type for passing protocol-specific data

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: dave <dave_accounts@squads.email>
Co-authored-by: Dave (Overseer) <dave_overseer@squads.email>
Co-authored-by: eve <eve_accounts@squads.email>
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.

4 participants