4

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?

I already watched Cardano: NerdOut - Key Derivation 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)?
  2. Reading further info, 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, 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.

3
  • 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". May 29, 2021 at 12:37
  • 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
    May 29, 2021 at 13:29
  • You could put a link to the first question in the 2nd one. May 29, 2021 at 16:15

2 Answers 2

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 tools to generate your keys, derive addressed, etc. You can do this in bash or call the cardano-wallet executables from a Python script.

4
  • 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
    May 29, 2021 at 21:43
  • 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
    May 29, 2021 at 22:04
  • 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
    May 29, 2021 at 22:09
  • 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
    May 30, 2021 at 14:21
0

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
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 github.com/input-output-hk/cardano-wallet.
    – nalyd88
    May 30, 2021 at 14:23
  • @nalyd88 Thanks for the hint! That could definitively come in handy.
    – Nos
    May 30, 2021 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.