Register accounts using EVM wallets
In this section, we'll walk you through creating a module for registering user accounts using EVM (Ethereum Virtual Machine) wallets. This functionality can be utilized to enable users to sign in with EVM-compatible wallets like MetaMask and can be extended to include various features such as payments.
Conceptual design
In this example, we will allow users to register an account by simply signing a message using MetaMask. This is done by
using the
open account registration strategy
that is part of the ft
library. The following sequence diagram illustrates the registration flow:
Implementation in Rell
Implementing the registration flow starts with creating a new module named registration
. Keeping registration as a
separate module makes it easy to include or remove this capability from the app and allows multiple registration
methods. Follow these steps:
-
Create a folder named
registration
and within it, create a file calledmodule.rell
. -
Add the following definitions to
registration/module.rell
:
module;
import ^.news_feed.*;
import lib.ft4.accounts.strategies.open;
import lib.ft4.accounts.strategies.{ register_account };
operation register_user(name) {
val account = register_account();
val user = create user ( name, account.id, account );
create follower ( user = user, follower = user );
}
- The
open
strategy allows users to register themselves. - The
register_user
operation first registers an account, then creates the relevant entities holding the user name and follower information. - The
register_account
function ensures the transaction is signed by a unique EVM account.
- Add an exclusion for this operation in your
chromia.yml
file, which tells theft
library that theregister_user
operation is safe to use:
blockchains:
news-feed:
module: main
moduleArgs:
lib.ft4.core.auth:
evm_signatures_authorized_operations:
- register_user
For more details on configuring your chromia.yml
file, you can refer to the Chromia Project Configuration documentation.
- In your
main.rell
file, add an import statement for the newregistration
module:
module;
import news_feed.*;
import registration.*;
Even though the register_user
operation requires a valid EVM signature, it exposes a potential DDOS attack vector
since each account is represented as a row in the database. Mitigation strategies include:
- Rate limiting the operation.
- Enforcing payments.
- Setting up an authentication server as a middle layer.