Skip to content

Commit bfb2e7c

Browse files
committed
Utilize signature module from ethereumjs-util
This replaces the use of the `sign` function in `ethereumjs-tx` with the `ecsign` function from the `ethereumjs-util` package as requested in We currently chose not to use EIP155 when generating the signatures. To add this, we would need to know the chain ID for the Ethereum chain we are signing the transaction. Activating EIP155 would make the generated signatures replay-resistant on other Ethereum blockchains.
1 parent f357171 commit bfb2e7c

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

app/sign.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ const handleSignEthereum = function(recoveryRequest, key, skipConfirm) {
225225
*/
226226
const signEthTx = function(recoveryRequest, key, skipConfirm, isToken) {
227227
const EthTx = require('ethereumjs-tx');
228+
const EthUtil = require('ethereumjs-util');
228229

229230
const txHex = getTransactionHexFromRequest(recoveryRequest);
230231
const transaction = new EthTx(txHex);
@@ -242,10 +243,20 @@ const signEthTx = function(recoveryRequest, key, skipConfirm, isToken) {
242243
outputs[0].amount = outputs[0].amount.div(TEN.pow(decimals));
243244
}
244245

245-
key = promptForConfirmationAndKey(recoveryRequest, outputs, skipConfirm, key);
246-
const signingKey = getBackupSigningKey(key, recoveryRequest.backupKey);
246+
// When generating signatures, we don't currently use EIP155 but this could
247+
// be activated if we wanted to. This would protect against replay attacks on other
248+
// blockchains, such as Ethereum Classic. To activate the EIP155, we would have to
249+
// know the chain ID of the Ethereum blockchains we are using as this value goes
250+
// into the V field when using EIP155.
251+
// cf. https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md
252+
const useEip155 = false;
247253

248-
transaction.sign(signingKey);
254+
key = promptForConfirmationAndKey(recoveryRequest, outputs, skipConfirm, key);
255+
const signingKey = Buffer.from(getBackupSigningKey(key, recoveryRequest.backupKey), "hex");
256+
const signature = EthUtil.ecsign(transaction.hash(useEip155), signingKey, transaction.chainId);
257+
transaction.v = signature.v; // Change this if activating EIP155
258+
transaction.r = signature.r;
259+
transaction.s = signature.s;
249260

250261
return transaction.serialize().toString('hex');
251262
};

0 commit comments

Comments
 (0)