From 1cf1c27b944047731a319e14acdadac24429d87c Mon Sep 17 00:00:00 2001 From: Tuyen Date: Sun, 22 Dec 2019 15:46:52 +0700 Subject: [PATCH] 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()),