Class Web3jWallet

java.lang.Object
com.tnsai.payment.x402.Web3jWallet
All Implemented Interfaces:
Wallet

public final class Web3jWallet extends Object implements Wallet
Real secp256k1 EVM wallet backed by web3j-crypto's ECKeyPair.

Holds a private key in process memory. Suitable for:

  • Tests — deterministic key derivation, no real funds.
  • Local dogfood — single-user, low-balance testnet wallets that the operator wants to spin up without setting up a key-management service.

Not suitable for production agent fleets — for that, plug in a Wallet.Factory backed by KMS, an HSM, or a remote signer. The Wallet SPI exists exactly so this implementation can be swapped without touching X402PaymentBroker.

EIP-712 signature shape

signTypedData(EIP712TypedData) produces 65 bytes — r || s || v — where v is the standard EIP-155 recovery byte (27 or 28 for chainId-less ECDSA, which is what EIP-712 uses; EIP-3009 verifiers expect this exact shape).
Since:
0.10.5 (TNS-449 P3)
  • Method Details

    • fromPrivateKey

      public static Web3jWallet fromPrivateKey(String privateKeyHex, Network network)
      Build a wallet from a raw hex-encoded private key.
      Parameters:
      privateKeyHex - 64-char hex string (optionally prefixed with 0x)
      network - the network this wallet is bound to
      Throws:
      IllegalArgumentException - if privateKeyHex is not a valid 32-byte hex
    • address

      public String address()
      Description copied from interface: Wallet
      Lowercase 0x... hex address. EVM addresses are 42 chars.
      Specified by:
      address in interface Wallet
    • network

      public Network network()
      Description copied from interface: Wallet
      Network the wallet is bound to. Cross-network use is not supported.
      Specified by:
      network in interface Wallet
    • signTypedData

      public byte[] signTypedData(EIP712TypedData td)
      Description copied from interface: Wallet
      Produce a signature over the EIP-712 digest implied by td.
      Specified by:
      signTypedData in interface Wallet
      Parameters:
      td - prepared domain-separator + struct-hash pair
      Returns:
      65 bytes for EVM (r || s || v), 64 for SVM
    • recoverAddress

      public static String recoverAddress(byte[] signature, EIP712TypedData td)
      Re-derive the signer address from a signature + the same typed data that produced it. Used by the broker to verify replays against the expected payer in tests; production callers normally leave verification to the facilitator.