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/
lib/
benchmark-reports

View File

@ -1,5 +1,5 @@
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
@ -8,6 +8,7 @@ declare namespace global {
export let messages: Buffer[];
export let signature: Buffer;
export let publicKeys: Buffer[];
export let keypairs: Keypair[];
export let verify: Function;
}
@ -19,29 +20,34 @@ global.verify = verifyMultiple;
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
const FUNCTION_NAME = "verifyValidAggregatedSignature"; // PLEASE FILL THIS OUT
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 {
testFunctions: [verifyValidAggregatedSignature],
setup: function() {
const {Keypair, aggregateSignatures} = require("../../../src");
const {sha256} = require('js-sha256');
const signatures = [];
global.publicKeys = [];
const sha256 = require('js-sha256');
const {aggregateSignatures} = require("../../../src");
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);
const signatures = [];
global.messages = [];
global.keypairs.forEach((keypair) => {
signatures.push(keypair.privateKey.signMessage(message, global.domain).toBytesCompressed());
global.messages.push(message);
});
global.signature = aggregateSignatures(signatures);
global.publicKeys.map(() => message);
},
file: dir + FUNCTION_NAME + ".txt",
// profile: true,