snstr
Version:
Secure Nostr Software Toolkit for Renegades - A comprehensive TypeScript library for Nostr protocol implementation
27 lines (26 loc) • 1.16 kB
TypeScript
/**
* Custom error class for relay URL validation errors
*/
export declare class RelayUrlValidationError extends Error {
/** The type of validation error */
readonly errorType: "scheme" | "format" | "security" | "construction";
/** The invalid URL that caused the error */
readonly invalidUrl?: string;
constructor(message: string, errorType: "scheme" | "format" | "security" | "construction", invalidUrl?: string);
}
/**
* Preprocesses a relay URL before normalization and validation.
* Adds wss:// prefix only to URLs without any scheme.
* Throws an error for URLs with incompatible schemes.
*/
export declare function preprocessRelayUrl(url: string): string;
/**
* Canonicalises a relay URL by lowercasing scheme & host and removing the root pathname.
* Path, query and fragment parts keep their case.
* Validates the normalized URL for security and throws an error if invalid.
*/
export declare function normalizeRelayUrl(url: string): string;
/**
* Combines normalisation and validation. Returns undefined when the URL is invalid.
*/
export declare function validateAndNormalizeRelayUrl(url: string): string | undefined;