refactor.
This commit is contained in:
parent
3bb03c63fa
commit
f0cc2f8c6c
@ -382,7 +382,7 @@ HD.parsePath = function parsePath(path, max) {
|
||||
if (!/^\d+$/.test(index))
|
||||
throw new Error('Non-number path index.');
|
||||
|
||||
index = +index;
|
||||
index = parseInt(index, 10);
|
||||
|
||||
if (hardened)
|
||||
index += constants.hd.HARDENED;
|
||||
|
||||
@ -1329,7 +1329,7 @@ utils.nonce = function _nonce() {
|
||||
*/
|
||||
|
||||
utils.readU8 = function readU8(data, off) {
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
return data[off];
|
||||
};
|
||||
|
||||
@ -1341,7 +1341,7 @@ utils.readU8 = function readU8(data, off) {
|
||||
*/
|
||||
|
||||
utils.readU16 = function readU16(data, off) {
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
return data[off] | (data[off + 1] << 8);
|
||||
};
|
||||
|
||||
@ -1353,7 +1353,7 @@ utils.readU16 = function readU16(data, off) {
|
||||
*/
|
||||
|
||||
utils.readU16BE = function readU16BE(data, off) {
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
return (data[off] << 8) | data[off + 1];
|
||||
};
|
||||
|
||||
@ -1365,7 +1365,7 @@ utils.readU16BE = function readU16BE(data, off) {
|
||||
*/
|
||||
|
||||
utils.readU32 = function readU32(data, off) {
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
|
||||
return ((data[off])
|
||||
| (data[off + 1] << 8)
|
||||
@ -1381,7 +1381,7 @@ utils.readU32 = function readU32(data, off) {
|
||||
*/
|
||||
|
||||
utils.readU32BE = function readU32BE(data, off) {
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
|
||||
return (data[off] * 0x1000000)
|
||||
+ ((data[off + 1] << 16)
|
||||
@ -1398,7 +1398,7 @@ utils.readU32BE = function readU32BE(data, off) {
|
||||
|
||||
utils.readU64 = function readU64(data, off) {
|
||||
var num;
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
num = data.slice(off, off + 8);
|
||||
return new bn(num, 'le');
|
||||
};
|
||||
@ -1412,7 +1412,7 @@ utils.readU64 = function readU64(data, off) {
|
||||
|
||||
utils.readU64BE = function readU64BE(data, off) {
|
||||
var num;
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
num = data.slice(off, off + 8);
|
||||
return new bn(num, 'be');
|
||||
};
|
||||
@ -1426,7 +1426,7 @@ utils.readU64BE = function readU64BE(data, off) {
|
||||
|
||||
utils.read8 = function read8(data, off) {
|
||||
var num;
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
num = data[off];
|
||||
return !(num & 0x80) ? num : (0xff - num + 1) * -1;
|
||||
};
|
||||
@ -1440,7 +1440,7 @@ utils.read8 = function read8(data, off) {
|
||||
|
||||
utils.read16 = function read16(data, off) {
|
||||
var num;
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
num = data[off] | (data[off + 1] << 8);
|
||||
return (num & 0x8000) ? num | 0xffff0000 : num;
|
||||
};
|
||||
@ -1454,7 +1454,7 @@ utils.read16 = function read16(data, off) {
|
||||
|
||||
utils.read16BE = function read16BE(data, off) {
|
||||
var num;
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
num = data[off + 1] | (data[off] << 8);
|
||||
return (num & 0x8000) ? num | 0xffff0000 : num;
|
||||
};
|
||||
@ -1467,7 +1467,7 @@ utils.read16BE = function read16BE(data, off) {
|
||||
*/
|
||||
|
||||
utils.read32 = function read32(data, off) {
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
|
||||
return (data[off])
|
||||
| (data[off + 1] << 8)
|
||||
@ -1483,7 +1483,7 @@ utils.read32 = function read32(data, off) {
|
||||
*/
|
||||
|
||||
utils.read32BE = function read32BE(data, off) {
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
|
||||
return (data[off] << 24)
|
||||
| (data[off + 1] << 16)
|
||||
@ -1501,7 +1501,7 @@ utils.read32BE = function read32BE(data, off) {
|
||||
utils.read64 = function read64(data, off) {
|
||||
var num;
|
||||
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
|
||||
num = data.slice(off, off + 8);
|
||||
|
||||
@ -1521,7 +1521,7 @@ utils.read64 = function read64(data, off) {
|
||||
utils.read64BE = function read64BE(data, off) {
|
||||
var num;
|
||||
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
|
||||
num = data.slice(off, off + 8);
|
||||
|
||||
@ -1537,8 +1537,7 @@ utils.read64BE = function read64BE(data, off) {
|
||||
*/
|
||||
|
||||
utils.writeU8 = function writeU8(dst, num, off) {
|
||||
num = +num;
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
dst[off] = num & 0xff;
|
||||
return 1;
|
||||
};
|
||||
@ -1549,8 +1548,7 @@ utils.writeU8 = function writeU8(dst, num, off) {
|
||||
*/
|
||||
|
||||
utils.writeU16 = function writeU16(dst, num, off) {
|
||||
num = +num;
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
dst[off] = num & 0xff;
|
||||
dst[off + 1] = (num >>> 8) & 0xff;
|
||||
return 2;
|
||||
@ -1562,8 +1560,7 @@ utils.writeU16 = function writeU16(dst, num, off) {
|
||||
*/
|
||||
|
||||
utils.writeU16BE = function write16BE(dst, num, off) {
|
||||
num = +num;
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
dst[off] = (num >>> 8) & 0xff;
|
||||
dst[off + 1] = num & 0xff;
|
||||
return 2;
|
||||
@ -1575,8 +1572,7 @@ utils.writeU16BE = function write16BE(dst, num, off) {
|
||||
*/
|
||||
|
||||
utils.writeU32 = function writeU32(dst, num, off) {
|
||||
num = +num;
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
dst[off + 3] = (num >>> 24) & 0xff;
|
||||
dst[off + 2] = (num >>> 16) & 0xff;
|
||||
dst[off + 1] = (num >>> 8) & 0xff;
|
||||
@ -1590,8 +1586,7 @@ utils.writeU32 = function writeU32(dst, num, off) {
|
||||
*/
|
||||
|
||||
utils.writeU32BE = function writeU32BE(dst, num, off) {
|
||||
num = +num;
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
dst[off] = (num >>> 24) & 0xff;
|
||||
dst[off + 1] = (num >>> 16) & 0xff;
|
||||
dst[off + 2] = (num >>> 8) & 0xff;
|
||||
@ -1665,7 +1660,7 @@ utils.write64N = function write64N(dst, num, off, be) {
|
||||
|
||||
assert(typeof num === 'number');
|
||||
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
|
||||
negative = num < 0;
|
||||
|
||||
@ -1729,7 +1724,7 @@ utils.write64NBE = function write64NBE(dst, num, off) {
|
||||
utils.readU64N = function readU64N(data, off, force53, be) {
|
||||
var hi, lo;
|
||||
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
|
||||
if (be) {
|
||||
hi = utils.readU32(data, off);
|
||||
@ -1772,7 +1767,7 @@ utils.readU64NBE = function readU64NBE(data, off, force53) {
|
||||
utils.read64N = function read64N(data, off, force53, be) {
|
||||
var hi, lo;
|
||||
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
|
||||
if (be) {
|
||||
hi = utils.readU32(data, off);
|
||||
@ -1872,8 +1867,7 @@ utils.read53BE = function read53BE(data, off) {
|
||||
*/
|
||||
|
||||
utils.write8 = function write8(dst, num, off) {
|
||||
num = +num;
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
dst[off] = num & 0xff;
|
||||
return 1;
|
||||
};
|
||||
@ -1887,8 +1881,7 @@ utils.write8 = function write8(dst, num, off) {
|
||||
*/
|
||||
|
||||
utils.write16 = function write16(dst, num, off) {
|
||||
num = +num;
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
dst[off] = num & 0xff;
|
||||
dst[off + 1] = (num >>> 8) & 0xff;
|
||||
return 2;
|
||||
@ -1903,8 +1896,7 @@ utils.write16 = function write16(dst, num, off) {
|
||||
*/
|
||||
|
||||
utils.write16BE = function write16BE(dst, num, off) {
|
||||
num = +num;
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
dst[off] = (num >>> 8) & 0xff;
|
||||
dst[off + 1] = num & 0xff;
|
||||
return 2;
|
||||
@ -1919,8 +1911,7 @@ utils.write16BE = function write16BE(dst, num, off) {
|
||||
*/
|
||||
|
||||
utils.write32 = function write32(dst, num, off) {
|
||||
num = +num;
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
dst[off] = num & 0xff;
|
||||
dst[off + 1] = (num >>> 8) & 0xff;
|
||||
dst[off + 2] = (num >>> 16) & 0xff;
|
||||
@ -1937,8 +1928,7 @@ utils.write32 = function write32(dst, num, off) {
|
||||
*/
|
||||
|
||||
utils.write32BE = function write32BE(dst, num, off) {
|
||||
num = +num;
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
dst[off] = (num >>> 24) & 0xff;
|
||||
dst[off + 1] = (num >>> 16) & 0xff;
|
||||
dst[off + 2] = (num >>> 8) & 0xff;
|
||||
@ -1960,7 +1950,7 @@ utils.write64 = function write64(dst, num, off) {
|
||||
if (typeof num === 'number')
|
||||
return utils.write64N(dst, num, off);
|
||||
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
|
||||
if (num.isNeg())
|
||||
num = num.neg().notn(64).addn(1);
|
||||
@ -1990,7 +1980,7 @@ utils.write64BE = function write64BE(dst, num, off) {
|
||||
if (typeof num === 'number')
|
||||
return utils.write64NBE(dst, num, off);
|
||||
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
|
||||
if (num.isNeg())
|
||||
num = num.neg().notn(64).addn(1);
|
||||
@ -2017,7 +2007,7 @@ utils.write64BE = function write64BE(dst, num, off) {
|
||||
utils.readVarint = function readVarint(data, off, big) {
|
||||
var r, bytes;
|
||||
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
|
||||
assert(off < data.length);
|
||||
|
||||
@ -2061,7 +2051,7 @@ utils.readVarint = function readVarint(data, off, big) {
|
||||
*/
|
||||
|
||||
utils.writeVarint = function writeVarint(dst, num, off) {
|
||||
off = off >>> 0;
|
||||
off >>>= 0;
|
||||
|
||||
if (bn.isBN(num)) {
|
||||
if (num.bitLength() > 32) {
|
||||
@ -2072,8 +2062,6 @@ utils.writeVarint = function writeVarint(dst, num, off) {
|
||||
num = num.toNumber();
|
||||
}
|
||||
|
||||
num = +num;
|
||||
|
||||
if (num < 0xfd) {
|
||||
dst[off] = num & 0xff;
|
||||
return 1;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user