Socket
Socket
Sign inDemoInstall

@nomicfoundation/ethereumjs-util

Package Overview
Dependencies
Maintainers
4
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nomicfoundation/ethereumjs-util

A collection of utility functions for Ethereum


Version published
Weekly downloads
170K
decreased by-7.53%
Maintainers
4
Weekly downloads
 
Created

What is @nomicfoundation/ethereumjs-util?

@nomicfoundation/ethereumjs-util is a utility library for Ethereum-related functions. It provides a variety of tools for handling Ethereum addresses, private keys, public keys, signatures, and other cryptographic operations.

What are @nomicfoundation/ethereumjs-util's main functionalities?

Address Generation

This feature allows you to generate an Ethereum address from a private key and convert it to a checksummed address.

const { privateToAddress, toChecksumAddress } = require('@nomicfoundation/ethereumjs-util');
const privateKey = Buffer.from('c87509a1c067bbde78beb793e6fa5e8b8d2a9f1d7b2a9b2a2b2a2b2a2b2a2b2a', 'hex');
const addressBuffer = privateToAddress(privateKey);
const address = toChecksumAddress(addressBuffer.toString('hex'));
console.log(address);

Signature Verification

This feature allows you to sign a message and verify the signature, recovering the public key and address from the signature.

const { ecsign, ecrecover, pubToAddress, toBuffer } = require('@nomicfoundation/ethereumjs-util');
const msg = 'Hello, Ethereum!';
const msgHash = toBuffer('0x' + require('crypto').createHash('sha256').update(msg).digest('hex'));
const privateKey = Buffer.from('c87509a1c067bbde78beb793e6fa5e8b8d2a9f1d7b2a9b2a2b2a2b2a2b2a2b2a', 'hex');
const sig = ecsign(msgHash, privateKey);
const publicKey = ecrecover(msgHash, sig.v, sig.r, sig.s);
const address = pubToAddress(publicKey).toString('hex');
console.log(address);

Hashing

This feature allows you to hash data using the Keccak-256 algorithm, which is used in Ethereum for various purposes.

const { keccak256 } = require('@nomicfoundation/ethereumjs-util');
const data = 'Hello, Ethereum!';
const hash = keccak256(Buffer.from(data));
console.log(hash.toString('hex'));

Other packages similar to @nomicfoundation/ethereumjs-util

Keywords

FAQs

Package last updated on 05 Feb 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc