amino: Add rawEd25519PubkeyToRawAddress helper
This commit is contained in:
parent
980e33b8a3
commit
25e0ee4e18
@ -6,6 +6,13 @@ import { Bech32, fromBase64 } from "@cosmjs/encoding";
|
||||
import { encodeAminoPubkey } from "./encoding";
|
||||
import { isEd25519Pubkey, isMultisigThresholdPubkey, isSecp256k1Pubkey, Pubkey } from "./pubkeys";
|
||||
|
||||
export function rawEd25519PubkeyToRawAddress(pubkeyData: Uint8Array): Uint8Array {
|
||||
if (pubkeyData.length !== 32) {
|
||||
throw new Error(`Invalid Ed25519 pubkey length: ${pubkeyData.length}`);
|
||||
}
|
||||
return sha256(pubkeyData).slice(0, 20);
|
||||
}
|
||||
|
||||
export function rawSecp256k1PubkeyToRawAddress(pubkeyData: Uint8Array): Uint8Array {
|
||||
if (pubkeyData.length !== 33) {
|
||||
throw new Error(`Invalid Secp256k1 pubkey length (compressed): ${pubkeyData.length}`);
|
||||
@ -20,10 +27,7 @@ export function pubkeyToRawAddress(pubkey: Pubkey): Uint8Array {
|
||||
return rawSecp256k1PubkeyToRawAddress(pubkeyData);
|
||||
} else if (isEd25519Pubkey(pubkey)) {
|
||||
const pubkeyData = fromBase64(pubkey.value);
|
||||
if (pubkeyData.length !== 32) {
|
||||
throw new Error(`Invalid Ed25519 pubkey length: ${pubkeyData.length}`);
|
||||
}
|
||||
return sha256(pubkeyData).slice(0, 20);
|
||||
return rawEd25519PubkeyToRawAddress(pubkeyData);
|
||||
} else if (isMultisigThresholdPubkey(pubkey)) {
|
||||
// https://github.com/tendermint/tendermint/blob/38b401657e4ad7a7eeb3c30a3cbf512037df3740/crypto/multisig/threshold_pubkey.go#L71-L74
|
||||
const pubkeyData = encodeAminoPubkey(pubkey);
|
||||
|
||||
@ -1,4 +1,9 @@
|
||||
export { pubkeyToAddress, pubkeyToRawAddress, rawSecp256k1PubkeyToRawAddress } from "./addresses";
|
||||
export {
|
||||
pubkeyToAddress,
|
||||
pubkeyToRawAddress,
|
||||
rawEd25519PubkeyToRawAddress,
|
||||
rawSecp256k1PubkeyToRawAddress,
|
||||
} from "./addresses";
|
||||
export { Coin, coin, coins, parseCoins } from "./coins";
|
||||
export {
|
||||
decodeAminoPubkey,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user