{"name":"@libp2p/interface-connection-encrypter","version":"4.0.1-ea8a0637","description":"Connection Encrypter interface for libp2p","license":"Apache-2.0 OR MIT","homepage":"https://github.com/libp2p/js-libp2p/tree/master/packages/interface-connection-encrypter#readme","repository":{"type":"git","url":"git+https://github.com/libp2p/js-libp2p.git"},"bugs":{"url":"https://github.com/libp2p/js-libp2p/issues"},"keywords":["interface","libp2p"],"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./dist/src/index.js"},"./errors":{"types":"./dist/src/errors.d.ts","import":"./dist/src/errors.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"clean":"aegir clean","lint":"aegir lint","dep-check":"aegir dep-check","build":"aegir build"},"dependencies":{"@libp2p/interface-peer-id":"2.0.2-ea8a0637","it-stream-types":"^2.0.1"},"devDependencies":{"aegir":"^39.0.10"},"typedoc":{"entryPoint":"./src/index.ts"},"readme":"# @libp2p/interface-connection-encrypter <!-- omit in toc -->\n\n[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)\n[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)\n[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p)\n[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=master\\&style=flat-square)](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amaster)\n\n> Connection Encrypter interface for libp2p\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [API](#api)\n  - [Secure Inbound](#secure-inbound)\n  - [Secure Outbound](#secure-outbound)\n- [Crypto Errors](#crypto-errors)\n  - [Error Types](#error-types)\n- [API Docs](#api-docs)\n- [License](#license)\n- [Contribution](#contribution)\n\n## Install\n\n```console\n$ npm i @libp2p/interface-connection-encrypter\n```\n\n**Modules that implement the interface**\n\n- [@chainSafe/js-libp2p-noise](https://github.com/ChainSafe/js-libp2p-noise)\n- [js-libp2p-secio](https://github.com/NodeFactoryIo/js-libp2p-secio)\n\n## API\n\n- `Crypto`\n  - `protocol<string>`: The protocol id of the crypto module.\n  - `secureInbound<function(PeerId, duplex)>`: Secures inbound connections.\n  - `secureOutbound<function(PeerId, duplex, PeerId)>`: Secures outbound connections.\n\n### Secure Inbound\n\n- `const { conn, remotePeer } = await crypto.secureInbound(localPeer, duplex, [remotePeer])`\n\nSecures an inbound [streaming iterable duplex][iterable-duplex] connection. It returns an encrypted [streaming iterable duplex][iterable-duplex], as well as the [PeerId][peer-id] of the remote peer.\n\n**Parameters**\n\n- `localPeer` is the [PeerId][peer-id] of the receiving peer.\n- `duplex` is the [streaming iterable duplex][iterable-duplex] that will be encryption.\n- `remotePeer` is the optional [PeerId][peer-id] of the initiating peer, if known. This may only exist during transport upgrades.\n\n**Return Value**\n\n- `<object>`\n  - `conn<duplex>`: An encrypted [streaming iterable duplex][iterable-duplex].\n  - `remotePeer<PeerId>`: The [PeerId][peer-id] of the remote peer.\n\n### Secure Outbound\n\n- `const { conn, remotePeer } = await crypto.secureOutbound(localPeer, duplex, remotePeer)`\n\nSecures an outbound [streaming iterable duplex][iterable-duplex] connection. It returns an encrypted [streaming iterable duplex][iterable-duplex], as well as the [PeerId][peer-id] of the remote peer.\n\n**Parameters**\n\n- `localPeer` is the [PeerId][peer-id] of the receiving peer.\n- `duplex` is the [streaming iterable duplex][iterable-duplex] that will be encrypted.\n- `remotePeer` is the [PeerId][peer-id] of the remote peer. If provided, implementations **should** use this to validate the integrity of the remote peer.\n\n**Return Value**\n\n- `<object>`\n  - `conn<duplex>`: An encrypted [streaming iterable duplex][iterable-duplex].\n  - `remotePeer<PeerId>`: The [PeerId][peer-id] of the remote peer. This **should** match the `remotePeer` parameter, and implementations should enforce this.\n\n## Crypto Errors\n\nCommon crypto errors come with the interface, and can be imported directly. All Errors take an optional message.\n\n```js\nconst {\n  InvalidCryptoExchangeError,\n  InvalidCryptoTransmissionError,\n  UnexpectedPeerError\n} = require('libp2p-interfaces/src/crypto/errors')\n\nconst error = new UnexpectedPeerError('a custom error message')\nconsole.log(error.code === UnexpectedPeerError.code) // true\n```\n\n### Error Types\n\n- `InvalidCryptoExchangeError` - Should be thrown when a peer provides data that is insufficient to finish the crypto exchange.\n- `InvalidCryptoTransmissionError` - Should be thrown when an error occurs during encryption/decryption.\n- `UnexpectedPeerError` - Should be thrown when the expected peer id does not match the peer id determined via the crypto exchange.\n\n## API Docs\n\n- <https://libp2p.github.io/js-libp2p/modules/_libp2p_interface_connection_encrypter.html>\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[peer-id]: https://github.com/libp2p/js-peer-id\n\n[iterable-duplex]: https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#duplex-it\n","readmeFilename":"README.md","gitHead":"ea8a06378d6733c0bcac28bed3aa3baef1e30ead","_id":"@libp2p/interface-connection-encrypter@4.0.1-ea8a0637","_nodeVersion":"18.16.0","_npmVersion":"8.19.4","dist":{"integrity":"sha512-aUEimXNuixbCqTl9v+Qx8qOh0rk7TiotBo3VZDUg6KThznN/tsHquT8sUJLOAsLG/x9buOhklRpChjcnig7RlA==","shasum":"aa287dcf84aa2fe0055fe65ada8c6aa994232a51","tarball":"http://registry-npm.ywwl.com/@libp2p/interface-connection-encrypter/download/@libp2p/interface-connection-encrypter-4.0.1-ea8a0637.tgz","fileCount":14,"unpackedSize":14099,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHRSO0IbQ7TdI3pDPXxDd4Byhc4ViIiBbsL9WvifXRtkAiEAp2j//bIl+sNaWODdNuYOtF+AiE9B0ZBvxzSnmGjklKg="}],"size":4277,"noattachment":false,"key":"/@libp2p/interface-connection-encrypter/-/@libp2p/interface-connection-encrypter-4.0.1-ea8a0637.tgz"},"_npmUser":{"name":"npm-service-account-libp2p","email":"npm-service-account+libp2p@protocol.ai"},"directories":{},"maintainers":[{"name":"jacobheun","email":"jacobheun@gmail.com"},{"name":"npm-service-account-libp2p","email":"npm-service-account+libp2p@protocol.ai"},{"name":"alanshaw","email":"alan138@gmail.com"},{"name":"vascosantos","email":"santos.vasco10@gmail.com"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"daviddias","email":"mail@daviddias.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/interface-connection-encrypter_4.0.1-ea8a0637_1687170420713_0.7196178018686235"},"_hasShrinkwrap":false,"publish_time":1687170420921,"_cnpm_publish_time":1687170420921,"dist-tags":{"latest":"4.0.1","next":"4.0.1-d853d124"}}