From bde9b13b154b33d28e736366f15c36c999eff9b8 Mon Sep 17 00:00:00 2001 From: Wei Lu Date: Mon, 3 Mar 2014 11:27:19 +0800 Subject: [PATCH] remove isArray shim [closes #40] --- src/ecdsa.js | 4 ++-- src/eckey.js | 8 ++++---- src/script.js | 8 ++++---- src/transaction.js | 6 +++--- src/util.js | 7 ------- 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/ecdsa.js b/src/ecdsa.js index 1c1e3b8..54fda8b 100644 --- a/src/ecdsa.js +++ b/src/ecdsa.js @@ -75,7 +75,7 @@ var ECDSA = { verify: function (hash, sig, pubkey) { var r,s; - if (util.isArray(sig)) { + if (Array.isArray(sig)) { var obj = ECDSA.parseSig(sig); r = obj.r; s = obj.s; @@ -89,7 +89,7 @@ var ECDSA = { var Q; if (pubkey instanceof ECPointFp) { Q = pubkey; - } else if (util.isArray(pubkey)) { + } else if (Array.isArray(pubkey)) { Q = ECPointFp.decodeFrom(ecparams.getCurve(), pubkey); } else { throw new Error("Invalid format for pubkey value, must be byte array or ECPointFp"); diff --git a/src/eckey.js b/src/eckey.js index ddec4f0..f6b907f 100644 --- a/src/eckey.js +++ b/src/eckey.js @@ -32,7 +32,7 @@ ECKey.prototype.import = function (input,compressed,version) { this.priv = input instanceof ECKey ? input.priv : input instanceof BigInteger ? input.mod(ecparams.getN()) - : util.isArray(input) ? fromBin(input.slice(0,32)) + : Array.isArray(input) ? fromBin(input.slice(0,32)) : typeof input != "string" ? null : input.length == 44 ? fromBin(conv.base64ToBytes(input)) : input.length == 51 && input[0] == '5' ? fromBin(base58.checkDecode(input)) @@ -46,7 +46,7 @@ ECKey.prototype.import = function (input,compressed,version) { compressed !== undefined ? compressed : input instanceof ECKey ? input.compressed : input instanceof BigInteger ? false - : util.isArray(input) ? false + : Array.isArray(input) ? false : typeof input != "string" ? null : input.length == 44 ? false : input.length == 51 && input[0] == '5' ? false @@ -61,7 +61,7 @@ ECKey.prototype.import = function (input,compressed,version) { version !== undefined ? version : input instanceof ECKey ? input.version : input instanceof BigInteger ? mainnet - : util.isArray(input) ? mainnet + : Array.isArray(input) ? mainnet : typeof input != "string" ? null : input.length == 44 ? mainnet : input.length == 51 && input[0] == '5' ? mainnet @@ -148,7 +148,7 @@ ECPubKey.prototype.import = function(input,compressed,version) { : input instanceof ECKey ? ecparams.getG().multiply(input.priv) : input instanceof ECPubKey ? input.pub : typeof input == "string" ? decode(conv.hexToBytes(input)) - : util.isArray(input) ? decode(input) + : Array.isArray(input) ? decode(input) : ecparams.getG().multiply(ecdsa.getBigRandom(ecparams.getN())) this.compressed = diff --git a/src/script.js b/src/script.js index 5d04371..d630727 100644 --- a/src/script.js +++ b/src/script.js @@ -187,17 +187,17 @@ Script.prototype.toAddress = function() { */ Script.prototype.getInType = function() { if (this.chunks.length == 1 && - util.isArray(this.chunks[0])) { + Array.isArray(this.chunks[0])) { // Direct IP to IP transactions only have the signature in their scriptSig. // TODO: We could also check that the length of the data is correct. return 'Pubkey'; } else if (this.chunks.length == 2 && - util.isArray(this.chunks[0]) && - util.isArray(this.chunks[1])) { + Array.isArray(this.chunks[0]) && + Array.isArray(this.chunks[1])) { return 'Address'; } else if (this.chunks[0] == Opcode.map.OP_0 && this.chunks.slice(1).reduce(function(t, chunk, i) { - return t && util.isArray(chunk) && (chunk[0] == 48 || i == this.chunks.length - 1); + return t && Array.isArray(chunk) && (chunk[0] == 48 || i == this.chunks.length - 1); }, true)) { return 'Multisig'; } else { diff --git a/src/transaction.js b/src/transaction.js index 2eade6f..6f7f15b 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -18,7 +18,7 @@ var Transaction = function (doc) { this.block = null; if (doc) { - if (typeof doc == "string" || util.isArray(doc)) { + if (typeof doc == "string" || Array.isArray(doc)) { doc = Transaction.deserialize(doc) } if (doc.hash) this.hash = doc.hash; @@ -559,7 +559,7 @@ TransactionIn.prototype.clone = function () { var TransactionOut = function (data) { this.script = data.script instanceof Script ? data.script.clone() - : util.isArray(data.script) ? new Script(data.script) + : Array.isArray(data.script) ? new Script(data.script) : typeof data.script == "string" ? new Script(conv.hexToBytes(data.script)) : data.scriptPubKey ? Script.fromScriptSig(data.scriptPubKey) : data.address ? Script.createOutputScript(data.address) @@ -568,7 +568,7 @@ var TransactionOut = function (data) { if (this.script.buffer.length > 0) this.address = this.script.toAddress(); this.value = - util.isArray(data.value) ? util.bytesToNum(data.value) + Array.isArray(data.value) ? util.bytesToNum(data.value) : "string" == typeof data.value ? parseInt(data.value) : data.value instanceof BigInteger ? parseInt(data.value.toString()) : data.value; diff --git a/src/util.js b/src/util.js index 93cf123..8d64662 100644 --- a/src/util.js +++ b/src/util.js @@ -1,12 +1,5 @@ var Crypto = require('./crypto-js/crypto'); -/** - * Cross-browser compatibility version of Array.isArray. - */ -exports.isArray = Array.isArray || function(o) { - return Object.prototype.toString.call(o) === '[object Array]'; -} - /** * Create a byte array representing a number with the given length */