/**
 * @module lazy-init
 * Lazy Xchange initialization for zero-click onboarding.
 *
 * Defers invite acceptance and key generation until first
 * sendWithXchange/receiveWithXchange call. Enables: `Xchange.lazy({ name: 'my-service' })`
 * with no async/await at construction time.
 *
 * @example
 * ```ts
 * // Environment: XCHANGE_INVITE_CODE=XCH-abc123
 *
 * // Old way (explicit):
 * const xchange = await Xchange.create({ name: 'my-service', registry, transport });
 *
 * // New way (lazy):
 * const xchange = Xchange.lazy({ name: 'my-service' });
 * // No await, no async — xchange is constructed synchronously.
 * // Invite auto-accepts on first send/receive:
 * await xchange.sendWithXchange({ to: partnerDid, payload: data, scope: 'test' });
 * ```
 */
import { Result } from '@private.me/shared';
import type { ProgressCallback } from '@private.me/ux-helpers';
import type { XchangeKey, XchangeError } from './xchange.js';
import type { AutoAcceptConfig } from './auto-accept.js';
/**
 * Lazy Xchange configuration options.
 */
export interface LazyXchangeConfig {
    /** Service name (required). */
    name: string;
    /** Invite code or URL. If omitted, reads from XCHANGE_INVITE_CODE. */
    inviteCode?: string;
    /** Auto-accept config (optional). */
    autoAccept?: AutoAcceptConfig;
    /** Service endpoint URL (required for invite acceptance). */
    endpoint?: string;
    /** DID for this service (required for invite acceptance). */
    did?: string;
    /** Public key in base64 (required for invite acceptance). */
    publicKey?: string;
    /** X25519 public key in base64 (optional). */
    x25519PublicKey?: string;
}
/**
 * Lazy Xchange error codes.
 */
export declare enum LazyXchangeErrorCode {
    INIT_FAILED = "LAZY_XCHANGE_INIT_FAILED",
    AUTO_ACCEPT_FAILED = "LAZY_XCHANGE_AUTO_ACCEPT_FAILED",
    KEY_GENERATION_FAILED = "LAZY_XCHANGE_KEY_GENERATION_FAILED",
    NOT_INITIALIZED = "LAZY_XCHANGE_NOT_INITIALIZED",
    MISSING_SERVICE_INFO = "LAZY_XCHANGE_MISSING_SERVICE_INFO"
}
/**
 * Lazy Xchange error.
 */
export interface LazyXchangeError {
    code: LazyXchangeErrorCode;
    message: string;
    hint?: string;
    cause?: any;
}
/**
 * Send options for lazy Xchange.
 */
export interface LazyXchangeSendOptions {
    /** Recipient DID. */
    to: string;
    /** Payload to encrypt and send. */
    payload: Uint8Array;
    /** Message scope. */
    scope: string;
    /** Optional progress callback. */
    onProgress?: ProgressCallback;
}
/**
 * Receive options for lazy Xchange.
 */
export interface LazyXchangeReceiveOptions {
    /** Bundle containing [key || IV || ciphertext]. */
    bundle: Uint8Array;
    /** Sender DID. */
    from: string;
    /** Message scope. */
    scope: string;
    /** Optional progress callback. */
    onProgress?: ProgressCallback;
}
/**
 * Lazy Xchange wrapper.
 *
 * Proxies all Xchange operations and initializes on first call.
 * Caches the initialized key for subsequent calls.
 */
export declare class LazyXchange {
    private config;
    private key;
    private initPromise;
    private lastError;
    constructor(config: LazyXchangeConfig);
    /**
     * Check if Xchange is ready (initialized).
     */
    isReady(): boolean;
    /**
     * Get last initialization error (if any).
     */
    getLastError(): LazyXchangeError | null;
    /**
     * Ensure Xchange is initialized.
     *
     * Can be called explicitly to trigger init before first send/receive.
     * Safe to call multiple times — subsequent calls return cached key.
     *
     * @returns XchangeKey instance or error
     */
    ensureInitialized(): Promise<Result<XchangeKey, LazyXchangeError>>;
    /**
     * Internal initialization logic.
     *
     * 1. Auto-accept invite (if XCHANGE_INVITE_CODE set)
     * 2. Generate Xchange key
     * 3. Return initialized key
     */
    private initialize;
    /**
     * Send encrypted payload using Xchange optimization.
     *
     * Automatically initializes on first call.
     */
    sendWithXchange(opts: LazyXchangeSendOptions): Promise<Result<Uint8Array, XchangeError | LazyXchangeError>>;
    /**
     * Receive and decrypt bundle using Xchange optimization.
     *
     * Automatically initializes on first call.
     */
    receiveWithXchange(opts: LazyXchangeReceiveOptions): Promise<Result<Uint8Array, XchangeError | LazyXchangeError>>;
    /**
     * Get environment variable value.
     *
     * @param key - Environment variable name
     * @returns Environment variable value or empty string
     */
    private getEnv;
    /**
     * Export the underlying key (for advanced use cases).
     *
     * Throws if key is not initialized.
     */
    getKey(): XchangeKey;
}
/**
 * Create a lazy Xchange instance that initializes on first use.
 *
 * Factory function for LazyXchange class.
 *
 * @param config - Lazy Xchange configuration
 * @returns Lazy Xchange wrapper
 *
 * @example
 * ```ts
 * // Environment: XCHANGE_INVITE_CODE=XCH-abc123
 *
 * const xchange = createLazyXchange({ name: 'my-service' });
 *
 * // No initialization yet — happens on first send:
 * const result = await xchange.sendWithXchange({
 *   to: 'did:key:z6Mk...',
 *   payload: new TextEncoder().encode('Hello'),
 *   scope: 'test',
 * });
 * ```
 */
export declare function createLazyXchange(config: LazyXchangeConfig): LazyXchange;
