How to make our wallets more user-friendly

As we know, Account Abstraction(AA) has been a hot topic in Ethereum recently, to further lower the onboarding barrier for users, and an essential feature of AA is the introduction of Session keys.

Session keys are helpful in that they free users from the need to constantly sign their on-chain operations, a poor user experience that has been criticized for a long time. Users can't accept exposing their private keys to risk to gain some convenience, and Session keys solve this problem.

Introduction to Session Keys

Firstly, let's introduce the meaning of Session in Substrate; Session in Substrate refers to a period with a constant set of validators and we are restricted to only changing the set of validators when the Session is changed.

Session keys are a set of hotkeys held by the validators for performing on-chain operations, and we change Session keys as the set of validators changes. In effect, Session keys are several keys kept together which provide the various signing functions required by network authorities/validators to perform their duties. Each session key plays a specific role in consensus or security in general. All session keys derive their authority from a session certificate

Code Implementation

For the Session Pallet, our most basic functions are the configuration of Session keys and the Rotation of Sessions.

Session keys configuration

Session keys are set with set_keys and are not used in the next Session but after the next Session. They are stored in NextKeys, which is a mapping between the caller's ValidatorId and the provided session key. set_keys allows the user to set their session key before being selected as a validator. This is a public call because it uses ensure_signed, and checks whether the origin is a signed account. Therefore, the origin account ID stored in NextKeys is not necessarily associated with the block author or validator. Once the account balance is zero, the account's session key will be deleted.

Session control

Instead of specifying a limit on the length of a session, we would normally determine the start of a new session through the implementation of ShouldEndSession. The pallet provides a PeriodicSessions structure for simple periodic sessions. The following is an implementation of the ShouldEndSession trait for the PeriodicSessions structure:

fn should_end_session(now: BlockNumber) -> bool {
    let offset = Offset::get();
    now >= offset && ((now - offset) % Period::get()).is_zero()
}

Use should_end_session to determine if you want to stop the session in the current block

At the same time, we also implement the

We need to be clear that if we want to open a new Session, we can choose to provide a new set of validators

We also need to have implemented the SessionHandler trait-related function

Session Rotation process

At the beginning of each block, the on_initialize function queries the provided implementation of ShouldEndSession. If the session is to end, the newly activated validator ID and session key are retrieved from storage and passed to SessionHandler. The set of validators provided by SessionManager::new_session and the corresponding Session keys (which may have been registered during the previous session via set_keys) are written to storage and they will wait for a session before being passed to SessionHandler.

The following are the most critical implementation

Summary

If we could have a UI/UX friendly session keys setup platform, we could greatly lower the user onboarding difficulty, and improve the user experience. For example, we could set up session keys for an on-chain game, which would allow us to get rid of the constant process of entering passwords, and we could also use session keys to make small, password-free payments.

In Polkadot.js there is a feature that allows you to choose to sign your password without having to enter it again within 15 minutes of entering it once, but as we can see by analyzing the source code, they do not use session keys but simply cache it for the UX boost. If we can use session keys wisely, we could have a much better user experience in our secondary wallet development!

Sign up for our newsletter

Stay up to date with the roadmap progress, announcements and exclusive discounts feel free to sign up with your email.

© By Whisker —@whisker17