Skip to content

fix: evm typed data signing for non-standard eip712 payloads - #190

Merged
AryanCypherock merged 3 commits into
mainfrom
fix/walletconnect-hyperliquid
Aug 19, 2026
Merged

fix: evm typed data signing for non-standard eip712 payloads#190
AryanCypherock merged 3 commits into
mainfrom
fix/walletconnect-hyperliquid

Conversation

@AryanCypherock

Copy link
Copy Markdown
Collaborator

Problem

Signing EIP-712 typed data on the X1 fails for dapps like Hyperliquid (https://app.hyperliquid.xyz). Connecting via WalletConnect and signing the "Establish connection" request (`eth_signTypedData_v4`) never completes.

Root cause is three defects in the typed-data struct encoder (`packages/app-evm/src/utils/signTypeDataProcessor.ts`):

  1. Non-identifier struct type names crash type hashing. Hyperliquid's primary types contain a colon (e.g. `HyperliquidTransaction:ApproveAgent`). The `eip-712` package resolves type names with `/^\w+/`, truncating at the colon, which ends in `TypeError: Cannot read properties of undefined (reading 'map')`.
  2. Undeclared extra keys in `message` crash encoding. Real Hyperliquid actions carry `type` and `signatureChainId` keys that are not declared in `types`. The encoder iterated message keys, so the lookup for an undeclared key threw. Other wallet implementations (MetaMask, ethers, eth_account) ignore undeclared keys.
  3. Struct fields were encoded in message key order instead of declaration order. EIP-712 hashes fields in declaration order and the device hashes children in received order, so any payload whose JSON key order differs from the declared order produced an invalid signature (the canonical MetaMask v4 example payload, with an alphabetized domain, hit this).

Fix

  • Type hashes are computed internally with an exact-name type lookup, using the already-injected ethers library (`keccak256(encodeType)`); the `eip-712` package is no longer used and `setEip712Lib`/`getEip712Lib` are deprecated (exports kept for compatibility).
  • Struct children are built from the fields declared in `types`, in declaration order; undeclared message keys are ignored; a missing declared field throws a descriptive error instead of being silently skipped.

Verification

  • Existing fixtures: type hashes are byte-identical for all standard payloads (verified with a differential test against both the `eip-712` package and `ethers.TypedDataEncoder` — 38 + 24 comparisons across every struct node). Two fixtures that pinned message-key ordering now pin declaration ordering (leaf data verified unchanged, order only); one synthetic empty-message fixture was populated since missing declared fields are now an error.
  • New fixture: real-shape Hyperliquid `ApproveAgent` payload (colon type name + undeclared keys).
  • All 11 Hyperliquid payload types from the official SDK (ApproveAgent, UsdSend, SpotSend, Withdraw, UsdClassTransfer, SendAsset, TokenDelegate, ApproveBuilderFee, ConvertToMultiSigUser, SendMultiSig, L1 Agent) encode and round-trip through the protobuf wire format, with type hashes cross-checked against `ethers.TypedDataEncoder`.
  • `jest` 66/66, lint clean, build clean.

Note: the X0 path (`ethers.TypedDataEncoder` on the host) already handled these payloads; this brings the X1 path to parity. On-device E2E against app.hyperliquid.xyz is pending a hardware pass.

🤖 Generated with Claude Code

@changeset-bot

changeset-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a740a39

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@cypherock/sdk-app-evm Minor
nodejs-test Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment thread packages/app-evm/src/utils/eip712.ts Outdated
@AryanCypherock
AryanCypherock merged commit 3b85559 into main Aug 19, 2026
2 checks passed
@AryanCypherock
AryanCypherock deleted the fix/walletconnect-hyperliquid branch August 19, 2026 15:27
@github-actions github-actions Bot mentioned this pull request Aug 19, 2026
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