import { EIP1193Events, EIP1193RequestFn, EIP1474Methods, TransactionRequest, SendTransactionParameters, Hex, SignTypedDataParameters, Chain, Transport } from 'viem';
import { PublicZksyncRpcSchema, SendEip712TransactionParameters } from 'viem/zksync';

/**
 * Options for creating an EIP1193 provider for a Privy cross-app wallet
 */
interface CreatePrivyWalletProviderOptions {
    /**
     * The Privy app ID of the cross-app wallet provider.
     */
    providerAppId: string;
    /**
     * The chain ID to use for the provider. If not provided, the chain ID will default to the first chain in the `chains` array.
     */
    chainId?: number;
    /**
     * The chains that the provider will support.
     */
    chains: readonly [Chain, ...Chain[]];
    /**
     * The transports to use for the provider. If not provided, the provider will default to using HTTP.
     */
    transports?: Record<number, Transport>;
    /**
     * @experimental Interfaces are subject to change in the future.
     * Informs the provider to use the smart wallet and
     * transforms the provider functions.
     */
    smartWalletMode?: boolean;
    /**
     * @experimental Interfaces are subject to change in the future.
     *
     * Configure the default amount of time before a wallet request is closed with
     * a timeout error.
     */
    defaultPopupTimeout?: number;
    /**
     * Override the default connect URL for the cross-app wallet provider.
     * When set, this URL will be used instead of the URL returned by the API.
     */
    overrideConnectUrl?: string;
    /**
     * Override the default transact URL for the cross-app wallet provider.
     * When set, this URL will be used instead of the URL returned by the API.
     */
    overrideTransactUrl?: string;
}
type AdditionalRpcMethods = [
    {
        /**
         * @description Returns an estimate of the transaction fee for a given transaction
         *
         */
        Method: 'zks_estimateFee';
        Parameters: [transaction: TransactionRequest];
        ReturnType: PublicZksyncRpcSchema[0]['ReturnType'];
    }
];
type CustomRpcMethods = [
    {
        /**
         * @description Creates, signs, and sends a new transaction to the network
         * @link https://eips.ethereum.org/EIPS/eip-1474
         * @example
         * provider.request({ method: 'privy_sendSmartWalletTx', params: [{ from: '0x...', to: '0x...', value: '0x...' }] })
         * // => '0x...'
         */
        Method: 'privy_sendSmartWalletTx';
        Parameters: [transaction: SendEip712TransactionParameters] | [transaction: SendTransactionParameters];
        ReturnType: Hex;
    },
    {
        /**
         * @description Signs a transaction, for the developer to send to the network
         * @link https://eips.ethereum.org/EIPS/eip-1474
         * @example
         * provider.request({ method: 'privy_signSmartWalletTx', params: [{ from: '0x...', to: '0x...', value: '0x...' }] })
         * // => '0x...'
         */
        Method: 'privy_signSmartWalletTx';
        Parameters: [transaction: SendEip712TransactionParameters] | [transaction: SendTransactionParameters];
        ReturnType: Hex;
    },
    {
        /**
         * @description Signs a message using the smart wallet
         * @link https://eips.ethereum.org/EIPS/eip-1474
         * @example
         * provider.request({ method: 'privy_signSmartWalletMessage', params: ['Test message'] })
         * // => '0x...'
         */
        Method: 'privy_signSmartWalletMessage';
        Parameters: [message: string] | [message: {
            raw: Hex;
        }];
        ReturnType: Hex;
    },
    {
        /**
         * @description Signs a typed data message using the smart wallet
         * @link https://eips.ethereum.org/EIPS/eip-1474
         * @example
         * provider.request({ method: 'privy_signSmartWalletTypedData', params: ['0xAddress', { from: '0x...', to: '0x...', value: '0x...' }] })
         * // => '0x...'
         */
        Method: 'privy_signSmartWalletTypedData';
        Parameters: [address: Hex, typedData: SignTypedDataParameters];
        ReturnType: Hex;
    }
];
type EIP1474MethodsExtended = [...EIP1474Methods, ...AdditionalRpcMethods, ...CustomRpcMethods];
type RequestFn = EIP1193RequestFn<EIP1474MethodsExtended>;
type PrivyEIP1193Provider = EIP1193Events & {
    request: RequestFn;
};
/**
 * @experimental
 *
 * Creates a _mostly_ EIP1193 compatible provider for a Privy cross-app wallet.
 *
 * @param opts {CreatePrivyWalletProviderOptions} Options for creating the provider.
 *
 * @returns A Privy cross-app wallet provider.
 */
declare const toPrivyWalletProvider: (opts: CreatePrivyWalletProviderOptions) => PrivyEIP1193Provider;

type ConnectionOpts = {
    smartWalletMode?: boolean;
};

interface CreatePrivyCrossAppClientOptions {
    providerAppId: string;
    chains: readonly [Chain, ...Chain[]];
    chainId?: number;
    connectionOpts?: ConnectionOpts;
    /**
     * @experimental Interfaces are subject to change in the future.
     *
     * Configure the default amount of time before a wallet request is closed with
     * a timeout error.
     */
    defaultPopupTimeout?: number;
    /**
     * Override the default connect URL for the cross-app wallet provider.
     * When set, this URL will be used instead of the URL returned by the API.
     */
    overrideConnectUrl?: string;
    /**
     * Override the default transact URL for the cross-app wallet provider.
     * When set, this URL will be used instead of the URL returned by the API.
     */
    overrideTransactUrl?: string;
}
declare const createPrivyCrossAppClient: ({ providerAppId, chains, chainId, apiUrl, connectionOpts, defaultPopupTimeout, overrideConnectUrl, overrideTransactUrl, }: CreatePrivyCrossAppClientOptions) => PrivyCrossAppClient;
declare class PrivyCrossAppClient {
    providerAppId: string;
    private _apiUrl;
    /**
     * The chain ID the client should use.
     */
    private chainId;
    private _providerDetailsLoaded;
    private _providerConnectUrl;
    private _providerTransactUrl;
    private readonly _connectionOpts;
    /**
     * The chains that the provider will support.
     */
    private readonly chains;
    private _sharedSecret;
    private _publicKey;
    private _address;
    private _defaultPopupTimeout;
    private _overrideConnectUrl;
    private _overrideTransactUrl;
    constructor(providerAppId: string, chains: readonly [Chain, ...Chain[]], chainId?: number, apiUrl?: string, connectionOpts?: ConnectionOpts, defaultPopupTimeout?: number, overrideConnectUrl?: string, overrideTransactUrl?: string);
    private get STORAGE_CONNECTION_KEY();
    private get STORAGE_CHAIN_ID_KEY();
    private loadProviderDetails;
    getProviderConnectUrl(): Promise<string>;
    getProviderTransactUrl(): Promise<string>;
    clearConnection(): void;
    get chain(): Chain;
    get address(): `0x${string}` | undefined;
    requestConnection(): Promise<void>;
    switchChain({ id }: {
        id: number;
    }): void;
    sendRequest(method: string, params: any): Promise<string>;
}

export { createPrivyCrossAppClient, toPrivyWalletProvider };
export type { PrivyEIP1193Provider };
