Updated dist files.

This commit is contained in:
Richard Moore 2018-08-27 13:42:26 +02:00
parent afae5cd2f9
commit ea5a56f0f0
No known key found for this signature in database
GPG Key ID: 525F70A6FCABC295
14 changed files with 129 additions and 73 deletions

@ -33,6 +33,7 @@ export declare class Contract {
readonly [name: string]: ContractFunction | any;
readonly addressPromise: Promise<string>;
readonly deployTransaction: TransactionResponse;
private _deployed;
constructor(addressOrName: string, contractInterface: Array<string | ParamType> | string | Interface, signerOrProvider: Signer | Provider);
deployed(): Promise<Contract>;
fallback(overrides?: TransactionRequest): Promise<TransactionResponse>;

@ -14,7 +14,6 @@ var bignumber_1 = require("../utils/bignumber");
var bytes_1 = require("../utils/bytes");
var constants_1 = require("../utils/constants");
var properties_1 = require("../utils/properties");
var web_1 = require("../utils/web");
var errors = __importStar(require("../utils/errors"));
///////////////////////////////
// Imported Abstracts
@ -93,8 +92,10 @@ function runMethod(contract, functionName, estimateOnly) {
errors.throwError('cannot override ' + key, errors.UNSUPPORTED_OPERATION, { operation: key });
}
});
// Send to the contract address
tx.to = contract.addressPromise;
// Send to the contract address (after checking the contract is deployed)
tx.to = contract.deployed().then(function () {
return contract.addressPromise;
});
return resolveAddresses(contract.provider, params, method.inputs).then(function (params) {
tx.data = method.encode(params);
if (method.type === 'call') {
@ -263,27 +264,36 @@ var Contract = /** @class */ (function () {
// @TODO: Allow timeout?
Contract.prototype.deployed = function () {
var _this = this;
// If we were just deployed, we know the transaction we should occur in
if (this.deployTransaction) {
return this.deployTransaction.wait().then(function () {
return _this;
});
if (!this._deployed) {
// If we were just deployed, we know the transaction we should occur in
if (this.deployTransaction) {
this._deployed = this.deployTransaction.wait().then(function () {
return _this;
});
}
else {
// @TODO: Once we allow a timeout to be passed in, we will wait
// up to that many blocks for getCode
// Otherwise, poll for our code to be deployed
this._deployed = this.provider.getCode(this.address).then(function (code) {
if (code === '0x') {
errors.throwError('contract not deployed', errors.UNSUPPORTED_OPERATION, {
contractAddress: _this.address,
operation: 'getDeployed'
});
}
return _this;
});
}
}
// Otherwise, poll for our code to be deployed
return web_1.poll(function () {
return _this.provider.getCode(_this.address).then(function (code) {
if (code === '0x') {
return undefined;
}
return _this;
});
}, { onceBlock: this.provider });
return this._deployed;
};
// @TODO:
// estimateFallback(overrides?: TransactionRequest): Promise<BigNumber>
// @TODO:
// estimateDeploy(bytecode: string, ...args): Promise<BigNumber>
Contract.prototype.fallback = function (overrides) {
var _this = this;
if (!this.signer) {
errors.throwError('sending a transaction require a signer', errors.UNSUPPORTED_OPERATION, { operation: 'sendTransaction(fallback)' });
}
@ -295,11 +305,17 @@ var Contract = /** @class */ (function () {
errors.throwError('cannot override ' + key, errors.UNSUPPORTED_OPERATION, { operation: key });
});
tx.to = this.addressPromise;
return this.signer.sendTransaction(tx);
return this.deployed().then(function () {
return _this.signer.sendTransaction(tx);
});
};
// Reconnect to a different signer or provider
Contract.prototype.connect = function (signerOrProvider) {
return new Contract(this.address, this.interface, signerOrProvider);
var contract = new Contract(this.address, this.interface, signerOrProvider);
if (this.deployTransaction) {
properties_1.defineReadOnly(contract, 'deployTransaction', this.deployTransaction);
}
return contract;
};
// Re-attach to a different on=chain instance of this contract
Contract.prototype.attach = function (addressOrName) {

92
dist/ethers.js vendored

@ -20,7 +20,6 @@ var bignumber_1 = require("../utils/bignumber");
var bytes_1 = require("../utils/bytes");
var constants_1 = require("../utils/constants");
var properties_1 = require("../utils/properties");
var web_1 = require("../utils/web");
var errors = __importStar(require("../utils/errors"));
///////////////////////////////
// Imported Abstracts
@ -99,8 +98,10 @@ function runMethod(contract, functionName, estimateOnly) {
errors.throwError('cannot override ' + key, errors.UNSUPPORTED_OPERATION, { operation: key });
}
});
// Send to the contract address
tx.to = contract.addressPromise;
// Send to the contract address (after checking the contract is deployed)
tx.to = contract.deployed().then(function () {
return contract.addressPromise;
});
return resolveAddresses(contract.provider, params, method.inputs).then(function (params) {
tx.data = method.encode(params);
if (method.type === 'call') {
@ -269,27 +270,36 @@ var Contract = /** @class */ (function () {
// @TODO: Allow timeout?
Contract.prototype.deployed = function () {
var _this = this;
// If we were just deployed, we know the transaction we should occur in
if (this.deployTransaction) {
return this.deployTransaction.wait().then(function () {
return _this;
});
if (!this._deployed) {
// If we were just deployed, we know the transaction we should occur in
if (this.deployTransaction) {
this._deployed = this.deployTransaction.wait().then(function () {
return _this;
});
}
else {
// @TODO: Once we allow a timeout to be passed in, we will wait
// up to that many blocks for getCode
// Otherwise, poll for our code to be deployed
this._deployed = this.provider.getCode(this.address).then(function (code) {
if (code === '0x') {
errors.throwError('contract not deployed', errors.UNSUPPORTED_OPERATION, {
contractAddress: _this.address,
operation: 'getDeployed'
});
}
return _this;
});
}
}
// Otherwise, poll for our code to be deployed
return web_1.poll(function () {
return _this.provider.getCode(_this.address).then(function (code) {
if (code === '0x') {
return undefined;
}
return _this;
});
}, { onceBlock: this.provider });
return this._deployed;
};
// @TODO:
// estimateFallback(overrides?: TransactionRequest): Promise<BigNumber>
// @TODO:
// estimateDeploy(bytecode: string, ...args): Promise<BigNumber>
Contract.prototype.fallback = function (overrides) {
var _this = this;
if (!this.signer) {
errors.throwError('sending a transaction require a signer', errors.UNSUPPORTED_OPERATION, { operation: 'sendTransaction(fallback)' });
}
@ -301,11 +311,17 @@ var Contract = /** @class */ (function () {
errors.throwError('cannot override ' + key, errors.UNSUPPORTED_OPERATION, { operation: key });
});
tx.to = this.addressPromise;
return this.signer.sendTransaction(tx);
return this.deployed().then(function () {
return _this.signer.sendTransaction(tx);
});
};
// Reconnect to a different signer or provider
Contract.prototype.connect = function (signerOrProvider) {
return new Contract(this.address, this.interface, signerOrProvider);
var contract = new Contract(this.address, this.interface, signerOrProvider);
if (this.deployTransaction) {
properties_1.defineReadOnly(contract, 'deployTransaction', this.deployTransaction);
}
return contract;
};
// Re-attach to a different on=chain instance of this contract
Contract.prototype.attach = function (addressOrName) {
@ -539,7 +555,7 @@ var Contract = /** @class */ (function () {
}());
exports.Contract = Contract;
},{"../providers/abstract-provider":48,"../utils/abi-coder":58,"../utils/address":59,"../utils/bignumber":61,"../utils/bytes":62,"../utils/constants":63,"../utils/errors":64,"../utils/properties":72,"../utils/web":82,"../wallet/abstract-signer":83,"./interface":4}],3:[function(require,module,exports){
},{"../providers/abstract-provider":48,"../utils/abi-coder":58,"../utils/address":59,"../utils/bignumber":61,"../utils/bytes":62,"../utils/constants":63,"../utils/errors":64,"../utils/properties":72,"../wallet/abstract-signer":83,"./interface":4}],3:[function(require,module,exports){
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
var contract_1 = require("./contract");
@ -11562,16 +11578,14 @@ var JsonRpcSigner = /** @class */ (function (_super) {
}
return _this;
}
Object.defineProperty(JsonRpcSigner.prototype, "address", {
get: function () {
if (!this._address) {
errors.throwError('no sync sync address available; use getAddress', errors.UNSUPPORTED_OPERATION, { operation: 'address' });
}
return this._address;
},
enumerable: true,
configurable: true
});
/* May add back in the future; for now it is considered confusing. :)
get address(): string {
if (!this._address) {
errors.throwError('no sync sync address available; use getAddress', errors.UNSUPPORTED_OPERATION, { operation: 'address' });
}
return this._address
}
*/
JsonRpcSigner.prototype.getAddress = function () {
var _this = this;
if (this._address) {
@ -11581,7 +11595,8 @@ var JsonRpcSigner = /** @class */ (function (_super) {
if (accounts.length <= _this._index) {
errors.throwError('unknown account #' + _this._index, errors.UNSUPPORTED_OPERATION, { operation: 'getAddress' });
}
return address_1.getAddress(accounts[_this._index]);
_this._address = address_1.getAddress(accounts[_this._index]);
return _this._address;
});
};
JsonRpcSigner.prototype.getBalance = function (blockTag) {
@ -12204,6 +12219,7 @@ function parseSignatureFunction(fragment) {
abi.constant = true;
abi.stateMutability = 'view';
break;
case 'external':
case 'public':
case '':
break;
@ -13765,6 +13781,7 @@ var RLP = __importStar(require("./rlp"));
exports.RLP = RLP;
var secp256k1_1 = require("./secp256k1");
exports.computePublicKey = secp256k1_1.computePublicKey;
exports.computeSharedSecret = secp256k1_1.computeSharedSecret;
exports.verifyMessage = secp256k1_1.verifyMessage;
var transaction_1 = require("./transaction");
exports.parseTransaction = transaction_1.parse;
@ -14352,15 +14369,24 @@ function computeAddress(key) {
return address_1.getAddress('0x' + keccak256_1.keccak256(publicKey).substring(26));
}
exports.computeAddress = computeAddress;
function verifyMessage(message, signature) {
function computeSharedSecret(privateKey, publicKey) {
var privateKeyPair = getCurve().keyFromPrivate(bytes_1.arrayify(privateKey));
var publicKeyPair = getCurve().keyFromPublic(bytes_1.arrayify(publicKey));
return bytes_1.hexZeroPad('0x' + privateKeyPair.derive(publicKeyPair.getPublic()).toString(16), 32);
}
exports.computeSharedSecret = computeSharedSecret;
function verifyDigest(digest, signature) {
var sig = bytes_1.splitSignature(signature);
var digest = hash_1.hashMessage(message);
return recoverAddress(digest, {
r: sig.r,
s: sig.s,
recoveryParam: sig.recoveryParam
});
}
exports.verifyDigest = verifyDigest;
function verifyMessage(message, signature) {
return verifyDigest(hash_1.hashMessage(message), signature);
}
exports.verifyMessage = verifyMessage;
},{"./address":59,"./bytes":62,"./errors":64,"./hash":65,"./keccak256":69,"./properties":72,"elliptic":11}],76:[function(require,module,exports){

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

@ -164,12 +164,12 @@ declare module 'ethers/utils' {
import { getNetwork } from 'ethers/utils/networks';
import { deepCopy, defineReadOnly, resolveProperties, shallowCopy } from 'ethers/utils/properties';
import * as RLP from 'ethers/utils/rlp';
import { computePublicKey, verifyMessage } from 'ethers/utils/secp256k1';
import { computePublicKey, computeSharedSecret, verifyMessage } from 'ethers/utils/secp256k1';
import { parse as parseTransaction, serialize as serializeTransaction } from 'ethers/utils/transaction';
import { formatBytes32String, parseBytes32String, toUtf8Bytes, toUtf8String } from 'ethers/utils/utf8';
import { formatEther, parseEther, formatUnits, parseUnits } from 'ethers/utils/units';
import { fetchJson } from 'ethers/utils/web';
export { defaultAbiCoder, formatSignature, formatParamType, parseSignature, parseParamType, RLP, fetchJson, getNetwork, deepCopy, defineReadOnly, resolveProperties, shallowCopy, arrayify, concat, padZeros, stripZeros, base64, bigNumberify, hexlify, hexStripZeros, hexZeroPad, hexDataLength, hexDataSlice, toUtf8Bytes, toUtf8String, formatBytes32String, parseBytes32String, hashMessage, namehash, id, getAddress, getIcapAddress, getContractAddress, formatEther, parseEther, formatUnits, parseUnits, keccak256, sha256, randomBytes, solidityPack, solidityKeccak256, soliditySha256, splitSignature, joinSignature, parseTransaction, serializeTransaction, getJsonWalletAddress, computePublicKey, verifyMessage };
export { defaultAbiCoder, formatSignature, formatParamType, parseSignature, parseParamType, RLP, fetchJson, getNetwork, deepCopy, defineReadOnly, resolveProperties, shallowCopy, arrayify, concat, padZeros, stripZeros, base64, bigNumberify, hexlify, hexStripZeros, hexZeroPad, hexDataLength, hexDataSlice, toUtf8Bytes, toUtf8String, formatBytes32String, parseBytes32String, hashMessage, namehash, id, getAddress, getIcapAddress, getContractAddress, formatEther, parseEther, formatUnits, parseUnits, keccak256, sha256, randomBytes, solidityPack, solidityKeccak256, soliditySha256, splitSignature, joinSignature, parseTransaction, serializeTransaction, getJsonWalletAddress, computePublicKey, computeSharedSecret, verifyMessage };
}
declare module 'ethers/types' {
@ -498,7 +498,6 @@ declare module 'ethers/providers/json-rpc-provider' {
export class JsonRpcSigner extends Signer {
readonly provider: JsonRpcProvider;
constructor(constructorGuard: any, provider: JsonRpcProvider, addressOrIndex?: string | number);
readonly address: string;
getAddress(): Promise<string>;
getBalance(blockTag?: BlockTag): Promise<BigNumber>;
getTransactionCount(blockTag?: BlockTag): Promise<number>;
@ -753,6 +752,8 @@ declare module 'ethers/utils/secp256k1' {
export function computePublicKey(key: Arrayish, compressed?: boolean): string;
export function recoverAddress(digest: Arrayish, signature: Signature): string;
export function computeAddress(key: string): string;
export function computeSharedSecret(privateKey: Arrayish, publicKey: Arrayish): string;
export function verifyDigest(digest: Arrayish | string, signature: Signature | string): string;
export function verifyMessage(message: Arrayish | string, signature: Signature | string): string;
}

@ -10,7 +10,6 @@ export declare class JsonRpcSigner extends Signer {
private _index;
private _address;
constructor(constructorGuard: any, provider: JsonRpcProvider, addressOrIndex?: string | number);
readonly address: string;
getAddress(): Promise<string>;
getBalance(blockTag?: BlockTag): Promise<BigNumber>;
getTransactionCount(blockTag?: BlockTag): Promise<number>;

@ -77,16 +77,14 @@ var JsonRpcSigner = /** @class */ (function (_super) {
}
return _this;
}
Object.defineProperty(JsonRpcSigner.prototype, "address", {
get: function () {
if (!this._address) {
errors.throwError('no sync sync address available; use getAddress', errors.UNSUPPORTED_OPERATION, { operation: 'address' });
}
return this._address;
},
enumerable: true,
configurable: true
});
/* May add back in the future; for now it is considered confusing. :)
get address(): string {
if (!this._address) {
errors.throwError('no sync sync address available; use getAddress', errors.UNSUPPORTED_OPERATION, { operation: 'address' });
}
return this._address
}
*/
JsonRpcSigner.prototype.getAddress = function () {
var _this = this;
if (this._address) {
@ -96,7 +94,8 @@ var JsonRpcSigner = /** @class */ (function (_super) {
if (accounts.length <= _this._index) {
errors.throwError('unknown account #' + _this._index, errors.UNSUPPORTED_OPERATION, { operation: 'getAddress' });
}
return address_1.getAddress(accounts[_this._index]);
_this._address = address_1.getAddress(accounts[_this._index]);
return _this._address;
});
};
JsonRpcSigner.prototype.getBalance = function (blockTag) {

1
thirdparty.d.ts vendored

@ -71,6 +71,7 @@ declare module "elliptic" {
getPublic(): BN;
getPrivate(encoding?: string): string;
encode(encoding: string, compressed: boolean): string;
derive(publicKey: BN): BN;
priv: BN;
}

@ -253,6 +253,7 @@ function parseSignatureFunction(fragment) {
abi.constant = true;
abi.stateMutability = 'view';
break;
case 'external':
case 'public':
case '':
break;

4
utils/index.d.ts vendored

@ -12,9 +12,9 @@ import { randomBytes } from './random-bytes';
import { getNetwork } from './networks';
import { deepCopy, defineReadOnly, resolveProperties, shallowCopy } from './properties';
import * as RLP from './rlp';
import { computePublicKey, verifyMessage } from './secp256k1';
import { computePublicKey, computeSharedSecret, verifyMessage } from './secp256k1';
import { parse as parseTransaction, serialize as serializeTransaction } from './transaction';
import { formatBytes32String, parseBytes32String, toUtf8Bytes, toUtf8String } from './utf8';
import { formatEther, parseEther, formatUnits, parseUnits } from './units';
import { fetchJson } from './web';
export { defaultAbiCoder, formatSignature, formatParamType, parseSignature, parseParamType, RLP, fetchJson, getNetwork, deepCopy, defineReadOnly, resolveProperties, shallowCopy, arrayify, concat, padZeros, stripZeros, base64, bigNumberify, hexlify, hexStripZeros, hexZeroPad, hexDataLength, hexDataSlice, toUtf8Bytes, toUtf8String, formatBytes32String, parseBytes32String, hashMessage, namehash, id, getAddress, getIcapAddress, getContractAddress, formatEther, parseEther, formatUnits, parseUnits, keccak256, sha256, randomBytes, solidityPack, solidityKeccak256, soliditySha256, splitSignature, joinSignature, parseTransaction, serializeTransaction, getJsonWalletAddress, computePublicKey, verifyMessage };
export { defaultAbiCoder, formatSignature, formatParamType, parseSignature, parseParamType, RLP, fetchJson, getNetwork, deepCopy, defineReadOnly, resolveProperties, shallowCopy, arrayify, concat, padZeros, stripZeros, base64, bigNumberify, hexlify, hexStripZeros, hexZeroPad, hexDataLength, hexDataSlice, toUtf8Bytes, toUtf8String, formatBytes32String, parseBytes32String, hashMessage, namehash, id, getAddress, getIcapAddress, getContractAddress, formatEther, parseEther, formatUnits, parseUnits, keccak256, sha256, randomBytes, solidityPack, solidityKeccak256, soliditySha256, splitSignature, joinSignature, parseTransaction, serializeTransaction, getJsonWalletAddress, computePublicKey, computeSharedSecret, verifyMessage };

@ -60,6 +60,7 @@ var RLP = __importStar(require("./rlp"));
exports.RLP = RLP;
var secp256k1_1 = require("./secp256k1");
exports.computePublicKey = secp256k1_1.computePublicKey;
exports.computeSharedSecret = secp256k1_1.computeSharedSecret;
exports.verifyMessage = secp256k1_1.verifyMessage;
var transaction_1 = require("./transaction");
exports.parseTransaction = transaction_1.parse;

@ -11,4 +11,6 @@ export declare function recoverPublicKey(digest: Arrayish, signature: Signature)
export declare function computePublicKey(key: Arrayish, compressed?: boolean): string;
export declare function recoverAddress(digest: Arrayish, signature: Signature): string;
export declare function computeAddress(key: string): string;
export declare function computeSharedSecret(privateKey: Arrayish, publicKey: Arrayish): string;
export declare function verifyDigest(digest: Arrayish | string, signature: Signature | string): string;
export declare function verifyMessage(message: Arrayish | string, signature: Signature | string): string;

@ -86,13 +86,22 @@ function computeAddress(key) {
return address_1.getAddress('0x' + keccak256_1.keccak256(publicKey).substring(26));
}
exports.computeAddress = computeAddress;
function verifyMessage(message, signature) {
function computeSharedSecret(privateKey, publicKey) {
var privateKeyPair = getCurve().keyFromPrivate(bytes_1.arrayify(privateKey));
var publicKeyPair = getCurve().keyFromPublic(bytes_1.arrayify(publicKey));
return bytes_1.hexZeroPad('0x' + privateKeyPair.derive(publicKeyPair.getPublic()).toString(16), 32);
}
exports.computeSharedSecret = computeSharedSecret;
function verifyDigest(digest, signature) {
var sig = bytes_1.splitSignature(signature);
var digest = hash_1.hashMessage(message);
return recoverAddress(digest, {
r: sig.r,
s: sig.s,
recoveryParam: sig.recoveryParam
});
}
exports.verifyDigest = verifyDigest;
function verifyMessage(message, signature) {
return verifyDigest(hash_1.hashMessage(message), signature);
}
exports.verifyMessage = verifyMessage;