Skip to content

Commit

Permalink
fix ledger hardware wallet to support 32bits chainId
Browse files Browse the repository at this point in the history
  • Loading branch information
hackmod committed Apr 27, 2019
1 parent 86f474b commit 5b2db68
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/wallets/hardware/ledger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ledgerWallet {
const txSigner = async tx => {
tx = new ethTx(tx);
const networkId = tx._chainId;
tx.raw[6] = Buffer.from([networkId]);
tx.raw[6] = networkId;
tx.raw[7] = Buffer.from([]);
tx.raw[8] = Buffer.from([]);
const tokenInfo = byContractAddress('0x' + tx.to.toString('hex'));
Expand All @@ -67,7 +67,17 @@ class ledgerWallet {
accountPath,
tx.serialize().toString('hex')
);
tx.v = getBufferFromHex(result.v);

// EIP155 support. check/recalc signature v value.
let v = result.v;
const rv = parseInt(v, 16);
let cv = networkId * 2 + 35;
if (rv !== cv && (rv & cv) !== rv) {
cv += 1; // add signature v bit.
}
v = cv.toString(16);

tx.v = getBufferFromHex(v);
tx.r = getBufferFromHex(result.r);
tx.s = getBufferFromHex(result.s);
const signedChainId = calculateChainIdFromV(tx.v);
Expand Down

0 comments on commit 5b2db68

Please sign in to comment.