Skip to main content

Crate hashtree_blossom

Crate hashtree_blossom 

Source
Expand description

§hashtree-blossom

Signed uploads and hash-verified downloads over the Blossom blob protocol. This client transfers raw stored bytes; use hashtree-core for logical files, chunking, and encryption.

Published API · Core guide

§Install

cargo add hashtree-blossom
cargo add nostr@0.44
cargo add tokio --features macros,rt-multi-thread

§Upload and download

This example compiles as a doctest but does not run against a public server. To run it yourself, replace the server URL with your upload-enabled endpoint. The generated signing key is only for the demo; apps should use their existing identity or a dedicated persisted upload identity.

use hashtree_blossom::BlossomClient;
use nostr::Keys;
use std::time::Duration;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = BlossomClient::new_empty(Keys::generate())
        .with_servers(vec!["https://blossom.example.com".to_string()])
        .with_timeout(Duration::from_secs(30));
    let hash = client.upload(b"Public demo blob").await?;
    let bytes = client.download(&hash).await?;
    assert_eq!(bytes, b"Public demo blob");
    Ok(())
}

new_empty() avoids loading the machine’s Hashtree configuration. Use with_read_servers() / with_write_servers() for separate endpoints. Authentication uses a signed kind-24242 Blossom authorization event. Uploads send bytes as supplied: the demo above is plaintext. For encrypted files, upload the stored ciphertext blocks generated by HashTree, including every referenced child, and share the complete CID separately. Announce a root only after the required blocks are available remotely.

upload() returns a hash after at least one configured server accepts the blob; it does not promise a copy on every server. download() verifies the hash and returns an error if retrieval fails. For presence checks where the distinction matters, check_on_server(hash, server) returns Present, Missing, or Unknown; exists() is only a convenience boolean.

§Store adapter and verification

The optional store feature exposes BlossomStore for Hashtree reads. Its put() only caches bytes locally; it does not upload them. Upload explicitly through BlossomClient before publishing a root. get() can collapse failed remote reads into a cache miss, so use the client or a routed read layer when your app must distinguish unavailability from absence.

From rust/, run cargo test --locked -p hashtree-blossom --doc to compile the example, or cargo doc --locked -p hashtree-blossom --no-deps --open to browse the checkout’s API. The published API follows the selected crate release.

Structs§

BatchUploadItem
BatchUploadResult
BlossomClient
Blossom protocol client

Enums§

BlobAvailability
Result of probing a blob’s presence on one Blossom server.
BlossomError

Constants§

BATCH_UPLOAD_BINARY_CONTENT_TYPE
BATCH_UPLOAD_HASH_LIST_AUTH_TAG
BATCH_UPLOAD_MAX_BLOBS
BATCH_UPLOAD_MAX_BYTES

Functions§

batch_upload_hash_list_digest
Return the compact authorization digest for an ordered batch upload hash list.
compute_sha256
Compute SHA256 hash of data, returning hex string