diff --git a/packages/web3-eth-accounts/types/index.d.ts b/packages/web3-eth-accounts/types/index.d.ts index bec0d7c916a..30d6880308e 100644 --- a/packages/web3-eth-accounts/types/index.d.ts +++ b/packages/web3-eth-accounts/types/index.d.ts @@ -21,10 +21,7 @@ import {AbstractWeb3Module, Transaction, Web3ModuleOptions} from 'web3-core'; import {provider} from 'web3-providers'; export class Accounts extends AbstractWeb3Module { - constructor( - provider: provider, - options?: Web3ModuleOptions - ); + constructor(provider: provider, options?: Web3ModuleOptions); create(entropy?: string): Account; @@ -36,7 +33,7 @@ export class Accounts extends AbstractWeb3Module { hashMessage(message: string): string; - sign(data: string, privateKey: string): string | Sign; + sign(data: string, privateKey: string): Sign; recover(message: SignedTransaction): string; recover(message: string | SignedTransaction, signature: string, preFixed?: boolean): string; @@ -54,7 +51,7 @@ export class Wallet { create(numberOfAccounts: number, entropy?: string): Wallet; - add(account: string | Account): AddedAccount; + add(account: string | AddAccount): AddedAccount; remove(account: string | number): boolean; @@ -69,12 +66,20 @@ export class Wallet { load(password: string, keyName?: string): Wallet; } +export interface AddAccount { + address: string; + privateKey: string; +} + export interface Account { address: string; privateKey: string; - signTransaction?: (tx: Transaction) => {}; - sign?: (data: string) => {}; - encrypt?: (password: string) => {}; + signTransaction: ( + tx: Transaction, + callback?: (signTransaction: SignedTransaction) => void + ) => Promise; + sign: (data: string) => Sign; + encrypt: (password: string) => EncryptedKeystoreV3Json; } export interface AddedAccount extends Account { @@ -83,22 +88,22 @@ export interface AddedAccount extends Account { export interface EncryptedKeystoreV3Json { version: number; - id: string, - address: string, + id: string; + address: string; crypto: { - ciphertext: string, - cipherparams: {iv: string}, - cipher: string, - kdf: string, + ciphertext: string; + cipherparams: {iv: string}; + cipher: string; + kdf: string; kdfparams: { - dklen: number, - salt: string, - n: number, - r: number, - p: number - }, + dklen: number; + salt: string; + n: number; + r: number; + p: number; + }; mac: string; - } + }; } export interface SignedTransaction { diff --git a/packages/web3-eth-accounts/types/tests/accounts-tests.ts b/packages/web3-eth-accounts/types/tests/accounts-tests.ts index 78dcd8ec07f..ae5e1a7b56b 100644 --- a/packages/web3-eth-accounts/types/tests/accounts-tests.ts +++ b/packages/web3-eth-accounts/types/tests/accounts-tests.ts @@ -29,18 +29,27 @@ accounts.create('2435@#@#@±±±±!!!!678543213456764321§3456754321345678543213 accounts.privateKeyToAccount('0x348ce564d427a3311b6536bbcff9390d69395b06ed6c486954e971d960fe8709'); // $ExpectType Promise -accounts.signTransaction({ - to: '0xF0109fC8DF283027b6285cc889F5aA624EaC1F55', - value: '1000000000', - gas: 2000000 -}, '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318'); +accounts.signTransaction( + { + to: '0xF0109fC8DF283027b6285cc889F5aA624EaC1F55', + value: '1000000000', + gas: 2000000 + }, + '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318' +); // $ExpectType Promise -accounts.signTransaction({ - to: '0xF0109fC8DF283027b6285cc889F5aA624EaC1F55', - value: '1000000000', - gas: 2000000 -}, '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318', () => { console.log('hey') }); +accounts.signTransaction( + { + to: '0xF0109fC8DF283027b6285cc889F5aA624EaC1F55', + value: '1000000000', + gas: 2000000 + }, + '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318', + () => { + console.log('hey'); + } +); // $ExpectType string accounts.recoverTransaction('0xf861808084aefcdfa08e7d2ee3f0b9d9ae184b2001fe0aff07603d9'); @@ -48,7 +57,7 @@ accounts.recoverTransaction('0xf861808084aefcdfa08e7d2ee3f0b9d9ae184b2001fe0aff0 // $ExpectType string accounts.hashMessage('hello world'); -// $ExpectType string | Sign +// $ExpectType Sign accounts.sign('Some data', '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318'); // $ExpectType string @@ -60,34 +69,45 @@ accounts.recover({ }); // $ExpectType string -accounts.recover('Some data', '0xb91467e570a6466aa9e9876cbcd013baba02900b8979d43fe208a4a4f339f5fd6007e74cd82e037b800186422fc2da167c747ef045e5d18a5f5d4300f8e1a0291c'); +accounts.recover( + 'Some data', + '0xb91467e570a6466aa9e9876cbcd013baba02900b8979d43fe208a4a4f339f5fd6007e74cd82e037b800186422fc2da167c747ef045e5d18a5f5d4300f8e1a0291c' +); // $ExpectType string -accounts.recover('Some data', '0x1c', '0xb91467e570a6466aa9e9876cbcd013baba02900b8979d43fe208a4a4f339f5fd', '0x6007e74cd82e037b800186422fc2da167c747ef045e5d18a5f5d4300f8e1a029'); +accounts.recover( + 'Some data', + '0x1c', + '0xb91467e570a6466aa9e9876cbcd013baba02900b8979d43fe208a4a4f339f5fd', + '0x6007e74cd82e037b800186422fc2da167c747ef045e5d18a5f5d4300f8e1a029' +); // $ExpectType EncryptedKeystoreV3Json accounts.encrypt('0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318', 'test!'); // $ExpectType Account -accounts.decrypt({ - version: 3, - id: '04e9bcbb-96fa-497b-94d1-14df4cd20af6', - address: '2c7536e3605d9c16a7a3d7b1898e529396a65c23', - crypto: { - ciphertext: 'a1c25da3ecde4e6a24f3697251dd15d6208520efc84ad97397e906e6df24d251', - cipherparams: { iv: '2885df2b63f7ef247d753c82fa20038a' }, - cipher: 'aes-128-ctr', - kdf: 'scrypt', - kdfparams: { - dklen: 32, - salt: '4531b3c174cc3ff32a6a7a85d6761b410db674807b2d216d022318ceee50be10', - n: 262144, - r: 8, - p: 1 - }, - mac: 'b8b010fff37f9ae5559a352a185e86f9b9c1d7f7a9f1bd4e82a5dd35468fc7f6' - } -}, 'test!'); +accounts.decrypt( + { + version: 3, + id: '04e9bcbb-96fa-497b-94d1-14df4cd20af6', + address: '2c7536e3605d9c16a7a3d7b1898e529396a65c23', + crypto: { + ciphertext: 'a1c25da3ecde4e6a24f3697251dd15d6208520efc84ad97397e906e6df24d251', + cipherparams: {iv: '2885df2b63f7ef247d753c82fa20038a'}, + cipher: 'aes-128-ctr', + kdf: 'scrypt', + kdfparams: { + dklen: 32, + salt: '4531b3c174cc3ff32a6a7a85d6761b410db674807b2d216d022318ceee50be10', + n: 262144, + r: 8, + p: 1 + }, + mac: 'b8b010fff37f9ae5559a352a185e86f9b9c1d7f7a9f1bd4e82a5dd35468fc7f6' + } + }, + 'test!' +); // $ExpectType Wallet accounts.wallet.create(2); @@ -117,50 +137,49 @@ accounts.wallet.clear(); accounts.wallet.encrypt('test'); // $ExpectType Wallet -accounts.wallet.decrypt([ - { - version: 3, - id: '83191a81-aaca-451f-b63d-0c5f3b849289', - address: '06f702337909c06c82b09b7a22f0a2f0855d1f68', - crypto: +accounts.wallet.decrypt( + [ { - ciphertext: '7d34deae112841fba86e3e6cf08f5398dda323a8e4d29332621534e2c4069e8d', - cipherparams: { iv: '497f4d26997a84d570778eae874b2333' }, - cipher: 'aes-128-ctr', - kdf: 'scrypt', - kdfparams: - { - dklen: 32, - salt: '208dd732a27aa4803bb760228dff18515d5313fd085bbce60594a3919ae2d88d', - n: 262144, - r: 8, - p: 1 - }, - mac: '0062a853de302513c57bfe3108ab493733034bf3cb313326f42cf26ea2619cf9' - } - }, - { - version: 3, - id: '7d6b91fa-3611-407b-b16b-396efb28f97e', - address: 'b5d89661b59a9af0b34f58d19138baa2de48baaf', - crypto: + version: 3, + id: '83191a81-aaca-451f-b63d-0c5f3b849289', + address: '06f702337909c06c82b09b7a22f0a2f0855d1f68', + crypto: { + ciphertext: '7d34deae112841fba86e3e6cf08f5398dda323a8e4d29332621534e2c4069e8d', + cipherparams: {iv: '497f4d26997a84d570778eae874b2333'}, + cipher: 'aes-128-ctr', + kdf: 'scrypt', + kdfparams: { + dklen: 32, + salt: '208dd732a27aa4803bb760228dff18515d5313fd085bbce60594a3919ae2d88d', + n: 262144, + r: 8, + p: 1 + }, + mac: '0062a853de302513c57bfe3108ab493733034bf3cb313326f42cf26ea2619cf9' + } + }, { - ciphertext: 'cb9712d1982ff89f571fa5dbef447f14b7e5f142232bd2a913aac833730eeb43', - cipherparams: { iv: '8cccb91cb84e435437f7282ec2ffd2db' }, - cipher: 'aes-128-ctr', - kdf: 'scrypt', - kdfparams: - { - dklen: 32, - salt: '08ba6736363c5586434cd5b895e6fe41ea7db4785bd9b901dedce77a1514e8b8', - n: 262144, - r: 8, - p: 1 - }, - mac: 'd2eb068b37e2df55f56fa97a2bf4f55e072bef0dd703bfd917717d9dc54510f0' + version: 3, + id: '7d6b91fa-3611-407b-b16b-396efb28f97e', + address: 'b5d89661b59a9af0b34f58d19138baa2de48baaf', + crypto: { + ciphertext: 'cb9712d1982ff89f571fa5dbef447f14b7e5f142232bd2a913aac833730eeb43', + cipherparams: {iv: '8cccb91cb84e435437f7282ec2ffd2db'}, + cipher: 'aes-128-ctr', + kdf: 'scrypt', + kdfparams: { + dklen: 32, + salt: '08ba6736363c5586434cd5b895e6fe41ea7db4785bd9b901dedce77a1514e8b8', + n: 262144, + r: 8, + p: 1 + }, + mac: 'd2eb068b37e2df55f56fa97a2bf4f55e072bef0dd703bfd917717d9dc54510f0' + } } - } -], 'test'); + ], + 'test' +); // $ExpectType boolean accounts.wallet.save('test#!$');