Skip to content

fix(siwe): accept punycode top-level domains in createSiweMessage - #5291

Closed
mortezashojaei wants to merge 2 commits into
wevm:mainfrom
mortezashojaei:fix/siwe-punycode-tld
Closed

mortezashojaei wants to merge 2 commits into
wevm:mainfrom
mortezashojaei:fix/siwe-punycode-tld

Conversation

@mortezashojaei

Copy link
Copy Markdown
Contributor

createSiweMessage rejects any domain whose top-level domain is internationalized. These TLDs are written in their ASCII (punycode) form, like xn--p1ai for .рф, but the domain check only allows letters in the last label:

createSiweMessage({ ...message, domain: 'example.xn--p1ai' })
// SiweInvalidMessageFieldError: Invalid Sign-In with Ethereum message field "domain".
// - Domain must be an RFC 3986 authority.

example.xn--p1ai is a valid RFC 3986 authority, which is what EIP-4361 requires and what the error message itself asks for. It is also a real, registrable domain. Punycode below the TLD already works (xn--fsq.com is accepted), and parseSiweMessage already parses these domains, so only message creation is affected. Sites on TLDs like .рф or .中国 currently can't create a SIWE message at all.

This lets the last label be either letters (as today) or a punycode A-label: xn-- followed by letters, digits or hyphens, not ending in a hyphen. It's the same kind of widening as #2351, which made example.co.uk pass. Nothing else changes: single-label hosts other than localhost, IPv6 literals and trailing dots are still rejected as before.

Added a case to the existing parameters: domain test. It fails on main and passes with this change, and the rest of the SIWE tests pass unchanged.

@changeset-bot

changeset-bot Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3f8e555

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

This PR includes changesets to release 1 package
Name Type
viem 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

@vercel

vercel Bot commented Oct 24, 2026

Copy link
Copy Markdown

@mortezashojaei is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

@pkg-pr-new

pkg-pr-new Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/viem@5291

commit: 3f8e555

jxom commented Oct 26, 2026

Copy link
Copy Markdown
Member

Thanks @mortezashojaei, this fix is correct. Closing in favor of #5299, which carries both of your commits unchanged (authorship kept). It also caps the letter-only TLD branch at 63 characters to match the new xn-- branch.


Generated by Claude Code

@jxom jxom closed this Oct 26, 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