Comments (5)
OK after reading the source of a few libraries I have figured this out. For unknown to me reason comspy and Injective use different hashing strategies for address derivation. Here is a reproduction of this issue:
import sha3
from bip_utils import Hash160
from pyinjective import PrivateKey as InjectivePrivateKey
from cosmpy.crypto.address import Address as CosmpyAddress
from cosmpy.crypto.keypairs import PrivateKey as CosmpyPrivateKey
def via_injective(private_key_hex: str) -> str:
priv_key = InjectivePrivateKey.from_hex(private_key_hex)
pub_key = priv_key.to_public_key()
return pub_key.to_address().to_acc_bech32()
def via_cosmpy(private_key_hex: str) -> str:
private_key = CosmpyPrivateKey(bytes.fromhex(private_key_hex))
public_key = private_key.public_key
return str(CosmpyAddress(public_key, prefix="inj"))
def keccak256(pubkey: bytes) -> bytes:
keccak_hash = sha3.keccak_256()
keccak_hash.update(pubkey[1:])
return keccak_hash.digest()[12:]
def via_bip_utils(private_key_hex: str, hrp="inj", use_keccak=False) -> str:
from bip_utils import Secp256k1PrivateKey, Bech32Encoder
import binascii
# Decode the hex string to bytes
private_key_bytes = binascii.unhexlify(private_key_hex)
# Create a private key object
private_key = Secp256k1PrivateKey.FromBytes(private_key_bytes)
# Get the public key from the private key
public_key = private_key.PublicKey()
# Hash the public key using SHA256, then RIPEMD-160 or keccak256
pub_key_hash = keccak256(public_key.RawUncompressed().ToBytes()) if use_keccak else Hash160.QuickDigest(public_key.RawCompressed().ToBytes())
# Convert the hash of the public key to an address using bech32 encoding
return Bech32Encoder.Encode(hrp, pub_key_hash)
private_key = "1112f3b9df973c25c5423f9c1ed5eb46b64059ba28a1b5870c525c816f9dbb52"
print("Injective lib", via_injective(private_key))
print("compy", via_cosmpy(private_key))
print("manual via keccak256", via_bip_utils(private_key, use_keccak=True))
print("manual via ripemd160", via_bip_utils(private_key, use_keccak=False))
Output is:
Injective lib inj1ftqt0zhaa7dvnx77q8y5ls2ups5khdx7wk8n4l
compy inj1pkczxghy5ms2fy3cqtty0l6kxqg4wa9eetwpx2
manual via keccak256 inj1ftqt0zhaa7dvnx77q8y5ls2ups5khdx7wk8n4l
manual via ripemd160 inj1pkczxghy5ms2fy3cqtty0l6kxqg4wa9eetwpx2
Would love to hear somebody's opinion on why this might be the case!
from cosmpy.
No, I ended up using py-injective for this particular wallet, cosmpy for the other ones.
from cosmpy.
Hi. Did you solve it?
from cosmpy.
same issue here
from cosmpy.
yes I noticed the same thing here
from cosmpy.
Related Issues (20)
- CosmPy: update protobuf
- Bug report: QueryStakingSummary returns 0 when coins are staked HOT 1
- Feature request: query_account() should return pub_key alongside account_number and sequence
- Bug report: Can not install cosmpy HOT 2
- Remove develop and change master to main
- Reduce dependencies as much as possible
- Use cosmpy with a different Cosmo chain HOT 7
- Feature request: Addition of event queries to LedgerClient
- events from contract calls back unhelpfully orgainsed
- Feature request: Query authz grants
- Bug report: GovClient.Proposal cannot consume expedited proposals
- Bug report: GovClient.Proposals() doesn't properly parse request
- Bug report: Authz info broken for Kujira network
- Bug Report: Message type "cosmos.base.abci.v1beta1.Result" has no field named "msg_responses".
- Bug report: query_account does not support PeriodicVestingAccount. Solution provided.
- Add public key type HOT 1
- Bug report: Failed to parse attributes field: HOT 2
- Bug report: send_tokens function HOT 1
- Bug report: ParseError when use TxRestClient.GetTxsEvent method HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cosmpy.