Update bls
This commit is contained in:
parent
e950c172f4
commit
825726b5cc
|
@ -7,10 +7,10 @@ import {PUBLIC_KEY_LENGTH, SIGNATURE_LENGTH} from "../constants";
|
|||
* @param source
|
||||
* @param length
|
||||
*/
|
||||
export function padLeft(source: Buffer, length: number): Buffer {
|
||||
export function padLeft(source: Uint8Array, length: number): Buffer {
|
||||
assert(source.length <= length, "Given array must be smaller or equal to desired array size");
|
||||
const result = Buffer.alloc(length, 0);
|
||||
source.copy(result, length - source.length);
|
||||
result.set(source, length - source.length);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -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, bytes32} from "@chainsafe/eth2.0-types";
|
||||
import {BLSPubkey, BLSSecretKey, BLSSignature, Bytes32, Domain} from "@chainsafe/eth2.0-types";
|
||||
import {PUBLIC_KEY_LENGTH} from "./constants";
|
||||
import assert from "assert";
|
||||
|
||||
|
@ -33,7 +33,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: Bytes32, domain: Domain): BLSSignature {
|
||||
assert(secretKey, "secretKey is null or undefined");
|
||||
assert(messageHash, "messageHash is null or undefined");
|
||||
assert(domain, "domain is null or undefined");
|
||||
|
@ -80,7 +80,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: Bytes32, signature: BLSSignature, domain: Domain): boolean {
|
||||
assert(publicKey, "publicKey is null or undefined");
|
||||
assert(messageHash, "messageHash is null or undefined");
|
||||
assert(signature, "signature is null or undefined");
|
||||
|
@ -103,7 +103,7 @@ export function verify(publicKey: BLSPubkey, messageHash: bytes32, signature: BL
|
|||
*/
|
||||
export function verifyMultiple(
|
||||
publicKeys: BLSPubkey[],
|
||||
messageHashes: bytes32[],
|
||||
messageHashes: Bytes32[],
|
||||
signature: BLSSignature,
|
||||
domain: Domain
|
||||
): boolean {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {SECRET_KEY_LENGTH} from "./constants";
|
||||
import assert from "assert";
|
||||
import {BLSSecretKey, Domain, bytes32} from "@chainsafe/eth2.0-types";
|
||||
import {BLSSecretKey, Bytes32, Domain} from "@chainsafe/eth2.0-types";
|
||||
import {SecretKeyType} from "@chainsafe/eth2-bls-wasm";
|
||||
import {generateRandomSecretKey} from "@chainsafe/bls-keygen";
|
||||
import {getContext} from "./context";
|
||||
|
@ -51,7 +51,7 @@ export class PrivateKey {
|
|||
// return Signature.fromValue(this.value.sign(message));
|
||||
// }
|
||||
|
||||
public signMessage(message: bytes32, domain: Domain): Signature {
|
||||
public signMessage(message: Bytes32, domain: Domain): Signature {
|
||||
domain = padLeft(domain, 8);
|
||||
return Signature.fromValue(this.value.signHashWithDomain(Buffer.concat([message, domain])));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import {PrivateKey} from "./privateKey";
|
||||
import {BLSPubkey, Domain, bytes32} from "@chainsafe/eth2.0-types";
|
||||
import {BLSPubkey, Bytes32, Domain} from "@chainsafe/eth2.0-types";
|
||||
import {PublicKeyType} from "@chainsafe/eth2-bls-wasm";
|
||||
import {getContext} from "./context";
|
||||
import {PUBLIC_KEY_LENGTH} from "./constants";
|
||||
|
@ -22,7 +22,7 @@ export class PublicKey {
|
|||
public static fromBytes(bytes: BLSPubkey): PublicKey {
|
||||
const context = getContext();
|
||||
const publicKey = new context.PublicKey();
|
||||
if(!bytes.equals(EMPTY_PUBLIC_KEY)) {
|
||||
if(!EMPTY_PUBLIC_KEY.equals(bytes)) {
|
||||
publicKey.deserialize(bytes);
|
||||
}
|
||||
return new PublicKey(
|
||||
|
@ -49,7 +49,7 @@ export class PublicKey {
|
|||
return agg;
|
||||
}
|
||||
|
||||
public verifyMessage(signature: Signature, messageHash: bytes32, domain: Domain): boolean {
|
||||
public verifyMessage(signature: Signature, messageHash: Bytes32, domain: Domain): boolean {
|
||||
return this.value.verifyHashWithDomain(signature.getValue(), Buffer.concat([messageHash, domain]));
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ export class PublicKey {
|
|||
}
|
||||
|
||||
public toHexString(): string {
|
||||
return `0x${this.toBytesCompressed().toString("hex")}`;
|
||||
return `0x${Buffer.from(this.toBytesCompressed()).toString("hex")}`;
|
||||
}
|
||||
|
||||
public getValue(): PublicKeyType {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import assert from "assert";
|
||||
import {FP_POINT_LENGTH} from "./constants";
|
||||
import {BLSSignature, Domain, bytes32} from "@chainsafe/eth2.0-types";
|
||||
import {BLSSignature, Bytes32, Domain} from "@chainsafe/eth2.0-types";
|
||||
import {SignatureType} from "@chainsafe/eth2-bls-wasm";
|
||||
import {getContext} from "./context";
|
||||
import {PublicKey} from "./publicKey";
|
||||
|
@ -21,7 +21,7 @@ export class Signature {
|
|||
);
|
||||
const context = getContext();
|
||||
const signature = new context.Signature();
|
||||
if(!value.equals(EMPTY_SIGNATURE)) {
|
||||
if(!EMPTY_SIGNATURE.equals(value)) {
|
||||
signature.deserialize(value);
|
||||
}
|
||||
return new Signature(signature);
|
||||
|
@ -43,12 +43,12 @@ export class Signature {
|
|||
return this.value;
|
||||
}
|
||||
|
||||
public verify(publicKey: PublicKey, message: bytes32, 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: bytes32[], 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()),
|
||||
|
|
Reference in New Issue