Skip to content

Commit

Permalink
Merge pull request #2094 from OpenCommunityCoin/ledger-32bits-chainid
Browse files Browse the repository at this point in the history
support 32bits chainid with the latest Ledger app
  • Loading branch information
ConnorBryan authored Sep 4, 2018
2 parents f011fd5 + 20fb2e7 commit e298305
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions common/libs/wallet/deterministic/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,34 @@ export class LedgerWallet extends HardwareWallet {

public async signRawTransaction(t: EthTx): Promise<Buffer> {
const txFields = getTransactionFields(t);
t.v = Buffer.from([t._chainId]);
t.v = toBuffer(t._chainId);
t.r = toBuffer(0);
t.s = toBuffer(0);

try {
const ethApp = await makeApp();
const result = await ethApp.signTransaction(this.getPath(), t.serialize().toString('hex'));

let v = result.v;
if (t._chainId > 0) {
// EIP155 support. check/recalc signature v value.
// Please see https://github.com/LedgerHQ/blue-app-eth/commit/8260268b0214810872dabd154b476f5bb859aac0
// currently, ledger returns only 1-byte truncated signatur_v
const rv = parseInt(v, 16);
let cv = t._chainId * 2 + 35; // calculated signature v, without signature bit.
/* tslint:disable no-bitwise */
if (rv !== cv && (rv & cv) !== rv) {
// (rv !== cv) : for v is truncated byte case
// (rv & cv): make cv to truncated byte
// (rv & cv) !== rv: signature v bit needed
cv += 1; // add signature v bit.
}
v = cv.toString(16);
}

const txToSerialize: TxObj = {
...txFields,
v: addHexPrefix(result.v),
v: addHexPrefix(v),
r: addHexPrefix(result.r),
s: addHexPrefix(result.s)
};
Expand Down

0 comments on commit e298305

Please sign in to comment.