All Downloads are FREE. Search and download functionalities are using the official Maven repository.

encrywm.lib.predef.functions.hash.Blake2b256Hash.scala Maven / Gradle / Ivy

There is a newer version: 0.3.2
Show newest version
package encrywm.lib.predef.functions.hash

import encrywm.backend.env.{ESBuiltInFunc, ESValue}
import encrywm.backend.executor.error.BuiltInFunctionExecError
import encrywm.lib.Types.ESByteVector
import encrywm.lib.predef.functions.BuiltInFunctionHolder
import scorex.crypto.hash.Blake2b256

object Blake2b256Hash extends BuiltInFunctionHolder {

  val name: String = "blake2b256hash"

  override def asFunc: ESBuiltInFunc = ESBuiltInFunc(name, args, body)

  val args = IndexedSeq("input" -> ESByteVector)

  private val body = (args: Seq[(String, ESValue)]) => {
    val validNumberOfArgs = args.size == 1
    val validArgTypes = args.forall { case (_, v) => v.tpe.isInstanceOf[ESByteVector.type] }
    if (validNumberOfArgs && validArgTypes) {
      val fnArgs = args.map(_._2.value.asInstanceOf[Array[Byte]])
      Right(Blake2b256.hash(fnArgs.head))
    } else {
      Left(BuiltInFunctionExecError)
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy