Merge pull request #904 from braydonf/bug/safari-address
Fixed bugs in Safari and IE. Closes #837 and #784
This commit is contained in:
commit
cfecfa2d8d
@ -100,15 +100,17 @@ function Address(data, network, type) {
|
|||||||
* @returns {Object} An "info" object with "type", "network", and "hashBuffer"
|
* @returns {Object} An "info" object with "type", "network", and "hashBuffer"
|
||||||
*/
|
*/
|
||||||
Address.prototype._classifyArguments = function(data, network, type) {
|
Address.prototype._classifyArguments = function(data, network, type) {
|
||||||
|
var PublicKey = require('./publickey');
|
||||||
|
var Script = require('./script');
|
||||||
/* jshint maxcomplexity: 10 */
|
/* jshint maxcomplexity: 10 */
|
||||||
// transform and validate input data
|
// transform and validate input data
|
||||||
if ((data instanceof Buffer || data instanceof Uint8Array) && data.length === 20) {
|
if ((data instanceof Buffer || data instanceof Uint8Array) && data.length === 20) {
|
||||||
return Address._transformHash(data);
|
return Address._transformHash(data);
|
||||||
} else if ((data instanceof Buffer || data instanceof Uint8Array) && data.length === 21) {
|
} else if ((data instanceof Buffer || data instanceof Uint8Array) && data.length === 21) {
|
||||||
return Address._transformBuffer(data, network, type);
|
return Address._transformBuffer(data, network, type);
|
||||||
} else if (data.constructor && (data.constructor.name && data.constructor.name === 'PublicKey')) {
|
} else if (data instanceof PublicKey) {
|
||||||
return Address._transformPublicKey(data);
|
return Address._transformPublicKey(data);
|
||||||
} else if (data.constructor && (data.constructor.name && data.constructor.name === 'Script')) {
|
} else if (data instanceof Script) {
|
||||||
return Address._transformScript(data, network);
|
return Address._transformScript(data, network);
|
||||||
} else if (typeof(data) === 'string') {
|
} else if (typeof(data) === 'string') {
|
||||||
return Address._transformString(data, network, type);
|
return Address._transformString(data, network, type);
|
||||||
@ -213,8 +215,9 @@ Address._transformBuffer = function(buffer, network, type){
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
Address._transformPublicKey = function(pubkey){
|
Address._transformPublicKey = function(pubkey){
|
||||||
|
var PublicKey = require('./publickey');
|
||||||
var info = {};
|
var info = {};
|
||||||
if (!pubkey.constructor || (pubkey.constructor.name && pubkey.constructor.name !== 'PublicKey')) {
|
if (!(pubkey instanceof PublicKey)) {
|
||||||
throw new TypeError('Address must be an instance of PublicKey.');
|
throw new TypeError('Address must be an instance of PublicKey.');
|
||||||
}
|
}
|
||||||
info.hashBuffer = Hash.sha256ripemd160(pubkey.toBuffer());
|
info.hashBuffer = Hash.sha256ripemd160(pubkey.toBuffer());
|
||||||
@ -230,8 +233,9 @@ Address._transformPublicKey = function(pubkey){
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
Address._transformScript = function(script, network){
|
Address._transformScript = function(script, network){
|
||||||
|
var Script = require('./script');
|
||||||
var info = {};
|
var info = {};
|
||||||
if (!script.constructor || (script.constructor.name && script.constructor.name !== 'Script')) {
|
if (!(script instanceof Script)) {
|
||||||
throw new TypeError('Address must be an instance of Script.');
|
throw new TypeError('Address must be an instance of Script.');
|
||||||
}
|
}
|
||||||
if (script.isScriptHashOut()) {
|
if (script.isScriptHashOut()) {
|
||||||
|
|||||||
@ -177,7 +177,6 @@ Script.fromString = function(str) {
|
|||||||
|
|
||||||
Script.prototype.toString = function() {
|
Script.prototype.toString = function() {
|
||||||
var str = '';
|
var str = '';
|
||||||
|
|
||||||
for (var i = 0; i < this.chunks.length; i++) {
|
for (var i = 0; i < this.chunks.length; i++) {
|
||||||
var chunk = this.chunks[i];
|
var chunk = this.chunks[i];
|
||||||
var opcodenum = chunk.opcodenum;
|
var opcodenum = chunk.opcodenum;
|
||||||
@ -459,7 +458,7 @@ Script.prototype._addByType = function(obj, prepend) {
|
|||||||
this._addOpcode(obj, prepend);
|
this._addOpcode(obj, prepend);
|
||||||
} else if (typeof obj === 'number') {
|
} else if (typeof obj === 'number') {
|
||||||
this._addOpcode(obj, prepend);
|
this._addOpcode(obj, prepend);
|
||||||
} else if (obj.constructor && obj.constructor.name && obj.constructor.name === 'Opcode') {
|
} else if (obj instanceof Opcode) {
|
||||||
this._addOpcode(obj, prepend);
|
this._addOpcode(obj, prepend);
|
||||||
} else if (BufferUtil.isBuffer(obj)) {
|
} else if (BufferUtil.isBuffer(obj)) {
|
||||||
this._addBuffer(obj, prepend);
|
this._addBuffer(obj, prepend);
|
||||||
@ -484,7 +483,7 @@ Script.prototype._addOpcode = function(opcode, prepend) {
|
|||||||
var op;
|
var op;
|
||||||
if (typeof opcode === 'number') {
|
if (typeof opcode === 'number') {
|
||||||
op = opcode;
|
op = opcode;
|
||||||
} else if (opcode.constructor && opcode.constructor.name && opcode.constructor.name === 'Opcode') {
|
} else if (opcode instanceof Opcode) {
|
||||||
op = opcode.toNumber();
|
op = opcode.toNumber();
|
||||||
} else {
|
} else {
|
||||||
op = Opcode(opcode).toNumber();
|
op = Opcode(opcode).toNumber();
|
||||||
|
|||||||
@ -83,7 +83,6 @@ Output.prototype.setScript = function(script) {
|
|||||||
this._scriptBuffer = script;
|
this._scriptBuffer = script;
|
||||||
this._script = null;
|
this._script = null;
|
||||||
} else {
|
} else {
|
||||||
console.log(script);
|
|
||||||
throw new TypeError('Unrecognized Argument');
|
throw new TypeError('Unrecognized Argument');
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@ -656,11 +656,11 @@ Transaction.prototype.verify = function() {
|
|||||||
var valueoutbn = BN(0);
|
var valueoutbn = BN(0);
|
||||||
for (var i = 0; i < this.outputs.length; i++) {
|
for (var i = 0; i < this.outputs.length; i++) {
|
||||||
var txout = this.outputs[i];
|
var txout = this.outputs[i];
|
||||||
var valuebn = BN(txout.satoshis.toString(16));
|
var valuebn = txout._satoshis;
|
||||||
if (valuebn.lt(0)) {
|
if (valuebn.lt(0)) {
|
||||||
return 'transaction txout ' + i + ' negative';
|
return 'transaction txout ' + i + ' negative';
|
||||||
}
|
}
|
||||||
if (valuebn.gt(Transaction.MAX_MONEY)) {
|
if (valuebn.gt(BN(Transaction.MAX_MONEY, 10))) {
|
||||||
return 'transaction txout ' + i + ' greater than MAX_MONEY';
|
return 'transaction txout ' + i + ' greater than MAX_MONEY';
|
||||||
}
|
}
|
||||||
valueoutbn = valueoutbn.add(valuebn);
|
valueoutbn = valueoutbn.add(valuebn);
|
||||||
|
|||||||
@ -8,6 +8,8 @@ var HDPrivateKey = bitcore.HDPrivateKey;
|
|||||||
var xprivkey = 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi';
|
var xprivkey = 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi';
|
||||||
|
|
||||||
describe('HDKey cache', function() {
|
describe('HDKey cache', function() {
|
||||||
|
this.timeout(10000);
|
||||||
|
|
||||||
/* jshint unused: false */
|
/* jshint unused: false */
|
||||||
var cache = bitcore._HDKeyCache;
|
var cache = bitcore._HDKeyCache;
|
||||||
var master = new HDPrivateKey(xprivkey);
|
var master = new HDPrivateKey(xprivkey);
|
||||||
|
|||||||
@ -1 +1,2 @@
|
|||||||
--recursive
|
--recursive
|
||||||
|
--timeout 5000
|
||||||
|
|||||||
@ -279,6 +279,8 @@ var bitpayRequest = new Buffer(''
|
|||||||
|
|
||||||
describe('PaymentProtocol', function() {
|
describe('PaymentProtocol', function() {
|
||||||
|
|
||||||
|
this.timeout(15000);
|
||||||
|
|
||||||
it('should be able to create class', function() {
|
it('should be able to create class', function() {
|
||||||
should.exist(PaymentProtocol);
|
should.exist(PaymentProtocol);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -259,7 +259,8 @@ describe('Interpreter', function() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
c++;
|
c++;
|
||||||
it('should pass tx_' + (expected ? '' : 'in') + 'valid vector ' + c, function() {
|
var cc = c; //copy to local
|
||||||
|
it('should pass tx_' + (expected ? '' : 'in') + 'valid vector ' + cc, function() {
|
||||||
var inputs = vector[0];
|
var inputs = vector[0];
|
||||||
var txhex = vector[1];
|
var txhex = vector[1];
|
||||||
var flags = getFlags(vector[2]);
|
var flags = getFlags(vector[2]);
|
||||||
@ -291,9 +292,10 @@ describe('Interpreter', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
var txVerified = tx.verify();
|
var txVerified = tx.verify();
|
||||||
txVerified = _.isBoolean(txVerified);
|
txVerified = (txVerified === true) ? true : false;
|
||||||
allInputsVerified = allInputsVerified && txVerified;
|
allInputsVerified = allInputsVerified && txVerified;
|
||||||
allInputsVerified.should.equal(expected);
|
allInputsVerified.should.equal(expected);
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -84,6 +84,7 @@ describe('Transaction', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('transaction creation test vector', function() {
|
describe('transaction creation test vector', function() {
|
||||||
|
this.timeout(5000);
|
||||||
var index = 0;
|
var index = 0;
|
||||||
transactionVector.forEach(function(vector) {
|
transactionVector.forEach(function(vector) {
|
||||||
index++;
|
index++;
|
||||||
|
|||||||
@ -52,7 +52,8 @@ describe('preconditions', function() {
|
|||||||
$.checkArgumentType(1, PrivateKey);
|
$.checkArgumentType(1, PrivateKey);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = e;
|
error = e;
|
||||||
e.message.should.equal('Invalid Argument for (unknown name), expected PrivateKey but got number');
|
var fail = !(~e.message.indexOf('Invalid Argument for (unknown name)'));
|
||||||
|
fail.should.equal(false);
|
||||||
}
|
}
|
||||||
should.exist(error);
|
should.exist(error);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user