Skip to content

fix: infer EIP-712 primaryType in viem adapter - #2000

Open
Mabolla wants to merge 2 commits into
ProjectOpenSea:mainfrom
Mabolla:agent/fix-viem-adapter-primary-type
Open

fix: infer EIP-712 primaryType in viem adapter#2000
Mabolla wants to merge 2 commits into
ProjectOpenSea:mainfrom
Mabolla:agent/fix-viem-adapter-primary-type

Conversation

@Mabolla

@Mabolla Mabolla commented Aug 22, 2026

Copy link
Copy Markdown

Thanks for opening a PR!

We really appreciate you taking the time to contribute. It means a lot to the OpenSea team and the broader developer community.

A quick note about how this repo works

This repository is a read-only mirror of a package maintained in an internal monorepo. Because of that, pull requests cannot be merged directly here.

But don't worry -- your contribution won't be lost! Here's what happens next:

  1. Our team reviews every PR that comes in.
  2. If the change looks good, we'll recreate it internally in our monorepo.
  3. The fix will be synced back to this public repo on the next release.

We'll keep you posted on the PR as things progress.

Is this a bug report?

If you're reporting a bug rather than submitting a code fix, opening an issue is usually the fastest path to a resolution. Bug report issues help us triage and prioritize effectively.

Thanks again for helping make OpenSea better for everyone!

Summary

Fixes EIP-712 signing through the SDK's standard viem wallet adapter when a dependency struct appears before the actual root struct in the types object.

This is the same primary-type inference issue addressed for the separate Seaport bridge path in #1998, but src/provider/viem-adapter.ts has its own signTypedData() implementation and retained the same first-key heuristic.

Root cause

createViemSigner().signTypedData() selected the first non-EIP712Domain key as primaryType.

EIP-712 does not require the root struct to be declared first. For example, when Person is declared before Mail and Mail references Person, the correct primary type is Mail, but the viem adapter selected Person.

Changes

  • Infer the root EIP-712 struct by finding the named type that is not referenced by another struct.
  • Handle struct references through array types such as Person[].
  • Preserve the existing first-type fallback for cyclic or ambiguous type graphs.
  • Add a regression test specifically against the standard viem wallet adapter path.

Validation

  • Regression test fails before the fix because Person is selected instead of Mail.
  • Targeted regression test: 1/1 passed after the fix.
  • Full unit suite: 946/946 passed across 42 test files.
  • Targeted Biome check passes for the changed files.

Related

#1998 fixes the separate Seaport bridge implementation. This PR covers the standard viem adapter implementation in src/provider/viem-adapter.ts.

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.

1 participant