-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
428 changed files
with
13,928 additions
and
11,431 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...gmastate/crypto/SigmaJsCryptoFacade.scala → ...la/sigma/crypto/SigmaJsCryptoFacade.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package sigmastate.crypto | ||
package sigma.crypto | ||
|
||
import debox.cfor | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package sigma.js | ||
|
||
import sigma.{Coll, Colls} | ||
import sigma.data.{CBigInt, Iso, RType} | ||
|
||
import java.math.BigInteger | ||
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): _*) | ||
} | ||
|
||
implicit val isoBigInt: Iso[js.BigInt, sigma.BigInt] = new Iso[js.BigInt, sigma.BigInt] { | ||
override def to(x: js.BigInt): sigma.BigInt = { | ||
CBigInt(new BigInteger(x.toString(10))) | ||
} | ||
|
||
override def from(x: sigma.BigInt): js.BigInt = { | ||
val bi = x.asInstanceOf[CBigInt].wrappedValue | ||
val s = bi.toString(10) | ||
js.BigInt(s) | ||
} | ||
} | ||
|
||
implicit val isoBigIntToLong: Iso[js.BigInt, Long] = new Iso[js.BigInt, Long] { | ||
override def to(x: js.BigInt): Long = java.lang.Long.parseLong(x.toString(10)) | ||
|
||
override def from(x: Long): js.BigInt = js.BigInt(x.toString) | ||
} | ||
} |
Oops, something went wrong.