Skip to content

Wallet-Core Integration

Overview Wallet-Core is vendored under external/wallet-core and built as part of the main CMake build. The engine exposes a minimal Fennel module for HD wallets and address derivation.

Wallet UI Integration

  • Wallet state is managed in Fennel by WalletManager, with the active wallet stored under app.wallet.active.
  • Wallet metadata and the active wallet pointer live under appdirs.user-data-dir in space/wallets/.
  • JSON writes use json-utils.write-json! for atomic updates to avoid corrupting files when the app exits mid-write.
  • Wallet balances are fetched via JSON-RPC using wallet-rpc (default: https://nova.arbitrum.io/rpc).

Bindings

  • Module: wallet-core
  • Factory: wallet-core.HDWallet({:mnemonic <string> :passphrase <string?>})
  • Functions:
    • wallet-core.mnemonic-valid(<string>) -> boolean
  • HDWallet methods:
    • :mnemonic() -> string
    • :address-for-coin(<coin-type>) -> string
    • :drop()
    • :is-closed() -> boolean
  • Coin constants:
    • wallet-core.coin-types.bitcoin
    • wallet-core.coin-types.ethereum
    • wallet-core.coin-types.arbitrum
    • wallet-core.coin-types.arbitrumnova
    • wallet-core.coin-types.solana

Build Notes

  • Wallet-Core is compiled via add_subdirectory(external/wallet-core) and linked into space_lib.
  • The Rust FFI static archive libwallet_core_rs.a is expected under external/wallet-core/rust/target/release/.
  • Registry-driven sources are generated and tracked in-tree:
    • external/wallet-core/src/Generated/CoinInfoData.cpp
    • external/wallet-core/include/TrustWalletCore/TWHRP.h
    • external/wallet-core/src/TWHRP.cpp

Tests

  • Fennel tests live in assets/lua/tests/test-wallet-core.fnl and are registered in assets/lua/tests/fast.fnl.
  • Run the suite with:
    • SKIP_KEYRING_TESTS=1 XDG_DATA_HOME=/tmp/space/tests/xdg-data SPACE_DISABLE_AUDIO=1 SPACE_ASSETS_PATH=$(pwd)/assets make test

Status Implemented:

  • Vendored wallet-core library builds with the main project.
  • Fennel wallet-core module with HD wallet creation, mnemonic validation, and address derivation.
  • Bitcoin address derivation test coverage.

Missing / TODO:

  • Expand coin type coverage (more constants, or a lookup API).
  • Expose additional wallet-core features (private keys, public keys, signing, address validation).
  • Add Fennel bindings for more data types (e.g., TWPrivateKey, TWAnyAddress, TWPublicKey).
  • Surface wallet-core errors with richer error types or messages in Fennel.

Build Issues Encountered

  • Clang recommendation warning: downgraded to a status message in external/wallet-core/CMakeLists.txt.
  • Rust archive path mismatch: wallet-core expected libwallet_core_rs.a under the top-level rust/target, but the vendored path is external/wallet-core/rust/target. Fixed by using CMAKE_CURRENT_SOURCE_DIR in external/wallet-core/CMakeLists.txt.
  • Missing coin registry sources: CoinInfoData.cpp and HRP files are generated by Ruby tooling. Ruby was unavailable, so these were generated via a Python helper and committed in:
    • external/wallet-core/src/Generated/CoinInfoData.cpp
    • external/wallet-core/include/TrustWalletCore/TWHRP.h
    • external/wallet-core/src/TWHRP.cpp
  • HRP enum mismatch for eCash: the generated enum uses TWHRPeCash (lowercase e), so the generator was adjusted to match the naming convention in the registry templates.
  • _Nonnull not defined in C++ builds: some internal headers use _Nonnull without Clang. Added definitions in external/wallet-core/src/Data.h so C++ builds with GCC succeed.

Roadmap

  • Add a stable, versioned Fennel API surface for wallet-core (expand coin types, normalize addresses, and expose signing workflows).
  • Expose additional wallet-core types through Fennel (private/public keys, AnyAddress, protobuf transaction builders).
  • Provide a small Fennel helper layer for coin metadata (symbol, decimals, chain id).
  • Decide whether to keep generated registry artifacts in-repo or add a scripted build step (with a Ruby/Python fallback).