import type { CompanyClient, SignInResult } from './company.js';
import type { MediatedExtension } from './types.js';
export type SignInType = 'direct' | 'device' | 'mediated';
export declare const MEDIATED_EXTENSION = "mediated-sign-in";
/**
 * Version 1 of the `mediated-sign-in` extension, when both `poppy.json` and the issuer offer it. It
 * defines its own grant type, so it isn't declared in `Poppy-Extensions` (3.3).
 */
export declare function mediatedExtension(company: CompanyClient): MediatedExtension | undefined;
/** `auth.disabled`: the Company offers Personal Agents no sign-in, even with an issuer (3.2). */
export declare function signInDisabled(company: CompanyClient): boolean;
/**
 * The sign-in types the Company offers (4): the issuer's grants, plus the extension, in the order to
 * prefer them. Direct Sign-In is preferred whenever it's offered (4). None with `auth.disabled`.
 */
export declare function offeredSignInTypes(company: CompanyClient): SignInType[];
/**
 * The sign-in types that can be used for `scope`. Direct and Device grant what the issuer's policies
 * allow; only Mediated keeps its own list. They come in the order to prefer them (extension, 6).
 */
export declare function eligibleSignInTypes(company: CompanyClient, scope: string): SignInType[];
export interface PendingDirectSignIn {
    /** The URL to open: with PAR, only `client_id` and `request_uri` (4.2). */
    url: string;
    /** With PAR: when the `request_uri` expires (epoch ms). Push again after that. */
    expiresAt?: number | undefined;
    state: string;
    codeVerifier: string;
    redirectUri: string;
    scope: string;
    issuer: string;
}
/**
 * Direct Sign-In (4.2): PKCE (S256), a random `state`, and `prompt=consent`, since the redirect may
 * reach this agent from another device than the one that opened the URL. When the issuer lists a
 * `pushed_authorization_request_endpoint`, the request is pushed (RFC 9126) with the client assertion
 * and a DPoP proof, and the URL carries only `client_id` and `request_uri`. A link the User opens
 * later should point at a page of this agent that calls this when it's opened.
 */
export declare function startDirectSignIn(company: CompanyClient, scope: string, opts?: {
    state?: string | undefined;
}): Promise<PendingDirectSignIn>;
/**
 * The redirect back (4.2): checks `state` and the RFC 9207 `iss` (exact match with the issuer we
 * started with), then exchanges the code with PKCE.
 */
export declare function completeDirectSignIn(company: CompanyClient, pending: PendingDirectSignIn, callback: URLSearchParams): Promise<SignInResult>;
export interface DeviceSignInOptions {
    /** Shows the link and code to the User. `device_code` is never passed here. */
    /** MUST show the Company's name and domain with the link (4.3). */
    display: (info: {
        organization: {
            name: string;
            domain: string;
        };
        userCode: string;
        verificationUri: string;
        verificationUriComplete?: string | undefined;
        expiresIn: number;
    }) => void;
    signal?: AbortSignal | undefined;
    /** Hook for tests. */
    sleep?: ((ms: number, signal?: AbortSignal) => Promise<void>) | undefined;
    onPoll?: ((status: 'authorization_pending' | 'slow_down', intervalSeconds: number) => void) | undefined;
}
/**
 * Before showing a device link (4.3): its host is the issuer's or `organization.domain`, or a
 * subdomain of either. Otherwise a Company could pass off another's sign-in page as its own.
 */
export declare function assertDeviceLinkHost(company: CompanyClient, link: string): void;
/** RFC 8628 device flow: start, show the code, poll every `interval`, +5s on `slow_down`. */
export declare function deviceSignIn(company: CompanyClient, scope: string, opts: DeviceSignInOptions): Promise<SignInResult>;
/**
 * One device-code exchange (4.3), for a server that cannot hold a polling loop open (the user
 * comes back and says "approved"): `'pending'` while the User has not decided, the sign-in when
 * they approved. `access_denied` / `expired_token` throw.
 */
export declare function pollDeviceSignInOnce(company: CompanyClient, deviceCode: string, scope: string): Promise<SignInResult | 'pending'>;
export type MediatedOutcome = {
    status: 'complete';
    result: SignInResult;
} | {
    status: 'code_required';
    signInId: string;
    sentTo?: string | undefined;
    /** Seconds until the sign-in expires. */
    expiresIn?: number | undefined;
}
/** `invalid_grant`, `expired_token`, `access_denied`. */
 | {
    status: 'failed' | 'expired' | 'denied';
};
/**
 * Mediated Sign-In (extension). Credentials go ONLY to the issuer's token endpoint, with this
 * grant. Secret values are never logged or echoed by this module. Transitional: prefer Direct or
 * Device when they cover the task.
 */
export declare function mediatedSignIn(company: CompanyClient, scope: string, credentials: Record<string, string>): Promise<MediatedOutcome>;
/** Sends the one-time code; the sign-in keeps the scopes of the first request (section 4). */
export declare function submitMediatedCode(company: CompanyClient, scope: string, signInId: string, code: string): Promise<MediatedOutcome>;
/**
 * The scopes to request when a task needs more than the refresh token allows (4.7): every scope still
 * needed, including the granted ones to keep, never only the missing ones. The Company grants only
 * the scopes a sign-in names, so asking for the missing ones alone would drop the others.
 */
export declare function scopesForSignIn(company: CompanyClient, needed: string | string[], opts?: {
    keep?: boolean | undefined;
}): string;
/**
 * The scopes a Personal Agent can request (4.7): `scopes_supported` of the issuer's metadata and of
 * the domain's protected resource metadata, or else the ones `auth.scopes` describes.
 * `poppy:browser-sign-in` only from a Company that lists a `browser_session_endpoint` (section 6).
 */
export declare function offeredScopes(company: CompanyClient): string[];
//# sourceMappingURL=signin.d.ts.map