Using Lit Network has never been easier before
An Ethereum private key is used to send requests to the Lit Network. Fund your wallet with a faucet on Lit's custom rollup chain.
npm install lit-wrapper-sdk
Generates a Solana key and sends a prompt to the Solana-agent-kit (This kit runs inside Lit's TEE)
async function executeSolanaAgentKit() {
const response = await litWrapper.createSolanaWK(ETHEREUM_PRIVATE_KEY);
const agentKitResponse = await litWrapper.executeSolanaAgentKit({
userPrivateKey: ETHEREUM_PRIVATE_KEY,
MESSAGE: "What is my sol balance?",
RPC_URL: "https://api.devnet.solana.com",
OPENAI_API_KEY: process.env.OPEN_AI_API_KEY!,
pkp: response?.pkpInfo!,
wk: response?.wkInfo!,
});
console.log(agentKitResponse);
}
Checks against a conditional logic and only creates signatures for a specified transaction when the condition is satisfies
async function createLitActionAndSignSolanaTxn() {
const response = await litWrapper.createSolanaWK(ETHEREUM_PRIVATE_KEY);
console.log("Solana Public Key", response?.wkInfo.generatedPublicKey);
const conditionLogic = `
const url = "https://api.weather.gov/gridpoints/TOP/31,80/forecast";
const resp = await fetch(url).then((response) => response.json());
const temp = resp.properties.periods[0].temperature;
console.log(temp);
// only sign if the temperature is below 60
if (temp < 60) {
createSignatureWithAction();
}`;
const txn = await litWrapper.createSerializedLitTxn({
wk: response?.wkInfo,
toAddress: "BTBPKRJQv7mn2kxBBJUpzh3wKN567ZLdXDWcxXFQ4KaV",
amount: 0.004 * Math.pow(10, 9),
network: "mainnet-beta",
flag: FlagForLitTxn.SOL,
});
const checkResult = await litWrapper.conditionalSigningOnSolana({
userPrivateKey: ETHEREUM_PRIVATE_KEY,
litTransaction: txn,
conditionLogic,
broadcastTransaction: true,
wk: response?.wkInfo,
pkp: response?.pkpInfo,
});
console.log(checkResult);
}
constructor(litNetwork: LIT_NETWORKS_KEYS)
- Initializes a new instance of the
LitWrapper
class. - Parameters:
litNetwork
: The Lit network key.
async checkPermits(pkpTokenId: string): Promise<{ actions: any[], authMethods: any[], addresses: any[] }>
- Checks the permits of a PKP.
- Parameters:
pkpTokenId
: The PKP token ID.
- Returns: An object containing the permitted actions, auth methods, and addresses.
async addAuthAddress(userPrivateKey: string, pkpTokenId: string, ethAddress: string): Promise<any>
- Adds an authorized address to a PKP.
- Parameters:
userPrivateKey
: The user's private key.pkpTokenId
: The PKP token ID.ethAddress
: The Ethereum address to authorize.
- Returns: The response from the Lit network.
async removeAuthAddress(userPrivateKey: string, pkpTokenId: string, ethAddress: string): Promise<any>
- Adds an authorized address to a PKP.
- Parameters:
userPrivateKey
: The user's private key.pkpTokenId
: The PKP token ID.ethAddress
: The Ethereum address to authorize.
- Returns: The response from the Lit network.
async addPermittedAction(params: AddPermittedActionParams): Promise<{ ipfsCID: string, response: any }>
- Adds a permitted action to a PKP.
- Parameters:
params
: An object containinguserPrivateKey
,pkpTokenId
,litActionCode
, andpinataAPIKey
.
- Returns: An object containing the IPFS CID and the response.
async removePermittedAction(params: RemovePermittedActionParams): Promise<{ ipfsCID: string, response: any }>
- Adds a permitted action to a PKP.
- Parameters:
params
: An object containinguserPrivateKey
,pkpTokenId
,litActionCode
, andpinataAPIKey
.
- Returns: An object containing the IPFS CID and the response.
async createSolanaWK(userPrivateKey: string): Promise<{ pkpInfo: PKP, wkInfo: WK }>
- Creates a Solana Wrapped Key (WK).
- Parameters:
userPrivateKey
: The user's private key.
- Returns: An object containing the PKP and WK information.
async getConditionalLitAction(conditionalLogic: string): Promise<string>
- Gets a conditional Lit action.
- Parameters:
conditionalLogic
: The conditional logic.
- Returns: The conditional Lit action.
async conditionalSigningOnSolana(params: ConditionalSigningOnSolanaParams): Promise<any>
- Performs conditional signing on Solana.
- Parameters:
params
: An object containinguserPrivateKey
,litTransaction
,broadcastTransaction
,conditionalLogic
,pkp
,wk
, andparams
.
- Returns: The result of the conditional signing.
async executeCustomActionOnSolana(params: ExecuteCustomActionOnSolanaParams): Promise<any>
- Executes a custom action on Solana.
- Parameters:
params
: An object containinguserPrivateKey
,litActionCode
,pkp
,wk
, andparams
.
- Returns: The result of the executed action.
async executeSolanaAgentKit(params: ExecuteSolanaAgentKitParams): Promise<any>
- Executes the Solana Agent Kit.
- Parameters:
params
: An object containinguserPrivateKey
,MESSAGE
,RPC_URL
,OPENAI_API_KEY
,pkp
, andwk
.
- Returns: The result of the executed action.
async sendSolanaWKTxnWithSol(params: SendSolanaWKTxnWithSolParams): Promise<any>
- Sends a Solana WK transaction with SOL.
- Parameters:
params
: An object containingamount
,toAddress
,network
,broadcastTransaction
,userPrivateKey
,wk
, andpkp
.
- Returns: The signed transaction.
async sendSolanaWKTxnWithCustomToken(params: SendSolanaWKTxnWithCustomTokenParams): Promise<any>
- Sends a Solana WK transaction with a custom token.
- Parameters:
params
: An object containingtokenMintAddress
,amount
,toAddress
,network
,broadcastTransaction
,userPrivateKey
,wk
, andpkp
.
- Returns: The signed transaction.
async createSerializedLitTxn(params: CreateSerializedLitTxnParams): Promise<any>
- Creates a serialized Lit transaction.
- Parameters:
params
: An object containingtoAddress
,amount
,network
,flag
,tokenMintAddress
, andwk
.
- Returns: The serialized transaction.
async createPKP(userPrivateKey: string): Promise<PKP | undefined>
- Creates a PKP (Programmable Key Pair).
- Parameters:
userPrivateKey
: The user's private key.
- Returns: The created PKP.
async createPKPWithLitAction(params: CreatePKPWithLitActionParams): Promise<{ pkp: PKP, ipfsCID: string }>
- Creates a PKP and adds a permitted action.
- Parameters:
params
: An object containinguserPrivateKey
,litActionCode
, andpinataAPIKey
.
- Returns: An object containing the created PKP and the IPFS CID.
async createPKPSessionSigs(userPrivateKey: string, pkpPublicKey: string): Promise<any>
- Creates session signatures for a PKP.
- Parameters:
userPrivateKey
: The user's private key.pkpPublicKey
: The PKP public key.
- Returns: The session signatures.
async getSessionSigs(userPrivateKey: string, pkpPublicKey: string, type: string): Promise<any>
- Gets session signatures.
- Parameters:
userPrivateKey
: The user's private key.pkpPublicKey
: The PKP public key.type
: The type of session.
- Returns: The session signatures.
async executeLitAction(params: ExecuteLitActionParams): Promise<any>
- Executes a Lit action.
- Parameters:
params
: An object containinguserPrivateKey
,pkpPublicKey
,litActionIpfsCid
,litActionCode
, andparams
.
- Returns: The result of the executed action.
async getDecipheringDetails(params: GetDecipheringDetailsParams): Promise<{ ciphertext: string, dataToEncryptHash: string }>
- Gets deciphering details.
- Parameters:
params
: An object containinguserPrivateKey
,pkp
, andwk
.
- Returns: An object containing the ciphertext and data to encrypt the hash.
async uploadViaPinata(params: UploadViaPinataParams): Promise<string>
- Uploads a file to Pinata.
- Parameters:
params
: An object containingpinataAPIKey
andlitActionCode
.
- Returns: The IPFS hash of the uploaded file.
constructor(userPrivateKey: string, litNetwork: LIT_NETWORKS_KEYS)
- Initializes a new instance of the
LitTester
class. - Parameters:
userPrivateKey
: The user's private key.litNetwork
: The Lit network key.
static async init(userPrivateKey: string, litNetwork: LIT_NETWORKS_KEYS): Promise<LitTester>
- Initializes a new instance of the
LitTester
class and initializes the PKP. - Parameters:
userPrivateKey
: The user's private key.litNetwork
: The Lit network key.
- Returns: The initialized
LitTester
instance.
async initializePKP(): Promise<void>
- Initializes the PKP.
- Returns: Nothing.
async testLitAction(params: TestLitActionParams): Promise<any>
- Tests a Lit action.
- Parameters:
params
: An object containinglitActionCode
andparams
.
- Returns: The result of the tested action.
enum FlagForLitTxn {
SOL,
CUSTOM,
}
- Enum for flags used in Lit transactions.
- Values:
SOL
: Indicates a SOL transaction.CUSTOM
: Indicates a custom token transaction.
interface PKP {
tokenId: string;
publicKey: string;
ethAddress: string;
}
- Interface for a PKP (Programmable Key Pair).
interface WK {
pkpAddress: string;
id: string;
generatedPublicKey: string;
}
- Interface for a Wrapped Key (WK).
interface AddPermittedActionParams {
userPrivateKey: string;
pkpTokenId: string;
litActionCode: string;
pinataAPIKey: string;
}
- Interface for parameters used in adding a permitted action.
interface UploadViaPinataParams {
pinataAPIKey: string;
litActionCode: string;
}
- Interface for parameters used in uploading via Pinata.
interface GetDecipheringDetailsParams {
userPrivateKey: string;
pkp: PKP;
wk: WK;
}
- Interface for parameters used in deciphering details.
interface CreatePKPWithLitActionParams {
userPrivateKey: string;
litActionCode: string;
pinataAPIKey: string;
}
- Interface for parameters used in creating a PKP with a Lit action.
interface ExecuteLitActionParams {
userPrivateKey: string;
pkpPublicKey: string;
litActionIpfsCid?: string;
litActionCode?: string;
params?: Object;
}
- Interface for parameters used in executing a Lit action.
interface ConditionalSigningOnSolanaParams {
userPrivateKey: string;
litTransaction: any;
broadcastTransaction: boolean;
conditionalLogic: string;
pkp?: PKP;
wk?: WK;
params?: Object;
}
- Interface for parameters used in conditional signing on Solana.
interface ExecuteCustomActionOnSolanaParams {
userPrivateKey: string;
litActionCode: string;
pkp?: PKP;
wk?: WK;
params?: Object;
}
- Interface for parameters used in executing a custom action on Solana.
interface ExecuteSolanaAgentKitParams {
userPrivateKey: string;
MESSAGE: string;
RPC_URL: string;
OPENAI_API_KEY: string;
pkp?: PKP;
wk?: WK;
}
- Interface for parameters used in executing the Solana Agent Kit.
interface CreateSerializedLitTxnParams {
toAddress: string;
amount: number;
network: Cluster;
flag: FlagForLitTxn;
tokenMintAddress?: string;
wk?: WK;
}
- Interface for parameters used in creating a serialized Lit transaction.
interface SendSolanaWKTxnWithSolParams {
amount: number;
toAddress: string;
network: Cluster;
broadcastTransaction: boolean;
userPrivateKey: string;
wk?: WK;
pkp?: PKP;
}
- Interface for parameters used in sending a Solana WK transaction with SOL.
interface SendSolanaWKTxnWithCustomTokenParams {
tokenMintAddress: string;
amount: number;
toAddress: string;
network: Cluster;
broadcastTransaction: boolean;
userPrivateKey: string;
wk?: WK;
pkp?: PKP;
}
- Interface for parameters used in sending a Solana WK transaction with a custom token.
interface TestLitActionParams {
litActionCode: string;
params: Object;
}
- Interface for parameters used in testing a Lit action.
Using Lit to create a Solana Key and send a Txn with it, an Ethereum private key is used as an auth method for generating signatures with a newly created Solana Key.
import { LitWrapper } from "lit-wrapper-sdk";
import "dotenv/config";
const litWrapper = new LitWrapper("datil-dev")
async function generateSolanaWallet() {
const res = await litWrapper.createSolanaWK(ETHEREUM_PRIVATE_KEY);
console.log("Solana Public Key", res.wkInfo.generatedPublicKey);
}
async function sendSolTxn() {
const signedTx = await litWrapper.sendSolanaWKTxnWithSol({
amount: 0.0022 * Math.pow(10, 9),
toAddress: "BTBPKRJQv7mn2kxBBJUpzh3wKN567ZLdXDWcxXFQ4KaV",
network: "mainnet-beta",
broadcastTransaction: true,
userPrivateKey: ETHEREUM_PRIVATE_KEY,
wkResponse: res.wkInfo,
pkp: res.pkpInfo,
});
console.log("Transaction Hash: ", signedTx);
}
async function sendBONKTxn() {
const signedTx = await litWrapper.sendSolanaWKTxnWithCustomToken({
tokenMintAddress: "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263", // BONK MINT TOKEN
amount: 4 * Math.pow(10, 5),
toAddress: "BTBPKRJQv7mn2kxBBJUpzh3wKN567ZLdXDWcxXFQ4KaV",
network: "mainnet-beta",
broadcastTransaction: true,
userPrivateKey: ETHEREUM_PRIVATE_KEY,
wkResponse: res.wkInfo,
pkp: res.pkpInfo,
});
console.log("Transaction Hash: ", signedTx);
}
Checks against a conditional logic and only creates signatures for a specified transaction when the condition is satisfies
async function createLitActionAndSignSolanaTxn() {
const response = await litWrapper.createSolanaWK(ETHEREUM_PRIVATE_KEY);
console.log("Solana Public Key", response?.wkInfo.generatedPublicKey);
const conditionLogic = `
const url = "https://api.weather.gov/gridpoints/TOP/31,80/forecast";
const resp = await fetch(url).then((response) => response.json());
const temp = resp.properties.periods[0].temperature;
console.log(temp);
// only sign if the temperature is below 60
if (temp < 60) {
createSignatureWithAction();
}`;
const txn = await litWrapper.createSerializedLitTxn({
wk: response?.wkInfo,
toAddress: "BTBPKRJQv7mn2kxBBJUpzh3wKN567ZLdXDWcxXFQ4KaV",
amount: 0.004 * Math.pow(10, 9),
network: "mainnet-beta",
flag: FlagForLitTxn.SOL,
});
const checkResult = await litWrapper.conditionalSigningOnSolana({
userPrivateKey: ETHEREUM_PRIVATE_KEY,
litTransaction: txn,
conditionLogic,
broadcastTransaction: true,
wk: response?.wkInfo,
pkp: response?.pkpInfo,
});
console.log(checkResult);
}
async function executeCustomLitAction() {
const response = await litWrapper.createSolanaWK(ETHEREUM_PRIVATE_KEY);
const litActionCode = `
const go = async () => {
try {
const callAI = await LitActions.runOnce({
waitForResponse: true, name: "Lit Actions Test" },
async () => {
const messages = [
{ role: "system", content: "You are an AI assistant. Only answer with a single sentence." },
];
const response = await fetch(
"https://api.openai.com/v1/chat/completions",
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: \`Bearer \${apiKey}\`,
},
body: JSON.stringify({ model: "gpt -4o-mini", messages }),
});
const json = await response.json();
console.log(json);
return json.choices[0].message;
});
console.log(callAI);
Lit.Actions.setResponse({ response: callAI });
} catch (error) {
Lit.Actions.setResponse({ response: error.message });
}
}; go();`;
const result = await litWrapper.executeCustomActionOnSolana({
userPrivateKey: ETHEREUM_PRIVATE_KEY,
litActionCode,
pkp: response?.pkpInfo!,
wk: response?.wkInfo!,
params: {
apiKey: process.env.OPEN_AI_API_KEY,
},
});
console.log(result);
}
Create a key, Upload Lit Action to IPFS, Permit on IPFS and Execute the action.
import { LitWrapper } from "lit-wrapper-sdk";
import "dotenv/config";
const litWrapper = new LitWrapper("datil-dev");
async function createKeyAndExecuteAction() {
const _litActionCode = async () => {
try {
const sigShare = await Lit.Actions.ethPersonalSignMessageEcdsa({
message: dataToSign,
publicKey: pkpPublicKey,
sigName,
});
Lit.Actions.setResponse({ response: sigShare });
} catch (error) {
Lit.Actions.setResponse({ response: error.message });
}
};
const litActionCode = `(${_litActionCode.toString()})();`;
const { pkp, ipfsCID } = await litWrapper.createPKPWithLitAction(
process.env.ETHEREUM_PRIVATE_KEY,
litActionCode,
process.env.PINATA_API_KEY
);
const params = {
dataToSign: ethers.utils.arrayify(
ethers.utils.keccak256([1, 2, 3, 4, 5])
),
sigName: "sig1",
}
const response = litWrapper.executeLitAction(usePrivateKey, pkp, ipfsCID, params);
console.log(response)
}
Instantly create a Lit Action and test its execution over Lit Network.
async function testAction() {
if (!process.env.ETHEREUM_PRIVATE_KEY) {
throw new Error("ETHEREUM_PRIVATE_KEY is not set");
}
const _litActionCode = async () => {
try {
const sigShare = await Lit.Actions.ethPersonalSignMessageEcdsa({
message: dataToSign,
publicKey: pkpPublicKey,
sigName,
});
Lit.Actions.setResponse({ response: sigShare });
} catch (error) {
Lit.Actions.setResponse({ response: error.message });
}
};
const litActionCode = `(${_litActionCode.toString()})();`;
const tester = await LitTester.init(
process.env.ETHEREUM_PRIVATE_KEY,
"datil-dev"
);
const params = [
{
dataToSign: ethers.utils.arrayify(
ethers.utils.keccak256([1, 2, 3, 4, 5])
),
sigName: "sig1",
}
];
const results = await tester.testLitAction(litActionCode, params[0]);
console.log("Test Results: ", results);
}