Skip to content

Commit

Permalink
decode ethsecp256k1 from bech32 is not possible yet: secp256k1 and et…
Browse files Browse the repository at this point in the history
…hsecp256k1 has the same prefix
  • Loading branch information
zakarialounes committed Oct 12, 2022
1 parent 3fa08f9 commit 2eb4f37
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
38 changes: 21 additions & 17 deletions packages/amino/src/encoding.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@ describe("encoding", () => {
});
});

it("works for ethsecp256k1", () => {
const amino = fromBech32(
"evmospub1addwnpepqvhmtwxummaqj32qe7fa8yglejl37s6k8lp280pth2at2sehq352w6wm5v0",
).data;
expect(decodeAminoPubkey(amino)).toEqual({
type: "tendermint/PubKeyEthSecp256k1",
value: "Ay+1uNze+glFQM+T05EfzL8fQ1Y/wqO8K7q6tUM3BGin",
});
});
// @todo: find a way to bypass the identical prefix for secp256k1 and ethsecp256k1
// in @amino/encoding:decodeAminoPubkey
// it("works for ethsecp256k1", () => {
// const amino = fromBech32(
// "evmospub1addwnpepqvhmtwxummaqj32qe7fa8yglejl37s6k8lp280pth2at2sehq352w6wm5v0",
// ).data;
// expect(decodeAminoPubkey(amino)).toEqual({
// type: "tendermint/PubKeyEthSecp256k1",
// value: "Ay+1uNze+glFQM+T05EfzL8fQ1Y/wqO8K7q6tUM3BGin",
// });
// });

it("works for ed25519", () => {
// Encoded from `corald tendermint show-validator`
Expand Down Expand Up @@ -152,14 +154,16 @@ describe("encoding", () => {
});
});

it("works for ethsecp256k1", () => {
expect(decodeBech32Pubkey(
"evmospub1addwnpepqvhmtwxummaqj32qe7fa8yglejl37s6k8lp280pth2at2sehq352w6wm5v0",
)).toEqual({
type: "tendermint/PubKeyEthSecp256k1",
value: "Ay+1uNze+glFQM+T05EfzL8fQ1Y/wqO8K7q6tUM3BGin",
});
});
// @todo: find a way to bypass the identical prefix for secp256k1 and ethsecp256k1
// in @amino/encoding:decodeAminoPubkey
// it("works for ethsecp256k1", () => {
// expect(
// decodeBech32Pubkey("evmospub1addwnpepqvhmtwxummaqj32qe7fa8yglejl37s6k8lp280pth2at2sehq352w6wm5v0"),
// ).toEqual({
// type: "tendermint/PubKeyEthSecp256k1",
// value: "Ay+1uNze+glFQM+T05EfzL8fQ1Y/wqO8K7q6tUM3BGin",
// });
// });

it("works for enigma pubkey", () => {
expect(
Expand Down
1 change: 1 addition & 0 deletions packages/amino/src/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const pubkeyAminoPrefixMultisigThreshold = fromHex("22c1f7e2" /* variable length

/**
* Decodes a pubkey in the Amino binary format to a type/value object.
* @todo: find a clean way to distinct Secp256k1 and EthSecp256k1 (has the same prefix)
*/
export function decodeAminoPubkey(data: Uint8Array): Pubkey {
if (arrayContentStartsWith(data, pubkeyAminoPrefixSecp256k1)) {
Expand Down

0 comments on commit 2eb4f37

Please sign in to comment.