-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Return r, s, and v without leading 0's #1288
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,14 +42,14 @@ var isNot = function(value) { | |
}; | ||
|
||
var trimLeadingZero = function (hex) { | ||
while (hex && hex.startsWith('0x00')) { | ||
hex = '0x' + hex.slice(4); | ||
while (hex && hex.startsWith('0x0')) { | ||
hex = '0x' + hex.slice(3); | ||
} | ||
return hex; | ||
}; | ||
|
||
var makeEven = function (hex) { | ||
if(hex % 2 === 1) { | ||
if(hex.length % 2 === 1) { | ||
hex = hex.replace('0x', '0x0'); | ||
} | ||
return hex; | ||
|
@@ -165,17 +165,17 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca | |
|
||
var rawTx = RLP.decode(rlpEncoded).slice(0, 6).concat(Account.decodeSignature(signature)); | ||
|
||
rawTx[7] = trimLeadingZero(rawTx[7]); | ||
rawTx[8] = trimLeadingZero(rawTx[8]); | ||
rawTx[7] = makeEven(trimLeadingZero(rawTx[7])); | ||
rawTx[8] = makeEven(trimLeadingZero(rawTx[8])); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And are you sure passing a modified value into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean It looks like it dynamically calculates the length, so I don't see any problems: https://github.com/MaiaVictor/eth-lib/blob/master/lib/rlp.js#L27 In fact, I believe leaving out 0 bytes at the beginning of an int in the RLP-encoded data is a more standard approach. (not sure if it's required though) |
||
|
||
var rawTransaction = RLP.encode(rawTx); | ||
|
||
var values = RLP.decode(rawTransaction); | ||
var result = { | ||
messageHash: hash, | ||
v: makeEven(values[6]), | ||
r: makeEven(values[7]), | ||
s: makeEven(values[8]), | ||
v: trimLeadingZero(values[6]), | ||
r: trimLeadingZero(values[7]), | ||
s: trimLeadingZero(values[8]), | ||
rawTransaction: rawTransaction | ||
}; | ||
if (_.isFunction(callback)) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with this is what if the rs, value is
0x00001234
Then a even number is made uneven