@nostr-dev-kit/blossom
Version:
Blossom protocol support for NDK (Nostr Development Kit)
126 lines • 3.75 kB
TypeScript
import type { NDKEvent } from "@nostr-dev-kit/ndk";
export interface BlossomBlobDescriptor {
sha256: string;
url: string;
size: number;
created_at: number;
mime_type: string;
width?: number;
height?: number;
blurhash?: string;
alt?: string;
[key: string]: any;
}
export interface BlossomServerList {
pubkey: string;
servers: string[];
created_at?: number;
event?: NDKEvent;
}
/**
* Options for uploading to Blossom servers
*/
export interface BlossomUploadOptions {
/**
* If provided, always use this server for upload (bypasses blossom list and fallback).
*/
server?: string;
/**
* If no blossom servers are available or all fail, use this server as a fallback.
*/
fallbackServer?: string;
/**
* Maximum number of retry attempts for network requests
*/
maxRetries?: number;
/**
* Delay between retry attempts in milliseconds
*/
retryDelay?: number;
/**
* Additional headers to include in the upload request
*/
headers?: Record<string, string>;
/**
* Callback for upload progress
*/
onProgress?: (progress: {
loaded: number;
total: number;
}) => "continue" | "cancel";
/**
* Callback for server errors
*/
onServerError?: (error: Error, serverUrl: string) => "retry" | "skip";
/**
* Custom SHA256 calculator implementation
*/
sha256Calculator?: SHA256Calculator;
}
export interface BlossomOptimizationOptions {
width?: number;
height?: number;
format?: string;
quality?: number;
fit?: "contain" | "cover" | "fill" | "inside" | "outside";
background?: string;
blur?: number;
sharpen?: boolean;
time?: string;
[key: string]: string | number | boolean | undefined;
}
export interface BlossomRetryOptions {
maxRetries: number;
retryDelay: number;
backoffFactor: number;
retryableStatusCodes: number[];
}
export interface BlossomServerConfig {
headers?: Record<string, string>;
}
export interface BlossomMirrorResult {
sourceUrl: string;
targetUrl?: string;
success: boolean;
error?: string;
}
export interface BlossomBatchMirrorResults {
succeeded: BlossomMirrorResult[];
failed: BlossomMirrorResult[];
}
export declare const ErrorCodes: {
readonly SERVER_UNAVAILABLE: "SERVER_UNAVAILABLE";
readonly SERVER_ERROR: "SERVER_ERROR";
readonly SERVER_REJECTED: "SERVER_REJECTED";
readonly SERVER_TIMEOUT: "SERVER_TIMEOUT";
readonly SERVER_LIST_EMPTY: "SERVER_LIST_EMPTY";
readonly SERVER_INVALID_RESPONSE: "SERVER_INVALID_RESPONSE";
readonly NO_SIGNER: "NO_SIGNER";
readonly AUTH_REQUIRED: "AUTH_REQUIRED";
readonly AUTH_INVALID: "AUTH_INVALID";
readonly AUTH_EXPIRED: "AUTH_EXPIRED";
readonly AUTH_REJECTED: "AUTH_REJECTED";
readonly UPLOAD_TOO_LARGE: "UPLOAD_TOO_LARGE";
readonly UPLOAD_INVALID_TYPE: "UPLOAD_INVALID_TYPE";
readonly UPLOAD_FAILED: "UPLOAD_FAILED";
readonly ALL_SERVERS_FAILED: "ALL_SERVERS_FAILED";
readonly BLOB_NOT_FOUND: "BLOB_NOT_FOUND";
readonly USER_SERVER_LIST_NOT_FOUND: "USER_SERVER_LIST_NOT_FOUND";
readonly SERVER_UNSUPPORTED: "SERVER_UNSUPPORTED";
readonly FORMAT_UNSUPPORTED: "FORMAT_UNSUPPORTED";
readonly NO_SHA256_CALCULATOR: "NO_SHA256_CALCULATOR";
};
export type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
/**
* Interface for SHA256 calculation implementation
*/
export interface SHA256Calculator {
/**
* Calculate SHA256 hash of a file
*
* @param file File to hash
* @returns Hash as hex string
*/
calculateSha256(file: File): Promise<string>;
}
//# sourceMappingURL=index.d.ts.map