{"id":26844304,"url":"https://github.com/phusion/node-sha3","last_synced_at":"2025-04-06T20:08:28.274Z","repository":{"id":4944619,"uuid":"6101799","full_name":"phusion/node-sha3","owner":"phusion","description":"SHA3 for JavaScript - The Keccak family of hash algorithms","archived":false,"fork":false,"pushed_at":"2023-01-06T01:36:44.000Z","size":3486,"stargazers_count":140,"open_issues_count":16,"forks_count":31,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-03-30T19:19:21.506Z","etag":null,"topics":["cryptography","hash","javascript","keccak","nodejs"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/sha3","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"openwebos/build-desktop","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phusion.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"canterberry"}},"created_at":"2012-10-06T10:31:15.000Z","updated_at":"2024-10-25T10:29:32.000Z","dependencies_parsed_at":"2023-01-13T13:18:30.022Z","dependency_job_id":null,"html_url":"https://github.com/phusion/node-sha3","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phusion%2Fnode-sha3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phusion%2Fnode-sha3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phusion%2Fnode-sha3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phusion%2Fnode-sha3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phusion","download_url":"https://codeload.github.com/phusion/node-sha3/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247543589,"owners_count":20955865,"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":["cryptography","hash","javascript","keccak","nodejs"],"created_at":"2025-03-30T19:19:29.725Z","updated_at":"2025-04-06T20:08:28.255Z","avatar_url":"https://github.com/phusion.png","language":"JavaScript","readme":"# SHA-3 for JavaScript\n\n[![Travis CI][3]][4]\n[![npm version][5]][6]\n[![npm downloads][7]][6]\n[![dependencies][8]][9]\n[![devDependencies][10]][9]\n[![license][11]][12]\n\nA pure JavaScript implementation of the Keccak family of cryptographic hashing algorithms, most notably including Keccak and SHA3.\n\n\u003e :bulb: **Legacy Note:** In previous versions of this library, the `SHA3Hash` object provided a *Keccak* hash, **not** what we\n\u003e currently know as a SHA-3 hash. For backwards-compatibility, this object is still exported. However, users are encouraged to\n\u003e switch to using the `SHA3` or `Keccak` objects instead, which provide the SHA-3 and Keccak hashing algorithms, respectively.\n\n## Installation\n\nVia `npm`:\n\n```bash\n$ npm install sha3\n```\n\nVia `yarn`:\n\n```bash\n$ yarn add sha3\n```\n\n## Usage\n\nYou can use this library from Node.js, from web browsers, and/or using ES6 imports.\n\n### Node.js (CommonJS style)\n\n```javascript\n// Standard FIPS 202 SHA-3 implementation\nconst { SHA3 } = require('sha3');\n\n// The Keccak hash function is also available\nconst { Keccak } = require('sha3');\n\n// The SHAKE extendable output function (XOF) is also available\nconst { SHAKE } = require('sha3');\n```\n\n### ES6\n\n```javascript\n// Standard FIPS 202 SHA-3 implementation\nimport { SHA3 } from 'sha3';\n\n// The Keccak hash function is also available\nimport { Keccak } from 'sha3';\n\n// The SHAKE extendable output function (XOF) is also available\nimport { SHAKE } from 'sha3';\n```\n\n### What's in the box\n\nFIPS-compatible interfaces for the following algorithms:\n\n * `SHA3`: The SHA3 algorithm.\n * `Keccak`: The Keccak algorithm.\n * `SHAKE`: The SHAKE XOF algorithm.\n\n\u003e :bulb: **Legacy Note:** Savvy inspectors may notice that `SHA3Hash` is also provided. Prior to v2.0.0,\n\u003e this library only implemented an early version of the SHA3 algorithm. Since then, SHA3 has diverged from\n\u003e Keccak and is using a different padding scheme, but for compatibility, this alias is sticking around\n\u003e for a bit longer.\n\n### Examples\n\n#### Generating a SHA3-512 hash\n\n```javascript\nimport { SHA3 } from 'sha3';\n\nconst hash = new SHA3(512);\n\nhash.update('foo');\nhash.digest('hex');\n```\n\n#### Generating a Keccak-256 hash\n\n```javascript\nimport { Keccak } from 'sha3';\n\nconst hash = new Keccak(256);\n\nhash.update('foo');\nhash.digest('hex');\n```\n\n#### Generating a SHAKE128 hash with 2048 bytes\n\n```javascript\nimport { SHAKE } from 'sha3';\n\nconst hash = new SHAKE(128);\n\nhash.update('foo');\nhash.digest({ buffer: Buffer.alloc(2048), format: 'hex' });\n```\n\n### API Reference\n\nAll hash implementations provided by this library conform to the following API specification.\n\n#### `#constructor([size=512])`\n\nThe constructor for each hash (e.g: `Keccak`, `SHA3`), expects the following parameters:\n\n * `size` (Number): Optional. The size of the hash to create, in bits. If provided, this must be one of `224`, `256`, `384`, or `512`. Defaults to `512`.\n\n##### Example\n\n```javascript\n// Construct a new Keccak hash of size 256\nconst hash = new Keccak(256);\n```\n\n#### `#update(data, [encoding='utf8'])`\n\nUpdates the hash content with the given data. Returns the hash object itself.\n\n * `data` (Buffer|string): **Required.** The data to read into the hash.\n * `encoding` (string): **Optional.** The encoding of the given `data`, if of type `string`. Defaults to `'utf8'`.\n\n\u003e :bulb: See [Buffers and Character Encodings][15] for a list of allowed encodings.\n\n##### Example\n\n```javascript\nconst hash = new Keccak(256);\n\nhash.update('hello');\n\nhash.update('we can also chain these').update('together');\n```\n\n#### `#digest([encoding='binary'])`\n\nDigests the hash and returns the result. After calling this function, the hash **may** continue to receive input.\n\n * `encoding` (string): **Optional.** The encoding to use for the returned digest. Defaults to `'binary'`.\n\nIf an `encoding` is provided and is a value other than `'binary'`, then this function returns a `string`.\nOtherwise, it returns a `Buffer`.\n\n\u003e :bulb: See [Buffers and Character Encodings][15] for a list of allowed encodings.\n\n##### Example\n\n```javascript\nconst hash = new Keccak(256);\n\nhash.update('hello');\n\nhash.digest('hex');\n// =\u003e hash of 'hello' as a hex-encoded string\n```\n\n#### `#digest([options={}])`\n\nDigests the hash and returns the result. After calling this function, the hash **may** continue to receive input.\n\nOptions include:\n\n * `buffer` (Buffer): **Optional.** A pre-allocated buffer to fill with output bytes. This is how XOF algorithms like SHAKE can be used to obtain an arbitrary number of hash bytes.\n * `format` (string): **Optional.** The encoding to use for the returned digest. Defaults to `'binary'`. If `buffer` is also provided, this value will passed directly into `Buffer#toString()` on the given buffer.\n * `padding` (byte): **Optional.** Override the padding used to pad the input bytes to the algorithm's block size. Typically this should be omitted, but may be required if building additional cryptographic algorithms on top of this library.\n\nIf a `format` is provided and is a value other than `'binary'`, then this function returns a `string`.\nOtherwise, it returns a `Buffer`.\n\n##### Example\n\n```javascript\nconst hash = new Keccak(256);\n\nhash.update('hello');\n\nhash.digest({ buffer: Buffer.alloc(32), format: 'hex' });\n// =\u003e hash of 'hello' as a hex-encoded string\n```\n\n#### `#reset()`\n\nResets a hash to its initial state.\n\n * All input buffers are cleared from memory.\n * The hash object can safely be reused to compute another hash.\n\n##### Example\n\n```javascript\nconst hash = new Keccak(256);\n\nhash.update('hello');\nhash.digest();\n// =\u003e hash of 'hello'\n\nhash.reset();\n\nhash.update('world');\nhash.digest();\n// =\u003e hash of 'world'\n```\n\n## Testing\n\nRun `yarn test` for the full test suite.\n\n## Disclaimer\n\nCryptographic hashes provide **integrity**, but do not provide **authenticity** or **confidentiality**.\nHash functions are one part of the cryptographic ecosystem, alongside other primitives like ciphers and\nMACs. If considering this library for the purpose of protecting passwords, you may actually be looking\nfor a [key derivation function][16], which can provide much better security guarantees for this use case.\n\n## Special Thanks\n\nThe following resources were invaluable to this implementation and deserve special thanks\nfor work well done:\n\n * [Keccak pseudocode][17]: The Keccak team's excellent pseudo-code and technical descriptions.\n\n * [mjosaarinen/tiny_sha3][18]: Markku-Juhani O. Saarinen's compact, legible, and hackable implementation.\n\n * [Phusion][13]: For the initial release and maintenance of this project, and gracious hand-off to Twuni for continued development and maintenance.\n\n[1]: https://keccak.team/keccak.html\n[2]: https://www.phusion.nl/\n[3]: https://img.shields.io/travis/phusion/node-sha3/master.svg?label=Travis%20CI\n[4]: https://travis-ci.org/phusion/node-sha3\n[5]: https://img.shields.io/npm/v/sha3.svg\n[6]: https://www.npmjs.com/package/sha3\n[7]: https://img.shields.io/npm/dt/sha3.svg\n[8]: https://img.shields.io/david/phusion/node-sha3.svg\n[9]: https://github.com/phusion/node-sha3/blob/master/package.json\n[10]: https://img.shields.io/david/dev/phusion/node-sha3.svg\n[11]: https://img.shields.io/github/license/phusion/node-sha3.svg\n[12]: https://github.com/phusion/node-sha3/blob/master/LICENSE\n[13]: https://www.phusion.nl/images/header/pinwheel_logo.svg\n[14]: http://codahale.com/how-to-safely-store-a-password/\n[15]: https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings\n[16]: https://www.npmjs.com/package/pbkdf2\n[17]: https://keccak.team/keccak_specs_summary.html\n[18]: https://github.com/mjosaarinen/tiny_sha3\n","funding_links":["https://github.com/sponsors/canterberry"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphusion%2Fnode-sha3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphusion%2Fnode-sha3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphusion%2Fnode-sha3/lists"}