Bourse.Signing.EIP712 (bourse v0.1.0)

Copy Markdown View Source

Minimal EIP-712 typed-data encoder for the custom DEX signing modules (Bourse.Signing.Hyperliquid).

Implements canonical EIP-712 encoding for the atomic-field message types Hyperliquid uses (Agent, HyperliquidTransaction:*). The result is the EIP-712 digest preimage 0x1901 ‖ domainSeparator ‖ hashStruct, as defined by EIP-712.

Scope

Only atomic field types are supported (string, bytes, bytes32, address, bool, uint*, int*). Struct-typed fields (nested custom types) raise — none of the supported Hyperliquid message types use them, so a nested type is a programming error rather than a silent wrong signature.

The EIP712Domain type is rendered in ethers' canonical field order (name, version, chainId, verifyingContract, salt), including only the fields present in the supplied domain.

Summary

Functions

Computes the 32-byte EIP-712 domain separator for domain.

Encodes typed data into the EIP-712 digest preimage 0x1901 ‖ domainSeparator ‖ hashStruct(primaryType, message).

Computes hashStruct(primaryType) = keccak256(typeHash ‖ encodeData).

Types

domain()

@type domain() :: %{optional(String.t()) => term()}

field()

@type field() :: %{required(String.t()) => String.t()}

Functions

domain_separator(domain)

@spec domain_separator(domain()) :: binary()

Computes the 32-byte EIP-712 domain separator for domain.

encode(domain, types, primary_type, message)

@spec encode(domain(), %{required(String.t()) => [field()]}, String.t(), map()) ::
  binary()

Encodes typed data into the EIP-712 digest preimage 0x1901 ‖ domainSeparator ‖ hashStruct(primaryType, message).

hash_struct(primary_type, types, message)

@spec hash_struct(String.t(), %{required(String.t()) => [field()]}, map()) :: binary()

Computes hashStruct(primaryType) = keccak256(typeHash ‖ encodeData).