{"id":13365660,"url":"https://github.com/cberGoon/merkletree","last_synced_at":"2025-03-12T17:32:02.063Z","repository":{"id":19853165,"uuid":"88002579","full_name":"cbergoon/merkletree","owner":"cbergoon","description":"A Merkle Tree implementation written in Go.","archived":false,"fork":false,"pushed_at":"2023-08-21T12:15:50.000Z","size":124,"stargazers_count":484,"open_issues_count":4,"forks_count":126,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-08-02T20:47:21.351Z","etag":null,"topics":["golang","hashtree","merkle-tree","tree"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cbergoon.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-12T02:50:11.000Z","updated_at":"2024-08-01T06:05:37.000Z","dependencies_parsed_at":"2024-06-18T12:24:07.299Z","dependency_job_id":"9a18d2f5-0c97-45b9-b294-c3c906620454","html_url":"https://github.com/cbergoon/merkletree","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbergoon%2Fmerkletree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbergoon%2Fmerkletree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbergoon%2Fmerkletree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbergoon%2Fmerkletree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cbergoon","download_url":"https://codeload.github.com/cbergoon/merkletree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221305494,"owners_count":16795145,"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","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":["golang","hashtree","merkle-tree","tree"],"created_at":"2024-07-30T00:01:11.022Z","updated_at":"2024-10-24T10:30:53.972Z","avatar_url":"https://github.com/cbergoon.png","language":"Go","funding_links":[],"categories":["数据结构","數據結構"],"sub_categories":["高级控制台界面","高級控制台界面"],"readme":"\u003ch1 align=\"center\"\u003eMerkle Tree in Golang\u003c/h1\u003e\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://travis-ci.org/cbergoon/merkletree\"\u003e\u003cimg src=\"https://travis-ci.org/cbergoon/merkletree.svg?branch=master\" alt=\"Build\"\u003e\u003c/a\u003e\n\u003ca href=\"https://goreportcard.com/report/github.com/cbergoon/merkletree\"\u003e\u003cimg src=\"https://goreportcard.com/badge/github.com/cbergoon/merkletree?1=1\" alt=\"Report\"\u003e\u003c/a\u003e\n\u003ca href=\"https://godoc.org/github.com/cbergoon/merkletree\"\u003e\u003cimg src=\"https://img.shields.io/badge/godoc-reference-brightgreen.svg\" alt=\"Docs\"\u003e\u003c/a\u003e\n\u003ca href=\"#\"\u003e\u003cimg src=\"https://img.shields.io/badge/version-0.1.0-brightgreen.svg\" alt=\"Version\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nAn implementation of a Merkle Tree written in Go. A Merkle Tree is a hash tree that provides an efficient way to verify\nthe contents of a set data are present and untampered with.\n\nAt its core, a Merkle Tree is a list of items representing the data that should be verified. Each of these items\nis inserted into a leaf node and a tree of hashes is constructed bottom up using a hash of the nodes left and\nright children's hashes. This means that the root node will effictively be a hash of all other nodes (hashes) in\nthe tree. This property allows the tree to be reproduced and thus verified by on the hash of the root node\nof the tree. The benefit of the tree structure is verifying any single content entry in the tree will require only\nnlog2(n) steps in the worst case.\n\n#### Documentation \n\nSee the docs [here](https://godoc.org/github.com/cbergoon/merkletree).\n\n#### Install\n```\ngo get github.com/cbergoon/merkletree\n```\n\n#### Example Usage\nBelow is an example that makes use of the entire API - its quite small.\n```go\npackage main\n\nimport (\n  \"crypto/sha256\"\n  \"errors\"\n  \"log\"\n\n  \"github.com/cbergoon/merkletree\"\n)\n\n//TestContent implements the Content interface provided by merkletree and represents the content stored in the tree.\ntype TestContent struct {\n  x string\n}\n\n//CalculateHash hashes the values of a TestContent\nfunc (t TestContent) CalculateHash() ([]byte, error) {\n  h := sha256.New()\n  if _, err := h.Write([]byte(t.x)); err != nil {\n    return nil, err\n  }\n\n  return h.Sum(nil), nil\n}\n\n//Equals tests for equality of two Contents\nfunc (t TestContent) Equals(other merkletree.Content) (bool, error) {\n  otherTC, ok := other.(TestContent).x\n  if !ok {\n    return false, errors.New(\"value is not of type TestContent\")\n  }    \n  return t.x == otherTC.x, nil\n}\n\nfunc main() {\n  //Build list of Content to build tree\n  var list []merkletree.Content\n  list = append(list, TestContent{x: \"Hello\"})\n  list = append(list, TestContent{x: \"Hi\"})\n  list = append(list, TestContent{x: \"Hey\"})\n  list = append(list, TestContent{x: \"Hola\"})\n\n  //Create a new Merkle Tree from the list of Content\n  t, err := merkletree.NewTree(list)\n  if err != nil {\n    log.Fatal(err)\n  }\n\n  //Get the Merkle Root of the tree\n  mr := t.MerkleRoot()\n  log.Println(mr)\n\n  //Verify the entire tree (hashes for each node) is valid\n  vt, err := t.VerifyTree()\n  if err != nil {\n    log.Fatal(err)\n  }\n  log.Println(\"Verify Tree: \", vt)\n\n  //Verify a specific content in in the tree\n  vc, err := t.VerifyContent(list[0])\n  if err != nil {\n    log.Fatal(err)\n  }\n\n  log.Println(\"Verify Content: \", vc)\n\n  //String representation\n  log.Println(t)\n}\n\n```\n#### Sample\n![merkletree](merkle_tree.png)\n\n\n#### License\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FcberGoon%2Fmerkletree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FcberGoon%2Fmerkletree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FcberGoon%2Fmerkletree/lists"}