UNPKG

702 BJavaScriptView Raw
1import { getRandomValues } from '@polkadot/x-randomvalues';
2import { createAsHex } from '../helpers.js';
3/**
4 * @name randomAsU8a
5 * @summary Creates a Uint8Array filled with random bytes.
6 * @description
7 * Returns a `Uint8Array` with the specified (optional) length filled with random bytes.
8 * @example
9 * <BR>
10 *
11 * ```javascript
12 * import { randomAsU8a } from '@polkadot/util-crypto';
13 *
14 * randomAsU8a(); // => Uint8Array([...])
15 * ```
16 */
17export function randomAsU8a(length = 32) {
18 return getRandomValues(new Uint8Array(length));
19}
20/**
21 * @name randomAsHex
22 * @description Creates a hex string filled with random bytes.
23 */
24export const randomAsHex = /*#__PURE__*/ createAsHex(randomAsU8a);