From a392258d6d6d7911b1181e1d80b9a2ccb6caa3b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Van=20Eyck?= Date: Mon, 9 Dec 2024 15:01:11 +0100 Subject: [PATCH] feat(12537): move to ledger keyring v8.0.0 --- app/core/Engine/Engine.ts | 16 +++++++++----- app/core/Ledger/Ledger.ts | 46 +++++++++++++++++++++++---------------- ios/Podfile.lock | 2 +- package.json | 3 +-- yarn.lock | 31 +++++++++++--------------- 5 files changed, 52 insertions(+), 46 deletions(-) diff --git a/app/core/Engine/Engine.ts b/app/core/Engine/Engine.ts index bddfa764db00..965788666ca0 100644 --- a/app/core/Engine/Engine.ts +++ b/app/core/Engine/Engine.ts @@ -80,7 +80,7 @@ import { LedgerKeyring, LedgerMobileBridge, LedgerTransportMiddleware, -} from '@metamask-previews/eth-ledger-bridge-keyring'; +} from '@metamask/eth-ledger-bridge-keyring'; import { Encryptor, LEGACY_DERIVATION_OPTIONS, pbkdf2 } from '../Encryptor'; import { isMainnetByChainId, @@ -951,8 +951,8 @@ export class Engine { disableSnaps: !isBasicFunctionalityToggleEnabled(), }), clientCryptography: { - pbkdf2Sha512: pbkdf2 - } + pbkdf2Sha512: pbkdf2, + }, }); const authenticationController = new AuthenticationController.Controller({ @@ -1277,7 +1277,9 @@ export class Engine { .addProperties({ token_standard: 'ERC20', asset_type: 'token', - chain_id: getDecimalChainId(getGlobalChainId(networkController)), + chain_id: getDecimalChainId( + getGlobalChainId(networkController), + ), }) .build(), ), @@ -1496,7 +1498,7 @@ export class Engine { if ( state.networksMetadata[state.selectedNetworkClientId].status === NetworkStatus.Available && - getGlobalChainId(networkController) !== currentChainId + getGlobalChainId(networkController) !== currentChainId ) { // We should add a state or event emitter saying the provider changed setTimeout(() => { @@ -1516,7 +1518,9 @@ export class Engine { } catch (error) { console.error( error, - `Network ID not changed, current chainId: ${getGlobalChainId(networkController)}`, + `Network ID not changed, current chainId: ${getGlobalChainId( + networkController, + )}`, ); } }, diff --git a/app/core/Ledger/Ledger.ts b/app/core/Ledger/Ledger.ts index a83eae0e4758..b3c10b3595d9 100644 --- a/app/core/Ledger/Ledger.ts +++ b/app/core/Ledger/Ledger.ts @@ -5,7 +5,7 @@ import Engine from '../Engine'; import { LedgerKeyring, LedgerMobileBridge, -} from '@metamask-previews/eth-ledger-bridge-keyring'; +} from '@metamask/eth-ledger-bridge-keyring'; import { LEDGER_BIP44_PATH, LEDGER_LEGACY_PATH, @@ -217,8 +217,12 @@ export const ledgerSignTypedMessage = async ( */ export const checkAccountNameExists = async (accountName: string) => { const accountsController = Engine.context.AccountsController; - const accounts = Object.values(accountsController.state.internalAccounts.accounts); - const existingAccount = accounts.find((account) => account.metadata.name === accountName); + const accounts = Object.values( + accountsController.state.internalAccounts.accounts, + ); + const existingAccount = accounts.find( + (account) => account.metadata.name === accountName, + ); return !!existingAccount; }; @@ -229,26 +233,30 @@ export const checkAccountNameExists = async (accountName: string) => { */ export const unlockLedgerWalletAccount = async (index: number) => { const accountsController = Engine.context.AccountsController; - const { unlockAccount, name} = await withLedgerKeyring(async (keyring: LedgerKeyring) => { - const existingAccounts = await keyring.getAccounts(); - const keyringName = keyringTypeToName(ExtendedKeyringTypes.ledger); - const accountName = `${keyringName} ${existingAccounts.length + 1}`; + const { unlockAccount, name } = await withLedgerKeyring( + async (keyring: LedgerKeyring) => { + const existingAccounts = await keyring.getAccounts(); + const keyringName = keyringTypeToName(ExtendedKeyringTypes.ledger); + const accountName = `${keyringName} ${existingAccounts.length + 1}`; - if(await checkAccountNameExists(accountName)) { - throw new Error(strings('ledger.account_name_existed', { accountName })); - } + if (await checkAccountNameExists(accountName)) { + throw new Error( + strings('ledger.account_name_existed', { accountName }), + ); + } - keyring.setAccountToUnlock(index); - const accounts = await keyring.addAccounts(1); - return { unlockAccount: accounts[accounts.length - 1], name: accountName }; - }); + keyring.setAccountToUnlock(index); + const accounts = await keyring.addAccounts(1); + return { + unlockAccount: accounts[accounts.length - 1], + name: accountName, + }; + }, + ); - const account = - accountsController.getAccountByAddress(unlockAccount); + const account = accountsController.getAccountByAddress(unlockAccount); - if(account && name !== account.metadata.name) { + if (account && name !== account.metadata.name) { accountsController.setAccountName(account.id, name); } }; - - diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 65361575cd72..bde2540d44b8 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -1330,7 +1330,7 @@ SPEC CHECKSUMS: lottie-react-native: b6776287d7fd31be4fd865059cd890f744242ffd MMKV: f7d1d5945c8765f97f39c3d121f353d46735d801 MMKVCore: c04b296010fcb1d1638f2c69405096aac12f6390 - MultiplatformBleAdapter: ea8bac405ec200d0ca9de0f89afef6f06fb2abbc + MultiplatformBleAdapter: b1fddd0d499b96b607e00f0faa8e60648343dc1d nanopb: 438bc412db1928dac798aa6fd75726007be04262 OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c Permission-BluetoothPeripheral: 34ab829f159c6cf400c57bac05f5ba1b0af7a86e diff --git a/package.json b/package.json index 9d63c75132fb..6b8f0d990610 100644 --- a/package.json +++ b/package.json @@ -160,7 +160,7 @@ "@metamask/eth-hd-keyring": "^9.0.0", "@metamask/eth-json-rpc-filters": "^8.0.0", "@metamask/eth-json-rpc-middleware": "^11.0.2", - "@metamask-previews/eth-ledger-bridge-keyring": "7.0.0-dde1dbb", + "@metamask/eth-ledger-bridge-keyring": "^8.0.0", "@metamask/eth-query": "^4.0.0", "@metamask/eth-sig-util": "^8.0.0", "@metamask/eth-snap-keyring": "^5.0.1", @@ -243,7 +243,6 @@ "base-64": "1.0.0", "bignumber.js": "^9.0.1", "bitcoin-address-validation": "2.2.3", - "browserify-zlib": "^0.2.0", "buffer": "6.0.3", "cockatiel": "^3.1.2", "compare-versions": "^3.6.0", diff --git a/yarn.lock b/yarn.lock index 9c633eb0a994..a53fbcf84c65 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4360,18 +4360,6 @@ resolved "https://registry.yarnpkg.com/@mantine/hooks/-/hooks-7.8.0.tgz#fc32e07746689459c4b049dc581d1dbda5545686" integrity sha512-+70fkgjhVJeJ+nJqnburIM3UAsfvxat1Low9HMPobLbv64FIdB4Nzu5ct3qojNQ58r5sK01tg5UoFIJYslaVrg== -"@metamask-previews/eth-ledger-bridge-keyring@7.0.0-dde1dbb": - version "7.0.0-dde1dbb" - resolved "https://registry.yarnpkg.com/@metamask-previews/eth-ledger-bridge-keyring/-/eth-ledger-bridge-keyring-7.0.0-dde1dbb.tgz#9fb596ee7d264153f852e7ff643f3cfc92bbf0ec" - integrity sha512-lHY15p0Dk+4Mf5TjVlt4+ERUfvhr2lrl9NXxYSQUoyYTa0YSJrzznVsNDckVj319AiEYNIZJIoi/cHb/3X2nbg== - dependencies: - "@ethereumjs/rlp" "^5.0.2" - "@ethereumjs/tx" "^4.2.0" - "@ethereumjs/util" "^8.1.0" - "@ledgerhq/hw-app-eth" "^6.39.0" - "@metamask/eth-sig-util" "^8.0.0" - hdkey "^2.1.0" - "@metamask/abi-utils@^1.2.0": version "1.2.0" resolved "https://registry.yarnpkg.com/@metamask/abi-utils/-/abi-utils-1.2.0.tgz#068e1b0f5e423dfae96961e0e5276a7c1babc03a" @@ -4648,6 +4636,18 @@ "@metamask/utils" "^10.0.0" uuid "^8.3.2" +"@metamask/eth-ledger-bridge-keyring@^8.0.0": + version "8.0.0" + resolved "https://consensys.jfrog.io/artifactory/api/npm/npm/@metamask/eth-ledger-bridge-keyring/-/eth-ledger-bridge-keyring-8.0.0.tgz#f425443dfe3e00f2e4f17ef57c9d0c3990c3e69f" + integrity sha512-HqdLXGKJOMIDVheep1kLhc7MfY4NGmgOYM886XIh7dcEdX0WuaujvOPfaJ4IKEKMPBbFr6wsOYY31KvZ3s+9ew== + dependencies: + "@ethereumjs/rlp" "^5.0.2" + "@ethereumjs/tx" "^4.2.0" + "@ethereumjs/util" "^8.1.0" + "@ledgerhq/hw-app-eth" "^6.39.0" + "@metamask/eth-sig-util" "^8.0.0" + hdkey "^2.1.0" + "@metamask/eth-query@^4.0.0": version "4.0.0" resolved "https://registry.yarnpkg.com/@metamask/eth-query/-/eth-query-4.0.0.tgz#a8c1651b69e298da58628b1c09d31dd504a939b3" @@ -12429,7 +12429,7 @@ axios-retry@^3.1.2: "@babel/runtime" "^7.15.4" is-retry-allowed "^2.2.0" -axios@1.4.0, axios@1.7.7, axios@^0.28.0, axios@^0.x, axios@^1.6.7, axios@^1.6.8, axios@^1.7.4, axios@~1.6.8: +axios@1.4.0, axios@1.7.7, axios@^0.28.0, axios@^1.6.7, axios@^1.6.8, axios@^1.7.4, axios@~1.6.8: version "1.7.4" resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.4.tgz#4c8ded1b43683c8dd362973c393f3ede24052aa2" integrity sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw== @@ -28687,11 +28687,6 @@ utility-types@^3.10.0: resolved "https://registry.yarnpkg.com/utility-types/-/utility-types-3.11.0.tgz#607c40edb4f258915e901ea7995607fdf319424c" integrity sha512-6Z7Ma2aVEWisaL6TvBCy7P8rm2LQoPv6dJ7ecIaIixHcwfbJ0x7mWdbcwlIM5IGQxPZSFYeqRCqlOOeKoJYMkw== -utility-types@^3.10.0: - version "3.11.0" - resolved "https://registry.yarnpkg.com/utility-types/-/utility-types-3.11.0.tgz#607c40edb4f258915e901ea7995607fdf319424c" - integrity sha512-6Z7Ma2aVEWisaL6TvBCy7P8rm2LQoPv6dJ7ecIaIixHcwfbJ0x7mWdbcwlIM5IGQxPZSFYeqRCqlOOeKoJYMkw== - utils-merge@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"