Remove crypto from common helpers

This commit is contained in:
dapplion 2020-11-25 15:06:05 +00:00
parent 530e86d98f
commit 847ec46ac9
3 changed files with 4 additions and 9 deletions

View File

@ -1,5 +1,6 @@
import crypto from "crypto";
import * as blst from "@chainsafe/blst"; import * as blst from "@chainsafe/blst";
import {bytesToHex, getRandomBytes, hexToBytes} from "../helpers/utils"; import {bytesToHex, hexToBytes} from "../helpers/utils";
import {IPrivateKey} from "../interface"; import {IPrivateKey} from "../interface";
import {PublicKey} from "./publicKey"; import {PublicKey} from "./publicKey";
import {Signature} from "./signature"; import {Signature} from "./signature";
@ -21,7 +22,7 @@ export class PrivateKey implements IPrivateKey {
} }
static fromKeygen(entropy?: Uint8Array): PrivateKey { static fromKeygen(entropy?: Uint8Array): PrivateKey {
const sk = blst.SecretKey.fromKeygen(entropy || getRandomBytes(32)); const sk = blst.SecretKey.fromKeygen(entropy || crypto.randomBytes(32));
return new PrivateKey(sk); return new PrivateKey(sk);
} }

View File

@ -1,4 +1,4 @@
import assert from "assert"; import {assert} from "./helpers";
import {IBls} from "./interface"; import {IBls} from "./interface";
// Returned type is enforced at each implementation's index // Returned type is enforced at each implementation's index

View File

@ -1,5 +1,3 @@
import crypto from "crypto";
export function assert(condition: unknown, message = "Assertion failed"): asserts condition { export function assert(condition: unknown, message = "Assertion failed"): asserts condition {
if (!condition) { if (!condition) {
throw new Error(message); throw new Error(message);
@ -14,10 +12,6 @@ export function bytesToHex(bytes: Uint8Array): string {
return "0x" + Buffer.from(bytes).toString("hex"); return "0x" + Buffer.from(bytes).toString("hex");
} }
export function getRandomBytes(size: number): Uint8Array {
return Uint8Array.from(crypto.randomBytes(size));
}
export function isEqualBytes(a: Buffer | Uint8Array, b: Buffer | Uint8Array): boolean { export function isEqualBytes(a: Buffer | Uint8Array, b: Buffer | Uint8Array): boolean {
return Buffer.from(a).equals(Buffer.from(b)); return Buffer.from(a).equals(Buffer.from(b));
} }