{"id":16834836,"url":"https://github.com/dchest/nacl-stream-js","last_synced_at":"2025-03-22T04:30:49.078Z","repository":{"id":57307400,"uuid":"22354041","full_name":"dchest/nacl-stream-js","owner":"dchest","description":"Streaming encryption based on TweetNaCl.js","archived":false,"fork":false,"pushed_at":"2018-07-13T22:39:48.000Z","size":138,"stargazers_count":38,"open_issues_count":0,"forks_count":9,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-02-28T19:13:24.818Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dchest.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-28T18:56:35.000Z","updated_at":"2024-02-26T14:05:00.000Z","dependencies_parsed_at":"2022-09-02T03:50:24.368Z","dependency_job_id":null,"html_url":"https://github.com/dchest/nacl-stream-js","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dchest%2Fnacl-stream-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dchest%2Fnacl-stream-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dchest%2Fnacl-stream-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dchest%2Fnacl-stream-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dchest","download_url":"https://codeload.github.com/dchest/nacl-stream-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244181419,"owners_count":20411603,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T12:08:01.812Z","updated_at":"2025-03-22T04:30:48.775Z","avatar_url":"https://github.com/dchest.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"nacl-stream: streaming encryption based on TweetNaCl.js\n=======================================================\n\nWritten by Dmitry Chestnykh in 2014. Public domain.\n\u003chttps://github.com/dchest/nacl-stream-js\u003e\n\nBased on\n\u003chttps://www.imperialviolet.org/2014/06/27/streamingencryption.html\u003e\n\n[![Build Status](https://travis-ci.org/dchest/nacl-stream-js.svg?branch=master)\n](https://travis-ci.org/dchest/nacl-stream-js)\n\nFormat description\n------------------\n\n- Inputs: 32-byte key, 16-byte nonce, a stream (or a file).\n- Stream is split into chunks of the specified length.\n- 24-byte fullNonce is acquired by concatenating 16-byte nonce and 8-byte\n  little-endian chunk number.\n- Each chunk except for the last one is encrypted like this, starting with\n  chunk number 0:\n  ```\n  fullNonce0 := nonce || 0\n  encryptedChunk0 := len(chunk0) || nacl.secretbox(chunk0, fullNonce0, key)\n  fullNonce1 := nonce || 1\n  encryptedChunk1 := len(chunk1) || nacl.secretbox(chunk1, fullNonce1, key)\n  ...\n  ```\n  where `len(chunk)` is a 4-byte little-endian plaintext chunk length.\n\n- The last chunk's fullNonce has the most significant bit set:\n  ```\n  fullNonceN := nonce || setMSB(N)\n  encryptedChunkN = len(chunkN) || nacl.secretbox(chunkN, fullNonceN, key)\n  ```\n- Encrypted chunks are concatenated to form the encrypted stream.\n\nUsage\n-----\n\n**The API is fairly low-level and should be used as a building block for some\nhigh-level API which would deal with actual streams or files.**\n\nThe module provides two constructor functions (in `window.nacl` namespace or as\na CommonJS module):\n\n### stream.createEncryptor(key, nonce, maxChunkLength)\n\nReturns a stream encryptor object using 32-byte key and 16-byte nonce (both of\n`Uint8Array` type) and the maximum chunk length with the following methods:\n\n#### *encryptor*.encryptChunk(chunk, isLast)\n\nEncrypts the given `Uint8Array` chunk and returns a new `Uint8Array` array\nwith encrypted chunk.\n\nIf encrypting the last chunk of stream, `isLast` must be set to `true`.\n\n#### *encryptor*.clean()\n\nZeroes out temporary space. Should be called after encrypting all chunks.\n\n### stream.createDecryptor(key, nonce, maxChunkLength)\n\nReturns a stream decryptor object using 32-byte key and 16-byte nonce (both of\n`Uint8Array` type) and the maximum chunk length with the following methods:\n\n#### *decryptor*.decryptChunk(encryptedChunk, isLast)\n\nDecrypts the given `Uint8Array` encrypted chunk and returns a new `Uint8Array`\narray with decrypted chunk.\n\nThe given encryptedChunk should be in the format created by `encryptChunk`,\ni.e. prefixed with original chunk length.\n\nReturns `null` if the chunk cannot be decrypted. In this case, futher\ncalls to `decryptChunk` will deliberately fail: callers should stop trying\nto decrypt this stream and, if possible, discard previously decrypted\nchunks.\n\nIf decrypting the last chunk of stream, `isLast` must be set to `true`.\n\n#### *decryptor*.clean()\n\nZeroes out temporary space. Should be called after decrypting all chunks.\n\n#### stream.readChunkLength(data[, offset])\n\nReads four bytes from the given offset (or from the beginning, if no offset is\ngiven) of `Uint8Array` data and returns the chunk length. Length of\nencryptedChunk passed to `decryptChunk` should be 4 + 16 + *chunkLength* bytes.\n\n\n## See also\n\n- [nacl-blob](https://github.com/bcomnes/nacl-blob)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdchest%2Fnacl-stream-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdchest%2Fnacl-stream-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdchest%2Fnacl-stream-js/lists"}