{"id":16863803,"url":"https://github.com/nazar-pc/merkle-tree-binary","last_synced_at":"2025-04-11T06:14:16.845Z","repository":{"id":48012473,"uuid":"132557819","full_name":"nazar-pc/merkle-tree-binary","owner":"nazar-pc","description":"Set of functions for creating Merkle Tree, proofs and verifying proofs using binary data","archived":false,"fork":false,"pushed_at":"2023-02-28T21:23:44.000Z","size":41,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T06:14:11.380Z","etag":null,"topics":["merkle","proof","root","tree"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"0bsd","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nazar-pc.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"copying.md","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":"2018-05-08T05:22:49.000Z","updated_at":"2023-02-28T21:23:44.000Z","dependencies_parsed_at":"2024-10-19T00:16:35.136Z","dependency_job_id":"6113b2d6-85f9-4bcd-8042-c62648c2c54f","html_url":"https://github.com/nazar-pc/merkle-tree-binary","commit_stats":{"total_commits":14,"total_committers":2,"mean_commits":7.0,"dds":0.1428571428571429,"last_synced_commit":"759d498186d7df90e2a7be7e913468e23662c272"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nazar-pc%2Fmerkle-tree-binary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nazar-pc%2Fmerkle-tree-binary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nazar-pc%2Fmerkle-tree-binary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nazar-pc%2Fmerkle-tree-binary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nazar-pc","download_url":"https://codeload.github.com/nazar-pc/merkle-tree-binary/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248351393,"owners_count":21089270,"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":["merkle","proof","root","tree"],"created_at":"2024-10-13T14:39:47.391Z","updated_at":"2025-04-11T06:14:16.823Z","avatar_url":"https://github.com/nazar-pc.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# merkle-tree-binary [![Travis CI](https://img.shields.io/travis/nazar-pc/merkle-tree-binary/master.svg?label=Travis%20CI)](https://travis-ci.org/nazar-pc/merkle-tree-binary)\nSet of functions for creating Merkle Tree, proofs and verifying proofs using binary data.\n\nThis library doesn't hash original data, you have to specify hashes (or binary data of fixed size).\n\nThis implementation is vulnerable to a forgery attack ([as a second pre-image attack](https://en.wikipedia.org/wiki/Merkle_tree#Second_preimage_attack)), see these[\\[1\\]](https://crypto.stackexchange.com/questions/2106/what-is-the-purpose-of-using-different-hash-functions-for-the-leaves-and-interna)[\\[2\\]](https://crypto.stackexchange.com/questions/43430/what-is-the-reason-to-separate-domains-in-the-internal-hash-algorithm-of-a-merkl/44971#44971) crypto.stackexchange questions for an explanation.\nTo avoid this vulnerability, you should pre-hash your leaves *using a different hash function* than the function provided such that `H(x) != H'(x)`, alternatively you can record tree depth alongside root hash and check it during validation.\n\nThis implementation is vulnerable to a forgery attack ([for an unbalanced Merkle Tree](https://bitcointalk.org/?topic=102395)), wherein, in an unbalanced Merkle Tree, the last leaf node can be duplicated to create an artificial balanced tree, resulting in the same root hash.\nTo avoid this vulnerability, do not accept unbalanced Merkle Trees in your application.\n\n## How to install\n```\nnpm install merkle-tree-binary\n```\n\n## How to use\nTypeScript:\n```javascript\nimport {Tree} from 'merkle-tree-binary';\n\n// Do stuff\n```\nNode.js:\n```javascript\nvar {Tree} = require('merkle-tree-binary')\n\n// Do stuff\n```\nBrowser:\n```javascript\nrequirejs(['merkle-tree-binary'], function ({Tree}) {\n    // Do stuff\n})\n```\n\n## API\n### merkleTreeBinary.Tree(items : Uint8Array[], hashFunction : (input: Uint8Array) =\u003e Uint8Array) : merkleTreeBinary.Tree\nConstructor, creates a tree object from items and using specified hash function (items should also be constant-size, like after some hash function).\n\n### merkleTreeBinary.Tree.getRoot() : Uint8Array\nReturns `Uint8Array` root of Merkle Tree.\n\n### merkleTreeBinary.getProof(targetItem : Uint8Array) : Uint8Array\nGenerates a proof for `targetItem` in form of single compact binary string.\n\nBinary string consists of blocks. Each block starts with `0` or `1` for left and right accordingly, where current hash should be inserted and followed by the other hash on the same level.\n\n### merkleTreeBinary.Tree.checkProof(root, proof, targetItem, hashFunction: (input: Uint8Array) =\u003e Uint8Array) : boolean\nStatic function on Tree class, checks whether proof generated by `getProof()` is correct or not.\n\n## Contribution\nFeel free to create issues and send pull requests (for big changes create an issue first and link it from the PR), they are highly appreciated!\n\nWhen reading LiveScript code make sure to configure 1 tab to be 4 spaces (GitHub uses 8 by default), otherwise code might be hard to read.\n\n## License\nZero-Clause BSD\n\nhttps://opensource.org/licenses/0BSD\n\nhttps://tldrlegal.com/license/bsd-0-clause-license \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnazar-pc%2Fmerkle-tree-binary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnazar-pc%2Fmerkle-tree-binary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnazar-pc%2Fmerkle-tree-binary/lists"}