Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move TypeSerializer and DataSerializer to core module (part 2) #917

Merged
merged 39 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e629124
sigma-ast: TypeSerializer code moved to CoreTypeSerializer
aslesarenko Sep 8, 2023
142fcc8
sigma-ast: TypeSerializer code moved to CoreTypeSerializer (fix compi…
aslesarenko Sep 9, 2023
01190bb
sigma-ast: AvlTreeData moved to core
aslesarenko Sep 10, 2023
f5d01ff
sigma-ast: everything compiles
aslesarenko Sep 10, 2023
e162665
sigma-ast: CryptoContext moved to core
aslesarenko Sep 10, 2023
a22282d
sigma-ast: GroupElementSerializer moved to core
aslesarenko Sep 10, 2023
02f6ad2
Merge remote-tracking branch 'origin/sigma-ast' into core-serializers
aslesarenko Sep 10, 2023
0e45513
sigma-ast: fix after merge
aslesarenko Sep 10, 2023
1a86c84
sigma-ast: fix Reflection for SigmaCompiler
aslesarenko Sep 10, 2023
c6585e1
Merge remote-tracking branch 'origin/sigma-ast' into core-serializers
aslesarenko Sep 11, 2023
61f2bda
core-serializers: CGroupElement moved to core
aslesarenko Sep 11, 2023
0c7e09a
core-serializers: fix compilation Scala 2.11
aslesarenko Sep 11, 2023
198e028
core-serializers: removed toBits unfinished method
aslesarenko Sep 11, 2023
5b07d30
core-serializers: removed all xxxQ methods from BigInt
aslesarenko Sep 11, 2023
637ecff
core-serializers: introduced SPCodes
aslesarenko Sep 11, 2023
d12e488
core-serializers: SigmaBoolean moved to a separate file
aslesarenko Sep 11, 2023
e16540d
core-serializers: SigmaBoolean became sealed
aslesarenko Sep 11, 2023
728895b
core-serializers: SigmaBoolean moved to core
aslesarenko Sep 11, 2023
c8de983
core-serializers: CSigmaProp moved to core
aslesarenko Sep 11, 2023
44d2463
core-serializers: CSigmaProp.propBytes implemented without ErgoTree
aslesarenko Sep 12, 2023
2d00c56
core-serializers: toColl extension method moved to core
aslesarenko Sep 12, 2023
d9b6b23
core-serializers: CAvlTree moved to core
aslesarenko Sep 13, 2023
dd91fa3
core-serializers: CoreDataSerializer introduced
aslesarenko Sep 13, 2023
c973adb
core-serializers: js.Type moved to core.js
aslesarenko Sep 13, 2023
4912a3c
Merge remote-tracking branch 'origin/sigma-ast' into core-serializers
aslesarenko Sep 13, 2023
5695687
core-serializers: fixes after merge
aslesarenko Sep 13, 2023
4fcd2a7
core-serializers: Value moved to core.js
aslesarenko Sep 13, 2023
feebe24
core-serializers2: renamed CostingBox -> CBox
aslesarenko Sep 20, 2023
d503dbe
core-serializers2: renamed CostingSigmaDslBuilder -> CSigmaDslBuilder
aslesarenko Sep 20, 2023
094beeb
core-serializers2: renamed CostingDataContext -> CContext
aslesarenko Sep 20, 2023
3f85433
core-serializers2: moved CAnyValue to core
aslesarenko Sep 20, 2023
2ddc80d
core-serializers2: moved Digest32Coll to core
aslesarenko Sep 20, 2023
42541ac
core-serializers2: ErgoTree moved out of Values object
aslesarenko Sep 20, 2023
731409f
core-serializers2: fix Scala 2.11 compilation
aslesarenko Sep 20, 2023
9cdcbde
Merge remote-tracking branch 'origin/ergotree-version' into core-seri…
aslesarenko Oct 4, 2023
a8ba147
core-serializers: fixes after merge
aslesarenko Oct 4, 2023
9617c12
Merge remote-tracking branch 'origin/core-serializers' into core-seri…
aslesarenko Oct 4, 2023
69a9148
core-serializers2: fixes after merge
aslesarenko Oct 4, 2023
dc23717
core-serializers2: cleanup code
aslesarenko Oct 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 20 additions & 32 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import scala.language.postfixOps
import scala.sys.process._
import org.scalajs.linker.interface.CheckedBehavior
import scala.sys.process.*
import org.scalajs.linker.interface.{CheckedBehavior, ModuleSplitStyle}

organization := "org.scorexfoundation"

Expand Down Expand Up @@ -196,7 +196,12 @@ lazy val core = crossProject(JVMPlatform, JSPlatform)
scorexUtilDependency,
publish / skip := true
)
.jvmSettings( crossScalaSettings )
.jvmSettings(
crossScalaSettings,
libraryDependencies ++= Seq(
bouncycastleBcprov
)
)
.jsSettings(
crossScalaSettingsJS,
scalacOptions ++= Seq(
Expand All @@ -212,6 +217,18 @@ lazy val core = crossProject(JVMPlatform, JSPlatform)
)
lazy val coreJS = core.js
.enablePlugins(ScalaJSBundlerPlugin)
.enablePlugins(ScalablyTypedConverterGenSourcePlugin)
.settings(
stOutputPackage := "sigmastate",
scalaJSLinkerConfig ~= { conf =>
conf.withSourceMap(false)
.withModuleKind(ModuleKind.CommonJSModule)
},
Compile / npmDependencies ++= Seq(
"sigmajs-crypto-facade" -> sigmajsCryptoFacadeVersion,
"@fleet-sdk/common" -> "0.1.3"
)
)

lazy val interpreter = crossProject(JVMPlatform, JSPlatform)
.in(file("interpreter"))
Expand All @@ -226,24 +243,10 @@ lazy val interpreter = crossProject(JVMPlatform, JSPlatform)
.jvmSettings( crossScalaSettings )
.jsSettings(
crossScalaSettingsJS,
libraryDependencies ++= Seq (
"org.scala-js" %%% "scala-js-macrotask-executor" % "1.0.0"
),
useYarn := true
)
lazy val interpreterJS = interpreter.js
.enablePlugins(ScalaJSBundlerPlugin)
.enablePlugins(ScalablyTypedConverterGenSourcePlugin)
.settings(
stOutputPackage := "sigmastate",
scalaJSLinkerConfig ~= { conf =>
conf.withSourceMap(false)
},
Compile / npmDependencies ++= Seq(
"sigmajs-crypto-facade" -> sigmajsCryptoFacadeVersion,
"@fleet-sdk/common" -> "0.1.3"
)
)

lazy val parsers = crossProject(JVMPlatform, JSPlatform)
.in(file("parsers"))
Expand All @@ -260,9 +263,6 @@ lazy val parsers = crossProject(JVMPlatform, JSPlatform)
)
.jsSettings(
crossScalaSettingsJS,
libraryDependencies ++= Seq(
"org.scala-js" %%% "scala-js-macrotask-executor" % "1.0.0"
),
useYarn := true
)
lazy val parsersJS = parsers.js
Expand All @@ -271,9 +271,6 @@ lazy val parsersJS = parsers.js
scalaJSLinkerConfig ~= { conf =>
conf.withSourceMap(false)
},
Compile / npmDependencies ++= Seq(
"sigmajs-crypto-facade" -> sigmajsCryptoFacadeVersion
)
)

lazy val sdk = crossProject(JVMPlatform, JSPlatform)
Expand All @@ -290,9 +287,6 @@ lazy val sdk = crossProject(JVMPlatform, JSPlatform)
)
.jsSettings(
crossScalaSettingsJS,
libraryDependencies ++= Seq(
"org.scala-js" %%% "scala-js-macrotask-executor" % "1.0.0"
),
useYarn := true
)
lazy val sdkJS = sdk.js
Expand All @@ -302,9 +296,6 @@ lazy val sdkJS = sdk.js
conf.withSourceMap(false)
.withModuleKind(ModuleKind.CommonJSModule)
},
Compile / npmDependencies ++= Seq(
"sigmajs-crypto-facade" -> sigmajsCryptoFacadeVersion
)
)

lazy val sc = crossProject(JVMPlatform, JSPlatform)
Expand Down Expand Up @@ -348,9 +339,6 @@ lazy val scJS = sc.js
.withArrayIndexOutOfBounds(CheckedBehavior.Compliant)
)
},
Compile / npmDependencies ++= Seq(
"sigmajs-crypto-facade" -> sigmajsCryptoFacadeVersion
)
)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sigmastate.crypto
package sigma.crypto

import sigma.data.RType
import scorex.util.encode.Base16
Expand Down Expand Up @@ -129,7 +129,7 @@ object Platform {
class Curve

// TODO JS: Use JS library for secure source of randomness
type SecureRandom = sigmastate.crypto.SecureRandomJS
type SecureRandom = sigma.crypto.SecureRandomJS

/** Opaque point type. */
@js.native
Expand Down Expand Up @@ -185,28 +185,28 @@ object Platform {
private val ctx = new CryptoContextJs

/** The underlying elliptic curve descriptor. */
override def curve: crypto.Curve = ???
override def curve: Curve = ???

override def fieldCharacteristic: BigInteger = Convert.bigIntToBigInteger(ctx.getModulus())

override def order: BigInteger = Convert.bigIntToBigInteger(ctx.getOrder())

override def validatePoint(x: BigInteger, y: BigInteger): crypto.Ecp = {
override def validatePoint(x: BigInteger, y: BigInteger): Ecp = {
val point = ctx.validatePoint(Convert.bigIntegerToBigInt(x), Convert.bigIntegerToBigInt(y))
new Ecp(point)
}

override def infinity(): crypto.Ecp =
override def infinity(): Ecp =
new Ecp(ctx.getInfinity())

override def decodePoint(encoded: Array[Byte]): crypto.Ecp = {
override def decodePoint(encoded: Array[Byte]): Ecp = {
if (encoded(0) == 0) {
return infinity()
}
new Ecp(ctx.decodePoint(Base16.encode(encoded)))
}

override def generator: crypto.Ecp =
override def generator: Ecp =
new Ecp(ctx.getGenerator())
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sigmastate.crypto
package sigma.crypto

import debox.cfor

Expand Down
50 changes: 50 additions & 0 deletions core/js/src/main/scala/sigma/js/AvlTree.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package sigma.js

import sigma.Extensions.ArrayOps
import sigma.data.Iso.{isoStringToArray, isoStringToColl}
import sigma.data.{AvlTreeData, AvlTreeFlags, CAvlTree, Iso}

import scala.scalajs.js
import scala.scalajs.js.UndefOr
import scala.scalajs.js.annotation.JSExportTopLevel

/** Equivalent of [[sigma.AvlTree]] available from JS. */
@JSExportTopLevel("AvlTree")
class AvlTree(
val digest: String,
val insertAllowed: Boolean,
val updateAllowed: Boolean,
val removeAllowed: Boolean,
val keyLength: Int,
val valueLengthOpt: UndefOr[Int]
) extends js.Object

object AvlTree {

implicit val isoAvlTree: Iso[AvlTree, sigma.AvlTree] = new Iso[AvlTree, sigma.AvlTree] {
override def to(x: AvlTree): sigma.AvlTree = {
CAvlTree(
AvlTreeData(
digest = isoStringToArray.to(x.digest).toColl,
treeFlags = AvlTreeFlags(x.insertAllowed, x.updateAllowed, x.removeAllowed),
x.keyLength,
valueLengthOpt = sigma.js.Isos.isoUndefOr(Iso.identityIso[Int]).to(x.valueLengthOpt),
),
)
}

override def from(x: sigma.AvlTree): AvlTree = {
val tree = x.asInstanceOf[CAvlTree]
val data = tree.treeData
new AvlTree(
digest = isoStringToColl.from(tree.digest),
insertAllowed = data.treeFlags.insertAllowed,
updateAllowed = data.treeFlags.updateAllowed,
removeAllowed = data.treeFlags.removeAllowed,
keyLength = data.keyLength,
valueLengthOpt = sigma.js.Isos.isoUndefOr(Iso.identityIso[Int]).from(data.valueLengthOpt),
)
}
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.ergoplatform.sdk.js
package sigma.js

import sigmastate.crypto.{CryptoFacade, CryptoFacadeJs, Ecp, Platform}
import sigmastate.eval.Extensions.ArrayByteOps
import sigma.Extensions.CoreArrayByteOps
import sigma.crypto.{CryptoFacade, CryptoFacadeJs, Ecp, Platform}

import scala.scalajs.js
import scala.scalajs.js.annotation.JSExportTopLevel
Expand Down
29 changes: 29 additions & 0 deletions core/js/src/main/scala/sigma/js/Isos.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package sigma.js

import sigma.{Coll, Colls}
import sigma.data.{Iso, RType}

import scala.reflect.ClassTag
import scala.scalajs.js
import scala.scalajs.js.JSConverters.JSRichOption

object Isos {

implicit def isoUndefOr[A, B](implicit iso: Iso[A, B]): Iso[js.UndefOr[A], Option[B]] = new Iso[js.UndefOr[A], Option[B]] {
override def to(x: js.UndefOr[A]): Option[B] = x.toOption.map(iso.to)
override def from(x: Option[B]): js.UndefOr[A] = x.map(iso.from).orUndefined
}

implicit def isoArrayToColl[A, B](iso: Iso[A, B])
(implicit ctA: ClassTag[A], tB: RType[B]): Iso[js.Array[A], Coll[B]] = new Iso[js.Array[A], Coll[B]] {
override def to(x: js.Array[A]): Coll[B] = Colls.fromArray(x.map(iso.to).toArray(tB.classTag))
override def from(x: Coll[B]): js.Array[A] = js.Array(x.toArray.map(iso.from): _*)
}

implicit def isoArrayToIndexed[A, B](iso: Iso[A, B])
(implicit cB: ClassTag[B]): Iso[js.Array[A], IndexedSeq[B]] = new Iso[js.Array[A], IndexedSeq[B]] {
override def to(x: js.Array[A]): IndexedSeq[B] = x.map(iso.to).toArray(cB).toIndexedSeq
override def from(x: IndexedSeq[B]): js.Array[A] = js.Array(x.map(iso.from): _*)
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.ergoplatform.sdk.js
package sigma.js

import sigmastate.Values.SigmaBoolean
import sigmastate.crypto.DLogProtocol.ProveDlog
import sigma.data.{ProveDlog, SigmaBoolean}

import scala.scalajs.js
import scala.scalajs.js.annotation.JSExportTopLevel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.ergoplatform.sdk.js
package sigma.js

import sigma.data.RType

Expand All @@ -10,7 +10,7 @@ import scala.scalajs.js.annotation.JSExportTopLevel
* wrapper around {@link RType} type descriptor.
*/
@JSExportTopLevel("Type")
class Type(private[js] final val rtype: RType[_]) extends js.Object {
class Type(final val rtype: RType[_]) extends js.Object {
/** Syntactically correct type name (type expression as String) */
def name: String = rtype.name

Expand Down
Loading
Loading