Skip to content

Commit

Permalink
Merge pull request #2278 from joshstevens19/types/fix/missing-import-…
Browse files Browse the repository at this point in the history
…raw-key

write missing typing for `web3-eth-personal`
  • Loading branch information
nivida committed Feb 4, 2019
2 parents cc59698 + 9e32d2e commit 75a900e
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 20 deletions.
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');

0 comments on commit 75a900e

Please sign in to comment.