Merge branch 'master' into bls-keygen-private-keys

This commit is contained in:
Gerald Nash 2020-01-16 15:05:39 -05:00 committed by GitHub
commit 042e2f3098
6 changed files with 13 additions and 13 deletions

View File

@ -2,7 +2,7 @@
[![Build Status](https://travis-ci.org/ChainSafe/lodestar.svg?branch=master)](https://travis-ci.org/ChainSafe/lodestar) [![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) [![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. This is a Javascript library that implements BLS (Boneh-Lynn-Shacham) signatures and supports signature aggregation.

View File

@ -40,7 +40,7 @@
"dependencies": { "dependencies": {
"@chainsafe/bls-keygen": "^0.0.2", "@chainsafe/bls-keygen": "^0.0.2",
"@chainsafe/eth2-bls-wasm": "^0.2.0", "@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", "assert": "^1.4.1",
"bls-wasm": "^0.2.7" "bls-wasm": "^0.2.7"
}, },

View File

@ -2,7 +2,7 @@ import {Keypair} from "./keypair";
import {PrivateKey} from "./privateKey"; import {PrivateKey} from "./privateKey";
import {PublicKey} from "./publicKey"; import {PublicKey} from "./publicKey";
import {Signature} from "./signature"; 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"; import {PUBLIC_KEY_LENGTH} from "./constants";
import assert from "assert"; import assert from "assert";
@ -33,7 +33,7 @@ export function generatePublicKey(secretKey: BLSSecretKey): BLSPubkey {
* @param messageHash * @param messageHash
* @param domain * @param domain
*/ */
export function sign(secretKey: BLSSecretKey, messageHash: Hash, domain: Domain): BLSSignature { export function sign(secretKey: BLSSecretKey, messageHash: bytes32, domain: Domain): BLSSignature {
assert(secretKey, "secretKey is null or undefined"); assert(secretKey, "secretKey is null or undefined");
assert(messageHash, "messageHash is null or undefined"); assert(messageHash, "messageHash is null or undefined");
assert(domain, "domain is null or undefined"); assert(domain, "domain is null or undefined");
@ -80,7 +80,7 @@ export function aggregatePubkeys(publicKeys: BLSPubkey[]): BLSPubkey {
* @param signature * @param signature
* @param domain * @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 {
assert(publicKey, "publicKey is null or undefined"); assert(publicKey, "publicKey is null or undefined");
assert(messageHash, "messageHash is null or undefined"); assert(messageHash, "messageHash is null or undefined");
assert(signature, "signature is null or undefined"); assert(signature, "signature is null or undefined");
@ -103,7 +103,7 @@ export function verify(publicKey: BLSPubkey, messageHash: Hash, signature: BLSSi
*/ */
export function verifyMultiple( export function verifyMultiple(
publicKeys: BLSPubkey[], publicKeys: BLSPubkey[],
messageHashes: Hash[], messageHashes: bytes32[],
signature: BLSSignature, signature: BLSSignature,
domain: Domain domain: Domain
): boolean { ): boolean {

View File

@ -1,6 +1,6 @@
import {SECRET_KEY_LENGTH} from "./constants"; import {SECRET_KEY_LENGTH} from "./constants";
import assert from "assert"; 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 {SecretKeyType} from "@chainsafe/eth2-bls-wasm";
import {generateRandomSecretKey} from "@chainsafe/bls-keygen"; import {generateRandomSecretKey} from "@chainsafe/bls-keygen";
import {getContext} from "./context"; import {getContext} from "./context";
@ -51,7 +51,7 @@ export class PrivateKey {
// return Signature.fromValue(this.value.sign(message)); // 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); domain = padLeft(domain, 8);
return Signature.fromValue(this.value.signHashWithDomain(Buffer.concat([message, domain]))); return Signature.fromValue(this.value.signHashWithDomain(Buffer.concat([message, domain])));
} }

View File

@ -1,5 +1,5 @@
import {PrivateKey} from "./privateKey"; 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 {PublicKeyType} from "@chainsafe/eth2-bls-wasm";
import {getContext} from "./context"; import {getContext} from "./context";
import {PUBLIC_KEY_LENGTH} from "./constants"; import {PUBLIC_KEY_LENGTH} from "./constants";
@ -49,7 +49,7 @@ export class PublicKey {
return agg; 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])); return this.value.verifyHashWithDomain(signature.getValue(), Buffer.concat([messageHash, domain]));
} }

View File

@ -1,6 +1,6 @@
import assert from "assert"; import assert from "assert";
import {FP_POINT_LENGTH} from "./constants"; 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 {SignatureType} from "@chainsafe/eth2-bls-wasm";
import {getContext} from "./context"; import {getContext} from "./context";
import {PublicKey} from "./publicKey"; import {PublicKey} from "./publicKey";
@ -43,12 +43,12 @@ export class Signature {
return this.value; 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); domain = padLeft(domain, 8);
return publicKey.verifyMessage(this, message, domain); 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); domain = padLeft(domain, 8);
return this.value.verifyAggregatedHashWithDomain( return this.value.verifyAggregatedHashWithDomain(
publicKeys.map((key) => key.getValue()), publicKeys.map((key) => key.getValue()),