Skip to content

Add Gem Keystore - #467

Merged
gemcoder21 merged 5 commits into
mainfrom
gem-keystore
Jun 10, 2026
Merged

Add Gem Keystore#467
gemcoder21 merged 5 commits into
mainfrom
gem-keystore

Conversation

@0xh3rman

@0xh3rman 0xh3rman commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Design

Replace Wallet Core's keystore with a Rust-owned Gem keystore: the wallet private key stays inside Rust. Signing, message-signing, and device auth all run in core — the apps only call high-level keystore operations, and no raw key crosses the FFI/JNI boundary.

3 commits, one per platform — please review commit-by-commit (the combined diff is large). core lands first since the apps build on its regenerated UniFFI bindings (bindings are gitignored, so the app commits aren't independently buildable without a stone regen).

1. core — gem keystore (Rust-owned v4)

  • v4 encrypted keystore: Argon2id KDF + AES-256-GCM, deterministic UUIDv5 id, atomic writes, process-global serialization.
  • keystore-internal signing, message signing, and device auth (gem_auth Ed25519) — the decrypted private key never crosses the FFI boundary; raw-key signers dropped from the UniFFI surface.
  • address derived from the public key; recovery-phrase + device-key entropy via getrandom (direct OS CSPRNG).
  • v3 (Wallet Core) migration reader; Wallet Core removed from core signing, address validation, and fee estimation.
  • crypto on the RustCrypto new generation (aes-gcm 0.11-rc / aes 0.9 / scrypt 0.12 / getrandom 0.4 / ripemd 0.2).

2. android — migrate to gem keystore

  • keystore ops via withGemKeystore (decode + zeroize password); transaction signing, message signing, and device auth run in Rust; raw-key SignClient / SignService removed.
  • downgrade-safe v3→v4 migration: v3 file left in place (keyed on v4 presence, no re-run); wallet deletion removes every on-disk copy.
  • Trust Wallet Core dependency removed.

3. ios — migrate to gem keystore

  • LocalKeystore.sign / signMessage / signAuthMessageHash via the Rust keystore; old getPrivateKey / ChainSigner / SwapSigner paths removed.
  • downgrade-safe v3→v4 migration (v3 left in place); wallet deletion removes every on-disk copy.
  • WalletCore SPM package removed.

@0xh3rman
0xh3rman force-pushed the gem-keystore branch 3 times, most recently from b66a163 to 7c37d35 Compare June 8, 2026 12:20
@0xh3rman
0xh3rman marked this pull request as ready for review June 8, 2026 13:23
@0xh3rman 0xh3rman self-assigned this Jun 9, 2026
do {
_ = try await keystore.migrateV3Keystore(for: wallet)
} catch {
os_log(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use debugLog

0xh3rman added 5 commits June 10, 2026 09:00
- v4 encrypted keystore: Argon2id KDF + AES-256-GCM (RustCrypto aes-gcm),
  deterministic UUIDv5 id, atomic writes, process-global serialization
- keystore-internal signing, message signing, and device auth (gem_auth Ed25519);
  the decrypted private key never crosses the FFI boundary
- address derivation from the public key; recovery-phrase entropy via getrandom
- v3 (WalletCore) migration reader; remove Wallet Core from core signing,
  address validation, and fee estimation
- crypto deps on the RustCrypto new generation (aes 0.9 / aes-gcm 0.11 /
  scrypt 0.12 / ctr 0.10 / getrandom 0.4 / ripemd 0.2)
- high-level keystore operators via withGemKeystore; transaction signing,
  message signing, and device auth run in Rust
- v3 to v4 migration leaves the v3 file in place (downgrade-safe), keyed on
  v4 presence; wallet deletion removes every on-disk copy
- remove the Trust Wallet Core dependency
- LocalKeystore sign / signMessage / signAuthMessageHash via the Rust keystore;
  the old getPrivateKey / ChainSigner / SwapSigner paths are removed
- v3 to v4 migration leaves the v3 file in place (downgrade-safe), keyed on
  v4 presence; wallet deletion removes every on-disk copy
- remove the WalletCore SPM package
…at, testdata vectors

- Reject empty keystore passwords at the platform choke points (iOS
  withV4Password, Android withGemKeystore) instead of failing deep in Rust
- Replace release-build os_log of migration failures with debugLog
- Rewrite Android String.words() without regex (Unicode whitespace, matches
  Rust split_whitespace) and cover it with a unit test
- Move gem_derivation mnemonic test vectors to testdata JSON per repo pattern
- Remove gemk header created_at (and the timestamp plumbing), update docs,
  README, and dump script; corrupt a KDF salt byte in the tamper test instead
- Hoist ".gemk" into FILE_EXTENSION const
- Inline phrase-discarding import_mnemonic_wallet into preview_import
- Drop unused legacyAndroidV3PasswordBytes and redundant v3_migrated test
  assertions; remove behavior-restating comments
@gemcoder21
gemcoder21 merged commit 21ba204 into main Jun 10, 2026
7 checks passed
@gemcoder21
gemcoder21 deleted the gem-keystore branch June 10, 2026 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants