Skip to content

fix: parse SIWE Chain ID from the structured field only - #424

Open
o-mid wants to merge 3 commits into
reown-com:developfrom
o-mid:fix/siwe-chain-id-parse
Open

fix: parse SIWE Chain ID from the structured field only#424
o-mid wants to merge 3 commits into
reown-com:developfrom
o-mid:fix/siwe-chain-id-parse

Conversation

@o-mid

@o-mid o-mid commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Hey @ignaciosantise / Reown team — getChainIdFromMessage was taking the first Chain ID: <digits> anywhere in the SIWE text.

If the statement says something like "Please use Chain ID: 137", AppKit then sends personal_sign on Polygon even when the real field is Chain ID: 1. This now only reads lines that start with Chain ID: .

Test plan

  • cd packages/reown_sign && flutter test test/auth/signature_test.dart
  • SIWE statement mentions another chain; signing still uses the structured Chain ID line

A statement that mentioned another chain used to win the first regex match and send personal_sign to the wrong network.
Copilot AI lite review requested due to automatic review settings September 5, 2026 07:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The updated chain-id parser can now return non-numeric values if the structured Chain ID: line contains trailing text, which regresses prior digits-only behavior and can break downstream chain-id validation/routing.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR fixes SIWE chain-id extraction so getChainIdFromMessage no longer picks up Chain ID: <digits> occurrences embedded in the free-form statement, and instead only considers lines that start with Chain ID: (the structured field).

Changes:

  • Update AuthSignature.getChainIdFromMessage to scan line-by-line for a Chain ID: -prefixed field.
  • Add a regression test where the statement mentions another chain id, ensuring the structured Chain ID is used.
  • Document the fix in packages/reown_sign changelog (1.4.1).
File summaries
File Description
packages/reown_sign/lib/utils/auth_signature.dart Adjusts SIWE chain-id parsing to avoid matching statement text.
packages/reown_sign/test/auth/signature_test.dart Adds coverage for statements that mention a different chain id.
packages/reown_sign/CHANGELOG.md Notes the SIWE chain-id parsing fix in a new release entry.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/reown_sign/lib/utils/auth_signature.dart
@o-mid

o-mid commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

@ignaciosantise this is the greedy SIWE regex — a statement that mentions another chain was winning over the real Chain ID: line and sending personal_sign to the wrong network. Happy to tweak if you'd rather keep the old \d+ restriction as well.

@o-mid

o-mid commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

@ignaciosantise still merge-ready after catching latest develop. Please approve/apply when you can.

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