[BUG] Undo previous commit making append_byte_array too loose.

This commit introduces an alternative way of setting the canonical signature
flag, without compromising the strictness of append_byte_array input
sanitizing.
This commit is contained in:
Stefan Thomas
2014-03-22 03:18:11 -07:00
parent 716fd0b938
commit 87ba2abc9a
2 changed files with 13 additions and 8 deletions

View File

@@ -120,8 +120,6 @@ SerializedType.prototype.parse_varint = function (so) {
* The result is appended to the serialized object ('so').
*/
function append_byte_array(so, val, bytes) {
val = val >>> 0;
if (!isNumber(val)) {
throw new Error('Value is not a number');
}

View File

@@ -62,9 +62,7 @@ function Transaction(remote) {
this.remote = remote;
// Transaction data
this.tx_json = {
Flags: Transaction.defaultFlags
};
this.tx_json = { Flags: 0 };
this._secret = void(0);
this._build_path = false;
@@ -75,11 +73,13 @@ function Transaction(remote) {
// Index at which transaction was submitted
this.submitIndex = void(0);
this.canonical = true;
// We aren't clever enough to eschew preventative measures so we keep an array
// of all submitted transactionIDs (which can change due to load_factor
// effecting the Fee amount). This should be populated with a transactionID
// any time it goes on the network
this.submittedIDs = [ ]
this.submittedIDs = [ ];
function finalize(message) {
if (!self.finalized) {
@@ -151,8 +151,6 @@ Transaction.flags = {
}
};
Transaction.defaultFlags = 0 | Transaction.flags.Universal.FullyCanonicalSig;
Transaction.formats = require('./binformat').tx;
Transaction.prototype.consts = {
@@ -282,6 +280,15 @@ Transaction.prototype.complete = function() {
this.tx_json.SigningPubKey = key.to_hex_pub();
}
// Set canonical flag - this enables canonicalized signature checking
if (this.canonical) {
this.tx_json.Flags |= Transaction.flags.Universal.FullyCanonicalSig;
// JavaScript converts operands to 32-bit signed ints before doing bitwise
// operations. We need to convert it back to an unsigned int.
this.tx_json.Flags = this.tx_json.Flags >>> 0;
}
return this.tx_json;
};