Delegated Keys Module

Manage temporary delegated keys for session-based signing

Delegated Keys Module

The delegated keys module provides functionality for creating and managing temporary delegated keys with permissions and optional expiration. Responses are controller-style; use extractResponseData(response) to get the payload. See Response and errors.

Import

import { create, findAll, findOne, update, remove } from 'cilantro-sdk/delegated-keys';
import type { CreateDelegatedKeyDto, DelegatedKeyControllerCreateResult } from 'cilantro-sdk/delegated-keys';
import { Keypair } from '@solana/web3.js';

Operations

create(walletId, options)

Create a delegated key with permissions and optional expiration. Store the keypair locally if you need to sign with it later.

publicKeystringrequired

Public key of the delegated key

expiresAtstringrequired

Expiration date (ISO 8601 format)

permissionsobjectrequired

Permissions: canSendSOL, canSendSPL, canExecuteTransaction, maxAmount (lamports), allowedTokenMints, allowedPrograms

const keypair = Keypair.generate();
const publicKey = keypair.publicKey.toString();

const result = await create(walletId, {
  publicKey,
  permissions: {
    canSendSOL: true,
    canSendSPL: true,
    canExecuteTransaction: true,
    maxAmount: '1000000000', // lamports
    allowedTokenMints: [],
    allowedPrograms: [],
  },
  expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toISOString(),
} as CreateDelegatedKeyDto);
const keyRecord = extractResponseData(result);

// Store keypair securely (e.g. localStorage keyed by keyRecord.id) for signing later

findAll(walletId)

List all delegated keys for a wallet.

const listResult = await findAll(walletId);
const keys = extractResponseData(listResult) ?? [];

findOne(walletId, keyId)

Get delegated key by ID.

const oneResult = await findOne(walletId, keyId);
const key = extractResponseData(oneResult);

update(walletId, keyId, options)

Update delegated key permissions.

await update(walletId, keyId, { permissions: { ... } });

remove(walletId, keyId)

Revoke a delegated key.

await remove(walletId, keyId);
Delegated Keys Module | Cilantro Smart Wallet Docs | Cilantro Smart Wallet