import { SimplePool, verifyEvent, type Event } from "nostr-tools"; import type { NostrProfile } from "./config-schema.js"; import { validateUrlSafety } from "./nostr-profile-url-safety.js"; import { contentToProfile, type ProfileContent } from "./nostr-profile.js";
export interface ProfileImportResult { /** Whether the import was successful */
ok: boolean; /** The imported profile (if found and valid) */
profile?: NostrProfile; /** The raw event (for advanced users) */
event?: {
id: string;
pubkey: string;
created_at: number;
}; /** Error message if import failed */
error?: string; /** Which relays responded */
relaysQueried: string[]; /** Which relay provided the winning event */
sourceRelay?: string;
}
export interface ProfileImportOptions { /** The public key to fetch profile for */
pubkey: string; /** Relay URLs to query */
relays: string[]; /** Timeout per relay in milliseconds (default: 5000) */
timeoutMs?: number;
}
/** *SanitizeURLsinanimportedprofiletopreventSSRFattacks. *RemovesanyURLsthatdon'tpassSSRFvalidation.
*/ function sanitizeProfileUrls(profile: NostrProfile): NostrProfile { const result = { ...profile }; const urlFields = ["picture", "banner", "website"] as const;
for (const field of urlFields) { const value = result[field]; if (value && typeof value === "string") { const validation = validateUrlSafety(value); if (!validation.ok) { // Remove unsafe URL delete result[field];
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.