{"id":23387481,"url":"https://github.com/reactivejson/merkletree","last_synced_at":"2025-08-18T05:13:40.215Z","repository":{"id":158899741,"uuid":"632456604","full_name":"reactivejson/merkleTree","owner":"reactivejson","description":"Go implementation of Merkle Tree for crypto and blockchain","archived":false,"fork":false,"pushed_at":"2023-05-03T08:31:04.000Z","size":4116,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-07T09:51:18.319Z","etag":null,"topics":["blake3","blockchain","cryptocurrency","go","hash","merkle-tree","trees","web3"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reactivejson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-04-25T12:53:33.000Z","updated_at":"2023-05-04T07:02:22.000Z","dependencies_parsed_at":"2023-07-31T06:45:33.423Z","dependency_job_id":null,"html_url":"https://github.com/reactivejson/merkleTree","commit_stats":{"total_commits":4,"total_committers":2,"mean_commits":2.0,"dds":0.25,"last_synced_commit":"f4450c69d4d7b394e55c0f1266e8b843e5c6cc37"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/reactivejson/merkleTree","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactivejson%2FmerkleTree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactivejson%2FmerkleTree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactivejson%2FmerkleTree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactivejson%2FmerkleTree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reactivejson","download_url":"https://codeload.github.com/reactivejson/merkleTree/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactivejson%2FmerkleTree/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270946068,"owners_count":24672890,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blake3","blockchain","cryptocurrency","go","hash","merkle-tree","trees","web3"],"created_at":"2024-12-22T01:16:32.670Z","updated_at":"2025-08-18T05:13:40.189Z","avatar_url":"https://github.com/reactivejson.png","language":"Go","readme":"## Merkle Tree API\nThis is Go implementation of Merkle Tree data structure,\nwhich is a hash-based data structure that is useful for verifying the integrity of data.\nIt is used in many different contexts, including in blockchain technology.\n\nWe use Blake3 hashing algorithm.\n\n## Endpoints\nThe API has a single endpoint:\n\n### POST /create\nCreate a new Merkle tree\nThis endpoint accepts a JSON payload containing a list of data and name for the new Merkle tree.\n\nRequest Payload\n\nExample request payload:\n````json\n{\n  \"data\": [\"Foo\", \"Bar\", \"Baz\"],\n  \"name\": \"tree1\"\n}\n````\n\n### POST /verify\nVerify a Merkle proof for a given data item\nThis endpoint accepts a JSON payload containing the data to be verified and name for the new Merkle tree.\n\nRequest Payload\n\n````json\n{\n  \"data\": \"Baz\",\n  \"name\": \"tree1\"\n}\n\n````\n\n\nResponse Payload\nThe response payload is a JSON object with a single field verified that is a boolean\n\nExample response payload:\n\n````json\n{\n  \"verified\": true\n}\n````\n\n### PUT /update\nUpdate a leaf node in a Merkle tree\nThis endpoint accepts a JSON payload containing The name, index, and new data for the leaf to update.\n\nRequest Payload\n\n````json\n{\n  \"data\": \"kk\",\n  \"name\": \"tree1\",\n  \"index\": 2\n}\n\n````\n\n### Project layout\n\nThis layout is following pattern:\n\n```text\nmerkleTree\n└───\n    ├── .github\n    │   └── workflows\n    │     └── go.yml\n    ├── cmd\n    │   └── main.go\n    ├── internal\n    │   └── merkleTree.go\n    ├── internal\n    │   └── merkleProof.go\n    ├── internal\n    │   └── hash\n    │     └── blake3.go\n    ├── build\n    │   └── Dockerfile\n    ├── Makefile\n    ├── README.md\n    └── \u003csource packages\u003e\n```\n\n## Setup\n\n### Getting started\nmerkle-tree is available in github\n[merkle-tree](https://github.com/reactivejson/merkleTree)\n\n```shell\ngo get github.com/reactivejson/merkleTree\n```\n\n#### Run\n```shell\ngo run cmd/main.go\n```\n\n#### Build\n```shell\nmake build\n```\n#### Testing\n```shell\nmake test\n```\n### Build docker image:\n\n```bash\nmake docker-build\n```\nThis will build this application docker image so-called merkle-tree\n\n## Benchmarking\n\nWe have run benchmarks using the `go test` command with the following options: `-bench=Bench -benchtime=5s -benchmem`.\n\n### Results\ngoos: windows\ngoarch: amd64\n\ncpu: 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz\n\n| Function                    | Iterations   | Execution Time   | Memory Allocation   | Allocations Per Operation |\n|-----------------------------|--------------|------------------|---------------------|---------------------------|\n| BenchmarkMerkleTree10-8     | 4907882      | 1213 ns/op       | 760 B/op            | 16 allocs/op              |\n| BenchmarkMerkleTree100-8    | 3520026      | 1769 ns/op       | 1272 B/op           | 25 allocs/op              |\n| BenchmarkMerkleTree1000-8   | 2718508      | 2374 ns/op       | 1768 B/op           | 34 allocs/op              |\n| BenchmarkMerkleTree10000-8  | 1714077      | 3344 ns/op       | 2458 B/op           | 46 allocs/op              |\n| BenchmarkMerkleTree100000-8 | 1598781      | 3777 ns/op       | 2975 B/op           | 55 allocs/op              |\n| MerkleTreeOneMillion        | 1111663      | 4552 ns/op       | 3731 B/op           | 69 allocs/op              |\n\n\nThe `ns/op` column shows the average number of nanoseconds per operation. The `B/op` column shows the average number of bytes allocated per operation. The `allocs/op` column shows the average number of memory allocations per operation.\n\nThe execution time is measured in nanoseconds per operation, and it indicates how long it takes to execute each operation. The execution time is calculated by multiplying the number of iterations by the average time per iteration.\n\nNote that the execution time may vary depending on the hardware and software configuration of the system running the benchmarks.\n\n## Merkle Tree Package\nThis is a Go package that provides a Merkle tree data structure implementation.\n\n### Usage\nThe package provides the merkletree package that contains the following functions:\n\n#### NewTree(data [][]byte, hash HashType) (*MerkleTree, error)\nThis function creates a new MerkleTree struct that represents a Merkle tree of the given data using the specified HashType.\n\n#### GenerateMProof(data []byte) (*MerkleProof, error)\nThis function generates a Merkle proof for a given data element. It returns a MerkleProof struct.\n\n#### MerkleRoot() []byte\nThis function returns the Merkle root hash.\n\n#### UpdateLeaf(index uint64, newData []byte) error\nThis function updates the leaf at the given index with new data. It returns an error if the index is out of bounds.\n\n#### VerifyMProof(data []byte, proof *MerkleProof, root []byte) (bool, error)\nThis function verifies a given Merkle proof against a Merkle root hash using the Blake3 hashing algorithm. It returns a boolean value indicating whether the proof is valid or not.\n\n### Types\nThe package provides the following types:\n\n#### MerkleTree struct\nThis struct represents a Merkle tree data structure. It contains the following fields:\n\nhash HashType: A HashType object that represents the hashing algorithm used to generate the Merkle tree.\ndata [][]byte: A slice of byte slices that contains the original data elements used to generate the Merkle tree.\nnodes [][]byte: A slice of byte slices that contains the nodes of the Merkle tree.\n#### MerkleProof struct\nThis struct represents a Merkle proof. It contains the following fields:\n\nHashes [][]byte: A slice of byte slices that contains the hashes of the nodes on the proof path.\nIndex uint64: An integer that represents the index of the data element that the proof is for.\n\n### Hashing\nThe package provides a HashType interface that defines the methods required for a hashing algorithm to be used with the MerkleTree struct.\nThe package includes a Blake3 hashing algorithm implementation which we used for this implementation.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freactivejson%2Fmerkletree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freactivejson%2Fmerkletree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freactivejson%2Fmerkletree/lists"}