Skip to content
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

Compiled JS failing when ran with Bunjs #8

Closed
ronhombre opened this issue Feb 14, 2024 · 6 comments · Fixed by #12 or #14
Closed

Compiled JS failing when ran with Bunjs #8

ronhombre opened this issue Feb 14, 2024 · 6 comments · Fixed by #12 or #14

Comments

@ronhombre
Copy link

image

Reproduction Steps:

  1. Run gradle browserWebpack
  2. Copy files in build/compileSync/js/main/productionExecutable/kotlin into a NodeJS project.
  3. Use the Kotlin/JS compiled files that use secure-random.
  4. Run Bunjs (Fails here).

Note: Additionally, using the compiled Webpack also causes the same bug when running on NodeJS.

Work around: Delete the first if-statement and leave whatever was in the else statement.

@05nelsonm
Copy link
Member

Wondering if this is a KotlinJS bug or not as a ByteArray should register as a UInt8Array

@ronhombre
Copy link
Author

image

It still breaks when run with Bunjs.

Removing the code below fixes it.

if (_get_isNode__xss3j(Companion_getInstance())) {
  _get_crypto__fwud1y(Companion_getInstance()).randomFillSync(array);
} else {
  
}

Leaving just the code below allows it to run.

var offset = 0;
while (offset < bytes.length) {
  var len = bytes.length > 65536 ? 65536 : bytes.length;
  _get_crypto__fwud1y(Companion_getInstance()).getRandomValues(array.subarray(offset, offset + len | 0));
  offset = offset + len | 0;
}

@05nelsonm 05nelsonm reopened this Mar 19, 2024
@05nelsonm
Copy link
Member

05nelsonm commented Mar 19, 2024

What version of Node.js is being utilized by bunjs

randomFillSync should accept a TypedArray, not just a Uint8Array.

@05nelsonm
Copy link
Member

#14 is up with a published SNAPSHOT. Could you test it out to verify the fix?

  1. Add the following to your root project's repositories block
    allprojects {
        repositories {
            // ...
            maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
        }
    }
  2. Use version org.kotlincrypto:secure-random:0.3.1-SNAPSHOT

@ronhombre
Copy link
Author

@05nelsonm Confirmed. Thanks for the fix.

image

@05nelsonm
Copy link
Member

@05nelsonm Confirmed. Thanks for the fix.

image

Great, will merge the fix and get a release out in a moment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants