In traditional web3 interactions, users often face the burden of performing repetitive tasks to enable smart contracts to execute specific actions, such as signing transactions and granting approvals. This manual process can become tedious and time-consuming.
However, by utilizing programmable key pairs, an additional layer of abstraction is introduced. With programmable key pairs, developers can incorporate logic into a pair of public/private key systems, allowing smart contracts to autonomously carry out advanced actions like executing transactions and automating tasks.
This eliminates the need for constant user interaction, streamlining the user experience and enhancing the capabilities of smart contracts.
With this innovation, developers can enhance the onboarding experience for web2 users entering web3 by utilizing seedless phrase wallets, web2 authentication for easy sign-on, and automation services for streamlined interactions with decentralized applications.
The creation of programmable key pairs (PKP) involves a technique called Distributed Key Generation (DKG). In DKG, multiple parties or nodes contribute to calculating a shared public and private key set. Each node holds a share of this key for signing purposes.
DKG was first introduced in 1991 by Torben Pedersen and later improved upon in 1999 by Rosario Gennaro, Stanislaw Jarecki, Hugo Krawczyk, and Tal Rabin.
https://en.wikipedia.org/w/index.php?title=Distributed_key_generation&oldid=1171811810
Lit protocol has popularized the application of DKG in creating PKPs. Lit actions, which are smart contracts written in JavaScript, allow developers to code logic into PKPs and customize applications according to their specific goals.
This process provides more flexibility compared to self-custody wallets.
In the implementation of pkp from Lit protocol, the distributed key pair is controlled by minting it as an ERC 721 NFT. This process is facilitated through Lit's platform(https://explorer.litprotocol.com/mint-pkp). The ERC 721 NFT serves as a "symbol" for controlling the distributed key within the Lit network.
Only the wallet address or smart contract holding this NFT has the authority to determine its usage, set access permissions, revoke permissions, and control what can be signed using the distributed key.
Prior to PKPs, self-custodial wallets like Metamask were the main way for users to interact with smart contracts and the blockchain. These wallets give users direct control over their actions and assets, but they are not distributed and can be vulnerable to security flaws. They operate on a one-user-to-one private key system and are not programmable.
PKPs represent a groundbreaking approach to smart contracts and blockchain interaction, introducing a wide array of innovative possibilities. These include the design of multi-signature wallets that require multiple signatures before transactions can be executed and the automation of smart contracts, enabling them to take actions without the need for end-user involvement.
This opens up opportunities for creating subscription-based decentralized applications (dApps) and enhancing the user experience in Decentralized Finance (DeFi) – a suite of blockchain-based applications providing lending, borrowing, and other financial services within the Web3 ecosystem.
In their fundamental form, PKPs are distributed, programmable, and immutable. Through the utilization of Lit Actions, which become unmodifiable once published, PKPs maintain a high level of data integrity.
With the added advantage of being programmable, pkps hold a lot of potential to further enhance the web3 experience in building innovative applications and enhancing available ones. These use cases include:
When it comes to leveraging cryptocurrency in the world of finance, centralized exchanges offer significant advantages. They are easier to set up and provide a wide array of trading tools, making the process more convenient.
One crucial tool is the availability of a limit order system, which allows orders to be executed at specific times or price points. PKPs have the potential to bring this functionality to decentralized exchanges and DeFi platforms.
By programming such services into dApps and contracts that leverage the programmability of PKPs, these platforms can achieve similar functionalities.
Another important use case for PKPs is the ability to handle recurring payments and subscription-based services, similar to what we see in traditional web2 platforms. With PKPs, the execution of transactions can be automated, making it feasible to implement a system that handles recurring payments seamlessly.
This feature brings convenience and efficiency to decentralized applications, allowing users to subscribe to services and make regular payments without manual intervention.
Decentralized Key Custodian
Due to their distributed nature, PKPs are ideal for creating multi-signature wallets that require multiple signatories to confirm a request before a transaction can be fully executed. This feature enhances security and reduces the risk of unauthorized transactions.
Additionally, PKPs open up opportunities for designing wallet systems that utilize a multiple seedless approach, where the private keys are not stored in a single location, further enhancing security.
One notable project that offers such a solution is Magic Wallet. Magic Wallet ensures that there is no single point of failure or compromise of private keys, providing users with a robust and secure wallet experience.
PKPs also play a crucial role in building cross-chain bridges, facilitating the seamless transfer of tokens between different blockchains. These bridges enable interoperability and liquidity across multiple blockchain networks, allowing users to bridge a specific token from one blockchain to another.
PKPs provide the programmability and flexibility necessary to create smart contracts and protocols that facilitate the secure and efficient transfer of assets between blockchains.
This functionality is vital for the growth and development of decentralized finance (DeFi) ecosystems, as it enables the integration of different blockchain networks and expands the possibilities for asset utilization and liquidity provision.
Token-Gated-Content
PKPs are ideal for social platforms that offer exclusive content and rewards based on specific criteria like owning a particular NFT. With their programmability, PKPs allow for conditional logic and executions, automating the distribution of rewards and access to exclusive features.
This enhances user engagement, gamification, and transparency while reducing reliance on centralized intermediaries.
Account Abstraction with support for Web2 Auth methods and on-chain reputation-building
PKP, through Account Abstraction with lit action, provides a way for users to access dApps and applications built on web3 using traditional sign-in methods like Google authentication and more.
This approach allows for a seamless onboarding experience for users into web3, eliminating the complexities of handling private keys, while still maintaining the secure and decentralized nature of web3.
They can also be utilized to track users' activities on apps that aim to rank users based on their participation and diligence, such as regular posting, liking, or commenting activities. By using PKPs, app developers can securely and transparently monitor and record user actions, which can then be used to calculate user rankings and distribute rewards accordingly.
This helps incentivize active user engagement, promote community involvement, and fairly distribute rewards based on user contributions.
Wallet Abstraction and Condition-Based Automation
Aside from its potential to seamlessly onboard new gamers that are unfamiliar with web3 wallets They can drastically reduce the time players spend manually claiming in-game rewards and selling in-game assets by automating such actions.
Getting started with PKP is as easy as following the developer documentation on (https://developer.litprotocol.com/v2/)
For the purpose of this article, I will take you through a quick start on how to use PKP as a wallet.
To begin working with pkps and using them in application logic, one first needs to mint one. Lit protocol provides various ways of minting a PKP. Let’s explore how to mint via webAuthn which works by presenting valid webAuthn credentials generated by your browser to the lit relayer server.
To do this, head over to https://pkp-walletconnect.vercel.app/ and follow the provided instructions.
To initialize a pkpetherswallet, an AuthSig will be needed in order to authorize signing requests. This can be obtained in the browser using the checkAndSignAuthMessage()
which can be used to obtain an AuthSig from an Externally Owned Account.
import { checkAndSignAuthMessage } from '@lit-protocol/lit-node-client';
const authSig = await checkAndSignAuthMessage({
chain: "ethereum",
});
When called, checkAndSignAuthMessage()
triggers a wallet selection popup in the user's browser. The user is then asked to sign a message, confirming ownership of their crypto address. The signature of the signed message is returned as the authSig variable.
A comprehensive breakdown of this process can be obtained from the lit documentation (https://developer.litprotocol.com/v2/pkp/usage/)
For a basic walkthrough, an installation of the pkp-ethers
package is required
npm install @lit-protocol/pkp-ethers
After installation, the pkpetherswallet
is then initialized with the AuthSig received earlier, and the PkP public key is generated when a pkp is minted.
import { PKPEthersWallet } from "@lit-protocol/pkp-ethers";
const pkpWallet = new PKPEthersWallet({
controllerAuthSig: "<Your AuthSig>",
// Or you can also pass in controllerSessionSigs
pkpPubKey: "<Your PKP public key>",
rpc: "https://chain-rpc.litprotocol.com/http",
});
await pkpWallet.init();
This initialized pkpwallet
can then be used to sign messages and transactions
const message = "Free the web";
const hexMsg = ethers.utils.hexlify(ethers.utils.toUtf8Bytes(message));
await pkpWallet.signMessage(hexMsg);
const from = address;
const to = address;
const gasLimit = BigNumber.from("21000");
const value = BigNumber.from("10");
const data = "0x";
// @lit-protocol/pkp-ethers will automatically add missing fields (nonce, chainId, gasPrice, gasLimit)
const transactionRequest = {
from,
to,
gasLimit,
value,
data,
};
const signedTransactionRequest = await pkpWallet.signTransaction(
transactionRequest
);
The concept of Web3 and the process of creating a secure wallet can initially seem daunting to the average person, as it may appear to require a high level of expertise or even genius-like intelligence to understand.
The idea of protecting keys without any means of recovery can be quite intimidating at first glance. Programmable key pairs seek to eliminate this barrier and make accessing Web3 systems as user-friendly as their Web2 counterparts.
Furthermore, PKPs empower developers by providing them with the tools to implement complex logic that would have otherwise been challenging to achieve without their use.
Although still in their early stages of development, PKPs are paving the way for a more user-friendly Web3 interaction system. This, in turn, is poised to facilitate the wider dissemination and adoption of Web3 technologies.