# Everything You Wanted to Know About Wallet Keys

#### â**Introduction**

At heart, a crypto wallet is a UI layer on top of your public and private keypair and abstracts the interface to access the blockchain. This keypair serves as your âpassportâ through the web3 ecosystem. Youâve probably heard catchphrases like ânot your keys, not your coinsâ which hint towards the importance of these keys and their ownership, but what are they actually? How do they work, and where do they come from? How do they guarantee your identity on the blockchain?

This blog post will take a deep dive into the technicalities of keys (and wallets) to understand the mathematics and cryptography that underpin them.

**Public-Key Cryptography Basics**

To understand what a wallet actually is, you first need to understand public key cryptography. Public-key cryptography (also called asymmetric cryptography) is a type of cryptosystem for secure data transmission that gives every user two keys â a public key known to everyone and a hidden private key.Â

The canonical example (which is inverse in crypto) of how these keys are used is that Alice wants to send a message for Bobâs eyes only. To do this, Alice encrypts the message using Bobâs widely available public key. Bob then uses his private key to decrypt the message.Â

Popular public-key cryptography algorithms that can create keypairs and encrypt/decrypt messages include modular exponentiation-based RSA. RSA is one of the most popular algorithms employed and uses large primes to generate key pairs.

â

**Generating the Keys**

When you create a new self-custodial wallet, you generate a new private key, then compute the public key from the private key. The wallet serves as a UI on top of your keys.

While the process of deriving the keypairs and addresses is standardized, blockchains may differ in the operations applied to the private keys. The details described below pertain to Ethereum.

â

*Generating the Private Key*

The private key is a randomly generated 256-bit number; there are roughly equivalent private key addresses as there are atoms in the universe. The operating system or wallet application dictates the randomness of the private key â it is crucial to have sufficient entropy in a private key generation, so the number generated is not predictable.^{1}

â

*Generating the Public Key*

The public key is then derived from the private key using the Elliptic Curve Digital Signature Algorithm (ECDSA), a variant of DSA. Ethereum, like Bitcoin, uses the elliptic curve parameter *secp256k1* as defined by the National Institute of Standards and Technology (NIST).Â **â**

*Generating the Ethereum Address*

Once the public key is calculated, the one-way function Keccak-256 is applied, and the 160 right-most hash output bits are used as the Ethereum address. The address is often prefixed with 0x to indicate they are in hexadecimal format.Â

â

**Public Key vs. Ethereum Address**

Note that the Ethereum address is not the same as the public key. The Ethereum address, which is a hash of the public key, is the alphanumeric string that users disseminate to receive funds. While the Ethereum address is available on every transaction, the public key can be derived from the values in the transaction header, which can be used to verify the authenticity of the signature.Â

â

**Key Storage in Wallets**

Once the keys have been generated, they must be securely stored to prevent theft. The early bitcoin crypto wallets stored the private key in a local âwallet.datâ file. More modern wallets provide more robust storage solutions by exporting keys to secure cloud storage systems or integrating with a hardware wallet like Ledger to provide access to funds.Â

The private keys, meanwhile, are often further encrypted/hashed. Centralized exchanges like Coinbase store your private keys on their servers, while for modern self-custodial wallets like MetaMask that are browser-based, the private keys are kept in the browserâs data store.

â

**Master Seed and Recovery Pharse**

Most wallets ask users to keep the recovery phrase in a safe place, usually offline. This phrase, which consists of 12-24 words which in specific order can map to the âMaster seedâ. The master seed is a randomly generated 256 bits, that can be used to derive an infinite number of private keys. This is how wallets can generate many accounts, each with their own private/public keys, while still allowing you to restore all of them with one recovery phrase.

â

**Signing Transactions**

With the keys stored safely in your wallet, they can now be used to âsign transactionsâ and otherwise participate in the web3 economy.

This works in sort of an inversion of the Alice-Bob message encryption example. To âsignâ a transaction on the blockchain, the user puts the transaction and their private key into a mathematical function that spits out the signature.Â

The signing algorithm uses a temporary private key and the transaction data to produce two outputs, commonly called *r *and* s. *This signature is then appended to the transaction message. To verify that a user signed the message, any third-party verifier can use the inverse of the signature generation function that takes in the transaction data, the userâs public key, and the two signature values to output a return value *q*. The transaction is valid if q is equal to the signature value r.

Of course, wallet users will never personally have to call any functions â the inner technical details of transaction signing are abstracted away by the wallet UI.

â

**Final thoughts**

At its core, a wallet is a program that generates a public/private key pair for you and signs and encrypts messages using them. In a departure from the traditional understanding of wallets, crypto wallets do not actually store your crypto assets; they just secure the assets stored in the blockchain and restrict their access.

The difference between a custodial wallet like Coinbase and a self-custodial wallet like MetaMask is that custodial wallets have access to and take care of your private key, while with self-custodial wallets, youâre responsible for them yourself. In future articles, weâll explore methods for managing your private keys, including sharing them via MPC, bringing in multisig approaches, and others.

â

_{(1)This uniqueness of the private key is at the core of the authentication mechanism here at Dynamic, we believe that utilizing the private key for the authentication flow, provides far superior security to any password you might come up with}