Skip to content

feat(kmp): DerivePath as KMP module + utils portable helpers in commonMain - #1203

Closed
bmc08gt wants to merge 2 commits into
code/cashfrom
feat/kmp-derive
Closed

feat(kmp): DerivePath as KMP module + utils portable helpers in commonMain#1203
bmc08gt wants to merge 2 commits into
code/cashfrom
feat/kmp-derive

Conversation

@bmc08gt

@bmc08gt bmc08gt commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Extracts `DerivePath` (BIP-44/SLIP-10 path parsing) into a new `:libs:encryption:derivepath` KMP module — pure Kotlin, zero platform dependencies, exported through the SharedCore XCFramework umbrella. The path logic for `m/44'/501'/0'/0'` (and all bucket/pool/rendezvous paths) is now cross-platform.
  • `DerivePath.relationship(domain)` refactored to `relationship(host: String)` to remove the `android.net.Uri` dependency; no production callers existed in the codebase.
  • Converts `:libs:encryption:utils` to KMP: portable byte helpers (`subByteArray`, `intToByteArray`, `Long.bytes`, `byteArrayToLong`, `hexEncodedString`, base58 extensions, `replaceParam`, `toUTF8Bytes`, `Byte.shl`) move to commonMain; Android-specific helpers (Base64, URL encode/decode, protobuf `ByteString`, Ed25519, `MessageDigest` SHA-512) stay in androidMain.
  • `Utils.java` ported to Kotlin in androidMain; logging replaces Timber with `trace()` from `:libs:logging` (positioned for future KMP extraction).
  • Fixes pre-existing `flipcashTestDebug` breakage: KMP modules (`com.android.kotlin.multiplatform.library`) expose `testAndroidHostTest` not `testDebugUnitTest`. Root `build.gradle.kts` gains a third dependency category; `settings.gradle.kts` carries the `kmpUnitTestModules` set. `:kmp:shared-core` (umbrella with no tests) is excluded from all test aggregation.
  • Both encryption modules follow the same plugin/target/hostTest pattern as `:libs:encryption:base58` (feat(kmp): graduate shared-core to real KMP module — Base58 + randomBytes #1201).

Test plan

  • `./gradlew :libs:encryption:derivepath:allTests` — DerivePathTest passes on JVM + iOS simulator
  • `./gradlew :libs:encryption:derivepath:compileKotlinIosSimulatorArm64` — iOS compiles
  • `./gradlew :libs:encryption:utils:compileKotlinIosSimulatorArm64` — iOS compiles
  • `./gradlew :libs:encryption:utils:testAndroidHostTest` — host tests pass (Base64, Utils, URL)
  • `./gradlew :kmp:shared-core:compileCommonMainKotlinMetadata` — shared-core with derivepath export compiles
  • `./gradlew :apps:flipcash:app:assembleDebug` — app compiles clean
  • `./gradlew flipcashTestDebug --dry-run` — resolves without task-not-found errors

…/android

- :libs:encryption:derivepath — new KMP module, pure Kotlin, no platform deps.
  Extracts DerivePath (BIP-44/SLIP-10 path parsing) from mnemonic so it can
  compile on iOS targets via SharedCore XCFramework. relationship(Domain)
  refactored to relationship(host: String) — callers pass domain.relationshipHost.
  Tests moved from mnemonic to derivepath commonTest; DerivePathTest runs on
  JVM + iosSimulatorArm64.

- :libs:encryption:utils — converted to KMP: portable byte helpers
  (intToByteArray, byteArrayToLong, subByteArray, hexEncodedString, base58
  extensions, replaceParam, toUTF8Bytes, Byte.shl) moved to commonMain;
  Android-specific helpers (Base64, URL encode, protobuf ByteString, Ed25519,
  MessageDigest SHA-512) moved to androidMain. Utils.java ported to Kotlin
  and placed in androidMain. Android-coupled tests (Base64, URL, Utils) moved
  to androidHostTest; commonTest covers the pure-Kotlin helpers with KAT vectors.

- :kmp:shared-core — exports :libs:encryption:derivepath so iOS gets it
  through the SharedCore XCFramework.
@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
…Test

KMP libraries (com.android.kotlin.multiplatform.library) expose
testAndroidHostTest rather than testDebugUnitTest. The aggregate
flipcashTestDebug task now has a third category for these modules.
Also excludes :kmp:shared-core (umbrella only, no tests) from all
test aggregation lists. Fixes the pre-existing breakage introduced
with the base58 KMP extraction.
@bmc08gt

bmc08gt commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

Closing — this went beyond the scope of the hashing task (it was meant to convert only sha256/sha512/hmac, which is #1202). Derivation (C1) is the highest-correctness step and will be done as its own focused PR, gated by the slip10.json cross-platform vectors, with the relationship(Domain) -> relationship(host) API change reviewed deliberately rather than riding in as a side-effect. Branch feat/kmp-derive is left intact for reference when that work is picked up.

@bmc08gt bmc08gt closed this Aug 7, 2026
@bmc08gt bmc08gt reopened this Aug 7, 2026
@bmc08gt

bmc08gt commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

Re-closing. This PR was reopened by an automated process in error — it was intentionally closed and that decision stands: DerivePath/utils extraction (C1) will be done as its own focused PR gated by slip10.json, not merged as a side-effect of the hashing work. The feat/kmp-derive branch remains available for reference.

@bmc08gt bmc08gt closed this Aug 7, 2026
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