Introduction to the Leaf Wallet Paradigm

Overview

The Leaf Wallet paradigm is designed to provide some features of Ethereum's account abstraction as outlined in the roadmap, without the complexity of the ERC-4337 framework. It's aimed to be more straightforward to implement for dApp developers, and unlike ERC-4337, it's available for use now.

The Leaf Wallet approach tackles similar challenges to account abstraction by reducing complexity and increasing accessibility for dApp developers. It does this through a simple three-step process:

  1. Leaf Wallet generation: A dApp on a user's device generates a secure individual "leaf" wallet that can independently sign transactions and interact with the blockchain, reducing reliance on third-party wallet apps or integrators.
  2. Registration: After the creation of a leaf wallet, it's registered in a registry smart contract alongside the user's primary wallet, ensuring that all assets associated with the leaf wallet also get linked to the user's main wallet.
  3. Transaction signing and execution: The leaf wallet can then independently sign and execute transactions, allowing the dApp to interact with the blockchain without further friction.

Important to note: Leaf Wallet is not ment to replace Account Abstraction but to embrace it. When ERC-4337 is fully available the Leaf Wallet paradigm can be embedded into Account Abstraction framworks and users therefore benefit from full scale features of ERC-4337.

This paradigm allows for simplified onboarding and interaction with dApps, and provides a level of abstraction from the specifics of Ethereum's blockchain mechanisms, thus making it more user-friendly.

The key difference between this approach and the ERC-4337 framework is that it bypasses the need for complex components like UserOperation, EntryPoint Contract, Account Contract, Account Factory Contract, and Paymaster Contract, which are central to the ERC-4337 architecture. These components introduce additional complexity and might be challenging for dApp developers to implement, especially those who are new to the Ethereum ecosystem.

It's further important to note that the Leaf Wallet paradigm, while simpler, might not provide all the features and flexibilities that full account abstraction via ERC-4337 can offer. Also, while it's currently available, its adoption and performance in various use-cases still remain to be evaluated.


Advantages of the Leaf Wallet Paradigm

The Leaf Wallet approach offers a unique solution to some of the most common problems faced by users of blockchain wallets, such as the risk of losing access to assets due to loss of private keys or seed phrases.

In traditional blockchain wallets, losing your private keys or seed phrases essentially means losing access to your assets. This is because these keys and phrases are the only way to unlock and gain control over your blockchain wallet. If you lose them, there's no way to recover your assets, as there's no central authority that can help you regain access.

However, with the Leaf Wallet approach, the risk of losing access to your assets is significantly reduced. Here's how:

  1. Separation of Risk: The Leaf Wallet paradigm separates your main wallet - where you store your valuable assets - from the leaf wallets that you use for daily transactions. This means you don't have to expose your main wallet and its keys to potential security risks associated with daily usage, such as interacting with dApps on your mobile device. Your main wallet can stay secure in a trusted environment, while your leaf wallets handle the day-to-day transactions.
  2. Key and Asset Management: In the Leaf Wallet approach, each leaf wallet is registered to your main wallet via a registry contract. This means that even if you lose access to your leaf wallet (for instance, if you lose the private keys of the leaf wallet or the device where it's stored), you don't lose your assets. Since the leaf wallets are linked to your main wallet in the registry contract, all assets assigned to a leaf wallet are also assigned to your main wallet. So, you can still access and control your assets through your main wallet.
  3. Ease of Recovery: If a leaf wallet gets lost or compromised, you can simply generate a new leaf wallet using the dApp on your device and register it with your main wallet. The lost leaf wallet can be safely disregarded, as its assets can be controlled through the main wallet and can further be delegated to new leaf wallets.

By solving these problems, the Leaf Wallet paradigm not only makes it easier for users to manage their blockchain wallets and assets but also significantly enhances the security and user experience of interacting with dApps and the Ethereum blockchain.


For dApp Builders

The Leaf Wallet paradigm facilitates the creation of decentralized applications (dApps). Our upcoming library, @leafwallet/mobile, simplifies the process of building dApps based on the Leaf Wallet paradigm. Here's an example of how easy it is to interact with the library:

                
                    async initialize() {
                        // Stage 1: Initializing Environment
                        // Wait until the library is ready
                        while(!this.leafwalletmobile.isReady) {
                            await timeout(100);
                        }

                        // Stage 2: Confirming dApp Wallet
                        // Check if a wallet already exists in the secret storage
                        if(!await this.leafwalletmobile.checkWalletExists()) {

                            // Stage 3: Creating dApp Wallet
                            // If no wallet exists, create a new one
                            await this.leafwalletmobile.createWallet();
                        }

                        // Stage 4: Loading dApp Wallet
                        // Load the wallet from the secret storage
                        this.wallet = await this.leafwalletmobile.loadWallet();

                        // Stage 5: Verifying dApp Registry
                        // If the wallet is registered, we're done. If not, move to registration stage
                        return this.leafwalletmobile.isRegistered;
                    }
                
                

In this code, the `initialize` function goes through various stages of setting up the dApp. It checks if the library is ready, then checks if a wallet exists. If not, it creates a new one. The wallet is then loaded and finally, it checks if the wallet is registered. If not you can use the state to show for example the registration qr code.


For dApp User

When you first use a dApp following the Leaf Wallet paradigm on your device, you'll be guided through a straightforward process to set up and register your unique leaf wallet. Here's how you can do it:

  1. Create and Link Your Leaf Wallet

    Upon launching the dApp, a unique leaf wallet will be created for you. You'll be presented with a QR code, representing the public key of your leaf wallet. To link this leaf wallet with your user wallet, simply scan this QR code in a trusted environment using the Registration application of the dApp you are using, which is usually indicated at the dApp QR Code screen. Remember, this QR code only contains the public key of your leaf wallet. It doesn't require extreme security measures, but it's always good practice to keep it private.
  2. Confirm the Registration

    After scanning the QR code, you'll be prompted to confirm the registration in the dApp itself by providing the secret number the Registration application shows. With your confirmation, your leaf wallet becomes registered and linked to your user wallet, ready for use.
  3. Fund Your Leaf Wallet

    Lastly, to start using your leaf wallet with the dApp, you need to transfer a minimal amount of funds to it. These funds are used to cover gas costs for your transactions. Think of your leaf wallet as a prepaid card - it only needs a small balance, reducing risk while still providing the full functionality you need.

In just three steps, you can set up your leaf wallet and enjoy a seamless, secure dApp experience.

A Word on Security

With the Leaf Wallet Paradigm, you don't have to worry about the private key for the leaf wallet or seed phrases. Your assets are never bound to the leaf wallet but always to the user wallet registered with the dApp. However, the dApp might provide an option to export the private key for your convenience, but it's not necessary for the operation or security of your assets.


Key Principles and Benefits of Leaf Wallet

1. Privacy and Security

Leaf Wallet ensures top-notch security by operating completely on the client-side. The private keys never leave your device, thus giving you full control over your assets. There's no need to trust a third party or worry about the risk of data breaches.

2. Seamless User Experience

Leaf Wallet offers an intuitive and user-friendly interface. By handling key management behind the scenes, it provides a seamless user experience similar to traditional web applications, without compromising the principles of decentralization.

3. Fully Decentralized

Unlike other solutions such as Wallet Connect that rely on centralized APIs, Leaf Wallet operates entirely on-chain and doesn't depend on any centralized infrastructure. This ensures that your interactions with dApps remain decentralized and censorship-resistant.

4. Compatibility

Leaf Wallet is compatible with any Ethereum-based dApp. It supports all the features of an Ethereum wallet, including ERC20 tokens and NFTs. You can easily integrate it with your existing dApps or use it to build new ones.

5. Cost-Effective

Implementing Leaf Wallet is not only simple but also cost-effective. As a dApp builder, you won't have to deal with excessive implementation overheads or pay any registration fees to third parties. It's all about maximizing your return on investment.

6. Ecosystem Friendly

Leaf Wallet contributes to the Ethereum ecosystem by promoting a more secure and user-friendly way of interacting with dApps. It helps in making blockchain more accessible to a wider audience, thereby fostering the growth of the Ethereum ecosystem.