remove isArray shim

[closes #40]
This commit is contained in:
Wei Lu 2014-03-03 11:27:19 +08:00
parent a8d9708caa
commit bde9b13b15
5 changed files with 13 additions and 20 deletions

View file

@ -75,7 +75,7 @@ var ECDSA = {
verify: function (hash, sig, pubkey) { verify: function (hash, sig, pubkey) {
var r,s; var r,s;
if (util.isArray(sig)) { if (Array.isArray(sig)) {
var obj = ECDSA.parseSig(sig); var obj = ECDSA.parseSig(sig);
r = obj.r; r = obj.r;
s = obj.s; s = obj.s;
@ -89,7 +89,7 @@ var ECDSA = {
var Q; var Q;
if (pubkey instanceof ECPointFp) { if (pubkey instanceof ECPointFp) {
Q = pubkey; Q = pubkey;
} else if (util.isArray(pubkey)) { } else if (Array.isArray(pubkey)) {
Q = ECPointFp.decodeFrom(ecparams.getCurve(), pubkey); Q = ECPointFp.decodeFrom(ecparams.getCurve(), pubkey);
} else { } else {
throw new Error("Invalid format for pubkey value, must be byte array or ECPointFp"); throw new Error("Invalid format for pubkey value, must be byte array or ECPointFp");

View file

@ -32,7 +32,7 @@ ECKey.prototype.import = function (input,compressed,version) {
this.priv = this.priv =
input instanceof ECKey ? input.priv input instanceof ECKey ? input.priv
: input instanceof BigInteger ? input.mod(ecparams.getN()) : 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 : typeof input != "string" ? null
: input.length == 44 ? fromBin(conv.base64ToBytes(input)) : input.length == 44 ? fromBin(conv.base64ToBytes(input))
: input.length == 51 && input[0] == '5' ? fromBin(base58.checkDecode(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 compressed !== undefined ? compressed
: input instanceof ECKey ? input.compressed : input instanceof ECKey ? input.compressed
: input instanceof BigInteger ? false : input instanceof BigInteger ? false
: util.isArray(input) ? false : Array.isArray(input) ? false
: typeof input != "string" ? null : typeof input != "string" ? null
: input.length == 44 ? false : input.length == 44 ? false
: input.length == 51 && input[0] == '5' ? false : input.length == 51 && input[0] == '5' ? false
@ -61,7 +61,7 @@ ECKey.prototype.import = function (input,compressed,version) {
version !== undefined ? version version !== undefined ? version
: input instanceof ECKey ? input.version : input instanceof ECKey ? input.version
: input instanceof BigInteger ? mainnet : input instanceof BigInteger ? mainnet
: util.isArray(input) ? mainnet : Array.isArray(input) ? mainnet
: typeof input != "string" ? null : typeof input != "string" ? null
: input.length == 44 ? mainnet : input.length == 44 ? mainnet
: input.length == 51 && input[0] == '5' ? 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 ECKey ? ecparams.getG().multiply(input.priv)
: input instanceof ECPubKey ? input.pub : input instanceof ECPubKey ? input.pub
: typeof input == "string" ? decode(conv.hexToBytes(input)) : typeof input == "string" ? decode(conv.hexToBytes(input))
: util.isArray(input) ? decode(input) : Array.isArray(input) ? decode(input)
: ecparams.getG().multiply(ecdsa.getBigRandom(ecparams.getN())) : ecparams.getG().multiply(ecdsa.getBigRandom(ecparams.getN()))
this.compressed = this.compressed =

View file

@ -187,17 +187,17 @@ Script.prototype.toAddress = function() {
*/ */
Script.prototype.getInType = function() { Script.prototype.getInType = function() {
if (this.chunks.length == 1 && 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. // 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. // TODO: We could also check that the length of the data is correct.
return 'Pubkey'; return 'Pubkey';
} else if (this.chunks.length == 2 && } else if (this.chunks.length == 2 &&
util.isArray(this.chunks[0]) && Array.isArray(this.chunks[0]) &&
util.isArray(this.chunks[1])) { Array.isArray(this.chunks[1])) {
return 'Address'; return 'Address';
} else if (this.chunks[0] == Opcode.map.OP_0 && } else if (this.chunks[0] == Opcode.map.OP_0 &&
this.chunks.slice(1).reduce(function(t, chunk, i) { 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)) { }, true)) {
return 'Multisig'; return 'Multisig';
} else { } else {

View file

@ -18,7 +18,7 @@ var Transaction = function (doc) {
this.block = null; this.block = null;
if (doc) { if (doc) {
if (typeof doc == "string" || util.isArray(doc)) { if (typeof doc == "string" || Array.isArray(doc)) {
doc = Transaction.deserialize(doc) doc = Transaction.deserialize(doc)
} }
if (doc.hash) this.hash = doc.hash; if (doc.hash) this.hash = doc.hash;
@ -559,7 +559,7 @@ TransactionIn.prototype.clone = function () {
var TransactionOut = function (data) { var TransactionOut = function (data) {
this.script = this.script =
data.script instanceof Script ? data.script.clone() 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)) : typeof data.script == "string" ? new Script(conv.hexToBytes(data.script))
: data.scriptPubKey ? Script.fromScriptSig(data.scriptPubKey) : data.scriptPubKey ? Script.fromScriptSig(data.scriptPubKey)
: data.address ? Script.createOutputScript(data.address) : 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(); if (this.script.buffer.length > 0) this.address = this.script.toAddress();
this.value = 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) : "string" == typeof data.value ? parseInt(data.value)
: data.value instanceof BigInteger ? parseInt(data.value.toString()) : data.value instanceof BigInteger ? parseInt(data.value.toString())
: data.value; : data.value;

View file

@ -1,12 +1,5 @@
var Crypto = require('./crypto-js/crypto'); 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 * Create a byte array representing a number with the given length
*/ */