Check threashold against number of pubkeys
This commit is contained in:
parent
7255af4186
commit
5fe0f5582e
@ -59,5 +59,11 @@ describe("multisig", () => {
|
||||
it("works with nosort", () => {
|
||||
expect(createMultisigThresholdPubkey([test3, test1], 2, true)).toEqual(testgroup4);
|
||||
});
|
||||
|
||||
it("throws for threshold lager than number of keys", () => {
|
||||
expect(() => createMultisigThresholdPubkey([test1, test2, test3], 5)).toThrowError(
|
||||
/threshold k = 5 exceeds number of keys n = 3/i,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -20,6 +20,11 @@ export function createMultisigThresholdPubkey(
|
||||
threshold: number,
|
||||
nosort = false,
|
||||
): MultisigThresholdPubkey {
|
||||
const uintThreshold = new Uint53(threshold);
|
||||
if (uintThreshold.toNumber() > pubkeys.length) {
|
||||
throw new Error(`Threshold k = ${uintThreshold.toNumber()} exceeds number of keys n = ${pubkeys.length}`);
|
||||
}
|
||||
|
||||
const outPubkeys = nosort
|
||||
? pubkeys
|
||||
: Array.from(pubkeys).sort((lhs, rhs) => {
|
||||
@ -31,7 +36,7 @@ export function createMultisigThresholdPubkey(
|
||||
return {
|
||||
type: "tendermint/PubKeyMultisigThreshold",
|
||||
value: {
|
||||
threshold: new Uint53(threshold).toString(),
|
||||
threshold: uintThreshold.toString(),
|
||||
pubkeys: outPubkeys,
|
||||
},
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user