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/verifyValidSignature.ts

44 lines
1.4 KiB
TypeScript
Raw Normal View History

2019-08-20 09:09:44 +00:00
/* eslint-disable @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires */
import {BenchSuite} from "@chainsafe/benchmark-utils";
import {verify} from "../../../src";
// eslint-disable-next-line @typescript-eslint/no-namespace
declare namespace global {
export let domain: Buffer;
export let message: Buffer;
export let signature: Buffer;
export let publicKey: Buffer;
export let verify: Function;
}
// @ts-ignore
global.require = require;
global.domain = Buffer.alloc(8);
global.verify = verify;
export function verifyValidSignatureBenchmark(dir: string): BenchSuite {
// Set the function test
const FUNCTION_NAME = "verifyValidSignature"; // PLEASE FILL THIS OUT
const verifyValidSignature = function (): void {
global.verify(global.publicKey, global.message, global.signature, global.domain);
};
return {
2019-11-27 20:58:41 +00:00
name: FUNCTION_NAME,
2019-08-20 09:09:44 +00:00
testFunctions: [verifyValidSignature],
setup: function() {
const {Keypair} = require("../../../src");
const {sha256} = require('js-sha256');
const keypair = Keypair.generate();
global.publicKey = keypair.publicKey.toBytesCompressed();
global.message = Buffer.from(sha256.arrayBuffer(Math.random().toString(36)));
global.signature = keypair.privateKey.signMessage(Buffer.from(global.message), global.domain).toBytesCompressed();
},
file: dir + FUNCTION_NAME + ".txt"
};
}