{"id":30459543,"url":"https://github.com/youneedwork/wallet-core-kmp-example","last_synced_at":"2025-08-23T18:30:37.277Z","repository":{"id":309466329,"uuid":"1034199945","full_name":"YouNeedWork/wallet-core-kmp-example","owner":"YouNeedWork","description":null,"archived":false,"fork":false,"pushed_at":"2025-08-12T02:10:40.000Z","size":201,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-22T22:39:13.716Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/YouNeedWork.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-08T02:40:01.000Z","updated_at":"2025-08-12T02:10:43.000Z","dependencies_parsed_at":"2025-08-12T04:23:44.222Z","dependency_job_id":"61ed15d0-769f-4cb5-9f65-857238d53b74","html_url":"https://github.com/YouNeedWork/wallet-core-kmp-example","commit_stats":null,"previous_names":["youneedwork/wallet-core-kmp-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/YouNeedWork/wallet-core-kmp-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YouNeedWork%2Fwallet-core-kmp-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YouNeedWork%2Fwallet-core-kmp-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YouNeedWork%2Fwallet-core-kmp-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YouNeedWork%2Fwallet-core-kmp-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YouNeedWork","download_url":"https://codeload.github.com/YouNeedWork/wallet-core-kmp-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YouNeedWork%2Fwallet-core-kmp-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271762692,"owners_count":24816816,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-08-23T18:30:35.451Z","updated_at":"2025-08-23T18:30:37.255Z","avatar_url":"https://github.com/YouNeedWork.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Kotlin Multiplatform Wallet-Core + Compose Example\n\n[中文版本 (Chinese)](./README_ZH.md)\n\nThis repository showcases how to integrate the following core capabilities in a Kotlin Multiplatform (Android \u0026 iOS) application using Compose Multiplatform:\n\n1. Trust Wallet `wallet-core` (mnemonic generation, key \u0026 address derivation, message signing \u0026 verification)\n2. Voyager for cross-platform screen navigation + ScreenModel (state/business logic)\n3. In-app browser via `compose-webview-multiplatform`\n4. Cross-platform networking with Ktor `HttpClient` (OkHttp on Android, Darwin engine on iOS)\n5. Centralized dependency version management with `libs.versions.toml`\n\nPrimary shared module: `composeApp` (shared code in `composeApp/src/commonMain`).\n\n---\n\n## Tech Stack\n\n| Capability     | Description                                  | Key Dependencies                                    |\n| -------------- | -------------------------------------------- | --------------------------------------------------- |\n| UI             | Compose Multiplatform (Material3, Resources) | `org.jetbrains.compose`                             |\n| Navigation     | Voyager Navigator + ScreenModel              | `cafe.adriel.voyager:*`                             |\n| In-app Browser | Compose WebView Multiplatform                | `io.github.kevinnzou:compose-webview-multiplatform` |\n| Wallet         | Trust Wallet Core Kotlin bindings            | `com.trustwallet:wallet-core-kotlin*`               |\n| Logging        | Kermit                                       | `co.touchlab:kermit`                                |\n| Concurrency    | Kotlinx Coroutines                           | `org.jetbrains.kotlinx:kotlinx-coroutines-*`        |\n| Networking     | Ktor Client (core + OkHttp + Darwin)         | `io.ktor:ktor-client-*`                             |\n\n---\n\n## Wallet-Core Integration\n\nThe project uses Trust Wallet Core Kotlin bindings for multi-chain wallet operations (mnemonic, keys, addresses, signing):\n\nIn `gradle/libs.versions.toml`:\n\n```\nwallet-core-kotlin = com.trustwallet:wallet-core-kotlin:{version}\nwallet-core-kotlin-android = com.trustwallet:wallet-core-kotlin-android:{version}\nwallet-core-kotlin-iosarm64 = ...\nwallet-core-kotlin-iossimulatorarm64 = ...\nwallet-core-kotlin-iosx64 = ...\n```\n\nIn `composeApp/build.gradle.kts`:\n\n```\ncommonMain.dependencies { implementation(libs.wallet.core.kotlin) }\nandroidMain.dependencies { implementation(libs.wallet.core.kotlin.android) }\niosMain.dependencies { implementation(libs.wallet.core.kotlin.iosarm64 /* etc */) }\n```\n\nAndroid entry point (`MainActivity.kt`) loads the native library:\n\n```kotlin\nSystem.loadLibrary(\"TrustWalletCore\")\n```\n\nUsage sample (`HomeScreen.rt.kt`):\n\n```kotlin\nval wallet = HDWallet(256, \"\")          // 256-bit entropy -\u003e mnemonic (English default)\nval mnemonic = wallet.mnemonic\nval btcAddress = wallet.getAddressForCoin(CoinType.Bitcoin)\nval ethAddress = wallet.getAddressForCoin(CoinType.Ethereum)\nval key = wallet.getKeyForCoin(CoinType.Ethereum)\nval sig = EthereumMessageSigner.signMessage(key, \"123\")\nval verified = EthereumMessageSigner.verifyMessage(key.getPublicKey(CoinType.Ethereum), \"123\", sig)\n```\n\nNotes:\n\n- Never use an empty passphrase in production.\n- Avoid logging mnemonics / private keys (shown here only for demonstration).\n- iOS does not need a manual `loadLibrary` (static framework bundle).\n\n---\n\n## Navigation \u0026 ScreenModel (Voyager)\n\nVoyager provides a lightweight, multiplatform navigation and state model pattern.\n\nKey concepts:\n\n- `Screen` = a navigation unit with a `Content()` composable.\n- `ScreenModel` = lifecycle-aware state holder (analogous to ViewModel).\n\nExample:\n\n```kotlin\nclass HomeScreen : Screen {\n    override val key: ScreenKey = uniqueScreenKey\n    @Composable override fun Content() {\n        val screenModel = rememberScreenModel { HomeScreenModel() }\n        val state by screenModel.state.collectAsState()\n        // Render based on state\n    }\n}\n```\n\nBenefits:\n\n1. Works naturally with Compose\n2. Consistent navigation abstraction across platforms\n3. Lifecycle scoping simplifies resource cleanup\n\nSuggested enhancements:\n\n- A centralized `NavigatorHost` to manage stack + deep links\n- Define a sealed `Route` hierarchy to avoid stringly-typed routes\n\n---\n\n## In-App Browser (WebView)\n\nDependency: `compose-webview-multiplatform` (added to `commonMain`).\n\nExample (pseudo):\n\n```kotlin\n@Composable\nfun InAppBrowser(url: String) {\n    // WebView(state = rememberWebViewState(url)) { /* custom config */ }\n}\n```\n\nUse cases:\n\n- Campaign / marketing pages\n- Third-party auth / payment callbacks\n- Viewing block explorer links\n\nPotential extensions:\n\n- URL scheme interception for DApps / WalletConnect\n- JS bridge for native \u003c-\u003e web interactions\n\n---\n\n## Ktor HttpClient (Multiplatform Networking)\n\nLocated in `Greeting.kt`:\n\n```kotlin\nprivate val client = HttpClient()\nsuspend fun greeting(): String = client.get(\"https://www.baidu.com/\").bodyAsText()\n```\n\nEngines:\n\n- Android -\u003e OkHttp (`ktor-client-okhttp`)\n- iOS -\u003e Darwin (`ktor-client-darwin`)\n\nRecommended configuration:\n\n```kotlin\nHttpClient {\n    expectSuccess = true\n    install(ContentNegotiation) { json() }\n    install(Logging) { level = LogLevel.INFO }\n    defaultRequest { header(\"User-Agent\", \"KMP-App\") }\n}\n```\n\nError handling:\n\n- Repository layer returning `Result\u003cT\u003e` or custom sealed classes\n- Platform-specific mapping for UI error messages\n\n---\n\n## Project Structure\n\n```\ncomposeApp/\n  src/\n    commonMain/   \u003c-- shared business logic, UI (Compose), navigation, wallet, networking\n    androidMain/  \u003c-- Android-specific (Activity, loadLibrary)\n    iosMain/      \u003c-- iOS-specific (framework export)\ngradle/libs.versions.toml \u003c-- centralized dependency versions\n```\n\n---\n\n## Build \u0026 Run\n\nAndroid:\n\n```\n./gradlew :composeApp:assembleDebug\n```\n\niOS:\n\n```\n./gradlew :composeApp:syncFramework\n# Open the Xcode project under iosApp/ and run\n```\n\nDesktop (if a desktop target is later added):\n\n```\n./gradlew :composeApp:run\n```\n\n---\n\n## Security Considerations (wallet-core)\n\n1. Do not log mnemonics / private keys in production.\n2. Use secure storage (Android Keystore / iOS Keychain) for sensitive data.\n3. Verify user intent before signing arbitrary messages (phishing protection).\n4. Track wallet-core release notes for breaking changes during upgrades.\n5. Ensure thread safety if sharing an `HDWallet` instance; prefer derived public keys for read-only operations.\n\n---\n\n## Possible Next Steps\n\n- Abstract a `WalletRepository` supporting multiple chains + caching (addresses, balances)\n- Sealed `Route` + navigation extensions\n- Dependency Injection (Koin / Kodein) for HttpClient \u0026 ScreenModels\n- Network: timeouts, retry, offline cache policies\n- Integrate WalletConnect / EIP-4361 (SIWE) auth flow\n- JS bridge in WebView for account \u0026 signing interactions\n\n---\n\n## License\n\nEducational example only. Add an appropriate LICENSE before distribution.\n\n---\n\nFeedback / contributions welcome. See the Chinese version here: [中文说明](./README_ZH.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyouneedwork%2Fwallet-core-kmp-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyouneedwork%2Fwallet-core-kmp-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyouneedwork%2Fwallet-core-kmp-example/lists"}