function randomPrivateKeyBytes
randomPrivateKeyBytes(): Uint8Array

Generates clamped private key from random data.

Clamping is done by clearing bits 0, 1, 2 of the first byte, bit 7 of last byte and setting bit 6 of the last byte.

Useful for generating private key.

Examples

Generate clamped private key bytes

import { assertEquals } from "@std/assert";
import { randomPrivateKeyBytes } from "@hertzg/wg-keys";

const key = randomPrivateKeyBytes();

assertEquals(key.length, 32);
// Bits 0, 1, 2 of the first byte are cleared.
assertEquals(key[0] & 0b00000111, 0);
// Bit 7 of the last byte is cleared, bit 6 is set.
assertEquals(key[31] & 0b11000000, 0b01000000);

Return Type

private key bytes

See

Usage

import { randomPrivateKeyBytes } from ".";