Skip to content

Commit a489a7b

Browse files
committed
feat: support ethsecp256k1 algorithm in SigningStargateClient for pubkey encoding
1 parent c640c39 commit a489a7b

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

packages/amino/src/addresses.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export function rawEthSecp256k1PubkeyToRawAddress(pubkeyData: Uint8Array): Uint8
3232
return hash.slice(-20);
3333
}
3434

35-
3635
// For secp256k1 this assumes we already have a compressed pubkey.
3736
export function pubkeyToRawAddress(pubkey: Pubkey): Uint8Array {
3837
if (isSecp256k1Pubkey(pubkey)) {

packages/stargate/src/signingstargateclient.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,12 @@ export class SigningStargateClient extends StargateClient {
397397
if (!accountFromSigner) {
398398
throw new Error("Failed to retrieve account from signer");
399399
}
400-
const pubkey = encodePubkey(encodeSecp256k1Pubkey(accountFromSigner.pubkey));
400+
let pubkey;
401+
if (accountFromSigner.algo == "eth_secp256k1" || accountFromSigner.algo == "ethsecp256k1") {
402+
pubkey = encodePubkey(encodeEthSecp256k1Pubkey(accountFromSigner.pubkey));
403+
} else {
404+
pubkey = encodePubkey(encodeSecp256k1Pubkey(accountFromSigner.pubkey));
405+
}
401406
const signMode = SignMode.SIGN_MODE_LEGACY_AMINO_JSON;
402407
const msgs = messages.map((msg) => this.aminoTypes.toAmino(msg));
403408
const signDoc = makeSignDocAmino(msgs, fee, chainId, memo, accountNumber, sequence, timeoutHeight);
@@ -445,7 +450,7 @@ export class SigningStargateClient extends StargateClient {
445450
throw new Error("Failed to retrieve account from signer");
446451
}
447452
let pubkey;
448-
if (accountFromSigner.algo == "eth_secp256k1") {
453+
if (accountFromSigner.algo == "eth_secp256k1" || accountFromSigner.algo == "ethsecp256k1") {
449454
pubkey = encodePubkey(encodeEthSecp256k1Pubkey(accountFromSigner.pubkey));
450455
} else {
451456
pubkey = encodePubkey(encodeSecp256k1Pubkey(accountFromSigner.pubkey));

0 commit comments

Comments
 (0)