3.1 KiB
BUD-10
Chunked blobs
draft optional
Breaking large blobs into smaller chunks for distribution
Chunking
The client MAY break large blobs into any number or size of chunks. although its recommended to use the size 1Mb or 4Mb for small and large chunks
Clients MUST NOT pad the remaining chunk, If clients need privacy they should use random chunk sizes and optionally encrypt the large blob
Clients MUST create a merkle tree using the chunk hashes as the leaf nodes
Publishing
Clients should publish a 2001 kind event after chunking the file in order to store the list of chunks
The events content MUST be a new-line delimitated list of sha256 hashes
7e668b56a58c7891e0cf263ea3f093b75eebade23d663a45aa9920f347b3d671
9b9c44a91396f19fd8700986eb0586dff2dcccf96c75bc2caefef302bcd78da1
7a281548f1223664b855b10b08e59e84389ccabeb742517f6cd75eda2724a798
fadeccee86b123088bbc452df10e8fbc99d4c2f22a70ef7a35605ec8e439c345
5d62398419e6d136771541f3d2215e0ce31b1be45e99dbc64b43a4b734b447ca
The event MUST have an x tag with the sha256 hash of the ordered concatenated hashes of each chunk
Example using xxd and sha256sum:
#!/bin/bash
hashes=(
"7e668b56a58c7891e0cf263ea3f093b75eebade23d663a45aa9920f347b3d671"
"9b9c44a91396f19fd8700986eb0586dff2dcccf96c75bc2caefef302bcd78da1"
"7a281548f1223664b855b10b08e59e84389ccabeb742517f6cd75eda2724a798"
"fadeccee86b123088bbc452df10e8fbc99d4c2f22a70ef7a35605ec8e439c345"
"5d62398419e6d136771541f3d2215e0ce31b1be45e99dbc64b43a4b734b447ca"
)
concatenated=""
for hex in "${hex_array[@]}"; do
concatenated="${concatenated}${hex}"
done
echo "Chunks:"
printf '%s\n' "${hex_array[@]}"
echo -e "\nConcatenated:"
echo "$concatenated"
echo -e "\nRoot hash:"
echo "$concatenated" | xxd -r -p | sha256sum
Metadata
The 2001 event MAY include additional metadata tags to help other clients know the filename, mime type or servers to download from
Metadata tags:
nameFilenamesummaryA short summary of the filemimeMime type of filesizeTotal size in bytes of the fileserver(multiple) Recommended servers to download chunks from
Examples
Example 2001 event
{
"id": "13dfd656bedaca1f5fbb5da3b585d9c13061aa6aee136a0dc7d534f4d2540941",
"pubkey": "939e77d64e8eb5c240f60bf29f80a619d6057e70fcf5d25755da012fe1b9502e",
"created_at": 1731405194,
"kind": 2001,
"content": "7e668b56a58c7891e0cf263ea3f093b75eebade23d663a45aa9920f347b3d671\n9b9c44a91396f19fd8700986eb0586dff2dcccf96c75bc2caefef302bcd78da1\n7a281548f1223664b855b10b08e59e84389ccabeb742517f6cd75eda2724a798\nfadeccee86b123088bbc452df10e8fbc99d4c2f22a70ef7a35605ec8e439c345\n5d62398419e6d136771541f3d2215e0ce31b1be45e99dbc64b43a4b734b447ca",
"tags": [
[ "x", "2d839865ac17d8bb10168490a88107637619f79dac21275fcec1705162581f39" ],
[ "name", "example.mp4" ],
[ "mime", "video/mp4" ],
[ "size", "4823449" ],
[ "server", "https://cdn.example.com" ],
[ "server", "https://nostr.download" ]
],
"sig": "949b52a12fcd788eb416069b231e106eeb36b4987052c29904b547cabf5a52ebb42acfbce1ae61139042064b6950e69e322c5edbe77603ac2241a4d0e953ddd4"
}