Functions

createAuthManager(authManagerParams)

Parameters

param.storage
LitAuthStorageProvider
required
The storage provider used by the Auth Manager.
import { createAuthManager, storagePlugins } from "@lit-protocol/auth";
const authManager = createAuthManager({
  storage: storagePlugins.localStorageNode({
    appName: "my-app",
    networkName: "naga-local",
    storagePath: "./lit-auth-local",
  }),
});

Returns

AuthManager
object
Complete AuthManager object with all returned methods.

createEoaAuthContext

Create an EOA (Externally Owned Account) auth context adapter for signing and session issuance.

Parameters

params
object

Returns

EoaAuthContext
object

Example

import { createAuthManager, storagePlugins } from '@lit-protocol/auth';

const authManager = createAuthManager({
  storage: storagePlugins.localStorageNode({
    appName: 'my-app',
    networkName: 'naga-local',
    storagePath: './lit-auth-local'
  })
});

const eoaAuthContext = await authManager.createEoaAuthContext({
  config: { account: myViemAccount },
  authConfig: {
    statement: 'I authorize this action.',
    domain: 'example.com',
    resources: [ ['lit-action-execution','*'], ['pkp-signing','*'] ],
    expiration: new Date(Date.now()+1000*60*15).toISOString()
  },
  litClient
});

// Use with litClient
await litClient.executeJs({ code: '...', authContext: eoaAuthContext });

createPkpAuthContext

Create a PKP auth context adapter using a user’s AuthData and a PKP public key.

Parameters

params
object

Returns

PkpAuthContext
object

Example

import { ViemAccountAuthenticator } from '@lit-protocol/auth';

const authData = await ViemAccountAuthenticator.authenticate(myViemAccount);
const pkpAuthContext = await authManager.createPkpAuthContext({
  authData,
  pkpPublicKey: myPkp.publicKey,
  authConfig: {
    resources: [ ['pkp-signing','*'], ['lit-action-execution','*'] ],
    expiration: new Date(Date.now()+1000*60*30).toISOString()
  },
  litClient
});

// Example: sign via PKP Viem account integration
const pkpAccount = await litClient.getPkpViemAccount({
  pkpPublicKey: myPkp.publicKey,
  authContext: pkpAuthContext,
  chainConfig: myChain
});

createCustomAuthContext

Create a Custom auth context that validates using a Lit Action (by inline code or IPFS CID).

Parameters

params
object

Returns

CustomAuthContext
object

Example

const customAuthContext = await authManager.createCustomAuthContext({
  pkpPublicKey: evePkp.publicKey,
  authConfig: {
    resources: [ ['pkp-signing','*'], ['lit-action-execution','*'] ],
    expiration: new Date(Date.now()+1000*60*30).toISOString()
  },
  litClient,
  customAuthParams: {
    litActionIpfsId: 'QmYourLitActionCID',
    jsParams: { 
      userId: 'eve',
      password: 'password'
  }
});

await litClient.executeJs({ ipfsId: 'QmYourLitActionCID', authContext: customAuthContext });