Skip to content

Commit

Permalink
Merge pull request #943 from ScorexFoundation/v5.0.14-RC
Browse files Browse the repository at this point in the history
Release Candidate v5.0.14
  • Loading branch information
aslesarenko authored Apr 4, 2024
2 parents 6e19797 + 6196e90 commit 35c2a7f
Show file tree
Hide file tree
Showing 434 changed files with 13,946 additions and 11,500 deletions.
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ For development of Ergo applications using JVM languages (Java/Scala/Kotlin/etc)
a better alternative is to use
[Appkit](https://github.com/ergoplatform/ergo-appkit).

The library is cross-compiled to JS using Scala.js and the main abstractions can be used
from JS directly by importing [NPM module](https://www.npmjs.com/package/sigmastate-js).
See [README](sigma-js/README.md) for details.

## Sigma Language Background

Every coin in Bitcoin is protected by a program in the stack-based Script
Expand Down Expand Up @@ -93,19 +97,21 @@ This library is
on Maven repository and can be added to the SBT configuration of Scala project.

```scala
libraryDependencies += "org.scorexfoundation" %% "sigma-state" % "5.0.6"
libraryDependencies += "org.scorexfoundation" %% "sigma-state" % "5.0.14"
```

## Repository Organization

| sub-module | description |
|-------------|-------------------------------------------------------------------------------------------|
| common | Used in all other submodules and contain basic utility classes |
| core-lib | Contains core classes such as Coll, BigInt used by interpreter |
| docs | Collection of documents |
| graph-ir | Implementation of graph-based intermediate representation of ErgoTree, which is used in by ErgoScript compiler |
| interpreter | Implementation of ErgoTree Interpreter |
| sc | Implementation of ErgoScript compiler |
| sub-module | description |
|-------------|------------------------------------------------------------------------------------|
| core | contains core classes of Sigma library |
| data | contains classes for working with ErgoTree, addresses and all related serializers |
| docs | Collection of documents |
| interpreter | contains an implementation of ErgoTree Interpreter |
| sdk | contains and implementation of transaction reduction and signing |
| parsers | contains an implementation of ErgoScript parsers using FastParse library |
| sc | contains an implementation of ErgoScript compiler |
| sigma-js | root directory of sigmastate-js JS module (see [package.json](sigma-js/README.md)) |

## Contributing

Expand Down Expand Up @@ -151,12 +157,13 @@ innovative and intelligent tools for profiling Java and .NET applications.

- [Ergo Site](https://ergoplatform.org/en/)
- [Ergo Sources](https://github.com/ergoplatform/ergo)
- [Sigma-js](https://www.npmjs.com/package/sigmastate-js)
- [Ergo Appkit](https://github.com/ergoplatform/ergo-appkit)
- [Ergo Appkit Examples](https://github.com/aslesarenko/ergo-appkit-examples)
- [ergo-android](https://github.com/aslesarenko/ergo-android)
- [ergo-wallet-android](https://github.com/MrStahlfelge/ergo-wallet-android)
- [ErgoTree Specification](https://ergoplatform.org/docs/ErgoTree.pdf)
- [Ergo Documents](https://ergoplatform.org/en/documents/)
- [Ergo Documents](https://docs.ergoplatform.org/)



79 changes: 43 additions & 36 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,10 +217,40 @@ 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 data = crossProject(JVMPlatform, JSPlatform)
.in(file("data"))
.dependsOn(core % allConfigDependency)
.settings(
commonSettings ++ testSettings2,
commonDependenies2,
testingDependencies2,
scorexUtilDependency, fastparseDependency, circeDependency, scryptoDependency,
publish / skip := true
)
.jvmSettings( crossScalaSettings )
.jsSettings(
crossScalaSettingsJS,
useYarn := true
)
lazy val dataJS = data.js
.enablePlugins(ScalaJSBundlerPlugin)

lazy val interpreter = crossProject(JVMPlatform, JSPlatform)
.in(file("interpreter"))
.dependsOn(core % allConfigDependency)
.dependsOn(core % allConfigDependency, data % allConfigDependency)
.settings(
commonSettings ++ testSettings2,
commonDependenies2,
Expand All @@ -226,24 +261,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 +281,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,28 +289,23 @@ lazy val parsersJS = parsers.js
scalaJSLinkerConfig ~= { conf =>
conf.withSourceMap(false)
},
Compile / npmDependencies ++= Seq(
"sigmajs-crypto-facade" -> sigmajsCryptoFacadeVersion
)
)

lazy val sdk = crossProject(JVMPlatform, JSPlatform)
.in(file("sdk"))
.dependsOn(core % allConfigDependency, interpreter % allConfigDependency, parsers % allConfigDependency)
.dependsOn(core % allConfigDependency, data % allConfigDependency, interpreter % allConfigDependency, parsers % allConfigDependency)
.settings(commonSettings ++ testSettings2,
commonDependenies2,
testingDependencies2,
scodecBitsDependency,
circeDependency,
publish / skip := true
)
.jvmSettings(
crossScalaSettings
)
.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 +315,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,20 +358,17 @@ lazy val scJS = sc.js
.withArrayIndexOutOfBounds(CheckedBehavior.Compliant)
)
},
Compile / npmDependencies ++= Seq(
"sigmajs-crypto-facade" -> sigmajsCryptoFacadeVersion
)
)


lazy val sigma = (project in file("."))
.aggregate(core.jvm, interpreter.jvm, parsers.jvm, sdk.jvm, sc.jvm)
.aggregate(core.jvm, data.jvm, interpreter.jvm, parsers.jvm, sdk.jvm, sc.jvm)
.settings(libraryDefSettings, rootSettings)
.settings(publish / aggregate := false)
.settings(publishLocal / aggregate := false)

lazy val aggregateCompile = ScopeFilter(
inProjects(core.jvm, interpreter.jvm, parsers.jvm, sdk.jvm, sc.jvm),
inProjects(core.jvm, data.jvm, interpreter.jvm, parsers.jvm, sdk.jvm, sc.jvm),
inConfigurations(Compile))

lazy val rootSettings = Seq(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package sigmastate.crypto
package sigma.crypto

import sigma.data.RType
import scorex.util.encode.Base16
import sigmastate._
import sigma.Coll
import sigma._
import sigma.ast._

import java.math.BigInteger
import scala.scalajs.js
Expand Down Expand Up @@ -128,7 +128,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 @@ -184,28 +184,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 All @@ -17,7 +17,7 @@ class GroupElement(val point: Ecp) extends js.Object {
}
}

@JSExportTopLevel("GroupElementObj")
@JSExportTopLevel("GroupElement$")
object GroupElement extends js.Object {
/** Creates a new [[GroupElement]] from the given hex string (ASN.1 encoding)
* representation of the underlying [[sigmastate.crypto.Platform.Point]].
Expand Down
Loading

0 comments on commit 35c2a7f

Please sign in to comment.