forked from tornado-packages/ethers.js
Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
427e16826e | ||
|
|
fab14f8f5a | ||
|
|
e8c89d7ca9 | ||
|
|
b1c6575a1b | ||
|
|
3b7176f322 | ||
|
|
5f7ddcd5d7 | ||
|
|
4c9d740cdf | ||
|
|
a930047a10 | ||
|
|
4e41871fa4 | ||
|
|
9947acc349 | ||
|
|
748f89660a | ||
|
|
2987925fa5 | ||
|
|
0589b3102e | ||
|
|
df51b26fe7 | ||
|
|
b288ad9ba7 | ||
|
|
6da5c53120 | ||
|
|
26d3271643 | ||
|
|
12da07579a | ||
|
|
bd066b8542 | ||
|
|
4478896ca5 | ||
|
|
f996ec0c32 | ||
|
|
c76e01e61f | ||
|
|
f8087ae39c |
41
CHANGELOG.md
41
CHANGELOG.md
@@ -1,6 +1,47 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
ethers/v4.0.47 (2020-04-21 23:15)
|
||||
---------------------------------
|
||||
|
||||
- Fixed typo in error message. ([#778](https://github.com/ethers-io/ethers.js/issues/778); [fab14f8](https://github.com/ethers-io/ethers.js/commit/fab14f8f5a16091810bbe4d35f38e0b976adab7c)).
|
||||
- Allow receive type in ABI without warning. ([#746](https://github.com/ethers-io/ethers.js/issues/746); [e8c89d7](https://github.com/ethers-io/ethers.js/commit/e8c89d7ca9cea6e20281f614c4fb22f180114622)).
|
||||
|
||||
ethers/v4.0.46 (2020-03-14 16:56)
|
||||
---------------------------------
|
||||
|
||||
- Fixed typo in error. ([#722](https://github.com/ethers-io/ethers.js/issues/722); [3b7176f](https://github.com/ethers-io/ethers.js/commit/3b7176f322376f8f42c333082388ef56d1720bae)).
|
||||
- Fix EtherscanProvider from throwing outside async context. ([#729](https://github.com/ethers-io/ethers.js/issues/729); [5f7ddcd](https://github.com/ethers-io/ethers.js/commit/5f7ddcd5d71d8a1c9efbeef1232c34ef93f92e5a)).
|
||||
|
||||
ethers/v4.0.45 (2020-02-16 16:16)
|
||||
---------------------------------
|
||||
|
||||
- Added default API key for EtherscanProvider. ([a930047](https://github.com/ethers-io/ethers.js/commit/a930047a102d3369c4e847d7ef43bd850704cf00)).
|
||||
- Fixed typo in arguments name for waitForTransaction. ([#477](https://github.com/ethers-io/ethers.js/issues/477); [4e41871](https://github.com/ethers-io/ethers.js/commit/4e41871fa4cf701d714ad73527a367e9ca1d3431)).
|
||||
- Partial support for non-English mnemonics for encrypted JSON wallets. ([#685](https://github.com/ethers-io/ethers.js/issues/685); [9947acc](https://github.com/ethers-io/ethers.js/commit/9947acc349691734bce8b33d870ab48944a7962f)).
|
||||
- Updated expected balance in test cases. ([748f896](https://github.com/ethers-io/ethers.js/commit/748f89660ac4bf60175f936da755cf1a0d370f46)).
|
||||
|
||||
ethers/v4.0.44 (2020-01-29 22:01)
|
||||
---------------------------------
|
||||
|
||||
- Fix backwards compatibility with certain parsed JSON objects passed into Interface and Contracts ([#721](https://github.com/ethers-io/ethers.js/issues/721); [0589b31](https://github.com/ethers-io/ethers.js/commit/0589b3102e2da702f4ac19a32c8b083faa6bbeea)).
|
||||
- Updated ENS registry address for all networks ([df51b26](https://github.com/ethers-io/ethers.js/commit/df51b26fe71c33fb8aa610d95c4955647345ce0a)).
|
||||
|
||||
ethers/v4.0.43 (2020-01-10 21:14)
|
||||
---------------------------------
|
||||
|
||||
- Fixed Contract and Interface constructor abi paramter type; should be a Fragment not a ParamType ([#602](https://github.com/ethers-io/ethers.js/issues/602); [6da5c53](https://github.com/ethers-io/ethers.js/commit/6da5c531206777ceef98d111a12b050a04bdf49c)).
|
||||
- Add missing chainId to transaction responses ([#700](https://github.com/ethers-io/ethers.js/issues/700); [26d3271](https://github.com/ethers-io/ethers.js/commit/26d32716436cd8925a5278173ba72ad54e00eef8)).
|
||||
- Fix resolveName when name is an address with an invalid checksum ([#694](https://github.com/ethers-io/ethers.js/issues/694); [bd066b8](https://github.com/ethers-io/ethers.js/commit/bd066b85421b1d0e575180e0626fcfb70135caf0)).
|
||||
- Fixed testcases for PhantomJS syntax. ([447889](https://github.com/ethers-io/ethers.js/commit/4478896ca5e77be0e20d6d491a092da981ed5343))
|
||||
|
||||
|
||||
ethers/v4.0.42 (2020-01-03 18:35)
|
||||
---------------------------------
|
||||
|
||||
- Properly handle errors in the IpcProvider ([#695](https://github.com/ethers-io/ethers.js/issues/695); [c76e01e](https://github.com/ethers-io/ethers.js/commit/c76e01e61fd52692f58c516842f7ed3b252b0f83))
|
||||
- Added utility function to compute CREATE2 addresses ([#697](https://github.com/ethers-io/ethers.js/issues/697); [f8087ae](https://github.com/ethers-io/ethers.js/commit/f8087ae39ce7631425b6b4763347a4f9618f9730))
|
||||
|
||||
ethers/v4.0.41 (2019-12-21 01:05)
|
||||
---------------------------------
|
||||
|
||||
|
||||
2
_version.d.ts
vendored
2
_version.d.ts
vendored
@@ -1 +1 @@
|
||||
export declare const version = "4.0.41";
|
||||
export declare const version = "4.0.47";
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.version = "4.0.41";
|
||||
exports.version = "4.0.47";
|
||||
|
||||
6
contract.d.ts
vendored
6
contract.d.ts
vendored
@@ -4,7 +4,7 @@ import { UnsignedTransaction } from './utils/transaction';
|
||||
import { BlockTag, Provider } from './providers/abstract-provider';
|
||||
import { Signer } from './abstract-signer';
|
||||
import { Arrayish } from './utils/bytes';
|
||||
import { ParamType } from './utils/abi-coder';
|
||||
import { EventFragment, FunctionFragment, ParamType } from './utils/abi-coder';
|
||||
import { Block, Listener, Log, TransactionReceipt, TransactionRequest, TransactionResponse } from './providers/abstract-provider';
|
||||
export declare type ContractFunction = (...params: Array<any>) => Promise<any>;
|
||||
export declare type EventFilter = {
|
||||
@@ -51,7 +51,7 @@ export declare class Contract {
|
||||
readonly addressPromise: Promise<string>;
|
||||
readonly deployTransaction: TransactionResponse;
|
||||
private _deployedPromise;
|
||||
constructor(addressOrName: string, contractInterface: Array<string | ParamType> | string | Interface, signerOrProvider: Signer | Provider);
|
||||
constructor(addressOrName: string, contractInterface: Array<string | FunctionFragment | EventFragment | ParamType> | string | Interface, signerOrProvider: Signer | Provider);
|
||||
deployed(): Promise<Contract>;
|
||||
_deployed(blockTag?: BlockTag): Promise<Contract>;
|
||||
fallback(overrides?: TransactionRequest): Promise<TransactionResponse>;
|
||||
@@ -74,7 +74,7 @@ export declare class ContractFactory {
|
||||
readonly interface: Interface;
|
||||
readonly bytecode: string;
|
||||
readonly signer: Signer;
|
||||
constructor(contractInterface: Array<string | ParamType> | string | Interface, bytecode: Arrayish | string | {
|
||||
constructor(contractInterface: Array<string | FunctionFragment | EventFragment | ParamType> | string | Interface, bytecode: Arrayish | string | {
|
||||
object: string;
|
||||
}, signer?: Signer);
|
||||
getDeployTransaction(...args: Array<any>): UnsignedTransaction;
|
||||
|
||||
@@ -256,6 +256,8 @@ var Contract = /** @class */ (function () {
|
||||
// https://github.com/Microsoft/TypeScript/issues/5453
|
||||
// Once this issue is resolved (there are open PR) we can do this nicer
|
||||
// by making addressOrName default to null for 2 operand calls. :)
|
||||
// ParamType is not actually correct here, but for legacy reasons,
|
||||
// we need it. See #721.
|
||||
function Contract(addressOrName, contractInterface, signerOrProvider) {
|
||||
var _this = this;
|
||||
errors.checkNew(this, Contract);
|
||||
@@ -602,6 +604,8 @@ var Contract = /** @class */ (function () {
|
||||
}());
|
||||
exports.Contract = Contract;
|
||||
var ContractFactory = /** @class */ (function () {
|
||||
// ParamType is not actually correct here, but for legacy reasons,
|
||||
// we need it. See #721.
|
||||
function ContractFactory(contractInterface, bytecode, signer) {
|
||||
var bytecodeHex = null;
|
||||
// Allow the bytecode object from the Solidity compiler
|
||||
|
||||
80
dist/ethers.js
vendored
80
dist/ethers.js
vendored
@@ -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.41";
|
||||
exports.version = "4.0.47";
|
||||
|
||||
},{}],2:[function(require,module,exports){
|
||||
"use strict";
|
||||
@@ -304,6 +304,8 @@ var Contract = /** @class */ (function () {
|
||||
// https://github.com/Microsoft/TypeScript/issues/5453
|
||||
// Once this issue is resolved (there are open PR) we can do this nicer
|
||||
// by making addressOrName default to null for 2 operand calls. :)
|
||||
// ParamType is not actually correct here, but for legacy reasons,
|
||||
// we need it. See #721.
|
||||
function Contract(addressOrName, contractInterface, signerOrProvider) {
|
||||
var _this = this;
|
||||
errors.checkNew(this, Contract);
|
||||
@@ -650,6 +652,8 @@ var Contract = /** @class */ (function () {
|
||||
}());
|
||||
exports.Contract = Contract;
|
||||
var ContractFactory = /** @class */ (function () {
|
||||
// ParamType is not actually correct here, but for legacy reasons,
|
||||
// we need it. See #721.
|
||||
function ContractFactory(contractInterface, bytecode, signer) {
|
||||
var bytecodeHex = null;
|
||||
// Allow the bytecode object from the Solidity compiler
|
||||
@@ -10295,6 +10299,9 @@ function checkTransactionResponse(transaction) {
|
||||
networkId = 0;
|
||||
}
|
||||
result.networkId = networkId;
|
||||
if (result.chainId == null && networkId != null) {
|
||||
result.chainId = networkId;
|
||||
}
|
||||
// 0x0000... should actually be null
|
||||
if (result.blockHash && result.blockHash.replace(/0/g, '') === 'x') {
|
||||
result.blockHash = null;
|
||||
@@ -11115,7 +11122,12 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
try {
|
||||
return Promise.resolve(address_1.getAddress(name));
|
||||
}
|
||||
catch (error) { }
|
||||
catch (error) {
|
||||
// See #694
|
||||
if (bytes_1.isHexString(name)) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
var self = this;
|
||||
var nodeHash = hash_1.namehash(name);
|
||||
// Get the addr from the resovler
|
||||
@@ -11392,6 +11404,7 @@ function checkLogTag(blockTag) {
|
||||
}
|
||||
return parseInt(blockTag.substring(2), 16);
|
||||
}
|
||||
var defaultApiKey = "8FG3JMZ9USS4NTA6YKEKHINU56SEPPVBJR";
|
||||
var EtherscanProvider = /** @class */ (function (_super) {
|
||||
__extends(EtherscanProvider, _super);
|
||||
function EtherscanProvider(network, apiKey) {
|
||||
@@ -11422,7 +11435,7 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
throw new Error('unsupported network');
|
||||
}
|
||||
properties_1.defineReadOnly(_this, 'baseUrl', baseUrl);
|
||||
properties_1.defineReadOnly(_this, 'apiKey', apiKey);
|
||||
properties_1.defineReadOnly(_this, 'apiKey', apiKey || defaultApiKey);
|
||||
return _this;
|
||||
}
|
||||
EtherscanProvider.prototype.perform = function (method, params) {
|
||||
@@ -11500,7 +11513,7 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
url += apiKey;
|
||||
return get(url);
|
||||
}
|
||||
throw new Error('getBlock by blockHash not implmeneted');
|
||||
return Promise.reject(new Error('getBlock by blockHash not implemeneted'));
|
||||
case 'getTransaction':
|
||||
url += '/api?module=proxy&action=eth_getTransactionByHash&txhash=' + params.transactionHash;
|
||||
url += apiKey;
|
||||
@@ -11517,7 +11530,7 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
url += '/api?module=proxy&action=eth_call' + transaction;
|
||||
//url += '&tag=' + params.blockTag + apiKey;
|
||||
if (params.blockTag !== 'latest') {
|
||||
throw new Error('EtherscanProvider does not support blockTag for call');
|
||||
return Promise.reject(new Error('EtherscanProvider does not support blockTag for call'));
|
||||
}
|
||||
url += apiKey;
|
||||
return get(url);
|
||||
@@ -12888,7 +12901,7 @@ var CoderAddress = /** @class */ (function (_super) {
|
||||
};
|
||||
CoderAddress.prototype.decode = function (data, offset) {
|
||||
if (data.length < offset + 32) {
|
||||
errors.throwError('insufficuent data for address type', errors.INVALID_ARGUMENT, {
|
||||
errors.throwError('insufficient data for address type', errors.INVALID_ARGUMENT, {
|
||||
arg: this.localName,
|
||||
coderType: 'address',
|
||||
value: bytes_1.hexlify(data.slice(offset, offset + 32))
|
||||
@@ -13460,6 +13473,41 @@ function getContractAddress(transaction) {
|
||||
])).substring(26));
|
||||
}
|
||||
exports.getContractAddress = getContractAddress;
|
||||
// See: https://eips.ethereum.org/EIPS/eip-1014
|
||||
function getCreate2Address(options) {
|
||||
var initCodeHash = options.initCodeHash;
|
||||
if (options.initCode) {
|
||||
if (initCodeHash) {
|
||||
if (keccak256_1.keccak256(options.initCode) !== initCodeHash) {
|
||||
errors.throwError("initCode/initCodeHash mismatch", errors.INVALID_ARGUMENT, {
|
||||
arg: "options", value: options
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
initCodeHash = keccak256_1.keccak256(options.initCode);
|
||||
}
|
||||
}
|
||||
if (!initCodeHash) {
|
||||
errors.throwError("missing initCode or initCodeHash", errors.INVALID_ARGUMENT, {
|
||||
arg: "options", value: options
|
||||
});
|
||||
}
|
||||
var from = getAddress(options.from);
|
||||
var salt = bytes_1.arrayify(options.salt);
|
||||
if (salt.length !== 32) {
|
||||
errors.throwError("invalid salt", errors.INVALID_ARGUMENT, {
|
||||
arg: "options", value: options
|
||||
});
|
||||
}
|
||||
return getAddress("0x" + keccak256_1.keccak256(bytes_1.concat([
|
||||
"0xff",
|
||||
from,
|
||||
salt,
|
||||
initCodeHash
|
||||
])).substring(26));
|
||||
}
|
||||
exports.getCreate2Address = getCreate2Address;
|
||||
|
||||
},{"../errors":5,"./bytes":64,"./keccak256":71,"./rlp":76,"bn.js":9}],61:[function(require,module,exports){
|
||||
'use strict';
|
||||
@@ -14505,6 +14553,7 @@ exports.parseParamType = abi_coder_1.parseParamType;
|
||||
var address_1 = require("./address");
|
||||
exports.getAddress = address_1.getAddress;
|
||||
exports.getContractAddress = address_1.getContractAddress;
|
||||
exports.getCreate2Address = address_1.getCreate2Address;
|
||||
exports.getIcapAddress = address_1.getIcapAddress;
|
||||
var base64 = __importStar(require("./base64"));
|
||||
exports.base64 = base64;
|
||||
@@ -14887,6 +14936,7 @@ function addMethod(method) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "receive":
|
||||
case 'fallback':
|
||||
// Nothing to do for fallback
|
||||
break;
|
||||
@@ -14896,6 +14946,8 @@ function addMethod(method) {
|
||||
}
|
||||
}
|
||||
var Interface = /** @class */ (function () {
|
||||
// ParamType is not actually correct here, but for legacy reasons,
|
||||
// we need it. See #721.
|
||||
function Interface(abi) {
|
||||
errors.checkNew(this, Interface);
|
||||
if (typeof (abi) === 'string') {
|
||||
@@ -15089,13 +15141,13 @@ function etcDefaultProvider(url, network) {
|
||||
}
|
||||
var homestead = {
|
||||
chainId: 1,
|
||||
ensAddress: "0x314159265dd8dbb310642f98f50c066173c1259b",
|
||||
ensAddress: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
|
||||
name: "homestead",
|
||||
_defaultProvider: ethDefaultProvider('homestead')
|
||||
};
|
||||
var ropsten = {
|
||||
chainId: 3,
|
||||
ensAddress: "0x112234455c3a32fd11230c42e7bccd4a84e02010",
|
||||
ensAddress: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
|
||||
name: "ropsten",
|
||||
_defaultProvider: ethDefaultProvider('ropsten')
|
||||
};
|
||||
@@ -15114,13 +15166,13 @@ var networks = {
|
||||
testnet: ropsten,
|
||||
rinkeby: {
|
||||
chainId: 4,
|
||||
ensAddress: "0xe7410170f87102DF0055eB195163A03B7F2Bff4A",
|
||||
ensAddress: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
|
||||
name: 'rinkeby',
|
||||
_defaultProvider: ethDefaultProvider('rinkeby')
|
||||
},
|
||||
goerli: {
|
||||
chainId: 5,
|
||||
ensAddress: "0x112234455c3a32fd11230c42e7bccd4a84e02010",
|
||||
ensAddress: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
|
||||
name: "goerli",
|
||||
_defaultProvider: ethDefaultProvider('goerli')
|
||||
},
|
||||
@@ -15783,7 +15835,8 @@ function decrypt(json, password, progressCallback) {
|
||||
return null;
|
||||
}
|
||||
// Version 0.1 x-ethers metadata must contain an encrypted mnemonic phrase
|
||||
if (searchPath(data, 'x-ethers/version') === '0.1') {
|
||||
var locale = searchPath(data, 'x-ethers/locale');
|
||||
if (searchPath(data, 'x-ethers/version') === '0.1' && (locale == null || locale === "en")) {
|
||||
var mnemonicCiphertext = looseArrayify(searchPath(data, 'x-ethers/mnemonicCiphertext'));
|
||||
var mnemonicIv = looseArrayify(searchPath(data, 'x-ethers/mnemonicCounter'));
|
||||
var mnemonicCounter = new aes_js_1.default.Counter(mnemonicIv);
|
||||
@@ -15915,7 +15968,7 @@ function encrypt(privateKey, password, options, progressCallback) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
entropy = bytes_1.arrayify(HDNode.mnemonicToEntropy(options.mnemonic));
|
||||
entropy = bytes_1.arrayify(HDNode.mnemonicToEntropy(options.mnemonic, options.wordlist));
|
||||
}
|
||||
}
|
||||
var path = options.path;
|
||||
@@ -16040,6 +16093,9 @@ function encrypt(privateKey, password, options, progressCallback) {
|
||||
path: path,
|
||||
version: "0.1"
|
||||
};
|
||||
if (options.wordlist && typeof (options.wordlist.locale) === "string") {
|
||||
data['x-ethers'].locale = options.wordlist.locale;
|
||||
}
|
||||
}
|
||||
if (progressCallback) {
|
||||
progressCallback(1);
|
||||
|
||||
2
dist/ethers.min.js
vendored
2
dist/ethers.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/ethers.min.js.map
vendored
2
dist/ethers.min.js.map
vendored
File diff suppressed because one or more lines are too long
26
dist/ethers.types.txt
vendored
26
dist/ethers.types.txt
vendored
@@ -29,7 +29,7 @@ declare module 'ethers/contract' {
|
||||
import { BlockTag, Provider } from 'ethers/providers/abstract-provider';
|
||||
import { Signer } from 'ethers/abstract-signer';
|
||||
import { Arrayish } from 'ethers/utils/bytes';
|
||||
import { ParamType } from 'ethers/utils/abi-coder';
|
||||
import { EventFragment, FunctionFragment, ParamType } from 'ethers/utils/abi-coder';
|
||||
import { Block, Listener, Log, TransactionReceipt, TransactionRequest, TransactionResponse } from 'ethers/providers/abstract-provider';
|
||||
export type ContractFunction = (...params: Array<any>) => Promise<any>;
|
||||
export type EventFilter = {
|
||||
@@ -75,7 +75,7 @@ declare module 'ethers/contract' {
|
||||
readonly [name: string]: ContractFunction | any;
|
||||
readonly addressPromise: Promise<string>;
|
||||
readonly deployTransaction: TransactionResponse;
|
||||
constructor(addressOrName: string, contractInterface: Array<string | ParamType> | string | Interface, signerOrProvider: Signer | Provider);
|
||||
constructor(addressOrName: string, contractInterface: Array<string | FunctionFragment | EventFragment | ParamType> | string | Interface, signerOrProvider: Signer | Provider);
|
||||
deployed(): Promise<Contract>;
|
||||
_deployed(blockTag?: BlockTag): Promise<Contract>;
|
||||
fallback(overrides?: TransactionRequest): Promise<TransactionResponse>;
|
||||
@@ -95,7 +95,7 @@ declare module 'ethers/contract' {
|
||||
readonly interface: Interface;
|
||||
readonly bytecode: string;
|
||||
readonly signer: Signer;
|
||||
constructor(contractInterface: Array<string | ParamType> | string | Interface, bytecode: Arrayish | string | {
|
||||
constructor(contractInterface: Array<string | FunctionFragment | EventFragment | ParamType> | string | Interface, bytecode: Arrayish | string | {
|
||||
object: string;
|
||||
}, signer?: Signer);
|
||||
getDeployTransaction(...args: Array<any>): UnsignedTransaction;
|
||||
@@ -211,7 +211,7 @@ declare module 'ethers/providers' {
|
||||
|
||||
declare module 'ethers/utils' {
|
||||
import { AbiCoder, defaultAbiCoder, formatSignature, formatParamType, parseSignature, parseParamType } from 'ethers/utils/abi-coder';
|
||||
import { getAddress, getContractAddress, getIcapAddress } from 'ethers/utils/address';
|
||||
import { getAddress, getContractAddress, getCreate2Address, getIcapAddress } from 'ethers/utils/address';
|
||||
import * as base64 from 'ethers/utils/base64';
|
||||
import { BigNumber, bigNumberify } from 'ethers/utils/bignumber';
|
||||
import { arrayify, concat, hexDataSlice, hexDataLength, hexlify, hexStripZeros, hexZeroPad, isHexString, joinSignature, padZeros, splitSignature, stripZeros } from 'ethers/utils/bytes';
|
||||
@@ -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, 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, };
|
||||
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, getCreate2Address, 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.41";
|
||||
export const version = "4.0.47";
|
||||
}
|
||||
|
||||
declare module 'ethers/utils/bignumber' {
|
||||
@@ -400,7 +400,7 @@ declare module 'ethers/utils/interface' {
|
||||
[name: string]: _EventDescription;
|
||||
};
|
||||
readonly deployFunction: _DeployDescription;
|
||||
constructor(abi: Array<string | ParamType> | string);
|
||||
constructor(abi: Array<string | FunctionFragment | EventFragment | ParamType> | string);
|
||||
parseTransaction(tx: {
|
||||
data: string;
|
||||
value?: BigNumberish;
|
||||
@@ -553,7 +553,7 @@ declare module 'ethers/providers/abstract-provider' {
|
||||
abstract listeners(eventName: EventType): Array<Listener>;
|
||||
abstract removeAllListeners(eventName: EventType): Provider;
|
||||
abstract removeListener(eventName: EventType, listener: Listener): Provider;
|
||||
abstract waitForTransaction(transactionHash: string, timeout?: number): Promise<TransactionReceipt>;
|
||||
abstract waitForTransaction(transactionHash: string, confirmations?: number): Promise<TransactionReceipt>;
|
||||
constructor();
|
||||
static isProvider(value: any): value is Provider;
|
||||
}
|
||||
@@ -614,7 +614,7 @@ declare module 'ethers/utils/abi-coder' {
|
||||
outputs: Array<ParamType>;
|
||||
payable: boolean;
|
||||
stateMutability: string;
|
||||
gas: BigNumber;
|
||||
gas?: BigNumber;
|
||||
};
|
||||
export const defaultCoerceFunc: CoerceFunc;
|
||||
export function parseParamType(type: string): ParamType;
|
||||
@@ -710,6 +710,7 @@ declare module 'ethers/utils/secret-storage' {
|
||||
entropy?: Arrayish;
|
||||
mnemonic?: string;
|
||||
path?: string;
|
||||
wordlist?: any;
|
||||
client?: string;
|
||||
salt?: Arrayish;
|
||||
uuid?: string;
|
||||
@@ -898,6 +899,13 @@ declare module 'ethers/utils/address' {
|
||||
from: string;
|
||||
nonce: Arrayish | BigNumber | number;
|
||||
}): string;
|
||||
export type Create2Options = {
|
||||
from: string;
|
||||
salt: Arrayish;
|
||||
initCode?: Arrayish;
|
||||
initCodeHash?: Arrayish;
|
||||
};
|
||||
export function getCreate2Address(options: Create2Options): string;
|
||||
}
|
||||
|
||||
declare module 'ethers/utils/base64' {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ethers",
|
||||
"version": "4.0.41",
|
||||
"version": "4.0.47",
|
||||
"description": "Ethereum wallet library.",
|
||||
"main": "./index.js",
|
||||
"types": "./index.d.ts",
|
||||
|
||||
2
providers/abstract-provider.d.ts
vendored
2
providers/abstract-provider.d.ts
vendored
@@ -102,7 +102,7 @@ export declare abstract class Provider implements OnceBlockable {
|
||||
abstract listeners(eventName: EventType): Array<Listener>;
|
||||
abstract removeAllListeners(eventName: EventType): Provider;
|
||||
abstract removeListener(eventName: EventType, listener: Listener): Provider;
|
||||
abstract waitForTransaction(transactionHash: string, timeout?: number): Promise<TransactionReceipt>;
|
||||
abstract waitForTransaction(transactionHash: string, confirmations?: number): Promise<TransactionReceipt>;
|
||||
constructor();
|
||||
static isProvider(value: any): value is Provider;
|
||||
}
|
||||
|
||||
@@ -227,6 +227,9 @@ function checkTransactionResponse(transaction) {
|
||||
networkId = 0;
|
||||
}
|
||||
result.networkId = networkId;
|
||||
if (result.chainId == null && networkId != null) {
|
||||
result.chainId = networkId;
|
||||
}
|
||||
// 0x0000... should actually be null
|
||||
if (result.blockHash && result.blockHash.replace(/0/g, '') === 'x') {
|
||||
result.blockHash = null;
|
||||
@@ -1047,7 +1050,12 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
try {
|
||||
return Promise.resolve(address_1.getAddress(name));
|
||||
}
|
||||
catch (error) { }
|
||||
catch (error) {
|
||||
// See #694
|
||||
if (bytes_1.isHexString(name)) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
var self = this;
|
||||
var nodeHash = hash_1.namehash(name);
|
||||
// Get the addr from the resovler
|
||||
|
||||
@@ -81,6 +81,7 @@ function checkLogTag(blockTag) {
|
||||
}
|
||||
return parseInt(blockTag.substring(2), 16);
|
||||
}
|
||||
var defaultApiKey = "8FG3JMZ9USS4NTA6YKEKHINU56SEPPVBJR";
|
||||
var EtherscanProvider = /** @class */ (function (_super) {
|
||||
__extends(EtherscanProvider, _super);
|
||||
function EtherscanProvider(network, apiKey) {
|
||||
@@ -111,7 +112,7 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
throw new Error('unsupported network');
|
||||
}
|
||||
properties_1.defineReadOnly(_this, 'baseUrl', baseUrl);
|
||||
properties_1.defineReadOnly(_this, 'apiKey', apiKey);
|
||||
properties_1.defineReadOnly(_this, 'apiKey', apiKey || defaultApiKey);
|
||||
return _this;
|
||||
}
|
||||
EtherscanProvider.prototype.perform = function (method, params) {
|
||||
@@ -189,7 +190,7 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
url += apiKey;
|
||||
return get(url);
|
||||
}
|
||||
throw new Error('getBlock by blockHash not implmeneted');
|
||||
return Promise.reject(new Error('getBlock by blockHash not implemeneted'));
|
||||
case 'getTransaction':
|
||||
url += '/api?module=proxy&action=eth_getTransactionByHash&txhash=' + params.transactionHash;
|
||||
url += apiKey;
|
||||
@@ -206,7 +207,7 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
url += '/api?module=proxy&action=eth_call' + transaction;
|
||||
//url += '&tag=' + params.blockTag + apiKey;
|
||||
if (params.blockTag !== 'latest') {
|
||||
throw new Error('EtherscanProvider does not support blockTag for call');
|
||||
return Promise.reject(new Error('EtherscanProvider does not support blockTag for call'));
|
||||
}
|
||||
url += apiKey;
|
||||
return get(url);
|
||||
|
||||
@@ -59,8 +59,16 @@ var IpcProvider = /** @class */ (function (_super) {
|
||||
});
|
||||
stream.on("end", function () {
|
||||
try {
|
||||
resolve(JSON.parse(response.toString('utf8')).result);
|
||||
// @TODO: Better pull apart the error
|
||||
var payload_1 = JSON.parse(response.toString('utf8'));
|
||||
if (payload_1.error) {
|
||||
var error = new Error(payload_1.error.message);
|
||||
error.code = payload_1.error.code;
|
||||
error.data = payload_1.error.data;
|
||||
reject(error);
|
||||
}
|
||||
else {
|
||||
resolve(payload_1.result);
|
||||
}
|
||||
stream.destroy();
|
||||
}
|
||||
catch (error) {
|
||||
|
||||
@@ -1 +1 @@
|
||||
export const version = "4.0.41";
|
||||
export const version = "4.0.47";
|
||||
|
||||
@@ -24,7 +24,7 @@ import { Signer } from './abstract-signer';
|
||||
|
||||
import { Arrayish } from './utils/bytes';
|
||||
import { EventDescription } from './utils/interface';
|
||||
import { ParamType } from './utils/abi-coder';
|
||||
import { EventFragment, FunctionFragment, ParamType } from './utils/abi-coder';
|
||||
import { Block, Listener, Log, TransactionReceipt, TransactionRequest, TransactionResponse } from './providers/abstract-provider';
|
||||
|
||||
///////////////////////////////
|
||||
@@ -364,7 +364,9 @@ export class Contract {
|
||||
// Once this issue is resolved (there are open PR) we can do this nicer
|
||||
// by making addressOrName default to null for 2 operand calls. :)
|
||||
|
||||
constructor(addressOrName: string, contractInterface: Array<string | ParamType> | string | Interface, signerOrProvider: Signer | Provider) {
|
||||
// ParamType is not actually correct here, but for legacy reasons,
|
||||
// we need it. See #721.
|
||||
constructor(addressOrName: string, contractInterface: Array<string | FunctionFragment | EventFragment | ParamType> | string | Interface, signerOrProvider: Signer | Provider) {
|
||||
errors.checkNew(this, Contract);
|
||||
|
||||
// @TODO: Maybe still check the addressOrName looks like a valid address or name?
|
||||
@@ -744,7 +746,9 @@ export class ContractFactory {
|
||||
readonly bytecode: string;
|
||||
readonly signer: Signer;
|
||||
|
||||
constructor(contractInterface: Array<string | ParamType> | string | Interface, bytecode: Arrayish | string | { object: string }, signer?: Signer) {
|
||||
// ParamType is not actually correct here, but for legacy reasons,
|
||||
// we need it. See #721.
|
||||
constructor(contractInterface: Array<string | FunctionFragment | EventFragment | ParamType> | string | Interface, bytecode: Arrayish | string | { object: string }, signer?: Signer) {
|
||||
|
||||
let bytecodeHex: string = null;
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ export abstract class Provider implements OnceBlockable {
|
||||
abstract removeListener(eventName: EventType, listener: Listener): Provider;
|
||||
|
||||
// @TODO: This *could* be implemented here, but would pull in events...
|
||||
abstract waitForTransaction(transactionHash: string, timeout?: number): Promise<TransactionReceipt>;
|
||||
abstract waitForTransaction(transactionHash: string, confirmations?: number): Promise<TransactionReceipt>;
|
||||
|
||||
constructor() {
|
||||
setType(this, 'Provider');
|
||||
|
||||
@@ -247,6 +247,9 @@ function checkTransactionResponse(transaction: any): TransactionResponse {
|
||||
if (typeof(networkId) !== 'number') { networkId = 0; }
|
||||
|
||||
result.networkId = networkId;
|
||||
if (result.chainId == null && networkId != null) {
|
||||
result.chainId = networkId;
|
||||
}
|
||||
|
||||
// 0x0000... should actually be null
|
||||
if (result.blockHash && result.blockHash.replace(/0/g, '') === 'x') {
|
||||
@@ -1178,7 +1181,10 @@ export class BaseProvider extends Provider {
|
||||
// If it is already an address, nothing to resolve
|
||||
try {
|
||||
return Promise.resolve(getAddress(name));
|
||||
} catch (error) { }
|
||||
} catch (error) {
|
||||
// See #694
|
||||
if (isHexString(name)) { throw error; }
|
||||
}
|
||||
|
||||
let self = this;
|
||||
|
||||
|
||||
@@ -73,6 +73,7 @@ function checkLogTag(blockTag: string): number | "latest" {
|
||||
return parseInt(blockTag.substring(2), 16);
|
||||
}
|
||||
|
||||
const defaultApiKey = "8FG3JMZ9USS4NTA6YKEKHINU56SEPPVBJR";
|
||||
|
||||
export class EtherscanProvider extends BaseProvider{
|
||||
readonly baseUrl: string;
|
||||
@@ -106,7 +107,7 @@ export class EtherscanProvider extends BaseProvider{
|
||||
}
|
||||
|
||||
defineReadOnly(this, 'baseUrl', baseUrl);
|
||||
defineReadOnly(this, 'apiKey', apiKey);
|
||||
defineReadOnly(this, 'apiKey', apiKey || defaultApiKey);
|
||||
}
|
||||
|
||||
|
||||
@@ -193,7 +194,7 @@ export class EtherscanProvider extends BaseProvider{
|
||||
url += apiKey;
|
||||
return get(url);
|
||||
}
|
||||
throw new Error('getBlock by blockHash not implmeneted');
|
||||
return Promise.reject(new Error('getBlock by blockHash not implemeneted'));
|
||||
|
||||
case 'getTransaction':
|
||||
url += '/api?module=proxy&action=eth_getTransactionByHash&txhash=' + params.transactionHash;
|
||||
@@ -212,7 +213,7 @@ export class EtherscanProvider extends BaseProvider{
|
||||
url += '/api?module=proxy&action=eth_call' + transaction;
|
||||
//url += '&tag=' + params.blockTag + apiKey;
|
||||
if (params.blockTag !== 'latest') {
|
||||
throw new Error('EtherscanProvider does not support blockTag for call');
|
||||
return Promise.reject(new Error('EtherscanProvider does not support blockTag for call'));
|
||||
}
|
||||
url += apiKey;
|
||||
return get(url);
|
||||
|
||||
@@ -54,8 +54,15 @@ export class IpcProvider extends JsonRpcProvider {
|
||||
|
||||
stream.on("end", () => {
|
||||
try {
|
||||
resolve(JSON.parse(response.toString('utf8')).result);
|
||||
// @TODO: Better pull apart the error
|
||||
const payload = JSON.parse(response.toString('utf8'));
|
||||
if (payload.error) {
|
||||
const error: any = new Error(payload.error.message);
|
||||
error.code = payload.error.code;
|
||||
error.data = payload.error.data;
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(payload.result);
|
||||
}
|
||||
stream.destroy();
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
|
||||
@@ -54,7 +54,7 @@ export type FunctionFragment = {
|
||||
payable: boolean,
|
||||
stateMutability: string,
|
||||
|
||||
gas: BigNumber
|
||||
gas?: BigNumber
|
||||
};
|
||||
|
||||
///////////////////////////////
|
||||
@@ -607,7 +607,7 @@ class CoderAddress extends Coder {
|
||||
}
|
||||
decode(data: Uint8Array, offset: number): DecodedResult {
|
||||
if (data.length < offset + 32) {
|
||||
errors.throwError('insufficuent data for address type', errors.INVALID_ARGUMENT, {
|
||||
errors.throwError('insufficient data for address type', errors.INVALID_ARGUMENT, {
|
||||
arg: this.localName,
|
||||
coderType: 'address',
|
||||
value: hexlify(data.slice(offset, offset + 32))
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// We use this for base 36 maths
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { arrayify, stripZeros, hexlify } from './bytes';
|
||||
import { arrayify, concat, stripZeros, hexlify } from './bytes';
|
||||
import { BigNumber } from './bignumber';
|
||||
import { keccak256 } from './keccak256';
|
||||
import { encode } from './rlp';
|
||||
@@ -140,3 +140,47 @@ export function getContractAddress(transaction: { from: string, nonce: Arrayish
|
||||
])).substring(26));
|
||||
}
|
||||
|
||||
export type Create2Options = {
|
||||
from: string,
|
||||
salt: Arrayish,
|
||||
initCode?: Arrayish,
|
||||
initCodeHash?: Arrayish,
|
||||
};
|
||||
|
||||
// See: https://eips.ethereum.org/EIPS/eip-1014
|
||||
export function getCreate2Address(options: Create2Options): string {
|
||||
let initCodeHash = options.initCodeHash;
|
||||
if (options.initCode) {
|
||||
if (initCodeHash) {
|
||||
if (keccak256(options.initCode) !== initCodeHash) {
|
||||
errors.throwError("initCode/initCodeHash mismatch", errors.INVALID_ARGUMENT, {
|
||||
arg: "options", value: options
|
||||
});
|
||||
}
|
||||
} else {
|
||||
initCodeHash = keccak256(options.initCode);
|
||||
}
|
||||
}
|
||||
|
||||
if (!initCodeHash) {
|
||||
errors.throwError("missing initCode or initCodeHash", errors.INVALID_ARGUMENT, {
|
||||
arg: "options", value: options
|
||||
});
|
||||
}
|
||||
|
||||
const from = getAddress(options.from);
|
||||
|
||||
const salt = arrayify(options.salt);
|
||||
if (salt.length !== 32) {
|
||||
errors.throwError("invalid salt", errors.INVALID_ARGUMENT, {
|
||||
arg: "options", value: options
|
||||
});
|
||||
}
|
||||
|
||||
return getAddress("0x" + keccak256(concat([
|
||||
"0xff",
|
||||
from,
|
||||
salt,
|
||||
initCodeHash
|
||||
])).substring(26));
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
import { AbiCoder, defaultAbiCoder, formatSignature, formatParamType, parseSignature, parseParamType } from './abi-coder';
|
||||
import { getAddress, getContractAddress, getIcapAddress } from './address';
|
||||
import { getAddress, getContractAddress, getCreate2Address, getIcapAddress } from './address';
|
||||
import * as base64 from './base64';
|
||||
import { BigNumber, bigNumberify } from './bignumber';
|
||||
import { arrayify, concat, hexDataSlice, hexDataLength, hexlify, hexStripZeros, hexZeroPad, isHexString, joinSignature, padZeros, splitSignature, stripZeros } from './bytes';
|
||||
@@ -103,6 +103,7 @@ export {
|
||||
getAddress,
|
||||
getIcapAddress,
|
||||
getContractAddress,
|
||||
getCreate2Address,
|
||||
|
||||
formatEther,
|
||||
parseEther,
|
||||
|
||||
@@ -374,6 +374,7 @@ function addMethod(method: any): void {
|
||||
break;
|
||||
}
|
||||
|
||||
case "receive":
|
||||
case 'fallback':
|
||||
// Nothing to do for fallback
|
||||
break;
|
||||
@@ -390,7 +391,9 @@ export class Interface {
|
||||
readonly events: { [ name: string ]: _EventDescription };
|
||||
readonly deployFunction: _DeployDescription;
|
||||
|
||||
constructor(abi: Array<string | ParamType> | string) {
|
||||
// ParamType is not actually correct here, but for legacy reasons,
|
||||
// we need it. See #721.
|
||||
constructor(abi: Array<string | FunctionFragment | EventFragment | ParamType> | string) {
|
||||
errors.checkNew(this, Interface);
|
||||
|
||||
if (typeof(abi) === 'string') {
|
||||
|
||||
@@ -46,14 +46,14 @@ function etcDefaultProvider(url: string, network: string): (providers: any) => a
|
||||
|
||||
const homestead: Network = {
|
||||
chainId: 1,
|
||||
ensAddress: "0x314159265dd8dbb310642f98f50c066173c1259b",
|
||||
ensAddress: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
|
||||
name: "homestead",
|
||||
_defaultProvider: ethDefaultProvider('homestead')
|
||||
};
|
||||
|
||||
const ropsten: Network = {
|
||||
chainId: 3,
|
||||
ensAddress: "0x112234455c3a32fd11230c42e7bccd4a84e02010",
|
||||
ensAddress: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
|
||||
name: "ropsten",
|
||||
_defaultProvider: ethDefaultProvider('ropsten')
|
||||
};
|
||||
@@ -77,14 +77,14 @@ const networks: { [name: string]: Network } = {
|
||||
|
||||
rinkeby: {
|
||||
chainId: 4,
|
||||
ensAddress: "0xe7410170f87102DF0055eB195163A03B7F2Bff4A",
|
||||
ensAddress: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
|
||||
name: 'rinkeby',
|
||||
_defaultProvider: ethDefaultProvider('rinkeby')
|
||||
},
|
||||
|
||||
goerli: {
|
||||
chainId: 5,
|
||||
ensAddress: "0x112234455c3a32fd11230c42e7bccd4a84e02010",
|
||||
ensAddress: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
|
||||
name: "goerli",
|
||||
_defaultProvider: ethDefaultProvider('goerli')
|
||||
},
|
||||
|
||||
@@ -26,6 +26,7 @@ export type EncryptOptions = {
|
||||
entropy?: Arrayish;
|
||||
mnemonic?: string;
|
||||
path?: string;
|
||||
wordlist?: any; // Should be a wordlist, but don't want to create the dependency
|
||||
client?: string;
|
||||
salt?: Arrayish;
|
||||
uuid?: string;
|
||||
@@ -177,7 +178,8 @@ export function decrypt(json: string, password: Arrayish, progressCallback?: Pro
|
||||
}
|
||||
|
||||
// Version 0.1 x-ethers metadata must contain an encrypted mnemonic phrase
|
||||
if (searchPath(data, 'x-ethers/version') === '0.1') {
|
||||
const locale = searchPath(data, 'x-ethers/locale');
|
||||
if (searchPath(data, 'x-ethers/version') === '0.1' && (locale == null || locale === "en")) {
|
||||
var mnemonicCiphertext = looseArrayify(searchPath(data, 'x-ethers/mnemonicCiphertext'));
|
||||
var mnemonicIv = looseArrayify(searchPath(data, 'x-ethers/mnemonicCounter'));
|
||||
|
||||
@@ -318,7 +320,7 @@ export function encrypt(privateKey: Arrayish | SigningKey, password: Arrayish |
|
||||
throw new Error('entropy and mnemonic mismatch');
|
||||
}
|
||||
} else {
|
||||
entropy = arrayify(HDNode.mnemonicToEntropy(options.mnemonic));
|
||||
entropy = arrayify(HDNode.mnemonicToEntropy(options.mnemonic, options.wordlist));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -441,6 +443,9 @@ export function encrypt(privateKey: Arrayish | SigningKey, password: Arrayish |
|
||||
path: path,
|
||||
version: "0.1"
|
||||
};
|
||||
if (options.wordlist && typeof(options.wordlist.locale) === "string") {
|
||||
data['x-ethers'].locale = options.wordlist.locale;
|
||||
}
|
||||
}
|
||||
|
||||
if (progressCallback) { progressCallback(1); }
|
||||
|
||||
@@ -36,3 +36,64 @@ describe('Checksum and ICAP address generation', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Create2 Address Generation", function() {
|
||||
var tests = [
|
||||
{
|
||||
name: "Example 0",
|
||||
from: "0x0000000000000000000000000000000000000000",
|
||||
salt: "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
initCode: "0x00",
|
||||
expected: "0x4D1A2e2bB4F88F0250f26Ffff098B0b30B26BF38"
|
||||
},
|
||||
{
|
||||
name: "Example 1",
|
||||
from: "0xdeadbeef00000000000000000000000000000000",
|
||||
salt: "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
initCode: "0x00",
|
||||
expected: "0xB928f69Bb1D91Cd65274e3c79d8986362984fDA3"
|
||||
},
|
||||
{
|
||||
name: "Example 2",
|
||||
from: "0xdeadbeef00000000000000000000000000000000",
|
||||
salt: "0x000000000000000000000000feed000000000000000000000000000000000000",
|
||||
initCode: "0x00",
|
||||
expected: "0xD04116cDd17beBE565EB2422F2497E06cC1C9833"
|
||||
},
|
||||
{
|
||||
name: "Example 3",
|
||||
from: "0x0000000000000000000000000000000000000000",
|
||||
salt: "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
initCode: "0xdeadbeef",
|
||||
expected: "0x70f2b2914A2a4b783FaEFb75f459A580616Fcb5e"
|
||||
},
|
||||
{
|
||||
name: "Example 4",
|
||||
from: "0x00000000000000000000000000000000deadbeef",
|
||||
salt: "0x00000000000000000000000000000000000000000000000000000000cafebabe",
|
||||
initCode: "0xdeadbeef",
|
||||
expected: "0x60f3f640a8508fC6a86d45DF051962668E1e8AC7"
|
||||
},
|
||||
{
|
||||
name: "Example 5",
|
||||
from: "0x00000000000000000000000000000000deadbeef",
|
||||
salt: "0x00000000000000000000000000000000000000000000000000000000cafebabe",
|
||||
initCode: "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
|
||||
expected: "0x1d8bfDC5D46DC4f61D6b6115972536eBE6A8854C"
|
||||
},
|
||||
{
|
||||
name: "Example 6",
|
||||
from: "0x0000000000000000000000000000000000000000",
|
||||
salt: "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
initCode: "0x",
|
||||
expected: "0xE33C0C7F7df4809055C3ebA6c09CFe4BaF1BD9e0"
|
||||
},
|
||||
];
|
||||
|
||||
tests.forEach(function(test) {
|
||||
it("correctly computes the Create2 address - " + test.name, function() {
|
||||
var address = ethers.utils.getCreate2Address(test);
|
||||
assert.equal(address, test.expected, "correctly computes Create2 address");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,7 +14,7 @@ var blockchainData = {
|
||||
homestead: {
|
||||
balance: {
|
||||
address: '0xAC1639CF97a3A46D431e6d1216f576622894cBB5',
|
||||
balance: bigNumberify('4918774100000000')
|
||||
balance: bigNumberify('0x1119c64d965d00')
|
||||
},
|
||||
block3: {
|
||||
hash: '0x3d6122660cc824376f11ee842f83addc3525e2dd6756b9bcf0affa6aa88cf741',
|
||||
@@ -46,7 +46,8 @@ var blockchainData = {
|
||||
v: 38,
|
||||
creates: null,
|
||||
raw: '0xf8d2808504a817c8008303d090946fc21092da55b392b045ed78f4732bff3c580e2c880186cc6acd4b0000b864f2c298be000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000067269636d6f6f000000000000000000000000000000000000000000000000000026a01e5605197a03e3f0a168f14749168dfeefc44c9228312dacbffdcbbb13263265a0269c3e5b3558267ad91b0a887d51f9f10098771c67b82ea6cb74f29638754f54',
|
||||
networkId: 1
|
||||
networkId: 1,
|
||||
chainId: 1
|
||||
},
|
||||
transactionReceipt: {
|
||||
blockHash: "0x36b4af7f0538559e581c8588f16477df0f676439ea67fe8d7a2ae4abb20e2566",
|
||||
@@ -392,6 +393,15 @@ function testProvider(providerName, networkName) {
|
||||
});
|
||||
}
|
||||
|
||||
if (networkName === "homestead") {
|
||||
it('fetches ENS names', function() {
|
||||
this.timeout(20000);
|
||||
return provider.resolveName("ricmoo.firefly.eth").then(function(address) {
|
||||
assert.equal(address, "0x8ba1f109551bD432803012645Ac136ddd64DBA72");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Obviously many more cases to add here
|
||||
// - getTransactionCount
|
||||
// - getCode
|
||||
|
||||
2
utils/abi-coder.d.ts
vendored
2
utils/abi-coder.d.ts
vendored
@@ -21,7 +21,7 @@ export declare type FunctionFragment = {
|
||||
outputs: Array<ParamType>;
|
||||
payable: boolean;
|
||||
stateMutability: string;
|
||||
gas: BigNumber;
|
||||
gas?: BigNumber;
|
||||
};
|
||||
export declare const defaultCoerceFunc: CoerceFunc;
|
||||
export declare function parseParamType(type: string): ParamType;
|
||||
|
||||
@@ -514,7 +514,7 @@ var CoderAddress = /** @class */ (function (_super) {
|
||||
};
|
||||
CoderAddress.prototype.decode = function (data, offset) {
|
||||
if (data.length < offset + 32) {
|
||||
errors.throwError('insufficuent data for address type', errors.INVALID_ARGUMENT, {
|
||||
errors.throwError('insufficient data for address type', errors.INVALID_ARGUMENT, {
|
||||
arg: this.localName,
|
||||
coderType: 'address',
|
||||
value: bytes_1.hexlify(data.slice(offset, offset + 32))
|
||||
|
||||
7
utils/address.d.ts
vendored
7
utils/address.d.ts
vendored
@@ -6,3 +6,10 @@ export declare function getContractAddress(transaction: {
|
||||
from: string;
|
||||
nonce: Arrayish | BigNumber | number;
|
||||
}): string;
|
||||
export declare type Create2Options = {
|
||||
from: string;
|
||||
salt: Arrayish;
|
||||
initCode?: Arrayish;
|
||||
initCodeHash?: Arrayish;
|
||||
};
|
||||
export declare function getCreate2Address(options: Create2Options): string;
|
||||
|
||||
@@ -123,3 +123,38 @@ function getContractAddress(transaction) {
|
||||
])).substring(26));
|
||||
}
|
||||
exports.getContractAddress = getContractAddress;
|
||||
// See: https://eips.ethereum.org/EIPS/eip-1014
|
||||
function getCreate2Address(options) {
|
||||
var initCodeHash = options.initCodeHash;
|
||||
if (options.initCode) {
|
||||
if (initCodeHash) {
|
||||
if (keccak256_1.keccak256(options.initCode) !== initCodeHash) {
|
||||
errors.throwError("initCode/initCodeHash mismatch", errors.INVALID_ARGUMENT, {
|
||||
arg: "options", value: options
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
initCodeHash = keccak256_1.keccak256(options.initCode);
|
||||
}
|
||||
}
|
||||
if (!initCodeHash) {
|
||||
errors.throwError("missing initCode or initCodeHash", errors.INVALID_ARGUMENT, {
|
||||
arg: "options", value: options
|
||||
});
|
||||
}
|
||||
var from = getAddress(options.from);
|
||||
var salt = bytes_1.arrayify(options.salt);
|
||||
if (salt.length !== 32) {
|
||||
errors.throwError("invalid salt", errors.INVALID_ARGUMENT, {
|
||||
arg: "options", value: options
|
||||
});
|
||||
}
|
||||
return getAddress("0x" + keccak256_1.keccak256(bytes_1.concat([
|
||||
"0xff",
|
||||
from,
|
||||
salt,
|
||||
initCodeHash
|
||||
])).substring(26));
|
||||
}
|
||||
exports.getCreate2Address = getCreate2Address;
|
||||
|
||||
4
utils/index.d.ts
vendored
4
utils/index.d.ts
vendored
@@ -1,5 +1,5 @@
|
||||
import { AbiCoder, defaultAbiCoder, formatSignature, formatParamType, parseSignature, parseParamType } from './abi-coder';
|
||||
import { getAddress, getContractAddress, getIcapAddress } from './address';
|
||||
import { getAddress, getContractAddress, getCreate2Address, getIcapAddress } from './address';
|
||||
import * as base64 from './base64';
|
||||
import { BigNumber, bigNumberify } from './bignumber';
|
||||
import { arrayify, concat, hexDataSlice, hexDataLength, hexlify, hexStripZeros, hexZeroPad, isHexString, joinSignature, padZeros, splitSignature, stripZeros } from './bytes';
|
||||
@@ -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, 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, };
|
||||
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, getCreate2Address, 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, };
|
||||
|
||||
@@ -17,6 +17,7 @@ exports.parseParamType = abi_coder_1.parseParamType;
|
||||
var address_1 = require("./address");
|
||||
exports.getAddress = address_1.getAddress;
|
||||
exports.getContractAddress = address_1.getContractAddress;
|
||||
exports.getCreate2Address = address_1.getCreate2Address;
|
||||
exports.getIcapAddress = address_1.getIcapAddress;
|
||||
var base64 = __importStar(require("./base64"));
|
||||
exports.base64 = base64;
|
||||
|
||||
2
utils/interface.d.ts
vendored
2
utils/interface.d.ts
vendored
@@ -98,7 +98,7 @@ export declare class Interface {
|
||||
[name: string]: _EventDescription;
|
||||
};
|
||||
readonly deployFunction: _DeployDescription;
|
||||
constructor(abi: Array<string | ParamType> | string);
|
||||
constructor(abi: Array<string | FunctionFragment | EventFragment | ParamType> | string);
|
||||
parseTransaction(tx: {
|
||||
data: string;
|
||||
value?: BigNumberish;
|
||||
|
||||
@@ -294,6 +294,7 @@ function addMethod(method) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "receive":
|
||||
case 'fallback':
|
||||
// Nothing to do for fallback
|
||||
break;
|
||||
@@ -303,6 +304,8 @@ function addMethod(method) {
|
||||
}
|
||||
}
|
||||
var Interface = /** @class */ (function () {
|
||||
// ParamType is not actually correct here, but for legacy reasons,
|
||||
// we need it. See #721.
|
||||
function Interface(abi) {
|
||||
errors.checkNew(this, Interface);
|
||||
if (typeof (abi) === 'string') {
|
||||
|
||||
@@ -37,13 +37,13 @@ function etcDefaultProvider(url, network) {
|
||||
}
|
||||
var homestead = {
|
||||
chainId: 1,
|
||||
ensAddress: "0x314159265dd8dbb310642f98f50c066173c1259b",
|
||||
ensAddress: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
|
||||
name: "homestead",
|
||||
_defaultProvider: ethDefaultProvider('homestead')
|
||||
};
|
||||
var ropsten = {
|
||||
chainId: 3,
|
||||
ensAddress: "0x112234455c3a32fd11230c42e7bccd4a84e02010",
|
||||
ensAddress: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
|
||||
name: "ropsten",
|
||||
_defaultProvider: ethDefaultProvider('ropsten')
|
||||
};
|
||||
@@ -62,13 +62,13 @@ var networks = {
|
||||
testnet: ropsten,
|
||||
rinkeby: {
|
||||
chainId: 4,
|
||||
ensAddress: "0xe7410170f87102DF0055eB195163A03B7F2Bff4A",
|
||||
ensAddress: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
|
||||
name: 'rinkeby',
|
||||
_defaultProvider: ethDefaultProvider('rinkeby')
|
||||
},
|
||||
goerli: {
|
||||
chainId: 5,
|
||||
ensAddress: "0x112234455c3a32fd11230c42e7bccd4a84e02010",
|
||||
ensAddress: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
|
||||
name: "goerli",
|
||||
_defaultProvider: ethDefaultProvider('goerli')
|
||||
},
|
||||
|
||||
1
utils/secret-storage.d.ts
vendored
1
utils/secret-storage.d.ts
vendored
@@ -6,6 +6,7 @@ export declare type EncryptOptions = {
|
||||
entropy?: Arrayish;
|
||||
mnemonic?: string;
|
||||
path?: string;
|
||||
wordlist?: any;
|
||||
client?: string;
|
||||
salt?: Arrayish;
|
||||
uuid?: string;
|
||||
|
||||
@@ -130,7 +130,8 @@ function decrypt(json, password, progressCallback) {
|
||||
return null;
|
||||
}
|
||||
// Version 0.1 x-ethers metadata must contain an encrypted mnemonic phrase
|
||||
if (searchPath(data, 'x-ethers/version') === '0.1') {
|
||||
var locale = searchPath(data, 'x-ethers/locale');
|
||||
if (searchPath(data, 'x-ethers/version') === '0.1' && (locale == null || locale === "en")) {
|
||||
var mnemonicCiphertext = looseArrayify(searchPath(data, 'x-ethers/mnemonicCiphertext'));
|
||||
var mnemonicIv = looseArrayify(searchPath(data, 'x-ethers/mnemonicCounter'));
|
||||
var mnemonicCounter = new aes_js_1.default.Counter(mnemonicIv);
|
||||
@@ -262,7 +263,7 @@ function encrypt(privateKey, password, options, progressCallback) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
entropy = bytes_1.arrayify(HDNode.mnemonicToEntropy(options.mnemonic));
|
||||
entropy = bytes_1.arrayify(HDNode.mnemonicToEntropy(options.mnemonic, options.wordlist));
|
||||
}
|
||||
}
|
||||
var path = options.path;
|
||||
@@ -387,6 +388,9 @@ function encrypt(privateKey, password, options, progressCallback) {
|
||||
path: path,
|
||||
version: "0.1"
|
||||
};
|
||||
if (options.wordlist && typeof (options.wordlist.locale) === "string") {
|
||||
data['x-ethers'].locale = options.wordlist.locale;
|
||||
}
|
||||
}
|
||||
if (progressCallback) {
|
||||
progressCallback(1);
|
||||
|
||||
Reference in New Issue
Block a user