-
Notifications
You must be signed in to change notification settings - Fork 48
Cross-compile to Scala.js #98
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
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
6eae6e7
scala-js: update dependencies
aslesarenko 74d88c4
scala-js: added scorex.utils.Bytes, Ints, Longs
aslesarenko a16ff85
scala-js: added scorex.utils.Shorts, UnsignedBytes.scala
aslesarenko c4c0805
scala-js: removed org.whispersystems dependency and Curve25519
aslesarenko 18736a6
scala-js: configure cross-platform sbt setup
aslesarenko b79798c
scala-js: update scorex-util dependency
aslesarenko 89add8a
scala-js: remove unused declarations
aslesarenko c99a931
scala-js: remove scala-logging dependence
aslesarenko 22b3dca
scala-js: move to JVM: Blake2b256Unsafe
aslesarenko 4fe303b
scala-js: move to JVM: Blake2b512Specification
aslesarenko 3b9ae72
scala-js: move to JVM: Blake2b512
aslesarenko 2676e4b
scala-js: move to JVM: KeccakSpecification
aslesarenko e127667
scala-js: move to JVM: Keccak
aslesarenko 054277f
scala-js: move to JVM: Whirlpool
aslesarenko 0fbb8a8
scala-js: move to JVM: Stribog
aslesarenko cd4e049
scala-js: move to JVM: Skein + Sha256Unsafe
aslesarenko 59eedd5
scala-js: move to JVM: CryptographicHash64 + ThreadUnsafeHash
aslesarenko 6fa1d57
scala-js: reimplement Blake2b256 via Platform.scala
aslesarenko 91b869f
scala-js: reimplement Sha256 via Platform.scala
aslesarenko 727c7a8
scala-js: configure benchmarks project
aslesarenko dcd9953
scala-js: enable JSPlatform
aslesarenko e4a8d3e
scala-js: make code and tests compile
aslesarenko b9f974e
scala-js: Platform implemented for JS
aslesarenko 546c402
scala-js: make all JS tests pass
aslesarenko dafca54
scala-js: setup ci.yml
aslesarenko 27fb071
scala-js: ScalaJsSpec.scala added
aslesarenko e49a312
scala-js: more tests for ScalaJsSpec
aslesarenko e96eb00
scala-js: add Scala 2.12 to JS tests and publishing
aslesarenko 95e9fa5
scala-js: replaced BouncycastleJs with @noble/hashes
aslesarenko a44a480
scala-js: release notes updated
aslesarenko b4526da
scala-js: ScalaDoc for BouncyCastleHash
aslesarenko 5150edf
scala-js: add npmDependencies
aslesarenko 8837261
scala-js: install npm CI action
aslesarenko cb2bee1
scala-js: fixes in release-notes.md
aslesarenko d54d1e1
scala-js: getting started guidelines in the Contributing section
aslesarenko 0c84965
scala-js: addressed review comments
aslesarenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,84 @@ | ||
package scorex.crypto.hash | ||
|
||
import typings.nobleHashes.blake2Mod.BlakeOpts | ||
import typings.nobleHashes.mod.blake2b | ||
import typings.nobleHashes.sha256Mod.sha256 | ||
import typings.nobleHashes.utilsMod | ||
|
||
import scala.scalajs.js.typedarray.Uint8Array | ||
|
||
/** JS platform specific implementation of methods. | ||
* When shared code is compiled to JS, this implementation is used. | ||
* | ||
* The JS implementation is based on type wrappers generated by ScalablyTyped for the | ||
* @noble/hashes library. (See configuration in build.sbt.) | ||
* | ||
* @see jvm/src/main/scala/scorex/crypto/hash/Platform.scala for JVM implementation | ||
*/ | ||
object Platform { | ||
|
||
/** Represents abstract digest from @noble. | ||
* See createBlake2bDigest, createSha256Digest methods. | ||
*/ | ||
type Digest = utilsMod.Hash[_] | ||
|
||
private def bytesToShorts(xs: Array[Byte]): Array[Short] = | ||
xs.map(x => (x & 0xFF).toShort) | ||
|
||
private def uint8ArrayToBytes(jsShorts: Uint8Array): Array[Byte] = { | ||
jsShorts.toArray[Short].map(x => x.toByte) | ||
} | ||
|
||
/** Creates an implementation of the cryptographic hash function Blakbe2b. | ||
* | ||
* @param bitSize the bit size of the digest | ||
* @return the digest implementation | ||
*/ | ||
def createBlake2bDigest(bitSize: Int): Digest = { | ||
val opts = BlakeOpts().setDkLen(bitSize / 8) | ||
blake2b.create(opts) | ||
} | ||
|
||
/** Creates an implementation of the cryptographic hash function SHA-256. | ||
* | ||
* @return the digest implementation | ||
*/ | ||
def createSha256Digest(): Digest = { | ||
sha256.create() | ||
} | ||
|
||
/** Update the message digest with a single byte. | ||
* | ||
* @param digest the digest to be updated | ||
* @param b the input byte to be entered. | ||
*/ | ||
def updateDigest(digest: Digest, b: Byte): Unit = { | ||
digest.update(Uint8Array.of((b & 0xFF).toShort)) | ||
kushti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** Update the message digest with a block of bytes. | ||
* | ||
* @param digest the digest to be updated | ||
* @param bytes the byte array containing the data. | ||
* @param inOff the offset into the byte array where the data starts. | ||
* @param inLen the length of the data. | ||
*/ | ||
def updateDigest(digest: Digest, | ||
bytes: Array[Byte], | ||
inOff: Int, | ||
inLen: Int): Unit = { | ||
val in = Uint8Array.of(bytesToShorts(bytes.slice(inOff, inOff + inLen)): _*) | ||
digest.update(in) | ||
} | ||
|
||
/** Close the digest, producing the final digest value. The doFinal | ||
* call leaves the digest reset. | ||
* A new array is created to store the result. | ||
* | ||
* @param digest the digest to be finalized | ||
*/ | ||
def doFinalDigest(digest: Digest): Array[Byte] = { | ||
val res = digest.digest() | ||
uint8ArrayToBytes(res) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.