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

feat(mobile): add integration with gateway backend for notifications feature #4878

Draft
wants to merge 20 commits into
base: dev
Choose a base branch
from

Conversation

Jonathansoufer
Copy link
Contributor

What it solves

Resolves #

How this PR fixes it

How to test it

Screenshots

Checklist

  • I've tested the branch on mobile 📱
  • I've documented how it affects the analytics (if at all) 📊
  • I've written a unit/e2e test for it (if applicable) 🧑‍💻

@Jonathansoufer Jonathansoufer self-assigned this Feb 4, 2025
}

// Step 1: Generate delegate key
const delegateMnemonic = ethers.Wallet.createRandom().mnemonic?.phrase
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need mnemonic here? Why don#t we go for creating a random private key?

const wallet = Wallet.createRandom(provider);
console.log(wallet.privatekey)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I'll avoid the Mnemonic.

Comment on lines 61 to 65
const encryptedDelegateKey = await DeviceCrypto.encrypt(asymmetricKey, delegatedAccount.privateKey, {
biometryTitle: 'Authenticate',
biometrySubTitle: 'Saving delegated key',
biometryDescription: 'Please authenticate yourself',
})
Copy link
Contributor

Choose a reason for hiding this comment

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

we don't need this kind of protection for the delegate key. It is not going to sign transactions and can be exchanged at any point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

aren't we showing and allowing users to revoke these keys? we can store it on redux only then. wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I meant that we don't need biometry protection. Users should be able to remove the keys as in the old app.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed already.

@@ -90,6 +90,7 @@
"react-native-device-info": "^14.0.1",
"react-native-draggable-flatlist": "^4.0.1",
"react-native-gesture-handler": "~2.20.2",
"react-native-get-random-values": "^1.11.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

before we add this package I would actually want to know why is quick-crypto not doing this. Maybe we are calling the polyfills from it too late?

Comment on lines 57 to 61
const signerAccount = ownerPrivateKey ? new Wallet(ownerPrivateKey) : Wallet.createRandom()

if (!signerAccount) {
throw Logger.error(ERROR_MSG, error)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

this could be moved to a getSignerAccount function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

const ownerPrivateKey = await getPrivateKey()

try {
if (!ownerAddress || !activeSafe || !nonce || !fcmToken) {
Copy link
Contributor

Choose a reason for hiding this comment

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

could be moved to a validate function.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that if the try block is structured as:

        validateParameters(...)

        const ownerPrivateKey = await getPrivateKey(...)
        const signerAccount = await createSignerAccount(ownerPrivateKey)
        if (!signerAccount) throw new Error(ERROR_MSG)

        const siweMessage = generateSiweMessage(...)

        // Verify the delegate on the backend and subscribe for notifications.
        await verifyAndSubscribeDelegate(...)

it would make it way easier to read and follow

Copy link
Contributor

Choose a reason for hiding this comment

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

Also what you get is separation of conserns. We abstract everything in small, testable functions. It not only improves readibility, but also makes it easier to unit test.

}
}, [])

const createOnBackEnd = useCallback(
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe something like authenticateAndSubscribeDelate would be more on point?

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.

2 participants