import { type ConsoleCipher } from './redis_channel.js';
import type { TenantToken, TenantVerifier } from './tenant_auth.js';
/**
 * Automatic crypto mode: when `@adonis-agora/crypto` is booted in the same app, console commands
 * are sealed with its key `console-agent` without a line of configuration. Crypto is detected by
 * its container binding (`'agora.crypto'`), never imported: the shape below is all this lib reads.
 */
/** What this lib reads of `@adonis-agora/crypto`'s runtime (`'agora.crypto'`). */
export interface CryptoRuntimeLike {
    topology: 'standalone' | 'control-plane' | 'tenant';
    /** This app's crypto partition (its app name on a server, its partition on a tenant). */
    partition: string;
    /** Present where crypto is embedded in this app (standalone, control plane). */
    service?: CryptoServiceLike | undefined;
    /** This app's own operations, in-process or over HTTP (or a broker). */
    operations: CryptoOperationsLike;
}
/** What this lib calls on `runtime.operations`. */
export interface CryptoOperationsLike extends ConsoleCipher {
    encrypt(input: {
        key: string;
        plaintext: string;
        aad?: string;
        context?: string;
        /** Seal with another partition's key (a crypto tenant holding `crypto:seal:<key>`). */
        partition?: string;
    }): Promise<{
        ciphertext: string;
    }>;
    getKey?(name: string): Promise<unknown>;
    /**
     * Whether this app's partition holds `key` (SECURITY-UNIFORM-SPEC §13f): answered with the same
     * auth as `decrypt`, not audited as an error, a missing key is `false`. Optional: older crypto
     * clients do not have it, and the key check then probes with a dummy decrypt.
     */
    hasKey?(input: {
        key: string;
    }): Promise<boolean>;
    createKey?(input: {
        name: string;
        type: string;
        description?: string;
    }): Promise<unknown>;
}
/** The principal crypto's service checks each call against. */
export interface CryptoPrincipalLike {
    partition: string;
    capabilities: string[];
    actor: string;
}
/** The few `CryptoService` calls auto mode makes. */
export interface CryptoServiceLike {
    encrypt(principal: CryptoPrincipalLike, input: {
        key: string;
        plaintext: string;
        aad?: string;
    }): Promise<{
        ciphertext: string;
    }>;
    decrypt(principal: CryptoPrincipalLike, input: {
        key: string;
        ciphertext: string;
        aad?: string;
        context?: string;
    }): Promise<{
        plaintext: string;
    }>;
    createKey(principal: CryptoPrincipalLike, input: {
        name: string;
        type: string;
        description?: string;
    }): Promise<unknown>;
    store: {
        getKey(partition: string, name: string): Promise<{
            type?: string;
            deletedAt?: unknown;
        } | null | undefined>;
    };
}
/** The actor auto mode acts as, in crypto's audit trail. */
export declare const AUTO_CRYPTO_ACTOR = "agent:console";
/** `@adonis-agora/crypto`'s runtime, when it is booted in this app. */
export declare function cryptoRuntimeOf(container: {
    hasBinding(binding: never): boolean;
    make(binding: never): Promise<unknown>;
}): Promise<CryptoRuntimeLike | undefined>;
/**
 * Create the `aes256-gcm` key `key` in `partition` unless it exists (idempotent, and safe when
 * another instance creates it at the same time). Throws when a key of that name is of another
 * type or deleted, naming it.
 */
export declare function ensureConsoleCryptoKey(service: CryptoServiceLike, partition: string, key?: string): Promise<'created' | 'present'>;
/**
 * The console side's cipher for the app whose crypto partition is `partition`, where crypto is
 * embedded in the console app: it may only encrypt, with `key`, in that partition.
 */
export declare function consoleEncryptCipher(service: CryptoServiceLike, partition: string, key?: string): ConsoleCipher;
/**
 * The console side's cipher for the app whose crypto partition is `partition`, where this console
 * app is a TENANT of a separate crypto server: the channel `config/crypto.ts` already set up, asked
 * to seal with that app's key (`partition`), which the server allows only for encryption and only
 * when this app's token holds `crypto:seal:<key>`.
 */
export declare function consoleSealCipher(operations: CryptoOperationsLike, partition: string, key?: string): ConsoleCipher;
/** What one decrypt failure says about the key. */
export type ConsoleKeyOutcome = 'missing' | 'usable' | 'refused' | 'unreachable';
/**
 * Classifies a decrypt error from @adonis-agora/crypto (its `CryptoError` / client error carry a
 * `code`; the message is the fallback for other clients). `usable`: the key exists and this app
 * may decrypt with it (only the dummy ciphertext was rejected).
 */
export declare function classifyConsoleKeyError(error: unknown): ConsoleKeyOutcome;
/** A `forbidden` refusal from crypto (its error code, or the message for other clients). */
export declare function isForbidden(error: unknown): boolean;
/** The one line to log for `outcome`, or `undefined` when all is well. */
export declare function consoleKeyNote(runtime: Pick<CryptoRuntimeLike, 'partition'>, outcome: ConsoleKeyOutcome | 'created', key?: string, detail?: string): {
    level: 'info' | 'warn';
    line: string;
} | undefined;
/**
 * Checks the console key once (a dummy decrypt) and, when it is missing, tries to create it
 * through the channel crypto already configured (works with `crypto:keys:manage:console-*`).
 * Never throws: returns the line to log, or `undefined` when the key is there and usable.
 */
export declare function checkTenantConsoleKey(runtime: CryptoRuntimeLike, key?: string): Promise<{
    level: 'info' | 'warn';
    line: string;
} | undefined>;
/**
 * The tenant's console key, watched: `atBoot()` runs {@link checkTenantConsoleKey} once;
 * `decrypt` wraps the app's own decrypt so that, while the last check warned, a command's failure
 * is classified and logged (one line, only when it changes) and its success clears the warning.
 * No extra crypto call per command.
 */
export declare function watchTenantConsoleKey(runtime: CryptoRuntimeLike, log: (note: {
    level: 'info' | 'warn';
    line: string;
}) => void, key?: string): {
    atBoot(): Promise<void>;
    decrypt: CryptoOperationsLike['decrypt'];
};
/** What this lib reads of authkit-client's calls between apps (`'authkit.client'`). */
export interface AuthkitClientLike {
    appCallTokens?(): {
        token(app: string): Promise<string>;
        reset?(app?: string): void;
    } | undefined | null;
    appCallerVerifier?(): {
        verifyToken(token: string): Promise<{
            app: string;
            capabilities: string[];
            clientId: string;
            expiresAt?: number;
        } | null>;
    } | null | undefined;
    /** authkit's key directory: publish this app's public key (background, retried; never rejects). */
    publishAppKey?(input: {
        purpose: string;
        jwk: OkpJwkLike;
    }): Promise<void>;
    /** authkit's key directory: another app's public key for `purpose` (cached), or `null`. */
    appKey?(input: {
        app: string;
        purpose: string;
    }): Promise<OkpJwkLike | null>;
}
/** A public OKP JWK as authkit's key directory holds it. */
export interface OkpJwkLike {
    kty: string;
    crv: string;
    x: string;
    kid?: string;
    [extra: string]: unknown;
}
/** The key directory purpose of the agent's console-command public key. */
export declare const CONSOLE_KEY_PURPOSE = "console:agent";
/** Whether authkit-client's key directory is there to read other apps' keys from. */
export declare function hasKeyDirectory(authkit: AuthkitClientLike | undefined): boolean;
/** authkit-client, when it is booted in this app. */
export declare function authkitClientOf(container: {
    hasBinding(binding: never): boolean;
    make(binding: never): Promise<unknown>;
}): Promise<AuthkitClientLike | undefined>;
/** The console side's token for `app` from authkit's calls between apps, when configured. */
export declare function appCallToken(authkit: AuthkitClientLike | undefined, app: string): TenantToken | undefined;
/**
 * The app side's verifier for authkit app-call tokens, when configured: the audience binds the
 * token to this app, so the result is `audienceBound` and its partition is the calling app.
 */
export declare function appCallVerifier(authkit: AuthkitClientLike | undefined): TenantVerifier | undefined;
/**
 * §13f: whether crypto says `key` exists in this app's partition, or `undefined` when it cannot
 * say and the caller falls back to the decrypt probe (no `hasKey`, or an older crypto server
 * without the route). A refusal (`forbidden`) is thrown as is: it is the "no permission" outcome.
 */
export declare function hasKeyOrUnknown(runtime: CryptoRuntimeLike, key: string): Promise<boolean | undefined>;
//# sourceMappingURL=auto_crypto.d.ts.map