Commit 76e7e59
refactor: Refactor keyring controller to use modular init pattern (#20732)
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->
## **Description**
This refactors the keyring controller to use modular init.
## **Changelog**
<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`
If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`
(This helps the Release Engineer do their job more quickly and
accurately)
-->
CHANGELOG entry:
## **Related issues**
Fixes:
## **Manual testing steps**
```gherkin
Feature: my feature name
Scenario: user [verb for user action]
Given [describe expected initial app state]
When user [verb for user action]
Then [describe expected outcome]
```
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
### **After**
<!-- [screenshots/recordings] -->
## **Pre-merge author checklist**
- [ ] I’ve followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **Pre-merge reviewer checklist**
- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Moves keyring setup from Engine into modular init functions with
dedicated messengers, updates Engine to use them, and adds supporting
types and tests.
>
> - **Engine**:
> - Refactors keyring setup to use modular controllers. Removes inlined
`HdKeyring`/`LedgerKeyring`/`QrKeyring` builders and direct
`KeyringController` construction and encryptor wiring.
> - Passes `initialKeyringState`, `qrKeyringScanner`, and
(keyring-snaps) `removeAccount` into `initModularizedControllers` and
retrieves `KeyringController` from `controllersByName`.
> - Adjusts snaps auth/user-storage init placement; minor import
cleanups.
> - **Controllers**:
> - Adds `keyring-controller-init` to construct `KeyringController`
(configures `Encryptor`, `HdKeyring`, `LedgerKeyring`, `QrKeyring`, and
(keyring-snaps) `SnapKeyringBuilder`).
> - Adds `snap-keyring-builder-init` to create `SnapKeyring` builder;
persists keyrings via init messenger and uses `removeAccount` helper.
> - **Messengers**:
> - Adds `keyring-controller-messenger` and
`snap-keyring-builder-messenger` (plus init messenger) and registers
them in `messengers/index`.
> - **Types/Utils**:
> - Extends engine `types` and init request to include
`initialKeyringState`, `qrKeyringScanner`, and (keyring-snaps)
`removeAccount`; adds `KeyringController` and `SnapKeyringBuilder` to
controller maps.
> - Updates test utils to provide new init request fields.
> - Enhances `SnapKeyringBuilder` interface (name/state metadata).
> - **Tests**:
> - Adds unit tests for keyring init and messengers; updates modular
init tests to include new controllers.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
47db4a3. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Charly Chevalier <charlyy.chevalier@gmail.com>1 parent cc34ce5 commit 76e7e59
File tree
14 files changed
+560
-175
lines changed- app/core
- Engine
- controllers
- messengers
- utils
- SnapKeyring
14 files changed
+560
-175
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | 46 | | |
48 | 47 | | |
49 | 48 | | |
| |||
54 | 53 | | |
55 | 54 | | |
56 | 55 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
| 56 | + | |
61 | 57 | | |
62 | 58 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | 59 | | |
70 | 60 | | |
71 | 61 | | |
| |||
130 | 120 | | |
131 | 121 | | |
132 | 122 | | |
133 | | - | |
134 | 123 | | |
135 | 124 | | |
136 | 125 | | |
| |||
147 | 136 | | |
148 | 137 | | |
149 | 138 | | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | 139 | | |
154 | 140 | | |
155 | 141 | | |
| |||
223 | 209 | | |
224 | 210 | | |
225 | 211 | | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
226 | 216 | | |
227 | 217 | | |
228 | 218 | | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | 219 | | |
233 | 220 | | |
234 | 221 | | |
| |||
554 | 541 | | |
555 | 542 | | |
556 | 543 | | |
| 544 | + | |
557 | 545 | | |
558 | 546 | | |
559 | 547 | | |
560 | 548 | | |
561 | | - | |
562 | | - | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
571 | | - | |
572 | | - | |
573 | | - | |
574 | | - | |
575 | | - | |
576 | | - | |
577 | | - | |
578 | | - | |
579 | | - | |
580 | | - | |
581 | | - | |
582 | | - | |
583 | | - | |
584 | | - | |
585 | | - | |
586 | | - | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
592 | | - | |
593 | | - | |
594 | | - | |
595 | | - | |
596 | | - | |
597 | | - | |
598 | | - | |
599 | | - | |
600 | | - | |
601 | | - | |
602 | | - | |
603 | | - | |
604 | | - | |
605 | | - | |
606 | | - | |
607 | | - | |
608 | | - | |
609 | | - | |
610 | | - | |
611 | | - | |
612 | | - | |
613 | | - | |
614 | | - | |
615 | | - | |
616 | | - | |
617 | | - | |
618 | | - | |
619 | | - | |
620 | | - | |
621 | | - | |
622 | | - | |
623 | | - | |
624 | | - | |
625 | | - | |
626 | | - | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | 549 | | |
641 | 550 | | |
642 | 551 | | |
| |||
666 | 575 | | |
667 | 576 | | |
668 | 577 | | |
669 | | - | |
670 | | - | |
671 | | - | |
672 | | - | |
673 | | - | |
674 | | - | |
675 | | - | |
676 | | - | |
677 | | - | |
678 | | - | |
679 | | - | |
680 | | - | |
681 | | - | |
682 | | - | |
683 | | - | |
684 | | - | |
685 | | - | |
686 | | - | |
687 | | - | |
688 | | - | |
689 | | - | |
690 | | - | |
691 | | - | |
692 | | - | |
693 | | - | |
694 | | - | |
695 | | - | |
696 | | - | |
697 | | - | |
698 | | - | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
703 | | - | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
716 | | - | |
717 | | - | |
718 | | - | |
719 | | - | |
720 | | - | |
721 | | - | |
722 | | - | |
723 | | - | |
724 | | - | |
725 | | - | |
726 | | - | |
727 | | - | |
728 | | - | |
729 | | - | |
730 | | - | |
731 | | - | |
732 | | - | |
733 | | - | |
734 | | - | |
735 | | - | |
736 | | - | |
737 | | - | |
738 | 578 | | |
739 | 579 | | |
740 | 580 | | |
| |||
805 | 645 | | |
806 | 646 | | |
807 | 647 | | |
808 | | - | |
809 | 648 | | |
810 | 649 | | |
811 | 650 | | |
812 | 651 | | |
813 | 652 | | |
814 | 653 | | |
815 | 654 | | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
816 | 660 | | |
817 | 661 | | |
818 | 662 | | |
819 | 663 | | |
820 | 664 | | |
821 | 665 | | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
822 | 670 | | |
823 | 671 | | |
824 | 672 | | |
| |||
901 | 749 | | |
902 | 750 | | |
903 | 751 | | |
| 752 | + | |
904 | 753 | | |
905 | 754 | | |
906 | 755 | | |
| |||
938 | 787 | | |
939 | 788 | | |
940 | 789 | | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
941 | 859 | | |
942 | 860 | | |
943 | 861 | | |
| |||
0 commit comments