Key Management
key management in this section, we will cover general terms – public key, private key, and an address, and how samsung blockchain keystore generates and manages these keys. samsung blockchain keystore is a hierarchical deterministic (hd) wallet and follow the industry standards of bip-32, bip-39 and bip-44. (bip stands for bitcoin improvement proposal). by implementing these standards, samsung blockchain keystore aim to provide better user experience to back up the wallet, since the user only needs to keep the root seed of the private and public keys safe. it is just the 12 words generated from samsung blockchain keystore that user needs to remember or write down. we will look into how this is achieved by implementing hierarchical deterministic wallet in samsung blockchain keystore. public key, private key, and address the key pair is mandatory to participate in the blockchain network. this key pair is composed of a public key and a private key. public key is used to derive an address that is used like a user’s account in blockchain. it is safe to share the public key or the address with others. on the other hand, a private key is used to sign transactions and must be kept secret. anyone who has access to the private key can sign transactions and spend cryptocurrency or use crypto-assets without user’s permission. simply put, the private key is a random number. based on the private key, there are algorithms, like elliptic curve digital signature algorithm (ecdsa) that derives the public key. this algorithm may differ depending on the blockchain platform. but one interesting characteristic of a public key is that it is derived from a private key, but the other way around is not possible – public key cannot derive nor predict the private key. the same relationship applies to the public key and the address. address, which is used like a user’s account, cannot derive any public keys. since a private key is a random number, this implies that the randomness of a private key generation must be guaranteed. yet, software random number generators, also known as pseudo random number generators, are known to have security vulnerabilities. because the public key and address format differs by blockchain platforms, user needs to have one key pair for ethereum, another key pair for bitcoin, and etc. if a user wants several accounts for ethereum, then that many number of key pairs will be required. moreover, bitcoin uses countless number of accounts, because after a transaction has been made, any bitcoin changes after the transaction is returned to a different account of the user’s. in other words, it becomes very complex and inconvenient if a user would have to save a key pair for every blockchain account that the user holds. samsung blockchain keystore aims to reduce this by implementing hierarchical deterministic wallet. hierarchical deterministic wallet (hd wallet) hierarchical deterministic wallet allows these multiple key pairs to be derived from a single root seed called, “root seed.” root seed is the root of a large tree of public and private keys. this root seed is the only thing that user needs to store and back up. this is the key to access all of your crypto secrets, so how it is generated and stored should be kept in a secure environment. root seed is between 128 and 256 bits and because the physical look of root seed is not very user friendly, and is a combination of “0” and “1”, there is an industry standard, to replace them with mnemonic words, or a group of words. for example, if the root seed is 128 bits, then with the checksum of 4 bits, a total of 132 bits is split into a group of 11 bits. each group falls into a group number between 0 and 2047, which is an index to a wordlist of 2048 words. these index numbers are then converted into the corresponding words and the combination of 12 words make up “recovery phrase” in samsung blockchain keystore. generating root seed and mnemonic words in samsung blockchain keystore samsung blockchain keystore generates the root seed by trusted app in trusted execution environment, by the steps below: ① true random number generator (trng), also known as hardware random number generator, that is embedded into samsung device chipsets, generates an initial entropy length (ent) of 128 random bits. elaborating more on ent, industry standard allows 128 to 256 bits, in multiple of 32 bits. depending on the length of the initial entropy length, the number of words that this will be converted into will differ, from 12 to 24, in multiple of 3. ② samsung blockchain keystore takes the first 4 bits of the sha-256 hash of the 128 bits to generate something called, “checksum.” theoretically, it is ent/32 that is taken to generate the checksum. so for samsung blockchain keystore, ent is 128 bits, resulting in 4 bits of checksum. for other wallets that generate 24 words with the ent of 256 bits, 8 bits are used as a checksum. ③ samsung blockchain keystore appends the previously generated 4 bits of checksum to the initial entropy length, resulting in 132 bits. ④ 132 bits (combination of initial entropy length and checksum) are divided into 11 bits, resulting in 12 words, “mnemonic codes”. these 12 words are industry standard, and is one of the 2048 words on the bip-39 english wordlist. ⑤ because the 12 words follow bip-39 standard used in the industry, user can back up wallet on a different samsung device that supports samsung blockchain keystore, or other wallets that are bip-39-compatible. importing a wallet when a user imports a wallet in samsung blockchain keystore, the user will enter the 12, 18 or 24 words into the trusted user interface (tui) that will protect user’s input. this time, samsung blockchain keystore will convert the mnemonic words entered in order to the original root seed. the root seed is the one and only source that samsung blockchain keystore will save in a secure area. likewise, this will become the source to generate countless number of public keys and sign transactions with the private keys when a request is made. randomly entering mnemonic words to guess recovery phrase some may raise a question on the feasibility of guessing the words among 2048 words on the mnemonic words list and somehow, getting access to the private key that corresponds to the recovery phrase. but it’s not just the words of 12 to 24 in multiple of 3, that have to correctly chosen, but the order of these words have to be correct as well. this is because if you are using 12 words, then 128 bits must be correctly guessed, and 266 bits for 24 words. choice between 0 and 1 on 128 bits give us 2 x 2 x 2 x … 2 = 2128 of the possible root seeds, and 2^256 cases for 24 words. moreover, the checksum of 4 bits for 12 words, and 8 bits for 24 words, protects randomly making a combination of words. when importing a wallet in samsung blockchain keystore, there is a checksum check after user has entered 12, 18 or 24 words, and it will throw an error that the combination of words entered isn’t a valid recovery phrase. the user will receive absolutely no information on which words make the checksum invalid, making it even more difficult to randomly guess the recovery phrase. hd path the hd wallet is a tree of theoretically infinite number of private and public keys. one interesting fact is that it allows derivation of a child keys from the root seed via a function defined in bip-32 standard, “child key derivation (ckd) functions.” this means with the root seed and the location of the tree, key derivation is feasible. more details on the key derivations can be found in the appendix. the location in the tree is called a “path” and bip-44 standard defines the standard to unify rules for wallet’s compatibility of these hd key generation. hence developers just need to specify the path to derive the address from, and whoever keeps the root seed will be able to calculate and return the actual key value for that specified location. each depth is represented by “/” in the hd path and the apostrophe (‘) implies that the depth is hardened. the following is hd path level standard defined in bip-44. ![](/sd2_images/services/blockchain/hd_path _level_standard.png) purpose’ is “44” here, with the implication that it is the following bip-44 standard. coin_type’ tells if it is ethereum, bitcoin, or other coins. the algorithms to derive the public key from the private key can differ by the coin type, though both ethereum and bitcoin use ecdsa algorithm. the number is constant and set for each crypto, and it can be registered in slip-0044 (slip: satoshilabs improvement proposals), managed by satoshilabs. for example, it is “0” for bitcoin, and “60” for ethereum. account‘ represents multiple accounts number and is usually ‘0’. change is usually used in bitcoin, using “1” for the account to receive all the changes after sending bitcoins to other accounts. normally, “0” is used. address_index is the last depth, and usually starts with 0, and increases by one, when you “add” an account in a wallet. for example, hd path for the first account of ethereum is: m/44’/60’/0’/0/0 and for the second account of bitcoin is: m/44’/0’ /0’/0/1 use of hd path in samsung blockchain keystore samsung blockchain keystore can be used to (1) derive an address or extended public key and (2) sign a transaction. to consume these two features, developers of dapps or wallets will need to define, where in the hd tree, they would like to derive the public key from, and use the corresponding private key to sign the transaction. hd path is a required parameter for apis related to the two features below. get address from samsung blockchain keystore if you are a dapp or wallet developer, you can use samsung blockchain keystore to first get the user’s address or extended public key (public key and the chain code), and search on the blockchain ledger, transaction history and records of the user, so that user can know how much cryptocurrency or crypto-asset is remaining. here’s a brief flow of getting the address. ① wallet or dapps will make a request to samsung blockchain keystore to derive an address or extended public key for hd path “m/44’/60’/ 0’/0/0” (ethereum account). ② using samsung blockchain keystore sdk, wallet/dapp’s request will be passed to samsung blockchain keystore. ③ once samsung blockchain keystore will receives the request to get the address or extended public key, it will pass onto the controller to communicate with trusted app to derive the public key. ④ root seed is stored safely in a secure area, and the derivation of the extended public key (public key and the chain code) of the hd path, is executed by trusted application in trusted execution environment. ⑤ derived public key will be then passed to samsung blockchain keystore app to derive the address, where one more algorithm function will be executed. ⑥ after the calculation, the address that corresponds to the requested hd path will be returned to wallet or dapp via samsung blockchain keystore sdk. sign a transaction by samsung blockchain keystore the user will now want to make a transaction, such as sending cryptocurrencies, that will require the user to “write” on the ledger. this change needs to be signed by the private key that corresponds to the user’s address, derived from user’s public key. below is a diagram and explanation for each step. ① wallet or dapps will make a request to samsung blockchain keystore to sign a transaction. a correctly formatted transaction without the signature part, and hd path to derive the private key to sign the transaction will be needed. ② using samsung blockchain keystore sdk, wallet/dapp’s request will be passed to samsung blockchain keystore. ③ once samsung blockchain keystore will receives the request to get the public key, it will pass onto the controller to communicate with trusted app. ④ trusted app will first parse the transaction, and show critical information on tui, such as recipient address, amount and fees. after user checks the transaction details, user will confirm it via pin verification or fingerprint authentication. ⑤ after the user’s confirmation, the safely stored root seed will now be used to derive the private key that corresponds to the hd path that was passed with the transaction request. then the trusted application will sign the transaction with the derived private key. likewise, these are all executed in trusted execution environment. ⑥ the signed transaction will be returned to samsung blockchain keystore app. ⑦ samsung blockchain keystore app will return the signed transaction to wallet/dapp via samsung blockchain keystore sdk and wallet/dapps can now submit the signed transaction to the blockchain network. more details on the bip-32, bip-39 and bip-44 can be found in the following links. **bip-32:** hierarchical deterministic wallets [https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) bip-39: mnemonic code for generating deterministic keys https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki#wordlists bip-44: multi-account hierarchy for deterministic wallets https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki slip-44: registered coin types for bip-0044 https://github.com/satoshilabs/slips/blob/master/slip-0044.md