This repository has been archived on 2023-04-09. You can view files and clone it, but cannot push or open issues or pull requests.
chainsafe-bls/test/benchmarks/suites/verifyValidAggregatedSignat...

48 lines
1.6 KiB
TypeScript
Raw Normal View History

2019-08-20 09:09:44 +00:00
import {BenchSuite} from "@chainsafe/benchmark-utils";
import {aggregateSignatures, verifyMultiple} from "../../../src";
// eslint-disable-next-line @typescript-eslint/no-namespace
declare namespace global {
export let domain: Buffer;
export let messages: Buffer[];
export let signature: Buffer;
export let publicKeys: Buffer[];
export let verify: Function;
}
// @ts-ignore
global.require = require;
global.domain = Buffer.alloc(8);
global.verify = verifyMultiple;
export function verifyValidAggregatedSignature(dir: string): BenchSuite {
// Set the function test
const FUNCTION_NAME = "verifyValidAggregatedSignature"; // PLEASE FILL THIS OUT
const verifyValidAggregatedSignature = function (): void {
global.verify(global.publicKeys, global.messages, global.signature, global.domain);
};
return {
testFunctions: [verifyValidAggregatedSignature],
setup: function() {
const {Keypair, aggregateSignatures} = require("../../../src");
const {sha256} = require('js-sha256');
const signatures = [];
global.publicKeys = [];
const message = Buffer.from(sha256.arrayBuffer(Math.random().toString(36)));
for(let i = 0; i < 128; i++) {
const keypair = Keypair.generate();
global.publicKeys.push(keypair.publicKey.toBytesCompressed());
signatures.push(keypair.privateKey.signMessage(Buffer.from(message), global.domain).toBytesCompressed());
}
global.messages = global.publicKeys.map(() => message);
global.signature = aggregateSignatures(signatures);
global.publicKeys.map(() => message);
},
file: dir + FUNCTION_NAME + ".txt"
};
}