From e7a5f0d4e023e872125ef95673cbec6e0a8135f6 Mon Sep 17 00:00:00 2001 From: Matthew Nelson Date: Mon, 18 Mar 2024 15:45:14 -0400 Subject: [PATCH] Add experimental support for `wasmJs` & `wasmWasi` (#58) --- .kotlin-js-store/yarn.lock | 18 +-- README.md | 8 +- .../main/kotlin/-KmpConfigurationExtension.kt | 26 +++- build.gradle.kts | 52 ++----- gradle/libs.versions.toml | 18 ++- gradle/wrapper/gradle-wrapper.properties | 4 +- .../org/kotlincrypto/hash/sha2/SHA512t.kt | 136 +++++++++--------- 7 files changed, 131 insertions(+), 131 deletions(-) diff --git a/.kotlin-js-store/yarn.lock b/.kotlin-js-store/yarn.lock index 510dcd5..b7cef21 100644 --- a/.kotlin-js-store/yarn.lock +++ b/.kotlin-js-store/yarn.lock @@ -38,9 +38,9 @@ balanced-match@^1.0.0: integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== binary-extensions@^2.0.0: - version "2.2.0" - resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" - integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA== + version "2.3.0" + resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.3.0.tgz#f6e14a97858d327252200242d4ccfe522c445522" + integrity sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw== brace-expansion@^1.1.7: version "1.1.11" @@ -151,9 +151,9 @@ emoji-regex@^8.0.0: integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== escalade@^3.1.1: - version "3.1.1" - resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40" - integrity sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw== + version "3.1.2" + resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.2.tgz#54076e9ab29ea5bf3d8f1ed62acffbb88272df27" + integrity sha512-ErCHMCae19vR8vQGe50xIsVomy19rg6gFu3+r3jkEO46suLMWBksvVyoGgQV+jOfl84ZSOSlmv6Gxa89PmTGmA== escape-string-regexp@4.0.0: version "4.0.0" @@ -191,9 +191,9 @@ fs.realpath@^1.0.0: integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== fsevents@~2.3.2: - version "2.3.2" - resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a" - integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== + version "2.3.3" + resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6" + integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw== get-caller-file@^2.0.5: version "2.0.5" diff --git a/README.md b/README.md index 1eab20f..1b70a0c 100644 --- a/README.md +++ b/README.md @@ -146,10 +146,10 @@ dependencies { [badge-license]: https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat -[badge-kotlin]: https://img.shields.io/badge/kotlin-1.9.21-blue.svg?logo=kotlin -[badge-core]: https://img.shields.io/badge/kotlincrypto.core-0.4.0-blue.svg -[badge-endians]: https://img.shields.io/badge/kotlincrypto.endians-0.2.0-blue.svg -[badge-sponges]: https://img.shields.io/badge/kotlincrypto.sponges-0.2.0-blue.svg +[badge-kotlin]: https://img.shields.io/badge/kotlin-1.9.23-blue.svg?logo=kotlin +[badge-core]: https://img.shields.io/badge/kotlincrypto.core-0.5.0-blue.svg +[badge-endians]: https://img.shields.io/badge/kotlincrypto.endians-0.3.0-blue.svg +[badge-sponges]: https://img.shields.io/badge/kotlincrypto.sponges-0.3.0-blue.svg [badge-platform-android]: http://img.shields.io/badge/-android-6EDB8D.svg?style=flat diff --git a/build-logic/src/main/kotlin/-KmpConfigurationExtension.kt b/build-logic/src/main/kotlin/-KmpConfigurationExtension.kt index 5c63108..3dd646e 100644 --- a/build-logic/src/main/kotlin/-KmpConfigurationExtension.kt +++ b/build-logic/src/main/kotlin/-KmpConfigurationExtension.kt @@ -17,6 +17,7 @@ import io.matthewnelson.kmp.configuration.extension.KmpConfigurationExtension import io.matthewnelson.kmp.configuration.extension.container.target.KmpConfigurationContainerDsl import org.gradle.api.Action import org.gradle.api.JavaVersion +import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl fun KmpConfigurationExtension.configureShared( publish: Boolean = false, @@ -33,8 +34,29 @@ fun KmpConfigurationExtension.configureShared( } js() -// wasmJs {} -// wasmWasi {} + + @OptIn(ExperimentalWasmDsl::class) + wasmJs { + target { + browser { + testTask { + useMocha { timeout = "30s" } + } + } + nodejs { + testTask { + useMocha { timeout = "30s" } + } + } + } + } + + @OptIn(ExperimentalWasmDsl::class) + wasmWasi { + target { + nodejs() + } + } androidNativeAll() diff --git a/build.gradle.kts b/build.gradle.kts index 1a795d3..e621815 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,7 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask +import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension +import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin +import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension @@ -21,7 +23,6 @@ plugins { alias(libs.plugins.multiplatform) apply(false) alias(libs.plugins.android.library) apply(false) alias(libs.plugins.binaryCompat) - alias(libs.plugins.gradleVersions) } allprojects { @@ -47,11 +48,19 @@ plugins.withType { the().lockFileDirectory = rootDir.resolve(".kotlin-js-store") } -apiValidation { - @Suppress("LocalVariableName") - val CHECK_PUBLICATION = findProperty("CHECK_PUBLICATION") as? String +plugins.withType { + the().apply { + nodeVersion = "21.0.0-v8-canary202309167e82ab1fa2" + nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary" + } + + tasks.withType().configureEach { + args.add("--ignore-engines") + } +} - if (CHECK_PUBLICATION != null) { +apiValidation { + if (findProperty("CHECK_PUBLICATION") != null) { ignoredProjects.add("check-publication") } else { nonPublicMarkers.add("org.kotlincrypto.core.InternalKotlinCryptoApi") @@ -59,34 +68,3 @@ apiValidation { ignoredProjects.add("testing") } } - -fun isNonStable(version: String): Boolean { - val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) } - val regex = "^[0-9,.v-]+(-r)?$".toRegex() - val isStable = stableKeyword || regex.matches(version) - return isStable.not() -} - -tasks.withType { - // Example 1: reject all non stable versions - rejectVersionIf { - isNonStable(candidate.version) - } - - // Example 2: disallow release candidates as upgradable versions from stable versions - rejectVersionIf { - isNonStable(candidate.version) && !isNonStable(currentVersion) - } - - // Example 3: using the full syntax - resolutionStrategy { - componentSelection { - @Suppress("RedundantSamConstructor") - all(Action { - if (isNonStable(candidate.version) && !isNonStable(currentVersion)) { - reject("Release candidate") - } - }) - } - } -} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1e333ae..98c3b85 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,16 +1,15 @@ [versions] android = "8.1.4" androidxTestRunner = "1.5.2" -binaryCompat = "0.13.2" +binaryCompat = "0.14.0" bouncyCastle = "1.73" -configuration = "0.1.5" -cryptoCore = "0.4.0" -encoding = "2.1.0" -endians = "0.2.0" -gradleVersions = "0.50.0" -kotlin = "1.9.21" -publish = "0.25.3" -sponges = "0.2.0" +configuration = "0.2.1" +cryptoCore = "0.5.0" +encoding = "2.2.1" +endians = "0.3.0" +kotlin = "1.9.23" +publish = "0.27.0" +sponges = "0.3.0" [libraries] kotlincrypto-core-digest = { module = "org.kotlincrypto.core:digest", version.ref = "cryptoCore" } @@ -31,4 +30,3 @@ encoding-base64 = { module = "io.matthewnelson.encoding:base64", version.ref = " android-library = { id = "com.android.library", version.ref = "android" } binaryCompat = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "binaryCompat" } multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } -gradleVersions = { id = "com.github.ben-manes.versions", version.ref = "gradleVersions" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a2b81f7..6357ddc 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -4,5 +4,5 @@ zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME # https://gradle.org/release-checksums/ -distributionSha256Sum=f2b9ed0faf8472cbe469255ae6c86eddb77076c75191741b4a462f33128dd419 -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip +distributionSha256Sum=85719317abd2112f021d4f41f09ec370534ba288432065f4b477b6a3b652910d +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip diff --git a/library/sha2/src/commonMain/kotlin/org/kotlincrypto/hash/sha2/SHA512t.kt b/library/sha2/src/commonMain/kotlin/org/kotlincrypto/hash/sha2/SHA512t.kt index ed9e399..e97fdc2 100644 --- a/library/sha2/src/commonMain/kotlin/org/kotlincrypto/hash/sha2/SHA512t.kt +++ b/library/sha2/src/commonMain/kotlin/org/kotlincrypto/hash/sha2/SHA512t.kt @@ -112,76 +112,78 @@ public class SHA512t: Bit64Digest { } val out = ByteArray(digestLength()) + var i = 0 - try { - out[ 0] = (a shr 56).toByte() - out[ 1] = (a shr 48).toByte() - out[ 2] = (a shr 40).toByte() - out[ 3] = (a shr 32).toByte() - out[ 4] = (a shr 24).toByte() - out[ 5] = (a shr 16).toByte() - out[ 6] = (a shr 8).toByte() - out[ 7] = (a ).toByte() - out[ 8] = (b shr 56).toByte() - out[ 9] = (b shr 48).toByte() - out[10] = (b shr 40).toByte() - out[11] = (b shr 32).toByte() - out[12] = (b shr 24).toByte() - out[13] = (b shr 16).toByte() - out[14] = (b shr 8).toByte() - out[15] = (b ).toByte() - out[16] = (c shr 56).toByte() - out[17] = (c shr 48).toByte() - out[18] = (c shr 40).toByte() - out[19] = (c shr 32).toByte() - out[20] = (c shr 24).toByte() - out[21] = (c shr 16).toByte() - out[22] = (c shr 8).toByte() - out[23] = (c ).toByte() - out[24] = (d shr 56).toByte() - out[25] = (d shr 48).toByte() - out[26] = (d shr 40).toByte() - out[27] = (d shr 32).toByte() - out[28] = (d shr 24).toByte() - out[29] = (d shr 16).toByte() - out[30] = (d shr 8).toByte() - out[31] = (d ).toByte() - out[32] = (e shr 56).toByte() - out[33] = (e shr 48).toByte() - out[34] = (e shr 40).toByte() - out[35] = (e shr 32).toByte() - out[36] = (e shr 24).toByte() - out[37] = (e shr 16).toByte() - out[38] = (e shr 8).toByte() - out[39] = (e ).toByte() - out[40] = (f shr 56).toByte() - out[41] = (f shr 48).toByte() - out[42] = (f shr 40).toByte() - out[43] = (f shr 32).toByte() - out[44] = (f shr 24).toByte() - out[45] = (f shr 16).toByte() - out[46] = (f shr 8).toByte() - out[47] = (f ).toByte() - out[48] = (g shr 56).toByte() - out[49] = (g shr 48).toByte() - out[50] = (g shr 40).toByte() - out[51] = (g shr 32).toByte() - out[52] = (g shr 24).toByte() - out[53] = (g shr 16).toByte() - out[54] = (g shr 8).toByte() - out[55] = (g ).toByte() - out[56] = (h shr 56).toByte() - out[57] = (h shr 48).toByte() - out[58] = (h shr 40).toByte() - out[59] = (h shr 32).toByte() - out[60] = (h shr 24).toByte() - out[61] = (h shr 16).toByte() - out[62] = (h shr 8).toByte() - out[63] = (h ).toByte() - } catch (_: IndexOutOfBoundsException) { - // ignore + fun Long.putOut() { + if (i == out.size) return + out[i++] = toByte() } + (a shr 56).putOut() + (a shr 48).putOut() + (a shr 40).putOut() + (a shr 32).putOut() + (a shr 24).putOut() + (a shr 16).putOut() + (a shr 8).putOut() + (a ).putOut() + (b shr 56).putOut() + (b shr 48).putOut() + (b shr 40).putOut() + (b shr 32).putOut() + (b shr 24).putOut() + (b shr 16).putOut() + (b shr 8).putOut() + (b ).putOut() + (c shr 56).putOut() + (c shr 48).putOut() + (c shr 40).putOut() + (c shr 32).putOut() + (c shr 24).putOut() + (c shr 16).putOut() + (c shr 8).putOut() + (c ).putOut() + (d shr 56).putOut() + (d shr 48).putOut() + (d shr 40).putOut() + (d shr 32).putOut() + (d shr 24).putOut() + (d shr 16).putOut() + (d shr 8).putOut() + (d ).putOut() + (e shr 56).putOut() + (e shr 48).putOut() + (e shr 40).putOut() + (e shr 32).putOut() + (e shr 24).putOut() + (e shr 16).putOut() + (e shr 8).putOut() + (e ).putOut() + (f shr 56).putOut() + (f shr 48).putOut() + (f shr 40).putOut() + (f shr 32).putOut() + (f shr 24).putOut() + (f shr 16).putOut() + (f shr 8).putOut() + (f ).putOut() + (g shr 56).putOut() + (g shr 48).putOut() + (g shr 40).putOut() + (g shr 32).putOut() + (g shr 24).putOut() + (g shr 16).putOut() + (g shr 8).putOut() + (g ).putOut() + (h shr 56).putOut() + (h shr 48).putOut() + (h shr 40).putOut() + (h shr 32).putOut() + (h shr 24).putOut() + (h shr 16).putOut() + (h shr 8).putOut() + (h ).putOut() + return out } }