<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Gui Bibeau</title>
    <description>The latest articles on Forem by Gui Bibeau (@guibibeau).</description>
    <link>https://forem.com/guibibeau</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F425777%2F948e9b35-ee95-4b98-8f8d-e1d9dcf275d0.jpeg</url>
      <title>Forem: Gui Bibeau</title>
      <link>https://forem.com/guibibeau</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/guibibeau"/>
    <language>en</language>
    <item>
      <title>Signing data with MetaMask</title>
      <dc:creator>Gui Bibeau</dc:creator>
      <pubDate>Wed, 01 Feb 2023 01:38:11 +0000</pubDate>
      <link>https://forem.com/metamask/signing-data-with-metamask-2ggl</link>
      <guid>https://forem.com/metamask/signing-data-with-metamask-2ggl</guid>
      <description>&lt;p&gt;Signing is an act that carries a big responsibility. You sign things like contracts, cheques, and legal documents. If you create an application for signing things, chances are that any mediumly tech-savvy person will be able to use it. But in the blockchain world, what does signing mean?&lt;/p&gt;

&lt;p&gt;This question you should take lightly, especially when it comes to your users and presenting them with transactions, messages, and data to be signed. Establishing trust with your users is critical and will be the tutorial's focus. In the following few paragraphs, we will put our dual UX and blockchain hats on and sign a message with Metamask.&lt;/p&gt;

&lt;h2&gt;
  
  
  Signing a message
&lt;/h2&gt;

&lt;p&gt;First, Let's demystify what signing means in the world of crypto. In the physical world, your identity is proven with an identification card or, in some contexts, a written signature. This validity is typically ensured because they are verified by a trusted entity such as a notary or a governmental organization.&lt;/p&gt;

&lt;p&gt;Trust in a blockchain comes from nodes in the network agreeing on the validity of transactions between two parties. It is to these transactions that the term signing is most often applied. Signing a transaction on Ethereum means using a private key to authorize a transfer of Ether or interaction with a smart contract on the Ethereum blockchain. It proves the ownership of the Ethereum address associated with the private key and allows the transaction to be added to the blockchain.&lt;/p&gt;

&lt;p&gt;But signing goes beyond this. It can also be used for other purposes. For example, signing a message can be used to proven to come from a specific address. This is useful for many use cases like authentication, authorizations, and even exchanges of information. MetaMask, a fully featured wallet, can be used to sign messages and data. We will see popular methods and even explore cutting-edge Dapp architectures built on top of it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Signing a message with MetaMask
&lt;/h2&gt;

&lt;p&gt;MetaMask always does its best to make sure standards are followed and that the user is in control of their information. The methods we'll discuss today are the ones we recommend to be implemented by Dapps. We'll discuss signing simple messages and signing typed data. The respective methods are &lt;code&gt;eth_sign&lt;/code&gt; and &lt;code&gt;eth_signTypedData&lt;/code&gt; and can be submitted through the &lt;code&gt;window.ethereum.request&lt;/code&gt; JSON-RPC API. &lt;/p&gt;

&lt;h3&gt;
  
  
  Signing a simple message
&lt;/h3&gt;

&lt;p&gt;In some cases, if you want to have users approve or sign a message and don't intend to use the message on a chain, you can use the &lt;code&gt;personnal_sign&lt;/code&gt; method,  defined in &lt;a href="https://eips.ethereum.org/EIPS/eip-191" rel="noopener noreferrer"&gt;EIP-191&lt;/a&gt;. This method is also relatively simple to implement in your code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// the message to be signed&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I like tacos and I approved of this message&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;0x...&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="c1"&gt;//* pass in the user's address here&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ethereum&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;request&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;personal_sign&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mesasge&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The advantage of this method is by far its simplicity and readability for users; they will be prompted by the MetaMask extension and will have a similar user experience to signing a document or a simple contract. A well-known use case is "Sign In With Ethereum," abbreviated as SIWE, defined in  &lt;a href="https://eips.ethereum.org/EIPS/eip-4361" rel="noopener noreferrer"&gt;EIP-4361&lt;/a&gt;, where users approve connecting to an application and this signature is validated before a session is created in the server.&lt;/p&gt;

&lt;p&gt;Even if we see that 95% of users typically will approve a request for signature, one of the limits with &lt;code&gt;personnal_sign&lt;/code&gt; is around using it inside smart contracts. While we can use the &lt;code&gt;string&lt;/code&gt; value of the message inside a smart contract, a string is expensive to parse into more complicated data formats.&lt;/p&gt;

&lt;p&gt;This is where &lt;code&gt;eth_signTypedData_v4&lt;/code&gt; comes in!&lt;/p&gt;

&lt;h3&gt;
  
  
  Signing typed data.
&lt;/h3&gt;

&lt;p&gt;JSON or JavaScript Object Notation is a famous data format used in web applications. However, JSON support is limited in the world of smart contracts, where performance means increasing user costs. Luckily &lt;a href="https://eips.ethereum.org/EIPS/eip-712" rel="noopener noreferrer"&gt;EIP-712&lt;/a&gt; is a proposed standard that allows users to sign data that smart contracts can understand. &lt;/p&gt;

&lt;p&gt;Its usage is fairly similar to &lt;code&gt;personal_sign&lt;/code&gt;, instead you simply have to pass a request of type &lt;code&gt;eth_signTypedData_v4&lt;/code&gt; and specify the Solidity types and details about the smart contract verifying the message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// The message will be parsed in &lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;domain&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;chainId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Example App&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;verifyingContract&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="c1"&gt;// should implement the top level type&lt;/span&gt;
    &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Are Doritos tacos any good?&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;answer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`YES THEY ARE!`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="c1"&gt;// Top level type&lt;/span&gt;
    &lt;span class="na"&gt;primaryType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;QA&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;types&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;EIP712Domain&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;version&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;chainId&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;uint256&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;verifyingContract&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;address&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;],&lt;/span&gt;
     &lt;span class="c1"&gt;// defining the top level type here. types refer to Solidity types    &lt;/span&gt;
      &lt;span class="na"&gt;QA&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;prompt&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;answer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;0x...&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; 
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ethereum&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;request&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; 
    &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;eth_signTypedData_v4&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="na"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The lift for front-end developers is a bit higher, but the most significant advantage of this signing method is that it opens up a world of possibilities for smart contracts! It also helps that we witness upwards of 97% approval of these messages in MetaMask! Now let's explore what kind of robust architectures you can unlock with &lt;code&gt;eth_signTypedData_v4&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  A New Generation of Dapps!
&lt;/h3&gt;

&lt;p&gt;In a world where malicious actors abound, moving approvals on-chain has a considerable amount of benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;auditable code &lt;/li&gt;
&lt;li&gt;ability to create authorization layers that live on-chain directly without requiring user approvals on each action.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The last benefit is one I want to explore more. Since typed data is easy to understand for smart contracts, we can use it to hold long-lived user approvals on-chain. Take this example, a smart-contract implementing a paycheck every two weeks. The steps would happen as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;An employer deposits a 10,000$ amount in a smart contract for the next ten weeks of paychecks&lt;/li&gt;
&lt;li&gt;The employer signs an authorization using &lt;code&gt;eth_signTypedData_v4&lt;/code&gt; that approves 1000$ per week for an employee&lt;/li&gt;
&lt;li&gt;The employee, on his own, will claim the salary each week&lt;/li&gt;
&lt;li&gt;The smart contract will verify if the authorization is valid and allow the disbursement&lt;/li&gt;
&lt;li&gt;The employer can revoke his authorization at any time if they terminate the contract&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This kind of scenario is the user experience you can implement if you integrate &lt;code&gt;eth_signTypedData_v4&lt;/code&gt;. It would help if you worked towards a user interface that communicates what happens and educates users about your smart contract when implementing such an authorization layer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We saw a lot of advanced concepts today, but understanding signatures is a great way to build sustainable and user-friendly Dapps. After the initial learning curve of communicating between wallet, smart contracts, and users, we are empowered to make better, more sustainable apps.&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>mentalhealth</category>
    </item>
    <item>
      <title>Digital Identity and SIWE</title>
      <dc:creator>Gui Bibeau</dc:creator>
      <pubDate>Wed, 25 Jan 2023 15:41:07 +0000</pubDate>
      <link>https://forem.com/metamask/hello-world-3p5c</link>
      <guid>https://forem.com/metamask/hello-world-3p5c</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Everywhere you go, you have a digital identity. This identity is the collection of data that represents your activity online. It is challenging to stay truly anonymous online in this era of social media.&lt;/p&gt;

&lt;p&gt;If you are present on a social like Facebook or TikTok, you probably have seen disturbing advertisements after visiting a website seemingly unrelated to those platforms. These advertisements are possible because websites implement a variety of cross-site tracking technologies, identifying you across the Internet.&lt;/p&gt;

&lt;h2&gt;
  
  
  An Overview of Digital Identity In Present-Day Earth, 2023
&lt;/h2&gt;

&lt;p&gt;"Digital Identity" refers to a person or entity's identity existing in the digital world. It encompasses the information, attributes, and characteristics associated with a person or entity. You can use identity for various purposes, such as authentication, authorization, and access control. In tech jargon, a digital identity is an online or networked identity adopted or claimed in cyberspace by an individual, organization, or electronic device.&lt;/p&gt;

&lt;p&gt;Digital identities can be centralized or decentralized, depending on how they are created and managed. A single entity, such as a government or a corporation, controls centralized digital identities, while the individual or entity they represent controls decentralized digital identities.&lt;/p&gt;

&lt;p&gt;A user's digital identity can have simple attributes like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Name&lt;/li&gt;
&lt;li&gt;Address&lt;/li&gt;
&lt;li&gt;Username and password&lt;/li&gt;
&lt;li&gt;Date of birth&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Or complex attributes such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Online search activities, like electronic transactions&lt;/li&gt;
&lt;li&gt;Social security number&lt;/li&gt;
&lt;li&gt;Medical history&lt;/li&gt;
&lt;li&gt;Purchasing history or behavior&lt;/li&gt;
&lt;li&gt;Biometric data&lt;/li&gt;
&lt;li&gt;Digital certificates&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In multiple industries, we see use cases for digital identities, such as finance, healthcare, and e-commerce, and uses, such as online banking, secure messaging, and personal data management.   &lt;/p&gt;

&lt;p&gt;A widespread issue plaguing digital identity on the Internet is Identity theft, so the subject of digital identity authentication and validation measures are critical to ensuring Web and network infrastructure security in the public and private sectors. Admittedly, there has been a lot of talk about authentication. With the advent of blockchain technology, we are seeing the use of digital identities in decentralized applications and platforms built on the blockchain. Recently, the Web3 community has become fragmented around multiple wallets and authentication methods. &lt;/p&gt;

&lt;p&gt;Web3 developers are digital self-sovereignty advocates, so let's look at what the concept of digital identity means in web3.&lt;/p&gt;

&lt;h2&gt;
  
  
  Identity in Web3 and Its Implementation
&lt;/h2&gt;

&lt;p&gt;Identity in web3 refers to self-sovereign identity, allowing individuals to own and control their digital identity. Centralized entities such as governments and corporations control Identities in traditional web2 systems. In web3, individuals can create and manage their digital identities using blockchain technology.&lt;/p&gt;

&lt;p&gt;There are several methods of implementing identity in web3, with popular ones such as Decentralized Identity Protocols(DID) and Smart Contract-based Identity Protocols, and others like Self-sovereign identity (SSI) systems, Public Key Infrastructure (PKI) based systems and Biometric-based Identity as well.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Decentralized Identity (DID): These protocols allow users to create and manage their own digital identities on the blockchain. DIDs are unique identifiers registered on a blockchain and can be used to authenticate and authorize individuals on the web3 network. Then be used to link different identities, such as social media and email, to a single blockchain-based identity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Smart Contract-based Identity: These protocols use smart contracts to store and manage user identities on the blockchain. Users can create and manage their identities using smart contracts and authenticate and authorize users on web3 applications.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Self-sovereign identity (SSI): Systems based on the same principles of DIDs, allowing the user to hold and control their identity data without needing a centralized entity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Public Key Infrastructure (PKI): PKI-based systems use digital certificates and public and private keys to authenticate and authorize users on web3 applications. Similar to traditional web2 systems.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Biometric-based Identity: With biometrics, we can create and authenticate digital identities in web3 using fingerprints and facial and voice recognition. With web3, individuals can exert control over their data and identity, allowing them to share it selectively and, at any time, revoke that access. We can also connect multiple identities to prove our identity as a user. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It's pertinent to remember that the implementation of some of these methods is in its early stages, and research and development are ongoing to improve user experience and adoption.&lt;/p&gt;

&lt;p&gt;Blockchain developers have long talked about developing "decentralized" identity standards to save users from the dangers of "Big Login," and this birthed: Sign-in With Ethereum proposal, a digital identity standard that was built by the community with direct support from the Ethereum Foundation and ENS, with Spruce Systems tapped to lead the charge.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the Sign-In With Ethereum Proposal Affects Digital Identity
&lt;/h2&gt;

&lt;p&gt;The Sign In With Ethereum(SIWE) proposal was a proposed standard for using Ethereum to authenticate and authorize users on web3 applications. It aimed to provide a standard way for users to sign in to web3 applications using their Ethereum address and private key, similar to how users currently sign in to web2 applications using their email and password. It uses a private key to authenticate a user's identity on the Ethereum blockchain. A private key is a unique string of characters associated with an Ethereum address and is used to sign digital transactions. When a user signs in with Ethereum, they provide a digital signature using their private key to prove that they are the owner of the Ethereum address. This proposal allows them to access their account and perform actions such as sending and receiving Ether, interacting with smart contracts, and more.&lt;/p&gt;

&lt;p&gt;With SIWE, users would create an Ethereum address and private key specifically for signing in to web3 applications. When they want to sign in to a web3 application, they will use their private key to sign a message proving they are the owner of the Ethereum address. The web3 application would then verify the signature and authenticate the user.&lt;/p&gt;

&lt;p&gt;SIWE affects digital identity by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Allowing individuals to use their Ethereum address as a way to authenticate on web3 applications&lt;/li&gt;
&lt;li&gt;Eliminating the need for complex passwords and usernames&lt;/li&gt;
&lt;li&gt;Allowing users to use their Ethereum address as a decentralized identity across different web3 applications&lt;/li&gt;
&lt;li&gt;Enabling web3 applications to authenticate and authorize users without the need for centralized identity providers 

&lt;ul&gt;
&lt;li&gt;such as social media login or email and password, which could lead to more privacy and security for the user&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;The proposal aims to standardize how you authenticate with a digital identity. The following are the steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A server creates a Nonce (unique number) for each user that will sign-in&lt;/li&gt;
&lt;li&gt;A user requests to connect a site with their wallet&lt;/li&gt;
&lt;li&gt;The user is presented with a unique message containing the Nonce and information about the website&lt;/li&gt;
&lt;li&gt;The user signs in with their wallet&lt;/li&gt;
&lt;li&gt;The user is then authenticated or approved&lt;/li&gt;
&lt;li&gt;Access to data for this user is given to the website&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;MetaMask is a popular tool and a browser extension that allows users to interact with the Ethereum blockchain and can be used to implement digital identity and SIWE. With it, we can create and manage Ethereum addresses and use them as digital identities on Web3 platforms and dApps.&lt;/p&gt;

&lt;p&gt;For your users, the experience is simple, but multiple steps are happening behind the scenes.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Implement Sign-In With Ethereum
&lt;/h2&gt;

&lt;p&gt;As mentioned above, we will need to generate a unique number called a Nonce; since this should be done on a server, we will be working with Next.js, the most popular React framework for building server-side rendered applications.&lt;/p&gt;

&lt;p&gt;We will be starting from a basic Next.js application created with &lt;a href="https://dev.tocreate-next-app"&gt;&lt;code&gt;create-next-app&lt;/code&gt;&lt;/a&gt;, and we will use the following&lt;br&gt;
libraries:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/@metamask/providers" rel="noopener noreferrer"&gt;&lt;code&gt;@metamask/providers&lt;/code&gt;&lt;/a&gt; - A library for interacting containing TypeScript types for the MetaMask provider API&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/ethers" rel="noopener noreferrer"&gt;&lt;code&gt;ethers&lt;/code&gt;&lt;/a&gt; - A library containing different utilities for interacting with the Ethereum blockchain&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/siwe" rel="noopener noreferrer"&gt;&lt;code&gt;siwe&lt;/code&gt;&lt;/a&gt; - A library containing utilities for implementing Sign In With Ethereum&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/iron-session" rel="noopener noreferrer"&gt;&lt;code&gt;iron-session&lt;/code&gt;&lt;/a&gt; - A library for implementing session management in Next.js applications&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;N.B. The complete code is &lt;a href="https://github.com/MetaMask/examples/tree/main/examples/metamask-siwe" rel="noopener noreferrer"&gt;available here&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  A Dance Between the Client and the Server
&lt;/h3&gt;

&lt;p&gt;With these libraries, we can lay down the architecture for implementing SIWE. To connect users, we will want to implement the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Generate a Nonce inside &lt;code&gt;getServerSideProps&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Pass the Nonce to the client&lt;/li&gt;
&lt;li&gt;Connect to a user's wallet&lt;/li&gt;
&lt;li&gt;Make the user sign a message containing the Nonce&lt;/li&gt;
&lt;li&gt;Verify the signature&lt;/li&gt;
&lt;li&gt;Store the signature in a session&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Generate a Nonce Inside &lt;code&gt;getServerSideProps&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Our first step is to generate a Nonce inside &lt;code&gt;getServerSideProps&lt;/code&gt; of our login page, located on the &lt;code&gt;pages/login.tsx&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Generating the Nonce inside &lt;code&gt;getServerSideProps&lt;/code&gt; is crucial because execution happens on the server, and we can pass it to the client, which is faster than fetching it from an API route like in other implementations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getServerSideProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;nonce&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;generateNonce&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;nonce&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this, we can now pass the Nonce to the client.&lt;/p&gt;

&lt;h3&gt;
  
  
  Passing Our Nonce to the Client
&lt;/h3&gt;

&lt;p&gt;Next, we will pass the Nonce to the client. We do this by defining a default export for the login page, a React component, that will receive the Nonce as a prop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Props&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;nonce&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Login&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;nonce&lt;/span&gt; &lt;span class="p"&gt;}:&lt;/span&gt; &lt;span class="nx"&gt;Props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ...rest of the component&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Connect to a users wallet and sign a message
&lt;/h3&gt;

&lt;p&gt;Now we go to the core of our implementation, connecting to a user's wallet. We do this inside a &lt;code&gt;connect&lt;/code&gt; function which gets called when the user clicks the connect button.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/MetaMask/examples/tree/main/examples/metamask-siwe/pages/login.tsx" rel="noopener noreferrer"&gt;See the full function&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Our function will work as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Request the user to connect to their wallet with &lt;code&gt;window.ethereum.request({ method: 'eth_requestAccounts' })&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Grab the current network with &lt;code&gt;window.ethereum.request({ method: 'eth_chainId' })&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Create a message to sign
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;siweInstance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SiweMessage&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="c1"&gt;// this will let the user validate the domain they are logging in to&lt;/span&gt;
  &lt;span class="na"&gt;domain&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="c1"&gt;// this will let the user validate the origin they are logging in to&lt;/span&gt;
  &lt;span class="na"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;origin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;address&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;statement&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I am logging in to the SIWE demo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;chainId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;chainId&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="nx"&gt;nonce&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Sign the message with
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ethereum&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;request&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;personal_sign&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Post the signature to the server
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/login&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;signature&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;address&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Verify the signature
&lt;/h3&gt;

&lt;p&gt;Then we can move to the server and verify the signature. This verification happens inside the &lt;code&gt;api/login&lt;/code&gt; route, which gets called when the user clicks the connect button.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/MetaMask/examples/tree/main/examples/metamask-siwe/pages/api/login.ts" rel="noopener noreferrer"&gt;See the full API route&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this API route, we'll focus on the following steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Verify the signature&lt;/li&gt;
&lt;li&gt;Ensure the signature is sent from the correct address&lt;/li&gt;
&lt;li&gt;Store the signature in a session&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With this done, you now have full access to the user's signature and can use it to authenticate the user on your web3 platform or dApp. The interesting part is that you now also have a session containing the user's address.&lt;/p&gt;

&lt;p&gt;This address is helpful for prefetching data about the user; for example, you can use the address to fetch data related to the user's address, all while keeping the user's privacy intact. &lt;/p&gt;

&lt;p&gt;If done well, digital identity in Web3 can provide a more secure and private way to handle user identities while providing a great user experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, digital identity in Web3 is a critical topic that is gaining more and more attention as the decentralized Web continues to grow. Implementing digital identity in Web3 can be done using various methods, including DIDs, smart contract-based identity protocols, and Metamask and Next.js. By using these tools and techniques, individuals can take control of their digital identity and use it to authenticate and authorize themselves on web3 platforms and dApps.&lt;/p&gt;

&lt;p&gt;For digital identity in Web3 to be successful, individuals, developers, and businesses need to continue to educate themselves on the benefits and best practices for implementing digital identity in a secure and decentralized manner. With the right tools and knowledge, digital identity in Web3 can provide a more secure and private way to handle user identities.&lt;/p&gt;

</description>
      <category>vibecoding</category>
    </item>
  </channel>
</rss>
