-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BN.isBN() breaks code when minified #133
Comments
Actually elliptic depends on the fact that the BN constructor allows the passthrough of BN instances. Removing that (by removing the shortcut in the constructor) the majority of tests fail in elliptic. |
have this issue too |
@axic @adrai presumably you're using UglifyJS2? If so, take a look at the |
@jprichardson I'm using minify (which could be using uglify in the back, don't know). I not entirely sure that is the right way to go. Your solution must be mentioned on the pages of all dependencies to avoid possible issues. That might be too much required. |
so should we revert #109? |
I would say just revert to the original proposal of #109, e.g. remove the |
This is causing issues for me as well at the moment - if this doesn't get fixed in BN.js itself I might have to find a way to exclude BN.js from minification.... |
@bergr01 does |
It seems to work for me with latest bn.js, thanks. |
@jprichardson Didn't seem to help, still getting 'fromRed only works with numbers in reduction context' in minified build of bn.js when running my application in Safari 9.1.1. @indutny Fedor any chance of looking into this some more? @axic how did you proceed in your case? |
How do you feel about: diff --git a/lib/bn.js b/lib/bn.js
index cb1d597..0326dd8 100644
--- a/lib/bn.js
+++ b/lib/bn.js
@@ -55,8 +55,11 @@
}
BN.isBN = function isBN (num) {
+ if (num instanceof BN)
+ return true;
+
return num !== null && typeof num === 'object' &&
- num.constructor.name === 'BN' && Array.isArray(num.words);
+ num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
};
BN.max = function max (left, right) { ? This should fix it. |
Sorry for not responding sooner @indutny , Will try out the latest version and see how I go! |
In the PR #109 it was suggested to include
n.constructor.name === 'BN'
in theisBN()
check. Unfortunately this breaks behaviour with minified code.The following sample
elliptic
code runs properly browserified, but fails when minified:The log output is:
The
isBN()
section in the BN constructor should be there to have a quick path, but should we assume the other code path should handle a BN input properly (by toString() and parsing that)?Had no time to fully track down everything. Perhaps this is more of a bug in
elliptic
where it assumes passing through BN objects will keep the reduction context (which it does ifisBN()
deems it to be an instance, otherwise the reduction context is lost).The text was updated successfully, but these errors were encountered: