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

docs(sdk): React native passkeys tutorial #663

Open
wants to merge 20 commits into
base: development
Choose a base branch
from

Conversation

yagopv
Copy link
Member

@yagopv yagopv commented Dec 18, 2024

Context

This PR adds a new tutorial to the advanced passkeys guides, teaching Safe developers how to work with React Native and Safe contracts, as well as how to add passkeys signers.

As a companion to this tutorial, we are introducing two new repositories:

@yagopv yagopv requested a review from germartinez December 18, 2024 15:01
Copy link

github-actions bot commented Dec 18, 2024

Branch preview

✅ Deployed successfully in branch deployment:

https://react_native_passkeys--docs.review.5afe.dev

Copy link

github-actions bot commented Dec 18, 2024

Overall readability score: 30.91 (🟢 +0.11)

File Readability
react-native.mdx 63.17 (-)
View detailed metrics

🟢 - Shows an increase in readability
🔴 - Shows a decrease in readability

File Readability FRE GF ARI CLI DCRS
react-native.mdx 63.17 47.38 9.95 10.6 11.19 7.19
  - - - - - -

Averages:

  Readability FRE GF ARI CLI DCRS
Average 30.91 26.92 13.63 17.74 15.81 8.96
  🟢 +0.11 🟢 +0.07 🟢 +0.01 🟢 +0.03 🟢 +0.02 🟢 +0.01
View metric targets
Metric Range Ideal score
Flesch Reading Ease 100 (very easy read) to 0 (extremely difficult read) 60
Gunning Fog 6 (very easy read) to 17 (extremely difficult read) 8 or less
Auto. Read. Index 6 (very easy read) to 14 (extremely difficult read) 8 or less
Coleman Liau Index 6 (very easy read) to 17 (extremely difficult read) 8 or less
Dale-Chall Readability 4.9 (very easy read) to 9.9 (extremely difficult read) 6.9 or less

@yagopv yagopv changed the title React native passkeys tutorial docs(sdk): React native passkeys tutorial Dec 18, 2024
@yagopv yagopv linked an issue Dec 18, 2024 that may be closed by this pull request
@yagopv yagopv requested a review from louis-md December 20, 2024 12:35
Copy link
Collaborator

@louis-md louis-md left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strong work! 💪 A few small remarks to help the user get to the end of the tutorial

pages/advanced/passkeys/tutorials/react-native.mdx Outdated Show resolved Hide resolved
pages/advanced/passkeys/tutorials/react-native.mdx Outdated Show resolved Hide resolved
pages/advanced/passkeys/tutorials/react-native.mdx Outdated Show resolved Hide resolved
pages/advanced/passkeys/tutorials/react-native.mdx Outdated Show resolved Hide resolved
pages/advanced/passkeys/tutorials/react-native.mdx Outdated Show resolved Hide resolved
Copy link
Collaborator

@valle-xyz valle-xyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, this is a great tutorial and a great use case. It was "relatively" easy to follow along, given the complexity of developing and running a mobile app.

However, the last step needs rework. It is important to handhold the developer, and to distuingish between iOS and Android (for example with Tabs). So we really need to be cristal clear and provide good guidance (better guidance than Apple and Google). I was unfortunately not able to add a passkey to the Safe on an Android Emulator. The Safe got deployed, though.

Additional to that, I would like to see some explanatory comments in the code, to guide the developer on what to look out for (as I mentioned in a comment).

When this is added, we need to retest it on Android and on iOS.

Run the following command to add the project dependencies:

```bash
npm install @safe-global/protocol-kit react-native-passkeys react-native-base64 @react-native-async-storage/async-storage react-native-prompt-android expo-build-properties
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to change directory first, which should be added even if it is self-explanatory.

Create a file named `.env` in the root of your project and add the following keys:

```bash
# Add the Safe account owners.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment that the developer should add one (or more) public addresses.

- [**Android Studio Emulator**](https://docs.expo.dev/get-started/set-up-your-environment/?platform=android&device=simulated&mode=development-build)
- [**iOS Simulator**](https://docs.expo.dev/get-started/set-up-your-environment/?platform=ios&device=simulated&mode=development-build)

**⚠️ An important consideration is that the selected Android emulator must be compatible with Google Play Services to store the passkeys in the Android keystore. When [creating the emulator](https://docs.expo.dev/get-started/set-up-your-environment/?platform=android&device=simulated&mode=development-build#set-up-an-emulator) using Android Studio Device Manager, ensure that you include one with Play Store services.**
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure, but what do you think? As most new Android Devices have this, I think a sentence somewhere in the text above would be enough. Like "Make sure the device has access to the Play Store, as this is required for passkeys". By this, we could be a little bit more cautious with warnings.

# The private key of the Safe account owner that will be used to deploy the Safe or execute transactions. Should have some test Sepolia ETH.
EXPO_PUBLIC_SAFE_SIGNER_PK=add_your_private_key_here
# Sepolia RPC URL you want to use
EXPO_PUBLIC_RPC_URL=https://...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add a free one like https://eth-sepolia.public.blastapi.io or so.

EXPO_PUBLIC_RPC_URL=https://...
```

Remember to add the .env file to your `.gitignore` file to avoid committing sensitive information.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is automatically done by expo when creating a project. From my side this could be removed, but sure, it's always good to remind the developers about security.

After completing all these configurations 🙃, you can finally run the local development build of the app on the emulators (Emulators should be running) by using the following commands:

```bash
npx expo run:android
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Android, this command would not work because I don't have the Java runtime installed. The command npx expo start worked. I had to manually copy the address, which could be documented.


Add the following code to the `storage.ts` file:

```tsx
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In these files, add a little bit more explanatory comments. They should introduce concepts, instead of documenting code. As ELI5 as possible. :)


## 7. Setup and host `AASA` and `assetslinks.json` files

To use passkeys in the app, you need to complete some additional setup in the Android and iOS projects. The steps are outlined in the `README.md` file of the [react-native-passkeys](https://github.com/peterferguson/react-native-passkeys) repository. Please follow the instructions for each platform you want to test. Basically you need to:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These steps should be outlined and explained in this tutorials. You can use tabs to differentiate between iOS and Android.

npm start
```

Once you have it running, you need a public domain secured with SSL to test the passkeys (`localhost` is not valid). You can use a service like [ngrok](https://download.ngrok.com/mac-os) to create a tunnel to your local server.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow ok, this is a requirement that we should list at the beginning :D This whole step is a big one and has too little space for how much work this actually takes.


```bash
git clone https://github.com/5afe/aasa-server.git
npm install
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should change directory before.

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

Successfully merging this pull request may close these issues.

[React Native] Create guide in docs
3 participants