From 87ba2abc9a2726ab18fd4f0de5a4ddb17ea77f6a Mon Sep 17 00:00:00 2001 From: Stefan Thomas Date: Sat, 22 Mar 2014 03:18:11 -0700 Subject: [PATCH] [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. --- src/js/ripple/serializedtypes.js | 2 -- src/js/ripple/transaction.js | 19 +++++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/js/ripple/serializedtypes.js b/src/js/ripple/serializedtypes.js index cdca9fe6..a79d3535 100644 --- a/src/js/ripple/serializedtypes.js +++ b/src/js/ripple/serializedtypes.js @@ -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'); } diff --git a/src/js/ripple/transaction.js b/src/js/ripple/transaction.js index da02827e..f50b74ab 100644 --- a/src/js/ripple/transaction.js +++ b/src/js/ripple/transaction.js @@ -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; };