Use isEqualBytes helper
This commit is contained in:
parent
fa12879651
commit
1e9f778846
|
@ -26,6 +26,10 @@ export function getRandomBytes(size: number): Uint8Array {
|
|||
return Uint8Array.from(crypto.randomBytes(size));
|
||||
}
|
||||
|
||||
export function isEqualBytes(a: Buffer | Uint8Array, b: Buffer | Uint8Array): boolean {
|
||||
return Buffer.from(a).equals(Buffer.from(b));
|
||||
}
|
||||
|
||||
export function toBuffer(input: Uint8Array): Buffer {
|
||||
return Buffer.from(input.buffer, input.byteOffset, input.length);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import {PublicKeyType} from "@chainsafe/eth2-bls-wasm";
|
|||
import {getContext} from "./context";
|
||||
import {EMPTY_PUBLIC_KEY} from "../constants";
|
||||
import {Signature} from "./signature";
|
||||
import {bytesToHex, hexToBytes} from "../helpers/utils";
|
||||
import {bytesToHex, hexToBytes, isEqualBytes} from "../helpers/utils";
|
||||
|
||||
export class PublicKey {
|
||||
readonly value: PublicKeyType;
|
||||
|
@ -14,7 +14,7 @@ export class PublicKey {
|
|||
static fromBytes(bytes: Uint8Array): PublicKey {
|
||||
const context = getContext();
|
||||
const publicKey = new context.PublicKey();
|
||||
if (!EMPTY_PUBLIC_KEY.equals(bytes)) {
|
||||
if (!isEqualBytes(EMPTY_PUBLIC_KEY, bytes)) {
|
||||
publicKey.deserialize(bytes);
|
||||
}
|
||||
return new PublicKey(publicKey);
|
||||
|
|
|
@ -3,7 +3,7 @@ import {SIGNATURE_LENGTH, EMPTY_SIGNATURE} from "../constants";
|
|||
import {SignatureType} from "@chainsafe/eth2-bls-wasm";
|
||||
import {getContext} from "./context";
|
||||
import {PublicKey} from "./publicKey";
|
||||
import {bytesToHex, hexToBytes} from "../helpers/utils";
|
||||
import {bytesToHex, hexToBytes, isEqualBytes} from "../helpers/utils";
|
||||
|
||||
export class Signature {
|
||||
readonly value: SignatureType;
|
||||
|
@ -17,7 +17,7 @@ export class Signature {
|
|||
assert(bytes.length === SIGNATURE_LENGTH, `Signature must have ${SIGNATURE_LENGTH} bytes`);
|
||||
const context = getContext();
|
||||
const signature = new context.Signature();
|
||||
if (!EMPTY_SIGNATURE.equals(bytes)) {
|
||||
if (!isEqualBytes(EMPTY_SIGNATURE, bytes)) {
|
||||
signature.deserialize(bytes);
|
||||
}
|
||||
return new Signature(signature);
|
||||
|
|
Reference in New Issue