From 4b94467078f550558f301e398c32bf1156a650aa Mon Sep 17 00:00:00 2001 From: dapplion Date: Wed, 4 Nov 2020 17:34:06 +0000 Subject: [PATCH 1/7] Add prettier as an eslint plugin --- .eslintrc.js | 4 +++- package.json | 6 ++++-- prettierrc.js | 11 +++++++++++ yarn.lock | 24 ++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 prettierrc.js diff --git a/.eslintrc.js b/.eslintrc.js index d29e5da..a9f9b74 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -18,7 +18,8 @@ module.exports = { }, plugins: [ "@typescript-eslint", - "eslint-plugin-import" + "eslint-plugin-import", + "prettier" ], extends: [ "eslint:recommended", @@ -29,6 +30,7 @@ module.exports = { ], settings: {}, rules: { + "prettier/prettier": "error", //doesnt work, it reports false errors "constructor-super": "off", "@typescript-eslint/class-name-casing": "error", diff --git a/package.json b/package.json index a7d80a8..c5a773f 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "@babel/preset-typescript": "^7.8.3", "@babel/register": "^7.8.3", "@chainsafe/as-sha256": "0.2.0", + "@chainsafe/eth2-spec-tests": "0.12.0", "@chainsafe/lodestar-spec-test-util": "^0.5.0", "@types/chai": "^4.2.9", "@types/mocha": "^7.0.1", @@ -61,6 +62,7 @@ "chai": "^4.2.0", "eslint": "^6.8.0", "eslint-plugin-import": "^2.20.1", + "eslint-plugin-prettier": "^3.1.4", "karma": "^4.4.1", "karma-chai": "^0.1.0", "karma-chrome-launcher": "^3.1.0", @@ -70,11 +72,11 @@ "karma-webpack": "^4.0.2", "mocha": "^6.2.0", "nyc": "^15.0.0", + "prettier": "^2.1.2", "ts-loader": "^6.2.1", "ts-node": "^8.6.2", "typescript": "^3.7.5", "webpack": "^4.30.0", - "webpack-cli": "^3.3.2", - "@chainsafe/eth2-spec-tests": "0.12.0" + "webpack-cli": "^3.3.2" } } diff --git a/prettierrc.js b/prettierrc.js new file mode 100644 index 0000000..20baea5 --- /dev/null +++ b/prettierrc.js @@ -0,0 +1,11 @@ +module.exports = { + printWidth: 120, + tabWidth: 2, + useTabs: false, + semi: true, + singleQuote: false, + quoteProps: "as-needed", + trailingComma: "es5", + bracketSpacing: false, + arrowParens: "always", +}; \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 1c7d01c..296f5d6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2600,6 +2600,13 @@ eslint-plugin-import@^2.20.1: read-pkg-up "^2.0.0" resolve "^1.12.0" +eslint-plugin-prettier@^3.1.4: + version "3.1.4" + resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.4.tgz#168ab43154e2ea57db992a2cd097c828171f75c2" + integrity sha512-jZDa8z76klRqo+TdGDTFJSavwbnWK2ZpqGKNZ+VvweMW516pDUMmQ2koXvxEE4JhzNvTv+radye/bWGBmA6jmg== + dependencies: + prettier-linter-helpers "^1.0.0" + eslint-scope@^4.0.3: version "4.0.3" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-4.0.3.tgz#ca03833310f6889a3264781aa82e63eb9cfe7848" @@ -2808,6 +2815,11 @@ fast-deep-equal@^3.1.1: resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz#545145077c501491e33b15ec408c294376e94ae4" integrity sha512-8UEa58QDLauDNfpbrX55Q9jrGHThw2ZMdOky5Gl1CDtVeJDPVrG4Jxx1N8jw2gkWaff5UUuX1KJd+9zGe2B+ZA== +fast-diff@^1.1.2: + version "1.2.0" + resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03" + integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w== + fast-json-stable-stringify@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633" @@ -4924,6 +4936,18 @@ prelude-ls@~1.1.2: resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ= +prettier-linter-helpers@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b" + integrity sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w== + dependencies: + fast-diff "^1.1.2" + +prettier@^2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5" + integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg== + private@^0.1.6: version "0.1.8" resolved "https://registry.yarnpkg.com/private/-/private-0.1.8.tgz#2381edb3689f7a53d653190060fcf822d2f368ff" From fd4c67b67dc4d219a6652933c6638546d91f35b3 Mon Sep 17 00:00:00 2001 From: dapplion Date: Wed, 4 Nov 2020 17:34:42 +0000 Subject: [PATCH 2/7] Run eslint on tests too --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c5a773f..a4e48e9 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "build-types": "tsc --declaration --incremental --outDir lib --emitDeclarationOnly", "build-web": "webpack --mode production --entry ./lib/web.js --output ./dist/bls.min.js", "check-types": "tsc --noEmit", - "lint": "eslint --color --ext .ts src/", + "lint": "eslint --color --ext .ts src/ test/", "lint:fix": "yarn run lint --fix", "pretest": "yarn check-types", "prepublishOnly": "yarn build", From c22069335fc79622e49f176f5b923bd329f288af Mon Sep 17 00:00:00 2001 From: Cayman Date: Wed, 4 Nov 2020 11:40:36 -0600 Subject: [PATCH 3/7] Run prettier --- CHANGELOG.md | 10 ++- README.md | 15 ++-- src/context.ts | 8 +- src/helpers/utils.ts | 7 +- src/index.ts | 71 ++++++++++-------- src/keypair.ts | 8 +- src/privateKey.ts | 23 +++--- src/publicKey.ts | 23 +++--- src/signature.ts | 34 +++++---- test/spec/aggregate_sigs.test.ts | 23 +++--- test/spec/aggregate_sigs_verify.test.ts | 19 +++-- test/spec/fast_aggregate_verify.test.ts | 19 +++-- test/spec/sign.test.ts | 15 ++-- test/spec/verify.test.ts | 13 ++-- test/unit/context.test.ts | 13 ++-- test/unit/index.test.ts | 97 +++++++++++-------------- test/unit/keypair.test.ts | 18 +++-- test/unit/privateKey.test.ts | 32 ++++---- test/unit/publicKey.test.ts | 18 ++--- 19 files changed, 248 insertions(+), 218 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66a8bfc..2c6e1d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,22 +10,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [4.0.0] - 2020-08-31 ### BREAKING CHANGES -* Signature.verifyAggregate now takes decompressed pubkeys instead of raw bytes of compressed key + +- Signature.verifyAggregate now takes decompressed pubkeys instead of raw bytes of compressed key ## [3.0.0] - 2020-07-31 ### BREAKING CHANGES -* Update bls-keygen to latest EIP-2333 standard ([55dd5d](https://github.com/chainsafe/bls/commit/55dd5d)) +- Update bls-keygen to latest EIP-2333 standard ([55dd5d](https://github.com/chainsafe/bls/commit/55dd5d)) ## [2.0.0] - 2020-05-21 -Compatible with [Eth2 spec 0.12.0](https://github.com/ethereum/eth2.0-specs/blob/v0.12.0/specs/phase0/beacon-chain.md#bls-signatures) +Compatible with [Eth2 spec 0.12.0](https://github.com/ethereum/eth2.0-specs/blob/v0.12.0/specs/phase0/beacon-chain.md#bls-signatures) and [IETF draft bls specification](https://github.com/ethereum/eth2.0-specs/blob/v0.12.0/specs/phase0/beacon-chain.md#bls-signatures) ## [1.0.0] - 2020-02-25 -Compatible with [Eth2 spec 0.10.1](https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#bls-signatures) +Compatible with [Eth2 spec 0.10.1](https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#bls-signatures) and [IETF draft bls specification](https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#bls-signatures) ### BREAKING CHANGES @@ -42,4 +43,5 @@ and [IETF draft bls specification](https://github.com/ethereum/eth2.0-specs/blob ## [0.2.2] - 2020-02-12 ###Bugfixes: + - updated bls wasm binding version - it isn't catching unhandled rejections and modify stacktraces diff --git a/README.md b/README.md index 967be04..b075bd5 100644 --- a/README.md +++ b/README.md @@ -8,17 +8,18 @@ This is a Javascript library that implements BLS (Boneh-Lynn-Shacham) signatures and supports signature aggregation. -| Version | Bls spec version | -|----------|:-------------:| -| 0.3.x | initial version | -| 1.x.x | draft #6 | -| 2.x.x | draft #7 | +| Version | Bls spec version | +| ------- | :--------------: | +| 0.3.x | initial version | +| 1.x.x | draft #6 | +| 2.x.x | draft #7 | ->[spec](https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/beacon-chain.md#bls-signatures) +> [spec](https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/beacon-chain.md#bls-signatures) ->[test vectors](https://github.com/ethereum/eth2.0-spec-tests/tree/master/tests/bls) +> [test vectors](https://github.com/ethereum/eth2.0-spec-tests/tree/master/tests/bls) ## Usage + - `yarn add @chainsafe/bls` ## License diff --git a/src/context.ts b/src/context.ts index daac1c5..f5c95ab 100644 --- a/src/context.ts +++ b/src/context.ts @@ -4,7 +4,7 @@ import blsWasmWrapper from "@chainsafe/eth2-bls-wasm"; let blsWrapper: typeof blsWasmWrapper | null = null; export async function init(): Promise { - if(blsWrapper) return blsWrapper; + if (blsWrapper) return blsWrapper; await blsWasmWrapper.init(); blsWrapper = blsWasmWrapper; return blsWrapper; @@ -14,9 +14,9 @@ export function destroy(): void { blsWrapper = null; } -export function getContext(): typeof blsWasmWrapper{ - if(blsWrapper) { +export function getContext(): typeof blsWasmWrapper { + if (blsWrapper) { return blsWrapper; } throw new Error("BLS not initialized"); -} \ No newline at end of file +} diff --git a/src/helpers/utils.ts b/src/helpers/utils.ts index 7430d7d..79b4bf9 100644 --- a/src/helpers/utils.ts +++ b/src/helpers/utils.ts @@ -1,5 +1,5 @@ import assert from "assert"; -import {PUBLIC_KEY_LENGTH, SIGNATURE_LENGTH} from "../constants"; +import { PUBLIC_KEY_LENGTH, SIGNATURE_LENGTH } from "../constants"; /** * Pads byte array with zeroes on left side up to desired length. @@ -8,7 +8,10 @@ import {PUBLIC_KEY_LENGTH, SIGNATURE_LENGTH} from "../constants"; * @param length */ export function padLeft(source: Uint8Array, length: number): Buffer { - assert(source.length <= length, "Given array must be smaller or equal to desired array size"); + assert( + source.length <= length, + "Given array must be smaller or equal to desired array size" + ); const result = Buffer.alloc(length, 0); result.set(source, length - source.length); return result; diff --git a/src/index.ts b/src/index.ts index 1f26e25..e8ca68a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,13 +1,13 @@ -import {Keypair} from "./keypair"; -import {PrivateKey} from "./privateKey"; -import {PublicKey} from "./publicKey"; -import {Signature} from "./signature"; -import {PUBLIC_KEY_LENGTH} from "./constants"; +import { Keypair } from "./keypair"; +import { PrivateKey } from "./privateKey"; +import { PublicKey } from "./publicKey"; +import { Signature } from "./signature"; +import { PUBLIC_KEY_LENGTH } from "./constants"; import assert from "assert"; -export {Keypair, PrivateKey, PublicKey, Signature}; +export { Keypair, PrivateKey, PublicKey, Signature }; -export {init as initBLS} from "./context"; +export { init as initBLS } from "./context"; function toBuffer(input: Uint8Array): Buffer { return Buffer.from(input.buffer, input.byteOffset, input.length); @@ -47,11 +47,16 @@ export function sign(secretKey: Uint8Array, messageHash: Uint8Array): Buffer { * @param signatures */ export function aggregateSignatures(signatures: Uint8Array[]): Buffer { - assert(signatures && signatures.length > 0, "signatures is null or undefined or empty array"); + assert( + signatures && signatures.length > 0, + "signatures is null or undefined or empty array" + ); return Signature.aggregate( - signatures.map((signature): Signature => { - return Signature.fromCompressedBytes(signature); - }) + signatures.map( + (signature): Signature => { + return Signature.fromCompressedBytes(signature); + } + ) ).toBytesCompressed(); } @@ -61,7 +66,7 @@ export function aggregateSignatures(signatures: Uint8Array[]): Buffer { */ export function aggregatePubkeys(publicKeys: Uint8Array[]): Buffer { assert(publicKeys, "publicKeys is null or undefined"); - if(publicKeys.length === 0) { + if (publicKeys.length === 0) { return Buffer.alloc(PUBLIC_KEY_LENGTH); } return publicKeys @@ -76,14 +81,19 @@ export function aggregatePubkeys(publicKeys: Uint8Array[]): Buffer { * @param messageHash * @param signature */ -export function verify(publicKey: Uint8Array, messageHash: Uint8Array, signature: Uint8Array): boolean { +export function verify( + publicKey: Uint8Array, + messageHash: Uint8Array, + signature: Uint8Array +): boolean { assert(publicKey, "publicKey is null or undefined"); assert(messageHash, "messageHash is null or undefined"); assert(signature, "signature is null or undefined"); try { - return PublicKey - .fromBytes(publicKey) - .verifyMessage(Signature.fromCompressedBytes(toBuffer(signature)), toBuffer(messageHash)); + return PublicKey.fromBytes(publicKey).verifyMessage( + Signature.fromCompressedBytes(toBuffer(signature)), + toBuffer(messageHash) + ); } catch (e) { return false; } @@ -95,14 +105,19 @@ export function verify(publicKey: Uint8Array, messageHash: Uint8Array, signature * @param messageHash * @param signature */ -export function verifyAggregate(publicKeys: Uint8Array[], messageHash: Uint8Array, signature: Uint8Array): boolean { +export function verifyAggregate( + publicKeys: Uint8Array[], + messageHash: Uint8Array, + signature: Uint8Array +): boolean { assert(publicKeys, "publicKey is null or undefined"); assert(messageHash, "messageHash is null or undefined"); assert(signature, "signature is null or undefined"); try { - return Signature - .fromCompressedBytes(signature) - .verifyAggregate(publicKeys.map(pubkey => PublicKey.fromBytes(pubkey)), messageHash); + return Signature.fromCompressedBytes(signature).verifyAggregate( + publicKeys.map((pubkey) => PublicKey.fromBytes(pubkey)), + messageHash + ); } catch (e) { return false; } @@ -125,17 +140,15 @@ export function verifyMultiple( assert(messageHashes, "messageHash is null or undefined"); assert(signature, "signature is null or undefined"); - if(publicKeys.length === 0 || publicKeys.length != messageHashes.length) { + if (publicKeys.length === 0 || publicKeys.length != messageHashes.length) { return false; } try { - return Signature - .fromCompressedBytes(toBuffer(signature)) - .verifyMultiple( - publicKeys.map((key) => PublicKey.fromBytes(toBuffer(key))), - messageHashes.map((m) => toBuffer(m)), - fast - ); + return Signature.fromCompressedBytes(toBuffer(signature)).verifyMultiple( + publicKeys.map((key) => PublicKey.fromBytes(toBuffer(key))), + messageHashes.map((m) => toBuffer(m)), + fast + ); } catch (e) { return false; } @@ -149,5 +162,5 @@ export default { aggregatePubkeys, verify, verifyAggregate, - verifyMultiple + verifyMultiple, }; diff --git a/src/keypair.ts b/src/keypair.ts index 6e2505f..17b4445 100644 --- a/src/keypair.ts +++ b/src/keypair.ts @@ -1,16 +1,14 @@ -import {PublicKey} from "./publicKey"; -import {PrivateKey} from "./privateKey"; - +import { PublicKey } from "./publicKey"; +import { PrivateKey } from "./privateKey"; export class Keypair { - private readonly _publicKey: PublicKey; private readonly _privateKey: PrivateKey; public constructor(privateKey: PrivateKey, publicKey?: PublicKey) { this._privateKey = privateKey; - if(!publicKey) { + if (!publicKey) { this._publicKey = PublicKey.fromPrivateKey(this._privateKey); } else { this._publicKey = publicKey; diff --git a/src/privateKey.ts b/src/privateKey.ts index fb46531..2eeedfa 100644 --- a/src/privateKey.ts +++ b/src/privateKey.ts @@ -1,13 +1,12 @@ -import {SECRET_KEY_LENGTH} from "./constants"; +import { SECRET_KEY_LENGTH } from "./constants"; import assert from "assert"; -import {SecretKeyType} from "@chainsafe/eth2-bls-wasm"; -import {generateRandomSecretKey} from "@chainsafe/bls-keygen"; -import {getContext} from "./context"; -import {PublicKey} from "./publicKey"; -import {Signature} from "./signature"; +import { SecretKeyType } from "@chainsafe/eth2-bls-wasm"; +import { generateRandomSecretKey } from "@chainsafe/bls-keygen"; +import { getContext } from "./context"; +import { PublicKey } from "./publicKey"; +import { Signature } from "./signature"; export class PrivateKey { - private value: SecretKeyType; protected constructor(value: SecretKeyType) { @@ -15,7 +14,10 @@ export class PrivateKey { } public static fromBytes(bytes: Uint8Array): PrivateKey { - assert(bytes.length === SECRET_KEY_LENGTH, "Private key should have 32 bytes"); + assert( + bytes.length === SECRET_KEY_LENGTH, + "Private key should have 32 bytes" + ); const context = getContext(); const secretKey = new context.SecretKey(); secretKey.deserialize(Buffer.from(bytes)); @@ -24,7 +26,10 @@ export class PrivateKey { public static fromHexString(value: string): PrivateKey { value = value.replace("0x", ""); - assert(value.length === SECRET_KEY_LENGTH * 2, "secret key must have 32 bytes"); + assert( + value.length === SECRET_KEY_LENGTH * 2, + "secret key must have 32 bytes" + ); const context = getContext(); return new PrivateKey(context.deserializeHexStrToSecretKey(value)); } diff --git a/src/publicKey.ts b/src/publicKey.ts index 039880a..3ff0361 100644 --- a/src/publicKey.ts +++ b/src/publicKey.ts @@ -1,13 +1,12 @@ -import {PrivateKey} from "./privateKey"; -import {PublicKeyType} from "@chainsafe/eth2-bls-wasm"; -import {getContext} from "./context"; -import {PUBLIC_KEY_LENGTH} from "./constants"; +import { PrivateKey } from "./privateKey"; +import { PublicKeyType } from "@chainsafe/eth2-bls-wasm"; +import { getContext } from "./context"; +import { PUBLIC_KEY_LENGTH } from "./constants"; import assert from "assert"; -import {Signature} from "./signature"; -import {EMPTY_PUBLIC_KEY} from "./helpers/utils"; +import { Signature } from "./signature"; +import { EMPTY_PUBLIC_KEY } from "./helpers/utils"; export class PublicKey { - private value: PublicKeyType; protected constructor(value: PublicKeyType) { @@ -21,21 +20,17 @@ export class PublicKey { public static fromBytes(bytes: Uint8Array): PublicKey { const context = getContext(); const publicKey = new context.PublicKey(); - if(!EMPTY_PUBLIC_KEY.equals(bytes)) { + if (!EMPTY_PUBLIC_KEY.equals(bytes)) { publicKey.deserialize(bytes); } - return new PublicKey( - publicKey - ); + return new PublicKey(publicKey); } public static fromHex(value: string): PublicKey { value = value.replace("0x", ""); assert(value.length === PUBLIC_KEY_LENGTH * 2); const context = getContext(); - return new PublicKey( - context.deserializeHexStrToPublicKey(value) - ); + return new PublicKey(context.deserializeHexStrToPublicKey(value)); } public static fromPublicKeyType(value: PublicKeyType): PublicKey { diff --git a/src/signature.ts b/src/signature.ts index a3c8a12..b60e630 100644 --- a/src/signature.ts +++ b/src/signature.ts @@ -1,12 +1,11 @@ import assert from "assert"; -import {FP_POINT_LENGTH} from "./constants"; -import {SignatureType} from "@chainsafe/eth2-bls-wasm"; -import {getContext} from "./context"; -import {PublicKey} from "./publicKey"; -import {EMPTY_SIGNATURE} from "./helpers/utils"; +import { FP_POINT_LENGTH } from "./constants"; +import { SignatureType } from "@chainsafe/eth2-bls-wasm"; +import { getContext } from "./context"; +import { PublicKey } from "./publicKey"; +import { EMPTY_SIGNATURE } from "./helpers/utils"; export class Signature { - private value: SignatureType; protected constructor(value: SignatureType) { @@ -21,7 +20,7 @@ export class Signature { ); const context = getContext(); const signature = new context.Signature(); - if(!EMPTY_SIGNATURE.equals(value)) { + if (!EMPTY_SIGNATURE.equals(value)) { signature.deserialize(value); } return new Signature(signature); @@ -35,33 +34,36 @@ export class Signature { const context = getContext(); const signature = new context.Signature(); signature.aggregate(signatures.map((sig) => sig.getValue())); - return new Signature( - signature - ); + return new Signature(signature); } public add(other: Signature): Signature { const agg = this.value.clone(); agg.add(other.value); - return new Signature( - agg - ); + return new Signature(agg); } public getValue(): SignatureType { return this.value; } - public verifyAggregate(publicKeys: PublicKey[], message: Uint8Array): boolean { + public verifyAggregate( + publicKeys: PublicKey[], + message: Uint8Array + ): boolean { return this.value.fastAggregateVerify( publicKeys.map((key) => key.getValue()), message ); } - public verifyMultiple(publicKeys: PublicKey[], messages: Uint8Array[], fast = false): boolean { + public verifyMultiple( + publicKeys: PublicKey[], + messages: Uint8Array[], + fast = false + ): boolean { const msgs = Buffer.concat(messages); - if(!fast && !getContext().areAllMsgDifferent(msgs)) { + if (!fast && !getContext().areAllMsgDifferent(msgs)) { return false; } return this.value.aggregateVerifyNoCheck( diff --git a/test/spec/aggregate_sigs.test.ts b/test/spec/aggregate_sigs.test.ts index 139522f..fb2c8bb 100644 --- a/test/spec/aggregate_sigs.test.ts +++ b/test/spec/aggregate_sigs.test.ts @@ -1,6 +1,9 @@ import path from "path"; -import bls, {initBLS} from "../../src"; -import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util"; +import bls, { initBLS } from "../../src"; +import { + describeDirectorySpecTest, + InputType, +} from "@chainsafe/lodestar-spec-test-util"; interface IAggregateSigsTestCase { data: { @@ -19,23 +22,25 @@ describeDirectorySpecTest( __dirname, "../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/aggregate/small" ), - (testCase => { + (testCase) => { try { - const result = bls.aggregateSignatures(testCase.data.input.map(pubKey => { - return Buffer.from(pubKey.replace("0x", ""), "hex"); - })); + const result = bls.aggregateSignatures( + testCase.data.input.map((pubKey) => { + return Buffer.from(pubKey.replace("0x", ""), "hex"); + }) + ); return `0x${result.toString("hex")}`; } catch (e) { - if(e.message === "signatures is null or undefined or empty array") { + if (e.message === "signatures is null or undefined or empty array") { return null; } throw e; } - }), + }, { inputTypes: { data: InputType.YAML, }, - getExpected: (testCase => testCase.data.output) + getExpected: (testCase) => testCase.data.output, } ); diff --git a/test/spec/aggregate_sigs_verify.test.ts b/test/spec/aggregate_sigs_verify.test.ts index 4f8c122..ddb89ad 100644 --- a/test/spec/aggregate_sigs_verify.test.ts +++ b/test/spec/aggregate_sigs_verify.test.ts @@ -1,6 +1,9 @@ import path from "path"; -import bls, {initBLS} from "../../src"; -import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util"; +import bls, { initBLS } from "../../src"; +import { + describeDirectorySpecTest, + InputType, +} from "@chainsafe/lodestar-spec-test-util"; interface AggregateSigsVerifyTestCase { data: { @@ -27,23 +30,23 @@ describeDirectorySpecTest( __dirname, "../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/aggregate_verify/small" ), - (testCase => { - const pubkeys = testCase.data.input.pubkeys.map(pubkey => { + (testCase) => { + const pubkeys = testCase.data.input.pubkeys.map((pubkey) => { return Buffer.from(pubkey.replace("0x", ""), "hex"); }); - const messages = testCase.data.input.messages.map(msg => { + const messages = testCase.data.input.messages.map((msg) => { return Buffer.from(msg.replace("0x", ""), "hex"); }); return bls.verifyMultiple( pubkeys, messages, - Buffer.from(testCase.data.input.signature.replace("0x", ""), "hex"), + Buffer.from(testCase.data.input.signature.replace("0x", ""), "hex") ); - }), + }, { inputTypes: { data: InputType.YAML, }, - getExpected: (testCase => testCase.data.output) + getExpected: (testCase) => testCase.data.output, } ); diff --git a/test/spec/fast_aggregate_verify.test.ts b/test/spec/fast_aggregate_verify.test.ts index 125b096..8117b13 100644 --- a/test/spec/fast_aggregate_verify.test.ts +++ b/test/spec/fast_aggregate_verify.test.ts @@ -1,6 +1,9 @@ import path from "path"; -import bls, {initBLS} from "../../src"; -import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util"; +import bls, { initBLS } from "../../src"; +import { + describeDirectorySpecTest, + InputType, +} from "@chainsafe/lodestar-spec-test-util"; interface AggregateSigsVerifyTestCase { data: { @@ -27,17 +30,19 @@ describeDirectorySpecTest( __dirname, "../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/fast_aggregate_verify/small" ), - (testCase => { + (testCase) => { return bls.verifyAggregate( - testCase.data.input.pubkeys.map((key) => Buffer.from(key.replace("0x", ""), "hex")), + testCase.data.input.pubkeys.map((key) => + Buffer.from(key.replace("0x", ""), "hex") + ), Buffer.from(testCase.data.input.message.replace("0x", ""), "hex"), - Buffer.from(testCase.data.input.signature.replace("0x", ""), "hex"), + Buffer.from(testCase.data.input.signature.replace("0x", ""), "hex") ); - }), + }, { inputTypes: { data: InputType.YAML, }, - getExpected: (testCase => testCase.data.output) + getExpected: (testCase) => testCase.data.output, } ); diff --git a/test/spec/sign.test.ts b/test/spec/sign.test.ts index 2c6925e..637317e 100644 --- a/test/spec/sign.test.ts +++ b/test/spec/sign.test.ts @@ -1,6 +1,9 @@ import path from "path"; -import bls, {initBLS} from "../../src"; -import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util"; +import bls, { initBLS } from "../../src"; +import { + describeDirectorySpecTest, + InputType, +} from "@chainsafe/lodestar-spec-test-util"; interface ISignMessageTestCase { data: { @@ -22,17 +25,17 @@ describeDirectorySpecTest( __dirname, "../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/sign/small" ), - (testCase => { - const signature = bls.sign( + (testCase) => { + const signature = bls.sign( Buffer.from(testCase.data.input.privkey.replace("0x", ""), "hex"), Buffer.from(testCase.data.input.message.replace("0x", ""), "hex") ); return `0x${signature.toString("hex")}`; - }), + }, { inputTypes: { data: InputType.YAML, }, - getExpected: (testCase => testCase.data.output) + getExpected: (testCase) => testCase.data.output, } ); diff --git a/test/spec/verify.test.ts b/test/spec/verify.test.ts index d1a8a5f..5fbaf44 100644 --- a/test/spec/verify.test.ts +++ b/test/spec/verify.test.ts @@ -1,6 +1,9 @@ import path from "path"; -import bls, {initBLS} from "../../src"; -import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util"; +import bls, { initBLS } from "../../src"; +import { + describeDirectorySpecTest, + InputType, +} from "@chainsafe/lodestar-spec-test-util"; interface IVerifyTestCase { data: { @@ -23,17 +26,17 @@ describeDirectorySpecTest( __dirname, "../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/verify/small" ), - (testCase => { + (testCase) => { return bls.verify( Buffer.from(testCase.data.input.pubkey.replace("0x", ""), "hex"), Buffer.from(testCase.data.input.message.replace("0x", ""), "hex"), Buffer.from(testCase.data.input.signature.replace("0x", ""), "hex") ); - }), + }, { inputTypes: { data: InputType.YAML, }, - getExpected: (testCase => testCase.data.output) + getExpected: (testCase) => testCase.data.output, } ); diff --git a/test/unit/context.test.ts b/test/unit/context.test.ts index 2001aed..123ab19 100644 --- a/test/unit/context.test.ts +++ b/test/unit/context.test.ts @@ -1,20 +1,19 @@ -import {init, getContext, destroy} from "../../src/context"; -import {expect} from "chai"; +import { init, getContext, destroy } from "../../src/context"; +import { expect } from "chai"; describe("bls wasm constext", function () { - afterEach(() => { destroy(); }); it("initializes and works", async function () { await init(); - expect(getContext().getCurveOrder()) - .to.be.equal("52435875175126190479447740508185965837690552500527637822603658699938581184513"); + expect(getContext().getCurveOrder()).to.be.equal( + "52435875175126190479447740508185965837690552500527637822603658699938581184513" + ); }); it("throws if context not initialized", async function () { expect(() => getContext().getCurveOrder()).to.throw(); }); - -}); \ No newline at end of file +}); diff --git a/test/unit/index.test.ts b/test/unit/index.test.ts index be19531..6e7734f 100644 --- a/test/unit/index.test.ts +++ b/test/unit/index.test.ts @@ -1,12 +1,18 @@ -import bls, {aggregatePubkeys, aggregateSignatures, initBLS, Keypair, verify, verifyMultiple} from "../../src"; +import bls, { + aggregatePubkeys, + aggregateSignatures, + initBLS, + Keypair, + verify, + verifyMultiple, +} from "../../src"; import SHA256 from "@chainsafe/as-sha256"; -import {expect} from "chai"; -import {destroy} from "../../src/context"; -import {padLeft} from "../../src/helpers/utils"; +import { expect } from "chai"; +import { destroy } from "../../src/context"; +import { padLeft } from "../../src/helpers/utils"; describe("test bls", function () { - - before(async function() { + before(async function () { await initBLS(); }); @@ -20,61 +26,57 @@ describe("test bls", function () { }); }); - describe("verify", function() { + describe("verify", function () { it("should verify signature", () => { const keypair = Keypair.generate(); const messageHash = Buffer.from(SHA256.digest(Buffer.from("Test"))); - const signature = keypair.privateKey.signMessage( - messageHash, - ); + const signature = keypair.privateKey.signMessage(messageHash); const result = verify( keypair.publicKey.toBytesCompressed(), messageHash, - signature.toBytesCompressed(), + signature.toBytesCompressed() ); expect(result).to.be.true; }); - it("should not modify original pubkey when verifying", () => { const keypair = Keypair.generate(); const messageHash = Buffer.from(SHA256.digest(Buffer.from("Test"))); - const signature = keypair.privateKey.signMessage( - messageHash, - ); + const signature = keypair.privateKey.signMessage(messageHash); const pubKey = keypair.publicKey.toBytesCompressed(); - verify( - pubKey, - messageHash, - signature.toBytesCompressed(), + verify(pubKey, messageHash, signature.toBytesCompressed()); + expect("0x" + pubKey.toString("hex")).to.be.equal( + keypair.publicKey.toHexString() ); - expect("0x" + pubKey.toString("hex")).to.be.equal(keypair.publicKey.toHexString()); }); - it("should fail verify empty signature", () => { const keypair = Keypair.generate(); - const messageHash2 = Buffer.from(SHA256.digest(Buffer.from("Test message2"))); + const messageHash2 = Buffer.from( + SHA256.digest(Buffer.from("Test message2")) + ); const signature = Buffer.alloc(96); const result = verify( keypair.publicKey.toBytesCompressed(), messageHash2, - signature, + signature ); expect(result).to.be.false; }); it("should fail verify signature of different message", () => { const keypair = Keypair.generate(); - const messageHash = Buffer.from(SHA256.digest(Buffer.from("Test message"))); - const messageHash2 = Buffer.from(SHA256.digest(Buffer.from("Test message2"))); - const signature = keypair.privateKey.signMessage( - messageHash, + const messageHash = Buffer.from( + SHA256.digest(Buffer.from("Test message")) ); + const messageHash2 = Buffer.from( + SHA256.digest(Buffer.from("Test message2")) + ); + const signature = keypair.privateKey.signMessage(messageHash); const result = verify( keypair.publicKey.toBytesCompressed(), messageHash2, - signature.toBytesCompressed(), + signature.toBytesCompressed() ); expect(result).to.be.false; }); @@ -82,26 +84,23 @@ describe("test bls", function () { it("should fail verify signature signed by different key", () => { const keypair = Keypair.generate(); const keypair2 = Keypair.generate(); - const messageHash = Buffer.from(SHA256.digest(Buffer.from("Test message"))); - const signature = keypair.privateKey.signMessage( - messageHash, + const messageHash = Buffer.from( + SHA256.digest(Buffer.from("Test message")) ); + const signature = keypair.privateKey.signMessage(messageHash); const result = verify( keypair2.publicKey.toBytesCompressed(), messageHash, - signature.toBytesCompressed(), + signature.toBytesCompressed() ); expect(result).to.be.false; }); }); - describe("verify multiple", function() { - + describe("verify multiple", function () { it("should verify aggregated signatures", function () { this.timeout(5000); - - const keypair1 = Keypair.generate(); const keypair2 = Keypair.generate(); const keypair3 = Keypair.generate(); @@ -135,7 +134,7 @@ describe("test bls", function () { const result = verifyMultiple( [aggregatePubKey12, aggregatePubKey34], [message1, message2], - aggregateSignature, + aggregateSignature ); expect(result).to.be.true; @@ -144,8 +143,6 @@ describe("test bls", function () { it("should verify aggregated signatures - same message", function () { this.timeout(5000); - - const keypair1 = Keypair.generate(); const keypair2 = Keypair.generate(); const keypair3 = Keypair.generate(); @@ -170,11 +167,11 @@ describe("test bls", function () { keypair1.publicKey.toBytesCompressed(), keypair2.publicKey.toBytesCompressed(), keypair3.publicKey.toBytesCompressed(), - keypair4.publicKey.toBytesCompressed() + keypair4.publicKey.toBytesCompressed(), ], [message, message, message, message], aggregateSignature, - true, + true ); expect(result).to.be.true; @@ -183,7 +180,6 @@ describe("test bls", function () { it("should fail to verify aggregated signatures - swapped messages", function () { this.timeout(5000); - const keypair1 = Keypair.generate(); const keypair2 = Keypair.generate(); const keypair3 = Keypair.generate(); @@ -217,15 +213,13 @@ describe("test bls", function () { const result = bls.verifyMultiple( [aggregatePubKey12, aggregatePubKey34], [message2, message1], - aggregateSignature, + aggregateSignature ); expect(result).to.be.false; }); it("should fail to verify aggregated signatures - different pubkeys and messsages", () => { - - const keypair1 = Keypair.generate(); const keypair2 = Keypair.generate(); const keypair3 = Keypair.generate(); @@ -244,7 +238,6 @@ describe("test bls", function () { keypair2.publicKey.toBytesCompressed(), ]); - const aggregateSignature = bls.aggregateSignatures([ signature1.toBytesCompressed(), signature2.toBytesCompressed(), @@ -255,29 +248,21 @@ describe("test bls", function () { const result = bls.verifyMultiple( [aggregatePubKey12], [message2, message1], - aggregateSignature, + aggregateSignature ); expect(result).to.be.false; }); it("should fail to verify aggregated signatures - no public keys", () => { - - const signature = Buffer.alloc(96); const message1 = Buffer.from(SHA256.digest(Buffer.from("Test1"))); const message2 = Buffer.from(SHA256.digest(Buffer.from("Test2"))); - const result = bls.verifyMultiple( - [], - [message2, message1], - signature, - ); + const result = bls.verifyMultiple([], [message2, message1], signature); expect(result).to.be.false; }); - }); - }); diff --git a/test/unit/keypair.test.ts b/test/unit/keypair.test.ts index a2d8114..dcd6e9d 100644 --- a/test/unit/keypair.test.ts +++ b/test/unit/keypair.test.ts @@ -1,9 +1,8 @@ -import {PrivateKey,PublicKey,Keypair} from "../../src"; -import {expect} from "chai"; -import {destroy, init} from "../../src/context"; - -describe("keypair", function() { +import { PrivateKey, PublicKey, Keypair } from "../../src"; +import { expect } from "chai"; +import { destroy, init } from "../../src/context"; +describe("keypair", function () { before(async function () { await init(); }); @@ -15,7 +14,9 @@ describe("keypair", function() { it("should create from private and public key", () => { const secret = PrivateKey.random(); const secret2 = PrivateKey.random(); - const publicKey = PublicKey.fromBytes(PublicKey.fromPrivateKey(secret2).toBytesCompressed()); + const publicKey = PublicKey.fromBytes( + PublicKey.fromPrivateKey(secret2).toBytesCompressed() + ); const keypair = new Keypair(secret, publicKey); expect(keypair.publicKey).to.be.equal(publicKey); expect(keypair.privateKey).to.be.equal(secret); @@ -26,7 +27,8 @@ describe("keypair", function() { const secret = PrivateKey.random(); const publicKey = PublicKey.fromPrivateKey(secret); const keypair = new Keypair(secret); - expect(keypair.publicKey.toBytesCompressed().toString("hex")) - .to.be.equal(publicKey.toBytesCompressed().toString("hex")); + expect(keypair.publicKey.toBytesCompressed().toString("hex")).to.be.equal( + publicKey.toBytesCompressed().toString("hex") + ); }); }); diff --git a/test/unit/privateKey.test.ts b/test/unit/privateKey.test.ts index ec06974..e1b4bbb 100644 --- a/test/unit/privateKey.test.ts +++ b/test/unit/privateKey.test.ts @@ -1,10 +1,9 @@ -import {PrivateKey} from "../../src"; -import {expect} from "chai"; -import {SECRET_KEY_LENGTH} from "../../src/constants"; -import {destroy, init} from "../../src/context"; - -describe("privateKey", function() { +import { PrivateKey } from "../../src"; +import { expect } from "chai"; +import { SECRET_KEY_LENGTH } from "../../src/constants"; +import { destroy, init } from "../../src/context"; +describe("privateKey", function () { before(async function () { await init(); }); @@ -16,25 +15,32 @@ describe("privateKey", function() { it("should generate random private key", function () { const privateKey1 = PrivateKey.random(); const privateKey2 = PrivateKey.random(); - expect(privateKey1.toHexString()).to.not.be.equal(privateKey2.toHexString()); + expect(privateKey1.toHexString()).to.not.be.equal( + privateKey2.toHexString() + ); }); it("should export private key to hex string", function () { - const privateKey = "0x07656fd676da43883d163f49566c72b9cbf0a5a294f26808c807700732456da7"; + const privateKey = + "0x07656fd676da43883d163f49566c72b9cbf0a5a294f26808c807700732456da7"; - expect(PrivateKey.fromHexString(privateKey).toHexString()).to.be.equal(privateKey); + expect(PrivateKey.fromHexString(privateKey).toHexString()).to.be.equal( + privateKey + ); - const privateKey2 = "07656fd676da43883d163f49566c72b9cbf0a5a294f26808c807700732456da7"; + const privateKey2 = + "07656fd676da43883d163f49566c72b9cbf0a5a294f26808c807700732456da7"; - expect(PrivateKey.fromHexString(privateKey2).toHexString()).to.be.equal(privateKey); + expect(PrivateKey.fromHexString(privateKey2).toHexString()).to.be.equal( + privateKey + ); }); it("should export private key to bytes", function () { expect(PrivateKey.random().toBytes().length).to.be.equal(SECRET_KEY_LENGTH); }); - + it("should not accept too short private key", function () { expect(() => PrivateKey.fromHexString("0x2123")).to.throw(); }); - }); diff --git a/test/unit/publicKey.test.ts b/test/unit/publicKey.test.ts index e00b05a..64deb28 100644 --- a/test/unit/publicKey.test.ts +++ b/test/unit/publicKey.test.ts @@ -1,9 +1,8 @@ -import {destroy, init} from "../../src/context"; -import {PublicKey, PrivateKey} from "../../src"; -import {expect} from "chai"; +import { destroy, init } from "../../src/context"; +import { PublicKey, PrivateKey } from "../../src"; +import { expect } from "chai"; describe("public key", function () { - before(async function f() { await init(); }); @@ -14,18 +13,19 @@ describe("public key", function () { it("from hex", function () { const publicKey = - "0xb6f21199594b56d77670564bf422cb331d5281ca2c1f9a45588a56881d8287ef8619efa6456d6cd2ef61306aa5b21311"; + "0xb6f21199594b56d77670564bf422cb331d5281ca2c1f9a45588a56881d8287ef8619efa6456d6cd2ef61306aa5b21311"; expect(PublicKey.fromHex(publicKey).toHexString()).to.be.equal(publicKey); }); it("from bytes", function () { const publicKey = - "b6f21199594b56d77670564bf422cb331d5281ca2c1f9a45588a56881d8287ef8619efa6456d6cd2ef61306aa5b21311"; - expect(PublicKey.fromBytes(Buffer.from(publicKey, "hex")).toHexString()).to.be.equal(`0x${publicKey}`); + "b6f21199594b56d77670564bf422cb331d5281ca2c1f9a45588a56881d8287ef8619efa6456d6cd2ef61306aa5b21311"; + expect( + PublicKey.fromBytes(Buffer.from(publicKey, "hex")).toHexString() + ).to.be.equal(`0x${publicKey}`); }); it("from private key", function () { PublicKey.fromPrivateKey(PrivateKey.random()); }); - -}); \ No newline at end of file +}); From eaffbae4496d052483c2a77448f9daa4a58445d9 Mon Sep 17 00:00:00 2001 From: dapplion Date: Wed, 4 Nov 2020 18:00:50 +0000 Subject: [PATCH 4/7] Include tests in ts-config --- package.json | 2 +- tsconfig.build.json | 5 +++++ tsconfig.json | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 tsconfig.build.json diff --git a/package.json b/package.json index a4e48e9..65ba239 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "build": "yarn build-lib && yarn build-types", "build:release": "yarn clean && yarn build && yarn build-web", "build-lib": "babel src -x .ts -d lib", - "build-types": "tsc --declaration --incremental --outDir lib --emitDeclarationOnly", + "build-types": "tsc --declaration --incremental --outDir lib --project tsconfig.build.json --emitDeclarationOnly", "build-web": "webpack --mode production --entry ./lib/web.js --output ./dist/bls.min.js", "check-types": "tsc --noEmit", "lint": "eslint --color --ext .ts src/ test/", diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..7e92fee --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,5 @@ +{ + "extends": "./tsconfig", + "include": ["src"], + "exclude": ["test"], +} diff --git a/tsconfig.json b/tsconfig.json index db678b5..a083043 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,5 @@ { - "include": ["src"], + "include": ["src", "test"], "compilerOptions": { "target": "esnext", "module": "commonjs", From dad7655a351705f81fb730e20286670ec962f2e8 Mon Sep 17 00:00:00 2001 From: dapplion Date: Wed, 4 Nov 2020 18:04:55 +0000 Subject: [PATCH 5/7] Fix prettier config file --- .prettierrc.yml | 9 +++++++++ prettierrc.js | 11 ----------- 2 files changed, 9 insertions(+), 11 deletions(-) create mode 100644 .prettierrc.yml delete mode 100644 prettierrc.js diff --git a/.prettierrc.yml b/.prettierrc.yml new file mode 100644 index 0000000..3d25a0e --- /dev/null +++ b/.prettierrc.yml @@ -0,0 +1,9 @@ +printWidth: 120 +tabWidth: 2 +useTabs: false +semi: true +singleQuote: false +quoteProps: "as-needed" +trailingComma: "es5" +bracketSpacing: false +arrowParens: "always" \ No newline at end of file diff --git a/prettierrc.js b/prettierrc.js deleted file mode 100644 index 20baea5..0000000 --- a/prettierrc.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - printWidth: 120, - tabWidth: 2, - useTabs: false, - semi: true, - singleQuote: false, - quoteProps: "as-needed", - trailingComma: "es5", - bracketSpacing: false, - arrowParens: "always", -}; \ No newline at end of file From 49d6d9f62cf1d8aa9be532b865820c175a917e0a Mon Sep 17 00:00:00 2001 From: Cayman Date: Thu, 5 Nov 2020 14:55:25 -0600 Subject: [PATCH 6/7] Run prettier --- src/helpers/utils.ts | 7 +-- src/index.ts | 31 ++++------- src/keypair.ts | 4 +- src/privateKey.ts | 22 +++----- src/publicKey.ts | 12 ++--- src/signature.ts | 26 +++------ test/spec/aggregate_sigs.test.ts | 12 ++--- test/spec/aggregate_sigs_verify.test.ts | 18 ++----- test/spec/fast_aggregate_verify.test.ts | 11 ++-- test/spec/sign.test.ts | 12 ++--- test/spec/verify.test.ts | 12 ++--- test/unit/context.test.ts | 4 +- test/unit/index.test.ts | 71 ++++++------------------- test/unit/keypair.test.ts | 10 ++-- test/unit/privateKey.test.ts | 26 ++++----- test/unit/publicKey.test.ts | 10 ++-- 16 files changed, 86 insertions(+), 202 deletions(-) diff --git a/src/helpers/utils.ts b/src/helpers/utils.ts index 79b4bf9..7430d7d 100644 --- a/src/helpers/utils.ts +++ b/src/helpers/utils.ts @@ -1,5 +1,5 @@ import assert from "assert"; -import { PUBLIC_KEY_LENGTH, SIGNATURE_LENGTH } from "../constants"; +import {PUBLIC_KEY_LENGTH, SIGNATURE_LENGTH} from "../constants"; /** * Pads byte array with zeroes on left side up to desired length. @@ -8,10 +8,7 @@ import { PUBLIC_KEY_LENGTH, SIGNATURE_LENGTH } from "../constants"; * @param length */ export function padLeft(source: Uint8Array, length: number): Buffer { - assert( - source.length <= length, - "Given array must be smaller or equal to desired array size" - ); + assert(source.length <= length, "Given array must be smaller or equal to desired array size"); const result = Buffer.alloc(length, 0); result.set(source, length - source.length); return result; diff --git a/src/index.ts b/src/index.ts index e8ca68a..b398620 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,13 +1,13 @@ -import { Keypair } from "./keypair"; -import { PrivateKey } from "./privateKey"; -import { PublicKey } from "./publicKey"; -import { Signature } from "./signature"; -import { PUBLIC_KEY_LENGTH } from "./constants"; +import {Keypair} from "./keypair"; +import {PrivateKey} from "./privateKey"; +import {PublicKey} from "./publicKey"; +import {Signature} from "./signature"; +import {PUBLIC_KEY_LENGTH} from "./constants"; import assert from "assert"; -export { Keypair, PrivateKey, PublicKey, Signature }; +export {Keypair, PrivateKey, PublicKey, Signature}; -export { init as initBLS } from "./context"; +export {init as initBLS} from "./context"; function toBuffer(input: Uint8Array): Buffer { return Buffer.from(input.buffer, input.byteOffset, input.length); @@ -47,10 +47,7 @@ export function sign(secretKey: Uint8Array, messageHash: Uint8Array): Buffer { * @param signatures */ export function aggregateSignatures(signatures: Uint8Array[]): Buffer { - assert( - signatures && signatures.length > 0, - "signatures is null or undefined or empty array" - ); + assert(signatures && signatures.length > 0, "signatures is null or undefined or empty array"); return Signature.aggregate( signatures.map( (signature): Signature => { @@ -81,11 +78,7 @@ export function aggregatePubkeys(publicKeys: Uint8Array[]): Buffer { * @param messageHash * @param signature */ -export function verify( - publicKey: Uint8Array, - messageHash: Uint8Array, - signature: Uint8Array -): boolean { +export function verify(publicKey: Uint8Array, messageHash: Uint8Array, signature: Uint8Array): boolean { assert(publicKey, "publicKey is null or undefined"); assert(messageHash, "messageHash is null or undefined"); assert(signature, "signature is null or undefined"); @@ -105,11 +98,7 @@ export function verify( * @param messageHash * @param signature */ -export function verifyAggregate( - publicKeys: Uint8Array[], - messageHash: Uint8Array, - signature: Uint8Array -): boolean { +export function verifyAggregate(publicKeys: Uint8Array[], messageHash: Uint8Array, signature: Uint8Array): boolean { assert(publicKeys, "publicKey is null or undefined"); assert(messageHash, "messageHash is null or undefined"); assert(signature, "signature is null or undefined"); diff --git a/src/keypair.ts b/src/keypair.ts index 17b4445..ca862b3 100644 --- a/src/keypair.ts +++ b/src/keypair.ts @@ -1,5 +1,5 @@ -import { PublicKey } from "./publicKey"; -import { PrivateKey } from "./privateKey"; +import {PublicKey} from "./publicKey"; +import {PrivateKey} from "./privateKey"; export class Keypair { private readonly _publicKey: PublicKey; diff --git a/src/privateKey.ts b/src/privateKey.ts index 2eeedfa..deb8029 100644 --- a/src/privateKey.ts +++ b/src/privateKey.ts @@ -1,10 +1,10 @@ -import { SECRET_KEY_LENGTH } from "./constants"; +import {SECRET_KEY_LENGTH} from "./constants"; import assert from "assert"; -import { SecretKeyType } from "@chainsafe/eth2-bls-wasm"; -import { generateRandomSecretKey } from "@chainsafe/bls-keygen"; -import { getContext } from "./context"; -import { PublicKey } from "./publicKey"; -import { Signature } from "./signature"; +import {SecretKeyType} from "@chainsafe/eth2-bls-wasm"; +import {generateRandomSecretKey} from "@chainsafe/bls-keygen"; +import {getContext} from "./context"; +import {PublicKey} from "./publicKey"; +import {Signature} from "./signature"; export class PrivateKey { private value: SecretKeyType; @@ -14,10 +14,7 @@ export class PrivateKey { } public static fromBytes(bytes: Uint8Array): PrivateKey { - assert( - bytes.length === SECRET_KEY_LENGTH, - "Private key should have 32 bytes" - ); + assert(bytes.length === SECRET_KEY_LENGTH, "Private key should have 32 bytes"); const context = getContext(); const secretKey = new context.SecretKey(); secretKey.deserialize(Buffer.from(bytes)); @@ -26,10 +23,7 @@ export class PrivateKey { public static fromHexString(value: string): PrivateKey { value = value.replace("0x", ""); - assert( - value.length === SECRET_KEY_LENGTH * 2, - "secret key must have 32 bytes" - ); + assert(value.length === SECRET_KEY_LENGTH * 2, "secret key must have 32 bytes"); const context = getContext(); return new PrivateKey(context.deserializeHexStrToSecretKey(value)); } diff --git a/src/publicKey.ts b/src/publicKey.ts index 3ff0361..c994489 100644 --- a/src/publicKey.ts +++ b/src/publicKey.ts @@ -1,10 +1,10 @@ -import { PrivateKey } from "./privateKey"; -import { PublicKeyType } from "@chainsafe/eth2-bls-wasm"; -import { getContext } from "./context"; -import { PUBLIC_KEY_LENGTH } from "./constants"; +import {PrivateKey} from "./privateKey"; +import {PublicKeyType} from "@chainsafe/eth2-bls-wasm"; +import {getContext} from "./context"; +import {PUBLIC_KEY_LENGTH} from "./constants"; import assert from "assert"; -import { Signature } from "./signature"; -import { EMPTY_PUBLIC_KEY } from "./helpers/utils"; +import {Signature} from "./signature"; +import {EMPTY_PUBLIC_KEY} from "./helpers/utils"; export class PublicKey { private value: PublicKeyType; diff --git a/src/signature.ts b/src/signature.ts index b60e630..08c38e6 100644 --- a/src/signature.ts +++ b/src/signature.ts @@ -1,9 +1,9 @@ import assert from "assert"; -import { FP_POINT_LENGTH } from "./constants"; -import { SignatureType } from "@chainsafe/eth2-bls-wasm"; -import { getContext } from "./context"; -import { PublicKey } from "./publicKey"; -import { EMPTY_SIGNATURE } from "./helpers/utils"; +import {FP_POINT_LENGTH} from "./constants"; +import {SignatureType} from "@chainsafe/eth2-bls-wasm"; +import {getContext} from "./context"; +import {PublicKey} from "./publicKey"; +import {EMPTY_SIGNATURE} from "./helpers/utils"; export class Signature { private value: SignatureType; @@ -14,10 +14,7 @@ export class Signature { } public static fromCompressedBytes(value: Uint8Array): Signature { - assert( - value.length === 2 * FP_POINT_LENGTH, - `Signature must have ${2 * FP_POINT_LENGTH} bytes` - ); + assert(value.length === 2 * FP_POINT_LENGTH, `Signature must have ${2 * FP_POINT_LENGTH} bytes`); const context = getContext(); const signature = new context.Signature(); if (!EMPTY_SIGNATURE.equals(value)) { @@ -47,21 +44,14 @@ export class Signature { return this.value; } - public verifyAggregate( - publicKeys: PublicKey[], - message: Uint8Array - ): boolean { + public verifyAggregate(publicKeys: PublicKey[], message: Uint8Array): boolean { return this.value.fastAggregateVerify( publicKeys.map((key) => key.getValue()), message ); } - public verifyMultiple( - publicKeys: PublicKey[], - messages: Uint8Array[], - fast = false - ): boolean { + public verifyMultiple(publicKeys: PublicKey[], messages: Uint8Array[], fast = false): boolean { const msgs = Buffer.concat(messages); if (!fast && !getContext().areAllMsgDifferent(msgs)) { return false; diff --git a/test/spec/aggregate_sigs.test.ts b/test/spec/aggregate_sigs.test.ts index fb2c8bb..70f69da 100644 --- a/test/spec/aggregate_sigs.test.ts +++ b/test/spec/aggregate_sigs.test.ts @@ -1,9 +1,6 @@ import path from "path"; -import bls, { initBLS } from "../../src"; -import { - describeDirectorySpecTest, - InputType, -} from "@chainsafe/lodestar-spec-test-util"; +import bls, {initBLS} from "../../src"; +import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util"; interface IAggregateSigsTestCase { data: { @@ -18,10 +15,7 @@ before(async function f() { describeDirectorySpecTest( "BLS - aggregate sigs", - path.join( - __dirname, - "../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/aggregate/small" - ), + path.join(__dirname, "../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/aggregate/small"), (testCase) => { try { const result = bls.aggregateSignatures( diff --git a/test/spec/aggregate_sigs_verify.test.ts b/test/spec/aggregate_sigs_verify.test.ts index ddb89ad..a4d711a 100644 --- a/test/spec/aggregate_sigs_verify.test.ts +++ b/test/spec/aggregate_sigs_verify.test.ts @@ -1,9 +1,6 @@ import path from "path"; -import bls, { initBLS } from "../../src"; -import { - describeDirectorySpecTest, - InputType, -} from "@chainsafe/lodestar-spec-test-util"; +import bls, {initBLS} from "../../src"; +import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util"; interface AggregateSigsVerifyTestCase { data: { @@ -26,10 +23,7 @@ before(async function f() { describeDirectorySpecTest( "BLS - aggregate sigs verify", - path.join( - __dirname, - "../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/aggregate_verify/small" - ), + path.join(__dirname, "../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/aggregate_verify/small"), (testCase) => { const pubkeys = testCase.data.input.pubkeys.map((pubkey) => { return Buffer.from(pubkey.replace("0x", ""), "hex"); @@ -37,11 +31,7 @@ describeDirectorySpecTest( const messages = testCase.data.input.messages.map((msg) => { return Buffer.from(msg.replace("0x", ""), "hex"); }); - return bls.verifyMultiple( - pubkeys, - messages, - Buffer.from(testCase.data.input.signature.replace("0x", ""), "hex") - ); + return bls.verifyMultiple(pubkeys, messages, Buffer.from(testCase.data.input.signature.replace("0x", ""), "hex")); }, { inputTypes: { diff --git a/test/spec/fast_aggregate_verify.test.ts b/test/spec/fast_aggregate_verify.test.ts index 8117b13..84abf33 100644 --- a/test/spec/fast_aggregate_verify.test.ts +++ b/test/spec/fast_aggregate_verify.test.ts @@ -1,9 +1,6 @@ import path from "path"; -import bls, { initBLS } from "../../src"; -import { - describeDirectorySpecTest, - InputType, -} from "@chainsafe/lodestar-spec-test-util"; +import bls, {initBLS} from "../../src"; +import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util"; interface AggregateSigsVerifyTestCase { data: { @@ -32,9 +29,7 @@ describeDirectorySpecTest( ), (testCase) => { return bls.verifyAggregate( - testCase.data.input.pubkeys.map((key) => - Buffer.from(key.replace("0x", ""), "hex") - ), + testCase.data.input.pubkeys.map((key) => Buffer.from(key.replace("0x", ""), "hex")), Buffer.from(testCase.data.input.message.replace("0x", ""), "hex"), Buffer.from(testCase.data.input.signature.replace("0x", ""), "hex") ); diff --git a/test/spec/sign.test.ts b/test/spec/sign.test.ts index 637317e..84d8e83 100644 --- a/test/spec/sign.test.ts +++ b/test/spec/sign.test.ts @@ -1,9 +1,6 @@ import path from "path"; -import bls, { initBLS } from "../../src"; -import { - describeDirectorySpecTest, - InputType, -} from "@chainsafe/lodestar-spec-test-util"; +import bls, {initBLS} from "../../src"; +import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util"; interface ISignMessageTestCase { data: { @@ -21,10 +18,7 @@ before(async function f() { describeDirectorySpecTest( "BLS - sign", - path.join( - __dirname, - "../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/sign/small" - ), + path.join(__dirname, "../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/sign/small"), (testCase) => { const signature = bls.sign( Buffer.from(testCase.data.input.privkey.replace("0x", ""), "hex"), diff --git a/test/spec/verify.test.ts b/test/spec/verify.test.ts index 5fbaf44..5f98fc8 100644 --- a/test/spec/verify.test.ts +++ b/test/spec/verify.test.ts @@ -1,9 +1,6 @@ import path from "path"; -import bls, { initBLS } from "../../src"; -import { - describeDirectorySpecTest, - InputType, -} from "@chainsafe/lodestar-spec-test-util"; +import bls, {initBLS} from "../../src"; +import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util"; interface IVerifyTestCase { data: { @@ -22,10 +19,7 @@ before(async function f() { describeDirectorySpecTest( "BLS - verify", - path.join( - __dirname, - "../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/verify/small" - ), + path.join(__dirname, "../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/verify/small"), (testCase) => { return bls.verify( Buffer.from(testCase.data.input.pubkey.replace("0x", ""), "hex"), diff --git a/test/unit/context.test.ts b/test/unit/context.test.ts index 123ab19..1942c54 100644 --- a/test/unit/context.test.ts +++ b/test/unit/context.test.ts @@ -1,5 +1,5 @@ -import { init, getContext, destroy } from "../../src/context"; -import { expect } from "chai"; +import {init, getContext, destroy} from "../../src/context"; +import {expect} from "chai"; describe("bls wasm constext", function () { afterEach(() => { diff --git a/test/unit/index.test.ts b/test/unit/index.test.ts index 6e7734f..9085828 100644 --- a/test/unit/index.test.ts +++ b/test/unit/index.test.ts @@ -1,15 +1,8 @@ -import bls, { - aggregatePubkeys, - aggregateSignatures, - initBLS, - Keypair, - verify, - verifyMultiple, -} from "../../src"; +import bls, {aggregatePubkeys, aggregateSignatures, initBLS, Keypair, verify, verifyMultiple} from "../../src"; import SHA256 from "@chainsafe/as-sha256"; -import { expect } from "chai"; -import { destroy } from "../../src/context"; -import { padLeft } from "../../src/helpers/utils"; +import {expect} from "chai"; +import {destroy} from "../../src/context"; +import {padLeft} from "../../src/helpers/utils"; describe("test bls", function () { before(async function () { @@ -31,11 +24,7 @@ describe("test bls", function () { const keypair = Keypair.generate(); const messageHash = Buffer.from(SHA256.digest(Buffer.from("Test"))); const signature = keypair.privateKey.signMessage(messageHash); - const result = verify( - keypair.publicKey.toBytesCompressed(), - messageHash, - signature.toBytesCompressed() - ); + const result = verify(keypair.publicKey.toBytesCompressed(), messageHash, signature.toBytesCompressed()); expect(result).to.be.true; }); @@ -45,54 +34,32 @@ describe("test bls", function () { const signature = keypair.privateKey.signMessage(messageHash); const pubKey = keypair.publicKey.toBytesCompressed(); verify(pubKey, messageHash, signature.toBytesCompressed()); - expect("0x" + pubKey.toString("hex")).to.be.equal( - keypair.publicKey.toHexString() - ); + expect("0x" + pubKey.toString("hex")).to.be.equal(keypair.publicKey.toHexString()); }); it("should fail verify empty signature", () => { const keypair = Keypair.generate(); - const messageHash2 = Buffer.from( - SHA256.digest(Buffer.from("Test message2")) - ); + const messageHash2 = Buffer.from(SHA256.digest(Buffer.from("Test message2"))); const signature = Buffer.alloc(96); - const result = verify( - keypair.publicKey.toBytesCompressed(), - messageHash2, - signature - ); + const result = verify(keypair.publicKey.toBytesCompressed(), messageHash2, signature); expect(result).to.be.false; }); it("should fail verify signature of different message", () => { const keypair = Keypair.generate(); - const messageHash = Buffer.from( - SHA256.digest(Buffer.from("Test message")) - ); - const messageHash2 = Buffer.from( - SHA256.digest(Buffer.from("Test message2")) - ); + const messageHash = Buffer.from(SHA256.digest(Buffer.from("Test message"))); + const messageHash2 = Buffer.from(SHA256.digest(Buffer.from("Test message2"))); const signature = keypair.privateKey.signMessage(messageHash); - const result = verify( - keypair.publicKey.toBytesCompressed(), - messageHash2, - signature.toBytesCompressed() - ); + const result = verify(keypair.publicKey.toBytesCompressed(), messageHash2, signature.toBytesCompressed()); expect(result).to.be.false; }); it("should fail verify signature signed by different key", () => { const keypair = Keypair.generate(); const keypair2 = Keypair.generate(); - const messageHash = Buffer.from( - SHA256.digest(Buffer.from("Test message")) - ); + const messageHash = Buffer.from(SHA256.digest(Buffer.from("Test message"))); const signature = keypair.privateKey.signMessage(messageHash); - const result = verify( - keypair2.publicKey.toBytesCompressed(), - messageHash, - signature.toBytesCompressed() - ); + const result = verify(keypair2.publicKey.toBytesCompressed(), messageHash, signature.toBytesCompressed()); expect(result).to.be.false; }); }); @@ -131,11 +98,7 @@ describe("test bls", function () { signature4.toBytesCompressed(), ]); - const result = verifyMultiple( - [aggregatePubKey12, aggregatePubKey34], - [message1, message2], - aggregateSignature - ); + const result = verifyMultiple([aggregatePubKey12, aggregatePubKey34], [message1, message2], aggregateSignature); expect(result).to.be.true; }); @@ -245,11 +208,7 @@ describe("test bls", function () { signature4.toBytesCompressed(), ]); - const result = bls.verifyMultiple( - [aggregatePubKey12], - [message2, message1], - aggregateSignature - ); + const result = bls.verifyMultiple([aggregatePubKey12], [message2, message1], aggregateSignature); expect(result).to.be.false; }); diff --git a/test/unit/keypair.test.ts b/test/unit/keypair.test.ts index dcd6e9d..8cbbddf 100644 --- a/test/unit/keypair.test.ts +++ b/test/unit/keypair.test.ts @@ -1,6 +1,6 @@ -import { PrivateKey, PublicKey, Keypair } from "../../src"; -import { expect } from "chai"; -import { destroy, init } from "../../src/context"; +import {PrivateKey, PublicKey, Keypair} from "../../src"; +import {expect} from "chai"; +import {destroy, init} from "../../src/context"; describe("keypair", function () { before(async function () { @@ -14,9 +14,7 @@ describe("keypair", function () { it("should create from private and public key", () => { const secret = PrivateKey.random(); const secret2 = PrivateKey.random(); - const publicKey = PublicKey.fromBytes( - PublicKey.fromPrivateKey(secret2).toBytesCompressed() - ); + const publicKey = PublicKey.fromBytes(PublicKey.fromPrivateKey(secret2).toBytesCompressed()); const keypair = new Keypair(secret, publicKey); expect(keypair.publicKey).to.be.equal(publicKey); expect(keypair.privateKey).to.be.equal(secret); diff --git a/test/unit/privateKey.test.ts b/test/unit/privateKey.test.ts index e1b4bbb..0fa9e4d 100644 --- a/test/unit/privateKey.test.ts +++ b/test/unit/privateKey.test.ts @@ -1,7 +1,7 @@ -import { PrivateKey } from "../../src"; -import { expect } from "chai"; -import { SECRET_KEY_LENGTH } from "../../src/constants"; -import { destroy, init } from "../../src/context"; +import {PrivateKey} from "../../src"; +import {expect} from "chai"; +import {SECRET_KEY_LENGTH} from "../../src/constants"; +import {destroy, init} from "../../src/context"; describe("privateKey", function () { before(async function () { @@ -15,25 +15,17 @@ describe("privateKey", function () { it("should generate random private key", function () { const privateKey1 = PrivateKey.random(); const privateKey2 = PrivateKey.random(); - expect(privateKey1.toHexString()).to.not.be.equal( - privateKey2.toHexString() - ); + expect(privateKey1.toHexString()).to.not.be.equal(privateKey2.toHexString()); }); it("should export private key to hex string", function () { - const privateKey = - "0x07656fd676da43883d163f49566c72b9cbf0a5a294f26808c807700732456da7"; + const privateKey = "0x07656fd676da43883d163f49566c72b9cbf0a5a294f26808c807700732456da7"; - expect(PrivateKey.fromHexString(privateKey).toHexString()).to.be.equal( - privateKey - ); + expect(PrivateKey.fromHexString(privateKey).toHexString()).to.be.equal(privateKey); - const privateKey2 = - "07656fd676da43883d163f49566c72b9cbf0a5a294f26808c807700732456da7"; + const privateKey2 = "07656fd676da43883d163f49566c72b9cbf0a5a294f26808c807700732456da7"; - expect(PrivateKey.fromHexString(privateKey2).toHexString()).to.be.equal( - privateKey - ); + expect(PrivateKey.fromHexString(privateKey2).toHexString()).to.be.equal(privateKey); }); it("should export private key to bytes", function () { diff --git a/test/unit/publicKey.test.ts b/test/unit/publicKey.test.ts index 64deb28..485148e 100644 --- a/test/unit/publicKey.test.ts +++ b/test/unit/publicKey.test.ts @@ -1,6 +1,6 @@ -import { destroy, init } from "../../src/context"; -import { PublicKey, PrivateKey } from "../../src"; -import { expect } from "chai"; +import {destroy, init} from "../../src/context"; +import {PublicKey, PrivateKey} from "../../src"; +import {expect} from "chai"; describe("public key", function () { before(async function f() { @@ -20,9 +20,7 @@ describe("public key", function () { it("from bytes", function () { const publicKey = "b6f21199594b56d77670564bf422cb331d5281ca2c1f9a45588a56881d8287ef8619efa6456d6cd2ef61306aa5b21311"; - expect( - PublicKey.fromBytes(Buffer.from(publicKey, "hex")).toHexString() - ).to.be.equal(`0x${publicKey}`); + expect(PublicKey.fromBytes(Buffer.from(publicKey, "hex")).toHexString()).to.be.equal(`0x${publicKey}`); }); it("from private key", function () { From 7f5403262694732dfd165b0e160f62b1e756de9e Mon Sep 17 00:00:00 2001 From: dapplion Date: Thu, 5 Nov 2020 21:44:36 +0000 Subject: [PATCH 7/7] Fix lint errors --- test/spec/aggregate_sigs_verify.test.ts | 4 ++-- test/spec/fast_aggregate_verify.test.ts | 4 ++-- test/unit/index.test.ts | 1 - 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/test/spec/aggregate_sigs_verify.test.ts b/test/spec/aggregate_sigs_verify.test.ts index a4d711a..8079830 100644 --- a/test/spec/aggregate_sigs_verify.test.ts +++ b/test/spec/aggregate_sigs_verify.test.ts @@ -2,7 +2,7 @@ import path from "path"; import bls, {initBLS} from "../../src"; import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util"; -interface AggregateSigsVerifyTestCase { +interface IAggregateSigsVerifyTestCase { data: { input: { pubkeys: string[]; @@ -21,7 +21,7 @@ before(async function f() { } }); -describeDirectorySpecTest( +describeDirectorySpecTest( "BLS - aggregate sigs verify", path.join(__dirname, "../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/aggregate_verify/small"), (testCase) => { diff --git a/test/spec/fast_aggregate_verify.test.ts b/test/spec/fast_aggregate_verify.test.ts index 84abf33..d4f8322 100644 --- a/test/spec/fast_aggregate_verify.test.ts +++ b/test/spec/fast_aggregate_verify.test.ts @@ -2,7 +2,7 @@ import path from "path"; import bls, {initBLS} from "../../src"; import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util"; -interface AggregateSigsVerifyTestCase { +interface IAggregateSigsVerifyTestCase { data: { input: { pubkeys: string[]; @@ -21,7 +21,7 @@ before(async function f() { } }); -describeDirectorySpecTest( +describeDirectorySpecTest( "BLS - aggregate sigs verify", path.join( __dirname, diff --git a/test/unit/index.test.ts b/test/unit/index.test.ts index 9085828..af18eb2 100644 --- a/test/unit/index.test.ts +++ b/test/unit/index.test.ts @@ -2,7 +2,6 @@ import bls, {aggregatePubkeys, aggregateSignatures, initBLS, Keypair, verify, ve import SHA256 from "@chainsafe/as-sha256"; import {expect} from "chai"; import {destroy} from "../../src/context"; -import {padLeft} from "../../src/helpers/utils"; describe("test bls", function () { before(async function () {