Nostr WoT

Archivos cifrados y gestión de blobs

Sube archivos cifrados, cancela tareas, replica y elimina blobs.

Esta referencia detallada de la API se mantiene en inglés y sigue el código del SDK enlazado. Los ejemplos con variables de aplicación requieren tu firmante, claves, almacenamiento o interfaz.

Encrypted attachments

Encrypt the attachment before calling this helper. It creates a fresh disposable signing identity for each upload, uses that identity across its fallback attempts, and scopes each authorization to the destination server. Both upload destinations and returned URLs must use HTTPS. The body is sent as application/octet-stream.

ts
import { uploadEncryptedBlob } from "nostr-wot-sdk/blossom";

const blob = await uploadEncryptedBlob(ciphertext, {
  servers: ["https://my.blossom", "https://blossom.primal.net"],
});

The server still sees the ciphertext size, hash, IP address, and request timing. This helper does not encrypt content or hide network metadata.

Cancellation and session changes

Both upload functions accept signal and assertActive. A signal is forwarded to fetch. The synchronous assertActive callback should throw when a session or operation becomes obsolete; it is checked before and after asynchronous steps and before fallback. These failures propagate without trying another server. An already pending signer or Blob read cannot itself be cancelled; the result is discarded when it resolves.

ts
const blob = await uploadToBlossom(file, {
  signer,
  signal: controller.signal,
  assertActive: () => {
    if (session !== currentSession()) throw new Error("Session changed");
  },
});

When all servers fail, BlossomUploadError exposes a readonly reasons array containing server diagnostics. Applications should map it to their own user-facing message.

Mirror

Mirroring downloads the original bytes and uploads to each target, returning descriptors for successful copies. Individual target failures do not discard successful results; a failure downloading the source rejects the operation.

ts
import { mirrorBlob } from "nostr-wot-sdk/blossom";

const copies = await mirrorBlob(existingBlob.url, {
  signer,
  targetServers: ["https://blossom.band", "https://nostr.build"],
});
// BlossomBlob[]

Delete

Deletion returns the server's success status. The authorization is scoped to that server. A server may retain a blob referenced by other users.

ts
import { deleteBlob } from "nostr-wot-sdk/blossom";

const deleted = await deleteBlob(blob.sha256, {
  signer,
  server: new URL(blob.url).origin,
});

Types

ts
type BlossomBlob = {
  url: string;
  sha256: string;
  size: number;
  type: string;
  uploaded: number;
};

Referencia de API