{"_id":"@biut-block/biutjs-devp2p","_rev":"2-b628abe35e9204693b7f2dd882eab896","name":"@biut-block/biutjs-devp2p","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@biut-block/biutjs-devp2p","version":"1.0.0","description":"A JavaScript implementation of ÐΞVp2p Protocol for BiutBlock, Based on Ethereum","keywords":["biut","p2p","networking","ndp","rlp"],"homepage":"https://github.com/BIUT-Block/biutjs-devp2p","bugs":{"url":"https://github.com/BIUT-Block/biutjs-devp2p/issues"},"license":"MIT","contributors":[{"name":"Li, Yuan","email":"abysmli@gmail.com","url":"https://github.com/abysmli"}],"main":"./lib/index.js","repository":{"type":"git","url":"git+https://github.com/BIUT-Block/biutjs-devp2p.git"},"engines":{"node":">=6.0"},"scripts":{"coverage":"nyc npm run test && nyc report --reporter=text-lcov > .nyc_output/lcov.info","coveralls":"npm run coverage && coveralls <.nyc_output/lcov.info","build":"babel src -d lib","integration":"tape -r babel-register test/integration/*.js","lint":"standard","prepublish":"npm run build","test":"npm run lint && npm run unit && npm run integration","unit":"tape -r babel-register test/*.js"},"dependencies":{"@biut-block/biutjs-rlp":"^1.0.0","babel-runtime":"^6.11.6","bl":"^1.1.2","debug":"^2.2.0","inherits":"^2.0.1","ip":"^1.1.3","k-bucket":"^3.2.1","keccak":"^1.0.0","lru-cache":"^4.0.1","ms":"^0.7.1","safe-buffer":"^5.1.1","secp256k1":"3.6.1"},"devDependencies":{"async":"^2.6.1","babel-cli":"^6.26.0","babel-eslint":"^7.0.0","babel-plugin-transform-class-properties":"^6.16.0","babel-plugin-transform-runtime":"^6.15.0","babel-preset-env":"^1.6.1","babel-register":"^6.14.0","chalk":"^1.1.3","coveralls":"^3.0.2","eslint-config-google":"^0.9.1","nyc":"^11.9.0","standard":"^12.0.1","tape":"^4.9.1"},"standard":{"parser":"babel-eslint"},"gitHead":"0df24941567ba03613de42c353e90158db61bd5a","_id":"@biut-block/biutjs-devp2p@1.0.0","_npmVersion":"5.6.0","_nodeVersion":"8.11.4","_npmUser":{"name":"zuweihan1992","email":"zuweihan1992@gmail.com"},"dist":{"integrity":"sha512-9t9DIatrA4y/Jvc1Cb4Unr9njVxXTGQR32WWrkhiNPcWVjNi1PNCsfseeUNLEWW74D6Y454eWHnkciAgfAmoKA==","shasum":"f078b823ab6a101e2ad430f168b75aa4c28b8d0e","tarball":"https://registry.npmjs.org/@biut-block/biutjs-devp2p/-/biutjs-devp2p-1.0.0.tgz","fileCount":26,"unpackedSize":134198,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJc1XSxCRA9TVsSAnZWagAA+a0QAJgK5I3Ee6wwy3whzqjP\nQ8Zw7UizGqRMLz4pgb/2NNUeWiP7l90VbOlvO1boNwUVEKELUCWmloyvOto/\niq0b2JLTMxBdXNG6Bh2Ppd9MIyQ2Efmu2/A1mVwVmwFI4rmWQR3aVBXP59qp\nh8+OCT1UgPKVd/VtOUAq5WmPs4Jwu850G9i8rLApEDjO9R0As6C/5B05RMOJ\n3yN6UN/Po5xN+T78tH0q+pifftFTMRP3SW+FrAzvTu20DGqQrhpIdeOZ8vOR\nN51f2YXUFdF80UixA3fRT77/gopSQy504K76v46FqNFh+oPz+mZcJok03iXu\nnPA3EO67k5RIHDDqhStmJnvOOvBaAwqn1mWCSqD2WQBTsa12WZ26DOT7gxq9\nhOYCf0QY4bo2lU1vx1dojJ7In7fGMRks/bo8SUZ4NV0/6MOOVfxlnExn24bj\nE4BkgcSh93s7JCEbZF9PMgIFsyTT6fBbXxyzkVdEwHxi6WO8hQ5GT5uL65w1\nl4wgZjeBMGMk9KWcJUt7mVT91HCpXS6Mznb8DblODJEdJJ8w8mUg5TSC31gl\noi48/nRkpZe9qzX9VAwaanbjdEFbWYuuOHaIluYHpVdYXrGJbcocv/ua/2Co\nR72Hpr+xuZyP9vLWWIb3tVMW7bP/mqLBK+StOQApAMnaFqylSUQqAlJXCr3R\nvtYO\r\n=fFSK\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEjtdqHcvxg8IfETy0ksCs6SyWHZzzN4Msaj65Dae5IoAiEA+0e8s/9EWWAQ1/whfCLZWaBWzu4ovfbisjGVb3pYQG0="}]},"maintainers":[{"name":"zuweihan1992","email":"zuweihan1992@gmail.com"},{"name":"tornadoming","email":"ming1992liu@gmail.com"},{"name":"g277321","email":"g277321@gmail.com"},{"name":"feiminhao","email":"fei.minhao1990@gmail.com"},{"name":"abysmli","email":"abysmli@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/biutjs-devp2p_1.0.0_1557492912395_0.21050750692518116"},"_hasShrinkwrap":false},"1.0.1":{"name":"@biut-block/biutjs-devp2p","version":"1.0.1","description":"A JavaScript implementation of ÐΞVp2p Protocol for BiutBlock, Based on Ethereum","keywords":["biut","p2p","networking","ndp","rlp"],"homepage":"https://github.com/BIUT-Block/biutjs-devp2p","bugs":{"url":"https://github.com/BIUT-Block/biutjs-devp2p/issues"},"license":"MIT","contributors":[{"name":"Li, Yuan","email":"abysmli@gmail.com","url":"https://github.com/abysmli"}],"main":"./lib/index.js","repository":{"type":"git","url":"git+https://github.com/BIUT-Block/biutjs-devp2p.git"},"engines":{"node":">=6.0"},"scripts":{"coverage":"nyc npm run test && nyc report --reporter=text-lcov > .nyc_output/lcov.info","coveralls":"npm run coverage && coveralls <.nyc_output/lcov.info","build":"babel src -d lib","integration":"tape -r babel-register test/integration/*.js","lint":"standard","prepublish":"npm run build","test":"npm run lint && npm run unit && npm run integration","unit":"tape -r babel-register test/*.js"},"dependencies":{"@biut-block/biutjs-rlp":"^1.0.0","babel-runtime":"^6.11.6","bl":"^1.1.2","debug":"^2.2.0","inherits":"^2.0.1","ip":"^1.1.3","k-bucket":"^3.2.1","keccak":"^1.0.0","lru-cache":"^4.0.1","ms":"^0.7.1","safe-buffer":"^5.1.1","secp256k1":"3.6.1"},"devDependencies":{"async":"^2.6.1","babel-cli":"^6.26.0","babel-eslint":"^7.0.0","babel-plugin-transform-class-properties":"^6.16.0","babel-plugin-transform-runtime":"^6.15.0","babel-preset-env":"^1.6.1","babel-register":"^6.14.0","chalk":"^1.1.3","coveralls":"^3.0.2","eslint-config-google":"^0.9.1","nyc":"^11.9.0","standard":"^12.0.1","tape":"^4.9.1"},"standard":{"parser":"babel-eslint"},"gitHead":"313b0963cf066b2f72aec37977f1e273749fcef2","_id":"@biut-block/biutjs-devp2p@1.0.1","_nodeVersion":"8.16.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-DlF/2IW/3+ybIfvnBXmhQ8iinMGQdF9NMCqc2ED6BP4+BwdrD/Y7tcN6q7n6J4fHySQEaPPTE9QuSeH/Uv6F1w==","shasum":"9573c9c559301d6306c38c7df91b2466b95fb335","tarball":"https://registry.npmjs.org/@biut-block/biutjs-devp2p/-/biutjs-devp2p-1.0.1.tgz","fileCount":26,"unpackedSize":132040,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdAud8CRA9TVsSAnZWagAACkgP/1gTMGitE4gC78K/Z57z\nWLqXhfNftGcafYUuZKNIyMBSf+e81/3e/e7ggAXXohy3F4R69zgbJtXkLX+U\nhmtrzgP/I1zMCYVcGYSbLDpviB2uC2fJcRv6RBU2UiZHv8R/BEYltUAbpbWP\nlPwyJcbgCALPWq0q43bRJ2M0Ws8izLTCr+n3SFsMRRjYrazxuFxUN6OuFe1A\nMaWuyOhFF2WBTPrhYU4m/ayUfzQjS4lYfD3eO5em0bVMQ9hbEIqvyWkTK4I7\nWUyaBTiKumlGhFEmO17kXkA8euRtC+dT3llGlaOJpV9rVXwPNjT98G0haRGM\nEFi9L8+qokmRY9DnfWJiJ5kQLBj+E08DvmxecJvxKTuX+PmiaoYCL0ZpQE3l\n7m8+xRy5uXhOIUTXiQoYuo6ama/J5kHhddsulD69dWjeHyOeTXYQW9eHINfg\npepxSaoHM1QbMAGckN65183u6iMotZm41iupij10tJ7UPHt6LTA1R1aQuxh4\nxK7XyOeRS+IX1JdNo/RDw8Q8OTsTqoaJfPFZ/EEEdTpzLAFth3xb65Eva8Vs\n0Z9IrF11883rrkOX8qaqDj4Cpj9us31cEGZI+pmdx5wqIIA4/cPMkB6kFTrT\n6A/XwGbNeePbTo8+Zi1Iu4LztxvAhSHr1xca+pyj58ImfTKpZX7NDYmcadGg\ndu72\r\n=J060\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHEcBtlUCZsRZikWrv4rwEbyBUodyGeD6gh8opsaVUcwAiBn4qS1vZIAmmLNMZlf+F6+XUQIbakIYOifmdZC8Yv0Jg=="}]},"maintainers":[{"name":"abysmli","email":"abysmli@gmail.com"},{"name":"feiminhao","email":"fei.minhao1990@gmail.com"},{"name":"g277321","email":"g277321@gmail.com"},{"name":"tornadoming","email":"ming1992liu@gmail.com"},{"name":"zuweihan1992","email":"zuweihan1992@gmail.com"}],"_npmUser":{"name":"abysmli","email":"abysmli@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/biutjs-devp2p_1.0.1_1560471419934_0.20009681021411407"},"_hasShrinkwrap":false}},"time":{"created":"2019-05-10T12:55:12.199Z","1.0.0":"2019-05-10T12:55:12.590Z","modified":"2022-04-04T19:14:51.994Z","1.0.1":"2019-06-14T00:17:00.066Z"},"maintainers":[{"name":"abysmli","email":"abysmli@gmail.com"},{"name":"feiminhao","email":"fei.minhao1990@gmail.com"},{"name":"g277321","email":"g277321@gmail.com"},{"name":"tornadoming","email":"ming1992liu@gmail.com"},{"name":"zuweihan1992","email":"zuweihan1992@gmail.com"}],"description":"A JavaScript implementation of ÐΞVp2p Protocol for BiutBlock, Based on Ethereum","homepage":"https://github.com/BIUT-Block/biutjs-devp2p","keywords":["biut","p2p","networking","ndp","rlp"],"repository":{"type":"git","url":"git+https://github.com/BIUT-Block/biutjs-devp2p.git"},"contributors":[{"name":"Li, Yuan","email":"abysmli@gmail.com","url":"https://github.com/abysmli"}],"bugs":{"url":"https://github.com/BIUT-Block/biutjs-devp2p/issues"},"license":"MIT","readme":"# biutjs-devp2p\n\n[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)\n\nThis library bundles different components for lower-level peer-to-peer connection and message exchange:\n\n- Distributed Peer Table (NDP) / Node Discovery\n- RLP Transport Protocol (biutjs-rlp)\n- SEC Wire Protocol (SEC)\n\n## Run/Build\n\nThis library has to be compiled with babel to a ``Node 6`` friendly source format.\nFor triggering a (first) build to create the ``lib/`` directory run:\n\n```\nnpm run build\n```\n\nYou can also use babel just-in-time compilation to run a script:\n\n```\nnode -r babel-register [YOUR_SCRIPT_TO_RUN.js]\n```\n\n## Usage/Examples\n\nAll components of this library are implemented as Node ``EventEmitter`` objects\nand make heavy use of the Node.js network stack.\n\nYou can react on events from the network like this:\n\n```\nndp.on('peer:added', (peer) => {\n  // Your Codes...\n})\n```\n\n## Distributed Peer Table / Node Discovery Protocol (NDP)\n\nMaintain/manage a list of peers, see [./src/ndp/](./src/ndp/), also \nincludes node discovery ([./src/ndp/server.js](./src/ndp/server.js))\n\n### Usage\n\nCreate your peer table:\n\n```\nconst ndp = new NDP(Buffer.from(PRIVATE_KEY, 'hex'), {\n  endpoint: {\n    address: '0.0.0.0',\n    udpPort: null,\n    tcpPort: null\n  }\n})\n```\n\n### API\n\n\n#### `NDP` (extends `EventEmitter`)\nNDP Manages a Kademlia DHT K-bucket for storing peer information \nand a BanList for keeping a list of bad peers. ``server.js`` implements the node discovery (``ping``, ``pong``, ``findNeighbours``).\n\n##### `new NDP(privateKey, options)`\nCreates new NDP object\n- `privateKey` - Key for message encoding/signing.\n- `options.refreshInterval` - Interval in ms for refreshing (calling ``findNeighbours``) the peer list (default: ``60s``).\n- `options.createSocket` - A datagram (dgram) ``createSocket`` function, passed to ``Server`` (default: ``dgram.createSocket.bind(null, 'udp4')``).\n- `options.timeout` - Timeout in ms for server ``ping``, passed to ``Server`` (default: ``10s``).\n- `options.endpoint` - Endpoint information to send with the server ``ping``, passed to ``Server`` (default: ``{ address: '0.0.0.0', udpPort: null, tcpPort: null }``).\n\n#### `ndp.bootstrap(peer)` (``async``)\nUses a peer as new bootstrap peer and calls ``findNeighbouts``.\n- `peer` - Peer to be added, format ``{ address: [ADDRESS], udpPort: [UDPPORT], tcpPort: [TCPPORT] }``.\n\n#### `ndp.addPeer(object)` (``async``)\nAdds a new peer.\n- `object` - Peer to be added, format ``{ address: [ADDRESS], udpPort: [UDPPORT], tcpPort: [TCPPORT] }``.\n\nFor other utility functions like ``getPeer``, ``getPeers`` see [./src/ndp/index.js](./src/ndp/index.js).\n\n### Events\n\nEvents emitted:\n\n| Event         | Description                              |\n| ------------- |:----------------------------------------:|\n| peer:added    | Peer added to DHT bucket                 |\n| peer:removed  | Peer removed from DHT bucket             |\n| peer:new      | New peer added                           |\n| listening     | Forwarded from server                    |\n| close         | Forwarded from server                    |\n| error         | Forwarded from server                    |\n\n## RLP Transport Protocol\n\nConnect to a peer, organize the communication, see [./src/rlp/](./src/rlp/)\n\n### Usage\n\nCreate your ``RLP`` object:\n\n```\nconst rlp = new devp2p.RLP(PRIVATE_KEY, {\n  ndp: ndp,\n  maxPeers: 25,\n  capabilities: [\n    devp2p.SEC.sec\n  ],\n  listenPort: null\n})\n```\n\n### API\n\n#### `RLP` (extends `EventEmitter`)\nManages the handshake (`ECIES`) and the handling of the peer communication (``Peer``).\n\n##### `new RLPx(privateKey, options)`\nCreates new RLPx object\n- `privateKey` - Key for message encoding/signing.\n- `options.timeout` - Peer `ping` timeout in ms (default: ``10s``).\n- `options.maxPeers` - Max number of peer connections (default: ``10``).\n- `options.clientId` - Client ID string (default example: ``sec``).\n- `options.remoteClientIdFilter` - Optional list of client ID filter strings (e.g. `['sec']`).\n- `options.capabilities` - Upper layer protocol capabilities, e.g. `[devp2p.SEC.sec]`.\n- `options.listenPort` - The listening port for the server or ``null`` for default.\n- `options.ndp` - `NDP` object for the peers to connect to (default: ``null``, no `NDP` peer management).\n\n#### `rlp.connect(peer)` (``async``)\nManually connect to peer without `NDP`.\n- `peer` - Peer to connect to, format ``{ id: PEER_ID, address: PEER_ADDRESS, port: PEER_PORT }``.\n\nFor other connection/utility functions like ``listen``, ``getPeers`` see [./src/rlp/index.js](./src/rlp/index.js).\n\n### Events\n\nEvents emitted:\n\n| Event         | Description                              |\n| ------------- |:----------------------------------------:|\n| peer:added    | Handshake with peer successful           |\n| peer:removed  | Disconnected from peer                   |\n| peer:error    | Error connecting to peer                 |\n| listening     | Forwarded from server                    |\n| close         | Forwarded from server                    |\n| error         | Forwarded from server                    |\n\n## SECBlock Wire Protocol (SEC)\n\nUpper layer protocol for exchanging SECBlock network data like block headers or transactions with a node, see [./src/sec/](./src/sec/).\n\n### Usage\n\nSend the initial status message with ``sendStatus()``, then wait for the corresponding `status` message\nto arrive to start the communication.\n\n```\nsec.once('status', () => {\n  // Send an initial message\n  sec.sendMessage()\n})\n```\n\nWait for follow-up messages to arrive, send your responses. \n\n```\nsec.on('message', async (code, payload) => {\n  if (code === devp2p.SEC.MESSAGE_CODES.NEW_BLOCK_HASHES) {\n    // Do something with your new block hashes :-)\n  }\n})\n```\n\nSee the ``example.js`` example for a more detailed use case.\n\n### API\n\n#### `SEC` (extends `EventEmitter`)\nHandles the different message types like `NEW_BLOCK_HASHES` or `GET_NODE_DATA` (see `MESSAGE_CODES`) for\na complete list. Currently protocol version `PV` is supported.\n\n##### `new SEC(privateKey, options)`\nNormally not instantiated directly but created as a ``SubProtocol`` in the ``Peer`` object.\n- `version` - The protocol version for communicating, e.g. `1`.\n- `peer` - `Peer` object to communicate with.\n- `send` - Wrapped ``peer.sendMessage()`` function where the communication is routed to.\n\n#### `sec.sendStatus(status)`\nSend initial status message.\n- `status` - Status message to send, format ``{ networkId: CHAIN_ID, td: TOTAL_DIFFICULTY_BUFFER, bestHash: BEST_HASH_BUFFER, genesisHash: GENESIS_HASH_BUFFER }``.\n\n#### `sec.sendMessage(code, payload)`\nSend initial status message.\n- `code` - The message code, see `MESSAGE_CODES` for available message types.\n- `payload` - Payload as a list, will be rlp-encoded.\n\n### Events\n\nEvents emitted:\n\n| Event         | Description                              |\n| ------------- |:----------------------------------------:|\n| message       | Message received                         |\n| status        | Status info received                     |\n\n## Tests\n\nThere are unit tests in the ``test/`` directory which can be run with:\n\n```\nnpm run test\n```\n\n## License\n\nMIT\n","readmeFilename":"README.md"}