0.3.4 • Published 4 years ago

eth-sign v0.3.4

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

eth-sign

sign and verify ETH transactions

Install

npm i -s eth-sign

Usage

var crypto = require('crypto')
var signer = require('eth-sign')

// all fields should be passed as buffers
var tx = {
  nonce: Buffer.from('00', 'hex'),
  gasPrice: Buffer.from('09184e72a000', 'hex'),
  gasLimit: Buffer.from('2710', 'hex'),
  to: Buffer.from('0000000000000000000000000000000000000000', 'hex'),
  value: Buffer.from('00', 'hex'),
  data: Buffer.from('7f7465737432000000000000000000000000000000000000000000000000000000600057', 'hex'),
}

var privKey = crypto.randomBytes(32)

var chainId = 1 // mainnet
const signed = signer.sign(tx, privKey, chainId) // specify chainId for EIP155 digest

signer.verify(signed.tx) // true
signer.verify(signed.raw) // true
signer.verify(signed.raw.toString('hex')) // true

API

signer.sign(tx, privKey, [chainId])

Sign a tx using privKey. Returns { tx, raw }, with raw being the bytecode of the signed transaction and tx of the form:

{
  nonce,
  gasPrice,
  gasLimit,
  to,
  value,
  data,
  v,          // recovery info for sig
  r,          // sig.r
  s,          // sig.s
  hash        // tx hash
}

All fields in tx MUST be passed as buffers. chainId may be specified to implement EIP155 signature digest, otherwise legacy digest is used by default.

signer.verify(tx)

Verify a signed tx. tx should be a signed tx object as above, or a raw tx encoded as a hex string or in a buffer. Returns true if verification succeeds, false otherwise.

License

ISC

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago

0.0.0

4 years ago