bn.js icon indicating copy to clipboard operation
bn.js copied to clipboard

remove Buffer dependency

Open SilentCicero opened this issue 7 years ago • 12 comments

Would it be possible to remove the Buffer dependency outright. My webpack is including Buffer, but I dont use it anywhere else, I traced it to BN.js.

SilentCicero avatar Apr 12 '17 22:04 SilentCicero

You should be able to exclude Buffer to no ill-affect, the require is wrapped in a try catch and is only done lazily if necessary.

dcousens avatar Apr 12 '17 22:04 dcousens

Just be careful if you have other dependencies (now or in the future) that could break.

On Wed, Apr 12, 2017, 6:25 PM Daniel Cousens [email protected] wrote:

You should be able to exclude Buffer to no ill-affect, the require is wrapped in a try catch and is only done lazily if necessary.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/indutny/bn.js/issues/160#issuecomment-293724829, or mute the thread https://github.com/notifications/unsubscribe-auth/ABE4nyXPvUVB7wF7vVCSeNhT3wYbAjxHks5rvU9ggaJpZM4M8CmK .

calvinmetcalf avatar Apr 13 '17 11:04 calvinmetcalf

@dcousens webpack still registers it as a dependency. It tries to make sense of the dynamics of it. I just think it's bad design to have dynamic requires. I would remove it outright. It doesn't seem needed for the trouble.

SilentCicero avatar Apr 13 '17 21:04 SilentCicero

@SilentCicero except for those of us that use Buffer everywhere in crypto.

dcousens avatar Apr 14 '17 06:04 dcousens

@dcousens well yes, your definitely right there, it is used in a ton of places for crypto (I use it a lot in a ton of places). But my extreme UNIX and module isolation policy has made me an insane person. And I thought I would make a case to have it removed since it plays a very little role in this specific module (as well, many of us are switching to Uin8Arrays =D).

SilentCicero avatar Apr 15 '17 14:04 SilentCicero

UInt8Arrays

You know that is what a Buffer is?

dcousens avatar Apr 15 '17 14:04 dcousens

@dcousens I'm not actually aware of what buffer is using internally, although I know it uses them. But a lot of the work we do for crypto stuff just requires some basic uses of uint8arrays (we are finding we dont need the whole buffer module for things).

Anyway, no worries, just trying to get that dynamic/almost unused buffer dependency removed. I love BN.js, it has been a solid fantastic module for me.

SilentCicero avatar Apr 15 '17 15:04 SilentCicero

@SilentCicero Buffer is quite literally UInt8Array, see here.

The difference is the added methods for serialization and conversion to avoid re-implementations popping up everywhere that almost always lead to bugs. It also makes node compatibility dead simple.

Anyway :+1:

dcousens avatar Apr 15 '17 15:04 dcousens

I think package.json has buffer: false in browser field now. Does this suffice?

indutny avatar Nov 29 '17 20:11 indutny

@indutny actually, that simply disables it out-right for all browserify users... even if buffer is imported elsewhere in your bundle. It removes it from the dependency chain for bn.js so the require fails.

dcousens avatar Nov 29 '17 22:11 dcousens

Oh yikes. Bundling is hard 😭

indutny avatar Nov 30 '17 02:11 indutny

@indutny I am not against using a require('bn.js/buffer') like import to get Buffer in there if it drops the dep in areas where it unnecessary.

Breaking change obviously.

dcousens avatar Jun 06 '18 05:06 dcousens