Skip to content

Commit 16afe47

Browse files
authored
Merge pull request #3 from stacchain/verify-tree
Verify tree
2 parents 1d1af94 + 28834dc commit 16afe47

File tree

16 files changed

+555
-73
lines changed

16 files changed

+555
-73
lines changed

CHANGELOG.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12-
### Changed
13-
14-
### Deprecated
15-
16-
### Removed
17-
18-
### Fixed
12+
- Added `verify` command to cli with accompanying script to ensure that the Merkle tree verification json produced by the `compute` command matches [#2](https://github.com/stacchain/stac-merkle-tree-cli/pull/2)
1913

2014
## [v0.3.0] - 2024-11-20
2115

README.md

Lines changed: 110 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,27 @@ catalog/
124124

125125
### Basic Usage
126126

127-
After installing the package, you can use the `stac-merkle-tree-cli` command to compute and add Merkle information to your STAC catalog.
127+
After installing the package, you can use the `stac-merkle-tree-cli` command to compute or verify Merkle information in your STAC catalog.
128+
129+
### Commands:
130+
131+
### 1. `compute`
132+
133+
The compute command computes and adds Merkle information (`merkle:object_hash`, `merkle:root`, `merkle:hash_method`) to your STAC catalog.
128134

129135
```bash
130-
stac-merkle-tree-cli path/to/catalog_directory [OPTIONS]
136+
stac-merkle-tree-cli compute path/to/catalog_directory [OPTIONS]
131137
```
132138

133139
#### Parameters:
134140

135-
- path/to/catalog_directory: (Required) Path to the root directory containing catalog.json.
141+
- `path/to/catalog_directory`: (Required) Path to the root directory containing `catalog.json`.
136142

137143
#### Options:
138144

139-
- --merkle-tree-file TEXT: (Optional) Path to the output Merkle tree structure file. Defaults to merkle_tree.json within the provided catalog_directory.
145+
- `--merkle-tree-file TEXT`: (Optional) Path to the output Merkle tree structure file. Defaults to `merkle_tree.json` within the provided catalog_directory.
140146

141-
### Example
147+
#### Example
142148

143149
Assuming your directory structure is as follows:
144150

@@ -161,7 +167,7 @@ my_stac_catalog/
161167
Run the tool:
162168

163169
```bash
164-
stac-merkle-tree-cli my_stac_catalog/
170+
stac-merkle-tree-cli compute my_stac_catalog/
165171
```
166172

167173
Expected Output:
@@ -177,6 +183,43 @@ Processed Catalog: /path/to/my_stac_catalog/catalog.json
177183
Merkle tree structure saved to /path/to/my_stac_catalog/merkle_tree.json
178184
```
179185

186+
### 2. `verify`
187+
188+
The `verify` command validates the integrity of a Merkle tree JSON file by recalculating `merkle:root` values and comparing them to the expected values.
189+
190+
```bash
191+
stac-merkle-tree-cli verify path/to/merkle_tree.json
192+
```
193+
194+
#### Parameters:
195+
196+
- `path/to/merkle_tree.json`: (Required) Path to the Merkle tree JSON file to verify.
197+
198+
#### Example:
199+
200+
Run the command:
201+
202+
```bash
203+
stac-merkle-tree-cli verify my_stac_catalog/merkle_tree.json
204+
```
205+
206+
Example Output (Success):
207+
208+
```bash
209+
Verification Successful: The merkle:root matches.
210+
```
211+
212+
Example Output (Failure):
213+
214+
```bash
215+
Verification Failed:
216+
- Expected merkle:root: 5808b480d9bed10e7663d52c218571d053c7b5df42a5aefc11e216c66c711f77
217+
- Calculated merkle:root: f0ed08b316b917a98c085e699c090af1cea964b697dd0bc44491ebced4d0006c
218+
Discrepancies found in the following nodes:
219+
- Collection 'COP-DEM' has mismatched merkle:root.
220+
- Catalog 'Catalogue' has mismatched merkle:root.
221+
```
222+
180223
## Merkle Tree Extension Specification
181224

182225
This tool complies with the [Merkle Tree Extension Specification](https://github.com/stacchain/merkle-tree), which outlines how to encode STAC objects in a Merkle tree to ensure metadata integrity.
@@ -352,15 +395,19 @@ Contributions are welcome! If you encounter issues or have suggestions for impro
352395

353396
## Verification Steps
354397

355-
### 1. Run the CLI Tool:
398+
### 1. Compute Merkle Tree
399+
400+
Use the `compute` command to process your STAC catalog and generate a Merkle tree structure.
356401

357402
```bash
358-
stac-merkle-tree-cli path/to/catalog_directory
403+
stac-merkle-tree-cli compute path/to/catalog_directory
359404
```
360405

361-
### 2. Check the Output:
406+
#### Options:
407+
408+
--merkle-tree-file <file_path>: Specify the output file name for the Merkle tree JSON (default is merkle_tree.json).
362409

363-
- **Console Output**: You should see logs indicating the processing of Items, Collections, and the Catalog.
410+
#### Example Output:
364411

365412
```ruby
366413
Processed Item: /path/to/catalog_directory/collections/collection1/item1.json
@@ -373,17 +420,64 @@ Processed Catalog: /path/to/catalog_directory/catalog.json
373420
Merkle tree structure saved to /path/to/catalog_directory/merkle_tree.json
374421
```
375422

376-
- **Merkle Tree JSON**: Verify that the `merkle_tree.json` (or your specified output file) accurately represents the hierarchical structure of your STAC catalog with correct `merkle:object_hash` and `merkle:root` values.
423+
- The tool will generate a `merkle_tree.json` file (or the specified output file), which represents the hierarchical structure of your STAC catalog, including `merkle:object_hash` and `merkle:root` values.
424+
425+
### 2. Verify Merkle Tree
426+
427+
Use the verify command to validate the integrity of the generated Merkle tree JSON file.
428+
429+
```bash
430+
stac-merkle-tree-cli verify path/to/catalog_directory/merkle_tree.json
431+
```
432+
433+
#### Example Output (Success):
434+
435+
```bash
436+
Verification Successful: The merkle:root matches.
437+
```
438+
439+
#### Example Output (Failure):
440+
441+
```bash
442+
Verification Failed:
443+
- Expected merkle:root: 5808b480d9bed10e7663d52c218571d053c7b5df42a5aefc11e216c66c711f77
444+
- Calculated merkle:root: f0ed08b316b917a98c085e699c090af1cea964b697dd0bc44491ebced4d0006c
445+
Discrepancies found in the following nodes:
446+
- Collection 'COP-DEM' has mismatched merkle:root.
447+
- Catalog 'Catalogue' has mismatched merkle:root.
448+
```
449+
450+
### 3. Validate STAC Structure Updates
451+
452+
Ensure that the STAC files (e.g., `catalog.json`, `collection.json`, item files) have been updated correctly:
453+
454+
#### Catalog:
455+
456+
- `catalog.json` should include:
457+
458+
- `merkle:object_hash`
459+
- `merkle:root`
460+
- `merkle:hash_method`
461+
462+
#### Collections:
463+
464+
- Each `collection.json` should include:
465+
- `merkle:object_hash`
466+
- `merkle:root`
467+
- `merkle:hash_method`
468+
469+
#### Items:
377470

378-
### 3. Verify Integrity:
471+
- Each Item JSON should have `merkle:object_hash` within its properties field.
379472

380-
- **Catalog**: Ensure that the `catalog.json` now includes `merkle:object_hash`, `merkle:root`, and `merkle:hash_method`.
473+
### 4. Verify Output File
381474

382-
- **Collections**: Each `collection.json` should include `merkle:object_hash`, `merkle:root`, and `merkle:hash_method`.
475+
Review the generated merkle_tree.json file to confirm:
383476

384-
- **Items**: Each Item's JSON should have `merkle:object_hash` within the properties field.
477+
- Proper hierarchical representation of the catalog.
478+
- Correct merkle:object_hash and merkle:root values for each node
385479

386-
### 4. Run Tests:
480+
### 5. Run Tests:
387481

388482
Ensure that all tests pass by executing:
389483

example_catalog/catalog.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"https://stacchain.github.io/merkle-tree/v1.0.0/schema.json"
5757
],
5858
"merkle:object_hash": "b14fd102417c1d673f481bc053d19946aefdc27d84c584989b23c676c897bd5a",
59-
"merkle:root": "2c637f0bae066e89de80839f3468f73e396e9d1498faefc469f0fd1039e19e0c",
59+
"merkle:root": "797bfc76d971db745b9b476d8c44e9fa021af889d5761476b74e982d69e7a3c2",
6060
"merkle:hash_method": {
6161
"function": "sha256",
6262
"fields": [

example_catalog/collections/COP-DEM/collection.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"href": "https://catalogue.dataspace.copernicus.eu/stac/collections/COP-DEM/items"
5151
}
5252
],
53-
"merkle:root": "fd2700dd6b39d254530a1a996d667620c4c7aacb69c86e9ea4ec71a7269f6aac",
53+
"merkle:root": "aa7f89b29cb339032ec86d81d4090bdbd52199152fb657f50b08eec1b3234ee2",
5454
"merkle:hash_method": {
5555
"function": "sha256",
5656
"fields": [

example_catalog/merkle_tree.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
"node_id": "Catalogue",
33
"type": "Catalog",
44
"merkle:object_hash": "b14fd102417c1d673f481bc053d19946aefdc27d84c584989b23c676c897bd5a",
5-
"merkle:root": "2c637f0bae066e89de80839f3468f73e396e9d1498faefc469f0fd1039e19e0c",
5+
"merkle:root": "797bfc76d971db745b9b476d8c44e9fa021af889d5761476b74e982d69e7a3c2",
66
"children": [
77
{
88
"node_id": "COP-DEM",
99
"type": "Collection",
1010
"merkle:object_hash": "17789b31f8ae304de8dbe2350a15263dbf5e31adfc0d17a997e7e55f4cfc2f53",
11-
"merkle:root": "fd2700dd6b39d254530a1a996d667620c4c7aacb69c86e9ea4ec71a7269f6aac",
11+
"merkle:root": "aa7f89b29cb339032ec86d81d4090bdbd52199152fb657f50b08eec1b3234ee2",
1212
"children": [
1313
{
1414
"node_id": "DEM1_SAR_DGE_30_20101215T103647_20130405T103047_ADS_000000_oCX9",

example_catalog_nested_items/catalog.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"https://stacchain.github.io/merkle-tree/v1.0.0/schema.json"
5757
],
5858
"merkle:object_hash": "b14fd102417c1d673f481bc053d19946aefdc27d84c584989b23c676c897bd5a",
59-
"merkle:root": "2c637f0bae066e89de80839f3468f73e396e9d1498faefc469f0fd1039e19e0c",
59+
"merkle:root": "614dbf76bf77d22fa824867beb0980c6c2c44aa12252555a8208783923a7569d",
6060
"merkle:hash_method": {
6161
"function": "sha256",
6262
"fields": [

example_catalog_nested_items/collections/COP-DEM/collection.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"href": "https://catalogue.dataspace.copernicus.eu/stac/collections/COP-DEM/items"
5151
}
5252
],
53-
"merkle:root": "2f4aa32184fbe70bd385d5b6b6e6d4ec5eb8b2e43611b441febcdf407c4e0030",
53+
"merkle:root": "7e990e84a86dc146547b6e3a3e35196f53e0123b6f216f871abd5d1f55d2ccc5",
5454
"merkle:hash_method": {
5555
"function": "sha256",
5656
"fields": [

example_catalog_nested_items/merkle_tree.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
"node_id": "Catalogue",
33
"type": "Catalog",
44
"merkle:object_hash": "b14fd102417c1d673f481bc053d19946aefdc27d84c584989b23c676c897bd5a",
5-
"merkle:root": "2c637f0bae066e89de80839f3468f73e396e9d1498faefc469f0fd1039e19e0c",
5+
"merkle:root": "614dbf76bf77d22fa824867beb0980c6c2c44aa12252555a8208783923a7569d",
66
"children": [
77
{
88
"node_id": "COP-DEM",
99
"type": "Collection",
1010
"merkle:object_hash": "17789b31f8ae304de8dbe2350a15263dbf5e31adfc0d17a997e7e55f4cfc2f53",
11-
"merkle:root": "2f4aa32184fbe70bd385d5b6b6e6d4ec5eb8b2e43611b441febcdf407c4e0030",
11+
"merkle:root": "7e990e84a86dc146547b6e3a3e35196f53e0123b6f216f871abd5d1f55d2ccc5",
1212
"children": [
1313
{
1414
"node_id": "DEM1_SAR_DGE_30_20101212T230244_20140325T230302_ADS_000000_1jTi",
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"stac_version": "1.0.0",
3+
"type": "Catalog",
4+
"id": "Catalogue",
5+
"description": "Catalogue of data available in the platform",
6+
"conformsTo": [
7+
"https://api.stacspec.org/v1.0.0/core",
8+
"https://api.stacspec.org/v1.0.0/collections",
9+
"https://api.stacspec.org/v1.0.0/ogcapi-features",
10+
"https://api.stacspec.org/v1.0.0/item-search",
11+
"https://www.opengis.net/spec/ogcapi-features-1/1.0/conf/core",
12+
"https://www.opengis.net/spec/ogcapi-features-1/1.0/conf/geojson"
13+
],
14+
"links": [
15+
{
16+
"href": "https://catalogue.dataspace.copernicus.eu/stac",
17+
"rel": "root",
18+
"type": "application/json"
19+
},
20+
{
21+
"href": "https://catalogue.dataspace.copernicus.eu/stac",
22+
"rel": "self",
23+
"type": "application/json"
24+
},
25+
{
26+
"href": "https://catalogue.dataspace.copernicus.eu/stac/api",
27+
"rel": "service-desc",
28+
"type": "application/vnd.oai.openapi"
29+
},
30+
{
31+
"href": "https://catalogue.dataspace.copernicus.eu/stac/conformance",
32+
"rel": "conformance",
33+
"type": "application/json"
34+
},
35+
{
36+
"href": "https://catalogue.dataspace.copernicus.eu/stac/collections",
37+
"rel": "data",
38+
"type": "application/json"
39+
},
40+
{
41+
"href": "https://catalogue.dataspace.copernicus.eu/stac/search",
42+
"title": "STAC search",
43+
"rel": "search",
44+
"type": "application/json",
45+
"method": "GET"
46+
},
47+
{
48+
"href": "https://catalogue.dataspace.copernicus.eu/stac/search",
49+
"title": "STAC search",
50+
"rel": "search",
51+
"type": "application/json",
52+
"method": "POST"
53+
}
54+
],
55+
"stac_extensions": [
56+
"https://stacchain.github.io/merkle-tree/v1.0.0/schema.json"
57+
],
58+
"merkle:object_hash": "b14fd102417c1d673f481bc053d19946aefdc27d84c584989b23c676c897bd5a",
59+
"merkle:root": "f0ed08b316b917a98c085e699c090af1cea964b697dd0bc44491ebced4d0006c",
60+
"merkle:hash_method": {
61+
"function": "sha256",
62+
"fields": [
63+
"*"
64+
],
65+
"ordering": "ascending",
66+
"description": "Computed by including the merkle:root of collections and the catalogs own merkle:object_hash."
67+
}
68+
}

0 commit comments

Comments
 (0)