some fixes

This commit is contained in:
Marin Petrunić 2019-08-28 16:28:17 +02:00
parent 84bf46cb58
commit 9f58dcb544
2 changed files with 20 additions and 13 deletions

1
.gitignore vendored
View File

@ -64,3 +64,4 @@ typings/
dist/ dist/
lib/ lib/
benchmark-reports

View File

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