-
Notifications
You must be signed in to change notification settings - Fork 83
Description
Prerequisites
- I am running the latest CosmPy version.
- I checked the documentation and found no answer to my problem.
- I checked the existing issues to make sure my problem has not already been reported.
- I have read the code of conduct before creating this issue.
Expected Behavior
Injective support was added by the developer of bip_utils, which now allows to generate the expected addresses from a mnemonic.
from cosmpy.aerial.wallet import LocalWallet
from cosmpy.crypto.keypairs import PrivateKey, PublicKey
from bip_utils import Bip39SeedGenerator, Bip44, Bip44Coins
mnemonic = "24 WORDS HERE"
seed_bytes = Bip39SeedGenerator(mnemonic).Generate()
bip44_mst_ctx = Bip44.FromSeed(seed_bytes, Bip44Coins.INJECTIVE)
bip44_acc_ctx = bip44_mst_ctx.Purpose().Coin().Account(0)
bip44_chg_ctx = bip44_acc_ctx.Change(Bip44Changes.CHAIN_EXT)
bip44_addr_ctx = bip44_chg_ctx.AddressIndex(0) #index 0 appears to be the right one here
print(bip44_addr_ctx.PublicKey().ToAddress()) # --> CORRECT ADDRESS
print(LocalWallet(PrivateKey(bip44_addr_ctx.PrivateKey().Raw().ToBytes()), prefix='inj')) #--> WRONG ADDRESS
The above is expected to print the same address twice.
Current Behavior
Using LocalWallet the generated address is incorrect.
This seems to be related to the fact that Cosmpy uses the Atom address encoder.
Running this code generates the same address than LocalWallet:
from bip_utils import AtomAddrEncoder
print(AtomAddrEncoder.EncodeKey(
bip44_addr_ctx.PublicKey().Bip32Key().KeyObject(),
hrp="inj"
))
To Reproduce
No response
Context
Tested on Ubuntu 23.04 with python3.11 and latest Fetchd and bip_utils.
Do you know of a workaround to this issue?
Failure Logs
No response