|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Cross-platform FFI library wrapping the [VSS (Versioned Storage Service) Rust Client](https://github.com/lightningdevkit/vss-server) via UniFFI. Generates bindings for Swift (iOS), Kotlin (Android), and Python. Used by mobile Lightning wallets to back up both app data and LDK (Lightning Development Kit) channel state to a VSS server. |
| 8 | + |
| 9 | +## Build & Test Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +cargo build # Debug build |
| 13 | +cargo build --release # Release build |
| 14 | +cargo test # All tests |
| 15 | +cargo test tests::tests --lib # Unit tests only |
| 16 | +cargo test ffi_tests --lib # FFI interface tests only |
| 17 | +cargo clippy # Lint |
| 18 | + |
| 19 | +# Platform bindings (requires platform-specific toolchains) |
| 20 | +./build.sh ios # XCFramework + Swift bindings |
| 21 | +./build.sh android # JNI libs + Kotlin bindings |
| 22 | +./build.sh python # Python package |
| 23 | +./build.sh all # All platforms |
| 24 | +``` |
| 25 | + |
| 26 | +## Architecture |
| 27 | + |
| 28 | +### Dual Client Design |
| 29 | + |
| 30 | +The library maintains two separate global singleton clients, each with its own key derivation: |
| 31 | + |
| 32 | +- **VssClient** (`implementation.rs`) — App backup client. Uses a **truncated 32-byte** seed for key derivation (backward compatible with v0.4.0). Manages general app data storage. |
| 33 | +- **LdkVssClient** (`ldk_client.rs`) — Dedicated LDK client. Uses the **full 64-byte** BIP39 seed, matching ldk-node's exact key derivation chain so it can correctly deobfuscate keys stored by ldk-node's VssStore. |
| 34 | + |
| 35 | +Both clients are stored as `OnceCell<Arc<Mutex<Option<T>>>>` statics in `lib.rs`. |
| 36 | + |
| 37 | +### Key Derivation Paths (BIP32) |
| 38 | + |
| 39 | +- `m/877'` — VSS master derivation → 32-byte `vss_seed` → HKDF → (data_encryption_key, obfuscation_key) |
| 40 | +- `m/877'/138'` — LNURL-auth signing key (both clients derive from truncated seed for same server identity) |
| 41 | +- `m/877'/118'` — Store ID derivation |
| 42 | + |
| 43 | +The critical difference: app client truncates the 64-byte BIP39 seed to 32 bytes before deriving the master key, while the LDK client uses all 64 bytes. This must be preserved for backward compatibility. |
| 44 | + |
| 45 | +### FFI Layer (`lib.rs`) |
| 46 | + |
| 47 | +- `execute_async!` macro bridges sync FFI calls to the single-threaded Tokio runtime |
| 48 | +- All exported functions are annotated with `#[uniffi::export]` |
| 49 | +- `uniffi::setup_scaffolding!()` generates the FFI glue code |
| 50 | +- UniFFI config in `uniffi.toml` (Kotlin package: `com.synonym.vssclient`) |
| 51 | + |
| 52 | +### LDK Namespaces (`types.rs`) |
| 53 | + |
| 54 | +`LdkNamespace` enum maps to ldk-node's storage layout: `Default`, `Monitors`, `MonitorUpdates { monitor_id }`, `ArchivedMonitors`. Each namespace becomes a key prefix in VSS. |
| 55 | + |
| 56 | +### Retry Policy |
| 57 | + |
| 58 | +Exponential backoff (10ms base, 10ms jitter, max 10 attempts, 15s total). Skips retry for NoSuchKey, InvalidRequest, and Conflict errors. |
| 59 | + |
| 60 | +## Related Repositories |
| 61 | + |
| 62 | +When investigating VSS server behavior, protocol details, or LDK key derivation, check the sibling repos: |
| 63 | + |
| 64 | +- **vss-server**: `../vss-server` |
| 65 | +- **ldk-node**: `../ldk-node` |
| 66 | + |
| 67 | +## Release Workflow (MANDATORY) |
| 68 | + |
| 69 | +1. **ALWAYS** bump the version in `Cargo.toml` before generating bindings. |
| 70 | +2. **ALWAYS** bump the iOS framework tag in `Package.swift` to match the new version. |
| 71 | +3. **ALWAYS** regenerate all bindings with `./build.sh all` after any code changes. |
| 72 | +4. **ALWAYS** upload `bindings/ios/VssRustClientFfi.xcframework.zip` to new GitHub releases. |
| 73 | + |
| 74 | +## Commit Convention |
| 75 | + |
| 76 | +``` |
| 77 | +feat: ... # New features |
| 78 | +fix: ... # Bug fixes |
| 79 | +refactor: ... # Code restructuring |
| 80 | +chore: ... # Bindings updates, dependencies |
| 81 | +``` |
0 commit comments