hashtagstruct_hash

Compute EIP-712 struct hash for TxSeismic

Compute the EIP-712 struct hash for a TxSeismic transaction.

Overview

struct_hash() computes the EIP-712 struct hash by encoding all transaction fields according to the EIP-712 specification. Dynamic types (like bytes) are hashed, while static types are left-padded to 32 bytes.

Signature

def struct_hash(tx: UnsignedSeismicTx) -> bytes

Parameters

Parameter
Type
Required
Description

tx

Yes

The unsigned Seismic transaction

Returns

Type
Description

bytes

32-byte keccak256 hash of the encoded struct

Examples

Basic Usage

from seismic_web3 import struct_hash, UnsignedSeismicTx

unsigned_tx = UnsignedSeismicTx(...)

# Compute struct hash
hash_value = struct_hash(unsigned_tx)

print(f"Struct hash: {hash_value.hex()}")
print(f"Length: {len(hash_value)} bytes")  # Always 32

Use in Signing Hash

Compare Different Transactions

Debug Field Encoding

How It Works

The function computes:

Field Encoding

Static Types (Left-Padded to 32 Bytes)

  • uint64 - chain_id, nonce, gas (gasLimit), expires_at_block

  • uint128 - gas_price

  • uint256 - value

  • uint96 - encryption_nonce (converted from 12 bytes to integer)

  • uint8 - message_version

  • bool - signed_read (0 or 1)

  • address - to (left-padded 12 bytes + 20-byte address, or 32 zero bytes if None)

  • bytes32 - recent_block_hash (already 32 bytes)

Dynamic Types (Hashed with keccak256)

  • bytes - data (encrypted calldata)

  • bytes - encryption_pubkey (33-byte compressed public key)

Implementation

Type Hash

The TX_SEISMIC_TYPE_HASH is the keccak256 hash of the type string:

Notes

  • Always 32 bytes (keccak256 output)

  • Encodes all transaction fields deterministically

  • Dynamic types (bytes) are hashed before inclusion

Encoding Details

encryption_nonce Conversion

The 12-byte EncryptionNonce is converted to a uint96 integer:

Then encoded as a 32-byte padded integer.

Address Encoding

Addresses are left-padded to 32 bytes:

  • Regular address: 0x000000000000000000000000 + <20-byte address>

  • None (contract creation): 0x0000000000000000000000000000000000000000000000000000000000000000

Boolean Encoding

Booleans are encoded as 32-byte integers:

  • True0x0000000000000000000000000000000000000000000000000000000000000001

  • False0x0000000000000000000000000000000000000000000000000000000000000000

See Also

Last updated