From 61aa989fb3714d63545531176230984b7c0cf32d Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 22 Mar 2021 12:13:44 +0100 Subject: [PATCH] Add MultisigThresholdPubkey/isMultisigThresholdPubkey --- packages/amino/src/index.ts | 10 +++++++++- packages/amino/src/pubkeys.spec.ts | 10 +++++++++- packages/amino/src/pubkeys.ts | 13 +++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/packages/amino/src/index.ts b/packages/amino/src/index.ts index 5469771a..11c4b303 100644 --- a/packages/amino/src/index.ts +++ b/packages/amino/src/index.ts @@ -5,4 +5,12 @@ export { encodeBech32Pubkey, encodeSecp256k1Pubkey, } from "./encoding"; -export { Pubkey, Secp256k1Pubkey, SinglePubkey, isSinglePubkey, pubkeyType } from "./pubkeys"; +export { + MultisigThresholdPubkey, + Pubkey, + Secp256k1Pubkey, + SinglePubkey, + isMultisigThresholdPubkey, + isSinglePubkey, + pubkeyType, +} from "./pubkeys"; diff --git a/packages/amino/src/pubkeys.spec.ts b/packages/amino/src/pubkeys.spec.ts index 858c0815..ec47bdcb 100644 --- a/packages/amino/src/pubkeys.spec.ts +++ b/packages/amino/src/pubkeys.spec.ts @@ -1,4 +1,4 @@ -import { isSinglePubkey } from "./pubkeys"; +import { isMultisigThresholdPubkey, isSinglePubkey } from "./pubkeys"; describe("pubkeys", () => { const pubkeyEd25519 = { @@ -41,4 +41,12 @@ describe("pubkeys", () => { expect(isSinglePubkey(pubkeyMultisigThreshold)).toEqual(false); }); }); + + describe("isMultisigThresholdPubkey", () => { + it("works", () => { + expect(isMultisigThresholdPubkey(pubkeyEd25519)).toEqual(false); + expect(isMultisigThresholdPubkey(pubkeySecp256k1)).toEqual(false); + expect(isMultisigThresholdPubkey(pubkeyMultisigThreshold)).toEqual(true); + }); + }); }); diff --git a/packages/amino/src/pubkeys.ts b/packages/amino/src/pubkeys.ts index e538e657..90da0a79 100644 --- a/packages/amino/src/pubkeys.ts +++ b/packages/amino/src/pubkeys.ts @@ -42,3 +42,16 @@ export function isSinglePubkey(pubkey: Pubkey): pubkey is SinglePubkey { const singPubkeyTypes: string[] = [pubkeyType.ed25519, pubkeyType.secp256k1, pubkeyType.sr25519]; return singPubkeyTypes.includes(pubkey.type); } + +export interface MultisigThresholdPubkey extends Pubkey { + readonly type: "tendermint/PubKeyMultisigThreshold"; + readonly value: { + /** A string-encoded integer */ + readonly threshold: string; + readonly pubkeys: readonly SinglePubkey[]; + }; +} + +export function isMultisigThresholdPubkey(pubkey: Pubkey): pubkey is MultisigThresholdPubkey { + return (pubkey as MultisigThresholdPubkey).type === "tendermint/PubKeyMultisigThreshold"; +}