Nostr WoT

File cifrati e gestione dei blob

Guida di integrazione e riferimento API: File cifrati e gestione dei blob.

Questo riferimento API dettagliato è mantenuto in inglese e segue il codice SDK collegato. Gli esempi con variabili applicative richiedono il proprio firmatario, chiavi, archiviazione o interfaccia.

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;
};

Riferimento API