@@ -6,7 +6,7 @@ import { keccak256 } from "@cosmjs/crypto";
66import { Secp256k1 } from "@cosmjs/crypto" ;
77
88import { encodeAminoPubkey } from "./encoding" ;
9- import { isEd25519Pubkey , isMultisigThresholdPubkey , isSecp256k1Pubkey , Pubkey } from "./pubkeys" ;
9+ import { isEd25519Pubkey , isEthSecp256k1Pubkey , isMultisigThresholdPubkey , isSecp256k1Pubkey , Pubkey } from "./pubkeys" ;
1010
1111export function rawEd25519PubkeyToRawAddress ( pubkeyData : Uint8Array ) : Uint8Array {
1212 if ( pubkeyData . length !== 32 ) {
@@ -23,6 +23,9 @@ export function rawSecp256k1PubkeyToRawAddress(pubkeyData: Uint8Array): Uint8Arr
2323}
2424
2525export function rawEthSecp256k1PubkeyToRawAddress ( pubkeyData : Uint8Array ) : Uint8Array {
26+ if ( pubkeyData . length !== 33 ) {
27+ throw new Error ( `Invalid Secp256k1 pubkey length (compressed): ${ pubkeyData . length } ` ) ;
28+ }
2629 const uncompressed = Secp256k1 . uncompressPubkey ( pubkeyData ) ;
2730 const pubkeyWithoutPrefix = uncompressed . slice ( 1 ) ;
2831 const hash = keccak256 ( pubkeyWithoutPrefix ) ;
@@ -35,6 +38,9 @@ export function pubkeyToRawAddress(pubkey: Pubkey): Uint8Array {
3538 if ( isSecp256k1Pubkey ( pubkey ) ) {
3639 const pubkeyData = fromBase64 ( pubkey . value ) ;
3740 return rawSecp256k1PubkeyToRawAddress ( pubkeyData ) ;
41+ } else if ( isEthSecp256k1Pubkey ( pubkey ) ) {
42+ const pubkeyData = fromBase64 ( pubkey . value ) ;
43+ return rawEthSecp256k1PubkeyToRawAddress ( pubkeyData ) ;
3844 } else if ( isEd25519Pubkey ( pubkey ) ) {
3945 const pubkeyData = fromBase64 ( pubkey . value ) ;
4046 return rawEd25519PubkeyToRawAddress ( pubkeyData ) ;
0 commit comments