|
1 | | -# js-sha3 |
| 1 | +# @multiformats/sha3 |
2 | 2 |
|
3 | | -Multiformats hash functions for SHA3. |
| 3 | +SHA3 (and related) multihash hashers for [multiformats](https://github.com/multiformats/js-multiformats). |
| 4 | + |
| 5 | +`MultihashHashers`s are exported from this library, they produce `MultihashDigest`s. Details about these can be found in the [multiformats multihash interface definitions](https://github.com/multiformats/js-multiformats/blob/master/src/hashes/interface.ts). |
4 | 6 |
|
5 | 7 | ```js |
6 | | -import multiformats from 'multiformats/basics' |
7 | | -import sha3 from '@multiformats/sha3' |
| 8 | +import * as Block from 'multiformats/block' |
| 9 | +import * as codec from '@ipld/dag-cbor' |
| 10 | +import { sha3256 as hasher } from '@multiformats/sha3' |
| 11 | + |
| 12 | +async function run () { |
| 13 | + const value = { hello: 'world' } |
| 14 | + const block = await Block.encode({ value, hasher, codec }) |
| 15 | + console.log(block.cid) |
| 16 | + // -> CID(bafyrmidyqnbqbeh5lmkwavjizfmsz6ezwvjleweh5frwk56akfyugoio2e) |
| 17 | +} |
| 18 | + |
| 19 | +run().catch(console.error) |
| 20 | +``` |
| 21 | + |
| 22 | +## Usage |
| 23 | + |
| 24 | +The `@multiformats/sha3` package exports `sha3*`, `shake*` and `keccak*` `MultihashHasher`s. The Multicodecs [table](https://github.com/multiformats/multicodec/blob/master/table.csv) defines these multihashes. |
| 25 | + |
| 26 | +The following `MultihashHasher`s are exported: |
8 | 27 |
|
9 | | -const { multihash } = multiformats |
10 | | -multihash.add(sha3) |
| 28 | +* `sha3224` - SHA3-224 |
| 29 | +* `sha3256` - SHA3-256 |
| 30 | +* `sha3384` - SHA3-384 |
| 31 | +* `sha3512` - SHA3-512 |
| 32 | +* `shake128` - SHAKE-128 (256 output bits) |
| 33 | +* `shake256` - SHAKE-256 (512 output bits) |
| 34 | +* `keccak224` - KECCAK-224 |
| 35 | +* `keccak256` - KECCAK-256 |
| 36 | +* `keccak384` - KECCAK-384 |
| 37 | +* `keccak512` - KECCAK-512 |
11 | 38 |
|
12 | | -const data = new Uint8Array([...someData]) |
13 | | -const hash = await multihash.hash(data, 'sha3-384') |
| 39 | + |
| 40 | +e.g. he `sha3-384`, multicodec code `0x15`, may be imported as: |
| 41 | + |
| 42 | +```js |
| 43 | +import { sha3384 } from '@multiformats/sha3' |
14 | 44 | ``` |
15 | 45 |
|
16 | | -This package contains hash functions for `sha3-224`, `sha3-256`, `sha3-384`,`sha3-512`, `shake-128`, `shake-256`, `keccak-224`, `keccak-256`, `keccak-384`, and `keccak-512`. |
| 46 | +## License |
| 47 | + |
| 48 | +Licensed under either of |
| 49 | + |
| 50 | + * Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / http://www.apache.org/licenses/LICENSE-2.0) |
| 51 | + * MIT ([LICENSE-MIT](LICENSE-MIT) / http://opensource.org/licenses/MIT) |
| 52 | + |
| 53 | +### Contribution |
| 54 | + |
| 55 | +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. |
0 commit comments