replace byte32 type on hashes to Hash
This commit is contained in:
parent
76be9d2507
commit
6f17cc349e
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Reference in New Issue