{"_id":"@dashevo/blockchain-spv","_rev":"16-428d3c0505d402f18303e0c5b1eefc2a","name":"@dashevo/blockchain-spv","dist-tags":{"latest":"3.1.3"},"versions":{"3.1.3":{"name":"@dashevo/blockchain-spv","version":"3.1.3","keywords":["dash","blockchain","spv","webcoin"],"author":{"name":"Matt Bell","email":"mappum@gmail.com"},"license":"MIT","_id":"@dashevo/blockchain-spv@3.1.3","maintainers":[{"name":"alex-werner","email":"alex@werner.fr"},{"name":"andyfreer","email":"andy@dash.org"},{"name":"antouhou","email":"antouhou@gmail.com"},{"name":"cofresi","email":"cofresi@dash.org"},{"name":"dreyacosta","email":"david.rey.acosta@gmail.com"},{"name":"kamuela","email":"kamuela.franco@gmail.com"},{"name":"nmarley","email":"nathan.marley@gmail.com"},{"name":"pierrevr","email":"pierre@dash.org"},{"name":"seigler","email":"joshua@seigler.net"},{"name":"shumkov","email":"ivan@shumkov.ru"},{"name":"snogcel","email":"ledniknoj@gmail.com"}],"homepage":"https://github.com/dashevo/blockchain-spv#readme","bugs":{"url":"https://github.com/dashevo/blockchain-spv/issues"},"dist":{"shasum":"d37cab204c8d0fc7dc3b12ce7ccbbf45cf032bba","tarball":"https://registry.npmjs.org/@dashevo/blockchain-spv/-/blockchain-spv-3.1.3.tgz","fileCount":6,"integrity":"sha512-Io3gQXC8S6aCjaUSxktnZ9yb+8r9YxxP89xw+MXnVujbX+sa5wr8NuHPXwrOL9rgQuk9HnazckDb9Q2yxmtESw==","signatures":[{"sig":"MEUCIC+XGSDAeF/dLcTVldy8p/C96V1mOxhHLQe0yPi7Eh3KAiEAvfIIzWssTTFjjepn4ovXQpqLxnW/mzNWpnX4MJmCFP8=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":34027,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa0kdzCRA9TVsSAnZWagAAsmAP/iAiKKAZdx2XkAkhPpXD\nbuL74iJ6sLDTTt4pByDmb4UINRxXBlUEFWVJfh2ZtAbD1Ov/nAEoLXg2XHk0\nYvdPBLzPIuxXSLIsWMXKy/LG7E4yACF4Mra00F9M28U7IFjKropQFCO3J66X\nHeFRyz8TfLvzEf8aHXSI46BDh86mR9GmAWsCSqUaIifcaJjmnE8DYBrFD1Bq\nTC/hYjaQbPb46SyGMfgGTb7Jc4xy6gDT5K1FsLFCNEmF4l6a/TVShxIbkX+O\nxbphjfoyplrg9dCJzr4oqqRkmyoknBingnXaZM1CBUyMYvH8sr2b43rykl5C\nZL9H3IUFo7jAIyXSP4GZJkak50Tza8a4uELObnYNtXDlqvniuEJgAjIQm5RF\nLygrHLd41fv5DIUrYY63UINoPpsCkWjfaIpsUslOnHwTkhG6ksnvvV6rXXr7\nIlQYC8S5mry39D9aGGanZHji7w0rqf4aXmdw1Mn2hVGbgESk95eHArCPp3KO\n34EImAl3fHlBLHaEHPLV25KKVjjFhr7Cba5+63F5iGE/pDaIpWHhOEiVSMZX\nqtlFUEr4woK1btnHDIn8zp0XmVQG9uZipvyoTKs3x2Wpji5o4ZaRG+eNsGLm\nmp4Q1QHiRIINhBMB/R/OcUpiOl51DS71bGn6WUjuxuYWGvapIAQ/e+W52XUE\nNzBg\r\n=IMup\r\n-----END PGP SIGNATURE-----\r\n"},"main":"index.js","gitHead":"b0e2c1a804edfd694d2139ef37910ae2fff42d3b","scripts":{"test":"standard src/*.js test/*.js && nyc tape test/*.js | faucet && nyc report","build":"rm -rf lib && babel --presets es2015 src -d lib","source":"rm -rf lib && ln -s src lib","publish":"npm run source","prepublish":"npm run build","test-browser":"npm run build && test/browser.sh && npm run source"},"_npmUser":{"name":"alex-werner","email":"alex@werner.fr"},"repository":{"url":"git+https://github.com/dashevo/blockchain-spv.git","type":"git"},"_npmVersion":"5.5.1","description":"Stores blockchain headers and verifies transactions with SPV","directories":{"test":"test"},"_nodeVersion":"8.9.3","dependencies":{"async":"^1.5.2","from2":"^2.1.1","inherits":"^2.0.1","dash-util":"^2.0.0","varstruct":"^5.1.0","setimmediate":"^1.0.4","object-assign":"^4.1.0","buffer-reverse":"^1.0.1","varuint-bitcoin":"^1.0.4","bitcore-lib-dash":"^0.13.19","flush-write-stream":"^1.0.0","level-transactions":"^1.5.3"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^6.4.4","tape":"^4.4.0","zuul":"^3.10.1","faucet":"0.0.1","levelup":"^1.3.1","memdown":"^1.1.1","standard":"^7.0.0","babel-cli":"^6.6.5","zuul-ngrok":"^4.0.0","webcoin-dash":"^3.0.0","event-cleanup":"^1.0.3","babel-preset-es2015":"^6.6.0"},"_npmOperationalInternal":{"tmp":"tmp/blockchain-spv_3.1.3_1523730290092_0.5113605187731436","host":"s3://npm-registry-packages"}}},"time":{"created":"2018-04-14T18:24:50.044Z","modified":"2026-01-20T16:36:14.285Z","3.1.3":"2018-04-14T18:24:50.201Z"},"bugs":{"url":"https://github.com/dashevo/blockchain-spv/issues"},"author":{"name":"Matt Bell","email":"mappum@gmail.com"},"license":"MIT","homepage":"https://github.com/dashevo/blockchain-spv#readme","keywords":["dash","blockchain","spv","webcoin"],"repository":{"url":"git+https://github.com/dashevo/blockchain-spv.git","type":"git"},"description":"Stores blockchain headers and verifies transactions with SPV","maintainers":[{"email":"ivan@shumkov.ru","name":"shumkov"},{"email":"obusco@gmail.com","name":"alex-werner"},{"email":"nathan.marley@gmail.com","name":"nmarley"},{"email":"cofresi@dash.org","name":"cofresi"},{"email":"evodeploy@blackcarrot.be","name":"evodeploy"},{"email":"djavidoff@gmail.com","name":"jawid-h"}],"readme":"# blockchain-spv\n\n[![npm version](https://img.shields.io/npm/v/@dashevo/blockchain-spv.svg)](https://www.npmjs.com/package/@dashevo/blockchain-spv)\n[![Build Status](https://travis-ci.org/dashevo/blockchain-spv?branch=master)](https://travis-ci.org/dashevo/blockchain-spv)\n[![Dependency Status](https://david-dm.org/dashevo/blockchain-spv.svg)](https://david-dm.org/dashevo/blockchain-spv\n\n**Stores blockchain headers and verifies transactions with SPV**\n\n## Usage\n\n`npm install @dashevo/blockchain-spv`\n\n```js\n// import blockchain parameters for Dash\nvar params = require('webcoin-dash').blockchain\n\n// create a LevelUp database where the block data should be stored\nvar db = levelup('dash.chain', { db: require('memdown') })\n\n// create blockchain\nvar Blockchain = require('@dashevo/blockchain-spv')\nvar chain = new Blockchain(params, db)\n\n// wait for the blockchain to be ready\nchain.on('ready', function () {\n  // use the blockchain\n}\n```\n\n`Blockchain` stores and verifies block headers, and does SPV (lite client) verification. It is compatible with Dash and Bitcoin-derived blockchains.\n\n----\n#### `new Blockchain(params, db)`\n\nCreates an SPV `Blockchain` which stores and verifies block headers.\n\n`params` should be the blockchain parameters for the blockchain you wish to use. Parameters for Dash are available at `require('webcoin-dash').blockchain`. For more info about params you can use, see the [Parameters](#parameters) section.\n\n`db` should be a [`LevelUp`](https://github.com/Level/levelup) instance where block data will be stored. The db should not be shared with another Blockchain (if you need to, use [`level-sublevel`](https://github.com/dominictarr/level-sublevel) to create a sub-section of your db).\n\nMake sure to wait for the `ready` event before using the blockchain.\n\n----\n#### `chain.addHeaders(headers, callback)`\n\nAdds block headers to the chain. `headers` should be an array of contiguous, ascending block headers. The headers will be verified (checked to make sure the expected amount of work was done, the difficulty was correct, etc.). The callback will be called with `cb(err, header)` where `header` is an invalid header if there was a validation error.\n\n----\n#### `chain.createWriteStream()`\n\nReturns a writable stream that takes in arrays of block headers and adds them to the chain. This is essentially just a stream wrapper for `chain.addHeaders()`, making it easier to get headers from a `HeaderStream` (from the [`bitcoin-net`](https://github.com/mappum/bitcoin-net) module).\n\n----\n#### `chain.createReadStream([opts])`\n\nReturns a readable stream that outputs blocks from the blockchain (in order). The stream will stay open even when it reaches the chain tip, and will output new blocks as they are received (this means you don't have to think about whether the chain is done syncing or not).\n\nIf a reorg happens (blocks that have been emitted are now on an invalid fork), the stream will emit the now-invalid blocks again in descending order (so that each can be un-processed). Each block has a boolean `add` property which is `false` if it is being removed from the chain. **NOTE:** It is important to always check the value of `block.add` and un-process blocks when they are invalidated.\n\n`opts` may contain the following options:\n- `from` *Buffer* (default: `null`) - start the stream at the block with this hash (exclusive). If `from` is `null`, the stream will start at the genesis block.\n\n----\n#### `chain.getBlock(hash, callback)`\n\nGets a block in the chain with hash `hash`. `hash` must be a Buffer. The callback is called with `cb(err, block)`.\n\n----\n#### `chain.getBlockAtHeight(height, callback)`\n\nGets a block in the chain with height `height`. The callback is called with `cb(err, block)`.\n\nNote that this requires the blockchain to be traversed (from the tip or genesis block, whichever is closest), so it runs in `O(N/2)` time.\n\n----\n#### `chain.getBlockAtTime(time, callback)`\n\nGets the highest block with a time that comes before or on `time`. `time` should be in [Unix time](https://en.wikipedia.org/wiki/Unix_time) measured in seconds (not milliseconds as returned by `Date.now()`). The callback is called with `cb(err, block)`.\n\nNote that this requires the blockchain to be traversed (from the tip or genesis block, whichever is closest), so it runs in `O(N)` time.\n\n----\n#### `chain.getTip()`\n\nReturns the highest block added to the chain.\n\n----\n#### `chain.getPath(from, to, callback)`\n\nGets the path of blocks between `from` and `to`. This is useful to know which blocks to process or unprocess when getting from one part of a chain to another (including going across forks). Calls the callback with `cb(err, path)` where `path` is the following:\n```js\n{\n  add: Array,\n  // an array of Blocks which should be processed\n\n  remove: Array,\n  // an array of Blocks which should be unprocessed\n\n  fork: Block\n  // the first block of the fork (if any)\n}\n```\n\n**Examples:**\n```\n[a]<-[b]<-[c]<-[d]\n\n'getPath(a, d)' results in:\n{\n  add: [ b, c, d ],\n  remove: [],\n  fork: undefined\n}\n\n'getPath(d, a)' results in:\n{\n  add: [],\n  remove: [ d, c, b ],\n  fork: undefined\n}\n```\n\n```\n[a]<-[b]<-[c]<-[d]\n  \\\n  [e]<-[f]\n\n'getPath(f, d)' results in:\n{\n  remove: [ f, e ],\n  add: [ b, c, d ],\n  fork: e\n}\n```\n\n----\n#### `chain.getPathToTip(from, callback)`\n\nA convenience method for `chain.getPath(from, chain.getTip(), cb)`.\n\n----\n### Parameters\n\nParameters specify blockchain rules and constants for different cryptocurrencies and blockchains. Parameters should contain the following:\n```js\n{\n  // REQUIRED\n\n  // the data used in the header of the genesis block for this blockchain\n  genesisHeader: {\n    version: Number,\n    prevHash: Buffer,\n    merkleRoot: Buffer,\n    time: Number,\n    bits: Number,\n    nonce: Number\n  },\n\n  // called to check if we should recalculate the difficulty this block\n  // should call the callback with `cb(err, retarget)`\n  // where `retarget` is a boolean\n  shouldRetarget: function (block, callback) { ... },\n\n  // called to calculate the expected difficulty for `block`\n  // should call the callback with `cb(err, target)`,\n  // where `target` is a Buffer containing the target hash\n  calculateTarget: function (block, blockchain, callback) { ... },\n\n  // called to compute the hash of the header used to verify mining\n  // should call the callback with `cb(err, hash)`,\n  // where `hash` is a Buffer\n  miningHash: function (header, callback) { ... },\n\n  // OPTIONAL\n\n  // an array of blocks to use to speed up initial blockchain sync,\n  // or as an extra source of data for verifying headers received from peers.\n  // any number of blocks can be provided, and they should be sorted ascending by height\n  checkpoints: [\n    {\n      height: Number,\n      header: {\n        version: Number,\n        prevHash: Buffer,\n        merkleRoot: Buffer,\n        time: Number,\n        bits: Number,\n        nonce: Number\n      }\n    }\n  ]\n}\n```\n\nFor some examples, see these parameter repos:\n- [`webcoin-bitcoin`](https://github.com/mappum/webcoin-bitcoin/blob/master/src/blockchain.js)\n- [`webcoin-bitcoin-testnet`](https://github.com/mappum/webcoin-bitcoin-testnet/blob/master/src/blockchain.js)\n- [`webcoin-zcash-alpha`](https://github.com/mappum/webcoin-zcash-alpha/blob/master/src/blockchain.js)\n","readmeFilename":"README.md"}