import { MessageHash, type EcdsaPublicKey } from '#internal/web';
import { BackupLocation, type KeyShareBackupInfo, type ThresholdSignatureScheme, type WaasWalletProperties } from '@dynamic-labs-wallet/core';
import type { JwtVerifiedCredential } from '@dynamic-labs/sdk-api-core';
import { getHttpStatus } from './httpStatus.js';
export declare const isBrowser: () => boolean;
/**
 * Helper function to extract pubkey from potentially nested structure
 * Handles cases where pubkey is stored as {pubkey: {0: 33, 1: 209, ...}} in localStorage
 */
export declare const extractPubkey: (pubkey: any) => Uint8Array | EcdsaPublicKey;
export declare const getClientKeyShareExportFileName: ({ thresholdSignatureScheme, accountAddress, isGoogleDrive, }: {
    thresholdSignatureScheme: ThresholdSignatureScheme;
    accountAddress: string;
    isGoogleDrive?: boolean;
}) => string;
export declare const getClientKeyShareBackupInfo: (params?: {
    walletProperties: WaasWalletProperties;
}) => KeyShareBackupInfo;
export declare const timeoutPromise: ({ timeInMs, activity }: {
    timeInMs: number;
    activity?: string;
}) => Promise<unknown>;
export { getHttpStatus };
interface RetryConfig {
    maxAttempts?: number;
    retryInterval?: number;
    operationName?: string;
    logContext?: Record<string, unknown>;
    /**
     * Optional predicate called after each failure. Receives the error and the
     * count of failures so far (1 = first failure). Return false to fail fast.
     * The predicate may run async side effects (e.g. refresh a stale credential)
     * before returning. If it throws, the original error is surfaced.
     *
     * When omitted, the default behavior retries every error except those marked
     * `isRetryable: false`.
     */
    shouldRetry?: (error: unknown, attempt: number) => boolean | Promise<boolean>;
}
/**
 * Generic helper function to retry a promise-based operations
 *
 * @param operation - The async operation to retry
 * @param config - Configuration options for retry behavior
 * @returns Promise with the operation result
 * @throws Last error encountered after all retries are exhausted
 */
export declare function retryPromise<T>(operation: () => Promise<T>, { maxAttempts, retryInterval, operationName, logContext, shouldRetry }?: RetryConfig): Promise<T>;
/**
 * Classifies whether a wallet-creation / wallet-import ceremony error is
 * worth retrying. Returns true for terminal errors that won't get better on
 * retry (wrong password, missing password, public-key mismatch, etc.) so the
 * caller can mark them with `isRetryable: false` and short-circuit
 * `retryPromise`.
 */
export declare const isNonRetryableCeremonyError: (error: unknown) => boolean;
/**
 * Marks an error as non-retryable in place so `retryPromise` will skip
 * remaining attempts. Used at ceremony retry boundaries.
 */
export declare const markCeremonyErrorNonRetryable: (error: unknown) => void;
export declare const formatEvmMessage: (message: string | Uint8Array) => MessageHash;
/**
 * TRON uses secp256k1 ECDSA with keccak256 hashing (same primitives as EVM).
 * TIP-191 message prefixing is applied client-side in the TRON wallet client,
 * which then passes the prefixed bytes through this hashing step. Tx-signing
 * pre-hashes with SHA-256 in the wallet client and passes `isFormatted: true`,
 * which bypasses `formatMessage` entirely.
 */
export declare const formatTronMessage: (message: string | Uint8Array) => MessageHash;
export declare const isHexString: (str: string) => boolean;
export declare const formatMessage: (chainName: string, message: string | Uint8Array) => string | Uint8Array | MessageHash;
export declare const getGoogleOAuthAccountId: (verifiedCredentials: JwtVerifiedCredential[]) => string | undefined;
export declare const createBackupData: ({ encryptedKeyShares, accountAddress, thresholdSignatureScheme, hasPassword, }: {
    encryptedKeyShares: string[];
    accountAddress: string;
    thresholdSignatureScheme: ThresholdSignatureScheme;
    hasPassword?: boolean;
}) => {
    keyShares: string[];
    metadata: {
        createdAt: string;
        accountAddress: string;
        thresholdSignatureScheme: ThresholdSignatureScheme;
        hasPassword: boolean;
        encryption: import("@dynamic-labs-wallet/core").EncryptionMetadata;
        encryptionVersion: import("./backup/encryption/constants.js").EncryptionVersion;
        shareCount: number;
    };
};
export declare const downloadStringAsFile: ({ filename, content, mimeType, }: {
    filename: string;
    content: string;
    mimeType?: string;
}) => void;
/**
 * Checks if a wallet has cached encrypted shares in storage.
 */
export declare const hasEncryptedSharesCached: ({ accountAddress, backupInfo, storage, }: {
    accountAddress: string;
    backupInfo?: KeyShareBackupInfo;
    storage: {
        getItem: (key: string) => Promise<string | null> | string | null;
    };
}) => Promise<boolean>;
/**
 * Checks if an error is a public key mismatch error that can be recovered
 * by re-fetching the client key share from backup.
 *
 * This error occurs when the local client key share doesn't match the server's
 * expected public key, typically due to stale or corrupted local storage.
 */
export declare const isPublicKeyMismatchError: (error: unknown) => boolean;
/**
 * Checks for the server's stale-share preflight rejection (HTTP 409 sent as
 * an SSE error event with `code: 'STALE_CLIENT_SHARES'`). The server compares
 * the `shareSetId` the SDK sends on sign requests against the wallet's active
 * share set and rejects BEFORE any room/ceremony work when they diverge
 * (e.g. the shares were rotated by a reshare/refresh on another device).
 * The SDK heals (re-syncs local shares from backup) and retries internally.
 *
 * The SSE event-stream layer copies the event's data fields onto the Error
 * object (see createErrorFromEventData), so `code` is available here.
 */
export declare const isStaleClientSharesError: (error: unknown) => boolean;
/**
 * Detects the server's 409 ROOM_ID_ALREADY_USED rejection. The client
 * may cache pre-created roomIds locally; if a cached roomId becomes
 * stale (e.g. localStorage restoration after an iframe reload, or a
 * write failure in a restricted storage context), the server rejects
 * the claim with this code. The SDK retries without the stale roomId
 * so the server creates a fresh room.
 */
export declare const isRoomIdAlreadyUsedError: (error: unknown) => boolean;
/**
 * Determines whether a reshare operation should reuse the wallet's existing backup locations.
 *
 * **Why this exists:**
 * When `reshareOnNextSignOn` is triggered (e.g., after Google OAuth refresh), the reshare happens
 * automatically without the caller specifying backup parameters. Without this detection, the reshare
 * would proceed with empty backup locations, potentially losing the user's Google Drive or
 * delegation backup configuration.
 *
 * **When it returns true:**
 * - Same threshold (not upgrading/downgrading the signature scheme)
 * - No cloud providers explicitly passed (caller didn't request backup changes)
 * - No delegation explicitly passed (caller didn't request delegation changes)
 *
 * When true, the reshare will auto-populate backup locations from the wallet's existing
 * `clientKeySharesBackupInfo` state, ensuring backups are preserved.
 */
export declare const shouldReshareToSameBackups: ({ oldThresholdSignatureScheme, newThresholdSignatureScheme, cloudProviders, delegateToProjectEnvironment, }: {
    oldThresholdSignatureScheme: ThresholdSignatureScheme;
    newThresholdSignatureScheme: ThresholdSignatureScheme;
    cloudProviders?: BackupLocation[];
    delegateToProjectEnvironment?: boolean;
}) => boolean;
//# sourceMappingURL=utils.d.ts.map