@bsv/authsocket-client
Version:
Mutually Authenticated Web Sockets Client
64 lines • 2.83 kB
text/typescript
import { ManagerOptions, Socket, SocketOptions } from "socket.io-client";
import { AsyncSessionManager, OriginatorDomainNameStringUnder250Bytes, Peer, RequestedCertificateSet, SessionManager, WalletInterface } from "@bsv/sdk";
//#region src/AuthSocketClient.d.ts
type AuthSocketClientErrorPhase = 'authentication' | 'application' | 'send';
interface AuthSocketClientErrorContext {
phase: AuthSocketClientErrorPhase;
socketId?: string;
eventName?: string;
}
type AuthSocketClientErrorHandler = (error: unknown, context: AuthSocketClientErrorContext) => void | Promise<void>;
declare function decodeAuthSocketEventPayload(payload: number[]): {
eventName: string;
data: any;
};
interface AuthSocketClientOptions {
wallet: WalletInterface;
requestedCertificates?: RequestedCertificateSet;
sessionManager?: SessionManager | AsyncSessionManager;
managerOptions?: Partial<ManagerOptions & SocketOptions>;
originator?: OriginatorDomainNameStringUnder250Bytes;
/** Maximum authentication messages processed concurrently. Defaults to 32. */
maxPendingAuthMessages?: number;
/** Receives contained transport and application errors without exposing remote payloads. */
onError?: AuthSocketClientErrorHandler;
}
/**
* Internal class that wraps a Socket.IO client connection with BRC-103 mutual authentication,
* enabling secure and identity-aware communication with a server.
*/
declare class AuthSocketClientImpl {
private readonly ioSocket;
private readonly peer;
private readonly onError;
connected: boolean;
id: string;
serverIdentityKey: string | undefined;
private readonly eventCallbacks;
/**
* Creates an instance of AuthSocketClient.
*
* @param ioSocket - The underlying Socket.IO client socket instance.
* @param peer - The BRC-103 Peer instance responsible for managing authenticated
* communication, including message signing and verification.
*/
constructor(ioSocket: Socket, peer: Peer, onError?: AuthSocketClientErrorHandler);
on(eventName: string, callback: (data?: any) => void | Promise<void>): this;
emit(eventName: string, data: any): this;
disconnect(): void;
private fireEventCallbacks;
private encodeEventPayload;
private decodeEventPayload;
private reportError;
private disconnectSafely;
}
/**
* Factory function for creating a new AuthSocketClientImpl instance.
*
* @param url - The server URL
* @param opts - Contains wallet, requested certificates, and other optional settings
*/
declare function AuthSocketClient(url: string, opts: AuthSocketClientOptions): AuthSocketClientImpl;
//#endregion
export { AuthSocketClient, AuthSocketClientErrorContext, AuthSocketClientErrorHandler, AuthSocketClientErrorPhase, AuthSocketClientOptions, decodeAuthSocketEventPayload };
//# sourceMappingURL=AuthSocketClient.d.cts.map