Cross-platform BIP39 mnemonic implementation for Swift.
Bip39.swift deploys to macOS, iOS, tvOS, watchOS and Linux. It has been tested on the latest OS releases only however, as the module uses very few platform-provided APIs, there should be very few issues with earlier versions.
Setup instructions:
-
Swift Package Manager: Add this to the dependency section of your
Package.swift
manifest:.package(url: "https://github.com/tesseract-one/Bip39.swift.git", from: "0.2.0")
-
CocoaPods: Put this in your
Podfile
:pod 'Bip39.swift', '~> 0.2'
import Bip39
// 128bit mnemonic by default
let mnemonic = try! Mnemonic()
// Obtaining phrase. English by default. Returns string array
let phrase = mnemonic.mnemonic().joined(separator: " ")
print("Mnemonic: ", phrase)
import Bip39
// Mnemonic phrase
let phrase = "rally speed budget undo purpose orchard hero news crunch flush wine finger"
// Creating mnemonic. English wordlist by default
let mnemonic = try! Mnemonic(mnemonic: phrase.components(separatedBy: " "))
// 128 bit entropy
print("Entropy: ", mnemonic.entropy)
import Bip39
// Mnemonic phrase
let phrase = "rally speed budget undo purpose orchard hero news crunch flush wine finger"
// Creating mnemonic. English wordlist by default
let mnemonic = try! Mnemonic(mnemonic: phrase.components(separatedBy: " "))
// Empty password and English wordlist by default
let seed = mnemonic.seed()
print("Seed: ", seed)
import Bip39
// Mnemonic phrase
let phrase = "rally speed budget undo purpose orchard hero news crunch flush wine finger"
// Validation. English wordlist by default
let isValid = Mnemonic.isValid(phrase: phrase.components(separatedBy: " "))
print("Valid: ", isValid)
Bip39.swift can be used, distributed and modified under the Apache 2.0 license.