Package com.tnsai.payment.x402
Class TransferAuthorization
java.lang.Object
com.tnsai.payment.x402.TransferAuthorization
Builds the EIP-712 typed-data hash pair for an EIP-3009
Why we don't use web3j's
transferWithAuthorization call — the payload an x402 client
signs to authorise a one-time USDC transfer without an on-chain
approval round-trip.
Two hashes come out:
- Domain separator =
keccak256(EIP712Domain(...)), scoped to the token contract that will verify the signature (theassetaddress from the 402 response). - Struct hash =
keccak256(TransferWithAuthorization(...)), bindingfrom,to,value,validAfter,validBefore, andnonce.
The wallet receives both as an EIP712TypedData record and
applies the EIP-712 prefix and secp256k1 signing on top —
specifically keccak256(0x1901 || domainSeparator || structHash)
— so this class never touches private-key material.
Why we don't use web3j's StructuredDataEncoder
StructuredDataEncoder round-trips through JSON Schema parsing,
which is heavier than necessary for this fixed schema. Inlining the
encoding keeps the broker's hot path tight and the implementation
legible alongside the EIP-712 / EIP-3009 spec.- Since:
- 0.10.5 (TNS-449 P3)
-
Method Details
-
builder
-
from
-
to
-
value
-
validAfter
-
validBefore
-
nonce
public byte[] nonce() -
toTypedData
EIP-712 typed data: the two 32-byte hashes the wallet will sign over.
-