Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write missing typing for web3-eth-personal #2278

Merged
merged 3 commits into from
Feb 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');