From 062e96113696f1e0899fad86885b3c6b2f23e8a5 Mon Sep 17 00:00:00 2001 From: Xiaoming Wang Date: Thu, 20 Jun 2024 13:28:21 +0100 Subject: [PATCH] feat: change setAccountToUnlock method signature to enforce index is number type. --- src/ledger-keyring.ts | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/ledger-keyring.ts b/src/ledger-keyring.ts index 57fa42bb..ee8a7f68 100644 --- a/src/ledger-keyring.ts +++ b/src/ledger-keyring.ts @@ -25,10 +25,10 @@ const keyringType = 'Ledger Hardware'; const MAX_INDEX = 1000; enum NetworkApiUrls { - Ropsten = 'http://api-ropsten.etherscan.io', - Kovan = 'http://api-kovan.etherscan.io', + Ropsten = 'https://api-ropsten.etherscan.io', + Kovan = 'https://api-kovan.etherscan.io', Rinkeby = 'https://api-rinkeby.etherscan.io', - Mainnet = 'https://api.etherscan.io', + Mainnet = `https://api.etherscan.io`, } type SignTransactionPayload = Awaited< @@ -314,11 +314,11 @@ export class LedgerKeyring extends EventEmitter { // transaction which is only communicated to ethereumjs-tx in this // value. In newer versions the chainId is communicated via the 'Common' // object. - // @ts-expect-error tx.v should be a Buffer but we are assigning a string + // @ts-expect-error tx.v should be a Buffer, but we are assigning a string tx.v = ethUtil.bufferToHex(tx.getChainId()); - // @ts-expect-error tx.r should be a Buffer but we are assigning a string + // @ts-expect-error tx.r should be a Buffer, but we are assigning a string tx.r = '0x00'; - // @ts-expect-error tx.s should be a Buffer but we are assigning a string + // @ts-expect-error tx.s should be a Buffer, but we are assigning a string tx.s = '0x00'; rawTxHex = tx.serialize().toString('hex'); @@ -422,11 +422,6 @@ export class LedgerKeyring extends EventEmitter { : new Error('Ledger: Unknown error while signing message'); } - let recoveryId = parseInt(String(payload.v), 10).toString(16); - if (recoveryId.length < 2) { - recoveryId = `0${recoveryId}`; - } - let modifiedV = parseInt(String(payload.v), 10).toString(16); if (modifiedV.length < 2) { modifiedV = `0${modifiedV}`; @@ -662,10 +657,7 @@ export class LedgerKeyring extends EventEmitter { `${apiUrl}/api?module=account&action=txlist&address=${address}&tag=latest&page=1&offset=1`, ); const parsedResponse = await response.json(); - if (parsedResponse.status !== '0' && parsedResponse.result.length > 0) { - return true; - } - return false; + return parsedResponse.status !== '0' && parsedResponse.result.length > 0; } #getApiUrl() {