# Generating private keys

Hive layer 1 keys can be generated via two methods:

  1. Derivation of a set of private keys from a password (sometimes referred to as a "Master Password"). This is typically used to initially create active, owner, posting, and memo keys for a Hive account.
  2. Randomly generate a new private key (generally should only be used in one-time-use scenarios).

# Generate a private key for an account role from a password

import { createWaxFoundation } from '@hiveio/wax';

const waxApi = await createWaxFoundation();
const accountName = "your-account";
const role = "active"; // roles can be 'active', 'owner', 'posting', or 'memo'
const masterPassword = "your-master-password";

// Generating a new private key from a password
const privateKeyData = waxApi.getPrivateKeyFromPassword(accountName, role, masterPassword);

console.log(`Associated Public Key: ${privateKeyData.associatedPublicKey}`);
console.log(`WIF Private Key: ${privateKeyData.wifPrivateKey}`);

# Suggest Brain Key

A brain key is a long passphrase that provides enough entropy to generate cryptographic keys. The suggestBrainKey function returns a brain key along with the corresponding private and public keys.

Using a brain key, you can regenerate the same key pairs whenever needed, provided the exact same mnemonic phrase is used. This is especially useful in scenarios requiring backup and recovery of cryptographic keys, ensuring they are never permanently lost.

# Generate a random private key

import { createWaxFoundation } from '@hiveio/wax';

const waxApi = await createWaxFoundation();

// Suggest brain key
const privateKeyData = waxApi.suggestBrainKey();

console.log(`Associated Public Key: ${privateKeyData.associatedPublicKey}`);
console.log(`WIF Private Key: ${privateKeyData.wifPrivateKey}`);
console.log(`Brain Key: ${privateKeyData.brainKey}`);