/**
 * Auth HTTP Client
 *
 * TypeScript equivalent of the Rust auth API client.
 * Makes direct HTTP calls to the auth and vault endpoints.
 */
import { BaseClient } from './base-client';
export class AuthClient extends BaseClient {
    async getChallenge() {
        const raw = await this.request('/api/v1/auth/challenge');
        return {
            nonce: raw.nonce,
            nonceHmac: raw.nonce_hmac,
        };
    }
    async walletLogin(request) {
        // Server uses snake_case field names
        const raw = await this.request('/api/v1/auth/login', {
            method: 'POST',
            body: JSON.stringify({
                wallet_address: request.address,
                app_id: request.appId,
                signature: request.signature,
                nonce: request.nonce,
                ...(request.nonceHmac && { nonce_hmac: request.nonceHmac }),
                ...(request.viewauthSignature && { viewauth_signature: request.viewauthSignature }),
                ...(request.mpk && { mpk: request.mpk }),
                ...(request.upgradeNonce && { upgrade_nonce: request.upgradeNonce }),
                ...(request.upgradeNonceHmac && { upgrade_nonce_hmac: request.upgradeNonceHmac }),
                ...(request.accountId && { account_id: request.accountId }),
                ...(request.accountSalt && { account_salt: request.accountSalt }),
                ...(request.nullifyingKey && { nullifying_key: request.nullifyingKey }),
                ...(request.authPkX && { auth_pk_x: request.authPkX }),
                ...(request.authPkY && { auth_pk_y: request.authPkY }),
                ...(request.authExpiry && { auth_expiry: request.authExpiry }),
                ...(request.authSignature && { auth_signature: request.authSignature }),
            }),
        });
        return {
            token: raw.jwt,
            expiresIn: raw.expires_in ?? 0,
            vaultExists: raw.vault_exists,
            tier: raw.tier,
        };
    }
    async authUpgrade(request) {
        // Server uses snake_case field names
        const raw = await this.request('/api/v1/auth/upgrade', {
            method: 'POST',
            body: JSON.stringify({
                mpk: request.mpk,
                viewauth_signature: request.viewauthSignature,
                nonce: request.nonce,
                account_id: request.accountId,
                viewing_public_key: request.viewingPublicKey,
                nullifying_key: request.nullifyingKey,
                wallet_address: request.walletAddress,
                auth_pk_x: request.authPkX,
                auth_pk_y: request.authPkY,
                auth_expiry: request.authExpiry,
                auth_signature: request.authSignature,
            }),
        });
        return {
            token: raw.access_token || raw.jwt || '',
            expiresIn: raw.expires_in ?? 0,
        };
    }
    async getAuthToken(payload) {
        return this.request('/api/v1/auth/token', {
            method: 'POST',
            body: JSON.stringify(payload),
        });
    }
    async getSessionInfo() {
        return this.request('/api/v1/auth/session');
    }
    async vaultInit(request) {
        return this.request('/api/v1/vault/init', {
            method: 'POST',
            body: JSON.stringify(request),
        });
    }
    async vaultUnlock(request) {
        return this.request('/api/v1/vault/unlock', {
            method: 'POST',
            body: JSON.stringify(request),
        });
    }
}
//# sourceMappingURL=auth-client.js.map