iden3 / ffjavascript

Finite Field Library in Javascript
GNU General Public License v3.0
49 stars 56 forks source link

Use ffjavascript with chrome extension #132

Open 0xmad opened 11 months ago

0xmad commented 11 months ago

Hello, we are developing browser extension and have ffjavascript and a dependency in our node modules. We have chrome extension manifest v3 and it's not possible to spawn a web worker inside service worker so we had to fork this repo to fix it https://github.com/CryptKeeperZK/ffjavascript. For now this solution works only for browser and fails for node.

Is it possible to add support for extensions? I can create a PR for this case but first I'd like to hear the feedback or maybe there is some other solution to make it works.

OBrezhniev commented 11 months ago

Hello @0xmad, please check if new release fixes your issue. There were fixes in this part of code. Also there's now new ESM build for browsers.

0xmad commented 11 months ago

@OBrezhniev thanks but our dependencies have v0.2.59 and I'm not sure if ESM will help here. The main issue: it's not possible to spawn workers inside service worker. Here is the solution for our case in our fork https://github.com/iden3/ffjavascript/compare/master...CryptKeeperZK:ffjavascript:master?expand=1#diff-0462ab1425fcb10bd181dc4f7513067635628058d4c1d851666e2b10a64ec2f4R115-R130 but it's not flexible (works only with browser) and we need to fork every package which has ffjavascript dependency.

0xisk commented 11 months ago

Thanks @OBrezhniev for replying back on this. I just wanted to add more details. In developing Crypt-Keeper browser extension in MV3 (https://github.com/CryptKeeperZK/crypt-keeper-extension) We had this error Reference Error: Worker is not defined

Error

And because ffjavascript is a dependency for snarkjs we had to fork and then for all the packages that is using snarkjs:

vmidyllic commented 11 months ago

you can make a workaround for workers without forking as in this example https://github.com/0xPolygonID/extension-demo/pull/14/files