Class: CardanoWallet::Utils::Mnemonic

Inherits:
Base
  • Object
show all
Defined in:
lib/cardano_wallet/utils.rb

Overview

Utils for mnemonics

Instance Attribute Summary

Attributes inherited from Base

#opt

Instance Method Summary collapse

Methods inherited from Base

#byron, #initialize, #misc, #shared, #shelley, #utils

Constructor Details

This class inherits a constructor from CardanoWallet::Base

Instance Method Details

#mnemonic_sentence(word_count = 24, language = 'english') ⇒ Object

Generate mnemonic sentence

Examples:

Default 24-word English mnemonic sentence

@cw.utils.mnemonic_sentence

15-word French mnemonic sentence

@cw.utils.mnemonic_sentence(15, 'french')


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cardano_wallet/utils.rb', line 23

def mnemonic_sentence(word_count = 24, language = 'english')
  languages = %w[english french spanish korean japanese
                 italian chinese_traditional chinese_simplified]
  unless languages.include?(language)
    raise ArgumentError,
          %(Not supported language: '#{language}'. Supported languages are: #{languages}.)
  end

  words = [9, 12, 15, 18, 21, 24]
  case word_count
  when 9
    bits = 96
  when 12
    bits = 128
  when 15
    bits = 164
  when 18
    bits = 196
  when 21
    bits = 224
  when 24
    bits = 256
  else
    raise ArgumentError,
          %(Not supported count of words #{word_count}. Supported counts are: #{words}.)
  end
  BipMnemonic.to_mnemonic(bits: bits, language: language).split
end