Skip to content

Commit

Permalink
fix: resolve some issue and suggestions from audit (#2655)
Browse files Browse the repository at this point in the history
* chore: rename func name

* fix: + max call stacks for gridplus

* fix: make password private
  • Loading branch information
vvvvvv1vvvvvv authored Dec 19, 2024
1 parent f73c656 commit de86e45
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
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 @@ -25,6 +25,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 @@ -92,6 +94,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 @@ -101,6 +104,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

0 comments on commit de86e45

Please sign in to comment.