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

Fula-sec react-native incompatibility (ReferenceError: Can't find variable: BigInt) #208

Closed
ghorbani-m opened this issue Jun 7, 2022 · 14 comments
Assignees
Milestone

Comments

@ghorbani-m
Copy link
Collaborator

We have an issue to use the fula-sec package in react-native projects.
The issue is that some fula-sec's dependencies use the BigInt type that react-native does not support.
There is a workaround here but it does not work for me, I guess because we used the Hermes engine.
Hermes team is working on this issue as well, and in the future probably Hermes will support BigInt.

@farhoud
Copy link
Contributor

farhoud commented Jun 7, 2022

@ghorbani-m from my perspective running a cryptographic algorithm on react-native will be near impossible (after you fix this you have to fix the missing secure random generator and the list will go on)

@ruffiano89 how much go-fula-sec is feasible?

@ghorbani-m
Copy link
Collaborator Author

@farhoud I agree, totally we need to move the encryption layer to the gomobile (go-fula) to encrypt files on the fly while streaming the files.
I am thinking that can we add all fula-sec functionalities to the go-fula project and use them in react-native-fula?
The reason is I don't like to add another .aar file to the Fotos app and increase the size of apk.

@farhoud
Copy link
Contributor

farhoud commented Jun 8, 2022

@ghorbani-m I'm totally agree with you.
@ruffiano89 I see you replay to this issue i think on slack can you move it here?

@farhoud
Copy link
Contributor

farhoud commented Jun 8, 2022

@ghorbani-m
did you try this?

@farhoud
Copy link
Contributor

farhoud commented Jun 8, 2022

For random i think you can :

We are heavily depend on did from ceramic network.
And I don't know if Jamshid can rewrite them in go.
So lets try to run DID usage on js. If we fail we can come up with something.

@ghorbani-m
Copy link
Collaborator Author

@ghorbani-m did you try this?

I don't need use BigInt directly in the Fotos, actually, the fula-sec dependencies used BigInt so we can not import fula-sec in a react-native project

@farhoud
Copy link
Contributor

farhoud commented Jun 8, 2022

@ghorbani-m
https://github.com/indutny/elliptic us bn.js you can use this:
https://github.com/margelo/react-native-bignumber#as-a-drop-in-replacement
so fula-sec uses react-native-bignumber instead of using bn.js

@farhoud
Copy link
Contributor

farhoud commented Jun 8, 2022

I check out fula-sec dependencies.

  "dependencies": {
    "@stablelib/x25519": "~1.0.2",
    "ethers": "~5.6.4",
    "did-jwt": "~5.12.4",
    "dids": "3.0.0-alpha.12",
    "key-did-provider-ed25519": "~1.1.0",
    "key-did-resolver": "~1.4.4"
  }

look like they depend on bn.js for bigint. (there may usages that i can not spot.)

@farhoud
Copy link
Contributor

farhoud commented Jun 8, 2022

@ghorbani-m
If you could provide more info like logs and other things i can be more helpful.

@ruffiano89
Copy link
Collaborator

Much appreciate if you send us error log
Pls look at this also.
Fixed Android BigInt Error
facebook/react-native#28492 (comment)

@farhoud
Copy link
Contributor

farhoud commented Jun 9, 2022

This is the log

 ERROR  ReferenceError: Can't find variable: BigInt 
App@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.example.reactnativefula&modulesOnly=false&runModule=true:112234:54
RCTView
View
RCTView
View
AppContainer@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.example.reactnativefula&modulesOnly=false&runModule=true:79315:36
FulaExample(RootComponent)@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.example.reactnativefula&modulesOnly=false&runModule=true:85695:28

And the source of it is :
https://github.com/rvagg/cborg/blob/master/lib/0uint.js

And :

Much appreciate if you send us error log Pls look at this also. Fixed Android BigInt Error facebook/react-native#28492 (comment)

This suggested are hacks and we end up with unstable fotos.

My suggestion for @ghorbani-m and @ruffiano89
don't wast your time on this and start golang fula-sec

@ghorbani-m
Copy link
Collaborator Author

I've worked more on this issue and solved the BigInt issue by rn-nodeify.
After that, I got another issue and the root was using etherjs in react-native which needs some prerequisites for react-native and finally solved that through @ethersproject/shims package.

To get a fast conclusion tried to install etherJs on the Fotos project directly and tried to create a Wallet same as we used in the Fula-sec (ethers.Wallet.createRandom()).

It works and I create a wallet programmatically but there is another issue, creating a wallet in react-native is too slow and for me takes around 30s!

@ghorbani-m
Copy link
Collaborator Author

Finally, I resolved the BigInt issue by rn-nodeify package.
@ruffiano89
Now I am trying to use the new release of fula-sec (0.6.6) but get an error.

My code:

import { FulaDID } from "@functionland/fula-sec"
.
.
.
const fulaDID = new FulaDID();
await fulaDID.create("password", "signiture");

Error message:

[TypeError: Cannot convert undefined value to object]

@ghorbani-m
Copy link
Collaborator Author

Finally, I resolved the BigInt issue by rn-nodeify package. @ruffiano89 Now I am trying to use the new release of fula-sec (0.6.6) but get an error.

My code:

import { FulaDID } from "@functionland/fula-sec"
.
.
.
const fulaDID = new FulaDID();
await fulaDID.create("password", "signiture");

Error message:

[TypeError: Cannot convert undefined value to object]

The reason was crypto.getRandomValues that has been used in the fula-sec dependencies.

Solution

We need to add react-native-get-random-values package to the project and follow the rules.

@gitaaron gitaaron added this to the fula v0.7.0 milestone Jul 22, 2022
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