Skip to content

Commit

Permalink
Merge pull request #1294 from cosmos/document-pubkeyToRawAddress-pubk…
Browse files Browse the repository at this point in the history
…eyToAddress

Add doc comments to pubkeyToRawAddress and pubkeyToAddress
  • Loading branch information
webmaster128 committed Oct 19, 2022
2 parents 51a7214 + 01f6e1f commit bba7780
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/tendermint-rpc/src/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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();
}

0 comments on commit bba7780

Please sign in to comment.