Skip to content

feat(ts): add x402 payments, BAI recharge recovery and ERC-8004 - #1002

Open
boboliu-1010 wants to merge 10 commits into
tronprotocol:release_v4.14.0from
boboliu-1010:feat/v4.14-x402-bai-8004
Open

feat(ts): add x402 payments, BAI recharge recovery and ERC-8004#1002
boboliu-1010 wants to merge 10 commits into
tronprotocol:release_v4.14.0from
boboliu-1010:feat/v4.14-x402-bai-8004

Conversation

@boboliu-1010

@boboliu-1010 boboliu-1010 commented Sep 7, 2026

Copy link
Copy Markdown

Summary

Add x402 payments and provider discovery, B.AI account queries and recharge recovery, and eight ERC-8004 identity commands to the TypeScript wallet CLI. All signing stays in the existing wallet software/device flow. The signer groundwork from #1000 retains its original commit authorship.

  • Reuse the local X402Service.roundtrip for B.AI recharge: validate the token and precision before target resolution or preorder creation, create the order using the personal API key, pay the trusted destination, then report the transaction. Remove the old recharge MCP dependency. Keep the three supported destination addresses in outbound configuration, without user overrides; changing them requires a release.
  • Accept B.AI canonical EVM binding responses (chain: eth, lowercase address) while rejecting unrelated chains or wallets; preserve signed message bytes. Document the required BAI recharge-binding message template and live verification that three distinct TRON/Base/BSC wallets coexist under one personal API key. Credential setup still checks existing bindings; no automatic binding command is added.
  • Enable TRON SDK allowance handling with allowanceMode: auto. Normalize EVM approval-sponsoring transactions from gas to gasLimit, preserving an explicit gas limit. EVM self-funded approval remains an explicit agent decision; GasFree shortfalls do not fall back to the ordinary TRON wallet.
  • Preserve typed wallet errors and map recognized SDK/facilitator failures to stable, sanitized codes, including GasFree balance/activation and Permit2 allowance failures. Keep verify/settle phase information without exposing raw provider messages.
  • Preserve settlement hashes and retryPayment: false when JSON parsing, response buffering or output writing fails after settlement. B.AI validation failures retain a bounded candidateTxHash, the failure reason and original recharge context without treating the candidate as confirmed payment.
  • Add bai recharge-report <txHash> --chain tron|bnb|base [--amount ...]. It reports an existing transaction without a local wallet, preorder, signature, payment or recipient re-resolution. Recipient recovery requires both original --to and --target-id; failed reports retain recovery data.
  • Use @bankofai/8004-sdk for registry configuration, ABI and event parsing while identity writes stay in the wallet transaction pipeline. Group write-receipt fields under identity.*; preserve ERC20/ERC721 approval semantics and bounded metadata loading.

The lockfile resolves x402 core 1.1.1-beta.1, TRON 2.0.0-beta.1, EVM/fetch 1.1.0, and 8004 SDK 1.2.0-beta.1. x402 dependencies are bundled into the CLI. Package version remains 4.13.0 pending the release version update.

Validation

Baseline validation at 48918534:

  • Full regression: 234 test files passed, 3 skipped; 2652 tests passed, 35 skipped (npm test -- --maxWorkers=4).
  • Typecheck, dependency-boundary checks, ESLint, build and diff whitespace checks passed.
  • Tarball creation, independent installation and installed CLI tests: 7 files / 59 tests passed (npm run verify:package).
  • Regression coverage includes SDK GasFree amount-plus-fee shortfalls, TRON approvals, BSC/Base sponsored-approval transaction decoding, post-settlement failures, B.AI preflight rejection, candidate-hash recovery and report-only CLI use without a wallet.

Latest binding patch 2a6789fb: 4 related test files / 54 tests passed; typecheck, ESLint, dependency-boundary checks, build and diff checks passed. Added regression cases for canonical EVM responses, unchanged signed message bytes, unrelated chains, wrong addresses and case-sensitive TRON addresses. Live binding requests with Wallet CLI signatures returned HTTP 200 for three distinct wallets; all three chain/address checks returned true using the same API key. No funds were transferred.

Latest API-diagnostics patch 2e9a5ce2: both B.AI clients decode bounded HTTP/tRPC failures into fixed business explanations (bai_rejected plus reason/operation/status), keep authentication and rate limits distinct, and redact unknown provider prose. Report failures preserve the transaction context and classified error without repeating payment. Local invalid inputs and binding response mismatches have actionable diagnostics.

Validation during this patch: 235 files passed / 3 skipped; 2680 tests passed / 35 skipped. Final targeted regression: 8 files / 78 tests passed; package verification: 7 files / 59 tests passed. Typecheck, ESLint, dependency checks and build passed. Small final error-classification refinements after the full run were covered by targeted regression and the final build.

Integration boundaries

No real funds were transferred and no physical Ledger test was performed. Production B.AI credit attribution, remaining recharge API contracts, duplicate reporting and real facilitator settlement still require integration verification. Recovery results must be retained by the caller; a persistent recovery journal is not included. Removing the CLI dependency does not decommission the old recharge server.

Design and command behavior are documented in Wallet-CLI v4.14.0 技術方案, ts/docs/development/bai-recharge.md, and ts/docs/machine-interface.md.

boboliu-1010 and others added 8 commits September 4, 2026 17:15
x402-cli signs its payments through @bankofai/agent-wallet. Migrating its
commands into wallet-cli means re-pointing that signer at a wallet-cli
account; this is the seam that makes the rest of that migration mechanical.
No x402 SDK is a dependency yet, and no command is wired.

- domain/x402/network-id — convert between wallet-cli network ids and the
  CAIP-2 ids x402 uses. TRON differs only in base (tron:728126428 is
  tron:0x2b6653dc); eip155 identifiers are identical on both sides.

- application/contracts/x402-payer — PayerSigner and PayerPolicy. The
  contract carries two closures rather than the domain Signer, because an
  x402 scheme calls the wallet from deep inside a payment flow, where
  nothing can run a Ledger's precheck / prompt / abort ceremony.

- application/services/x402/payer-signer — resolve the active account,
  refusing a watch-only one before any keystore decrypt, and apply that
  ceremony once per signature. The TRON allowance path signs an approve
  transaction before the payment, so each signature needs its own round.

- adapters/outbound/x402/signer-bridge — reshape the payer for the x402
  SDK, declared structurally so no x402 package is imported. It is the one
  place every typed-data payload passes through, so it carries all three
  guards: the payload's payer must be the selected account, a GasFree
  maxFee must stay within the caller's ceiling, and the returned signature
  must be for the struct that was requested. The first two refuse before
  any signature is requested, so a rejected payment never reaches a device
  prompt.

- domain/typed-data — resolvePrimaryType, so those guards work from the
  payload's real signing root instead of an optional field. Without it, a
  payload that omitted primaryType skipped all three checks.

- three error codes: payer_mismatch, fee_cap_exceeded and
  signed_payload_mismatch, with their rows in machine-interface.md.
@boboliu-1010 boboliu-1010 changed the title feat(ts): integrate x402 payments, BAI commands and ERC-8004 beta feat(ts): add x402 payments, BAI recharge recovery and ERC-8004 Sep 9, 2026
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