Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@smithy/util-utf8
Advanced tools
@smithy/util-utf8 is a utility package for handling UTF-8 encoding and decoding in JavaScript. It provides functions to convert strings to UTF-8 byte arrays and vice versa, which can be useful in various scenarios such as data serialization, network communication, and file handling.
UTF-8 Encoding
This feature allows you to encode a string into a UTF-8 byte array. The `toUtf8` function takes a string as input and returns a Uint8Array representing the UTF-8 encoded bytes.
const { toUtf8 } = require('@smithy/util-utf8');
const utf8Bytes = toUtf8('Hello, world!');
console.log(utf8Bytes);
UTF-8 Decoding
This feature allows you to decode a UTF-8 byte array back into a string. The `fromUtf8` function takes a Uint8Array as input and returns the decoded string.
const { fromUtf8 } = require('@smithy/util-utf8');
const utf8Bytes = new Uint8Array([72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33]);
const decodedString = fromUtf8(utf8Bytes);
console.log(decodedString);
The `utf8` package provides similar functionality for encoding and decoding UTF-8 strings. It offers methods like `encode` and `decode` to handle UTF-8 conversions. Compared to @smithy/util-utf8, it is more focused on providing a simple API for UTF-8 handling without additional dependencies.
The `text-encoding` package is a polyfill for the TextEncoder and TextDecoder APIs, which are part of the Encoding Living Standard. It provides a more comprehensive solution for handling various text encodings, including UTF-8. This package is useful if you need broader encoding support beyond just UTF-8.
The `buffer` package is a Node.js core module that provides a way to handle binary data, including UTF-8 encoding and decoding. It offers methods like `Buffer.from` and `Buffer.toString` for converting between strings and byte arrays. This package is more versatile and widely used in Node.js environments.
FAQs
A UTF-8 string <-> UInt8Array converter
We found that @smithy/util-utf8 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.