Cotal TypeScript packages
    Preparing search index...

    Interface StartAuthCalloutOpts

    Hooks for distinct connections may run concurrently. Each connection still awaits its own authority checks and durable issuance before its encrypted response is released.

    interface StartAuthCalloutOpts {
        authAccount: { pub: string; signingSeed: string };
        authorizeActor: (t: ValidatedUserToken) => void | Promise<void>;
        connectLimiter?: ConnectLimiter;
        dataAccount: { pub: string; signingSeed: string };
        expectedServerIds?: string[];
        limits?: AuthCalloutLimits;
        log?: (line: string) => void;
        onMint?: (info: { exp: number; jwt: string; principal: string }) => void;
        permissionsFor: (
            t: ValidatedUserToken,
            connId: string,
            readerId: string,
        ) => Record<string, unknown> | Promise<Record<string, unknown>>;
        recordIssuance: NativeIssuanceRecorder;
        serviceAuthority?: NativeServiceCalloutAuthority;
        space: string;
        token: { issuer: string; key: JWTVerifyGetKey | CryptoKey };
        xkeySeed: string;
    }
    Index
    authAccount: { pub: string; signingSeed: string }

    The auth account (response issuer): its pub + the signing seed the response is signed with.

    authorizeActor: (t: ValidatedUserToken) => void | Promise<void>

    The spawn-ledger hook: THROW to deny. Client-supplied actor claims are only as good as this server-side check — the flip wires the manager's authenticated spawn ledger in here.

    connectLimiter?: ConnectLimiter

    The connect limits, shared with the exchange so an actor limited here is refused there too. Absent: a limiter of this callout's own at the default limits.

    dataAccount: { pub: string; signingSeed: string }

    The data account users are bound into: its pub + the signing seed that mints user JWTs.

    expectedServerIds?: string[]

    Allow-list of trusted nats-server ids (server_id.id) — the tightest request-provenance pin: a request whose server id is not listed is dropped (no response). STRONGLY RECOMMENDED for any hardened / multi-server deploy. When omitted, the ONLY barrier left is NATS $SYS system-subject isolation (no in-account user can publish $SYS.REQ.USER.AUTH, and the callout user is even explicitly pub-denied it) — the app-layer iss === server_id.id + N…-prefix check is NOT independently sufficient, since an attacker who could reach the subject could present their own createServer() key and matching sealing xkey. That isolation holds single-broker, so omitting the list is safe today; startup logs a WARNING so the over-trust is never silent.

    Deadline, concurrency and slow-line limits. Absent: every default.

    log?: (line: string) => void

    Diagnostics sink (default: console.error). Never carries bearer contents. Each answered request writes one auth callout: level=… line, whose fields docs/identity-and-auth.mdx names.

    onMint?: (info: { exp: number; jwt: string; principal: string }) => void

    Audit hook fired on each successful mint, BEFORE the response is sent — the minted user JWT plus its principal and bound expiry. For metering/audit and for asserting the revocation lever (the mint's exp is bound to the bearer's, so broker access dies with the bearer).

    permissionsFor: (
        t: ValidatedUserToken,
        connId: string,
        readerId: string,
    ) => Record<string, unknown> | Promise<Record<string, unknown>>

    Permission builder for a validated principal (the flip feeds core's permissionsFor via a thin @cotal-ai/auth adapter). connId is the connection name (req.connect_opts.name), NOT the NATS-minted req.user_nkey. The builder scopes the private reply inbox _INBOX_<connId>.> on it. The callout checks that a principal-bound name matches the bearer. Legacy nonces remain valid. Neither form may contain subject metacharacters. readerId is core's calloutReaderId of this connection, which keys the observer and admin profiles' history-reader deletes: the client chooses the connId, so the connId cannot key them.

    recordIssuance: NativeIssuanceRecorder

    REQUIRED: durably record the minted JWT's broker user key (req.user_nkey) against the validated principal BEFORE the response leaves (SPEC 13.1 natkey.). Awaited; a throw becomes the signed deny and the minted JWT is never sent. A thrown record write may still have landed: evidence of an issuance, never proof a client received the JWT or the connection was accepted.

    serviceAuthority?: NativeServiceCalloutAuthority

    Optional sealed native service path. Absent means service-endpoint continues to refuse.

    space: string

    The space — enforced as the bearer's audience.

    token: { issuer: string; key: JWTVerifyGetKey | CryptoKey }

    Pinned bearer verification: the key resolver (pinned JWKS/local key) + exact issuer.

    xkeySeed: string

    The callout xkey SEED — MANDATORY. No xkey, no service (fail startup, never plaintext).