pub fn sign(self, private_key: &K256PrivateKey, chain_id: u64) -> SignedTransaction {
        let adjust_v_value = matches!(
            self.transaction_type.map(|t| t.as_u64()),
            Some(LEGACY_TX_ID) | None
        );

        let encoded = self.encode(chain_id, None);
        let message_hash = H256(keccak256(encoded.as_ref()));

        let signature = if adjust_v_value {
            private_key.sign_web3(&message_hash, Some(chain_id))
        } else {
            private_key.sign_web3_message(&message_hash)
        };

        let signed = self.encode(chain_id, Some(&signature));
        let transaction_hash = keccak256(signed.as_ref()).into();

        SignedTransaction {
            message_hash,
            v: signature.v,
            r: signature.r,
            s: signature.s,
            raw_transaction: signed.into(),
            transaction_hash,
        }
    }
Sign and return a raw signed transaction.
core/lib/eth_signer/src/raw_ethereum_tx.rs