mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-04-22 09:08:03 +00:00
29 lines
860 B
JavaScript
29 lines
860 B
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.randomAsHex = void 0;
|
|
exports.randomAsU8a = randomAsU8a;
|
|
const x_randomvalues_1 = require("@pezkuwi/x-randomvalues");
|
|
const helpers_js_1 = require("../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([...])
|
|
* ```
|
|
*/
|
|
function randomAsU8a(length = 32) {
|
|
return (0, x_randomvalues_1.getRandomValues)(new Uint8Array(length));
|
|
}
|
|
/**
|
|
* @name randomAsHex
|
|
* @description Creates a hex string filled with random bytes.
|
|
*/
|
|
exports.randomAsHex = (0, helpers_js_1.createAsHex)(randomAsU8a);
|