Skip to content

Commit

Permalink
fix: remove iso-random-stream dependency (libp2p#262)
Browse files Browse the repository at this point in the history
This dependency brings in NodeJS's `Buffer` which then needs to be polyfilled in the browser.

`@noble/*` already brings a utility that switch between Node's and the browser's `randomBytes` interfaces.
  • Loading branch information
D4nte committed Aug 3, 2022
1 parent a5ccfb7 commit c5cb096
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion benchmark/ed25519/compat.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion benchmark/ed25519/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
1 change: 0 additions & 1 deletion benchmark/ed25519/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,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": "^2.0.2",
Expand Down
4 changes: 2 additions & 2 deletions src/random-bytes.ts
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit c5cb096

Please sign in to comment.