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

Release 2.0.3 #76

Merged
merged 6 commits into from
May 11, 2022
Merged

Release 2.0.3 #76

merged 6 commits into from
May 11, 2022

Conversation

w4ll3
Copy link
Member

@w4ll3 w4ll3 commented May 11, 2022

This updates the library to have a consistent behaviour of SIWE message parsing, creation and verification. For message parsing, siwe-parser is used. It enables domain, nonce and time-based verification. Time-based means that it is now possible to check the not-before and expiration-date from the SIWE message properties against a given time.

This update introduces the following breaking changes and implements more strict checks from the EIP-4361 specification:

  • validate(…) was renamed to validateMessage() and now is private. Use verify(…) instead, which enforces signature verification and allows for domain, nonce or time-based verification.
  • ethers became a peer dependency.
  • EIP-55 validation of EIP-155 is enforced, non-EIP-155 messages are considered as invalid.
  • removed type and signature properties from SiweMessage
  • not-before message field is now being checked
  • the verify(params, provider) function takes an object as params defined as:
export interface VerifyParams {
    /** Signature of the message signed by the wallet */
    signature: string;

    /** RFC 4501 dns authority that is requesting the signing. */
    domain?: string;

    /** Randomized token used to prevent replay attacks, at least 8 alphanumeric characters. */
    nonce?: string;

    /**ISO 8601 datetime string of the current time. */
    time?: string;
}

So to migrate to the newest version change validate(signature) to verify({ signature: signature }).

  • the new verify(...) function now returns an object SiweResponse defined as:
export interface SiweResponse {
    /** Boolean representing if the message was verified with success. */
    success: boolean;

    /** If present `success` MUST be false and will provide extra information on the failure reason. */
    error?: SiweError;

    /** Original message that was verified. */
    data: SiweMessage;
}

So instead of try catch blocks, just check if success is true, and if false check for error. data will always be the message verified.

This update introduces more granular error types in case verification or message parsing failed:

  • EXPIRED_MESSAGE
  • INVALID_DOMAIN
  • DOMAIN_MISMATCH
  • NONCE_MISMATCH
  • INVALID_ADDRESS
  • INVALID_URI
  • INVALID_NONCE
  • NOT_YET_VALID_MESSAGE
  • INVALID_SIGNATURE
  • INVALID_TIME_FORMAT
  • INVALID_MESSAGE_VERSION
  • UNABLE_TO_PARSE

Copy link
Contributor

@skgbafa skgbafa left a comment

Choose a reason for hiding this comment

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

The changes look good to me. Ran the package and tests locally, successfully.

@w4ll3 w4ll3 marked this pull request as ready for review May 11, 2022 15:01
@w4ll3 w4ll3 requested review from awoie and wyc May 11, 2022 15:01
Copy link

@awoie awoie left a comment

Choose a reason for hiding this comment

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

have we made sure to update README.md accordingly? otherwise looks good.

@w4ll3
Copy link
Member Author

w4ll3 commented May 11, 2022

have we made sure to update README.md accordingly? otherwise looks good.

Not really sure what changes would be needed for the README

@w4ll3 w4ll3 requested a review from awoie May 11, 2022 18:24
Copy link

@awoie awoie left a comment

Choose a reason for hiding this comment

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

lgtm

@w4ll3 w4ll3 merged commit 7a5dd34 into main May 11, 2022
@w4ll3 w4ll3 deleted the release/2.0.3 branch May 11, 2022 19:02
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.

4 participants