@polkadot/util-crypto
Version:
A collection of useful crypto utilities for @polkadot
29 lines (28 loc) • 884 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.randomAsHex = exports.randomAsU8a = void 0;
const x_randomvalues_1 = require("@polkadot/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 '@polkadot/util-crypto';
*
* randomAsU8a(); // => Uint8Array([...])
* ```
*/
function randomAsU8a(length = 32) {
return (0, x_randomvalues_1.getRandomValues)(new Uint8Array(length));
}
exports.randomAsU8a = randomAsU8a;
/**
* @name randomAsHex
* @description Creates a hex string filled with random bytes.
*/
exports.randomAsHex = (0, helpers_js_1.createAsHex)(randomAsU8a);
;