Connect Wallet !== Sign In - t.mirror.xyz awkweb.eth
web3con 2022 · 5 Mar 2022 · 13:32
Tom, front-end lead at Mirror and author of the wagmi React hooks library for Ethereum, explains why connecting a wallet is not the same as signing in. He walks from a simple wallet connection through message signing to Sign-In with Ethereum (EIP-4361), showing how nonces, origins and expiry prevent spoofing and replay attacks, and how standard messages enable sessions and clearer wallet prompts for secure web3 apps.
Topics
From web3con 2022, hosted by Developer DAO.
Transcript
this talk is sponsored by radical radical is a peer-to-peer stack for building software together built on protocols instead of platforms radical provides creators with the secure and unsensible code infrastructure tools for collective code governance and new ways to earn for open source work learn more at radical.xyz hi everyone welcome to connect wallet does not equal sign in excited to have this time at web3 con to chat about how we can replace web2 off methods and providers with web3 connect wallet and also talk about some common
misconceptions and how to build secure rich web 3 apps this way but first before we get started gm i'm tom i'm the front-end lead at mirror which is a web3 publishing platform i'm also the author of wagney which is a react hooks library for ethereum and you can find me in various places at aqua so let's start again here we have a humble connect wallet button stands for the promise of building new systems um decentralized ownership owning your own data all these great things it's probably one of the first things you do when building a new web3 app
is you set this up it's up against the existing system of doing things off methods that people are used to using things like connecting email and then these social providers google facebook apple these are pretty easy they allow people to build web apps they've been used for a long time and how do we how do we get people to feel good about this if not better about using connex wallet so let's talk about connect wallet from first principles so what is it
an app request access to a wallet you select the connect wallet button what happens next is user can approve or reject that request in your browser extension or your mobile wallet app once it's approved the app opens up a connection with that wallet and this is really important because once a wallet is connected and i can make further requests and interact with the network either things like creating signatures sending transactions interacting with contracts minting nfts swapping tokens on uniswap things like that but if we're comparing this to
the standard of web 2 methods it falls a little bit short it doesn't necessarily do everything that we need on our own particularly authentication am i am i who i say i am like identity and authorization do i have like permission and access to do certain things so outside of building like a really simple uh web3 app connect wallet falls a little short anyone can spoof an address so you can't necessarily verify identity with connect wallet alone and similarly you can't necessarily give people access to store and access like
sensitive data based on a connect wallet thing we don't necessarily know someone is operating and has the permissions to do exactly what they should based on the wall being connected so that brings us to an evolution which maybe you've seen before is you connect your wallet to a web 3 app and then you're asked to sign this message and the message is usually text and it says something like please sign this message to connect to mirror and so you sign it and sort of like what is this again from first principle this will again you connect your wallet
you sign the message uh cryptographically usually this is personal sign method so it shows up as text in your wallet provider it's like easy to read and see what it's doing and then like once you sign the message the app will verify that the signature is valid it will take the signature and the message and check to see that the recovered address is the same as the wallet connection so why is this interesting what else is to prove ownership of a wallet or like the private keys that exist within the wallet you know that this person is who they say they are and then what's cool is this can
extend now to other primitives which is like once you know that this person controls this wallet then it's like you can check to see do they control this token or this nft interesting things like that so when comparing to again our web 2 methods this doesn't necessarily make it on its own it's a little bit better than connect wallet we're able to verify identity now um but we can't necessarily like store and access data based on this we don't necessarily know that it's not it doesn't it's not resistant to things like replay attacks where it's like you
take that text message where it's like i want to connect my wallet or sign into xyz site an attacker could do the same thing um because it's not unique they could fish you you could they could get you to go to a website that looks like the one that you want to go to like open c for example and then just get you to sign the same message that they have and then once once you've signed that then they can use that on sites that have the same message to interact on your behalf so as an evolution here is something called signing with ethereum
and so maybe you've seen what this is but it's pretty similar to the combination of connect wallet and personal sign that we saw before here you do a personal sign with a little bit different message so instead of it being just a plain text message we try to add in some structured unique data in here so you see we'll have things like the origin uri where the message is getting signed um and then like that matches up with the the site that you're on at that moment maybe things like the ethereum network the chain id that you're connecting to a unique nonce
which prevents and makes it resistant from replay attacks and then there could be some other fields too like when the message was issued when it should expire these type of things and so let's talk about this real quick again from first principles to understand it some more so it looked pretty similar to signing the message you connect to wallet this step you sign a message but instead of it just being a plain message you're signing this standardized sign in with ethereum message which has some unique information and in it once the message is verified what you can do is add it to a session or like
confirm the message in middleware this is if you have like an api and you're building like a rich web 3 app with some off chain data like user preferences that you want to access it's like you have a persistent session so why is this interesting important what else is to standardize message signing across certain fields and data with this eip fourth 430 or 4361 um which lays out uh how a message should be formatted
uh what information it should have and how to make sure you're validating it and doing secure things with it and this is really cool because not only does it have a standard that everyone can use but instead of using personal assign which we've done in the past we can switch to signing type data instead and you could imagine wallet providers having like a really nice ui presentation for that so in metamask or rainbow or another wall provider instead of there being a text message that you read it just says like would you like to sign into mirror.xyz
um maybe there's a button to view more details if you want to like inspect the message and then it has like a like a cancel or sign in button in the bottom of it um and then alternatively if you're not on the correct origin or the wallet provider suspects that there's something malicious it can also show like a typed uh like prompt with like some info about like hey like this is probably spam or like danger something bad could happen if you sign this basically just having a standard allows everyone to align and show better interface or better in
product experiences for web3 another thing that's really cool is this allows us to keep track of sessions once the message is signed we can validate it across origin like you like website address but then also using like expiration too so like you know we can check to see if the message is expired in the future this could also be used to like grant granular permissions to apps so maybe you're only allowed to request their balance or some specific information that is stored in like a vault somewhere so we're comparing this to
the web 2 methods that we talked about earlier this does a really good job it allows us to verify the identity just like signing messages does it also allows us to securely store and access data we can create sessions we can make sure that users are able to only access their information they're able to securely store the information that's persisted across like sessions they can come back refresh the page and still be able to access it so this this like this does it everyone should implement sign with ethereum um and yeah it allows us to like create rich secure web apps building on
like these principles like connecting a wallet and signing a message which is really cool this means that you know instead of using email login or like a social auth provider or even something like auth0 you can just use this one connect wallet sign in with ethereum flow and users can feel good that it's secure and they're getting consistent experience across web3 they know that synonym ethereum is a thing that works well on mirror like a publishing platform or an nft marketplace or like a decentralized finance um front-end all these places it can it
can work the same so yeah just to quickly review connect wallet is all about giving access to an app to make more requests to send transactions sign messages those type of interactions signing a message is all about proving you own the private keys you are who you say you are and sign up ethereum is about standardized secure access building on top of the tomb so if you want to go a little bit further um wag me which is the library react works live river ethereum has guides for each one of these things connecting wallet
signing message signing with ethereum um so you can check that out and sort of play around with it and see see how these things work also it can be really good for hackathon if you want to get started you're familiar comfortable using react um you can start using these methods in like a quick start type of way so yeah that that's about it we're gonna make it we just have to make sure that we're building secure experiences for people using the apps that we build thanks so much for listening and you can find me at these places see ya
