{"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":{"integrity":"sha512-19muIG07A/AIzmvjq7f+1tvWJy8Ex/LEZtTqE8zoQrT+kBOXZwZUFEwYWvWSzJ+JiEV1cp2hDPfQm/Gfq2JbRw==","shasum":"cf9d0acd7520c5412ec02fbbf2cddbd8e2146c0f","tarball":"http://registry-npm.ywwl.com/simple-handshake/download/simple-handshake-1.1.2.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\nwsFcBAEBCAAQBQJb7AeoCRA9TVsSAnZWagAAoNEP/097GcJlV3LoA0X8C/YC\n52BqxEtoWQ8SnpbbCGIq75tvPNhVWLZ7hOtoeLx6aBLUANVwadWkpKAfsyRk\nNRwVE6reLQFTel1MATOb5yK122DYBi1lEyFRSU1cuLSkevQme67Ln07/tp1a\nqL4qpGV/ydinhUokNXO0XW+/SH7fDLXslGG7IGFglmISi9ts9ohs2AGP3Nvo\ndSpYHggOQREEYvfdCi0I9GWOYr1PN1j7KGMwMrMcYD0B0NGcqeLbYKZOqWmo\nRwWR8NETx0JxN90c8W6Oyq9xgtdFJswh/3CWN9bEA+A9+WH/kio2lcgrg2rw\nDu2A62Y7y/6BxGRXozB2M/D+2BrLTovyqPJuwJ0CExhP3WxQlFtVGLDKFnna\nUwZ6KyCkGK+lhEhAqyqn9ydsxPrqHTswb5DU93JmQzUZc4h6+n3D2nhzzvDW\nISx6bGph4AStRMLOQePZKr1yiwEnAbEXpQwqHISqpGIMcNv0qz+qskJQjI1c\nBg0dWYuyWIcTVhVkL7GLf9iEH1bi8Oc3t9CIMaFwhbeTDUmnXNwUOEVF+YYW\nUrP4iQUX94e5dJQXUi9GZr64gVdkBzUWu1rQf+Byo3oy8bTDa18CIbYCtnyq\nv8AofJTgK1Mfw5h9fjKljWywxYMUJFU7nWgvGbO+GC2WeRYJf/JdNCfFtEI8\nHDEl\r\n=XZk0\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBvUt5dXSmOKjZDZBaVhEnBm8zB3+vV5ZRTzghdM1yfrAiEAslEK79mFVUauQb5soo2w5pHxEjsRBhL+rP52D3MqpJ4="}],"size":5083,"noattachment":false,"key":"/simple-handshake/-/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,"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":1542195112173,"_cnpm_publish_time":1542195112173,"dist-tags":{"latest":"3.0.0"}}