Open
Conversation
# wormhole-crypto [](https://socket.dev/npm/package/wormhole-crypto) [![ci][ci-image]][ci-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url] [ci-image]: https://img.shields.io/github/workflow/status/webtorrent/wormhole-crypto/ci/master [ci-url]: https://github.com/webtorrent/wormhole-crypto/actions [npm-image]: https://img.shields.io/npm/v/wormhole-crypto.svg [npm-url]: https://npmjs.org/package/wormhole-crypto [downloads-image]: https://img.shields.io/npm/dm/wormhole-crypto.svg [downloads-url]: https://npmjs.org/package/wormhole-crypto [standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg [standard-url]: https://standardjs.com ### Streaming encryption for Wormhole.app, based on [Encrypted Content-Encoding for HTTP (RFC 8188)](https://tools.ietf.org/html/rfc8188) This package is used by [Wormhole.app](https://wormhole.app). ## Install ```bash npm install wormhole-crypto ``` ## Usage Here's a quick example of how to use this package to turn a plaintext WHATWG readable stream into an encrypted stream. ```js import { Keychain } from 'wormhole-crypto' // Create a new keychain. Since no arguments are specified, the key and salt // are generated. const keychain = new Keychain() // Get a WHATWG stream somehow, from fetch(), from a Blob(), etc. const stream = getStream() // Create an encrypted version of that stream const encryptedStream = await keychain.encryptStream(stream) // Normally you'd now use `encryptedStream`, e.g. in fetch(), etc. // However, for this example, we'll just decrypt the stream immediately const plaintextStream = await keychain.decryptStream(encryptedStream) // Now, you can use `plaintextStream` and it will be identical to if you had // used `stream`. ``` ## API ### `new Keychain([key, [salt]])` Type: `Class` Returns: `Keychain` Create a new keychain object. The keychain can be used to create encryption streams, decryption streams, and to encrypt or decrypt a "metadata" buffer. #### `key` Type: `Uint8Array | string | null` Default: `null` The main key. This should be 16 bytes in length. If a `string` is given, then it should be a base64-encoded string. If the argument is `null`, then a key will be automatically generated. #### `salt` Type: `Uint8Array | string | null` Default: `null` The salt. This should be 16 bytes in length. If a `string` is given, then it should be a base64-encoded string. If this argument is `null`, then a salt will be automatically generated. ### `keychain.key` Type: `Uint8Array` The main key. ### `keychain.keyB64` Type: `string` The main key as a base64-encoded string. ### `keychain.salt` Type: `Uint8Array`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
"