Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

@ethereumjs/util

Package Overview
Dependencies
8
Maintainers
4
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @ethereumjs/util

A collection of utility functions for Ethereum


Version published
Weekly downloads
525K
increased by6.08%
Maintainers
4
Install size
3.94 MB
Created
Weekly downloads
 

Package description

What is @ethereumjs/util?

@ethereumjs/util is a utility library for Ethereum-related operations. It provides a wide range of utility functions for handling Ethereum addresses, private keys, public keys, signatures, and other cryptographic operations. This package is essential for developers working on Ethereum-based applications, as it simplifies many common tasks.

What are @ethereumjs/util's main functionalities?

Address Utilities

This feature allows you to convert an Ethereum address to its checksummed version, which includes mixed-case letters to help prevent errors.

const { toChecksumAddress } = require('@ethereumjs/util');
const address = '0x32Be343B94f860124dC4fEe278FDCBD38C102D88';
const checksumAddress = toChecksumAddress(address);
console.log(checksumAddress); // '0x32Be343B94f860124dC4fEe278FDCBD38C102D88'

Private Key Utilities

This feature allows you to derive an Ethereum address from a given private key.

const { privateToAddress } = require('@ethereumjs/util');
const privateKey = Buffer.from('c87509a1c067bbde78beb793e6fa1b2b4a5c4c9c3c8e3b3a3b3a3b3a3b3a3b3a', 'hex');
const address = privateToAddress(privateKey);
console.log(address.toString('hex')); // '0x32Be343B94f860124dC4fEe278FDCBD38C102D88'

Signature Utilities

This feature allows you to sign a message hash with a private key and convert the signature to RPC format.

const { ecsign, toRpcSig } = require('@ethereumjs/util');
const msgHash = Buffer.from('5c6ffbdd40d9556b73a21e63c3e0e904e4e1a8a0', 'hex');
const privateKey = Buffer.from('c87509a1c067bbde78beb793e6fa1b2b4a5c4c9c3c8e3b3a3b3a3b3a3b3a3b3a', 'hex');
const sig = ecsign(msgHash, privateKey);
const rpcSig = toRpcSig(sig.v, sig.r, sig.s);
console.log(rpcSig); // '0x...' (signature in RPC format)

Other packages similar to @ethereumjs/util

Readme

Source

@ethereumjs/util

NPM Package GitHub Issues Actions Status Code Coverage Discord

A collection of utility functions for Ethereum. It can be used in Node.js and in the browser with browserify.

Installation

To obtain the latest version, simply require the project using npm:

npm install @ethereumjs/util

Usage

import assert from 'assert'
import { isValidChecksumAddress, unpadBuffer } from '@ethereumjs/util'

assert.ok(isValidChecksumAddress('0x2F015C60E0be116B1f0CD534704Db9c92118FB6A'))

assert.ok(unpadBuffer(Buffer.from('000000006600', 'hex')).equals(Buffer.from('6600', 'hex')))

API

Documentation

Read the API docs.

Modules

  • account
    • Account class
    • Private/public key and address-related functionality (creation, validation, conversion)
  • address
    • Address class and type
  • bytes
    • Byte-related helper and conversion functions
  • constants
    • Exposed constants
      • e.g. KECCAK256_NULL_S for string representation of Keccak-256 hash of null
  • hash
  • signature
    • Signing, signature validation, conversion, recovery
  • types
    • Helpful TypeScript types
  • internal
    • Internalized helper methods
  • withdrawal
    • Withdrawal class (EIP-4895)

BigInt Support

Starting with v8 the usage of BN.js for big numbers has been removed from the library and replaced with the usage of the native JS BigInt data type (introduced in ES2020).

Please note that number-related API signatures have changed along with this version update and the minimal build target has been updated to ES2020.

ethjs-util methods

The following methods are available by an internalized version of the ethjs-util package (MIT license), see internal.ts. The original package is not maintained any more and the original functionality will be replaced by own implementations over time (starting with the v7.1.3 release, October 2021).

  • arrayContainsArray
  • getBinarySize
  • stripHexPrefix
  • isHexPrefixed
  • isHexString
  • padToEven
  • fromAscii
  • fromUtf8
  • toUtf8
  • toAscii
  • getKeys

They can be imported by name:

import { stripHexPrefix } from '@ethereumjs/util'

EthereumJS

See our organizational documentation for an introduction to EthereumJS as well as information on current standards and best practices. If you want to join for work or carry out improvements on the libraries, please review our contribution guidelines first.

License

MPL-2.0

Keywords

FAQs

Last updated on 20 Jun 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc