UNPKG

@abstract-foundation/agw-client

Version:
26 lines 1.3 kB
import { BaseError, } from "viem"; import { SESSION_KEY_VALIDATOR_ADDRESS } from "../constants.js"; import { encodeSessionWithPeriodIds, getPeriodIdsForTransaction, } from "../sessions.js"; import { isSmartAccountDeployed } from "../utils.js"; import { signTransaction } from "./signTransaction.js"; export async function signTransactionForSession(client, signerClient, publicClient, parameters, session, customPaymasterHandler = undefined) { const isDeployed = await isSmartAccountDeployed(publicClient, client.account.address); if (!isDeployed) { throw new BaseError("Smart account not deployed"); } const selector = parameters.data ? `0x${parameters.data.slice(2, 10)}` : undefined; if (!parameters.to) { throw new BaseError("Transaction to field is not specified"); } return await signTransaction(client, signerClient, publicClient, parameters, SESSION_KEY_VALIDATOR_ADDRESS, { [SESSION_KEY_VALIDATOR_ADDRESS]: encodeSessionWithPeriodIds(session, getPeriodIdsForTransaction({ sessionConfig: session, target: parameters.to, selector, timestamp: BigInt(Math.floor(Date.now() / 1000)), })), }, customPaymasterHandler); } //# sourceMappingURL=signTransactionForSession.js.map