From 01f6e1fffbbf2ad09e3c1c0a1fc16fa440748a06 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 18 Oct 2022 14:17:25 +0200 Subject: [PATCH] Add doc comments to pubkeyToRawAddress and pubkeyToAddress --- packages/tendermint-rpc/src/addresses.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/tendermint-rpc/src/addresses.ts b/packages/tendermint-rpc/src/addresses.ts index 24c5d429..9e2cd924 100644 --- a/packages/tendermint-rpc/src/addresses.ts +++ b/packages/tendermint-rpc/src/addresses.ts @@ -15,7 +15,15 @@ export function rawSecp256k1PubkeyToRawAddress(pubkeyData: Uint8Array): Uint8Arr return ripemd160(sha256(pubkeyData)); } -// For secp256k1 this assumes we already have a compressed pubkey. +/** + * Returns Tendermint address as bytes. + * + * This is for addresses that are derived by the Tendermint keypair (typically Ed25519). + * Sometimes those addresses are bech32-encoded and contain the term "cons" in the presix + * ("cosmosvalcons1..."). + * + * For secp256k1 this assumes we already have a compressed pubkey, which is the default in Cosmos. + */ export function pubkeyToRawAddress(type: "ed25519" | "secp256k1", data: Uint8Array): Uint8Array { switch (type) { case "ed25519": @@ -28,6 +36,15 @@ export function pubkeyToRawAddress(type: "ed25519" | "secp256k1", data: Uint8Arr } } +/** + * Returns Tendermint address in uppercase hex format. + * + * This is for addresses that are derived by the Tendermint keypair (typically Ed25519). + * Sometimes those addresses are bech32-encoded and contain the term "cons" in the presix + * ("cosmosvalcons1..."). + * + * For secp256k1 this assumes we already have a compressed pubkey, which is the default in Cosmos. + */ export function pubkeyToAddress(type: "ed25519" | "secp256k1", data: Uint8Array): string { return toHex(pubkeyToRawAddress(type, data)).toUpperCase(); }