Crypto-Wallets: A Technical Perspective
Svetlin Nakov @ OpenFest 2018 - https://www.openfest.org/2018/en/
Sofia, 4 November 2018
In this talk the speaker explains the concepts of crypto-wallets used by the blockchain developers to securely keep the private keys controlling the blockchain addresses and crypto-assets. The different wallet types (brain, paper, desktop, mobile, online, hardware) will be introduced and how to build and interact with wallets, sign and send blockchain transactions are demonstrated. The speaker explains the basic concepts and will give examples how to use and interact with keystores (holding a single ECC-based private key) and hierarchical deterministic wallets (HD wallets), which use mnemonic phrases with key-derivation based on the BIP39 and the BIP44 standards to keep multiple private keys.
All attendees are invited to create their own crypto-wallet and to get some testing crypto-coins (Ethereum Ropsten Testnet ethers – ETHt) and to send a few payment transactions on the Testnet.
All concepts are demonstrated with live examples in JavaScript: creating a simple wallet, encrypting and saving it; creating a new random HD wallet and creating an HD wallet from mnemonic phrase, along with deriving private keys.
Learn more at: http://www.nakov.com/blog/2018/11/04/crypto-wallets-a-technical-perspective-nakov-at-openfest-2018/
3. 3
Technical advisor @ LockChain / LockTrip: https://locktrip.com
Raised ~ 10.000 ETH in token sale (Sep-Nov 2017)
Currently LOC token holders book hotels @ 20-30% better price
Head of blockchain education (Jan-June 2018) @ Academy
School of Blockchain: https://academytoken.com
Raised ~ 48M USD in token sale (Jan-Apr 2018)
Tech advisor for blockchain crypto startups:
Tokenize Exchange, Bountie, Weidex, IRIS Payments Solutions,
Aeternity Ventures
Nakov – Blockchain & Crypto Projects
4. 4
Book "Practical Cryptography for Developers"
GitHub:
https://github.com
/nakov/practical-
cryptography-for-
developers-book
Official site:
https://cryptobook.
nakov.com
5. Table of Contents
5
1. Public Blockchains: Nano Introduction
2. Blockchain Wallets: Types, Functions, Concepts
3. Practice: Play with the Jaxx Wallet on the Ropsten Testnet
4. Simple Keystores: Encrypted Private Keys
5. Simple Keystores: JS Code Examples and Live Demo
6. HD Wallets: Mnemonics (BIP39), HD Wallets (BIP32, BIP44)
7. HD Wallets: JS Code Examples and Live Demo
6. 6
Public Blockchains: Nano Introduction
Distributed ledger
Peer-to-Peer
network
Nodes hold
ledger of facts +
history of updates
Decentralized
(no owner)
Secure
Transactions are
verified by the
entire network
Immutable
8. 8
Crypto wallet == software that stores private keys along with their
respective blockchain addresses
Enables users to send and receive crypto currency / tokens
Communicates with the blockchain network (through API or by
running a blockchain node)
Signs transactions and sends them to the blockchain network
What is a Cryptocurrency Wallet?
9. 9
Mobile wallet (mobile app)
Desktop wallet (desktop app)
Web-based wallet (web site)
Hardware-based wallet
(USB stick, e.g. Ledger, Trezor)
Paper wallet (private key
printed on a sheet of paper)
Types of Crypto Wallets
15. Request test ethers (ETHt) from the Faucets
http://tiny.cc/ropsten-faucet
https://faucet.metamask.io
https://faucet.ropsten.be
http://faucet.bitfwd.xyz
15
Ethereum Testnet Faucets
16. 16
Simple keystores
Example: myetherwallet.com
Keep a simple ECC private key, password protected
Similar to OpenSSH and OpenSSL PEM keystores (see PKCS#8)
HD wallets
Example: https://iancoleman.io/bip39
Hierarchical-deterministic (HD) wallet
Keep a mnemonic phrase (12 or 24 words)
Derive many private keys from the mnemonic
Simple Keystores vs. HD Wallets
19. https://github.com/ethers-io/ethers.js
19
Creating a Simple Keystore in JavaScript
npm install --save ethers
let ethers = require('ethers');
let newWallet = ethers.Wallet.createRandom();
console.log("Address: " + newWallet.address);
console.log("Private key: " + newWallet.privateKey);
newWallet.encrypt('P@SS~12345a').then(walletJSON => {
console.log("Encrypted wallet JSON:", walletJSON);
});
20. 20
Simple Keystore from Private Key in JS
let ethers = require('ethers');
let privKey =
"0x0e210eff4fc77ff086d81d646c94af42ec5b1bbaf3f1d525f5bf5b82af7056da";
let existingWallet = new ethers.Wallet(privKey);
console.log("Address: " + existingWallet.address);
// Address: 0xe25ACB5AaE29c38DABdc13Ea41177Aba1191D323
const provider =
ethers.providers.getDefaultProvider('ropsten');
provider.getBalance(existingWallet.address).then(balance =>
console.log('Balance:', ethers.utils.formatEther(balance)));
21. 21
Mnemonics and HD Wallets (BIP39, BIP44)
HD wallets keep a securely generated random seed
And use a hierarchical deterministic (HD) key-derivation (see BIP-32)
The seed (root key) can be represented as 12 or 24 words, e.g.
Each word comes from a wordlist of 2048 words 1 word == 11 bits
24 words 256-bit entropy 512-bits seed (see BIP-39)
All private keys + addresses are derived from the seed (see BIP-44)
See https://iancoleman.io/bip39 to understand the idea in practice
force moon book duck idle best sad net pelican deal dog close
23. 23
HD Wallets in JavaScript: From Mnemonics
let ethers = require('ethers');
let mnemonic = "summer silent settle explain cigar print
drift genius quarter smart subway humble";
let hdWallet = ethers.HDNode.fromMnemonic(mnemonic);
for (let index=0; index<5; index++) {
let key = hdWallet.derivePath(`m/44'/60'/0'/0/${index}`);
console.log(`Private key #${index}: ${key.privateKey}`);
}
24. 24
HD Wallets in JavaScript: New HD Wallet
let ethers = require('ethers');
let rnd256Bits = ethers.utils.randomBytes(256 / 8);
let mnemonics = ethers.HDNode.entropyToMnemonic(rnd256Bits);
let hdWallet = ethers.HDNode.fromMnemonic(mnemonics);
console.log("Wallet mnemonics:", mnemonics);
console.log("Wallet private key:", hdWallet.privateKey);
for (let index=0; index<5; index++) {
let key = hdWallet.derivePath(`m/44'/60'/0'/0/${index}`);
console.log(`Private key #${index}: ${key.privateKey}`);
}
26. License
This course (slides, examples, demos, videos, homework, etc.)
is licensed under the "Creative Commons Attribution-
NonCommercial-ShareAlike 4.0 International" license
26
27. Trainings @ Software University (SoftUni)
Software University – High-Quality Education,
Profession and Job for Software Developers
softuni.org
Software University Foundation
softuni.foundation
Software University @ Facebook
facebook.com/SoftwareUniversity
Software University Forums
forum.softuni.bg
Notas del editor
a software program that stores private and public keys and interacts with various blockchains
a program that enables users to send and receive digital currency and monitor their balance
if you want to use Bitcoin or any other cryptocurrency you will need to have a cryptocurrency wallet