feat: support optional domain fields (nil verifying_contract)#2
Open
mdon wants to merge 1 commit into
Open
Conversation
Per the EIP-712 spec, domain fields like `verifyingContract` and `salt` are optional. Previously, passing `nil` for `verifying_contract` in the Domain struct would crash with `FunctionClauseError` in `EIP712.Util.pad/2` because `nil` is not a binary. This change: - Makes `domain_type/1` accept a Domain struct and only include non-nil fields in the type hash (matching the EIP-712 spec behavior) - Updates `serialize_keys/1` to filter out nil-valued fields - Updates `domain_seperator/1` to pass the domain to `domain_type/1` - Keeps backwards compatibility: `domain_type/0` (no args) still returns all fields This is needed for protocols like Polymarket whose ClobAuth domain only has 3 fields (name, version, chainId) without verifyingContract. All existing doctests pass unchanged.
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.
Problem
Passing
nilforverifying_contractin the Domain struct crashes withFunctionClauseErrorinEIP712.Util.pad/2:Per the EIP-712 spec, domain fields like
verifyingContractandsaltare optional — protocols should be able to omit them from the domain type hash entirely.This is needed for protocols like Polymarket whose
ClobAuthdomain only has 3 fields (name,version,chainId) withoutverifyingContract.Changes
domain_type/1now accepts aDomainstruct and only includes non-nil fields in the type definition (used for the type hash)serialize_keys/1filters out nil-valued fields instead of including themdomain_seperator/1passes the domain struct todomain_type/1domain_type/0(no args) still returns all fields for backwards compatibilityVerification
verifyingContract) — domain separator matches the Pythonpy-clob-clientreference implementation