{"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":{"integrity":"sha512-bIO48aBlyIoKs0j5gzWp/ecJ+oVSvkZBxh/ubY6qsKR43rJ8f+a4oEDXPs9saMOi99e5+MAWUM7LIJQPY7UdEA==","shasum":"a411e7754d919a0c94e36643c3c7d4b5402a3dd2","tarball":"http://registry-npm.ywwl.com/simple-handshake/download/simple-handshake-1.1.1.tgz","fileCount":7,"unpackedSize":12180,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJb6/BXCRA9TVsSAnZWagAACWYP/jztvzEYZYz8DcFV0yzt\nv2cN4P70vQj0YxWoymthUohQ5iRnBiKLs/2niBo3wp2OaIHe220hK2laivEW\nhoj3LG1HswQehcsoJJvD+ga5fUCgLw2U/75SpENaVboM/Vn/evEikGPqJv2I\nUEcfSLgZ+nqZmsHcBaHCk2cTQgTJgIBGPRh3ilz1xd76Qo1OmTgw/FCKXcUx\nwwiVlqX0R5JGwrEUg+VfRPDjrbDqlP8LTsoK122ld2JAeOQgo7jJtV5OtYH3\nQXCT7NFkGnpcksxD/+VvpjXB1dXNKDFCZuiZ40M6vHfHbHbWJsqjk+K8z6Dj\n6MAd5pyVfofUaezMpgBP6MSHB6mhqJ7K2eclvIwjpzm6xuy6B5xxxjzkUeUK\nOI4+9CYwZgZloycECblUmNHbmOzG1pbCWlvxGT+AxYRmE5Whr8iUWaaC8vF1\nPWdS19FsxPgVHg47s2UEID6ldY6OixObjcgtObw+1fwub2T12LCGyDb1tK7E\nCNTwLuzmK9VwXX5QMGY9L98otjUCUsvNEa/9GoujFh5XjBP/7UJEJkrRawCH\ndLt/H5LIwAjE4AROvLzL0mXqlOsihHgCUBrdVBtiWJZT/IEUX2JEVZPetT+l\nA2/QAzrHEaCk0gVsGYsgkPH5KjSgHEkXxqXwPYzNoH6FEN5ThE5yQyJ7Zu6i\n4Dfu\r\n=zMRh\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDx/F5XSarGmkc6GlfajEGuvRAVp9UMVC2HTOqQ5fIi/wIgKxFVm8k62VopvqqkCePjQPWUyBU21JIFS2u/MNj5+Rk="}],"size":5085,"noattachment":false,"key":"/simple-handshake/-/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,"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","publish_time":1542189142636,"_cnpm_publish_time":1542189142636,"dist-tags":{"latest":"3.0.0"}}