Skip to content

Commit

Permalink
Account signing fix (web3#1111)
Browse files Browse the repository at this point in the history
* prepare release

* update eth-lib and added api changes

* updated dist/web3.min.js

* updated eth-lib to 0.2.5

* add warning to the accounts docs
  • Loading branch information
frozeman authored and nachomazzara committed Jun 4, 2020
1 parent 355e6e1 commit 4f027e3
Show file tree
Hide file tree
Showing 27 changed files with 124 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ethereum:[email protected].22
ethereum:[email protected].23
[email protected]
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"namespace": "ethereum",
"name": "web3",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "Ethereum JavaScript API",
"license": "LGPL-3.0",
"main": [
Expand Down
2 changes: 1 addition & 1 deletion dist/web3.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion docs/web3-eth-accounts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ web3.eth.accounts

The ``web3.eth.accounts`` contains functions to generate Ethereum accounts and sign transactions and data.

To use this package standalone use:
.. note:: This package has NOT been audited and might potentially be unsafe. Take precautions to clear memory properly, store the private keys safely, and test transaction receiving and sending functionality properly before using in production!

To use this package standalone use:


.. code-block:: javascript
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"lerna": "2.0.0",
"packages": [
"packages/*"
Expand Down
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* jshint ignore:start */
Package.describe({
name: 'ethereum:web3',
version: '1.0.0-beta.22',
version: '1.0.0-beta.23',
summary: 'Ethereum JavaScript API, middleware to talk to a ethreum node over RPC',
git: 'https://github.com/ethereum/ethereum.js',
// By default, Meteor will default to using README.md for documentation.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "web3",
"namespace": "ethereum",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "Ethereum JavaScript API wrapper repository",
"license": "LGPL-3.0",
"directories": {
Expand Down
6 changes: 3 additions & 3 deletions packages/web3-core-helpers/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "web3-core-helpers",
"namespace": "ethereum",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "Web3 core tools helper for sub packages. This is an internal package.",
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-core-helpers",
"license": "LGPL-3.0",
"main": "src/index.js",
"dependencies": {
"underscore": "1.8.3",
"web3-eth-iban": "^1.0.0-beta.22",
"web3-utils": "^1.0.0-beta.22"
"web3-eth-iban": "^1.0.0-beta.23",
"web3-utils": "^1.0.0-beta.23"
}
}
8 changes: 4 additions & 4 deletions packages/web3-core-method/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "web3-core-method",
"namespace": "ethereum",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "Creates the methods on the web3 modules. This is an internal package.",
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-core-method",
"license": "LGPL-3.0",
"main": "src/index.js",
"dependencies": {
"underscore": "1.8.3",
"web3-core-helpers": "^1.0.0-beta.22",
"web3-core-helpers": "^1.0.0-beta.23",
"web3-core-promievent": "^1.0.0-beta.22",
"web3-core-subscriptions": "^1.0.0-beta.22",
"web3-utils": "^1.0.0-beta.22"
"web3-core-subscriptions": "^1.0.0-beta.23",
"web3-utils": "^1.0.0-beta.23"
}
}
10 changes: 5 additions & 5 deletions packages/web3-core-requestmanager/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "web3-core-requestmanager",
"namespace": "ethereum",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "Web3 module to handle requests to external providers.",
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-core-requestmanager",
"license": "LGPL-3.0",
"main": "src/index.js",
"dependencies": {
"underscore": "1.8.3",
"web3-core-helpers": "^1.0.0-beta.22",
"web3-providers-http": "^1.0.0-beta.22",
"web3-providers-ipc": "^1.0.0-beta.22",
"web3-providers-ws": "^1.0.0-beta.22"
"web3-core-helpers": "^1.0.0-beta.23",
"web3-providers-http": "^1.0.0-beta.23",
"web3-providers-ipc": "^1.0.0-beta.23",
"web3-providers-ws": "^1.0.0-beta.23"
}
}
4 changes: 2 additions & 2 deletions packages/web3-core-subscriptions/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "web3-core-subscriptions",
"namespace": "ethereum",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "Manages web3 subscriptions. This is an internal package.",
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-core-subscriptions",
"license": "LGPL-3.0",
"main": "src/index.js",
"dependencies": {
"eventemitter3": "1.1.1",
"underscore": "1.8.3",
"web3-core-helpers": "^1.0.0-beta.22"
"web3-core-helpers": "^1.0.0-beta.23"
}
}
10 changes: 5 additions & 5 deletions packages/web3-core/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "web3-core",
"namespace": "ethereum",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "Web3 core tools for sub packages. This is an internal package.",
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-core",
"license": "LGPL-3.0",
"main": "src/index.js",
"dependencies": {
"web3-core-helpers": "^1.0.0-beta.22",
"web3-core-method": "^1.0.0-beta.22",
"web3-core-requestmanager": "^1.0.0-beta.22",
"web3-utils": "^1.0.0-beta.22"
"web3-core-helpers": "^1.0.0-beta.23",
"web3-core-method": "^1.0.0-beta.23",
"web3-core-requestmanager": "^1.0.0-beta.23",
"web3-utils": "^1.0.0-beta.23"
}
}
6 changes: 3 additions & 3 deletions packages/web3-eth-abi/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "web3-eth-abi",
"namespace": "ethereum",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "Web3 module encode and decode EVM in/output.",
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-eth-abi",
"license": "LGPL-3.0",
"main": "src/index.js",
"dependencies": {
"bn.js": "4.11.6",
"underscore": "1.8.3",
"web3-core-helpers": "^1.0.0-beta.22",
"web3-utils": "^1.0.0-beta.22"
"web3-core-helpers": "^1.0.0-beta.23",
"web3-utils": "^1.0.0-beta.23"
}
}
12 changes: 6 additions & 6 deletions packages/web3-eth-accounts/package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"name": "web3-eth-accounts",
"namespace": "ethereum",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "Web3 module to generate Ethereum accounts and sign data and transactions.",
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-eth-accounts",
"license": "LGPL-3.0",
"main": "src/index.js",
"dependencies": {
"bluebird": "3.3.1",
"eth-lib": "^0.1.27",
"eth-lib": "0.2.5",
"scrypt.js": "0.2.0",
"underscore": "1.8.3",
"uuid": "2.0.1",
"web3-core": "^1.0.0-beta.22",
"web3-core-helpers": "^1.0.0-beta.22",
"web3-core-method": "^1.0.0-beta.22",
"web3-utils": "^1.0.0-beta.22"
"web3-core": "^1.0.0-beta.23",
"web3-core-helpers": "^1.0.0-beta.23",
"web3-core-method": "^1.0.0-beta.23",
"web3-utils": "^1.0.0-beta.23"
}
}
30 changes: 27 additions & 3 deletions packages/web3-eth-accounts/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var Promise = require('bluebird');
var Account = require("eth-lib/lib/account");
var Hash = require("eth-lib/lib/hash");
var RLP = require("eth-lib/lib/rlp");
var Nat = require("eth-lib/lib/nat");
var Bytes = require("eth-lib/lib/bytes");
var cryp = require('crypto');
var scryptsy = require('scrypt.js');
var uuid = require('uuid');
Expand Down Expand Up @@ -131,10 +133,24 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca
chainId: utils.numberToHex(tx.chainId)
};

var rlpEncoded = RLP.encode([
Bytes.fromNat(transaction.nonce),
Bytes.fromNat(transaction.gasPrice),
Bytes.fromNat(transaction.gas),
transaction.to.toLowerCase(),
Bytes.fromNat(transaction.value),
transaction.data,
Bytes.fromNat(transaction.chainId || "0x1"),
"0x",
"0x"]);

var hash = Hash.keccak256(rlpEncoded);


var signature = Account.makeSigner(Nat.toNumber(transaction.chainId || "0x1") * 2 + 35)(Hash.keccak256(rlpEncoded), privateKey);
var rawTx = RLP.decode(rlpEncoded).slice(0,6).concat(Account.decodeSignature(signature));
var rawTransaction = RLP.encode(rawTx);

var hash = Hash.keccak256(Account.transactionSigningData(transaction));
var rawTransaction = Account.signTransaction(transaction, privateKey);
var values = RLP.decode(rawTransaction);
var result = {
messageHash: hash,
Expand Down Expand Up @@ -168,9 +184,17 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca
});
};

/* jshint ignore:start */
Accounts.prototype.recoverTransaction = function recoverTransaction(rawTx) {
return Account.recoverTransaction(rawTx);
var values = RLP.decode(rawTx);
var signature = Account.encodeSignature(values.slice(6,9));
var recovery = Bytes.toNumber(values[6]);
var extraData = recovery < 35 ? [] : [Bytes.fromNumber((recovery - 35) >> 1), "0x", "0x"];
var signingData = values.slice(0,6).concat(extraData);
var signingDataHex = RLP.encode(signingData);
return Account.recover(Hash.keccak256(signingDataHex), signature);
};
/* jshint ignore:end */

Accounts.prototype.hashMessage = function hashMessage(data) {
var message = utils.isHexStrict(data) ? utils.hexToUtf8(data) : data;
Expand Down
14 changes: 7 additions & 7 deletions packages/web3-eth-contract/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"name": "web3-eth-contract",
"namespace": "ethereum",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "Web3 module to interact with Ethereum smart contracts.",
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-eth-contract",
"license": "LGPL-3.0",
"main": "src/index.js",
"dependencies": {
"underscore": "1.8.3",
"web3-core": "^1.0.0-beta.22",
"web3-core-helpers": "^1.0.0-beta.22",
"web3-core-method": "^1.0.0-beta.22",
"web3-core": "^1.0.0-beta.23",
"web3-core-helpers": "^1.0.0-beta.23",
"web3-core-method": "^1.0.0-beta.23",
"web3-core-promievent": "^1.0.0-beta.22",
"web3-core-subscriptions": "^1.0.0-beta.22",
"web3-eth-abi": "^1.0.0-beta.22",
"web3-utils": "^1.0.0-beta.22"
"web3-core-subscriptions": "^1.0.0-beta.23",
"web3-eth-abi": "^1.0.0-beta.23",
"web3-utils": "^1.0.0-beta.23"
}
}
4 changes: 2 additions & 2 deletions packages/web3-eth-iban/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "web3-eth-iban",
"namespace": "ethereum",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "This package converts Ethereum addresses to IBAN addresses a vice versa.",
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-eth-iban",
"license": "LGPL-3.0",
"main": "src/index.js",
"dependencies": {
"bn.js": "^4.11.6",
"web3-utils": "^1.0.0-beta.22"
"web3-utils": "^1.0.0-beta.23"
}
}
12 changes: 6 additions & 6 deletions packages/web3-eth-personal/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "web3-eth-personal",
"namespace": "ethereum",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "Web3 module to interact with the Ethereum blockchain accounts stored in the node.",
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-eth-personal",
"license": "LGPL-3.0",
"main": "src/index.js",
"dependencies": {
"web3-core": "^1.0.0-beta.22",
"web3-core-helpers": "^1.0.0-beta.22",
"web3-core-method": "^1.0.0-beta.22",
"web3-net": "^1.0.0-beta.22",
"web3-utils": "^1.0.0-beta.22"
"web3-core": "^1.0.0-beta.23",
"web3-core-helpers": "^1.0.0-beta.23",
"web3-core-method": "^1.0.0-beta.23",
"web3-net": "^1.0.0-beta.23",
"web3-utils": "^1.0.0-beta.23"
}
}
24 changes: 12 additions & 12 deletions packages/web3-eth/package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"name": "web3-eth",
"namespace": "ethereum",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "Web3 module to interact with the Ethereum blockchain and smart contracts.",
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-eth",
"license": "LGPL-3.0",
"main": "src/index.js",
"dependencies": {
"underscore": "1.8.3",
"web3-core": "^1.0.0-beta.22",
"web3-core-helpers": "^1.0.0-beta.22",
"web3-core-method": "^1.0.0-beta.22",
"web3-core-subscriptions": "^1.0.0-beta.22",
"web3-eth-abi": "^1.0.0-beta.22",
"web3-eth-accounts": "^1.0.0-beta.22",
"web3-eth-contract": "^1.0.0-beta.22",
"web3-eth-iban": "^1.0.0-beta.22",
"web3-eth-personal": "^1.0.0-beta.22",
"web3-net": "^1.0.0-beta.22",
"web3-utils": "^1.0.0-beta.22"
"web3-core": "^1.0.0-beta.23",
"web3-core-helpers": "^1.0.0-beta.23",
"web3-core-method": "^1.0.0-beta.23",
"web3-core-subscriptions": "^1.0.0-beta.23",
"web3-eth-abi": "^1.0.0-beta.23",
"web3-eth-accounts": "^1.0.0-beta.23",
"web3-eth-contract": "^1.0.0-beta.23",
"web3-eth-iban": "^1.0.0-beta.23",
"web3-eth-personal": "^1.0.0-beta.23",
"web3-net": "^1.0.0-beta.23",
"web3-utils": "^1.0.0-beta.23"
}
}
8 changes: 4 additions & 4 deletions packages/web3-net/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "web3-net",
"namespace": "ethereum",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "Web3 module to interact with the Ethereum nodes networking properties.",
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-net",
"license": "LGPL-3.0",
"main": "src/index.js",
"dependencies": {
"web3-core": "^1.0.0-beta.22",
"web3-core-method": "^1.0.0-beta.22",
"web3-utils": "^1.0.0-beta.22"
"web3-core": "^1.0.0-beta.23",
"web3-core-method": "^1.0.0-beta.23",
"web3-utils": "^1.0.0-beta.23"
}
}
4 changes: 2 additions & 2 deletions packages/web3-providers-http/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "web3-providers-http",
"namespace": "ethereum",
"version": "1.0.0-beta.22",
"version": "1.0.0-beta.23",
"description": "Module to handle web3 RPC connections over HTTP.",
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-providers-http",
"license": "LGPL-3.0",
"main": "src/index.js",
"dependencies": {
"web3-core-helpers": "^1.0.0-beta.22",
"web3-core-helpers": "^1.0.0-beta.23",
"xhr2": "0.1.4"
}
}
Loading

0 comments on commit 4f027e3

Please sign in to comment.