BIP39Mnemonic

@interface BIP39Mnemonic : NSObject

Bitcoin Improvement Protocol (BIP) #39 Mnemonic code for generating deterministic keys

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

This class implements mnemonic encoding/decoding according to BIP-39.

  • Returns the closest language identifier for given localeIdentifier. The language identifier is passed to other BIP39Mnemonic functions that require it.

    Declaration

    Objective-C

    + (nullable NSString *)languageIDForLocaleIdentifier:
        (nullable NSString *)localeIdentifier;

    Swift

    class func languageID(forLocaleIdentifier localeIdentifier: String?) -> String?

    Parameters

    localeIdentifier

    Optional locale for the wordlist - for null will default to preferred locale

    Return Value

    A string matching the closest language identifier for the locale.

  • Return an array of languageIDs supported

    Declaration

    Objective-C

    + (nonnull NSArray<NSString *> *)availableLanguages;

    Swift

    class func availableLanguages() -> [String]

    Return Value

    An array of string’s of the languageIDs supported

  • Return a the number of mnemonic words needed for given bit size

    Declaration

    Objective-C

    + (BOOL)mnemonicCountForBits:(NSUInteger)bitSize
                   mnemonicCount:(nonnull NSUInteger *)mnemonicountOut;

    Swift

    class func mnemonicCount(forBits bitSize: UInt, mnemonicCount mnemonicountOut: UnsafeMutablePointer<UInt>) -> Bool

    Parameters

    bitSize

    number of bits to encode/decode

    mnemonicountOut

    if bitsSize is valid, return the number of words needed

    Return Value

    TRUE if bitSize is valid 128/160/192/224/256

  • Return a list of acceptable mnemonic words for a given Locale

    Declaration

    Objective-C

    + (nullable NSArray<NSString *> *)
        wordListForLanguageID:(NSString *_Nullable)languageID
                        error:(NSError *_Nullable *_Nullable)errorOut;

    Swift

    class func wordList(forLanguageID languageID: String?) throws -> [String]

    Parameters

    languageID

    optional languageID for the wordlist - for null will default to prefered locale

    errorOut

    If an error occurs, this parameter will indicate what the problem was.

    Return Value

    An array of 2048 unique words in the word list

  • Return a matching mnemonic word for a given string - expend abbreviated to proper mnemonic

    Declaration

    Objective-C

    + (nullable NSString *)matchingMnemonicForString:(nonnull NSString *)word
                                          languageID:(NSString *_Nullable)languageID
                                               error:(NSError *_Nullable *_Nullable)
                                                         errorOut;

    Swift

    class func matchingMnemonic(for word: String, languageID: String?) throws -> String

    Parameters

    languageID

    optional languageID for the wordlist - for null will default to prefered locale

    word

    word to use to search wordlist

    errorOut

    If an error occurs, this parameter will indicate what the problem was.

    Return Value

    A string with matching mnemonic

  • Converts from a mnemonic to its data.

    Declaration

    Objective-C

    + (nullable NSData *)dataFromMnemonic:(nonnull NSArray<NSString *> *)mnemonic
                               languageID:(NSString *_Nullable)languageID
                                    error:(NSError *_Nullable *_Nullable)errorOut;

    Swift

    class func data(fromMnemonic mnemonic: [String], languageID: String?) throws -> Data

    Parameters

    mnemonic

    The mnemonic output from a previous encoding (using the same language file).

    languageID

    optional languageID for the wordlist - for null will default to prefered locale

    errorOut

    If an error occurs, this parameter will indicate what the problem was.

    Return Value

    The key which the mnemonic was encoding.

  • Converts from data to a mnemonic (word list).

    Declaration

    Objective-C

    + (nullable NSArray<NSString *> *)
        mnemonicFromData:(nonnull NSData *)keyData
              languageID:(NSString *_Nullable)languageID
                   error:(NSError *_Nullable *_Nullable)errorOut;

    Swift

    class func mnemonic(from keyData: Data, languageID: String?) throws -> [String]

    Parameters

    keyData

    The data to convert to a mnemonic. The data size must be a multiple of 32 bits, with a total length between 128-256 bits (inclusive).

    languageID

    optional languageID for the wordlist - for null will default to prefered locale

    errorOut

    If an error occurs, this parameter will indicate what the problem was.

    Return Value

    The mnemonic, represented as an array of words from the language file.

  • Converts from a key to a mnemonic (word list).

    Declaration

    Objective-C

    + (nullable NSArray<NSString *> *)
        mnemonicFromKey:(nonnull NSData *)keyData
             passphrase:(NSString *_Nullable)passphrase
             languageID:(NSString *_Nullable)languageID
                  error:(NSError *_Nullable *_Nullable)errorOut;

    Swift

    class func mnemonic(fromKey keyData: Data, passphrase: String?, languageID: String?) throws -> [String]

    Parameters

    keyData

    The key to convert to a mnemonic. The key size must be a multiple of 32 bits, with a total length between 128-256 bits (inclusive).

    passphrase

    The mnemonic may be optionally protected with a passphrase. If a passphrase is not present, an empty string “” is used instead.

    languageID

    optional languageID for the wordlist - for null will default to prefered locale

    errorOut

    If an error occurs, this parameter will indicate what the problem was.

    Return Value

    The mnemonic, represented as an array of words from the language file.

  • Converts from a mnemonic back to a key.

    Declaration

    Objective-C

    + (nullable NSData *)keyFromMnemonic:(nonnull NSArray<NSString *> *)mnemonic
                              passphrase:(NSString *_Nullable)passphrase
                              languageID:(NSString *_Nullable)languageID
                                   error:(NSError *_Nullable *_Nullable)errorOut;

    Swift

    class func key(fromMnemonic mnemonic: [String], passphrase: String?, languageID: String?) throws -> Data

    Parameters

    mnemonic

    The mnemonic output from a previous encoding (using the same passphrase & language file).

    passphrase

    If the mnemonic was protected with a passphrase, that should be passed here.

    languageID

    optional languageID for the wordlist - for null will default to prefered locale

    errorOut

    If an error occurs, this parameter will indicate what the problem was.

    Return Value

    The key which the mnemonic was encoding.