import { EventTemplate, NostrEvent } from "nostr-tools";
import { Subscription } from "rxjs";
import { ConnectRequestParams, ConnectResponseResults, NostrConnectMethod, NostrConnectResponse, NostrConnectURI } from "../helpers/nostr-connect.js";
import { ISigner, NostrConnectionMethodsOptions, NostrPool, NostrPublishMethod, NostrSubscriptionMethod } from "../interop.js";
export interface ProviderAuthorization {
    /** A method used to accept or reject `connect` requests */
    onConnect?: (client: string, permissions: string[]) => boolean | Promise<boolean>;
    /** A method used to accept or reject `sign_event` requests */
    onSignEvent?: (draft: EventTemplate, client: string) => boolean | Promise<boolean>;
    /** A method used to accept or reject `nip04_encrypt` requests */
    onNip04Encrypt?: (pubkey: string, plaintext: string, client: string) => boolean | Promise<boolean>;
    /** A method used to accept or reject `nip04_decrypt` requests */
    onNip04Decrypt?: (pubkey: string, ciphertext: string, client: string) => boolean | Promise<boolean>;
    /** A method used to accept or reject `nip44_encrypt` requests */
    onNip44Encrypt?: (pubkey: string, plaintext: string, client: string) => boolean | Promise<boolean>;
    /** A method used to accept or reject `nip44_decrypt` requests */
    onNip44Decrypt?: (pubkey: string, ciphertext: string, client: string) => boolean | Promise<boolean>;
}
export type NostrConnectProviderOptions = ProviderAuthorization & NostrConnectionMethodsOptions & {
    /** The relays to communicate over */
    relays: string[];
    /** The signer to use for signing events and encryption */
    upstream: ISigner;
    /** Optional signer for provider identity */
    signer?: ISigner;
    /** A random secret used to authorize clients to connect */
    secret?: string;
    /** Callback for when a client connects (receives a `connect` request) */
    onClientConnect?: (client: string) => any;
    /** Callback for when a client disconnects (previously connected and the provider stops) */
    onClientDisconnect?: (client: string) => void;
};
export declare class NostrConnectProvider implements ProviderAuthorization {
    /** A fallback method to use for subscriptionMethod if none is passed in when creating the provider */
    static subscriptionMethod: NostrSubscriptionMethod | undefined;
    /** A fallback method to use for publishMethod if none is passed in when creating the provider */
    static publishMethod: NostrPublishMethod | undefined;
    /** A fallback pool to use if none is pass in when creating the provider */
    static pool: NostrPool | undefined;
    /** A method that is called when an event needs to be published */
    protected publishMethod: NostrPublishMethod;
    /** The active nostr subscription */
    protected subscriptionMethod: NostrSubscriptionMethod;
    /** Internal logger */
    protected log: import("debug").Debugger;
    /** A set of nostr requests that have been seen */
    protected seen: Set<string>;
    /** The main signer for the actual signing operations */
    upstream: ISigner;
    /** The identity signer (provider's identity) */
    signer: ISigner;
    /** Whether the provider is listening for events */
    listening: boolean;
    /** The connected client's public key */
    client?: string;
    /** The secret used to authorize clients to connect */
    secret?: string;
    /** Relays to communicate over */
    readonly relays: string[];
    /** Whether a client is connected (received a `connect` request) */
    connected: boolean;
    /** Callbacks */
    onClientConnect?: (client: string) => any;
    onClientDisconnect?: (client: string) => any;
    /** A method used to accept or reject `connect` requests */
    onConnect?: (client: string, permissions: string[]) => boolean | Promise<boolean>;
    /** A method used to accept or reject `sign_event` requests */
    onSignEvent?: (draft: EventTemplate, client: string) => boolean | Promise<boolean>;
    /** A method used to accept or reject `nip04_encrypt` requests */
    onNip04Encrypt?: (pubkey: string, plaintext: string, client: string) => boolean | Promise<boolean>;
    /** A method used to accept or reject `nip04_decrypt` requests */
    onNip04Decrypt?: (pubkey: string, ciphertext: string, client: string) => boolean | Promise<boolean>;
    /** A method used to accept or reject `nip44_encrypt` requests */
    onNip44Encrypt?: (pubkey: string, plaintext: string, client: string) => boolean | Promise<boolean>;
    /** A method used to accept or reject `nip44_decrypt` requests */
    onNip44Decrypt?: (pubkey: string, ciphertext: string, client: string) => boolean | Promise<boolean>;
    constructor(options: NostrConnectProviderOptions);
    /** The currently active REQ subscription */
    protected req?: Subscription;
    /** Updates the relay subscription to listen for request events */
    protected updateSubscription(): Promise<void>;
    /**
     * Start the provider
     * @param request - An inital `connect` request to respond to or a {@link NostrConnectURI}
     */
    start(request?: NostrEvent | NostrConnectURI | string): Promise<void>;
    /** Stop the provider */
    stop(): Promise<void>;
    private waitingPromise;
    /** Wait for a client to connect */
    waitForClient(abort?: AbortSignal): Promise<string>;
    /** Call this method with incoming events */
    handleEvent(event: NostrEvent): Promise<void>;
    /** Handle an initial NostrConnectURI */
    handleNostrConnectURI(uri: NostrConnectURI | string): Promise<void>;
    /** Handle connect request */
    protected handleConnect(client: string, [target, secret, permissionsStr]: ConnectRequestParams[NostrConnectMethod.Connect]): Promise<ConnectResponseResults[NostrConnectMethod.Connect]>;
    /** Handle sign event request */
    protected handleSignEvent([eventJson]: ConnectRequestParams[NostrConnectMethod.SignEvent]): Promise<ConnectResponseResults[NostrConnectMethod.SignEvent]>;
    /** Handle NIP-04 encryption */
    protected handleNip04Encrypt([pubkey, plaintext,]: ConnectRequestParams[NostrConnectMethod.Nip04Encrypt]): Promise<ConnectResponseResults[NostrConnectMethod.Nip04Encrypt]>;
    /** Handle NIP-04 decryption */
    protected handleNip04Decrypt([pubkey, ciphertext,]: ConnectRequestParams[NostrConnectMethod.Nip04Decrypt]): Promise<ConnectResponseResults[NostrConnectMethod.Nip04Decrypt]>;
    /** Handle NIP-44 encryption */
    protected handleNip44Encrypt([pubkey, plaintext,]: ConnectRequestParams[NostrConnectMethod.Nip44Encrypt]): Promise<ConnectResponseResults[NostrConnectMethod.Nip44Encrypt]>;
    /** Handle NIP-44 decryption */
    protected handleNip44Decrypt([pubkey, ciphertext,]: ConnectRequestParams[NostrConnectMethod.Nip44Decrypt]): Promise<ConnectResponseResults[NostrConnectMethod.Nip44Decrypt]>;
    /**
     * Send a response to the client
     * @param clientOrRequest - The client pubkey or request event
     * @param requestId - The id of the request
     * @param result - The result of the request
     */
    protected sendResponse<T extends NostrConnectMethod>(clientOrRequest: NostrEvent | string, requestId: string, result: ConnectResponseResults[T]): Promise<void>;
    /** Send an error response to the client */
    protected sendErrorResponse(event: NostrEvent, requestId: string, error: string): Promise<void>;
    /** Send an encrypted message to the client */
    protected sendMessage(clientOrRequest: string | NostrEvent, message: NostrConnectResponse<any>): Promise<void>;
    /** Get the connection string that clients can use to connect */
    getBunkerURI(): Promise<string>;
}
