{"name":"@hyperswarm/secret-stream","version":"6.9.2","description":"Secret stream backed by Noise and libsodium's secretstream","main":"index.js","imports":{"crypto":{"bare":"bare-crypto","default":"crypto"},"events":{"bare":"bare-events","default":"events"},"net":{"bare":"bare-net","default":"net"}},"dependencies":{"b4a":"^1.1.0","hypercore-crypto":"^3.3.1","noise-curve-ed":"^2.0.1","noise-handshake":"^4.0.0","sodium-secretstream":"^1.1.0","sodium-universal":"^5.0.0","streamx":"^2.14.0","timeout-refresh":"^2.0.0","unslab":"^1.3.0"},"devDependencies":{"bare-crypto":"^1.12.0","bare-events":"^2.0.0","bare-net":"^2.2.0","brittle":"^3.3.0","lunte":"^1.3.0","prettier":"^3.6.2","prettier-config-holepunch":"^2.0.0","udx-native":"^1.13.2"},"scripts":{"format":"prettier --write .","lint":"prettier --check . && lunte","test":"npm run test:node && npm run test:bare","test:node":"brittle-node test.js","test:bare":"brittle-bare test.js"},"repository":{"type":"git","url":"git+https://github.com/holepunchto/hyperswarm-secret-stream.git"},"author":{"name":"Mathias Buus","url":"@mafintosh"},"license":"Apache-2.0","bugs":{"url":"https://github.com/holepunchto/hyperswarm-secret-stream/issues"},"homepage":"https://github.com/holepunchto/hyperswarm-secret-stream","gitHead":"553bd082904aaeb68b0a63b8a8b2c482db4d36e7","_id":"@hyperswarm/secret-stream@6.9.2","_nodeVersion":"24.20.0","_npmVersion":"11.19.0","dist":{"integrity":"sha512-BE6tC6QxN6JBxUSsEbdr5Clo0MidouzLIywDNOGaaACsogJAGjRetJtJ7gjG7KXGXTBDybByArMAMHZ7ftjNSA==","shasum":"bddc77e6f5626b0a405d6ff20be5350b5f319c51","tarball":"http://registry-npm.ywwl.com/@hyperswarm/secret-stream/download/@hyperswarm/secret-stream-6.9.2.tgz","fileCount":6,"unpackedSize":37286,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@hyperswarm%2fsecret-stream@6.9.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCkKheJM+VH8tNVzSvFO91GA8iySinvMvxWSJ12NEqBJAIgIcl3TRB959mGu9ZnhxeCJNRG5dMqF17EGdr5TgcBzFI="}],"size":11071,"noattachment":false,"key":"/@hyperswarm/secret-stream/-/@hyperswarm/secret-stream-6.9.2.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:6d3ff8a7-454a-4e6f-b1bc-1c88a79bf00e"}},"directories":{},"maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/secret-stream_6.9.2_1789076192479_0.3169868110588656"},"_hasShrinkwrap":false,"readme":"# @hyperswarm/secret-stream\n\n### [See the full API docs at docs.pears.com](https://docs.pears.com/helpers/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  enableSend: true // (advanced) set false to disable the send API\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#### `await s.send(buffer)`\n\nSends an encrypted unordered message, see [udx-native](https://github.com/holepunchto/udx-native/tree/main?tab=readme-ov-file#await-streamsendbuffer) for details.  \nThis method with silently fail if called before handshake is complete or if the underlying rawStream is not an UDX-stream (not capable of UDP).\n\n#### `s.trySend(buffer)`\n\nSame as `send(buffer)` but does not return a promise.\n\n#### `s.on('message', onmessage)`\n\nEmmitted when an unordered message is received\n\n#### `keyPair = SecretStream.keyPair([seed])`\n\nGenerate a ed25519 key pair.\n\n## License\n\nApache-2.0\n","publish_time":1789076192614,"_cnpm_publish_time":1789076192614,"dist-tags":{"latest":"6.9.2"}}