3

In the cardano-cli tool,

it is possible to accept both --payment-verification-key-file and --payment-verification-key when running cardano-cli address key-hash From the docs, it seems that the --payment-verification-key is supposed to be bech32 encoded.

But it is unclear how that is achieved.

How can I convert from the key-file to the key-string?

0

So after some experiments, the answer is to

Remove the first 2 bytes (5820) from the cborhex and pipe the output to bech32 with addr_vk

For example

$ cat vkey
{
    "type": "PaymentVerificationKeyShelley_ed25519",
    "description": "Payment Verification Key",
    "cborHex": "5820ba6e94a603da493604a0e0d0e8c4f3465ba299a0d0967a1cafd4c0fa0ab882ad"
}

$ echo "ba6e94a603da493604a0e0d0e8c4f3465ba299a0d0967a1cafd4c0fa0ab882ad" | bech32 addr_vk > vkeystring

$ cardano-cli address key-hash --payment-verification-key $(cat vkeystring)
$ cardano-cli address key-hash --payment-verification-key-file vkey 

Both key-hash should be the same.

0

As Alan has already answered this for himself I'd like to add that when using an extended verification key you can produce the non-extended key first and then bech32 encode it to produce the hash.

For example, produce non-extended verification key from extended one:

$ cat acct.vkey
  {
      "type": "PaymentExtendedVerificationKeyShelley_ed25519_bip32",
      "description": "Payment Verification Key",
      "cborHex": "58406d2d6c3e1bf46cfab0977279105a87bb89adb4c6dac3eb25ea2f300ef3e9aa0af720099909a8f7a871db0cb1b2158549cedd2019d60d7ac6c4891bf03cfdc652"
  }
$ cardano-cli key non-extended-key --extended-verification-key-file acct.vkey --verification-key-file acct_short.vkey
$ cat acct_short.vkey
  {
      "type": "PaymentVerificationKeyShelley_ed25519",
      "description": "",
      "cborHex": "58206d2d6c3e1bf46cfab0977279105a87bb89adb4c6dac3eb25ea2f300ef3e9aa0a"
  }

Remove first 2 bytes from non-extended key and produce valid encoded address (bech32 binary is included in wallet release bundle):

$ echo "6d2d6c3e1bf46cfab0977279105a87bb89adb4c6dac3eb25ea2f300ef3e9aa0a" | bech32 addr_vk
  addr_vk1d5kkc0sm73k04vyhwfu3qk58hwy6mdxxmtp7kf029ucqaulf4g9q8d6yzn

Produce key hashes and compare:

$ cardano-cli address key-hash --payment-verification-key addr_vk1d5kkc0sm73k04vyhwfu3qk58hwy6mdxxmtp7kf029ucqaulf4g9q8d6yzn
ad2704179252c6343d8e27708b725656ec30bc8a347dbb42bfd5509a
$ cardano-cli address key-hash --payment-verification-key-file acct.vkey 
ad2704179252c6343d8e27708b725656ec30bc8a347dbb42bfd5509a

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.