Skip to content
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

[2.6] Use of native BigInt in BigNumber library breaks support for several browsers #60

Closed
deanpress opened this issue Jan 26, 2020 · 6 comments

Comments

@deanpress
Copy link

Somewhat related to ArkEcosystem/core#3423

Native BigInt (which is used in the toBigNumber() method in the @arkecosystem/utils big-number.ts library) is not yet supported in all popular browsers (e.g. Safari).

Possible Solution

Replace native BigInt with JSBI BigInt in utils: https://github.com/GoogleChromeLabs/jsbi.

The only thing it doesn't support is floats, but from what I observed that isn't supported in the current BigNumber implementation either.

Your Environment

  • Version used: 2.6.0-next.9
  • Browser Version: Safari 13
@ghost
Copy link

ghost commented Jan 26, 2020

Thanks for opening this issue! A maintainer will review this in the next few days and explicitly select labels so you know what's going on.

If no reviewer appears after a week, a reminder will be sent out.

@deanpress deanpress changed the title [2.6] Use of native BigInt in BigNumber library breaks support for Safari [2.6] Use of native BigInt in BigNumber library breaks support for several browsers Jan 26, 2020
@faustbrian
Copy link
Contributor

The lack of browsers is intentional and won't change anytime soon due to the performance impact on core with new transaction types. This package isn't meant to be used in browsers and neither is our crypto package, meaning if either of those work in the browser it's a coincidence but not a feature or supported circumstance.

In the future there might be a stripped down version of the crypto package for browsers but I am not willing to compromise performance for the sake of browser support.

@ghost
Copy link

ghost commented Jan 26, 2020

This issue has been closed. If you wish to re-open it please provide additional information.

@deanpress
Copy link
Author

deanpress commented Jan 26, 2020

@faustbrian What if an app could set an env var to select the preferred library on build e.g. BIGNUM_LIB=jsbi, and using utils by default? This way nothing changes for the node process but it allows JSBI to be used in the case of a browser app.

@deanpress
Copy link
Author

Another possible fix might be to select the lib to use for BigNumber (default or jsbi) by checking typeof BigInt. If BigInt is not supported, it falls back to JSBI.

@faustbrian
Copy link
Contributor

This would still come at the cost of performance because every time you create an instance of the BigNumber class it will need to figure out what to use internally instead of simply doing whatever it is told to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants