diff --git a/types/web3/eth/accounts.d.ts b/types/web3/eth/accounts.d.ts index cd91e22183..8421d0d1bf 100644 --- a/types/web3/eth/accounts.d.ts +++ b/types/web3/eth/accounts.d.ts @@ -3,20 +3,31 @@ import { Tx } from "./types"; export interface Account { address: string; privateKey: string; - publicKey: string; + sign(data: string): MessageSignature; + signTransaction( + tx: Tx, + cb?: (err: Error, result: TxSignature) => void + ): Promise; + encrypt(password: string, options?: any): PrivateKey; } export interface Signature { - message: string; - hash: string; + messageHash: string; r: string; s: string; v: string; } +export interface MessageSignature extends Signature { + message: string; + signature: string; +} +export interface TxSignature extends Signature { + rawTransaction: string; +} export interface PrivateKey { address: string; - Crypto: { + crypto: { cipher: string; ciphertext: string; cipherparams: { @@ -43,15 +54,13 @@ export default interface Accounts { signTransaction( tx: Tx, privateKey: string, - returnSignature?: boolean, - cb?: (err: Error, result: string | Signature) => void - ): Promise | Signature; - recoverTransaction(signature: string | Signature): string; + cb?: (err: Error, result: TxSignature) => void + ): Promise; + recoverTransaction(signature: string): string; sign( data: string, - privateKey: string, - returnSignature?: boolean - ): string | Signature; + privateKey: string + ): MessageSignature; recover( sigOrHash: string | Signature, sigOrV?: string, diff --git a/types/web3/web3-tests.ts b/types/web3/web3-tests.ts index 923294b9c2..9a62331c50 100644 --- a/types/web3/web3-tests.ts +++ b/types/web3/web3-tests.ts @@ -39,6 +39,38 @@ myContract.options.gas = 5000000; // // web3.eth.accounts // -------------------------------------------------------------------------- +const account = web3.eth.accounts.privateKeyToAccount("0x1234"); + +// check that no `publicKey` field is present on `Account` type +const noPublicKeyInAccount: typeof account & { publicKey?: never } = account; + +const testTx = { + to: '0xF0109fC8DF283027b6285cc889F5aA624EaC1F55', + value: '1000000000', + gas: 2000000 +}; + +web3.eth.accounts.signTransaction(testTx, "").then(txSig => { + txSig.messageHash = "0x1234"; + txSig.rawTransaction = "0x5678"; + + const noHashFieldInTxSig: typeof txSig & { hash?: never, message?: never, signature?: never } = txSig; +}); + +const msgSig = web3.eth.accounts.sign("0x1234", "0x5678"); +msgSig.messageHash = "0x1234"; +msgSig.message = "0x5678"; +msgSig.signature = "0x90ab"; + +const noHashFieldInMsgSig: typeof msgSig & { hash?: never, rawTransaction?: never } = msgSig; + +const encryptedKeystore = web3.eth.accounts.encrypt("0x1234", "5678"); +encryptedKeystore.crypto.cipher = "aes-128-ctr"; + +const msgSignature: string = account.sign("0x1234").signature; +account.signTransaction(testTx).then(txSig => { + const txSignature: string = txSig.rawTransaction; +}); // // web3.eth.personal