Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump @spruceid/siwe-parser to 2.1.0 #4141

Merged
merged 3 commits into from
Apr 11, 2024
Merged

Conversation

NicholasEllul
Copy link
Contributor

@NicholasEllul NicholasEllul commented Apr 10, 2024

Explanation

This pull request bumps the siwe-parser to the latest version which adds additional support for the scheme parameter. I also refactor the tests to explicitly call the siwe-parser library to act as a smoke test that can catch any issues in the future. This will make breaking changes easier to catch.

References

https://github.com/MetaMask/MetaMask-planning/issues/2278

Changelog

None

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

@NicholasEllul NicholasEllul requested a review from a team as a code owner April 10, 2024 17:08
Copy link

socket-security bot commented Apr 10, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/apg-js@4.1.3 filesystem 0 1.45 MB ldthomas
npm/valid-url@1.0.9 None 0 17.2 kB odysseas

🚮 Removed packages: npm/apg-js@4.3.0

View full report↗︎

@NicholasEllul
Copy link
Contributor Author

Each commit takes a different approach to testing.

In the first commit, I am explicit about the expected return values within the code. However, comparing them to the output of the detectSIWE function is not straightforward due to the fact that a valid ParsedMessage object according to the type has no undefined fields. However, the object we get back from calling new ParsedMessage() does have undefined fields.

In the second commit, I switch this to be less explicit, but easier test maintainability/cleaner code. This is what i'm proposing in the final changes. Open to discussion if anyone feels strongly about the approach.

@@ -251,12 +240,12 @@ describe('siwe', () => {
origin,
})}`, () => {
const result = isValidSIWEOrigin({
from: '0x0',
from: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing due to the fact the previous value was not a valid EIP-55 address which is required for SIWE: https://eips.ethereum.org/EIPS/eip-4361#abnf-message-format

address = "0x" 40*40HEXDIG
; Must also conform to capitalization
; checksum encoding specified in EIP-55
; where applicable (EOAs).

Copy link
Contributor

@witmicko witmicko left a comment

Choose a reason for hiding this comment

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

LGTM!

@NicholasEllul NicholasEllul merged commit 498e748 into main Apr 11, 2024
139 checks passed
@NicholasEllul NicholasEllul deleted the ellul/bump-siwe-parser branch April 11, 2024 16:14
digiwand added a commit to MetaMask/metamask-extension that referenced this pull request Apr 24, 2024
#24138)

## **Description**

Resolves @spruceid/siwe-parser 1.1.3 → 2.1.0 The updated
@spruceid/siwe-parser allows `http` and `https` schemas in a transaction
message's URL.

Additional changes are included in the @spruceid/siwe-parser upgrade
from v1.1.3 → v2.1.0. One important update is the requirement of
[EIP-55](https://npmfs.com/package/@spruceid/siwe-parser/1.1.3/lib/abnf.ts)
complaint addresses. This means that if a dapp attempts to sign a
`personal_sign` message with a from address that is not EIP-55
compliant, SIWE will not be detected. This is what we want as
[EIP-4361](https://eips.ethereum.org/EIPS/eip-4361) enforces EIP-55
addresses. There's a separate ticket that'll warn users if a
`personal_sign` message looks like a SIWE but doesn't parse to a SIWE
message: #24128

Issue to update test-dapp SIWE addresses to be EIP-55 complaint:
MetaMask/test-dapp#326

Related Links (Thanks @NicholasEllul for these): 
- https://app.warp.dev/block/4eE6QC12lVuwARbpFj62VJ 
- https://npmfs.com/package/@spruceid/siwe-parser/1.1.3/lib/abnf.ts

## **Related issues**

Fixes: MetaMask/MetaMask-planning#2256
Relates To: MetaMask/MetaMask-planning#2278

Related to: #24107
Related to: MetaMask/core#4153
Related to: MetaMask/core#4141

## **Manual testing steps**

1. Go to the metamask test-dapp or run the test-dapp locally
2. When testing locally, optionally update the from addresses used by
the buttons
3. Test Sign-in With Ethereum buttons
4. Observe MM


## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

---------

Co-authored-by: MetaMask Bot <metamaskbot@users.noreply.github.com>
Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
Co-authored-by: Nicholas Ellul <nicholas.ellul1@gmail.com>
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