{"name":"@hyperswarm/secret-stream","version":"5.1.6","author":{"url":"@mafintosh","name":"Mathias Buus"},"license":"MIT","_id":"@hyperswarm/secret-stream@5.1.6","homepage":"https://github.com/hyperswarm/secret-stream","bugs":{"url":"https://github.com/hyperswarm/secret-stream/issues"},"dist":{"shasum":"f34963f73568c1e3a15a23d7c00c72516ace035c","tarball":"http://registry-npm.ywwl.com/@hyperswarm/secret-stream/download/@hyperswarm/secret-stream-5.1.6.tgz","fileCount":8,"integrity":"sha512-X1NwlnBDRCV3JKug/AKuVwNObZxd29TFGvcFYfm6A0fNdqZ3rSMmojSlsFQCllzohgA0CEQugCjjPuw6LRXrWA==","signatures":[{"sig":"MEUCIQDep9bnD9niJIhlgJ/FC0E8n2PPrLp8sUAXN1zOJpKjKwIgctYSdMa3qtYJqDrmQXXPv+NdvptClxokxmKweKw3i28=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":28805,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh+UohCRA9TVsSAnZWagAAiSsP/1g9a9deNTxBE+eDqiq6\nmKSHxb6N6OSv92P3pG1Ed5MeJ7zmY2DBbLbkeQSLoWIdChLnoA2eWTadfxh3\nSo3kti1kExHvWOep7GKV2c8o0cTrIS1f+56vo4orz9wdJbn7zQkWxH4hugY9\ny6IpN4u49Rfs+eN7CrIKeyje1tZ2+tZzGuoCrIvjQlJHLOI3TyCzEzVLygOD\nj+L68/A5wEaDWD9l6Duf+hYYuEX0wPn88dYKJXo1Om+rngZSWItZhob08kz8\n+TZXIDU+18Gp3CmjyopdbvnfKcOWidTrk66Hu8TN+qm3igROv2XbN2Xwymkw\n5WVBatBUeRVLhzVMDW5rskcmJn32T9htR70pZcHi/SM4FvdD9fWapebxLcAI\nWODaC5XAQkQ4yACTQd5Q5LtI2LQT78Ttj85pFpsfFcKho1Cbb8Jtq/6f/xLG\n8Tt6+foqYrmxwkk2EhQqTe59kauAtbtGBwJ5zl9YgMdz9AAtO4OeWUgk/ONr\nrWtbc9lJR4fgKEdTWCA8sCvGVOiy886l8eLdaQLGpLT1jGRl8CHmLHkuy5+w\nmKrQNegGL5SYTzc0yUm2NBw/kXFUrOT9StAc0uV77hTC4XHe5WvYNzGYCxaU\nasUYDkbN/sjCHhGlKdk7DVrNDTzTepDqo+31wJh2eK7y/G9Pi2P6/C2UKBwQ\npvPC\r\n=J3yQ\r\n-----END PGP SIGNATURE-----\r\n","size":7699,"noattachment":false,"key":"/@hyperswarm/secret-stream/-/@hyperswarm/secret-stream-5.1.6.tgz"},"main":"index.js","gitHead":"5274fa5eb39ff97812279af375ec95f877c374a6","scripts":{"test":"standard && tape test.js"},"_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"repository":{"url":"git+https://github.com/hyperswarm/secret-stream.git","type":"git"},"_npmVersion":"8.1.2","description":"Secret stream backed by Noise and libsodium's secretstream","directories":{},"_nodeVersion":"16.13.2","dependencies":{"b4a":"^1.1.0","streamx":"^2.10.2","noise-curve-ed":"^1.0.2","noise-handshake":"^2.1.0","sodium-universal":"^3.0.4","sodium-secretstream":"^1.0.0"},"_hasShrinkwrap":false,"devDependencies":{"tape":"^5.2.2","standard":"^16.0.3"},"_npmOperationalInternal":{"tmp":"tmp/secret-stream_5.1.6_1643727393460_0.06874894602384196","host":"s3://npm-registry-packages"},"readme":"# @hyperswarm/secret-stream\n\n### [See the full API docs at docs.holepunch.to](https://docs.holepunch.to/building-blocks/hyperswarm#secretstream)\n\nSecret stream backed by Noise and libsodium's secretstream\n\n```\nnpm install @hyperswarm/secret-stream\n```\n\n## Usage\n\nYou can either make a secret stream from an existing transport stream.\n\n``` js\nconst SecretStream = require('@hyperswarm/secret-stream')\n\nconst a = new SecretStream(true, tcpClientStream)\nconst b = new SecretStream(false, tcpServerStream)\n\n// pipe the underlying rawstreams together\n\na.write(Buffer.from('hello encrypted!'))\n\nb.on('data', function (data) {\n  console.log(data) // <Buffer hello encrypted!>\n})\n```\n\nOr by making your own pipeline\n\n``` js\nconst a = new SecretStream(true)\nconst b = new SecretStream(false)\n\n// pipe the underlying rawstreams together\na.rawStream.pipe(b.rawStream).pipe(a.rawStream)\n\na.write(Buffer.from('hello encrypted!'))\n\nb.on('data', function (data) {\n  console.log(data) // <Buffer hello encrypted!>\n})\n```\n\n## API\n\n#### `const s = new SecretStream(isInitiator, [rawStream], [options])`\n\nMake a new stream. `isInitiator` is a boolean indication whether you are the client or the server.\n`rawStream` can be set to an underlying transport stream you want to run the noise stream over.\n\nOptions include:\n\n```js\n{\n  pattern: 'XX', // which noise pattern to use\n  remotePublicKey, // set if your handshake requires it\n  keyPair: { publicKey, secretKey },\n  handshake: { // if you want to use an handshake performed elsewhere pass it here\n    tx,\n    rx,\n    hash,\n    publicKey,\n    remotePublicKey\n  }\n}\n```\n\nThe SecretStream returned is a Duplex stream that you use as as normal stream, to write/read data from,\nexcept it's payloads are encrypted using the libsodium secretstream.\n\nNote that this uses ed25519 for the handshakes per default.\n\nIf need to load the key pair asynchronously, then secret-stream also supports passing in a promise\ninstead of the keypair that later resolves to `{ publicKey, secretKey }`. The stream lifecycle will wait\nfor the resolution and auto destroy the stream if the promise errors.\n\n#### `s.start(rawStream, [options])`\n\nStart a SecretStream from a rawStream asynchrously.\n\n``` js\nconst s = new SecretStream({\n  autoStart: false // call start manually\n})\n\n// ... do async stuff or destroy the stream\n\ns.start(rawStream, {\n  ... options from above\n})\n```\n\n#### `s.setTimeout(ms)`\n\nSet the stream timeout. If no data is received within a `ms` window,\nthe stream is auto destroyed.\n\n#### `s.setKeepAlive(ms)`\n\nSend a heartbeat (empty message) every time the socket is idle for `ms` milliseconds. **Note:** If one side calls `s.setKeepAlive()` and the other does not, then the empty messages will be passed through to the piped stream.\n\n#### `s.publicKey`\n\nGet the local public key.\n\n#### `s.remotePublicKey`\n\nGet the remote's public key.\nPopulated after `open` is emitted.\n\n#### `s.handshakeHash`\n\nGet the unique hash of this handshake.\nPopulated after `open` is emitted.\n\n#### `s.keepAlive`\n\nGet the interval (in milliseconds) at which keep-alive messages are sent (0 means none are sent).\n\n#### `s.sendKeepAlive()`\n\nA convenience method that sends an empty message.\n\n#### `s.rawBytesWritten`\n\nThe number of bytes (measured after encryption) written.\n\n#### `s.rawBytesRead`\n\nThe number of bytes (measured before decryption) received.\n\n#### `s.on('connect', onconnect)`\n\nEmitted when the handshake is fully done.\nIt is safe to write to the stream immediately though, as data is buffered\ninternally before the handshake has been completed.\n\n#### `keyPair = SecretStream.keyPair([seed])`\n\nGenerate a ed25519 key pair.\n\n## License\n\nApache-2.0\n","publish_time":1643727393616,"maintainers":[{"name":"kasperisager","email":"kasperisager@hey.com"},{"name":"mafintosh","email":"mathiasbuus@gmail.com"},{"name":"davidmarkclements","email":"huperekchuno@googlemail.com"}],"_cnpm_publish_time":1643727393616,"dist-tags":{"latest":"6.9.2"}}