Skip to content

Commit bd5c756

Browse files
feat: add EthSecp256k1Pubkey to pubkeyToRawAddress function
1 parent 34b009e commit bd5c756

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/amino/src/addresses.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { keccak256 } from "@cosmjs/crypto";
66
import { Secp256k1 } from "@cosmjs/crypto";
77

88
import { encodeAminoPubkey } from "./encoding";
9-
import { isEd25519Pubkey, isMultisigThresholdPubkey, isSecp256k1Pubkey, Pubkey } from "./pubkeys";
9+
import { isEd25519Pubkey, isEthSecp256k1Pubkey, isMultisigThresholdPubkey, isSecp256k1Pubkey, Pubkey } from "./pubkeys";
1010

1111
export function rawEd25519PubkeyToRawAddress(pubkeyData: Uint8Array): Uint8Array {
1212
if (pubkeyData.length !== 32) {
@@ -23,6 +23,9 @@ export function rawSecp256k1PubkeyToRawAddress(pubkeyData: Uint8Array): Uint8Arr
2323
}
2424

2525
export 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

Comments
 (0)