ionspin / kotlin-multiplatform-bignum

A Kotlin multiplatform library for arbitrary precision arithmetics
Apache License 2.0
339 stars 40 forks source link

[JS] Method `BigInteger.fromByteArray` fails in JS (NodeJS & Browser) #265

Open hamada147 opened 11 months ago

hamada147 commented 11 months ago

Describe the bug BigInteger.fromByteArray fails in JS but works with no issues in all other platforms.

To Reproduce Steps to reproduce the behaviour:

val byteArrayInBase64Padded = "P6XiWtDoaj6g3le12ljqjl3J/ZXa/kRswC9GNUYmkTU="
val byteArray = byteArrayInBase64Padded.base64PadDecodedBytes // value is [63, -91, -30, 90, -48, -24, 106, 62, -96, -34, 87, -75, -38, 88, -22, -114, 93, -55, -3, -107, -38, -2, 68, 108, -64, 47, 70, 53, 70, 38, -111, 53] // correct value
val bigInteger = BigInteger.fromByteArray(byteArray, Sign.POSITIVE) // fails here with `ClassCastException`
println(bigInteger.toString()) // 28788801469504357252816216561604952156895770089726804292579259475621317087541

Expected behaviour Should create a BigInteger value without issue.

Platform [JS]

If JS (please complete the following information):

Additional context The following method in unit test testToAndFromByteArray on https://github.com/ionspin/kotlin-multiplatform-bignum/blob/main/bignum/src/commonTest/kotlin/com/ionspin/kotlin/bignum/integer/ByteArrayConversionTest.kt also fails with the same exception ClassCastException.

ionspin commented 11 months ago

Thanks for reporting.

ionspin commented 5 months ago

Sorry for taking so long to look into this, is it still reproducible?

hamada147 commented 4 months ago

Unfortunately yes, it is still reproducible