Programmable Key Pairs (PKPs): An Overview and Quick Start Guide

Nyikwagh MosesNyikwagh Moses
5 min read

Introduction:

Programmable Key Pairs (PKPs) have revolutionized the field of secure communication and cryptographic operations. PKPs offer developers a powerful toolset to manage encryption, authentication, and digital signatures. In this article, we will provide a high-level overview of how PKPs work, explore the various use cases they can support, and offer a quick start guide for developers interested in harnessing the capabilities of PKPs.

Understanding PKPs:

Programmable Key Pairs consist of a public key and a corresponding private key. These keys are mathematically related, with the private key being kept secret by the owner, while the public key is shared with others. PKPs are based on asymmetric cryptography, which employs different keys for encryption and decryption.

The private key is used to perform operations such as signing and decrypting, while the public key is used for verifying signatures and encrypting messages. PKPs enable secure communication, ensuring confidentiality, integrity, and non-repudiation.

Use Cases for PKPs:

Seed-phraseless onboarding experiences with multi-factor authentication :

This refers to a user-friendly method of creating accounts or accessing cryptographic systems without the need for traditional seed phrases while incorporating an additional layer of security through multi-factor authentication. By combining seed-phraseless onboarding experiences with MFA, users can enjoy a more user-friendly account creation process while ensuring enhanced security. These approaches aim to strike a balance between usability and security, making it easier for users to adopt cryptographic systems and reducing the risk of losing access to their accounts due to seed phrase mishandling or loss.

Signing Automation and Conditional Transaction Execution:

This refers to techniques used to streamline and automate the process of signing transactions while incorporating conditions for their execution. This involves the use of software or systems to automatically generate cryptographic signatures for transactions and that is where PKPs are used. Instead of manually signing each transaction, signing automation enables the automation of this process, saving time and effort for users.

Conditional transaction execution allows for the execution of transactions based on predefined conditions. These conditions can be programmed into smart contracts or transaction scripts, specifying certain criteria that must be met for the transaction to be executed. This feature enables the creation of more complex transaction workflows and facilitates conditional decision-making during transaction execution.

Cross-Chain Messaging and Swaps:

This refers to the ability to send and receive messages or data between different blockchain platforms. It enables interoperability and communication across disparate blockchain networks, allowing for the seamless transfer of information and instructions.

Cross-chain swaps, on the other hand, involve the exchange of assets or tokens between different blockchain networks without the need for intermediaries or centralized exchanges. These swaps enable users to trade assets across different chains, unlocking liquidity and expanding the possibilities for decentralized trading.

By combining cross-chain messaging and swaps, users can leverage the benefits of different blockchain networks, access a wider range of assets, and overcome the limitations of a single blockchain ecosystem. This promotes interoperability and opens up new opportunities for decentralized finance (DeFi), decentralized applications (dApps), and other blockchain-based services.

Quick Start Guide:

Step 1: Install Lit SDK:

First, you need to install the Lit SDK, there 3 ways you can achieve this, depending on your need,

for the sdk in the browser and node, use

yarn add @lit-protocol/lit-node-client

if you prefer to add it to your project using a script tag, you can use

<script src="https://cdn.jsdelivr.net/npm/@lit-protocol/lit-node-client-vanilla/lit-node-client.js"></script>

otherwise, if you prefer to use it in your node application on the server side alone,

yarn add @lit-protocol/lit-node-client-nodejs

Step 2: Generate a Key Pair:

To get started with PKPs, you need to generate a programable key pair. You can mint PKP in various ways which include:

  • Through WebAuthn by presenting a valid WebAuthn credential generated by your browser to the Lit Relay server.

  • Through social auth by presenting a valid OAuth token as an authentication method to the Lit Relay server. Currently, only Google OAuth tokens are supported, but there are plans to support Discord in the near term

  • Through email or sms OTP by presenting a generated token from successful OTP code confirmation, which will be returned by the lit-auth-client in the AuthMethod return from successful code confirmation.

Step 3: Connect to the Lit Network:

After installing the Lit SDK, you would need to connect to the Lit Network to be able to perform most o the functionalities, even though you do not need it if you are verifying JSON Web Token only. You can achieve that by using the code below after installing using a package manager eg yarn or npm

const client = new LitJsSdk.LitNodeClient();
await client.connect();
window.litNodeClient = client;

Step 4: Listening for the lit-ready event:

After installing the Lit SDK, set up your development environment, configuring environment your variables, and initializing the Lit Protocol SDK. You would want to save the litNodeClient in a global variable so that you can access it throughout your app. When all is done, you would need to listen for the "lit-ready" event which is fired when the network is fully connected: An example would be after setting up your Lit object using your

document.addEventListener(
  "lit-ready",
  function (e) {
    console.log("LIT network is ready");
    setNetworkLoading(false); // replace this line with your own code that tells your app the network is ready
  },
  false
);

Conclusion:

Programmable Key Pairs offer developers a robust toolkit for implementing a range of security features for your dApp. By understanding the fundamentals of PKPs and following best practices, developers can harness the power of asymmetric cryptography to enhance security and build trustworthy systems.

0
Subscribe to my newsletter

Read articles from Nyikwagh Moses directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Nyikwagh Moses
Nyikwagh Moses