CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-polkadot--util-crypto

A collection of useful crypto utilities for Polkadot ecosystem projects

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

random.mddocs/

Random Number Generation

Cryptographically secure random number generation in various formats for keys, nonces, and other security-critical randomness.

Capabilities

Random Bytes

Generate cryptographically secure random bytes.

/**
 * Generate random bytes
 * @param bitLength - Length in bits (default: 256)
 * @returns Random bytes as Uint8Array
 */
function randomAsU8a(bitLength?: number): Uint8Array;

/**
 * Generate random hex string
 * @param bitLength - Length in bits (default: 256)
 * @returns Random hex string with 0x prefix
 */
function randomAsHex(bitLength?: number): string;

/**
 * Generate random number
 * @param bitLength - Length in bits (default: 53)
 * @returns Random number within JavaScript safe integer range
 */
function randomAsNumber(bitLength?: number): number;

Usage Examples:

import { randomAsU8a, randomAsHex, randomAsNumber } from "@polkadot/util-crypto";

// Generate 32 random bytes (256 bits)
const randomBytes = randomAsU8a(256);
console.log(randomBytes.length); // 32

// Generate random hex string
const randomHex = randomAsHex(128); // 16 bytes as hex
console.log(randomHex); // "0x..."

// Generate random number (up to 53 bits for JavaScript safety)
const randomNum = randomAsNumber(32);
console.log(randomNum); // Random 32-bit integer

Install with Tessl CLI

npx tessl i tessl/npm-polkadot--util-crypto

docs

address.md

base-encoding.md

crypto-init.md

ethereum.md

hashing.md

index.md

json-encryption.md

key-derivation-pbkdf.md

key-derivation.md

keypairs.md

mnemonic.md

random.md

signatures.md

tile.json