{"name":"merkle-lib","version":"2.0.2","description":"A performance conscious library for merkle root and tree calculations.","keywords":["bitcoin","bitcoinjs-lib","leaf","merkle tree","merkle","root","hash","chain","tree"],"homepage":"https://github.com/bitcoinjs/merkle-lib","bugs":{"url":"https://github.com/bitcoinjs/merkle-lib/issues"},"license":"MIT","author":{"name":"Daniel Cousens"},"files":["index.js","fastRoot.js","proof.js"],"main":"index.js","repository":{"type":"git","url":"git+https://github.com/bitcoinjs/merkle-lib.git"},"scripts":{"coverage":"nyc --check-coverage --branches 90 --functions 90 tape test/*.js","lint":"standard","unit":"tape test/*.js","test":"npm run lint && npm run unit"},"devDependencies":{"nyc":"^6.4.0","standard":"*","tape":"^4.5.1"},"gitHead":"3ae5edb85c885ff5b26c096e26d4ed4d6f4647b4","_id":"merkle-lib@2.0.2","_shasum":"8d380f151e4e381d6acbb4ece5082a8db34ef2d2","_from":".","_npmVersion":"3.10.9","_nodeVersion":"7.0.0","_npmUser":{"name":"dcousens","email":"email@dcousens.com"},"dist":{"shasum":"8d380f151e4e381d6acbb4ece5082a8db34ef2d2","tarball":"http://registry-npm.ywwl.com/merkle-lib/download/merkle-lib-2.0.2.tgz","integrity":"sha512-+rNlgwv/NKfY4hsFzyvlf+309/89YT1idCvRGMHP9WUA2T7PGc+KWeaKJ5Rf8cCRZmYby0/YDnr+5jTQWFdQiA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIATkU4OCa056uzb3sQpbFj6L/zHPZly2qZxlTrUXeidbAiAhI6nYkeN3XWkre8cBbjvfvWUBnFSFy0s8hGO2NQkHXg=="}],"size":2938,"noattachment":false,"key":"/merkle-lib/-/merkle-lib-2.0.2.tgz"},"maintainers":[{"name":"dcousens","email":"email@dcousens.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/merkle-lib-2.0.2.tgz_1478222722453_0.05017642956227064"},"directories":{},"readme":"# merkle-lib\n\n[![Build Status](https://travis-ci.org/bitcoinjs/merkle-lib.png?branch=master)](https://travis-ci.org/bitcoinjs/merkle-lib)\n[![NPM](https://img.shields.io/npm/v/merkle-lib.svg)](https://www.npmjs.org/package/merkle-lib)\n\n[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)\n\nA performance conscious library for merkle root and tree calculations.\n\n**NOTE**: As is,  this 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) 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)`.\n\n\n## Examples\nPreamble\n``` javscript\nvar crypto = require('crypto')\n\nfunction sha256 (data) {\n  return crypto.createHash('sha256').update(data).digest()\n}\n\nvar data = [\n  'cafebeef',\n  'ffffffff',\n  'aaaaaaaa',\n  'bbbbbbbb',\n  'cccccccc'\n].map(x => new Buffer(x, 'hex'))\n\n// ... now, the examples\n```\n\nTree\n``` javascript\nvar merkle = require('merkle-lib')\nvar tree = merkle(data, sha256)\n\nconsole.log(tree.map(x => x.toString('hex')))\n// => [\n//  'cafebeef',\n//  'ffffffff',\n//  'aaaaaaaa',\n//  'bbbbbbbb',\n//  'cccccccc',\n//  'bda5c39dec343da54ce91c57bf8e796c2ca16a1bd8cae6a2cefbdd16efc32578',\n//  '8b722baf6775a313f1032ba9984c0dce32ff3c40d7a67b5df8de4dbaa43a3db0',\n//  '3d2f424783df5853c8d7121b1371650c04241f318e1b0cd46bedbc805b9164c3',\n//  'bb232963fd0efdeacb0fd76e26cf69055fa5facc19a5f5c2f2f27a6925d1db2f',\n//  '2256e70bea2c591190a0d4d6c1415acd7458fae84d8d85cdc68b851da27777d4',\n//  'c2692b0e127b3b774a92f6e1d8ff8c3a5ea9eef9a1d389fe294f0a7a2fec9be1'\n//]\n```\n\nRoot only (equivalent to `tree[tree.length - 1]`)\n``` javascript\nvar fastRoot = require('merkle-lib/fastRoot')\nvar root = fastRoot(data, sha256)\n\nconsole.log(root.toString('hex'))\n// => 'c2692b0e127b3b774a92f6e1d8ff8c3a5ea9eef9a1d389fe294f0a7a2fec9be1'\n```\n\nProof (with verify)\n``` javascript\nvar merkleProof = require('merkle-lib/proof')\nvar proof = merkleProof(tree, data[0])\n\nif (proof === null) {\n  console.error('No proof exists!')\n}\n\nconsole.log(proof.map(x => x && x.toString('hex')))\n// => [\n//   'cafebeef',\n//   'ffffffff',\n//   null,\n//   '8b722baf6775a313f1032ba9984c0dce32ff3c40d7a67b5df8de4dbaa43a3db0',\n//   null,\n//   '2256e70bea2c591190a0d4d6c1415acd7458fae84d8d85cdc68b851da27777d4',\n//   'c2692b0e127b3b774a92f6e1d8ff8c3a5ea9eef9a1d389fe294f0a7a2fec9be1'\n// ]\n\nconsole.log(merkleProof.verify(proof, sha256))\n// => true\n```\n\n\n#### Credits\nThanks to [Meni Rosenfield on bitcointalk](https://bitcointalk.org/index.php?topic=403231.msg9054025#msg9054025) for the math.\n","publish_time":1478222724112,"_cnpm_publish_time":1478222724112,"dist-tags":{"latest":"2.0.11"}}