From f19a8caac788f3189eb8905858ea3d2272b3ceca Mon Sep 17 00:00:00 2001
From: gantunesr <gustavoantunesrod@gmail.com>
Date: Thu, 7 Dec 2023 14:25:37 -0300
Subject: [PATCH 01/18] feat: bump @metamask/keyring-controller to v7.5.0

---
 package.json |   2 +-
 yarn.lock    | 178 +++++++++++++++++++++++++++++----------------------
 2 files changed, 101 insertions(+), 79 deletions(-)

diff --git a/package.json b/package.json
index 7fa87118f2a..e3ad7f29ae9 100644
--- a/package.json
+++ b/package.json
@@ -184,7 +184,7 @@
     "@metamask/eth-sig-util": "^4.0.1",
     "@metamask/etherscan-link": "^2.0.0",
     "@metamask/gas-fee-controller": "^5.0.0",
-    "@metamask/keyring-controller": "^6.0.0",
+    "@metamask/keyring-controller": "^7.5.0",
     "@metamask/logging-controller": "^1.0.1",
     "@metamask/network-controller": "^8.0.0",
     "@metamask/permission-controller": "^4.0.1",
diff --git a/yarn.lock b/yarn.lock
index 9c0bee58c09..f25e52c96d6 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1820,7 +1820,7 @@
     bufio "^1.0.7"
     chai "^4.3.4"
 
-"@ethereumjs/common@^2.0.0", "@ethereumjs/common@^2.3.1", "@ethereumjs/common@^2.6.1", "@ethereumjs/common@^2.6.3", "@ethereumjs/common@^2.6.4":
+"@ethereumjs/common@^2.0.0", "@ethereumjs/common@^2.3.1", "@ethereumjs/common@^2.6.1", "@ethereumjs/common@^2.6.4":
   version "2.6.5"
   resolved "https://registry.yarnpkg.com/@ethereumjs/common/-/common-2.6.5.tgz#0a75a22a046272579d91919cb12d84f2756e8d30"
   integrity sha512-lRyVQOeCDaIVtgfbowla32pzeDv2Obr8oR8Put5RdUBNRGr1VGPGQNGP6elWIpgK3YdpzqTOh4GyUGOureVeeA==
@@ -1849,14 +1849,6 @@
     "@ethereumjs/common" "^2.0.0"
     ethereumjs-util "^7.0.7"
 
-"@ethereumjs/tx@3.5.1":
-  version "3.5.1"
-  resolved "https://registry.yarnpkg.com/@ethereumjs/tx/-/tx-3.5.1.tgz#8d941b83a602b4a89949c879615f7ea9a90e6671"
-  integrity sha512-xzDrTiu4sqZXUcaBxJ4n4W5FrppwxLxZB4ZDGVLtxSQR4lVuOnFR6RcUHdg1mpUhAPVrmnzLJpxaeXnPxIyhWA==
-  dependencies:
-    "@ethereumjs/common" "^2.6.3"
-    ethereumjs-util "^7.1.4"
-
 "@ethereumjs/tx@^3.2.1", "@ethereumjs/tx@^3.3.0", "@ethereumjs/tx@^3.5.0", "@ethereumjs/tx@^3.5.2":
   version "3.5.2"
   resolved "https://registry.yarnpkg.com/@ethereumjs/tx/-/tx-3.5.2.tgz#197b9b6299582ad84f9527ca961466fce2296c1c"
@@ -1865,7 +1857,7 @@
     "@ethereumjs/common" "^2.6.4"
     ethereumjs-util "^7.1.5"
 
-"@ethereumjs/tx@^4.1.2", "@ethereumjs/tx@^4.2.0":
+"@ethereumjs/tx@^4.0.2", "@ethereumjs/tx@^4.1.2", "@ethereumjs/tx@^4.2.0":
   version "4.2.0"
   resolved "https://registry.yarnpkg.com/@ethereumjs/tx/-/tx-4.2.0.tgz#5988ae15daf5a3b3c815493bc6b495e76009e853"
   integrity sha512-1nc6VO4jtFd172BbSnTnDQVr9IYBFl1y4xPzZdtkrkKIncBCkdbgfdRV+MiTkJYAtTxvV12GRZLqBFT1PNK6Yw==
@@ -3235,6 +3227,18 @@
   resolved "https://registry.yarnpkg.com/@juggle/resize-observer/-/resize-observer-3.4.0.tgz#08d6c5e20cf7e4cc02fd181c4b0c225cd31dbb60"
   integrity sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA==
 
+"@keystonehq/base-eth-keyring@^0.14.1":
+  version "0.14.1"
+  resolved "https://registry.yarnpkg.com/@keystonehq/base-eth-keyring/-/base-eth-keyring-0.14.1.tgz#b838524678e5d3e70c0f1e9e1089baece6ef5f87"
+  integrity sha512-rhsbN7YlwWEcaUcwapApZe4EC/xQFJVnU0CpzLN0r9b2nqyEp8q9oz42jPr8W6vXHD72bezAZKMvqU/6rCecQQ==
+  dependencies:
+    "@ethereumjs/tx" "^4.0.2"
+    "@ethereumjs/util" "^8.0.0"
+    "@keystonehq/bc-ur-registry-eth" "^0.19.1"
+    hdkey "^2.0.1"
+    rlp "^3.0.0"
+    uuid "^8.3.2"
+
 "@keystonehq/base-eth-keyring@^0.3.2":
   version "0.3.2"
   resolved "https://registry.yarnpkg.com/@keystonehq/base-eth-keyring/-/base-eth-keyring-0.3.2.tgz#71efe1495d4931fab5fd0016c8722fe5d9657da9"
@@ -3257,25 +3261,13 @@
     hdkey "^2.0.1"
     uuid "^8.3.2"
 
-"@keystonehq/base-eth-keyring@^0.7.1":
-  version "0.7.1"
-  resolved "https://registry.yarnpkg.com/@keystonehq/base-eth-keyring/-/base-eth-keyring-0.7.1.tgz#64517d1b2a032679d81c35e37815c27bbed6c537"
-  integrity sha512-bhX4Psq26U0Ik/3vPM9dwnHt2ffEHeSzClCLNviydNDTc+y0nT4RJVt//ckxg3y73Hmk4s/MpkNxZli8E/Rwxg==
-  dependencies:
-    "@ethereumjs/tx" "3.5.1"
-    "@ethereumjs/util" "^8.0.0"
-    "@keystonehq/bc-ur-registry-eth" "^0.12.1"
-    hdkey "^2.0.1"
-    rlp "^3.0.0"
-    uuid "^8.3.2"
-
-"@keystonehq/bc-ur-registry-eth@^0.12.1":
-  version "0.12.1"
-  resolved "https://registry.yarnpkg.com/@keystonehq/bc-ur-registry-eth/-/bc-ur-registry-eth-0.12.1.tgz#c8e9227b58d5229210af1cd2cd34601e78a32046"
-  integrity sha512-MhEbYdPI/6zB8oGvx+ZELGmmWLJmaGjPGT6I1El0rmG4dr2koPBPSQGCTboKV+poQVo9ySd8VH0HQw9+QPI70Q==
+"@keystonehq/bc-ur-registry-eth@^0.19.1":
+  version "0.19.1"
+  resolved "https://registry.yarnpkg.com/@keystonehq/bc-ur-registry-eth/-/bc-ur-registry-eth-0.19.1.tgz#eac508b9d15d17c0abd00b107691585f9c789ffc"
+  integrity sha512-5+skb1zsmMEIGZCbk+4KssZTpLMTriaFlt+Lc6pZLmxexXrX8a/9aHoho3asOqf7GeXXqkB9YKs8i8TN/hbaHA==
   dependencies:
     "@ethereumjs/util" "^8.0.0"
-    "@keystonehq/bc-ur-registry" "^0.5.0-alpha.5"
+    "@keystonehq/bc-ur-registry" "^0.6.0"
     hdkey "^2.0.1"
     uuid "^8.3.2"
 
@@ -3327,6 +3319,27 @@
     base58check "^2.0.0"
     tslib "^2.3.0"
 
+"@keystonehq/bc-ur-registry@^0.6.0":
+  version "0.6.4"
+  resolved "https://registry.yarnpkg.com/@keystonehq/bc-ur-registry/-/bc-ur-registry-0.6.4.tgz#9c57ff9687cafdc0d2bbd04dc36676d3a38c1485"
+  integrity sha512-j8Uy44DuAkvYkbf0jMxRY3UizJfn8wsEQr7GS3miRF44vcq7k0/yemVkftbn3jQ+0JYaUXf5wY7lVpLhAeW5nQ==
+  dependencies:
+    "@ngraveio/bc-ur" "^1.1.5"
+    bs58check "^2.1.2"
+    tslib "^2.3.0"
+
+"@keystonehq/metamask-airgapped-keyring@^0.13.1":
+  version "0.13.1"
+  resolved "https://registry.yarnpkg.com/@keystonehq/metamask-airgapped-keyring/-/metamask-airgapped-keyring-0.13.1.tgz#286be5bd2fa1b2a43dc749c4501270cc70701e9d"
+  integrity sha512-muEBn/EXHCMtW2EJpLYRCW+3QVyLVCn/BHLPOxqx+rEOJnOZZexMR91fmCLSYo86v27DQMs76nlsnHc2WcGBng==
+  dependencies:
+    "@ethereumjs/tx" "^4.0.2"
+    "@keystonehq/base-eth-keyring" "^0.14.1"
+    "@keystonehq/bc-ur-registry-eth" "^0.19.1"
+    "@metamask/obs-store" "^7.0.0"
+    rlp "^2.2.6"
+    uuid "^8.3.2"
+
 "@keystonehq/metamask-airgapped-keyring@^0.2.2":
   version "0.2.2"
   resolved "https://registry.yarnpkg.com/@keystonehq/metamask-airgapped-keyring/-/metamask-airgapped-keyring-0.2.2.tgz#8beb3e3fddf814be05e3c3178f973769b3ab40d7"
@@ -3351,18 +3364,6 @@
     rlp "^2.2.6"
     uuid "^8.3.2"
 
-"@keystonehq/metamask-airgapped-keyring@^0.6.1":
-  version "0.6.1"
-  resolved "https://registry.yarnpkg.com/@keystonehq/metamask-airgapped-keyring/-/metamask-airgapped-keyring-0.6.1.tgz#e4858586e054d10dcf6b03827225ac0ee0f6563f"
-  integrity sha512-e8WQv79MTec8cFhUMP1dYFpgEzr/1Jd33Ir1NatzbpSUiD6Vdjp1Dao+Un2V7IaORsRAbJmQMplmjztzcb4bHQ==
-  dependencies:
-    "@ethereumjs/tx" "^3.3.0"
-    "@keystonehq/base-eth-keyring" "^0.7.1"
-    "@keystonehq/bc-ur-registry-eth" "^0.12.1"
-    "@metamask/obs-store" "^7.0.0"
-    rlp "^2.2.6"
-    uuid "^8.3.2"
-
 "@keystonehq/ur-decoder@^0.6.1":
   version "0.6.1"
   resolved "https://registry.yarnpkg.com/@keystonehq/ur-decoder/-/ur-decoder-0.6.1.tgz#1034da3ad459e053ed8e4e4c824e24a5e24a8589"
@@ -3623,7 +3624,7 @@
     "@metamask/controller-utils" "^3.0.0"
     immer "^9.0.6"
 
-"@metamask/base-controller@^3.0.0", "@metamask/base-controller@^3.1.0", "@metamask/base-controller@^3.2.1", "@metamask/base-controller@^3.2.3":
+"@metamask/base-controller@^3.0.0", "@metamask/base-controller@^3.2.1", "@metamask/base-controller@^3.2.3":
   version "3.2.3"
   resolved "https://registry.yarnpkg.com/@metamask/base-controller/-/base-controller-3.2.3.tgz#7436a14f6789acf0814952dabaa70ee4fb7d473c"
   integrity sha512-k66oZe7BOEx0D5N5X8feE/32QlrUTmiEHHAZU/yCac2+VHllJOCEQV/cTeaAtgepnEf8O7SskvYZN+eIjgS99w==
@@ -3631,10 +3632,20 @@
     "@metamask/utils" "^8.1.0"
     immer "^9.0.6"
 
-"@metamask/browser-passworder@^4.0.2":
-  version "4.1.0"
-  resolved "https://registry.yarnpkg.com/@metamask/browser-passworder/-/browser-passworder-4.1.0.tgz#d515db2ffd69ecab813a688e2b7553f2766c5e79"
-  integrity sha512-FBvah1mPte5HudQdkgqAh2+Zc75T9kYxey+dCtHIj9gKohkHDcIA1bTOPLk0bBH+6PnOzYNPG8devvH04GOmPA==
+"@metamask/base-controller@^4.0.0":
+  version "4.0.0"
+  resolved "https://registry.yarnpkg.com/@metamask/base-controller/-/base-controller-4.0.0.tgz#f3b86923a8a4f7bf5a35f3e3f165c0c25ca7cc40"
+  integrity sha512-ajG/1vXt3USkxEoYQd8aTckXqgMiuD4StRziTxXt0p5ROkKRZOp9luhwYrW/EBLJtdNEYXLAK5864q9okfRJHQ==
+  dependencies:
+    "@metamask/utils" "^8.2.0"
+    immer "^9.0.6"
+
+"@metamask/browser-passworder@^4.1.0":
+  version "4.3.0"
+  resolved "https://registry.yarnpkg.com/@metamask/browser-passworder/-/browser-passworder-4.3.0.tgz#62c200750efcea864bd31d685120331859e1ab1e"
+  integrity sha512-RU1TVVV5DkbZRr6zPYg0NkexZ0/T2LCKNvF3A50jvUweyxDFuoNbSTN6z8K3Fy8O6/X2JQ1yyAbVzxZLq0qrGg==
+  dependencies:
+    "@metamask/utils" "^8.2.0"
 
 "@metamask/build-utils@^1.0.0":
   version "1.0.0"
@@ -3656,7 +3667,7 @@
   resolved "https://registry.yarnpkg.com/@metamask/contract-metadata/-/contract-metadata-2.2.0.tgz#277764d0d56e37180ae7644a9d11eb96295b36fc"
   integrity sha512-SM6A4C7vXNbVpgMTX67kfW8QWvu3eSXxMZlY5PqZBTkvri1s9zgQ0uwRkK5r2VXNEoVmXCDnnEX/tX5EzzgNUQ==
 
-"@metamask/controller-utils@^3.0.0", "@metamask/controller-utils@^3.4.0", "@metamask/controller-utils@^4.0.0", "@metamask/controller-utils@^4.0.1", "@metamask/controller-utils@^4.2.0", "@metamask/controller-utils@^4.3.2", "@metamask/controller-utils@^5.0.2":
+"@metamask/controller-utils@^3.0.0", "@metamask/controller-utils@^3.4.0", "@metamask/controller-utils@^4.0.0", "@metamask/controller-utils@^4.0.1", "@metamask/controller-utils@^4.3.2", "@metamask/controller-utils@^5.0.2", "@metamask/controller-utils@^6.0.0":
   version "3.4.0"
   resolved "https://registry.yarnpkg.com/@metamask/controller-utils/-/controller-utils-3.4.0.tgz#3714799a3e2648cd758272612578238749e3e11b"
   integrity sha512-/++y7qXUd9+aRzOklypfzmehO87QVKndlJXsbLRk36W5L5DJo4lrR2pd/IBbwbWEhFJWHhlfbMD+T+gEBvIftw==
@@ -3743,28 +3754,18 @@
     "@metamask/safe-event-emitter" "^3.0.0"
     "@metamask/utils" "^5.0.1"
 
-"@metamask/eth-keyring-controller@^10.0.1":
-  version "10.0.1"
-  resolved "https://registry.yarnpkg.com/@metamask/eth-keyring-controller/-/eth-keyring-controller-10.0.1.tgz#732ccd7156b0139da352b028cd921dfbed05992e"
-  integrity sha512-oLjBT/UG4N3IjSWW/OZGkZRsUBtUstSS2yOPQJGgWKn4SL5r8sj6XZMUNRipMLBdXZTYPOuAFxhc+2pSlWh8Sw==
+"@metamask/eth-keyring-controller@^13.0.1":
+  version "13.0.1"
+  resolved "https://registry.yarnpkg.com/@metamask/eth-keyring-controller/-/eth-keyring-controller-13.0.1.tgz#9756a70ed2ea4f4dc6a8c335ac55b6322990e435"
+  integrity sha512-zxULUAAR4CUiIw5lYeELfkyKqfxoepbRjxpEJ9OaSPMZz66oVQGCxIyzKLgXe5i782WfGEihTHLHj338A0RLZw==
   dependencies:
-    "@metamask/browser-passworder" "^4.0.2"
+    "@ethereumjs/tx" "^4.2.0"
+    "@metamask/browser-passworder" "^4.1.0"
     "@metamask/eth-hd-keyring" "^6.0.0"
-    "@metamask/eth-sig-util" "5.0.2"
+    "@metamask/eth-sig-util" "^6.0.0"
     "@metamask/eth-simple-keyring" "^5.0.0"
-    obs-store "^4.0.3"
-
-"@metamask/eth-sig-util@5.0.2":
-  version "5.0.2"
-  resolved "https://registry.yarnpkg.com/@metamask/eth-sig-util/-/eth-sig-util-5.0.2.tgz#c518279a6e17a88135a13d53a0b970f145ff8bce"
-  integrity sha512-RU6fG/H6/UlBol221uBkq5C7w3TwLK611nEZliO2u+kO0vHKGBXnIPlhI0tzKUigjhUeOd9mhCNbNvhh0LKt9Q==
-  dependencies:
-    "@ethereumjs/util" "^8.0.0"
-    bn.js "^4.11.8"
-    ethereum-cryptography "^1.1.2"
-    ethjs-util "^0.1.6"
-    tweetnacl "^1.0.3"
-    tweetnacl-util "^0.15.1"
+    "@metamask/obs-store" "^8.1.0"
+    "@metamask/utils" "^8.1.0"
 
 "@metamask/eth-sig-util@^4.0.1":
   version "4.0.1"
@@ -3854,18 +3855,17 @@
     "@metamask/safe-event-emitter" "^3.0.0"
     "@metamask/utils" "^8.1.0"
 
-"@metamask/keyring-controller@^6.0.0":
-  version "6.1.0"
-  resolved "https://registry.yarnpkg.com/@metamask/keyring-controller/-/keyring-controller-6.1.0.tgz#09528297bcc47a57355b9328d3ecdc94e0710d95"
-  integrity sha512-X+unaoqgt1ol6p32fCprmYDzU29Mhgn3mEvqI3lHkXSEjna+wFyf4l3akxlZSmn/nobJJugcw2IUkq1EQHAxTA==
+"@metamask/keyring-controller@^7.5.0":
+  version "7.5.0"
+  resolved "https://registry.yarnpkg.com/@metamask/keyring-controller/-/keyring-controller-7.5.0.tgz#7c168a0ffe884aaefb37529643ae1bf2a6071828"
+  integrity sha512-bmVOEQYrSjb/GwRbcHNCOaDn3KeBFrgMv/wLlIVlrYT8tXRA0ZsGTFyt60aaPX4IqYj0Z8vGKb9K/hhsPpYxZg==
   dependencies:
-    "@keystonehq/metamask-airgapped-keyring" "^0.6.1"
-    "@metamask/base-controller" "^3.1.0"
-    "@metamask/controller-utils" "^4.2.0"
-    "@metamask/eth-keyring-controller" "^10.0.1"
-    "@metamask/eth-sig-util" "^6.0.0"
-    "@metamask/message-manager" "^7.1.0"
-    "@metamask/preferences-controller" "^4.2.0"
+    "@keystonehq/metamask-airgapped-keyring" "^0.13.1"
+    "@metamask/base-controller" "^3.2.1"
+    "@metamask/eth-keyring-controller" "^13.0.1"
+    "@metamask/message-manager" "^7.3.2"
+    "@metamask/preferences-controller" "^4.4.0"
+    "@metamask/utils" "^6.2.0"
     async-mutex "^0.2.6"
     ethereumjs-util "^7.0.10"
     ethereumjs-wallet "^1.0.1"
@@ -3880,7 +3880,7 @@
     "@metamask/controller-utils" "^4.3.2"
     uuid "^8.3.2"
 
-"@metamask/message-manager@^7.0.0", "@metamask/message-manager@^7.1.0":
+"@metamask/message-manager@^7.0.0":
   version "7.3.2"
   resolved "https://registry.yarnpkg.com/@metamask/message-manager/-/message-manager-7.3.2.tgz#8cc742c0e4896aa9086447624a0fab5632040fac"
   integrity sha512-v6yUoaxuoYXNcsRotxZ1FMG5QxxQjP+/c6i2VqdHozA3QQRp6VGF2X2Xa96Z5ZJTEZ4RFDFSgIvYXV3BuS42dg==
@@ -3894,6 +3894,20 @@
     jsonschema "^1.2.4"
     uuid "^8.3.2"
 
+"@metamask/message-manager@^7.3.2":
+  version "7.3.6"
+  resolved "https://registry.yarnpkg.com/@metamask/message-manager/-/message-manager-7.3.6.tgz#86034d11e695d26da1dbbfc736449301eef2644c"
+  integrity sha512-Nz6tSvu64mIKV2VupOWlQD6s3AxJU+dovsg6m3dVjTZkxNu5cSfDV4LhLgeVXEk4RQgWk7BHX1wUndC6bJF9xA==
+  dependencies:
+    "@metamask/base-controller" "^4.0.0"
+    "@metamask/controller-utils" "^6.0.0"
+    "@metamask/eth-sig-util" "^7.0.0"
+    "@metamask/utils" "^8.2.0"
+    "@types/uuid" "^8.3.0"
+    ethereumjs-util "^7.0.10"
+    jsonschema "^1.2.4"
+    uuid "^8.3.2"
+
 "@metamask/metamask-eth-abis@3.0.0":
   version "3.0.0"
   resolved "https://registry.yarnpkg.com/@metamask/metamask-eth-abis/-/metamask-eth-abis-3.0.0.tgz#eccc0746b3ab1ab63000444403819c16e88b5272"
@@ -3939,6 +3953,14 @@
     "@metamask/safe-event-emitter" "^2.0.0"
     through2 "^2.0.3"
 
+"@metamask/obs-store@^8.1.0":
+  version "8.1.0"
+  resolved "https://registry.yarnpkg.com/@metamask/obs-store/-/obs-store-8.1.0.tgz#15a9e2f059104362b1b4c9a265c0730d3b3e83c7"
+  integrity sha512-MBi8UwzWoCQXVMLp7iOCppU9grSqbjshckNryUidx6Ozx1LJH6gNBmqayXLKjPqwNcsPajyh76PMKWYKBYNy2A==
+  dependencies:
+    "@metamask/safe-event-emitter" "^2.0.0"
+    through2 "^2.0.3"
+
 "@metamask/oss-attribution-generator@^2.0.1":
   version "2.0.1"
   resolved "https://registry.yarnpkg.com/@metamask/oss-attribution-generator/-/oss-attribution-generator-2.0.1.tgz#cb9d050a411aea5f890ec261718fdfef627a2d4f"
@@ -3988,7 +4010,7 @@
     elliptic "^6.5.4"
     json-rpc-random-id "^1.0.1"
 
-"@metamask/preferences-controller@^3.0.0", "@metamask/preferences-controller@^4.0.0", "@metamask/preferences-controller@^4.2.0":
+"@metamask/preferences-controller@^3.0.0", "@metamask/preferences-controller@^4.0.0", "@metamask/preferences-controller@^4.4.0":
   version "4.4.3"
   resolved "https://registry.yarnpkg.com/@metamask/preferences-controller/-/preferences-controller-4.4.3.tgz#f0f05793370892d2d7bc9b07e685583a1f4d80c9"
   integrity sha512-ftDRfOEgRrQqFyfZEQk9AVD1YMdP54NvtiBCrlqAG4hiFgBXQbQTcyl0i/jR/cfki8hYMuH1gPdId14CCAJbDQ==
@@ -14086,7 +14108,7 @@ ethereumjs-util@^6.0.0, ethereumjs-util@^6.2.1:
     ethjs-util "0.1.6"
     rlp "^2.2.3"
 
-ethereumjs-util@^7.0.10, ethereumjs-util@^7.0.7, ethereumjs-util@^7.0.8, ethereumjs-util@^7.0.9, ethereumjs-util@^7.1.2, ethereumjs-util@^7.1.4, ethereumjs-util@^7.1.5:
+ethereumjs-util@^7.0.10, ethereumjs-util@^7.0.7, ethereumjs-util@^7.0.8, ethereumjs-util@^7.0.9, ethereumjs-util@^7.1.2, ethereumjs-util@^7.1.5:
   version "7.1.5"
   resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-7.1.5.tgz#9ecf04861e4fbbeed7465ece5f23317ad1129181"
   integrity sha512-SDl5kKrQAudFBUe5OJM9Ac6WmMyYmXX/6sTmLZ3ffG2eY6ZIGBes3pEDxNN6V72WyOw4CPD5RomKdsa8DAAwLg==

From 7789cf054c06d183e22de95304c9f69a9bf8dd6f Mon Sep 17 00:00:00 2001
From: gantunesr <gustavoantunesrod@gmail.com>
Date: Thu, 7 Dec 2023 14:26:06 -0300
Subject: [PATCH 02/18] chore: update keyring-controller patch

---
 ... @metamask+keyring-controller+7.5.0.patch} | 54 ++++++++-----------
 1 file changed, 23 insertions(+), 31 deletions(-)
 rename patches/{@metamask+keyring-controller+6.1.0.patch => @metamask+keyring-controller+7.5.0.patch} (68%)

diff --git a/patches/@metamask+keyring-controller+6.1.0.patch b/patches/@metamask+keyring-controller+7.5.0.patch
similarity index 68%
rename from patches/@metamask+keyring-controller+6.1.0.patch
rename to patches/@metamask+keyring-controller+7.5.0.patch
index c429985437f..9753061eb43 100644
--- a/patches/@metamask+keyring-controller+6.1.0.patch
+++ b/patches/@metamask+keyring-controller+7.5.0.patch
@@ -1,13 +1,14 @@
 diff --git a/node_modules/@metamask/keyring-controller/dist/KeyringController.d.ts b/node_modules/@metamask/keyring-controller/dist/KeyringController.d.ts
-index dff777b..a61b5ed 100644
+index a05f2a9..7e6b3a6 100644
 --- a/node_modules/@metamask/keyring-controller/dist/KeyringController.d.ts
 +++ b/node_modules/@metamask/keyring-controller/dist/KeyringController.d.ts
-@@ -1,3 +1,4 @@
+@@ -1,4 +1,5 @@
+ import type { TxData, TypedTransaction } from '@ethereumjs/tx';
 +import { KeyringController as EthKeyringController } from '@metamask/eth-keyring-controller';
- import { MetaMaskKeyring as QRKeyring, IKeyringState as IQRKeyringState } from '@keystonehq/metamask-airgapped-keyring';
- import { BaseControllerV2, RestrictedControllerMessenger } from '@metamask/base-controller';
- import { PreferencesController } from '@metamask/preferences-controller';
-@@ -141,6 +142,18 @@ export declare class KeyringController extends BaseControllerV2<typeof name, Key
+ import { type MetaMaskKeyring as QRKeyring, type IKeyringState as IQRKeyringState } from '@keystonehq/metamask-airgapped-keyring';
+ import type { RestrictedControllerMessenger } from '@metamask/base-controller';
+ import { BaseControllerV2 } from '@metamask/base-controller';
+@@ -167,6 +168,19 @@ export declare class KeyringController extends BaseControllerV2<typeof name, Key
       * @param opts.state - Initial state to set on this controller.
       */
      constructor({ removeIdentity, syncIdentities, updateIdentities, setSelectedAddress, setAccountLabel, encryptor, keyringBuilders, cacheEncryptionKey, messenger, state, }: KeyringControllerOptions);
@@ -20,32 +21,22 @@ index dff777b..a61b5ed 100644
 +     * ===============================================================================
 +     */
 +    /**
-+      * Gets the internal keyring controller.
-+    */
++     * Gets the internal keyring controller.
++     */
 +    getEthKeyringController(): typeof EthKeyringController;
++
      /**
       * Adds a new account to the default (first) HD seed phrase keyring.
       *
-@@ -342,7 +355,10 @@ export declare class KeyringController extends BaseControllerV2<typeof name, Key
-     }[]>;
-     unlockQRHardwareWalletAccount(index: number): Promise<void>;
-     getAccountKeyringType(account: string): Promise<KeyringTypes>;
--    forgetQRDevice(): Promise<void>;
-+    forgetQRDevice(): Promise<{
-+        removedAccounts: string[];
-+        remainingAccounts: string[];
-+    }>;
- }
- export default KeyringController;
- //# sourceMappingURL=KeyringController.d.ts.map
 diff --git a/node_modules/@metamask/keyring-controller/dist/KeyringController.js b/node_modules/@metamask/keyring-controller/dist/KeyringController.js
-index c905cc0..16f35e4 100644
+index c4dd1d0..75d5848 100644
 --- a/node_modules/@metamask/keyring-controller/dist/KeyringController.js
 +++ b/node_modules/@metamask/keyring-controller/dist/KeyringController.js
-@@ -139,6 +139,19 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
-         this.setSelectedAddress = setSelectedAddress;
+@@ -154,6 +154,21 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
          this.setAccountLabel = setAccountLabel;
+         __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_registerMessageHandlers).call(this);
      }
++    
 +    /**
 +     * ============================== PATCH INFORMATION ==============================
 +     * This patch was added for ledger integration. It adds a new method to the
@@ -54,24 +45,25 @@ index c905cc0..16f35e4 100644
 +     * ===============================================================================
 +     */
 +    /**
-+      * Gets the internal keyring controller.
-+    */
++     * Gets the internal keyring controller.
++     */
 +    getEthKeyringController() {
 +        return __classPrivateFieldGet(this, _KeyringController_keyring, "f");
 +    }
++
      /**
       * Adds a new account to the default (first) HD seed phrase keyring.
       *
-@@ -678,13 +691,21 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
+@@ -745,13 +760,21 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
      }
      forgetQRDevice() {
          return __awaiter(this, void 0, void 0, function* () {
 +            /**
-+              * ============================== PATCH INFORMATION ==============================
-+              * This patch addresses an issue regarding the forget device functionality. It
-+              * improves the logic  to correctly remove the QR accounts and update the
-+              * identities as needed.
-+              * ===============================================================================
++             * ============================== PATCH INFORMATION ==============================
++             * This patch addresses an issue regarding the forget device functionality. It
++             * improves the logic  to correctly remove the QR accounts and update the
++             * identities as needed.
++             * ===============================================================================
 +            */
              const keyring = yield this.getOrAddQRKeyring();
 +            const allAccounts = (yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").getAccounts());

From d63f79c453cdc57cd9aa71eef9e30461378e74b8 Mon Sep 17 00:00:00 2001
From: gantunesr <gustavoantunesrod@gmail.com>
Date: Thu, 7 Dec 2023 14:52:22 -0300
Subject: [PATCH 03/18] fix: update keyring-controller constructor

---
 app/core/Engine.ts | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/app/core/Engine.ts b/app/core/Engine.ts
index aeb9229b708..b39f48d3ee8 100644
--- a/app/core/Engine.ts
+++ b/app/core/Engine.ts
@@ -454,7 +454,11 @@ class Engine {
         ],
         allowedActions: ['KeyringController:getState'],
       }),
-      state: initialKeyringState || initialState.KeyringController,
+      state: {
+        vault:
+          initialKeyringState?.vault || initialState.KeyringController?.vault,
+      },
+      // @ts-expect-error To Do: Update the type of QRHardwareKeyring to Keyring<Json>
       keyringBuilders: [qrKeyringBuilder, ledgerKeyringBuilder],
     });
 

From 55add8e34613b25dc5b4fcf1ef5ba621bd470f3e Mon Sep 17 00:00:00 2001
From: gantunesr <gustavoantunesrod@gmail.com>
Date: Fri, 8 Dec 2023 08:26:44 -0300
Subject: [PATCH 04/18] chore: update data type from string to Hex

---
 app/components/UI/AccountSelectorList/AccountSelectorList.tsx | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/app/components/UI/AccountSelectorList/AccountSelectorList.tsx b/app/components/UI/AccountSelectorList/AccountSelectorList.tsx
index 5acff4ddaa5..9fa760ce7a1 100644
--- a/app/components/UI/AccountSelectorList/AccountSelectorList.tsx
+++ b/app/components/UI/AccountSelectorList/AccountSelectorList.tsx
@@ -4,6 +4,7 @@ import { Alert, ListRenderItem, Platform, View } from 'react-native';
 import { FlatList } from 'react-native-gesture-handler';
 import { useSelector } from 'react-redux';
 import { KeyringTypes } from '@metamask/keyring-controller';
+import type { Hex } from '@metamask/utils';
 
 // External dependencies.
 import Cell, {
@@ -80,7 +81,7 @@ const AccountSelectorList = ({
       isSelected,
       index,
     }: {
-      address: string;
+      address: Hex;
       imported: boolean;
       isSelected: boolean;
       index: number;

From f195f33fda4f9b77cb42594bdb2e9e371cae9c49 Mon Sep 17 00:00:00 2001
From: gantunesr <gustavoantunesrod@gmail.com>
Date: Fri, 8 Dec 2023 08:27:11 -0300
Subject: [PATCH 05/18] test: update keyring-controller mock state

---
 app/core/BackupVault/backupVault.test.ts | 1 -
 1 file changed, 1 deletion(-)

diff --git a/app/core/BackupVault/backupVault.test.ts b/app/core/BackupVault/backupVault.test.ts
index 605af3b12b1..1d230351609 100644
--- a/app/core/BackupVault/backupVault.test.ts
+++ b/app/core/BackupVault/backupVault.test.ts
@@ -17,7 +17,6 @@ describe('backupVault', () => {
       vault: undefined,
       keyrings: [],
       isUnlocked: false,
-      keyringTypes: [],
     };
     const response = await backupVault(keyringState);
     expect(response.success).toBe(false);

From be50074b06110e41da710b9f466b226cabaa4585 Mon Sep 17 00:00:00 2001
From: gantunesr <gustavoantunesrod@gmail.com>
Date: Fri, 8 Dec 2023 08:27:44 -0300
Subject: [PATCH 06/18] feat: udpate ledger core methods to not use
 ethKeyringController directly

---
 app/core/Ledger/Ledger.ts | 70 ++++++++++-----------------------------
 1 file changed, 17 insertions(+), 53 deletions(-)

diff --git a/app/core/Ledger/Ledger.ts b/app/core/Ledger/Ledger.ts
index aae680d1697..4b537211b91 100644
--- a/app/core/Ledger/Ledger.ts
+++ b/app/core/Ledger/Ledger.ts
@@ -1,52 +1,20 @@
 import Engine from '../Engine';
-import {
-  KeyringController,
-  SignTypedDataVersion,
-} from '@metamask/keyring-controller';
+import { SignTypedDataVersion } from '@metamask/keyring-controller';
 import type BleTransport from '@ledgerhq/react-native-hw-transport-ble';
 import LedgerKeyring, {
   SerializationOptions,
 } from '@consensys/ledgerhq-metamask-keyring';
 import ExtendedKeyringTypes from '../../constants/keyringTypes';
 
-/**
- * Get EthKeyringController from KeyringController
- *
- * @returns The EthKeyringController
- */
-const getEthKeyringController = () => {
-  const keyringController: KeyringController = Engine.context.KeyringController;
-  return keyringController.getEthKeyringController();
-};
-
-/**
- * A method replicate #fullupdate from the keyring controller.
- */
-export const syncKeyringState = async (): Promise<void> => {
-  const keyringController = Engine.context.KeyringController;
-  const ethKeyringController = getEthKeyringController();
-  const { vault } = ethKeyringController.store.getState();
-  const { keyrings, isUnlocked, encryptionKey, encryptionSalt } =
-    ethKeyringController.memStore.getState();
-
-  keyringController.update(() => ({
-    vault,
-    keyrings,
-    isUnlocked,
-    encryptionKey,
-    encryptionSalt,
-  }));
-};
-
 /**
  * Add LedgerKeyring.
  *
  * @returns The Ledger Keyring
  */
-export const addLedgerKeyring = async (): Promise<LedgerKeyring> =>
-  (await getEthKeyringController().addNewKeyring(
-    ExtendedKeyringTypes.ledger,
-  )) as unknown as LedgerKeyring;
+export const addLedgerKeyring = async (): Promise<LedgerKeyring> => {
+  const keyringController = Engine.context.KeyringController;
+  return await keyringController.addNewKeyring(ExtendedKeyringTypes.ledger);
+};
 
 /**
  * Retrieve the existing LedgerKeyring or create a new one.
@@ -54,9 +22,10 @@ export const addLedgerKeyring = async (): Promise<LedgerKeyring> =>
  * @returns The stored Ledger Keyring
  */
 export const getLedgerKeyring = async (): Promise<LedgerKeyring> => {
-  const keyring = getEthKeyringController().getKeyringsByType(
+  const keyringController = Engine.context.KeyringController;
+  const keyring = keyringController.getKeyringsByType(
     ExtendedKeyringTypes.ledger,
-  )[0] as unknown as LedgerKeyring;
+  );
 
   if (keyring) {
     return keyring;
@@ -74,11 +43,9 @@ export const restoreLedgerKeyring = async (
   keyringSerialized: SerializationOptions,
 ): Promise<void> => {
   const keyringController = Engine.context.KeyringController;
-  const ethKeyringController = getEthKeyringController();
 
   (await getLedgerKeyring()).deserialize(keyringSerialized);
-  keyringController.updateIdentities(await ethKeyringController.getAccounts());
-  await syncKeyringState();
+  keyringController.updateIdentities(await keyringController.getAccounts());
 };
 
 /**
@@ -108,11 +75,10 @@ export const unlockLedgerDefaultAccount = async (): Promise<{
   balance: string;
 }> => {
   const keyringController = Engine.context.KeyringController;
-  const ethKeyringController = getEthKeyringController();
   const keyring = await getLedgerKeyring();
-  const oldAccounts = await ethKeyringController.getAccounts();
-  await ethKeyringController.addNewAccount(keyring);
-  const newAccounts = await ethKeyringController.getAccounts();
+  const oldAccounts = await keyringController.getAccounts();
+  keyringController.addNewAccountForKeyring(keyring);
+  const newAccounts = await keyringController.getAccounts();
 
   keyringController.updateIdentities(newAccounts);
   newAccounts.forEach((address: string) => {
@@ -124,8 +90,7 @@ export const unlockLedgerDefaultAccount = async (): Promise<{
       keyringController.setSelectedAddress(address);
     }
   });
-  await ethKeyringController.persistAllKeyrings();
-  await syncKeyringState();
+  await keyringController.persistAllKeyrings();
 
   const address = await keyring.getDefaultAccount();
   return {
@@ -155,15 +120,13 @@ export const closeRunningAppOnLedger = async (): Promise<void> => {
  */
 export const forgetLedger = async (): Promise<void> => {
   const keyringController = Engine.context.KeyringController;
-  const ethKeyringController = getEthKeyringController();
   const keyring = await getLedgerKeyring();
   keyring.forgetDevice();
 
-  const accounts: string[] = await ethKeyringController.getAccounts();
+  const accounts: string[] = await keyringController.getAccounts();
   keyringController.setSelectedAddress(accounts[0]);
 
-  await ethKeyringController.persistAllKeyrings();
-  await syncKeyringState();
+  await keyringController.persistAllKeyrings();
 };
 
 /**
@@ -188,8 +151,9 @@ export const ledgerSignTypedMessage = async (
   },
   version: SignTypedDataVersion,
 ): Promise<string> => {
+  const keyringController = Engine.context.KeyringController;
   await getLedgerKeyring();
-  return await getEthKeyringController().signTypedMessage(
+  return await keyringController.signTypedMessage(
     {
       from: messageParams.from,
       data: messageParams.data as

From 522b894f90fbd7c33d1df9ed88f72165ada52822 Mon Sep 17 00:00:00 2001
From: gantunesr <gustavoantunesrod@gmail.com>
Date: Fri, 8 Dec 2023 23:34:21 -0300
Subject: [PATCH 07/18] test: update initial background state

---
 app/util/test/initial-background-state.json | 1 -
 1 file changed, 1 deletion(-)

diff --git a/app/util/test/initial-background-state.json b/app/util/test/initial-background-state.json
index 01ec9c5381c..776ca7e24fb 100644
--- a/app/util/test/initial-background-state.json
+++ b/app/util/test/initial-background-state.json
@@ -1,7 +1,6 @@
 {
   "KeyringController": {
     "isUnlocked": false,
-    "keyringTypes": [],
     "keyrings": []
   },
   "LoggingController": {

From 141a001f6d15b06e022bd7aab451db435671994a Mon Sep 17 00:00:00 2001
From: gantunesr <gustavoantunesrod@gmail.com>
Date: Mon, 18 Dec 2023 12:00:09 -0300
Subject: [PATCH 08/18] chore: update keyring-controller patch

---
 patches/@metamask+keyring-controller+7.5.0.patch | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/patches/@metamask+keyring-controller+7.5.0.patch b/patches/@metamask+keyring-controller+7.5.0.patch
index 9753061eb43..0ab8d149670 100644
--- a/patches/@metamask+keyring-controller+7.5.0.patch
+++ b/patches/@metamask+keyring-controller+7.5.0.patch
@@ -1,5 +1,5 @@
 diff --git a/node_modules/@metamask/keyring-controller/dist/KeyringController.d.ts b/node_modules/@metamask/keyring-controller/dist/KeyringController.d.ts
-index a05f2a9..7e6b3a6 100644
+index a05f2a9..1291081 100644
 --- a/node_modules/@metamask/keyring-controller/dist/KeyringController.d.ts
 +++ b/node_modules/@metamask/keyring-controller/dist/KeyringController.d.ts
 @@ -1,4 +1,5 @@
@@ -28,6 +28,19 @@ index a05f2a9..7e6b3a6 100644
      /**
       * Adds a new account to the default (first) HD seed phrase keyring.
       *
+@@ -407,7 +421,10 @@ export declare class KeyringController extends BaseControllerV2<typeof name, Key
+     }[]>;
+     unlockQRHardwareWalletAccount(index: number): Promise<void>;
+     getAccountKeyringType(account: string): Promise<string>;
+-    forgetQRDevice(): Promise<void>;
++    forgetQRDevice(): Promise<{
++        removedAccounts: string[];
++        remainingAccounts: string[];
++    }>;
+ }
+ export default KeyringController;
+ //# sourceMappingURL=KeyringController.d.ts.map
+\ No newline at end of file
 diff --git a/node_modules/@metamask/keyring-controller/dist/KeyringController.js b/node_modules/@metamask/keyring-controller/dist/KeyringController.js
 index c4dd1d0..75d5848 100644
 --- a/node_modules/@metamask/keyring-controller/dist/KeyringController.js

From aee0a661908e0262754d77980b34e3b64baeee1b Mon Sep 17 00:00:00 2001
From: gantunesr <gustavoantunesrod@gmail.com>
Date: Mon, 18 Dec 2023 12:40:43 -0300
Subject: [PATCH 09/18] chore: revert core ledger

---
 app/core/Ledger/Ledger.ts | 70 +++++++++++++++++++++++++++++----------
 1 file changed, 53 insertions(+), 17 deletions(-)

diff --git a/app/core/Ledger/Ledger.ts b/app/core/Ledger/Ledger.ts
index 4b537211b91..aae680d1697 100644
--- a/app/core/Ledger/Ledger.ts
+++ b/app/core/Ledger/Ledger.ts
@@ -1,5 +1,8 @@
 import Engine from '../Engine';
-import { SignTypedDataVersion } from '@metamask/keyring-controller';
+import {
+  KeyringController,
+  SignTypedDataVersion,
+} from '@metamask/keyring-controller';
 import type BleTransport from '@ledgerhq/react-native-hw-transport-ble';
 import LedgerKeyring, {
   SerializationOptions,
@@ -7,25 +10,53 @@ import LedgerKeyring, {
 import ExtendedKeyringTypes from '../../constants/keyringTypes';
 
 /**
- * Add LedgerKeyring.
+ * Get EthKeyringController from KeyringController
  *
- * @returns The Ledger Keyring
+ * @returns The EthKeyringController
+ */
+const getEthKeyringController = () => {
+  const keyringController: KeyringController = Engine.context.KeyringController;
+  return keyringController.getEthKeyringController();
+};
+
+/**
+ * A method replicate #fullupdate from the keyring controller.
  */
-export const addLedgerKeyring = async (): Promise<LedgerKeyring> => {
+export const syncKeyringState = async (): Promise<void> => {
   const keyringController = Engine.context.KeyringController;
-  return await keyringController.addNewKeyring(ExtendedKeyringTypes.ledger);
+  const ethKeyringController = getEthKeyringController();
+  const { vault } = ethKeyringController.store.getState();
+  const { keyrings, isUnlocked, encryptionKey, encryptionSalt } =
+    ethKeyringController.memStore.getState();
+
+  keyringController.update(() => ({
+    vault,
+    keyrings,
+    isUnlocked,
+    encryptionKey,
+    encryptionSalt,
+  }));
 };
 
+/**
+ * Add LedgerKeyring.
+ *
+ * @returns The Ledger Keyring
+ */
+export const addLedgerKeyring = async (): Promise<LedgerKeyring> =>
+  (await getEthKeyringController().addNewKeyring(
+    ExtendedKeyringTypes.ledger,
+  )) as unknown as LedgerKeyring;
+
 /**
  * Retrieve the existing LedgerKeyring or create a new one.
  *
  * @returns The stored Ledger Keyring
  */
 export const getLedgerKeyring = async (): Promise<LedgerKeyring> => {
-  const keyringController = Engine.context.KeyringController;
-  const keyring = keyringController.getKeyringsByType(
+  const keyring = getEthKeyringController().getKeyringsByType(
     ExtendedKeyringTypes.ledger,
-  );
+  )[0] as unknown as LedgerKeyring;
 
   if (keyring) {
     return keyring;
@@ -43,9 +74,11 @@ export const restoreLedgerKeyring = async (
   keyringSerialized: SerializationOptions,
 ): Promise<void> => {
   const keyringController = Engine.context.KeyringController;
+  const ethKeyringController = getEthKeyringController();
 
   (await getLedgerKeyring()).deserialize(keyringSerialized);
-  keyringController.updateIdentities(await keyringController.getAccounts());
+  keyringController.updateIdentities(await ethKeyringController.getAccounts());
+  await syncKeyringState();
 };
 
 /**
@@ -75,10 +108,11 @@ export const unlockLedgerDefaultAccount = async (): Promise<{
   balance: string;
 }> => {
   const keyringController = Engine.context.KeyringController;
+  const ethKeyringController = getEthKeyringController();
   const keyring = await getLedgerKeyring();
-  const oldAccounts = await keyringController.getAccounts();
-  keyringController.addNewAccountForKeyring(keyring);
-  const newAccounts = await keyringController.getAccounts();
+  const oldAccounts = await ethKeyringController.getAccounts();
+  await ethKeyringController.addNewAccount(keyring);
+  const newAccounts = await ethKeyringController.getAccounts();
 
   keyringController.updateIdentities(newAccounts);
   newAccounts.forEach((address: string) => {
@@ -90,7 +124,8 @@ export const unlockLedgerDefaultAccount = async (): Promise<{
       keyringController.setSelectedAddress(address);
     }
   });
-  await keyringController.persistAllKeyrings();
+  await ethKeyringController.persistAllKeyrings();
+  await syncKeyringState();
 
   const address = await keyring.getDefaultAccount();
   return {
@@ -120,13 +155,15 @@ export const closeRunningAppOnLedger = async (): Promise<void> => {
  */
 export const forgetLedger = async (): Promise<void> => {
   const keyringController = Engine.context.KeyringController;
+  const ethKeyringController = getEthKeyringController();
   const keyring = await getLedgerKeyring();
   keyring.forgetDevice();
 
-  const accounts: string[] = await keyringController.getAccounts();
+  const accounts: string[] = await ethKeyringController.getAccounts();
   keyringController.setSelectedAddress(accounts[0]);
 
-  await keyringController.persistAllKeyrings();
+  await ethKeyringController.persistAllKeyrings();
+  await syncKeyringState();
 };
 
 /**
@@ -151,9 +188,8 @@ export const ledgerSignTypedMessage = async (
   },
   version: SignTypedDataVersion,
 ): Promise<string> => {
-  const keyringController = Engine.context.KeyringController;
   await getLedgerKeyring();
-  return await keyringController.signTypedMessage(
+  return await getEthKeyringController().signTypedMessage(
     {
       from: messageParams.from,
       data: messageParams.data as

From b873c19000e2a471130a16f49f8559cdaf45e9db Mon Sep 17 00:00:00 2001
From: gantunesr <gustavoantunesrod@gmail.com>
Date: Mon, 18 Dec 2023 13:22:59 -0300
Subject: [PATCH 10/18] test: fix keyring-controller initial state

---
 app/core/Engine.test.js | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/app/core/Engine.test.js b/app/core/Engine.test.js
index 7ccb393aeec..a9f604b418e 100644
--- a/app/core/Engine.test.js
+++ b/app/core/Engine.test.js
@@ -63,6 +63,14 @@ describe('Engine', () => {
           },
         },
       },
+      KeyringController: {
+        ...backgroundState.KeyringController,
+        vault: {
+          cipher: 'mock-cipher',
+          iv: 'mock-iv',
+          lib: 'original',
+        },
+      },
     };
 
     expect(backgroundState).toStrictEqual(initialState);

From 4d04a355cd574768e1e5f34b0f6dd531476ac6e7 Mon Sep 17 00:00:00 2001
From: gantunesr <gustavoantunesrod@gmail.com>
Date: Mon, 18 Dec 2023 13:23:07 -0300
Subject: [PATCH 11/18] test: fix keyring-controller initial state

---
 app/util/test/initial-background-state.json | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/app/util/test/initial-background-state.json b/app/util/test/initial-background-state.json
index 2a4129024a9..38299fd9e5e 100644
--- a/app/util/test/initial-background-state.json
+++ b/app/util/test/initial-background-state.json
@@ -1,7 +1,12 @@
 {
   "KeyringController": {
     "isUnlocked": false,
-    "keyrings": []
+    "keyrings": [],
+    "vault": {
+      "cipher": "mock-cipher",
+      "iv": "mock-iv",
+      "lib": "original"
+    }
   },
   "LoggingController": {
     "logs": {}

From 9c28c8474cf71f29a9cf4a658207b82f12ff8310 Mon Sep 17 00:00:00 2001
From: gantunesr <gustavoantunesrod@gmail.com>
Date: Mon, 18 Dec 2023 13:50:37 -0300
Subject: [PATCH 12/18] chore: dedupe dependencies

---
 yarn.lock | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/yarn.lock b/yarn.lock
index 27a994508c4..455ddde14d8 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3897,21 +3897,7 @@
     "@metamask/controller-utils" "^4.3.2"
     uuid "^8.3.2"
 
-"@metamask/message-manager@^7.0.0":
-  version "7.3.2"
-  resolved "https://registry.yarnpkg.com/@metamask/message-manager/-/message-manager-7.3.2.tgz#8cc742c0e4896aa9086447624a0fab5632040fac"
-  integrity sha512-v6yUoaxuoYXNcsRotxZ1FMG5QxxQjP+/c6i2VqdHozA3QQRp6VGF2X2Xa96Z5ZJTEZ4RFDFSgIvYXV3BuS42dg==
-  dependencies:
-    "@metamask/base-controller" "^3.2.1"
-    "@metamask/controller-utils" "^4.3.2"
-    "@metamask/eth-sig-util" "^7.0.0"
-    "@metamask/utils" "^6.2.0"
-    "@types/uuid" "^8.3.0"
-    ethereumjs-util "^7.0.10"
-    jsonschema "^1.2.4"
-    uuid "^8.3.2"
-
-"@metamask/message-manager@^7.3.2":
+"@metamask/message-manager@^7.0.0", "@metamask/message-manager@^7.3.2":
   version "7.3.6"
   resolved "https://registry.yarnpkg.com/@metamask/message-manager/-/message-manager-7.3.6.tgz#86034d11e695d26da1dbbfc736449301eef2644c"
   integrity sha512-Nz6tSvu64mIKV2VupOWlQD6s3AxJU+dovsg6m3dVjTZkxNu5cSfDV4LhLgeVXEk4RQgWk7BHX1wUndC6bJF9xA==

From 494b0e281188b3d651c197b6f728ee92e26386da Mon Sep 17 00:00:00 2001
From: gantunesr <gustavoantunesrod@gmail.com>
Date: Mon, 18 Dec 2023 17:16:06 -0300
Subject: [PATCH 13/18] chore: deduplicate dependencies

---
 yarn.lock | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/yarn.lock b/yarn.lock
index 8ff80f0c755..26df30f058f 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1836,14 +1836,6 @@
     "@ethereumjs/common" "^2.0.0"
     ethereumjs-util "^7.0.7"
 
-"@ethereumjs/tx@3.5.1":
-  version "3.5.1"
-  resolved "https://registry.yarnpkg.com/@ethereumjs/tx/-/tx-3.5.1.tgz#8d941b83a602b4a89949c879615f7ea9a90e6671"
-  integrity sha512-xzDrTiu4sqZXUcaBxJ4n4W5FrppwxLxZB4ZDGVLtxSQR4lVuOnFR6RcUHdg1mpUhAPVrmnzLJpxaeXnPxIyhWA==
-  dependencies:
-    "@ethereumjs/common" "^2.6.3"
-    ethereumjs-util "^7.1.4"
-
 "@ethereumjs/tx@^3.2.1", "@ethereumjs/tx@^3.3.0", "@ethereumjs/tx@^3.5.2":
   version "3.5.2"
   resolved "https://registry.yarnpkg.com/@ethereumjs/tx/-/tx-3.5.2.tgz#197b9b6299582ad84f9527ca961466fce2296c1c"

From 85cc326851a6f844a325c4503a8bbfc1ab3f1774 Mon Sep 17 00:00:00 2001
From: gantunesr <gustavoantunesrod@gmail.com>
Date: Mon, 18 Dec 2023 17:27:00 -0300
Subject: [PATCH 14/18] chroe: udpate keyring-controller patch

---
 patches/@metamask+keyring-controller+7.5.0.patch | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/patches/@metamask+keyring-controller+7.5.0.patch b/patches/@metamask+keyring-controller+7.5.0.patch
index 0ab8d149670..6964781acbe 100644
--- a/patches/@metamask+keyring-controller+7.5.0.patch
+++ b/patches/@metamask+keyring-controller+7.5.0.patch
@@ -42,7 +42,7 @@ index a05f2a9..1291081 100644
  //# sourceMappingURL=KeyringController.d.ts.map
 \ No newline at end of file
 diff --git a/node_modules/@metamask/keyring-controller/dist/KeyringController.js b/node_modules/@metamask/keyring-controller/dist/KeyringController.js
-index c4dd1d0..75d5848 100644
+index c4dd1d0..ddc4155 100644
 --- a/node_modules/@metamask/keyring-controller/dist/KeyringController.js
 +++ b/node_modules/@metamask/keyring-controller/dist/KeyringController.js
 @@ -154,6 +154,21 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
@@ -67,7 +67,7 @@ index c4dd1d0..75d5848 100644
      /**
       * Adds a new account to the default (first) HD seed phrase keyring.
       *
-@@ -745,13 +760,21 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
+@@ -745,13 +760,23 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
      }
      forgetQRDevice() {
          return __awaiter(this, void 0, void 0, function* () {
@@ -76,8 +76,10 @@ index c4dd1d0..75d5848 100644
 +             * This patch addresses an issue regarding the forget device functionality. It
 +             * improves the logic  to correctly remove the QR accounts and update the
 +             * identities as needed.
++             * 
++             * Solved in https://github.com/MetaMask/core/pull/3641
 +             * ===============================================================================
-+            */
++             */
              const keyring = yield this.getOrAddQRKeyring();
 +            const allAccounts = (yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").getAccounts());
              keyring.forgetDevice();

From 74f2806faba6fcbd44c5a40742c2760ba928be73 Mon Sep 17 00:00:00 2001
From: gantunesr <gustavoantunesrod@gmail.com>
Date: Mon, 18 Dec 2023 21:51:50 -0300
Subject: [PATCH 15/18] chore: remove references to eth-keyring-controller

---
 app/core/Ledger/Ledger.ts | 64 +++++++++++----------------------------
 1 file changed, 18 insertions(+), 46 deletions(-)

diff --git a/app/core/Ledger/Ledger.ts b/app/core/Ledger/Ledger.ts
index e75440b2779..9fd17672d4a 100644
--- a/app/core/Ledger/Ledger.ts
+++ b/app/core/Ledger/Ledger.ts
@@ -5,6 +5,7 @@ import {
 } from '@metamask/keyring-controller';
 import ExtendedKeyringTypes from '../../constants/keyringTypes';
 
+// Mock interface for the SerializationOptions
 interface SerializationOptions {
   vault: any;
   keyrings: any[];
@@ -13,6 +14,7 @@ interface SerializationOptions {
   encryptionSalt: string;
 }
 
+// Mock interface for the LedgerKeyring
 interface LedgerKeyring {
   setTransport: (transport: any, deviceId: string) => void;
   getAppAndVersion: () => Promise<{ appName: string }>;
@@ -25,44 +27,17 @@ interface LedgerKeyring {
   getName: () => string;
 }
 
-/**
- * Get EthKeyringController from KeyringController
- *
- * @returns The EthKeyringController
- */
-const getEthKeyringController = () => {
-  const keyringController: KeyringController = Engine.context.KeyringController;
-  return keyringController.getEthKeyringController();
-};
-
-/**
- * A method replicate #fullupdate from the keyring controller.
- */
-export const syncKeyringState = async (): Promise<void> => {
-  const keyringController = Engine.context.KeyringController;
-  const ethKeyringController = getEthKeyringController();
-  const { vault } = ethKeyringController.store.getState();
-  const { keyrings, isUnlocked, encryptionKey, encryptionSalt } =
-    ethKeyringController.memStore.getState();
-
-  keyringController.update(() => ({
-    vault,
-    keyrings,
-    isUnlocked,
-    encryptionKey,
-    encryptionSalt,
-  }));
-};
-
 /**
  * Add LedgerKeyring.
  *
  * @returns The Ledger Keyring
  */
-export const addLedgerKeyring = async (): Promise<LedgerKeyring> =>
-  (await getEthKeyringController().addNewKeyring(
+export const addLedgerKeyring = async (): Promise<LedgerKeyring> => {
+  const keyringController = Engine.context.KeyringController;
+  return (await keyringController.addNewKeyring(
     ExtendedKeyringTypes.ledger,
   )) as unknown as LedgerKeyring;
+};
 
 /**
  * Retrieve the existing LedgerKeyring or create a new one.
@@ -70,7 +45,9 @@ export const addLedgerKeyring = async (): Promise<LedgerKeyring> =>
  * @returns The stored Ledger Keyring
  */
 export const getLedgerKeyring = async (): Promise<LedgerKeyring> => {
-  const keyring = getEthKeyringController().getKeyringsByType(
+  const keyringController = Engine.context.KeyringController;
+  // There should only be one ledger keyring.
+  const keyring = keyringController().getKeyringsByType(
     ExtendedKeyringTypes.ledger,
   )[0] as unknown as LedgerKeyring;
 
@@ -90,11 +67,9 @@ export const restoreLedgerKeyring = async (
   keyringSerialized: SerializationOptions,
 ): Promise<void> => {
   const keyringController = Engine.context.KeyringController;
-  const ethKeyringController = getEthKeyringController();
 
   (await getLedgerKeyring()).deserialize(keyringSerialized);
-  keyringController.updateIdentities(await ethKeyringController.getAccounts());
-  await syncKeyringState();
+  keyringController.updateIdentities(await keyringController.getAccounts());
 };
 
 /**
@@ -124,11 +99,10 @@ export const unlockLedgerDefaultAccount = async (): Promise<{
   balance: string;
 }> => {
   const keyringController = Engine.context.KeyringController;
-  const ethKeyringController = getEthKeyringController();
   const keyring = await getLedgerKeyring();
-  const oldAccounts = await ethKeyringController.getAccounts();
-  await ethKeyringController.addNewAccount(keyring);
-  const newAccounts = await ethKeyringController.getAccounts();
+  const oldAccounts = await keyringController.getAccounts();
+  await keyringController.addNewAccountForKeyring(keyring);
+  const newAccounts = await keyringController.getAccounts();
 
   keyringController.updateIdentities(newAccounts);
   newAccounts.forEach((address: string) => {
@@ -140,8 +114,7 @@ export const unlockLedgerDefaultAccount = async (): Promise<{
       keyringController.setSelectedAddress(address);
     }
   });
-  await ethKeyringController.persistAllKeyrings();
-  await syncKeyringState();
+  await keyringController.persistAllKeyrings();
 
   const address = await keyring.getDefaultAccount();
   return {
@@ -171,15 +144,13 @@ export const closeRunningAppOnLedger = async (): Promise<void> => {
  */
 export const forgetLedger = async (): Promise<void> => {
   const keyringController = Engine.context.KeyringController;
-  const ethKeyringController = getEthKeyringController();
   const keyring = await getLedgerKeyring();
   keyring.forgetDevice();
 
-  const accounts: string[] = await ethKeyringController.getAccounts();
+  const accounts: string[] = await keyringController.getAccounts();
   keyringController.setSelectedAddress(accounts[0]);
 
-  await ethKeyringController.persistAllKeyrings();
-  await syncKeyringState();
+  await keyringController.persistAllKeyrings();
 };
 
 /**
@@ -205,7 +176,8 @@ export const ledgerSignTypedMessage = async (
   version: SignTypedDataVersion,
 ): Promise<string> => {
   await getLedgerKeyring();
-  return await getEthKeyringController().signTypedMessage(
+  const keyringController = Engine.context.KeyringController;
+  return await keyringController.signTypedMessage(
     {
       from: messageParams.from,
       data: messageParams.data as

From f89cf0b5d35350a24cfc896768d68d1d11127ade Mon Sep 17 00:00:00 2001
From: gantunesr <gustavoantunesrod@gmail.com>
Date: Wed, 20 Dec 2023 22:28:12 -0300
Subject: [PATCH 16/18] chore: lint

---
 app/core/Ledger/Ledger.ts | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/app/core/Ledger/Ledger.ts b/app/core/Ledger/Ledger.ts
index 9fd17672d4a..869f5e87f67 100644
--- a/app/core/Ledger/Ledger.ts
+++ b/app/core/Ledger/Ledger.ts
@@ -1,8 +1,5 @@
 import Engine from '../Engine';
-import {
-  KeyringController,
-  SignTypedDataVersion,
-} from '@metamask/keyring-controller';
+import { SignTypedDataVersion } from '@metamask/keyring-controller';
 import ExtendedKeyringTypes from '../../constants/keyringTypes';
 
 // Mock interface for the SerializationOptions

From 840658e506da94bb48791070098394058e846149 Mon Sep 17 00:00:00 2001
From: gantunesr <gustavoantunesrod@gmail.com>
Date: Thu, 4 Jan 2024 16:43:12 -0300
Subject: [PATCH 17/18] chore: update KeyringController construction params

---
 app/core/Engine.ts | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/app/core/Engine.ts b/app/core/Engine.ts
index df9c859cb8f..6cf9a0ba62b 100644
--- a/app/core/Engine.ts
+++ b/app/core/Engine.ts
@@ -547,10 +547,7 @@ class Engine {
         ],
         allowedActions: ['KeyringController:getState'],
       }),
-      state: {
-        vault:
-          initialKeyringState?.vault || initialState.KeyringController?.vault,
-      },
+      state: initialKeyringState || initialState.KeyringController,
       // @ts-expect-error To Do: Update the type of QRHardwareKeyring to Keyring<Json>
       keyringBuilders: [qrKeyringBuilder],
     });

From 315fe0408a504860d10c642506910e9bfb1e50d8 Mon Sep 17 00:00:00 2001
From: gantunesr <gustavoantunesrod@gmail.com>
Date: Thu, 4 Jan 2024 16:43:43 -0300
Subject: [PATCH 18/18] fix: use setSelectedAddress from PreferencesController
 instead of KeyringController

---
 app/core/Ledger/Ledger.ts | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/app/core/Ledger/Ledger.ts b/app/core/Ledger/Ledger.ts
index 869f5e87f67..31a84d2f702 100644
--- a/app/core/Ledger/Ledger.ts
+++ b/app/core/Ledger/Ledger.ts
@@ -96,6 +96,7 @@ export const unlockLedgerDefaultAccount = async (): Promise<{
   balance: string;
 }> => {
   const keyringController = Engine.context.KeyringController;
+  const preferencesController = Engine.context.PreferencesController;
   const keyring = await getLedgerKeyring();
   const oldAccounts = await keyringController.getAccounts();
   await keyringController.addNewAccountForKeyring(keyring);
@@ -108,7 +109,7 @@ export const unlockLedgerDefaultAccount = async (): Promise<{
         // The first ledger account is always returned.
         keyringController.setAccountLabel(address, `${keyring.getName()} 1`);
       }
-      keyringController.setSelectedAddress(address);
+      preferencesController.setSelectedAddress(address);
     }
   });
   await keyringController.persistAllKeyrings();
@@ -141,11 +142,12 @@ export const closeRunningAppOnLedger = async (): Promise<void> => {
  */
 export const forgetLedger = async (): Promise<void> => {
   const keyringController = Engine.context.KeyringController;
+  const preferencesController = Engine.context.PreferencesController;
   const keyring = await getLedgerKeyring();
   keyring.forgetDevice();
 
   const accounts: string[] = await keyringController.getAccounts();
-  keyringController.setSelectedAddress(accounts[0]);
+  preferencesController.setSelectedAddress(accounts[0]);
 
   await keyringController.persistAllKeyrings();
 };