From 6f17cc349e0d9681bf14bd6262fcd33b5c010f02 Mon Sep 17 00:00:00 2001 From: austinabell Date: Tue, 3 Sep 2019 14:17:55 -0400 Subject: [PATCH] replace byte32 type on hashes to Hash --- src/helpers/g2point.ts | 6 +++--- src/index.ts | 8 ++++---- src/privateKey.ts | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/helpers/g2point.ts b/src/helpers/g2point.ts index a41a519..d283721 100644 --- a/src/helpers/g2point.ts +++ b/src/helpers/g2point.ts @@ -1,12 +1,12 @@ import {BIG} from "@chainsafe/milagro-crypto-js/src/big"; import {ECP2} from "@chainsafe/milagro-crypto-js/src/ecp2"; -import { sha256 } from 'js-sha256'; +import {sha256} from 'js-sha256'; import ctx from "../ctx"; import * as random from "secure-random"; import {calculateYFlag, getModulus, padLeft} from "./utils"; import assert from "assert"; import {FP_POINT_LENGTH, G2_HASH_PADDING} from "../constants"; -import {bytes32, bytes48, Domain} from "@chainsafe/eth2.0-types"; +import {bytes48, Domain, Hash} from "@chainsafe/eth2.0-types"; export class G2point { @@ -58,7 +58,7 @@ export class G2point { ]); } - public static hashToG2(message: bytes32, domain: Domain): G2point { + public static hashToG2(message: Hash, domain: Domain): G2point { const padding = Buffer.alloc(G2_HASH_PADDING, 0); const xReBytes = Buffer.concat([ padding, diff --git a/src/index.ts b/src/index.ts index 2888c71..beac54e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ import {PublicKey} from "./publicKey"; import {Signature} from "./signature"; import {ElipticCurvePairing} from "./helpers/ec-pairing"; import ctx from "./ctx"; -import {BLSPubkey, BLSSecretKey, BLSSignature, bytes32, Domain} from "@chainsafe/eth2.0-types"; +import {BLSPubkey, BLSSecretKey, BLSSignature, Domain, Hash} from "@chainsafe/eth2.0-types"; export {Keypair, PrivateKey, PublicKey, Signature}; @@ -32,7 +32,7 @@ export function generatePublicKey(secretKey: BLSSecretKey): BLSPubkey { * @param messageHash * @param domain */ -export function sign(secretKey: BLSSecretKey, messageHash: bytes32, domain: Domain): BLSSignature { +export function sign(secretKey: BLSSecretKey, messageHash: Hash, domain: Domain): BLSSignature { const privateKey = PrivateKey.fromBytes(secretKey); const hash = G2point.hashToG2(messageHash, domain); return privateKey.sign(hash).toBytesCompressed(); @@ -72,7 +72,7 @@ export function aggregatePubkeys(publicKeys: BLSPubkey[]): BLSPubkey { * @param signature * @param domain */ -export function verify(publicKey: BLSPubkey, messageHash: bytes32, signature: BLSSignature, domain: Domain): boolean { +export function verify(publicKey: BLSPubkey, messageHash: Hash, signature: BLSSignature, domain: Domain): boolean { try { const key = PublicKey.fromBytes(publicKey); const sig = Signature.fromCompressedBytes(signature); @@ -93,7 +93,7 @@ export function verify(publicKey: BLSPubkey, messageHash: bytes32, signature: BL * @param signature * @param domain */ -export function verifyMultiple(publicKeys: BLSPubkey[], messageHashes: bytes32[], signature: BLSSignature, domain: Domain): boolean { +export function verifyMultiple(publicKeys: BLSPubkey[], messageHashes: Hash[], signature: BLSSignature, domain: Domain): boolean { if(publicKeys.length === 0 || publicKeys.length != messageHashes.length) { return false; } diff --git a/src/privateKey.ts b/src/privateKey.ts index e525a0c..329fe2d 100644 --- a/src/privateKey.ts +++ b/src/privateKey.ts @@ -5,7 +5,7 @@ import ctx from "./ctx"; import {padLeft} from "./helpers/utils"; import {G2point} from "./helpers/g2point"; import * as random from "secure-random"; -import {BLSSecretKey, bytes32, Domain} from "@chainsafe/eth2.0-types"; +import {BLSSecretKey, Hash, Domain} from "@chainsafe/eth2.0-types"; export class PrivateKey { @@ -23,7 +23,7 @@ export class PrivateKey { return message.mul(this.value); } - public signMessage(message: bytes32, domain: Domain): G2point { + public signMessage(message: Hash, domain: Domain): G2point { return G2point.hashToG2(message, domain).mul(this.value); }