Skip to content

Commit

Permalink
Merge branch 'feat/ledger-clear' into tmp/20241018
Browse files Browse the repository at this point in the history
  • Loading branch information
heisenberg-2077 committed Oct 15, 2024
2 parents b055992 + 6309ebc commit 379423a
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 120 deletions.
2 changes: 1 addition & 1 deletion apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@ethereumjs/tx": "5.1.0",
"@ethereumjs/util": "^9.0.1",
"@gorhom/bottom-sheet": "alpha",
"@ledgerhq/react-native-hw-transport-ble": "6.33.2",
"@ledgerhq/react-native-hw-transport-ble": "6.33.4",
"@metamask/abi-utils": "2.0.2",
"@metamask/eth-sig-util": "5.1.0",
"@ngraveio/bc-ur": "1.1.6",
Expand Down
4 changes: 2 additions & 2 deletions packages/eth-keyring-ledger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"test:watch": "jest --watch"
},
"dependencies": {
"@ledgerhq/hw-app-eth": "6.29.9",
"@ledgerhq/hw-transport": "^6.30.3",
"@ledgerhq/hw-app-eth": "6.40.0",
"@ledgerhq/hw-transport": "6.31.4",
"@rabby-wallet/base-utils": "workspace:^",
"@rabby-wallet/keyring-utils": "workspace:^",
"eth-sig-util": "^3.0.1",
Expand Down
78 changes: 32 additions & 46 deletions packages/eth-keyring-ledger/src/LedgerKeyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
TransactionFactory,
FeeMarketEIP1559Transaction,
} from '@ethereumjs/tx';
import LedgerEth, { ledgerService } from '@ledgerhq/hw-app-eth';
import LedgerEth from '@ledgerhq/hw-app-eth';
import type Transport from '@ledgerhq/hw-transport';
import { addressUtils } from '@rabby-wallet/base-utils';
import {
Expand Down Expand Up @@ -416,12 +416,7 @@ class LedgerKeyring {
const hdPath = await this.unlockAccountByAddress(address);
await this.makeApp(true);
try {
const resolution = await ledgerService.resolveTransaction(
rawTxHex,
{},
{},
);
const res = await this.app!.signTransaction(hdPath, rawTxHex, resolution);
const res = await this.app!.signTransaction(hdPath, rawTxHex);
const newOrMutatedTx = handleSigning(res);
const valid = newOrMutatedTx.verifySignature();
if (valid) {
Expand Down Expand Up @@ -511,21 +506,6 @@ class LedgerKeyring {
);
}

const { domain, types, primaryType, message } =
sigUtil.TypedDataUtils.sanitizeData(data);
const domainSeparatorHex = sigUtil.TypedDataUtils.hashStruct(
'EIP712Domain',
domain,
types,
isV4,
).toString('hex');
const hashStructMessageHex = sigUtil.TypedDataUtils.hashStruct(
primaryType as string,
message,
types,
isV4,
).toString('hex');

const hdPath = await this.unlockAccountByAddress(withAccount);
try {
await this.makeApp(true);
Expand All @@ -537,30 +517,36 @@ class LedgerKeyring {
};

// https://github.com/LedgerHQ/ledger-live/blob/5bae039273beeeb02d8640d778fd7bf5f7fd3776/libs/coin-evm/src/hw-signMessage.ts#L68C7-L79C10
// try {
// res = await this.app!.signEIP712Message(hdPath, data);
// } catch (e) {
// if (
// e instanceof Error &&
// 'statusText' in e &&
// (e as any).statusText === 'INS_NOT_SUPPORTED'
// ) {
// res = await this.app!.signEIP712HashedMessage(
// hdPath,
// domainSeparatorHex,
// hashStructMessageHex
// );
// } else {
// throw e;
// }
// }

// eslint-disable-next-line prefer-const
res = await this.app!.signEIP712HashedMessage(
hdPath,
domainSeparatorHex,
hashStructMessageHex,
);
try {
res = await this.app!.signEIP712Message(hdPath, data);
} catch (e: any) {
const shouldFallbackOnHashedMethod =
'statusText' in e && e.statusText === 'INS_NOT_SUPPORTED';
if (!shouldFallbackOnHashedMethod) {
throw e;
}

const { domain, types, primaryType, message } =
sigUtil.TypedDataUtils.sanitizeData(data);
const domainSeparatorHex = sigUtil.TypedDataUtils.hashStruct(
'EIP712Domain',
domain,
types,
isV4,
).toString('hex');
const hashStructMessageHex = sigUtil.TypedDataUtils.hashStruct(
primaryType as string,
message,
types,
isV4,
).toString('hex');

res = await this.app!.signEIP712HashedMessage(
hdPath,
domainSeparatorHex,
hashStructMessageHex,
);
}

let v = res.v.toString(16);
if (v.length < 2) {
Expand Down
Loading

0 comments on commit 379423a

Please sign in to comment.