Coder Social home page Coder Social logo

bip39's Introduction

Scala BIP39

CircleCI Coverage Status

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

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

Example

import com.github.alanverbner.bip39.{EnglishWordList, Entropy128, WordList}

val sentence = bip39.generate(Entropy128, WordList.load(EnglishWordList).get, new SecureRandom())
println(sentence)
bip39.check(sentence, EnglishWordList) shouldEqual true

API

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

bip39's People

Contributors

alanverbner avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.