eth-sign
sign and verify ETH transactions
Install
npm i -s eth-sign
Usage
var crypto = var signer = // all fields should be passed as buffersvar tx = nonce: Buffer gasPrice: Buffer gasLimit: Buffer to: Buffer value: Buffer data: Buffer var privKey = crypto var chainId = 1 // mainnetconst signed = signer // specify chainId for EIP155 digest signer // truesigner // truesigner // 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 buffer
s. 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.