howardwu / wagyu

A Rust library for generating cryptocurrency wallets
https://wagyu.dev
Apache License 2.0
610 stars 106 forks source link

Generate multiple addresses for the same wallet #167

Open BlinkyStitt opened 4 years ago

BlinkyStitt commented 4 years ago

Hello! Thanks for the awesome library!

I have an ethereum mnemonic and am trying to generate 10 addresses using BIP44. What's the best way to do this?

If I run wagyu ethereum hd --count 10 it generates 10 separate wallets, which is not what I want.

There sure are a lot of different ways of handling the path, but BIP44 defines the path as m / purpose' / coin_type' / account' / change / address_index. import-hd only has a flag for --index. I would like to set the account (and maybe change), too.

This probably belongs on a separate issue, but while trying to figure this out, I think --index is not working like I expect it to.

$ wagyu ethereum import-hd -m "virus harbor pact end relief change limit magnet screen term desert fit" -d "ethereum" --index 9

      Path                 m/44'/60'/0'/9
      Mnemonic             virus harbor pact end relief change limit magnet screen term desert fit
      Extended Private Key xprvA221HiWQYs4iPcXEEUxdTJqHncsaSMNotBhCtnC7CfJKscyA1MfxApf91xsNhFrMBfMFBbzkPjSAvbqCWiaXUAMPzzMS2jAy9pJ4npaLmmR
      Extended Public Key  xpub6F1MhE3JPEd1c6bhLWVdpSn2Lei4qp6fFQcohAbikzqJkRJJYtzCicycsGt7BURuCw4aHXqNir5fjmTbM4FiWwk4TWXvF74NspU4XnSHTes
      Private Key          451171f4c637bfb35d44d859886d363b64114d84afc3423c6606fed0a7ec3536
      Public Key           cdcf2b1c5bae5b57e1cc2f01c1b62f9c4cc75970d050d855052c7bfd3762582716a0e785182d18eee5c35678495a047b07d34566633f57e728d2246c9741f1e1
      Address              0x6b9472ebbfe4F7EF4eFe57013A5dC35303A6B452

I expected "Path" to be m/44'/60'/0'/0/9 like Ganache uses:

$ wagyu ethereum import-hd -m "virus harbor pact end relief change limit magnet screen term desert fit" -d "m/44'/60'/0'/0/9"

      Path                 m/44'/60'/0'/0/9
      Mnemonic             virus harbor pact end relief change limit magnet screen term desert fit
      Extended Private Key xprvA3yJkjbs6TKGjx6zr8fkWvDEkmEFfXqUziiQEFPTMMnai5qxbEvH4HBatpadpVN4B1j41rvyd1FvQkfuxvKq3H8rUGPJTAV9nsWboS6mY6e
      Extended Public Key  xpub6GxfAF8kvpsZxSBTxACkt49yJo4k4zZLMwe12do4uhKZatB78nEXc5W4k6zYwkYpgShfeRCJ714oz2TFjbGK6xZD8xDh3YgHzqWXwzeRfaG
      Private Key          5fdee1800c5263dc7e0cbcb52ba3a884837fe1bc077976fcc035b514157e9304
      Public Key           15dc3fd47a15120dff636be498cb88d5d13c8d4da3aa9962134076e83d9af60c3ed1508b7a77c16c4d33154ad2cee608398527bdc1d79253b1fee7856400747d
      Address              0x2A53D0f3310A5832d5A030b4b2f3E9C910C2AF7b

For now, I can build the path manually, but it would be nice if wagyu could do this for me.

howardwu commented 4 years ago

This is a great idea! We've been wanting to add this as well. Glad there is interest, and we'll make an effort to incorporate it

howardwu commented 4 years ago

@WyseNynja #207 adds support for deriving sequential indices. The approach we took was to continue supporting the --count command for multiple wallets, while introducing a new counter --indices (short -k) for sequential indices. The shorthand flag of -n -l -j were all taken (which were the potential logical options).

For usage, if I want to create a new Ethereum HD wallet and print out the indices from index 3 to index 8, I would use the following convention:

wagyu ethereum hd -i 3 -k 5

Ditto for importing an Ethereum HD wallet:

wagyu ethereum import-hd -m {mnemonic} -i 3 -k 5