Fix hash for ed25119 (#12)

* no hasher for default ed25519

* support interop buffers
This commit is contained in:
Dima 2019-07-15 14:34:54 +03:00 committed by GitHub
parent 1502772f8e
commit 64f12eb609
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 5 deletions

View File

@ -14,7 +14,7 @@ val scalaV = scalaVersion := "2.12.8"
val commons = Seq(
scalaV,
version := "0.0.10",
version := "0.0.15",
fork in Test := true,
parallelExecution in Test := false,
organization := "one.fluence",

View File

@ -24,6 +24,6 @@ import scala.language.higherKinds
object CryptoJsHelpers {
implicit class ByteVectorOp(bv: ByteVector) {
def toJsBuffer: Buffer = Buffer.from(bv.toHex, "hex")
def toJsBuffer: Buffer = new Buffer(ByteVector(bv.toArray).toHex, "hex")
}
}

View File

@ -22,9 +22,8 @@ import cats.data.EitherT
import fluence.crypto.CryptoError.nonFatalHandling
import fluence.crypto.facade.ed25519.Supercop
import fluence.crypto.hash.JsCryptoHasher
import fluence.crypto.{Crypto, CryptoError, KeyPair, CryptoJsHelpers}
import fluence.crypto.{Crypto, CryptoError, CryptoJsHelpers, KeyPair}
import fluence.crypto.signature.{SignAlgo, Signature, SignatureChecker, Signer}
import io.scalajs.nodejs.buffer.Buffer
import scodec.bits.ByteVector
import scala.language.higherKinds
@ -38,7 +37,7 @@ class Ed25519(hasher: Option[Crypto.Hasher[Array[Byte], Array[Byte]]]) {
hash JsCryptoHasher.hash(message, hasher)
sign nonFatalHandling {
Supercop.sign(
Buffer.from(ByteVector(hash).toHex, "hex"),
ByteVector(hash).toJsBuffer,
keyPair.publicKey.value.toJsBuffer,
keyPair.secretKey.value.toJsBuffer
)

View File

@ -0,0 +1,27 @@
/*
* Copyright (C) 2017 Fluence Labs Limited
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fluence.crypto.facade
import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal
@js.native
@JSGlobal("Buffer")
class Buffer(arr: js.Array[Byte]) extends js.Object {
def toString(enc: String): String = js.native
}