Skip to content

Seed Phrase Generation

Process and functions involved in generating and deriving cryptographic seeds from mnemonic phrases within the Non-Custodial Application. Seed phrases are a critical component of hierarchical deterministic (HD) wallets, providing a human-readable backup for cryptographic keys.


1. Introduction to Seed Phrases

A seed phrase (or mnemonic phrase) is a sequence of 12 words that serves as a master key for a cryptocurrency wallet. It is generated using a standardized algorithm BIP-39 and can be used to deterministically derive all private keys and addresses within a wallet. This makes it the single most important piece of information for recovering or backing up a wallet.

In this application, the seed phrase is generated and then used to derive a cryptographic seed, which is subsequently used to initialize the hardware security card.


2. Core Functions

The seed phrase generation and derivation process relies on two primary functions:

generateMnemonic()

This function is responsible for creating a new, random mnemonic phrase.

  • Description: Generates a new 12-word mnemonic phrase according to the BIP-39 standard. The words are selected from a predefined wordlist.
  • Parameters: None.
  • Returns: string[] - An array of 12 words, representing the mnemonic phrase.
  • Usage: This function should be called when a new wallet is being set up or a new card is being registered, requiring a fresh seed.

deriveSeedFromMnemonic(mnemonicString)

This function takes a mnemonic phrase and converts it into a cryptographic seed.

  • Description: Derives a 512-bit (64-byte) cryptographic seed from a given mnemonic phrase string. This process typically involves a key derivation function like PBKDF2, using the mnemonic as the password and a fixed salt.
  • Parameters:
    • mnemonicString: string - The space-separated 12-word mnemonic phrase.
  • Returns: Uint8Array - A Uint8Array containing the 64-byte derived seed.
  • Usage: The derived seed is then used to initialize the hardware security card, ensuring that the card's keys are deterministically linked to the user's seed phrase.

3. Usage Example

Here’s how you would typically use these functions to generate a seed phrase and derive a master key for a new card registration process.

javascript
// Assuming '@/api/mnemonic' contains the generateMnemonic and deriveSeedFromMnemonic functions

import { generateMnemonic, deriveSeedFromMnemonic } from '@/api/mnemonic';

// 1. Generate a new 12-word mnemonic phrase
const seedPhrasesArray = generateMnemonic();
console.log('Generated Mnemonic Phrase:', seedPhrasesArray.join(' '));
// Example output: "word1 word2 word3 word4 word5 word6 word7 word8 word9 word10 word11 word12"

// 2. Join the array of words into a single space-separated string
const seedPhrasesString = seedPhrasesArray.join(' ');

// 3. Derive the cryptographic seed from the mnemonic string
const derivedSeed = deriveSeedFromMnemonic(seedPhrasesString);
console.log('Derived Seed (Uint8Array):', derivedSeed);
// Example output: Uint8Array(64) [123, 45, 67, ..., 89] (a 64-byte array)