Skip to content
main
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

Bip39.swift

🐧 linux: ready GitHub license Build Status GitHub release SPM compatible CocoaPods version Platform macOS | iOS | tvOS | watchOS | Linux

Cross-platform BIP39 mnemonic implementation for Swift.

Installation

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.1.0")
  • CocoaPods: Put this in your Podfile:

    pod 'Bip39.swift', '~> 0.1'

Usage Examples

Random generated mnemonic

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)

Mnemonic from Bip39 string

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)

Seed from Mnemonic

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)

Check Bip39 string is valid

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)

License

Bip39.swift can be used, distributed and modified under the Apache 2.0 license.

About

Cross-platform BIP39 mnemonic implementation for Swift.

Resources

License

Packages

No packages published