Skip to content

feat: move checksumText to native#1942

Merged
RohitKushvaha01 merged 2 commits intoAcode-Foundation:mainfrom
RohitKushvaha01:offload_plugin_install_to_native
Mar 13, 2026
Merged

feat: move checksumText to native#1942
RohitKushvaha01 merged 2 commits intoAcode-Foundation:mainfrom
RohitKushvaha01:offload_plugin_install_to_native

Conversation

@RohitKushvaha01
Copy link
Copy Markdown
Member

@RohitKushvaha01 RohitKushvaha01 commented Mar 12, 2026

Related: #1803

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 12, 2026

Greptile Summary

This PR offloads the checksumText function from a pure-JavaScript implementation (using the Web Crypto API and TextEncoder) to a native Android implementation via the existing Cordova System plugin. Both approaches produce identical SHA-256 hex output over UTF-8 bytes, so previously stored hashes in InstallState remain compatible and no data migration is needed.

Key changes:

  • src/lib/installState.js: checksumText now delegates to cordova.exec("System", "checksumText", ...) instead of calling window.crypto.subtle.digest directly.
  • System.java: A new checksumText switch case runs MessageDigest.getInstance("SHA-256") on the Cordova thread pool and returns the hex digest.
  • A pre-existing missing break after the compare-texts case is also silently fixed (the fall-through to default: break was harmless but is now explicit).
  • Three of the four new Java imports (org.apache.cordova.*, org.json.JSONArray, org.json.JSONException) are duplicates of imports already present at the top of the file; only java.security.MessageDigest is new.

Confidence Score: 4/5

  • This PR is safe to merge; the logic is correct and the hash output is compatible with the old implementation.
  • The core change is functionally correct — SHA-256 over UTF-8 bytes produces the same hex output in both the old JS and new Java paths, so no backward-compatibility issue exists for stored checksums. The identified issues are all style/hygiene concerns (duplicate imports, string-based charset literal, potential null error message) with no runtime impact in practice on Android where SHA-256 and UTF-8 are always available.
  • The three duplicate imports in System.java (lines 110–113) should be cleaned up before merging to avoid import-section confusion in future edits.

Important Files Changed

Filename Overview
src/lib/installState.js Replaces the pure-JS checksumText implementation (Web Crypto API + TextEncoder) with a Cordova native bridge call to the new checksumText action on the System plugin. Both the old and new implementations produce identical SHA-256 hex output over UTF-8 bytes, so stored hashes remain compatible.
src/plugins/system/android/com/foxdebug/system/System.java Adds the checksumText case to the switch dispatcher, running SHA-256 hashing on the thread pool and returning a hex string. Issues: three duplicate imports added (org.apache.cordova.*, JSONArray, JSONException already exist at lines 48–54); getBytes("UTF-8") should use StandardCharsets.UTF_8; e.getMessage() can return null.

Sequence Diagram

sequenceDiagram
    participant JS as installState.js
    participant Cordova as Cordova Bridge
    participant Java as System.java (Java)
    participant MD as MessageDigest (SHA-256)

    JS->>Cordova: cordova.exec("System", "checksumText", [text])
    Cordova->>Java: execute("checksumText", args, callbackContext)
    Java->>Java: cordova.getThreadPool().execute(lambda)
    Java->>MD: getInstance("SHA-256")
    MD-->>Java: digest instance
    Java->>MD: digest(text.getBytes("UTF-8"))
    MD-->>Java: byte[] hash
    Java->>Java: build hex string
    Java->>Cordova: callbackContext.success(hexString)
    Cordova-->>JS: resolve(hash)
Loading

Last reviewed commit: 8465dcf

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@RohitKushvaha01 RohitKushvaha01 merged commit 8da3049 into Acode-Foundation:main Mar 13, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants