Skip to main content

eip712: Message classes for typed structured data hashing and signing in Ethereum

Project description

Quick Start

Message classes for typed structured data hashing and signing in Ethereum. See EIP-712 for details.

Dependencies

Installation

via pip

You can install the latest release via pip:

pip install eip712

via uv

You can clone the repository and use uv for the most up-to-date version:

git clone https://github.com/ApeWorX/eip712.git
cd eip712
uv sync --group dev

Quick Usage

Define EIP-712 models:

from eip712.messages import EIP712Message

# NOTE: It is **highly** recommended to use ABI types from this library
from eth_pydantic_types import abi

from pydantic import BaseModel


# You can define your inner nested types using normal Pydantic models
class Person(EIP712Type):
    # Define fields using types from the `abi` module
    name: abi.string
    wallet: abi.address


# All valid EIP712 Message Structs **must** subclass `EIP712Message`
class Mail(EIP712Message):
    #  to define your EIP712 domain configuration
    eip712_domain = EIP712Domain(
        name="Ether Mail",
        version="1",
        verifyingContract="0xDDdDddDdDdddDDddDDddDDDDdDdDDdDDdDDDDDDd",
        chainId=1,
    )

    # Struct fields (can be "basic" types, `BaseModel` types, or arrays of either)
    sender: Person
    # Dynamic array support is as easy as using `list` with the corresponding type
    receivers: list[Person]
    ttl: abi.uint256

Then initialize these models:

sender = Person(name="Alice", wallet="0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa")
receivers = [
    Person(name="Bob", wallet="0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"),
    Person(name="Charlie", wallet="0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"),
]
mail = Mail(sender=sender, receiver=receiver)

Finally, you can sign these messages using eth-account:

from eth_account import Account

acct = Account.from_key(private_key)
sig = acct.sign_message(mail.signable_message)

or natively in Ape:

# `ape console`
me = accounts.load(me)
sig = me.sign_message(mail)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eip712-0.3.3.tar.gz (61.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

eip712-0.3.3-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file eip712-0.3.3.tar.gz.

File metadata

  • Download URL: eip712-0.3.3.tar.gz
  • Upload date:
  • Size: 61.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for eip712-0.3.3.tar.gz
Algorithm Hash digest
SHA256 a27a4ba832ad9e2838e779170148478f271f7f093a603dd33e2a7bbf86aae7cd
MD5 eed96c651616d1c75a785f476f3c7ca4
BLAKE2b-256 25f704f45a50f4539dc259a6c45343861ba99c75c3d401b72d20b6350f5e01d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for eip712-0.3.3.tar.gz:

Publisher: publish.yaml on ApeWorX/eip712

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file eip712-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: eip712-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for eip712-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 45113f0d9aa85d5ef8b415957f962b58f47c5f9343998865ec831ad6c604aa21
MD5 a750a32cc8871d9eda3062c240652d20
BLAKE2b-256 fcd356e16f54b37bf013c304c66d6cdbe9f1ba8fe7799166873721d4e3519273

See more details on using hashes here.

Provenance

The following attestation bundles were made for eip712-0.3.3-py3-none-any.whl:

Publisher: publish.yaml on ApeWorX/eip712

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page