Data is the new oil, but how can we ensure that we have full control over our own data, and who can access it? How can we share data securely and selectively with different parties without compromising our privacy or security? How can we leverage the power of cryptography and blockchain to create decentralized applications that respect our data sovereignty?
These are some of the questions that Programmable Key Pairs (PKPs) aim to answer. PKPs are a new tool that allows developers to create and manage data access policies using smart contracts on the LIT Protocol, a decentralized network for data access and privacy. PKPs enable users to encrypt their data with their own public keys, and grant or revoke access to their data with their own private keys. PKPs also allow users to specify conditions and logic for data access, such as time limits, payment requirements, or verification steps.
PKPs are based on the concept of asymmetric encryption, which uses a pair of keys: a public key and a private key. The public key can be used to encrypt data, while the private key can be used to decrypt it. Only the owner of the private key can decrypt the data encrypted with the corresponding public key.
PKPs extend this concept by allowing users to program their keys with smart contracts. A smart contract is a piece of code that runs on a blockchain and executes predefined rules and logic. By programming their keys with smart contracts, users can create custom data access policies that define who can access their data, when, how, and under what conditions.
For example, a user can create a PKP that encrypts their medical records with their public key, and grants access to their doctor only for a limited period of time, or only after verifying their identity with a biometric scan. Alternatively, a user can create a PKP that encrypts their social media posts with their public key, and grants access to their friends only if they pay a small fee in cryptocurrency, or only if they agree to share their own posts in return.
PKPs can be used to support a variety of use cases that require secure and selective data sharing across different domains and platforms. Some examples are:
Healthcare: Patients can use PKPs to encrypt their health records and share them with their doctors, insurers, or researchers, while retaining full control over their data privacy and consent.
Finance: Users can use PKPs to encrypt their financial transactions and share them with their banks, auditors, or regulators, while ensuring data security and compliance.
Social media: Users can use PKPs to encrypt their social media posts and share them with their friends, followers, or advertisers, while monetizing their data and protecting their identity.
Gaming: Gamers can use PKPs to encrypt their game assets and share them with other players, developers, or platforms, while creating new gaming experiences and economies.
Education: Students can use PKPs to encrypt their academic records and share them with their teachers, employers, or institutions, while proving their skills and achievements.
If you are a developer interested in getting started with PKPs, you can follow these steps:
npm install @litprotocol/lit-js-sdk
or
yarn add @litprotocol/lit-js-sdk
import { LitNodeClient } from '@litprotocol/lit-js-sdk';
// Create a client instance
const client = new LitNodeClient();
// Connect to the network
await client.connect();
import { LitNodeClient } from '@litprotocol/lit-js-sdk';
// Create a client instance
const client = new LitNodeClient();
// Connect to the network
await client.connect();
// Generate keys
const { publicKey, privateKey } = await client.generateKeyPair();
// Write a smart contract
const contract = `
pragma solidity ^0.8.0;
contract MyPKP {
// Define your logic here
}
`;
// Compile the contract
const { abi, bytecode } = await client.compileContract(contract);
import { LitNodeClient } from '@litprotocol/lit-js-sdk';
// Create a client instance
const client = new LitNodeClient();
// Connect to the network
await client.connect();
// Generate keys
const { publicKey, privateKey } = await client.generateKeyPair();
// Write a smart contract
const contract = `
pragma solidity ^0.8.0;
contract MyPKP {
// Define your logic here
}
`;
// Compile the contract
const { abi, bytecode } = await client.compileContract(contract);
// Create a transaction
const tx = {
publicKey,
privateKey,
abi,
bytecode,
};
// Sign the transaction
const signedTx = await client.signTransaction(tx);
// Send the transaction
const receipt = await client.sendTransaction(signedTx);
import { LitNodeClient } from '@litprotocol/lit-js-sdk';
// Create a client instance
const client = new LitNodeClient();
// Connect to the network
await client.connect();
// Generate keys
const { publicKey, privateKey } = await client.generateKeyPair();
// Write a smart contract
const contract = `
pragma solidity ^0.8.0;
contract MyPKP {
// Define your logic here
}
`;
// Compile the contract
const { abi, bytecode } = await client.compileContract(contract);
// Create a transaction
const tx = {
publicKey,
privateKey,
abi,
bytecode,
};
// Sign the transaction
const signedTx = await client.signTransaction(tx);
// Send the transaction
const receipt = await client.sendTransaction(signedTx);
// Encrypt some data
const data = 'Hello world!';
const encryptedData = await client.encryptData(data, publicKey);
// Decrypt the data
const decryptedData = await client.decryptData(encryptedData, privateKey);
import { LitNodeClient } from '@litprotocol/lit-js-sdk';
// Create a client instance
const client = new LitNodeClient();
// Connect to the network
await client.connect();
// Generate keys
const { publicKey, privateKey } = await client.generateKeyPair();
// Write a smart contract
const contract = `
pragma solidity ^0.8.0;
contract MyPKP {
// Define your logic here
// Grant access to an address
function grantAccess(address _grantee) public {
// Implement your logic here
}
// Revoke access from an address
function revokeAccess(address _grantee) public {
// Implement your logic here
}
}
`;
// Compile the contract
const { abi, bytecode } = await client.compileContract(contract);
// Create a transaction
const tx = {
publicKey,
privateKey,
abi,
bytecode,
};
// Sign the transaction
const signedTx = await client.signTransaction(tx);
// Send the transaction
const receipt = await client.sendTransaction(signedTx);
// Get the PKP address from the receipt
const pkpAddress = receipt.pkpAddress;
// Grant access to someone
await client.callContractFunction(pkpAddress, 'grantAccess', [granteeAddress]);
// Revoke access from someone
await client.callContractFunction(pkpAddress, 'revokeAccess', [granteeAddress]);
Programmable Key Pairs are a new way to manage data access and privacy using cryptography and blockchain. They allow users to encrypt their data with their own keys, and grant or revoke access to their data with their own rules. They enable developers to create decentralized applications that respect user data sovereignty and enable secure and selective data sharing across different domains and platforms.
If you want to learn more about PKPs and how to use them, you can visit the following resources:
Developer Docs: https://developer.litprotocol.com/
Intro to PKPs: https://developer.litprotocol.com/pkp/intro/
Lit Blog: https://spark.litprotocol.com/