Skip to content

fix(auth): store bip39 compatibility regardless of wallet type#216

Merged
CharlVS merged 3 commits intodevfrom
bugfix/store-bip39-compatibility
Sep 8, 2025
Merged

fix(auth): store bip39 compatibility regardless of wallet type#216
CharlVS merged 3 commits intodevfrom
bugfix/store-bip39-compatibility

Conversation

@takenagain
Copy link
Copy Markdown
Contributor

@takenagain takenagain commented Sep 7, 2025

Fixes the issue with the HD wallet toggle not appearing for legacy migrations and seed file imports. Related to #3068, and it's follow-up #3126.

Changes

  • Always update isBip39Seed regardless of wallet type This previously defaulted to false for iguana wallets and only updated for HD registrations.
  • Bump the KDF commit hash and checksums to ea91c0d

Context

The WalletLogIn page in komodo-wallet uses the isBip39Seed flag to determine whether to show the HD wallet toggle, which would previously remain hidden for legacy wallet migrations, and likely seed file imports as well.

When migrating a legacy wallet or importing a seed file, the user's funds are in the "iguana" derived wallet, so the initial login remains iguana, while allowing for login to the HD wallet if the user wishes (via the HD toggle).

---
title: Previous implementation (with bip39 compatible seed)
---
flowchart LR
    lwl[Legacy Wallet Login]
    lsr[Register SDK wallet with legacy wallet seed]
    lsrc@{ shape: comment, label: "derivationMethod: iguana
    isBip39Seed: false
    show HD toggle: true" }
    
    lwl --> lsr --> lsrc
Loading
---
title: Current implementation (with bip39 compatible seed)
---
flowchart LR
    lwl[Legacy Wallet Login]
    lsr[Register SDK wallet with legacy wallet seed]
    lsrc@{ shape: comment, label: "derivationMethod: iguana
    isBip39Seed: true
    show HD toggle: true" }
    
    lwl --> lsr --> lsrc
Loading

Before

before.mov

After

after.mov

Summary by CodeRabbit

  • Bug Fixes

    • HD wallet registration now validates BIP39 seeds immediately, providing clearer errors and preventing setup with invalid mnemonics.
  • Chores

    • Updated backend/API version for compatibility.
    • Refreshed platform build checksums to ensure integrity across web, desktop, and mobile.
    • Updated bundled coin definitions to the latest set.

previous behaviour of throwing if HD wallet seed is not bip39 compatible
pre-emptive avoidance of build errors as dev builds are pruned regularly
@takenagain takenagain self-assigned this Sep 7, 2025
@takenagain takenagain added the bug Something isn't working label Sep 7, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Sep 7, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Updates build configuration hashes and checksums across platforms and adds BIP39 seed compatibility checks during user registration in the local auth service, introducing a helper to decrypt and validate the mnemonic and adjusting the HD wallet registration flow to verify and return early on success/failure.

Changes

Cohort / File(s) Summary
Build config updates
packages/komodo_defi_framework/app_build/build_config.json
Updated api_commit_hash, platform valid_zip_sha256_checksums (web, ios, macos, windows, android-armv7, android-aarch64, linux), and coins.bundled_coins_repo_commit.
Auth registration BIP39 verification
packages/komodo_defi_local_auth/lib/src/auth/auth_service_auth_extension.dart
Added _isSeedBip39Compatible helper; in _registerNewUser, precomputes isBip39Seed, initializes KdfUser with it, and for HD wallets delegates to _verifyBip39Compatibility with early return. Existing verification logic retained.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor App
  participant AuthService
  participant Crypto as Crypto/KeyStore
  participant BIP39 as MnemonicValidator

  App->>AuthService: registerNewUser(config)
  AuthService->>Crypto: decrypt seed (_getMnemonic)
  Crypto-->>AuthService: mnemonic or error
  AuthService->>BIP39: validate mnemonic
  BIP39-->>AuthService: isValid (true/false)
  AuthService->>AuthService: create KdfUser(isBip39Seed = isValid)

  alt HD wallet
    AuthService->>Crypto: decrypt seed
    Crypto-->>AuthService: mnemonic
    AuthService->>BIP39: validate
    BIP39-->>AuthService: isValid
    alt valid
      AuthService-->>App: return verified KdfUser
    else invalid
      AuthService-->>App: throw AuthException
    end
  else Non-HD wallet
    AuthService-->>App: return KdfUser
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • CharlVS

Poem

A rabbit taps the checksum keys,
New hashes hum across the breeze.
Seeds decrypted, words aligned—
BIP39 now certified.
HD paths checked, quick and neat,
Hop, verify, secure the seed. 🐇🔐

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix/store-bip39-compatibility

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@takenagain
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@takenagain takenagain requested a review from Copilot September 7, 2025 20:29
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Sep 7, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request fixes an issue where the HD wallet toggle was not appearing for legacy wallet migrations and seed file imports by ensuring the isBip39Seed flag is properly set regardless of wallet type. Previously, this flag defaulted to false for iguana wallets and was only updated for HD registrations.

Key changes:

  • Extract BIP39 compatibility check into a separate method that runs for all wallet types
  • Always set isBip39Seed flag based on actual seed validation rather than wallet type
  • Update build configuration with new commit hashes and checksums

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
auth_service_auth_extension.dart Refactored to always check BIP39 compatibility and set the flag appropriately for all wallet types
build_config.json Updated API commit hash and platform-specific checksums for new build artifacts

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread packages/komodo_defi_local_auth/lib/src/auth/auth_service_auth_extension.dart Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
packages/komodo_defi_local_auth/lib/src/auth/auth_service_auth_extension.dart (3)

26-29: Fix invalid argument order in _verifyBip39Compatibility call (positional after named).

Dart requires positional args before named. This currently won’t compile.

-      currentUser = await _verifyBip39Compatibility(
-        walletPassword: config.walletPassword,
-        currentUser,
-      );
+      currentUser = await _verifyBip39Compatibility(
+        currentUser,
+        walletPassword: config.walletPassword,
+      );

132-134: Use a single initialized MnemonicValidator instance.

Avoid calling init() on one instance and validate() on another.

-      await MnemonicValidator().init();
-      isBip39 = MnemonicValidator().validateBip39(plaintext.plaintextMnemonic!);
+      final validator = MnemonicValidator();
+      await validator.init();
+      isBip39 = validator.validateBip39(plaintext.plaintextMnemonic!);

146-152: Preserve specific AuthException types; current catch masks invalidBip39Mnemonic.

Everything thrown inside the try (including the explicit invalidBip39Mnemonic) is wrapped as generalAuthError, losing signal for callers.

-    } catch (e) {
-      await _stopKdf();
-      throw AuthException(
-        'Failed to verify seed compatibility: $e',
-        type: AuthExceptionType.generalAuthError,
-      );
-    }
+    } on AuthException {
+      await _stopKdf();
+      rethrow;
+    } catch (e) {
+      await _stopKdf();
+      throw AuthException(
+        'Failed to verify seed compatibility: $e',
+        type: AuthExceptionType.generalAuthError,
+      );
+    }
🧹 Nitpick comments (1)
packages/komodo_defi_local_auth/lib/src/auth/auth_service_auth_extension.dart (1)

65-76: Remove redundant try/catch that only rethrows.

It adds noise without changing behavior; let the callee surface precise errors.

-      try {
-        return await _verifyBip39Compatibility(
-          currentUser,
-          walletPassword: config.walletPassword,
-        );
-      } on AuthException {
-        // Verify BIP39 compatibility for HD wallets after registration
-        // if verification fails, the user can still log into the wallet in legacy
-        // mode.
-        rethrow;
-      }
+      return await _verifyBip39Compatibility(
+        currentUser,
+        walletPassword: config.walletPassword,
+      );
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3f503d2 and 830f1cc.

📒 Files selected for processing (2)
  • packages/komodo_defi_framework/app_build/build_config.json (3 hunks)
  • packages/komodo_defi_local_auth/lib/src/auth/auth_service_auth_extension.dart (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build_and_preview_sdk_example_preview
  • GitHub Check: build_and_preview_playground_preview
  • GitHub Check: Flutter tests (all packages)
🔇 Additional comments (3)
packages/komodo_defi_local_auth/lib/src/auth/auth_service_auth_extension.dart (2)

58-60: Good change: set isBip39Seed during registration for all wallet types.

This aligns with the PR goal so the HD toggle can be shown appropriately post-login.


62-64: Clarify comment vs behavior.

The comments suggest legacy-mode fallback on HD verification failure, but the code rethrows (after the refactor above you’ll still propagate errors). Confirm intended UX; if fallback should occur here, handle it locally instead of throwing.

Also applies to: 71-74

packages/komodo_defi_framework/app_build/build_config.json (1)

3-3: Hashes & checksums validated Verified both commit hashes exist on GitHub and all SHA-256 checksum entries are valid 64-hex strings.

Comment thread packages/komodo_defi_local_auth/lib/src/auth/auth_service_auth_extension.dart Outdated
@takenagain takenagain marked this pull request as ready for review September 7, 2025 21:04
@takenagain takenagain requested a review from CharlVS September 7, 2025 21:04
Copy link
Copy Markdown
Collaborator

@CharlVS CharlVS left a comment

Choose a reason for hiding this comment

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

Thank you for taking initiative with this issue.

@CharlVS CharlVS merged commit 508d63f into dev Sep 8, 2025
5 of 8 checks passed
@takenagain takenagain deleted the bugfix/store-bip39-compatibility branch September 22, 2025 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants