Class InMemoryWallet

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

public final class InMemoryWallet extends Object implements Wallet
Test-only Wallet that never touches real cryptography.

What it does

  • Holds a fixed 0x... address and a Network.
  • signTypedData(EIP712TypedData) returns a deterministic 65-byte (EVM) or 64-byte (SVM) array computed as SHA-256(address || domainSeparator || structHash) padded to the requested length. The output looks like a signature byte-shape-wise but is not verifiable on any chain.

Why it exists

Two reasons:
  1. Unit tests of the broker layer need a Wallet they can call without a private key or a network. The deterministic output lets tests assert "the broker passed the right digest" without hard-coding a signature value.
  2. The SPI's "what does an implementation look like" reference — anything trickier than this would obscure the shape.

What it is NOT

Not for production. Not for testnet either — its output won't pass any real facilitator's signature check. Any code path that constructs an InMemoryWallet and ships to mainnet has a bug, and the class name is meant to make that bug visible at code review.
Since:
0.10.5 (TNS-449 P2)
  • Field Details

  • Method Details

    • forTesting

      public static InMemoryWallet forTesting(String address, Network network)
      Factory method — naming makes the test-only intent explicit at the call site. Production code that wants a wallet should go through Wallet.Factory.discover() instead.
      Parameters:
      address - 0x... hex address; case is normalised
      network - the network this wallet claims to be on
    • 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