Skip to content

Mnemonic

MarcoDotIO edited this page Apr 25, 2023 · 1 revision

Mnemonic

Used for deriving BIP39 Phrases

public class Mnemonic 

Inheritance

Equatable

Initializers

init(strength:wordlist:)

public init(strength: Int = 256, wordlist: [String] = Wordlists.english) 

init(wordcount:wordlist:)

public init(wordcount: Int = 12, wordlist: [String] = Wordlists.english) 

init(phrase:passphrase:)

public init(phrase: [String], passphrase: String = "") throws 

init(entropy:wordlist:passphrase:)

public init(entropy: [UInt8], wordlist: [String] = Wordlists.english, passphrase: String = "") throws 

Properties

phrase

Contains the seed phrases themselves

public let phrase: [String]

seed

Used for deriving the seed when generating the private and public keys

public var seed: Data? 

Methods

toMnemonic(_:wordlist:)

Converts an array of bytes to a list of mnemonic words using a specified wordlist.

public static func toMnemonic(_ bytes: [UInt8], wordlist: [String] = Wordlists.english) throws -> [String] 

Parameters

  • bytes: An array of bytes to be converted to a mnemonic phrase.
  • wordlist: An optional parameter specifying the wordlist to be used. If not provided, the default English wordlist will be used.

Throws

Any error thrown by Mnemonic.deriveChecksumBits() function if there is an issue calculating the checksum bits.

Returns

A list of mnemonic words representing the input bytes.

toEntropy(_:wordlist:)

Converts a list of mnemonic words to an array of bytes.

public static func toEntropy(_ phrase: [String], wordlist: [String] = Wordlists.english) throws -> [UInt8] 

Parameters

  • phrase: A list of mnemonic words to be converted to an array of bytes.
  • wordlist: An optional parameter specifying the wordlist to be used. If not provided, the default English wordlist will be used.

Throws

An Error.invalidMnemonic error if the checksum of the input mnemonic phrase does not match the expected checksum.

Returns

An array of bytes representing the input mnemonic phrase.

isValid(phrase:wordlist:)

Checks if a given mnemonic phrase is valid based on a specified wordlist.

public static func isValid(phrase: [String], wordlist: [String] = Wordlists.english) -> Bool 

Parameters

  • phrase: A list of mnemonic words to be validated.
  • wordlist: An optional parameter specifying the wordlist to be used for validation. If not provided, the default English wordlist will be used.

Returns

A boolean value indicating whether the input mnemonic phrase is valid according to the specified wordlist.

deriveChecksumBits(_:)

Calculates the checksum bits for a given array of bytes.

public static func deriveChecksumBits(_ bytes: [UInt8]) -> String 

Parameters

  • bytes: An array of bytes for which to calculate the checksum bits.

Returns

A string representing the checksum bits.

Operators

==

public static func == (lhs: Mnemonic, rhs: Mnemonic) -> Bool 
Types
Protocols
Global Variables
Global Functions
Extensions
Clone this wiki locally