import { type AuthorizationRequest, type SignedAuthorization } from 'viem'; import { type OpenfortError } from '../../errors/base.js'; import type { OpenfortHookOptions } from '../../types.js'; export type SignAuthorizationParameters = AuthorizationRequest; export type SignAuthorizationReturnType = SignedAuthorization; /** * The resolved result of an EIP-7702 authorization request. * * @example * ```ts * import type { SignAuthorizationResult } from '@openfort/react' * * function readAuthorization(result: SignAuthorizationResult) { * if (result.status === 'error') return result.error.shortMessage * return result.authorization.address * } * ``` */ export type SignAuthorizationResult = { status: 'success'; authorization: SignAuthorizationReturnType; } | { status: 'error'; error: OpenfortError; }; type SignAuthorizationSuccess = Extract; /** * Per-request signing controls and lifecycle callbacks. * * @example * ```ts * import type { SignAuthorizationOptions } from '@openfort/react' * * const options: SignAuthorizationOptions = { * hashMessage: false, * onError: (error) => console.error(error.shortMessage), * } * ``` */ export type SignAuthorizationOptions = OpenfortHookOptions & { hashMessage?: boolean; arrayifyMessage?: boolean; /** * Permits `chainId: 0`, which authorises the delegation on every EIP-7702 * chain and never expires. Off by default: it is signed once and cannot be * narrowed afterwards. */ allowAllChains?: boolean; }; /** * Hook-level lifecycle callbacks for EIP-7702 signing. * * @example * ```ts * import type { Use7702AuthorizationOptions } from '@openfort/react' * * const options: Use7702AuthorizationOptions = { * onSuccess: ({ authorization }) => console.log(authorization.address), * } * ``` */ export type Use7702AuthorizationOptions = OpenfortHookOptions; /** * Hook for signing EIP-7702 wallet authorizations * * This hook uses the embedded Openfort client to sign authorization payloads * prepared via viem while keeping private key management inside the SDK. * Calls resolve to either `{ authorization }` or `{ error }`. * * @returns Helper with a `signAuthorization` function that signs authorizations with the active Openfort wallet * * @example * ```tsx * import { use7702Authorization } from '@openfort/react' * * function AuthorizationButton() { * const { signAuthorization, isLoading, error } = use7702Authorization() * * const authorize = async () => { * const result = await signAuthorization({ * contractAddress: '0x1111111111111111111111111111111111111111', * chainId: 8453, * nonce: 1, * }) * if (result.status === 'error') return * console.log(result.authorization) * } * * return * } * ``` */ export declare function use7702Authorization(hookOptions?: Use7702AuthorizationOptions): { isLoading: boolean; isError: boolean; isSuccess: boolean; error: OpenfortError | null | undefined; signAuthorization: (parameters: SignAuthorizationParameters, options?: SignAuthorizationOptions) => Promise; data: SignAuthorizationReturnType | null; reset: () => void; }; export {};