npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eth-signer

v0.3.4

Published

A lightweight ethereum javascript signer.

Downloads

189

Readme

Eth-Signer

A minimal ethereum javascript signer.

This is a fork of eth-lightwallet and will not be backwards compatible.

TODO update docs and example code. See tests for the time being.

Get Started

npm install eth-signer

The eth-signer package contains dist/eth-signer.min.js that can be included in an HTML page:

<html>
  <body>
    <script src="eth-signer.min.js"></script>
  </body>
</html>

The file eth-signer.min.js exposes the global object EthSigner to the browser.

Tests

Run all tests:

npm run test
npm run coverage

License

MIT License.

Usage of meta transactions

In order to sign and send meta tx there are a few steps that has to be taken. A user first has to sign the raw tx, then send it to a relay service. The relay service then verifies the meta signature and after that sends the tx to the ethereum network.

Sign a metaTx

var proxyAddress = // the address of your proxy contract
var metaIdentityManagerAddress = // the address of the metaIdentityManager contract
var relayAddress = // the address of the txRelay contract
var txSenderAddress = // the address of the service that is sending your tx
var whitelistOwner = // the owner of a specific whitelist in the txRelay contract. Can be the zero address for no whitelist.
var keyPair = // your keypair that will be used to meta sign a transaction

var relaySigner = new TxRelaySigner(keypair, relayAddress, txSenderAddress, whitelistOwner);
var signer = new MIMProxySigner(proxyAddress, relaySigner, metaIdentityManagerAddress);

var rawTx = // a raw tx that you want to send
// IMPORTANT - the raw tx above has to have the nonce coresponding to your
// keypairs address in the txRelay contract. If different the tx will fail.

signer.signRawTx(rawTx, (error, metaSignedRawTx) => {
  // send tx to relay service
})

Verify signature of a rawMetaTx

The relay service will want to verify that the metaTx it's relaying has a valid signature in order to avoid sending invalid txs. This can be done in the following way:

var decodedMetaTx = TxRelaySigner.decodeMetaTx(metaSignedRawTx)
txRelay.getNonce(decodedMetaTx.claimedAddress).then(nonce => {
  nonce = nonce.toString() // the nonce has to be a string
  var validMetaSig = TxRelaySigner.isMetaSignatureValid(txRelay.address, decodedMetaTx, nonce)
  if (validMetaSig) {
    // send the tx
  }
})

Sign and send tx to network

The raw meta tx that is sent to the relay can be signed with a simpleSigner:

var metaSignedRawTx = // the meta signed tx from above
// IMPORTANT - since the user won't know the nonce of the sender address it will have to provide it
var Transaction = require('ethereumjs-tx');
var tx = new Transaction(Buffer.from(metaSignedRawTx, 'hex'))
tx.nonce = // the nonce of sender address
var rawTx = tx.serialize().toString('hex')

var keypair = // sender keypair
var signer = SimpleSigner(keypair)
signer.signRawTx(rawTx, (error, signedRawTx) => {
  // send tx to ethereum network
})

Use IdentityManager without metaTxs

In the MetaIdentityManager contract it is possible to sign transactions directly. If you want to sign a tx in this way you can do the following:

var simpleSigner = SimpleSigner(keypair)
var signer = new MIMProxySigner(proxyAddress, simpleSigner, metaIdentityManagerAddress);

var rawTx = // a raw tx that you want to send
signer.signRawTx(rawTx, (error, metaSignedRawTx) => {
  // send tx to ethereum network
})