-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
316 changed files
with
14,796 additions
and
11,622 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
const find = require('findit'); // eslint-disable-line | ||
const fs = require('fs'); | ||
|
||
const finder = find('./node_modules/@liskhq'); | ||
const fix = "console.log('monkey patch');"; | ||
const buffer = './node_modules/node-libs-browser/node_modules/buffer/index.js'; | ||
const fix = './config/readBigUInt64BE.js'; | ||
|
||
finder.on('file', (file) => { | ||
if (file.match(/\.js/)) { | ||
fs.readFile(file, 'utf8', (err, data) => { | ||
fs.readFile(buffer, (bufferErr, bufferCode) => { | ||
if (bufferErr) throw bufferErr; | ||
|
||
fs.readFile(fix, (fixErr, fixCode) => { | ||
if (fixErr) throw fixErr; | ||
|
||
fs.writeFile(buffer, bufferCode + fixCode, 'utf8', (err) => { | ||
if (err) throw err; | ||
let newData = ''; | ||
if (data.match(/process\.env\.NACL_FAST\s=\s'disable';/)) { | ||
newData = data | ||
.replace(/process.env.NACL_FAST = 'disable';/, fix); | ||
/* eslint-disable-next-line no-console */ | ||
console.log(`Fix the LiskSDK bug in ${file} `); | ||
fs.writeFileSync(file, newData, { encoding: 'utf8', flag: 'w' }); | ||
} | ||
|
||
// eslint-disable-next-line no-console | ||
console.log('Successfully added readBigUInt64BE to Buffer.'); | ||
}); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* eslint-disable */ | ||
Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE (offset = 0) { | ||
validateNumber(offset, 'offset') | ||
const first = this[offset] | ||
const last = this[offset + 7] | ||
if (first === undefined || last === undefined) { | ||
boundsError(offset, this.length - 8) | ||
} | ||
|
||
const hi = first * 2 ** 24 + | ||
this[++offset] * 2 ** 16 + | ||
this[++offset] * 2 ** 8 + | ||
this[++offset] | ||
|
||
const lo = this[++offset] * 2 ** 24 + | ||
this[++offset] * 2 ** 16 + | ||
this[++offset] * 2 ** 8 + | ||
last | ||
|
||
return (BigInt(hi) << 32n) + BigInt(lo) | ||
}) | ||
|
||
Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE (value, offset = 0) { | ||
return wrtBigUInt64BE(this, value, offset, 0n, 0xffffffffffffffffn) | ||
}) | ||
|
||
function wrtBigUInt64BE (buf, value, offset, min, max) { | ||
checkIntBI(value, min, max, buf, offset, 7) | ||
|
||
let lo = Number(value & 0xffffffffn) | ||
buf[offset + 7] = lo | ||
lo = lo >> 8 | ||
buf[offset + 6] = lo | ||
lo = lo >> 8 | ||
buf[offset + 5] = lo | ||
lo = lo >> 8 | ||
buf[offset + 4] = lo | ||
let hi = Number(value >> 32n & 0xffffffffn) | ||
buf[offset + 3] = hi | ||
hi = hi >> 8 | ||
buf[offset + 2] = hi | ||
hi = hi >> 8 | ||
buf[offset + 1] = hi | ||
hi = hi >> 8 | ||
buf[offset] = hi | ||
return offset + 8 | ||
} | ||
|
||
function checkBounds (buf, offset, byteLength) { | ||
validateNumber(offset, 'offset') | ||
if (buf[offset] === undefined || buf[offset + byteLength] === undefined) { | ||
boundsError(offset, buf.length - (byteLength + 1)) | ||
} | ||
} | ||
|
||
function checkIntBI (value, min, max, buf, offset, byteLength) { | ||
if (value > max || value < min) { | ||
const n = typeof min === 'bigint' ? 'n' : '' | ||
let range | ||
if (byteLength > 3) { | ||
if (min === 0 || min === 0n) { | ||
range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}` | ||
} else { | ||
range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` + | ||
`${(byteLength + 1) * 8 - 1}${n}` | ||
} | ||
} else { | ||
range = `>= ${min}${n} and <= ${max}${n}` | ||
} | ||
throw new errors.ERR_OUT_OF_RANGE('value', range, value) | ||
} | ||
checkBounds(buf, offset, byteLength) | ||
} | ||
|
||
function defineBigIntMethod (fn) { | ||
return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn | ||
} | ||
|
||
function BufferBigIntNotDefined () { | ||
throw new Error('BigInt not supported') | ||
} | ||
|
||
function validateNumber (value, name) { | ||
if (typeof value !== 'number') { | ||
throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value) | ||
} | ||
} | ||
|
||
function boundsError (value, length, type) { | ||
if (Math.floor(value) !== value) { | ||
validateNumber(value, type) | ||
throw new errors.ERR_OUT_OF_RANGE(type || 'offset', 'an integer', value) | ||
} | ||
|
||
if (length < 0) { | ||
throw new errors.ERR_BUFFER_OUT_OF_BOUNDS() | ||
} | ||
|
||
throw new errors.ERR_OUT_OF_RANGE(type || 'offset', | ||
`>= ${type ? 1 : 0} and <= ${length}`, | ||
value) | ||
} | ||
|
||
Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE (value, offset = 0) { | ||
return wrtBigUInt64BE(this, value, offset, -0x8000000000000000n, 0x7fffffffffffffffn) | ||
}) | ||
|
||
Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE (offset = 0) { | ||
validateNumber(offset, 'offset') | ||
const first = this[offset] | ||
const last = this[offset + 7] | ||
if (first === undefined || last === undefined) { | ||
boundsError(offset, this.length - 8) | ||
} | ||
|
||
const val = (first << 24) + // Overflow | ||
this[++offset] * 2 ** 16 + | ||
this[++offset] * 2 ** 8 + | ||
this[++offset] | ||
|
||
return (BigInt(val) << 32n) + | ||
BigInt(this[++offset] * 2 ** 24 + | ||
this[++offset] * 2 ** 16 + | ||
this[++offset] * 2 ** 8 + | ||
last) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.