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] crypto package: bcrypto dependency's "lib/node/bn.js" breaks front-end application in Safari and iOS #3423

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

Comments

@deanpress
Copy link
Contributor

The @arkecosystem/crypto package currently breaks front-end applications in Safari and on all browsers in iOS devices.

The reason is that crypto's bcrypto dependency lib/node/bn.js uses literals which isn't supported in some browsers and can't be transpiled in Babel.

bcrypto has three versions of bn.js in its package. The correct version to use for browsers is the only located in lib/js/bn.js instead of the default lib/node/bn.js.

You can select the package you want to use using env vars (where setting NODE_BACKEND=js should allow the package to) but it appears that in many cases the node version is still included in the compiled bundle (I haven't been able to figure out how to get it to build without forking).

This is a known issue with the bcrypto package. See: bcoin-org/bcrypto#32 bcoin-org/bcrypto#14

Possible Solution

Fork bcrypto and apply this PR: bcoin-org/bcrypto#33

This PR solves the issue and lowers the size of the package. It basically replaces lib/node/bn.js with lib/js/bn.js since BigInt works in both browser and node, and saves people the headache of having to figure this out when using the crypto package for a front-end app.

It also saves ~20% of the dependency's build size.

Steps to Reproduce (for bugs)

  1. Include @arkecosystem/crypto : "2.6-next.9" in a browser app.
  2. Include it in a component
  3. Try the app in Safari on macOS.
  4. See console error: "No identifiers allowed directly after numeric literal"
  5. Try transpiling with babel, see warning: SyntaxError: D:\nos\web-wallet-svelte\node_modules\bcrypto\lib\node\bn.js: Identifier directly after number (46:17)

Your Environment

  • Version used: 2.6-next.9
  • Operating Systems and versions: macOS Catalina, iPhone 11, 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] crypto package: bcrypto dependency breaks front-end application in Safari and iOS [2.6] crypto package: bcrypto dependency's "lib/node/bn.js" breaks front-end application in Safari and iOS Jan 26, 2020
@Lemii
Copy link
Contributor

Lemii commented Jan 29, 2020

I'm currently running into the same problem. I'm using the@arkecosystem/crypto package to create regular and custom transactions in a front end web application. As far as I know there currently are no alternatives for this (ark-ts seems abandoned).

@dractw
Copy link

dractw commented Feb 21, 2020

Same issue here.

@stale
Copy link

stale bot commented Mar 22, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale label Mar 22, 2020
@stale stale bot closed this as completed Mar 29, 2020
@ghost
Copy link

ghost commented Mar 29, 2020

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

@dlecan
Copy link

dlecan commented Apr 29, 2020

Hi @deanpress, how does this solve Safari "BigInt" incompatibility?
Thank you

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

4 participants