diff --git a/CHANGELOG.md b/CHANGELOG.md index ee89aa1..7e91d0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [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) +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) diff --git a/README.md b/README.md index a1c5b82..d27379c 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,19 @@ [![Build Status](https://travis-ci.org/ChainSafe/lodestar.svg?branch=master)](https://travis-ci.org/ChainSafe/lodestar) [![codecov](https://codecov.io/gh/ChainSafe/lodestar/branch/master/graph/badge.svg)](https://codecov.io/gh/ChainSafe/lodestar) -![ETH2.0_Spec_Version 0.11.1](https://img.shields.io/badge/ETH2.0_Spec_Version-0.11.1-2e86c1.svg) +![ETH2.0_Spec_Version 0.12.0](https://img.shields.io/badge/ETH2.0_Spec_Version-0.12.0-2e86c1.svg) This is a Javascript library that implements BLS (Boneh-Lynn-Shacham) signatures and supports signature aggregation. ->[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) +| Version | Bls spec version | +|----------|:-------------:| +| 0.3.x | initial version | +| 1.x.x | draft #6 | +| 2.x.x | draft #7 | -##### Notice: *0.3.x* branch and releases follows old [eth2 bls specitification](https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/bls_signature.md) +>[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) ## Usage - `yarn add @chainsafe/bls` diff --git a/package.json b/package.json index 23b90ee..17d8796 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@chainsafe/bls", - "version": "1.0.0", + "version": "2.0.0", "description": "Implementation of bls signature verification for ethereum 2.0", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -40,7 +40,7 @@ }, "dependencies": { "@chainsafe/bls-keygen": "^0.0.2", - "@chainsafe/eth2-bls-wasm": "^0.4.0", + "@chainsafe/eth2-bls-wasm": "^0.5.0", "assert": "^1.4.1" }, "devDependencies": { @@ -74,9 +74,7 @@ "ts-node": "^8.6.2", "typescript": "^3.7.5", "webpack": "^4.30.0", - "webpack-cli": "^3.3.2" - }, - "optionalDependencies": { - "@chainsafe/eth2-spec-tests": "^0.11.1-fix" + "webpack-cli": "^3.3.2", + "@chainsafe/eth2-spec-tests": "0.12.0" } } diff --git a/src/index.ts b/src/index.ts index 9ce9534..0e5f485 100644 --- a/src/index.ts +++ b/src/index.ts @@ -47,7 +47,7 @@ export function sign(secretKey: Uint8Array, messageHash: Uint8Array): Buffer { * @param signatures */ export function aggregateSignatures(signatures: Uint8Array[]): Buffer { - assert(signatures, "signatures is null or undefined"); + assert(signatures && signatures.length > 0, "signatures is null or undefined or empty array"); return Signature.aggregate( signatures.map((signature): Signature => { return Signature.fromCompressedBytes(signature); diff --git a/test/spec/aggregate_sigs.test.ts b/test/spec/aggregate_sigs.test.ts index 3d9191e..139522f 100644 --- a/test/spec/aggregate_sigs.test.ts +++ b/test/spec/aggregate_sigs.test.ts @@ -20,10 +20,17 @@ describeDirectorySpecTest( "../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/aggregate/small" ), (testCase => { - const result = bls.aggregateSignatures(testCase.data.input.map(pubKey => { - return Buffer.from(pubKey.replace("0x", ""), "hex"); - })); - return `0x${result.toString("hex")}`; + try { + 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") { + return null; + } + throw e; + } }), { inputTypes: { diff --git a/test/spec/aggregate_sigs_verify.test.ts b/test/spec/aggregate_sigs_verify.test.ts index c6d2dd8..4f8c122 100644 --- a/test/spec/aggregate_sigs_verify.test.ts +++ b/test/spec/aggregate_sigs_verify.test.ts @@ -5,10 +5,8 @@ import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-tes interface AggregateSigsVerifyTestCase { data: { input: { - pairs: [{ - pubkey: string; - message: string; - }]; + pubkeys: string[]; + messages: string[]; signature: string; }; output: boolean; @@ -30,11 +28,11 @@ describeDirectorySpecTest( "../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/aggregate_verify/small" ), (testCase => { - const pubkeys = testCase.data.input.pairs.map(pair => { - return Buffer.from(pair.pubkey.replace("0x", ""), "hex"); + const pubkeys = testCase.data.input.pubkeys.map(pubkey => { + return Buffer.from(pubkey.replace("0x", ""), "hex"); }); - const messages = testCase.data.input.pairs.map(pair => { - return Buffer.from(pair.message.replace("0x", ""), "hex"); + const messages = testCase.data.input.messages.map(msg => { + return Buffer.from(msg.replace("0x", ""), "hex"); }); return bls.verifyMultiple( pubkeys, diff --git a/yarn.lock b/yarn.lock index f448d3c..85fd517 100644 --- a/yarn.lock +++ b/yarn.lock @@ -820,17 +820,17 @@ bip39 "^3.0.2" buffer "^5.4.3" -"@chainsafe/eth2-bls-wasm@^0.4.0": - version "0.4.0" - resolved "https://registry.yarnpkg.com/@chainsafe/eth2-bls-wasm/-/eth2-bls-wasm-0.4.0.tgz#94e89e4e53ec6cdcc07178dbfeb0b80215550d2f" - integrity sha512-4BGktOKmUyyYJNCio5Zn1LdxaGWLhPqdUoZXokrfCLW3SKhw4E6MlnpAHwPtvnDuGSkmdF/GLhYeyjQYTtovqg== +"@chainsafe/eth2-bls-wasm@^0.5.0": + version "0.5.0" + resolved "https://registry.yarnpkg.com/@chainsafe/eth2-bls-wasm/-/eth2-bls-wasm-0.5.0.tgz#45d0cb8807b569537d1e0099922a9617e0410b3a" + integrity sha512-7aHphmg504W4YTvAEvGscODrr1Fo5Mf9NxB72fuFv2BKUS/0BPgkoxG9tA+KxcFQq1hs/VUeLhq6qVdI5WfNNA== dependencies: buffer "^5.4.3" -"@chainsafe/eth2-spec-tests@^0.11.1-fix": - version "0.11.1-fixed" - resolved "https://registry.yarnpkg.com/@chainsafe/eth2-spec-tests/-/eth2-spec-tests-0.11.1-fixed.tgz#4c873a627740aa43c9dd85fbfcb90a528a7e6467" - integrity sha512-kjxeVrg5DJJXhrbydD+FSNdNj6Z2JIOitRUY7gnXVI9DRDEjAa59tZ9ZqFjx7M0UAOCJ9DLR6JdHAU/0nLLIZQ== +"@chainsafe/eth2-spec-tests@0.12.0": + version "0.12.0" + resolved "https://registry.yarnpkg.com/@chainsafe/eth2-spec-tests/-/eth2-spec-tests-0.12.0.tgz#f95ffe5bc20ddaa4d2240cffe1e417877adc8055" + integrity sha512-EECbmI/1SdjSPUaQOkZqBOA6AfhviS7jlXVmAs3P2biJTeH2p0p31V4fZImR2NXAgGVFAP16sRx2OCwflOq0mw== "@chainsafe/lodestar-params@^0.5.0": version "0.5.0"