项目作者: AlanVerbner

项目描述 :
Scala BIP-39 implementation
高级语言: Scala
项目地址: git://github.com/AlanVerbner/bip39.git
创建时间: 2017-09-09T22:16:58Z
项目社区:https://github.com/AlanVerbner/bip39

开源协议:MIT License

下载


Scala BIP39

CircleCI
Coverage Status

This is a toy BIP39 Scala based implementation I made for fun.

  1. "com.github.alanverbner" %% "bip39" % "0.1"

Example

  1. import com.github.alanverbner.bip39.{EnglishWordList, Entropy128, WordList}
  2. val sentence = bip39.generate(Entropy128, WordList.load(EnglishWordList).get, new SecureRandom())
  3. println(sentence)
  4. bip39.check(sentence, EnglishWordList) shouldEqual true

API

  1. /**
  2. * Generates a BIP-39 mnemonic
  3. * @param entropy The size in bits of the entropy to be created
  4. * @param wordList Language based word list
  5. * @param secureRandom Cryptographically strong random number generator (RNG)
  6. * @return Mnemonic sentence based on random words joined by WordList delimiter
  7. */
  8. def generate(entropy: Entropy, wordList: WordList, secureRandom: SecureRandom): String
  1. /***
  2. * Generates a BIP-39 mnemonic based on a pre-calculated entropy
  3. * @param ent Precalculated entropy. Size should be 16, 20, 24, 28 or 32.
  4. * @param wordList Language based word list
  5. * @return Mnemonic sentence based on random words joined by WordList delimiter
  6. */
  7. def generate(ent: Array[Byte], wordList: WordList): String
  1. /**
  2. * Given a mnemonic and a given wordl list, determines if it's valid using BIP-39 checksum
  3. * @param mnemonic The mnemonic sentence used to derive seed bytes. Will be NFKD Normalized
  4. * @param wordList Language based word list
  5. * @return True if valid, false otherwise
  6. */
  7. def check(mnemonic: String, wordList: WordList): Boolean
  1. /**
  2. * Generates a seed bytes based on the given mnemonic and passphrase (if provided)
  3. * @param mnemonic The mnemonic sentence used to derive seed bytes. Will be NFKD Normalized
  4. * @param passphrase Optional passphrase used to protect seed bytes, defaults to empty
  5. * @return Seed bytes
  6. */
  7. def toSeed(mnemonic: String, passphrase: Option[String] = None): Array[Byte]