Skip to content

feat(kmp): convert :libs:encryption:utils to KMP - #1206

Merged
bmc08gt merged 1 commit into
code/cashfrom
feat/kmp-derivepath-utils
Aug 8, 2026
Merged

bmc08gt merged 1 commit into
code/cashfrom
feat/kmp-derivepath-utils

Conversation

@bmc08gt

@bmc08gt bmc08gt commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Converts :libs:encryption:utils from Android-only to Kotlin Multiplatform, following the same pattern as :libs:encryption:base58, :sha256, :sha512, and :hmac.
  • Portable byte helpers move to commonMain so they compile on iOS targets (and are usable from the SharedCore XCFramework pipeline).
  • Android-specific code (Base64, URL encode/decode, protobuf ByteString, Ed25519, SHA-512 via MessageDigest) stays in androidMain.
  • Utils.java ported to Kotlin (Utils.kt in androidMain); all public API and @JvmStatic annotations preserved — zero changes required in callers.
  • :libs:encryption:utils added to kmpUnitTestModules in settings.gradle.kts so the aggregate test task uses testAndroidHostTest.

What moved where

Source Destination
Extensions.kt (portable helpers) commonMain/Extensions.kt
Extensions.kt (Base64, URL, ByteString, Ed25519, SHA-512) androidMain/Extensions.android.kt
Utils.java androidMain/Utils.kt (Kotlin port)
ExtensionsTest.kt (portable) commonTest/ExtensionsTest.kt
ExtensionsTest.kt (URL tests) androidHostTest/UrlExtensionsTest.kt
Base64ExtensionsTest.kt androidHostTest/Base64ExtensionsTest.kt
UtilsTest.kt androidHostTest/UtilsTest.kt

Note on settings.gradle.kts

Adding :libs:encryption:utils to kmpUnitTestModules may conflict at merge time if concurrent work is adding other modules to that set. Resolve with a simple union merge.

Test results

  • ./gradlew :libs:encryption:utils:compileCommonMainKotlinMetadata — PASS
  • ./gradlew :libs:encryption:utils:compileAndroidMain — PASS
  • ./gradlew :libs:encryption:utils:testAndroidHostTest — PASS (all tests)
  • ./gradlew :libs:encryption:utils:allTests — PASS (JVM + iosSimulatorArm64)
  • ./gradlew :apps:flipcash:app:compileDebugSources — PASS (only processDebugGoogleServices fails as expected in worktree)

Split the Android-only module into commonMain + androidMain:

- commonMain/Extensions.kt: portable byte helpers — intToByteArray,
  byteArrayToLong/Int, subByteArray, hexEncodedString, base58 extensions,
  replaceParam, toUTF8Bytes, Byte.shl, HexEncodingOptions. Depends only on
  :libs:encryption:base58 (pure KMP). String.toUTF8Bytes now uses
  encodeToByteArray() instead of toByteArray(Charsets.UTF_8) for KMP compat.

- androidMain/Extensions.android.kt: Android-specific helpers — Base64 encode/
  decode (android.util.Base64), URL encode/decode (java.net.URLEncoder/Decoder),
  protobuf ByteString conversions, SHA-512 via MessageDigest, Ed25519 key helpers.

- androidMain/Utils.kt: port of Utils.java to Kotlin object with @JvmStatic.
  Timber replaces raw Timber calls; all public API preserved with same signatures
  so existing callers need no changes.

- commonTest/ExtensionsTest.kt: pure-Kotlin KAT vectors for commonMain helpers;
  runs on JVM + iosSimulatorArm64. URL tests removed (Android-only).

- androidHostTest/: Base64ExtensionsTest (Robolectric; android.util.Base64),
  UrlExtensionsTest (java.net.URLEncoder), UtilsTest (BigInteger/stream/MPI).

- settings.gradle.kts: add :libs:encryption:utils to kmpUnitTestModules so the
  aggregate test task uses testAndroidHostTest instead of testDebugUnitTest.
@github-actions github-actions Bot added type: feature New functionality area: crypto Solana, keys, encryption, signing area: build-system Gradle, convention plugins, build-logic labels Aug 7, 2026
@bmc08gt bmc08gt self-assigned this Aug 7, 2026
@bmc08gt
bmc08gt merged commit 0b30839 into code/cash Aug 8, 2026
3 of 4 checks passed
@bmc08gt
bmc08gt deleted the feat/kmp-derivepath-utils branch August 8, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: build-system Gradle, convention plugins, build-logic area: crypto Solana, keys, encryption, signing type: feature New functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant