UNPKG

1.29 kBJavaScriptView Raw
1// Copyright 2017-2022 @polkadot/util-crypto authors & contributors
2// SPDX-License-Identifier: Apache-2.0
3import { keccak_256 as keccak256Js, keccak_512 as keccak512Js } from '@noble/hashes/sha3';
4import { keccak256, keccak512 } from '@polkadot/wasm-crypto';
5import { createAsHex, createBitHasher, createDualHasher } from "../helpers.js";
6/**
7 * @name keccakAsU8a
8 * @summary Creates a keccak Uint8Array from the input.
9 * @description
10 * From either a `string` or a `Buffer` input, create the keccak and return the result as a `Uint8Array`.
11 * @example
12 * <BR>
13 *
14 * ```javascript
15 * import { keccakAsU8a } from '@polkadot/util-crypto';
16 *
17 * keccakAsU8a('123'); // => Uint8Array
18 * ```
19 */
20
21export const keccakAsU8a = createDualHasher({
22 256: keccak256,
23 512: keccak512
24}, {
25 256: keccak256Js,
26 512: keccak512Js
27});
28/**
29 * @name keccak256AsU8a
30 * @description Creates a keccak256 Uint8Array from the input.
31 */
32
33export const keccak256AsU8a = createBitHasher(256, keccakAsU8a);
34/**
35 * @name keccak512AsU8a
36 * @description Creates a keccak512 Uint8Array from the input.
37 */
38
39export const keccak512AsU8a = createBitHasher(512, keccakAsU8a);
40/**
41 * @name keccakAsHex
42 * @description Creates a keccak hex string from the input.
43 */
44
45export const keccakAsHex = createAsHex(keccakAsU8a);
\No newline at end of file