Skip to main content

Code Map

Quick reference to key files and their responsibilities in the Blockchain Kit SDK.

Module Tier System

The SDK follows a tiered dependency architecture. Higher tiers may depend on lower tiers, but never the reverse.

TIER 3 (Facade)       sdk/          BlockchainKitSdk, MpcService, BlockchainSdkService

TIER 2 (Features) blockchain/ EVM operations, signing, tx tracking
transport/ Transport abstraction (BLE, future: USB)

TIER 1 (Domain) mpc/ Protocol orchestration (DKG, presign, sign)
backup/ Backup bundle, encryption, unlock strategies
auth/ Passkey, credential management

TIER 0 (Core) util/ Logger, Result helpers, JSON config
crypto/ Encryption, hashing, key derivation
idcp/ Frame parsing (transport-agnostic)
internal/ SDK config, storage container, UniFFI init

Dependency rules:

  • Tier 0 has zero internal dependencies
  • Tier 1 depends only on Tier 0
  • Tier 2 depends on Tier 0 + Tier 1
  • Tier 3 (facade) wires everything together

Visibility rules:

  • @PublicApi marks classes/models intended for SDK consumers
  • internal marks implementation details hidden from consumers
  • All @FlutterModule classes are public API (Tier 3)
  • All @Serializable model classes used in @FlutterMethod signatures are public API

Core SDK

FileDescription
BlockchainKitSdk.ktMain SDK entry point with @FlutterModule
MpcService.ktMPC submodule — transport-agnostic scan/connect/disconnect, MPC protocol orchestration, reactive connectionInfo stream (@FlutterSubmodule)
BlockchainSdkService.ktBlockchain service facade (accessed via @FlutterSubmodule)
platform/PlatformContext.ktPlatform-specific context (expect/actual pattern)

Blockchain Services (blockchain/)

FileDescription
EvmBlockchainService.ktEVM query operations (balance, nonce, fee, status, broadcast, preImageHash)
EvmSigningService.ktMPC signing operations (sign, signWithHw, assembleAndCompileSignedTx)
EvmTransactionBuilder.ktWalletCore integration for preImageHash/signing
EvmAbi.ktERC-20 ABI encoding (balanceOf, transfer) via WalletCore
EthereumRpcClient.ktEVM JSON-RPC client

Models

FileDescription
Fee.ktFee sealed class hierarchy
Asset.ktAsset sealed class (NativeCoin, Token)
Transaction.ktTransaction sealed class (Transfer)
Network.ktNetwork configuration model
Balance.ktBalance data class with BalanceResult typealias
Broadcast.ktBroadcast data class with BroadcastResult typealias
TransactionStatus.ktTransactionStatus sealed class (Pending, Confirmed, Failed, NotFound)

Passkey/WebAuthn (passkey/)

FilePlatformDescription
PasskeyManager.ktcommonMainexpect declaration for passkey operations
PasskeyManager.android.ktandroidMainAndroid Credential Manager integration
PasskeyManager.ios.ktiosMainiOS AuthenticationServices integration with PRF support (iOS 18+)
PasskeyAuthorizationController.ktiosMainiOS ASAuthorizationController wrapper
PrfSupport.ktcommonMainexpect isPrfSupportedPlatform() declaration
PrfSupport.android.ktandroidMainAndroid PRF support (API 34+)
PrfSupport.ios.ktiosMainiOS 18+ version check via NSProcessInfo.operatingSystemVersion
PrfAuthResult.ktcommonMainPRF authentication result with credentialId, prfSecret, credentialInfo

PasskeyAuthorizationController Methods (iOS)

  • createAuthenticationRequestWithPrf() - Configure PRF extension on assertion request
  • performAuthenticationWithPrf() - Suspend function for PRF authentication
  • PrfAuthenticationResult - Data class holding assertion + PRF output

IDCP Frame Parsing (idcp/frame/)

Transport-agnostic IDCP protocol parsing, usable with BLE, WebSocket, USB, or any other transport.

FileDescription
Layer1FrameParser.ktParse Layer 1 IDCP frames (magic detection, header config, size extraction)
FrameReassembler.ktReassemble fragmented frames (duplicate detection, overflow protection)
IdcpFrameBuilder.ktBuild Layer 1 frames for transmission (TssMessage encoding, Layer 2 wrapping)

Signing Protocol (signing/)

Transport-agnostic signing protocol encoders (TX25, future FROST support).

FileDescription
TssMessageEncoder.ktTX25 TssMessage protobuf wire format encoding
MessageTypeRegistry.ktData-driven TX25 message type resolution

Transport Abstraction (transport/)

Transport-agnostic interfaces for hardware device discovery, connection, and communication. All transports (BLE, future USB) implement these interfaces so MpcService and protocol code never depend on a specific transport.

FileDescription
HwTransportProvider.ktInterface: scan(), connect(deviceId), disconnect(), connectionState
HwTransport.ktInterface: extends KmpHwTransport (UniFFI) + close(), deviceInfo, transportType
DeviceInfo.ktTransport-agnostic device model (id, name, transportType, rssi)
TransportType.ktEnum: BLUETOOTH, USB
ConnectionState.ktEnum: DISCONNECTED, SCANNING, CONNECTING, CONNECTED
ConnectionInfo.ktReactive state model (state, transportType, deviceInfo) — exposed via @FlutterFlow
ProtocolStateMachine.ktThread-safe half-duplex state machine (IDLE ↔ AWAITING_RESPONSE), moved from bluetooth/

BLE Transport (bluetooth/)

BLE-specific implementation of the transport interfaces using the Kable library.

FileDescription
BleTransportProvider.ktImplements HwTransportProvider — BLE scan/connect via Kable, peripheral state monitoring for unexpected disconnects
BleHwTransport.ktImplements HwTransport — BLE read/write with MTU fragmentation, notification listener, write mutex
BleTransportExecutor.ktSynchronous bridge for UniFFI callbacks (Rust MPC SDK expects blocking I/O)
BleConstants.ktBLE protocol constants (UUIDs, MTU, timeouts, device name patterns)
encoding/ByteArrayUtils.ktKMP byte manipulation (replaces JVM ByteBuffer/ByteArrayOutputStream)

MPC Protocol (mpc/)

FileDescription
MpcConstants.ktParty topology (P1=HW, P2=Server, P3=Mobile), message types
MpcProtocolModels.ktIdentityExchangeResult, DkgResult, PresignResult, SignResult, MpcPhase, MpcProtocolState
IdentityExchangeProtocol.kt9-step identity key exchange (AC ↔ Mobile ↔ Server)
DkgProtocol.ktThreshold DKG orchestration via keygenThresholdWithHw()
PresignProtocol.ktThreshold presign orchestration via presignThresholdWithHw()
SignProtocol.ktThreshold sign orchestration via signThresholdWithHw()
MpcProtocolOrchestrator.ktFacade with StateFlow progress — accepts HwTransport (transport-agnostic)
P256KeyPair.ktexpect/actual P-256 keypair generation for identity exchange

MPC Wallet Storage (storage/)

Unified storage for 2-of-2 and 2-of-3 MPC wallet shares with multi-algorithm support.

Architecture Note: See hot-storage-architecture.md for comprehensive architecture documentation with diagrams.

Storage Models (MpcStorageModels.kt)

ModelDescription
StoredWalletInfoWallet-level metadata (groupId, displayName, walletType, createdAt)
StoredDkgResult2-of-3 DKG result with extendedDataBytes, shareBytes, combinedPublicKey, sessionId
StoredPresignResultPresign material (consumed after signing)
StoredKeygenResult2-of-2 keygen result with algorithmId, shareBytes, publicKeyBytes
StoredShareResultSealed class: Keygen (2-of-2), Dkg (2-of-3), Frost (future)

MpcWalletStorage Methods

Wallet Info (metadata):

  • storeWalletInfo(groupId, displayName, walletType) - Store wallet metadata
  • loadWalletInfo(groupId) - Load wallet metadata
  • getDisplayName(groupId) - Get display name for a wallet

Keygen (2-of-2):

  • storeKeygenResult(groupId, algorithmId, shareBytes, publicKeyBytes) - Store 2-of-2 share
  • loadKeygenResult(groupId, algorithmId) - Load 2-of-2 share

DKG (2-of-3):

  • storeDkgResult(groupId, ...) - Store 2-of-3 DKG result
  • storeDkgResultWithAlgorithm(groupId, algorithmId, ...) - Store with algorithm suffix

Multi-algorithm:

  • loadAllShares(groupId) - Load all algorithm shares for backup (Map<String, StoredShareResult>)
  • getPublicKey(groupId, algorithmId) - Get public key for address derivation

Group management:

  • listGroups() - List all wallet group IDs
  • deleteGroup(groupId) - Delete all data for a group (shares, wallet info, index)

Storage Key Patterns

PatternExampleDescription
mpc_wallet_{groupId}mpc_wallet_abc123Wallet info
mpc_keygen_{groupId}_{algorithmId}mpc_keygen_abc123_ecdsa_secp256k12-of-2 share
mpc_dkg_{groupId}_{algorithmId}mpc_dkg_abc123_ecdsa_secp256k12-of-3 share
mpc_presign_{groupId}mpc_presign_abc123Presign (consumed after signing)
mpc_groups_index-JSON array of groupIds

Wallet Backup System (storage/backup/)

PIN-encrypted backup system for wallet recovery. Uses V2 format with two-layer DEK/KEK encryption.

Data Models

FileDescription
BackupCredential.ktSealed class for credential types (None, Pin, Password, Passkey)
WalletBackupPayload.ktV2 backup format structures
WalletRestoreResult.ktRestore result model (address, groupId, walletType, displayName)

WalletBackupPayload Structure

  • WalletBackupPayload - Root: format_version: 2, salt, ciphertext_dek, wallet, checksum
  • BackupMetadata - credential_type, kek_derivation, encryption, algorithms list
  • WalletData - groupId, displayName, walletType, address, shares: Map<AlgorithmId, String>
  • AlgorithmId enum - ECDSA_SECP256K1, FROST_ED25519
  • ShareData sealed interface - EcdsaShareData, FrostShareData

Cryptography (expect/actual)

FileAndroidiOS
KeyDerivation.ktSecretKeyFactory PBKDF2WithHmacSHA256CommonCrypto.CCKeyDerivationPBKDF
AesGcm.ktJCE AES/GCM/NoPaddinglibsodium SecretBox.easy()
BackupEncryption.ktTwo-layer: DEK encrypts shares, KEK wraps DEK

Storage Providers

FileDescription
WalletBackupProvider.ktInterface for modular backup storage backends
LocalFileBackupProvider.ktLocal file storage (Android: context.filesDir, iOS: Documents)

Services

FileDescription
WalletBackupService.ktUnified backup/restore orchestration

Methods:

  • addWallet(groupId, displayName, walletType, credential) - Add wallet to backup
  • restoreWallet(credential) - Restore all wallets from backup

Shared Utilities (util/)

FileDescription
ResultExt.ktrunCatchingResult (wraps TResult<T>) and resultCatching (guards Result<T> blocks)
SdkLogger.ktSdkLogger interface + PrintSdkLogger (stdout) + NoOpSdkLogger (silent)
CurrentTimeMillis.ktexpect/actual cross-platform timestamp

Platform Expect/Actual Summary

DeclarationAndroidiOS
currentTimeMillis()System.currentTimeMillis()NSDate
configurePeripheralBuilder()requestMtu(512)no-op (auto-negotiated)
generateP256KeyPair()KeyPairGenerator("EC")SecKeyCreateRandomKey
deriveKeyFromPassword()JCE PBKDF2WithHmacSHA256CommonCrypto CCKeyDerivationPBKDF
aesGcmEncrypt()/aesGcmDecrypt()JCE AES-256-GCMlibsodium SecretBox
LocalFileBackupProvidercontext.filesDirDocuments directory

Build Logic (build-logic/)

Gradle convention plugins providing standardized configuration for KMP modules.

Module Structure

ModulePlugin IDDescription
common-Shared utilities (pluginId() helper function)
kmpkmpLibraryWrapperKMP library configuration (targets, source sets, frameworks)
open-apiopenApiWrapperOpenAPI code generation wrapper

KMP Plugin Components (build-logic/kmp/)

Primitives (primitives/):

FileDescription
BuildMode.ktDEBUG/RELEASE enum with resolution from env vars and development.config
TargetPlatform.ktPlatform combinations (AndroidOnly, IosOnly, AndroidAndSimulator, All, etc.)

Extensions (extensions/):

FileDescription
KMPLibWrapperExtension.ktMain DSL extension (configureKmpLibrary { ... })
ConfigurationScope.ktDependency scope interface (api, implementation, ksp, testImplementation)
AndroidConfigurationScope.ktAndroid-specific scope (adds instrumentedTestImplementation, etc.)
ProjectExtensions.ktExtension properties for Project (targetPlatform, buildMode)

Configurations (configurations/):

FileDescription
ConfigureKMPKotlinExt.ktKotlin multiplatform configuration (targets, source sets, XCFramework)
ConfigureKMPAndroidExt.ktAndroid library configuration (SDK versions, packaging, test runners)

Configuration File (development.config)

Required file in project root controlling local builds:

# Target platform for local development
# Options: device, mac, arm64Simulator, intelX64Simulator
iTestLocallyOnAndroidAnd=arm64Simulator

# Build mode: debug or release
buildMode=debug

Environment Variable Overrides

VariableValuesDescription
TARGET_PLATFORMAndroid, Ios, IosArm64, IosX64, IosSimulatorArm64, AllOverride target platform
BUILD_MODEDebug, ReleaseOverride build mode

Native MPC SDK (native/mpc-sdk/)

UniFFI-based Rust bindings for MPC cryptography.

DirectoryDescription
mpc-sdk-rs/Rust MPC library (git submodule)
wrapper/Gradle module for UniFFI Kotlin bindings

Build dependency: Unit tests depend on native:mpc-sdk:wrapper:build to ensure JNI bindings are available.


Sample Apps (sample/)

Sample applications for testing and development.

DirectoryDescription
androidApp/Android sample app
composeApp/Compose Multiplatform sample (shared UI)
iosApp/iOS sample app (SwiftUI)