Closed Jackson-DKMG closed 1 year ago
Hi, I have to add it. If it is like the other coins built on Cosmos it shoud be pretty quick.
Regards, Emanuele
Thanks for the quick reply! That would be awesome.
Hello, I added Injective as a coin.
Please note that Injective uses a different algorithm for encoding the address with respect to other Cosmos-based coins, as you can see in the code snippet from their docs. So I added a specific address encoder/decoder just for it. With my implementation, I get the same addresses of Cosmostation wallet, which I always use as reference for Cosmos-based coins.
I don't know if the cosmpy
library uses the Injective algorithm or just the standard Cosmos algorithm for encoding the address. I took a quick look and found no trace of it in the code. So, if you get different addresses with respect to cosmpy
it's because of that.
Hello,
Great and thanks a lot This works as intended, although indeed when using Cosmpy the result is still wrong:
from cosmpy.aerial.wallet import LocalWallet
from cosmpy.crypto.keypairs import PrivateKey, PublicKey
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
I've ran a number of tests this morning but couldn't find a solution. I'll try some more and open an issue with the Cosmpy team if still no success.
That's because it uses the standard Cosmos algorithm, to get the same result with bip_utils
:
print(LocalWallet(PrivateKey(bip44_addr_ctx.PrivateKey().Raw().ToBytes()), prefix="inj"))
# Same address
print(AtomAddrEncoder.EncodeKey(
bip44_addr_ctx.PublicKey().Bip32Key().KeyObject(),
hrp="inj"
))
Indeed I'll mention this in the issue.
Hey,
I've spent quite some time trying to figure this out but in all honesty, it is way above my abilities.
It's not possible to generate the correct Injective addresses (because none of the Bip44Coins types are compatible at the moment).
For example to generate a Cosmos wallet adresse from a mnemonic, the below works:
mnemonic = "24 words here"
seed_bytes = Bip39SeedGenerator(mnemonic).Generate()
bip44_def_ctx = Bip44.FromSeed(seed_bytes, Bip44Coins.COSMOS).DeriveDefaultPath()
Then using the above with the Cosmpy library to get the expected wallet address.
Do you happen to have a solution for the Injective blockchain, by any chance?