import { OutpointString, CreateActionOutput, HexString } from '../wallet/Wallet.interfaces.js';
import { KVStoreConfig, KVStoreQuery, KVStoreEntry, KVStoreGetOptions, KVStoreSetOptions, KVStoreRemoveOptions } from './types.js';
/**
 * Implements a global key-value storage system which uses an overlay service to track key-value pairs.
 * Each key-value pair is represented by a PushDrop token output.
 * Allows getting, setting, and removing key-value pairs with optional fetching by protocolID and history tracking.
 */
export declare class GlobalKVStore {
    /**
     * The wallet interface used to create transactions and perform cryptographic operations.
     * @readonly
     */
    private readonly wallet;
    /**
     * Configuration for the KVStore instance containing all runtime options.
     * @private
     * @readonly
     */
    private readonly config;
    /**
     * Historian instance used to extract history from transaction outputs.
     * @private
     */
    private readonly historian;
    /**
     * Lookup resolver used to query the overlay for transaction outputs.
     * @private
     */
    private readonly lookupResolver;
    /**
     * Topic broadcaster used to broadcast transactions to the overlay.
     * @private
     */
    private readonly topicBroadcaster;
    /**
     * A map to store locks for each key to ensure atomic updates.
     * @private
     */
    private readonly keyLocks;
    /**
     * Cached user identity key
     * @private
     */
    private cachedIdentityKey;
    /**
     * Creates an instance of the GlobalKVStore.
     *
     * @param {KVStoreConfig} [config={}] - Configuration options for the KVStore. Defaults to empty object.
     * @param {WalletInterface} [config.wallet] - Wallet to use for operations. Defaults to WalletClient.
     * @throws {Error} If the configuration contains invalid parameters.
     */
    constructor(config?: KVStoreConfig);
    /**
     * Retrieves data from the KVStore.
     * Can query by key+controller (single result), protocolID, controller, or key (multiple results).
     *
     * @param {KVStoreQuery} query - Query parameters sent to overlay
     * @param {KVStoreGetOptions} [options={}] - Configuration options for the get operation
     * @returns {Promise<KVStoreEntry | KVStoreEntry[] | undefined>} Single entry for key+controller queries, array for all other queries
     */
    get(query: KVStoreQuery, options?: KVStoreGetOptions): Promise<KVStoreEntry | KVStoreEntry[] | undefined>;
    /**
     * Ensures lookup pagination and ordering options are only used with a real KV selector.
     *
     * @param {KVStoreQuery} query - Query parameters sent to overlay.
     * @throws {Error} If the query does not include a valid selector.
     */
    private validateQuerySelectors;
    /**
     * Sets a key-value pair. The current user (wallet identity) becomes the controller.
     *
     * @param {string} key - The key to set (user computes this however they want)
     * @param {string} value - The value to store
     * @param {KVStoreSetOptions} [options={}] - Configuration options for the set operation
     * @returns {Promise<OutpointString>} The outpoint of the created token
     */
    set(key: string, value: string, options?: KVStoreSetOptions): Promise<OutpointString>;
    /**
     * Removes the key-value pair associated with the given key from the overlay service.
     *
     * @param {string} key - The key to remove.
     * @param {CreateActionOutput[] | undefined} [outputs=undefined] - Additional outputs to include in the removal transaction.
     * @param {KVStoreRemoveOptions} [options=undefined] - Optional parameters for the removal operation.
     * @returns {Promise<HexString>} A promise that resolves to the txid of the removal transaction if successful.
     * @throws {Error} If the key is invalid.
     * @throws {Error} If the key does not exist in the store.
     * @throws {Error} If the overlay service is unreachable or the transaction fails.
     * @throws {Error} If there are existing tokens that cannot be unlocked.
     */
    remove(key: string, outputs?: CreateActionOutput[], options?: KVStoreRemoveOptions): Promise<HexString>;
    /**
     * Queues an operation on a specific key to ensure atomic updates.
     * Prevents concurrent operations on the same key from interfering with each other.
     *
     * @param {string} key - The key to queue an operation for.
     * @returns {Promise<Array<(value: void | PromiseLike<void>) => void>>} The lock queue for cleanup.
     * @private
     */
    private queueOperationOnKey;
    /**
     * Finishes an operation on a key and resolves the next waiting operation.
     *
     * @param {string} key - The key to finish the operation for.
     * @param {Array<(value: void | PromiseLike<void>) => void>} lockQueue - The lock queue from queueOperationOnKey.
     * @private
     */
    private finishOperationOnKey;
    /**
     * Helper function to fetch and cache user identity key
     *
     * @returns {Promise<PubKeyHex>} The identity key of the current user
     * @private
     */
    private getIdentityKey;
    /**
     * Queries the overlay service for KV entries.
     *
     * @param {KVStoreQuery} query - Query parameters sent to overlay
     * @param {KVStoreGetOptions} options - Configuration options for the query
     * @returns {Promise<KVStoreEntry[]>} Array of matching KV entries
     * @private
     */
    private queryOverlay;
    /**
     * Submits a transaction to an overlay service using TopicBroadcaster.
     * Broadcasts the transaction to the configured topics for network propagation.
     *
     * @param {Transaction} transaction - The transaction to broadcast.
     * @returns {Promise<BroadcastResponse | BroadcastFailure>} The broadcast result.
     * @throws {Error} If the broadcast fails or the network is unreachable.
     * @private
     */
    private submitToOverlay;
}
export default GlobalKVStore;
//# sourceMappingURL=GlobalKVStore.d.ts.map