23 lines
618 B
TypeScript
23 lines
618 B
TypeScript
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import { getRandomValues } from '@polkadot/x-randomvalues';
|
|
|
|
/**
|
|
* @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([...])
|
|
* ```
|
|
*/
|
|
export function randomAsU8a (length = 32): Uint8Array {
|
|
return getRandomValues(new Uint8Array(length));
|
|
}
|