Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/libauth/src/lib/key/key-utils.ts>generatePrivateKey

An ultra-lightweight, zero-dependency JavaScript library for Bitcoin Cash, Bitcoin, and Bitauth applications.
Go to Latest
variable generatePrivateKey
import { generatePrivateKey } from "https://deno.land/x/libauth@v2.0.0-alpha.6/src/lib/key/key-utils.ts";

Securely generate a valid Secp256k1 private key given a secure source of randomness.

Node.js Usage

import { randomBytes } from 'crypto';
import { generatePrivateKey } from '@bitauth/libauth';

const key = generatePrivateKey(() => randomBytes(32));

Browser Usage

import { generatePrivateKey } from '@bitauth/libauth';

const key = generatePrivateKey(() =>
  window.crypto.getRandomValues(new Uint8Array(32))
);

type

(secureRandom: () => Uint8Array) => unknown