-
Notifications
You must be signed in to change notification settings - Fork 154
Description
Edit: Duplicate of #255
BN throws buffer undefined assertion errors in some browser-like environments, despite having Buffer defined as a global. I'm using bn in an electron app with strict security settings: nodeIntegration: false, contextIsolation: true, enabledRemoteModule: false etc.
With these settings require is disabled in the renderer thread, where bn.js is invoked. Because of this, Buffer needs to be polyfilled as a global.
The following code declares a variable that redeclares the globally defined Buffer type to undefined in the local scope. Then silently fails when it tries to tries to require in the try block.
Lines 51 to 55 in 6ef485d
| var Buffer; | |
| try { | |
| Buffer = require('buffer').Buffer; | |
| } catch (e) { | |
| } |
Not sure on the most appropriate fix, but something like this should work around the issue.
Buffer = window.Buffer || global.Buffer || require('buffer').Buffer;