import { JWTPayload, AttestationData } from "./types"; import { Secret } from 'jsonwebtoken'; import { PolkadotClient } from "polkadot-api"; import { IStorage } from "./storage"; import { SerializableSignerData } from "./storage/SignerSerializer"; /** * Server version of the Auth class * This class only contains methods that DO NOT depend on browser APIs * and can be executed in a Node.js environment */ export default class ServerAuth { private readonly baseUrl; private readonly clientFactory; private readonly storage?; private _jwtSecret; private _jwtExpiresIn; private _client; private _sessionSigner; private readonly sessionDuration; /** * Creates a new ServerAuth instance * * @param baseUrl - The base URL of the federate server * @param clientFactory - Factory function to get the Polkadot client * @param storage - Storage implementation for sessions * @param jwtConfig - JWT configuration for token generation and verification */ constructor(baseUrl: string, clientFactory: () => Promise, storage?: IStorage | undefined, jwtConfig?: { secret: string | Secret; expiresIn?: number; }); /** * Generates a JWT token for a user * * @param userId - The ID of the user * @param publicKey - The public key of the user * @returns The generated JWT token * @throws Error if JWT configuration is not available */ private generateToken; private getClient; /** * Static method to extract the server address from a session signer * This is used by the NonceManager to get the correct address for nonce calculation * * @param sessionSigner - The session signer with the stored address * @returns The original address of the session signer */ static getServerSignerAddress(sessionSigner: any): string; /** * Verifies a JWT token * * @param token - The JWT token to verify * @returns The decoded token payload if valid * @throws VError if the token is invalid or expired */ verifyToken(token: string): JWTPayload; /** * Decodes a JWT token without verifying its signature * This method extracts the payload information without validation * * @param token - The JWT token to decode * @returns The decoded token payload * @throws VError if the token format is invalid */ decodeToken(token: string): JWTPayload; /** * Signs a command after verifying the JWT token * Signs directly without using the transaction queue * * @param token - The JWT token to verify * @param extrinsic - The extrinsic to sign * @returns The signed command result * @throws VError if the token is invalid or expired */ signWithToken(token: string, extrinsic: string): Promise<{ ok: boolean; hash: import("polkadot-api").HexString; blockHash: string; }>; /** * Completes the registration process on the server side * This method is designed to run in a Node.js environment * * The method: * 1. Sends the prepared registration data to the federate server * 2. Processes the response * * @param preparedData - The registration data prepared by the client, including: * - userId: The unique identifier for the user * - attestationResponse: The WebAuthn credential data * - blockNumber: The blockchain block number for registration * @returns Promise with the server's response to the registration * @throws Will throw an error if the server request fails */ completeRegistration(attestation: AttestationData, hashedUserId: string, credentialId: string, userId: string, address: string): Promise; /** * Completes the connection process on the server side * This method is designed to run in a Node.js environment * * The method: * 1. Sends the prepared connection data to the federate server * 2. Creates a session for the user using the session manager * 3. Returns both the server response and session information * 4. Generates a JWT token if JWT configuration is available * * @param preparedData - The connection data prepared by the client, including: * - userId: The unique identifier for the user * - assertionResponse: The WebAuthn assertion response * - blockNumber: The blockchain block number for connection * @returns Promise with the server's response, session information, and auth token * @throws Will throw an error if the server request fails or session creation fails */ completeConnection(userId: string): Promise<{ ok: boolean; extrinsic: string; token: string | null; publicKey: string; }>; /** * Checks if a user is registered with the federate server * This method is a utility to verify registration status * * @param userId - The unique identifier of the user to check * @returns Promise with a boolean indicating if the user is registered * @throws Will throw an error if the server request fails */ isRegistered(userId: string): Promise; addMember(userId: string): Promise; isMember(address: string): Promise; } //# sourceMappingURL=serverAuth.d.ts.map