{"id":46415030,"url":"https://github.com/chaintope/merkle","last_synced_at":"2026-03-05T14:03:50.294Z","repository":{"id":305842067,"uuid":"1021915899","full_name":"chaintope/merkle","owner":"chaintope","description":"A Ruby library for Merkle trees","archived":false,"fork":false,"pushed_at":"2025-12-30T01:56:52.000Z","size":51,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-15T06:05:20.721Z","etag":null,"topics":["merkletree","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/chaintope.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-18T06:41:07.000Z","updated_at":"2025-12-30T01:56:55.000Z","dependencies_parsed_at":"2025-07-22T09:48:18.944Z","dependency_job_id":null,"html_url":"https://github.com/chaintope/merkle","commit_stats":null,"previous_names":["chaintope/merkle"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/chaintope/merkle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaintope%2Fmerkle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaintope%2Fmerkle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaintope%2Fmerkle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaintope%2Fmerkle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chaintope","download_url":"https://codeload.github.com/chaintope/merkle/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaintope%2Fmerkle/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30130031,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T12:40:50.676Z","status":"ssl_error","status_checked_at":"2026-03-05T12:39:32.209Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["merkletree","ruby"],"created_at":"2026-03-05T14:03:40.601Z","updated_at":"2026-03-05T14:03:50.283Z","avatar_url":"https://github.com/chaintope.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Merkle\n\nA Ruby library for Merkle tree construction and proof generation with support for multiple tree structures and hashing algorithms.\n\n## Features\n\n- **Multiple tree structures**: Binary Tree (Bitcoin-compatible), Adaptive Tree, and Custom Tree implementations\n- **Flexible configuration**: Support for different hash algorithms (SHA256, Double SHA256) and tagged hashing\n- **Proof generation and verification**: Generate and verify Merkle proofs for any leaf\n- **Sorted hashing support**: Optional lexicographical sorting for deterministic tree construction\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'merkle'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install merkle\n\n## Usage\n\n### Basic Example\n\n```ruby\nrequire 'merkle'\n\n# Create configuration\nconfig = Merkle::Config.new(hash_type: :sha256)\n\n# Method 1: Using pre-hashed leaves\nleaves = [\n  'a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3',\n  'b3a8e0e1f9ab1bfe3a36f231f676f78bb30a519d2b21e6c530c0eee8ebb4a5d0',\n  'c3c9bc9a6c7c5b4e8c3b6b5a2a8c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c'\n]\n\n# Create binary tree (Bitcoin-compatible)\ntree = Merkle::BinaryTree.new(config: config, leaves: leaves)\n\n# Compute merkle root\nroot = tree.compute_root\nputs \"Merkle root: #{root}\"\n\n# Generate proof for leaf at index 1\nproof = tree.generate_proof(1)\nputs \"Proof siblings: #{proof.siblings}\"\nputs \"Proof directions: #{proof.directions}\"\n\n# Verify proof\nputs \"Proof valid: #{proof.valid?}\"\n```\n\n### Using from_elements\n\n```ruby\n# Method 2: Using from_elements to automatically hash raw data\nelements = ['hello', 'world', 'merkle', 'tree']\n\n# Create tree from raw elements\ntree = Merkle::BinaryTree.from_elements(\n  config: config, \n  elements: elements\n)\n\n# The elements are automatically hashed before building the tree\nroot = tree.compute_root\nputs \"Root from elements: #{root}\"\n\n# With optional leaf tag for tagged hashing (e.g., Taproot)\ntaproot_config = Merkle::Config.taptree\ntagged_tree = Merkle::AdaptiveTree.from_elements(\n  config: taproot_config,\n  elements: elements,\n  leaf_tag: 'TapLeaf'  # Optional tag for leaf hashing\n)\n\n# Generate and verify proof\nproof = tree.generate_proof(0)\nputs \"Proof for first element valid: #{proof.valid?}\"\n```\n\n### Adaptive Tree Example\n\n```ruby\n# Create adaptive tree for better performance with frequently accessed leaves\nadaptive_tree = Merkle::AdaptiveTree.new(config: config, leaves: leaves)\n\nroot = adaptive_tree.compute_root\nproof = adaptive_tree.generate_proof(0)\nputs \"Adaptive tree proof valid: #{proof.valid?}\"\n```\n\n### Custom Tree Example\n\n```ruby\n# CustomTree allows you to define your own tree structure using nested arrays\n# This gives you precise control over how leaves are grouped\n\n# Example 1: Basic usage with pre-hashed leaves\nleaf_a = config.tagged_hash('A')\nleaf_b = config.tagged_hash('B')\nleaf_c = config.tagged_hash('C')\nleaf_d = config.tagged_hash('D')\n\n# Define structure: [[A, [B, C]], D]\nnested_leaves = [[leaf_a, [leaf_b, leaf_c]], leaf_d]\ncustom_tree = Merkle::CustomTree.new(config: config, leaves: nested_leaves)\n\nroot = custom_tree.compute_root\nputs \"Custom tree root: #{root}\"\n\n# Valid structures:\n# - [A, B] → Simple binary node\n# - [[A, B], C] → Left subtree with right leaf\n# - [A] → Single child node\n# Invalid: [A, B, C] → Error (max 2 children per node)\n```\n\n### Configuration Options\n\n```ruby\n# Bitcoin-compatible configuration with double SHA256\nbitcoin_config = Merkle::Config.new(hash_type: :double_sha256)\n\n# Configuration with tagged hashing (Taproot-style)\ntaproot_config = Merkle::Config.taptree\n\n# Configuration with non-sorted hashing (directions needed in proofs)\nnon_sorted_config = Merkle::Config.new(\n  hash_type: :sha256,\n  sort_hashes: false\n)\n```\n\n## Architecture\n\n### Tree Structures\n\n- **BinaryTree**: Bitcoin-compatible merkle tree that duplicates odd nodes\n- **AdaptiveTree**: Unbalanced tree that promotes odd nodes to higher levels for optimized access patterns\n- **CustomTree**: User-defined tree structure using nested arrays for precise control over leaf grouping\n\n### Proof System\n\nThe library generates compact Merkle proofs that include:\n- `siblings`: Array of sibling hashes needed for verification\n- `directions`: Array indicating left (0) or right (1) position at each level\n- `root`: The merkle root hash\n- `leaf`: The original leaf value\n\n### Verification\n\n```ruby\nproof = tree.generate_proof(leaf_index)\nis_valid = proof.valid? # Returns true/false\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchaintope%2Fmerkle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchaintope%2Fmerkle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchaintope%2Fmerkle/lists"}