Skip to content

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

Merged
gummy789j merged 16 commits into
tronprotocol:release_v4.14.0from
boboliu-1010:feat/v4.14-x402-bai-8004
Sep 11, 2026
Merged

gummy789j merged 16 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
Contributor

Summary

Add x402 payments and provider discovery, B.AI account queries and recharge, and eight ERC-8004 identity commands to the TypeScript wallet CLI. B.AI supports personal API keys and recharge on TRON/USDT, BSC/USDT and Base/USDC, including crediting another user. Signing stays in the existing wallet software/device flow.

Implementation

  • Mixed command-group help lists chain-bound and neutral commands together, so bai --help includes both recharge and account/report commands. A regular registry-backed test prevents this discovery regression.

  • CLI commands route through application use cases and ports to outbound adapters. B.AI recharge and ERC-8004 use chain/family bindings; account queries and report-only recovery do not require a signing wallet. ERC-8004 writes use the common transaction pipeline. x402 retains its SDK/facilitator lifecycle while reusing the wallet signer resolver and signature flow.

  • B.AI credential setup validates an existing wallet binding. Each wallet signs its own prescribed binding message; the adapter preserves message bytes and accepts canonical EVM binding responses while rejecting unrelated wallets/chains. No automatic binding command is added. The local confirmation cache is specific to the API key, chain and wallet.

  • Recharge validates the network, token, precision, minimum amount and binding, resolves the recipient, creates an order with the personal API key, pays through local X402Service.roundtrip, then reports the transaction. Amounts remain strings across application ports; numeric conversion is checked at the B.AI HTTP boundary. Three trusted destinations live in outbound configuration, cannot be overridden, and require a release to change. The old recharge MCP is no longer a CLI dependency; the remote facilitator still verifies and settles payments.

  • Settlement validation checks success, network, hash and payer. Equivalent valid TRON Base58Check and SDK hexadecimal payer representations compare as the same address. Failed validation retains safe candidate evidence and the original recharge context without declaring payment confirmed.

  • Recharge and bai recharge-report retry only TX_NOT_FOUND_OR_INVALID and TX_TIMESTAMP_UNAVAILABLE: up to three retries after 15/20/25 seconds, at most four reports within a 90-second reporting budget including HTTP time. They never repeat payment. Other business, authentication and transport failures stop automatic reporting. Recovery preserves the hash, original recipient and retryPayment: false; recipient recovery requires original --to and --target-id. There is no persistent recovery queue.

  • TRON exact uses SDK allowanceMode: auto. EVM sponsored approval converts gas to gasLimit, preserving an explicit limit. EVM self-funded approval remains an explicit agent decision; Base USDC's EIP-3009 path does not require ERC20 allowance. The local B.AI paywall does not advertise sponsorship extensions. GasFree shortfalls do not fall back to the ordinary TRON wallet.

  • Payment errors preserve the failure stage, safe HTTP status, recognized connection codes and candidate settlement hashes. Native facilitator connection exceptions are classified on the server and retained by the client. Unknown upstream prose and request contents are filtered. Post-settlement response failures retain settlement evidence; uncertain outcomes never trigger automatic repayment.

  • ERC-8004 SDK supplies registry configuration, ABI, address conversion and event parsing; no ExternalSigner or separate SDK transaction sender is used. Receipt metadata is nested under identity, ERC20/ERC721 approval semantics stay distinct, and URI loading is bounded. TRON payable resource estimation receives the same callValueSun as transaction construction.

Lockfile versions: 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. Package version is currently 4.13.1, pending the release version update. This branch includes the v4.13.1 merge into release_v4.14.0; signer groundwork from #1000 retains its original authorship.

Validation

  • Full regression at 59f7f5aa: 240 files passed / 3 skipped; 2787 tests passed / 35 skipped. Typecheck, dependency-boundary checks, ESLint, formatting and build passed.
  • Final connection-diagnostics patch: 13 x402 test files / 101 tests passed, plus typecheck, ESLint, build and diff checks. Tests exercise verify/settle connection failures, allowlisted codes and redaction through server/client boundaries. The full suite was not rerun after this small patch.
  • Latest help/packaging fix 040ea1e5: 4 help test files / 39 tests passed; tarball creation, independent install and installed CLI verification: 7 files / 59 tests passed. Typecheck, ESLint, build and diff checks passed locally. This fixes the missing recharge row that failed the Node 22/24 package check on 88fa30b1; the new remote CI run remains to be confirmed.
  • Three distinct TRON/Base/BSC wallets were signed with Wallet CLI, bound and queried successfully under one personal API key.
  • BSC mainnet: 1 USDT self-recharge (order 47527) and 1 USDT recipient recharge (47531) credited. Base mainnet: 1 USDC recipient recharge (47541) credited after reporting recovery.
  • TRON mainnet, September 11, using the latest local build: 1 USDT credited to bobo.liu@tron.network, order 47632, 990000 points, creditStatus: credited, approximately 67 seconds. Trace records one order, one verify, one settle and three reports; the wallet balance changed from 1 USDT to 0. Transaction. This validates automatic report recovery without a second payment; network-failure diagnostics are covered by simulated failures, not an induced mainnet outage.

QA and release scope

Ready for QA with the latest commit included in the test build. Remaining acceptance coverage includes report idempotency, physical hardware wallets, deployed facilitator sponsorship extensions, and ERC-8004 transactions across supported networks. Successful B.AI mainnet tests do not establish coverage of those paths. Test funds must be replenished before more paid cases; the TRON USDT balance is now zero and remaining Base/BSC funds were returned earlier.

Update the package version and verify the final installable artifact before release. Removing the CLI's old recharge-server dependency does not decommission that remote service.

Repository behavior is documented in ts/docs/development/architecture.md, ts/docs/development/bai-recharge.md, ts/docs/development/erc8004-sdk-integration.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
Retain the release branch's legacy derivation fixes and 4.13.1 package metadata. Resolve version handling through package.json and preserve both x402 and derivation error documentation.
Bound report-only recovery for transaction indexing delays without replaying payments. Retain safe x402 failure phases and settlement evidence, and pass TRON callValue through resource estimation.
@gummy789j
gummy789j merged commit 6da1996 into tronprotocol:release_v4.14.0 Sep 11, 2026
1 of 2 checks passed
@gummy789j gummy789j mentioned this pull request Sep 18, 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