UNPKG

1.23 kBJavaScriptView Raw
1import { keccak_256 as keccak256Js, keccak_512 as keccak512Js } from '@noble/hashes/sha3';
2import { keccak256, keccak512 } from '@polkadot/wasm-crypto';
3import { createAsHex, createBitHasher, createDualHasher } from '../helpers.js';
4/**
5 * @name keccakAsU8a
6 * @summary Creates a keccak Uint8Array from the input.
7 * @description
8 * From either a `string` or a `Buffer` input, create the keccak and return the result as a `Uint8Array`.
9 * @example
10 * <BR>
11 *
12 * ```javascript
13 * import { keccakAsU8a } from '@polkadot/util-crypto';
14 *
15 * keccakAsU8a('123'); // => Uint8Array
16 * ```
17 */
18export const keccakAsU8a = /*#__PURE__*/ createDualHasher({ 256: keccak256, 512: keccak512 }, { 256: keccak256Js, 512: keccak512Js });
19/**
20 * @name keccak256AsU8a
21 * @description Creates a keccak256 Uint8Array from the input.
22 */
23export const keccak256AsU8a = /*#__PURE__*/ createBitHasher(256, keccakAsU8a);
24/**
25 * @name keccak512AsU8a
26 * @description Creates a keccak512 Uint8Array from the input.
27 */
28export const keccak512AsU8a = /*#__PURE__*/ createBitHasher(512, keccakAsU8a);
29/**
30 * @name keccakAsHex
31 * @description Creates a keccak hex string from the input.
32 */
33export const keccakAsHex = /*#__PURE__*/ createAsHex(keccakAsU8a);