Skip to main content
The auth adapter (hip4.auth) manages the agent key lifecycle for HIP-4 prediction trading. Rather than prompting the user to sign every individual order, HIP-4 uses an ephemeral agent keypair that you approve once via the user’s wallet. After approval, the agent key signs all orders and USDH spot trades silently on the user’s behalf. The adapter tracks the current auth state and exposes it synchronously so your UI can react to changes without awaiting async calls.

HIP4Signer interface

The signer argument you pass to initAuth must implement HIP4Signer:
This interface is compatible with:
  • viem PrivateKeyAccount (from privateKeyToAccount)
  • ethers Signer (v5 and v6)
  • Any other EIP-712-capable signer that returns a hex string or { r, s, v } object
Note that signer here is the agent key, not the user’s wallet. The agent has a different address from the user’s wallet by design.

Methods on adapter.auth

initAuth(walletAddress, signer)

Sets the adapter to "ready" state and stores the agent signer for use by the trading and wallet adapters.
Returns Promise<PredictionAuthState>.

getAuthStatus()

Returns the current auth state synchronously. Use this to gate UI elements or order flows.

clearAuth()

Resets the auth adapter to "disconnected" state. Call this on user logout or when the agent key is rotated.

Standalone functions

These functions are exported from @outcome.xyz/hip4 and are used to create and submit the one-time agent approval before calling initAuth.

getAgentApprovalTypedData(agentAddress, name, nonce, testnet)

Builds the EIP-712 typed data object for the user to sign when approving an agent. Returns the typed data object ready for walletClient.signTypedData.

submitAgentApproval(sig, agentAddress, name, nonce, testnet)

Submits the signed agent approval to Hyperliquid. After this call succeeds, the agent can sign orders on the user’s behalf. Returns Promise<{ success: boolean; error?: string }>. Check success before proceeding to initAuth.

Full agent approval flow

The following example shows the complete setup using viem. You run this flow once per user (or when rotating the agent key), then persist agentKey in secure storage.
The agent’s address differs from the user’s wallet address. The SDK does not validate that they match - this is intentional, since the agent signs on behalf of the user.