ethereumjs-util
Advanced tools
Comparing version 2.1.0 to 2.2.0
17
index.js
@@ -53,2 +53,19 @@ const SHA3 = require('sha3') | ||
/** | ||
* pads an array of buffer with trailing zeros till it has `length` bytes | ||
* @method rpad | ||
* @param {Buffer|Array} array | ||
* @param {Integer} length the number of bytes the output should be | ||
* @return {Buffer|Array} | ||
*/ | ||
exports.rpad = function (msg, length) { | ||
msg = exports.toBuffer(msg) | ||
if (msg.length < length) { | ||
var buf = exports.zeros(length) | ||
msg.copy(buf) | ||
return buf | ||
} | ||
return msg.slice(-length) | ||
} | ||
/** | ||
* Trims leading zeros from a buffer or an array | ||
@@ -55,0 +72,0 @@ * |
{ | ||
"name": "ethereumjs-util", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "a collection of utility functions for Ethereum", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -34,2 +34,10 @@ # SYNOPSIS | ||
### `rpad(val, length)` | ||
pads an `array` or `buffer` with trailing zeros till it has `length` bytes | ||
**Parameters** | ||
- `val` - the value to pad | ||
- `length` - the of the resulting value | ||
**Return:** `array` or `buffer` | ||
### `unpad(val)` | ||
@@ -36,0 +44,0 @@ Trims leading zeros from a buffer or an array |
@@ -55,2 +55,10 @@ var assert = require('assert') | ||
describe('rpad', function () { | ||
it('should right pad a Buffer', function () { | ||
var buf = new Buffer([9, 9]) | ||
var padded = ethUtils.rpad(buf, 3) | ||
assert.equal(padded.toString('hex'), '090900') | ||
}) | ||
}) | ||
describe('intToHex', function () { | ||
@@ -57,0 +65,0 @@ it('should convert a int to hex', function () { |
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 2 instances in 1 package
513
186
0
21453
6