Update dev delendencies, tests, linter

This commit is contained in:
Cayman 2020-02-20 14:26:26 -06:00
parent c93b5c130b
commit cbaef47671
No known key found for this signature in database
GPG Key ID: 54B21AEC3C53E1F5
7 changed files with 6481 additions and 40 deletions

View File

@ -1,3 +1,22 @@
{ {
"extends": "../../.babelrc" "presets": [
[
"@babel/env",
{
"targets": {
"node": "10.4",
"browsers": ">1%, not ie 11"
},
"exclude": [
"transform-regenerator"
]
}
],
"@babel/typescript"
],
"plugins": [
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread",
"@babel/plugin-syntax-bigint"
]
} }

87
.eslintrc.js Normal file
View File

@ -0,0 +1,87 @@
const path = require('path');
module.exports = {
root: true,
env: {
browser: true,
es6: true,
node: true,
mocha: true
},
globals: {
BigInt: true,
},
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 10,
project: "./tsconfig.json"
},
plugins: [
"@typescript-eslint",
"eslint-plugin-import"
],
extends: [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"plugin:@typescript-eslint/recommended"
],
settings: {},
rules: {
//doesnt work, it reports false errors
"constructor-super": "off",
"@typescript-eslint/class-name-casing": "error",
"@typescript-eslint/explicit-function-return-type": ["error", {
"allowExpressions": true
}],
"@typescript-eslint/func-call-spacing": "error",
"@typescript-eslint/indent": ["error", 2],
"@typescript-eslint/interface-name-prefix": ["error", "always"],
"@typescript-eslint/member-ordering": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/no-unused-vars": ["error", {
"varsIgnorePattern": "^_"
}],
"@typescript-eslint/ban-ts-ignore": "warn",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/semi": "error",
"@typescript-eslint/type-annotation-spacing": "error",
//it doesn't recognize module/lib/something (like mainnet & minimal presets)
"import/no-duplicates": "off",
"import/no-extraneous-dependencies": ["error", {
"devDependencies": false,
"optionalDependencies": false,
"peerDependencies": false
}],
"func-call-spacing": "off",
"max-len": ["error", {
"code": 120
}],
//if --fix is run it messes imports like /lib/presets/minimal & /lib/presets/mainnet
"import/no-duplicates": "off",
"new-parens": "error",
"no-caller": "error",
"no-bitwise": "off",
"no-cond-assign": "error",
"no-consecutive-blank-lines": 0,
"no-console": "warn",
"no-var": "error",
"object-curly-spacing": ["error", "never"],
"object-literal-sort-keys": 0,
"no-prototype-builtins": 0,
"prefer-const": "error",
"quotes": ["error", "double"],
"semi": "off"
},
"overrides": [
{
"files": ["**/test/**/*.ts"],
"rules": {
"import/no-extraneous-dependencies": "off",
"@typescript-eslint/no-explicit-any": "off"
}
}
]
};

View File

@ -23,7 +23,7 @@
"build": "yarn build-lib && yarn build-types", "build": "yarn build-lib && yarn build-types",
"build:release": "yarn clean && yarn build && yarn build-web", "build:release": "yarn clean && yarn build && yarn build-web",
"build-lib": "babel src -x .ts -d lib", "build-lib": "babel src -x .ts -d lib",
"build-types": "tsc --declaration --project tsconfig.build.json --incremental --outDir lib --emitDeclarationOnly", "build-types": "tsc --declaration --incremental --outDir lib --emitDeclarationOnly",
"build-web": "webpack --mode production --entry ./lib/web.js --output ./dist/bls.min.js", "build-web": "webpack --mode production --entry ./lib/web.js --output ./dist/bls.min.js",
"check-types": "tsc --noEmit", "check-types": "tsc --noEmit",
"lint": "eslint --color --ext .ts src/", "lint": "eslint --color --ext .ts src/",
@ -43,8 +43,22 @@
"assert": "^1.4.1" "assert": "^1.4.1"
}, },
"devDependencies": { "devDependencies": {
"js-sha256": "^0.9.0", "@babel/cli": "^7.8.4",
"js-yaml": "^3.13.1", "@babel/core": "^7.8.4",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-object-rest-spread": "^7.8.3",
"@babel/plugin-syntax-bigint": "^7.8.3",
"@babel/preset-env": "^7.8.4",
"@babel/preset-typescript": "^7.8.3",
"@babel/register": "^7.8.3",
"@chainsafe/as-sha256": "^0.2.0",
"@types/chai": "^4.2.9",
"@types/mocha": "^7.0.1",
"@typescript-eslint/eslint-plugin": "^2.20.0",
"@typescript-eslint/parser": "^2.20.0",
"chai": "^4.2.0",
"eslint": "^6.8.0",
"eslint-plugin-import": "^2.20.1",
"karma": "^4.4.1", "karma": "^4.4.1",
"karma-chai": "^0.1.0", "karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.1.0", "karma-chrome-launcher": "^3.1.0",
@ -52,7 +66,11 @@
"karma-mocha": "^1.3.0", "karma-mocha": "^1.3.0",
"karma-spec-reporter": "^0.0.32", "karma-spec-reporter": "^0.0.32",
"karma-webpack": "^4.0.2", "karma-webpack": "^4.0.2",
"mocha": "^7.0.1",
"nyc": "^15.0.0",
"ts-loader": "^6.2.1", "ts-loader": "^6.2.1",
"ts-node": "^8.6.2",
"typescript": "^3.7.5",
"webpack": "^4.30.0", "webpack": "^4.30.0",
"webpack-cli": "^3.3.2" "webpack-cli": "^3.3.2"
} }

View File

@ -1,8 +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 "js-sha256"; import SHA256 from "@chainsafe/as-sha256";
import {expect} from "chai"; import {expect} from "chai";
import {destroy} from "../../src/context"; import {destroy} from "../../src/context";
import {padLeft} from "../../lib/helpers/utils"; import {padLeft} from "../../src/helpers/utils";
describe("test bls", function () { describe("test bls", function () {
@ -23,7 +23,7 @@ describe("test bls", function () {
describe("verify", function() { describe("verify", function() {
it("should verify signature", () => { it("should verify signature", () => {
const keypair = Keypair.generate(); const keypair = Keypair.generate();
const messageHash = Buffer.from(sha256.arrayBuffer("Test")); const messageHash = Buffer.from(SHA256.digest(Buffer.from("Test")));
const domain = Buffer.alloc(8, 1); const domain = Buffer.alloc(8, 1);
const signature = keypair.privateKey.signMessage( const signature = keypair.privateKey.signMessage(
messageHash, messageHash,
@ -41,7 +41,7 @@ describe("test bls", function () {
it("should not modify original pubkey when verifying", () => { it("should not modify original pubkey when verifying", () => {
const keypair = Keypair.generate(); const keypair = Keypair.generate();
const messageHash = Buffer.from(sha256.arrayBuffer("Test")); const messageHash = Buffer.from(SHA256.digest(Buffer.from("Test")));
const domain = Buffer.alloc(8, 1); const domain = Buffer.alloc(8, 1);
const signature = keypair.privateKey.signMessage( const signature = keypair.privateKey.signMessage(
messageHash, messageHash,
@ -60,7 +60,7 @@ describe("test bls", function () {
it("should fail verify empty signature", () => { it("should fail verify empty signature", () => {
const keypair = Keypair.generate(); const keypair = Keypair.generate();
const messageHash2 = Buffer.from(sha256.arrayBuffer("Test message2")); const messageHash2 = Buffer.from(SHA256.digest(Buffer.from("Test message2")));
const domain = Buffer.from("01", "hex"); const domain = Buffer.from("01", "hex");
const signature = Buffer.alloc(96); const signature = Buffer.alloc(96);
const result = verify( const result = verify(
@ -74,8 +74,8 @@ describe("test bls", function () {
it("should fail verify signature of different message", () => { it("should fail verify signature of different message", () => {
const keypair = Keypair.generate(); const keypair = Keypair.generate();
const messageHash = Buffer.from(sha256.arrayBuffer("Test message")); const messageHash = Buffer.from(SHA256.digest(Buffer.from("Test message")));
const messageHash2 = Buffer.from(sha256.arrayBuffer("Test message2")); const messageHash2 = Buffer.from(SHA256.digest(Buffer.from("Test message2")));
const domain = padLeft(Buffer.from("01", "hex"), 8); const domain = padLeft(Buffer.from("01", "hex"), 8);
const signature = keypair.privateKey.signMessage( const signature = keypair.privateKey.signMessage(
messageHash, messageHash,
@ -92,7 +92,7 @@ describe("test bls", function () {
it("should fail verify signature of different domain", () => { it("should fail verify signature of different domain", () => {
const keypair = Keypair.generate(); const keypair = Keypair.generate();
const messageHash = Buffer.from(sha256.arrayBuffer("Test message")); const messageHash = Buffer.from(SHA256.digest(Buffer.from("Test message")));
const domain = padLeft(Buffer.from("01", "hex"), 8); const domain = padLeft(Buffer.from("01", "hex"), 8);
const domain2 = padLeft(Buffer.from("02", "hex"), 8); const domain2 = padLeft(Buffer.from("02", "hex"), 8);
const signature = keypair.privateKey.signMessage( const signature = keypair.privateKey.signMessage(
@ -111,7 +111,7 @@ describe("test bls", function () {
it("should fail verify signature signed by different key", () => { it("should fail verify signature signed by different key", () => {
const keypair = Keypair.generate(); const keypair = Keypair.generate();
const keypair2 = Keypair.generate(); const keypair2 = Keypair.generate();
const messageHash = Buffer.from(sha256.arrayBuffer("Test message")); const messageHash = Buffer.from(SHA256.digest(Buffer.from("Test message")));
const domain = Buffer.from("01", "hex"); const domain = Buffer.from("01", "hex");
const signature = keypair.privateKey.signMessage( const signature = keypair.privateKey.signMessage(
messageHash, messageHash,
@ -140,8 +140,8 @@ describe("test bls", function () {
const keypair3 = Keypair.generate(); const keypair3 = Keypair.generate();
const keypair4 = Keypair.generate(); const keypair4 = Keypair.generate();
const message1 = Buffer.from(sha256.arrayBuffer("Test1")); const message1 = Buffer.from(SHA256.digest(Buffer.from("Test1")));
const message2 = Buffer.from(sha256.arrayBuffer("Test2")); const message2 = Buffer.from(SHA256.digest(Buffer.from("Test2")));
const signature1 = keypair1.privateKey.signMessage(message1, domain); const signature1 = keypair1.privateKey.signMessage(message1, domain);
const signature2 = keypair2.privateKey.signMessage(message1, domain); const signature2 = keypair2.privateKey.signMessage(message1, domain);
@ -186,7 +186,7 @@ describe("test bls", function () {
const keypair3 = Keypair.generate(); const keypair3 = Keypair.generate();
const keypair4 = Keypair.generate(); const keypair4 = Keypair.generate();
const message = Buffer.from(sha256.arrayBuffer("Test1")); const message = Buffer.from(SHA256.digest(Buffer.from("Test1")));
const signature1 = keypair1.privateKey.signMessage(message, domain); const signature1 = keypair1.privateKey.signMessage(message, domain);
const signature2 = keypair2.privateKey.signMessage(message, domain); const signature2 = keypair2.privateKey.signMessage(message, domain);
@ -225,8 +225,8 @@ describe("test bls", function () {
const keypair3 = Keypair.generate(); const keypair3 = Keypair.generate();
const keypair4 = Keypair.generate(); const keypair4 = Keypair.generate();
const message1 = Buffer.from(sha256.arrayBuffer("Test1")); const message1 = Buffer.from(SHA256.digest(Buffer.from("Test1")));
const message2 = Buffer.from(sha256.arrayBuffer("Test2")); const message2 = Buffer.from(SHA256.digest(Buffer.from("Test2")));
const signature1 = keypair1.privateKey.signMessage(message1, domain); const signature1 = keypair1.privateKey.signMessage(message1, domain);
const signature2 = keypair2.privateKey.signMessage(message1, domain); const signature2 = keypair2.privateKey.signMessage(message1, domain);
@ -269,8 +269,8 @@ describe("test bls", function () {
const keypair3 = Keypair.generate(); const keypair3 = Keypair.generate();
const keypair4 = Keypair.generate(); const keypair4 = Keypair.generate();
const message1 = Buffer.from(sha256.arrayBuffer("Test1")); const message1 = Buffer.from(SHA256.digest(Buffer.from("Test1")));
const message2 = Buffer.from(sha256.arrayBuffer("Test2")); const message2 = Buffer.from(SHA256.digest(Buffer.from("Test2")));
const signature1 = keypair1.privateKey.signMessage(message1, domain); const signature1 = keypair1.privateKey.signMessage(message1, domain);
const signature2 = keypair2.privateKey.signMessage(message1, domain); const signature2 = keypair2.privateKey.signMessage(message1, domain);
@ -310,8 +310,8 @@ describe("test bls", function () {
const keypair3 = Keypair.generate(); const keypair3 = Keypair.generate();
const keypair4 = Keypair.generate(); const keypair4 = Keypair.generate();
const message1 = Buffer.from(sha256.arrayBuffer("Test1")); const message1 = Buffer.from(SHA256.digest(Buffer.from("Test1")));
const message2 = Buffer.from(sha256.arrayBuffer("Test2")); const message2 = Buffer.from(SHA256.digest(Buffer.from("Test2")));
const signature1 = keypair1.privateKey.signMessage(message1, domain); const signature1 = keypair1.privateKey.signMessage(message1, domain);
const signature2 = keypair2.privateKey.signMessage(message1, domain); const signature2 = keypair2.privateKey.signMessage(message1, domain);
@ -348,8 +348,8 @@ describe("test bls", function () {
const signature = Buffer.alloc(96); const signature = Buffer.alloc(96);
const message1 = Buffer.from(sha256.arrayBuffer("Test1")); const message1 = Buffer.from(SHA256.digest(Buffer.from("Test1")));
const message2 = Buffer.from(sha256.arrayBuffer("Test2")); const message2 = Buffer.from(SHA256.digest(Buffer.from("Test2")));
const result = bls.verifyMultiple( const result = bls.verifyMultiple(
[], [],

View File

@ -1,10 +0,0 @@
{
"extends": "../../tsconfig",
"include": ["src"],
"compilerOptions": {
"typeRoots": [
"src/@types",
"../../node_modules/@types"
]
}
}

View File

@ -1,10 +1,15 @@
{ {
"extends": "../../tsconfig", "include": ["src"],
"include": ["src", "test"],
"compilerOptions": { "compilerOptions": {
"typeRoots": [ "target": "esnext",
"src/@types", "module": "commonjs",
"../../node_modules/@types" "pretty": true,
] "lib": [
"esnext.bigint"
],
"declaration": true,
"strict": true,
"strictNullChecks": false,
"esModuleInterop": true
} }
} }

6322
yarn.lock Normal file

File diff suppressed because it is too large Load Diff