From 4774a231b9a5f7aa69964b260d332ab0714bd2b3 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Wed, 20 Jul 2022 20:35:05 +1000 Subject: [PATCH] chore: remove iso-random-stream dependency This dependency brings in NodeJS's `Buffer` which then needs to be polyfilled in the browser. @noble/secp256k1 already brings a utility that switch between Node's and the browser's `randomBytes` interfaces. --- benchmark/ed25519/compat.cjs | 2 +- benchmark/ed25519/index.cjs | 2 +- benchmark/ed25519/package.json | 1 - package.json | 1 - src/random-bytes.ts | 4 ++-- 5 files changed, 4 insertions(+), 6 deletions(-) diff --git a/benchmark/ed25519/compat.cjs b/benchmark/ed25519/compat.cjs index f8b54a7f..e8e31e4a 100644 --- a/benchmark/ed25519/compat.cjs +++ b/benchmark/ed25519/compat.cjs @@ -16,12 +16,12 @@ const forge = require('node-forge/lib/forge') * function because key generation is deterministic for a given seed. */ -const randomBytes = require('iso-random-stream/src/random') const { concat } = require('uint8arrays/concat') const { fromString } = require('uint8arrays/from-string') const native = require('ed25519') const noble = require('@noble/ed25519') +const { randomBytes } = noble.utils const { subtle } = require('crypto').webcrypto require('node-forge/lib/ed25519') const stable = require('@stablelib/ed25519') diff --git a/benchmark/ed25519/index.cjs b/benchmark/ed25519/index.cjs index 6319da1f..12876016 100644 --- a/benchmark/ed25519/index.cjs +++ b/benchmark/ed25519/index.cjs @@ -2,9 +2,9 @@ // @ts-expect-error types are missing const forge = require('node-forge/lib/forge') const Benchmark = require('benchmark') -const randomBytes = require('iso-random-stream/src/random') const native = require('ed25519') const noble = require('@noble/ed25519') +const { randomBytes } = noble.utils const { subtle } = require('crypto').webcrypto require('node-forge/lib/ed25519') const stable = require('@stablelib/ed25519') diff --git a/benchmark/ed25519/package.json b/benchmark/ed25519/package.json index e3f66766..869564df 100644 --- a/benchmark/ed25519/package.json +++ b/benchmark/ed25519/package.json @@ -13,7 +13,6 @@ "benchmark": "^2.1.4", "ed25519": "^0.0.5", "ed25519-wasm-pro": "^1.1.1", - "iso-random-stream": "^2.0.0", "node-forge": "^1.0.0", "supercop.wasm": "^5.0.1" } diff --git a/package.json b/package.json index ff9e6ea1..85b638c7 100644 --- a/package.json +++ b/package.json @@ -178,7 +178,6 @@ "@noble/ed25519": "^1.6.0", "@noble/secp256k1": "^1.5.4", "err-code": "^3.0.1", - "iso-random-stream": "^2.0.0", "multiformats": "^9.4.5", "node-forge": "^1.1.0", "protons-runtime": "^1.0.4", diff --git a/src/random-bytes.ts b/src/random-bytes.ts index 2dfbc186..d0018262 100644 --- a/src/random-bytes.ts +++ b/src/random-bytes.ts @@ -1,9 +1,9 @@ -import isoRandomBytes from 'iso-random-stream/src/random.js' +import { utils } from "@noble/secp256k1" import errcode from 'err-code' export default function randomBytes (length: number): Uint8Array { if (isNaN(length) || length <= 0) { throw errcode(new Error('random bytes length must be a Number bigger than 0'), 'ERR_INVALID_LENGTH') } - return isoRandomBytes(length) + return utils.randomBytes(length) }