Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MnemonicPassPhrase describes a mnemonic pass phrase generator as defined by the Bitcoin BIP39 standard which can be found at following URL:

https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki

This class uses features provided by the bitcoinjs/bip39 package and therefor is licensed under the BSD-2 Clause License as mentioned here.

see

https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki

see

https://github.com/bitcoinjs/bip39

since

0.1.0

Hierarchy

  • MnemonicPassPhrase

Index

Constructors

constructor

Properties

Readonly plain

plain: string

Static Readonly DEFAULT_LANGUAGE

DEFAULT_LANGUAGE: "english" = 'english'

Default wordlist language used.

see

List of Supported Languages

var

{string}

Static Readonly DEFAULT_STRENGTH

DEFAULT_STRENGTH: 256 = 256

Methods

isValid

  • isValid(language?: string): boolean
  • Validate a mnemonic pass phrase with optional language.

    If the language argument is ommited, the default language 'english' will be used.

    The bitcoinjs/bip39 package's validateMnemonic function checks the mnemonic pass phrase by internally converting to an entropy bytes array with mnemonicToEntropy.

    Validation steps include size, checksum bits and checksum validations.

    throws

    {Error} On unsupported language argument.

    Parameters

    • language: string = MnemonicPassPhrase.DEFAULT_LANGUAGE

      (Optional) The language used for the wordlist.

    Returns boolean

    True for valid mnemonic, False for invalid mnemonic.

toArray

  • toArray(): string[]
  • Get the array representation for the mnemonic pass phrase.

    Words are split using a white-space character as a separator.

    Returns string[]

    Array of plain text words

toEntropy

  • toEntropy(language?: string): string
  • Converts a mnemonic to hexadecimal entropy (of strength bits).

    If the language argument is ommited, the default language 'english' will be used.

    The bitcoinjs/bip39 package's mnemonicToEntropy function converts words into 11 bit binary strings, then validates the checksum and finally, returns the built entropy hexadecimal (of strength bits).

    It is not recommended to store the result of this function. Please, have a look at mnemonicToSeed(m, pw) instead.

    see

    {MnemonicPassPhrase}#mnemonicToSeed

    throws

    {Error} On unsupported language argument.

    Parameters

    • language: string = MnemonicPassPhrase.DEFAULT_LANGUAGE

      (Optional) The language used for the wordlist.

    Returns string

    Returns the hexadecimal format of the entropy value.

toSeed

  • toSeed(password?: string): Buffer
  • Convert a mnemonic to an encrypted hexadecimal seed.

    If the password argument is ommited, an empty password will be assumed.

    The bitcoinjs/bip39 package's mnemonicToSeedSync function will first normalize the mnemonic pass phrase Buffer to NFKD form. Afterwards the buffer will be salted with the password (or empty) prepend by the string 'mnemonic'. In its last step, the function will then use PBKDF2 to derivate the password- protected hexadecimal seed from the salted buffer.

    see

    https://en.wikipedia.org/wiki/Unicode_equivalence#Normal_forms

    Parameters

    • Optional password: string

    Returns Buffer

    Buffer containing bytes of the hexadecimal seed.

Static BITXORCORE_RNG

  • BITXORCORE_RNG(bytes: number): Buffer
  • Random number generator using nacl_bitxorcore.

    Implicit conversion to Buffer is needed to comply with bitcoinjs/bip39.

    Parameters

    • bytes: number

      Number of bytes to generate.

    Returns Buffer

Static Protected assertLanguageSupported

  • assertLanguageSupported(language: string): true

Static createFromEntropy

  • Convert an entropy value to a mnemonic pass phrase in plain text.

    If the language argument is ommited, the default language 'english' will be used.

    The bitcoinjs/bip39 package's entropyToMnemonic function validates the entropy value by parsing it, then builds the mnemonic pass phrase by retrieving and joining words from the wordlist.

    throws

    {Error} On unsupported language argument.

    Parameters

    • entropy: string | Buffer
    • language: string = MnemonicPassPhrase.DEFAULT_LANGUAGE

      (Optional) The language used for the wordlist.

    Returns MnemonicPassPhrase

    Returns the mnemonic pass phrase in plain text format.

Static createRandom

  • createRandom(language?: string, strength?: number, rng?: (size: number) => Buffer): MnemonicPassPhrase
  • Create a random mnemonic pass phrase. Arguments to this method are all optional, default values are static variables of this class.

    This static method returns a sentence built following the Bitcoin BIP39 standard using the bitcoinjs/bip39 library.

    todo

    strength replace by countWords for higher level approach

    throws

    {Error} On unsupported language argument.

    Parameters

    • language: string = MnemonicPassPhrase.DEFAULT_LANGUAGE

      (Optional) The language used for the wordlist.

    • strength: number = MnemonicPassPhrase.DEFAULT_STRENGTH

      (Optional) Strength of mnemonic pass phrase (% 32 == 0).

    • rng: (size: number) => Buffer = MnemonicPassPhrase.BITXORCORE_RNG

      (Optional) Random Number Generator to be used.

        • (size: number): Buffer
        • Parameters

          • size: number

          Returns Buffer

    Returns MnemonicPassPhrase

    Returns the mnemonic pass phrase in plain text format.

Generated using TypeDoc