Skip to main content

Blockchain Kit SDK - Global Architecture

This document provides comprehensive architecture diagrams for the Blockchain Kit SDK KMP project. Each diagram is stored as a separate .mermaid file in diagrams/ for reuse and rendering flexibility.

Table of Contents

  1. High-Level Overview
  2. Flutter Layer
  3. Blockchain Services
  4. MPC & Signing
  5. Bluetooth/BLE Protocol
  6. Backup & Recovery
  7. Passkey & WebAuthn
  8. Storage Layer
  9. Data Flow Diagrams

1. High-Level Overview

Three-tier architecture: Platform ConsumersKMP Core SDKPlatform Implementations + External Dependencies.

View interactive diagram →

LayerResponsibility
Platform ConsumersiOS (Swift), Android (Kotlin), Flutter (Dart)
Flutter PluginGenerated Dart API, MethodChannel/EventChannel bridge
KMP CoreBusiness logic, cross-platform services, expect/actual
Platform ImplementationsCredentialManager (Android), ASAuthorization (iOS), Keychain, EncryptedPrefs
External DependenciesWalletCore (address/tx), MPC SDK (Rust/UniFFI), Kable (BLE), Ktor (HTTP)
Backend ServicesGuardian MPC Server, Guardian Recovery API, Blockchain RPC Nodes

2. Flutter Layer

The Flutter plugin wraps the KMP SDK via MethodChannel/EventChannel with auto-generated Dart models.

View interactive diagram →

State Management: InheritedNotifier + ChangeNotifier (zero external dependencies)

Navigation Flow:

  • AuthPage checks hasBackup() / hasWalletInHotStorage() → routes accordingly
  • First-time users: WalletSetupPageBackupSetupPageBleSetupPage (2of3) or HomePage (2of2)
  • Returning users: LoginPage → credential auth → HomePage

3. Blockchain Services

Clean abstraction layer with pluggable chain implementations (currently EVM).

View interactive diagram →

Key Design Decisions:

  • BlockchainSdkService is chain-agnostic — delegates to EvmBlockchainService
  • On-demand address derivation via getAddress(asset, groupId) — no stored addresses
  • Transaction status tracking via StateFlow with polling
  • PlatformHttpClientFactory (expect/actual) — Ktor Darwin on iOS, OkHttp on Android

4. MPC & Signing

Multi-Party Computation layer providing 2-of-2 (local) and 2-of-3 (BLE) signing flows.

View interactive diagram →

Security Properties:

  • PresignMaterial is consumed after signing (prevents replay)
  • MPC keys never leave the device in plaintext
  • 2-of-3 requires physical BLE device for signing
  • MpcProgressTracker provides real-time StateFlow updates

Signing Comparison:

Aspect2-of-22-of-3
Key materialKeygenResultDkgResult
SigningLocal MPCBLE + MPC Orchestrator
PresignMpcKmpClient.presign()BleHwTransport rounds
DevicesMobile onlyMobile + AC device

5. Bluetooth/BLE Protocol

Half-duplex BLE transport with IDCP framing for MPC protocol communication.

View interactive diagram →

IDCP Frame Layers:

  • Layer 0 — Fragmentation: 488-byte segment splitting
  • Layer 1 — IDCP Framing: Magic ?##, encryption type, reassembly
  • Layer 2 — MPC Frames: TssMessage protobuf payloads

State Machines:

  • Connection: DISCONNECTED → SCANNING → CONNECTING → CONNECTED
  • Protocol: IDLE → IDENTITY_EXCHANGE → DKG → PRESIGN → SIGN → COMPLETE
  • Transport: IDLE ↔ AWAITING_RESPONSE (half-duplex)

6. Backup & Recovery

V3 backup bundle format with multi-wrapper support and DEK/KEK envelope encryption.

View Backup diagram → | View Recovery diagram →

Encryption Design:

  • DEK (Data Encryption Key): Random 32 bytes, encrypts wallet shares with AES-256-GCM
  • KEK (Key Encryption Key): Derived from credential (PRF/PIN/Password), wraps DEK
  • Multi-wrapper: Same encrypted data, multiple KEK wrappers → multiple recovery paths

Wrapper Types:

WrapperKEK DerivationUse Case
AllPasskeysPRF extension output → HKDFPrimary, hardware-backed
SpecificPasskeyPRF extension output → HKDFExplicit passkey selection
GuardianGatedEscrow.NoGateRandom KEK escrow/retrieveAssisted recovery (NoGate)
PinPBKDF2-SHA256User-friendly fallback
PasswordPBKDF2-SHA256Strong passphrase option
NoneNo encryptionDevelopment only

7. Passkey & WebAuthn

Cross-platform passkey support with PRF extension for cryptographic key derivation.

View interactive diagram →

Platform Support:

FeatureAndroidiOS
Passkey APICredentialManager (14+)ASAuthorizationController
PRF ExtensionAPI 34+iOS 18+
ImplementationPasskeyManager.android.ktPasskeyManager.ios.kt

PRF Flow: Registration creates credential with PRF salt → Authentication returns 32-byte PRF output → HKDF derives KEK → KEK wraps/unwraps DEK isPrfSupported() is platform-gated via isPrfSupportedPlatform() (Android API 34+, iOS 18+).


8. Storage Layer

Secure storage using platform-native encrypted stores with a common KeyValueStorageInterface.

View interactive diagram →

Platform Storage:

PlatformImplementationBacking
AndroidEncryptedSharedPreferencesAndroid Keystore (hardware-backed)
iOSKeychain ServicesSecure Enclave (if available)

Data Categories:

  • Hot Storage: MPC key material (KeygenResult, DkgResult, PresignMaterial)
  • Credential Storage: Passkey credential metadata (credentialId, prfCapable, transports)
  • Backup Storage: Encrypted V3 bundles in iCloud / Google Backup / local file

9. Data Flow Diagrams

9.1 Wallet Creation (2-of-2)

Local MPC keygen → store → backup.

View interactive diagram →

9.2 Wallet Creation (2-of-3 with BLE)

Group creation → BLE scan+auto-connect → identity exchange → DKG → backup.

View interactive diagram →

9.3 Transaction Signing (2-of-2)

PreImage → local MPC presign + sign → WalletCore compile → broadcast.

View interactive diagram →

9.4 Backup Restore

Load bundle → PRF authentication → HKDF → unwrap DEK → decrypt wallets → restore to storage.

View interactive diagram →


Summary

LayerResponsibility
FlutterUI, state management, platform communication
KMP CoreBusiness logic, cross-platform services
BlockchainEVM operations, RPC, transaction building
MPCKey generation, signing protocols (2-of-2, 2-of-3)
BluetoothBLE transport, IDCP protocol, half-duplex state machine
BackupMulti-wrapper encryption, cloud storage, V3 bundles
PasskeyWebAuthn, PRF extension, credential management
StorageSecure key material, credentials, platform-native encryption

Key Architectural Patterns:

  • expect/actual for platform-specific implementations
  • Lazy initialization for services and clients
  • Half-duplex state machine for BLE protocol
  • DEK/KEK envelope encryption for backup security
  • Result<T> error handling with safe runCatchingResult
  • On-demand address derivation for multi-chain flexibility