Everything You Wanted to Know About Wallet Keys (2024)

Blog

Learn

Everything You Wanted to Know About Wallet Keys

By

Yoni Goldberg

Everything You Wanted to Know About Wallet Keys (1)

August 5, 2022

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.

Everything You Wanted to Know About Wallet Keys (2)

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).

Everything You Wanted to Know About Wallet Keys (3)

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

Share this article

Everything You Wanted to Know About Wallet Keys (4)

Yoni Goldberg

Yoni is the co-founder and CTO of Dynamic. Prior to Dynamic he was VP at Juul labs, AQR and Even Financial, and a tech lead at Gilt Groupe. He previously completed his thesis at Google Research, and holds B.Sc and M.Eng degrees in Computer Science from MIT.

I'm an enthusiast with a deep understanding of cryptocurrency and blockchain technology. The information provided in the article titled "Learn Everything You Wanted to Know About Wallet Keys" by Yoni Goldberg is comprehensive and covers the fundamental concepts related to crypto wallets and keys. Here's a breakdown of the key concepts discussed in the article:

  1. Crypto Wallet Overview:

    • A crypto wallet serves as a user interface (UI) layer on top of a public and private keypair.
    • It abstracts the interface to access the blockchain, and the keypair acts as a "passport" through the web3 ecosystem.
  2. Public-Key Cryptography Basics:

    • Public-key cryptography involves a pair of keys – a public key known to everyone and a hidden private key.
    • The public key is used for encryption, while the private key is used for decryption.
  3. Generating the Keys:

    • When creating a self-custodial wallet, a new private key is generated, and the public key is computed from it.
    • The private key is a randomly generated 256-bit number, ensuring unpredictability.
    • The public key is derived using the Elliptic Curve Digital Signature Algorithm (ECDSA).
  4. Generating the Ethereum Address:

    • The Ethereum address is obtained by applying the Keccak-256 one-way function to the public key.
    • The Ethereum address is not the same as the public key and is a hash of the public key.
  5. Key Storage in Wallets:

    • Private keys must be securely stored to prevent theft.
    • Modern wallets provide various storage solutions, including secure cloud storage and integration with hardware wallets like Ledger.
  6. Master Seed and Recovery Phrase:

    • Users are often required to keep a recovery phrase offline, consisting of 12-24 words.
    • The recovery phrase maps to a "Master seed," a randomly generated 256-bit value used to derive infinite private keys.
  7. Signing Transactions:

    • Wallets use private keys to sign transactions, involving a mathematical function that produces a signature.
    • The signature is appended to the transaction message, and verification involves the public key and transaction data.
  8. Final Thoughts:

    • A wallet is a program that generates a public/private key pair and signs and encrypts messages.
    • Crypto wallets do not store assets but secure assets on the blockchain, with custodial and self-custodial wallets differing in key management.

This breakdown provides a comprehensive overview of the concepts discussed in the article. If you have any specific questions or if there's a particular aspect you'd like more information on, feel free to ask.

Everything You Wanted to Know About Wallet Keys (2024)
Top Articles
Latest Posts
Article information

Author: Prof. Nancy Dach

Last Updated:

Views: 5801

Rating: 4.7 / 5 (57 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Prof. Nancy Dach

Birthday: 1993-08-23

Address: 569 Waelchi Ports, South Blainebury, LA 11589

Phone: +9958996486049

Job: Sales Manager

Hobby: Web surfing, Scuba diving, Mountaineering, Writing, Sailing, Dance, Blacksmithing

Introduction: My name is Prof. Nancy Dach, I am a lively, joyous, courageous, lovely, tender, charming, open person who loves writing and wants to share my knowledge and understanding with you.