|
|
|
@ -338,10 +338,24 @@ func (w *ledgerDriver) ledgerSign(derivationPath []uint32, tx *types.Transaction |
|
|
|
|
return common.Address{}, nil, err |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if tx.Type() == types.DynamicFeeTxType { |
|
|
|
|
if txrlp, err = rlp.EncodeToBytes([]interface{}{chainID, tx.Nonce(), tx.GasTipCap(), tx.GasFeeCap(), tx.Gas(), tx.To(), tx.Value(), tx.Data(), tx.AccessList()}); err != nil { |
|
|
|
|
return common.Address{}, nil, err |
|
|
|
|
} |
|
|
|
|
// append type to transaction
|
|
|
|
|
txrlp = append([]byte{tx.Type()}, txrlp...) |
|
|
|
|
} else if tx.Type() == types.AccessListTxType { |
|
|
|
|
if txrlp, err = rlp.EncodeToBytes([]interface{}{chainID, tx.Nonce(), tx.GasPrice(), tx.Gas(), tx.To(), tx.Value(), tx.Data(), tx.AccessList()}); err != nil { |
|
|
|
|
return common.Address{}, nil, err |
|
|
|
|
} |
|
|
|
|
// append type to transaction
|
|
|
|
|
txrlp = append([]byte{tx.Type()}, txrlp...) |
|
|
|
|
} else if tx.Type() == types.LegacyTxType { |
|
|
|
|
if txrlp, err = rlp.EncodeToBytes([]interface{}{tx.Nonce(), tx.GasPrice(), tx.Gas(), tx.To(), tx.Value(), tx.Data(), chainID, big.NewInt(0), big.NewInt(0)}); err != nil { |
|
|
|
|
return common.Address{}, nil, err |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
payload := append(path, txrlp...) |
|
|
|
|
|
|
|
|
|
// Send the request and wait for the response
|
|
|
|
@ -353,8 +367,10 @@ func (w *ledgerDriver) ledgerSign(derivationPath []uint32, tx *types.Transaction |
|
|
|
|
// Chunk size selection to mitigate an underlying RLP deserialization issue on the ledger app.
|
|
|
|
|
// https://github.com/LedgerHQ/app-ethereum/issues/409
|
|
|
|
|
chunk := 255 |
|
|
|
|
if tx.Type() == types.LegacyTxType { |
|
|
|
|
for ; len(payload)%chunk <= ledgerEip155Size; chunk-- { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for len(payload) > 0 { |
|
|
|
|
// Calculate the size of the next data chunk
|
|
|
|
@ -381,9 +397,12 @@ func (w *ledgerDriver) ledgerSign(derivationPath []uint32, tx *types.Transaction |
|
|
|
|
if chainID == nil { |
|
|
|
|
signer = new(types.HomesteadSigner) |
|
|
|
|
} else { |
|
|
|
|
signer = types.NewEIP155Signer(chainID) |
|
|
|
|
signer = types.LatestSignerForChainID(chainID) |
|
|
|
|
// For non-legacy transactions, V is 0 or 1, no need to subtract here.
|
|
|
|
|
if tx.Type() == types.LegacyTxType { |
|
|
|
|
signature[64] -= byte(chainID.Uint64()*2 + 35) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
signed, err := tx.WithSignature(signer, signature) |
|
|
|
|
if err != nil { |
|
|
|
|
return common.Address{}, nil, err |
|
|
|
|