Let's say I have a public key hash, is it possible to get the address corresponding to that hash using the CLI?
2 Answers
No, as that would sort of defeat the purpose of having a key hash in the first place (Hashing is, by definition, a one-way operation). Also, addresses can be built using different combinations of payment and staking keys, so a single key hash can be indicative of a key with ownership over multiple addresses.
-
1In the question it is assumed that we have an pubkeyhash. If we look at the defenition of an address it consists of a credential and maybe a stakingcredential. The former is in the case of a normal shelley address given by a pubkeyHash. If it is a script, then its the validator hash. So it is definitly possible to construct an address from a pubkeyhash. What is not possible is deriving the pubkey from the pubkeyhash (as you state). See playground.plutus.iohkdev.io/doc/haddock/plutus-ledger/html/…– FermatCommented Apr 14, 2022 at 18:39
You might want to investigate cardano-serialization-lib or cardano-addresses for this.
echo addr1gqtnpvdhqrtpd4g424fcaq7k0ufuzyadt7djygf8qdyzevuph3wczvf2dwyx5u | ./cardano-address address inspect
{
"stake_reference": "by pointer",
"spending_key_hash_bech32": "addr_vkh1zuctrdcq6ctd29242w8g84nlz0q38t2lnv3zzfcrfqktx0c9tzp",
"pointer": {
"slot_num": 24157,
"output_index": 42,
"transaction_index": 177
},
"address_style": "Shelley",
"spending_key_hash": "1730b1b700d616d51555538e83d67f13c113ad5f9b22212703482cb3",
"network_tag": 0 }
But that is a movement in an opposite direction, getting a pkh from address.