From 199b2c4b629a31bf8dd05dea201cede6f467f401 Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Tue, 29 Jan 2019 11:59:13 +0000 Subject: [PATCH 1/8] fix: import buffer into types file so `node` does not need to be installed on the project --- packages/web3-bzz/types/index.d.ts | 2 ++ packages/web3-utils/types/index.d.ts | 1 + 2 files changed, 3 insertions(+) diff --git a/packages/web3-bzz/types/index.d.ts b/packages/web3-bzz/types/index.d.ts index 9d9ebb731eb..5d3d8844e10 100644 --- a/packages/web3-bzz/types/index.d.ts +++ b/packages/web3-bzz/types/index.d.ts @@ -17,6 +17,8 @@ * @date 2018 */ +import {Buffer} from 'buffer'; + export class Bzz { constructor(provider: string | {}); diff --git a/packages/web3-utils/types/index.d.ts b/packages/web3-utils/types/index.d.ts index aa8391bb3ad..8aa73dd224e 100644 --- a/packages/web3-utils/types/index.d.ts +++ b/packages/web3-utils/types/index.d.ts @@ -21,6 +21,7 @@ */ import BigNumber from 'bn.js'; +import {Buffer} from 'buffer'; export type Unit = | 'noether' From 94886981c81a99b3723f61fc4489e6f69f273874 Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Tue, 29 Jan 2019 11:59:43 +0000 Subject: [PATCH 2/8] fix: map the reference path for the `net` module so it compiles without having to install node on the project --- packages/web3-core/types/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/web3-core/types/index.d.ts b/packages/web3-core/types/index.d.ts index 85a298e2e3e..59311ab9d8b 100644 --- a/packages/web3-core/types/index.d.ts +++ b/packages/web3-core/types/index.d.ts @@ -17,6 +17,7 @@ * @date 2018 */ +/// import * as net from 'net'; import { BatchRequest, From 8e0c5fdb274e6087fb083fb6309d61a7de1597a2 Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Tue, 29 Jan 2019 12:38:25 +0000 Subject: [PATCH 3/8] fix: patch the angular `browser.js` to allow `{crypto: true, stream: true` --- packages/web3/angular-patch.js | 17 +++++++++++++++++ packages/web3/package.json | 6 +++--- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 packages/web3/angular-patch.js diff --git a/packages/web3/angular-patch.js b/packages/web3/angular-patch.js new file mode 100644 index 00000000000..50544745266 --- /dev/null +++ b/packages/web3/angular-patch.js @@ -0,0 +1,17 @@ +const fs = require('fs'); +const f = '../../node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js'; + +// This is because we have to replace the `node:false` in the `/angular-cli-files/models/webpack-configs/browser.js` +// with `node: {crypto: true, stream: true}` to allow web3 to work with angular (as they enforce node: false.) +// as explained here - https://github.com/ethereum/web3.js/issues/2260#issuecomment-458519127 +if (fs.existsSync(f)) { + fs.readFile(f, 'utf8', function (err, data) { + if (err) { + return console.log(err); + } + var result = data.replace(/node: false/g, 'node: {crypto: true, stream: true}'); + fs.writeFile(f, result, 'utf8', function (err) { + if (err) return console.log(err); + }); + }); +} diff --git a/packages/web3/package.json b/packages/web3/package.json index ba2907609c7..7b9b8f944c8 100644 --- a/packages/web3/package.json +++ b/packages/web3/package.json @@ -17,8 +17,7 @@ "API" ], "author": "ethereum.org", - "authors": [ - { + "authors": [{ "name": "Samuel Furter", "email": "samuel@ethereum.org", "homepage": "https://github.com/nivida" @@ -52,7 +51,8 @@ "build": "rollup -c", "dev": "rollup -c -w", "test": "jest", - "dtslint": "dtslint types --onlyTestTsNext" + "dtslint": "dtslint types --onlyTestTsNext", + "postinstall": "node angular-patch.js" }, "types": "types", "dependencies": { From f859a24e1a5b376b89d39ebf6e96a604ee16d6b6 Mon Sep 17 00:00:00 2001 From: Leon Prouger Date: Wed, 30 Jan 2019 11:02:21 +0200 Subject: [PATCH 4/8] fixing example of whisper protocol --- docs/web3-shh.rst | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/docs/web3-shh.rst b/docs/web3-shh.rst index e80176167fd..5e7b72b08b2 100644 --- a/docs/web3-shh.rst +++ b/docs/web3-shh.rst @@ -761,8 +761,7 @@ Example .. code-block:: javascript - const identities = [], - subscription = null; + const identities = []; Promise.all([ web3.shh.newSymKey().then((id) => {identities.push(id);}), @@ -771,7 +770,7 @@ Example ]).then(() => { // will receive also its own message send, below - subscription = shh.subscribe("messages", { + const subscription = shh.subscribe("messages", { symKeyID: identities[0], topics: ['0xffaadd11'] }).on('data', console.log); @@ -785,7 +784,7 @@ Example payload: '0xffffffdddddd1122', powTime: 3, powTarget: 0.5 - }).then(hash => console.log(`Message with hash ${h} was successfuly sent`)) + }).then(hash => console.log(`Message with hash ${hash} was successfuly sent`)) .catch(err => console.log("Error: ", err)); }); @@ -1023,5 +1022,3 @@ Example "topic": "0x01020304", "ttl": 50 },{...}] - - From 85c0f0bb48124a16267117501d77560e0a7f8074 Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Thu, 31 Jan 2019 10:03:45 +0000 Subject: [PATCH 5/8] write missing typing for `web3-eth-personal` --- packages/web3-eth-personal/types/index.d.ts | 49 +++++++++++---- .../types/tests/personal-tests.ts | 59 ++++++++++++++++--- 2 files changed, 89 insertions(+), 19 deletions(-) diff --git a/packages/web3-eth-personal/types/index.d.ts b/packages/web3-eth-personal/types/index.d.ts index ca600b125d0..c8d7faea7db 100644 --- a/packages/web3-eth-personal/types/index.d.ts +++ b/packages/web3-eth-personal/types/index.d.ts @@ -13,28 +13,55 @@ */ /** * @file index.d.ts - * @author Huan Zhang + * @author Huan Zhang , + * @author Josh Stevens * @date 2018 */ -import {Accounts} from 'web3-eth-accounts' +import {Accounts} from 'web3-eth-accounts'; import {provider} from 'web3-providers'; import {AbstractWeb3Module, Providers, RLPEncodedTransaction, Transaction, Web3ModuleOptions} from 'web3-core'; export class Personal extends AbstractWeb3Module { - constructor( - provider: provider, - accounts: Accounts, - options?: Web3ModuleOptions - ); + constructor(provider: provider, accounts: Accounts, options?: Web3ModuleOptions); newAccount(password: string, callback?: (error: Error, address: string) => void): Promise; - sign(dataToSign: string, address: string, password: string, callback?: (error: Error, signature: string) => void): Promise; + sign( + dataToSign: string, + address: string, + password: string, + callback?: (error: Error, signature: string) => void + ): Promise; - ecRecover(dataThatWasSigned: string, signature: string, callback?: (error: Error, address: string) => void): Promise; + ecRecover( + dataThatWasSigned: string, + signature: string, + callback?: (error: Error, address: string) => void + ): Promise; - signTransaction(transation: Transaction, password: string, callback?: (error: Error, RLPEncodedTransaction: RLPEncodedTransaction) => void): Promise; + signTransaction( + transation: Transaction, + password: string, + callback?: (error: Error, RLPEncodedTransaction: RLPEncodedTransaction) => void + ): Promise; - unlockAccount(address: string, password: string, unlockDuration: number, callback?: (error: Error) => void): Promise; + sendTransaction( + transation: Transaction, + password: string, + callback?: (error: Error, transactionHash: string) => void + ): Promise; + + unlockAccount( + address: string, + password: string, + unlockDuration: number, + callback?: (error: Error) => void + ): Promise; + + lockAccount(address: string, callback?: (error: Error, success: boolean) => void): Promise; + + getAccounts(callback?: (error: Error, accounts: string[]) => void): Promise; + + importRawKey(privateKey: string, password: string): Promise; } diff --git a/packages/web3-eth-personal/types/tests/personal-tests.ts b/packages/web3-eth-personal/types/tests/personal-tests.ts index a582c73db42..64ad666dfd0 100644 --- a/packages/web3-eth-personal/types/tests/personal-tests.ts +++ b/packages/web3-eth-personal/types/tests/personal-tests.ts @@ -13,7 +13,9 @@ */ /** * @file personal-tests.ts - * @author Huan Zhang , Samuel Furter + * @author Huan Zhang + * @author Samuel Furter + * @author Josh Stevens * @date 2018 */ @@ -22,11 +24,7 @@ import {Personal} from 'web3-eth-personal'; import {HttpProvider} from 'web3-providers'; import {Accounts} from 'web3-eth-accounts'; -const personal = new Personal( - 'http://localhost:7545', - new Accounts('http://localhost:7545', {}), - {} -); +const personal = new Personal('http://localhost:7545', new Accounts('http://localhost:7545', {}), {}); // $ExpectType Promise personal.newAccount('test password'); @@ -36,7 +34,12 @@ personal.newAccount('test password', (error: Error, address: string) => {}); // $ExpectType Promise personal.sign('Hello world', '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', 'test password!'); // $ExpectType Promise -personal.sign('Hello world', '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', 'test password!', (error: Error, signature: string) => {}); +personal.sign( + 'Hello world', + '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', + 'test password!', + (error: Error, signature: string) => {} +); // $ExpectType Promise personal.ecRecover('Hello world', '0x30755ed65396facf86c53e6217c52b4daebe72aa'); @@ -67,9 +70,49 @@ personal.signTransaction( }, 'test password', (error: Error, RLPEncodedTransaction: RLPEncodedTransaction) => {} -) +); + +// $ExpectType Promise +personal.sendTransaction( + { + from: '0xEB014f8c8B418Db6b45774c326A0E64C78914dC0', + gasPrice: '20000000000', + gas: '21000', + to: '0x3535353535353535353535353535353535353535', + value: '1000000000000000000', + data: '' + }, + 'test password' +); + +// $ExpectType Promise +personal.sendTransaction( + { + from: '0xEB014f8c8B418Db6b45774c326A0E64C78914dC0', + gasPrice: '20000000000', + gas: '21000', + to: '0x3535353535353535353535353535353535353535', + value: '1000000000000000000', + data: '' + }, + 'test password', + (error: Error, transactionHash: string) => {} +); // $ExpectType Promise personal.unlockAccount('0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', 'test password!', 600); // $ExpectType Promise personal.unlockAccount('0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', 'test password!', 600, (error: Error) => {}); + +// $ExpectType Promise +personal.lockAccount('0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe'); +// $ExpectType Promise +personal.lockAccount('0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', (error: Error, sucess: boolean) => {}); + +// $ExpectType Promise +personal.getAccounts(); +// $ExpectType Promise +personal.getAccounts((error: Error, accounts: string[]) => {}); + +// $ExpectType Promise +personal.importRawKey('privateKey', 'blah2'); From da970728066780676f21d48d9daec2f6c0155d51 Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Thu, 31 Jan 2019 10:12:52 +0000 Subject: [PATCH 6/8] remove unused code out of the tests --- packages/web3-eth-personal/types/tests/personal-tests.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/web3-eth-personal/types/tests/personal-tests.ts b/packages/web3-eth-personal/types/tests/personal-tests.ts index 64ad666dfd0..7c9b5c4ac6c 100644 --- a/packages/web3-eth-personal/types/tests/personal-tests.ts +++ b/packages/web3-eth-personal/types/tests/personal-tests.ts @@ -21,10 +21,9 @@ import {RLPEncodedTransaction} from 'web3-core'; import {Personal} from 'web3-eth-personal'; -import {HttpProvider} from 'web3-providers'; import {Accounts} from 'web3-eth-accounts'; -const personal = new Personal('http://localhost:7545', new Accounts('http://localhost:7545', {}), {}); +const personal = new Personal('http://localhost:7545', new Accounts('http://localhost:7545')); // $ExpectType Promise personal.newAccount('test password'); From f3b594b29e308d927009bdf8c4c202cca1d6ae6e Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Fri, 1 Feb 2019 10:27:09 +0000 Subject: [PATCH 7/8] fix: add `status` onto `TransactionReceipt` --- packages/web3-core/types/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/web3-core/types/index.d.ts b/packages/web3-core/types/index.d.ts index 85a298e2e3e..d398dabb5a5 100644 --- a/packages/web3-core/types/index.d.ts +++ b/packages/web3-core/types/index.d.ts @@ -123,6 +123,7 @@ export interface RLPEncodedTransaction { } export interface TransactionReceipt { + status: boolean; transactionHash: string; transactionIndex: number; blockHash: string; From 66c67af029250c447fc6197e08af5818e8c275ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20=C5=A0?= Date: Sun, 3 Feb 2019 11:45:53 +0100 Subject: [PATCH 8/8] Add missing quotes --- docs/web3-eth-ens.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/web3-eth-ens.rst b/docs/web3-eth-ens.rst index 20e602087f0..10572f0046e 100644 --- a/docs/web3-eth-ens.rst +++ b/docs/web3-eth-ens.rst @@ -12,7 +12,7 @@ The ``web3.eth.ens`` functions let you interacting with Ens. import Web3 from 'web3'; import {Ens} from 'web3-eth-ens'; - import {Accounts} from 'web3-eth-accounts; + import {Accounts} from 'web3-eth-accounts'; // "Web3.givenProvider" will be set if in an Ethereum supported browser. const eth = new Ens( @@ -388,7 +388,7 @@ Example .. code-block:: javascript - web3.eth.ens.getText('ethereum.eth', 'key).then((result) => { + web3.eth.ens.getText('ethereum.eth', 'key').then((result) => { console.log(result); }); > "0000000000000000000000000000000000000000000000000000000000000000"