<h2>1. Storage of Keys, Addresses etc</h2>
<blockquote>
<p><strong>How exactly is all this stored?</strong></p>
</blockquote>
<h3>In General</h3>
<p>Any way that the developers of a particular wallet want. It is likely that different wallets store their data differently.</p>
<hr />
<h3>In Bitcoin core, for example.</h3>
<p>The wallet software named &quot;Bitcoin core&quot; will store the private keys in the <code>wallet.dat</code> file in the specified or default data directory. The default is <code>%APPDATA%/Bitcoin/</code> or <code>~/.bitcoin/</code> depending on platform. If a wallet password is provided, the key data is stored in encrypted form with the password being the encryption key (possibly indirectly and probably using AES IIRC).</p>
<p>The addresses generated are stored in the same file but need not be encrypted.</p>
<p>I don't know if the full derivation paths are explicitly stored.  I imagine that at least the least significant digits ought to be stored along with each derived address. <em>Maybe someone can comment</em>.</p>
<p><strong>BDB vs SQLite wallets</strong></p>
<p>The overall organisation of this file has changed and is based on simple <a href="https://en.wikipedia.org/wiki/Key%E2%80%93value_database" rel="nofollow noreferrer">key-value database</a> libraries, initially Berkeley-DB (BDB) and more recently SQLite AFAIK.</p>
<p><strong>Descriptor vs non-Descriptor wallets</strong></p>
<p>The keys and values have changed from the original form to a &quot;<a href="https://bitcoindevkit.org/descriptors/" rel="nofollow noreferrer">descriptor</a>&quot; form. So there are non-descriptor wallets and descriptor wallets.</p>
<p><strong>HD vs non-HD wallets</strong></p>
<p>There was also a change to <a href="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki" rel="nofollow noreferrer">Hierarchical Deterministic</a> (HD) wallets from the original non-HD wallet.</p>
<hr />
<h2>2. Derivation Paths</h2>
<blockquote>
<p><strong>I see that all addresses are identified using a path naming convention. Does that mean that all the paths are stored, and in a scenario where an address needs to be reused, it is regenerated each time?</strong></p>
</blockquote>
<p>Those are implementation details. I don't know how Bitcoin core or other wallets handle this and I believe anyone writing a wallet should make their own decisions.</p>
<p>If writing a wallet app, I would probably explicitly store all generated addresses and paths. Some other people would do something very different.</p>
<hr />
<h2>3. Further reading:</h2>
<ul>
<li><a href="https://bitcoin.stackexchange.com/q/3173/13866">What information does a wallet contain?</a></li>
<li><a href="https://bitcoin.stackexchange.com/q/103389/13866">View backed up wallet.dat using sqlite browser</a></li>
<li><a href="https://bitcoin.stackexchange.com/q/853/13866">What do the different .dat files contain?</a></li>
</ul>

CC BY-SA 4.0
2024-11-06T14:25:30.110Z
2024-11-06T14:56:56.217Z
2024-11-06T14:56:56.217Z
RedGrittyBrick
<p>As far as I'm aware, the recovery code is presented to the user once and then not stored at all by the wallet, in which case, it has to store at least the master private key, and would also probably store all the addresses (as it would be inefficient to regenerate them each time they are needed)</p>
<p>How exactly is all this stored?</p>
<p>From <a href="https://github.com/bitcoinbook/bitcoinbook/blob/third_edition_print1/ch05_wallets.adoc#hd-wallet-key-identifier-path" rel="nofollow noreferrer">here</a>, I see that all addresses are identified using a path naming convention.
Does that mean that all the paths are stored, and in a scenario where an address needs to be reused, it is regenerated each time?</p>

CC BY-SA 4.0
2024-11-06T14:25:49.323Z
This question is similar to: [How are derivation paths stored and regenerated for HD wallets?](https://bitcoin.stackexchange.com/questions/106928/how-are-derivation-paths-stored-and-regenerated-for-hd-wallets). If you believe it’s different, please [edit] the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem.
Vojtěch Strnad
<address><private-key><bip32-hd-wallets><storage>
How do HD wallets store the keys and addresses?
TechPro424
# How do HD wallets store the keys and addresses?

(Asked by: username_0 on 2024-11-06)

As far as I'm aware, the recovery code is presented to the user once and then not stored at all by the wallet, in which case, it has to store at least the master private key, and would also probably store all the addresses (as it would be inefficient to regenerate them each time they are needed)

How exactly is all this stored?

From [here](https://github.com/bitcoinbook/bitcoinbook/blob/third_edition_print1/ch05_wallets.adoc#hd-wallet-key-identifier-path), I see that all addresses are identified using a path naming convention.
Does that mean that all the paths are stored, and in a scenario where an address needs to be reused, it is regenerated each time?

**Tags:** address, private-key, bip32-hd-wallets, storage

> **Comments:**
> **username_1**: This question is similar to: [How are derivation paths stored and regenerated for HD wallets?](https://bitcoin.stackexchange.com/questions/106928/how-are-derivation-paths-stored-and-regenerated-for-hd-wallets). If you believe it’s different, please [edit] the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem.  

---

## 1 answers

### Answer by username_2 on 2024-11-06. Score: 0

## 1. Storage of Keys, Addresses etc

> **How exactly is all this stored?**

### In General

Any way that the developers of a particular wallet want. It is likely that different wallets store their data differently.

---

### In Bitcoin core, for example.

The wallet software named "Bitcoin core" will store the private keys in the `wallet.dat` file in the specified or default data directory. The default is `%APPDATA%/Bitcoin/` or `~/.bitcoin/` depending on platform. If a wallet password is provided, the key data is stored in encrypted form with the password being the encryption key (possibly indirectly and probably using AES IIRC).

The addresses generated are stored in the same file but need not be encrypted.

I don't know if the full derivation paths are explicitly stored. I imagine that at least the least significant digits ought to be stored along with each derived address. *Maybe someone can comment*.

**BDB vs SQLite wallets**

The overall organisation of this file has changed and is based on simple [key-value database](https://en.wikipedia.org/wiki/Key%E2%80%93value_database) libraries, initially Berkeley-DB (BDB) and more recently SQLite AFAIK.

**Descriptor vs non-Descriptor wallets**

The keys and values have changed from the original form to a "[descriptor](https://bitcoindevkit.org/descriptors/)" form. So there are non-descriptor wallets and descriptor wallets.

**HD vs non-HD wallets**

There was also a change to [Hierarchical Deterministic](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) (HD) wallets from the original non-HD wallet.

---

## 2. Derivation Paths

> **I see that all addresses are identified using a path naming convention. Does that mean that all the paths are stored, and in a scenario where an address needs to be reused, it is regenerated each time?**

Those are implementation details. I don't know how Bitcoin core or other wallets handle this and I believe anyone writing a wallet should make their own decisions.

If writing a wallet app, I would probably explicitly store all generated addresses and paths. Some other people would do something very different.

---

## 3. Further reading:

* [What information does a wallet contain?](https://bitcoin.stackexchange.com/q/3173/13866)
* [View backed up wallet.dat using sqlite browser](https://bitcoin.stackexchange.com/q/103389/13866)
* [What do the different .dat files contain?](https://bitcoin.stackexchange.com/q/853/13866)


---

