Fix noble

This commit is contained in:
Paul Miller 2020-12-04 18:54:47 +00:00 committed by GitHub
parent 86c956e12a
commit 94d8fce815
2 changed files with 26 additions and 11 deletions

View File

@ -7,7 +7,7 @@ import {aggCount, runsNoble} from "./params";
(async function () { (async function () {
// verify // verify
await runBenchmark<{pk: Uint8Array; msg: Uint8Array; sig: Uint8Array}, boolean>({ await runBenchmark<{pk: noble.PointG1; msg: noble.PointG2; sig: noble.PointG2}, boolean>({
id: `noble verify`, id: `noble verify`,
prepareTest: async () => { prepareTest: async () => {
@ -29,7 +29,7 @@ import {aggCount, runsNoble} from "./params";
// Fast aggregate // Fast aggregate
await runBenchmark<{pks: Uint8Array[]; msg: Uint8Array; sig: Uint8Array}, boolean>({ await runBenchmark<{pks: noble.PointG1[]; msg: noble.PointG2; sig: noble.PointG2}, boolean>({
id: `noble verifyAggregate (${aggCount})`, id: `noble verifyAggregate (${aggCount})`,
prepareTest: async () => { prepareTest: async () => {
@ -44,15 +44,15 @@ import {aggCount, runsNoble} from "./params";
); );
const pks = dataArr.map((data) => data.pk); const pks = dataArr.map((data) => data.pk);
const sig = noble.aggregateSignatures(dataArr.map((data) => data.sig)) as unknown as noble.PointG2[]; const sig = noble.aggregateSignatures(dataArr.map((data) => data.sig)) as any as noble.PointG2;
return { return {
input: {pks, msg, sig}, input: {pks, msg: await noble.PointG2.hashToCurve(msg), sig},
resultCheck: (valid: boolean) => valid === true, resultCheck: (valid: boolean) => valid === true,
}; };
}, },
testRunner: async ({pks, msg, sig}) => { testRunner: async ({pks, msg, sig}) => {
const pk = noble.aggregatePublicKeys(pks); const pk = noble.aggregatePublicKeys(pks) as any as noble.PointG1;
return await noble.verify(sig, msg, pk); return await noble.verify(sig, msg, pk);
}, },
runs: runsNoble, runs: runsNoble,
@ -60,7 +60,7 @@ import {aggCount, runsNoble} from "./params";
// // Verify multiple // // Verify multiple
await runBenchmark<{pks: Uint8Array[]; msgs: Uint8Array[]; sig: Uint8Array}, boolean>({ await runBenchmark<{pks: noble.PointG1[]; msgs: noble.PointG2[]; sig: noble.PointG2}, boolean>({
id: `noble verifyMultiple (${aggCount})`, id: `noble verifyMultiple (${aggCount})`,
prepareTest: async () => { prepareTest: async () => {
@ -76,7 +76,7 @@ import {aggCount, runsNoble} from "./params";
const pks = dataArr.map((data) => data.pk); const pks = dataArr.map((data) => data.pk);
const msgs = dataArr.map((data) => data.msg); const msgs = dataArr.map((data) => data.msg);
const sig = noble.aggregateSignatures(dataArr.map((data) => data.sig)); const sig = noble.aggregateSignatures(dataArr.map((data) => data.sig)) as any as noble.PointG2;
return { return {
input: {pks, msgs, sig}, input: {pks, msgs, sig},
@ -91,7 +91,7 @@ import {aggCount, runsNoble} from "./params";
// Aggregate pubkeys // Aggregate pubkeys
await runBenchmark<Uint8Array[], void>({ await runBenchmark<noble.PointG1[], void>({
id: `noble aggregate pubkeys (${aggCount})`, id: `noble aggregate pubkeys (${aggCount})`,
prepareTest: () => { prepareTest: () => {
@ -105,13 +105,28 @@ import {aggCount, runsNoble} from "./params";
runs: runsNoble, runs: runsNoble,
}); });
await runBenchmark<{sk: Uint8Array; msg: Uint8Array}, void>({ await runBenchmark<noble.PointG2[], void>({
id: `noble aggregate signatures (${aggCount})`,
prepareTest: async () => {
const hashes = range(aggCount).map(() => generateRandomSecretKey()).map(noble.PointG2.hashToCurve);
return {
input: await Promise.all(hashes),
};
},
testRunner: async (sigs) => {
noble.aggregateSignatures(sigs);
},
runs: runsNoble,
});
await runBenchmark<{sk: Uint8Array; msg: noble.PointG2}, void>({
id: `noble sign`, id: `noble sign`,
prepareTest: async () => ({ prepareTest: async () => ({
input: { input: {
sk: generateRandomSecretKey(), sk: generateRandomSecretKey(),
msg: randomMessage(), msg: await noble.PointG2.hashToCurve(randomMessage()),
}, },
}), }),
testRunner: async ({sk, msg}) => { testRunner: async ({sk, msg}) => {

View File

@ -7,7 +7,7 @@ export async function runBenchmark<T, R>({
id, id,
}: { }: {
prepareTest: (i: number) => PromiseOptional<{input: T; resultCheck?: (result: R) => boolean}>; prepareTest: (i: number) => PromiseOptional<{input: T; resultCheck?: (result: R) => boolean}>;
testRunner: (input: any) => PromiseOptional<R>; testRunner: (input: T) => PromiseOptional<R>;
runs?: number; runs?: number;
id: string; id: string;
}): Promise<void> { }): Promise<void> {