hicommonwealth / commonwealth

A platform for decentralized communities
https://commonwealth.im
GNU General Public License v3.0
68 stars 44 forks source link

Architecture for the native app using react-native. #9910

Open burtonator opened 1 week ago

burtonator commented 1 week ago

Overview

We need to have a mobile app to help resolve issues with our app on mobile devices.

The main benefits would be:

Design

The first step is to make sure the webserver and everything can work properly together.

Issues

Loading the app via remote URL

In the past I've used an embedded web server to load the application code. However, that project is not 4 years old and I cant' find a modern implementation.

It also DOES NOT support SSL/TLS so we can't go that route.

We would have to load the production URL (common.xyz or commonwealth.im) via https in the webview.

We will have to make the following changes:

Auth

TODO: I think this is going to require the more research. It seems like Metamask runs an embedded browser and then provides window.ethereum. Of we run within our own react-native app we won't have window.ethereum so I do not think any of our crypto APIs would work. Apparently, there IS a way to make it work with the native browser but we're going to have to make 100% certain that this would work. This is probably the trickiest issue we're going to have.

For auth I think we should use a combination of browser auth and redirecting to the mobile app with a token to grant auth inside the mobile app.

We should NOT do the full auth flow inside react-native.

There's also the benefit that the browser has existing credentials so it would prevent them from entering in their password again.

We'd have to exclude auth.commonwealth.im from direct linking so that it loads the browser, then redirects BACK into the app with an auth token.

The auth token would NOT be the JWT token ideally. We should not be exposing this as we are now but should just serve it as an HTTP cookie. We would have to have a mapping from the auth token to the JWT token so that auth doesn't happen on the backend again.

I wold need to think about this more because if the auth token leaks, there's still a security issue because that could be used to get the JWT too. We'd have to write this up in greater detail and also try to figure out if there's an 'official' way to do this that's more secure and documented.

Apple/Google Approval Issues.

Apple generally requires you to have a valid reason to ship a mobile app.

I think our reasoning is that:

I think that's enough to get approved.

The main issue I see is that Apple does not allow you to load remote code. All your code needs to be served from the device and they might view loading our app from the website as bypassing that.

We could do some more research (maybe ask on reddit) to see if we're ok with this strategy.

Tasks towards implementation

Issues

dillchen commented 3 days ago

On auth, it’s not “necessary”. On mobile, users are not show any injected wallet options (I.e uses window object), instead we only show wallet connect. This is standard across other web3 mobile apps.

Wallet connect has their own deep linking protocol and links to other mobile wallets.

I would really not worry about this.

See an app like Drakula for example: https://apps.apple.com/us/app/drakula-watch-videos/id6476138397