Skip to content

Use Lit Protocol with ZeroDev

Lit Protocol is distributed cryptography for signing, encryption, and compute. A generalizable key management network, Lit provides you with a set of tools for managing sovereign identities on the open Web.

Set up

To use Lit with ZeroDev, first create an application that integrates with Lit.

  • Refer to the Lit documentation site for instructions on setting up an application with the Lit.
  • For a quick start, Lit provides examples, available here.

Integration

Integrating ZeroDev with Lit is straightforward after setting up the project. Lit provides an Externally Owned Account (EOA) wallet to use as a signer with Kernel.

Create the pkpWallet

After following the Lit documentation, you will have access to a pkpWallet. An example is shown below:

import { LitAbility, LitActionResource } from "@lit-protocol/auth-helpers";
import { LitNodeClient } from "@lit-protocol/lit-node-client";
import { PKPEthersWallet } from "@lit-protocol/pkp-ethers";
import { AuthCallbackParams } from "@lit-protocol/types";
 
const POLYGON_MUMBAI_RPC_URL = "<YOUR RPC URL HERE>";
const PKP_PUBLIC_KEY = "<YOUR PKP PUBLIC KEY>";
 
const litNodeClient = new LitNodeClient({
  litNetwork: "cayenne",
  debug: false,
});
await litNodeClient.connect();
 
const resourceAbilities = [
  {
    resource: new LitActionResource("*"),
    ability: LitAbility.PKPSigning,
  },
];
 
/**
 * For provisioning keys and setting up authentication methods see documentation below
 * https://developer.litprotocol.com/v2/pkp/minting
 */
const authNeededCallback = async (params: AuthCallbackParams) => {
  const response = await litNodeClient.signSessionKey({
    sessionKey: params.sessionKeyPair,
    statement: params.statement,
    authMethods: [],
    pkpPublicKey: PKP_PUBLIC_KEY,
    expiration: params.expiration,
    resources: params.resources,
    chainId: 1,
  });
  return response.authSig;
};
 
const sessionSigs = await litNodeClient
  .getSessionSigs({
    chain: "ethereum",
    expiration: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7).toISOString(),
    resourceAbilityRequests: resourceAbilities,
    authNeededCallback,
  })
  .catch((err) => {
    console.log("error while attempting to access session signatures: ", err);
    throw err;
  });
 
const pkpWallet = new PKPEthersWallet({
  pkpPubKey: PKP_PUBLIC_KEY,
  rpc: POLYGON_MUMBAI_RPC_URL,
  controllerSessionSigs: sessionSigs,
});

Use with ZeroDev

Use the provider from Lit Protocol to create a smart account signer, which can be passed to a validator. For detailed guidance on using a validator, refer to our documentation on creating accounts.

import { signerToEcdsaValidator } from "@zerodev/ecdsa-validator"
import { KERNEL_V3_1, getEntryPoint } from "@zerodev/sdk/constants"
import { createPublicClient } from "viem";
import { polygonAmoy } from 'viem/chains';
 
const smartAccountSigner = await providerToSmartAccountSigner(pkpWallet);
 
const publicClient = createPublicClient({
  // Use your own RPC provider (e.g. Infura/Alchemy).
  transport: http('https://rpc-amoy.polygon.technology'),
  chain: polygonAmoy,
})
 
// Pass your `pkpWallet` to the validator
const ecdsaValidator = await signerToEcdsaValidator(publicClient, {
  signer: pkpWallet,
  entryPoint: getEntryPoint("0.7"),
  kernelVersion: KERNEL_V3_1
})
 
// You can now use this ECDSA Validator to create a Kernel account