import type { BaseClient } from "../client/base.js"; import type { Credentials } from "../signer/signer.js"; export class AuthApi { constructor(private readonly client: BaseClient) {} /** * List all credentials associated with a Polygon address */ async listApiKeys(): Promise { const response = await this.client.request<{ apiKeys: Credentials[] }>({ method: "GET", path: "/auth/api-keys", auth: { kind: "l2" }, }); return response.apiKeys; } /** * Creates a new API key */ async createApiKey(nonce: number): Promise { return this.client.request({ method: "POST", path: "/auth/api-key", auth: { kind: "l1", nonce, }, }); } /** * Derive an existing API key for an address and nonce */ async deriveApiKey(nonce: number): Promise { const response = await this.client.request<{ apiKey: string; secret: string; passphrase: string; }>({ method: "GET", path: "/auth/derive-api-key", auth: { kind: "l1", nonce, }, }); return { key: response.apiKey, secret: response.secret, passphrase: response.passphrase, }; } /** * Delete an API key */ async deleteApiKey(): Promise { return this.client.request({ method: "DELETE", path: "/auth/api-key", auth: { kind: "l2" }, }); } /** * Retrieve the closed-only mode flag status */ async getClosedOnlyMode(): Promise { return this.client.request({ method: "GET", path: "/auth/ban-status/closed-only", auth: { kind: "l2" }, }); } }