Added basic authentication to JsonRpcProvider.
This commit is contained in:
parent
eddf9de8f9
commit
e649a22ccf
95
dist/ethers-providers.js
vendored
95
dist/ethers-providers.js
vendored
@ -4231,7 +4231,7 @@ utils.defineProperty(EtherscanProvider.prototype, 'getHistory', function(address
|
|||||||
|
|
||||||
module.exports = EtherscanProvider;;
|
module.exports = EtherscanProvider;;
|
||||||
|
|
||||||
},{"../utils/convert.js":18,"../utils/properties.js":23,"./provider.js":13}],8:[function(require,module,exports){
|
},{"../utils/convert.js":19,"../utils/properties.js":24,"./provider.js":13}],8:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var inherits = require('inherits');
|
var inherits = require('inherits');
|
||||||
@ -4295,7 +4295,7 @@ utils.defineProperty(FallbackProvider.prototype, 'perform', function(method, par
|
|||||||
|
|
||||||
module.exports = FallbackProvider;
|
module.exports = FallbackProvider;
|
||||||
|
|
||||||
},{"../utils/properties.js":23,"./provider.js":13,"inherits":3}],9:[function(require,module,exports){
|
},{"../utils/properties.js":24,"./provider.js":13,"inherits":3}],9:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var Provider = require('./provider');
|
var Provider = require('./provider');
|
||||||
@ -4337,7 +4337,7 @@ if (IpcProvider) {
|
|||||||
|
|
||||||
module.exports = exports;
|
module.exports = exports;
|
||||||
|
|
||||||
},{"./etherscan-provider":7,"./fallback-provider":8,"./infura-provider":10,"./ipc-provider":19,"./json-rpc-provider":11,"./provider":13,"./web3-provider":14}],10:[function(require,module,exports){
|
},{"./etherscan-provider":7,"./fallback-provider":8,"./infura-provider":10,"./ipc-provider":20,"./json-rpc-provider":11,"./provider":13,"./web3-provider":14}],10:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var Provider = require('./provider');
|
var Provider = require('./provider');
|
||||||
@ -4399,7 +4399,7 @@ utils.defineProperty(InfuraProvider.prototype, 'listAccounts', function() {
|
|||||||
|
|
||||||
module.exports = InfuraProvider;
|
module.exports = InfuraProvider;
|
||||||
|
|
||||||
},{"../utils/errors":20,"../utils/properties":23,"./json-rpc-provider":11,"./provider":13}],11:[function(require,module,exports){
|
},{"../utils/errors":21,"../utils/properties":24,"./json-rpc-provider":11,"./provider":13}],11:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// See: https://github.com/ethereum/wiki/wiki/JSON-RPC
|
// See: https://github.com/ethereum/wiki/wiki/JSON-RPC
|
||||||
@ -4561,7 +4561,7 @@ function JsonRpcProvider(url, network) {
|
|||||||
network = Provider.getNetwork(url);
|
network = Provider.getNetwork(url);
|
||||||
url = null;
|
url = null;
|
||||||
} catch (error) { }
|
} catch (error) { }
|
||||||
} else {
|
} else if (url && url.url == null) {
|
||||||
network = url;
|
network = url;
|
||||||
url = null;
|
url = null;
|
||||||
}
|
}
|
||||||
@ -4699,7 +4699,7 @@ utils.defineProperty(JsonRpcProvider, '_hexlifyTransaction', function(transactio
|
|||||||
|
|
||||||
module.exports = JsonRpcProvider;
|
module.exports = JsonRpcProvider;
|
||||||
|
|
||||||
},{"../utils/address":15,"../utils/convert":18,"../utils/errors":20,"../utils/properties":23,"../utils/utf8":26,"./provider.js":13}],12:[function(require,module,exports){
|
},{"../utils/address":15,"../utils/convert":19,"../utils/errors":21,"../utils/properties":24,"../utils/utf8":27,"./provider.js":13}],12:[function(require,module,exports){
|
||||||
module.exports={
|
module.exports={
|
||||||
"unspecified": {
|
"unspecified": {
|
||||||
"chainId": 0,
|
"chainId": 0,
|
||||||
@ -4760,6 +4760,7 @@ var networks = require('./networks.json');
|
|||||||
|
|
||||||
var utils = (function() {
|
var utils = (function() {
|
||||||
var convert = require('../utils/convert');
|
var convert = require('../utils/convert');
|
||||||
|
var utf8 = require('../utils/utf8');
|
||||||
return {
|
return {
|
||||||
defineProperty: require('../utils/properties').defineProperty,
|
defineProperty: require('../utils/properties').defineProperty,
|
||||||
|
|
||||||
@ -4776,14 +4777,19 @@ var utils = (function() {
|
|||||||
hexStripZeros: convert.hexStripZeros,
|
hexStripZeros: convert.hexStripZeros,
|
||||||
stripZeros: convert.stripZeros,
|
stripZeros: convert.stripZeros,
|
||||||
|
|
||||||
|
base64: require('../utils/base64'),
|
||||||
|
|
||||||
namehash: require('../utils/namehash'),
|
namehash: require('../utils/namehash'),
|
||||||
|
|
||||||
toUtf8String: require('../utils/utf8').toUtf8String,
|
toUtf8String: utf8.toUtf8String,
|
||||||
|
toUtf8Bytes: utf8.toUtf8Bytes,
|
||||||
|
|
||||||
RLP: require('../utils/rlp'),
|
RLP: require('../utils/rlp'),
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
var errors = require('../utils/errors');
|
||||||
|
|
||||||
function copyObject(obj) {
|
function copyObject(obj) {
|
||||||
var result = {};
|
var result = {};
|
||||||
for (var key in obj) { result[key] = obj[key]; }
|
for (var key in obj) { result[key] = obj[key]; }
|
||||||
@ -5313,17 +5319,36 @@ utils.defineProperty(Provider, 'getNetwork', function(network) {
|
|||||||
utils.defineProperty(Provider, 'networks', networks);
|
utils.defineProperty(Provider, 'networks', networks);
|
||||||
|
|
||||||
utils.defineProperty(Provider, 'fetchJSON', function(url, json, processFunc) {
|
utils.defineProperty(Provider, 'fetchJSON', function(url, json, processFunc) {
|
||||||
|
var headers = [ ];
|
||||||
|
|
||||||
|
if (typeof(url) === 'object' && url.url != null && url.user != null && url.password != null) {
|
||||||
|
if (url.url.substring(0, 6) !== 'https:' && url.forceInsecure !== true) {
|
||||||
|
errors.throwError('basic authentication requires a secure https url', errors.INVALID_ARGUMENT, { arg: 'url', url: url.url, user: url.user, password: '[REDACTED]' });
|
||||||
|
}
|
||||||
|
|
||||||
|
var authorization = url.user + ':' + url.password;
|
||||||
|
headers.push({
|
||||||
|
key: 'Authorization',
|
||||||
|
value: 'Basic ' + utils.base64.encode(utils.toUtf8Bytes(authorization))
|
||||||
|
});
|
||||||
|
|
||||||
|
url = url.url;
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
var request = new XMLHttpRequest();
|
var request = new XMLHttpRequest();
|
||||||
|
|
||||||
if (json) {
|
if (json) {
|
||||||
request.open('POST', url, true);
|
request.open('POST', url, true);
|
||||||
request.setRequestHeader('Content-Type','application/json');
|
headers.push({ key: 'Content-Type', value: 'application/json' });
|
||||||
} else {
|
} else {
|
||||||
request.open('GET', url, true);
|
request.open('GET', url, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
headers.forEach(function(header) {
|
||||||
|
request.setRequestHeader(header.key, header.value);
|
||||||
|
});
|
||||||
|
|
||||||
request.onreadystatechange = function() {
|
request.onreadystatechange = function() {
|
||||||
if (request.readyState !== 4) { return; }
|
if (request.readyState !== 4) { return; }
|
||||||
|
|
||||||
@ -5906,7 +5931,7 @@ utils.defineProperty(Provider, '_formatters', {
|
|||||||
|
|
||||||
module.exports = Provider;
|
module.exports = Provider;
|
||||||
|
|
||||||
},{"../utils/address":15,"../utils/bignumber":16,"../utils/contract-address":17,"../utils/convert":18,"../utils/namehash":22,"../utils/properties":23,"../utils/rlp":24,"../utils/utf8":26,"./networks.json":12,"inherits":3,"xmlhttprequest":6}],14:[function(require,module,exports){
|
},{"../utils/address":15,"../utils/base64":17,"../utils/bignumber":16,"../utils/contract-address":18,"../utils/convert":19,"../utils/errors":21,"../utils/namehash":23,"../utils/properties":24,"../utils/rlp":25,"../utils/utf8":27,"./networks.json":12,"inherits":3,"xmlhttprequest":6}],14:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var Provider = require('./provider');
|
var Provider = require('./provider');
|
||||||
@ -5976,7 +6001,7 @@ utils.defineProperty(Web3Provider.prototype, 'send', function(method, params) {
|
|||||||
|
|
||||||
module.exports = Web3Provider;
|
module.exports = Web3Provider;
|
||||||
|
|
||||||
},{"../utils/errors":20,"../utils/properties":23,"./json-rpc-provider":11,"./provider":13}],15:[function(require,module,exports){
|
},{"../utils/errors":21,"../utils/properties":24,"./json-rpc-provider":11,"./provider":13}],15:[function(require,module,exports){
|
||||||
|
|
||||||
var BN = require('bn.js');
|
var BN = require('bn.js');
|
||||||
|
|
||||||
@ -6102,7 +6127,7 @@ module.exports = {
|
|||||||
getAddress: getAddress,
|
getAddress: getAddress,
|
||||||
}
|
}
|
||||||
|
|
||||||
},{"./convert":18,"./keccak256":21,"./throw-error":25,"bn.js":1}],16:[function(require,module,exports){
|
},{"./convert":19,"./keccak256":22,"./throw-error":26,"bn.js":1}],16:[function(require,module,exports){
|
||||||
/**
|
/**
|
||||||
* BigNumber
|
* BigNumber
|
||||||
*
|
*
|
||||||
@ -6253,7 +6278,33 @@ module.exports = {
|
|||||||
BigNumber: BigNumber
|
BigNumber: BigNumber
|
||||||
};
|
};
|
||||||
|
|
||||||
},{"./convert":18,"./properties":23,"./throw-error":25,"bn.js":1}],17:[function(require,module,exports){
|
},{"./convert":19,"./properties":24,"./throw-error":26,"bn.js":1}],17:[function(require,module,exports){
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var convert = require('./convert');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
decode: function(textData) {
|
||||||
|
textData = atob(textData);
|
||||||
|
var data = [];
|
||||||
|
for (var i = 0; i < textData.length; i++) {
|
||||||
|
data.push(textData.charCodeAt(i));
|
||||||
|
}
|
||||||
|
return convert.arrayify(data);
|
||||||
|
},
|
||||||
|
encode: function(data) {
|
||||||
|
data = convert.arrayify(data);
|
||||||
|
var textData = '';
|
||||||
|
for (var i = 0; i < data.length; i++) {
|
||||||
|
textData += String.fromCharCode(data[i]);
|
||||||
|
}
|
||||||
|
return btoa(textData);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
},{"./convert":19}],18:[function(require,module,exports){
|
||||||
|
|
||||||
var getAddress = require('./address').getAddress;
|
var getAddress = require('./address').getAddress;
|
||||||
var convert = require('./convert');
|
var convert = require('./convert');
|
||||||
@ -6275,7 +6326,7 @@ module.exports = {
|
|||||||
getContractAddress: getContractAddress,
|
getContractAddress: getContractAddress,
|
||||||
}
|
}
|
||||||
|
|
||||||
},{"./address":15,"./convert":18,"./keccak256":21,"./rlp":24}],18:[function(require,module,exports){
|
},{"./address":15,"./convert":19,"./keccak256":22,"./rlp":25}],19:[function(require,module,exports){
|
||||||
/**
|
/**
|
||||||
* Conversion Utilities
|
* Conversion Utilities
|
||||||
*
|
*
|
||||||
@ -6501,10 +6552,10 @@ module.exports = {
|
|||||||
hexZeroPad: hexZeroPad,
|
hexZeroPad: hexZeroPad,
|
||||||
};
|
};
|
||||||
|
|
||||||
},{"./errors":20,"./properties.js":23}],19:[function(require,module,exports){
|
},{"./errors":21,"./properties.js":24}],20:[function(require,module,exports){
|
||||||
module.exports = undefined;
|
module.exports = undefined;
|
||||||
|
|
||||||
},{}],20:[function(require,module,exports){
|
},{}],21:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var defineProperty = require('./properties').defineProperty;
|
var defineProperty = require('./properties').defineProperty;
|
||||||
@ -6577,7 +6628,7 @@ defineProperty(codes, 'checkNew', function(self, kind) {
|
|||||||
|
|
||||||
module.exports = codes;
|
module.exports = codes;
|
||||||
|
|
||||||
},{"./properties":23}],21:[function(require,module,exports){
|
},{"./properties":24}],22:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var sha3 = require('js-sha3');
|
var sha3 = require('js-sha3');
|
||||||
@ -6591,7 +6642,7 @@ function keccak256(data) {
|
|||||||
|
|
||||||
module.exports = keccak256;
|
module.exports = keccak256;
|
||||||
|
|
||||||
},{"./convert.js":18,"js-sha3":4}],22:[function(require,module,exports){
|
},{"./convert.js":19,"js-sha3":4}],23:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var convert = require('./convert');
|
var convert = require('./convert');
|
||||||
@ -6631,7 +6682,7 @@ function namehash(name, depth) {
|
|||||||
module.exports = namehash;
|
module.exports = namehash;
|
||||||
|
|
||||||
|
|
||||||
},{"./convert":18,"./keccak256":21,"./utf8":26}],23:[function(require,module,exports){
|
},{"./convert":19,"./keccak256":22,"./utf8":27}],24:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function defineProperty(object, name, value) {
|
function defineProperty(object, name, value) {
|
||||||
@ -6655,7 +6706,7 @@ module.exports = {
|
|||||||
defineProperty: defineProperty,
|
defineProperty: defineProperty,
|
||||||
};
|
};
|
||||||
|
|
||||||
},{}],24:[function(require,module,exports){
|
},{}],25:[function(require,module,exports){
|
||||||
//See: https://github.com/ethereum/wiki/wiki/RLP
|
//See: https://github.com/ethereum/wiki/wiki/RLP
|
||||||
|
|
||||||
var convert = require('./convert.js');
|
var convert = require('./convert.js');
|
||||||
@ -6799,7 +6850,7 @@ module.exports = {
|
|||||||
decode: decode,
|
decode: decode,
|
||||||
}
|
}
|
||||||
|
|
||||||
},{"./convert.js":18}],25:[function(require,module,exports){
|
},{"./convert.js":19}],26:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function throwError(message, params) {
|
function throwError(message, params) {
|
||||||
@ -6812,7 +6863,7 @@ function throwError(message, params) {
|
|||||||
|
|
||||||
module.exports = throwError;
|
module.exports = throwError;
|
||||||
|
|
||||||
},{}],26:[function(require,module,exports){
|
},{}],27:[function(require,module,exports){
|
||||||
|
|
||||||
var convert = require('./convert.js');
|
var convert = require('./convert.js');
|
||||||
|
|
||||||
@ -6927,5 +6978,5 @@ module.exports = {
|
|||||||
toUtf8String: bytesToUtf8,
|
toUtf8String: bytesToUtf8,
|
||||||
};
|
};
|
||||||
|
|
||||||
},{"./convert.js":18}]},{},[9])(9)
|
},{"./convert.js":19}]},{},[9])(9)
|
||||||
});
|
});
|
4
dist/ethers-providers.min.js
vendored
4
dist/ethers-providers.min.js
vendored
File diff suppressed because one or more lines are too long
65
dist/ethers-utils.js
vendored
65
dist/ethers-utils.js
vendored
@ -5412,7 +5412,7 @@ utils.defineProperty(Coder, 'defaultCoder', new Coder());
|
|||||||
|
|
||||||
module.exports = Coder
|
module.exports = Coder
|
||||||
|
|
||||||
},{"../utils/address":20,"../utils/bignumber.js":21,"../utils/convert.js":24,"../utils/properties.js":30,"../utils/throw-error":34,"../utils/utf8.js":36}],20:[function(require,module,exports){
|
},{"../utils/address":20,"../utils/bignumber.js":21,"../utils/convert.js":25,"../utils/properties.js":31,"../utils/throw-error":35,"../utils/utf8.js":37}],20:[function(require,module,exports){
|
||||||
|
|
||||||
var BN = require('bn.js');
|
var BN = require('bn.js');
|
||||||
|
|
||||||
@ -5538,7 +5538,7 @@ module.exports = {
|
|||||||
getAddress: getAddress,
|
getAddress: getAddress,
|
||||||
}
|
}
|
||||||
|
|
||||||
},{"./convert":24,"./keccak256":28,"./throw-error":34,"bn.js":1}],21:[function(require,module,exports){
|
},{"./convert":25,"./keccak256":29,"./throw-error":35,"bn.js":1}],21:[function(require,module,exports){
|
||||||
/**
|
/**
|
||||||
* BigNumber
|
* BigNumber
|
||||||
*
|
*
|
||||||
@ -5689,7 +5689,33 @@ module.exports = {
|
|||||||
BigNumber: BigNumber
|
BigNumber: BigNumber
|
||||||
};
|
};
|
||||||
|
|
||||||
},{"./convert":24,"./properties":30,"./throw-error":34,"bn.js":1}],22:[function(require,module,exports){
|
},{"./convert":25,"./properties":31,"./throw-error":35,"bn.js":1}],22:[function(require,module,exports){
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var convert = require('./convert');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
decode: function(textData) {
|
||||||
|
textData = atob(textData);
|
||||||
|
var data = [];
|
||||||
|
for (var i = 0; i < textData.length; i++) {
|
||||||
|
data.push(textData.charCodeAt(i));
|
||||||
|
}
|
||||||
|
return convert.arrayify(data);
|
||||||
|
},
|
||||||
|
encode: function(data) {
|
||||||
|
data = convert.arrayify(data);
|
||||||
|
var textData = '';
|
||||||
|
for (var i = 0; i < data.length; i++) {
|
||||||
|
textData += String.fromCharCode(data[i]);
|
||||||
|
}
|
||||||
|
return btoa(textData);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
},{"./convert":25}],23:[function(require,module,exports){
|
||||||
(function (global){
|
(function (global){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@ -5736,7 +5762,7 @@ if (crypto._weakCrypto === true) {
|
|||||||
module.exports = randomBytes;
|
module.exports = randomBytes;
|
||||||
|
|
||||||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||||||
},{"./convert":24,"./properties":30}],23:[function(require,module,exports){
|
},{"./convert":25,"./properties":31}],24:[function(require,module,exports){
|
||||||
|
|
||||||
var getAddress = require('./address').getAddress;
|
var getAddress = require('./address').getAddress;
|
||||||
var convert = require('./convert');
|
var convert = require('./convert');
|
||||||
@ -5758,7 +5784,7 @@ module.exports = {
|
|||||||
getContractAddress: getContractAddress,
|
getContractAddress: getContractAddress,
|
||||||
}
|
}
|
||||||
|
|
||||||
},{"./address":20,"./convert":24,"./keccak256":28,"./rlp":31}],24:[function(require,module,exports){
|
},{"./address":20,"./convert":25,"./keccak256":29,"./rlp":32}],25:[function(require,module,exports){
|
||||||
/**
|
/**
|
||||||
* Conversion Utilities
|
* Conversion Utilities
|
||||||
*
|
*
|
||||||
@ -5984,7 +6010,7 @@ module.exports = {
|
|||||||
hexZeroPad: hexZeroPad,
|
hexZeroPad: hexZeroPad,
|
||||||
};
|
};
|
||||||
|
|
||||||
},{"./errors":25,"./properties.js":30}],25:[function(require,module,exports){
|
},{"./errors":26,"./properties.js":31}],26:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var defineProperty = require('./properties').defineProperty;
|
var defineProperty = require('./properties').defineProperty;
|
||||||
@ -6057,7 +6083,7 @@ defineProperty(codes, 'checkNew', function(self, kind) {
|
|||||||
|
|
||||||
module.exports = codes;
|
module.exports = codes;
|
||||||
|
|
||||||
},{"./properties":30}],26:[function(require,module,exports){
|
},{"./properties":31}],27:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var keccak256 = require('./keccak256');
|
var keccak256 = require('./keccak256');
|
||||||
@ -6069,7 +6095,7 @@ function id(text) {
|
|||||||
|
|
||||||
module.exports = id;
|
module.exports = id;
|
||||||
|
|
||||||
},{"./keccak256":28,"./utf8":36}],27:[function(require,module,exports){
|
},{"./keccak256":29,"./utf8":37}],28:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// This is SUPER useful, but adds 140kb (even zipped, adds 40kb)
|
// This is SUPER useful, but adds 140kb (even zipped, adds 40kb)
|
||||||
@ -6077,6 +6103,7 @@ module.exports = id;
|
|||||||
|
|
||||||
var address = require('./address');
|
var address = require('./address');
|
||||||
var AbiCoder = require('./abi-coder');
|
var AbiCoder = require('./abi-coder');
|
||||||
|
var base64 = require('./base64');
|
||||||
var bigNumber = require('./bignumber');
|
var bigNumber = require('./bignumber');
|
||||||
var contractAddress = require('./contract-address');
|
var contractAddress = require('./contract-address');
|
||||||
var convert = require('./convert');
|
var convert = require('./convert');
|
||||||
@ -6111,6 +6138,8 @@ module.exports = {
|
|||||||
padZeros: convert.padZeros,
|
padZeros: convert.padZeros,
|
||||||
stripZeros: convert.stripZeros,
|
stripZeros: convert.stripZeros,
|
||||||
|
|
||||||
|
base64: base64,
|
||||||
|
|
||||||
bigNumberify: bigNumber.bigNumberify,
|
bigNumberify: bigNumber.bigNumberify,
|
||||||
BigNumber: bigNumber.BigNumber,
|
BigNumber: bigNumber.BigNumber,
|
||||||
|
|
||||||
@ -6143,7 +6172,7 @@ module.exports = {
|
|||||||
splitSignature: convert.splitSignature,
|
splitSignature: convert.splitSignature,
|
||||||
}
|
}
|
||||||
|
|
||||||
},{"./abi-coder":19,"./address":20,"./bignumber":21,"./contract-address":23,"./convert":24,"./id":26,"./keccak256":28,"./namehash":29,"./properties":30,"./random-bytes":22,"./rlp":31,"./sha2":32,"./solidity":33,"./units":35,"./utf8":36}],28:[function(require,module,exports){
|
},{"./abi-coder":19,"./address":20,"./base64":22,"./bignumber":21,"./contract-address":24,"./convert":25,"./id":27,"./keccak256":29,"./namehash":30,"./properties":31,"./random-bytes":23,"./rlp":32,"./sha2":33,"./solidity":34,"./units":36,"./utf8":37}],29:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var sha3 = require('js-sha3');
|
var sha3 = require('js-sha3');
|
||||||
@ -6157,7 +6186,7 @@ function keccak256(data) {
|
|||||||
|
|
||||||
module.exports = keccak256;
|
module.exports = keccak256;
|
||||||
|
|
||||||
},{"./convert.js":24,"js-sha3":16}],29:[function(require,module,exports){
|
},{"./convert.js":25,"js-sha3":16}],30:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var convert = require('./convert');
|
var convert = require('./convert');
|
||||||
@ -6197,7 +6226,7 @@ function namehash(name, depth) {
|
|||||||
module.exports = namehash;
|
module.exports = namehash;
|
||||||
|
|
||||||
|
|
||||||
},{"./convert":24,"./keccak256":28,"./utf8":36}],30:[function(require,module,exports){
|
},{"./convert":25,"./keccak256":29,"./utf8":37}],31:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function defineProperty(object, name, value) {
|
function defineProperty(object, name, value) {
|
||||||
@ -6221,7 +6250,7 @@ module.exports = {
|
|||||||
defineProperty: defineProperty,
|
defineProperty: defineProperty,
|
||||||
};
|
};
|
||||||
|
|
||||||
},{}],31:[function(require,module,exports){
|
},{}],32:[function(require,module,exports){
|
||||||
//See: https://github.com/ethereum/wiki/wiki/RLP
|
//See: https://github.com/ethereum/wiki/wiki/RLP
|
||||||
|
|
||||||
var convert = require('./convert.js');
|
var convert = require('./convert.js');
|
||||||
@ -6365,7 +6394,7 @@ module.exports = {
|
|||||||
decode: decode,
|
decode: decode,
|
||||||
}
|
}
|
||||||
|
|
||||||
},{"./convert.js":24}],32:[function(require,module,exports){
|
},{"./convert.js":25}],33:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var hash = require('hash.js');
|
var hash = require('hash.js');
|
||||||
@ -6390,7 +6419,7 @@ module.exports = {
|
|||||||
createSha512: hash.sha512,
|
createSha512: hash.sha512,
|
||||||
}
|
}
|
||||||
|
|
||||||
},{"./convert.js":24,"hash.js":3}],33:[function(require,module,exports){
|
},{"./convert.js":25,"hash.js":3}],34:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var bigNumberify = require('./bignumber').bigNumberify;
|
var bigNumberify = require('./bignumber').bigNumberify;
|
||||||
@ -6489,7 +6518,7 @@ module.exports = {
|
|||||||
sha256: sha256,
|
sha256: sha256,
|
||||||
}
|
}
|
||||||
|
|
||||||
},{"./address":20,"./bignumber":21,"./convert":24,"./keccak256":28,"./sha2":32,"./utf8":36}],34:[function(require,module,exports){
|
},{"./address":20,"./bignumber":21,"./convert":25,"./keccak256":29,"./sha2":33,"./utf8":37}],35:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function throwError(message, params) {
|
function throwError(message, params) {
|
||||||
@ -6502,7 +6531,7 @@ function throwError(message, params) {
|
|||||||
|
|
||||||
module.exports = throwError;
|
module.exports = throwError;
|
||||||
|
|
||||||
},{}],35:[function(require,module,exports){
|
},{}],36:[function(require,module,exports){
|
||||||
var bigNumberify = require('./bignumber.js').bigNumberify;
|
var bigNumberify = require('./bignumber.js').bigNumberify;
|
||||||
var throwError = require('./throw-error');
|
var throwError = require('./throw-error');
|
||||||
|
|
||||||
@ -6652,7 +6681,7 @@ module.exports = {
|
|||||||
parseUnits: parseUnits,
|
parseUnits: parseUnits,
|
||||||
}
|
}
|
||||||
|
|
||||||
},{"./bignumber.js":21,"./throw-error":34}],36:[function(require,module,exports){
|
},{"./bignumber.js":21,"./throw-error":35}],37:[function(require,module,exports){
|
||||||
|
|
||||||
var convert = require('./convert.js');
|
var convert = require('./convert.js');
|
||||||
|
|
||||||
@ -6767,5 +6796,5 @@ module.exports = {
|
|||||||
toUtf8String: bytesToUtf8,
|
toUtf8String: bytesToUtf8,
|
||||||
};
|
};
|
||||||
|
|
||||||
},{"./convert.js":24}]},{},[27])(27)
|
},{"./convert.js":25}]},{},[28])(28)
|
||||||
});
|
});
|
2
dist/ethers-utils.min.js
vendored
2
dist/ethers-utils.min.js
vendored
File diff suppressed because one or more lines are too long
83
dist/ethers-wallet.js
vendored
83
dist/ethers-wallet.js
vendored
File diff suppressed because one or more lines are too long
8
dist/ethers-wallet.min.js
vendored
8
dist/ethers-wallet.min.js
vendored
File diff suppressed because one or more lines are too long
136
dist/ethers.js
vendored
136
dist/ethers.js
vendored
File diff suppressed because one or more lines are too long
10
dist/ethers.min.js
vendored
10
dist/ethers.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ethers",
|
"name": "ethers",
|
||||||
"version": "3.0.11",
|
"version": "3.0.12",
|
||||||
"description": "Ethereum wallet library.",
|
"description": "Ethereum wallet library.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -35,6 +35,7 @@
|
|||||||
"browser": {
|
"browser": {
|
||||||
"fs": "./tests/browser-fs.js",
|
"fs": "./tests/browser-fs.js",
|
||||||
"zlib": "browserify-zlib",
|
"zlib": "browserify-zlib",
|
||||||
|
"./utils/base64.js": "./utils/browser-base64.js",
|
||||||
"./utils/random-bytes.js": "./utils/browser-random-bytes.js",
|
"./utils/random-bytes.js": "./utils/browser-random-bytes.js",
|
||||||
"./providers/ipc-provider.js": "./utils/empty.js",
|
"./providers/ipc-provider.js": "./utils/empty.js",
|
||||||
"xmlhttprequest": "./providers/browser-xmlhttprequest.js"
|
"xmlhttprequest": "./providers/browser-xmlhttprequest.js"
|
||||||
|
@ -159,7 +159,7 @@ function JsonRpcProvider(url, network) {
|
|||||||
network = Provider.getNetwork(url);
|
network = Provider.getNetwork(url);
|
||||||
url = null;
|
url = null;
|
||||||
} catch (error) { }
|
} catch (error) { }
|
||||||
} else {
|
} else if (url && url.url == null) {
|
||||||
network = url;
|
network = url;
|
||||||
url = null;
|
url = null;
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ var networks = require('./networks.json');
|
|||||||
|
|
||||||
var utils = (function() {
|
var utils = (function() {
|
||||||
var convert = require('../utils/convert');
|
var convert = require('../utils/convert');
|
||||||
|
var utf8 = require('../utils/utf8');
|
||||||
return {
|
return {
|
||||||
defineProperty: require('../utils/properties').defineProperty,
|
defineProperty: require('../utils/properties').defineProperty,
|
||||||
|
|
||||||
@ -24,14 +25,19 @@ var utils = (function() {
|
|||||||
hexStripZeros: convert.hexStripZeros,
|
hexStripZeros: convert.hexStripZeros,
|
||||||
stripZeros: convert.stripZeros,
|
stripZeros: convert.stripZeros,
|
||||||
|
|
||||||
|
base64: require('../utils/base64'),
|
||||||
|
|
||||||
namehash: require('../utils/namehash'),
|
namehash: require('../utils/namehash'),
|
||||||
|
|
||||||
toUtf8String: require('../utils/utf8').toUtf8String,
|
toUtf8String: utf8.toUtf8String,
|
||||||
|
toUtf8Bytes: utf8.toUtf8Bytes,
|
||||||
|
|
||||||
RLP: require('../utils/rlp'),
|
RLP: require('../utils/rlp'),
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
var errors = require('../utils/errors');
|
||||||
|
|
||||||
function copyObject(obj) {
|
function copyObject(obj) {
|
||||||
var result = {};
|
var result = {};
|
||||||
for (var key in obj) { result[key] = obj[key]; }
|
for (var key in obj) { result[key] = obj[key]; }
|
||||||
@ -561,17 +567,36 @@ utils.defineProperty(Provider, 'getNetwork', function(network) {
|
|||||||
utils.defineProperty(Provider, 'networks', networks);
|
utils.defineProperty(Provider, 'networks', networks);
|
||||||
|
|
||||||
utils.defineProperty(Provider, 'fetchJSON', function(url, json, processFunc) {
|
utils.defineProperty(Provider, 'fetchJSON', function(url, json, processFunc) {
|
||||||
|
var headers = [ ];
|
||||||
|
|
||||||
|
if (typeof(url) === 'object' && url.url != null && url.user != null && url.password != null) {
|
||||||
|
if (url.url.substring(0, 6) !== 'https:' && url.forceInsecure !== true) {
|
||||||
|
errors.throwError('basic authentication requires a secure https url', errors.INVALID_ARGUMENT, { arg: 'url', url: url.url, user: url.user, password: '[REDACTED]' });
|
||||||
|
}
|
||||||
|
|
||||||
|
var authorization = url.user + ':' + url.password;
|
||||||
|
headers.push({
|
||||||
|
key: 'Authorization',
|
||||||
|
value: 'Basic ' + utils.base64.encode(utils.toUtf8Bytes(authorization))
|
||||||
|
});
|
||||||
|
|
||||||
|
url = url.url;
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
var request = new XMLHttpRequest();
|
var request = new XMLHttpRequest();
|
||||||
|
|
||||||
if (json) {
|
if (json) {
|
||||||
request.open('POST', url, true);
|
request.open('POST', url, true);
|
||||||
request.setRequestHeader('Content-Type','application/json');
|
headers.push({ key: 'Content-Type', value: 'application/json' });
|
||||||
} else {
|
} else {
|
||||||
request.open('GET', url, true);
|
request.open('GET', url, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
headers.forEach(function(header) {
|
||||||
|
request.setRequestHeader(header.key, header.value);
|
||||||
|
});
|
||||||
|
|
||||||
request.onreadystatechange = function() {
|
request.onreadystatechange = function() {
|
||||||
if (request.readyState !== 4) { return; }
|
if (request.readyState !== 4) { return; }
|
||||||
|
|
||||||
|
@ -407,3 +407,47 @@ describe('Test extra Etherscan operations', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Test Basic Authentication', function() {
|
||||||
|
// https://stackoverflow.com/questions/6509278/authentication-test-servers#16756383
|
||||||
|
|
||||||
|
var Provider = require('..').providers.Provider;
|
||||||
|
|
||||||
|
function test(name, url) {
|
||||||
|
it('tests ' + name, function() {
|
||||||
|
return Provider.fetchJSON(url).then(function(data) {
|
||||||
|
assert.equal(data.authenticated, true, 'authenticates user');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var secure = {
|
||||||
|
url: 'https://httpbin.org/basic-auth/user/passwd',
|
||||||
|
user: 'user',
|
||||||
|
password: 'passwd'
|
||||||
|
};
|
||||||
|
|
||||||
|
var insecure = {
|
||||||
|
url: 'http://httpbin.org/basic-auth/user/passwd',
|
||||||
|
user: 'user',
|
||||||
|
password: 'passwd'
|
||||||
|
};
|
||||||
|
|
||||||
|
var insecureForced = {
|
||||||
|
url: 'http://httpbin.org/basic-auth/user/passwd',
|
||||||
|
user: 'user',
|
||||||
|
password: 'passwd',
|
||||||
|
forceInsecure: true
|
||||||
|
};
|
||||||
|
|
||||||
|
test('secure url', secure);
|
||||||
|
test('insecure url', insecureForced);
|
||||||
|
|
||||||
|
it('tests insecure connections fail', function() {
|
||||||
|
assert.throws(function() {
|
||||||
|
Provider.fetchJSON(insecure);
|
||||||
|
}, function(error) {
|
||||||
|
return (error.reason === 'basic authentication requires a secure https url');
|
||||||
|
}, 'throws an exception for insecure connections');
|
||||||
|
})
|
||||||
|
});
|
||||||
|
@ -211,3 +211,18 @@ describe('Test Solidity splitSignature', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Test Base64 coder', function() {
|
||||||
|
|
||||||
|
var utf8 = require('../utils/utf8')
|
||||||
|
var base64 = require('../utils').base64;
|
||||||
|
|
||||||
|
// https://en.wikipedia.org/wiki/Base64#Examples
|
||||||
|
it('encodes and decodes the example from wikipedia', function() {
|
||||||
|
var decodedText = 'Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.';
|
||||||
|
var decoded = utf8.toUtf8Bytes(decodedText);
|
||||||
|
var encoded = 'TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=';
|
||||||
|
assert.equal(base64.encode(decoded), encoded, 'encodes to base64 string');
|
||||||
|
assert.equal(utf8.toUtf8String(base64.decode(encoded)), decodedText, 'decodes from base64 sstring');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
13
utils/base64.js
Normal file
13
utils/base64.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var convert = require('./convert');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
decode: function(textData) {
|
||||||
|
return convert.arrayify(new Buffer(textData, 'base64'));
|
||||||
|
},
|
||||||
|
|
||||||
|
encode: function(data) {
|
||||||
|
return (new Buffer(convert.arrayify(data))).toString('base64');
|
||||||
|
}
|
||||||
|
};
|
24
utils/browser-base64.js
Normal file
24
utils/browser-base64.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var convert = require('./convert');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
decode: function(textData) {
|
||||||
|
textData = atob(textData);
|
||||||
|
var data = [];
|
||||||
|
for (var i = 0; i < textData.length; i++) {
|
||||||
|
data.push(textData.charCodeAt(i));
|
||||||
|
}
|
||||||
|
return convert.arrayify(data);
|
||||||
|
},
|
||||||
|
encode: function(data) {
|
||||||
|
data = convert.arrayify(data);
|
||||||
|
var textData = '';
|
||||||
|
for (var i = 0; i < data.length; i++) {
|
||||||
|
textData += String.fromCharCode(data[i]);
|
||||||
|
}
|
||||||
|
return btoa(textData);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
var address = require('./address');
|
var address = require('./address');
|
||||||
var AbiCoder = require('./abi-coder');
|
var AbiCoder = require('./abi-coder');
|
||||||
|
var base64 = require('./base64');
|
||||||
var bigNumber = require('./bignumber');
|
var bigNumber = require('./bignumber');
|
||||||
var contractAddress = require('./contract-address');
|
var contractAddress = require('./contract-address');
|
||||||
var convert = require('./convert');
|
var convert = require('./convert');
|
||||||
@ -39,6 +40,8 @@ module.exports = {
|
|||||||
padZeros: convert.padZeros,
|
padZeros: convert.padZeros,
|
||||||
stripZeros: convert.stripZeros,
|
stripZeros: convert.stripZeros,
|
||||||
|
|
||||||
|
base64: base64,
|
||||||
|
|
||||||
bigNumberify: bigNumber.bigNumberify,
|
bigNumberify: bigNumber.bigNumberify,
|
||||||
BigNumber: bigNumber.BigNumber,
|
BigNumber: bigNumber.BigNumber,
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user