Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanVerbner committed Sep 10, 2017
0 parents commit 4a2d93f
Show file tree
Hide file tree
Showing 19 changed files with 15,175 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Scala CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/sample-config/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/openjdk:8-jdk

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/postgres:9.4

working_directory: ~/repo

environment:
# Customize the JVM maximum heap limit
JVM_OPTS: -Xmx3200m
TERM: dumb

steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "build.sbt" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run: cat /dev/null | sbt test:compile

- save_cache:
paths:
- ~/.m2
key: v1-dependencies--{{ checksum "build.sbt" }}

# run tests!
- run: cat /dev/null | sbt test:test
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.class
*.log
target

*.iml
*.ipr
*.iws
.idea
out
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Alan Verbner

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
## Scala BIP39

[![CircleCI](https://circleci.com/gh/AlanVerbner/bip39.svg?style=svg)](https://circleci.com/gh/AlanVerbner/bip39)

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

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

### Example

```scala
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

```

### TODO

- [ ] Japanese support
- [ ] Add more tests

### API

```scala
/**
* 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
```

```scala
/***
* 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
```

```scala
/**
* 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
```

```scala
/**
* 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]
```

50 changes: 50 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
organization := "com.github.alanverbner"

name := "bip39"

version := "0.1"

scalaVersion := "2.12.3"

libraryDependencies ++= Seq(
"org.consensusresearch" %% "scrypto" % "1.2.0-RC3",
"org.scodec" %% "scodec-bits" % "1.1.5",

"org.scalatest" %% "scalatest" % "3.0.1" % "test"
)

useGpg := true

pomIncludeRepository := { _ => false }

licenses := Seq("MIT" -> url("https://github.com/AlanVerbner/bip39/blob/master/LICENSE"))

homepage := Some(url("https://github.com/AlanVerbner/bip39"))

scmInfo := Some(
ScmInfo(
url("https://github.com/AlanVerbner/bip39"),
"scm:git@github.com:AlanVerbner/bip39.git"
)
)

developers := List(
Developer(
id = "lalanv",
name = "Alan Verbner",
email = "alverbner@gmail.com",
url = url("https://onename.com/lalanv")
)
)

publishMavenStyle := true
publishArtifact in Test := false

publishTo := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value)
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
}

1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version = 0.13.16
4 changes: 4 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1")
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")

99 changes: 99 additions & 0 deletions scalastyle-config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<scalastyle>
<name>Scalastyle standard configuration</name>
<check level="error" class="org.scalastyle.file.FileTabChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.file.FileLengthChecker" enabled="true">
<parameters>
<parameter name="maxFileLength"><![CDATA[800]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.SpacesAfterPlusChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.file.WhitespaceEndOfLineChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.scalariform.SpacesBeforePlusChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.file.FileLineLengthChecker" enabled="true">
<parameters>
<parameter name="maxLineLength"><![CDATA[160]]></parameter>
<parameter name="tabSize"><![CDATA[4]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.ClassNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[[A-Z][A-Za-z]*]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.ObjectNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[[A-Z][A-Za-z]*]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.PackageObjectNamesChecker" enabled="false">
<parameters>
<parameter name="regex"><![CDATA[^[a-z][A-Za-z]*$]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.EqualsHashCodeChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.scalariform.IllegalImportsChecker" enabled="true">
<parameters>
<parameter name="illegalImports"><![CDATA[sun._,java.awt._]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.ParameterNumberChecker" enabled="true">
<parameters>
<parameter name="maxParameters"><![CDATA[8]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.MagicNumberChecker" enabled="true">
<parameters>
<parameter name="ignore"><![CDATA[-1,0,1,2,3,4,5,6,7,8,9,10,16,32,256,0x00,0x01,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x10,0xFF]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.NoWhitespaceBeforeLeftBracketChecker"
enabled="true"></check>
<check level="error" class="org.scalastyle.scalariform.NoWhitespaceAfterLeftBracketChecker"
enabled="true"></check>
<check level="error" class="org.scalastyle.scalariform.ReturnChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.scalariform.NullChecker" enabled="false"></check>
<check level="error" class="org.scalastyle.scalariform.NoCloneChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.scalariform.NoFinalizeChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.scalariform.CovariantEqualsChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.scalariform.StructuralTypeChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.scalariform.NumberOfTypesChecker" enabled="true">
<parameters>
<parameter name="maxTypes"><![CDATA[40]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.CyclomaticComplexityChecker" enabled="true">
<parameters>
<parameter name="maximum"><![CDATA[16]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.SimplifyBooleanExpressionChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.scalariform.IfBraceChecker" enabled="false">
<parameters>
<parameter name="singleLineAllowed"><![CDATA[true]]></parameter>
<parameter name="doubleLineAllowed"><![CDATA[false]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.MethodLengthChecker" enabled="true">
<parameters>
<parameter name="maxLength"><![CDATA[50]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.NumberOfMethodsInTypeChecker" enabled="true">
<parameters>
<parameter name="maxMethods"><![CDATA[30]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.PublicMethodsHaveTypeChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.file.NewLineAtEofChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.file.NoNewLineAtEofChecker" enabled="false"></check>
<check level="error" class="org.scalastyle.scalariform.TodoCommentChecker" enabled="false">
<parameters>
<parameter name="words">TODO|FIXME|todo|fixme|bug|BUG</parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.file.RegexChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[println]]></parameter>
</parameters>
</check>
</scalastyle>
Empty file.
Loading

0 comments on commit 4a2d93f

Please sign in to comment.