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

support 32bits chainid with the latest Ledger app #2094

Merged
Merged
Changes from 1 commit
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
16 changes: 14 additions & 2 deletions common/libs/wallet/deterministic/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,29 @@ 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;
hackmod marked this conversation as resolved.
Show resolved Hide resolved
if (t._chainId > 0) {
// EIP155 support. check/recalc signature v value.
const rv = parseInt(v, 16);
let cv = t._chainId * 2 + 35;
/* tslint:disable no-bitwise */
if (rv !== cv && (rv & cv) !== rv) {
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