class Bip0039::Mnemonic

Overview

Implements a Bip0039 Mnemonic class. Ref: bitcoin/bips/bip-0039

Defined in:

bip39.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(ent : Int32 = 128) #

Implements a Bip0039 Mnemonic with a random entropy of ENT bits.

Parameters:

  • #ent (Int32): the bit-size of the random entropy to use (128/160/192/224/256).
mnemonic = Bip0039::Mnemonic.new 256
# => #<Bip0039::Mnemonic:0x7f8be5611d80>

[View source]
def self.new(hex : String) #

Implements a Bip0039 Mnemonic restored from a hexadecimal seed.

Parameters:

  • hex (String): the hex-seed to use to generate the mnemonic from.
mnemonic = Bip0039::Mnemonic.new "9e885d952ad362caebefe34e91bd2"
# => #<Bip0039::Mnemonic:0x7f8be5611d80>

[View source]
def self.new(seed : BigInt, ent : Int32 = 128) #

Implements a Bip0039 Mnemonic restored from a numeric seed of given size.

Parameters:

  • #seed (BigInt): the numeric seed to use to generate the mnemonic from.
  • #ent (Int32): the bit-size of the random entropy to use (128/160/192/224/256).
mnemonic = Bip0039::Mnemonic.new BigInt.new("9e885d952ad362caebefe34e91bd2", 16), 128
# => #<Bip0039::Mnemonic:0x7f8be5611d80>

[View source]
def self.new(phrase : Array(String)) #

Implements a Bip0039 Mnemonic restored from a seed phrase.

Parameters:

  • phrase (Array(String)): the seed phrase to recover the mnemonic from (12/15/18/21/24 words).
mnemonic = Bip0039::Mnemonic.new ["ozone", "drill", "grab", "fiber", "curtain", "grace", "pudding", "thank", "cruise", "elder", "eight", "picnic"]
# => #<Bip0039::Mnemonic:0x7f8be5611d80>

[View source]

Instance Method Detail

def ent : Int32 #

The bit-size of the entropy of the mnemonic.


[View source]
def ent=(ent : Int32) #

The bit-size of the entropy of the mnemonic.


[View source]
def seed : BigInt #

The random seed of the mnemonic.


[View source]
def seed=(seed : BigInt) #

The random seed of the mnemonic.


[View source]
def to_hex : String #

Generates a padded hex string containing the seed of the size of ENT bits.

Bip0039::Mnemonic.new.to_hex
# => "9e885d952ad362caeb4efe34a8e91bd2"

[View source]
def to_words : Array(String) #

Generates a phrase of words according to the Bip0039 specification based on the used seed.

Bip0039::Mnemonic.new.to_words
# => ["ozone", "drill", "grab", "fiber", "curtain", "grace", "pudding", "thank", "cruise", "elder", "eight", "picnic"]

[View source]