{"name":"noise-handshake","version":"3.0.1","description":"## Usage ```js const Noise = require('noise-handshake') const Cipher = require('noise-handshake/cipher') const initiator = new Noise('IK', true) const responder = new Noise('IK', false)","main":"noise.js","scripts":{"test":"standard && tape test/*.js"},"author":"","license":"ISC","repository":{"type":"git","url":"git+https://github.com/chm-diederichs/noise-handshake.git"},"dependencies":{"b4a":"^1.1.0","nanoassert":"^2.0.0","sodium-universal":"^3.0.4"},"devDependencies":{"noise-protocol":"github:chm-diederichs/noise-protocol#xx-ephemeral-key","standard":"^16.0.3","tape":"^5.2.2"},"gitHead":"d1f41a7a938573d97140be4e9b6545683f0b426e","bugs":{"url":"https://github.com/chm-diederichs/noise-handshake/issues"},"homepage":"https://github.com/chm-diederichs/noise-handshake#readme","_id":"noise-handshake@3.0.1","_nodeVersion":"16.17.0","_npmVersion":"8.19.2","dist":{"integrity":"sha512-H5rHzYaCNTwCgCHUu2tJgkdKE9lpqyXVVxzGC9mRQrL+/uE1pgP7kUk21LVgEycmJqoPm0ltCzhZzo8EguD8pg==","shasum":"e74a66e6f6bb40462335697d4a673dafc9e4c44e","tarball":"http://registry-npm.ywwl.com/noise-handshake/download/noise-handshake-3.0.1.tgz","fileCount":9,"unpackedSize":17232,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIA2bVkrZUEpRq77PSWVtenaU3oHUIcC1wk/U+bLFU7WRAiEAk+3GI/CxahlEigpSX1nk42Tg8OtMbJ++VkpT2e29fSM="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjmIyhACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmpiwg/+KlssRB6PnfaiF4xE8zvTuADsWP6n4lfsPwlvk0Ghu53pDjZs\r\n7jqSFt6MzBN5YK2neObtsHw/0HtlTlDQrgpmYVNBsndS1o5zYX1H+ZyZuf6c\r\nAqErnlfk6TwslWyjS+/F48+DBrCLd/P1z04YOXKe3AuIxqqexldk90PRJzxe\r\n5+bTscrnavHRhmJuE29b/Qu3jajmf5l6sR+TIha/Z5dYcFYkcZsZnLlas6k0\r\n9uyDk5ezCFg88k7Y0cj87mgp+1EMxFw3v4DdBo9zM0FHMfxu6NU9M3mEgHeF\r\nMdjMvqX14n9JQAQmZ3R/KkA/HT4Ylp4sijrCDVmXuLou1JS0u8UqUaMRTVmO\r\nK+/pdifITsCy7ZSjNZbXu5zakGfBeQypxk6PUFNrIJAjFjUV6uceJMHsH+Ad\r\neOQYDTYvhSyR598T+Gtik6lYV/k0XIwNTOsk7LbMjpXvcxeSdY4p32aot9y4\r\nfbKlAPW0UG+HJNW8aaYt3ThG1wjzRirByuD54zCVTZDG56WEODYQaZE3JBq3\r\nXEyD2cJcS/hWQ3yQAbWqxWat8e7NmuOdrTrYFJGNxzfqfBQK5D15TVfEC56f\r\nzKkmZh6ek/bicQJjWhw6gBSzX2ovZIMPc5gvX7W1K2TVvCKRrqrZ79vVuwVS\r\nShPRIN9f7HwpJodWcP84sUOT6EctP3jZmT8=\r\n=YnA7\r\n-----END PGP SIGNATURE-----\r\n","size":5233,"noattachment":false,"key":"/noise-handshake/-/noise-handshake-3.0.1.tgz"},"_npmUser":{"name":"chm-diederichs","email":"chm-diederichs@protonmail.com"},"directories":{},"maintainers":[{"name":"chm-diederichs","email":"chm-diederichs@protonmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/noise-handshake_3.0.1_1670941857729_0.7593169751762658"},"_hasShrinkwrap":false,"readme":"# noise-handshake\n\n## Usage\n```js\nconst Noise = require('noise-handshake')\nconst Cipher = require('noise-handshake/cipher')\nconst initiator = new Noise('IK', true)\nconst responder = new Noise('IK', false)\n\nconst prologue = Buffer.alloc(0)\n\n// preshared key\ninitiator.initialise(prologue, responder.s.publicKey)\nresponder.initialise(prologue)\n\n// -> e, es, s, ss\nconst message = initiator.send()\nresponder.recv(message)\n\n// <- e, ee, se\nconst reply = responder.send()\ninitiator.recv(reply)\n\nconsole.log(initiator.complete) // true\n\n// convention is to use rx for\n// sending and tx for receiving\n\n// initiator.rx === responder.tx\n// responder.rx === initiator.tx\n\n// instantiate a cipher using shared secrets\nconst send = new Cipher(initiator.tx)\nconst recieve = new Cipher(responder.rx)\n\nconst msg = Buffer.from('hello, world')\n\nconst enc = send.encrypt(msg)\nconsole.log(recieve.decrypt(enc)) // hello, world\n```\n\n## API\n\n#### `const peer = new Noise(pattern, initiator, staticKeypair, [opts])`\n\nCreate a new handshake state for a given pattern. Initiator should be either `true` or `false` depending on the role. A preexisting keypair may be passed as `staticKeypair`\n\n`opts` may be used to pass in the following:\n- `curve`: module for performing Noise over other curves.\n- `psk`: a 32-byte buffer containing a pre-shared key for patterns containing `psk0`. (Other psk positions are not currently supported.)\n\nCurve modules should export the following:\n```\n{\n  DHLEN,\n  PKLEN,\n  SKLEN,\n  ALG,\n  generateKeyPair,\n  dh\n}\n```\n\nSee [dh.js](./dh) for an example.\n\n#### `peer.initialise(prologue, remoteStatic)`\n\nInitialise the handshake state with a prologue and any preshared keys.\n\n#### `const buf = send([payload])`\n\nSend the next message in the handshake, add an optional payload buffer to be included in the message, payload is a zero length buffer by default.\n\n#### `const payload = peer.recv(buf)`\n\nReceive a handshake message from the peer and return the encrypted payload.\n\n#### `peer.complete`\n\n`true` or `false`. Indicates whether `rx` and `tx` have been created yet.\n\nWhen complete, the working handshake state shall be cleared *only* the following state shall remain on the object:\n\n```js\n{\n  tx, // session key to decrypt messages from remote peer\n  rx, // session key to encrypt messages to remote peer\n  rs, // the remote peer's public key,\n  hash, // a hash of the entire handshake state\n}\n```\n","publish_time":1670941857893,"_cnpm_publish_time":1670941857893,"dist-tags":{"latest":"4.2.0"}}