Skip to content

Commit a46ea44

Browse files
committed
Migrate bigint module to use shared web declarations
1 parent 35aab7e commit a46ea44

File tree

6 files changed

+35
-122
lines changed

6 files changed

+35
-122
lines changed

cryptography-bigint/build.gradle.kts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023-2024 Oleg Yukhnevich. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright (c) 2023-2025 Oleg Yukhnevich. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
import ckbuild.*
@@ -23,11 +23,7 @@ kotlin {
2323
applyDefaultHierarchyTemplate {
2424
common {
2525
group("nonJvm") {
26-
// js and wasmJs
27-
group("jsAndWasmJs") {
28-
withJs()
29-
withWasmJs()
30-
}
26+
group("web")
3127
// all native targets + wasmWasi
3228
group("nativeAndWasmWasi") {
3329
group("native")

cryptography-bigint/src/jsAndWasmJsMain/kotlin/JsBigInt.kt

Lines changed: 0 additions & 21 deletions
This file was deleted.

cryptography-bigint/src/jsMain/kotlin/JsBigInt.js.kt

Lines changed: 0 additions & 47 deletions
This file was deleted.

cryptography-bigint/src/wasmJsMain/kotlin/JsBigInt.wasmJs.kt

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2024-2025 Oleg Yukhnevich. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
@file:OptIn(ExperimentalWasmJsInterop::class)
6+
7+
package dev.whyoleg.cryptography.bigint
8+
9+
import kotlin.js.*
10+
11+
internal external interface JsBigInt : JsAny {
12+
@JsName("toString")
13+
fun convertToString(): String
14+
15+
@JsName("toString")
16+
fun convertToString(radix: Int): String
17+
}
18+
19+
@JsName("BigInt")
20+
internal external fun jsBigInt(value: Int): JsBigInt
21+
22+
@JsName("BigInt")
23+
internal external fun jsBigInt(value: String): JsBigInt
24+
25+
internal fun jsBigIntNegate(value: JsBigInt): JsBigInt = js("-value")
26+
27+
internal fun jsBigIntSign(value: JsBigInt): Int = js("value == 0 ? 0 : (value < 0 ? -1 : 1)")
28+
29+
internal fun jsBigIntCompareTo(a: JsBigInt, b: JsBigInt): Int = js("a < b ? -1 : a > b ? 1 : 0")
30+
31+
internal fun jsBigIntEquals(a: JsBigInt, b: JsBigInt): Boolean = js("a === b")
32+
33+
internal fun jsBigIntAsInt(value: JsBigInt, bits: Int): JsBigInt = js("BigInt.asIntN(bits, value)")

0 commit comments

Comments
 (0)