# sha256-wasm

> WebAssembly implementation of SHA-256

Latest version **2.2.2** (published 2021-10-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install sha256-wasm
pnpm add sha256-wasm
yarn add sha256-wasm
bun add sha256-wasm
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.2 |
| Published | 2021-10-25 |
| First published | 2019-11-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | separate (@types/sha256-wasm) |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 12.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Christophe Diederichs |
| Maintainers | chm-diederichs |
| Keywords | WebAssembly, SHA-256 |

## Links

- npm: https://www.npmjs.com/package/sha256-wasm
- Repository: https://github.com/chm-diederichs/sha256-wasm
- Homepage: https://github.com/chm-diederichs/sha256-wasm#readme
- Issues: https://github.com/chm-diederichs/sha256-wasm/issues
- npm.io page: https://npm.io/package/sha256-wasm

## Dependencies (2)

- [b4a](https://npm.io/package/b4a.md) ^1.0.1
- [nanoassert](https://npm.io/package/nanoassert.md) ^2.0.0

## Recent versions

- 2.2.2 (latest) — 2021-10-25
- 2.2.1 — 2021-04-28
- 2.2.0 — 2021-04-28
- 2.1.2 — 2020-12-18
- 2.1.1 — 2020-12-18
- 2.1.0 — 2020-09-03
- 2.0.3 — 2020-07-02
- 2.0.2 — 2020-07-02
- 2.0.1 — 2020-07-02
- 2.0.0 — 2020-07-02
- 1.3.0 — 2020-06-18
- 1.2.3 — 2020-02-18
- 1.2.2 — 2020-02-17
- 1.2.1 — 2020-01-18
- 1.2.0 — 2020-01-16
- … 6 more at https://npm.io/package/sha256-wasm/versions

## README

# sha256-wasm
## Usage
```js
const sha256 = require('sha256-wasm')

if (!Sha256.SUPPORTED) {
  console.log('WebAssembly not supported by your runtime')
}

var hash = sha256()
  .update('hello')
  .update(' ')
  .update(Buffer.from('world'))
  .digest('hex')

console.log('Sha256 hash of "hello world" is ', hash)
// b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
```

## API
#### `const hash = sha256()`

Create a new hash instance.

#### `hash.update(data, [enc])`

Update the hash with a new piece of data. `data` may be passed as a buffer, uint8array or a string. If `data` is passed as a string, then it will be interpreted as a `utf8` string unless `enc` specifies an encoding.

Supported `enc`s are:
- `utf8` / `utf-8` (defualt)
- `hex`
- `base64`

#### `hash.digest([enc])`

Digest the hash. If `enc` is specified, then the digest shall be returned as an `enc` encoded string. Otherwise a buffer is returned.

Supported `enc`s are:
- `utf8` / `utf-8` (defualt)
- `hex`
- `base64`

#### `var promise = sha256.ready([cb])`

Wait for the WASM code to load. Returns the WebAssembly instance promise as well for convenience.
You have to call this at least once before instantiating the hash.

## Contributing

The bulk of this module is implemented in WebAssembly in the [sha256.wat](sha256.wat) file. To build the thin Javascript wrapper do:

```
npm run compile
```

## License

MIT

---
_Source: https://npm.io/package/sha256-wasm · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
