Updated dist files.
This commit is contained in:
parent
e092746165
commit
810e9e743e
2
_version.d.ts
vendored
2
_version.d.ts
vendored
@ -1 +1 @@
|
|||||||
export declare const version = "4.0.0-beta.12";
|
export declare const version = "4.0.0-beta.13";
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.version = "4.0.0-beta.12";
|
exports.version = "4.0.0-beta.13";
|
||||||
|
@ -426,7 +426,7 @@ var Contract = /** @class */ (function () {
|
|||||||
}
|
}
|
||||||
var wrappedListener = function (log) {
|
var wrappedListener = function (log) {
|
||||||
var decoded = Array.prototype.slice.call(eventFilter.decode(log));
|
var decoded = Array.prototype.slice.call(eventFilter.decode(log));
|
||||||
var event = properties_1.jsonCopy(log);
|
var event = properties_1.deepCopy(log);
|
||||||
event.args = decoded;
|
event.args = decoded;
|
||||||
event.decode = eventFilter.event.decode;
|
event.decode = eventFilter.event.decode;
|
||||||
event.event = eventFilter.event.name;
|
event.event = eventFilter.event.name;
|
||||||
|
@ -36,20 +36,11 @@ var _Indexed = /** @class */ (function () {
|
|||||||
}());
|
}());
|
||||||
var Description = /** @class */ (function () {
|
var Description = /** @class */ (function () {
|
||||||
function Description(info) {
|
function Description(info) {
|
||||||
|
properties_1.setType(this, 'Description');
|
||||||
for (var key in info) {
|
for (var key in info) {
|
||||||
var value = info[key];
|
properties_1.defineReadOnly(this, key, properties_1.deepCopy(info[key], true));
|
||||||
if (value != null && typeof (value) === 'object') {
|
|
||||||
if (bignumber_1.BigNumber.isBigNumber(value)) {
|
|
||||||
properties_1.defineReadOnly(this, key, value);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
properties_1.defineFrozen(this, key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
properties_1.defineReadOnly(this, key, value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Object.freeze(this);
|
||||||
}
|
}
|
||||||
return Description;
|
return Description;
|
||||||
}());
|
}());
|
||||||
@ -195,7 +186,7 @@ var _EventDescription = /** @class */ (function (_super) {
|
|||||||
var resultIndexed = abi_coder_1.defaultAbiCoder.decode(inputIndexed, bytes_1.concat(topics));
|
var resultIndexed = abi_coder_1.defaultAbiCoder.decode(inputIndexed, bytes_1.concat(topics));
|
||||||
}
|
}
|
||||||
var resultNonIndexed = abi_coder_1.defaultAbiCoder.decode(inputNonIndexed, bytes_1.arrayify(data));
|
var resultNonIndexed = abi_coder_1.defaultAbiCoder.decode(inputNonIndexed, bytes_1.arrayify(data));
|
||||||
var result = new Result({});
|
var result = {};
|
||||||
var nonIndexedIndex = 0, indexedIndex = 0;
|
var nonIndexedIndex = 0, indexedIndex = 0;
|
||||||
this.inputs.forEach(function (input, index) {
|
this.inputs.forEach(function (input, index) {
|
||||||
if (input.indexed) {
|
if (input.indexed) {
|
||||||
@ -217,7 +208,7 @@ var _EventDescription = /** @class */ (function (_super) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
result.length = this.inputs.length;
|
result.length = this.inputs.length;
|
||||||
return result;
|
return new Result(result);
|
||||||
};
|
};
|
||||||
return _EventDescription;
|
return _EventDescription;
|
||||||
}(Description));
|
}(Description));
|
||||||
@ -326,7 +317,7 @@ var Interface = /** @class */ (function () {
|
|||||||
// @TODO: We should probable do some validation; create abiCoder.formatSignature for checking
|
// @TODO: We should probable do some validation; create abiCoder.formatSignature for checking
|
||||||
_abi.push(fragment);
|
_abi.push(fragment);
|
||||||
});
|
});
|
||||||
properties_1.defineFrozen(this, 'abi', _abi);
|
properties_1.defineReadOnly(this, 'abi', properties_1.deepCopy(_abi, true));
|
||||||
_abi.forEach(addMethod, this);
|
_abi.forEach(addMethod, this);
|
||||||
// If there wasn't a constructor, create the default constructor
|
// If there wasn't a constructor, create the default constructor
|
||||||
if (!this.deployFunction) {
|
if (!this.deployFunction) {
|
||||||
|
243
dist/ethers.js
vendored
243
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){
|
(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";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.version = "4.0.0-beta.12";
|
exports.version = "4.0.0-beta.13";
|
||||||
|
|
||||||
},{}],2:[function(require,module,exports){
|
},{}],2:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
@ -432,7 +432,7 @@ var Contract = /** @class */ (function () {
|
|||||||
}
|
}
|
||||||
var wrappedListener = function (log) {
|
var wrappedListener = function (log) {
|
||||||
var decoded = Array.prototype.slice.call(eventFilter.decode(log));
|
var decoded = Array.prototype.slice.call(eventFilter.decode(log));
|
||||||
var event = properties_1.jsonCopy(log);
|
var event = properties_1.deepCopy(log);
|
||||||
event.args = decoded;
|
event.args = decoded;
|
||||||
event.decode = eventFilter.event.decode;
|
event.decode = eventFilter.event.decode;
|
||||||
event.event = eventFilter.event.name;
|
event.event = eventFilter.event.name;
|
||||||
@ -586,20 +586,11 @@ var _Indexed = /** @class */ (function () {
|
|||||||
}());
|
}());
|
||||||
var Description = /** @class */ (function () {
|
var Description = /** @class */ (function () {
|
||||||
function Description(info) {
|
function Description(info) {
|
||||||
|
properties_1.setType(this, 'Description');
|
||||||
for (var key in info) {
|
for (var key in info) {
|
||||||
var value = info[key];
|
properties_1.defineReadOnly(this, key, properties_1.deepCopy(info[key], true));
|
||||||
if (value != null && typeof (value) === 'object') {
|
|
||||||
if (bignumber_1.BigNumber.isBigNumber(value)) {
|
|
||||||
properties_1.defineReadOnly(this, key, value);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
properties_1.defineFrozen(this, key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
properties_1.defineReadOnly(this, key, value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Object.freeze(this);
|
||||||
}
|
}
|
||||||
return Description;
|
return Description;
|
||||||
}());
|
}());
|
||||||
@ -745,7 +736,7 @@ var _EventDescription = /** @class */ (function (_super) {
|
|||||||
var resultIndexed = abi_coder_1.defaultAbiCoder.decode(inputIndexed, bytes_1.concat(topics));
|
var resultIndexed = abi_coder_1.defaultAbiCoder.decode(inputIndexed, bytes_1.concat(topics));
|
||||||
}
|
}
|
||||||
var resultNonIndexed = abi_coder_1.defaultAbiCoder.decode(inputNonIndexed, bytes_1.arrayify(data));
|
var resultNonIndexed = abi_coder_1.defaultAbiCoder.decode(inputNonIndexed, bytes_1.arrayify(data));
|
||||||
var result = new Result({});
|
var result = {};
|
||||||
var nonIndexedIndex = 0, indexedIndex = 0;
|
var nonIndexedIndex = 0, indexedIndex = 0;
|
||||||
this.inputs.forEach(function (input, index) {
|
this.inputs.forEach(function (input, index) {
|
||||||
if (input.indexed) {
|
if (input.indexed) {
|
||||||
@ -767,7 +758,7 @@ var _EventDescription = /** @class */ (function (_super) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
result.length = this.inputs.length;
|
result.length = this.inputs.length;
|
||||||
return result;
|
return new Result(result);
|
||||||
};
|
};
|
||||||
return _EventDescription;
|
return _EventDescription;
|
||||||
}(Description));
|
}(Description));
|
||||||
@ -876,7 +867,7 @@ var Interface = /** @class */ (function () {
|
|||||||
// @TODO: We should probable do some validation; create abiCoder.formatSignature for checking
|
// @TODO: We should probable do some validation; create abiCoder.formatSignature for checking
|
||||||
_abi.push(fragment);
|
_abi.push(fragment);
|
||||||
});
|
});
|
||||||
properties_1.defineFrozen(this, 'abi', _abi);
|
properties_1.defineReadOnly(this, 'abi', properties_1.deepCopy(_abi, true));
|
||||||
_abi.forEach(addMethod, this);
|
_abi.forEach(addMethod, this);
|
||||||
// If there wasn't a constructor, create the default constructor
|
// If there wasn't a constructor, create the default constructor
|
||||||
if (!this.deployFunction) {
|
if (!this.deployFunction) {
|
||||||
@ -12840,8 +12831,9 @@ function getParamCoder(coerceFunc, param) {
|
|||||||
var match = param.type.match(paramTypeArray);
|
var match = param.type.match(paramTypeArray);
|
||||||
if (match) {
|
if (match) {
|
||||||
var size = parseInt(match[2] || "-1");
|
var size = parseInt(match[2] || "-1");
|
||||||
param = properties_1.jsonCopy(param);
|
param = properties_1.shallowCopy(param);
|
||||||
param.type = match[1];
|
param.type = match[1];
|
||||||
|
param = properties_1.deepCopy(param);
|
||||||
return new CoderArray(coerceFunc, getParamCoder(coerceFunc, param), size, param.name);
|
return new CoderArray(coerceFunc, getParamCoder(coerceFunc, param), size, param.name);
|
||||||
}
|
}
|
||||||
if (param.type.substring(0, 5) === 'tuple') {
|
if (param.type.substring(0, 5) === 'tuple') {
|
||||||
@ -12896,7 +12888,7 @@ var AbiCoder = /** @class */ (function () {
|
|||||||
typeObject = parseParam(type);
|
typeObject = parseParam(type);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
typeObject = properties_1.jsonCopy(type);
|
typeObject = properties_1.deepCopy(type);
|
||||||
}
|
}
|
||||||
coders.push(getParamCoder(this.coerceFunc, typeObject));
|
coders.push(getParamCoder(this.coerceFunc, typeObject));
|
||||||
}, this);
|
}, this);
|
||||||
@ -13765,7 +13757,7 @@ exports.randomBytes = random_bytes_1.randomBytes;
|
|||||||
var networks_1 = require("./networks");
|
var networks_1 = require("./networks");
|
||||||
exports.getNetwork = networks_1.getNetwork;
|
exports.getNetwork = networks_1.getNetwork;
|
||||||
var properties_1 = require("./properties");
|
var properties_1 = require("./properties");
|
||||||
exports.defineFrozen = properties_1.defineFrozen;
|
exports.deepCopy = properties_1.deepCopy;
|
||||||
exports.defineReadOnly = properties_1.defineReadOnly;
|
exports.defineReadOnly = properties_1.defineReadOnly;
|
||||||
exports.resolveProperties = properties_1.resolveProperties;
|
exports.resolveProperties = properties_1.resolveProperties;
|
||||||
exports.shallowCopy = properties_1.shallowCopy;
|
exports.shallowCopy = properties_1.shallowCopy;
|
||||||
@ -13778,6 +13770,8 @@ var transaction_1 = require("./transaction");
|
|||||||
exports.parseTransaction = transaction_1.parse;
|
exports.parseTransaction = transaction_1.parse;
|
||||||
exports.serializeTransaction = transaction_1.serialize;
|
exports.serializeTransaction = transaction_1.serialize;
|
||||||
var utf8_1 = require("./utf8");
|
var utf8_1 = require("./utf8");
|
||||||
|
exports.formatBytes32String = utf8_1.formatBytes32String;
|
||||||
|
exports.parseBytes32String = utf8_1.parseBytes32String;
|
||||||
exports.toUtf8Bytes = utf8_1.toUtf8Bytes;
|
exports.toUtf8Bytes = utf8_1.toUtf8Bytes;
|
||||||
exports.toUtf8String = utf8_1.toUtf8String;
|
exports.toUtf8String = utf8_1.toUtf8String;
|
||||||
var units_1 = require("./units");
|
var units_1 = require("./units");
|
||||||
@ -14010,14 +14004,6 @@ function defineReadOnly(object, name, value) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.defineReadOnly = defineReadOnly;
|
exports.defineReadOnly = defineReadOnly;
|
||||||
function defineFrozen(object, name, value) {
|
|
||||||
var frozen = JSON.stringify(value);
|
|
||||||
Object.defineProperty(object, name, {
|
|
||||||
enumerable: true,
|
|
||||||
get: function () { return JSON.parse(frozen); }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
exports.defineFrozen = defineFrozen;
|
|
||||||
// There are some issues with instanceof with npm link, so we use this
|
// There are some issues with instanceof with npm link, so we use this
|
||||||
// to ensure types are what we expect.
|
// to ensure types are what we expect.
|
||||||
function setType(object, type) {
|
function setType(object, type) {
|
||||||
@ -14056,10 +14042,48 @@ function shallowCopy(object) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
exports.shallowCopy = shallowCopy;
|
exports.shallowCopy = shallowCopy;
|
||||||
function jsonCopy(object) {
|
var opaque = { boolean: true, number: true, string: true };
|
||||||
return JSON.parse(JSON.stringify(object));
|
function deepCopy(object, frozen) {
|
||||||
|
if (object === undefined || object === null || opaque[typeof (object)]) {
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
if (Array.isArray(object)) {
|
||||||
|
var result_1 = [];
|
||||||
|
object.forEach(function (item) {
|
||||||
|
result_1.push(deepCopy(item, frozen));
|
||||||
|
});
|
||||||
|
if (frozen) {
|
||||||
|
Object.freeze(result_1);
|
||||||
|
}
|
||||||
|
return result_1;
|
||||||
|
}
|
||||||
|
if (typeof (object) === 'object') {
|
||||||
|
// Some internal objects, which are already immutable
|
||||||
|
if (isType(object, 'BigNumber')) {
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
if (isType(object, 'Description')) {
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
if (isType(object, 'Indexed')) {
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
var result = {};
|
||||||
|
for (var key in object) {
|
||||||
|
var value = object[key];
|
||||||
|
if (value === undefined) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
defineReadOnly(result, key, deepCopy(value, frozen));
|
||||||
|
}
|
||||||
|
if (frozen) {
|
||||||
|
Object.freeze(result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
throw new Error('Cannot deepCopy ' + typeof (object));
|
||||||
}
|
}
|
||||||
exports.jsonCopy = jsonCopy;
|
exports.deepCopy = deepCopy;
|
||||||
// See: https://github.com/isaacs/inherits/blob/master/inherits_browser.js
|
// See: https://github.com/isaacs/inherits/blob/master/inherits_browser.js
|
||||||
function inherits(ctor, superCtor) {
|
function inherits(ctor, superCtor) {
|
||||||
ctor.super_ = superCtor;
|
ctor.super_ = superCtor;
|
||||||
@ -14617,7 +14641,7 @@ var names = [
|
|||||||
'Mwei',
|
'Mwei',
|
||||||
'Gwei',
|
'Gwei',
|
||||||
'szabo',
|
'szabo',
|
||||||
'finny',
|
'finney',
|
||||||
'ether',
|
'ether',
|
||||||
];
|
];
|
||||||
var unitInfos = {};
|
var unitInfos = {};
|
||||||
@ -14754,6 +14778,7 @@ exports.parseEther = parseEther;
|
|||||||
'use strict';
|
'use strict';
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
var bytes_1 = require("./bytes");
|
var bytes_1 = require("./bytes");
|
||||||
|
var constants_1 = require("./constants");
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
var UnicodeNormalizationForm;
|
var UnicodeNormalizationForm;
|
||||||
(function (UnicodeNormalizationForm) {
|
(function (UnicodeNormalizationForm) {
|
||||||
@ -14771,28 +14796,32 @@ function toUtf8Bytes(str, form) {
|
|||||||
str = str.normalize(form);
|
str = str.normalize(form);
|
||||||
}
|
}
|
||||||
var result = [];
|
var result = [];
|
||||||
var offset = 0;
|
|
||||||
for (var i = 0; i < str.length; i++) {
|
for (var i = 0; i < str.length; i++) {
|
||||||
var c = str.charCodeAt(i);
|
var c = str.charCodeAt(i);
|
||||||
if (c < 128) {
|
if (c < 0x80) {
|
||||||
result[offset++] = c;
|
result.push(c);
|
||||||
}
|
}
|
||||||
else if (c < 2048) {
|
else if (c < 0x800) {
|
||||||
result[offset++] = (c >> 6) | 192;
|
result.push((c >> 6) | 0xc0);
|
||||||
result[offset++] = (c & 63) | 128;
|
result.push((c & 0x3f) | 0x80);
|
||||||
}
|
}
|
||||||
else if (((c & 0xFC00) == 0xD800) && (i + 1) < str.length && ((str.charCodeAt(i + 1) & 0xFC00) == 0xDC00)) {
|
else if ((c & 0xfc00) == 0xd800) {
|
||||||
|
i++;
|
||||||
|
var c2 = str.charCodeAt(i);
|
||||||
|
if (i >= str.length || (c2 & 0xfc00) !== 0xdc00) {
|
||||||
|
throw new Error('invalid utf-8 string');
|
||||||
|
}
|
||||||
// Surrogate Pair
|
// Surrogate Pair
|
||||||
c = 0x10000 + ((c & 0x03FF) << 10) + (str.charCodeAt(++i) & 0x03FF);
|
c = 0x10000 + ((c & 0x03ff) << 10) + (c2 & 0x03ff);
|
||||||
result[offset++] = (c >> 18) | 240;
|
result.push((c >> 18) | 0xf0);
|
||||||
result[offset++] = ((c >> 12) & 63) | 128;
|
result.push(((c >> 12) & 0x3f) | 0x80);
|
||||||
result[offset++] = ((c >> 6) & 63) | 128;
|
result.push(((c >> 6) & 0x3f) | 0x80);
|
||||||
result[offset++] = (c & 63) | 128;
|
result.push((c & 0x3f) | 0x80);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result[offset++] = (c >> 12) | 224;
|
result.push((c >> 12) | 0xe0);
|
||||||
result[offset++] = ((c >> 6) & 63) | 128;
|
result.push(((c >> 6) & 0x3f) | 0x80);
|
||||||
result[offset++] = (c & 63) | 128;
|
result.push((c & 0x3f) | 0x80);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bytes_1.arrayify(result);
|
return bytes_1.arrayify(result);
|
||||||
@ -14800,69 +14829,96 @@ function toUtf8Bytes(str, form) {
|
|||||||
exports.toUtf8Bytes = toUtf8Bytes;
|
exports.toUtf8Bytes = toUtf8Bytes;
|
||||||
;
|
;
|
||||||
// http://stackoverflow.com/questions/13356493/decode-utf-8-with-javascript#13691499
|
// http://stackoverflow.com/questions/13356493/decode-utf-8-with-javascript#13691499
|
||||||
function toUtf8String(bytes) {
|
function toUtf8String(bytes, ignoreErrors) {
|
||||||
bytes = bytes_1.arrayify(bytes);
|
bytes = bytes_1.arrayify(bytes);
|
||||||
var result = '';
|
var result = '';
|
||||||
var i = 0;
|
var i = 0;
|
||||||
// Invalid bytes are ignored
|
// Invalid bytes are ignored
|
||||||
while (i < bytes.length) {
|
while (i < bytes.length) {
|
||||||
var c = bytes[i++];
|
var c = bytes[i++];
|
||||||
if (c >> 7 == 0) {
|
// 0xxx xxxx
|
||||||
// 0xxx xxxx
|
if (c >> 7 === 0) {
|
||||||
result += String.fromCharCode(c);
|
result += String.fromCharCode(c);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Invalid starting byte
|
// Multibyte; how many bytes left for this character?
|
||||||
if (c >> 6 == 0x02) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// Multibyte; how many bytes left for thus character?
|
|
||||||
var extraLength = null;
|
var extraLength = null;
|
||||||
if (c >> 5 == 0x06) {
|
var overlongMask = null;
|
||||||
|
// 110x xxxx 10xx xxxx
|
||||||
|
if ((c & 0xe0) === 0xc0) {
|
||||||
extraLength = 1;
|
extraLength = 1;
|
||||||
|
overlongMask = 0x7f;
|
||||||
|
// 1110 xxxx 10xx xxxx 10xx xxxx
|
||||||
}
|
}
|
||||||
else if (c >> 4 == 0x0e) {
|
else if ((c & 0xf0) === 0xe0) {
|
||||||
extraLength = 2;
|
extraLength = 2;
|
||||||
|
overlongMask = 0x7ff;
|
||||||
|
// 1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx
|
||||||
}
|
}
|
||||||
else if (c >> 3 == 0x1e) {
|
else if ((c & 0xf8) === 0xf0) {
|
||||||
extraLength = 3;
|
extraLength = 3;
|
||||||
}
|
overlongMask = 0xffff;
|
||||||
else if (c >> 2 == 0x3e) {
|
|
||||||
extraLength = 4;
|
|
||||||
}
|
|
||||||
else if (c >> 1 == 0x7e) {
|
|
||||||
extraLength = 5;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (!ignoreErrors) {
|
||||||
|
if ((c & 0xc0) === 0x80) {
|
||||||
|
throw new Error('invalid utf8 byte sequence; unexpected continuation byte');
|
||||||
|
}
|
||||||
|
throw new Error('invalid utf8 byte sequence; invalid prefix');
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Do we have enough bytes in our data?
|
// Do we have enough bytes in our data?
|
||||||
if (i + extraLength > bytes.length) {
|
if (i + extraLength > bytes.length) {
|
||||||
// If there is an invalid unprocessed byte, try to continue
|
if (!ignoreErrors) {
|
||||||
|
throw new Error('invalid utf8 byte sequence; too short');
|
||||||
|
}
|
||||||
|
// If there is an invalid unprocessed byte, skip continuation bytes
|
||||||
for (; i < bytes.length; i++) {
|
for (; i < bytes.length; i++) {
|
||||||
if (bytes[i] >> 6 != 0x02) {
|
if (bytes[i] >> 6 !== 0x02) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i != bytes.length)
|
continue;
|
||||||
continue;
|
|
||||||
// All leftover bytes are valid.
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
// Remove the UTF-8 prefix from the char (res)
|
// Remove the length prefix from the char
|
||||||
var res = c & ((1 << (8 - extraLength - 1)) - 1);
|
var res = c & ((1 << (8 - extraLength - 1)) - 1);
|
||||||
var count;
|
for (var j = 0; j < extraLength; j++) {
|
||||||
for (count = 0; count < extraLength; count++) {
|
var nextChar = bytes[i];
|
||||||
var nextChar = bytes[i++];
|
// Invalid continuation byte
|
||||||
// Is the char valid multibyte part?
|
if ((nextChar & 0xc0) != 0x80) {
|
||||||
if (nextChar >> 6 != 0x02) {
|
res = null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
res = (res << 6) | (nextChar & 0x3f);
|
res = (res << 6) | (nextChar & 0x3f);
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
if (count != extraLength) {
|
if (res === null) {
|
||||||
i--;
|
if (!ignoreErrors) {
|
||||||
|
throw new Error('invalid utf8 byte sequence; invalid continuation byte');
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Check for overlong seuences (more bytes than needed)
|
||||||
|
if (res <= overlongMask) {
|
||||||
|
if (!ignoreErrors) {
|
||||||
|
throw new Error('invalid utf8 byte sequence; overlong');
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Maximum code point
|
||||||
|
if (res > 0x10ffff) {
|
||||||
|
if (!ignoreErrors) {
|
||||||
|
throw new Error('invalid utf8 byte sequence; out-of-range');
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Reserved for UTF-16 surrogate halves
|
||||||
|
if (res >= 0xd800 && res <= 0xdfff) {
|
||||||
|
if (!ignoreErrors) {
|
||||||
|
throw new Error('invalid utf8 byte sequence; utf-16 surrogate');
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (res <= 0xffff) {
|
if (res <= 0xffff) {
|
||||||
@ -14875,8 +14931,37 @@ function toUtf8String(bytes) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
exports.toUtf8String = toUtf8String;
|
exports.toUtf8String = toUtf8String;
|
||||||
|
function formatBytes32String(text) {
|
||||||
|
// Get the bytes
|
||||||
|
var bytes = toUtf8Bytes(text);
|
||||||
|
// Check we have room for null-termination
|
||||||
|
if (bytes.length > 31) {
|
||||||
|
throw new Error('bytes32 string must be less than 32 bytes');
|
||||||
|
}
|
||||||
|
// Zero-pad (implicitly null-terminates)
|
||||||
|
return bytes_1.hexlify(bytes_1.concat([bytes, constants_1.HashZero]).slice(0, 32));
|
||||||
|
}
|
||||||
|
exports.formatBytes32String = formatBytes32String;
|
||||||
|
function parseBytes32String(bytes) {
|
||||||
|
var data = bytes_1.arrayify(bytes);
|
||||||
|
// Must be 32 bytes with a null-termination
|
||||||
|
if (data.length !== 32) {
|
||||||
|
throw new Error('invalid bytes32 - not 32 bytes long');
|
||||||
|
}
|
||||||
|
if (data[31] !== 0) {
|
||||||
|
throw new Error('invalid bytes32 sdtring - no null terminator');
|
||||||
|
}
|
||||||
|
// Find the null termination
|
||||||
|
var length = 31;
|
||||||
|
while (data[length - 1] === 0) {
|
||||||
|
length--;
|
||||||
|
}
|
||||||
|
// Determine the string value
|
||||||
|
return toUtf8String(data.slice(0, length));
|
||||||
|
}
|
||||||
|
exports.parseBytes32String = parseBytes32String;
|
||||||
|
|
||||||
},{"./bytes":62}],82:[function(require,module,exports){
|
},{"./bytes":62,"./constants":63}],82:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
var __importStar = (this && this.__importStar) || function (mod) {
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
if (mod && mod.__esModule) return mod;
|
if (mod && mod.__esModule) return mod;
|
||||||
|
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
15
dist/ethers.types.txt
vendored
15
dist/ethers.types.txt
vendored
@ -162,14 +162,14 @@ declare module 'ethers/utils' {
|
|||||||
import { keccak256 as solidityKeccak256, pack as solidityPack, sha256 as soliditySha256 } from 'ethers/utils/solidity';
|
import { keccak256 as solidityKeccak256, pack as solidityPack, sha256 as soliditySha256 } from 'ethers/utils/solidity';
|
||||||
import { randomBytes } from 'ethers/utils/random-bytes';
|
import { randomBytes } from 'ethers/utils/random-bytes';
|
||||||
import { getNetwork } from 'ethers/utils/networks';
|
import { getNetwork } from 'ethers/utils/networks';
|
||||||
import { defineFrozen, defineReadOnly, resolveProperties, shallowCopy } from 'ethers/utils/properties';
|
import { deepCopy, defineReadOnly, resolveProperties, shallowCopy } from 'ethers/utils/properties';
|
||||||
import * as RLP from 'ethers/utils/rlp';
|
import * as RLP from 'ethers/utils/rlp';
|
||||||
import { computePublicKey, verifyMessage } from 'ethers/utils/secp256k1';
|
import { computePublicKey, verifyMessage } from 'ethers/utils/secp256k1';
|
||||||
import { parse as parseTransaction, serialize as serializeTransaction } from 'ethers/utils/transaction';
|
import { parse as parseTransaction, serialize as serializeTransaction } from 'ethers/utils/transaction';
|
||||||
import { toUtf8Bytes, toUtf8String } from 'ethers/utils/utf8';
|
import { formatBytes32String, parseBytes32String, toUtf8Bytes, toUtf8String } from 'ethers/utils/utf8';
|
||||||
import { formatEther, parseEther, formatUnits, parseUnits } from 'ethers/utils/units';
|
import { formatEther, parseEther, formatUnits, parseUnits } from 'ethers/utils/units';
|
||||||
import { fetchJson } from 'ethers/utils/web';
|
import { fetchJson } from 'ethers/utils/web';
|
||||||
export { defaultAbiCoder, formatSignature, formatParamType, parseSignature, parseParamType, RLP, fetchJson, getNetwork, defineReadOnly, defineFrozen, resolveProperties, shallowCopy, arrayify, concat, padZeros, stripZeros, base64, bigNumberify, hexlify, hexStripZeros, hexZeroPad, hexDataLength, hexDataSlice, toUtf8Bytes, toUtf8String, 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, verifyMessage };
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module 'ethers/types' {
|
declare module 'ethers/types' {
|
||||||
@ -209,7 +209,7 @@ declare module 'ethers/utils/shims' {
|
|||||||
}
|
}
|
||||||
|
|
||||||
declare module 'ethers/_version' {
|
declare module 'ethers/_version' {
|
||||||
export const version = "4.0.0-beta.12";
|
export const version = "4.0.0-beta.13";
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module 'ethers/contracts/contract' {
|
declare module 'ethers/contracts/contract' {
|
||||||
@ -725,12 +725,11 @@ declare module 'ethers/utils/networks' {
|
|||||||
|
|
||||||
declare module 'ethers/utils/properties' {
|
declare module 'ethers/utils/properties' {
|
||||||
export function defineReadOnly(object: any, name: string, value: any): void;
|
export function defineReadOnly(object: any, name: string, value: any): void;
|
||||||
export function defineFrozen(object: any, name: string, value: any): void;
|
|
||||||
export function setType(object: any, type: string): void;
|
export function setType(object: any, type: string): void;
|
||||||
export function isType(object: any, type: string): boolean;
|
export function isType(object: any, type: string): boolean;
|
||||||
export function resolveProperties(object: any): Promise<any>;
|
export function resolveProperties(object: any): Promise<any>;
|
||||||
export function shallowCopy(object: any): any;
|
export function shallowCopy(object: any): any;
|
||||||
export function jsonCopy(object: any): any;
|
export function deepCopy(object: any, frozen?: boolean): any;
|
||||||
export function inheritable(parent: any): (child: any) => void;
|
export function inheritable(parent: any): (child: any) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -798,7 +797,9 @@ declare module 'ethers/utils/utf8' {
|
|||||||
NFKD = "NFKD"
|
NFKD = "NFKD"
|
||||||
}
|
}
|
||||||
export function toUtf8Bytes(str: string, form?: UnicodeNormalizationForm): Uint8Array;
|
export function toUtf8Bytes(str: string, form?: UnicodeNormalizationForm): Uint8Array;
|
||||||
export function toUtf8String(bytes: Arrayish): string;
|
export function toUtf8String(bytes: Arrayish, ignoreErrors?: boolean): string;
|
||||||
|
export function formatBytes32String(text: string): string;
|
||||||
|
export function parseBytes32String(bytes: Arrayish): string;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module 'ethers/utils/units' {
|
declare module 'ethers/utils/units' {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ethers",
|
"name": "ethers",
|
||||||
"version": "4.0.0-beta.12",
|
"version": "4.0.0-beta.13",
|
||||||
"description": "Ethereum wallet library.",
|
"description": "Ethereum wallet library.",
|
||||||
"main": "./index.js",
|
"main": "./index.js",
|
||||||
"types": "./index.d.ts",
|
"types": "./index.d.ts",
|
||||||
|
@ -1 +1 @@
|
|||||||
export const version = "4.0.0-beta.12";
|
export const version = "4.0.0-beta.13";
|
||||||
|
@ -880,8 +880,9 @@ function getParamCoder(coerceFunc, param) {
|
|||||||
var match = param.type.match(paramTypeArray);
|
var match = param.type.match(paramTypeArray);
|
||||||
if (match) {
|
if (match) {
|
||||||
var size = parseInt(match[2] || "-1");
|
var size = parseInt(match[2] || "-1");
|
||||||
param = properties_1.jsonCopy(param);
|
param = properties_1.shallowCopy(param);
|
||||||
param.type = match[1];
|
param.type = match[1];
|
||||||
|
param = properties_1.deepCopy(param);
|
||||||
return new CoderArray(coerceFunc, getParamCoder(coerceFunc, param), size, param.name);
|
return new CoderArray(coerceFunc, getParamCoder(coerceFunc, param), size, param.name);
|
||||||
}
|
}
|
||||||
if (param.type.substring(0, 5) === 'tuple') {
|
if (param.type.substring(0, 5) === 'tuple') {
|
||||||
@ -936,7 +937,7 @@ var AbiCoder = /** @class */ (function () {
|
|||||||
typeObject = parseParam(type);
|
typeObject = parseParam(type);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
typeObject = properties_1.jsonCopy(type);
|
typeObject = properties_1.deepCopy(type);
|
||||||
}
|
}
|
||||||
coders.push(getParamCoder(this.coerceFunc, typeObject));
|
coders.push(getParamCoder(this.coerceFunc, typeObject));
|
||||||
}, this);
|
}, this);
|
||||||
|
6
utils/index.d.ts
vendored
6
utils/index.d.ts
vendored
@ -10,11 +10,11 @@ import { sha256 } from './sha2';
|
|||||||
import { keccak256 as solidityKeccak256, pack as solidityPack, sha256 as soliditySha256 } from './solidity';
|
import { keccak256 as solidityKeccak256, pack as solidityPack, sha256 as soliditySha256 } from './solidity';
|
||||||
import { randomBytes } from './random-bytes';
|
import { randomBytes } from './random-bytes';
|
||||||
import { getNetwork } from './networks';
|
import { getNetwork } from './networks';
|
||||||
import { defineFrozen, defineReadOnly, resolveProperties, shallowCopy } from './properties';
|
import { deepCopy, defineReadOnly, resolveProperties, shallowCopy } from './properties';
|
||||||
import * as RLP from './rlp';
|
import * as RLP from './rlp';
|
||||||
import { computePublicKey, verifyMessage } from './secp256k1';
|
import { computePublicKey, verifyMessage } from './secp256k1';
|
||||||
import { parse as parseTransaction, serialize as serializeTransaction } from './transaction';
|
import { parse as parseTransaction, serialize as serializeTransaction } from './transaction';
|
||||||
import { toUtf8Bytes, toUtf8String } from './utf8';
|
import { formatBytes32String, parseBytes32String, toUtf8Bytes, toUtf8String } from './utf8';
|
||||||
import { formatEther, parseEther, formatUnits, parseUnits } from './units';
|
import { formatEther, parseEther, formatUnits, parseUnits } from './units';
|
||||||
import { fetchJson } from './web';
|
import { fetchJson } from './web';
|
||||||
export { defaultAbiCoder, formatSignature, formatParamType, parseSignature, parseParamType, RLP, fetchJson, getNetwork, defineReadOnly, defineFrozen, resolveProperties, shallowCopy, arrayify, concat, padZeros, stripZeros, base64, bigNumberify, hexlify, hexStripZeros, hexZeroPad, hexDataLength, hexDataSlice, toUtf8Bytes, toUtf8String, 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, verifyMessage };
|
||||||
|
@ -52,7 +52,7 @@ exports.randomBytes = random_bytes_1.randomBytes;
|
|||||||
var networks_1 = require("./networks");
|
var networks_1 = require("./networks");
|
||||||
exports.getNetwork = networks_1.getNetwork;
|
exports.getNetwork = networks_1.getNetwork;
|
||||||
var properties_1 = require("./properties");
|
var properties_1 = require("./properties");
|
||||||
exports.defineFrozen = properties_1.defineFrozen;
|
exports.deepCopy = properties_1.deepCopy;
|
||||||
exports.defineReadOnly = properties_1.defineReadOnly;
|
exports.defineReadOnly = properties_1.defineReadOnly;
|
||||||
exports.resolveProperties = properties_1.resolveProperties;
|
exports.resolveProperties = properties_1.resolveProperties;
|
||||||
exports.shallowCopy = properties_1.shallowCopy;
|
exports.shallowCopy = properties_1.shallowCopy;
|
||||||
@ -65,6 +65,8 @@ var transaction_1 = require("./transaction");
|
|||||||
exports.parseTransaction = transaction_1.parse;
|
exports.parseTransaction = transaction_1.parse;
|
||||||
exports.serializeTransaction = transaction_1.serialize;
|
exports.serializeTransaction = transaction_1.serialize;
|
||||||
var utf8_1 = require("./utf8");
|
var utf8_1 = require("./utf8");
|
||||||
|
exports.formatBytes32String = utf8_1.formatBytes32String;
|
||||||
|
exports.parseBytes32String = utf8_1.parseBytes32String;
|
||||||
exports.toUtf8Bytes = utf8_1.toUtf8Bytes;
|
exports.toUtf8Bytes = utf8_1.toUtf8Bytes;
|
||||||
exports.toUtf8String = utf8_1.toUtf8String;
|
exports.toUtf8String = utf8_1.toUtf8String;
|
||||||
var units_1 = require("./units");
|
var units_1 = require("./units");
|
||||||
|
3
utils/properties.d.ts
vendored
3
utils/properties.d.ts
vendored
@ -1,8 +1,7 @@
|
|||||||
export declare function defineReadOnly(object: any, name: string, value: any): void;
|
export declare function defineReadOnly(object: any, name: string, value: any): void;
|
||||||
export declare function defineFrozen(object: any, name: string, value: any): void;
|
|
||||||
export declare function setType(object: any, type: string): void;
|
export declare function setType(object: any, type: string): void;
|
||||||
export declare function isType(object: any, type: string): boolean;
|
export declare function isType(object: any, type: string): boolean;
|
||||||
export declare function resolveProperties(object: any): Promise<any>;
|
export declare function resolveProperties(object: any): Promise<any>;
|
||||||
export declare function shallowCopy(object: any): any;
|
export declare function shallowCopy(object: any): any;
|
||||||
export declare function jsonCopy(object: any): any;
|
export declare function deepCopy(object: any, frozen?: boolean): any;
|
||||||
export declare function inheritable(parent: any): (child: any) => void;
|
export declare function inheritable(parent: any): (child: any) => void;
|
||||||
|
@ -8,14 +8,6 @@ function defineReadOnly(object, name, value) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.defineReadOnly = defineReadOnly;
|
exports.defineReadOnly = defineReadOnly;
|
||||||
function defineFrozen(object, name, value) {
|
|
||||||
var frozen = JSON.stringify(value);
|
|
||||||
Object.defineProperty(object, name, {
|
|
||||||
enumerable: true,
|
|
||||||
get: function () { return JSON.parse(frozen); }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
exports.defineFrozen = defineFrozen;
|
|
||||||
// There are some issues with instanceof with npm link, so we use this
|
// There are some issues with instanceof with npm link, so we use this
|
||||||
// to ensure types are what we expect.
|
// to ensure types are what we expect.
|
||||||
function setType(object, type) {
|
function setType(object, type) {
|
||||||
@ -54,10 +46,48 @@ function shallowCopy(object) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
exports.shallowCopy = shallowCopy;
|
exports.shallowCopy = shallowCopy;
|
||||||
function jsonCopy(object) {
|
var opaque = { boolean: true, number: true, string: true };
|
||||||
return JSON.parse(JSON.stringify(object));
|
function deepCopy(object, frozen) {
|
||||||
|
if (object === undefined || object === null || opaque[typeof (object)]) {
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
if (Array.isArray(object)) {
|
||||||
|
var result_1 = [];
|
||||||
|
object.forEach(function (item) {
|
||||||
|
result_1.push(deepCopy(item, frozen));
|
||||||
|
});
|
||||||
|
if (frozen) {
|
||||||
|
Object.freeze(result_1);
|
||||||
|
}
|
||||||
|
return result_1;
|
||||||
|
}
|
||||||
|
if (typeof (object) === 'object') {
|
||||||
|
// Some internal objects, which are already immutable
|
||||||
|
if (isType(object, 'BigNumber')) {
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
if (isType(object, 'Description')) {
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
if (isType(object, 'Indexed')) {
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
var result = {};
|
||||||
|
for (var key in object) {
|
||||||
|
var value = object[key];
|
||||||
|
if (value === undefined) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
defineReadOnly(result, key, deepCopy(value, frozen));
|
||||||
|
}
|
||||||
|
if (frozen) {
|
||||||
|
Object.freeze(result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
throw new Error('Cannot deepCopy ' + typeof (object));
|
||||||
}
|
}
|
||||||
exports.jsonCopy = jsonCopy;
|
exports.deepCopy = deepCopy;
|
||||||
// See: https://github.com/isaacs/inherits/blob/master/inherits_browser.js
|
// See: https://github.com/isaacs/inherits/blob/master/inherits_browser.js
|
||||||
function inherits(ctor, superCtor) {
|
function inherits(ctor, superCtor) {
|
||||||
ctor.super_ = superCtor;
|
ctor.super_ = superCtor;
|
||||||
|
@ -16,7 +16,7 @@ var names = [
|
|||||||
'Mwei',
|
'Mwei',
|
||||||
'Gwei',
|
'Gwei',
|
||||||
'szabo',
|
'szabo',
|
||||||
'finny',
|
'finney',
|
||||||
'ether',
|
'ether',
|
||||||
];
|
];
|
||||||
var unitInfos = {};
|
var unitInfos = {};
|
||||||
|
4
utils/utf8.d.ts
vendored
4
utils/utf8.d.ts
vendored
@ -7,4 +7,6 @@ export declare enum UnicodeNormalizationForm {
|
|||||||
NFKD = "NFKD"
|
NFKD = "NFKD"
|
||||||
}
|
}
|
||||||
export declare function toUtf8Bytes(str: string, form?: UnicodeNormalizationForm): Uint8Array;
|
export declare function toUtf8Bytes(str: string, form?: UnicodeNormalizationForm): Uint8Array;
|
||||||
export declare function toUtf8String(bytes: Arrayish): string;
|
export declare function toUtf8String(bytes: Arrayish, ignoreErrors?: boolean): string;
|
||||||
|
export declare function formatBytes32String(text: string): string;
|
||||||
|
export declare function parseBytes32String(bytes: Arrayish): string;
|
||||||
|
153
utils/utf8.js
153
utils/utf8.js
@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
var bytes_1 = require("./bytes");
|
var bytes_1 = require("./bytes");
|
||||||
|
var constants_1 = require("./constants");
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
var UnicodeNormalizationForm;
|
var UnicodeNormalizationForm;
|
||||||
(function (UnicodeNormalizationForm) {
|
(function (UnicodeNormalizationForm) {
|
||||||
@ -18,28 +19,32 @@ function toUtf8Bytes(str, form) {
|
|||||||
str = str.normalize(form);
|
str = str.normalize(form);
|
||||||
}
|
}
|
||||||
var result = [];
|
var result = [];
|
||||||
var offset = 0;
|
|
||||||
for (var i = 0; i < str.length; i++) {
|
for (var i = 0; i < str.length; i++) {
|
||||||
var c = str.charCodeAt(i);
|
var c = str.charCodeAt(i);
|
||||||
if (c < 128) {
|
if (c < 0x80) {
|
||||||
result[offset++] = c;
|
result.push(c);
|
||||||
}
|
}
|
||||||
else if (c < 2048) {
|
else if (c < 0x800) {
|
||||||
result[offset++] = (c >> 6) | 192;
|
result.push((c >> 6) | 0xc0);
|
||||||
result[offset++] = (c & 63) | 128;
|
result.push((c & 0x3f) | 0x80);
|
||||||
}
|
}
|
||||||
else if (((c & 0xFC00) == 0xD800) && (i + 1) < str.length && ((str.charCodeAt(i + 1) & 0xFC00) == 0xDC00)) {
|
else if ((c & 0xfc00) == 0xd800) {
|
||||||
|
i++;
|
||||||
|
var c2 = str.charCodeAt(i);
|
||||||
|
if (i >= str.length || (c2 & 0xfc00) !== 0xdc00) {
|
||||||
|
throw new Error('invalid utf-8 string');
|
||||||
|
}
|
||||||
// Surrogate Pair
|
// Surrogate Pair
|
||||||
c = 0x10000 + ((c & 0x03FF) << 10) + (str.charCodeAt(++i) & 0x03FF);
|
c = 0x10000 + ((c & 0x03ff) << 10) + (c2 & 0x03ff);
|
||||||
result[offset++] = (c >> 18) | 240;
|
result.push((c >> 18) | 0xf0);
|
||||||
result[offset++] = ((c >> 12) & 63) | 128;
|
result.push(((c >> 12) & 0x3f) | 0x80);
|
||||||
result[offset++] = ((c >> 6) & 63) | 128;
|
result.push(((c >> 6) & 0x3f) | 0x80);
|
||||||
result[offset++] = (c & 63) | 128;
|
result.push((c & 0x3f) | 0x80);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result[offset++] = (c >> 12) | 224;
|
result.push((c >> 12) | 0xe0);
|
||||||
result[offset++] = ((c >> 6) & 63) | 128;
|
result.push(((c >> 6) & 0x3f) | 0x80);
|
||||||
result[offset++] = (c & 63) | 128;
|
result.push((c & 0x3f) | 0x80);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bytes_1.arrayify(result);
|
return bytes_1.arrayify(result);
|
||||||
@ -47,69 +52,96 @@ function toUtf8Bytes(str, form) {
|
|||||||
exports.toUtf8Bytes = toUtf8Bytes;
|
exports.toUtf8Bytes = toUtf8Bytes;
|
||||||
;
|
;
|
||||||
// http://stackoverflow.com/questions/13356493/decode-utf-8-with-javascript#13691499
|
// http://stackoverflow.com/questions/13356493/decode-utf-8-with-javascript#13691499
|
||||||
function toUtf8String(bytes) {
|
function toUtf8String(bytes, ignoreErrors) {
|
||||||
bytes = bytes_1.arrayify(bytes);
|
bytes = bytes_1.arrayify(bytes);
|
||||||
var result = '';
|
var result = '';
|
||||||
var i = 0;
|
var i = 0;
|
||||||
// Invalid bytes are ignored
|
// Invalid bytes are ignored
|
||||||
while (i < bytes.length) {
|
while (i < bytes.length) {
|
||||||
var c = bytes[i++];
|
var c = bytes[i++];
|
||||||
if (c >> 7 == 0) {
|
// 0xxx xxxx
|
||||||
// 0xxx xxxx
|
if (c >> 7 === 0) {
|
||||||
result += String.fromCharCode(c);
|
result += String.fromCharCode(c);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Invalid starting byte
|
// Multibyte; how many bytes left for this character?
|
||||||
if (c >> 6 == 0x02) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// Multibyte; how many bytes left for thus character?
|
|
||||||
var extraLength = null;
|
var extraLength = null;
|
||||||
if (c >> 5 == 0x06) {
|
var overlongMask = null;
|
||||||
|
// 110x xxxx 10xx xxxx
|
||||||
|
if ((c & 0xe0) === 0xc0) {
|
||||||
extraLength = 1;
|
extraLength = 1;
|
||||||
|
overlongMask = 0x7f;
|
||||||
|
// 1110 xxxx 10xx xxxx 10xx xxxx
|
||||||
}
|
}
|
||||||
else if (c >> 4 == 0x0e) {
|
else if ((c & 0xf0) === 0xe0) {
|
||||||
extraLength = 2;
|
extraLength = 2;
|
||||||
|
overlongMask = 0x7ff;
|
||||||
|
// 1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx
|
||||||
}
|
}
|
||||||
else if (c >> 3 == 0x1e) {
|
else if ((c & 0xf8) === 0xf0) {
|
||||||
extraLength = 3;
|
extraLength = 3;
|
||||||
}
|
overlongMask = 0xffff;
|
||||||
else if (c >> 2 == 0x3e) {
|
|
||||||
extraLength = 4;
|
|
||||||
}
|
|
||||||
else if (c >> 1 == 0x7e) {
|
|
||||||
extraLength = 5;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (!ignoreErrors) {
|
||||||
|
if ((c & 0xc0) === 0x80) {
|
||||||
|
throw new Error('invalid utf8 byte sequence; unexpected continuation byte');
|
||||||
|
}
|
||||||
|
throw new Error('invalid utf8 byte sequence; invalid prefix');
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Do we have enough bytes in our data?
|
// Do we have enough bytes in our data?
|
||||||
if (i + extraLength > bytes.length) {
|
if (i + extraLength > bytes.length) {
|
||||||
// If there is an invalid unprocessed byte, try to continue
|
if (!ignoreErrors) {
|
||||||
|
throw new Error('invalid utf8 byte sequence; too short');
|
||||||
|
}
|
||||||
|
// If there is an invalid unprocessed byte, skip continuation bytes
|
||||||
for (; i < bytes.length; i++) {
|
for (; i < bytes.length; i++) {
|
||||||
if (bytes[i] >> 6 != 0x02) {
|
if (bytes[i] >> 6 !== 0x02) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i != bytes.length)
|
continue;
|
||||||
continue;
|
|
||||||
// All leftover bytes are valid.
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
// Remove the UTF-8 prefix from the char (res)
|
// Remove the length prefix from the char
|
||||||
var res = c & ((1 << (8 - extraLength - 1)) - 1);
|
var res = c & ((1 << (8 - extraLength - 1)) - 1);
|
||||||
var count;
|
for (var j = 0; j < extraLength; j++) {
|
||||||
for (count = 0; count < extraLength; count++) {
|
var nextChar = bytes[i];
|
||||||
var nextChar = bytes[i++];
|
// Invalid continuation byte
|
||||||
// Is the char valid multibyte part?
|
if ((nextChar & 0xc0) != 0x80) {
|
||||||
if (nextChar >> 6 != 0x02) {
|
res = null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
res = (res << 6) | (nextChar & 0x3f);
|
res = (res << 6) | (nextChar & 0x3f);
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
if (count != extraLength) {
|
if (res === null) {
|
||||||
i--;
|
if (!ignoreErrors) {
|
||||||
|
throw new Error('invalid utf8 byte sequence; invalid continuation byte');
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Check for overlong seuences (more bytes than needed)
|
||||||
|
if (res <= overlongMask) {
|
||||||
|
if (!ignoreErrors) {
|
||||||
|
throw new Error('invalid utf8 byte sequence; overlong');
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Maximum code point
|
||||||
|
if (res > 0x10ffff) {
|
||||||
|
if (!ignoreErrors) {
|
||||||
|
throw new Error('invalid utf8 byte sequence; out-of-range');
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Reserved for UTF-16 surrogate halves
|
||||||
|
if (res >= 0xd800 && res <= 0xdfff) {
|
||||||
|
if (!ignoreErrors) {
|
||||||
|
throw new Error('invalid utf8 byte sequence; utf-16 surrogate');
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (res <= 0xffff) {
|
if (res <= 0xffff) {
|
||||||
@ -122,3 +154,32 @@ function toUtf8String(bytes) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
exports.toUtf8String = toUtf8String;
|
exports.toUtf8String = toUtf8String;
|
||||||
|
function formatBytes32String(text) {
|
||||||
|
// Get the bytes
|
||||||
|
var bytes = toUtf8Bytes(text);
|
||||||
|
// Check we have room for null-termination
|
||||||
|
if (bytes.length > 31) {
|
||||||
|
throw new Error('bytes32 string must be less than 32 bytes');
|
||||||
|
}
|
||||||
|
// Zero-pad (implicitly null-terminates)
|
||||||
|
return bytes_1.hexlify(bytes_1.concat([bytes, constants_1.HashZero]).slice(0, 32));
|
||||||
|
}
|
||||||
|
exports.formatBytes32String = formatBytes32String;
|
||||||
|
function parseBytes32String(bytes) {
|
||||||
|
var data = bytes_1.arrayify(bytes);
|
||||||
|
// Must be 32 bytes with a null-termination
|
||||||
|
if (data.length !== 32) {
|
||||||
|
throw new Error('invalid bytes32 - not 32 bytes long');
|
||||||
|
}
|
||||||
|
if (data[31] !== 0) {
|
||||||
|
throw new Error('invalid bytes32 sdtring - no null terminator');
|
||||||
|
}
|
||||||
|
// Find the null termination
|
||||||
|
var length = 31;
|
||||||
|
while (data[length - 1] === 0) {
|
||||||
|
length--;
|
||||||
|
}
|
||||||
|
// Determine the string value
|
||||||
|
return toUtf8String(data.slice(0, length));
|
||||||
|
}
|
||||||
|
exports.parseBytes32String = parseBytes32String;
|
||||||
|
Loading…
Reference in New Issue
Block a user