cosmos / cosmjs

The Swiss Army knife to power JavaScript based client solutions ranging from Web apps/explorers over browser extensions to server-side clients like faucets/scrapers.
https://cosmos.github.io/cosmjs/
Apache License 2.0
648 stars 332 forks source link

toBech32() - creates address using coin type 118 only #1500

Closed taitruong closed 11 months ago

taitruong commented 11 months ago

Hi, given e.g. a stars address we need to convert to a terra address. Only problem is that toBech32() uses coin type 118 ("Cosmos), whereas Terra uses coin type 330 ("Luna"). So it ends up with a different address.

https://github.com/cosmos/cosmjs/blob/4e6d54b6cf5ef50bbf6f6c238980c4431ff7b401/packages/encoding/src/bech32.ts#L3

webmaster128 commented 11 months ago

To do this kind of conversion you can't operate on the address only. You need to derive the keypair using e.g. Secp256k1HdWallet. The "Hd" in there means it can generate kerpairs from a secret key phase (aka. mnemonic). Without the private key, you can't convert between the two.