Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve some issue and suggestions from audit #2655

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import EventEmitter from 'events';
import * as ethUtil from 'ethereumjs-util';
import { FeeMarketEIP1559Transaction, Transaction } from '@ethereumjs/tx';
import { EVENTS } from '@/constant';
import { is1559Tx } from '@/utils/transaction';
import { bytesToHex } from 'web3-utils';
import { ImKeyBridgeInterface } from './imkey-bridge-interface';
Expand All @@ -10,7 +9,7 @@ import { signHashHex } from './utils';
const keyringType = 'imKey Hardware';
const MAX_INDEX = 1000;

const convertToBigint = (value: any) => {
const convertToHex = (value: any) => {
return typeof value === 'bigint'
? `0x${value.toString(16)}`
: `0x${value.toString('hex')}`;
Expand Down Expand Up @@ -255,29 +254,27 @@ export class EthImKeyKeyring extends EventEmitter {
const txData = is1559
? {
data: dataHex === '' ? '' : `0x${dataHex}`,
gasLimit: convertToBigint(transaction.gasLimit),
type: convertToBigint(transaction.type.toString()),
gasLimit: convertToHex(transaction.gasLimit),
type: convertToHex(transaction.type.toString()),
accessList: transaction.accessList,
maxFeePerGas: convertToBigint(transaction.maxFeePerGas),
maxPriorityFeePerGas: convertToBigint(
transaction.maxPriorityFeePerGas
),
nonce: convertToBigint(transaction.nonce),
maxFeePerGas: convertToHex(transaction.maxFeePerGas),
maxPriorityFeePerGas: convertToHex(transaction.maxPriorityFeePerGas),
nonce: convertToHex(transaction.nonce),
to: transaction.to!.toString(),
value: convertToBigint(transaction.value),
value: convertToHex(transaction.value),
chainId: txChainId,
path: accountDetail.hdPath,
}
: {
to: transaction.to!.toString(),
value: convertToBigint(transaction.value),
value: convertToHex(transaction.value),
data: dataHex === '' ? '' : `0x${dataHex}`,
nonce: convertToBigint(transaction.nonce),
gasLimit: convertToBigint(transaction.gasLimit),
nonce: convertToHex(transaction.nonce),
gasLimit: convertToHex(transaction.gasLimit),
gasPrice:
typeof (transaction as Transaction).gasPrice !== 'undefined'
? convertToBigint((transaction as Transaction).gasPrice)
: convertToBigint(
? convertToHex((transaction as Transaction).gasPrice)
: convertToHex(
(transaction as FeeMarketEIP1559Transaction).maxFeePerGas
),
chainId: txChainId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const HD_PATH_TYPE = {
[HD_PATH_BASE[HDPathType.LedgerLive]]: HDPathType.LedgerLive,
};

let callStackCounter = 0;

class LatticeKeyring extends OldLatticeKeyring {
[x: string]: any;
appName = 'Rabby';
Expand Down Expand Up @@ -104,6 +106,7 @@ class LatticeKeyring extends OldLatticeKeyring {
index: start + i + 1,
};
});
callStackCounter = 0;
return accounts;
} catch (err) {
// This will get hit for a few reasons. Here are two possibilities:
Expand All @@ -113,6 +116,8 @@ class LatticeKeyring extends OldLatticeKeyring {
// In either event we should try to resync the wallet and if that
// fails throw an error
try {
if (callStackCounter > 20) throw new Error('Max call stacks');
callStackCounter++;
await this._connect();
return this.getAddresses(start, end);
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion src/background/service/keyring/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class KeyringService extends EventEmitter {
store!: ObservableStore<any>;
memStore: ObservableStore<MemStoreState>;
keyrings: any[];
password: string | null = null;
private password: string | null = null;

constructor() {
super();
Expand Down
Loading