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(keyring-eth-ledger-bridge): trim 0x prefix for signTransaction (due to latest @ethereumjs upgrade) #253

Merged
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
Expand Up @@ -3,7 +3,7 @@ import { RLP } from '@ethereumjs/rlp';
import { TransactionFactory } from '@ethereumjs/tx';
import * as ethUtil from '@ethereumjs/util';
import * as sigUtil from '@metamask/eth-sig-util';
import { bytesToHex, Hex } from '@metamask/utils';
import { bytesToHex, Hex, remove0x } from '@metamask/utils';
import EthereumTx from 'ethereumjs-tx';
import HDKey from 'hdkey';

Expand Down Expand Up @@ -719,7 +719,9 @@ describe('LedgerKeyring', function () {
.mockImplementation(async (params) => {
expect(params).toStrictEqual({
hdPath: "m/44'/60'/0'/0",
tx: bytesToHex(fakeTypeTwoTx.getMessageToSign() as Uint8Array),
tx: remove0x(
bytesToHex(fakeTypeTwoTx.getMessageToSign() as Uint8Array),
),
});
return expectedRSV;
});
Expand All @@ -745,7 +747,7 @@ describe('LedgerKeyring', function () {

await expect(
keyring.signTransaction(fakeAccounts[0], fakeTx),
).rejects.toThrow('Ledger: Unknown error while signing transaction');
).rejects.toThrow('Ledger: hdPath is empty while signing transaction');
});

it('throws different error to the default one if the bridge error is an instance of the Error object', async function () {
Expand Down
5 changes: 3 additions & 2 deletions packages/keyring-eth-ledger-bridge/src/ledger-keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,14 @@ export class LedgerKeyring implements Keyring {
const hdPath = await this.unlockAccountByAddress(address);

if (!hdPath) {
throw new Error('Ledger: Unknown error while signing transaction');
throw new Error('Ledger: hdPath is empty while signing transaction');
}

let payload;

try {
payload = await this.bridge.deviceSignTransaction({
tx: rawTxHex,
tx: remove0x(rawTxHex),
hdPath,
});
} catch (error) {
Expand Down
Loading