{"id":24143289,"url":"https://github.com/little-core-labs/secretbox-encoding","last_synced_at":"2026-05-13T17:38:06.602Z","repository":{"id":65493692,"uuid":"211974015","full_name":"little-core-labs/secretbox-encoding","owner":"little-core-labs","description":"XSalsa20 Poly1305 codec that implements the abstract-encoding interface.","archived":false,"fork":false,"pushed_at":"2020-01-07T21:45:58.000Z","size":13,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-02-02T12:11:11.046Z","etag":null,"topics":["abstract","encoding","xsalsa20poly1305"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/little-core-labs.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":"2019-09-30T23:09:58.000Z","updated_at":"2020-01-07T21:58:16.000Z","dependencies_parsed_at":"2023-01-25T21:15:19.821Z","dependency_job_id":null,"html_url":"https://github.com/little-core-labs/secretbox-encoding","commit_stats":null,"previous_names":["jwerle/secretbox-encoding"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/little-core-labs%2Fsecretbox-encoding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/little-core-labs%2Fsecretbox-encoding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/little-core-labs%2Fsecretbox-encoding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/little-core-labs%2Fsecretbox-encoding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/little-core-labs","download_url":"https://codeload.github.com/little-core-labs/secretbox-encoding/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241374516,"owners_count":19952544,"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":["abstract","encoding","xsalsa20poly1305"],"created_at":"2025-01-12T05:14:55.886Z","updated_at":"2025-11-23T20:10:34.285Z","avatar_url":"https://github.com/little-core-labs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"secretbox-encoding\n==================\n\n\u003e [XSalsa20 Poly1305][secretbox] codec that implements the [abstract-encoding][abstract-encoding] interface.\n\u003e Nonces are generated randomly and prepended to the ciphertext.\n\n## Installation\n\n```sh\n$ npm install secretbox-encoding\n```\n\n## Usage\n\n```js\nconst codec = require('secretbox-encoding')(secretKey)\n\n// encode a value\nbuffer = codec.encode(value)\n\n// decode a value\nvalue = codec.decode(buffer)\n```\n\n## Example\n\n```js\nconst crypto = require('crypto')\nconst Codec = require('secretbox-encoding')\n\nconst key = crypto.randomBytes(32)\n\nconst codec = Codec(key)\nconst hello = codec.encode('hello')\nconst world = codec.encode('world')\n\nconsole.log('%s %s', codec.decode(hello), codec.decode(world)) // 'hello world'\n```\n\n### Custom Value Encodings\n\n```js\nconst pbs = require('protocol-buffers')\nconst { Message } = pbs(`\nmessage {\n  string data = 1;\n}\n`)\n\nconst codec = Codec(key, { valueEncoding: Message })\nconst encoded = codec.encode({ data: 'hello world' })\nconst message = codec.decode(encoded) // { data: 'hello world' }\n```\n\n## API\n\n### `codec = require('secretbox-encoding')(secretKey[, opts])`\n\nCreate a codec object from 32 byte `secretKey`.\n\n```js\nconst key = crypto.randomBytes(32)\nconst codec = Codec(key)\n```\n\n#### `buffer = codec.encode(value[, output[, offset]])`\n\nEncode a value using [crypto_secretbox_easy](https://download.libsodium.org/doc/secret-key_cryptography/secretbox) into an optional `output` buffer at an optional `offset`\ndefaulting to `0`. If an `output` buffer is not given, one is allocated\nfor you and returned.\n\n```js\nconst buffer = codec.encode('hello world')\n```\n\n#### `value = codec.decode(buffer[, offset])`\n\nDecode a buffer using [crypto_secretbox_open_easy](\nhttps://download.libsodium.org/doc/secret-key_cryptography/secretbox)\nat an optional `offset` defaulting to `0`.\n\n```js\nconst value = codec.decode(buffer)\n```\n\n#### `length = codec.encodingLength(value)`\n\nReturns the encoding length for a given `value`.\n\n```js\nconst length = codec.encodingLength('hello world') // 11\n```\n\n## License\n\nMIT\n\n\n[abstract-encoding]: https://github.com/mafintosh/abstract-encoding\n[secretbox]: https://download.libsodium.org/doc/secret-key_cryptography/secretbox\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flittle-core-labs%2Fsecretbox-encoding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flittle-core-labs%2Fsecretbox-encoding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flittle-core-labs%2Fsecretbox-encoding/lists"}