digitalbazaar / forge

A native implementation of TLS in Javascript and tools to write crypto-based and network-heavy webapps
https://digitalbazaar.com/
Other
5.05k stars 779 forks source link

TypeError: i.randomBytes is not a function #1079

Closed vricosti closed 4 months ago

vricosti commented 4 months ago

Hi,

I forked a project called androidtv-remote (my repo is here and the branch is dev/webpack) to be able to use it inside a node or browser environment, so I have added webpack config (umd configuration) and I replaced the use of path, url and crypto. (Actually my real goal is to use it inside a react-native mobile app that's why even if tls is not available I am ignoring the missing require and I will use a react-native-tls fallback, or maybe later on I will use forge also instead of tls). Anyway with all my modifications since I am testing the example on node I thought it would work out of the box...

To replace crypto I am using forge and you can see my modifications here: https://github.com/louis49/androidtv-remote/compare/main...vricosti:dev/webpack?expand=1

when trying to test the example I have the following error:

TypeError: i.randomBytes is not a function
    at t.seedFileSync (/home/vricosti/Dev/androidtv-remote/example/node_modules/androidtv-remote/dist/index.js:1:159283)
    at o (/home/vricosti/Dev/androidtv-remote/example/node_modules/androidtv-remote/dist/index.js:1:156982)
    at t.generateSync (/home/vricosti/Dev/androidtv-remote/example/node_modules/androidtv-remote/dist/index.js:1:159008)
    at t.generate (/home/vricosti/Dev/androidtv-remote/example/node_modules/androidtv-remote/dist/index.js:1:158178)
    at e.getBytesSync (/home/vricosti/Dev/androidtv-remote/example/node_modules/androidtv-remote/dist/index.js:1:162426)
    at Object.nextBytes (/home/vricosti/Dev/androidtv-remote/example/node_modules/androidtv-remote/dist/index.js:1:173765)
    at s.fromNumber (/home/vricosti/Dev/androidtv-remote/example/node_modules/androidtv-remote/dist/index.js:1:83481)
    at new s (/home/vricosti/Dev/androidtv-remote/example/node_modules/androidtv-remote/dist/index.js:1:72775)
    at u.rsa.stepKeyPairGenerationState (/home/vricosti/Dev/androidtv-remote/example/node_modules/androidtv-remote/dist/index.js:1:174377)
    at u.rsa.generateKeyPair (/home/vricosti/Dev/androidtv-remote/example/node_modules/androidtv-remote/dist/index.js:1:177625)

To reproduce:

git clone https://github.com/vricosti/androidtv-remote.git
cd androidtv-remote
git fetch origin
git checkout dev/webpack
yarn install
yarn --cwd example install
yarn build
rm -rf example/node_modules/androidtv-remote/dist/*
cp ./dist/* example/node_modules/androidtv-remote/dist/
cd example/
node example.js