1 | // Copyright 2017-2022 @polkadot/util-crypto authors & contributors
|
2 | // SPDX-License-Identifier: Apache-2.0
|
3 | import { keccak_256 as keccak256Js, keccak_512 as keccak512Js } from '@noble/hashes/sha3';
|
4 | import { keccak256, keccak512 } from '@polkadot/wasm-crypto';
|
5 | import { 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 |
|
21 | export 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 |
|
33 | export const keccak256AsU8a = createBitHasher(256, keccakAsU8a);
|
34 | /**
|
35 | * @name keccak512AsU8a
|
36 | * @description Creates a keccak512 Uint8Array from the input.
|
37 | */
|
38 |
|
39 | export const keccak512AsU8a = createBitHasher(512, keccakAsU8a);
|
40 | /**
|
41 | * @name keccakAsHex
|
42 | * @description Creates a keccak hex string from the input.
|
43 | */
|
44 |
|
45 | export const keccakAsHex = createAsHex(keccakAsU8a); |
\ | No newline at end of file |