Add ed25519 support to encodeBech32Pubkey

This commit is contained in:
Simon Warta 2020-08-10 23:23:58 +02:00
parent 3a5c23c2e8
commit 05524b5b1b
3 changed files with 19 additions and 0 deletions

View File

@ -1,5 +1,9 @@
# CHANGELOG # CHANGELOG
## 0.22.1 (unreleased)
- @cosmjs/launchpad: Add ed25519 support to `encodeBech32Pubkey`.
## 0.22.0 (2020-08-03) ## 0.22.0 (2020-08-03)
- @cosmjs/cli: Now supports HTTPs URLs for `--init` code sources. - @cosmjs/cli: Now supports HTTPs URLs for `--init` code sources.

View File

@ -51,5 +51,17 @@ describe("pubkey", () => {
"cosmospub1addwnpepqd8sgxq7aw348ydctp3n5ajufgxp395hksxjzc6565yfp56scupfqhlgyg5", "cosmospub1addwnpepqd8sgxq7aw348ydctp3n5ajufgxp395hksxjzc6565yfp56scupfqhlgyg5",
); );
}); });
it("works for ed25519", () => {
// Decoded from http://localhost:26657/validators
// Encoded from `corald tendermint show-validator`
const pubkey: PubKey = {
type: "tendermint/PubKeyEd25519",
value: "YZHlYxP5R6olj3Tj3f7VgkQE5VaOvv9G0jKATqdQsqI=",
};
expect(encodeBech32Pubkey(pubkey, "coralvalconspub")).toEqual(
"coralvalconspub1zcjduepqvxg72ccnl9r65fv0wn3amlk4sfzqfe2k36l073kjx2qyaf6sk23qw7j8wq",
);
});
}); });
}); });

View File

@ -62,6 +62,9 @@ export function encodeBech32Pubkey(pubkey: PubKey, prefix: string): string {
case pubkeyType.secp256k1: case pubkeyType.secp256k1:
aminoPrefix = pubkeyAminoPrefixSecp256k1; aminoPrefix = pubkeyAminoPrefixSecp256k1;
break; break;
case pubkeyType.ed25519:
aminoPrefix = pubkeyAminoPrefixEd25519;
break;
default: default:
throw new Error("Unsupported pubkey type"); throw new Error("Unsupported pubkey type");
} }