@eth-optimism/core-utils
Advanced tools
Comparing version 0.0.1-alpha.17 to 0.0.1-alpha.18
@@ -39,5 +39,6 @@ "use strict"; | ||
const numberToBuffer = (num, numBytes = 4, bufferBytes = 32, bigEndian = true) => { | ||
const buf = Buffer.alloc(bufferBytes); | ||
const minBytes = Math.max(bufferBytes, numBytes); | ||
const buf = Buffer.alloc(minBytes); | ||
if (bigEndian) { | ||
buf.writeIntBE(num, bufferBytes - numBytes, numBytes); | ||
buf.writeIntBE(num, minBytes - numBytes, numBytes); | ||
} | ||
@@ -49,2 +50,18 @@ else { | ||
}; | ||
const numberToBufferPacked = (num, minLength = 1) => { | ||
const buf = Buffer.alloc(4); | ||
buf.writeInt32BE(num, 0); | ||
return removeEmptyBytes(buf, minLength); | ||
}; | ||
const removeEmptyBytes = (buf, minLength) => { | ||
let firstNonZeroIndex = 0; | ||
while (firstNonZeroIndex < buf.length && buf[firstNonZeroIndex] === 0) { | ||
firstNonZeroIndex++; | ||
} | ||
const startIndex = Math.min(firstNonZeroIndex, buf.length - 1); | ||
const index = buf.length - startIndex < minLength ? buf.length - minLength : startIndex; | ||
return index < 0 | ||
? Buffer.concat([Buffer.from('00'.repeat(0 - index), 'hex'), buf]) | ||
: buf.slice(index); | ||
}; | ||
const numbersEqual = (first, second) => { | ||
@@ -78,2 +95,3 @@ const firstString = misc_1.remove0x(misc_1.bufToHexString(first)); | ||
numberToBuffer, | ||
numberToBufferPacked, | ||
numbersEqual, | ||
@@ -80,0 +98,0 @@ bufferToAddress, |
{ | ||
"name": "@eth-optimism/core-utils", | ||
"version": "0.0.1-alpha.17", | ||
"version": "0.0.1-alpha.18", | ||
"description": "Optimism Core Utils", | ||
@@ -63,3 +63,3 @@ "main": "build/index.js", | ||
}, | ||
"gitHead": "80ca22191f0e2233ad27930ee1adfb9655d1fdb8" | ||
"gitHead": "c43809d91ea0371bd618f95551630c27dd65c859" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57980
49
1499