fix(eip712): don't truncate colon-namespaced type names in struct hashing#51
Merged
Merged
Conversation
…hing The eip-712 package's dependency walker matched type names against /^\w+/, intended to strip a trailing array suffix (Person[] -> Person) but actually truncating ANY type name at its first non-word character. Hyperliquid's dApp uses primaryType values like "HyperliquidTransaction:ApproveAgent" (and ~11 sibling actions - UsdSend, Withdraw, SpotSend, TokenDelegate, etc.) which all share this colon-namespaced convention. The truncated lookup found nothing in typedData.types, returned an empty dependency list, and encodeType crashed on typedData.types[undefined] - surfaced to users as a generic "Failed to sign typed ETH message". Patched via patch-package (patches/eip-712+1.0.0.patch): only strip a trailing array suffix via ARRAY_REGEX, otherwise use the type name verbatim. Added known-answer regression vectors for two Hyperliquid action types (ApproveAgent, UsdSend) plus a direct getDependencies unit check, so a future `yarn install` that drops the patch fails loudly.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Bug
Hyperliquid's dApp signs EIP-712 typed data with
primaryTypevalues like"HyperliquidTransaction:ApproveAgent"— a colon-namespaced type name. Thisis one of ~12 sibling action types Hyperliquid uses for user-signed actions
(
UsdSend,Withdraw,SpotSend,TokenDelegate,ApproveBuilderFee, etc.),all sharing this same naming convention (confirmed against the reference
hyperliquid-python-sdk signing.py).
ethereum.ts'sethSignTypedDatacalls into theeip-712npm package'sgetStructHash, whose dependency walker matched type names againstTYPE_REGEX = /^\w+/— intended to strip a trailing array suffix(
Person[]→Person) but actually truncating any type name at itsfirst non-word character.
"HyperliquidTransaction:ApproveAgent"truncatedto
"HyperliquidTransaction", which isn't a key intypedData.types, sogetDependenciesreturned an empty list,encodeTypedestructuredprimary = undefined, andtypedData.types[undefined].map(...)threw aTypeError— caught by a generic catch-all and surfaced to users as"Failed to sign typed ETH message".Fix
Patched via
patch-package(patches/eip-712+1.0.0.patch, applied to bothlib/cjsandlib/esbuilds): only strip a trailing array suffix via theexisting
ARRAY_REGEX, otherwise use the type name verbatim. This is ageneric fix — it covers every
HyperliquidTransaction:*action, not justApproveAgent.Tests
packages/hdwallet-keepkey/src/eip712-struct-hash.test.ts: added known-answervectors for
HyperliquidTransaction:ApproveAgentandHyperliquidTransaction:UsdSend(computed against the patched library, topin correctness of the actual hash output — not just "doesn't throw").
getDependenciesunit check for the colon-namespacedprimaryType.
(11/11 in the full struct-hash suite; 112/112 across the whole
hdwallet-keepkeypackage).