
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
utf8-bytes-swap
Advanced tools
return an utf8 string or bytes array
This module converts UTF8 <-> Bytes Array
Use the package manager npm to install utf8-bytes-swap.
npm install utf8-bytes-swap
Storing strings on the blockchain is expensive. Using string to bytes array significantly reduces transaction cost for storing IPFS CID hashes.
A IPFS cidV1 hash is 59 byte and fit inside a bytes32[2]. Solidity does not accept incomplete byteArrays: fill=true is required for the 5 unused bytes.
const { stringToBytesArray, bytesArrayToString } = require('utf8-bytes-swap');
let cidV1 = 'bafkreicizr7rctuvyki43dtpp7n23go56r6ouw3qxc3iq3r4dtkf2izv6i';
let bytesArray = stringToBytesArray(cidV1, 32, true);
/*
[
Uint32Array(32) [
98, 97, 102, 107, 114, 101, 105,
99, 105, 122, 114, 55, 114, 99,
116, 117, 118, 121, 107, 105, 52,
51, 100, 116, 112, 112, 55, 110,
50, 51, 103, 111
],
Uint32Array(32) [
53, 54, 114, 54, 111, 117, 119, 51,
113, 120, 99, 51, 105, 113, 51, 114,
52, 100, 116, 107, 102, 50, 105, 122,
118, 54, 105, 0, 0, 0, 0, 0
]
]
*/
let retrievedCidV1 = bytesArrayToString(bytesArray);
// bafkreicizr7rctuvyki43dtpp7n23go56r6ouw3qxc3iq3r4dtkf2izv6i
// default: size to 32, fill partial bytesArray
function stringToBytesArray(str, size=32, fill=true){...};
// returns bytesArray to utf8 string
function bytesArrayToString(bytesArray){...};
Return an array of integers from 0 through 255, inclusive, representing the
bytes in the unicode string str.
Return an unicode str from a hex or integer array of 0 through 255.
MIT,
FAQs
This module converts UTF8 <-> Bytes Array
We found that utf8-bytes-swap 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.