Conversation
Contributor
There was a problem hiding this comment.
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 aEthers.TypedData.SchemaDSL to construct typed data from maps or native structs. - Adds typed-data signing support via
Ethers.sign_typed_data/2forSigner.LocalandSigner.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.
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 ause Ethers.TypedData.SchemaDSL (typed_schema/field).encode_type,type_hash,hash_struct,domain_separator, and the signing digest.Ethers.sign_typed_data/2(+!) viaSigner.Local(r‖s‖v) andSigner.JsonRPC(eth_signTypedData_v4).Ethers.TypedData.recover_signer/2andvalid_signature?/3.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'seth_signTypedData_v4. No new dependencies.