|
1 | | -[install] |
| 1 | +# 10.1: Creating Secrets from the Command Line |
| 2 | + |
| 3 | +Bitcoin addresses are ultimately built on a hierarchy of secrets. In |
| 4 | +an HD wallet, a seed leads to a master key which leads to an account |
| 5 | +key which leads to address keys. However, in Bitcoin Core, you never |
| 6 | +see the seed, even though it's the fundamental use of interoperability |
| 7 | +for the wider Bitcoin ecosystem. This section shows you how to create |
| 8 | +a seed, which we'll import into Bitcoin Core over the course of this |
| 9 | +chapter. |
| 10 | + |
| 11 | +## Understand How Seeds Work |
| 12 | + |
| 13 | +A seed is a secret. It's a large number. As we discussed in |
| 14 | +[§3.4](03_4_Understanding_the_Descriptor_Wallet.md), it's also the |
| 15 | +foundation of a hierarchy of secrets: |
| 16 | + |
| 17 | +* A master private key is derived from the seed. |
| 18 | +* Account private keys are derived from the master private key and an |
| 19 | +account derivation path (e.g., `84h/0h/0h` for a P2WPKH account). |
| 20 | +* Address private keys are derived from an account private key and an |
| 21 | +address derivation path (e.g., `0/0` for the first external |
| 22 | +address). |
| 23 | +* Public keys are derived from the associated public keys. |
| 24 | +* Addresses are derived from address public keys. |
| 25 | + |
| 26 | +The descriptors that we first encountered in §3.4 are made up of the lower-level secrets in this hierarchy: |
| 27 | +``` |
| 28 | +wpkh([e18dae20/84h/1h/0h]tpubDC4ujMbsd9REzpGk3gnTjkrfJFw1NnvCpx6QBbLj3CHBzcLmVzssTVP8meRAM1WW4pZnK6SCCPGyzi9eMfzSXoeFMNprqtgxG71VRXTmetu/0/*)#3658f8sn", |
| 29 | +``` |
| 30 | + |
| 31 | +Here: |
| 32 | + |
| 33 | +* `e18dae20` is a fingerprint of the **master public key** (but we don't actually see it). |
| 34 | +* `/84h/1h/0h` is the **account derivation path**. |
| 35 | +* `tpubDC4ujMbsd9REzpGk3gnTjkrfJFw1NnvCpx6QBbLj3CHBzcLmVzssTVP8meRAM1WW4pZnK6SCCPGyzi9eMfzSXoe` is the **account public key**. |
| 36 | +* `/0/*` is a **ranged address derivation path**. |
| 37 | + |
| 38 | +That's sufficient to regenerate all the external P2WPKH addresses in |
| 39 | +this wallet, but it hides the seed and the master private key, which |
| 40 | +lowers the ineroperability: we'd have to import each of our eight or |
| 41 | +more descriptors independently into another wallet (including four |
| 42 | +different private keys), rather than being able to just load up the |
| 43 | +seed and tell it what derivation paths to use. |
| 44 | + |
| 45 | +The seed is great, because it's ultimately the only secret you need to |
| 46 | +recover your funds (though it might be a lot of work if you don't know |
| 47 | +the proper derivation paths, and you could lose funds if you only had |
| 48 | +the seed and you used non-standard derivation paths). That's why in |
| 49 | +this chapter we're going to step outside of the Bitcoin Core paradigm |
| 50 | +to create a seed, then import that into Bitcoin Core by hand. |
| 51 | + |
| 52 | +> 📖 **What is a seed?** A seed is a "top-level" secret in |
| 53 | +Bitcoin. It's what's used to generate all the keys that you use to |
| 54 | +secure your Bitcoin funds. Technically, if you're using a BIP-32 |
| 55 | +hierarchical wallet, the seed generates a master key, which generates |
| 56 | +account keys, which generates address keys, which generates addresses. |
| 57 | + |
| 58 | +## Install Your Own Seed Generator |
| 59 | + |
| 60 | +We have to go outside of Bitcoin Core to generate seeds (or at least |
| 61 | +to generate seeds that we can actually see). To accomplish this (and |
| 62 | +later to transform and archive seeds), we're going to use a variety of |
| 63 | +command-line tools created by [Blockchain |
| 64 | +Commons](https://www.blockchaincommons.com/). The first one, which |
| 65 | +generates seeds, is |
| 66 | +[`seedtool`](https://github.com/BlockchainCommons/seedtool-cli). |
| 67 | + |
| 68 | +### Install Rust |
| 69 | + |
| 70 | +`seedtool` is a Rust tool, which means that it can easily be installed |
| 71 | +with `cargo`, but you have to have Rust installed first. If you |
| 72 | +already have Rust installed, skip ahead, otherwise continue on. |
| 73 | + |
| 74 | +If want to install Rust on a Debian machine, such as the Linode that |
| 75 | +we suggest, follow a three-step process. |
| 76 | + |
| 77 | +First, install the C compiler: |
| 78 | + |
| 79 | +``` |
| 80 | +$ sudo apt-get install build-essential |
| 81 | +``` |
| 82 | + |
| 83 | +Second, use `curl` to install Rust. The following will install it into |
| 84 | +your current account. Choose the "standard installation" when you're |
| 85 | +asked: |
| 86 | + |
| 87 | +``` |
| 88 | +$ curl https://sh.rustup.rs -sSf | sh |
| 89 | +``` |
| 90 | + |
| 91 | +Third, reset your environment: |
| 92 | + |
| 93 | +``` |
| 94 | +$ . "$HOME/.cargo/env" |
| 95 | +``` |
| 96 | + |
| 97 | +For Mac, follow a similar procedure, but skip the `apt-get` and |
| 98 | +instead `xcode-select --install` if you don't have a C compiler |
| 99 | +installed. |
| 100 | + |
| 101 | +For Windows, see Rust's [other installation |
| 102 | +methods](https://forge.rust-lang.org/infra/other-installation-methods.html). |
| 103 | + |
| 104 | +### Install Seedtool |
| 105 | + |
| 106 | +Once you have Rust installed, installing Rust packages is easy. The |
| 107 | +following will install `seedtool`: |
| 108 | + |
| 109 | +``` |
| 110 | +$ cargo install seedtool-cli |
| 111 | +``` |
| 112 | + |
| 113 | +> ⚠️ **Memory Pressure.** We've had our little 4G Debian Linode get |
| 114 | +stuck when we asked it to install multiple Rust crates back to |
| 115 | +back. If a `cargo install` seems to get stuck, with "memory pressure" |
| 116 | +warnings, reboot the machine and try again. |
| 117 | + |
| 118 | +## Use Seedtool |
| 119 | + |
| 120 | +Using seedtool is also ridiculously easy. You run `seedtool` and it generates a seed. |
| 121 | + |
| 122 | +``` |
| 123 | +$ SEED=$(seedtool) |
| 124 | +$ echo $SEED |
| 125 | +f6cfffce024b5b1a8d8925aa6903d039 |
| 126 | +``` |
| 127 | + |
| 128 | +You've now got a seed that you can use to generate entire hierarchies of Bitcoin addresses! |
| 129 | + |
| 130 | +## Backup Your Seed |
| 131 | + |
| 132 | +Hexadecimal seeds like `f6cfffce024b5b1a8d8925aa6903d039` can be a |
| 133 | +little unwieldly. You're not going to remember them, and it would be |
| 134 | +easy to corrupt a seed by losing or changing a digit. |
| 135 | + |
| 136 | +Seedtool allows you to translate a seed into a friendlier format by |
| 137 | +reading in your hex with a `-i hex` flag and then outputting it in |
| 138 | +your favorite format with `-o [type]`. This includes a variety of |
| 139 | +output formats that are great for backup. |
| 140 | + |
| 141 | +> ⚠️ **Don't Forget the -i.** If you omit the `-i` flag, `seedtool` |
| 142 | +will instead generate a new seed and then convert that. That's almost |
| 143 | +definitely not what you want! |
| 144 | + |
| 145 | +`seedtool --help` lists all the possible output (and input) |
| 146 | +formats. Three are discussed below: BIP-39 (`bip39`), Bytewords |
| 147 | +(`btw`), and SSKR (`sskr`). |
| 148 | + |
| 149 | +[§10.5](10_5_Storing_Secrets_with_Envelope.md) will discuss how to use |
| 150 | +Gordian Envelope for even more powerful and resilient storage of |
| 151 | +secrets. But these are a great start. |
| 152 | + |
| 153 | +### Backup as BIP-39 |
| 154 | + |
| 155 | +[BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) |
| 156 | +invented the idea of a seed phrase. It allows a seed to be converted |
| 157 | +into a list of words that are less prone to errors when you store and |
| 158 | +recover them. Choosing `-o bip39` will output your seed as an |
| 159 | +English-language BIP-39 word list: |
| 160 | + |
| 161 | +``` |
| 162 | +$ seedtool -i hex $SEED -o bip39 |
| 163 | +walnut lend vicious afraid remember minute curtain caution price elite village inhale |
| 164 | +``` |
| 165 | + |
| 166 | +This word list can then be stored somewhere safe. The [#SmartCustody |
| 167 | +course](https://www.smartcustody.com/) suggests inscribing it into |
| 168 | +metal. This should make your seed much less prone to loss. |
| 169 | + |
| 170 | +> 📖 **What is a seed phase?** A collection of 12 or 24 ordered |
| 171 | +mnemonic words can define a seed. Though seed phrases are not |
| 172 | +currently used by Bitcoin Core, they are in wide use in the larger |
| 173 | +Bitcoin ecosystem. |
| 174 | + |
| 175 | +### Backup as Bytewords |
| 176 | + |
| 177 | +Blockchain Commons has its own set of mnemonic words, |
| 178 | +[Bytewords](https://developer.blockchaincommons.com/bytewords/), which |
| 179 | +are more regular that BIP-39 words and chosen to be easy to remember |
| 180 | +and hard to confuse. (They're also the foundation of the |
| 181 | +[UR](https://developer.blockchaincommons.com/ur/) and [Animated |
| 182 | +QR](https://developer.blockchaincommons.com/animated-qrs/) technology |
| 183 | +that you used [§8.4](08_4_Creating_Animated_QR_Codes.md).) |
| 184 | + |
| 185 | +You can output as Bytewords with `-o btw` |
| 186 | + |
| 187 | +``` |
| 188 | +$ seedtool -i hex $SEED -o btw |
| 189 | +yawn task zoom taco also gear help city lung loud data peck iron apex taxi eyes kept miss ramp huts |
| 190 | +``` |
| 191 | + |
| 192 | +### Backup as SSKR |
| 193 | + |
| 194 | +Backups tend to increase resilience (the odds that your secret is |
| 195 | +lost) but also increase the chance of compromise (the odds that your |
| 196 | +secret is stolen). The more copies of something you make, the better |
| 197 | +your chance of recovering that secret, but the more likely someone |
| 198 | +else steals it. |
| 199 | + |
| 200 | +Shamir's Secret Sharing resolves that issue by letting you shard a |
| 201 | +secret, distribute the shares created, and then reconstruct your |
| 202 | +secret from some fraction (a "threshold") of those shares. It's common |
| 203 | +to create shares with a 2-of-3 threshold (there are three shares, but |
| 204 | +you can reconstruct from any two) or a 3-of-5 threshold (there are |
| 205 | +five shares, you can reconstruct from any three). |
| 206 | + |
| 207 | +[SSKR](https://developer.blockchaincommons.com/sskr/) is Blockchain |
| 208 | +Commons' expansion of Shamir's Secret Sharing, which is built into |
| 209 | +reference applications such as `seedtool` and `envelope`. |
| 210 | + |
| 211 | +SSKR shares can be created through `-o sskr` and a `--groups` variable |
| 212 | +that defines the threshold. The output is all done in Blockchain |
| 213 | +Commons specified formats. The following outputs SSKR shares as URs: |
| 214 | + |
| 215 | +``` |
| 216 | +$ seedtool -i hex $SEED -o sskr --groups 2-of-3 --sskr-format ur |
| 217 | +ur:sskr/gocfaaaeadaenskelybeetesvytptnehrytaemsnetjemhpanlcp |
| 218 | +ur:sskr/gocfaaaeadadpdpscknbmtensncnbbdaaasgaholrpsortuywpsp |
| 219 | +ur:sskr/gocfaaaeadaowkstoxjelbdirhechlcftyzmgucwfheetdeooxvl |
| 220 | +``` |
| 221 | + |
| 222 | +`seedtool -i sskr` can then be used to input any two of these shares |
| 223 | +and regenerate the seed: |
| 224 | + |
| 225 | +``` |
| 226 | +$ seedtool -i sskr |
| 227 | +ur:sskr/gocfaaaeadaenskelybeetesvytptnehrytaemsnetjemhpanlcp |
| 228 | +ur:sskr/gocfaaaeadaowkstoxjelbdirhechlcftyzmgucwfheetdeooxvl |
| 229 | +^D |
| 230 | +f6cfffce024b5b1a8d8925aa6903d039 |
| 231 | +``` |
| 232 | + |
| 233 | +[#SmartCustody](https://github.com/BlockchainCommons/SmartCustody/blob/master/Docs/SSKR-Sharing.md) |
| 234 | +contains more information on how to design a scenario for how many |
| 235 | +shares to create, where to store them, and what threshold to use. |
| 236 | + |
| 237 | +## Summary: Creating Secrets from the Command Line |
| 238 | + |
| 239 | +This section offered two simple lessons: how to create a seed and why |
| 240 | +you'd want to. Doing so allows the ultimate portability: you can use |
| 241 | +that same seed to create the same keys and addresses in different |
| 242 | +wallets. |
| 243 | + |
| 244 | +> 🔥 **_What is the Power of Seeds?_** Seeds are as far as you can get |
| 245 | +from a bag of keys. They are a singular secret that you can use to |
| 246 | +create many different addresses in many different accounts. They're |
| 247 | +the intended root of a HD wallet, even if they're not visible in |
| 248 | +Bitcoin Core. |
| 249 | + |
| 250 | +## What's Next? |
| 251 | + |
| 252 | +Continue "Exploring the Ecosystem" with [§10.2: Converting Secrets with |
| 253 | +Keytool](10_2_Converting_Secrets_with_Keytool.md). |
2 | 254 |
|
3 | | -$ seedtool |
4 | | -2635481b4cb633e9a7f55e455e3d5aed |
5 | 255 |
|
0 commit comments