ebellocchia / bip_utils

Generation of mnemonics, seeds, private/public keys and addresses for different types of cryptocurrencies
MIT License
324 stars 86 forks source link

problem create address from mnemonic CARDANO #113

Closed Noname400 closed 1 year ago

Noname400 commented 1 year ago

I ask for help. since I don't understand why the address is not generated correctly. test mnemonic: physical require taxi question have visual sound damp draft actual kangaroo gold btc - GOOD 143UG5cB8Zdyd9bdLkVX4yxgRmo8XcdJac 34stpkVG26cH1q1NbyqQ1hUru47HGJpcri bc1qc2w7v450jzd34t5k5u5a8dta54lnjajyhfc2ap

eth - GOOD 0x277A5f010B56EBd647926CADd38B97b849f90884

polkadot - GOOD 16hFxBdPaKy41o4wMxr1rt4aD46gi2oaVNUL6SLTAs3riHS1

Kusama - BAD HMWcVMjwirrgWdXyAxvdQDmZaHVbJf4MP7T9wQZn3FtqKtC

cardano - BAD addr1q8anvwjcl5k92wep96y7sjejyjgkuezayr6fvae5pp2xl2hmxca93lfv25ajzt5fap9nyfy3dej96g85jemngzz5d74qcyv6d4

this address (addr1q8anvwjcl5k92wep96y7sjejyjgkuezayr6fvae5pp2xl2hmxca93lfv25ajzt5fap9nyfy3dej96g85jemngzz5d74qcyv6d4) Shelley. but not one of the generators can repeat it.

Noname400 commented 1 year ago

this code `# Generate seed from mnemonic seed_bytes = Bip39SeedGenerator(mnemonic).Generate() coin_type = Bip44Coins.CARDANO_BYRON_ICARUS bip32_ctx = Bip32Slip10Secp256k1.FromSeed(seed_bytes).DerivePath(f"m/44'/1815'/0'/0/0") priv_keybytes = bip32_ctx.PrivateKey().Raw().ToHex() priv_key_bytes = bip32_ctx.PrivateKey().Raw().ToBytes() pub_key_bytes = bip32_ctx.PublicKey().RawCompressed().ToBytes() print(f"Derived private key (bytes): {priv_keybytes}") print(f"Derived public key (extended): {pub_key_bytes}")

s = binascii.unhexlify(pub_key_bytes)

bip44_ctx = Bip44.FromPublicKey(pub_key_bytes[1:], coin_type) print(f"Address: {bip44_ctx.PublicKey().ToAddress()}")`

I get the correct private key. but how do I get the address in a different format. the test address is listed above.

ebellocchia commented 1 year ago

What do you use to generate the cardano address? Yoroi does not support 12 words, only 15 and 24

Noname400 commented 1 year ago

I took all the data from exodus in exodus I used 12 words maybe the problem is that when generating in exodus the path 1825/1815 is used and not 44/1815

Noname400 commented 1 year ago

it is possible to generate BYRON and get the address in Shelley format

ebellocchia commented 1 year ago

When you use wallets like Exodus and Atomic it happens that they derive keys in their own ways, so they are not compatible with other wallets. If you check the derivation path of Cardano in Exosdus page there is an asterisk indicating that is has a non-standard path.

ebellocchia commented 1 year ago

It's not easy to understand what they are doing, because Cardano has many ways to generate the seed and derive keys as you can see from the readme. So, I don't know which algorithm they use to derive keys and which one for generating the seed, it's not just a matter of changing the derivation path to 44'. Moreover, the Shelly address also needs the staking key beside the public key, so you should understand also how the staking key is generated.

Noname400 commented 1 year ago

import binascii from bip_utils import Bip44Changes, Bip44Levels, Cip1852Coins, Cip1852

seed_bytes = binascii.unhexlify(b"0000000000000000000000000000000000000000") cip1852_mst_ctx = Cip1852.FromSeed(seed_bytes, Cip1852Coins.CARDANO_ICARUS)

print(cip1852_mst_ctx.PrivateKey().Raw().ToHex()) print(cip1852_mst_ctx.PublicKey().RawCompressed().ToHex()) print(cip1852_mst_ctx.PublicKey().ChainCode().ToHex())

print(cip1852_mst_ctx.Level()) print(cip1852_mst_ctx.IsLevel(Bip44Levels.MASTER))

cip1852_acc_ctx = cip1852_mst_ctx.Purpose().Coin().Account(0) print(cip1852_acc_ctx.PrivateKey().Raw().ToHex()) print(cip1852_acc_ctx.PublicKey().RawCompressed().ToHex())

cip1852_chg_ctx = cip1852_acc_ctx.Change(Bip44Changes.CHAIN_EXT)

for i in range(5): cip1852_addr_ctx = cip1852_chg_ctx.AddressIndex(i) print(cip1852_addr_ctx.PrivateKey().Raw().ToHex()) print(cip1852_addr_ctx.PublicKey().RawCompressed().ToHex()) print(cip1852_addr_ctx.PublicKey().ChainCode().ToHex()) try: print(cip1852_addr_ctx.PublicKey().ToAddress()) except ValueError: pass

this example not work!

ebellocchia commented 1 year ago

I have no problem running it, what do you mean?