cosmology-tech / chain-registry

Cosmos chain registry ⚛️
https://cosmology.zone/products/chain-registry
MIT License
61 stars 35 forks source link

utils functions for validating address of a chain and convert address between chains #27

Open kombos opened 1 year ago

kombos commented 1 year ago

we require some crucial functions to be made part of the utils library of chain-registry, such as validating an address of a particular chain. This should be a functions to verify if an address is a valid bech32 address for a particular chain, in chain-registry ? this should ideally be under @chain-registry/utils or @chain-registry/assets.. for each asset, we could provide a verifyAddress() function, where we pass the complete address (human readable prefix + control digit + remaining hash value) and it will return a boolean value. for e.g. verifyAddress("osmosis", "osmo1egdwq4khcmsyd0tk6mpq28r7eawjpe6nzd9kjd") could give return value - true - since it is a valid address.

Also, a function to convert an address represented in one chain to address represented in another chain.. for eg. convertAddress("cosmoshub", "osmosis", "cosmos1egdwq4khcmsyd0tk6mpq28r7eawjpe6n2kkxyl") could give back - "osmo1egdwq4khcmsyd0tk6mpq28r7eawjpe6nzd9kjd"

pyramation commented 1 year ago

hey — I think we can put this under @chain-registry/utils for verifyAddress

however, I don't see how we can do convertAddress unless they share a coin type. e.g. you cannot create secret to osmo since they don't share a cointype, so this convert address is not really a safe method to provide. If we did this we'd have to throw errors for incompatible coin types.

pyramation commented 1 year ago

verify address — it was mentioned maybe folks should use these libraries and info to do validation, we'll take a look and see if we can do it in a minimal way that doesn't use much dependencies, if any.

https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki

https://github.com/bitcoinjs/bech32