Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
cs1707 committed Dec 6, 2024
2 parents c4894bd + b292cb9 commit 9bfd941
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 48 deletions.
72 changes: 31 additions & 41 deletions src/background/service/keyring/eth-ledger-keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as ethUtil from 'ethereumjs-util';
import * as sigUtil from 'eth-sig-util';
import TransportWebHID from '@ledgerhq/hw-transport-webhid';
import Transport from '@ledgerhq/hw-transport';
import LedgerEth from '@ledgerhq/hw-app-eth';
import LedgerEth, { ledgerService } from '@ledgerhq/hw-app-eth';
import { is1559Tx } from '@/utils/transaction';
import {
TransactionFactory,
Expand Down Expand Up @@ -317,7 +317,12 @@ class LedgerBridgeKeyring {
const hdPath = await this.unlockAccountByAddress(address);
await this.makeApp(true);
try {
const res = await this.app!.signTransaction(hdPath, rawTxHex);
const resolution = await ledgerService.resolveTransaction(
rawTxHex,
{},
{}
);
const res = await this.app!.signTransaction(hdPath, rawTxHex, resolution);
const newOrMutatedTx = handleSigning(res);
const valid = newOrMutatedTx.verifySignature();
if (valid) {
Expand Down Expand Up @@ -403,45 +408,30 @@ class LedgerBridgeKeyring {
try {
await this.makeApp(true);

let res: {
v: number;
s: string;
r: string;
};

// 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) {
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
);
}
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 res = await this.app!.signEIP712HashedMessage(
hdPath,
domainSeparatorHex,
hashStructMessageHex
);

let v = res.v.toString(16);
if (v.length < 2) {
Expand Down
12 changes: 5 additions & 7 deletions src/ui/models/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,12 @@ export const chains = createModel<RootModel>()({
},
effects: (dispatch) => ({
init(_: void, store) {
Promise.race([store.app.wallet.getCustomTestnetLogos(), sleep(3000)])
.then(() => store.app.wallet.getCustomTestnetList())
.then((testnetList) => {
updateChainStore({
testnetList: testnetList,
});
this.setField({ testnetList });
store.app.wallet.getCustomTestnetLogos();
store.app.wallet.getCustomTestnetList().then((testnetList) => {
updateChainStore({
testnetList: testnetList,
});
});
getMainnetListFromLocal().then((mainnetList) => {
if (mainnetList.length) {
updateChainStore({
Expand Down
9 changes: 9 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19596,6 +19596,15 @@ wrap-ansi@^7.0.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down

0 comments on commit 9bfd941

Please sign in to comment.