Created
January 24, 2024 16:40
-
-
Save clemensgg/9c0836f03d85646d8434d2db75cb64be to your computer and use it in GitHub Desktop.
pubkeytovalcons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import crypto from 'crypto'; | |
import bech32 from 'bech32'; | |
const pubkey = "+hZsfi4r1OdyIgkZBbQgCDiADkQWlzN0iQ3Szr9+Dp8="; | |
const prefix = "odin"; | |
function pubKeyToValcons (pubkey, prefix) { | |
const consensusPubkeyBytes = Buffer.from(pubkey, | |
'base64'); | |
const sha256Hash = crypto.createHash('sha256').update(consensusPubkeyBytes).digest(); | |
const addressBytes = sha256Hash.slice(0, | |
20); | |
const valconsAddress = bech32.bech32.encode(prefix + 'valcons', | |
bech32.bech32.toWords(addressBytes)); | |
return valconsAddress; | |
} | |
console.log(pubKeyToValcons(pubkey, prefix)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment