Skip to content

Instantly share code, notes, and snippets.

@clemensgg
Created January 24, 2024 16:40
Show Gist options
  • Save clemensgg/9c0836f03d85646d8434d2db75cb64be to your computer and use it in GitHub Desktop.
Save clemensgg/9c0836f03d85646d8434d2db75cb64be to your computer and use it in GitHub Desktop.
pubkeytovalcons
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