# eth-signer

> A lightweight ethereum javascript signer.

Latest version **0.3.4** (published 2017-12-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install eth-signer
pnpm add eth-signer
yarn add eth-signer
bun add eth-signer
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.4 |
| Published | 2017-12-11 |
| First published | 2016-06-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 14 |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| Maintainers | oed, pelleb |
| Keywords | ethereum, blockchain, transactions, contracts, wallet |

## Links

- npm: https://www.npmjs.com/package/eth-signer
- Repository: https://github.com/ConsenSys/eth-signer
- Homepage: https://github.com/ConsenSys/eth-signer#readme
- Issues: https://github.com/ConsenSys/eth-signer/issues
- npm.io page: https://npm.io/package/eth-signer

## Dependencies (14)

- [rlp](https://npm.io/package/rlp.md) ^2.0.0
- [web3](https://npm.io/package/web3.md) ^0.19.1
- [buffer](https://npm.io/package/buffer.md) ^4.9.1
- [elliptic](https://npm.io/package/elliptic.md) ^6.3.1
- [secp256k1](https://npm.io/package/secp256k1.md) ^3.2.0
- [tweetnacl](https://npm.io/package/tweetnacl.md) 0.14.3
- [estraverse](https://npm.io/package/estraverse.md) ^4.2.0
- [scrypt-async](https://npm.io/package/scrypt-async.md) ^1.3.0
- [ethereumjs-tx](https://npm.io/package/ethereumjs-tx.md) ^1.1.2
- [solidity-sha3](https://npm.io/package/solidity-sha3.md) ^0.4.1
- [tweetnacl-util](https://npm.io/package/tweetnacl-util.md) ^0.13.3
- [uport-identity](https://npm.io/package/uport-identity.md) ^2.0.0
- [ethereumjs-util](https://npm.io/package/ethereumjs-util.md) ^4.5.0
- [bitcore-mnemonic](https://npm.io/package/bitcore-mnemonic.md) ^1.2.2

## Recent versions

- 0.3.4 (latest) — 2017-12-11
- 0.3.4-beta-2 (next) — 2017-12-05
- 0.3.4-beta — 2017-11-30
- 0.3.3 — 2017-11-24
- 0.3.2 — 2017-08-29
- 0.3.1 — 2017-08-28
- 0.3.0 — 2017-08-16
- 0.2.3 — 2017-06-25
- 0.2.2 — 2017-03-20
- 0.2.1 — 2016-10-19
- 0.2.0 — 2016-10-18
- 0.1.3 — 2016-09-08
- 0.1.2 — 2016-06-19
- 0.1.1 — 2016-06-18
- 0.1.0 — 2016-06-15

## 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
<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
```

[BIP39]: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
[BIP32]: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki

## 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
```js
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:
```js
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:
```js
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:
```js
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
})
```

---
_Source: https://npm.io/package/eth-signer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
