Introduction.
Are you new to Programmable Key Pairs??
Don't worry because this article has you covered. By the end, you are going to get an in-depth understanding of what PKPs mean, how they work and how you can integrate them into your projects as a developer.
Definition of (PKPs)
A Programmable key pair is an ECDSA key pair that is held as private key shares safeguarded by the lit nodes.
They are generated by the Lit network and are minted in the form of an ERC-721 NFT. The owner of the NFT becomes the sole controller of the underlying private key and this allows for automation in that the owner of the NFT can then ask the PKP to sign anything on the blockchain on their behalf i.e. signing off Ethereum transactions etc Due to this amazing feature, web3 users can interact with blockchains seamlessly. They are no longer required to cram their seed phrases.
How do they work?
Programmable key pairs (PKPs) are implemented using asymmetric encryption also known as public-key cryptography. The public key is publicly shared and used for encryption or verification purposes, while the private key is securely held by the owner and used for decryption or signing.
This allows developers to dynamically manage and control cryptographic operations, such as key generation, storage, rotation, and revocation, programmatically. This programmability empowers developers to build robust and scalable security solutions while providing greater control and adaptability to changing security requirements.
On the Lit protocol, PKPs are generated collectively by the lit nodes through a process called Distributed Key Generation where multiple parties contribute to the calculation of a shared public and private key set. By distributing the generation of keys DKG mitigates the risk of private key exposure and unauthorized access.
Types of (PKPs).
1). Seed-Phraseless. 4). Signing Automation.
2). Credential Issuance. 5). Versatile Web3 Wallets.
3). Cross-chain Messaging and swaps. 6). Signer on an AA Wallet PKPs.
Uses Cases.
PKPs can be used for user authentication. The onboarding experience has been simplified as long seed phrases are no longer required for signing into web3 applications.
DEFI trading is more simple with PKPs. You can create a lit action that checks the price of a token that you've staked. If the price drops below the staked price with the help of your PKP you can unstake the token and sell it. This can all be done without the user's input.
PKP can also be used as a vault. As a developer, you can mint a PKP and then send a bunch of assets into it. Later you can sell the PKP NFT and transfer with it all the assets
PKPs enhance secure communication. This is made possible by the use of public keys to encrypt data and private keys to decrypt.
Getting Started With PKPs
Install Dependencies
To use PKPs you’ll need to install the necessary dependencies. The main dependency is the Lit Protocol SDK, which provides the tools and functionality for interacting with the Lit Protocol. You can install it using npm or yarn:
yarn add @lit-protocol/lit-node-client
Import SDK library
import * as LitJsSdk from '@lit-protocol/lit-node-client';
Connecting to the lit network
const client = new LitJsSdk.LitNodeClient();
await client.connect();
window.litNodeClient = client;
An Example Performing Encryption
Steps to encrypt:
Obtain an
authSig
and create an access control condition.Encrypt the static content (string, file, etc.) to get the
encryptedString
, for example.Use
litNodeClient.saveEncryptionKey
to tie theaccessControlConditions
with thesymmetrickey
we got above. This returns us to theencryptedSymmetricKey
.Finally, we have to store the
encryptedString
& other metadata:encryptedSymmetricKey
,accessControlConditions
(or other conditions eg:evmContractConditions
) andchain
. IPFS is generally used to store these values.
const accessControlConditions = [
{
contractAddress: "",
standardContractType: "",
chain: "ethereum",
method: "eth_getBalance",
parameters: [":userAddress", "latest"],
returnValueTest: {
comparator: ">=",
value: "1000000000000", // 0.000001 ETH
},
},
];
async encrypt(message: string) {
if (!this.litNodeClient) {
await this.connect()
}
const authSig = await LitJsSdk.checkAndSignAuthMessage({ chain })
const { encryptedString, symmetricKey } = await LitJsSdk.encryptString(message)
const encryptedSymmetricKey = await window.litNodeClient.saveEncryptionKey({
accessControlConditions,
symmetricKey,
authSig,
chain,
})
return {
encryptedString,
encryptedSymmetricKey: LitJsSdk.uint8arrayToString(encryptedSymmetricKey, "base16")
}
}
Conclusion
As a developer, exploring and leveraging PKPs with Lit Protocol can significantly enhance the security and reliability of your applications. By adopting PKPs, you can simplify key management, strengthen access controls, and ensure the confidentiality and integrity of your data and assets.
Remember to follow best practices for key security, including storing private keys in secure environments and protecting them with appropriate access controls while ensuring the confidentiality and integrity of sensitive data.
I encourage you to dive deeper into PKPs and the capabilities offered by Lit Protocol to unlock the full potential of secure key management in your applications.
Kindly visit https://developer.litprotocol.com and check out their documentation on PKPs and how to get started.
Happy Coding!!🥳🥳🚀🚀