UNPKG

@abstract-foundation/agw-client

Version:
81 lines 3.22 kB
import {} from 'viem'; import { writeContract } from 'viem/actions'; import { getAction } from 'viem/utils'; import { SessionKeyValidatorAbi } from '../abis/SessionKeyValidator.js'; import { SESSION_KEY_VALIDATOR_ADDRESS } from '../constants.js'; import { getSessionHash } from '../sessions.js'; /** * Function to revoke session keys from the connected Abstract Global Wallet. * * This allows you to invalidate existing session keys, preventing them from being used for future transactions. * * @example * ```tsx * import { useAbstractClient } from "@abstract-foundation/agw-react"; * * export default function RevokeSessions() { * const { data: agwClient } = useAbstractClient(); * * async function revokeSessions() { * if (!agwClient) return; * * // Revoke a single session by passing the session configuration * const { transactionHash } = await agwClient.revokeSessions({ * session: existingSession, * }); * * // Or - revoke multiple sessions at once * const { transactionHash } = await agwClient.revokeSessions({ * session: [existingSession1, existingSession2], * }); * * // Or - revoke sessions using their creation transaction hashes * const { transactionHash } = await agwClient.revokeSessions({ * session: "0x1234...", * }); * * // Or - revoke multiple sessions using their creation transaction hashes * const { transactionHash } = await agwClient.revokeSessions({ * session: ["0x1234...", "0x5678..."], * }); * * // Or - revoke multiple sessions using both session configuration and creation transaction hashes * const { transactionHash } = await agwClient.revokeSessions({ * session: [existingSession, "0x1234..."], * }); * } * } * ``` * * @param parameters - Parameters for revoking sessions * @param parameters.session - The session(s) to revoke (required). Can be provided in three formats: * - A single SessionConfig object * - A single session key creation transaction hash from createSession * - An array of SessionConfig objects and/or session key creation transaction hashes * @param parameters.paymaster - Optional paymaster address to sponsor the transaction * @param parameters.paymasterInput - Optional paymaster input data * @returns Object containing the transaction hash of the revocation transaction */ export async function revokeSessions(client, args) { const { session, ...rest } = args; const sessionHashes = typeof session === 'string' ? [session] : Array.isArray(session) ? session.map(sessionHash) : [getSessionHash(session)]; const transactionHash = await getAction(client, writeContract, 'writeContract')({ address: SESSION_KEY_VALIDATOR_ADDRESS, abi: SessionKeyValidatorAbi, functionName: 'revokeKeys', args: [sessionHashes], ...rest, }); return { transactionHash }; } function sessionHash(session) { if (typeof session === 'string') { return session; } return getSessionHash(session); } //# sourceMappingURL=revokeSessions.js.map