Skip to content

Viem signer passes NaN chainId when typed-data domain omits chainId #1994

Description

@omerbek

Bug

The viem adapter converts the typed-data domain chain id with Number(domain.chainId) unconditionally:

chainId: Number(domain.chainId),

When callers sign typed data whose domain intentionally omits chainId, this passes NaN into walletClient.signTypedData. That is different from the ethers adapter, which forwards the domain as provided, and from the seaport bridge in this repo, which already treats domain.chainId as optional.

Expected behavior

If domain.chainId is absent, the viem adapter should omit chainId / pass undefined rather than materializing NaN.

Why this matters

EIP-712 domains can omit optional fields. Passing NaN makes the viem entry point reject or sign a malformed domain for otherwise valid typed-data payloads that do not include a chain id.

Suggested fix

Use the same optional handling as src/provider/seaport-bridge.ts:

chainId: domain.chainId ? Number(domain.chainId) : undefined,

and add a regression test that calls the viem signer with a domain without chainId and asserts the forwarded domain uses chainId: undefined rather than NaN.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions