From 421e927bfab07c1d58148e7abeb52989d276e023 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Sat, 8 Jul 2023 11:06:42 -0400 Subject: [PATCH 01/67] Update mnemonic util methods --- app/util/SRP/index.test.ts | 48 ------------------- app/util/SRP/index.ts | 3 -- app/util/SRP/onboarding.ts | 29 ------------ app/util/mnemonic/index.test.ts | 81 +++++++++++++++++++++++++++++++++ app/util/mnemonic/index.ts | 55 ++++++++++++++++++++++ 5 files changed, 136 insertions(+), 80 deletions(-) delete mode 100644 app/util/SRP/index.test.ts delete mode 100644 app/util/SRP/index.ts delete mode 100644 app/util/SRP/onboarding.ts create mode 100644 app/util/mnemonic/index.test.ts create mode 100644 app/util/mnemonic/index.ts diff --git a/app/util/SRP/index.test.ts b/app/util/SRP/index.test.ts deleted file mode 100644 index 0fef7767453..00000000000 --- a/app/util/SRP/index.test.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { shuffle, compareSRPs } from './onboarding'; - -const mockSRPArrayOne = [ - 'ar9gx', - 'e97vw', - '95wx4', - 'c93d1', - 'zdiai', - 'h07an', - '78eld', - 'snqx8', - '1o472', - 'ixpwq', - 'p31fg', - 'vfnfy', -]; - -const mockSRPArrayTwo = [ - 'r6rrh', - 'ujfkr', - 'n8n0h', - '9fsgb', - 'obyjo', - 'a8wnk', - 'eqcnj', - '4e55t', - '170tl', - 'uur4s', - '4wf4g', - '242lz', -]; - -describe('SRP::onboarding::shuffle', () => { - it('should shuffle the array', () => { - expect(mockSRPArrayOne.join('')).not.toEqual( - shuffle(mockSRPArrayOne).join(''), - ); - }); -}); - -describe('SRP::onboarding::compareSRPs', () => { - it('should return false', () => { - expect(compareSRPs(mockSRPArrayOne, mockSRPArrayTwo)).toBe(false); - }); - it('should return true', () => { - expect(compareSRPs(mockSRPArrayOne, mockSRPArrayOne)).toBe(true); - }); -}); diff --git a/app/util/SRP/index.ts b/app/util/SRP/index.ts deleted file mode 100644 index 2970198f4c8..00000000000 --- a/app/util/SRP/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { shuffle, compareSRPs } from './onboarding'; - -export { shuffle, compareSRPs }; diff --git a/app/util/SRP/onboarding.ts b/app/util/SRP/onboarding.ts deleted file mode 100644 index cbbb469f079..00000000000 --- a/app/util/SRP/onboarding.ts +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Method to shuffles an array of string. - * - * The previous method was replaced according to the following tutorial. - * https://javascript.info/array-methods#shuffle-an-array - * - * @param array - Array of string. - * @returns Array of string. - */ -// eslint-disable-next-line import/prefer-default-export -export const shuffle = (array: string[]): string[] => { - const shuffledArray = [...array]; - for (let i = array.length - 1; i > 0; i--) { - const j = Math.floor(Math.random() * (i + 1)); - - // Swap elements. - [shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]]; - } - return shuffledArray; -}; - -/** - * Compare two SRP arrays. - * @param validSRP - Array of string with the correct SRP. - * @param input - Array of string with the user's input. - * @returns Boolean indicating with the input matches the valid SRP. - */ -export const compareSRPs = (validSRP: string[], input: string[]): boolean => - validSRP.join('') === input.join(''); diff --git a/app/util/mnemonic/index.test.ts b/app/util/mnemonic/index.test.ts new file mode 100644 index 00000000000..8c19d30c709 --- /dev/null +++ b/app/util/mnemonic/index.test.ts @@ -0,0 +1,81 @@ +import { shuffle, compareMnemonics, uint8ArrayToMnemonic } from '.'; + +const mockSRPArrayOne = [ + 'ar9gx', + 'e97vw', + '95wx4', + 'c93d1', + 'zdiai', + 'h07an', + '78eld', + 'snqx8', + '1o472', + 'ixpwq', + 'p31fg', + 'vfnfy', +]; + +const mockSRPArrayTwo = [ + 'r6rrh', + 'ujfkr', + 'n8n0h', + '9fsgb', + 'obyjo', + 'a8wnk', + 'eqcnj', + '4e55t', + '170tl', + 'uur4s', + '4wf4g', + '242lz', +]; + +describe('mnemonic::shuffle', () => { + it('should shuffle the array', () => { + expect(mockSRPArrayOne.join('')).not.toEqual( + shuffle(mockSRPArrayOne).join(''), + ); + }); +}); + +describe('mnemonic::compareMnemonics', () => { + it('should return false', () => { + expect(compareMnemonics(mockSRPArrayOne, mockSRPArrayTwo)).toBe(false); + }); + it('should return true', () => { + expect(compareMnemonics(mockSRPArrayOne, mockSRPArrayOne)).toBe(true); + }); +}); + +describe('mnemonic::uint8ArrayToMnemonic', () => { + const mockWordlist = [ + 'apple', + 'banana', + 'carrot', + 'dog', + 'elephant', + 'fox', + 'grape', + 'horse', + 'ice cream', + 'jellyfish', + ]; + + it('should convert a Uint8Array to a seed phrase', () => { + const uint8Array = new Uint8Array([ + 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, + ]); + const expectedOutput = + 'apple banana carrot dog elephant fox grape horse ice cream jellyfish'; + + const result = uint8ArrayToMnemonic(uint8Array, mockWordlist); + + expect(result).toEqual(expectedOutput); + }); + + it('should handle an empty Uint8Array', () => { + expect(() => + uint8ArrayToMnemonic(new Uint8Array([]), mockWordlist), + ).toThrow('The method uint8ArrayToMnemonic expects a non-empty array'); + }); +}); diff --git a/app/util/mnemonic/index.ts b/app/util/mnemonic/index.ts new file mode 100644 index 00000000000..6ac09a70f25 --- /dev/null +++ b/app/util/mnemonic/index.ts @@ -0,0 +1,55 @@ +/** + * Method to shuffles an array of string. + * + * The previous method was replaced according to the following tutorial. + * https://javascript.info/array-methods#shuffle-an-array + * + * @param array - Array of string. + * @returns Array of string. + */ +// eslint-disable-next-line import/prefer-default-export +export const shuffle = (array: string[]): string[] => { + const shuffledArray = [...array]; + for (let i = array.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + + // Swap elements. + [shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]]; + } + return shuffledArray; +}; + +/** + * Compare two mnemonics arrays. + * @param validMnemonic - Array of string with the correct SRP. + * @param input - Array of string with the user's input. + * @returns Boolean indicating with the input matches the valid SRP. + */ +export const compareMnemonics = ( + validMnemonic: string[], + input: string[], +): boolean => validMnemonic.join('') === input.join(''); + +/** + * Transform a typed array containing mnemonic data to the seed phrase. + * @param uint8Array - Typed array containing mnemonic data. + * @param wordlist - BIP-39 wordlist. + * @returns The seed phrase. + */ +export const uint8ArrayToMnemonic = ( + uint8Array: Uint8Array, + wordlist: string[], +): string => { + if (uint8Array.length === 0) { + throw new Error( + 'The method uint8ArrayToMnemonic expects a non-empty array', + ); + } + + const recoveredIndices = Array.from( + new Uint16Array(new Uint8Array(uint8Array).buffer), + ); + return JSON.stringify(recoveredIndices.map((i) => wordlist[i]).join(' ')) + .replace(/"/g, '') + .trimEnd(); +}; From 3b041dbd85f251353141487e6026fdc644063339 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Sat, 8 Jul 2023 11:08:18 -0400 Subject: [PATCH 02/67] Update logic to retrieve mnemonic from KeyringController --- .../Views/ManualBackupStep1/index.js | 8 ++-- .../RevealPrivateCredential.tsx | 40 +++++++++++-------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/app/components/Views/ManualBackupStep1/index.js b/app/components/Views/ManualBackupStep1/index.js index 743c27ab787..01e9cc73795 100644 --- a/app/components/Views/ManualBackupStep1/index.js +++ b/app/components/Views/ManualBackupStep1/index.js @@ -14,6 +14,7 @@ import { connect } from 'react-redux'; import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'; import FeatherIcons from 'react-native-vector-icons/Feather'; import { BlurView } from '@react-native-community/blur'; +import { wordlist } from '@metamask/scure-bip39/dist/wordlists/english'; import { baseStyles } from '../../../styles/common'; import StyledButton from '../../UI/StyledButton'; import OnboardingProgress from '../../UI/OnboardingProgress'; @@ -29,6 +30,7 @@ import { WRONG_PASSWORD_ERROR, } from '../../../constants/onboarding'; import { useTheme } from '../../../util/theme'; +import { uint8ArrayToMnemonic } from '../../../util/mnemonic'; import { createStyles } from './styles'; import { CONFIRM_CHANGE_PASSWORD_INPUT_BOX_ID } from '../../../constants/test-ids'; @@ -63,10 +65,10 @@ const ManualBackupStep1 = ({ route, navigation, appTheme }) => { const tryExportSeedPhrase = async (password) => { const { KeyringController } = Engine.context; - const mnemonic = await KeyringController.exportSeedPhrase( + const uint8ArrayMnemonic = await KeyringController.exportSeedPhrase( password, - ).toString(); - return JSON.stringify(mnemonic).replace(/"/g, '').split(' '); + ); + return uint8ArrayToMnemonic(uint8ArrayMnemonic, wordlist).split(' '); }; useEffect(() => { diff --git a/app/components/Views/RevealPrivateCredential/RevealPrivateCredential.tsx b/app/components/Views/RevealPrivateCredential/RevealPrivateCredential.tsx index 9ab19156fcc..e6a2b2cccc2 100644 --- a/app/components/Views/RevealPrivateCredential/RevealPrivateCredential.tsx +++ b/app/components/Views/RevealPrivateCredential/RevealPrivateCredential.tsx @@ -11,6 +11,7 @@ import { } from 'react-native'; import { useDispatch, useSelector } from 'react-redux'; import AsyncStorage from '@react-native-async-storage/async-storage'; +import { wordlist } from '@metamask/scure-bip39/dist/wordlists/english'; import QRCode from 'react-native-qrcode-svg'; import ScrollableTabView, { DefaultTabBar, @@ -38,6 +39,7 @@ import Engine from '../../../core/Engine'; import { BIOMETRY_CHOICE } from '../../../constants/storage'; import { MetaMetricsEvents } from '../../../core/Analytics'; import AnalyticsV2 from '../../../util/analyticsV2'; +import { uint8ArrayToMnemonic } from '../../../util/mnemonic'; import { Authentication } from '../../../core/'; import Device from '../../../util/device'; @@ -124,10 +126,8 @@ const RevealPrivateCredential = ({ try { let privateCredential; if (!isPrivateKeyReveal) { - const mnemonic = await KeyringController.exportSeedPhrase( - pswd, - ).toString(); - privateCredential = JSON.stringify(mnemonic).replace(/"/g, ''); + const uint8ArraySeed = await KeyringController.exportSeedPhrase(pswd); + privateCredential = uint8ArrayToMnemonic(uint8ArraySeed, wordlist); } else { privateCredential = await KeyringController.exportAccount( pswd, @@ -205,20 +205,23 @@ const RevealPrivateCredential = ({ navigateBack(); }; - const tryUnlock = () => { + const tryUnlock = async () => { const { KeyringController } = Engine.context as any; - if (KeyringController.validatePassword(password)) { - if (!isPrivateKey) { - const currentDate = new Date(); - dispatch(recordSRPRevealTimestamp(currentDate.toString())); - AnalyticsV2.trackEvent(MetaMetricsEvents.NEXT_REVEAL_SRP_CTA, {}); - } - setIsModalVisible(true); - setWarningIncorrectPassword(''); - } else { + try { + await KeyringController.verifyPassword(password); + } catch { const msg = strings('reveal_credential.warning_incorrect_password'); setWarningIncorrectPassword(msg); + return; } + + if (!isPrivateKey) { + const currentDate = new Date(); + dispatch(recordSRPRevealTimestamp(currentDate.toString())); + AnalyticsV2.trackEvent(MetaMetricsEvents.NEXT_REVEAL_SRP_CTA, {}); + } + setIsModalVisible(true); + setWarningIncorrectPassword(''); }; const onPasswordChange = (pswd: string) => { @@ -411,9 +414,14 @@ const RevealPrivateCredential = ({ setIsModalVisible(false); }; - const enableNextButton = () => { + const enableNextButton = async () => { const { KeyringController } = Engine.context as any; - return KeyringController.validatePassword(password); + try { + await KeyringController.verifyPassword(password) + } catch { + return false; + } + return true; }; const renderModal = ( From 22cb90f4df6063f524fc02111f785f5dc977aa8e Mon Sep 17 00:00:00 2001 From: gantunesr Date: Sat, 8 Jul 2023 11:08:46 -0400 Subject: [PATCH 03/67] Add resolution for @ethereumjs/util --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 936aab6b46e..fdf5b219011 100644 --- a/package.json +++ b/package.json @@ -136,7 +136,8 @@ "detox/**/moment": "^2.29.4", "oss-attribution-generator/**/debug": "^2.6.9", "d3-color": "3.1.0", - "**/fast-xml-parser": "4.2.4" + "**/fast-xml-parser": "4.2.4", + "@ethereumjs/util": "8.0.2" }, "dependencies": { "@consensys/on-ramp-sdk": "1.20.0", From b8b5c384f07fd9999366d1ce142e8a8ee1773ca5 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Sat, 8 Jul 2023 11:09:19 -0400 Subject: [PATCH 04/67] Add @metamask/scure-bip39 module --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index fdf5b219011..7c0edc1f6ca 100644 --- a/package.json +++ b/package.json @@ -165,6 +165,7 @@ "@metamask/permission-controller": "~3.0.0", "@metamask/phishing-controller": "^3.0.0", "@metamask/preferences-controller": "^2.1.0", + "@metamask/scure-bip39": "^2.1.0", "@metamask/sdk-communication-layer": "0.3.0", "@metamask/signature-controller": "^2.0.0", "@metamask/swaps-controller": "^6.8.0", From 305ae13ce6c696d762301855784dd3bcfc6bfb6b Mon Sep 17 00:00:00 2001 From: gantunesr Date: Sat, 8 Jul 2023 11:09:41 -0400 Subject: [PATCH 05/67] Bump KeyringController to v5.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7c0edc1f6ca..7807adf6ea0 100644 --- a/package.json +++ b/package.json @@ -160,7 +160,7 @@ "@metamask/eth-sig-util": "^4.0.1", "@metamask/etherscan-link": "^2.0.0", "@metamask/gas-fee-controller": "4.0.0", - "@metamask/keyring-controller": "^1.0.1", + "@metamask/keyring-controller": "^5.0.0", "@metamask/network-controller": "^5.0.0", "@metamask/permission-controller": "~3.0.0", "@metamask/phishing-controller": "^3.0.0", From 5aff7746b988fdd4fae91b9ce4744ccc8e8629d5 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Sat, 8 Jul 2023 11:10:12 -0400 Subject: [PATCH 06/67] Sort package.json --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 7807adf6ea0..3e9c34794b7 100644 --- a/package.json +++ b/package.json @@ -331,11 +331,11 @@ "zxcvbn": "4.4.2" }, "devDependencies": { + "@actions/core": "^1.10.0", + "@actions/github": "^5.1.1", "@babel/core": "^7.20.0", "@babel/preset-env": "^7.20.0", "@babel/runtime": "^7.20.0", - "@actions/core": "^1.10.0", - "@actions/github": "^5.1.1", "@cucumber/message-streams": "^4.0.1", "@cucumber/messages": "^22.0.0", "@ethersproject/contracts": "^5.7.0", @@ -353,14 +353,14 @@ "@storybook/addon-ondevice-actions": "^5.3.23", "@storybook/addon-ondevice-knobs": "^5.3.25", "@storybook/react-native": "^5.3.25", - "@testing-library/react-hooks": "^8.0.1", "@testing-library/react": "14.0.0", + "@testing-library/react-hooks": "^8.0.1", "@testing-library/react-native": "12.1.2", "@types/enzyme": "^3.10.9", "@types/is-url": "^1.2.30", "@types/jest": "^27.2.0", - "@types/qs": "^6.9.7", "@types/node": "^17.0.21", + "@types/qs": "^6.9.7", "@types/react": "^17.0.11", "@types/react-native": "^0.64.10", "@types/react-native-background-timer": "^2.0.0", @@ -430,8 +430,8 @@ "regenerator-runtime": "0.13.9", "rn-nodeify": "10.3.0", "stack-beautifier": "1.0.2", - "typescript": "^4.4.2", "ts-node": "^10.5.0", + "typescript": "^4.4.2", "wdio-cucumberjs-json-reporter": "^4.4.3", "xml2js": "^0.5.0" }, From 6e2cc793740db28a9285c0804cdb289139917989 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Sat, 8 Jul 2023 11:10:26 -0400 Subject: [PATCH 07/67] Update yarn.lock --- yarn.lock | 192 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 100 insertions(+), 92 deletions(-) diff --git a/yarn.lock b/yarn.lock index aeb4620eb74..45ecfbdba1f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3077,7 +3077,7 @@ "@ethereumjs/util" "^8.0.6" ethereum-cryptography "^2.0.0" -"@ethereumjs/util@^8.0.0": +"@ethereumjs/util@8.0.2", "@ethereumjs/util@^8.0.0", "@ethereumjs/util@^8.0.2", "@ethereumjs/util@^8.0.6": version "8.0.2" resolved "https://registry.yarnpkg.com/@ethereumjs/util/-/util-8.0.2.tgz#b7348fc7253649b0f00685a94546c6eee1fad819" integrity sha512-b1Fcxmq+ckCdoLPhVIBkTcH8szigMapPuEmD8EDakvtI5Na5rzmX1sBW73YQqaPc7iUxGCAzZP1LrFQ7aEMugA== @@ -3086,16 +3086,6 @@ async "^3.2.4" ethereum-cryptography "^1.1.2" -"@ethereumjs/util@^8.0.6": - version "8.0.6" - resolved "https://registry.yarnpkg.com/@ethereumjs/util/-/util-8.0.6.tgz#f9716ed34235ea05eff8353bc5d483e5a6455989" - integrity sha512-zFLG/gXtF3QUC7iKFn4PT6HCr+DEnlCbwUGKGtXoqjA+64T+e0FuqMjlo4bQIY2ngRzk3EtudKdGYC4g31ehhg== - dependencies: - "@chainsafe/ssz" "^0.11.1" - "@ethereumjs/rlp" "^4.0.1" - ethereum-cryptography "^2.0.0" - micro-ftch "^0.3.1" - "@ethersproject/abi@5.4.1": version "5.4.1" resolved "https://registry.yarnpkg.com/@ethersproject/abi/-/abi-5.4.1.tgz#6ac28fafc9ef6f5a7a37e30356a2eb31fa05d39b" @@ -5146,14 +5136,6 @@ single-call-balance-checker-abi "^1.0.0" uuid "^8.3.2" -"@metamask/base-controller@^1.1.1": - version "1.1.1" - resolved "https://registry.yarnpkg.com/@metamask/base-controller/-/base-controller-1.1.1.tgz#34c2db471328b92a3a46f9c2547bbb9d37803258" - integrity sha512-erDfd+OcHnixSZObPNHuDn2G3rRT2B9J/JaOmjjQN64o9RqDYid87Zb0z03wK8cbJ/pEHhhDIBn6t2gMWcdwrQ== - dependencies: - "@metamask/controller-utils" "^1.0.0" - immer "^9.0.6" - "@metamask/base-controller@^2.0.0": version "2.0.0" resolved "https://registry.yarnpkg.com/@metamask/base-controller/-/base-controller-2.0.0.tgz#8f9130df3edaa270ade00378cf57917545d44617" @@ -5170,15 +5152,10 @@ "@metamask/utils" "^5.0.2" immer "^9.0.6" -"@metamask/bip39@^4.0.0": - version "4.0.0" - resolved "https://registry.yarnpkg.com/@metamask/bip39/-/bip39-4.0.0.tgz#1cb867a8454e3d45d065107b4e070d58bdb64aac" - integrity sha512-xH2g8mFe9p2WePnKeQJH4U8MB6pWPyvwpsz4stb0YdnMOR7cKA6Jm/KOSFiPKr1i9+AzNDImt/XxhwF5ej4jXQ== - dependencies: - "@types/node" "11.11.6" - create-hash "^1.1.0" - pbkdf2 "^3.0.9" - randombytes "^2.0.1" +"@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/composable-controller@^2.0.0": version "2.0.0" @@ -5192,7 +5169,7 @@ resolved "https://registry.yarnpkg.com/@metamask/contract-metadata/-/contract-metadata-2.2.0.tgz#277764d0d56e37180ae7644a9d11eb96295b36fc" integrity sha512-SM6A4C7vXNbVpgMTX67kfW8QWvu3eSXxMZlY5PqZBTkvri1s9zgQ0uwRkK5r2VXNEoVmXCDnnEX/tX5EzzgNUQ== -"@metamask/controller-utils@^1.0.0", "@metamask/controller-utils@^3.0.0", "@metamask/controller-utils@^3.4.0", "@metamask/controller-utils@~3.0.0": +"@metamask/controller-utils@^3.0.0", "@metamask/controller-utils@^3.4.0", "@metamask/controller-utils@^4.0.0", "@metamask/controller-utils@^4.1.0", "@metamask/controller-utils@~3.0.0": version "3.0.0" resolved "https://registry.yarnpkg.com/@metamask/controller-utils/-/controller-utils-3.0.0.tgz#e0984cdab14280409297671b5858891527c5e4ee" integrity sha512-JjFWBZnnh5DSX2tRsw5xtXxaqVkTzaW7mkSZ+lL3LoCAw47Cf8zGP1kGR6VKxcceKi+MpEFvZr7gf1OFnOoEjw== @@ -5258,18 +5235,40 @@ resolved "https://registry.yarnpkg.com/@metamask/eslint-config/-/eslint-config-7.0.1.tgz#eeb87baa902965ca7931c26911d7027373706f34" integrity sha512-dMZ+iyZrHdZK0D1uStTx8UN6Q6IK9YGbqPUwxgTj63M0mZOsuqs8qpGf+9Dn7uqS+8Oe9jNqejKxozjTiJvsEw== -"@metamask/eth-hd-keyring@^4.0.2": - version "4.0.2" - resolved "https://registry.yarnpkg.com/@metamask/eth-hd-keyring/-/eth-hd-keyring-4.0.2.tgz#0a81556a556b361755c8d6fb5aced1ce5be0331c" - integrity sha512-v47VOTCCmZUZ6uxM5tQNoasQjLdrZADmgph2fhk4m7zKVUxDvYFU7FJT3Rm55fk8mg+dKSbEObDriqbdWeBbcA== +"@metamask/eth-hd-keyring@^6.0.0": + version "6.0.0" + resolved "https://registry.yarnpkg.com/@metamask/eth-hd-keyring/-/eth-hd-keyring-6.0.0.tgz#a46788d4bbc7aa5d8263ed6e4348101a80519a69" + integrity sha512-dEj/I6Ag9FyCmjPcRXeXCkRXkVJE/uElhDVRcLBU6mT/GsXKgzVWXC/k0dhE8rEDrQbidhl+8wEElSJ2LI1InA== dependencies: - "@metamask/bip39" "^4.0.0" - "@metamask/eth-sig-util" "^4.0.0" - eth-simple-keyring "^4.2.0" - ethereumjs-util "^7.0.9" - ethereumjs-wallet "^1.0.1" + "@ethereumjs/util" "^8.0.2" + "@metamask/eth-sig-util" "^5.0.2" + "@metamask/scure-bip39" "^2.0.3" + ethereum-cryptography "^1.1.2" -"@metamask/eth-sig-util@^4.0.0", "@metamask/eth-sig-util@^4.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== + dependencies: + "@metamask/browser-passworder" "^4.0.2" + "@metamask/eth-hd-keyring" "^6.0.0" + "@metamask/eth-sig-util" "5.0.2" + "@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/eth-sig-util@^4.0.1": version "4.0.1" resolved "https://registry.yarnpkg.com/@metamask/eth-sig-util/-/eth-sig-util-4.0.1.tgz#3ad61f6ea9ad73ba5b19db780d40d9aae5157088" integrity sha512-tghyZKLHZjcdlDqCA3gNZmLeR0XvOE9U1qoQO9ohyAZT6Pya+H9vkBPcsyXytmYLNgVoin7CKCmweo/R43V+tQ== @@ -5280,6 +5279,28 @@ tweetnacl "^1.0.3" tweetnacl-util "^0.15.1" +"@metamask/eth-sig-util@^5.0.1", "@metamask/eth-sig-util@^5.0.2", "@metamask/eth-sig-util@^5.0.3": + version "5.1.0" + resolved "https://registry.yarnpkg.com/@metamask/eth-sig-util/-/eth-sig-util-5.1.0.tgz#a47f62800ee1917fef976ba67544a0ccd7d1bd6b" + integrity sha512-mlgziIHYlA9pi/XZerChqg4NocdOgBPB9NmxgXWQO2U2hH8RGOJQrz6j/AIKkYxgCMIE2PY000+joOwXfzeTDQ== + dependencies: + "@ethereumjs/util" "^8.0.6" + bn.js "^4.12.0" + ethereum-cryptography "^2.0.0" + ethjs-util "^0.1.6" + tweetnacl "^1.0.3" + tweetnacl-util "^0.15.1" + +"@metamask/eth-simple-keyring@^5.0.0": + version "5.0.0" + resolved "https://registry.yarnpkg.com/@metamask/eth-simple-keyring/-/eth-simple-keyring-5.0.0.tgz#307772d1aa3298e41a2444b428cd8f4522b7bf5c" + integrity sha512-UJfP36Z9g1eeD8mSHWaVqUvkgbgYm3S7YuzlMzQi+WgPnWu81CdbldMMtvreTlu4I1mTyljXLDMjIp65P0bygQ== + dependencies: + "@ethereumjs/util" "^8.0.0" + "@metamask/eth-sig-util" "^5.0.1" + ethereum-cryptography "^1.1.2" + randombytes "^2.1.0" + "@metamask/etherscan-link@^2.0.0": version "2.1.0" resolved "https://registry.yarnpkg.com/@metamask/etherscan-link/-/etherscan-link-2.1.0.tgz#c0be8e68445b7b83cf85bcc03a56cdf8e256c973" @@ -5301,42 +5322,43 @@ immer "^9.0.6" uuid "^8.3.2" -"@metamask/keyring-controller@^1.0.1": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@metamask/keyring-controller/-/keyring-controller-1.0.1.tgz#c2836bbafaab8c2d1300f4e56aad3b32b3dd90c0" - integrity sha512-D7+GbSvE5B0DqPyfeTypkShoj8tATUM64a/Nb9FmqYW20slZ4TMUAdbMOHi6KqZnaZcKu8oOUTxEiRe+MsRGAw== +"@metamask/keyring-controller@^5.0.0": + version "5.1.0" + resolved "https://registry.yarnpkg.com/@metamask/keyring-controller/-/keyring-controller-5.1.0.tgz#19bffa4ed80e38481dd3f97c638027b509adcb8b" + integrity sha512-/Ft+6Gsf9usuoK4MSVakc5GqfGMC4Jnl1M5gw9VTT78VmZhdPfy+k54nNTY8XMYMnIlL/Fiyjc/iPS+bcTgodg== dependencies: "@keystonehq/metamask-airgapped-keyring" "^0.6.1" - "@metamask/base-controller" "^1.1.1" - "@metamask/controller-utils" "^1.0.0" - "@metamask/message-manager" "^1.0.1" - "@metamask/preferences-controller" "^1.0.1" + "@metamask/base-controller" "^3.0.0" + "@metamask/controller-utils" "^4.0.0" + "@metamask/eth-keyring-controller" "^10.0.1" + "@metamask/eth-sig-util" "^5.0.3" + "@metamask/message-manager" "^6.0.0" + "@metamask/preferences-controller" "^4.1.0" async-mutex "^0.2.6" - eth-keyring-controller "^7.0.2" - eth-sig-util "^3.0.0" ethereumjs-util "^7.0.10" ethereumjs-wallet "^1.0.1" -"@metamask/message-manager@^1.0.1": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@metamask/message-manager/-/message-manager-1.0.1.tgz#5834fb5ed14a844f35f796268966745a966847ed" - integrity sha512-8IvTS6T4gZm7mL8+xUwWHOMGuXaMF3OZJB5g34taASp0p5pXHoLNEXL+qBaw0RkgDxbFsuij02Gs3Mx/jQ6U6A== +"@metamask/message-manager@^5.0.0": + version "5.0.0" + resolved "https://registry.yarnpkg.com/@metamask/message-manager/-/message-manager-5.0.0.tgz#1f419ad5b24c8f5ae8b07f0772376d96a939ac5e" + integrity sha512-p/7Q6n/g3dsSDowjDWJjrONOmQHkx99sK62He6FUxVvkS45RzB1SZuz4Lvg4uCgbVdl9HzBjb+BlTsfYD9wHvQ== dependencies: - "@metamask/base-controller" "^1.1.1" - "@metamask/controller-utils" "^1.0.0" + "@metamask/base-controller" "^2.0.0" + "@metamask/controller-utils" "^3.4.0" "@types/uuid" "^8.3.0" eth-sig-util "^3.0.0" ethereumjs-util "^7.0.10" jsonschema "^1.2.4" uuid "^8.3.2" -"@metamask/message-manager@^5.0.0": - version "5.0.0" - resolved "https://registry.yarnpkg.com/@metamask/message-manager/-/message-manager-5.0.0.tgz#1f419ad5b24c8f5ae8b07f0772376d96a939ac5e" - integrity sha512-p/7Q6n/g3dsSDowjDWJjrONOmQHkx99sK62He6FUxVvkS45RzB1SZuz4Lvg4uCgbVdl9HzBjb+BlTsfYD9wHvQ== +"@metamask/message-manager@^6.0.0": + version "6.0.0" + resolved "https://registry.yarnpkg.com/@metamask/message-manager/-/message-manager-6.0.0.tgz#929416ff7ad25e13f8541e10cfb0858cc3826bbc" + integrity sha512-uWvTeR1RcE/ajXm4yHteHgwHPTbzfarSxJztUQUhIkv9SWeAibOBhDFJSdbt6Wglq3l4sxNZ92pxf4pwj2yjZw== dependencies: - "@metamask/base-controller" "^2.0.0" - "@metamask/controller-utils" "^3.4.0" + "@metamask/base-controller" "^3.0.0" + "@metamask/controller-utils" "^4.0.0" + "@metamask/utils" "^5.0.2" "@types/uuid" "^8.3.0" eth-sig-util "^3.0.0" ethereumjs-util "^7.0.10" @@ -5402,14 +5424,6 @@ eth-phishing-detect "^1.2.0" punycode "^2.1.1" -"@metamask/preferences-controller@^1.0.1": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@metamask/preferences-controller/-/preferences-controller-1.0.1.tgz#20f2187be103a1e7f49df4021e39afb12ee422a0" - integrity sha512-6fAruDd9sag/hwJGKIP0eSdYC92J/wkDnigQo7ONpu7n94giot7vvsR5+4zNjC32tLa5GpHG50PynZaHfYzK0Q== - dependencies: - "@metamask/base-controller" "^1.1.1" - "@metamask/controller-utils" "^1.0.0" - "@metamask/preferences-controller@^2.0.0", "@metamask/preferences-controller@^2.1.0": version "2.1.0" resolved "https://registry.yarnpkg.com/@metamask/preferences-controller/-/preferences-controller-2.1.0.tgz#c3ed464259f3f969ff492167c368752d23db3924" @@ -5418,11 +5432,27 @@ "@metamask/base-controller" "^2.0.0" "@metamask/controller-utils" "^3.0.0" +"@metamask/preferences-controller@^4.1.0": + version "4.2.0" + resolved "https://registry.yarnpkg.com/@metamask/preferences-controller/-/preferences-controller-4.2.0.tgz#82665c55cb2eac44f4b4472d4a91291d33121619" + integrity sha512-Or+Qu4r3WifgpJRIknrFb2m5/nmbt4KUsawWpn8scI7TPxa6xLnlLeOlrcTDRISYVbKL6LgpV+Dna2FyJSubnw== + dependencies: + "@metamask/base-controller" "^3.0.0" + "@metamask/controller-utils" "^4.1.0" + "@metamask/safe-event-emitter@^2.0.0": version "2.0.0" resolved "https://registry.yarnpkg.com/@metamask/safe-event-emitter/-/safe-event-emitter-2.0.0.tgz#af577b477c683fad17c619a78208cede06f9605c" integrity sha512-/kSXhY692qiV1MXu6EeOZvg5nECLclxNXcKCxJ3cXQgYuRymRHpdx/t7JXfsK+JLjwA1e1c1/SBrlQYpusC29Q== +"@metamask/scure-bip39@^2.0.3", "@metamask/scure-bip39@^2.1.0": + version "2.1.0" + resolved "https://registry.yarnpkg.com/@metamask/scure-bip39/-/scure-bip39-2.1.0.tgz#13456884736e56ede15e471bd93c0aa0acdedd0b" + integrity sha512-Ndwdnld0SI6YaftEUUVq20sdoWcWNXsJXxvQkbiY42FKmrA16U6WoSh9Eq+NpugpKKwK6f5uvaTDusjndiEDGQ== + dependencies: + "@noble/hashes" "~1.1.1" + "@scure/base" "~1.1.0" + "@metamask/sdk-communication-layer@0.3.0": version "0.3.0" resolved "https://registry.yarnpkg.com/@metamask/sdk-communication-layer/-/sdk-communication-layer-0.3.0.tgz#ee7eac4f108bcf5d2ea0edfb9fedd97d1bf10360" @@ -7313,11 +7343,6 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-18.15.11.tgz#b3b790f09cb1696cffcec605de025b088fa4225f" integrity sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q== -"@types/node@11.11.6": - version "11.11.6" - resolved "https://registry.yarnpkg.com/@types/node/-/node-11.11.6.tgz#df929d1bb2eee5afdda598a41930fe50b43eaa6a" - integrity sha512-Exw4yUWMBXM3X+8oqzJNRqZSwUAaS4+7NdvHqQuFi/d+synz++xmX3QIf+BFqneW8N31R8Ky+sikfZUXq07ggQ== - "@types/node@16.9.1": version "16.9.1" resolved "https://registry.yarnpkg.com/@types/node/-/node-16.9.1.tgz#0611b37db4246c937feef529ddcc018cf8e35708" @@ -10605,7 +10630,7 @@ bn.js@4.11.8: resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f" integrity sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA== -bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.10.0, bn.js@^4.11.0, bn.js@^4.11.1, bn.js@^4.11.8, bn.js@^4.11.9: +bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.10.0, bn.js@^4.11.0, bn.js@^4.11.1, bn.js@^4.11.8, bn.js@^4.11.9, bn.js@^4.12.0: version "4.12.0" resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88" integrity sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA== @@ -14284,18 +14309,6 @@ eth-keyring-controller@^6.2.1: loglevel "^1.5.0" obs-store "^4.0.3" -eth-keyring-controller@^7.0.2: - version "7.0.2" - resolved "https://registry.yarnpkg.com/eth-keyring-controller/-/eth-keyring-controller-7.0.2.tgz#c4d7f9be179f08b3bb18410066bc4c8e91f50552" - integrity sha512-U4bqbXkTn7js/47rnFtVyBYQcvOKtmraD/YReBwuy4R56bFSJN8kinP0JJRl3WTtVfVS1l5A/jjsF3qk5TaTeg== - dependencies: - "@metamask/bip39" "^4.0.0" - "@metamask/eth-hd-keyring" "^4.0.2" - browser-passworder "^2.0.3" - eth-sig-util "^3.0.1" - eth-simple-keyring "^4.2.0" - obs-store "^4.0.3" - eth-method-registry@1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/eth-method-registry/-/eth-method-registry-1.1.0.tgz#3cc01bd23dcf513428d14a0bb19910652cc5cac0" @@ -20365,11 +20378,6 @@ metro@0.73.10: ws "^7.5.1" yargs "^17.5.1" -micro-ftch@^0.3.1: - version "0.3.1" - resolved "https://registry.yarnpkg.com/micro-ftch/-/micro-ftch-0.3.1.tgz#6cb83388de4c1f279a034fb0cf96dfc050853c5f" - integrity sha512-/0LLxhzP0tfiR5hcQebtudP56gUurs2CLkGarnCiB/OqEyUFQ6U3paQi/tgLv0hBJYt2rnr9MNpxz4fiiugstg== - micromatch@^3.1.10: version "3.1.10" resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-3.1.10.tgz#70859bc95c9840952f359a068a3fc49f9ecfac23" From a7db848b268375ea349c74116dbc17614d2292b9 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Sat, 8 Jul 2023 11:10:47 -0400 Subject: [PATCH 08/67] Update import in ManualBackupStep2 --- app/components/Views/ManualBackupStep2/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/components/Views/ManualBackupStep2/index.js b/app/components/Views/ManualBackupStep2/index.js index e870eb1fcb8..631136b755a 100644 --- a/app/components/Views/ManualBackupStep2/index.js +++ b/app/components/Views/ManualBackupStep2/index.js @@ -16,7 +16,7 @@ import { connect } from 'react-redux'; import { seedphraseBackedUp } from '../../../actions/user'; import MaterialIcon from 'react-native-vector-icons/MaterialCommunityIcons'; import { getOnboardingNavbarOptions } from '../../UI/Navbar'; -import { shuffle, compareSRPs } from '../../../util/SRP'; +import { shuffle, compareMnemonics } from '../../../util/mnemonic'; import { MetaMetricsEvents } from '../../../core/Analytics'; import AnalyticsV2 from '../../../util/analyticsV2'; import { useTheme } from '../../../util/theme'; @@ -120,7 +120,7 @@ const ManualBackupStep2 = ({ navigation, seedphraseBackedUp, route }) => { (confirmedWord) => confirmedWord.word, ); - return compareSRPs(validWords, proposedWords); + return compareMnemonics(validWords, proposedWords); }, [confirmedWords, route.params?.words]); const goNext = () => { From 93c61988ee55adb5162226741d7cd1179467dc1e Mon Sep 17 00:00:00 2001 From: gantunesr Date: Sat, 8 Jul 2023 20:39:53 -0400 Subject: [PATCH 09/67] Update KeyringController patch --- ... @metamask+keyring-controller+5.1.0.patch} | 41 ++----------------- 1 file changed, 3 insertions(+), 38 deletions(-) rename patches/{@metamask+keyring-controller+1.0.1.patch => @metamask+keyring-controller+5.1.0.patch} (58%) diff --git a/patches/@metamask+keyring-controller+1.0.1.patch b/patches/@metamask+keyring-controller+5.1.0.patch similarity index 58% rename from patches/@metamask+keyring-controller+1.0.1.patch rename to patches/@metamask+keyring-controller+5.1.0.patch index 601eb60d0bf..c2e7f54969a 100644 --- a/patches/@metamask+keyring-controller+1.0.1.patch +++ b/patches/@metamask+keyring-controller+5.1.0.patch @@ -1,43 +1,8 @@ diff --git a/node_modules/@metamask/keyring-controller/dist/KeyringController.js b/node_modules/@metamask/keyring-controller/dist/KeyringController.js -index a5e5af1..e2dbbd2 100644 +index ecec472..183cbdf 100644 --- a/node_modules/@metamask/keyring-controller/dist/KeyringController.js +++ b/node_modules/@metamask/keyring-controller/dist/KeyringController.js -@@ -125,6 +125,7 @@ class KeyringController extends base_controller_1.BaseController { - } - /** - * Adds a new account to the default (first) HD seed phrase keyring. -+ * Patched to not auto switch accounts. - * - * @returns Promise resolving to current state when the account is added. - */ -@@ -140,12 +141,13 @@ class KeyringController extends base_controller_1.BaseController { - const newAccounts = yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").getAccounts(); - yield this.verifySeedPhrase(); - this.updateIdentities(newAccounts); -+ let addedAccountAddress = ''; - newAccounts.forEach((selectedAddress) => { - if (!oldAccounts.includes(selectedAddress)) { -- this.setSelectedAddress(selectedAddress); -+ addedAccountAddress = selectedAddress - } - }); -- return this.fullUpdate(); -+ return { addedAccountAddress, keyringState: this.fullUpdate() }; - }); - } - /** -@@ -313,8 +315,8 @@ class KeyringController extends base_controller_1.BaseController { - const accounts = yield newKeyring.getAccounts(); - const allAccounts = yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").getAccounts(); - this.updateIdentities(allAccounts); -- this.setSelectedAddress(accounts[0]); -- return this.fullUpdate(); -+ const importedAccountAddress = accounts[0]; -+ return { importedAccountAddress, keyringState: this.fullUpdate() }; - }); - } - /** -@@ -615,16 +617,19 @@ class KeyringController extends base_controller_1.BaseController { +@@ -706,16 +706,19 @@ class KeyringController extends base_controller_1.BaseController { yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").addNewAccount(keyring); const newAccounts = yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").getAccounts(); this.updateIdentities(newAccounts); @@ -58,7 +23,7 @@ index a5e5af1..e2dbbd2 100644 }); } getAccountKeyringType(account) { -@@ -635,13 +640,15 @@ class KeyringController extends base_controller_1.BaseController { +@@ -726,13 +729,15 @@ class KeyringController extends base_controller_1.BaseController { forgetQRDevice() { return __awaiter(this, void 0, void 0, function* () { const keyring = yield this.getOrAddQRKeyring(); From dec343b42d9929b1596debac31dc96849526f832 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Sun, 9 Jul 2023 23:26:25 -0400 Subject: [PATCH 10/67] Delete patch --- .../@metamask+keyring-controller+5.1.0.patch | 45 ------------------- 1 file changed, 45 deletions(-) delete mode 100644 patches/@metamask+keyring-controller+5.1.0.patch diff --git a/patches/@metamask+keyring-controller+5.1.0.patch b/patches/@metamask+keyring-controller+5.1.0.patch deleted file mode 100644 index c2e7f54969a..00000000000 --- a/patches/@metamask+keyring-controller+5.1.0.patch +++ /dev/null @@ -1,45 +0,0 @@ -diff --git a/node_modules/@metamask/keyring-controller/dist/KeyringController.js b/node_modules/@metamask/keyring-controller/dist/KeyringController.js -index ecec472..183cbdf 100644 ---- a/node_modules/@metamask/keyring-controller/dist/KeyringController.js -+++ b/node_modules/@metamask/keyring-controller/dist/KeyringController.js -@@ -706,16 +706,19 @@ class KeyringController extends base_controller_1.BaseController { - yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").addNewAccount(keyring); - const newAccounts = yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").getAccounts(); - this.updateIdentities(newAccounts); -+ let newHardwareWalletAddress = ''; - newAccounts.forEach((address) => { - if (!oldAccounts.includes(address)) { - if (this.setAccountLabel) { - this.setAccountLabel(address, `${keyring.getName()} ${index}`); - } -- this.setSelectedAddress(address); -+ newHardwareWalletAddress = address; - } - }); - yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").persistAllKeyrings(); - yield this.fullUpdate(); -+ // Return address of hardware wallet address that was created. -+ return newHardwareWalletAddress; - }); - } - getAccountKeyringType(account) { -@@ -726,13 +729,15 @@ class KeyringController extends base_controller_1.BaseController { - forgetQRDevice() { - return __awaiter(this, void 0, void 0, function* () { - const keyring = yield this.getOrAddQRKeyring(); -+ const accountsIncludingHardware = (yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").getAccounts()); - keyring.forgetDevice(); -- const accounts = (yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").getAccounts()); -- accounts.forEach((account) => { -- this.setSelectedAddress(account); -- }); -+ const remainingAccounts = (yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").getAccounts()); -+ const removedAccounts = accountsIncludingHardware.filter((address) => !remainingAccounts.includes(address)); -+ this.updateIdentities(remainingAccounts); - yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").persistAllKeyrings(); - yield this.fullUpdate(); -+ // Return list of removed accounts as well as remaining accounts for the app to use. -+ return { removedAccounts, remainingAccounts }; - }); - } - } From eaa14989c405250a532206dc8e8718fc0d15a614 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Sun, 9 Jul 2023 23:27:27 -0400 Subject: [PATCH 11/67] Bump keyring-controller to v6.0.0 and controller-utils to v3.3.0 --- package.json | 5 ++-- yarn.lock | 66 +++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index c7324d7b098..4b2629d9d4c 100644 --- a/package.json +++ b/package.json @@ -114,7 +114,6 @@ "react-native-level-fs/**/bl": "^1.2.3", "react-native-level-fs/**/semver": "^4.3.2", "@metamask/contract-metadata": "^2.1.0", - "@metamask/controller-utils": "~3.0.0", "@metamask/approval-controller": "3.3.0", "@exodus/react-native-payments/validator": "^13.7.0", "react-devtools-core": "4.22.1", @@ -155,12 +154,12 @@ "@metamask/base-controller": "^2.0.0", "@metamask/composable-controller": "^2.0.0", "@metamask/contract-metadata": "^2.1.0", - "@metamask/controller-utils": "~3.0.0", + "@metamask/controller-utils": "3.3.0", "@metamask/design-tokens": "^1.11.1", "@metamask/eth-sig-util": "^4.0.1", "@metamask/etherscan-link": "^2.0.0", "@metamask/gas-fee-controller": "4.0.0", - "@metamask/keyring-controller": "^5.0.0", + "@metamask/keyring-controller": "^6.0.0", "@metamask/network-controller": "^5.0.0", "@metamask/permission-controller": "~3.0.0", "@metamask/phishing-controller": "^3.0.0", diff --git a/yarn.lock b/yarn.lock index 45ecfbdba1f..fc49bb1fe88 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5169,7 +5169,20 @@ 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.1.0", "@metamask/controller-utils@~3.0.0": +"@metamask/controller-utils@3.3.0": + version "3.3.0" + resolved "https://registry.yarnpkg.com/@metamask/controller-utils/-/controller-utils-3.3.0.tgz#3db16c9965482e9563cdaeefe1ca484468666c22" + integrity sha512-uSnGoC1t2MYkP3C0wJB1iGOIs6nv+63e86DTPh/qM4CBOBFtlUVZF4Neo8ukqDAU4pURgVHdWJYnSjD2U5Zixg== + dependencies: + "@metamask/utils" "^5.0.1" + "@spruceid/siwe-parser" "1.1.3" + eth-ens-namehash "^2.0.8" + eth-rpc-errors "^4.0.2" + ethereumjs-util "^7.0.10" + ethjs-unit "^0.1.6" + fast-deep-equal "^3.1.3" + +"@metamask/controller-utils@^3.0.0": version "3.0.0" resolved "https://registry.yarnpkg.com/@metamask/controller-utils/-/controller-utils-3.0.0.tgz#e0984cdab14280409297671b5858891527c5e4ee" integrity sha512-JjFWBZnnh5DSX2tRsw5xtXxaqVkTzaW7mkSZ+lL3LoCAw47Cf8zGP1kGR6VKxcceKi+MpEFvZr7gf1OFnOoEjw== @@ -5180,6 +5193,34 @@ ethjs-unit "^0.1.6" fast-deep-equal "^3.1.3" +"@metamask/controller-utils@^3.4.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== + dependencies: + "@metamask/utils" "^5.0.1" + "@spruceid/siwe-parser" "1.1.3" + eth-ens-namehash "^2.0.8" + eth-rpc-errors "^4.0.2" + ethereumjs-util "^7.0.10" + ethjs-unit "^0.1.6" + fast-deep-equal "^3.1.3" + +"@metamask/controller-utils@^4.0.0", "@metamask/controller-utils@^4.1.0": + version "4.1.0" + resolved "https://registry.yarnpkg.com/@metamask/controller-utils/-/controller-utils-4.1.0.tgz#bb090de5172f703c414fdfa5f9be4eb9e32f9657" + integrity sha512-KsNpzdy6QkkZVgqfheCuGZwPrp+Luj7Z0+5rqgBAs+K7P4sFWwucay4jSxqZ5dx/kuG5bFG8ABpH5I+zaZq6Lw== + dependencies: + "@metamask/utils" "^5.0.2" + "@spruceid/siwe-parser" "1.1.3" + babel-runtime "^6.26.0" + eth-ens-namehash "^2.0.8" + eth-query "^2.1.2" + eth-rpc-errors "^4.0.2" + ethereumjs-util "^7.0.10" + ethjs-unit "^0.1.6" + fast-deep-equal "^3.1.3" + "@metamask/controllers@^26.0.0": version "26.0.0" resolved "git+https://github.com/MetaMask/controllers.git#d4e9507d9612f2d36c3f848333b33330a19b811b" @@ -5322,10 +5363,10 @@ immer "^9.0.6" uuid "^8.3.2" -"@metamask/keyring-controller@^5.0.0": - version "5.1.0" - resolved "https://registry.yarnpkg.com/@metamask/keyring-controller/-/keyring-controller-5.1.0.tgz#19bffa4ed80e38481dd3f97c638027b509adcb8b" - integrity sha512-/Ft+6Gsf9usuoK4MSVakc5GqfGMC4Jnl1M5gw9VTT78VmZhdPfy+k54nNTY8XMYMnIlL/Fiyjc/iPS+bcTgodg== +"@metamask/keyring-controller@^6.0.0": + version "6.0.0" + resolved "https://registry.yarnpkg.com/@metamask/keyring-controller/-/keyring-controller-6.0.0.tgz#e774c95ad098903b8fc3320c308bb28041b3b141" + integrity sha512-PNyqfMDwWQ0kexKapZ6nTVKtAPvtQnHYPZFJu5ejpSgaW91TfhGy1/fmAZ8+9yTqrhI3c77W1Qye5qgJgMx9Sw== dependencies: "@keystonehq/metamask-airgapped-keyring" "^0.6.1" "@metamask/base-controller" "^3.0.0" @@ -5337,6 +5378,7 @@ async-mutex "^0.2.6" ethereumjs-util "^7.0.10" ethereumjs-wallet "^1.0.1" + immer "^9.0.6" "@metamask/message-manager@^5.0.0": version "5.0.0" @@ -5530,7 +5572,7 @@ semver "^7.3.8" superstruct "^1.0.3" -"@metamask/utils@^5.0.2": +"@metamask/utils@^5.0.1", "@metamask/utils@^5.0.2": version "5.0.2" resolved "https://registry.yarnpkg.com/@metamask/utils/-/utils-5.0.2.tgz#140ba5061d90d9dac0280c19cab101bc18c8857c" integrity sha512-yfmE79bRQtnMzarnKfX7AEJBwFTxvTyw3nBQlu/5rmGXrjAeAMltoGxO62TFurxrQAFMNa/fEjIHNvungZp0+g== @@ -6310,6 +6352,13 @@ resolved "https://registry.yarnpkg.com/@socket.io/component-emitter/-/component-emitter-3.1.0.tgz#96116f2a912e0c02817345b3c10751069920d553" integrity sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg== +"@spruceid/siwe-parser@1.1.3": + version "1.1.3" + resolved "https://registry.yarnpkg.com/@spruceid/siwe-parser/-/siwe-parser-1.1.3.tgz#0eebe8bbd63c6de89cb44c06b6329b00b305df65" + integrity sha512-oQ8PcwDqjGWJvLmvAF2yzd6iniiWxK0Qtz+Dw+gLD/W5zOQJiKIUXwslHOm8VB8OOOKW9vfR3dnPBhHaZDvRsw== + dependencies: + apg-js "^4.1.1" + "@stablelib/aead@^1.0.1": version "1.0.1" resolved "https://registry.yarnpkg.com/@stablelib/aead/-/aead-1.0.1.tgz#c4b1106df9c23d1b867eb9b276d8f42d5fc4c0c3" @@ -9079,6 +9128,11 @@ anymatch@^3.0.3, anymatch@~3.1.2: normalize-path "^3.0.0" picomatch "^2.0.4" +apg-js@^4.1.1: + version "4.1.3" + resolved "https://registry.yarnpkg.com/apg-js/-/apg-js-4.1.3.tgz#0cb9dc99f8830740d7a8f9fc0048fa618ae4d199" + integrity sha512-XYyDcoBho8OpnWPRnedMwyL+76ovCtsESerHZEfY39dO4IrEqN97mdEYkOyHa0XTX5+3+U5FmpqPLttK0f7n6g== + appdirsjs@^1.2.4: version "1.2.6" resolved "https://registry.yarnpkg.com/appdirsjs/-/appdirsjs-1.2.6.tgz#fccf9ee543315492867cacfcfd4a2b32257d30ac" From b526a3caaa9427b73e14082358f9c23d61b433d3 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Sun, 9 Jul 2023 23:29:14 -0400 Subject: [PATCH 12/67] Update keyring-controller constructor --- app/core/Engine.ts | 78 +++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/app/core/Engine.ts b/app/core/Engine.ts index 34e15175c84..67fa7b97e94 100644 --- a/app/core/Engine.ts +++ b/app/core/Engine.ts @@ -244,30 +244,34 @@ class Engine { return newIdentities; }; - const keyringState = - initialKeyringState || initialState.KeyringController; + const keyringState = { + keyringTypes: additionalKeyrings, + ...initialState.KeyringController, + ...initialKeyringState, + }; - const keyringController = new KeyringController( - { - removeIdentity: preferencesController.removeIdentity.bind( - preferencesController, - ), - syncIdentities: preferencesController.syncIdentities.bind( - preferencesController, - ), - updateIdentities: preferencesController.updateIdentities.bind( - preferencesController, - ), - setSelectedAddress: preferencesController.setSelectedAddress.bind( - preferencesController, - ), - setAccountLabel: preferencesController.setAccountLabel.bind( - preferencesController, - ), - }, - { encryptor, keyringTypes: additionalKeyrings }, - keyringState, - ); + const keyringController = new KeyringController({ + removeIdentity: preferencesController.removeIdentity.bind( + preferencesController, + ), + syncIdentities: preferencesController.syncIdentities.bind( + preferencesController, + ), + updateIdentities: preferencesController.updateIdentities.bind( + preferencesController, + ), + setSelectedAddress: preferencesController.setSelectedAddress.bind( + preferencesController, + ), + setAccountLabel: preferencesController.setAccountLabel.bind( + preferencesController, + ), + encryptor, + messenger: this.controllerMessenger.getRestricted({ + name: 'KeyringController', + }), + state: keyringState, + }); const controllers = [ keyringController, @@ -516,19 +520,21 @@ class Engine { } handleVaultBackup() { - const { KeyringController } = this.context; - KeyringController.subscribe((state) => - backupVault(state) - .then((result) => { - if (result.success) { - Logger.log('Engine', 'Vault back up successful'); - } else { - Logger.log('Engine', 'Vault backup failed', result.error); - } - }) - .catch((error) => { - Logger.error(error, 'Engine Vault backup failed'); - }), + // @ts-expect-error Expect type error + this.controllerMessenger.subscribe( + 'KeyringController:getState', + (state: any) => + backupVault(state) + .then((result) => { + if (result.success) { + Logger.log('Engine', 'Vault back up successful'); + } else { + Logger.log('Engine', 'Vault backup failed', result.error); + } + }) + .catch((error) => { + Logger.error(error, 'Engine Vault backup failed'); + }), ); } From 9420c470779e3afa8a4772f48ff9694b000d5c8e Mon Sep 17 00:00:00 2001 From: gantunesr Date: Sun, 9 Jul 2023 23:29:57 -0400 Subject: [PATCH 13/67] Fix BaseControllerV2 change --- app/core/EngineService/EngineService.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/core/EngineService/EngineService.ts b/app/core/EngineService/EngineService.ts index f2bb124f8b7..3556eb09388 100644 --- a/app/core/EngineService/EngineService.ts +++ b/app/core/EngineService/EngineService.ts @@ -41,7 +41,10 @@ class EngineService { { name: 'TokensController' }, { name: 'TokenDetectionController' }, { name: 'NftDetectionController' }, - { name: 'KeyringController' }, + { + name: 'KeyringController', + key: `${engine.context.KeyringController.name}:stateChange`, + }, { name: 'AccountTrackerController' }, { name: 'NetworkController', From cd650cdc5ead4abaa9bc6675197650f258756d33 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Tue, 11 Jul 2023 22:23:41 -0400 Subject: [PATCH 14/67] Add @metamask/eth-keyring-controller --- package.json | 1 + yarn.lock | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 4b2629d9d4c..5d29f737af8 100644 --- a/package.json +++ b/package.json @@ -156,6 +156,7 @@ "@metamask/contract-metadata": "^2.1.0", "@metamask/controller-utils": "3.3.0", "@metamask/design-tokens": "^1.11.1", + "@metamask/eth-keyring-controller": "10.0.1", "@metamask/eth-sig-util": "^4.0.1", "@metamask/etherscan-link": "^2.0.0", "@metamask/gas-fee-controller": "4.0.0", diff --git a/yarn.lock b/yarn.lock index fc49bb1fe88..8ae09ae2e4a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5286,7 +5286,7 @@ "@metamask/scure-bip39" "^2.0.3" ethereum-cryptography "^1.1.2" -"@metamask/eth-keyring-controller@^10.0.1": +"@metamask/eth-keyring-controller@10.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== From 5b7805d3e9b8076b2e8a1021619cabd1e5c01a72 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Tue, 11 Jul 2023 22:23:49 -0400 Subject: [PATCH 15/67] Add @metamask/eth-keyring-controller to declarations --- app/declarations.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/declarations.d.ts b/app/declarations.d.ts index 06d7c44bfd3..cf96e5083ac 100644 --- a/app/declarations.d.ts +++ b/app/declarations.d.ts @@ -12,3 +12,5 @@ declare module '*.png' { const content: ImageSourcePropType; export default content; } + +declare module '@metamask/eth-keyring-controller'; From c4269aad20077de6f6fcc8ea0d2d508bcdb84e98 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Tue, 11 Jul 2023 22:24:18 -0400 Subject: [PATCH 16/67] Add QRHardwareKeyring builder --- app/core/Engine.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/core/Engine.ts b/app/core/Engine.ts index 67fa7b97e94..628509cf845 100644 --- a/app/core/Engine.ts +++ b/app/core/Engine.ts @@ -28,6 +28,7 @@ import { PermissionController } from '@metamask/permission-controller'; import SwapsController, { swapsUtils } from '@metamask/swaps-controller'; import AsyncStorage from '@react-native-async-storage/async-storage'; import { MetaMaskKeyring as QRHardwareKeyring } from '@keystonehq/metamask-airgapped-keyring'; +import { keyringBuilderFactory } from '@metamask/eth-keyring-controller'; import Encryptor from './Encryptor'; import Networks, { isMainnetByChainId, @@ -267,10 +268,12 @@ class Engine { preferencesController, ), encryptor, + // @ts-expect-error Error expected. messenger: this.controllerMessenger.getRestricted({ name: 'KeyringController', }), state: keyringState, + keyringBuilders: [keyringBuilderFactory(QRHardwareKeyring)], }); const controllers = [ From c562daf9bf7bb362e991dcfd101bcb57c7cad8a2 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Tue, 11 Jul 2023 22:45:00 -0400 Subject: [PATCH 17/67] Subscribe to lock and unlock --- app/core/BackgroundBridge/BackgroundBridge.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/core/BackgroundBridge/BackgroundBridge.js b/app/core/BackgroundBridge/BackgroundBridge.js index 24a42bf863d..4f24f6e7c3b 100644 --- a/app/core/BackgroundBridge/BackgroundBridge.js +++ b/app/core/BackgroundBridge/BackgroundBridge.js @@ -100,8 +100,11 @@ export class BackgroundBridge extends EventEmitter { ); Engine.context.PreferencesController.subscribe(this.sendStateUpdate); - Engine.context.KeyringController.onLock(this.onLock.bind(this)); - Engine.context.KeyringController.onUnlock(this.onUnlock.bind(this)); + Engine.controllerMessenger.subscribe('KeyringController:lock', this.onLock); + Engine.controllerMessenger.subscribe( + 'KeyringController:unlock', + this.onUnlock, + ); this.on('update', this.onStateUpdate); From 5c5dfacdcc97dd0eea0e8be8b7f007735b0200f2 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Wed, 12 Jul 2023 00:43:05 -0400 Subject: [PATCH 18/67] Fix exportSeedPhrase breaking change --- app/components/Views/ChoosePassword/index.js | 5 +---- app/components/Views/ResetPassword/index.js | 5 +---- app/core/Vault.js | 5 +---- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/app/components/Views/ChoosePassword/index.js b/app/components/Views/ChoosePassword/index.js index cc33a07e271..8139cfd194f 100644 --- a/app/components/Views/ChoosePassword/index.js +++ b/app/components/Views/ChoosePassword/index.js @@ -551,10 +551,7 @@ class ChoosePassword extends PureComponent { const { KeyringController } = Engine.context; const { password } = this.state; const keychainPassword = this.keyringControllerPasswordSet ? password : ''; - const mnemonic = await KeyringController.exportSeedPhrase( - keychainPassword, - ).toString(); - return JSON.stringify(mnemonic).replace(/"/g, ''); + return await KeyringController.exportSeedPhrase(keychainPassword); }; jumpToConfirmPassword = () => { diff --git a/app/components/Views/ResetPassword/index.js b/app/components/Views/ResetPassword/index.js index e7c64f2f346..d45604a6b51 100644 --- a/app/components/Views/ResetPassword/index.js +++ b/app/components/Views/ResetPassword/index.js @@ -473,10 +473,7 @@ class ResetPassword extends PureComponent { const { KeyringController } = Engine.context; const { originalPassword } = this.state; const keychainPassword = originalPassword; - const mnemonic = await KeyringController.exportSeedPhrase( - keychainPassword, - ).toString(); - return JSON.stringify(mnemonic).replace(/"/g, ''); + return await KeyringController.exportSeedPhrase(keychainPassword); }; jumpToConfirmPassword = () => { diff --git a/app/core/Vault.js b/app/core/Vault.js index 615b1bd0925..9cf4876fd23 100644 --- a/app/core/Vault.js +++ b/app/core/Vault.js @@ -10,10 +10,7 @@ import { KeyringTypes } from '@metamask/keyring-controller'; */ export const getSeedPhrase = async (password = '') => { const { KeyringController } = Engine.context; - const mnemonic = await KeyringController.exportSeedPhrase( - password, - ).toString(); - return JSON.stringify(mnemonic).replace(/"/g, ''); + return await KeyringController.exportSeedPhrase(password); }; /** From 75118fbffb9936d3258666f5841b626c6d689748 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Wed, 12 Jul 2023 00:55:18 -0400 Subject: [PATCH 19/67] Update event subscription --- app/core/Engine.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/core/Engine.ts b/app/core/Engine.ts index 628509cf845..0d8ea6728fe 100644 --- a/app/core/Engine.ts +++ b/app/core/Engine.ts @@ -525,7 +525,7 @@ class Engine { handleVaultBackup() { // @ts-expect-error Expect type error this.controllerMessenger.subscribe( - 'KeyringController:getState', + 'KeyringController:stateChange', (state: any) => backupVault(state) .then((result) => { From 9034bb57a223e62740e1c0980a36aab3e20d3d37 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Wed, 12 Jul 2023 22:11:48 -0400 Subject: [PATCH 20/67] Update yarn.lock --- yarn.lock | 65 +++++++++---------------------------------------------- 1 file changed, 10 insertions(+), 55 deletions(-) diff --git a/yarn.lock b/yarn.lock index 1e32f02622d..fcb1a02659b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5169,20 +5169,7 @@ resolved "https://registry.yarnpkg.com/@metamask/contract-metadata/-/contract-metadata-2.2.0.tgz#277764d0d56e37180ae7644a9d11eb96295b36fc" integrity sha512-SM6A4C7vXNbVpgMTX67kfW8QWvu3eSXxMZlY5PqZBTkvri1s9zgQ0uwRkK5r2VXNEoVmXCDnnEX/tX5EzzgNUQ== -"@metamask/controller-utils@3.3.0": - version "3.3.0" - resolved "https://registry.yarnpkg.com/@metamask/controller-utils/-/controller-utils-3.3.0.tgz#3db16c9965482e9563cdaeefe1ca484468666c22" - integrity sha512-uSnGoC1t2MYkP3C0wJB1iGOIs6nv+63e86DTPh/qM4CBOBFtlUVZF4Neo8ukqDAU4pURgVHdWJYnSjD2U5Zixg== - dependencies: - "@metamask/utils" "^5.0.1" - "@spruceid/siwe-parser" "1.1.3" - eth-ens-namehash "^2.0.8" - eth-rpc-errors "^4.0.2" - ethereumjs-util "^7.0.10" - ethjs-unit "^0.1.6" - fast-deep-equal "^3.1.3" - -"@metamask/controller-utils@^3.0.0": +"@metamask/controller-utils@^3.0.0", "@metamask/controller-utils@^3.4.0", "@metamask/controller-utils@^4.0.0", "@metamask/controller-utils@^4.1.0", "@metamask/controller-utils@~3.0.0": version "3.0.0" resolved "https://registry.yarnpkg.com/@metamask/controller-utils/-/controller-utils-3.0.0.tgz#e0984cdab14280409297671b5858891527c5e4ee" integrity sha512-JjFWBZnnh5DSX2tRsw5xtXxaqVkTzaW7mkSZ+lL3LoCAw47Cf8zGP1kGR6VKxcceKi+MpEFvZr7gf1OFnOoEjw== @@ -5193,34 +5180,6 @@ ethjs-unit "^0.1.6" fast-deep-equal "^3.1.3" -"@metamask/controller-utils@^3.4.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== - dependencies: - "@metamask/utils" "^5.0.1" - "@spruceid/siwe-parser" "1.1.3" - eth-ens-namehash "^2.0.8" - eth-rpc-errors "^4.0.2" - ethereumjs-util "^7.0.10" - ethjs-unit "^0.1.6" - fast-deep-equal "^3.1.3" - -"@metamask/controller-utils@^4.0.0", "@metamask/controller-utils@^4.1.0": - version "4.1.0" - resolved "https://registry.yarnpkg.com/@metamask/controller-utils/-/controller-utils-4.1.0.tgz#bb090de5172f703c414fdfa5f9be4eb9e32f9657" - integrity sha512-KsNpzdy6QkkZVgqfheCuGZwPrp+Luj7Z0+5rqgBAs+K7P4sFWwucay4jSxqZ5dx/kuG5bFG8ABpH5I+zaZq6Lw== - dependencies: - "@metamask/utils" "^5.0.2" - "@spruceid/siwe-parser" "1.1.3" - babel-runtime "^6.26.0" - eth-ens-namehash "^2.0.8" - eth-query "^2.1.2" - eth-rpc-errors "^4.0.2" - ethereumjs-util "^7.0.10" - ethjs-unit "^0.1.6" - fast-deep-equal "^3.1.3" - "@metamask/controllers@^26.0.0": version "26.0.0" resolved "git+https://github.com/MetaMask/controllers.git#d4e9507d9612f2d36c3f848333b33330a19b811b" @@ -5487,6 +5446,14 @@ resolved "https://registry.yarnpkg.com/@metamask/safe-event-emitter/-/safe-event-emitter-2.0.0.tgz#af577b477c683fad17c619a78208cede06f9605c" integrity sha512-/kSXhY692qiV1MXu6EeOZvg5nECLclxNXcKCxJ3cXQgYuRymRHpdx/t7JXfsK+JLjwA1e1c1/SBrlQYpusC29Q== +"@metamask/scure-bip39@^2.0.3", "@metamask/scure-bip39@^2.1.0": + version "2.1.0" + resolved "https://registry.yarnpkg.com/@metamask/scure-bip39/-/scure-bip39-2.1.0.tgz#13456884736e56ede15e471bd93c0aa0acdedd0b" + integrity sha512-Ndwdnld0SI6YaftEUUVq20sdoWcWNXsJXxvQkbiY42FKmrA16U6WoSh9Eq+NpugpKKwK6f5uvaTDusjndiEDGQ== + dependencies: + "@noble/hashes" "~1.1.1" + "@scure/base" "~1.1.0" + "@metamask/sdk-communication-layer@^0.5.0": version "0.5.0" resolved "https://registry.yarnpkg.com/@metamask/sdk-communication-layer/-/sdk-communication-layer-0.5.0.tgz#a2333ab1f0d96c52aed9f749e7539e9e927f53db" @@ -5564,7 +5531,7 @@ semver "^7.3.8" superstruct "^1.0.3" -"@metamask/utils@^5.0.1", "@metamask/utils@^5.0.2": +"@metamask/utils@^5.0.2": version "5.0.2" resolved "https://registry.yarnpkg.com/@metamask/utils/-/utils-5.0.2.tgz#140ba5061d90d9dac0280c19cab101bc18c8857c" integrity sha512-yfmE79bRQtnMzarnKfX7AEJBwFTxvTyw3nBQlu/5rmGXrjAeAMltoGxO62TFurxrQAFMNa/fEjIHNvungZp0+g== @@ -6344,13 +6311,6 @@ resolved "https://registry.yarnpkg.com/@socket.io/component-emitter/-/component-emitter-3.1.0.tgz#96116f2a912e0c02817345b3c10751069920d553" integrity sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg== -"@spruceid/siwe-parser@1.1.3": - version "1.1.3" - resolved "https://registry.yarnpkg.com/@spruceid/siwe-parser/-/siwe-parser-1.1.3.tgz#0eebe8bbd63c6de89cb44c06b6329b00b305df65" - integrity sha512-oQ8PcwDqjGWJvLmvAF2yzd6iniiWxK0Qtz+Dw+gLD/W5zOQJiKIUXwslHOm8VB8OOOKW9vfR3dnPBhHaZDvRsw== - dependencies: - apg-js "^4.1.1" - "@stablelib/aead@^1.0.1": version "1.0.1" resolved "https://registry.yarnpkg.com/@stablelib/aead/-/aead-1.0.1.tgz#c4b1106df9c23d1b867eb9b276d8f42d5fc4c0c3" @@ -9120,11 +9080,6 @@ anymatch@^3.0.3, anymatch@~3.1.2: normalize-path "^3.0.0" picomatch "^2.0.4" -apg-js@^4.1.1: - version "4.1.3" - resolved "https://registry.yarnpkg.com/apg-js/-/apg-js-4.1.3.tgz#0cb9dc99f8830740d7a8f9fc0048fa618ae4d199" - integrity sha512-XYyDcoBho8OpnWPRnedMwyL+76ovCtsESerHZEfY39dO4IrEqN97mdEYkOyHa0XTX5+3+U5FmpqPLttK0f7n6g== - appdirsjs@^1.2.4: version "1.2.6" resolved "https://registry.yarnpkg.com/appdirsjs/-/appdirsjs-1.2.6.tgz#fccf9ee543315492867cacfcfd4a2b32257d30ac" From 49d2b0fbbf6f78fa429bf522394db6b9d3c5ab9f Mon Sep 17 00:00:00 2001 From: gantunesr Date: Wed, 12 Jul 2023 22:12:15 -0400 Subject: [PATCH 21/67] Add temporary solution to BackgroundBridge --- app/core/BackgroundBridge/BackgroundBridge.js | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/app/core/BackgroundBridge/BackgroundBridge.js b/app/core/BackgroundBridge/BackgroundBridge.js index 4f24f6e7c3b..bb66fd47d2c 100644 --- a/app/core/BackgroundBridge/BackgroundBridge.js +++ b/app/core/BackgroundBridge/BackgroundBridge.js @@ -156,10 +156,14 @@ export class BackgroundBridge extends EventEmitter { return; } - this.sendNotification({ - method: NOTIFICATION_NAMES.unlockStateChanged, - params: true, - }); + try { + this.sendNotification({ + method: NOTIFICATION_NAMES.unlockStateChanged, + params: true, + }); + } catch (e) { + // Do nothing + } } onLock() { @@ -178,10 +182,14 @@ export class BackgroundBridge extends EventEmitter { return; } - this.sendNotification({ - method: NOTIFICATION_NAMES.unlockStateChanged, - params: false, - }); + try { + this.sendNotification({ + method: NOTIFICATION_NAMES.unlockStateChanged, + params: false, + }); + } catch (e) { + // Do nothing + } } getProviderNetworkState({ network }) { From 6e9b5000820e4a00f9d3a3768e8d2a0c12d190df Mon Sep 17 00:00:00 2001 From: gantunesr Date: Mon, 24 Jul 2023 11:19:58 +0200 Subject: [PATCH 22/67] Lint --- .../Views/RevealPrivateCredential/RevealPrivateCredential.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/Views/RevealPrivateCredential/RevealPrivateCredential.tsx b/app/components/Views/RevealPrivateCredential/RevealPrivateCredential.tsx index 3e300fdb67c..5dc26b49428 100644 --- a/app/components/Views/RevealPrivateCredential/RevealPrivateCredential.tsx +++ b/app/components/Views/RevealPrivateCredential/RevealPrivateCredential.tsx @@ -415,7 +415,7 @@ const RevealPrivateCredential = ({ const enableNextButton = async () => { const { KeyringController } = Engine.context as any; try { - await KeyringController.verifyPassword(password) + await KeyringController.verifyPassword(password); } catch { return false; } From 7beb9c2fc9544c15ebe4a00b73c0902aec3f2cd0 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Mon, 24 Jul 2023 13:00:11 +0200 Subject: [PATCH 23/67] Add fix for initial engine state and fixture --- app/core/Engine.test.js | 4 ++++ app/util/test/initial-background-state.json | 2 ++ 2 files changed, 6 insertions(+) diff --git a/app/core/Engine.test.js b/app/core/Engine.test.js index dcc33fbe995..5b1d6179460 100644 --- a/app/core/Engine.test.js +++ b/app/core/Engine.test.js @@ -40,6 +40,10 @@ describe('Engine', () => { // Use this to keep the unit test initial background state fixture up-to-date it('matches initial state fixture', () => { const engine = Engine.init({}); + // Replace [Function MetaMaskKeyring] in KeyringController since JSON can't support methods + engine.datamodel.state.KeyringController.keyringTypes = [ + ['MetaMaskKeyring'], + ]; const backgroundState = engine.datamodel.state; // Replace phishing controller fallback config, as it bloats the test fixture too much backgroundState.PhishingController.listState.allowlist = []; diff --git a/app/util/test/initial-background-state.json b/app/util/test/initial-background-state.json index 19b68e56835..619d10bdd1d 100644 --- a/app/util/test/initial-background-state.json +++ b/app/util/test/initial-background-state.json @@ -1,5 +1,7 @@ { "KeyringController": { + "isUnlocked": false, + "keyringTypes": [["MetaMaskKeyring"]], "keyrings": [] }, "AccountTrackerController": { From b17622303236815b5d42907157afeaa232d7545e Mon Sep 17 00:00:00 2001 From: gantunesr Date: Mon, 24 Jul 2023 13:18:04 +0200 Subject: [PATCH 24/67] Modify password logic in reveal credentials --- .../RevealPrivateCredential.tsx | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/app/components/Views/RevealPrivateCredential/RevealPrivateCredential.tsx b/app/components/Views/RevealPrivateCredential/RevealPrivateCredential.tsx index 5dc26b49428..a08fa57f14d 100644 --- a/app/components/Views/RevealPrivateCredential/RevealPrivateCredential.tsx +++ b/app/components/Views/RevealPrivateCredential/RevealPrivateCredential.tsx @@ -412,16 +412,6 @@ const RevealPrivateCredential = ({ setIsModalVisible(false); }; - const enableNextButton = async () => { - const { KeyringController } = Engine.context as any; - try { - await KeyringController.verifyPassword(password); - } catch { - return false; - } - return true; - }; - const renderModal = ( isPrivateKeyReveal: boolean, privCredentialName: string, @@ -540,7 +530,7 @@ const RevealPrivateCredential = ({ onCancelPress={unlocked ? done : cancelReveal} onConfirmPress={() => tryUnlock()} showConfirmButton={!unlocked} - confirmDisabled={!enableNextButton()} + confirmDisabled={password.length < 8} cancelTestID={SECRET_RECOVERY_PHRASE_CANCEL_BUTTON_ID} confirmTestID={SECRET_RECOVERY_PHRASE_NEXT_BUTTON_ID} > From 9a9c5ca02ac4dd587c6b1534bb2c64b722117efc Mon Sep 17 00:00:00 2001 From: gantunesr Date: Wed, 26 Jul 2023 16:11:15 -0400 Subject: [PATCH 25/67] Remove fixture fix --- app/core/Engine.test.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/core/Engine.test.js b/app/core/Engine.test.js index 5b1d6179460..dcc33fbe995 100644 --- a/app/core/Engine.test.js +++ b/app/core/Engine.test.js @@ -40,10 +40,6 @@ describe('Engine', () => { // Use this to keep the unit test initial background state fixture up-to-date it('matches initial state fixture', () => { const engine = Engine.init({}); - // Replace [Function MetaMaskKeyring] in KeyringController since JSON can't support methods - engine.datamodel.state.KeyringController.keyringTypes = [ - ['MetaMaskKeyring'], - ]; const backgroundState = engine.datamodel.state; // Replace phishing controller fallback config, as it bloats the test fixture too much backgroundState.PhishingController.listState.allowlist = []; From dfec3a03a359e1a8c66d66c5489e29d5d7dc078a Mon Sep 17 00:00:00 2001 From: gantunesr Date: Wed, 26 Jul 2023 16:11:34 -0400 Subject: [PATCH 26/67] Update fixture --- app/util/test/initial-background-state.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/util/test/initial-background-state.json b/app/util/test/initial-background-state.json index 619d10bdd1d..65297a29b87 100644 --- a/app/util/test/initial-background-state.json +++ b/app/util/test/initial-background-state.json @@ -1,7 +1,7 @@ { "KeyringController": { "isUnlocked": false, - "keyringTypes": [["MetaMaskKeyring"]], + "keyringTypes": ["QR Hardware Wallet Device"], "keyrings": [] }, "AccountTrackerController": { From 674e3cd8a327c48b937fe9f8181d13a01b692aa7 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Wed, 26 Jul 2023 16:12:31 -0400 Subject: [PATCH 27/67] Update KeyringController constructor --- app/core/Engine.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/core/Engine.ts b/app/core/Engine.ts index 146c61af89e..7ff2dab563d 100644 --- a/app/core/Engine.ts +++ b/app/core/Engine.ts @@ -16,6 +16,7 @@ import { ControllerMessenger } from '@metamask/base-controller'; import { ComposableController } from '@metamask/composable-controller'; import { KeyringController, + KeyringTypes, SignTypedDataVersion, } from '@metamask/keyring-controller'; import { NetworkController } from '@metamask/network-controller'; @@ -235,8 +236,6 @@ class Engine { const phishingController = new PhishingController(); phishingController.maybeUpdateState(); - const additionalKeyrings = [QRHardwareKeyring]; - const getIdentities = () => { const identities = preferencesController.state.identities; const newIdentities = {}; @@ -247,7 +246,7 @@ class Engine { }; const keyringState = { - keyringTypes: additionalKeyrings, + keyringTypes: [KeyringTypes.qr], ...initialState.KeyringController, ...initialKeyringState, }; From 50285e1cade41d6c1a9eca4876fb4ef83106b795 Mon Sep 17 00:00:00 2001 From: Gustavo Antunes <17601467+gantunesr@users.noreply.github.com> Date: Thu, 27 Jul 2023 08:45:21 -0400 Subject: [PATCH 28/67] Update app/core/BackgroundBridge/BackgroundBridge.js Bind object in subscription Co-authored-by: Mark Stacey --- app/core/BackgroundBridge/BackgroundBridge.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/core/BackgroundBridge/BackgroundBridge.js b/app/core/BackgroundBridge/BackgroundBridge.js index bb66fd47d2c..ad70d7cd1af 100644 --- a/app/core/BackgroundBridge/BackgroundBridge.js +++ b/app/core/BackgroundBridge/BackgroundBridge.js @@ -100,7 +100,7 @@ export class BackgroundBridge extends EventEmitter { ); Engine.context.PreferencesController.subscribe(this.sendStateUpdate); - Engine.controllerMessenger.subscribe('KeyringController:lock', this.onLock); + Engine.controllerMessenger.subscribe('KeyringController:lock', this.onLock.bind(this)); Engine.controllerMessenger.subscribe( 'KeyringController:unlock', this.onUnlock, From bf4c22cbf9b6b4540222347cce7dc6070578ddf8 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Thu, 27 Jul 2023 08:52:43 -0400 Subject: [PATCH 29/67] Remove getSeedPhrase from ResetPassword --- app/components/Views/ResetPassword/index.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/app/components/Views/ResetPassword/index.js b/app/components/Views/ResetPassword/index.js index 7aac2a7fbd2..22019188450 100644 --- a/app/components/Views/ResetPassword/index.js +++ b/app/components/Views/ResetPassword/index.js @@ -465,18 +465,6 @@ class ResetPassword extends PureComponent { ); }; - /** - * Returns current vault seed phrase - * It does it using an empty password or a password set by the user - * depending on the state the app is currently in - */ - getSeedPhrase = async () => { - const { KeyringController } = Engine.context; - const { originalPassword } = this.state; - const keychainPassword = originalPassword; - return await KeyringController.exportSeedPhrase(keychainPassword); - }; - jumpToConfirmPassword = () => { const { current } = this.confirmPasswordInput; current && current.focus(); From 6ea94076d04c82e886ccab5772896707220f16c3 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Thu, 27 Jul 2023 13:22:38 -0400 Subject: [PATCH 30/67] Update uint8ArrayToMnemonic method --- app/util/mnemonic/index.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/util/mnemonic/index.ts b/app/util/mnemonic/index.ts index 6ac09a70f25..6717144e728 100644 --- a/app/util/mnemonic/index.ts +++ b/app/util/mnemonic/index.ts @@ -49,7 +49,6 @@ export const uint8ArrayToMnemonic = ( const recoveredIndices = Array.from( new Uint16Array(new Uint8Array(uint8Array).buffer), ); - return JSON.stringify(recoveredIndices.map((i) => wordlist[i]).join(' ')) - .replace(/"/g, '') - .trimEnd(); + + return recoveredIndices.map((i) => wordlist[i]).join(' '); }; From 223f956a1a0f89a3da6c74fc328175a9886fd784 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Thu, 27 Jul 2023 13:24:11 -0400 Subject: [PATCH 31/67] Update uint8ArrayToMnemonic method - Add trimEnd --- app/util/mnemonic/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/util/mnemonic/index.ts b/app/util/mnemonic/index.ts index 6717144e728..a5bf395c595 100644 --- a/app/util/mnemonic/index.ts +++ b/app/util/mnemonic/index.ts @@ -50,5 +50,5 @@ export const uint8ArrayToMnemonic = ( new Uint16Array(new Uint8Array(uint8Array).buffer), ); - return recoveredIndices.map((i) => wordlist[i]).join(' '); + return recoveredIndices.map((i) => wordlist[i]).join(' ').trimEnd(); }; From 9ba2624b4d284929ba6c48ff6e3b83f82e1c5e23 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Thu, 27 Jul 2023 14:05:52 -0400 Subject: [PATCH 32/67] Update controller subscription to bind method --- app/core/BackgroundBridge/BackgroundBridge.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/core/BackgroundBridge/BackgroundBridge.js b/app/core/BackgroundBridge/BackgroundBridge.js index ad70d7cd1af..f23f0573fe0 100644 --- a/app/core/BackgroundBridge/BackgroundBridge.js +++ b/app/core/BackgroundBridge/BackgroundBridge.js @@ -103,7 +103,7 @@ export class BackgroundBridge extends EventEmitter { Engine.controllerMessenger.subscribe('KeyringController:lock', this.onLock.bind(this)); Engine.controllerMessenger.subscribe( 'KeyringController:unlock', - this.onUnlock, + this.onUnlock.bind(this), ); this.on('update', this.onStateUpdate); From 6caf6d33378de7605ac01cfb6a4d9f5f43223ab0 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Thu, 27 Jul 2023 14:06:10 -0400 Subject: [PATCH 33/67] Remove try-catch temporal fix --- app/core/BackgroundBridge/BackgroundBridge.js | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/app/core/BackgroundBridge/BackgroundBridge.js b/app/core/BackgroundBridge/BackgroundBridge.js index f23f0573fe0..c5e7591bbe3 100644 --- a/app/core/BackgroundBridge/BackgroundBridge.js +++ b/app/core/BackgroundBridge/BackgroundBridge.js @@ -156,14 +156,10 @@ export class BackgroundBridge extends EventEmitter { return; } - try { - this.sendNotification({ - method: NOTIFICATION_NAMES.unlockStateChanged, - params: true, - }); - } catch (e) { - // Do nothing - } + this.sendNotification({ + method: NOTIFICATION_NAMES.unlockStateChanged, + params: true, + }); } onLock() { @@ -182,14 +178,10 @@ export class BackgroundBridge extends EventEmitter { return; } - try { - this.sendNotification({ - method: NOTIFICATION_NAMES.unlockStateChanged, - params: false, - }); - } catch (e) { - // Do nothing - } + this.sendNotification({ + method: NOTIFICATION_NAMES.unlockStateChanged, + params: false, + }); } getProviderNetworkState({ network }) { From 06c1588d2173d4fae9885bc2a20f7a8e55a9ed75 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Thu, 27 Jul 2023 14:06:56 -0400 Subject: [PATCH 34/67] Update Keyring builder pattern --- app/core/Engine.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/core/Engine.ts b/app/core/Engine.ts index 3ac99ee8d3c..f445cdbf951 100644 --- a/app/core/Engine.ts +++ b/app/core/Engine.ts @@ -32,7 +32,6 @@ import { PermissionController } from '@metamask/permission-controller'; import SwapsController, { swapsUtils } from '@metamask/swaps-controller'; import AsyncStorage from '@react-native-async-storage/async-storage'; import { MetaMaskKeyring as QRHardwareKeyring } from '@keystonehq/metamask-airgapped-keyring'; -import { keyringBuilderFactory } from '@metamask/eth-keyring-controller'; import Encryptor from './Encryptor'; import Networks, { isMainnetByChainId, @@ -254,6 +253,9 @@ class Engine { ...initialKeyringState, }; + const qrKeyringBuilder = () => new QRHardwareKeyring(); + qrKeyringBuilder.type = QRHardwareKeyring.type; + const keyringController = new KeyringController({ removeIdentity: preferencesController.removeIdentity.bind( preferencesController, @@ -271,12 +273,11 @@ class Engine { preferencesController, ), encryptor, - // @ts-expect-error Error expected. messenger: this.controllerMessenger.getRestricted({ name: 'KeyringController', }), state: keyringState, - keyringBuilders: [keyringBuilderFactory(QRHardwareKeyring)], + keyringBuilders: [qrKeyringBuilder], }); const controllers = [ From d6f4a2f93643da747534a2bb84b171f98945fb7c Mon Sep 17 00:00:00 2001 From: gantunesr Date: Thu, 27 Jul 2023 14:32:31 -0400 Subject: [PATCH 35/67] Remove @metamask/eth-keyring-controller --- package.json | 1 - yarn.lock | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index b2797697cc1..5b3c172e4fa 100644 --- a/package.json +++ b/package.json @@ -161,7 +161,6 @@ "@metamask/contract-metadata": "^2.1.0", "@metamask/controller-utils": "^3.4.0", "@metamask/design-tokens": "^1.11.1", - "@metamask/eth-keyring-controller": "10.0.1", "@metamask/eth-sig-util": "^4.0.1", "@metamask/etherscan-link": "^2.0.0", "@metamask/gas-fee-controller": "4.0.0", diff --git a/yarn.lock b/yarn.lock index 2ec00918718..dc3853cec6c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5225,7 +5225,7 @@ "@metamask/scure-bip39" "^2.0.3" ethereum-cryptography "^1.1.2" -"@metamask/eth-keyring-controller@10.0.1", "@metamask/eth-keyring-controller@^10.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== From 0e8418a1163c912bd8839913903b991eb750a545 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Thu, 27 Jul 2023 14:33:34 -0400 Subject: [PATCH 36/67] Change state parameter pattern --- app/core/Engine.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/core/Engine.ts b/app/core/Engine.ts index f445cdbf951..2a27fe06cf0 100644 --- a/app/core/Engine.ts +++ b/app/core/Engine.ts @@ -247,12 +247,6 @@ class Engine { return newIdentities; }; - const keyringState = { - keyringTypes: [KeyringTypes.qr], - ...initialState.KeyringController, - ...initialKeyringState, - }; - const qrKeyringBuilder = () => new QRHardwareKeyring(); qrKeyringBuilder.type = QRHardwareKeyring.type; @@ -276,7 +270,7 @@ class Engine { messenger: this.controllerMessenger.getRestricted({ name: 'KeyringController', }), - state: keyringState, + state: initialKeyringState || initialState.KeyringController, keyringBuilders: [qrKeyringBuilder], }); From 2e319d34ce8928e0b65081ed4b696f5776f52817 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Thu, 27 Jul 2023 23:39:23 -0400 Subject: [PATCH 37/67] Remove unused value --- app/core/Engine.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/core/Engine.ts b/app/core/Engine.ts index 2a27fe06cf0..245b1636f85 100644 --- a/app/core/Engine.ts +++ b/app/core/Engine.ts @@ -16,7 +16,6 @@ import { ControllerMessenger } from '@metamask/base-controller'; import { ComposableController } from '@metamask/composable-controller'; import { KeyringController, - KeyringTypes, SignTypedDataVersion, } from '@metamask/keyring-controller'; import { NetworkController } from '@metamask/network-controller'; @@ -248,7 +247,7 @@ class Engine { }; const qrKeyringBuilder = () => new QRHardwareKeyring(); - qrKeyringBuilder.type = QRHardwareKeyring.type; + qrKeyringBuilder.type = QRHardwareKeyring.type; const keyringController = new KeyringController({ removeIdentity: preferencesController.removeIdentity.bind( From 1b26b15dd875db4a7f715b9abcef78884083d666 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Thu, 27 Jul 2023 23:39:43 -0400 Subject: [PATCH 38/67] Lint --- app/core/BackgroundBridge/BackgroundBridge.js | 5 ++++- app/util/mnemonic/index.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/core/BackgroundBridge/BackgroundBridge.js b/app/core/BackgroundBridge/BackgroundBridge.js index c5e7591bbe3..4e045020d1f 100644 --- a/app/core/BackgroundBridge/BackgroundBridge.js +++ b/app/core/BackgroundBridge/BackgroundBridge.js @@ -100,7 +100,10 @@ export class BackgroundBridge extends EventEmitter { ); Engine.context.PreferencesController.subscribe(this.sendStateUpdate); - Engine.controllerMessenger.subscribe('KeyringController:lock', this.onLock.bind(this)); + Engine.controllerMessenger.subscribe( + 'KeyringController:lock', + this.onLock.bind(this), + ); Engine.controllerMessenger.subscribe( 'KeyringController:unlock', this.onUnlock.bind(this), diff --git a/app/util/mnemonic/index.ts b/app/util/mnemonic/index.ts index a5bf395c595..948afdd20a4 100644 --- a/app/util/mnemonic/index.ts +++ b/app/util/mnemonic/index.ts @@ -50,5 +50,8 @@ export const uint8ArrayToMnemonic = ( new Uint16Array(new Uint8Array(uint8Array).buffer), ); - return recoveredIndices.map((i) => wordlist[i]).join(' ').trimEnd(); + return recoveredIndices + .map((i) => wordlist[i]) + .join(' ') + .trimEnd(); }; From 1fccf7c9bc9e8349d8abb5c3a4a0e0b0304ba84b Mon Sep 17 00:00:00 2001 From: gantunesr Date: Thu, 27 Jul 2023 23:40:00 -0400 Subject: [PATCH 39/67] Update engine fixture --- app/util/test/initial-background-state.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/util/test/initial-background-state.json b/app/util/test/initial-background-state.json index 65297a29b87..24a24203cc4 100644 --- a/app/util/test/initial-background-state.json +++ b/app/util/test/initial-background-state.json @@ -1,7 +1,7 @@ { "KeyringController": { "isUnlocked": false, - "keyringTypes": ["QR Hardware Wallet Device"], + "keyringTypes": [], "keyrings": [] }, "AccountTrackerController": { From 6ffc9f6a7f74ea43054ab1766fe16b92531bad42 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Fri, 28 Jul 2023 10:15:11 -0400 Subject: [PATCH 40/67] fix: Unlocking QR wallet accounts --- app/components/Views/ConnectQRHardware/index.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/components/Views/ConnectQRHardware/index.tsx b/app/components/Views/ConnectQRHardware/index.tsx index 605da537ec6..dc74d5d52ad 100644 --- a/app/components/Views/ConnectQRHardware/index.tsx +++ b/app/components/Views/ConnectQRHardware/index.tsx @@ -255,14 +255,10 @@ const ConnectQRHardware = ({ navigation }: IConnectQRHardwareProps) => { const { PreferencesController } = Engine.context as any; resetError(); setBlockingModalVisible(true); - const importedAccountAddresses = []; try { for (const account of checkedAccounts) { - const accountAddress = - await KeyringController.unlockQRHardwareWalletAccount(account); - importedAccountAddresses.push(accountAddress); + await KeyringController.unlockQRHardwareWalletAccount(account); } - PreferencesController.setSelectedAddress(importedAccountAddresses[0]); } catch (err) { Logger.log('Error: Connecting QR hardware wallet', err); } From 1020e424f9f626756f36975426ed73610b7c5b9b Mon Sep 17 00:00:00 2001 From: gantunesr Date: Fri, 28 Jul 2023 10:15:46 -0400 Subject: [PATCH 41/67] lint: Remove unused object --- app/components/Views/ConnectQRHardware/index.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/app/components/Views/ConnectQRHardware/index.tsx b/app/components/Views/ConnectQRHardware/index.tsx index dc74d5d52ad..cde8048415c 100644 --- a/app/components/Views/ConnectQRHardware/index.tsx +++ b/app/components/Views/ConnectQRHardware/index.tsx @@ -252,7 +252,6 @@ const ConnectQRHardware = ({ navigation }: IConnectQRHardwareProps) => { ); const onUnlock = useCallback(async () => { - const { PreferencesController } = Engine.context as any; resetError(); setBlockingModalVisible(true); try { From f06c323a9f07871dfe563071e674d81fcd6895b7 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Fri, 28 Jul 2023 11:12:54 -0400 Subject: [PATCH 42/67] Add patch to @metamask/keyring-controller --- .../@metamask+keyring-controller+6.0.0.patch | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 patches/@metamask+keyring-controller+6.0.0.patch diff --git a/patches/@metamask+keyring-controller+6.0.0.patch b/patches/@metamask+keyring-controller+6.0.0.patch new file mode 100644 index 00000000000..5c4b4317374 --- /dev/null +++ b/patches/@metamask+keyring-controller+6.0.0.patch @@ -0,0 +1,21 @@ +diff --git a/node_modules/@metamask/keyring-controller/dist/KeyringController.js b/node_modules/@metamask/keyring-controller/dist/KeyringController.js +index c905cc0..4827771 100644 +--- a/node_modules/@metamask/keyring-controller/dist/KeyringController.js ++++ b/node_modules/@metamask/keyring-controller/dist/KeyringController.js +@@ -679,12 +679,12 @@ class KeyringController extends base_controller_1.BaseControllerV2 { + forgetQRDevice() { + return __awaiter(this, void 0, void 0, function* () { + const keyring = yield this.getOrAddQRKeyring(); ++ const allAccounts = (yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").getAccounts()); + keyring.forgetDevice(); +- const accounts = (yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").getAccounts()); +- accounts.forEach((account) => { +- this.setSelectedAddress(account); +- }); ++ const remainingAccounts = (yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").getAccounts()); ++ const removedAccounts = allAccounts.filter((address) => !remainingAccounts.includes(address)); + yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").persistAllKeyrings(); ++ return { removedAccounts, remainingAccounts }; + }); + } + } From ba7e726c401164cb3e2b016dd553e48a9427f4e6 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Tue, 15 Aug 2023 20:48:22 -0400 Subject: [PATCH 43/67] Remove @metamask/eth-keyring-controller module declaration --- app/declarations.d.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/declarations.d.ts b/app/declarations.d.ts index e66a4c6c3b2..8eb32bc845f 100644 --- a/app/declarations.d.ts +++ b/app/declarations.d.ts @@ -19,5 +19,3 @@ declare module '*.png' { const content: ImageSourcePropType; export default content; } - -declare module '@metamask/eth-keyring-controller'; From 65409dc3a6fccd1c2f2d5adc3256c67e3afb9eca Mon Sep 17 00:00:00 2001 From: gantunesr Date: Tue, 15 Aug 2023 21:00:42 -0400 Subject: [PATCH 44/67] Update data type in state subscription --- app/core/Engine.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/core/Engine.ts b/app/core/Engine.ts index 245b1636f85..9ce2d09e5f7 100644 --- a/app/core/Engine.ts +++ b/app/core/Engine.ts @@ -17,6 +17,7 @@ import { ComposableController } from '@metamask/composable-controller'; import { KeyringController, SignTypedDataVersion, + KeyringControllerState, } from '@metamask/keyring-controller'; import { NetworkController } from '@metamask/network-controller'; import { PhishingController } from '@metamask/phishing-controller'; @@ -519,7 +520,7 @@ class Engine { // @ts-expect-error Expect type error this.controllerMessenger.subscribe( 'KeyringController:stateChange', - (state: any) => + (state: KeyringControllerState) => backupVault(state) .then((result) => { if (result.success) { From ebbeec2be818a31619b6783d5a713ad8c6601218 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Tue, 15 Aug 2023 21:01:00 -0400 Subject: [PATCH 45/67] Remove comment to ignore error --- app/core/Engine.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/app/core/Engine.ts b/app/core/Engine.ts index 9ce2d09e5f7..8d7a9b25aa6 100644 --- a/app/core/Engine.ts +++ b/app/core/Engine.ts @@ -517,7 +517,6 @@ class Engine { } handleVaultBackup() { - // @ts-expect-error Expect type error this.controllerMessenger.subscribe( 'KeyringController:stateChange', (state: KeyringControllerState) => From e5148b220293377fabd97b80e883b16e4a0cdb1b Mon Sep 17 00:00:00 2001 From: gantunesr Date: Tue, 15 Aug 2023 21:22:36 -0400 Subject: [PATCH 46/67] Update method uint8ArrayToMnemonic and fix test --- app/util/mnemonic/index.test.ts | 6 +++--- app/util/mnemonic/index.ts | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/util/mnemonic/index.test.ts b/app/util/mnemonic/index.test.ts index 8c19d30c709..8d2749e8fc6 100644 --- a/app/util/mnemonic/index.test.ts +++ b/app/util/mnemonic/index.test.ts @@ -57,16 +57,16 @@ describe('mnemonic::uint8ArrayToMnemonic', () => { 'fox', 'grape', 'horse', - 'ice cream', + 'abandon', 'jellyfish', ]; it('should convert a Uint8Array to a seed phrase', () => { const uint8Array = new Uint8Array([ - 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, + 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, ]); const expectedOutput = - 'apple banana carrot dog elephant fox grape horse ice cream jellyfish'; + 'apple banana carrot dog elephant fox grape horse abandon jellyfish'; const result = uint8ArrayToMnemonic(uint8Array, mockWordlist); diff --git a/app/util/mnemonic/index.ts b/app/util/mnemonic/index.ts index 948afdd20a4..1db634dec16 100644 --- a/app/util/mnemonic/index.ts +++ b/app/util/mnemonic/index.ts @@ -53,5 +53,4 @@ export const uint8ArrayToMnemonic = ( return recoveredIndices .map((i) => wordlist[i]) .join(' ') - .trimEnd(); }; From 247a06477740f7fe467ee499bd6c831301f449fc Mon Sep 17 00:00:00 2001 From: gantunesr Date: Tue, 15 Aug 2023 23:22:36 -0400 Subject: [PATCH 47/67] lint --- app/util/mnemonic/index.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/util/mnemonic/index.ts b/app/util/mnemonic/index.ts index 1db634dec16..6717144e728 100644 --- a/app/util/mnemonic/index.ts +++ b/app/util/mnemonic/index.ts @@ -50,7 +50,5 @@ export const uint8ArrayToMnemonic = ( new Uint16Array(new Uint8Array(uint8Array).buffer), ); - return recoveredIndices - .map((i) => wordlist[i]) - .join(' ') + return recoveredIndices.map((i) => wordlist[i]).join(' '); }; From 2cf0a8850b005b12dd725d94d668f8cc924c4d33 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Tue, 12 Sep 2023 10:57:27 -0300 Subject: [PATCH 48/67] chore: update @metamask/keyring-controller patch --- ...oller+6.0.0.patch => @metamask+keyring-controller+6.1.0.patch} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename patches/{@metamask+keyring-controller+6.0.0.patch => @metamask+keyring-controller+6.1.0.patch} (100%) diff --git a/patches/@metamask+keyring-controller+6.0.0.patch b/patches/@metamask+keyring-controller+6.1.0.patch similarity index 100% rename from patches/@metamask+keyring-controller+6.0.0.patch rename to patches/@metamask+keyring-controller+6.1.0.patch From 6c8dd3a274b89acd7e16efa4e61276189e5a497d Mon Sep 17 00:00:00 2001 From: gantunesr Date: Tue, 12 Sep 2023 11:06:25 -0300 Subject: [PATCH 49/67] fix: add caret to @metamask/gas-fee-controller package version --- package.json | 2 +- yarn.lock | 26 ++++++-------------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 4365df6ba17..18df6ef0b8f 100644 --- a/package.json +++ b/package.json @@ -168,7 +168,7 @@ "@metamask/design-tokens": "^1.12.0", "@metamask/eth-sig-util": "^4.0.1", "@metamask/etherscan-link": "^2.0.0", - "@metamask/gas-fee-controller": "4.0.0", + "@metamask/gas-fee-controller": "^4.0.0", "@metamask/keyring-controller": "^6.0.0", "@metamask/network-controller": "^7.0.0", "@metamask/permission-controller": "^4.0.1", diff --git a/yarn.lock b/yarn.lock index 8b6b2a45ab9..7bd5f9210af 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4071,14 +4071,14 @@ resolved "https://registry.yarnpkg.com/@metamask/etherscan-link/-/etherscan-link-2.1.0.tgz#c0be8e68445b7b83cf85bcc03a56cdf8e256c973" integrity sha512-ADuWlTUkFfN2vXlz81Bg/0BA+XRor+CdK1055p6k7H6BLIPoDKn9SBOFld9haQFuR9cKh/JYHcnlSIv5R4fUEw== -"@metamask/gas-fee-controller@4.0.0": - version "4.0.0" - resolved "https://registry.yarnpkg.com/@metamask/gas-fee-controller/-/gas-fee-controller-4.0.0.tgz#b3532373ed1a245aaecdd23903a02951e20ee47b" - integrity sha512-dIN8e4UAU8uOjUk4Zl1l8fwsWk8vFpFoeng2VHvfxkvDkK5XxNbxF4IidffRnoJpCaynNWNH0Y+7QrtSR3qf+w== +"@metamask/gas-fee-controller@^4.0.0": + version "4.0.1" + resolved "https://registry.yarnpkg.com/@metamask/gas-fee-controller/-/gas-fee-controller-4.0.1.tgz#12ddf59e68af724c1f91a078596c34a4af7beb6c" + integrity sha512-GQxZNZr0gi93nCv1/43BDjA/2TIw4sik4w84xJA+dH3UN7Nzo5JWGnqtjG6JYzwGd1YeYLXYe1H/+3WH12GoAA== dependencies: "@metamask/base-controller" "^2.0.0" - "@metamask/controller-utils" "^3.0.0" - "@metamask/network-controller" "^5.0.0" + "@metamask/controller-utils" "^3.1.0" + "@metamask/network-controller" "^6.0.0" "@types/uuid" "^8.3.0" babel-runtime "^6.26.0" eth-query "^2.1.2" @@ -4151,20 +4151,6 @@ resolved "https://registry.yarnpkg.com/@metamask/mobile-provider/-/mobile-provider-2.1.0.tgz#685b2f6a55d24197af3f26de4dd0bb78e10ac83e" integrity sha512-VuVUIZ5jEQmLaU8SJC8692crxtNncsxyR9q5j1J6epyMHUU75WTtQdq7VSsu1ghkmP9NXNAz3inlWOGsbT8lLA== -"@metamask/network-controller@^5.0.0": - version "5.0.0" - resolved "https://registry.yarnpkg.com/@metamask/network-controller/-/network-controller-5.0.0.tgz#7f14a06f9ebec738888d6e2bf10ae05a4caabcb6" - integrity sha512-rYZl/geh3+M03umPJrWkkMhy+hJL6L0P7rV+KwzFwgfE8jL3EdB+Z9PtIVkGj0qj/8QIswhP3j/xAFWzyRlsZw== - dependencies: - "@metamask/base-controller" "^2.0.0" - "@metamask/controller-utils" "^3.0.0" - async-mutex "^0.2.6" - babel-runtime "^6.26.0" - eth-json-rpc-infura "^5.1.0" - eth-query "^2.1.2" - immer "^9.0.6" - web3-provider-engine "^16.0.3" - "@metamask/network-controller@^6.0.0": version "6.0.0" resolved "https://registry.yarnpkg.com/@metamask/network-controller/-/network-controller-6.0.0.tgz#7b762c6461b97a301c55e9d73e87487a94f31efe" From 4335f0fb2be0261969455441c8265f8cb57c5370 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Tue, 12 Sep 2023 11:50:02 -0300 Subject: [PATCH 50/67] chore: patch micro-ftch to ignore zlib import in node context --- patches/micro-ftch+0.3.1.patch | 245 +++++++++++++++++++++++++++++++++ 1 file changed, 245 insertions(+) create mode 100644 patches/micro-ftch+0.3.1.patch diff --git a/patches/micro-ftch+0.3.1.patch b/patches/micro-ftch+0.3.1.patch new file mode 100644 index 00000000000..02ac3555f2a --- /dev/null +++ b/patches/micro-ftch+0.3.1.patch @@ -0,0 +1,245 @@ +diff --git a/node_modules/micro-ftch/index.js b/node_modules/micro-ftch/index.js +index 7f00c3d..3762bf0 100644 +--- a/node_modules/micro-ftch/index.js ++++ b/node_modules/micro-ftch/index.js +@@ -49,123 +49,123 @@ function detectType(b, type) { + return b; + } + let agents = {}; +-function fetchNode(url, _options) { +- let options = { ...DEFAULT_OPT, ..._options }; +- const http = require('http'); +- const https = require('https'); +- const zlib = require('zlib'); +- const { promisify } = require('util'); +- const { resolve: urlResolve } = require('url'); +- const isSecure = !!/^https/.test(url); +- let opts = { +- method: options.method || 'GET', +- headers: { 'Accept-Encoding': 'gzip, deflate, br' }, +- }; +- const compactFP = (s) => s.replace(/:| /g, '').toLowerCase(); +- if (options.keepAlive) { +- const agentOpt = { +- keepAlive: true, +- keepAliveMsecs: 30 * 1000, +- maxFreeSockets: 1024, +- maxCachedSessions: 1024, +- }; +- const agentKey = [ +- isSecure, +- isSecure && options.sslPinnedCertificates?.map((i) => compactFP(i)).sort(), +- ].join(); +- opts.agent = +- agents[agentKey] || (agents[agentKey] = new (isSecure ? https : http).Agent(agentOpt)); +- } +- if (options.type === 'json') +- opts.headers['Content-Type'] = 'application/json'; +- if (options.data) { +- if (!options.method) +- opts.method = 'POST'; +- opts.body = options.type === 'json' ? JSON.stringify(options.data) : options.data; +- } +- opts.headers = { ...opts.headers, ...options.headers }; +- if (options.sslAllowSelfSigned) +- opts.rejectUnauthorized = false; +- const handleRes = async (res) => { +- const status = res.statusCode; +- if (options.redirect && 300 <= status && status < 400 && res.headers['location']) { +- if (options._redirectCount == 10) +- throw new Error('Request failed. Too much redirects.'); +- options._redirectCount += 1; +- return await fetchNode(urlResolve(url, res.headers['location']), options); +- } +- if (options.expectStatusCode && status !== options.expectStatusCode) { +- res.resume(); +- throw new InvalidStatusCodeError(status); +- } +- let buf = []; +- for await (const chunk of res) +- buf.push(chunk); +- let bytes = Buffer.concat(buf); +- const encoding = res.headers['content-encoding']; +- if (encoding === 'br') +- bytes = await promisify(zlib.brotliDecompress)(bytes); +- if (encoding === 'gzip' || encoding === 'deflate') +- bytes = await promisify(zlib.unzip)(bytes); +- const body = detectType(bytes, options.type); +- if (options.full) +- return { headers: res.headers, status, body }; +- return body; +- }; +- return new Promise((resolve, reject) => { +- const handleError = async (err) => { +- if (err && err.code === 'DEPTH_ZERO_SELF_SIGNED_CERT') { +- try { +- await fetchNode(url, { ...options, sslAllowSelfSigned: true, sslPinnedCertificates: [] }); +- } +- catch (e) { +- if (e && e.fingerprint256) { +- err = new InvalidCertError(`Self-signed SSL certificate: ${e.fingerprint256}`, e.fingerprint256); +- } +- } +- } +- reject(err); +- }; +- const req = (isSecure ? https : http).request(url, opts, (res) => { +- res.on('error', handleError); +- (async () => { +- try { +- resolve(await handleRes(res)); +- } +- catch (error) { +- reject(error); +- } +- })(); +- }); +- req.on('error', handleError); +- const pinned = options.sslPinnedCertificates?.map((i) => compactFP(i)); +- const mfetchSecureConnect = (socket) => { +- const fp256 = compactFP(socket.getPeerCertificate()?.fingerprint256 || ''); +- if (!fp256 && socket.isSessionReused()) +- return; +- if (pinned.includes(fp256)) +- return; +- req.emit('error', new InvalidCertError(`Invalid SSL certificate: ${fp256} Expected: ${pinned}`, fp256)); +- return req.abort(); +- }; +- if (options.sslPinnedCertificates) { +- req.on('socket', (socket) => { +- const hasListeners = socket +- .listeners('secureConnect') +- .map((i) => (i.name || '').replace('bound ', '')) +- .includes('mfetchSecureConnect'); +- if (hasListeners) +- return; +- socket.on('secureConnect', mfetchSecureConnect.bind(null, socket)); +- }); +- } +- if (options.keepAlive) +- req.setNoDelay(true); +- if (opts.body) +- req.write(opts.body); +- req.end(); +- }); +-} ++// function fetchNode(url, _options) { ++// let options = { ...DEFAULT_OPT, ..._options }; ++// const http = require('http'); ++// const https = require('https'); ++// const zlib = require('zlib'); ++// const { promisify } = require('util'); ++// const { resolve: urlResolve } = require('url'); ++// const isSecure = !!/^https/.test(url); ++// let opts = { ++// method: options.method || 'GET', ++// headers: { 'Accept-Encoding': 'gzip, deflate, br' }, ++// }; ++// const compactFP = (s) => s.replace(/:| /g, '').toLowerCase(); ++// if (options.keepAlive) { ++// const agentOpt = { ++// keepAlive: true, ++// keepAliveMsecs: 30 * 1000, ++// maxFreeSockets: 1024, ++// maxCachedSessions: 1024, ++// }; ++// const agentKey = [ ++// isSecure, ++// isSecure && options.sslPinnedCertificates?.map((i) => compactFP(i)).sort(), ++// ].join(); ++// opts.agent = ++// agents[agentKey] || (agents[agentKey] = new (isSecure ? https : http).Agent(agentOpt)); ++// } ++// if (options.type === 'json') ++// opts.headers['Content-Type'] = 'application/json'; ++// if (options.data) { ++// if (!options.method) ++// opts.method = 'POST'; ++// opts.body = options.type === 'json' ? JSON.stringify(options.data) : options.data; ++// } ++// opts.headers = { ...opts.headers, ...options.headers }; ++// if (options.sslAllowSelfSigned) ++// opts.rejectUnauthorized = false; ++// const handleRes = async (res) => { ++// const status = res.statusCode; ++// if (options.redirect && 300 <= status && status < 400 && res.headers['location']) { ++// if (options._redirectCount == 10) ++// throw new Error('Request failed. Too much redirects.'); ++// options._redirectCount += 1; ++// return await fetchNode(urlResolve(url, res.headers['location']), options); ++// } ++// if (options.expectStatusCode && status !== options.expectStatusCode) { ++// res.resume(); ++// throw new InvalidStatusCodeError(status); ++// } ++// let buf = []; ++// for await (const chunk of res) ++// buf.push(chunk); ++// let bytes = Buffer.concat(buf); ++// const encoding = res.headers['content-encoding']; ++// if (encoding === 'br') ++// bytes = await promisify(zlib.brotliDecompress)(bytes); ++// if (encoding === 'gzip' || encoding === 'deflate') ++// bytes = await promisify(zlib.unzip)(bytes); ++// const body = detectType(bytes, options.type); ++// if (options.full) ++// return { headers: res.headers, status, body }; ++// return body; ++// }; ++// return new Promise((resolve, reject) => { ++// const handleError = async (err) => { ++// if (err && err.code === 'DEPTH_ZERO_SELF_SIGNED_CERT') { ++// try { ++// await fetchNode(url, { ...options, sslAllowSelfSigned: true, sslPinnedCertificates: [] }); ++// } ++// catch (e) { ++// if (e && e.fingerprint256) { ++// err = new InvalidCertError(`Self-signed SSL certificate: ${e.fingerprint256}`, e.fingerprint256); ++// } ++// } ++// } ++// reject(err); ++// }; ++// const req = (isSecure ? https : http).request(url, opts, (res) => { ++// res.on('error', handleError); ++// (async () => { ++// try { ++// resolve(await handleRes(res)); ++// } ++// catch (error) { ++// reject(error); ++// } ++// })(); ++// }); ++// req.on('error', handleError); ++// const pinned = options.sslPinnedCertificates?.map((i) => compactFP(i)); ++// const mfetchSecureConnect = (socket) => { ++// const fp256 = compactFP(socket.getPeerCertificate()?.fingerprint256 || ''); ++// if (!fp256 && socket.isSessionReused()) ++// return; ++// if (pinned.includes(fp256)) ++// return; ++// req.emit('error', new InvalidCertError(`Invalid SSL certificate: ${fp256} Expected: ${pinned}`, fp256)); ++// return req.abort(); ++// }; ++// if (options.sslPinnedCertificates) { ++// req.on('socket', (socket) => { ++// const hasListeners = socket ++// .listeners('secureConnect') ++// .map((i) => (i.name || '').replace('bound ', '')) ++// .includes('mfetchSecureConnect'); ++// if (hasListeners) ++// return; ++// socket.on('secureConnect', mfetchSecureConnect.bind(null, socket)); ++// }); ++// } ++// if (options.keepAlive) ++// req.setNoDelay(true); ++// if (opts.body) ++// req.write(opts.body); ++// req.end(); ++// }); ++// } + const SAFE_HEADERS = new Set(['Accept', 'Accept-Language', 'Content-Language', 'Content-Type'].map((i) => i.toLowerCase())); + const FORBIDDEN_HEADERS = new Set(['Accept-Charset', 'Accept-Encoding', 'Access-Control-Request-Headers', 'Access-Control-Request-Method', + 'Connection', 'Content-Length', 'Cookie', 'Cookie2', 'Date', 'DNT', 'Expect', 'Host', 'Keep-Alive', 'Origin', 'Referer', 'TE', 'Trailer', From ca30637d7b320d2f6b8e2321719534b6e91bd8bd Mon Sep 17 00:00:00 2001 From: gantunesr Date: Tue, 12 Sep 2023 11:54:50 -0300 Subject: [PATCH 51/67] chore: remove @ethereumjs/util resolution --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 18df6ef0b8f..985281aad44 100644 --- a/package.json +++ b/package.json @@ -145,7 +145,6 @@ "oss-attribution-generator/**/debug": "^2.6.9", "d3-color": "3.1.0", "**/fast-xml-parser": "4.2.4", - "@ethereumjs/util": "8.0.2", "tough-cookie": "4.1.3" }, "dependencies": { From 3bab33bd3b7d6ec06e592fd2a5f25c62fc65b506 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Tue, 12 Sep 2023 11:55:04 -0300 Subject: [PATCH 52/67] chore: remove @ethereumjs/util resolution - yarn.lock update --- yarn.lock | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/yarn.lock b/yarn.lock index 7bd5f9210af..a5790275352 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1789,7 +1789,7 @@ "@ethereumjs/util" "^8.1.0" ethereum-cryptography "^2.0.0" -"@ethereumjs/util@8.0.2", "@ethereumjs/util@^8.0.0", "@ethereumjs/util@^8.0.2", "@ethereumjs/util@^8.0.6", "@ethereumjs/util@^8.1.0": +"@ethereumjs/util@^8.0.0": version "8.0.2" resolved "https://registry.yarnpkg.com/@ethereumjs/util/-/util-8.0.2.tgz#b7348fc7253649b0f00685a94546c6eee1fad819" integrity sha512-b1Fcxmq+ckCdoLPhVIBkTcH8szigMapPuEmD8EDakvtI5Na5rzmX1sBW73YQqaPc7iUxGCAzZP1LrFQ7aEMugA== @@ -1798,6 +1798,15 @@ async "^3.2.4" ethereum-cryptography "^1.1.2" +"@ethereumjs/util@^8.0.2", "@ethereumjs/util@^8.0.6", "@ethereumjs/util@^8.1.0": + version "8.1.0" + resolved "https://registry.yarnpkg.com/@ethereumjs/util/-/util-8.1.0.tgz#299df97fb6b034e0577ce9f94c7d9d1004409ed4" + integrity sha512-zQ0IqbdX8FZ9aw11vP+dZkKDkS+kgIvQPHnSAXzP9pLu+Rfu3D3XEeLbicvoXJTYnhZiPmsZUxgdzXwNKxRPbA== + dependencies: + "@ethereumjs/rlp" "^4.0.1" + ethereum-cryptography "^2.0.0" + micro-ftch "^0.3.1" + "@ethersproject/abi@5.4.1": version "5.4.1" resolved "https://registry.yarnpkg.com/@ethersproject/abi/-/abi-5.4.1.tgz#6ac28fafc9ef6f5a7a37e30356a2eb31fa05d39b" @@ -19327,6 +19336,11 @@ metro@0.73.10: ws "^7.5.1" yargs "^17.5.1" +micro-ftch@^0.3.1: + version "0.3.1" + resolved "https://registry.yarnpkg.com/micro-ftch/-/micro-ftch-0.3.1.tgz#6cb83388de4c1f279a034fb0cf96dfc050853c5f" + integrity sha512-/0LLxhzP0tfiR5hcQebtudP56gUurs2CLkGarnCiB/OqEyUFQ6U3paQi/tgLv0hBJYt2rnr9MNpxz4fiiugstg== + micromatch@^3.1.10: version "3.1.10" resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-3.1.10.tgz#70859bc95c9840952f359a068a3fc49f9ecfac23" From 3c92886e43dc96e81cb17215212352446911318e Mon Sep 17 00:00:00 2001 From: gantunesr Date: Tue, 12 Sep 2023 11:55:41 -0300 Subject: [PATCH 53/67] chore: update lavamoat allowscripts to include @keystonehq modules --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 985281aad44..9760879685c 100644 --- a/package.json +++ b/package.json @@ -553,7 +553,9 @@ "ganache>utf-8-validate": false, "wdio-image-comparison-service>webdriver-image-comparison>canvas": false, "appium-adb>@appium/support>sharp": true, - "react-native-svg-asset-plugin>sharp": true + "react-native-svg-asset-plugin>sharp": true, + "@metamask/keyring-controller>@keystonehq/metamask-airgapped-keyring>@keystonehq/base-eth-keyring>@ethereumjs/tx>ethereumjs-util>ethereum-cryptography>keccak": false, + "@metamask/keyring-controller>@keystonehq/metamask-airgapped-keyring>@keystonehq/base-eth-keyring>@ethereumjs/tx>ethereumjs-util>ethereum-cryptography>secp256k1": false } } } From 64d6983e1c54dc5eeea4f8fcfd65abbfc2f5f755 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Tue, 12 Sep 2023 14:14:52 -0300 Subject: [PATCH 54/67] chore: update @metamask/message-manager --- ... => @metamask+message-manager+7.0.1.patch} | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) rename patches/{@metamask+signature-controller++@metamask+message-manager+7.0.1.patch => @metamask+message-manager+7.0.1.patch} (86%) diff --git a/patches/@metamask+signature-controller++@metamask+message-manager+7.0.1.patch b/patches/@metamask+message-manager+7.0.1.patch similarity index 86% rename from patches/@metamask+signature-controller++@metamask+message-manager+7.0.1.patch rename to patches/@metamask+message-manager+7.0.1.patch index ea97e5de935..0c5425ad532 100644 --- a/patches/@metamask+signature-controller++@metamask+message-manager+7.0.1.patch +++ b/patches/@metamask+message-manager+7.0.1.patch @@ -1,10 +1,7 @@ -diff --git a/node_modules/@metamask/signature-controller/node_modules/@metamask/message-manager/dist/.DS_Store b/node_modules/@metamask/signature-controller/node_modules/@metamask/message-manager/dist/.DS_Store -new file mode 100644 -index 0000000..e69de29 -diff --git a/node_modules/@metamask/signature-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts b/node_modules/@metamask/signature-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts +diff --git a/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts b/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts index 078af88..0675794 100644 ---- a/node_modules/@metamask/signature-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts -+++ b/node_modules/@metamask/signature-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts +--- a/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts ++++ b/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts @@ -1,4 +1,3 @@ -import { SIWEMessage } from '@metamask/controller-utils'; import { AbstractMessageManager, AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, OriginalRequest } from './AbstractMessageManager'; @@ -22,19 +19,19 @@ index 078af88..0675794 100644 } /** * @type MessageParamsMetamask -diff --git a/node_modules/@metamask/signature-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts.map b/node_modules/@metamask/signature-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts.map +diff --git a/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts.map b/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts.map index ab04adc..52e6b44 100644 ---- a/node_modules/@metamask/signature-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts.map -+++ b/node_modules/@metamask/signature-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts.map +--- a/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts.map ++++ b/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"PersonalMessageManager.d.ts","sourceRoot":"","sources":["../src/PersonalMessageManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAErE,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;;;GAUG;AACH,MAAM,WAAW,eAAgB,SAAQ,eAAe;IACtD,aAAa,EAAE,qBAAqB,CAAC;CACtC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,qBAAsB,SAAQ,qBAAqB;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,6BACf,SAAQ,6BAA6B;IACrC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB,CAChE,eAAe,EACf,qBAAqB,EACrB,6BAA6B,CAC9B;IACC;;OAEG;IACM,IAAI,SAA4B;IAEzC;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAa,EAAE,qBAAqB,EACpC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IA0BlB;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,6BAA6B,GAC3C,OAAO,CAAC,qBAAqB,CAAC;CAIlC;AAED,eAAe,sBAAsB,CAAC"} \ No newline at end of file +{"version":3,"file":"PersonalMessageManager.d.ts","sourceRoot":"","sources":["../src/PersonalMessageManager.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;;;GAUG;AACH,MAAM,WAAW,eAAgB,SAAQ,eAAe;IACtD,aAAa,EAAE,qBAAqB,CAAC;CACtC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,qBAAsB,SAAQ,qBAAqB;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE;QACL,aAAa,EAAE,OAAO,CAAC;QACvB,aAAa,EAAE,IAAI,CAAC;KACrB,CAAC;CACH;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,6BACf,SAAQ,6BAA6B;IACrC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB,CAChE,eAAe,EACf,qBAAqB,EACrB,6BAA6B,CAC9B;IACC;;OAEG;IACM,IAAI,SAA4B;IAEzC;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAa,EAAE,qBAAqB,EACpC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IA6BlB;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,6BAA6B,GAC3C,OAAO,CAAC,qBAAqB,CAAC;CAIlC;AAED,eAAe,sBAAsB,CAAC"} \ No newline at end of file -diff --git a/node_modules/@metamask/signature-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js b/node_modules/@metamask/signature-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js +diff --git a/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js b/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js index 92e9b3d..0321f2e 100644 ---- a/node_modules/@metamask/signature-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js -+++ b/node_modules/@metamask/signature-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js +--- a/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js ++++ b/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js @@ -11,7 +11,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge Object.defineProperty(exports, "__esModule", { value: true }); exports.PersonalMessageManager = void 0; @@ -55,10 +52,10 @@ index 92e9b3d..0321f2e 100644 const finalMsgParams = Object.assign(Object.assign({}, messageParams), { siwe: ethereumSignInData }); const messageId = (0, uuid_1.v1)(); const messageData = { -diff --git a/node_modules/@metamask/signature-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js.map b/node_modules/@metamask/signature-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js.map +diff --git a/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js.map b/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js.map index b23be96..00b1e54 100644 ---- a/node_modules/@metamask/signature-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js.map -+++ b/node_modules/@metamask/signature-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js.map +--- a/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js.map ++++ b/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js.map @@ -1 +1 @@ -{"version":3,"file":"PersonalMessageManager.js","sourceRoot":"","sources":["../src/PersonalMessageManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAAoC;AACpC,iEAAqE;AACrE,mCAAwE;AACxE,qEAMkC;AA6ClC;;GAEG;AACH,MAAa,sBAAuB,SAAQ,+CAI3C;IAJD;;QAKE;;WAEG;QACM,SAAI,GAAG,wBAAwB,CAAC;IAsD3C,CAAC;IApDC;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAoC,EACpC,GAAqB;;YAErB,IAAA,+BAAuB,EAAC,aAAa,CAAC,CAAC;YACvC,IAAI,GAAG,EAAE;gBACP,aAAa,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;aACnC;YACD,aAAa,CAAC,IAAI,GAAG,IAAA,4BAAoB,EAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YAE9D,MAAM,kBAAkB,GAAG,IAAA,6BAAU,EAAC,aAAa,CAAC,CAAC;YACrD,MAAM,cAAc,mCAAQ,aAAa,KAAE,IAAI,EAAE,kBAAkB,GAAE,CAAC;YAEtE,MAAM,SAAS,GAAG,IAAA,SAAM,GAAE,CAAC;YAC3B,MAAM,WAAW,GAAoB;gBACnC,EAAE,EAAE,SAAS;gBACb,aAAa,EAAE,cAAc;gBAC7B,MAAM,EAAE,YAAY;gBACpB,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;gBAChB,IAAI,EAAE,eAAe;aACtB,CAAC;YACF,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;YACnC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,kCAC5B,cAAc,GACd,EAAE,UAAU,EAAE,SAAS,EAAE,EAC5B,CAAC;YACH,OAAO,SAAS,CAAC;QACnB,CAAC;KAAA;IAED;;;;;;OAMG;IACH,qBAAqB,CACnB,aAA4C;QAE5C,OAAO,aAAa,CAAC,UAAU,CAAC;QAChC,OAAO,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACxC,CAAC;CACF;AA9DD,wDA8DC;AAED,kBAAe,sBAAsB,CAAC","sourcesContent":["import { v1 as random } from 'uuid';\nimport { detectSIWE, SIWEMessage } from '@metamask/controller-utils';\nimport { normalizeMessageData, validateSignMessageData } from './utils';\nimport {\n AbstractMessageManager,\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n OriginalRequest,\n} from './AbstractMessageManager';\n\n/**\n * @type Message\n *\n * Represents and contains data about a 'personal_sign' type signature request.\n * These are created when a signature for a personal_sign call is requested.\n * @property id - An id to track and identify the message object\n * @property messageParams - The parameters to pass to the personal_sign method once the signature request is approved\n * @property type - The json-prc signing method for which a signature request has been made.\n * A 'Message' which always has a 'personal_sign' type\n * @property rawSig - Raw data of the signature request\n */\nexport interface PersonalMessage extends AbstractMessage {\n messageParams: PersonalMessageParams;\n}\n\n/**\n * @type PersonalMessageParams\n *\n * Represents the parameters to pass to the personal_sign method once the signature request is approved.\n * @property data - A hex string conversion of the raw buffer data of the signature request\n * @property from - Address to sign this message from\n * @property origin? - Added for request origin identification\n */\nexport interface PersonalMessageParams extends AbstractMessageParams {\n data: string;\n siwe?: SIWEMessage;\n}\n\n/**\n * @type MessageParamsMetamask\n *\n * Represents the parameters to pass to the personal_sign method once the signature request is approved\n * plus data added by MetaMask.\n * @property metamaskId - Added for tracking and identification within MetaMask\n * @property data - A hex string conversion of the raw buffer data of the signature request\n * @property from - Address to sign this message from\n * @property origin? - Added for request origin identification\n */\nexport interface PersonalMessageParamsMetamask\n extends AbstractMessageParamsMetamask {\n data: string;\n}\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - Messages.\n */\nexport class PersonalMessageManager extends AbstractMessageManager<\n PersonalMessage,\n PersonalMessageParams,\n PersonalMessageParamsMetamask\n> {\n /**\n * Name of this controller used during composition\n */\n override name = 'PersonalMessageManager';\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the\n * unapproved Messages.\n *\n * @param messageParams - The params for the personal_sign call to be made after the message\n * is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns The id of the newly created message.\n */\n async addUnapprovedMessage(\n messageParams: PersonalMessageParams,\n req?: OriginalRequest,\n ): Promise {\n validateSignMessageData(messageParams);\n if (req) {\n messageParams.origin = req.origin;\n }\n messageParams.data = normalizeMessageData(messageParams.data);\n\n const ethereumSignInData = detectSIWE(messageParams);\n const finalMsgParams = { ...messageParams, siwe: ethereumSignInData };\n\n const messageId = random();\n const messageData: PersonalMessage = {\n id: messageId,\n messageParams: finalMsgParams,\n status: 'unapproved',\n time: Date.now(),\n type: 'personal_sign',\n };\n await this.addMessage(messageData);\n this.hub.emit(`unapprovedMessage`, {\n ...finalMsgParams,\n ...{ metamaskId: messageId },\n });\n return messageId;\n }\n\n /**\n * Removes the metamaskId property from passed messageParams and returns a promise which\n * resolves the updated messageParams.\n *\n * @param messageParams - The messageParams to modify.\n * @returns Promise resolving to the messageParams with the metamaskId property removed.\n */\n prepMessageForSigning(\n messageParams: PersonalMessageParamsMetamask,\n ): Promise {\n delete messageParams.metamaskId;\n return Promise.resolve(messageParams);\n }\n}\n\nexport default PersonalMessageManager;\n"]} \ No newline at end of file From d8389a5648a70a9ab6759e557e49ace5fb83d23e Mon Sep 17 00:00:00 2001 From: gantunesr Date: Tue, 12 Sep 2023 14:51:43 -0300 Subject: [PATCH 55/67] chore: update message-manager patch 7.0.1 and remove patch 1.0.1 --- patches/@metamask+message-manager+1.0.1.patch | 36 ------------------- 1 file changed, 36 deletions(-) delete mode 100644 patches/@metamask+message-manager+1.0.1.patch diff --git a/patches/@metamask+message-manager+1.0.1.patch b/patches/@metamask+message-manager+1.0.1.patch deleted file mode 100644 index 8a690643b3e..00000000000 --- a/patches/@metamask+message-manager+1.0.1.patch +++ /dev/null @@ -1,36 +0,0 @@ -diff --git a/node_modules/@metamask/message-manager/dist/MessageManager.js b/node_modules/@metamask/message-manager/dist/MessageManager.js -index e7c5d99..11948f9 100644 ---- a/node_modules/@metamask/message-manager/dist/MessageManager.js -+++ b/node_modules/@metamask/message-manager/dist/MessageManager.js -@@ -58,6 +58,7 @@ class MessageManager extends AbstractMessageManager_1.AbstractMessageManager { - const messageData = { - id: messageId, - messageParams, -+ securityAlertResponse: req?.securityAlertResponse, - status: 'unapproved', - time: Date.now(), - type: 'eth_sign', -diff --git a/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js b/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js -index 036bd3b..c9bd117 100644 ---- a/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js -+++ b/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js -@@ -58,6 +58,7 @@ class PersonalMessageManager extends AbstractMessageManager_1.AbstractMessageMan - const messageData = { - id: messageId, - messageParams, -+ securityAlertResponse: req?.securityAlertResponse, - status: 'unapproved', - time: Date.now(), - type: 'personal_sign', -diff --git a/node_modules/@metamask/message-manager/dist/TypedMessageManager.js b/node_modules/@metamask/message-manager/dist/TypedMessageManager.js -index e4b1aa3..f3abc5d 100644 ---- a/node_modules/@metamask/message-manager/dist/TypedMessageManager.js -+++ b/node_modules/@metamask/message-manager/dist/TypedMessageManager.js -@@ -67,6 +67,7 @@ class TypedMessageManager extends AbstractMessageManager_1.AbstractMessageManage - const messageData = { - id: messageId, - messageParams, -+ securityAlertResponse: req?.securityAlertResponse, - status: 'unapproved', - time: Date.now(), - type: 'eth_signTypedData', From c47bb45a8eb80868acc5a0e93bff6904d630ade7 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Tue, 12 Sep 2023 14:51:51 -0300 Subject: [PATCH 56/67] chore: update message-manager patch 7.0.1 and remove patch 1.0.1 --- patches/@metamask+message-manager+7.0.1.patch | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/patches/@metamask+message-manager+7.0.1.patch b/patches/@metamask+message-manager+7.0.1.patch index 0c5425ad532..07bb2bf13b7 100644 --- a/patches/@metamask+message-manager+7.0.1.patch +++ b/patches/@metamask+message-manager+7.0.1.patch @@ -1,3 +1,15 @@ +diff --git a/node_modules/@metamask/message-manager/dist/MessageManager.js b/node_modules/@metamask/message-manager/dist/MessageManager.js +index 89fcd8f..717ed56 100644 +--- a/node_modules/@metamask/message-manager/dist/MessageManager.js ++++ b/node_modules/@metamask/message-manager/dist/MessageManager.js +@@ -45,6 +45,7 @@ class MessageManager extends AbstractMessageManager_1.AbstractMessageManager { + const messageData = { + id: messageId, + messageParams, ++ securityAlertResponse: req?.securityAlertResponse, + status: 'unapproved', + time: Date.now(), + type: 'eth_sign', diff --git a/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts b/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts index 078af88..0675794 100644 --- a/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts @@ -29,7 +41,7 @@ index ab04adc..52e6b44 100644 +{"version":3,"file":"PersonalMessageManager.d.ts","sourceRoot":"","sources":["../src/PersonalMessageManager.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;;;GAUG;AACH,MAAM,WAAW,eAAgB,SAAQ,eAAe;IACtD,aAAa,EAAE,qBAAqB,CAAC;CACtC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,qBAAsB,SAAQ,qBAAqB;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE;QACL,aAAa,EAAE,OAAO,CAAC;QACvB,aAAa,EAAE,IAAI,CAAC;KACrB,CAAC;CACH;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,6BACf,SAAQ,6BAA6B;IACrC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB,CAChE,eAAe,EACf,qBAAqB,EACrB,6BAA6B,CAC9B;IACC;;OAEG;IACM,IAAI,SAA4B;IAEzC;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAa,EAAE,qBAAqB,EACpC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IA6BlB;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,6BAA6B,GAC3C,OAAO,CAAC,qBAAqB,CAAC;CAIlC;AAED,eAAe,sBAAsB,CAAC"} \ No newline at end of file diff --git a/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js b/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js -index 92e9b3d..0321f2e 100644 +index 92e9b3d..9145738 100644 --- a/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js +++ b/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js @@ -11,7 +11,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge @@ -40,7 +52,7 @@ index 92e9b3d..0321f2e 100644 const utils_1 = require("./utils"); const AbstractMessageManager_1 = require("./AbstractMessageManager"); /** -@@ -42,7 +41,10 @@ class PersonalMessageManager extends AbstractMessageManager_1.AbstractMessageMan +@@ -42,12 +41,16 @@ class PersonalMessageManager extends AbstractMessageManager_1.AbstractMessageMan messageParams.origin = req.origin; } messageParams.data = (0, utils_1.normalizeMessageData)(messageParams.data); @@ -52,6 +64,12 @@ index 92e9b3d..0321f2e 100644 const finalMsgParams = Object.assign(Object.assign({}, messageParams), { siwe: ethereumSignInData }); const messageId = (0, uuid_1.v1)(); const messageData = { + id: messageId, + messageParams: finalMsgParams, ++ securityAlertResponse: req?.securityAlertResponse, + status: 'unapproved', + time: Date.now(), + type: 'personal_sign', diff --git a/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js.map b/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js.map index b23be96..00b1e54 100644 --- a/node_modules/@metamask/message-manager/dist/PersonalMessageManager.js.map @@ -61,3 +79,15 @@ index b23be96..00b1e54 100644 \ No newline at end of file +{"version":3,"file":"PersonalMessageManager.js","sourceRoot":"","sources":["../src/PersonalMessageManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAAoC;AACpC,mCAAwE;AACxE,qEAMkC;AAgDlC;;GAEG;AACH,MAAa,sBAAuB,SAAQ,+CAI3C;IAJD;;QAKE;;WAEG;QACM,SAAI,GAAG,wBAAwB,CAAC;IAyD3C,CAAC;IAvDC;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAoC,EACpC,GAAqB;;YAErB,IAAA,+BAAuB,EAAC,aAAa,CAAC,CAAC;YACvC,IAAI,GAAG,EAAE;gBACP,aAAa,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;aACnC;YACD,aAAa,CAAC,IAAI,GAAG,IAAA,4BAAoB,EAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YAE9D,MAAM,kBAAkB,GAAG;gBACzB,aAAa,EAAE,KAAK;gBACpB,aAAa,EAAE,IAAI;aACpB,CAAA;YACD,MAAM,cAAc,mCAAQ,aAAa,KAAE,IAAI,EAAE,kBAAkB,GAAE,CAAC;YAEtE,MAAM,SAAS,GAAG,IAAA,SAAM,GAAE,CAAC;YAC3B,MAAM,WAAW,GAAoB;gBACnC,EAAE,EAAE,SAAS;gBACb,aAAa,EAAE,cAAc;gBAC7B,MAAM,EAAE,YAAY;gBACpB,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;gBAChB,IAAI,EAAE,eAAe;aACtB,CAAC;YACF,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;YACnC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,kCAC5B,cAAc,GACd,EAAE,UAAU,EAAE,SAAS,EAAE,EAC5B,CAAC;YACH,OAAO,SAAS,CAAC;QACnB,CAAC;KAAA;IAED;;;;;;OAMG;IACH,qBAAqB,CACnB,aAA4C;QAE5C,OAAO,aAAa,CAAC,UAAU,CAAC;QAChC,OAAO,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACxC,CAAC;CACF;AAjED,wDAiEC;AAED,kBAAe,sBAAsB,CAAC","sourcesContent":["import { v1 as random } from 'uuid';\nimport { normalizeMessageData, validateSignMessageData } from './utils';\nimport {\n AbstractMessageManager,\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n OriginalRequest,\n} from './AbstractMessageManager';\n\n/**\n * @type Message\n *\n * Represents and contains data about a 'personal_sign' type signature request.\n * These are created when a signature for a personal_sign call is requested.\n * @property id - An id to track and identify the message object\n * @property messageParams - The parameters to pass to the personal_sign method once the signature request is approved\n * @property type - The json-prc signing method for which a signature request has been made.\n * A 'Message' which always has a 'personal_sign' type\n * @property rawSig - Raw data of the signature request\n */\nexport interface PersonalMessage extends AbstractMessage {\n messageParams: PersonalMessageParams;\n}\n\n/**\n * @type PersonalMessageParams\n *\n * Represents the parameters to pass to the personal_sign method once the signature request is approved.\n * @property data - A hex string conversion of the raw buffer data of the signature request\n * @property from - Address to sign this message from\n * @property origin? - Added for request origin identification\n */\nexport interface PersonalMessageParams extends AbstractMessageParams {\n data: string;\n siwe?: {\n isSIWEMessage: boolean,\n parsedMessage: null,\n };\n}\n\n/**\n * @type MessageParamsMetamask\n *\n * Represents the parameters to pass to the personal_sign method once the signature request is approved\n * plus data added by MetaMask.\n * @property metamaskId - Added for tracking and identification within MetaMask\n * @property data - A hex string conversion of the raw buffer data of the signature request\n * @property from - Address to sign this message from\n * @property origin? - Added for request origin identification\n */\nexport interface PersonalMessageParamsMetamask\n extends AbstractMessageParamsMetamask {\n data: string;\n}\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - Messages.\n */\nexport class PersonalMessageManager extends AbstractMessageManager<\n PersonalMessage,\n PersonalMessageParams,\n PersonalMessageParamsMetamask\n> {\n /**\n * Name of this controller used during composition\n */\n override name = 'PersonalMessageManager';\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the\n * unapproved Messages.\n *\n * @param messageParams - The params for the personal_sign call to be made after the message\n * is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns The id of the newly created message.\n */\n async addUnapprovedMessage(\n messageParams: PersonalMessageParams,\n req?: OriginalRequest,\n ): Promise {\n validateSignMessageData(messageParams);\n if (req) {\n messageParams.origin = req.origin;\n }\n messageParams.data = normalizeMessageData(messageParams.data);\n\n const ethereumSignInData = {\n isSIWEMessage: false,\n parsedMessage: null,\n }\n const finalMsgParams = { ...messageParams, siwe: ethereumSignInData };\n\n const messageId = random();\n const messageData: PersonalMessage = {\n id: messageId,\n messageParams: finalMsgParams,\n status: 'unapproved',\n time: Date.now(),\n type: 'personal_sign',\n };\n await this.addMessage(messageData);\n this.hub.emit(`unapprovedMessage`, {\n ...finalMsgParams,\n ...{ metamaskId: messageId },\n });\n return messageId;\n }\n\n /**\n * Removes the metamaskId property from passed messageParams and returns a promise which\n * resolves the updated messageParams.\n *\n * @param messageParams - The messageParams to modify.\n * @returns Promise resolving to the messageParams with the metamaskId property removed.\n */\n prepMessageForSigning(\n messageParams: PersonalMessageParamsMetamask,\n ): Promise {\n delete messageParams.metamaskId;\n return Promise.resolve(messageParams);\n }\n}\n\nexport default PersonalMessageManager;\n"]} \ No newline at end of file +diff --git a/node_modules/@metamask/message-manager/dist/TypedMessageManager.js b/node_modules/@metamask/message-manager/dist/TypedMessageManager.js +index d5d7e37..c0eb98b 100644 +--- a/node_modules/@metamask/message-manager/dist/TypedMessageManager.js ++++ b/node_modules/@metamask/message-manager/dist/TypedMessageManager.js +@@ -57,6 +57,7 @@ class TypedMessageManager extends AbstractMessageManager_1.AbstractMessageManage + const messageData = { + id: messageId, + messageParams, ++ securityAlertResponse: req?.securityAlertResponse, + status: 'unapproved', + time: Date.now(), + type: 'eth_signTypedData', From 0f77e2874443a7d7bcbf1c494f16e633db5f215b Mon Sep 17 00:00:00 2001 From: gantunesr Date: Tue, 12 Sep 2023 14:59:36 -0300 Subject: [PATCH 57/67] chore: lint --- app/core/Engine.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/core/Engine.ts b/app/core/Engine.ts index 387219161ea..502f125949b 100644 --- a/app/core/Engine.ts +++ b/app/core/Engine.ts @@ -391,8 +391,6 @@ class Engine { const phishingController = new PhishingController(); phishingController.maybeUpdateState(); - const additionalKeyrings = [QRHardwareKeyring]; - const getIdentities = () => { const identities = preferencesController.state.identities; const lowerCasedIdentities: PreferencesState['identities'] = {}; From 0b9605777902d3171154716c8e3a8fea59e9c124 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Tue, 12 Sep 2023 16:34:40 -0300 Subject: [PATCH 58/67] chore: lint --- app/core/BackupVault/backupVault.ts | 4 ++-- app/core/Engine.ts | 7 +++---- app/selectors/types.ts | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/core/BackupVault/backupVault.ts b/app/core/BackupVault/backupVault.ts index 87a0cce5283..f5d837385c6 100644 --- a/app/core/BackupVault/backupVault.ts +++ b/app/core/BackupVault/backupVault.ts @@ -1,4 +1,4 @@ -import { KeyringState } from '@metamask/keyring-controller'; +import { KeyringControllerState } from '@metamask/keyring-controller'; import Logger from '../../util/Logger'; import { getInternetCredentials, @@ -35,7 +35,7 @@ interface KeyringBackupResponse { } */ export async function backupVault( - keyringState: KeyringState, + keyringState: KeyringControllerState, ): Promise { if (keyringState.vault) { const backupResult = await setInternetCredentials( diff --git a/app/core/Engine.ts b/app/core/Engine.ts index 502f125949b..92936759571 100644 --- a/app/core/Engine.ts +++ b/app/core/Engine.ts @@ -30,7 +30,6 @@ import { BaseState, ControllerMessenger } from '@metamask/base-controller'; import { ComposableController } from '@metamask/composable-controller'; import { KeyringController, - KeyringState, SignTypedDataVersion, KeyringControllerState, } from '@metamask/keyring-controller'; @@ -145,7 +144,7 @@ export interface EngineState { NftController: NftState; TokenListController: TokenListState; CurrencyRateController: CurrencyRateState; - KeyringController: KeyringState; + KeyringController: KeyringControllerState; NetworkController: NetworkState; PreferencesController: PreferencesState; PhishingController: PhishingState; @@ -221,7 +220,7 @@ class Engine { // eslint-disable-next-line @typescript-eslint/default-param-last constructor( initialState: Partial = {}, - initialKeyringState?: KeyringState | null, + initialKeyringState?: KeyringControllerState | null, ) { this.controllerMessenger = new ControllerMessenger(); @@ -420,6 +419,7 @@ class Engine { preferencesController, ), encryptor, + // @ts-expect-error Error might be caused by base controller version mismatch messenger: this.controllerMessenger.getRestricted({ name: 'KeyringController', }), @@ -619,7 +619,6 @@ class Engine { keyringController.signPersonalMessage.bind(keyringController), signTypedMessage: (msgParams, { version }) => keyringController.signTypedMessage( - // @ts-expect-error Error might be caused by base controller version mismatch msgParams, version as SignTypedDataVersion, ), diff --git a/app/selectors/types.ts b/app/selectors/types.ts index 87cd6e6a6d9..669f094d234 100644 --- a/app/selectors/types.ts +++ b/app/selectors/types.ts @@ -13,7 +13,7 @@ import SwapsController from '@metamask/swaps-controller'; import { NetworkState } from '@metamask/network-controller'; import { AddressBookState } from '@metamask/address-book-controller'; import { BaseState } from '@metamask/base-controller'; -import { KeyringMemState } from '@metamask/keyring-controller'; +import { KeyringControllerMemState } from '@metamask/keyring-controller'; import { PreferencesState } from '@metamask/preferences-controller'; import { PhishingState } from '@metamask/phishing-controller'; import { TransactionState } from '@metamask/transaction-controller'; @@ -30,7 +30,7 @@ export interface EngineState { NftController: NftState; TokenListController: TokenListState; CurrencyRateController: CurrencyRateState; - KeyringController: KeyringMemState; + KeyringController: KeyringControllerMemState; NetworkController: NetworkState; PreferencesController: PreferencesState; PhishingController: PhishingState; From 091642344fb11bf988e0c89c2ddb4c50411fda66 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Tue, 12 Sep 2023 17:48:38 -0300 Subject: [PATCH 59/67] chore: update @metamask/keyring-controller patch to modify PersonalMessageParams type --- ...roller++@metamask+message-manager+7.3.1.patch | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 patches/@metamask+keyring-controller++@metamask+message-manager+7.3.1.patch diff --git a/patches/@metamask+keyring-controller++@metamask+message-manager+7.3.1.patch b/patches/@metamask+keyring-controller++@metamask+message-manager+7.3.1.patch new file mode 100644 index 00000000000..91882e793e1 --- /dev/null +++ b/patches/@metamask+keyring-controller++@metamask+message-manager+7.3.1.patch @@ -0,0 +1,16 @@ +diff --git a/node_modules/@metamask/keyring-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts b/node_modules/@metamask/keyring-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts +index 5bf0005..f372485 100644 +--- a/node_modules/@metamask/keyring-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts ++++ b/node_modules/@metamask/keyring-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts +@@ -25,7 +25,10 @@ export interface PersonalMessage extends AbstractMessage { + */ + export interface PersonalMessageParams extends AbstractMessageParams { + data: string; +- siwe?: SIWEMessage; ++ siwe?: { ++ isSIWEMessage: boolean; ++ parsedMessage: null; ++ }; + } + /** + * @type MessageParamsMetamask From a116bfd2b0e6dc7f647d67360a582c4b178d0a57 Mon Sep 17 00:00:00 2001 From: Gustavo Antunes <17601467+gantunesr@users.noreply.github.com> Date: Fri, 15 Sep 2023 11:02:07 -0300 Subject: [PATCH 60/67] fix: keyring-controller construction Co-authored-by: Michele Esposito <34438276+mikesposito@users.noreply.github.com> --- app/core/Engine.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/core/Engine.ts b/app/core/Engine.ts index 92936759571..a1845e0fd9a 100644 --- a/app/core/Engine.ts +++ b/app/core/Engine.ts @@ -422,6 +422,13 @@ class Engine { // @ts-expect-error Error might be caused by base controller version mismatch messenger: this.controllerMessenger.getRestricted({ name: 'KeyringController', + allowedEvents: [ + 'KeyringController:lock', + 'KeyringController:unlock', + 'KeyringController:stateChange', + 'KeyringController:accountRemoved', + ], + allowedActions: ['KeyringController:getState'], }), state: initialKeyringState || initialState.KeyringController, keyringBuilders: [qrKeyringBuilder], From d8f856562787e0d67d693b7e10fcf9b78efd8323 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Fri, 15 Sep 2023 12:37:35 -0300 Subject: [PATCH 61/67] chore: add KeyringController actions and events to global constraints --- app/core/Engine.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/core/Engine.ts b/app/core/Engine.ts index a1845e0fd9a..04911ca91f7 100644 --- a/app/core/Engine.ts +++ b/app/core/Engine.ts @@ -32,6 +32,8 @@ import { KeyringController, SignTypedDataVersion, KeyringControllerState, + KeyringControllerActions, + KeyringControllerEvents, } from '@metamask/keyring-controller'; import { NetworkController, @@ -124,7 +126,8 @@ type GlobalActions = | GetTokenListState | NetworkControllerActions | PermissionControllerActions - | SignatureControllerActions; + | SignatureControllerActions + | KeyringControllerActions; type GlobalEvents = | ApprovalControllerEvents | CurrencyRateStateChange @@ -132,7 +135,8 @@ type GlobalEvents = | TokenListStateChange | NetworkControllerEvents | PermissionControllerEvents - | SignatureControllerEvents; + | SignatureControllerEvents + | KeyringControllerEvents; type PermissionsByRpcMethod = ReturnType; type Permissions = PermissionsByRpcMethod[keyof PermissionsByRpcMethod]; @@ -737,7 +741,6 @@ class Engine { handleVaultBackup() { this.controllerMessenger.subscribe( - // @ts-expect-error To Do: Include 'KeyringController:stateChange' to type. AppConstants.KEYRING_STATE_CHANGE_EVENT, (state: KeyringControllerState) => backupVault(state) From 38bacfdd233ccfb635bd2ca8da966975b73182cc Mon Sep 17 00:00:00 2001 From: gantunesr Date: Fri, 15 Sep 2023 23:57:03 -0300 Subject: [PATCH 62/67] refactor: use passwordRequirementsMet as requiment to enable CTA --- .../Views/RevealPrivateCredential/RevealPrivateCredential.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/components/Views/RevealPrivateCredential/RevealPrivateCredential.tsx b/app/components/Views/RevealPrivateCredential/RevealPrivateCredential.tsx index a82604bef2b..691ff5bd3e3 100644 --- a/app/components/Views/RevealPrivateCredential/RevealPrivateCredential.tsx +++ b/app/components/Views/RevealPrivateCredential/RevealPrivateCredential.tsx @@ -41,6 +41,7 @@ import { BIOMETRY_CHOICE } from '../../../constants/storage'; import { MetaMetricsEvents } from '../../../core/Analytics'; import AnalyticsV2 from '../../../util/analyticsV2'; import { uint8ArrayToMnemonic } from '../../../util/mnemonic'; +import { passwordRequirementsMet } from '../../../util/password'; import { Authentication } from '../../../core/'; import Device from '../../../util/device'; @@ -531,7 +532,7 @@ const RevealPrivateCredential = ({ onCancelPress={unlocked ? done : cancelReveal} onConfirmPress={() => tryUnlock()} showConfirmButton={!unlocked} - confirmDisabled={password.length < 8} + confirmDisabled={!passwordRequirementsMet(password)} cancelTestID={SECRET_RECOVERY_PHRASE_CANCEL_BUTTON_ID} confirmTestID={SECRET_RECOVERY_PHRASE_NEXT_BUTTON_ID} > From 63965dc158417f366edd582392cf5c138dee9660 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Fri, 15 Sep 2023 23:57:43 -0300 Subject: [PATCH 63/67] chore: add comment to micro-ftch patch to explain its purpose --- patches/micro-ftch+0.3.1.patch | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/patches/micro-ftch+0.3.1.patch b/patches/micro-ftch+0.3.1.patch index 02ac3555f2a..545f22c0168 100644 --- a/patches/micro-ftch+0.3.1.patch +++ b/patches/micro-ftch+0.3.1.patch @@ -1,8 +1,8 @@ diff --git a/node_modules/micro-ftch/index.js b/node_modules/micro-ftch/index.js -index 7f00c3d..3762bf0 100644 +index 7f00c3d..a4a6f79 100644 --- a/node_modules/micro-ftch/index.js +++ b/node_modules/micro-ftch/index.js -@@ -49,123 +49,123 @@ function detectType(b, type) { +@@ -49,123 +49,133 @@ function detectType(b, type) { return b; } let agents = {}; @@ -123,6 +123,16 @@ index 7f00c3d..3762bf0 100644 - req.end(); - }); -} ++ ++/** ++ * ============================== PATCH INFORMATION ============================== ++ * This patch addresses an incompatibility issue with the zlib node library that ++ * causes the React Native (RN) app to crash. The zlib library isn't compatible ++ * with RN. The patch mitigates this problem by commenting out a section of code ++ * that is specific to Node.js and not applicable to RN. ++ * =============================================================================== ++ */ ++ +// function fetchNode(url, _options) { +// let options = { ...DEFAULT_OPT, ..._options }; +// const http = require('http'); From 279c27046db8c0ffe79dec35299d17962b82eaf3 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Sun, 17 Sep 2023 00:02:43 -0300 Subject: [PATCH 64/67] fix: add missing updateIdentities call in keyring-controller patch --- patches/@metamask+keyring-controller+6.1.0.patch | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/patches/@metamask+keyring-controller+6.1.0.patch b/patches/@metamask+keyring-controller+6.1.0.patch index 5c4b4317374..277f0e0d15c 100644 --- a/patches/@metamask+keyring-controller+6.1.0.patch +++ b/patches/@metamask+keyring-controller+6.1.0.patch @@ -1,8 +1,9 @@ diff --git a/node_modules/@metamask/keyring-controller/dist/KeyringController.js b/node_modules/@metamask/keyring-controller/dist/KeyringController.js -index c905cc0..4827771 100644 +index c905cc0..f670fd3 100644 --- a/node_modules/@metamask/keyring-controller/dist/KeyringController.js +++ b/node_modules/@metamask/keyring-controller/dist/KeyringController.js -@@ -679,12 +679,12 @@ class KeyringController extends base_controller_1.BaseControllerV2 { +@@ -678,13 +678,21 @@ class KeyringController extends base_controller_1.BaseControllerV2 { + } forgetQRDevice() { return __awaiter(this, void 0, void 0, function* () { const keyring = yield this.getOrAddQRKeyring(); @@ -14,6 +15,7 @@ index c905cc0..4827771 100644 - }); + const remainingAccounts = (yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").getAccounts()); + const removedAccounts = allAccounts.filter((address) => !remainingAccounts.includes(address)); ++ this.updateIdentities(remainingAccounts); yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").persistAllKeyrings(); + return { removedAccounts, remainingAccounts }; }); From 6c4b74d0887acbd359abdee6e261fb6d2a15bd12 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Sun, 17 Sep 2023 00:04:12 -0300 Subject: [PATCH 65/67] chore: add information comment to keyring-controller patch --- patches/@metamask+keyring-controller+6.1.0.patch | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/patches/@metamask+keyring-controller+6.1.0.patch b/patches/@metamask+keyring-controller+6.1.0.patch index 277f0e0d15c..839e8536306 100644 --- a/patches/@metamask+keyring-controller+6.1.0.patch +++ b/patches/@metamask+keyring-controller+6.1.0.patch @@ -6,6 +6,13 @@ index c905cc0..f670fd3 100644 } 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. ++ * =============================================================================== ++ */ const keyring = yield this.getOrAddQRKeyring(); + const allAccounts = (yield __classPrivateFieldGet(this, _KeyringController_keyring, "f").getAccounts()); keyring.forgetDevice(); From 61781ff25a5e3942686c312a1e04a079e14ebdc3 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Sun, 17 Sep 2023 00:06:08 -0300 Subject: [PATCH 66/67] chore: add information comment to message manager patch inside the keyring-controller dependencies --- ...ler++@metamask+message-manager+7.3.1.patch | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/patches/@metamask+keyring-controller++@metamask+message-manager+7.3.1.patch b/patches/@metamask+keyring-controller++@metamask+message-manager+7.3.1.patch index 91882e793e1..ffa4622185f 100644 --- a/patches/@metamask+keyring-controller++@metamask+message-manager+7.3.1.patch +++ b/patches/@metamask+keyring-controller++@metamask+message-manager+7.3.1.patch @@ -1,12 +1,34 @@ diff --git a/node_modules/@metamask/keyring-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts b/node_modules/@metamask/keyring-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts -index 5bf0005..f372485 100644 +index 5bf0005..2d3a3c3 100644 --- a/node_modules/@metamask/keyring-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts +++ b/node_modules/@metamask/keyring-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts -@@ -25,7 +25,10 @@ export interface PersonalMessage extends AbstractMessage { +@@ -25,7 +25,32 @@ export interface PersonalMessage extends AbstractMessage { */ export interface PersonalMessageParams extends AbstractMessageParams { data: string; - siwe?: SIWEMessage; ++ /** ++ * ============================== PATCH INFORMATION ============================== ++ * This patch addresses an error type introduced in patch ++ * @metamask+message-manager+7.0.1.patch. The error type is thrown when a message ++ * is received that is not a valid SIWE message. the patch changes the data type ++ * in the following way. ++ * ++ * Previous data type: ++ * ```ts ++ * siwe?: SIWEMessage; ++ * ``` ++ * ++ * Current data type introduced in @metamask+message-manager+7.0.1.patch: ++ * ```ts ++ * siwe?: { ++ * isSIWEMessage: boolean; ++ * parsedMessage: null; ++ * }; ++ * ``` ++ * ++ * =============================================================================== ++ */ + siwe?: { + isSIWEMessage: boolean; + parsedMessage: null; From 0a506a869cec50759e1343eac1a59e7e7ae8ec0b Mon Sep 17 00:00:00 2001 From: gantunesr Date: Sun, 17 Sep 2023 00:32:13 -0300 Subject: [PATCH 67/67] fix: typo in @metamask/keyring-controller/@metamask/message-manager --- ...-controller++@metamask+message-manager+7.3.1.patch | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/patches/@metamask+keyring-controller++@metamask+message-manager+7.3.1.patch b/patches/@metamask+keyring-controller++@metamask+message-manager+7.3.1.patch index ffa4622185f..005acdccd60 100644 --- a/patches/@metamask+keyring-controller++@metamask+message-manager+7.3.1.patch +++ b/patches/@metamask+keyring-controller++@metamask+message-manager+7.3.1.patch @@ -1,18 +1,17 @@ diff --git a/node_modules/@metamask/keyring-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts b/node_modules/@metamask/keyring-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts -index 5bf0005..2d3a3c3 100644 +index 5bf0005..2702abd 100644 --- a/node_modules/@metamask/keyring-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts +++ b/node_modules/@metamask/keyring-controller/node_modules/@metamask/message-manager/dist/PersonalMessageManager.d.ts -@@ -25,7 +25,32 @@ export interface PersonalMessage extends AbstractMessage { +@@ -25,7 +25,31 @@ export interface PersonalMessage extends AbstractMessage { */ export interface PersonalMessageParams extends AbstractMessageParams { data: string; - siwe?: SIWEMessage; + /** + * ============================== PATCH INFORMATION ============================== -+ * This patch addresses an error type introduced in patch -+ * @metamask+message-manager+7.0.1.patch. The error type is thrown when a message -+ * is received that is not a valid SIWE message. the patch changes the data type -+ * in the following way. ++ * This patch addresses a type error that was introduced in ++ * @metamask+message-manager+7.0.1.patch. The error is triggered when a message is ++ * not a valid SIWE message. The patch modifies the data type as follows, + * + * Previous data type: + * ```ts