Skip to content

M1: key management (BIP39, seed vault, PIN, biometrics) - #3

Open
erubboli wants to merge 45 commits into
feat/m0-foundationsfrom
feat/m1-keys
Open

erubboli wants to merge 45 commits into
feat/m0-foundationsfrom
feat/m1-keys

Conversation

@erubboli

Copy link
Copy Markdown
Member

Summary

Milestone M1 (keys): real key management under the M0 UI.

  • Full BIP39: bundled 2048-word list, checksum validation, PBKDF2-SHA512, parity-tested against upstream vectors; BTC keyring on scure (BIP84 vectors asserted)
  • Seed vault: AES-256-GCM sealed (Keystore/Keychain resident keys, native BiometricPrompt + CryptoObject authorization on Android, Keychain ACL on iOS), two-slot re-seal for gate upgrades (no data-loss window)
  • PIN: PBKDF2 verifier (210k), persisted escalating lockout (doubling), shared pinEntryCheck everywhere, change-PIN flow
  • Biometrics: choice-based vault gating (PIN-only wallets stay fully PIN), biometry-only fallback, real expo-local-authentication enrolment + unlock, step-up auth on phrase reveal, auto-lock on background with persisted settings
  • Discovery derives real ML + BTC addresses (fixed and custom derivation paths, vector-backed)
  • Vendored wallet-bindings v0.1.0 artifacts wired into both builds, checksums verified in CI; native call-through facade documented as M2+ seam
  • Gate: OCR + security + DRY + UX + mobile/i18n audits across 5 review cycles, 0 critical / 0 medium at close

Known follow-ups (tracked)

  • Native binding call-throughs (signing, tx encode) land with M2/M3 alongside EAS/Mac mini device builds
  • KeySession abstraction deferred to M2 (decision recorded)
  • Manual device tests tracked in the project test list (vault prompts, upgrade paths, biometric re-enrolment)

expo-local-authentication cannot pass a CryptoObject, so its generic
prompt never authorized the auth-per-use Keystore key: on Android every
seal and open failed behind the scenes and the wallet could neither
finish onboarding nor unlock. The prompt now lives inside the module:
MojitoCore seals and opens through BiometricPrompt with the cipher's own
CryptoObject (BIOMETRIC_STRONG, current activity), cancellation and
failure map to MOJITO_AUTH_REQUIRED, a biometric re-enrolment kill maps
to a distinct MOJITO_KEY_INVALIDATED with restore-from-phrase guidance,
and the JS-side generic step-up retry around vault operations is gone.

The gate now follows the persisted Secure-screen choice: seal carries a
gated flag to key creation (a PIN-only wallet never prompts for vault
ops), key creation fails when the activity context is missing instead of
silently creating an ungated key, and an existing alias with an
unreadable key fails instead of silently regenerating. A new keyGated
query exposes the real gate state without prompting.
The Swift facade passed CryptoKit Nonce/Ciphertext/Tag structs where
hex() expects Data, so the podspec build broke; wrap them in Data().
keyExists drops kSecReturnData, making the cold-start existence probe an
attribute-level query that never fires the Keychain ACL prompt, and the
App probe degrades to the locked state on failure instead of wedging the
splash. Key creation now keys on the persisted biometrics choice carried
by seal, fails closed when SecAccessControlCreateWithFlags returns nil
instead of silently creating an ungated key, and open no longer creates
a missing key. A cancelled ACL prompt and a failed biometric check now
map to separate codes (retryable vs restore-from-phrase).
Every Face ID prompt (enrolment scan, unlock scan and the Keychain ACL
prompt that guards the vault key) crashed on FaceID devices because the
usage string was absent everywhere. The expo-local-authentication plugin
now carries a user-facing sentence, so prebuild writes
NSFaceIDUsageDescription into the Info.plist.
The backup reveal effect depended on [backup, ctx], but ctx is a fresh
object literal on every Onboarding render: openWords succeeded, set
state, re-rendered with a new ctx, and decrypted again, forever. With a
gated key every iteration re-ran the OS biometric prompt over the lock
screen. The effect now waits for the lock layer to clear, early-returns
once the words sit in onboarding state, and depends on stable inputs
only; the phrase also leaves onboarding state exactly when the backup
layer closes, and the session docstrings say so.
Gating used to key on hardware detection at key creation, so wallets
from those builds hold an ungated key while the persisted choice says
biometrics. At unlock, when the persisted choice is a real true and the
native keyGated query reports no gate, the session seed is re-sealed
under a fresh gated key (wipe and save). A failed re-seal surfaces the
restore-from-phrase guidance, since the wipe-save window is the cost of
upgrading a single key slot. The session keeps the persisted choice
distinct from the unlock-UI flag, which folds in hardware detection.
The Storage section described hardware-detection gating and a JS
step-up retry, both gone. It now describes the persisted-choice gate,
the prompt inside the native module, the two typed failure classes, the
upgrade re-seal, and the prompt-free keyExists probe; a new manual-check
list covers the gated-vault paths a Node test run cannot reach,
including the biometric-change recovery via phrase restore.
Disabling auto-lock or biometrics wrote straight through, so anyone
holding the unlocked phone could switch a security control off with one
tap. Toggling either control off now opens an in-app PIN confirm against
the persisted verifier, using the same verdict and lockout bookkeeping
as the unlock screen (extracted into a shared pinEntryCheck). Turning
auto-lock off also re-locks the session immediately instead of letting
the unlocked session ride on. Enabling a control still needs no
step-up.
The unlock screen opened in bio mode whenever biometrics were enabled
and its scan never consulted pinStore, so five wrong PINs armed a
lockout that the default unlock path simply ignored (only the PIN-to-bio
switch was hidden). Bio mode now polls the armed deadline, refuses scan
starts while it runs, and shows the same countdown copy as the PIN path.
parseAccountPath dropped the first path token with slice(1) instead of
asserting it, so a bare /84'/0'/0' or a typo like n/84'/0'/0' derived as
if the master token said m/. Uppercase M passed too. The master token is
now asserted before slicing, and the BtcKeyring suite pins the
rejections.
The stored wallet meta claimed mainnet while discovery derives testnet
addresses, so the meta now names what the derivation actually used, and
the fixture probe drops its unreachable mainnet entry. Discovery copy no
longer promises a selection UI that does not exist and no longer claims
Account 1 has history on the empty branch. The dash-gate script records
why vendor/ sits outside the scan (checksum-pinned third-party
artifacts), the README says the same, and the dead MlBlobs test-helper
export is gone.
The upgrade path alerted and then re-alerted through the unlock catch
with the same copy stacked on top. The inner layer now only escalates
the typed error; the single alert with the erase option comes from the
unlock handler.
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.

1 participant