remove domain param from every method in bls

This commit is contained in:
Marin Petrunić 2020-02-04 17:17:11 +01:00 committed by Cayman
parent ee3ce5d951
commit c1a6c41dd4
No known key found for this signature in database
GPG Key ID: 54B21AEC3C53E1F5
4 changed files with 14 additions and 38 deletions

View File

@ -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;

View File

@ -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 {

View File

@ -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 {

View File

@ -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
);
}