Skip to content

Fix dom.crypto.getRandomValues #669

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 7 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion api-reports/2_12.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25514,7 +25514,7 @@ crypto/package[SO] @deprecated("use dom.RsaKeyGenParams instead", "2.0.0") val R
crypto/package[SO] @deprecated("use dom.RsaOaepParams instead", "2.0.0") val RsaOaepParams = dom.RsaOaepParams
crypto/package[SO] @deprecated("use dom.RsaPssParams instead", "2.0.0") val RsaPssParams = dom.RsaPssParams
crypto/package[SO] def crypto: Crypto (@deprecated in 2.0.0)
crypto/package[SO] @JSGlobal("crypto.getRandomValues") @js.native def getRandomValues(array: ArrayBufferView): ArrayBufferView
crypto/package[SO] def getRandomValues(array: ArrayBufferView)(implicit dummy: DummyImplicit): ArrayBufferView
crypto/package[SO] @JSGlobal("crypto.subtle") @js.native val subtle: dom.SubtleCrypto
experimental/Fullscreen[SO] (@deprecated in 2.0.0)
experimental/PointerLock[SO] type PointerLockDocument = dom.Document (@deprecated in 2.0.0)
Expand Down
2 changes: 1 addition & 1 deletion api-reports/2_13.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25514,7 +25514,7 @@ crypto/package[SO] @deprecated("use dom.RsaKeyGenParams instead", "2.0.0") val R
crypto/package[SO] @deprecated("use dom.RsaOaepParams instead", "2.0.0") val RsaOaepParams = dom.RsaOaepParams
crypto/package[SO] @deprecated("use dom.RsaPssParams instead", "2.0.0") val RsaPssParams = dom.RsaPssParams
crypto/package[SO] def crypto: Crypto (@deprecated in 2.0.0)
crypto/package[SO] @JSGlobal("crypto.getRandomValues") @js.native def getRandomValues(array: ArrayBufferView): ArrayBufferView
crypto/package[SO] def getRandomValues(array: ArrayBufferView)(implicit dummy: DummyImplicit): ArrayBufferView
crypto/package[SO] @JSGlobal("crypto.subtle") @js.native val subtle: dom.SubtleCrypto
experimental/Fullscreen[SO] (@deprecated in 2.0.0)
experimental/PointerLock[SO] type PointerLockDocument = dom.Document (@deprecated in 2.0.0)
Expand Down
8 changes: 6 additions & 2 deletions dom/src/main/scala/org/scalajs/dom/crypto/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ package object crypto {
@js.native
val subtle: dom.SubtleCrypto = js.native

/** Fills the passed TypedArray with cryptographically sound random values. */
// for binary compat; unusable
@JSGlobal("crypto.getRandomValues")
@js.native
def getRandomValues(array: ArrayBufferView): ArrayBufferView = js.native
protected[crypto] def getRandomValues(array: ArrayBufferView): ArrayBufferView = js.native

/** Fills the passed TypedArray with cryptographically sound random values. */
@inline def getRandomValues(array: ArrayBufferView)(implicit dummy: DummyImplicit): ArrayBufferView =
webcrypto.getRandomValues(array)

@deprecated("use dom.crypto instead", "2.0.0")
@inline def crypto: Crypto = GlobalCrypto.crypto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import scala.scalajs.js.typedarray._

trait WebCryptoApiTests {

// https://github.com/scala-js/scala-js-dom/issues/668
@Test final def cryptoGetRandomValues(): Unit =
dom.crypto.getRandomValues(new Uint8Array(1))

@Test final def getRandomValuesWork: Unit = {
dom.webcrypto.getRandomValues(Array.ofDim[Byte](8).toTypedArray)
}
Expand Down