<p>After a bit of fiddling (see <a href="https://cardano.stackexchange.com/questions/831/what-encoding-is-used-for-yorois-wallet-export">What encoding is used for Yorois Wallet export?</a> and <a href="https://cardano.stackexchange.com/questions/833/why-is-there-a-small-difference-between-addresses-derived-by-the-cardano-address">Why is there a small difference between addresses derived by the cardano-address tool and Yoroi?</a>) I found a solution using the <a href="https://github.com/input-output-hk/cardano-addresses" rel="nofollow noreferrer">cardano-addresses tool</a> and the <a href="https://github.com/input-output-hk/bech32" rel="nofollow noreferrer">bech32 tool</a>.</p>
<p>Starting from a key exported from Yoroi (for this demonstration let's assume that this key is in a file <code>root_yoroi_raw.pub</code>):</p>
<pre><code># Encode the public key:
./bech32 acct_xvk &lt; root_yoroi_raw.pub &gt; root_yoroi.pub

# Derive the stake key:
cat root_yoroi.pub | ./cardano-address key child 2/0 &gt; stake.xvk

# Generate first Yoroi address:
cat root_yoroi.pub | ./cardano-address key child 0/0 | ./cardano-address address payment --network-tag mainnet &gt; payment1.addr
./cardano-address address delegation $(cat stake.xvk) &lt; payment1.addr &gt; payment-delegated1.addr
cat payment-delegated1.addr

# Generate second Yoroi address:
cat root_yoroi.pub | ./cardano-address key child 0/1 | ./cardano-address address payment --network-tag mainnet &gt; payment2.addr
./cardano-address address delegation $(cat stake.xvk) &lt; payment2.addr &gt; payment-delegated2.addr
cat payment-delegated2.addr
</code></pre>

CC BY-SA 4.0
2021-05-30T14:23:48.433Z
Just FYI, the bech32 and cardano-address tools are part of the cardano-wallet suite. If you download the cardano-wallet release you get all the tools plus some others https://github.com/input-output-hk/cardano-wallet.
nalyd88
CC BY-SA 4.0
2021-05-30T14:46:34.450Z
@nalyd88 Thanks for the hint! That could definitively come in handy.
Nos
CC BY-SA 4.0
2021-05-30T00:12:14.110Z
2021-05-30T00:12:14.110Z
Nos
<p>I would suggest you leave Yoroi out of it. You have a seed phrase that can generate your wallet private keys. So, use the <a href="https://github.com/input-output-hk/cardano-wallet" rel="nofollow noreferrer">cardano-wallet</a> tools to generate your keys, derive addressed, etc. You can do this in bash or call the cardano-wallet executables from a Python script.</p>

CC BY-SA 4.0
2021-05-29T21:43:49.160Z
Thanks for the suggestion. However, that is no option for me, since I want to create a watch-only wallet. I'm using a Ledger Nano S, and therefore the seed phrase/private key should not be stored anywhere else.
Nos
CC BY-SA 4.0
2021-05-29T22:04:31.130Z
You can use the cardano-node CLI to get the balance for an address. But you will have to have all the addresses that your wallet uses (since they automatically generate new ones for anonymity). There is not a way to just export a key and watch all the funds in the entire wallet. Cardano uses HD wallets so you need the private root key to derive all the addresses. Except for the stake key, that is unique and can be used to find all the addresses that belong to the wallet but doing so it non-trivial.
nalyd88
CC BY-SA 4.0
2021-05-29T22:09:11.167Z
Thanks for your help. However, I'm not sure whether what you are saying is correct. I think that knowledge of the extended public key associated with the wallet would allow me to derive all public keys and therefore addresses associated with the wallet. That is also supported by the hint that Yoroi gives during the export: 
"Below you can find your wallet's public key information. Public keys allow seeing the wallet history for the wallet, but does not allow to spend or move the funds in any way (private key is not included)"
Nos
CC BY-SA 4.0
2021-05-30T14:21:45.683Z
Yeah you are right. After the `1835H/1815H/0H` path you can get a public key that will allow you to generate addresses. I didn't think that Yoroi was outputting that key though. I figured it was the public key associated with the full derivation path e.g., `1835H/1815H/0H/0/1`.
nalyd88
CC BY-SA 4.0
2021-05-29T18:04:37.363Z
2021-05-29T18:04:37.363Z
nalyd88
<p>I’d like to code a small crypto portfolio app using python. So to track my ADA, I need to scan the addresses of my wallet.</p>
<p>I found Yorois feature to export a “key” and conveniently, it also states the derivation path. Unfortunately, I’m a noob with regard to key derivation and I’m a little confused by the encoding of the key, since it does not seem to come in a base58 format like BTC extended public keys.</p>
<p>So to have a common testing ground, I created a test wallet and this is the &quot;key&quot; that Yoroi gives me, when I go to Options=&gt;Wallet=&gt;Export Wallet=&gt;Export:</p>
<p><code>95e74df114717de17ebfb24c05f9fd1c8019bb6f1de117eec10a43670a692866b837a4a5f51d62f3dc3d630d075c8e39e5294323ba146c386c48123aeef5438a</code></p>
<p>So how would I go about generating addresses from this key using python libraries or the <a href="https://github.com/input-output-hk/cardano-addresses" rel="nofollow noreferrer">cardano-addresses tool</a>?</p>
<p>I already watched <a href="https://www.youtube.com/watch?v=4tSQBK75CPU" rel="nofollow noreferrer">Cardano: NerdOut - Key Derivation</a> by Andrew Westberg. Unfortunately, the public key used by Andrew was exported using Daedalus and not Yoroi and uses a different encoding.</p>
<p>So there are a two more specific questions, that may help with the solution of this problem:</p>
<ol>
<li>Did I grasp it correctly, that the key given by Yoroi just needs to be converted using bech32 and a xpub prefix, to generate a “standard” xpub key (e.g. <code>bech32 xpub &lt;&lt;&lt; yoroikey</code> using the <a href="https://github.com/input-output-hk/bech32" rel="nofollow noreferrer">bech32 tool</a>)?</li>
<li>Reading <a href="https://docs.cardano.org/projects/cardano-serialization-lib/en/latest/getting-started/generating-keys.html" rel="nofollow noreferrer">further info</a>, I learned that Cardano does not use standard BIP-44, but BIP-44-Ed25519. But is this even relevant for the address derivation using a xpub key? At least, looking at an <a href="https://github.com/sdlck/cardano-utils/blob/master/address-generator/addrGenerator.py" rel="nofollow noreferrer">example for Byron addresses</a>, it does not look that way, since the ed25519 library is just used at the very beginning of the derivation.</li>
</ol>
<p>Thanks.</p>
<p>EDIT: Added key for testing purposes.</p>

CC BY-SA 4.0
2021-05-29T12:37:24.727Z
+1 but it's better to ask 1 question per post. I recommend splitting it up so that this doesn't get closed as "needs more focus".
Nike Dattani
CC BY-SA 4.0
2021-05-29T13:29:50.150Z
Thanks for the hint. I thought about splitting up the question. However, that would introduce a lot of redundancy, since all the questions are part of the ultimate question that's in the title. Also, I don't necessarily care about the answers to the more specific questions, if there is an easier solution to the general question.
Nos
CC BY-SA 4.0
2021-05-29T16:15:46.637Z
You could put a link to the first question in the 2nd one.
Nike Dattani
<yoroi><address><python><cardano-address>
How to derive addresses from a key exported from Yoroi
# How to derive addresses from a key exported from Yoroi

(Asked by: username_0 on 2021-05-29)

I’d like to code a small crypto portfolio app using python. So to track my ADA, I need to scan the addresses of my wallet.

I found Yorois feature to export a “key” and conveniently, it also states the derivation path. Unfortunately, I’m a noob with regard to key derivation and I’m a little confused by the encoding of the key, since it does not seem to come in a base58 format like BTC extended public keys.

So to have a common testing ground, I created a test wallet and this is the "key" that Yoroi gives me, when I go to Options=>Wallet=>Export Wallet=>Export:

`95e74df114717de17ebfb24c05f9fd1c8019bb6f1de117eec10a43670a692866b837a4a5f51d62f3dc3d630d075c8e39e5294323ba146c386c48123aeef5438a`

So how would I go about generating addresses from this key using python libraries or the [cardano-addresses tool](https://github.com/input-output-hk/cardano-addresses)?

I already watched [Cardano: NerdOut - Key Derivation](https://www.youtube.com/watch?v=4tSQBK75CPU) by Andrew Westberg. Unfortunately, the public key used by Andrew was exported using Daedalus and not Yoroi and uses a different encoding.

So there are a two more specific questions, that may help with the solution of this problem:

1. Did I grasp it correctly, that the key given by Yoroi just needs to be converted using bech32 and a xpub prefix, to generate a “standard” xpub key (e.g. `bech32 xpub <<< yoroikey` using the [bech32 tool](https://github.com/input-output-hk/bech32))?
2. Reading [further info](https://docs.cardano.org/projects/cardano-serialization-lib/en/latest/getting-started/generating-keys.html), I learned that Cardano does not use standard BIP-44, but BIP-44-Ed25519. But is this even relevant for the address derivation using a xpub key? At least, looking at an [example for Byron addresses](https://github.com/sdlck/cardano-utils/blob/master/address-generator/addrGenerator.py), it does not look that way, since the ed25519 library is just used at the very beginning of the derivation.

Thanks.

EDIT: Added key for testing purposes.

**Tags:** yoroi, address, python, cardano-address
> **Comments:**
> **username_1**: +1 but it's better to ask 1 question per post. I recommend splitting it up so that this doesn't get closed as "needs more focus".  
> **username_0**: Thanks for the hint. I thought about splitting up the question. However, that would introduce a lot of redundancy, since all the questions are part of the ultimate question that's in the title. Also, I don't necessarily care about the answers to the more specific questions, if there is an easier solution to the general question.  
> **username_1**: You could put a link to the first question in the 2nd one.  

---

## 2 answers

### Answer by username_0 on 2021-05-30. Score: 0 | Accepted answer

After a bit of fiddling (see What encoding is used for Yorois Wallet export? and Why is there a small difference between addresses derived by the cardano-address tool and Yoroi?) I found a solution using the cardano-addresses tool and the bech32 tool.
Starting from a key exported from Yoroi (for this demonstration let's assume that this key is in a file root_yoroi_raw.pub):
# Encode the public key:
./bech32 acct_xvk < root_yoroi_raw.pub > root_yoroi.pub

# Derive the stake key:
cat root_yoroi.pub | ./cardano-address key child 2/0 > stake.xvk

# Generate first Yoroi address:
cat root_yoroi.pub | ./cardano-address key child 0/0 | ./cardano-address address payment --network-tag mainnet > payment1.addr
./cardano-address address delegation $(cat stake.xvk) < payment1.addr > payment-delegated1.addr
cat payment-delegated1.addr

# Generate second Yoroi address:
cat root_yoroi.pub | ./cardano-address key child 0/1 | ./cardano-address address payment --network-tag mainnet > payment2.addr
./cardano-address address delegation $(cat stake.xvk) < payment2.addr > payment-delegated2.addr
cat payment-delegated2.addr

> **Comments:**
> **username_2**: Just FYI, the bech32 and cardano-address tools are part of the cardano-wallet suite. If you download the cardano-wallet release you get all the tools plus some others https://github.com/input-output-hk/cardano-wallet.  
> **username_0**: @nalyd88 Thanks for the hint! That could definitively come in handy.  

---

### Answer by username_2 on 2021-05-29. Score: 1

I would suggest you leave Yoroi out of it. You have a seed phrase that can generate your wallet private keys. So, use the [cardano-wallet](https://github.com/input-output-hk/cardano-wallet) tools to generate your keys, derive addressed, etc. You can do this in bash or call the cardano-wallet executables from a Python script.

> **Comments:**
> **username_0**: Thanks for the suggestion. However, that is no option for me, since I want to create a watch-only wallet. I'm using a Ledger Nano S, and therefore the seed phrase/private key should not be stored anywhere else.  
> **username_2**: You can use the cardano-node CLI to get the balance for an address. But you will have to have all the addresses that your wallet uses (since they automatically generate new ones for anonymity). There is not a way to just export a key and watch all the funds in the entire wallet. Cardano uses HD wallets so you need the private root key to derive all the addresses. Except for the stake key, that is unique and can be used to find all the addresses that belong to the wallet but doing so it non-trivial.  
> **username_0**: Thanks for your help. However, I'm not sure whether what you are saying is correct. I think that knowledge of the extended public key associated with the wallet would allow me to derive all public keys and therefore addresses associated with the wallet. That is also supported by the hint that Yoroi gives during the export:  "Below you can find your wallet's public key information. Public keys allow seeing the wallet history for the wallet, but does not allow to spend or move the funds in any way (private key is not included)"  
> **username_2**: Yeah you are right. After the `1835H/1815H/0H` path you can get a public key that will allow you to generate addresses. I didn't think that Yoroi was outputting that key though. I figured it was the public key associated with the full derivation path e.g., `1835H/1815H/0H/0/1`.  

---

