diff --git a/packages/web3-core/types/index.d.ts b/packages/web3-core/types/index.d.ts index 4dcbaf133e5..aa0e09ab3fd 100644 --- a/packages/web3-core/types/index.d.ts +++ b/packages/web3-core/types/index.d.ts @@ -37,6 +37,8 @@ export class AbstractWeb3Module { readonly defaultBlock: string | number; readonly defaultAccount: string | null; readonly currentProvider: AbstractProviderAdapter; + readonly providers: Providers; + readonly givenProvider: provider | null; setProvider(provider: AbstractProviderAdapter | provider, net?: net.Server): boolean; isSameProvider(provider: AbstractProviderAdapter | provider): boolean; clearSubscriptions(): void; diff --git a/packages/web3-eth/types/index.d.ts b/packages/web3-eth/types/index.d.ts index f314477f544..186b12c456f 100644 --- a/packages/web3-eth/types/index.d.ts +++ b/packages/web3-eth/types/index.d.ts @@ -48,7 +48,7 @@ export class Eth extends AbstractWeb3Module { setProvider(provider: AbstractProviderAdapter | provider, net?: net.Server): boolean; readonly providers: Providers; readonly givenProvider: provider | null; - BatchRequest(): BatchRequest; + BatchRequest: new () => BatchRequest; getProtocolVersion(callback?: (error: Error, protocolVersion: string) => void): Promise; isSyncing(callback?: (error: Error, syncing: Syncing) => void): Promise; getCoinbase(callback?: (error: Error, coinbaseAddress: string) => void): Promise; diff --git a/packages/web3-eth/types/tests/eth.tests.ts b/packages/web3-eth/types/tests/eth.tests.ts index 943f1c478d2..f28f41f77cc 100644 --- a/packages/web3-eth/types/tests/eth.tests.ts +++ b/packages/web3-eth/types/tests/eth.tests.ts @@ -78,7 +78,7 @@ eth.providers; eth.givenProvider; // $ExpectType BatchRequest -eth.BatchRequest(); +new eth.BatchRequest(); // $ExpectType string | null eth.defaultAccount diff --git a/packages/web3-providers/types/index.d.ts b/packages/web3-providers/types/index.d.ts index 93f0b2d3484..b13cc95a46f 100644 --- a/packages/web3-providers/types/index.d.ts +++ b/packages/web3-providers/types/index.d.ts @@ -55,6 +55,7 @@ export class SocketProviderAdapter extends AbstractProviderAdapter { } export class BatchRequest { + constructor(); constructor(provider: provider, jsonRpcMapper: JsonRpcMapper, jsonRpcResponseValidator: JsonRpcResponseValidator); add(request: any): void; execute(): void; diff --git a/packages/web3-utils/types/index.d.ts b/packages/web3-utils/types/index.d.ts index cf479bfd59b..1dceba48a70 100644 --- a/packages/web3-utils/types/index.d.ts +++ b/packages/web3-utils/types/index.d.ts @@ -123,13 +123,60 @@ export function jsonInterfaceMethodToString(abiItem: ABIItem): string; export function soliditySha3(...val: Mixed[]): string; export function getUnitValue(unit: Unit): string; export function unitMap(): Units; - // bloom types export function testAddress(bloom: string, address: string): boolean; export function testTopic(bloom: string, topic: string): boolean; // interfaces +export interface Utils { + isBN(value: string | number): boolean; + isBigNumber(value: BN): boolean; + toBN(value: number | string): BN; + toTwosComplement(value: number | string | BN): string; + isAddress(address: string): boolean; + isHex(hex: Hex): boolean; + isHexStrict(hex: Hex): boolean; + asciiToHex(string: string): string; + hexToAscii(string: string): string; + toAscii(string: string): string; + bytesToHex(bytes: number[]): string; + numberToHex(value: number | string | BN): string; + checkAddressChecksum(address: string): boolean; + fromAscii(string: string): string; + fromDecimal(value: string | number): string; + fromUtf8(string: string): string; + fromWei(value: BN, unit?: Unit): BN | string; + hexToBytes(hex: Hex): number[]; + hexToNumber(hex: Hex): number; + hexToNumberString(hex: Hex): string; + hexToString(hex: Hex): string; + hexToUtf8(string: string): string; + keccak256(value: string | BN): string; + padLeft(value: string | number, characterAmount: number, sign?: string): string; + leftPad(string: string | number, characterAmount: number, sign?: string): string; + rightPad(string: string | number, characterAmount: number, sign?: string): string; + padRight(string: string | number, characterAmount: number, sign?: string): string; + sha3(value: string | BN): string; + randomHex(bytesSize: number): string; + utf8ToHex(string: string): string; + stringToHex(string: string): string; + toChecksumAddress(address: string): string; + toDecimal(hex: Hex): number; + toHex(value: number | string | BN): string; + toUtf8(string: string): string; + toWei(value: number | string | BN, unit?: Unit): string | BN; + isBloom(bloom: string): boolean; + isTopic(topic: string): boolean; + jsonInterfaceMethodToString(abiItem: ABIItem): string; + soliditySha3(...val: Mixed[]): string; + getUnitValue(unit: Unit): string; + unitMap(): Units; + // bloom types + testAddress(bloom: string, address: string): boolean; + testTopic(bloom: string, topic: string): boolean; +} + export interface Units { noether: string; wei: string; diff --git a/packages/web3/package-lock.json b/packages/web3/package-lock.json index be15212e803..6541f32c42d 100644 --- a/packages/web3/package-lock.json +++ b/packages/web3/package-lock.json @@ -195,6 +195,11 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.5.tgz", "integrity": "sha512-GzdHjq3t3eGLMv92Al90Iq+EoLL+86mPfQhuglbBFO7HiLdC/rkt+zrzJJumAiBF6nsrBWhou22rPW663AAyFw==" }, + "@types/parsimmon": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/@types/parsimmon/-/parsimmon-1.10.0.tgz", + "integrity": "sha512-bsTIJFVQv7jnvNiC42ld2pQW2KRI+pAG243L+iATvqzy3X6+NH1obz2itRKDZZ8VVhN3wjwYax/VBGCcXzgTqQ==" + }, "abstract-leveldown": { "version": "0.12.4", "resolved": "http://registry.npmjs.org/abstract-leveldown/-/abstract-leveldown-0.12.4.tgz", @@ -210,6 +215,11 @@ } } }, + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" + }, "ansi-styles": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", @@ -218,6 +228,19 @@ "color-convert": "^1.9.0" } }, + "any-promise": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz", + "integrity": "sha1-q8av7tzqUugJzcA3au0845Y10X8=" + }, + "argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "requires": { + "sprintf-js": "~1.0.2" + } + }, "arr-diff": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/arr-diff/-/arr-diff-2.0.0.tgz", @@ -246,6 +269,50 @@ "minimalistic-assert": "^1.0.0" } }, + "babel-code-frame": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", + "integrity": "sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=", + "requires": { + "chalk": "^1.1.3", + "esutils": "^2.0.2", + "js-tokens": "^3.0.2" + }, + "dependencies": { + "ansi-styles": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", + "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=" + }, + "chalk": { + "version": "1.1.3", + "resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", + "requires": { + "ansi-styles": "^2.2.1", + "escape-string-regexp": "^1.0.2", + "has-ansi": "^2.0.0", + "strip-ansi": "^3.0.0", + "supports-color": "^2.0.0" + } + }, + "js-tokens": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", + "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=" + }, + "supports-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", + "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=" + } + } + }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" + }, "bl": { "version": "0.8.2", "resolved": "http://registry.npmjs.org/bl/-/bl-0.8.2.tgz", @@ -282,6 +349,15 @@ "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz", "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==" }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, "braces": { "version": "1.8.5", "resolved": "https://registry.npmjs.org/braces/-/braces-1.8.5.tgz", @@ -429,6 +505,16 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" }, + "commander": { + "version": "2.19.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.19.0.tgz", + "integrity": "sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg==" + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + }, "concat-stream": { "version": "1.6.2", "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", @@ -521,6 +607,14 @@ "abstract-leveldown": "~0.12.1" } }, + "definitelytyped-header-parser": { + "version": "github:Microsoft/definitelytyped-header-parser#e0561530379dfa01324a89936b75d90b20df9bd2", + "from": "github:Microsoft/definitelytyped-header-parser#production", + "requires": { + "@types/parsimmon": "^1.3.0", + "parsimmon": "^1.2.0" + } + }, "des.js": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/des.js/-/des.js-1.0.0.tgz", @@ -530,6 +624,11 @@ "minimalistic-assert": "^1.0.0" } }, + "diff": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", + "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==" + }, "diffie-hellman": { "version": "5.0.3", "resolved": "http://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz", @@ -540,6 +639,18 @@ "randombytes": "^2.0.0" } }, + "dtslint": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/dtslint/-/dtslint-0.3.0.tgz", + "integrity": "sha512-3oWL8MD+2nKaxmNzrt8EAissP63hNSJ4OLr/itvNnPdAAl+7vxnjQ8p2Zdk0MNgdenqwk7GcaUDz7fQHaPgCyA==", + "requires": { + "definitelytyped-header-parser": "github:Microsoft/definitelytyped-header-parser#e0561530379dfa01324a89936b75d90b20df9bd2", + "fs-promise": "^2.0.0", + "strip-json-comments": "^2.0.1", + "tslint": "^5.9.1", + "typescript": "^3.3.0-dev.20181214" + } + }, "elliptic": { "version": "6.4.1", "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.1.tgz", @@ -575,6 +686,11 @@ "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" }, + "esprima": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==" + }, "estree-walker": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.5.2.tgz", @@ -653,6 +769,31 @@ "resolved": "https://registry.npmjs.org/foreach/-/foreach-2.0.5.tgz", "integrity": "sha1-C+4AUBiusmDQo6865ljdATbsG5k=" }, + "fs-extra": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-2.1.2.tgz", + "integrity": "sha1-BGxwFjzvmq1GsOSn+kZ/si1x3jU=", + "requires": { + "graceful-fs": "^4.1.2", + "jsonfile": "^2.1.0" + } + }, + "fs-promise": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/fs-promise/-/fs-promise-2.0.3.tgz", + "integrity": "sha1-9k5PhUvPaJqovdy6JokW2z20aFQ=", + "requires": { + "any-promise": "^1.3.0", + "fs-extra": "^2.0.0", + "mz": "^2.6.0", + "thenify-all": "^1.6.0" + } + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" + }, "fwd-stream": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/fwd-stream/-/fwd-stream-1.0.4.tgz", @@ -684,6 +825,19 @@ } } }, + "glob": { + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", + "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, "glob-base": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/glob-base/-/glob-base-0.3.0.tgz", @@ -711,6 +865,14 @@ "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz", "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==" }, + "has-ansi": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", + "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", + "requires": { + "ansi-regex": "^2.0.0" + } + }, "has-flag": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", @@ -759,6 +921,15 @@ "resolved": "https://registry.npmjs.org/indexof/-/indexof-0.0.1.tgz", "integrity": "sha1-gtwzbSMrkGIXnQWrMpOmYFn9Q10=" }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", @@ -869,6 +1040,15 @@ "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==" }, + "js-yaml": { + "version": "3.12.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.0.tgz", + "integrity": "sha512-PIt2cnwmPfL4hKNwqeiuz4bKfnzHTBv6HyVgjahA6mPLwPDzjDWrplJBMjHUFxku/N3FlmrbyPclad+I+4mJ3A==", + "requires": { + "argparse": "^1.0.7", + "esprima": "^4.0.0" + } + }, "jsesc": { "version": "2.5.2", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", @@ -884,6 +1064,14 @@ "resolved": "http://registry.npmjs.org/json5/-/json5-0.5.1.tgz", "integrity": "sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE=" }, + "jsonfile": { + "version": "2.4.0", + "resolved": "http://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz", + "integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=", + "requires": { + "graceful-fs": "^4.1.6" + } + }, "kind-of": { "version": "3.2.2", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", @@ -1155,11 +1343,29 @@ "resolved": "https://registry.npmjs.org/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz", "integrity": "sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo=" }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "requires": { + "brace-expansion": "^1.1.7" + } + }, "ms": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" }, + "mz": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz", + "integrity": "sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==", + "requires": { + "any-promise": "^1.0.0", + "object-assign": "^4.0.1", + "thenify-all": "^1.0.0" + } + }, "normalize-package-data": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.4.0.tgz", @@ -1179,6 +1385,11 @@ "remove-trailing-separator": "^1.0.1" } }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" + }, "object-keys": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-0.2.0.tgz", @@ -1243,6 +1454,16 @@ "json-parse-better-errors": "^1.0.1" } }, + "parsimmon": { + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/parsimmon/-/parsimmon-1.12.0.tgz", + "integrity": "sha512-uC/BjuSfb4jfaWajKCp1mVncXXq+V1twbcYChbTxN3GM7fn+8XoHwUdvUz+PTaFtDSCRQxU8+Rnh+iMhAkVwdw==" + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "http://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + }, "path-parse": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", @@ -1561,6 +1782,11 @@ "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.2.tgz", "integrity": "sha512-qky9CVt0lVIECkEsYbNILVnPvycuEBkXoMFLRWsREkomQLevYhtRKC+R91a5TOAQ3bCMjikRwhyaRqj1VYatYg==" }, + "sprintf-js": { + "version": "1.0.3", + "resolved": "http://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=" + }, "string-range": { "version": "1.2.2", "resolved": "http://registry.npmjs.org/string-range/-/string-range-1.2.2.tgz", @@ -1574,11 +1800,24 @@ "safe-buffer": "~5.1.0" } }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "requires": { + "ansi-regex": "^2.0.0" + } + }, "strip-bom": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=" }, + "strip-json-comments": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", + "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=" + }, "supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", @@ -1587,6 +1826,22 @@ "has-flag": "^3.0.0" } }, + "thenify": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.0.tgz", + "integrity": "sha1-5p44obq+lpsBCCB5eLn2K4hgSDk=", + "requires": { + "any-promise": "^1.0.0" + } + }, + "thenify-all": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/thenify-all/-/thenify-all-1.6.0.tgz", + "integrity": "sha1-GhkY1ALY/D+Y+/I02wvMjMEOlyY=", + "requires": { + "thenify": ">= 3.1.0 < 4" + } + }, "to-fast-properties": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", @@ -1597,6 +1852,38 @@ "resolved": "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz", "integrity": "sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM=" }, + "tslib": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", + "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==" + }, + "tslint": { + "version": "5.11.0", + "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.11.0.tgz", + "integrity": "sha1-mPMMAurjzecAYgHkwzywi0hYHu0=", + "requires": { + "babel-code-frame": "^6.22.0", + "builtin-modules": "^1.1.1", + "chalk": "^2.3.0", + "commander": "^2.12.1", + "diff": "^3.2.0", + "glob": "^7.1.1", + "js-yaml": "^3.7.0", + "minimatch": "^3.0.4", + "resolve": "^1.3.2", + "semver": "^5.3.0", + "tslib": "^1.8.0", + "tsutils": "^2.27.2" + } + }, + "tsutils": { + "version": "2.29.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz", + "integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==", + "requires": { + "tslib": "^1.8.1" + } + }, "typedarray": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", @@ -1607,6 +1894,11 @@ "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-1.0.4.tgz", "integrity": "sha1-m7i6DoQfs/TPH+fCRenz+opf6Zw=" }, + "typescript": { + "version": "3.3.0-dev.20181214", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.3.0-dev.20181214.tgz", + "integrity": "sha512-dy3hilVp3gHsKEqj837gzo6YLn5IuX+5obTkdLJuvceYQ1B/fBnj4Y+FB44IQdmZ4oaeQd5+7u+uI6vDvp5FhQ==" + }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", diff --git a/packages/web3/package.json b/packages/web3/package.json index 374f3229e22..899da7e71a7 100644 --- a/packages/web3/package.json +++ b/packages/web3/package.json @@ -51,8 +51,10 @@ "scripts": { "build": "rollup -c", "dev": "rollup -c -w", - "test": "jest" + "test": "jest", + "dtslint": "dtslint types" }, + "types": "types", "dependencies": { "web3-bzz": "1.0.0-beta.36", "web3-core": "1.0.0-beta.36", @@ -76,9 +78,11 @@ "rollup-plugin-commonjs": "^9.1.0", "rollup-plugin-json": "^3.1.0", "rollup-plugin-node-builtins": "^2.1.2", - "rollup-plugin-node-resolve": "^3.4.0" + "rollup-plugin-node-resolve": "^3.4.0", + "dtslint": "^0.3.0" }, "files": [ - "dist" + "dist", + "types/index.d.ts" ] } diff --git a/packages/web3/types/index.d.ts b/packages/web3/types/index.d.ts new file mode 100644 index 00000000000..a79242aab41 --- /dev/null +++ b/packages/web3/types/index.d.ts @@ -0,0 +1,53 @@ +/* + This file is part of web3.js. + web3.js is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + web3.js is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + You should have received a copy of the GNU Lesser General Public License + along with web3.js. If not, see . +*/ +/** + * @file index.d.ts + * @author Josh Stevens + * @date 2018 + */ + +import {AbstractWeb3Module, Web3ModuleOptions, Providers} from 'web3-core'; +import {Utils} from 'web3-utils'; +import * as net from 'net'; +import {provider, AbstractProviderAdapter, BatchRequest} from 'web3-providers'; +import {Eth} from 'web3-eth'; +import {Network} from 'web3-net'; + +export class Web3 extends AbstractWeb3Module { + constructor( + provider: AbstractProviderAdapter | provider, + net?: net.Server, + options?: Web3ModuleOptions + ); + static utils: Utils; + utils: Utils; + static version: string; + version: string; + static givenProvider: provider; + static providers: Providers; + static modules: Modules; + setProvider(provider: provider, net?: net.Server): boolean; + BatchRequest: new () => BatchRequest; + eth: Eth; + shh: any; // coming when shh types are written; + bzz: any; // coming when bzz types are written; +} + +export interface Modules { + Eth: Eth; + Net: Network; + Personal: any; // coming when personal types are written + Shh: any; // coming when shh types are written; + Bzz: any; // coming when bzz types are written; +} diff --git a/packages/web3/types/tests/web3-test.ts b/packages/web3/types/tests/web3-test.ts new file mode 100644 index 00000000000..c2f51393c36 --- /dev/null +++ b/packages/web3/types/tests/web3-test.ts @@ -0,0 +1,98 @@ +/* + This file is part of web3.js. + web3.js is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + web3.js is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + You should have received a copy of the GNU Lesser General Public License + along with web3.js. If not, see . +*/ +/** + * @file web3-test.ts + * @author Josh Stevens + * @date 2018 + */ + +import {Web3} from 'web3'; +import {HttpProvider} from 'web3-providers'; + +// $ExpectType Utils +Web3.utils; + +// $ExpectType string +Web3.version; + +// $ExpectType provider +Web3.givenProvider; + +// $ExpectType Providers +Web3.providers; + +// $ExpectType Modules +Web3.modules; + +const web3 = new Web3('https://localhost:5000/'); + +// $ExpectType Utils +web3.utils; + +// $ExpectType string +web3.version; + +// $ExpectType Eth +web3.eth; + +// $ExpectType any +web3.shh; + +// $ExpectType any +web3.bzz; + +// $ExpectType boolean +web3.setProvider(new HttpProvider('https://localhost:1234/')); +// $ExpectType boolean +web3.eth.setProvider(new HttpProvider('https://localhost:1234/')); +// $ExpectType any +web3.shh.setProvider(new HttpProvider('https://localhost:1234/')); +// $ExpectType any +web3.bzz.setProvider(new HttpProvider('https://localhost:1234/')); + +// $ExpectType Providers +web3.providers; +// $ExpectType Providers +web3.eth.providers; +// $ExpectType any +web3.shh.providers; +// $ExpectType any +web3.bzz.providers; + +// $ExpectType string | HttpProvider | IpcProvider | WebsocketProvider | null +web3.givenProvider; +// $ExpectType string | HttpProvider | IpcProvider | WebsocketProvider | null +web3.eth.givenProvider; +// $ExpectType any +web3.shh.givenProvider; +// $ExpectType any +web3.bzz.givenProvider; + +// $ExpectType AbstractProviderAdapter +web3.currentProvider; +// $ExpectType AbstractProviderAdapter +web3.eth.currentProvider; +// $ExpectType any +web3.shh.currentProvider; +// $ExpectType any +web3.bzz.currentProvider; + +// $ExpectType BatchRequest +new web3.BatchRequest(); +// $ExpectType BatchRequest +new web3.eth.BatchRequest(); +// $ExpectType any +new web3.shh.BatchRequest(); +// $ExpectType any +new web3.bzz.BatchRequest(); diff --git a/packages/web3/types/tsconfig.json b/packages/web3/types/tsconfig.json new file mode 100644 index 00000000000..9007fc9c010 --- /dev/null +++ b/packages/web3/types/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "target": "es6", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "noEmit": true, + "allowSyntheticDefaultImports": true, + "baseUrl": ".", + "paths": { + "web3": ["."] + } + } +} diff --git a/packages/web3/types/tslint.json b/packages/web3/types/tslint.json new file mode 100644 index 00000000000..871d605704b --- /dev/null +++ b/packages/web3/types/tslint.json @@ -0,0 +1,11 @@ +{ + "extends": "dtslint/dtslint.json", + "rules": { + "semicolon": false, + "no-import-default-of-export-equals": false, + "file-name-casing": [true, "kebab-case"], + "whitespace": false, + "no-unnecessary-class": false, + "unified-signatures": false + } +}