Skip to content

Commit 6e044f9

Browse files
committed
feat: support ethsecp256k1 algorithm in SigningStargateClient for pubkey encoding
1 parent 511ffaa commit 6e044f9

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
@@ -399,7 +399,12 @@ export class SigningStargateClient extends StargateClient {
399399
if (!accountFromSigner) {
400400
throw new Error("Failed to retrieve account from signer");
401401
}
402-
const pubkey = encodePubkey(encodeSecp256k1Pubkey(accountFromSigner.pubkey));
402+
let pubkey;
403+
if (accountFromSigner.algo == "eth_secp256k1" || accountFromSigner.algo == "ethsecp256k1") {
404+
pubkey = encodePubkey(encodeEthSecp256k1Pubkey(accountFromSigner.pubkey));
405+
} else {
406+
pubkey = encodePubkey(encodeSecp256k1Pubkey(accountFromSigner.pubkey));
407+
}
403408
const signMode = SignMode.SIGN_MODE_LEGACY_AMINO_JSON;
404409
const msgs = messages.map((msg) => this.aminoTypes.toAmino(msg));
405410
const signDoc = makeSignDocAmino(msgs, fee, chainId, memo, accountNumber, sequence, timeoutHeight);
@@ -447,7 +452,7 @@ export class SigningStargateClient extends StargateClient {
447452
throw new Error("Failed to retrieve account from signer");
448453
}
449454
let pubkey;
450-
if (accountFromSigner.algo == "eth_secp256k1") {
455+
if (accountFromSigner.algo == "eth_secp256k1" || accountFromSigner.algo == "ethsecp256k1") {
451456
pubkey = encodePubkey(encodeEthSecp256k1Pubkey(accountFromSigner.pubkey));
452457
} else {
453458
pubkey = encodePubkey(encodeSecp256k1Pubkey(accountFromSigner.pubkey));

0 commit comments

Comments
 (0)