Compare commits

..

18 Commits

Author SHA1 Message Date
Richard Moore
fbf15c0ffe Fixed testnet exteneded private keys (#553). 2019-06-28 15:38:19 -04:00
Richard Moore
10fdbe7274 Updated dist files. 2019-06-21 19:18:49 -04:00
Richard Moore
384fc328f2 No longer use hard-coded id of 42 in Web3Provider. 2019-06-21 19:17:55 -04:00
Richard Moore
055694ae61 Updated dist files. 2019-06-10 02:00:55 -04:00
Richard Moore
edf59d2c26 Updatd dist files. 2019-06-10 01:59:51 -04:00
Richard Moore
92c978e5c2 Fixed error in throwing an error for ABI decode (#539). 2019-06-10 01:57:03 -04:00
Richard Moore
34397fa2aa Updated dist files. 2019-05-24 19:41:38 -04:00
Richard Moore
19587eea3f Warn on deprecated INFURA API Token; use Project ID instead (#462). 2019-05-24 14:56:47 -04:00
Richard Moore
4a9373e773 Fixed typo in error message (#470). 2019-05-24 14:48:01 -04:00
Richard Moore
2997bae935 Export poll function (#514). 2019-05-24 14:38:54 -04:00
Richard Moore
b0bd9ee162 Updated dist files. 2019-05-23 18:58:05 -04:00
Richard Moore
7075c8c235 Fixed error message for unconfigured ENS names (#504). 2019-05-23 18:51:08 -04:00
Richard Moore
a4a532fe8e Fixed security recommendations (development deps only; not a problem, but quiets automatic audits). 2019-05-14 18:11:45 -04:00
Richard Moore
77c771bf76 Updated dist files. 2019-05-14 17:45:13 -04:00
Richard Moore
c93b48920e Increment JSON-RPC ID for JsonRpcProviders for environments that unsafely manage callbacks (#489). 2019-04-18 13:49:37 +02:00
Richard Moore
04c92bb8d5 Updated dist files. 2019-03-08 14:29:59 -05:00
Richard Moore
16c9745326 Added goerli to InfuraProvider (#421). 2019-03-08 14:28:39 -05:00
Richard Moore
05648177aa Updated dist files. 2019-02-15 13:44:33 -05:00
31 changed files with 595 additions and 471 deletions

2
_version.d.ts vendored
View File

@@ -1 +1 @@
export declare const version = "4.0.25";
export declare const version = "4.0.31";

View File

@@ -1,3 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.version = "4.0.25";
exports.version = "4.0.31";

102
dist/ethers.js vendored
View File

@@ -1,7 +1,7 @@
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ethers = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.version = "4.0.25";
exports.version = "4.0.31";
},{}],2:[function(require,module,exports){
"use strict";
@@ -10076,6 +10076,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
var address_1 = require("../utils/address");
var bignumber_1 = require("../utils/bignumber");
var bytes_1 = require("../utils/bytes");
var constants_1 = require("../constants");
var hash_1 = require("../utils/hash");
var networks_1 = require("../utils/networks");
var properties_1 = require("../utils/properties");
@@ -10712,18 +10713,20 @@ var BaseProvider = /** @class */ (function (_super) {
if (confirmations == null) {
confirmations = 1;
}
if (confirmations === 0) {
return this.getTransactionReceipt(transactionHash);
}
return new Promise(function (resolve) {
var handler = function (receipt) {
if (receipt.confirmations < confirmations) {
return;
}
_this.removeListener(transactionHash, handler);
resolve(receipt);
};
_this.on(transactionHash, handler);
return this.getTransactionReceipt(transactionHash).then(function (receipt) {
if (confirmations === 0 || (receipt && receipt.confirmations >= confirmations)) {
return receipt;
}
return (new Promise(function (resolve) {
var handler = function (receipt) {
if (receipt.confirmations < confirmations) {
return;
}
_this.removeListener(transactionHash, handler);
resolve(receipt);
};
_this.on(transactionHash, handler);
}));
});
};
BaseProvider.prototype.getBlockNumber = function () {
@@ -10752,7 +10755,7 @@ var BaseProvider = /** @class */ (function (_super) {
return this.ready.then(function () {
return properties_1.resolveProperties({ addressOrName: addressOrName, blockTag: blockTag }).then(function (_a) {
var addressOrName = _a.addressOrName, blockTag = _a.blockTag;
return _this.resolveName(addressOrName).then(function (address) {
return _this._getAddress(addressOrName).then(function (address) {
var params = { address: address, blockTag: checkBlockTag(blockTag) };
return _this.perform('getBalance', params).then(function (result) {
return bignumber_1.bigNumberify(result);
@@ -10766,7 +10769,7 @@ var BaseProvider = /** @class */ (function (_super) {
return this.ready.then(function () {
return properties_1.resolveProperties({ addressOrName: addressOrName, blockTag: blockTag }).then(function (_a) {
var addressOrName = _a.addressOrName, blockTag = _a.blockTag;
return _this.resolveName(addressOrName).then(function (address) {
return _this._getAddress(addressOrName).then(function (address) {
var params = { address: address, blockTag: checkBlockTag(blockTag) };
return _this.perform('getTransactionCount', params).then(function (result) {
return bignumber_1.bigNumberify(result).toNumber();
@@ -10780,7 +10783,7 @@ var BaseProvider = /** @class */ (function (_super) {
return this.ready.then(function () {
return properties_1.resolveProperties({ addressOrName: addressOrName, blockTag: blockTag }).then(function (_a) {
var addressOrName = _a.addressOrName, blockTag = _a.blockTag;
return _this.resolveName(addressOrName).then(function (address) {
return _this._getAddress(addressOrName).then(function (address) {
var params = { address: address, blockTag: checkBlockTag(blockTag) };
return _this.perform('getCode', params).then(function (result) {
return bytes_1.hexlify(result);
@@ -10794,7 +10797,7 @@ var BaseProvider = /** @class */ (function (_super) {
return this.ready.then(function () {
return properties_1.resolveProperties({ addressOrName: addressOrName, position: position, blockTag: blockTag }).then(function (_a) {
var addressOrName = _a.addressOrName, position = _a.position, blockTag = _a.blockTag;
return _this.resolveName(addressOrName).then(function (address) {
return _this._getAddress(addressOrName).then(function (address) {
var params = {
address: address,
blockTag: checkBlockTag(blockTag),
@@ -11037,6 +11040,14 @@ var BaseProvider = /** @class */ (function (_super) {
});
});
};
BaseProvider.prototype._getAddress = function (addressOrName) {
return this.resolveName(addressOrName).then(function (address) {
if (address == null) {
errors.throwError("ENS name not configured", errors.UNSUPPORTED_OPERATION, { operation: "resolveName(" + JSON.stringify(addressOrName) + ")" });
}
return address;
});
};
// @TODO: Could probably use resolveProperties instead?
BaseProvider.prototype._resolveNames = function (object, keys) {
var promises = [];
@@ -11045,7 +11056,7 @@ var BaseProvider = /** @class */ (function (_super) {
if (result[key] == null) {
return;
}
promises.push(this.resolveName(result[key]).then(function (address) {
promises.push(this._getAddress(result[key]).then(function (address) {
result[key] = address;
return;
}));
@@ -11068,7 +11079,11 @@ var BaseProvider = /** @class */ (function (_super) {
if (bytes_1.hexDataLength(data) !== 32) {
return null;
}
return address_1.getAddress(bytes_1.hexDataSlice(data, 12));
var address = address_1.getAddress(bytes_1.hexDataSlice(data, 12));
if (address === constants_1.AddressZero) {
return null;
}
return address;
});
});
};
@@ -11089,6 +11104,9 @@ var BaseProvider = /** @class */ (function (_super) {
var nodeHash = hash_1.namehash(name);
// Get the addr from the resovler
return this._getResolver(name).then(function (resolverAddress) {
if (resolverAddress == null) {
return null;
}
// keccak256('addr(bytes32)')
var data = '0x3b3b57de' + nodeHash.substring(2);
var transaction = { to: resolverAddress, data: data };
@@ -11099,7 +11117,7 @@ var BaseProvider = /** @class */ (function (_super) {
return null;
}
var address = address_1.getAddress(bytes_1.hexDataSlice(data, 12));
if (address === '0x0000000000000000000000000000000000000000') {
if (address === constants_1.AddressZero) {
return null;
}
return address;
@@ -11271,7 +11289,7 @@ var BaseProvider = /** @class */ (function (_super) {
exports.BaseProvider = BaseProvider;
properties_1.defineReadOnly(abstract_provider_1.Provider, 'inherits', properties_1.inheritable(abstract_provider_1.Provider));
},{"../errors":5,"../utils/address":59,"../utils/bignumber":62,"../utils/bytes":63,"../utils/hash":64,"../utils/networks":71,"../utils/properties":73,"../utils/rlp":75,"../utils/transaction":82,"../utils/utf8":84,"../utils/web":85,"./abstract-provider":49}],51:[function(require,module,exports){
},{"../constants":3,"../errors":5,"../utils/address":59,"../utils/bignumber":62,"../utils/bytes":63,"../utils/hash":64,"../utils/networks":71,"../utils/properties":73,"../utils/rlp":75,"../utils/transaction":82,"../utils/utf8":84,"../utils/web":85,"./abstract-provider":49}],51:[function(require,module,exports){
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
@@ -11799,6 +11817,9 @@ var InfuraProvider = /** @class */ (function (_super) {
case 'rinkeby':
host = 'rinkeby.infura.io';
break;
case 'goerli':
host = 'goerli.infura.io';
break;
case 'kovan':
host = 'kovan.infura.io';
break;
@@ -11816,6 +11837,7 @@ var InfuraProvider = /** @class */ (function (_super) {
// Legacy API Access Token
}
else {
errors.warn("The legacy INFURA apiAccesToken API is deprecated; please upgrade to a Project ID instead (see INFURA dshboard; https://infura.io)");
_this = _super.call(this, 'https://' + host + '/' + projectId, standard) || this;
properties_1.defineReadOnly(_this, 'apiAccessToken', projectId);
properties_1.defineReadOnly(_this, 'projectId', null);
@@ -11894,6 +11916,10 @@ function getLowerCase(value) {
return value;
}
var _constructorGuard = {};
// Some environments (Trust Wallet and company) use a global map
// to track JSON-RPC ID, so we try to keep IDs unique across all
// connections. See #489.
var _nextId = 42;
var JsonRpcSigner = /** @class */ (function (_super) {
__extends(JsonRpcSigner, _super);
function JsonRpcSigner(constructorGuard, provider, addressOrIndex) {
@@ -11998,7 +12024,7 @@ var JsonRpcSigner = /** @class */ (function (_super) {
}
return _this.provider._wrapTransaction(tx, hash);
});
}, { onceBlock: _this.provider }).catch(function (error) {
}, { fastRetry: 250, onceBlock: _this.provider }).catch(function (error) {
error.transactionHash = hash;
throw error;
});
@@ -12080,7 +12106,7 @@ var JsonRpcProvider = /** @class */ (function (_super) {
var request = {
method: method,
params: params,
id: 42,
id: (_nextId++),
jsonrpc: "2.0"
};
return web_1.fetchJson(this.connection, JSON.stringify(request), getResult).then(function (result) {
@@ -12266,6 +12292,7 @@ utils.defineProperty(Web3Signer, 'onchange', {
});
*/
var _nextId = 42;
var Web3Provider = /** @class */ (function (_super) {
__extends(Web3Provider, _super);
function Web3Provider(web3Provider, network) {
@@ -12299,7 +12326,7 @@ var Web3Provider = /** @class */ (function (_super) {
var request = {
method: method,
params: params,
id: 42,
id: (_nextId++),
jsonrpc: "2.0"
};
_this._sendAsync(request, function (error, result) {
@@ -12309,10 +12336,10 @@ var Web3Provider = /** @class */ (function (_super) {
}
if (result.error) {
// @TODO: not any
var error = new Error(result.error.message);
error.code = result.error.code;
error.data = result.error.data;
reject(error);
var error_1 = new Error(result.error.message);
error_1.code = result.error.code;
error_1.data = result.error.data;
reject(error_1);
return;
}
resolve(result.result);
@@ -12806,7 +12833,7 @@ var CoderFixedBytes = /** @class */ (function (_super) {
};
CoderFixedBytes.prototype.decode = function (data, offset) {
if (data.length < offset + 32) {
errors.throwError('insufficient data for ' + name + ' type', errors.INVALID_ARGUMENT, {
errors.throwError('insufficient data for ' + this.name + ' type', errors.INVALID_ARGUMENT, {
arg: this.localName,
coderType: this.name,
value: bytes_1.hexlify(data.slice(offset, offset + 32))
@@ -14532,6 +14559,7 @@ exports.formatUnits = units_1.formatUnits;
exports.parseUnits = units_1.parseUnits;
var web_1 = require("./web");
exports.fetchJson = web_1.fetchJson;
exports.poll = web_1.poll;
////////////////////////
// Enums
var hmac_1 = require("./hmac");
@@ -15066,12 +15094,7 @@ var networks = {
chainId: 5,
ensAddress: "0x112234455c3a32fd11230c42e7bccd4a84e02010",
name: "goerli",
_defaultProvider: function (providers) {
if (providers.EtherscanProvider) {
return new providers.EtherscanProvider("goerli");
}
return null;
}
_defaultProvider: ethDefaultProvider('goerli')
},
kovan: {
chainId: 42,
@@ -16724,7 +16747,7 @@ function parseBytes32String(bytes) {
throw new Error('invalid bytes32 - not 32 bytes long');
}
if (data[31] !== 0) {
throw new Error('invalid bytes32 sdtring - no null terminator');
throw new Error('invalid bytes32 string - no null terminator');
}
// Find the null termination
var length = 31;
@@ -16918,6 +16941,7 @@ function poll(func, options) {
}
}, options.timeout);
}
var fastTimeout = options.fastRetry || null;
var attempt = 0;
function check() {
return func().then(function (result) {
@@ -16940,6 +16964,12 @@ function poll(func, options) {
if (timeout > options.ceiling) {
timeout = options.ceiling;
}
// Fast Timeout, means we quickly try again the first time
if (fastTimeout) {
attempt--;
timeout = fastTimeout;
fastTimeout = null;
}
setTimeout(check, timeout);
}
return null;

2
dist/ethers.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -232,7 +232,7 @@ declare module 'ethers/utils' {
import { parse as parseTransaction, serialize as serializeTransaction } from 'ethers/utils/transaction';
import { formatBytes32String, parseBytes32String, toUtf8Bytes, toUtf8String } from 'ethers/utils/utf8';
import { commify, formatEther, parseEther, formatUnits, parseUnits } from 'ethers/utils/units';
import { fetchJson } from 'ethers/utils/web';
import { fetchJson, poll } from 'ethers/utils/web';
import { SupportedAlgorithms } from 'ethers/utils/hmac';
import { UnicodeNormalizationForm } from 'ethers/utils/utf8';
import { CoerceFunc, EventFragment, FunctionFragment, ParamType } from 'ethers/utils/abi-coder';
@@ -244,7 +244,7 @@ declare module 'ethers/utils' {
import { ConnectionInfo, OnceBlockable, PollOptions } from 'ethers/utils/web';
import { EncryptOptions, ProgressCallback } from 'ethers/utils/secret-storage';
import { Wordlist } from 'ethers/utils/wordlist';
export { AbiCoder, defaultAbiCoder, formatSignature, formatParamType, parseSignature, parseParamType, RLP, fetchJson, getNetwork, checkProperties, deepCopy, defineReadOnly, resolveProperties, shallowCopy, arrayify, concat, padZeros, stripZeros, HDNode, SigningKey, Interface, base64, BigNumber, bigNumberify, hexlify, isHexString, hexStripZeros, hexZeroPad, hexDataLength, hexDataSlice, toUtf8Bytes, toUtf8String, formatBytes32String, parseBytes32String, hashMessage, namehash, id, getAddress, getIcapAddress, getContractAddress, formatEther, parseEther, formatUnits, parseUnits, commify, keccak256, sha256, randomBytes, solidityPack, solidityKeccak256, soliditySha256, splitSignature, joinSignature, parseTransaction, populateTransaction, serializeTransaction, getJsonWalletAddress, computeAddress, computePublicKey, recoverAddress, recoverPublicKey, verifyMessage, SupportedAlgorithms, UnicodeNormalizationForm, CoerceFunc, EventFragment, FunctionFragment, ParamType, BigNumberish, Arrayish, Hexable, Signature, Indexed, DeployDescription, EventDescription, FunctionDescription, LogDescription, TransactionDescription, Network, Networkish, Transaction, UnsignedTransaction, ConnectionInfo, OnceBlockable, PollOptions, EncryptOptions, ProgressCallback, Wordlist, };
export { AbiCoder, defaultAbiCoder, formatSignature, formatParamType, parseSignature, parseParamType, RLP, fetchJson, getNetwork, checkProperties, deepCopy, defineReadOnly, resolveProperties, shallowCopy, arrayify, concat, padZeros, stripZeros, HDNode, SigningKey, Interface, base64, BigNumber, bigNumberify, hexlify, isHexString, hexStripZeros, hexZeroPad, hexDataLength, hexDataSlice, toUtf8Bytes, toUtf8String, formatBytes32String, parseBytes32String, hashMessage, namehash, id, getAddress, getIcapAddress, getContractAddress, formatEther, parseEther, formatUnits, parseUnits, commify, keccak256, sha256, randomBytes, solidityPack, solidityKeccak256, soliditySha256, splitSignature, joinSignature, parseTransaction, populateTransaction, serializeTransaction, getJsonWalletAddress, computeAddress, computePublicKey, recoverAddress, recoverPublicKey, verifyMessage, poll, SupportedAlgorithms, UnicodeNormalizationForm, CoerceFunc, EventFragment, FunctionFragment, ParamType, BigNumberish, Arrayish, Hexable, Signature, Indexed, DeployDescription, EventDescription, FunctionDescription, LogDescription, TransactionDescription, Network, Networkish, Transaction, UnsignedTransaction, ConnectionInfo, OnceBlockable, PollOptions, EncryptOptions, ProgressCallback, Wordlist, };
}
declare module 'ethers/wordlists' {
@@ -266,7 +266,7 @@ declare module 'ethers/utils/shims' {
}
declare module 'ethers/_version' {
export const version = "4.0.25";
export const version = "4.0.31";
}
declare module 'ethers/utils/bignumber' {
@@ -771,6 +771,7 @@ declare module 'ethers/providers/base-provider' {
getTransactionReceipt(transactionHash: string): Promise<TransactionReceipt>;
getLogs(filter: Filter | FilterByBlock): Promise<Array<Log>>;
getEtherPrice(): Promise<number>;
_getAddress(addressOrName: string): Promise<string>;
resolveName(name: string | Promise<string>): Promise<string>;
lookupAddress(address: string | Promise<string>): Promise<string>;
static checkTransactionResponse(transaction: any): TransactionResponse;
@@ -1041,6 +1042,7 @@ declare module 'ethers/utils/web' {
ceiling?: number;
interval?: number;
onceBlock?: OnceBlockable;
fastRetry?: number;
};
export function fetchJson(connection: string | ConnectionInfo, json: string, processFunc: (value: any) => any): Promise<any>;
export function poll(func: () => Promise<any>, options?: PollOptions): Promise<any>;

768
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "ethers",
"version": "4.0.25",
"version": "4.0.31",
"description": "Ethereum wallet library.",
"main": "./index.js",
"types": "./index.d.ts",
@@ -34,7 +34,7 @@
"browserify": "^16.2.3",
"browserify-zlib": "^0.2.0",
"dts-bundle": "^0.7.3",
"eslint": "^5.0.1",
"eslint": "^5.16.0",
"eslint-plugin-promise": "^3.8.0",
"ethereumjs-tx": "^1.3.5",
"ethereumjs-util": "^5.2.0",

View File

@@ -53,6 +53,7 @@ export declare class BaseProvider extends Provider {
getTransactionReceipt(transactionHash: string): Promise<TransactionReceipt>;
getLogs(filter: Filter | FilterByBlock): Promise<Array<Log>>;
getEtherPrice(): Promise<number>;
_getAddress(addressOrName: string): Promise<string>;
private _resolveNames;
private _getResolver;
resolveName(name: string | Promise<string>): Promise<string>;

View File

@@ -20,6 +20,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
var address_1 = require("../utils/address");
var bignumber_1 = require("../utils/bignumber");
var bytes_1 = require("../utils/bytes");
var constants_1 = require("../constants");
var hash_1 = require("../utils/hash");
var networks_1 = require("../utils/networks");
var properties_1 = require("../utils/properties");
@@ -656,18 +657,20 @@ var BaseProvider = /** @class */ (function (_super) {
if (confirmations == null) {
confirmations = 1;
}
if (confirmations === 0) {
return this.getTransactionReceipt(transactionHash);
}
return new Promise(function (resolve) {
var handler = function (receipt) {
if (receipt.confirmations < confirmations) {
return;
}
_this.removeListener(transactionHash, handler);
resolve(receipt);
};
_this.on(transactionHash, handler);
return this.getTransactionReceipt(transactionHash).then(function (receipt) {
if (confirmations === 0 || (receipt && receipt.confirmations >= confirmations)) {
return receipt;
}
return (new Promise(function (resolve) {
var handler = function (receipt) {
if (receipt.confirmations < confirmations) {
return;
}
_this.removeListener(transactionHash, handler);
resolve(receipt);
};
_this.on(transactionHash, handler);
}));
});
};
BaseProvider.prototype.getBlockNumber = function () {
@@ -696,7 +699,7 @@ var BaseProvider = /** @class */ (function (_super) {
return this.ready.then(function () {
return properties_1.resolveProperties({ addressOrName: addressOrName, blockTag: blockTag }).then(function (_a) {
var addressOrName = _a.addressOrName, blockTag = _a.blockTag;
return _this.resolveName(addressOrName).then(function (address) {
return _this._getAddress(addressOrName).then(function (address) {
var params = { address: address, blockTag: checkBlockTag(blockTag) };
return _this.perform('getBalance', params).then(function (result) {
return bignumber_1.bigNumberify(result);
@@ -710,7 +713,7 @@ var BaseProvider = /** @class */ (function (_super) {
return this.ready.then(function () {
return properties_1.resolveProperties({ addressOrName: addressOrName, blockTag: blockTag }).then(function (_a) {
var addressOrName = _a.addressOrName, blockTag = _a.blockTag;
return _this.resolveName(addressOrName).then(function (address) {
return _this._getAddress(addressOrName).then(function (address) {
var params = { address: address, blockTag: checkBlockTag(blockTag) };
return _this.perform('getTransactionCount', params).then(function (result) {
return bignumber_1.bigNumberify(result).toNumber();
@@ -724,7 +727,7 @@ var BaseProvider = /** @class */ (function (_super) {
return this.ready.then(function () {
return properties_1.resolveProperties({ addressOrName: addressOrName, blockTag: blockTag }).then(function (_a) {
var addressOrName = _a.addressOrName, blockTag = _a.blockTag;
return _this.resolveName(addressOrName).then(function (address) {
return _this._getAddress(addressOrName).then(function (address) {
var params = { address: address, blockTag: checkBlockTag(blockTag) };
return _this.perform('getCode', params).then(function (result) {
return bytes_1.hexlify(result);
@@ -738,7 +741,7 @@ var BaseProvider = /** @class */ (function (_super) {
return this.ready.then(function () {
return properties_1.resolveProperties({ addressOrName: addressOrName, position: position, blockTag: blockTag }).then(function (_a) {
var addressOrName = _a.addressOrName, position = _a.position, blockTag = _a.blockTag;
return _this.resolveName(addressOrName).then(function (address) {
return _this._getAddress(addressOrName).then(function (address) {
var params = {
address: address,
blockTag: checkBlockTag(blockTag),
@@ -981,6 +984,14 @@ var BaseProvider = /** @class */ (function (_super) {
});
});
};
BaseProvider.prototype._getAddress = function (addressOrName) {
return this.resolveName(addressOrName).then(function (address) {
if (address == null) {
errors.throwError("ENS name not configured", errors.UNSUPPORTED_OPERATION, { operation: "resolveName(" + JSON.stringify(addressOrName) + ")" });
}
return address;
});
};
// @TODO: Could probably use resolveProperties instead?
BaseProvider.prototype._resolveNames = function (object, keys) {
var promises = [];
@@ -989,7 +1000,7 @@ var BaseProvider = /** @class */ (function (_super) {
if (result[key] == null) {
return;
}
promises.push(this.resolveName(result[key]).then(function (address) {
promises.push(this._getAddress(result[key]).then(function (address) {
result[key] = address;
return;
}));
@@ -1012,7 +1023,11 @@ var BaseProvider = /** @class */ (function (_super) {
if (bytes_1.hexDataLength(data) !== 32) {
return null;
}
return address_1.getAddress(bytes_1.hexDataSlice(data, 12));
var address = address_1.getAddress(bytes_1.hexDataSlice(data, 12));
if (address === constants_1.AddressZero) {
return null;
}
return address;
});
});
};
@@ -1033,6 +1048,9 @@ var BaseProvider = /** @class */ (function (_super) {
var nodeHash = hash_1.namehash(name);
// Get the addr from the resovler
return this._getResolver(name).then(function (resolverAddress) {
if (resolverAddress == null) {
return null;
}
// keccak256('addr(bytes32)')
var data = '0x3b3b57de' + nodeHash.substring(2);
var transaction = { to: resolverAddress, data: data };
@@ -1043,7 +1061,7 @@ var BaseProvider = /** @class */ (function (_super) {
return null;
}
var address = address_1.getAddress(bytes_1.hexDataSlice(data, 12));
if (address === '0x0000000000000000000000000000000000000000') {
if (address === constants_1.AddressZero) {
return null;
}
return address;

View File

@@ -42,6 +42,9 @@ var InfuraProvider = /** @class */ (function (_super) {
case 'rinkeby':
host = 'rinkeby.infura.io';
break;
case 'goerli':
host = 'goerli.infura.io';
break;
case 'kovan':
host = 'kovan.infura.io';
break;
@@ -59,6 +62,7 @@ var InfuraProvider = /** @class */ (function (_super) {
// Legacy API Access Token
}
else {
errors.warn("The legacy INFURA apiAccesToken API is deprecated; please upgrade to a Project ID instead (see INFURA dshboard; https://infura.io)");
_this = _super.call(this, 'https://' + host + '/' + projectId, standard) || this;
properties_1.defineReadOnly(_this, 'apiAccessToken', projectId);
properties_1.defineReadOnly(_this, 'projectId', null);

View File

@@ -51,6 +51,10 @@ function getLowerCase(value) {
return value;
}
var _constructorGuard = {};
// Some environments (Trust Wallet and company) use a global map
// to track JSON-RPC ID, so we try to keep IDs unique across all
// connections. See #489.
var _nextId = 42;
var JsonRpcSigner = /** @class */ (function (_super) {
__extends(JsonRpcSigner, _super);
function JsonRpcSigner(constructorGuard, provider, addressOrIndex) {
@@ -155,7 +159,7 @@ var JsonRpcSigner = /** @class */ (function (_super) {
}
return _this.provider._wrapTransaction(tx, hash);
});
}, { onceBlock: _this.provider }).catch(function (error) {
}, { fastRetry: 250, onceBlock: _this.provider }).catch(function (error) {
error.transactionHash = hash;
throw error;
});
@@ -237,7 +241,7 @@ var JsonRpcProvider = /** @class */ (function (_super) {
var request = {
method: method,
params: params,
id: 42,
id: (_nextId++),
jsonrpc: "2.0"
};
return web_1.fetchJson(this.connection, JSON.stringify(request), getResult).then(function (result) {

View File

@@ -27,6 +27,7 @@ utils.defineProperty(Web3Signer, 'onchange', {
});
*/
var _nextId = 42;
var Web3Provider = /** @class */ (function (_super) {
__extends(Web3Provider, _super);
function Web3Provider(web3Provider, network) {
@@ -60,7 +61,7 @@ var Web3Provider = /** @class */ (function (_super) {
var request = {
method: method,
params: params,
id: 42,
id: (_nextId++),
jsonrpc: "2.0"
};
_this._sendAsync(request, function (error, result) {
@@ -70,10 +71,10 @@ var Web3Provider = /** @class */ (function (_super) {
}
if (result.error) {
// @TODO: not any
var error = new Error(result.error.message);
error.code = result.error.code;
error.data = result.error.data;
reject(error);
var error_1 = new Error(result.error.message);
error_1.code = result.error.code;
error_1.data = result.error.data;
reject(error_1);
return;
}
resolve(result.result);

View File

@@ -1 +1 @@
export const version = "4.0.25";
export const version = "4.0.31";

View File

@@ -3,6 +3,7 @@
import { getAddress, getContractAddress } from '../utils/address';
import { BigNumber, bigNumberify } from '../utils/bignumber';
import { hexDataLength, hexDataSlice, hexlify, hexStripZeros, isHexString, stripZeros } from '../utils/bytes';
import { AddressZero } from "../constants";
import { namehash } from '../utils/hash';
import { getNetwork } from '../utils/networks';
import { defineReadOnly, inheritable, resolveProperties, shallowCopy } from '../utils/properties';
@@ -816,7 +817,7 @@ export class BaseProvider extends Provider {
getBalance(addressOrName: string | Promise<string>, blockTag?: BlockTag | Promise<BlockTag>): Promise<BigNumber> {
return this.ready.then(() => {
return resolveProperties({ addressOrName: addressOrName, blockTag: blockTag }).then(({ addressOrName, blockTag }) => {
return this.resolveName(addressOrName).then((address) => {
return this._getAddress(addressOrName).then((address) => {
let params = { address: address, blockTag: checkBlockTag(blockTag) };
return this.perform('getBalance', params).then((result) => {
return bigNumberify(result);
@@ -829,7 +830,7 @@ export class BaseProvider extends Provider {
getTransactionCount(addressOrName: string | Promise<string>, blockTag?: BlockTag | Promise<BlockTag>): Promise<number> {
return this.ready.then(() => {
return resolveProperties({ addressOrName: addressOrName, blockTag: blockTag }).then(({ addressOrName, blockTag }) => {
return this.resolveName(addressOrName).then((address) => {
return this._getAddress(addressOrName).then((address) => {
let params = { address: address, blockTag: checkBlockTag(blockTag) };
return this.perform('getTransactionCount', params).then((result) => {
return bigNumberify(result).toNumber();
@@ -842,7 +843,7 @@ export class BaseProvider extends Provider {
getCode(addressOrName: string | Promise<string>, blockTag?: BlockTag | Promise<BlockTag>): Promise<string> {
return this.ready.then(() => {
return resolveProperties({ addressOrName: addressOrName, blockTag: blockTag }).then(({ addressOrName, blockTag }) => {
return this.resolveName(addressOrName).then((address) => {
return this._getAddress(addressOrName).then((address) => {
let params = {address: address, blockTag: checkBlockTag(blockTag)};
return this.perform('getCode', params).then((result) => {
return hexlify(result);
@@ -855,7 +856,7 @@ export class BaseProvider extends Provider {
getStorageAt(addressOrName: string | Promise<string>, position: BigNumberish | Promise<BigNumberish>, blockTag?: BlockTag | Promise<BlockTag>): Promise<string> {
return this.ready.then(() => {
return resolveProperties({ addressOrName: addressOrName, position: position, blockTag: blockTag }).then(({ addressOrName, position, blockTag }) => {
return this.resolveName(addressOrName).then((address) => {
return this._getAddress(addressOrName).then((address) => {
let params = {
address: address,
blockTag: checkBlockTag(blockTag),
@@ -1108,6 +1109,15 @@ export class BaseProvider extends Provider {
});
}
_getAddress(addressOrName: string): Promise<string> {
return this.resolveName(addressOrName).then((address) => {
if (address == null) {
errors.throwError("ENS name not configured", errors.UNSUPPORTED_OPERATION, { operation: "resolveName(" + JSON.stringify(addressOrName) + ")" });
}
return address;
});
}
// @TODO: Could probably use resolveProperties instead?
private _resolveNames(object: any, keys: Array<string>): Promise<{ [key: string]: string }> {
let promises: Array<Promise<void>> = [];
@@ -1116,7 +1126,7 @@ export class BaseProvider extends Provider {
keys.forEach(function(key) {
if (result[key] == null) { return; }
promises.push(this.resolveName(result[key]).then((address: string) => {
promises.push(this._getAddress(result[key]).then((address: string) => {
result[key] = address;
return;
}));
@@ -1143,10 +1153,11 @@ export class BaseProvider extends Provider {
let transaction = { to: network.ensAddress, data: data };
return this.call(transaction).then((data) => {
// extract the address from the data
if (hexDataLength(data) !== 32) { return null; }
return getAddress(hexDataSlice(data, 12));
let address = getAddress(hexDataSlice(data, 12));
if (address === AddressZero) { return null; }
return address;
});
});
}
@@ -1171,6 +1182,7 @@ export class BaseProvider extends Provider {
// Get the addr from the resovler
return this._getResolver(name).then(function(resolverAddress) {
if (resolverAddress == null) { return null; }
// keccak256('addr(bytes32)')
let data = '0x3b3b57de' + nodeHash.substring(2);
@@ -1181,7 +1193,7 @@ export class BaseProvider extends Provider {
}).then(function(data) {
if (hexDataLength(data) !== 32) { return null; }
let address = getAddress(hexDataSlice(data, 12));
if (address === '0x0000000000000000000000000000000000000000') { return null; }
if (address === AddressZero) { return null; }
return address;
});
}

View File

@@ -32,6 +32,9 @@ export class InfuraProvider extends JsonRpcProvider {
case 'rinkeby':
host = 'rinkeby.infura.io';
break;
case 'goerli':
host = 'goerli.infura.io';
break;
case 'kovan':
host = 'kovan.infura.io';
break;
@@ -50,6 +53,7 @@ export class InfuraProvider extends JsonRpcProvider {
// Legacy API Access Token
} else {
errors.warn("The legacy INFURA apiAccesToken API is deprecated; please upgrade to a Project ID instead (see INFURA dshboard; https://infura.io)");
super('https://' + host + '/' + projectId, standard);
defineReadOnly(this, 'apiAccessToken', projectId);
defineReadOnly(this, 'projectId', null);

View File

@@ -50,6 +50,11 @@ function getLowerCase(value: string): string {
const _constructorGuard = {};
// Some environments (Trust Wallet and company) use a global map
// to track JSON-RPC ID, so we try to keep IDs unique across all
// connections. See #489.
let _nextId = 42;
export class JsonRpcSigner extends Signer {
readonly provider: JsonRpcProvider;
private _index: number;
@@ -250,7 +255,7 @@ export class JsonRpcProvider extends BaseProvider {
let request = {
method: method,
params: params,
id: 42,
id: (_nextId++),
jsonrpc: "2.0"
};

View File

@@ -27,6 +27,8 @@ utils.defineProperty(Web3Signer, 'onchange', {
*/
let _nextId = 42;
export class Web3Provider extends JsonRpcProvider {
readonly _web3Provider: AsyncSendable;
private _sendAsync: (request: any, callback: (error: any, response: any) => void) => void;
@@ -65,10 +67,10 @@ export class Web3Provider extends JsonRpcProvider {
}
return new Promise((resolve, reject) => {
var request = {
let request = {
method: method,
params: params,
id: 42,
id: (_nextId++),
jsonrpc: "2.0"
};
@@ -80,7 +82,7 @@ export class Web3Provider extends JsonRpcProvider {
if (result.error) {
// @TODO: not any
var error: any = new Error(result.error.message);
let error: any = new Error(result.error.message);
error.code = result.error.code;
error.data = result.error.data;
reject(error);

View File

@@ -574,7 +574,7 @@ class CoderFixedBytes extends Coder {
decode(data: Uint8Array, offset: number): DecodedResult {
if (data.length < offset + 32) {
errors.throwError('insufficient data for ' + name + ' type', errors.INVALID_ARGUMENT, {
errors.throwError('insufficient data for ' + this.name + ' type', errors.INVALID_ARGUMENT, {
arg: this.localName,
coderType: this.name,
value: hexlify(data.slice(offset, offset + 32))

View File

@@ -240,7 +240,7 @@ export function fromExtendedKey(extendedKey: string): HDNode {
return new HDNode(_constructorGuard, null, hexlify(key), parentFingerprint, chainCode, index, depth, null, null);
// Private Key
case "0x0488ade4": case "0x04358394 ":
case "0x0488ade4": case "0x04358394":
if (key[0] !== 0) { break; }
return new HDNode(_constructorGuard, hexlify(key.slice(1)), null, parentFingerprint, chainCode, index, depth, null, null);
}

View File

@@ -22,7 +22,7 @@ import { populateTransaction } from './transaction';
import { parse as parseTransaction, serialize as serializeTransaction } from './transaction';
import { formatBytes32String, parseBytes32String, toUtf8Bytes, toUtf8String } from './utf8';
import { commify, formatEther, parseEther, formatUnits, parseUnits } from './units';
import { fetchJson } from './web';
import { fetchJson, poll } from './web';
////////////////////////
@@ -136,6 +136,8 @@ export {
recoverPublicKey,
verifyMessage,
poll,
////////////////////////
// Enums

View File

@@ -86,12 +86,7 @@ const networks: { [name: string]: Network } = {
chainId: 5,
ensAddress: "0x112234455c3a32fd11230c42e7bccd4a84e02010",
name: "goerli",
_defaultProvider: (providers: any): any => {
if (providers.EtherscanProvider) {
return new providers.EtherscanProvider("goerli");
}
return null;
}
_defaultProvider: ethDefaultProvider('goerli')
},
kovan: {

View File

@@ -190,7 +190,7 @@ export function parseBytes32String(bytes: Arrayish): string {
// Must be 32 bytes with a null-termination
if (data.length !== 32) { throw new Error('invalid bytes32 - not 32 bytes long'); }
if (data[31] !== 0) { throw new Error('invalid bytes32 sdtring - no null terminator'); }
if (data[31] !== 0) { throw new Error('invalid bytes32 string - no null terminator'); }
// Find the null termination
let length = 31;

View File

@@ -414,12 +414,6 @@ function testProvider(providerName, networkName) {
['default', 'homestead', 'ropsten', 'rinkeby', 'kovan', 'goerli'].forEach(function(networkName) {
['getDefaultProvider', 'InfuraProvider', 'EtherscanProvider', 'Web3Provider'].forEach(function(providerName) {
if (networkName === "goerli") {
if (providerName === "InfuraProvider" || providerName === "Web3Provider") {
return;
}
}
// @TODO: Remove this! Temporary because Etherscan is down
//if (providerName === 'EtherscanProvider') {
// console.log("******** Remove this soon! Etherscan is having issues.");

View File

@@ -480,7 +480,7 @@ var CoderFixedBytes = /** @class */ (function (_super) {
};
CoderFixedBytes.prototype.decode = function (data, offset) {
if (data.length < offset + 32) {
errors.throwError('insufficient data for ' + name + ' type', errors.INVALID_ARGUMENT, {
errors.throwError('insufficient data for ' + this.name + ' type', errors.INVALID_ARGUMENT, {
arg: this.localName,
coderType: this.name,
value: bytes_1.hexlify(data.slice(offset, offset + 32))

4
utils/index.d.ts vendored
View File

@@ -20,7 +20,7 @@ import { populateTransaction } from './transaction';
import { parse as parseTransaction, serialize as serializeTransaction } from './transaction';
import { formatBytes32String, parseBytes32String, toUtf8Bytes, toUtf8String } from './utf8';
import { commify, formatEther, parseEther, formatUnits, parseUnits } from './units';
import { fetchJson } from './web';
import { fetchJson, poll } from './web';
import { SupportedAlgorithms } from './hmac';
import { UnicodeNormalizationForm } from './utf8';
import { CoerceFunc, EventFragment, FunctionFragment, ParamType } from './abi-coder';
@@ -32,4 +32,4 @@ import { Transaction, UnsignedTransaction } from './transaction';
import { ConnectionInfo, OnceBlockable, PollOptions } from './web';
import { EncryptOptions, ProgressCallback } from './secret-storage';
import { Wordlist } from './wordlist';
export { AbiCoder, defaultAbiCoder, formatSignature, formatParamType, parseSignature, parseParamType, RLP, fetchJson, getNetwork, checkProperties, deepCopy, defineReadOnly, resolveProperties, shallowCopy, arrayify, concat, padZeros, stripZeros, HDNode, SigningKey, Interface, base64, BigNumber, bigNumberify, hexlify, isHexString, hexStripZeros, hexZeroPad, hexDataLength, hexDataSlice, toUtf8Bytes, toUtf8String, formatBytes32String, parseBytes32String, hashMessage, namehash, id, getAddress, getIcapAddress, getContractAddress, formatEther, parseEther, formatUnits, parseUnits, commify, keccak256, sha256, randomBytes, solidityPack, solidityKeccak256, soliditySha256, splitSignature, joinSignature, parseTransaction, populateTransaction, serializeTransaction, getJsonWalletAddress, computeAddress, computePublicKey, recoverAddress, recoverPublicKey, verifyMessage, SupportedAlgorithms, UnicodeNormalizationForm, CoerceFunc, EventFragment, FunctionFragment, ParamType, BigNumberish, Arrayish, Hexable, Signature, Indexed, DeployDescription, EventDescription, FunctionDescription, LogDescription, TransactionDescription, Network, Networkish, Transaction, UnsignedTransaction, ConnectionInfo, OnceBlockable, PollOptions, EncryptOptions, ProgressCallback, Wordlist, };
export { AbiCoder, defaultAbiCoder, formatSignature, formatParamType, parseSignature, parseParamType, RLP, fetchJson, getNetwork, checkProperties, deepCopy, defineReadOnly, resolveProperties, shallowCopy, arrayify, concat, padZeros, stripZeros, HDNode, SigningKey, Interface, base64, BigNumber, bigNumberify, hexlify, isHexString, hexStripZeros, hexZeroPad, hexDataLength, hexDataSlice, toUtf8Bytes, toUtf8String, formatBytes32String, parseBytes32String, hashMessage, namehash, id, getAddress, getIcapAddress, getContractAddress, formatEther, parseEther, formatUnits, parseUnits, commify, keccak256, sha256, randomBytes, solidityPack, solidityKeccak256, soliditySha256, splitSignature, joinSignature, parseTransaction, populateTransaction, serializeTransaction, getJsonWalletAddress, computeAddress, computePublicKey, recoverAddress, recoverPublicKey, verifyMessage, poll, SupportedAlgorithms, UnicodeNormalizationForm, CoerceFunc, EventFragment, FunctionFragment, ParamType, BigNumberish, Arrayish, Hexable, Signature, Indexed, DeployDescription, EventDescription, FunctionDescription, LogDescription, TransactionDescription, Network, Networkish, Transaction, UnsignedTransaction, ConnectionInfo, OnceBlockable, PollOptions, EncryptOptions, ProgressCallback, Wordlist, };

View File

@@ -92,6 +92,7 @@ exports.formatUnits = units_1.formatUnits;
exports.parseUnits = units_1.parseUnits;
var web_1 = require("./web");
exports.fetchJson = web_1.fetchJson;
exports.poll = web_1.poll;
////////////////////////
// Enums
var hmac_1 = require("./hmac");

View File

@@ -70,12 +70,7 @@ var networks = {
chainId: 5,
ensAddress: "0x112234455c3a32fd11230c42e7bccd4a84e02010",
name: "goerli",
_defaultProvider: function (providers) {
if (providers.EtherscanProvider) {
return new providers.EtherscanProvider("goerli");
}
return null;
}
_defaultProvider: ethDefaultProvider('goerli')
},
kovan: {
chainId: 42,

View File

@@ -174,7 +174,7 @@ function parseBytes32String(bytes) {
throw new Error('invalid bytes32 - not 32 bytes long');
}
if (data[31] !== 0) {
throw new Error('invalid bytes32 sdtring - no null terminator');
throw new Error('invalid bytes32 string - no null terminator');
}
// Find the null termination
var length = 31;

1
utils/web.d.ts vendored
View File

@@ -17,6 +17,7 @@ export declare type PollOptions = {
ceiling?: number;
interval?: number;
onceBlock?: OnceBlockable;
fastRetry?: number;
};
export declare function fetchJson(connection: string | ConnectionInfo, json: string, processFunc: (value: any) => any): Promise<any>;
export declare function poll(func: () => Promise<any>, options?: PollOptions): Promise<any>;

View File

@@ -179,6 +179,7 @@ function poll(func, options) {
}
}, options.timeout);
}
var fastTimeout = options.fastRetry || null;
var attempt = 0;
function check() {
return func().then(function (result) {
@@ -201,6 +202,12 @@ function poll(func, options) {
if (timeout > options.ceiling) {
timeout = options.ceiling;
}
// Fast Timeout, means we quickly try again the first time
if (fastTimeout) {
attempt--;
timeout = fastTimeout;
fastTimeout = null;
}
setTimeout(check, timeout);
}
return null;