From c1a6c41dd458b43800dadd3c7925a33f0b742dec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marin=20Petruni=C4=87?= Date: Tue, 4 Feb 2020 17:17:11 +0100 Subject: [PATCH] remove domain param from every method in bls --- src/index.ts | 30 +++++------------------------- src/privateKey.ts | 6 ++---- src/publicKey.ts | 4 ++-- src/signature.ts | 12 +++++------- 4 files changed, 14 insertions(+), 38 deletions(-) diff --git a/src/index.ts b/src/index.ts index e07080a..422ae8f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -34,17 +34,12 @@ export function generatePublicKey(secretKey: Uint8Array): Buffer { * Signs given message using secret key. * @param secretKey * @param messageHash - * @param domain */ -export function sign(secretKey: Uint8Array, messageHash: Uint8Array, domain: Uint8Array): Buffer { +export function sign(secretKey: Uint8Array, messageHash: Uint8Array): Buffer { assert(secretKey, "secretKey is null or undefined"); assert(messageHash, "messageHash is null or undefined"); - assert(domain, "domain is null or undefined"); const privateKey = PrivateKey.fromBytes(toBuffer(secretKey)); - return privateKey.signMessage( - toBuffer(messageHash), - toBuffer(domain), - ).toBytesCompressed(); + return privateKey.signMessage(toBuffer(messageHash)).toBytesCompressed(); } /** @@ -80,26 +75,15 @@ export function aggregatePubkeys(publicKeys: Uint8Array[]): Buffer { * @param publicKey * @param messageHash * @param signature - * @param domain */ -export function verify( - publicKey: Uint8Array, - messageHash: Uint8Array, - signature: Uint8Array, - domain: Uint8Array -): boolean { +export function verify(publicKey: Uint8Array, messageHash: Uint8Array, signature: Uint8Array): boolean { assert(publicKey, "publicKey is null or undefined"); assert(messageHash, "messageHash is null or undefined"); assert(signature, "signature is null or undefined"); - assert(domain, "domain is null or undefined"); try { return PublicKey - .fromBytes(toBuffer(publicKey)) - .verifyMessage( - Signature.fromCompressedBytes(toBuffer(signature)), - toBuffer(messageHash), - toBuffer(domain) - ); + .fromBytes(publicKey) + .verifyMessage(Signature.fromCompressedBytes(toBuffer(signature)), toBuffer(messageHash)); } catch (e) { return false; } @@ -110,18 +94,15 @@ export function verify( * @param publicKeys * @param messageHashes * @param signature - * @param domain */ export function verifyMultiple( publicKeys: Uint8Array[], messageHashes: Uint8Array[], signature: Uint8Array, - domain: Uint8Array ): boolean { assert(publicKeys, "publicKey is null or undefined"); assert(messageHashes, "messageHash is null or undefined"); assert(signature, "signature is null or undefined"); - assert(domain, "domain is null or undefined"); if(publicKeys.length === 0 || publicKeys.length != messageHashes.length) { return false; @@ -132,7 +113,6 @@ export function verifyMultiple( .verifyMultiple( publicKeys.map((key) => PublicKey.fromBytes(toBuffer(key))), messageHashes.map((m) => toBuffer(m)), - toBuffer(domain), ); } catch (e) { return false; diff --git a/src/privateKey.ts b/src/privateKey.ts index d4e5051..0b4134d 100644 --- a/src/privateKey.ts +++ b/src/privateKey.ts @@ -5,7 +5,6 @@ import {generateRandomSecretKey} from "@chainsafe/bls-keygen"; import {getContext} from "./context"; import {PublicKey} from "./publicKey"; import {Signature} from "./signature"; -import {padLeft} from "./helpers/utils"; export class PrivateKey { @@ -50,9 +49,8 @@ export class PrivateKey { // return Signature.fromValue(this.value.sign(message)); // } - public signMessage(message: Uint8Array, domain: Uint8Array): Signature { - domain = padLeft(domain, 8); - return Signature.fromValue(this.value.signHashWithDomain(Buffer.concat([message, domain]))); + public signMessage(message: Uint8Array): Signature { + return Signature.fromValue(this.value.signHashWithDomain(message)); } public toPublicKey(): PublicKey { diff --git a/src/publicKey.ts b/src/publicKey.ts index c072ac8..e1e740c 100644 --- a/src/publicKey.ts +++ b/src/publicKey.ts @@ -48,8 +48,8 @@ export class PublicKey { return agg; } - public verifyMessage(signature: Signature, messageHash: Uint8Array, domain: Uint8Array): boolean { - return this.value.verifyHashWithDomain(signature.getValue(), Buffer.concat([messageHash, domain])); + public verifyMessage(signature: Signature, messageHash: Uint8Array): boolean { + return this.value.verifyHashWithDomain(signature.getValue(), messageHash); } public toBytesCompressed(): Buffer { diff --git a/src/signature.ts b/src/signature.ts index ef97998..dd9e6e8 100644 --- a/src/signature.ts +++ b/src/signature.ts @@ -3,7 +3,7 @@ import {FP_POINT_LENGTH} from "./constants"; import {SignatureType} from "@chainsafe/eth2-bls-wasm"; import {getContext} from "./context"; import {PublicKey} from "./publicKey"; -import {EMPTY_SIGNATURE, padLeft} from "./helpers/utils"; +import {EMPTY_SIGNATURE} from "./helpers/utils"; export class Signature { @@ -42,16 +42,14 @@ export class Signature { return this.value; } - public verify(publicKey: PublicKey, message: Uint8Array, domain: Uint8Array): boolean { - domain = padLeft(domain, 8); - return publicKey.verifyMessage(this, message, domain); + public verify(publicKey: PublicKey, message: Uint8Array): boolean { + return publicKey.verifyMessage(this, message); } - public verifyMultiple(publicKeys: PublicKey[], messages: Uint8Array[], domain: Uint8Array): boolean { - domain = padLeft(domain, 8); + public verifyMultiple(publicKeys: PublicKey[], messages: Uint8Array[]): boolean { return this.value.verifyAggregatedHashWithDomain( publicKeys.map((key) => key.getValue()), - messages.map((message) => Buffer.concat([message, domain])) + messages ); }