replace merkle trees with simple hash

This commit is contained in:
hzrd149
2024-11-14 07:45:05 -06:00
parent e39afe2149
commit 51c93670aa

View File

@@ -18,34 +18,42 @@ Clients MUST create a merkle tree using the chunk hashes as the leaf nodes
Clients should publish a `2001` kind event after chunking the file in order to store the list of chunks Clients should publish a `2001` kind event after chunking the file in order to store the list of chunks
The events `content` MUST be set to am ordered JSON array of the chunks sha256 hashes. e.g. The events `content` MUST be a new-line delimitated list of sha256 hashes
```json ```txt
[ 7e668b56a58c7891e0cf263ea3f093b75eebade23d663a45aa9920f347b3d671
"7e668b56a58c7891e0cf263ea3f093b75eebade23d663a45aa9920f347b3d671", // A 9b9c44a91396f19fd8700986eb0586dff2dcccf96c75bc2caefef302bcd78da1
"9b9c44a91396f19fd8700986eb0586dff2dcccf96c75bc2caefef302bcd78da1", // B 7a281548f1223664b855b10b08e59e84389ccabeb742517f6cd75eda2724a798
"7a281548f1223664b855b10b08e59e84389ccabeb742517f6cd75eda2724a798", // C fadeccee86b123088bbc452df10e8fbc99d4c2f22a70ef7a35605ec8e439c345
"fadeccee86b123088bbc452df10e8fbc99d4c2f22a70ef7a35605ec8e439c345", // D 5d62398419e6d136771541f3d2215e0ce31b1be45e99dbc64b43a4b734b447ca
"5d62398419e6d136771541f3d2215e0ce31b1be45e99dbc64b43a4b734b447ca" // E
]
``` ```
The event MUST have an `x` tag with the value of the unsorted sha256 [Merkle root](https://en.wikipedia.org/wiki/Merkle_tree) The event MUST have an `x` tag with the sha256 hash of the ordered concatenated hashes of each chunk
Example merkle tree: Example using `xxd` and `sha256sum`:
```bash
#!/bin/bash
hashes=(
"7e668b56a58c7891e0cf263ea3f093b75eebade23d663a45aa9920f347b3d671"
"9b9c44a91396f19fd8700986eb0586dff2dcccf96c75bc2caefef302bcd78da1"
"7a281548f1223664b855b10b08e59e84389ccabeb742517f6cd75eda2724a798"
"fadeccee86b123088bbc452df10e8fbc99d4c2f22a70ef7a35605ec8e439c345"
"5d62398419e6d136771541f3d2215e0ce31b1be45e99dbc64b43a4b734b447ca"
)
```mermaid concatenated=""
graph TD for hex in "${hex_array[@]}"; do
Root["Root (ABCDE)"] --> ABCD concatenated="${concatenated}${hex}"
Root --> E done
ABCD --> AB echo "Chunks:"
ABCD --> CD printf '%s\n' "${hex_array[@]}"
AB --> A echo -e "\nConcatenated:"
AB --> B echo "$concatenated"
CD --> C
CD --> D echo -e "\nRoot hash:"
echo "$concatenated" | xxd -r -p | sha256sum
``` ```
### Metadata ### Metadata
@@ -55,7 +63,7 @@ The `2001` event MAY include additional metadata tags to help other clients know
Metadata tags: Metadata tags:
- `name` Filename - `name` Filename
- `summary` A short summary of the file - `summary` A short summary of the file
- `m` Mime type of file - `mime` Mime type of file
- `size` Total size in bytes of the file - `size` Total size in bytes of the file
- `server` (multiple) Recommended servers to download chunks from - `server` (multiple) Recommended servers to download chunks from
@@ -64,19 +72,19 @@ Metadata tags:
Example `2001` event Example `2001` event
```json ```json
{ {
"id": "9d0a95a2d2681a758ca4023256e62ff71494d8346b62f11601029b1f74b3b933", "id": "13dfd656bedaca1f5fbb5da3b585d9c13061aa6aee136a0dc7d534f4d2540941",
"pubkey": "84ac0424fa2dec0ffd6a1f256afd1d18304cc127081f2c81da499fe4b875f1d6", "pubkey": "939e77d64e8eb5c240f60bf29f80a619d6057e70fcf5d25755da012fe1b9502e",
"created_at": 1731405194, "created_at": 1731405194,
"kind": 2001, "kind": 2001,
"content": "[\"7e668b56a58c7891e0cf263ea3f093b75eebade23d663a45aa9920f347b3d671\",\"9b9c44a91396f19fd8700986eb0586dff2dcccf96c75bc2caefef302bcd78da1\",\"7a281548f1223664b855b10b08e59e84389ccabeb742517f6cd75eda2724a798\",\"fadeccee86b123088bbc452df10e8fbc99d4c2f22a70ef7a35605ec8e439c345\",\"5d62398419e6d136771541f3d2215e0ce31b1be45e99dbc64b43a4b734b447ca\"]", "content": "7e668b56a58c7891e0cf263ea3f093b75eebade23d663a45aa9920f347b3d671\n9b9c44a91396f19fd8700986eb0586dff2dcccf96c75bc2caefef302bcd78da1\n7a281548f1223664b855b10b08e59e84389ccabeb742517f6cd75eda2724a798\nfadeccee86b123088bbc452df10e8fbc99d4c2f22a70ef7a35605ec8e439c345\n5d62398419e6d136771541f3d2215e0ce31b1be45e99dbc64b43a4b734b447ca",
"tags": [ "tags": [
[ "x", "ebb6b0c58ad555db23c9a34e449ea8d37cfc9644cc0982f0facea11d1c3dfab0" ], [ "x", "2d839865ac17d8bb10168490a88107637619f79dac21275fcec1705162581f39" ],
[ "name", "example.mp4" ], [ "name", "example.mp4" ],
[ "m", "video/mp4" ], [ "mime", "video/mp4" ],
[ "size", "4823449" ], [ "size", "4823449" ],
[ "server", "https://cdn.example.com" ], [ "server", "https://cdn.example.com" ],
[ "server", "https://nostr.download" ] [ "server", "https://nostr.download" ]
], ],
"sig": "f930eceb7dd8f5bfe9c238e7ec124b6ca34fc335688be1aaa1cb41c33f722c86e23a527aadbed266767d5b6224451bddeac9cf9b43ac7c068c8388cbdbcbd189" "sig": "949b52a12fcd788eb416069b231e106eeb36b4987052c29904b547cabf5a52ebb42acfbce1ae61139042064b6950e69e322c5edbe77603ac2241a4d0e953ddd4"
} }
``` ```