Links: API, Interfaces, Classes, Functions
export interface AuthMiddlewareOptions {
wallet: Wallet;
sessionManager?: SessionManager;
allowUnauthenticated?: boolean;
certificatesToRequest?: RequestedCertificateSet;
onCertificatesReceived?: (senderPublicKey: string, certs: VerifiableCertificate[], req: Request, res: Response, next: NextFunction) => void;
logger?: typeof console;
logLevel?: "debug" | "info" | "warn" | "error";
}
Interface AuthMiddlewareOptions Details
Optional logging level. Defaults to no logging if not provided. 'debug' | 'info' | 'warn' | 'error'
- debug: Logs everything, including low-level details of the auth process.
- info: Logs general informational messages about normal operation.
- warn: Logs potential issues but not necessarily errors.
- error: Logs only critical issues and errors.
logLevel?: "debug" | "info" | "warn" | "error"
Optional logger (e.g., console). If not provided, logging is disabled.
logger?: typeof console
Links: API, Interfaces, Classes, Functions
Transport implementation for Express.
export class ExpressTransport implements Transport {
peer?: Peer;
allowAuthenticated: boolean;
openNonGeneralHandles: Record<string, Response[]> = {};
openGeneralHandles: Record<string, Response> = {};
openNextHandlers: Record<string, NextFunction> = {};
constructor(allowUnauthenticated: boolean = false, logger?: typeof console, logLevel?: "debug" | "info" | "warn" | "error")
setPeer(peer: Peer): void
async send(message: AuthMessage): Promise<void>
async onData(callback: (message: AuthMessage) => Promise<void>): Promise<void>
public handleIncomingRequest(req: Request, res: Response, next: NextFunction, onCertificatesReceived?: (senderPublicKey: string, certs: VerifiableCertificate[], req: Request, res: Response, next: NextFunction) => void): void
}
Class ExpressTransport Details
Constructs a new ExpressTransport instance.
constructor(allowUnauthenticated: boolean = false, logger?: typeof console, logLevel?: "debug" | "info" | "warn" | "error")
Argument Details
- allowUnauthenticated
- Whether to allow unauthenticated requests passed the auth middleware.
If
true
, requests without authentication will be permitted, andreq.auth.identityKey
will be set to"unknown"
. Iffalse
, unauthenticated requests will result in a401 Unauthorized
response.
- Whether to allow unauthenticated requests passed the auth middleware.
If
- logger
- Logger to use (e.g., console). If omitted, logging is disabled.
- logLevel
- Log level. If omitted, no logs are output.
Handles an incoming request for the Express server.
This method processes both general and non-general message types, manages peer-to-peer certificate handling, and modifies the response object to enable custom behaviors like certificate requests and tailored responses.
- For
/.well-known/auth
:- Handles non-general messages and listens for certificates.
- Calls the
onCertificatesReceived
callback (if provided) when certificates are received.
- For general messages:
- Sets up a listener for peer-to-peer general messages.
- Overrides response methods (
send
,json
, etc.) for custom handling.
- Returns a 401 error if mutual authentication fails.
public handleIncomingRequest(req: Request, res: Response, next: NextFunction, onCertificatesReceived?: (senderPublicKey: string, certs: VerifiableCertificate[], req: Request, res: Response, next: NextFunction) => void): void
Argument Details
- req
- The incoming HTTP request.
- res
- The HTTP response.
- next
- The Express
next
middleware function.
- The Express
- onCertificatesReceived
- Optional callback invoked when certificates are received.
Stores the callback bound by a Peer
async onData(callback: (message: AuthMessage) => Promise<void>): Promise<void>
Sends an AuthMessage to the connected Peer. This method uses an Express response object to deliver the message to the specified Peer.
async send(message: AuthMessage): Promise<void>
Returns
A promise that resolves once the message has been sent successfully.
Argument Details
- message
- The authenticated message to send.
Links: API, Interfaces, Classes, Functions
Creates an Express middleware that handles authentication via BSV-SDK.
export function createAuthMiddleware(options: AuthMiddlewareOptions)
See also: AuthMiddlewareOptions
Function createAuthMiddleware Details
Returns
Express middleware
Links: API, Interfaces, Classes, Functions