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

New Sign and Verify Messages Guide #2011

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

youssefea
Copy link

What changed? Why?

The current guides for signing and verifying messages in the Smart Wallet documentation are not sufficient to answer developers questions about the common issues they are facing.

Based on the existing code which describes components for Signing Simple and Typed Messages (Onchain and Offchain), a new guide has been written and reviewed.

Notes to reviewers

How has it been tested?

Locally

Copy link

vercel bot commented Mar 13, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
base-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 18, 2025 11:22am
web-base-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 18, 2025 11:22am

Copy link

vercel bot commented Mar 13, 2025

@youssefea is attempting to deploy a commit to the Coinbase Team on Vercel.

A member of the Team first needs to authorize it.

@cb-heimdall
Copy link
Collaborator

cb-heimdall commented Mar 13, 2025

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 1/2
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 1
Sum 2


Blockchain-based apps use wallet signatures for two main categories:

1. **Signatures for offchain verification**: Used for authenticating users in dApps (e.g., Sign-In with Ethereum) to avoid spoofing. The signature is not used for any onchain action.
Copy link
Contributor

Choose a reason for hiding this comment

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

"dApp" -> "app"

We avoid common web3 jargon (including the word web3 which we always convert to onchain). Even if its onchain its still an app

Copy link
Author

Choose a reason for hiding this comment

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

changed to onchain app


- Your project can use Wagmi/Viem
- You're signing an offchain message
- Your smart wallet can be deployed or undeployed (methods are ERC-6492 compatible)
Copy link
Contributor

Choose a reason for hiding this comment

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

capitalize Smart Wallet

Copy link
Author

Choose a reason for hiding this comment

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

done

if (!signature || !account.address || !client) return;

client
.verifyMessage({
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be worth adding a note after the code block or a comment in the code block calling out that wagmi's publicClient.verifyMessage handles verification of both EOA signatures and smart contract wallet signatures and that this is not always the case when using other frameworks.

Copy link
Author

Choose a reason for hiding this comment

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

added after code block and renamed that section and added details that this is Sign in with ethereum as well as referecing the eip involved (https://eips.ethereum.org/EIPS/eip-4361)


### Signing a Simple Message

The following example demonstrates how to implement basic message signing using a Smart Wallet:
Copy link
Contributor

Choose a reason for hiding this comment

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

Call out that the simple message is a SIWE message since this is a common use case

Copy link
Author

Choose a reason for hiding this comment

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

Done as per comment before

- For non-Viem implementations, see alternative approaches below

:::info
There is an example implementation of Permit2 using Wagmi in the [wagmi-scw repository](https://github.com/wilsoncusack/wagmi-scw/blob/main/src/components/Permit2.tsx).
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice use of existing working example 👍


### Server-side Verification

You can handle server-side verification using NextJS edge functions such as shown [here](https://github.com/youssefea/ethden2025-sign-tx-csw/blob/main/src/app/api/verify/route.ts):
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious, why have the link to the github and have the code block below? When I see the link my assumption is I have to navigate to it to get the information but then its also below.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see they're different. Is the code block below necessary? It isn't explicitly necessary to store the signature in a DB right?

I think it would make more sense to show the linked code block in the block below (and call out that its using viem instead of wagmi since its server side)

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, this was a mistake. I wanted to show the same code, no database storage. I fixed it.

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.

3 participants