Package com.tnsai.payment.x402
Class Web3jWallet
java.lang.Object
com.tnsai.payment.x402.Web3jWallet
- All Implemented Interfaces:
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)
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.tnsai.payment.x402.Wallet
Wallet.Factory -
Method Summary
Modifier and TypeMethodDescriptionaddress()Lowercase0x...hex address.static Web3jWalletfromPrivateKey(String privateKeyHex, Network network) Build a wallet from a raw hex-encoded private key.network()Network the wallet is bound to.static StringrecoverAddress(byte[] signature, EIP712TypedData td) Re-derive the signer address from a signature + the same typed data that produced it.byte[]Produce a signature over the EIP-712 digest implied bytd.
-
Method Details
-
fromPrivateKey
Build a wallet from a raw hex-encoded private key.- Parameters:
privateKeyHex- 64-char hex string (optionally prefixed with0x)network- the network this wallet is bound to- Throws:
IllegalArgumentException- ifprivateKeyHexis not a valid 32-byte hex
-
address
Description copied from interface:WalletLowercase0x...hex address. EVM addresses are 42 chars. -
network
Description copied from interface:WalletNetwork the wallet is bound to. Cross-network use is not supported. -
signTypedData
Description copied from interface:WalletProduce a signature over the EIP-712 digest implied bytd.- Specified by:
signTypedDatain interfaceWallet- Parameters:
td- prepared domain-separator + struct-hash pair- Returns:
- 65 bytes for EVM (
r || s || v), 64 for SVM
-
recoverAddress
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.
-