import { c as Address } from "../../abi-Bjd7pZee.mjs"; import { r as Hex } from "../../misc-BASHpEmW.mjs"; import { Caveat, DelegationStatus, ExecutionAction, SignedDelegation, UnsignedDelegation } from "./delegation-types.mjs"; import { DelegationInfo, Policy } from "./policy-types.mjs"; import { CompilationResult } from "./delegation-compiler.mjs"; //#region extensions/crypto/src/services/delegation-service.d.ts interface CreateDelegationInput { /** The policy to create a delegation for. */ policy: Policy; /** The user's wallet address (delegator). Override auto-detected. */ delegator?: Address; /** The agent's wallet address (delegate). Override auto-detected. */ delegate?: Address; /** Target chain ID. Defaults to Base (8453). */ chainId?: number; } interface CreateDelegationResult { /** The compilation result with delegation and caveat details. */ compilation: CompilationResult; /** Human-readable summary for user review before signing. */ summary: string; /** The chain ID for this delegation. */ chainId: number; } /** * Step 1: Compile a policy into a delegation and return it for user review. * Fetches live ETH price for USD→wei conversion when possible. * Does NOT sign or store — the user must review and approve first. */ declare function prepareDelegation(input: CreateDelegationInput): Promise; /** * Step 2: Sign a delegation using the connected wallet. * * Supports three modes: * - private_key: auto-sign via viem WalletClient.signTypedData() * - walletconnect: prompts user's external wallet for EIP-712 signature * - bankr: signs via Bankr Agent API (eth_signTypedData_v4) * * Returns the signed delegation or an error string. */ declare function signDelegation(unsigned: UnsignedDelegation, chainId: number): Promise<{ signed: SignedDelegation; } | { error: string; }>; /** * Step 3: Store a signed delegation in the policy metadata and get its hash. * Persists the full SignedDelegation struct to the delegation store (for * later redemption and on-chain revocation) and lightweight metadata on * the policy. Attempts to read the delegation hash from DelegationManager. */ declare function storeDelegation(policy: Policy, userId: string, delegation: SignedDelegation, chainId: number, unmappedRules: string[], expiresAt?: string): Promise; interface CreateSubDelegationInput { /** The parent signed delegation to derive from. */ parentDelegation: SignedDelegation; /** Parent delegation hash (used as authority for chaining). */ parentHash: Hex; /** Chain ID for the sub-delegation. */ chainId: number; /** Sub-agent's ephemeral wallet address (the new delegate). */ subAgentAddress: Address; /** Sub-agent's ephemeral private key (for signing the sub-delegation). */ subAgentPrivateKey: Hex; /** Optional: additional caveats to narrow the parent's permissions. */ additionalCaveats?: Caveat[]; /** Optional: subset of parent's caveats to include (by enforcer address). */ caveatFilter?: Address[]; } interface SubDelegationResult { /** The signed sub-delegation. */ delegation: SignedDelegation; /** Chain of delegations (parent + child) for redemption. */ chain: SignedDelegation[]; /** The parent delegation hash used as authority. */ authority: Hex; } /** * Create a sub-delegation from a parent delegation. * * Sub-delegation narrows the parent's permissions by: * 1. Setting the `authority` field to the parent delegation's hash * (creating a delegation chain) * 2. Inheriting the parent's caveats (optionally filtered) * 3. Adding additional restricting caveats (narrowing only — cannot expand) * * The parent agent (current delegate) signs the sub-delegation, granting * the sub-agent a subset of its own permissions. * * DelegationManager verifies the full chain during redemption: * User → Agent (parent) → Sub-Agent (child) * * Important: caveats can only be made MORE restrictive in sub-delegations. * The on-chain enforcers check both the parent and child caveats during * redemption. Adding a wider spending limit on the child delegation is * harmless — the parent's enforcer still caps the total. */ declare function createSubDelegation(input: CreateSubDelegationInput): Promise; /** * Revoke a delegation on-chain via DelegationManager.disableDelegation(). * Requires the delegator's wallet to send the transaction. */ declare function revokeDelegationOnChain(delegation: SignedDelegation, chainId: number): Promise<{ txHash: string; } | { error: string; }>; /** * Check delegation status on-chain. * Reads the `disabledDelegations` mapping on DelegationManager. */ declare function checkDelegationStatus(delegationHash: Hex, chainId: number): Promise; /** * Refresh delegation status for a policy and persist the result. */ declare function refreshDelegationStatus(policy: Policy, userId: string): Promise; /** * Build an EIP-7715 wallet_requestExecutionPermissions request payload. * Can be sent to wallets that support the EIP-7715 JSON-RPC method. */ declare function buildEip7715Request(compilation: CompilationResult, chainId: number): Record; /** * Revoke a delegation by policy ID. Loads the full SignedDelegation from the * delegation store and calls disableDelegation() on-chain. Also updates the * policy metadata and cleans up the stored struct. * * Returns { txHash } on success, or { error } if wallet/store/chain fails. * Falls back to local-only revocation if the full struct isn't stored. */ declare function revokeByPolicy(policy: Policy, userId: string): Promise<{ txHash: string; } | { localOnly: true; } | { error: string; }>; /** * Encode a delegation chain as permissionContext. * Accepts an array of SignedDelegations ordered from root (parent) to leaf (child). * Internally reverses to leaf-first order as required by the DelegationManager * (delegations[0].delegate must equal msg.sender). * For a single root delegation, pass a 1-element array (no reversal needed). */ declare function encodePermissionContextChain(chain: SignedDelegation[]): Hex; interface RedemptionResult { /** Transaction hash from the redeemDelegations call. */ txHash: string; /** Chain ID where the redemption was executed. */ chainId: number; } /** * Redeem a delegation to execute an action on-chain. * * This is the core execution path: the agent calls redeemDelegations() on the * DelegationManager, which verifies all caveats and executes the action through * the delegator's smart account. * * The caller must have the delegate's wallet (agent wallet) connected, since * the agent is the one redeeming. * * @param policyId - The policy whose delegation to redeem * @param action - The execution action (target, value, calldata) * @returns - Transaction hash or error */ declare function redeemDelegation(policyId: string, action: ExecutionAction): Promise; /** * Check if a delegation is available for redemption (stored and not revoked). */ declare function canRedeem(policyId: string): { ready: boolean; reason?: string; }; /** * Format delegation info as a human-readable status block. */ declare function formatDelegationStatus(meta: DelegationInfo): string; /** * Get all policies with delegations for a user. */ declare function getDelegatedPolicies(userId: string): Policy[]; /** * Get supported chains as a formatted string. */ declare function formatSupportedChains(): string; //#endregion export { CreateDelegationInput, CreateDelegationResult, CreateSubDelegationInput, RedemptionResult, SubDelegationResult, buildEip7715Request, canRedeem, checkDelegationStatus, createSubDelegation, encodePermissionContextChain, formatDelegationStatus, formatSupportedChains, getDelegatedPolicies, prepareDelegation, redeemDelegation, refreshDelegationStatus, revokeByPolicy, revokeDelegationOnChain, signDelegation, storeDelegation }; //# sourceMappingURL=delegation-service.d.mts.map