Skip to content

Commit

Permalink
feat(12537): move to ledger keyring v8.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Akaryatrh committed Dec 9, 2024
1 parent a60fe1a commit a392258
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 46 deletions.
16 changes: 10 additions & 6 deletions app/core/Engine/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -951,8 +951,8 @@ export class Engine {
disableSnaps: !isBasicFunctionalityToggleEnabled(),
}),
clientCryptography: {
pbkdf2Sha512: pbkdf2
}
pbkdf2Sha512: pbkdf2,
},
});

const authenticationController = new AuthenticationController.Controller({
Expand Down Expand Up @@ -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(),
),
Expand Down Expand Up @@ -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(() => {
Expand All @@ -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,
)}`,
);
}
},
Expand Down
46 changes: 27 additions & 19 deletions app/core/Ledger/Ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
};

Expand All @@ -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);
}
};


2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
31 changes: 13 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4360,18 +4360,6 @@
resolved "https://registry.yarnpkg.com/@mantine/hooks/-/hooks-7.8.0.tgz#fc32e07746689459c4b049dc581d1dbda5545686"
integrity sha512-+70fkgjhVJeJ+nJqnburIM3UAsfvxat1Low9HMPobLbv64FIdB4Nzu5ct3qojNQ58r5sK01tg5UoFIJYslaVrg==

"@metamask-previews/[email protected]":
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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -12429,7 +12429,7 @@ axios-retry@^3.1.2:
"@babel/runtime" "^7.15.4"
is-retry-allowed "^2.2.0"

[email protected], [email protected], axios@^0.28.0, axios@^0.x, axios@^1.6.7, axios@^1.6.8, axios@^1.7.4, axios@~1.6.8:
[email protected], [email protected], 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==
Expand Down Expand Up @@ -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==

[email protected]:
version "1.0.1"
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
Expand Down

0 comments on commit a392258

Please sign in to comment.