From 87a4a962f53f7d1e60c55c314ac5c203703ed428 Mon Sep 17 00:00:00 2001 From: Cayman Date: Thu, 19 Dec 2019 16:17:22 -0600 Subject: [PATCH 1/3] Align monorepo dependencies --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6324907..2e88320 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ }, "dependencies": { "@chainsafe/eth2-bls-wasm": "^0.2.0", - "@chainsafe/eth2.0-types": "^0.1.0", + "@chainsafe/eth2.0-types": "^0.2.0", "assert": "^1.4.1", "bls-wasm": "^0.2.7" }, From 1cf1c27b944047731a319e14acdadac24429d87c Mon Sep 17 00:00:00 2001 From: Tuyen Date: Sun, 22 Dec 2019 15:46:52 +0700 Subject: [PATCH 2/3] Refactor Hash to Root/bytes32 --- src/index.ts | 8 ++++---- src/privateKey.ts | 4 ++-- src/publicKey.ts | 4 ++-- src/signature.ts | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/index.ts b/src/index.ts index a50c78a..d7ad9a0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ import {Keypair} from "./keypair"; import {PrivateKey} from "./privateKey"; import {PublicKey} from "./publicKey"; import {Signature} from "./signature"; -import {BLSPubkey, BLSSecretKey, BLSSignature, Domain, Hash} from "@chainsafe/eth2.0-types"; +import {BLSPubkey, BLSSecretKey, BLSSignature, Domain, bytes32} from "@chainsafe/eth2.0-types"; import {PUBLIC_KEY_LENGTH} from "./constants"; export {Keypair, PrivateKey, PublicKey, Signature}; @@ -31,7 +31,7 @@ export function generatePublicKey(secretKey: BLSSecretKey): BLSPubkey { * @param messageHash * @param domain */ -export function sign(secretKey: BLSSecretKey, messageHash: Hash, domain: Domain): BLSSignature { +export function sign(secretKey: BLSSecretKey, messageHash: bytes32, domain: Domain): BLSSignature { const privateKey = PrivateKey.fromBytes(secretKey); return privateKey.signMessage(messageHash, domain).toBytesCompressed(); } @@ -73,7 +73,7 @@ export function aggregatePubkeys(publicKeys: BLSPubkey[]): BLSPubkey { * @param signature * @param domain */ -export function verify(publicKey: BLSPubkey, messageHash: Hash, signature: BLSSignature, domain: Domain): boolean { +export function verify(publicKey: BLSPubkey, messageHash: bytes32, signature: BLSSignature, domain: Domain): boolean { try { return PublicKey .fromBytes(publicKey) @@ -92,7 +92,7 @@ export function verify(publicKey: BLSPubkey, messageHash: Hash, signature: BLSSi */ export function verifyMultiple( publicKeys: BLSPubkey[], - messageHashes: Hash[], + messageHashes: bytes32[], signature: BLSSignature, domain: Domain ): boolean { diff --git a/src/privateKey.ts b/src/privateKey.ts index 48865e1..7958014 100644 --- a/src/privateKey.ts +++ b/src/privateKey.ts @@ -1,6 +1,6 @@ import {SECRET_KEY_LENGTH} from "./constants"; import assert from "assert"; -import {BLSSecretKey, Domain, Hash} from "@chainsafe/eth2.0-types"; +import {BLSSecretKey, Domain, bytes32} from "@chainsafe/eth2.0-types"; import {SecretKeyType} from "@chainsafe/eth2-bls-wasm"; import {getContext} from "./context"; import {PublicKey} from "./publicKey"; @@ -52,7 +52,7 @@ export class PrivateKey { // return Signature.fromValue(this.value.sign(message)); // } - public signMessage(message: Hash, domain: Domain): Signature { + public signMessage(message: bytes32, domain: Domain): Signature { domain = padLeft(domain, 8); return Signature.fromValue(this.value.signHashWithDomain(Buffer.concat([message, domain]))); } diff --git a/src/publicKey.ts b/src/publicKey.ts index 2be80d4..c74a415 100644 --- a/src/publicKey.ts +++ b/src/publicKey.ts @@ -1,5 +1,5 @@ import {PrivateKey} from "./privateKey"; -import {BLSPubkey, Domain, Hash} from "@chainsafe/eth2.0-types"; +import {BLSPubkey, Domain, bytes32} from "@chainsafe/eth2.0-types"; import {PublicKeyType} from "@chainsafe/eth2-bls-wasm"; import {getContext} from "./context"; import {PUBLIC_KEY_LENGTH} from "./constants"; @@ -49,7 +49,7 @@ export class PublicKey { return agg; } - public verifyMessage(signature: Signature, messageHash: Hash, domain: Domain): boolean { + public verifyMessage(signature: Signature, messageHash: bytes32, domain: Domain): boolean { return this.value.verifyHashWithDomain(signature.getValue(), Buffer.concat([messageHash, domain])); } diff --git a/src/signature.ts b/src/signature.ts index 9e01452..399da02 100644 --- a/src/signature.ts +++ b/src/signature.ts @@ -1,6 +1,6 @@ import assert from "assert"; import {FP_POINT_LENGTH} from "./constants"; -import {BLSSignature, Domain, Hash} from "@chainsafe/eth2.0-types"; +import {BLSSignature, Domain, bytes32} from "@chainsafe/eth2.0-types"; import {SignatureType} from "@chainsafe/eth2-bls-wasm"; import {getContext} from "./context"; import {PublicKey} from "./publicKey"; @@ -43,12 +43,12 @@ export class Signature { return this.value; } - public verify(publicKey: PublicKey, message: Hash, domain: Domain): boolean { + public verify(publicKey: PublicKey, message: bytes32, domain: Domain): boolean { domain = padLeft(domain, 8); return publicKey.verifyMessage(this, message, domain); } - public verifyMultiple(publicKeys: PublicKey[], messages: Hash[], domain: Domain): boolean { + public verifyMultiple(publicKeys: PublicKey[], messages: bytes32[], domain: Domain): boolean { domain = padLeft(domain, 8); return this.value.verifyAggregatedHashWithDomain( publicKeys.map((key) => key.getValue()), From 4579f07882bfa0a57620b58bda4b9e889ccb4c12 Mon Sep 17 00:00:00 2001 From: Cayman Date: Thu, 16 Jan 2020 12:56:14 -0600 Subject: [PATCH 3/3] Remove references to 0.8.x --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cc77012..b46228f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![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.8.3](https://img.shields.io/badge/ETH2.0_Spec_Version-0.8.3-2e86c1.svg) +![ETH2.0_Spec_Version 0.9.2](https://img.shields.io/badge/ETH2.0_Spec_Version-0.8.2-2e86c1.svg) This is a Javascript library that implements BLS (Boneh-Lynn-Shacham) signatures and supports signature aggregation.