Skip to content

Add EIP-712 Typed Data Support#264

Merged
alisinabh merged 3 commits into
mainfrom
eip712
Jul 17, 2026
Merged

Add EIP-712 Typed Data Support#264
alisinabh merged 3 commits into
mainfrom
eip712

Conversation

@alisinabh

Copy link
Copy Markdown
Member

Adds first-class EIP-712 typed structured data: construct, hash, sign, and verify.

What's new

  • Ethers.TypedData — build typed data from maps, or from native structs via a use Ethers.TypedData.Schema DSL (typed_schema/field).
  • Hashing engineencode_type, type_hash, hash_struct, domain_separator, and the signing digest.
  • SigningEthers.sign_typed_data/2 (+!) via Signer.Local (r‖s‖v) and Signer.JsonRPC (eth_signTypedData_v4).
  • Recover/verifyEthers.TypedData.recover_signer/2 and valid_signature?/3.
  • Guide (guides/eip-712.md), README, and CHANGELOG updates.

Correctness

Pinned to external vectors: matches the EIP-712 spec's Mail digest 0xbe609aee…, cross-checked against ethers.js v6.17.0, and the local signature is byte-for-byte equal to anvil's eth_signTypedData_v4. No new dependencies.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class EIP-712 typed structured data support to the Ethers codebase, including schema-based typed data construction, hashing/encoding primitives, signing via local and JSON-RPC signers, and signer recovery/verification, plus documentation and test vectors to pin correctness to the EIP-712 spec and ethers.js.

Changes:

  • Introduces Ethers.TypedData (+ Domain, Field, Encoder) and a Ethers.TypedData.Schema DSL to construct typed data from maps or native structs.
  • Adds typed-data signing support via Ethers.sign_typed_data/2 for Signer.Local and Signer.JsonRPC (eth_signTypedData_v4), plus recover/verify helpers.
  • Adds extensive unit tests and user-facing docs (guide + README + changelog) including pinned known-good vectors.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/support/eip712_schemas.ex Adds shared schema modules used by doctests/examples.
test/ethers/typed_data/schema_test.exs Tests the schema DSL struct generation and introspection/guardrails.
test/ethers/typed_data/schema_expansion_test.exs Tests struct-to-typed-data expansion and hashes vs hand-built payloads.
test/ethers/typed_data/encoder_test.exs Pins EIP-712 hashing engine outputs to spec/ethers.js vectors.
test/ethers/typed_data_test.exs Tests typed data construction, normalization, and validation rules.
test/ethers/typed_data_signing_test.exs Tests end-to-end typed-data signing + recovery + verification.
test/ethers/typed_data_json_test.exs Tests JSON serialization compatibility for eth_signTypedData_v4.
test/ethers/signer/local_test.exs Adds deterministic typed-data signing tests for the local signer.
test/ethers/signer/json_rpc_test.exs Adds typed-data signing tests for JSON-RPC signer output shape/error cases.
README.md Documents how to build/sign/verify EIP-712 typed data.
mix.exs Adds EIP-712 guide to docs and groups Typed Data modules in ExDoc.
lib/ethers/typed_data/schema.ex Implements compile-time schema DSL and struct expansion to typed-data params.
lib/ethers/typed_data/field.ex Introduces TypedData.Field normalization struct.
lib/ethers/typed_data/encoder.ex Implements EIP-712 encodeType/hashStruct/domain separator/digest engine.
lib/ethers/typed_data/domain.ex Introduces TypedData.Domain and canonical present-field ordering.
lib/ethers/typed_data.ex Adds public typed-data API: build/validate/hash/serialize/recover/verify.
lib/ethers/signer/local.ex Adds typed-data signing (r‖s‖v) to the local signer.
lib/ethers/signer/json_rpc.ex Adds eth_signTypedData_v4 support to the JSON-RPC signer.
lib/ethers/signer.ex Extends signer behaviour with optional sign_typed_data/2 callback.
lib/ethers.ex Adds sign_typed_data/2 and sign_typed_data!/2 entry points.
guides/eip-712.md Adds a full walkthrough guide for typed data construction/hashing/signing.
CHANGELOG.md Announces EIP-712 typed data feature and schema DSL in Unreleased.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/ethers/signer/json_rpc.ex
Comment thread lib/ethers.ex
Comment thread lib/ethers/typed_data.ex
- Ethers.sign_typed_data/2: return {:error, :not_supported} instead of
  crashing with UndefinedFunctionError when the resolved signer does not
  implement the optional sign_typed_data/2 callback (scoped rescue; other
  UndefinedFunctionErrors are re-raised).
- Signer.JsonRPC.sign_typed_data/2: return {:error, :missing_from_address}
  instead of raising KeyError when :from is absent, honoring the callback's
  {:ok, _} | {:error, _} contract.
- TypedData.recover_signer/2: return {:error, :invalid_signature} on
  malformed input (bad length/hex) instead of raising, matching the
  documented return and making valid_signature?/3 robust; also accept v as
  raw parity (0/1) in addition to 27/28 for wider signer interoperability.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@alisinabh
alisinabh merged commit 968481c into main Jul 17, 2026
5 checks passed
@alisinabh
alisinabh deleted the eip712 branch July 17, 2026 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants