Socket
Socket
Sign inDemoInstall

eth-sig-util

Package Overview
Dependencies
44
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    eth-sig-util

A few useful functions for signing ethereum data


Version published
Weekly downloads
152K
decreased by-7.89%
Maintainers
1
Install size
6.13 MB
Created
Weekly downloads
 

Package description

What is eth-sig-util?

The eth-sig-util npm package provides utilities for signing and verifying Ethereum signatures. It is commonly used in Ethereum-based applications to handle cryptographic operations related to user authentication, transaction signing, and message verification.

What are eth-sig-util's main functionalities?

Sign Typed Data

This feature allows you to sign typed data according to the EIP-712 standard. The code sample demonstrates how to sign a typed data object using a private key.

const sigUtil = require('eth-sig-util');
const privateKey = Buffer.from('your_private_key', 'hex');
const data = { types: { EIP712Domain: [ { name: 'name', type: 'string' }, { name: 'version', type: 'string' }, { name: 'chainId', type: 'uint256' }, { name: 'verifyingContract', type: 'address' } ], Person: [ { name: 'name', type: 'string' }, { name: 'wallet', type: 'address' } ] }, primaryType: 'Person', domain: { name: 'MyApp', version: '1', chainId: 1, verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC' }, message: { name: 'Alice', wallet: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC' } };
const signature = sigUtil.signTypedData_v4(privateKey, { data });
console.log(signature);

Recover Typed Data Signer

This feature allows you to recover the address of the signer from a signed typed data object. The code sample demonstrates how to recover the signer's address using the signature and the original data.

const sigUtil = require('eth-sig-util');
const signature = 'your_signature';
const data = { types: { EIP712Domain: [ { name: 'name', type: 'string' }, { name: 'version', type: 'string' }, { name: 'chainId', type: 'uint256' }, { name: 'verifyingContract', type: 'address' } ], Person: [ { name: 'name', type: 'string' }, { name: 'wallet', type: 'address' } ] }, primaryType: 'Person', domain: { name: 'MyApp', version: '1', chainId: 1, verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC' }, message: { name: 'Alice', wallet: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC' } };
const recoveredAddress = sigUtil.recoverTypedSignature_v4({ data, sig: signature });
console.log(recoveredAddress);

Personal Sign

This feature allows you to sign a personal message. The code sample demonstrates how to sign a simple message using a private key.

const sigUtil = require('eth-sig-util');
const privateKey = Buffer.from('your_private_key', 'hex');
const message = 'Hello, world!';
const signature = sigUtil.personalSign(privateKey, { data: message });
console.log(signature);

Recover Personal Signer

This feature allows you to recover the address of the signer from a signed personal message. The code sample demonstrates how to recover the signer's address using the signature and the original message.

const sigUtil = require('eth-sig-util');
const signature = 'your_signature';
const message = 'Hello, world!';
const recoveredAddress = sigUtil.recoverPersonalSignature({ data: message, sig: signature });
console.log(recoveredAddress);

Other packages similar to eth-sig-util

Readme

Source

Eth-Sig-Util CircleCI

A small collection of ethereum signing functions.

Methods

concatSig(v, r, s)

All three arguments should be provided as buffers.

Returns a continuous, hex-prefixed hex value for the signature, suitable for inclusion in a JSON transaction's data field.

normalize(address)

Takes an address of either upper or lower case, with or without a hex prefix, and returns an all-lowercase, hex-prefixed address, suitable for submitting to an ethereum provider.

personalSign (privateKeyBuffer, msgParams)

msgParams should have a data key that is hex-encoded data to sign.

Returns the prefixed signature expected for calls to eth.personalSign.

recoverPersonalSignature (msgParams)

msgParams should have a data key that is hex-encoded data unsigned, and a sig key that is hex-encoded and already signed.

Returns a hex-encoded sender address.

extractPublicKey (msgParams)

msgParams should have a data key that is hex-encoded data unsigned, and a sig key that is hex-encoded and already signed.

Returns a hex-encoded public key.

Keywords

FAQs

Last updated on 01 Mar 2017

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