init crypto js project (#32)

* init crypto js project

* replace test

* fix PR comments

* fix PR comments
This commit is contained in:
Dima 2018-02-07 15:50:47 +03:00 committed by GitHub
parent 41be69ecc4
commit fdae5eaf8f
12 changed files with 20 additions and 21 deletions

View File

@ -1,12 +0,0 @@
import SbtCommons._
commons
libraryDependencies ++= Seq(
cats1,
scodecBits,
bouncyCastle,
scalatest,
circeCore,
circeParser
)

View File

@ -0,0 +1,5 @@
object Main {
def main(args: Array[String]): Unit = {
println("Hello world!")
}
}

View File

@ -17,8 +17,8 @@
package fluence.crypto.algorithm
import java.security.spec.{ PKCS8EncodedKeySpec, X509EncodedKeySpec }
import java.security._
import java.security.spec.{ PKCS8EncodedKeySpec, X509EncodedKeySpec }
import cats.MonadError
import cats.syntax.flatMap._
@ -88,7 +88,7 @@ class Ecdsa[F[_]](curveType: String, scheme: String)(implicit F: MonadError[F, T
signProvider.initSign(keyFactory.generatePrivate(keySpec))
signProvider.update(message)
signProvider.sign()
} ("Cannot sign message.")
}("Cannot sign message.")
}
} yield sign
}
@ -103,7 +103,7 @@ class Ecdsa[F[_]](curveType: String, scheme: String)(implicit F: MonadError[F, T
signProvider.initVerify(keyFactory.generatePublic(keySpec))
signProvider.update(message)
signProvider.verify(signature)
} ("Cannot verify message.")
}("Cannot verify message.")
}
} yield verify
}

View File

@ -26,7 +26,7 @@ import fluence.crypto.keypair.KeyPair
import org.scalatest.{ BeforeAndAfterAll, Matchers, WordSpec }
import scodec.bits.ByteVector
import scala.util.{ Random, Try }
import scala.util.Random
class SignatureSpec extends WordSpec with Matchers with BeforeAndAfterAll {

View File

@ -67,8 +67,7 @@ object KeyStore {
implicit val encodeKeyStorage: Encoder[KeyStore] = new Encoder[KeyStore] {
final def apply(ks: KeyStore): Json = Json.obj(("keystore", Json.obj(
("secret", Json.fromString(ks.keyPair.secretKey.value.toBase64)),
("public", Json.fromString(ks.keyPair.publicKey.value.toBase64))
)))
("public", Json.fromString(ks.keyPair.publicKey.value.toBase64)))))
}
implicit val decodeKeyStorage: Decoder[Option[KeyStore]] = new Decoder[Option[KeyStore]] {

View File

@ -21,6 +21,8 @@ import java.security.SecureRandom
import fluence.crypto.keypair.KeyPair
import scala.language.higherKinds
trait KeyGenerator[F[_]] {
def generateKeyPair(random: SecureRandom): F[KeyPair]
def generateKeyPair(): F[KeyPair]

View File

@ -19,7 +19,9 @@ package fluence.crypto.cipher
import cats.Monad
import cats.syntax.functor._
import scala.collection.Searching.{ Found, InsertionPoint, SearchResult }
import scala.language.implicitConversions
import scala.math.Ordering
/**

View File

@ -22,6 +22,8 @@ import java.nio.ByteBuffer
import cats.Applicative
import cats.syntax.applicative._
import scala.language.higherKinds
/**
* No operation implementation. Just convert the element to bytes back and forth without any cryptography.
*/
@ -41,8 +43,7 @@ object NoOpCrypt {
def forLong[F[_] : Applicative]: NoOpCrypt[F, Long] = apply[F, Long](
serializer = ByteBuffer.allocate(java.lang.Long.BYTES).putLong(_).array().pure[F],
deserializer = bytes ByteBuffer.wrap(bytes).getLong().pure[F]
)
deserializer = bytes ByteBuffer.wrap(bytes).getLong().pure[F])
def apply[F[_], T](serializer: T F[Array[Byte]], deserializer: Array[Byte] F[T]): NoOpCrypt[F, T] =
new NoOpCrypt(serializer, deserializer)

View File

@ -20,6 +20,8 @@ package fluence.crypto.signature
import cats.MonadError
import scodec.bits.ByteVector
import scala.language.higherKinds
trait SignatureChecker {
def check[F[_]](signature: Signature, plain: ByteVector)(implicit F: MonadError[F, Throwable]): F[Boolean]
}

View File

@ -17,8 +17,8 @@
package fluence.crypto
import fluence.crypto.cipher.NoOpCrypt
import cats.instances.try_._
import fluence.crypto.cipher.NoOpCrypt
import org.scalatest.{ Matchers, WordSpec }
import scala.collection.Searching.{ Found, InsertionPoint }