From 18efa5d74251222cbccd6eae33063de2bd46261e Mon Sep 17 00:00:00 2001 From: wltsmrz Date: Wed, 23 Apr 2014 03:56:36 -0700 Subject: [PATCH] Emit an error on invalid secret, cleanup --- src/js/ripple/transaction.js | 55 ++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/src/js/ripple/transaction.js b/src/js/ripple/transaction.js index 2d74612d..9cf5537e 100644 --- a/src/js/ripple/transaction.js +++ b/src/js/ripple/transaction.js @@ -153,7 +153,7 @@ Transaction.set_clear_flags = { asfRequireDest: 1, asfRequireAuth: 2, asfDisallowXRP: 3, - asfDisableMaster: 4 + asfDisableMaster: 4 } }; @@ -295,9 +295,13 @@ Transaction.prototype.complete = function() { } if (typeof this.tx_json.SigningPubKey === 'undefined') { - var seed = Seed.from_json(this._secret); - var key = seed.get_key(this.tx_json.Account); - this.tx_json.SigningPubKey = key.to_hex_pub(); + try { + var seed = Seed.from_json(this._secret); + var key = seed.get_key(this.tx_json.Account); + this.tx_json.SigningPubKey = key.to_hex_pub(); + } catch(e) { + return this.emit('error', new RippleError('tejSecretInvalid', 'Invalid secret')); + } } // Set canonical flag - this enables canonicalized signature checking @@ -512,20 +516,16 @@ Transaction.prototype.transferRate = function(rate) { Transaction.prototype.setFlags = function(flags) { if (!flags) return this; - var transaction_flags = Transaction.flags[this.tx_json.TransactionType]; var flag_set = Array.isArray(flags) ? flags : Array.prototype.slice.call(arguments); - - // We plan to not define this field on new Transaction. - if (this.tx_json.Flags === void(0)) { - this.tx_json.Flags = 0; - } + var transaction_flags = Transaction.flags[this.tx_json.TransactionType] || { }; for (var i=0, l=flag_set.length; i