functionland / fula-archived

Client-server stack for Web3! Turn your Raspberry Pi to a BAS server in minutes and enjoy the freedom of decentralized Web with a superior user experience!
https://fx.land
MIT License
4 stars 0 forks source link

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

Closed ghorbani-m closed 2 years ago

ghorbani-m commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

@ghorbani-m did you try this?

farhoud commented 2 years ago

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 commented 2 years ago

@ghorbani-m did you try this?

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

farhoud commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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

ruffiano89 commented 2 years ago

Much appreciate if you send us error log Pls look at this also. Fixed Android BigInt Error https://github.com/facebook/react-native/issues/28492#issuecomment-897732834

farhoud commented 2 years ago

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 commented 2 years ago

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/shimspackage.

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 commented 2 years ago

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 commented 2 years ago

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.