Skip to content

Commit

Permalink
support 32bits chainId
Browse files Browse the repository at this point in the history
  • Loading branch information
hackmod committed Apr 20, 2019
1 parent d8d866b commit 2538fe7
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 2538fe7

Please sign in to comment.