
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@nostr-dev-kit/ndk-blossom
Advanced tools
NDK-Blossom is an extension for NDK (Nostr Development Kit) that adds support for the Blossom protocol, making it easy to upload, manage, and interact with binary data (images, videos, documents, etc.) stored on Blossom servers.
# Using npm
npm install @nostr-dev-kit/ndk-blossom
# Using yarn
yarn add @nostr-dev-kit/ndk-blossom
# Using bun
bun add @nostr-dev-kit/ndk-blossom
import { NDK } from '@nostr-dev-kit/ndk';
import { NDKBlossom } from '@nostr-dev-kit/ndk-blossom';
import { imetaTagToTag } from '@nostr-dev-kit/ndk/lib/utils/imeta';
// Create NDK instance
const ndk = new NDK({
explicitRelayUrls: ['wss://relay.example.com']
});
// Create NDKBlossom instance
const blossom = new NDKBlossom(ndk);
// Connect to NDK
await ndk.connect();
// Upload a file
const fileInput = document.getElementById('fileInput') as HTMLInputElement;
const file = fileInput.files?.[0];
if (file) {
// Handle upload failures
blossom.onUploadFailed = (error) => console.error(error);
// Track upload progress (especially useful for large files)
blossom.onUploadProgress = (progress, file, serverUrl) => {
const percentage = Math.round((progress.loaded / progress.total) * 100);
console.log(`Upload progress: ${percentage}%`);
return 'continue';
};
// Upload the file
const imeta = await blossom.upload(file);
console.log('File uploaded:', imeta);
// Convert the imeta object to a proper tag for nostr events
const imetaTag = imetaTagToTag(imeta);
// Use the URL in a nostr note
const note = await ndk.publish({
kind: 1,
content: `Check out this file: ${imeta.url}`,
tags: [imetaTag] // Use the properly formatted imeta tag
});
}
// Fix a broken URL
const user = ndk.getUser({ npub: 'npub...' });
const fixedUrl = await blossom.fixUrl(user, 'https://broken-server.example/abcdef123...');
For full documentation, see the documentation directory:
NDK-Blossom implements the Blossom protocol, which includes several Blossom Upgrade Documents (BUDs):
NDK-Blossom allows you to provide your own SHA256 calculation implementation:
import { NDK } from '@nostr-dev-kit/ndk';
import { NDKBlossom, SHA256Calculator } from '@nostr-dev-kit/ndk-blossom';
// Create NDK instance
const ndk = new NDK();
// Create NDKBlossom instance
const blossom = new NDKBlossom(ndk);
// Create a custom SHA256 calculator
class CustomSHA256Calculator implements SHA256Calculator {
async calculateSha256(file: File): Promise<string> {
// Your custom implementation here
// For example, using a different hashing library
// or modifying how hashing is performed
// Example using a hypothetical external library:
// return await externalHashLibrary.hashFile(file);
// Must return a hex string representation of the hash
return "...custom implementation...";
}
}
// Set the custom calculator
blossom.setSHA256Calculator(new CustomSHA256Calculator());
// Or provide it directly during upload
const imeta = await blossom.upload(file, {
sha256Calculator: new CustomSHA256Calculator()
});
This feature is useful for:
MIT
FAQs
Blossom protocol support for NDK (Nostr Development Kit)
The npm package @nostr-dev-kit/ndk-blossom receives a total of 190 weekly downloads. As such, @nostr-dev-kit/ndk-blossom popularity was classified as not popular.
We found that @nostr-dev-kit/ndk-blossom demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.