{"_id":"simple-handshake","_rev":"481576","name":"simple-handshake","description":"Simple Noise handshake state machine","dist-tags":{"latest":"3.0.0"},"maintainers":[{"name":"emilbayes","email":"github@tixz.dk"}],"time":{"modified":"2021-08-05T09:39:37.000Z","created":"2018-10-03T12:09:35.722Z","3.0.0":"2020-09-01T13:17:35.880Z","2.0.0":"2020-05-12T23:27:08.403Z","1.3.1":"2019-09-06T13:05:38.797Z","1.3.0":"2019-07-23T18:57:29.286Z","1.2.0":"2019-07-23T07:37:49.777Z","1.1.2":"2018-11-14T11:31:52.173Z","1.1.1":"2018-11-14T09:52:22.636Z","1.1.0":"2018-11-14T09:27:54.057Z","1.0.1":"2018-10-08T07:52:16.321Z","0.0.0":"2018-10-03T12:09:35.722Z"},"users":{},"author":{"name":"Emil Bay","email":"github@tixz.dk"},"repository":{"type":"git","url":"git+https://github.com/emilbayes/simple-handshake.git"},"versions":{"3.0.0":{"name":"simple-handshake","version":"3.0.0","description":"Simple Noise handshake state machine","main":"index.js","dependencies":{"nanoassert":"^2.0.0","noise-protocol":"^3.0.0"},"devDependencies":{"standard":"^14.3.4","tape":"^4.8.0"},"scripts":{"pretest":"standard","test":"tape tests/*.js"},"repository":{"type":"git","url":"git+https://github.com/emilbayes/simple-handshake.git"},"keywords":[],"author":{"name":"Emil Bay","email":"github@tixz.dk"},"license":"ISC","bugs":{"url":"https://github.com/emilbayes/simple-handshake/issues"},"homepage":"https://github.com/emilbayes/simple-handshake#readme","gitHead":"ff0265da4dff7ac9a41038f20906c3597cb3f3fb","_id":"simple-handshake@3.0.0","_nodeVersion":"14.4.0","_npmVersion":"6.14.5","dist":{"shasum":"76241e702642a65496f8356dd463989ec23e407c","size":6204,"noattachment":false,"key":"/simple-handshake/-/simple-handshake-3.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/simple-handshake/download/simple-handshake-3.0.0.tgz"},"maintainers":[{"name":"emilbayes","email":"github@tixz.dk"}],"_npmUser":{"name":"emilbayes","email":"github@tixz.dk"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/simple-handshake_3.0.0_1598966255696_0.15202318520421776"},"_hasShrinkwrap":false,"publish_time":1598966255880,"_cnpm_publish_time":1598966255880},"2.0.0":{"name":"simple-handshake","version":"2.0.0","description":"Simple Noise handshake state machine","main":"index.js","dependencies":{"nanoassert":"^2.0.0","noise-protocol":"^2.0.0"},"devDependencies":{"standard":"^14.3.4","tape":"^4.8.0"},"scripts":{"pretest":"standard","test":"tape tests/*.js"},"repository":{"type":"git","url":"git+https://github.com/emilbayes/simple-handshake.git"},"keywords":[],"author":{"name":"Emil Bay","email":"github@tixz.dk"},"license":"ISC","bugs":{"url":"https://github.com/emilbayes/simple-handshake/issues"},"homepage":"https://github.com/emilbayes/simple-handshake#readme","gitHead":"93db05e2f0d3ef1299ca958d827a1b0197dc81a7","_id":"simple-handshake@2.0.0","_nodeVersion":"14.2.0","_npmVersion":"6.14.4","dist":{"shasum":"ad6bf4e3b4b2929c2caeb6ca7b5d0e0f69ffece6","size":6202,"noattachment":false,"key":"/simple-handshake/-/simple-handshake-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/simple-handshake/download/simple-handshake-2.0.0.tgz"},"maintainers":[{"name":"emilbayes","email":"github@tixz.dk"}],"_npmUser":{"name":"emilbayes","email":"github@tixz.dk"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/simple-handshake_2.0.0_1589326028257_0.8643576460443332"},"_hasShrinkwrap":false,"publish_time":1589326028403,"_cnpm_publish_time":1589326028403},"1.3.1":{"name":"simple-handshake","version":"1.3.1","description":"Simple Noise handshake state machine","main":"index.js","dependencies":{"nanoassert":"^1.1.0","noise-protocol":"^1.0.0"},"devDependencies":{"tape":"^4.8.0"},"scripts":{"test":"tape test.js"},"repository":{"type":"git","url":"git+https://github.com/emilbayes/simple-handshake.git"},"keywords":[],"author":{"name":"Emil Bay","email":"github@tixz.dk"},"license":"ISC","bugs":{"url":"https://github.com/emilbayes/simple-handshake/issues"},"homepage":"https://github.com/emilbayes/simple-handshake#readme","gitHead":"9117b084403fc7146953fa9987026516a71e2fe3","_id":"simple-handshake@1.3.1","_nodeVersion":"12.10.0","_npmVersion":"6.10.3","dist":{"shasum":"3f3d3ef103cb59e25f85c6b5952a631659e53411","size":6483,"noattachment":false,"key":"/simple-handshake/-/simple-handshake-1.3.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/simple-handshake/download/simple-handshake-1.3.1.tgz"},"maintainers":[{"name":"emilbayes","email":"github@tixz.dk"}],"_npmUser":{"name":"emilbayes","email":"github@tixz.dk"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/simple-handshake_1.3.1_1567775138639_0.2692741708707913"},"_hasShrinkwrap":false,"publish_time":1567775138797,"_cnpm_publish_time":1567775138797},"1.3.0":{"name":"simple-handshake","version":"1.3.0","description":"Simple Noise handshake state machine","main":"index.js","dependencies":{"nanoassert":"^1.1.0","noise-protocol":"^1.0.0"},"devDependencies":{"tape":"^4.8.0"},"scripts":{"test":"tape test.js"},"repository":{"type":"git","url":"git+https://github.com/emilbayes/simple-handshake.git"},"keywords":[],"author":{"name":"Emil Bay","email":"github@tixz.dk"},"license":"ISC","bugs":{"url":"https://github.com/emilbayes/simple-handshake/issues"},"homepage":"https://github.com/emilbayes/simple-handshake#readme","gitHead":"dd3fbae0f6f8ea50bb241ea9f4a0471c070dcaf0","_id":"simple-handshake@1.3.0","_nodeVersion":"10.16.0","_npmVersion":"6.9.0","dist":{"shasum":"7901d7b97046f876d276c64e6347d61c5ab49e99","size":5513,"noattachment":false,"key":"/simple-handshake/-/simple-handshake-1.3.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/simple-handshake/download/simple-handshake-1.3.0.tgz"},"maintainers":[{"name":"emilbayes","email":"github@tixz.dk"}],"_npmUser":{"name":"emilbayes","email":"github@tixz.dk"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/simple-handshake_1.3.0_1563908249148_0.8262427028608723"},"_hasShrinkwrap":false,"publish_time":1563908249286,"_cnpm_publish_time":1563908249286},"1.2.0":{"name":"simple-handshake","version":"1.2.0","description":"Simple Noise handshake state machine","main":"index.js","dependencies":{"nanoassert":"^1.1.0","noise-protocol":"^1.0.0"},"devDependencies":{"tape":"^4.8.0"},"scripts":{"test":"tape test.js"},"repository":{"type":"git","url":"git+https://github.com/emilbayes/simple-handshake.git"},"keywords":[],"author":{"name":"Emil Bay","email":"github@tixz.dk"},"license":"ISC","bugs":{"url":"https://github.com/emilbayes/simple-handshake/issues"},"homepage":"https://github.com/emilbayes/simple-handshake#readme","gitHead":"8aad42ea1ca81f97c97452b718677ac1a38f4521","_id":"simple-handshake@1.2.0","_nodeVersion":"10.16.0","_npmVersion":"6.9.0","dist":{"shasum":"47b21c0ab06fe3015d32d5e3742c184ffc1e4cc0","size":5268,"noattachment":false,"key":"/simple-handshake/-/simple-handshake-1.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/simple-handshake/download/simple-handshake-1.2.0.tgz"},"maintainers":[{"name":"emilbayes","email":"github@tixz.dk"}],"_npmUser":{"name":"emilbayes","email":"github@tixz.dk"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/simple-handshake_1.2.0_1563867469606_0.7066058496272907"},"_hasShrinkwrap":false,"publish_time":1563867469777,"_cnpm_publish_time":1563867469777},"1.1.2":{"name":"simple-handshake","version":"1.1.2","description":"Simple Noise handshake state machine","main":"index.js","dependencies":{"nanoassert":"^1.1.0","noise-protocol":"^1.0.0"},"devDependencies":{"tape":"^4.8.0"},"scripts":{"test":"tape test.js"},"repository":{"type":"git","url":"git+https://github.com/emilbayes/simple-handshake.git"},"keywords":[],"author":{"name":"Emil Bay","email":"github@tixz.dk"},"license":"ISC","bugs":{"url":"https://github.com/emilbayes/simple-handshake/issues"},"homepage":"https://github.com/emilbayes/simple-handshake#readme","gitHead":"4d4155a4e94de40a1449a321b140308f0617d312","_id":"simple-handshake@1.1.2","_npmVersion":"6.4.1","_nodeVersion":"11.1.0","_npmUser":{"name":"emilbayes","email":"github@tixz.dk"},"dist":{"shasum":"cf9d0acd7520c5412ec02fbbf2cddbd8e2146c0f","size":5083,"noattachment":false,"key":"/simple-handshake/-/simple-handshake-1.1.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/simple-handshake/download/simple-handshake-1.1.2.tgz"},"maintainers":[{"name":"emilbayes","email":"github@tixz.dk"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/simple-handshake_1.1.2_1542195111919_0.2585129913316413"},"_hasShrinkwrap":false,"publish_time":1542195112173,"_cnpm_publish_time":1542195112173},"1.1.1":{"name":"simple-handshake","version":"1.1.1","description":"Simple Noise handshake state machine","main":"index.js","dependencies":{"nanoassert":"^1.1.0","noise-protocol":"^0.3.0"},"devDependencies":{"tape":"^4.8.0"},"scripts":{"test":"tape test.js"},"repository":{"type":"git","url":"git+https://github.com/emilbayes/simple-handshake.git"},"keywords":[],"author":{"name":"Emil Bay","email":"github@tixz.dk"},"license":"ISC","bugs":{"url":"https://github.com/emilbayes/simple-handshake/issues"},"homepage":"https://github.com/emilbayes/simple-handshake#readme","gitHead":"24ee63098a362134434e2d1e773bbe0a66a0274f","_id":"simple-handshake@1.1.1","_npmVersion":"6.4.1","_nodeVersion":"11.1.0","_npmUser":{"name":"emilbayes","email":"github@tixz.dk"},"dist":{"shasum":"a411e7754d919a0c94e36643c3c7d4b5402a3dd2","size":5085,"noattachment":false,"key":"/simple-handshake/-/simple-handshake-1.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/simple-handshake/download/simple-handshake-1.1.1.tgz"},"maintainers":[{"name":"emilbayes","email":"github@tixz.dk"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/simple-handshake_1.1.1_1542189142484_0.2809941582593616"},"_hasShrinkwrap":false,"publish_time":1542189142636,"_cnpm_publish_time":1542189142636},"1.1.0":{"name":"simple-handshake","version":"1.1.0","description":"Simple Noise handshake state machine","main":"index.js","dependencies":{"nanoassert":"^1.1.0","noise-protocol":"^0.2.1"},"devDependencies":{"tape":"^4.8.0"},"scripts":{"test":"tape test.js"},"repository":{"type":"git","url":"git+https://github.com/emilbayes/simple-handshake.git"},"keywords":[],"author":{"name":"Emil Bay","email":"github@tixz.dk"},"license":"ISC","bugs":{"url":"https://github.com/emilbayes/simple-handshake/issues"},"homepage":"https://github.com/emilbayes/simple-handshake#readme","gitHead":"dcb0693be7e82084550872049f7d1e9e6254ef63","_id":"simple-handshake@1.1.0","_npmVersion":"6.4.1","_nodeVersion":"11.1.0","_npmUser":{"name":"emilbayes","email":"github@tixz.dk"},"dist":{"shasum":"646350303061ec4f4fab1a0b61082266fc8a3c26","size":5085,"noattachment":false,"key":"/simple-handshake/-/simple-handshake-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/simple-handshake/download/simple-handshake-1.1.0.tgz"},"maintainers":[{"name":"emilbayes","email":"github@tixz.dk"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/simple-handshake_1.1.0_1542187673834_0.4692145649932429"},"_hasShrinkwrap":false,"publish_time":1542187674057,"_cnpm_publish_time":1542187674057},"1.0.1":{"name":"simple-handshake","version":"1.0.1","description":"Simple Noise handshake state machine","main":"index.js","dependencies":{"nanoassert":"^1.1.0","noise-protocol":"^0.2.1"},"devDependencies":{"tape":"^4.8.0"},"scripts":{"test":"tape test.js"},"repository":{"type":"git","url":"git+https://github.com/emilbayes/simple-handshake.git"},"keywords":[],"author":{"name":"Emil Bay","email":"github@tixz.dk"},"license":"ISC","bugs":{"url":"https://github.com/emilbayes/simple-handshake/issues"},"homepage":"https://github.com/emilbayes/simple-handshake#readme","gitHead":"7c40d24e90a0e5482d4e980e1f0ed12c8836af6b","_id":"simple-handshake@1.0.1","_npmVersion":"6.4.1","_nodeVersion":"10.11.0","_npmUser":{"name":"emilbayes","email":"github@tixz.dk"},"dist":{"shasum":"9ee081eacc045afc4fb161d630675f56ff0fa5e9","size":5080,"noattachment":false,"key":"/simple-handshake/-/simple-handshake-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/simple-handshake/download/simple-handshake-1.0.1.tgz"},"maintainers":[{"name":"emilbayes","email":"github@tixz.dk"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/simple-handshake_1.0.1_1538985136185_0.5919697745462407"},"_hasShrinkwrap":false,"publish_time":1538985136321,"_cnpm_publish_time":1538985136321},"0.0.0":{"name":"simple-handshake","version":"0.0.0","description":"Simple Noise handshake over streams","main":"index.js","dependencies":{"duplexify":"^3.6.0","nanoassert":"^1.1.0","noise-protocol":"^0.1.1"},"devDependencies":{"tape":"^4.8.0"},"scripts":{"test":"tape test.js"},"repository":{"type":"git","url":"git+https://github.com/emilbayes/simple-handshake.git"},"keywords":[],"author":{"name":"Emil Bay","email":"github@tixz.dk"},"license":"ISC","bugs":{"url":"https://github.com/emilbayes/simple-handshake/issues"},"homepage":"https://github.com/emilbayes/simple-handshake#readme","gitHead":"d86433a2adeb763949be492afcebc3f85cd01406","_id":"simple-handshake@0.0.0","_npmVersion":"6.4.1","_nodeVersion":"10.11.0","_npmUser":{"name":"emilbayes","email":"github@tixz.dk"},"dist":{"shasum":"afef52ac39e3c192780f6c8544d1023f300690ef","size":2477,"noattachment":false,"key":"/simple-handshake/-/simple-handshake-0.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/simple-handshake/download/simple-handshake-0.0.0.tgz"},"maintainers":[{"name":"emilbayes","email":"github@tixz.dk"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/simple-handshake_0.0.0_1538568575616_0.08645113319516518"},"_hasShrinkwrap":false,"publish_time":1538568575722,"_cnpm_publish_time":1538568575722}},"readme":"# `simple-handshake`\n\n[![Build Status](https://travis-ci.org/emilbayes/simple-handshake.svg?branch=master)](https://travis-ci.org/emilbayes/simple-handshake)\n\n> Simple Noise handshake state machine\n\n## Usage\n\n```js\nvar simpleHandshake = require('simple-handshake')\n\n// Generate static keys. Ideally these are saved as the represent either party's\n// identity\nvar clientKeys = simpleHandshake.keygen()\nvar serverKeys = simpleHandshake.keygen()\n\n// Make a client/server pair. These are also known as initiator/responder\nvar client = simpleHandshake(true, {\n  pattern: 'XX',\n  staticKeyPair: clientKeys\n})\n\nvar server = simpleHandshake(false, {\n  pattern: 'XX',\n  staticKeyPair: serverKeys\n})\n\n// Use a simple Round trip function to do the back and forth.\n// In practise this would go over a network\nrtt(client, server, function (err) {\n  if (err) throw err\n\n  // Now both parties have arrived at the same shared secrets\n  // client.tx === server.rx and server.tx === client.rx\n  console.log(client.split, server.split)\n})\n\nfunction rtt (from, to, cb) {\n  // waiting === true means waiting to receive data, hence it should be false\n  // if we're ready to send data!\n  if (from.waiting !== false) return cb(new Error('Not ready to send data'))\n\n  from.send(null, function (err, buf) {\n    if (err) return cb(err)\n\n    to.recv(buf, function (err) {\n      if (err) return cb(err)\n\n      // Keep going until from is finished\n      if (from.finished === true) return cb()\n\n      // recurse until finished\n      return rtt(to, from, cb)\n    })\n  })\n}\n```\n\n## API\n\n### `var hs = simpleHandshake(isInitiator, [opts])`\n\nOptions include:\n\n```js\n{\n  pattern: 'XX', // Noise handshake pattern. XX transmits the keys\n  prologue: Buffer.alloc(0), // Defaults to empty Buffer\n  staticKeyPair: {publicKey, secretKey}, // Local static key pair\n  remoteStaticKey: Buffer, // Remote public key for other patterns eg. KK\n\n  // Callback when receiving a ephemeral public key from a remote peer.\n  onephemeralkey(remoteEphemeralKey, cb),\n\n  // Callback when receiving a static public key from a remote peer.\n  // Can be used to validate the key against certificates, CRL etc.\n  onstatickey(remoteStaticKey, cb),\n\n  // Callback when handshaking has finished.\n  // Can be used to access the handshakeHash or other state data, before it is\n  // cleared\n  onhandshake(state, cb),\n\n  // Normally not set, but may be if upgrading from another pattern.\n  ephemeralKeyPair: {publicKey, secretKey},\n  remoteEphemeralKey: Buffer\n}\n```\n\n### `hs.waiting`\n\nFlag indicating whether this instance is waiting for remote data, ie. `hs.recv` should be called next. If `false` `hs.send` should be called next.\n\n### `hs.finished`\n\nFlag indicating whether the handshake is finished. If an error occurs this flag\nwill also be set `true`, as the instance is no longer usable.\n\n### `hs.split`\n\nA Noise split containing a `{rx, tx}` object of Buffers which are\n`32 byte shared secret | 8 byte nonce` (a Noise `CipherState`). `rx` at the\ninitiator matches `tx` at the responder.\n\n### `hs.handshakeHash`\n\nChannel binding handshake hash, available after the handshake has completed and\na split has occurred. See the [Noise Specification for details](https://noiseprotocol.org/noise.html#channel-binding)\n\n### `hs.send(payload, cb(err, message))`\n\nEncode a message with a `payload` (which if `null` defaults to an empty buffer),\nfor sending to the other party. Message is written in a preallocated Buffer,\nmeaning that the backing Buffer is reused at the next call to `.send`.\n\n### `hs.recv(message, cb(err, payload))`\n\nDecode a `message` with a `payload` (which may be an empty buffer). `payload` is\nwritten in a preallocated Buffer, meaning that the backing Buffer for is reused\nat the next call to `.recv`, so you must copy the payload if you need it for\nlonger. If a static key is received and `onstatickey` is set, this function is\ncalled between parsing and `cb`.\n\n### `hs.destroy()`\n\nDestroy internal state in case you need to terminate the handshake before it has\ncompleted.\n\n### `SimpleHandshake.keygen()`\n\nGenerate a key pair for use with the `staticKeyPair` option\n\n## Install\n\n```sh\nnpm install simple-handshake\n```\n\n## License\n\n[ISC](LICENSE)\n","_attachments":{},"homepage":"https://github.com/emilbayes/simple-handshake#readme","bugs":{"url":"https://github.com/emilbayes/simple-handshake/issues"},"license":"ISC"}