Skip to content

Commit 27b5e66

Browse files
committed
isHexa -> isHexaOrEmpty
So it's possible to ``` bitcore.crypto.Hash.sha256 (bitcore.util.buffer.hexToBuffer('')).toString ('hex'); ``` that correctly produce "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" instead of an assertion error. This small change is quite invasive anyway, so I think that before being merged, it must be well tested.
1 parent a90b8f5 commit 27b5e66

File tree

46 files changed

+77
-77
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+77
-77
lines changed

packages/bitcore-lib-cash/lib/address.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ Address.fromString = function(str, network, type) {
515515
*/
516516
Address.fromObject = function fromObject(obj) {
517517
$.checkState(
518-
JSUtil.isHexa(obj.hash),
518+
JSUtil.isHexaOrEmpty(obj.hash),
519519
'Unexpected hash property, "' + obj.hash + '", expected to be hex.'
520520
);
521521
var hashBuffer = Buffer.from(obj.hash, 'hex');

packages/bitcore-lib-cash/lib/hdprivatekey.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ HDPrivateKey.prototype._buildFromObject = function(arg) {
370370
parentFingerPrint: _.isNumber(arg.parentFingerPrint) ? BufferUtil.integerAsBuffer(arg.parentFingerPrint) : arg.parentFingerPrint,
371371
childIndex: _.isNumber(arg.childIndex) ? BufferUtil.integerAsBuffer(arg.childIndex) : arg.childIndex,
372372
chainCode: _.isString(arg.chainCode) ? Buffer.from(arg.chainCode,'hex') : arg.chainCode,
373-
privateKey: (_.isString(arg.privateKey) && JSUtil.isHexa(arg.privateKey)) ? Buffer.from(arg.privateKey,'hex') : arg.privateKey,
373+
privateKey: (_.isString(arg.privateKey) && JSUtil.isHexaOrEmpty(arg.privateKey)) ? Buffer.from(arg.privateKey,'hex') : arg.privateKey,
374374
checksum: arg.checksum ? (arg.checksum.length ? arg.checksum : BufferUtil.integerAsBuffer(arg.checksum)) : undefined
375375
};
376376
return this._buildFromBuffers(buffers);
@@ -405,7 +405,7 @@ HDPrivateKey.prototype._generateRandomly = function(network) {
405405
*/
406406
HDPrivateKey.fromSeed = function(hexa, network) {
407407
/* jshint maxcomplexity: 8 */
408-
if (JSUtil.isHexaString(hexa)) {
408+
if (JSUtil.isHexaOrEmptyString(hexa)) {
409409
hexa = Buffer.from(hexa,'hex');
410410
}
411411
if (!Buffer.isBuffer(hexa)) {

packages/bitcore-lib-cash/lib/privatekey.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ PrivateKey.prototype._classifyArguments = function(data, network) {
102102
info.bn = PrivateKey._getRandomBN();
103103
info.network = Networks.get(data);
104104
} else if (typeof(data) === 'string'){
105-
if (JSUtil.isHexa(data)) {
105+
if (JSUtil.isHexaOrEmpty(data)) {
106106
info.bn = new BN(Buffer.from(data, 'hex'));
107107
} else {
108108
info = PrivateKey._transformWIF(data, network);

packages/bitcore-lib-cash/lib/script/script.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ Script.fromHex = function(str) {
176176
};
177177

178178
Script.fromString = function(str) {
179-
if (JSUtil.isHexa(str) || str.length === 0) {
179+
if (JSUtil.isHexaOrEmpty(str) || str.length === 0) {
180180
return new Script(Buffer.from(str, 'hex'));
181181
}
182182
var script = new Script();

packages/bitcore-lib-cash/lib/transaction/input/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Input.fromObject = function(obj) {
6262

6363
Input.prototype._fromObject = function(params) {
6464
var prevTxId;
65-
if (_.isString(params.prevTxId) && JSUtil.isHexa(params.prevTxId)) {
65+
if (_.isString(params.prevTxId) && JSUtil.isHexaOrEmpty(params.prevTxId)) {
6666
prevTxId = Buffer.from(params.prevTxId, 'hex');
6767
} else {
6868
prevTxId = params.prevTxId;
@@ -131,7 +131,7 @@ Input.prototype.setScript = function(script) {
131131
this._script = Script.empty();
132132
this._script._isInput = true;
133133
this._scriptBuffer = this._script.toBuffer();
134-
} else if (JSUtil.isHexa(script)) {
134+
} else if (JSUtil.isHexaOrEmpty(script)) {
135135
// hex string script
136136
this._scriptBuffer = Buffer.from(script, 'hex');
137137
} else if (_.isString(script)) {

packages/bitcore-lib-cash/lib/transaction/output.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function Output(args) {
2222
this._scriptBuffer = args.script;
2323
} else {
2424
var script;
25-
if (_.isString(args.script) && JSUtil.isHexa(args.script)) {
25+
if (_.isString(args.script) && JSUtil.isHexaOrEmpty(args.script)) {
2626
script = Buffer.from(args.script, 'hex');
2727
} else {
2828
script = args.script;

packages/bitcore-lib-cash/lib/transaction/signature.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ TransactionSignature.prototype._checkObjectArgs = function(arg) {
5454
$.checkArgument(arg.prevTxId, 'prevTxId');
5555
$.checkState(arg.signature instanceof Signature ||
5656
BufferUtil.isBuffer(arg.signature) ||
57-
JSUtil.isHexa(arg.signature), 'signature must be a buffer or hexa value');
57+
JSUtil.isHexaOrEmpty(arg.signature), 'signature must be a buffer or hexa value');
5858
$.checkState(BufferUtil.isBuffer(arg.prevTxId) ||
59-
JSUtil.isHexa(arg.prevTxId), 'prevTxId must be a buffer or hexa value');
59+
JSUtil.isHexaOrEmpty(arg.prevTxId), 'prevTxId must be a buffer or hexa value');
6060
$.checkArgument(arg.sigtype, 'sigtype');
6161
$.checkState(_.isNumber(arg.sigtype), 'sigtype must be a number');
6262
};

packages/bitcore-lib-cash/lib/transaction/transaction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function Transaction(serialized) {
4444
if (serialized) {
4545
if (serialized instanceof Transaction) {
4646
return Transaction.shallowCopy(serialized);
47-
} else if (JSUtil.isHexa(serialized)) {
47+
} else if (JSUtil.isHexaOrEmpty(serialized)) {
4848
this.fromString(serialized);
4949
} else if (BufferUtil.isBuffer(serialized)) {
5050
this.fromBuffer(serialized);

packages/bitcore-lib-cash/lib/transaction/unspentoutput.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function UnspentOutput(data) {
3333
$.checkArgument(_.isObject(data), 'Must provide an object from where to extract data');
3434
var address = data.address ? new Address(data.address) : undefined;
3535
var txId = data.txid ? data.txid : data.txId;
36-
if (!txId || !JSUtil.isHexaString(txId) || txId.length > 64) {
36+
if (!txId || !JSUtil.isHexaOrEmptyString(txId) || txId.length > 64) {
3737
// TODO: Use the errors library
3838
throw new Error('Invalid TXID in object', data);
3939
}

packages/bitcore-lib-cash/lib/util/js.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ var _ = require('lodash');
55
/**
66
* Determines whether a string contains only hexadecimal values
77
*
8-
* @name JSUtil.isHexa
8+
* @name JSUtil.isHexaOrEmpty
99
* @param {string} value
10-
* @return {boolean} true if the string is the hexa representation of a number
10+
* @return {boolean} true if the string is the hexa representation of a number or is empty
1111
*/
12-
var isHexa = function isHexa(value) {
12+
var isHexaOrEmpty = function isHexaOrEmpty(value) {
1313
if (!_.isString(value)) {
1414
return false;
1515
}
16-
return /^[0-9a-fA-F]+$/.test(value);
16+
return /^[0-9a-fA-F]+$/.test(value) || ('' === value);
1717
};
1818

1919
/**
@@ -42,8 +42,8 @@ module.exports = {
4242
}
4343
return false;
4444
},
45-
isHexa: isHexa,
46-
isHexaString: isHexa,
45+
isHexaOrEmpty: isHexaOrEmpty,
46+
isHexaOrEmptyString: isHexaOrEmpty,
4747

4848
/**
4949
* Clone an array

0 commit comments

Comments
 (0)