Skip to content

Commit

Permalink
Merge branch '1.0' into web3GH-2293
Browse files Browse the repository at this point in the history
  • Loading branch information
nivida authored Feb 4, 2019
2 parents f246043 + 888d88a commit f077f7a
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 31 deletions.
4 changes: 2 additions & 2 deletions docs/web3-eth-ens.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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"
Expand Down
9 changes: 3 additions & 6 deletions docs/web3-shh.rst
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,7 @@ Example
.. code-block:: javascript
const identities = [],
subscription = null;
const identities = [];
Promise.all([
web3.shh.newSymKey().then((id) => {identities.push(id);}),
Expand All @@ -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);
Expand All @@ -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));
});
Expand Down Expand Up @@ -1023,5 +1022,3 @@ Example
"topic": "0x01020304",
"ttl": 50
},{...}]
2 changes: 2 additions & 0 deletions packages/web3-bzz/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* @date 2018
*/

import {Buffer} from 'buffer';

export class Bzz {
constructor(provider: string | {});

Expand Down
2 changes: 2 additions & 0 deletions packages/web3-core/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @date 2018
*/

///<reference path='../node_modules/@types/node/index.d.ts'/>
import * as net from 'net';
import {
BatchRequest,
Expand Down Expand Up @@ -123,6 +124,7 @@ export interface RLPEncodedTransaction {
}

export interface TransactionReceipt {
status: boolean;
transactionHash: string;
transactionIndex: number;
blockHash: string;
Expand Down
49 changes: 38 additions & 11 deletions packages/web3-eth-personal/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,55 @@
*/
/**
* @file index.d.ts
* @author Huan Zhang <huanzhang30@gmail.com>
* @author Huan Zhang <huanzhang30@gmail.com>,
* @author Josh Stevens <joshstevens19@hotmail.co.uk>
* @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<string>;

sign(dataToSign: string, address: string, password: string, callback?: (error: Error, signature: string) => void): Promise<string>;
sign(
dataToSign: string,
address: string,
password: string,
callback?: (error: Error, signature: string) => void
): Promise<string>;

ecRecover(dataThatWasSigned: string, signature: string, callback?: (error: Error, address: string) => void): Promise<string>;
ecRecover(
dataThatWasSigned: string,
signature: string,
callback?: (error: Error, address: string) => void
): Promise<string>;

signTransaction(transation: Transaction, password: string, callback?: (error: Error, RLPEncodedTransaction: RLPEncodedTransaction) => void): Promise<RLPEncodedTransaction>;
signTransaction(
transation: Transaction,
password: string,
callback?: (error: Error, RLPEncodedTransaction: RLPEncodedTransaction) => void
): Promise<RLPEncodedTransaction>;

unlockAccount(address: string, password: string, unlockDuration: number, callback?: (error: Error) => void): Promise<boolean>;
sendTransaction(
transation: Transaction,
password: string,
callback?: (error: Error, transactionHash: string) => void
): Promise<string>;

unlockAccount(
address: string,
password: string,
unlockDuration: number,
callback?: (error: Error) => void
): Promise<boolean>;

lockAccount(address: string, callback?: (error: Error, success: boolean) => void): Promise<boolean>;

getAccounts(callback?: (error: Error, accounts: string[]) => void): Promise<string[]>;

importRawKey(privateKey: string, password: string): Promise<string>;
}
60 changes: 51 additions & 9 deletions packages/web3-eth-personal/types/tests/personal-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,17 @@
*/
/**
* @file personal-tests.ts
* @author Huan Zhang <huanzhang30@gmail.com>, Samuel Furter <samuel@ethereum.org>
* @author Huan Zhang <huanzhang30@gmail.com>
* @author Samuel Furter <samuel@ethereum.org>
* @author Josh Stevens <joshstevens19@hotmail.co.uk>
* @date 2018
*/

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<string>
personal.newAccount('test password');
Expand All @@ -36,7 +33,12 @@ personal.newAccount('test password', (error: Error, address: string) => {});
// $ExpectType Promise<string>
personal.sign('Hello world', '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', 'test password!');
// $ExpectType Promise<string>
personal.sign('Hello world', '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', 'test password!', (error: Error, signature: string) => {});
personal.sign(
'Hello world',
'0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe',
'test password!',
(error: Error, signature: string) => {}
);

// $ExpectType Promise<string>
personal.ecRecover('Hello world', '0x30755ed65396facf86c53e6217c52b4daebe72aa');
Expand Down Expand Up @@ -67,9 +69,49 @@ personal.signTransaction(
},
'test password',
(error: Error, RLPEncodedTransaction: RLPEncodedTransaction) => {}
)
);

// $ExpectType Promise<string>
personal.sendTransaction(
{
from: '0xEB014f8c8B418Db6b45774c326A0E64C78914dC0',
gasPrice: '20000000000',
gas: '21000',
to: '0x3535353535353535353535353535353535353535',
value: '1000000000000000000',
data: ''
},
'test password'
);

// $ExpectType Promise<string>
personal.sendTransaction(
{
from: '0xEB014f8c8B418Db6b45774c326A0E64C78914dC0',
gasPrice: '20000000000',
gas: '21000',
to: '0x3535353535353535353535353535353535353535',
value: '1000000000000000000',
data: ''
},
'test password',
(error: Error, transactionHash: string) => {}
);

// $ExpectType Promise<boolean>
personal.unlockAccount('0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', 'test password!', 600);
// $ExpectType Promise<boolean>
personal.unlockAccount('0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', 'test password!', 600, (error: Error) => {});

// $ExpectType Promise<boolean>
personal.lockAccount('0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe');
// $ExpectType Promise<boolean>
personal.lockAccount('0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', (error: Error, sucess: boolean) => {});

// $ExpectType Promise<string[]>
personal.getAccounts();
// $ExpectType Promise<string[]>
personal.getAccounts((error: Error, accounts: string[]) => {});

// $ExpectType Promise<string>
personal.importRawKey('privateKey', 'blah2');
1 change: 1 addition & 0 deletions packages/web3-utils/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

import BigNumber from 'bn.js';
import {Buffer} from 'buffer';

export type Unit =
| 'noether'
Expand Down
17 changes: 17 additions & 0 deletions packages/web3/angular-patch.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
}
6 changes: 3 additions & 3 deletions packages/web3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"API"
],
"author": "ethereum.org",
"authors": [
{
"authors": [{
"name": "Samuel Furter",
"email": "samuel@ethereum.org",
"homepage": "https://github.com/nivida"
Expand Down Expand Up @@ -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": {
Expand Down

0 comments on commit f077f7a

Please sign in to comment.