SlideShare a Scribd company logo
1 of 52
Download to read offline
Understanding HD Wallets: Design and Implementation
Brought to you by Shijun Wang
1
HD Wallet= Hierarchical Deterministic Wallet
2
Wallet
3
What is Wallet?
• Wallets contain keys, not coins, each user has a wallet containing keys
• Users sign transactions with the keys, all transactions stored on blockchain
4
What is Wallet? (ctnd.) 5
Deterministic Wallet
6
What is Non-Deterministic Wallet?
Random Wallet
• Private/public key pairs are generated randomly, not related to each other
• Backup/restore/migration must be done with each key pair
• Satoshi Client : JBOK (just a bunch of keys)
7
What is Non-Deterministic Wallet? (ctnd.) 8
What is Deterministic Wallet?
Seeded Wallet
• Derive large amounts of private/public key pairs from same single seed phrase
• Backup/restore/migration can be done with the seed phrase at creation time
• Derive algorithm = one way hash function
• Deterministic wallets can be sequential or hierarchical
9
What is Sequential Deterministic Wallet? 10
Hierarchical Deterministic Wallet
11
What is Hierarchical Deterministic Wallet? 12
What is Hierarchical Deterministic Wallet? (ctnd.)
• Generated private/public key pairs are organized into a tree, derived using a path
• Tree structure can be used to express additional organizational meaning
• Each node has private and public key, any node can derive any number of children
• Can be shared partially or entirely with different systems, each with or without the ability to
spend coins
• Industry standard for generating multiple network wallets with same seed phrase,
supported by most wallet apps
13
Design and Implementation (BIP32 and BIP44)
14
What is BIP then?
BIP = Bitcoin Improvement Proposal
Design document providing information to the Bitcoin community, or describing a new
feature for Bitcoin or its processes or environment. Each BIP is assigned a number.
• Meta BIP
• BIP Workflow
• Complete BIP list
15
HD Wallet related BIPs
• BIP32: Hierarchical Deterministic Wallets
• BIP43: Purpose Field for Deterministic Wallets
• BIP44: Multi-Account Hierarchy for Deterministic Wallets
16
What is BIP32?
Core BIP related to HD Wallet
• Spec for key pair derivation from a master seed
• Spec for wallet construction on top of such key pair tree
17
BIP32: Child Key Derivation Algorithm?
Child Key Derivation function
• CKD is one-way hash function that make uses of following 3 inputs
• A parent private or public key
• A seed called a chain code
• An index number (32 bits means 2^32 child)
• Important property of derived keys
• Child private keys are indistinguishable from non-deterministic (random) keys
• Can be used to make a public key and a address
• Can be used to sign transactions to spend anything paid to that address
• The fact that they are part of a sequence is not visible outside of the HD wallet
18
BIP32: How to Derive Child Private Key? 19
BIP32: How to Derive Child Public Key? 20
BIP32: How to Derive Child Key: Javascript
HDKey.prototype.deriveChild = function(index) {
var indexBuffer = Buffer.allocUnsafe(4);
indexBuffer.writeUInt32BE(index, 0);
var data = Buffer.concat([this.publicKey, indexBuffer]);
var I = crypto.createHmac('sha512', this.chainCode).update(data).digest();
var IL = I.slice(0, 32);
var IR = I.slice(32);
var child = new HDKey();
if (this.privateKey) {
child.privateKey = secp256k1.privateKeyTweakAdd(this.privateKey, IL);
} else {
child.publicKey = secp256k1.publicKeyTweakAdd(this.publicKey, IL, true);
}
child.chainCode = IR;
child.depth = this.depth + 1;
child.index = index;
return child;
};
21
BIP32: Child Key Derive Function Notation
• Child private key derivation:
• Child public key derivation:
22
BIP32: Why Chain Code in CKD?
• Introduce deterministic random data to the process
• Initial chain code seed (at the root of the tree) is generated from the seed
• Subsequent child chain codes are derived from each parent chain code
• Add another layer to HD wallet privacy
• Public key can be easily found, if chain code not present, all child keys are revealed
23
BIP32: What is Extended Key?
Child key derivation requires both parent key and parent chain code.
• Extensible keys, keys that can derive children
• Extended Private Key = Private Key + Chain Code , xpriv
• Extended Public Key = Public Key + Chain Code , xpub
• Can be root of a branch in the tree structure of the HD wallet
• Knowing xpriv allows reconstruction of all descendant private keys and public keys
• Knowing xpub allows reconstruction of all descendant public keys
• Should be treated with more care than random generated public key
24
BIP32: Where Should We Start? Master Key!
Now we have CKD functions, where should we start to generate a tree?
• Generate random extended keys directly?
• We have a total of 2^512 extended keys, because it’s 512 bits long
• But can only produced 2^256 possible public/private keys, because they are 256 bits long
• Generate master key from potential random value ( better )
• Generate seed of a chosen length from RNG
• Calculate HMAC-SHA512 hash from the seed
• Split hash into 2 256-bits sequences
• Left as master secret key, right as master chain code
25
BIP32: From Seed to Master Key and Extended Key 26
BIP32: Security Flaw with CKD 27
BIP32: Rescue to Security Flaw: Hardened CKD 28
BIP32: Child Key Derive Path Notation
• CKDpriv(CKDpriv(CKDpriv(m,3),2),5) => m/3/2/5
• CKDpriv(CKDpriv(CKDpriv(m,3H),2),5) => m/3'/2/5
• CKDpub(CKDpub(CKDpub(m,0),0),0) => M/0/0/0
29
BIP32: HD Wallet Structure Overview 30
Why BIP44? 31
Why BIP44?
• BIP32 specification offers implementors too many degrees of freedom, infinite depth
• BIP32 compatible wallets can produce wallets with different logical structures
32
What is BIP44?
• BIP43: Purpose Field for Deterministic Wallets
• BIP44: Multi-Account Hierarchy for Deterministic Wallets
• Defined a specific logical hierarchy for deterministic wallets based on the
algorithm described in BIP-32
• Provided a network agnostic method of generating secure keys in an incredibly
flexible manner
33
BIP44: Derive Path Notation
Notation
Example
• CKD: m : CKDpriv is used, M for CKDPub
• Purpose: 44' , hardened , which spec is used, 44 means BIP44
• Coin: 60' , hardened , 60 means Ethereum, coin types
• Account: 0' , hardened , enable multiple accounts under single network
• Change: 0 , 0 means external in Bitcoin, always 0 in Ethereum
• Index: 0 , the first public/private key pair leaf node
m / purpose' / coin_type' / account' / chain / address_index
m/44'/60'/0'/0/0
34
Making HD Wallet User Friendly (BIP39)
35
Why BIP39? 36
What is Mnemonic Code?
Mnemonic Code = Word sequences that represent a random number
used as a seed to derive HD wallets
• Easy to transcribe, record on paper
• Easy to export and import into another wallet
• More secure than brain wallet ,
37
What is BIP39?
Mnemonic code for generating deterministic keys
• Describes how to generate mnemonic code from random number
• Describes how to convert mnemonic code to master seed
38
BIP39: Mnemonic Generating Work ow 39
BIP39: Entropy and Mnemonic code
Different length of random number( entropy ) leads to different Mnemonic length
Entropy Checksum Entropy + Checksum Mnemonic Length
128 4 132 12
160 5 165 15
192 6 198 18
224 7 231 21
256 8 264 24
Mnemonic word duplicate is possible
40
BIP39: Mnemonic Code Wordlist
Multilingual support (2048 words in each language):
• English
• Japanese
• Korean
• Spanish
• Chinese (Simplified)
• Chinese (Traditional)
• French
• Italian
41
BIP39: Mnemonic Generating Code: Javascript
function generateMnemonic(strength, rng, wordlist) {
strength = strength || 128;
if (strength % 32 !== 0) throw new TypeError(INVALID_ENTROPY);
rng = rng || randomBytes;
return entropyToMnemonic(rng(strength / 8), wordlist);
}
function entropyToMnemonic(entropy, wordlist) {
if (!Buffer.isBuffer(entropy)) entropy = Buffer.from(entropy, 'hex');
wordlist = wordlist || DEFAULT_WORDLIST;
var entropyBits = bytesToBinary([].slice.call(entropy));
var checksumBits = deriveChecksumBits(entropy);
var bits = entropyBits + checksumBits;
var chunks = bits.match(/(.{1,11})/g);
var words = chunks.map(function(binary) {
var index = binaryToByte(binary);
return wordlist[index];
});
return wordlist === JAPANESE_WORDLIST ? words.join('u3000') : words.join(' ');
}
42
BIP39: Possible to Brute Force Attack Mnemonic?
Take 12 words mnemonic, 2048 word list as example:
• Possible permutation = 2048!/(2048 - 12)! = 5.27e+39
• 10000 guess/second = 10000 * 60 * 60 * 24 * 364 = 3.15*e+11 guess/year
• Years take to check all = 1.67e+28 year
Longer Mnemonic = Better Randomness = Better Security
43
BIP39: From Mnemonic to Master Seed 44
BIP39: From Mnemonic to Master Seed (code)
function mnemonicToSeed(mnemonic, password) {
var mnemonicBuffer = Buffer.from(unorm.nfkd(mnemonic), 'utf8');
var saltBuffer = Buffer.from(salt(unorm.nfkd(password)), 'utf8');
return pbkdf2(mnemonicBuffer, saltBuffer, 2048, 64, 'sha512');
}
45
BIP39: Mnemonic + Passphrase = Better Security
• Mnemonic
• Checksum makes randomly generated word sequences invalid mnemonic
• Possible set of 2^512 wallets, no practical possibility of brute-forcing or accidentally guessing
one that is in use
• Passphrase
• Given a single mnemonic, every possible passphrase leads to a different seed
• Passphrase as second factor, makes it hard to compromise the wallet when mnemonic leaked
46
Connect the Dots
47
Mnemonic => Ethereum HD Wallet
const bip39 = require('bip39');
const HDKey = require('hdkey');
const EthUtil = require('ethereumjs-util');
const mnemonic = bip39.generateMnemonic(128);
const seed = bip39.mnemonicToSeed(mnemonic, '');
const master = HDKey.fromMasterSeed(seed);
const account = master.derive("m/44'/60'/0'");
const addr = account.deriveChild(0).deriveChild(0);
const pubKey = EthUtil.privateToPublic(addr.privateKey);
const address = EthUtil.publicToAddress(pubKey).toString('hex');
// address: 0xd98efff831aaa4fe8834f9cb211d8397193a5492
48
Mnemonic HD Wallet in Action
49
One More Thing
50
Where to Learn More?
• BIP32: Hierarchical Deterministic Wallets
• BIP39: Mnemonic code for generating deterministic keys
• BIP43: Purpose Field for Deterministic Wallets
• BIP44: Multi-Account Hierarchy for Deterministic Wallets
• Master Bitcoin 2nd Edition: Wallets and Address
• Bitcoin Developer Guide
• HD Wallet Playground: Support Many Chains
• HD Wallet Playground: Only Ethereum Support
51
52

More Related Content

What's hot

Introduction to Bitcoin's Scripting Language
Introduction to Bitcoin's Scripting LanguageIntroduction to Bitcoin's Scripting Language
Introduction to Bitcoin's Scripting LanguageJeff Flowers
 
Basics of Blockchain Technology
Basics of Blockchain TechnologyBasics of Blockchain Technology
Basics of Blockchain TechnologyNasir Bhutta
 
Blockchain 101 by imran bashir
Blockchain 101  by imran bashirBlockchain 101  by imran bashir
Blockchain 101 by imran bashirImran Bashir
 
Blockchain - HyperLedger Fabric
Blockchain - HyperLedger FabricBlockchain - HyperLedger Fabric
Blockchain - HyperLedger FabricAraf Karsh Hamid
 
Hyperledger Fabric Architecture
Hyperledger Fabric ArchitectureHyperledger Fabric Architecture
Hyperledger Fabric Architecture상문 오
 
Bitcoin Addresses
Bitcoin AddressesBitcoin Addresses
Bitcoin Addressesashmoran
 
Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...
Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...
Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...Simplilearn
 
Introduction To Solidity
Introduction To SolidityIntroduction To Solidity
Introduction To Solidity101 Blockchains
 
Understanding Proof of Work (PoW) and Proof of Stake (PoS) Algorithms
Understanding Proof of Work (PoW) and Proof of Stake (PoS) AlgorithmsUnderstanding Proof of Work (PoW) and Proof of Stake (PoS) Algorithms
Understanding Proof of Work (PoW) and Proof of Stake (PoS) AlgorithmsGautam Anand
 
Security in the blockchain
Security in the blockchainSecurity in the blockchain
Security in the blockchainBellaj Badr
 
01 - Introduction to Hyperledger : A Blockchain Technology for Business
01 - Introduction to Hyperledger : A Blockchain Technology for Business01 - Introduction to Hyperledger : A Blockchain Technology for Business
01 - Introduction to Hyperledger : A Blockchain Technology for BusinessMerlec Mpyana
 
Overview of blockchain technology and architecture
Overview of blockchain technology and   architectureOverview of blockchain technology and   architecture
Overview of blockchain technology and architectureEY
 
Non-fungible tokens (nfts)
Non-fungible tokens (nfts)Non-fungible tokens (nfts)
Non-fungible tokens (nfts)Gene Leybzon
 
Ethereum in a nutshell
Ethereum in a nutshellEthereum in a nutshell
Ethereum in a nutshellDaniel Chan
 
Introduction to bitcoin
Introduction to bitcoinIntroduction to bitcoin
Introduction to bitcoinWolf McNally
 
Hyperledger Fabric Technical Deep Dive 20190618
Hyperledger Fabric Technical Deep Dive 20190618Hyperledger Fabric Technical Deep Dive 20190618
Hyperledger Fabric Technical Deep Dive 20190618Arnaud Le Hors
 

What's hot (20)

Introduction to Bitcoin's Scripting Language
Introduction to Bitcoin's Scripting LanguageIntroduction to Bitcoin's Scripting Language
Introduction to Bitcoin's Scripting Language
 
Ethereum-Cryptocurrency (All about Ethereum)
Ethereum-Cryptocurrency (All about Ethereum) Ethereum-Cryptocurrency (All about Ethereum)
Ethereum-Cryptocurrency (All about Ethereum)
 
Basics of Blockchain Technology
Basics of Blockchain TechnologyBasics of Blockchain Technology
Basics of Blockchain Technology
 
Blockchain 101 by imran bashir
Blockchain 101  by imran bashirBlockchain 101  by imran bashir
Blockchain 101 by imran bashir
 
Blockchain - HyperLedger Fabric
Blockchain - HyperLedger FabricBlockchain - HyperLedger Fabric
Blockchain - HyperLedger Fabric
 
Hyperledger Fabric Architecture
Hyperledger Fabric ArchitectureHyperledger Fabric Architecture
Hyperledger Fabric Architecture
 
Ethereum
EthereumEthereum
Ethereum
 
Bitcoin Addresses
Bitcoin AddressesBitcoin Addresses
Bitcoin Addresses
 
Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...
Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...
Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...
 
Introduction To Solidity
Introduction To SolidityIntroduction To Solidity
Introduction To Solidity
 
Understanding Proof of Work (PoW) and Proof of Stake (PoS) Algorithms
Understanding Proof of Work (PoW) and Proof of Stake (PoS) AlgorithmsUnderstanding Proof of Work (PoW) and Proof of Stake (PoS) Algorithms
Understanding Proof of Work (PoW) and Proof of Stake (PoS) Algorithms
 
Security in the blockchain
Security in the blockchainSecurity in the blockchain
Security in the blockchain
 
01 - Introduction to Hyperledger : A Blockchain Technology for Business
01 - Introduction to Hyperledger : A Blockchain Technology for Business01 - Introduction to Hyperledger : A Blockchain Technology for Business
01 - Introduction to Hyperledger : A Blockchain Technology for Business
 
Overview of blockchain technology and architecture
Overview of blockchain technology and   architectureOverview of blockchain technology and   architecture
Overview of blockchain technology and architecture
 
Introduction to Blockchain
Introduction to Blockchain Introduction to Blockchain
Introduction to Blockchain
 
Non-fungible tokens (nfts)
Non-fungible tokens (nfts)Non-fungible tokens (nfts)
Non-fungible tokens (nfts)
 
Ethereum in a nutshell
Ethereum in a nutshellEthereum in a nutshell
Ethereum in a nutshell
 
Introduction to bitcoin
Introduction to bitcoinIntroduction to bitcoin
Introduction to bitcoin
 
Hyperledger Fabric Technical Deep Dive 20190618
Hyperledger Fabric Technical Deep Dive 20190618Hyperledger Fabric Technical Deep Dive 20190618
Hyperledger Fabric Technical Deep Dive 20190618
 
Ethereum A to Z
Ethereum A to ZEthereum A to Z
Ethereum A to Z
 

Similar to Understanding hd wallets design and implementation

Hitcon badge 2018
Hitcon badge 2018 Hitcon badge 2018
Hitcon badge 2018 Alan Lee
 
Bitcoin developer guide
Bitcoin developer guideBitcoin developer guide
Bitcoin developer guide承翰 蔡
 
2019 03 18_kenneth_simplebitcoinwebsite
2019 03 18_kenneth_simplebitcoinwebsite 2019 03 18_kenneth_simplebitcoinwebsite
2019 03 18_kenneth_simplebitcoinwebsite Hu Kenneth
 
Bitcoin & Blockchain
Bitcoin & Blockchain Bitcoin & Blockchain
Bitcoin & Blockchain Len Mei
 
J.burke HackMiami6
J.burke HackMiami6J.burke HackMiami6
J.burke HackMiami6Jesse Burke
 
Bitcoin Wallet &amp Keys
Bitcoin Wallet &amp KeysBitcoin Wallet &amp Keys
Bitcoin Wallet &amp KeysShun Shiku
 
SMART Seminar Series: "Blockchain and its Applications". Presented by Prof Wi...
SMART Seminar Series: "Blockchain and its Applications". Presented by Prof Wi...SMART Seminar Series: "Blockchain and its Applications". Presented by Prof Wi...
SMART Seminar Series: "Blockchain and its Applications". Presented by Prof Wi...SMART Infrastructure Facility
 
Wallet from noob to pro
Wallet from noob to proWallet from noob to pro
Wallet from noob to proBrian Yap
 
以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)
以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)
以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)Nicholas Lin
 
create your own cryptocurrency
create your own cryptocurrencycreate your own cryptocurrency
create your own cryptocurrencyBellaj Badr
 
Crypto Wallets: A Technical Perspective (Nakov at OpenFest 2018)
Crypto Wallets: A Technical Perspective (Nakov at OpenFest 2018)Crypto Wallets: A Technical Perspective (Nakov at OpenFest 2018)
Crypto Wallets: A Technical Perspective (Nakov at OpenFest 2018)Svetlin Nakov
 
Crypto & Crpyocurrencies Intro
Crypto & Crpyocurrencies IntroCrypto & Crpyocurrencies Intro
Crypto & Crpyocurrencies IntroTal Shmueli
 
Deploy a blockchain web-app with Hyperledger Fabric 1.4 - Concepts & Code
Deploy a blockchain web-app with Hyperledger Fabric 1.4 - Concepts & CodeDeploy a blockchain web-app with Hyperledger Fabric 1.4 - Concepts & Code
Deploy a blockchain web-app with Hyperledger Fabric 1.4 - Concepts & CodeHorea Porutiu
 
Deployablockchainwebappwithhyperledgerfabricpresentation 190820170703
Deployablockchainwebappwithhyperledgerfabricpresentation 190820170703Deployablockchainwebappwithhyperledgerfabricpresentation 190820170703
Deployablockchainwebappwithhyperledgerfabricpresentation 190820170703Nevruz Mesut Sahin
 
A Quick Start To Blockchain by Seval Capraz
A Quick Start To Blockchain by Seval CaprazA Quick Start To Blockchain by Seval Capraz
A Quick Start To Blockchain by Seval CaprazSeval Çapraz
 

Similar to Understanding hd wallets design and implementation (20)

Hitcon badge 2018
Hitcon badge 2018 Hitcon badge 2018
Hitcon badge 2018
 
Bitcoin developer guide
Bitcoin developer guideBitcoin developer guide
Bitcoin developer guide
 
2019 03 18_kenneth_simplebitcoinwebsite
2019 03 18_kenneth_simplebitcoinwebsite 2019 03 18_kenneth_simplebitcoinwebsite
2019 03 18_kenneth_simplebitcoinwebsite
 
Tmc mastering bitcoins ppt
Tmc mastering bitcoins pptTmc mastering bitcoins ppt
Tmc mastering bitcoins ppt
 
Bitcoin & Blockchain
Bitcoin & Blockchain Bitcoin & Blockchain
Bitcoin & Blockchain
 
J.burke HackMiami6
J.burke HackMiami6J.burke HackMiami6
J.burke HackMiami6
 
Crypography in c#
Crypography in c#Crypography in c#
Crypography in c#
 
Bitcoin Wallet &amp Keys
Bitcoin Wallet &amp KeysBitcoin Wallet &amp Keys
Bitcoin Wallet &amp Keys
 
SMART Seminar Series: "Blockchain and its Applications". Presented by Prof Wi...
SMART Seminar Series: "Blockchain and its Applications". Presented by Prof Wi...SMART Seminar Series: "Blockchain and its Applications". Presented by Prof Wi...
SMART Seminar Series: "Blockchain and its Applications". Presented by Prof Wi...
 
Wallet from noob to pro
Wallet from noob to proWallet from noob to pro
Wallet from noob to pro
 
Bitcoin
BitcoinBitcoin
Bitcoin
 
以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)
以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)
以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)
 
Study on Bitcoin
Study on Bitcoin Study on Bitcoin
Study on Bitcoin
 
create your own cryptocurrency
create your own cryptocurrencycreate your own cryptocurrency
create your own cryptocurrency
 
Crypto Wallets: A Technical Perspective (Nakov at OpenFest 2018)
Crypto Wallets: A Technical Perspective (Nakov at OpenFest 2018)Crypto Wallets: A Technical Perspective (Nakov at OpenFest 2018)
Crypto Wallets: A Technical Perspective (Nakov at OpenFest 2018)
 
Crypto & Crpyocurrencies Intro
Crypto & Crpyocurrencies IntroCrypto & Crpyocurrencies Intro
Crypto & Crpyocurrencies Intro
 
Deploy a blockchain web-app with Hyperledger Fabric 1.4 - Concepts & Code
Deploy a blockchain web-app with Hyperledger Fabric 1.4 - Concepts & CodeDeploy a blockchain web-app with Hyperledger Fabric 1.4 - Concepts & Code
Deploy a blockchain web-app with Hyperledger Fabric 1.4 - Concepts & Code
 
Deployablockchainwebappwithhyperledgerfabricpresentation 190820170703
Deployablockchainwebappwithhyperledgerfabricpresentation 190820170703Deployablockchainwebappwithhyperledgerfabricpresentation 190820170703
Deployablockchainwebappwithhyperledgerfabricpresentation 190820170703
 
A Quick Start To Blockchain by Seval Capraz
A Quick Start To Blockchain by Seval CaprazA Quick Start To Blockchain by Seval Capraz
A Quick Start To Blockchain by Seval Capraz
 
Blockchain
BlockchainBlockchain
Blockchain
 

More from ArcBlock

ArcBlock Introduction to Blockchain
ArcBlock Introduction to BlockchainArcBlock Introduction to Blockchain
ArcBlock Introduction to BlockchainArcBlock
 
Forge blockchain deployment made easy
Forge  blockchain deployment made easyForge  blockchain deployment made easy
Forge blockchain deployment made easyArcBlock
 
Designing Decentralized Apps: Programmable Tokens
Designing Decentralized Apps: Programmable TokensDesigning Decentralized Apps: Programmable Tokens
Designing Decentralized Apps: Programmable TokensArcBlock
 
Build a Decentralized, public verifiable Database with ex_abci and Tendermint
Build a Decentralized, public verifiable Database with ex_abci and TendermintBuild a Decentralized, public verifiable Database with ex_abci and Tendermint
Build a Decentralized, public verifiable Database with ex_abci and TendermintArcBlock
 
ArcBlock Presents 5 Winning Factors to Building a Successful DApp
ArcBlock Presents 5 Winning Factors to Building a Successful DAppArcBlock Presents 5 Winning Factors to Building a Successful DApp
ArcBlock Presents 5 Winning Factors to Building a Successful DAppArcBlock
 
QRCodes are Fun, Easy, and Useful for Links, Payments and Identity Verification
QRCodes are Fun, Easy, and Useful for Links, Payments and Identity VerificationQRCodes are Fun, Easy, and Useful for Links, Payments and Identity Verification
QRCodes are Fun, Easy, and Useful for Links, Payments and Identity VerificationArcBlock
 
Designing Decentralized Applications (DApps)
Designing Decentralized Applications (DApps) Designing Decentralized Applications (DApps)
Designing Decentralized Applications (DApps) ArcBlock
 
Cryptography for everyone
Cryptography for everyoneCryptography for everyone
Cryptography for everyoneArcBlock
 
Introduction to HTTP/2 and How To Use It
Introduction to HTTP/2 and How To Use ItIntroduction to HTTP/2 and How To Use It
Introduction to HTTP/2 and How To Use ItArcBlock
 
IPFS: A Whole New World
IPFS: A Whole New WorldIPFS: A Whole New World
IPFS: A Whole New WorldArcBlock
 
Ethereum virtual machine for Developers Part 1
Ethereum virtual machine for Developers Part 1Ethereum virtual machine for Developers Part 1
Ethereum virtual machine for Developers Part 1ArcBlock
 
Technical Learning Series - Elixir ExUnit
Technical Learning Series - Elixir ExUnitTechnical Learning Series - Elixir ExUnit
Technical Learning Series - Elixir ExUnitArcBlock
 
Tendermint in a nutshell
Tendermint in a nutshellTendermint in a nutshell
Tendermint in a nutshellArcBlock
 
Introduction to CQRS & Commended
Introduction to CQRS & CommendedIntroduction to CQRS & Commended
Introduction to CQRS & CommendedArcBlock
 
Decipher Multi-Factor Authentication - A Developers Introduction
Decipher Multi-Factor Authentication - A Developers IntroductionDecipher Multi-Factor Authentication - A Developers Introduction
Decipher Multi-Factor Authentication - A Developers IntroductionArcBlock
 
Introduction to aws data pipeline services
Introduction to aws data pipeline servicesIntroduction to aws data pipeline services
Introduction to aws data pipeline servicesArcBlock
 
Introduction to Ethereum Smart Contracts
Introduction to Ethereum Smart Contracts Introduction to Ethereum Smart Contracts
Introduction to Ethereum Smart Contracts ArcBlock
 
ArcBlock Presents An Introduction to Blockchain
ArcBlock Presents An Introduction to BlockchainArcBlock Presents An Introduction to Blockchain
ArcBlock Presents An Introduction to BlockchainArcBlock
 

More from ArcBlock (18)

ArcBlock Introduction to Blockchain
ArcBlock Introduction to BlockchainArcBlock Introduction to Blockchain
ArcBlock Introduction to Blockchain
 
Forge blockchain deployment made easy
Forge  blockchain deployment made easyForge  blockchain deployment made easy
Forge blockchain deployment made easy
 
Designing Decentralized Apps: Programmable Tokens
Designing Decentralized Apps: Programmable TokensDesigning Decentralized Apps: Programmable Tokens
Designing Decentralized Apps: Programmable Tokens
 
Build a Decentralized, public verifiable Database with ex_abci and Tendermint
Build a Decentralized, public verifiable Database with ex_abci and TendermintBuild a Decentralized, public verifiable Database with ex_abci and Tendermint
Build a Decentralized, public verifiable Database with ex_abci and Tendermint
 
ArcBlock Presents 5 Winning Factors to Building a Successful DApp
ArcBlock Presents 5 Winning Factors to Building a Successful DAppArcBlock Presents 5 Winning Factors to Building a Successful DApp
ArcBlock Presents 5 Winning Factors to Building a Successful DApp
 
QRCodes are Fun, Easy, and Useful for Links, Payments and Identity Verification
QRCodes are Fun, Easy, and Useful for Links, Payments and Identity VerificationQRCodes are Fun, Easy, and Useful for Links, Payments and Identity Verification
QRCodes are Fun, Easy, and Useful for Links, Payments and Identity Verification
 
Designing Decentralized Applications (DApps)
Designing Decentralized Applications (DApps) Designing Decentralized Applications (DApps)
Designing Decentralized Applications (DApps)
 
Cryptography for everyone
Cryptography for everyoneCryptography for everyone
Cryptography for everyone
 
Introduction to HTTP/2 and How To Use It
Introduction to HTTP/2 and How To Use ItIntroduction to HTTP/2 and How To Use It
Introduction to HTTP/2 and How To Use It
 
IPFS: A Whole New World
IPFS: A Whole New WorldIPFS: A Whole New World
IPFS: A Whole New World
 
Ethereum virtual machine for Developers Part 1
Ethereum virtual machine for Developers Part 1Ethereum virtual machine for Developers Part 1
Ethereum virtual machine for Developers Part 1
 
Technical Learning Series - Elixir ExUnit
Technical Learning Series - Elixir ExUnitTechnical Learning Series - Elixir ExUnit
Technical Learning Series - Elixir ExUnit
 
Tendermint in a nutshell
Tendermint in a nutshellTendermint in a nutshell
Tendermint in a nutshell
 
Introduction to CQRS & Commended
Introduction to CQRS & CommendedIntroduction to CQRS & Commended
Introduction to CQRS & Commended
 
Decipher Multi-Factor Authentication - A Developers Introduction
Decipher Multi-Factor Authentication - A Developers IntroductionDecipher Multi-Factor Authentication - A Developers Introduction
Decipher Multi-Factor Authentication - A Developers Introduction
 
Introduction to aws data pipeline services
Introduction to aws data pipeline servicesIntroduction to aws data pipeline services
Introduction to aws data pipeline services
 
Introduction to Ethereum Smart Contracts
Introduction to Ethereum Smart Contracts Introduction to Ethereum Smart Contracts
Introduction to Ethereum Smart Contracts
 
ArcBlock Presents An Introduction to Blockchain
ArcBlock Presents An Introduction to BlockchainArcBlock Presents An Introduction to Blockchain
ArcBlock Presents An Introduction to Blockchain
 

Recently uploaded

英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 

Recently uploaded (20)

英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 

Understanding hd wallets design and implementation

  • 1. Understanding HD Wallets: Design and Implementation Brought to you by Shijun Wang 1
  • 2. HD Wallet= Hierarchical Deterministic Wallet 2
  • 4. What is Wallet? • Wallets contain keys, not coins, each user has a wallet containing keys • Users sign transactions with the keys, all transactions stored on blockchain 4
  • 5. What is Wallet? (ctnd.) 5
  • 7. What is Non-Deterministic Wallet? Random Wallet • Private/public key pairs are generated randomly, not related to each other • Backup/restore/migration must be done with each key pair • Satoshi Client : JBOK (just a bunch of keys) 7
  • 8. What is Non-Deterministic Wallet? (ctnd.) 8
  • 9. What is Deterministic Wallet? Seeded Wallet • Derive large amounts of private/public key pairs from same single seed phrase • Backup/restore/migration can be done with the seed phrase at creation time • Derive algorithm = one way hash function • Deterministic wallets can be sequential or hierarchical 9
  • 10. What is Sequential Deterministic Wallet? 10
  • 12. What is Hierarchical Deterministic Wallet? 12
  • 13. What is Hierarchical Deterministic Wallet? (ctnd.) • Generated private/public key pairs are organized into a tree, derived using a path • Tree structure can be used to express additional organizational meaning • Each node has private and public key, any node can derive any number of children • Can be shared partially or entirely with different systems, each with or without the ability to spend coins • Industry standard for generating multiple network wallets with same seed phrase, supported by most wallet apps 13
  • 14. Design and Implementation (BIP32 and BIP44) 14
  • 15. What is BIP then? BIP = Bitcoin Improvement Proposal Design document providing information to the Bitcoin community, or describing a new feature for Bitcoin or its processes or environment. Each BIP is assigned a number. • Meta BIP • BIP Workflow • Complete BIP list 15
  • 16. HD Wallet related BIPs • BIP32: Hierarchical Deterministic Wallets • BIP43: Purpose Field for Deterministic Wallets • BIP44: Multi-Account Hierarchy for Deterministic Wallets 16
  • 17. What is BIP32? Core BIP related to HD Wallet • Spec for key pair derivation from a master seed • Spec for wallet construction on top of such key pair tree 17
  • 18. BIP32: Child Key Derivation Algorithm? Child Key Derivation function • CKD is one-way hash function that make uses of following 3 inputs • A parent private or public key • A seed called a chain code • An index number (32 bits means 2^32 child) • Important property of derived keys • Child private keys are indistinguishable from non-deterministic (random) keys • Can be used to make a public key and a address • Can be used to sign transactions to spend anything paid to that address • The fact that they are part of a sequence is not visible outside of the HD wallet 18
  • 19. BIP32: How to Derive Child Private Key? 19
  • 20. BIP32: How to Derive Child Public Key? 20
  • 21. BIP32: How to Derive Child Key: Javascript HDKey.prototype.deriveChild = function(index) { var indexBuffer = Buffer.allocUnsafe(4); indexBuffer.writeUInt32BE(index, 0); var data = Buffer.concat([this.publicKey, indexBuffer]); var I = crypto.createHmac('sha512', this.chainCode).update(data).digest(); var IL = I.slice(0, 32); var IR = I.slice(32); var child = new HDKey(); if (this.privateKey) { child.privateKey = secp256k1.privateKeyTweakAdd(this.privateKey, IL); } else { child.publicKey = secp256k1.publicKeyTweakAdd(this.publicKey, IL, true); } child.chainCode = IR; child.depth = this.depth + 1; child.index = index; return child; }; 21
  • 22. BIP32: Child Key Derive Function Notation • Child private key derivation: • Child public key derivation: 22
  • 23. BIP32: Why Chain Code in CKD? • Introduce deterministic random data to the process • Initial chain code seed (at the root of the tree) is generated from the seed • Subsequent child chain codes are derived from each parent chain code • Add another layer to HD wallet privacy • Public key can be easily found, if chain code not present, all child keys are revealed 23
  • 24. BIP32: What is Extended Key? Child key derivation requires both parent key and parent chain code. • Extensible keys, keys that can derive children • Extended Private Key = Private Key + Chain Code , xpriv • Extended Public Key = Public Key + Chain Code , xpub • Can be root of a branch in the tree structure of the HD wallet • Knowing xpriv allows reconstruction of all descendant private keys and public keys • Knowing xpub allows reconstruction of all descendant public keys • Should be treated with more care than random generated public key 24
  • 25. BIP32: Where Should We Start? Master Key! Now we have CKD functions, where should we start to generate a tree? • Generate random extended keys directly? • We have a total of 2^512 extended keys, because it’s 512 bits long • But can only produced 2^256 possible public/private keys, because they are 256 bits long • Generate master key from potential random value ( better ) • Generate seed of a chosen length from RNG • Calculate HMAC-SHA512 hash from the seed • Split hash into 2 256-bits sequences • Left as master secret key, right as master chain code 25
  • 26. BIP32: From Seed to Master Key and Extended Key 26
  • 27. BIP32: Security Flaw with CKD 27
  • 28. BIP32: Rescue to Security Flaw: Hardened CKD 28
  • 29. BIP32: Child Key Derive Path Notation • CKDpriv(CKDpriv(CKDpriv(m,3),2),5) => m/3/2/5 • CKDpriv(CKDpriv(CKDpriv(m,3H),2),5) => m/3'/2/5 • CKDpub(CKDpub(CKDpub(m,0),0),0) => M/0/0/0 29
  • 30. BIP32: HD Wallet Structure Overview 30
  • 32. Why BIP44? • BIP32 specification offers implementors too many degrees of freedom, infinite depth • BIP32 compatible wallets can produce wallets with different logical structures 32
  • 33. What is BIP44? • BIP43: Purpose Field for Deterministic Wallets • BIP44: Multi-Account Hierarchy for Deterministic Wallets • Defined a specific logical hierarchy for deterministic wallets based on the algorithm described in BIP-32 • Provided a network agnostic method of generating secure keys in an incredibly flexible manner 33
  • 34. BIP44: Derive Path Notation Notation Example • CKD: m : CKDpriv is used, M for CKDPub • Purpose: 44' , hardened , which spec is used, 44 means BIP44 • Coin: 60' , hardened , 60 means Ethereum, coin types • Account: 0' , hardened , enable multiple accounts under single network • Change: 0 , 0 means external in Bitcoin, always 0 in Ethereum • Index: 0 , the first public/private key pair leaf node m / purpose' / coin_type' / account' / chain / address_index m/44'/60'/0'/0/0 34
  • 35. Making HD Wallet User Friendly (BIP39) 35
  • 37. What is Mnemonic Code? Mnemonic Code = Word sequences that represent a random number used as a seed to derive HD wallets • Easy to transcribe, record on paper • Easy to export and import into another wallet • More secure than brain wallet , 37
  • 38. What is BIP39? Mnemonic code for generating deterministic keys • Describes how to generate mnemonic code from random number • Describes how to convert mnemonic code to master seed 38
  • 40. BIP39: Entropy and Mnemonic code Different length of random number( entropy ) leads to different Mnemonic length Entropy Checksum Entropy + Checksum Mnemonic Length 128 4 132 12 160 5 165 15 192 6 198 18 224 7 231 21 256 8 264 24 Mnemonic word duplicate is possible 40
  • 41. BIP39: Mnemonic Code Wordlist Multilingual support (2048 words in each language): • English • Japanese • Korean • Spanish • Chinese (Simplified) • Chinese (Traditional) • French • Italian 41
  • 42. BIP39: Mnemonic Generating Code: Javascript function generateMnemonic(strength, rng, wordlist) { strength = strength || 128; if (strength % 32 !== 0) throw new TypeError(INVALID_ENTROPY); rng = rng || randomBytes; return entropyToMnemonic(rng(strength / 8), wordlist); } function entropyToMnemonic(entropy, wordlist) { if (!Buffer.isBuffer(entropy)) entropy = Buffer.from(entropy, 'hex'); wordlist = wordlist || DEFAULT_WORDLIST; var entropyBits = bytesToBinary([].slice.call(entropy)); var checksumBits = deriveChecksumBits(entropy); var bits = entropyBits + checksumBits; var chunks = bits.match(/(.{1,11})/g); var words = chunks.map(function(binary) { var index = binaryToByte(binary); return wordlist[index]; }); return wordlist === JAPANESE_WORDLIST ? words.join('u3000') : words.join(' '); } 42
  • 43. BIP39: Possible to Brute Force Attack Mnemonic? Take 12 words mnemonic, 2048 word list as example: • Possible permutation = 2048!/(2048 - 12)! = 5.27e+39 • 10000 guess/second = 10000 * 60 * 60 * 24 * 364 = 3.15*e+11 guess/year • Years take to check all = 1.67e+28 year Longer Mnemonic = Better Randomness = Better Security 43
  • 44. BIP39: From Mnemonic to Master Seed 44
  • 45. BIP39: From Mnemonic to Master Seed (code) function mnemonicToSeed(mnemonic, password) { var mnemonicBuffer = Buffer.from(unorm.nfkd(mnemonic), 'utf8'); var saltBuffer = Buffer.from(salt(unorm.nfkd(password)), 'utf8'); return pbkdf2(mnemonicBuffer, saltBuffer, 2048, 64, 'sha512'); } 45
  • 46. BIP39: Mnemonic + Passphrase = Better Security • Mnemonic • Checksum makes randomly generated word sequences invalid mnemonic • Possible set of 2^512 wallets, no practical possibility of brute-forcing or accidentally guessing one that is in use • Passphrase • Given a single mnemonic, every possible passphrase leads to a different seed • Passphrase as second factor, makes it hard to compromise the wallet when mnemonic leaked 46
  • 48. Mnemonic => Ethereum HD Wallet const bip39 = require('bip39'); const HDKey = require('hdkey'); const EthUtil = require('ethereumjs-util'); const mnemonic = bip39.generateMnemonic(128); const seed = bip39.mnemonicToSeed(mnemonic, ''); const master = HDKey.fromMasterSeed(seed); const account = master.derive("m/44'/60'/0'"); const addr = account.deriveChild(0).deriveChild(0); const pubKey = EthUtil.privateToPublic(addr.privateKey); const address = EthUtil.publicToAddress(pubKey).toString('hex'); // address: 0xd98efff831aaa4fe8834f9cb211d8397193a5492 48
  • 49. Mnemonic HD Wallet in Action 49
  • 51. Where to Learn More? • BIP32: Hierarchical Deterministic Wallets • BIP39: Mnemonic code for generating deterministic keys • BIP43: Purpose Field for Deterministic Wallets • BIP44: Multi-Account Hierarchy for Deterministic Wallets • Master Bitcoin 2nd Edition: Wallets and Address • Bitcoin Developer Guide • HD Wallet Playground: Support Many Chains • HD Wallet Playground: Only Ethereum Support 51
  • 52. 52