DEV Community

chandra penugonda
chandra penugonda

Posted on

How MetaMask Creates Accounts

How MetaMask Creates Accounts

  1. when you install MetaMask, you were shown a list of 12 words known as the Secret Recovery Phrase.

    • Note: The order of the words in the secret recovery phrase is important.
    • MetaMask uses a specification known as the BIP39 to generate these 12 words.
    • BIP39(Bitcoin Improvement Proposals) recommends use of a mnemonic phrase to recover accounts in the event your accounts are compromised or lost.MetaMask calls this mnemonic phrase as the Secret Recovery Phrase.
    • 12 words are chosen from a list of 2048 words.The complete list of 2048 words can be found from here
  2. Each word in the secret recovery phrase has a number associated with it. These numbers are used to form a seed integer, which is then used to create a set of public/private keys

seed integer generation

Generating the public/private key pair and the Ethereum address using seed interger

  1. a private key is generated using the seed integer using the SHA256 hash function
  2. public key is generated from private key using ECDSA(Elliptic Curve Signature) algorithm
  3. from the public key derived, compute a keccak256 hash
  4. from the keccak256 hash, take the last 20 bytes (which is 40 hexadecimals), prefix it with “0x” and this is your Ethereum address.

Creating the Default Account

  1. With the public/private key pair created from the seed integer, MetaMask will now be able to create your first account.As explained, your first account is generated from the keccak256 hash.

  2. Internally, MetaMask encrypts your private key using the password that you supplied during the installation stage, and stores it in your browser’s data store. It does not store them on the cloud.

where do Metamask stores key

Creating Additional Accounts

  1. MetaMask makes use of the private key of the first account and hashes it to get the next private key.Using the newly created private key, the same procedure applies (as described earlier) to get the public key and subsequently the account address. And the next account is always the hash of the previous private key.

Multiple accounts from private key
Note:

  • This is the reason why your accounts can be recovered as long as you have your secret recovery phrase.
  • And this brings us to this very important point you have to know — protect your secret recovery phrase under lock and key! - Once you compromised your secret recovery phrase, your accounts can be accessed by anyone who has them. Needless to say, your cryptocurrencies will be gone in a heartbeat!

Credits: Wei-Meng Lee

Billboard image

Synthetic monitoring. Built for developers.

Join Vercel, Render, and thousands of other teams that trust Checkly to streamline monitor creation and configuration with Monitoring as Code.

Start Monitoring

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay