Getting Started
Create a new project with npm (or whatever package manager you use):
mkdir keypo
cd keypo
npm init -y
touch .env
Install the keypo sdk:
npm install @keypo/typescript-sdk
Add an RPC URL and the Keypo API URL to your .env file (you can use https://sepolia.base.org as an RPC URL for testing, it’s free):
API_URL=https://api.keypo.io
RPC_URL=https://sepolia.base.org
Create a script index.ts with the following code:
import { init, preProcess, encrypt, decrypt, postProcess } from "@keypo/typescript-sdk";
import { http, createWalletClient } from "viem"
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts"
import { baseSepolia } from "viem/chains"
import { ethers } from "ethers";
import dotenv from "dotenv";
dotenv.config();
async function end2endDemo() {
const API_URL = process.env.CLIENT_KEYPO_API;
const RPC_URL = process.env.CLIENT_RPC_URL;
if (!API_URL || !RPC_URL) {
throw new Error("API_URL or RPC_URL is not set");
}
// Create a new wallet and sign authorization for using as a smart account
const keypo = await init(API_URL);
const privateKey = generatePrivateKey()
const signer = privateKeyToAccount(privateKey)
const encryptWallet = createWalletClient({
chain: baseSepolia,
transport: http(RPC_URL),
account: signer,
});
const provider = new ethers.providers.JsonRpcProvider(RPC_URL);
const decryptWallet = new ethers.Wallet(privateKey as string, provider);
const authorization = await encryptWallet.signAuthorization({
contractAddress: keypo.kernelAddress as `0x${string}`, // Kernel V3.3 implementation address
});
// Preprocess data for encryption
const data = "Hello World";
const { dataOut, metadataOut } = await preProcess(data, "test string");
// Encrypt data
const { dataCID, dataIdentifier } = await encrypt(dataOut, encryptWallet, metadataOut, authorization, keypo.encryptConfig);
// Decrypt data
const { decryptedData, metadata } = await decrypt(dataIdentifier, decryptWallet, keypo.decryptConfig);
// Postprocess data
const processedData = await postProcess(decryptedData, metadata);
return processedData;
}
async function main() {
const processedData = await end2endDemo();
console.log("DECRYPTED OUTPUT: ", processedData);
}
main();
Run it:
npx tsx index.ts
You should see the following output:
lit-js-sdk:constants:errors deprecated LitErrorKind is deprecated and will be removed in a future version. Use LIT_ERROR_KIND instead. node:internal/modules/cjs/loader:1723:14
lit-js-sdk:constants:constants deprecated LogLevel is deprecated and will be removed in a future version. Use LOG_LEVEL instead. node_modules/@lit-protocol/core/src/lib/lit-core.js:453:119
Storage key "lit-session-key" is missing. Not a problem. Continue...
Storage key "lit-wallet-sig" is missing. Not a problem. Continue...
Unable to store walletSig in local storage. Not a problem. Continue...
DECRYPTED OUTPUT: Hello World
Congrats – you just encrypted and decrypted data using Keypo!
Now that you’ve gotten your hands dirty, check out:
- Functions for detailed information on how to run each function in the SDK.
- Key Concepts to learn how encryption, access control and decryption is handled by Keypo.
- Flow Diagrams for diagrams that visualize the interactions between different components of the Keypo system.
- Glossary for a comprehensive list of all interfaces and types used throughout the SDK.