{"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":{"integrity":"sha512-8Te0vlxvhpNCMgwnWFTbRR6Re2l8hq8wyXQc3lY9dPYXFxYwVkh79LhDQHFCOWRavmbiOdfqq1l5HT/73Rn2/w==","shasum":"76241e702642a65496f8356dd463989ec23e407c","tarball":"http://registry-npm.ywwl.com/simple-handshake/download/simple-handshake-3.0.0.tgz","fileCount":7,"unpackedSize":19346,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfTknwCRA9TVsSAnZWagAAOakP/RY6+x4waI0WZzqPYFIK\nIoapDOuCQs54h45UwlbtjiskaVdnc51YBnGS2cU2eigIZKxS7zTvILdNae11\nZPnmtqIX/55x0myh73fwLxDNhdpaBxl8sXq8SRPKM/dZMAnRGWu2nXZ8JAIm\nYIhxESPTZOMb7/uegZ1V3t3kOyMYCzu6rSpPI60cVJErUF2UQz/KLAHaIA+R\nvR9qDTF1uYbab+7fI/6OrcovCNnQEQmkdehcIx53idS6Xl+PgVgILYye193Z\n/S/VhMVIMHQlMCJFoZRqkwaogN1X4sUO4OWHQ3FiNrqLviBVd2zW5tXLW7Y0\nCqX7070vTmFpLG+P1B5xsA7gm1nBYj0GX/iCE1Ycnn0ZbEGfSdZaB0dgrThC\n+KCVenmf54Yg0bG/GDDyHyz4i4Nn7x14+2RlieCP+h0hpArLrYGzYzqnvoch\nkQs+XPO10ZJXwIHqrRbbKR8JRVP8CbXKh6RR95IHteMZYyKIDYHIQ1FH3vsM\nFMW5wG6D4zEH58KVpRlG5a0ZYWB//SnGwzBDuZB2RXcc3hU/JajPFVGqy3aS\nH7gNVe/dnsRQCwGAjajmqfhkZGBr40ICDLTF5Qyv/OLh2vnRkkaDlfLnpgXS\nWX2yoZgfg6njwzdsj0sbA6QoHrNZs6+PxMYM7ZJXOe4tpczvIT4zlugLF5rV\nMskV\r\n=f1B4\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDIi9PHeDJCTOkJhFROxhDRvLdh8qR0FYbrNU9w8tGSUQIgHEFFpkdyvo995nQAlGEMgBP/4XI/dbHWzOBibKlkrEw="}],"size":6204,"noattachment":false,"key":"/simple-handshake/-/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,"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":1598966255880,"_cnpm_publish_time":1598966255880,"dist-tags":{"latest":"3.0.0"}}