From 847ec46ac9aac80722f603ce3ae8ece98bd9a633 Mon Sep 17 00:00:00 2001 From: dapplion Date: Wed, 25 Nov 2020 15:06:05 +0000 Subject: [PATCH] Remove crypto from common helpers --- src/blst/privateKey.ts | 5 +++-- src/functional.ts | 2 +- src/helpers/utils.ts | 6 ------ 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/blst/privateKey.ts b/src/blst/privateKey.ts index a421147..c9d7a29 100644 --- a/src/blst/privateKey.ts +++ b/src/blst/privateKey.ts @@ -1,5 +1,6 @@ +import crypto from "crypto"; import * as blst from "@chainsafe/blst"; -import {bytesToHex, getRandomBytes, hexToBytes} from "../helpers/utils"; +import {bytesToHex, hexToBytes} from "../helpers/utils"; import {IPrivateKey} from "../interface"; import {PublicKey} from "./publicKey"; import {Signature} from "./signature"; @@ -21,7 +22,7 @@ export class PrivateKey implements IPrivateKey { } 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); } diff --git a/src/functional.ts b/src/functional.ts index f25e670..ddc84bc 100644 --- a/src/functional.ts +++ b/src/functional.ts @@ -1,4 +1,4 @@ -import assert from "assert"; +import {assert} from "./helpers"; import {IBls} from "./interface"; // Returned type is enforced at each implementation's index diff --git a/src/helpers/utils.ts b/src/helpers/utils.ts index fecda8c..2451c50 100644 --- a/src/helpers/utils.ts +++ b/src/helpers/utils.ts @@ -1,5 +1,3 @@ -import crypto from "crypto"; - export function assert(condition: unknown, message = "Assertion failed"): asserts condition { if (!condition) { throw new Error(message); @@ -14,10 +12,6 @@ export function bytesToHex(bytes: Uint8Array): string { 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 { return Buffer.from(a).equals(Buffer.from(b)); }