Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@ethersproject/bytes
Advanced tools
@ethersproject/bytes is a utility library for handling and manipulating byte arrays in JavaScript. It is part of the ethers.js library, which is widely used for interacting with the Ethereum blockchain. This package provides various functions to work with byte arrays, including conversion, concatenation, slicing, and more.
Conversion between hex strings and byte arrays
This feature allows you to convert a hex string to a byte array and vice versa. The `arrayify` function converts a hex string to a Uint8Array, and the `hexlify` function converts a Uint8Array back to a hex string.
const { arrayify, hexlify } = require('@ethersproject/bytes');
const hexString = '0x123456';
const byteArray = arrayify(hexString);
console.log(byteArray); // Uint8Array [ 18, 52, 86 ]
const newHexString = hexlify(byteArray);
console.log(newHexString); // '0x123456'
Concatenation of byte arrays
This feature allows you to concatenate multiple byte arrays into a single byte array. The `concat` function takes an array of Uint8Arrays and returns a new Uint8Array that is the concatenation of all the input arrays.
const { concat } = require('@ethersproject/bytes');
const byteArray1 = new Uint8Array([1, 2, 3]);
const byteArray2 = new Uint8Array([4, 5, 6]);
const concatenatedArray = concat([byteArray1, byteArray2]);
console.log(concatenatedArray); // Uint8Array [ 1, 2, 3, 4, 5, 6 ]
Slicing byte arrays
This feature allows you to slice a byte array to get a subarray. The `slice` function takes a byte array and start and end indices, and returns a new byte array that is a subarray of the input array.
const { arrayify, hexlify, slice } = require('@ethersproject/bytes');
const hexString = '0x1234567890abcdef';
const byteArray = arrayify(hexString);
const slicedArray = slice(byteArray, 2, 6);
console.log(hexlify(slicedArray)); // '0x34567890'
The 'buffer' package is a core Node.js module that provides a way to handle binary data. It offers similar functionalities to @ethersproject/bytes, such as conversion between different formats, concatenation, and slicing of byte arrays. However, 'buffer' is more general-purpose and not specifically tailored for Ethereum or blockchain-related tasks.
The 'ethereumjs-util' package is a collection of utility functions for Ethereum, including functions for handling byte arrays. It provides similar functionalities to @ethersproject/bytes, such as conversion between hex strings and byte arrays, and byte array manipulation. However, 'ethereumjs-util' includes a broader range of utilities specifically for Ethereum development.
EXPERIMENTAL
Please see the ethers repository for more informations.
@TODO
MIT License
FAQs
Bytes utility functions for ethers.
The npm package @ethersproject/bytes receives a total of 406,172 weekly downloads. As such, @ethersproject/bytes popularity was classified as popular.
We found that @ethersproject/bytes demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.