feat(user_worker): SIWE core — EIP-4361 parser, EIP-191 ecrecover, EIP-55, RFC3339 (UNIT 1)#2
Merged
Merged
Conversation
…over, EIP-55, RFC3339)
UNIT 1: replace the siwe.rs stub with a pure, host-testable implementation:
- strict line-oriented EIP-4361 parser (ordered fields, optional statement /
Expiration Time, tolerated Not Before / Request ID / Resources)
- keccak256 + EIP-191 personal_sign address recovery via k256 (low-s
normalization with recovery-id parity flip, v in {0,1,27,28})
- EIP-55 checksum encoding
- hand-rolled RFC 3339 -> epoch seconds (Z / numeric offsets / fractional
seconds, days-from-civil)
In-file unit tests: ecrecover roundtrip incl. v=27, EIP-55 official vectors,
parser accept/reject cases, RFC 3339 vectors.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Implements UNIT 1 of the SIWE user system by replacing the prior siwe.rs stub with a pure, host-testable implementation covering EIP-4361 parsing, EIP-191 signature recovery (ecrecover), EIP-55 address checksumming, and RFC3339-to-epoch parsing, along with unit tests.
Changes:
- Added a strict, line-oriented EIP-4361 (
parse_siwe) parser with ordered required fields and tolerated trailing fields. - Implemented crypto helpers:
keccak256, EIP-191 digest +recover_address, andto_checksum(EIP-55). - Added a hand-rolled
parse_rfc3339_epochand comprehensive unit tests for all components.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+251
to
+254
| if !(1..=12).contains(&month) || !(1..=31).contains(&day) || hour > 23 || min > 59 || sec > 59 | ||
| { | ||
| return None; | ||
| } |
Comment on lines
+206
to
+219
| let hex_part = addr_lower.strip_prefix("0x").unwrap_or(addr_lower); | ||
| let hash = keccak256(hex_part.as_bytes()); | ||
| let mut out = String::with_capacity(42); | ||
| out.push_str("0x"); | ||
| // `.take(64)` bounds the hash index for over-long (invalid) inputs. | ||
| for (i, c) in hex_part.chars().enumerate().take(64) { | ||
| let nibble = if i % 2 == 0 { hash[i / 2] >> 4 } else { hash[i / 2] & 0xf }; | ||
| if c.is_ascii_alphabetic() && nibble >= 8 { | ||
| out.push(c.to_ascii_uppercase()); | ||
| } else { | ||
| out.push(c); | ||
| } | ||
| } | ||
| out |
Comment on lines
+185
to
+192
| let digest = keccak256( | ||
| &[ | ||
| b"\x19Ethereum Signed Message:\n", | ||
| message.len().to_string().as_bytes(), | ||
| message.as_bytes(), | ||
| ] | ||
| .concat(), | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
UNIT 1 of the SIWE user system: replaces the `user_worker/src/siwe.rs` stub with a pure, host-testable implementation. No `worker` imports; public signatures unchanged from the frozen scaffold.
Test plan
🤖 Generated with Claude Code