mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-04-22 05:38:03 +00:00
25 lines
700 B
JavaScript
25 lines
700 B
JavaScript
import { getRandomValues } from '@pezkuwi/x-randomvalues';
|
|
import { createAsHex } from '../helpers.js';
|
|
/**
|
|
* @name randomAsU8a
|
|
* @summary Creates a Uint8Array filled with random bytes.
|
|
* @description
|
|
* Returns a `Uint8Array` with the specified (optional) length filled with random bytes.
|
|
* @example
|
|
* <BR>
|
|
*
|
|
* ```javascript
|
|
* import { randomAsU8a } from '@pezkuwi/util-crypto';
|
|
*
|
|
* randomAsU8a(); // => Uint8Array([...])
|
|
* ```
|
|
*/
|
|
export function randomAsU8a(length = 32) {
|
|
return getRandomValues(new Uint8Array(length));
|
|
}
|
|
/**
|
|
* @name randomAsHex
|
|
* @description Creates a hex string filled with random bytes.
|
|
*/
|
|
export const randomAsHex = /*#__PURE__*/ createAsHex(randomAsU8a);
|