koilib 2.5.0 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/koinos.js +2525 -2525
- package/dist/koinos.min.js +1 -1
- package/lib/Contract.js +1 -1
- package/lib/Contract.js.map +1 -1
- package/lib/Signer.d.ts +6 -6
- package/lib/utils.js +1 -1
- package/package.json +1 -1
package/dist/koinos.js
CHANGED
|
@@ -1630,58 +1630,58 @@ exports.utils = {
|
|
|
1630
1630
|
/***/ ((module) => {
|
|
1631
1631
|
|
|
1632
1632
|
"use strict";
|
|
1633
|
-
|
|
1634
|
-
module.exports = asPromise;
|
|
1635
|
-
|
|
1636
|
-
/**
|
|
1637
|
-
* Callback as used by {@link util.asPromise}.
|
|
1638
|
-
* @typedef asPromiseCallback
|
|
1639
|
-
* @type {function}
|
|
1640
|
-
* @param {Error|null} error Error, if any
|
|
1641
|
-
* @param {...*} params Additional arguments
|
|
1642
|
-
* @returns {undefined}
|
|
1643
|
-
*/
|
|
1644
|
-
|
|
1645
|
-
/**
|
|
1646
|
-
* Returns a promise from a node-style callback function.
|
|
1647
|
-
* @memberof util
|
|
1648
|
-
* @param {asPromiseCallback} fn Function to call
|
|
1649
|
-
* @param {*} ctx Function context
|
|
1650
|
-
* @param {...*} params Function arguments
|
|
1651
|
-
* @returns {Promise<*>} Promisified function
|
|
1652
|
-
*/
|
|
1653
|
-
function asPromise(fn, ctx/*, varargs */) {
|
|
1654
|
-
var params = new Array(arguments.length - 1),
|
|
1655
|
-
offset = 0,
|
|
1656
|
-
index = 2,
|
|
1657
|
-
pending = true;
|
|
1658
|
-
while (index < arguments.length)
|
|
1659
|
-
params[offset++] = arguments[index++];
|
|
1660
|
-
return new Promise(function executor(resolve, reject) {
|
|
1661
|
-
params[offset] = function callback(err/*, varargs */) {
|
|
1662
|
-
if (pending) {
|
|
1663
|
-
pending = false;
|
|
1664
|
-
if (err)
|
|
1665
|
-
reject(err);
|
|
1666
|
-
else {
|
|
1667
|
-
var params = new Array(arguments.length - 1),
|
|
1668
|
-
offset = 0;
|
|
1669
|
-
while (offset < params.length)
|
|
1670
|
-
params[offset++] = arguments[offset];
|
|
1671
|
-
resolve.apply(null, params);
|
|
1672
|
-
}
|
|
1673
|
-
}
|
|
1674
|
-
};
|
|
1675
|
-
try {
|
|
1676
|
-
fn.apply(ctx || null, params);
|
|
1677
|
-
} catch (err) {
|
|
1678
|
-
if (pending) {
|
|
1679
|
-
pending = false;
|
|
1680
|
-
reject(err);
|
|
1681
|
-
}
|
|
1682
|
-
}
|
|
1683
|
-
});
|
|
1684
|
-
}
|
|
1633
|
+
|
|
1634
|
+
module.exports = asPromise;
|
|
1635
|
+
|
|
1636
|
+
/**
|
|
1637
|
+
* Callback as used by {@link util.asPromise}.
|
|
1638
|
+
* @typedef asPromiseCallback
|
|
1639
|
+
* @type {function}
|
|
1640
|
+
* @param {Error|null} error Error, if any
|
|
1641
|
+
* @param {...*} params Additional arguments
|
|
1642
|
+
* @returns {undefined}
|
|
1643
|
+
*/
|
|
1644
|
+
|
|
1645
|
+
/**
|
|
1646
|
+
* Returns a promise from a node-style callback function.
|
|
1647
|
+
* @memberof util
|
|
1648
|
+
* @param {asPromiseCallback} fn Function to call
|
|
1649
|
+
* @param {*} ctx Function context
|
|
1650
|
+
* @param {...*} params Function arguments
|
|
1651
|
+
* @returns {Promise<*>} Promisified function
|
|
1652
|
+
*/
|
|
1653
|
+
function asPromise(fn, ctx/*, varargs */) {
|
|
1654
|
+
var params = new Array(arguments.length - 1),
|
|
1655
|
+
offset = 0,
|
|
1656
|
+
index = 2,
|
|
1657
|
+
pending = true;
|
|
1658
|
+
while (index < arguments.length)
|
|
1659
|
+
params[offset++] = arguments[index++];
|
|
1660
|
+
return new Promise(function executor(resolve, reject) {
|
|
1661
|
+
params[offset] = function callback(err/*, varargs */) {
|
|
1662
|
+
if (pending) {
|
|
1663
|
+
pending = false;
|
|
1664
|
+
if (err)
|
|
1665
|
+
reject(err);
|
|
1666
|
+
else {
|
|
1667
|
+
var params = new Array(arguments.length - 1),
|
|
1668
|
+
offset = 0;
|
|
1669
|
+
while (offset < params.length)
|
|
1670
|
+
params[offset++] = arguments[offset];
|
|
1671
|
+
resolve.apply(null, params);
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
};
|
|
1675
|
+
try {
|
|
1676
|
+
fn.apply(ctx || null, params);
|
|
1677
|
+
} catch (err) {
|
|
1678
|
+
if (pending) {
|
|
1679
|
+
pending = false;
|
|
1680
|
+
reject(err);
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
});
|
|
1684
|
+
}
|
|
1685
1685
|
|
|
1686
1686
|
|
|
1687
1687
|
/***/ }),
|
|
@@ -1690,145 +1690,145 @@ function asPromise(fn, ctx/*, varargs */) {
|
|
|
1690
1690
|
/***/ ((__unused_webpack_module, exports) => {
|
|
1691
1691
|
|
|
1692
1692
|
"use strict";
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
/**
|
|
1696
|
-
* A minimal base64 implementation for number arrays.
|
|
1697
|
-
* @memberof util
|
|
1698
|
-
* @namespace
|
|
1699
|
-
*/
|
|
1700
|
-
var base64 = exports;
|
|
1701
|
-
|
|
1702
|
-
/**
|
|
1703
|
-
* Calculates the byte length of a base64 encoded string.
|
|
1704
|
-
* @param {string} string Base64 encoded string
|
|
1705
|
-
* @returns {number} Byte length
|
|
1706
|
-
*/
|
|
1707
|
-
base64.length = function length(string) {
|
|
1708
|
-
var p = string.length;
|
|
1709
|
-
if (!p)
|
|
1710
|
-
return 0;
|
|
1711
|
-
var n = 0;
|
|
1712
|
-
while (--p % 4 > 1 && string.charAt(p) === "=")
|
|
1713
|
-
++n;
|
|
1714
|
-
return Math.ceil(string.length * 3) / 4 - n;
|
|
1715
|
-
};
|
|
1716
|
-
|
|
1717
|
-
// Base64 encoding table
|
|
1718
|
-
var b64 = new Array(64);
|
|
1719
|
-
|
|
1720
|
-
// Base64 decoding table
|
|
1721
|
-
var s64 = new Array(123);
|
|
1722
|
-
|
|
1723
|
-
// 65..90, 97..122, 48..57, 43, 47
|
|
1724
|
-
for (var i = 0; i < 64;)
|
|
1725
|
-
s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
|
|
1726
|
-
|
|
1727
|
-
/**
|
|
1728
|
-
* Encodes a buffer to a base64 encoded string.
|
|
1729
|
-
* @param {Uint8Array} buffer Source buffer
|
|
1730
|
-
* @param {number} start Source start
|
|
1731
|
-
* @param {number} end Source end
|
|
1732
|
-
* @returns {string} Base64 encoded string
|
|
1733
|
-
*/
|
|
1734
|
-
base64.encode = function encode(buffer, start, end) {
|
|
1735
|
-
var parts = null,
|
|
1736
|
-
chunk = [];
|
|
1737
|
-
var i = 0, // output index
|
|
1738
|
-
j = 0, // goto index
|
|
1739
|
-
t; // temporary
|
|
1740
|
-
while (start < end) {
|
|
1741
|
-
var b = buffer[start++];
|
|
1742
|
-
switch (j) {
|
|
1743
|
-
case 0:
|
|
1744
|
-
chunk[i++] = b64[b >> 2];
|
|
1745
|
-
t = (b & 3) << 4;
|
|
1746
|
-
j = 1;
|
|
1747
|
-
break;
|
|
1748
|
-
case 1:
|
|
1749
|
-
chunk[i++] = b64[t | b >> 4];
|
|
1750
|
-
t = (b & 15) << 2;
|
|
1751
|
-
j = 2;
|
|
1752
|
-
break;
|
|
1753
|
-
case 2:
|
|
1754
|
-
chunk[i++] = b64[t | b >> 6];
|
|
1755
|
-
chunk[i++] = b64[b & 63];
|
|
1756
|
-
j = 0;
|
|
1757
|
-
break;
|
|
1758
|
-
}
|
|
1759
|
-
if (i > 8191) {
|
|
1760
|
-
(parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
|
|
1761
|
-
i = 0;
|
|
1762
|
-
}
|
|
1763
|
-
}
|
|
1764
|
-
if (j) {
|
|
1765
|
-
chunk[i++] = b64[t];
|
|
1766
|
-
chunk[i++] = 61;
|
|
1767
|
-
if (j === 1)
|
|
1768
|
-
chunk[i++] = 61;
|
|
1769
|
-
}
|
|
1770
|
-
if (parts) {
|
|
1771
|
-
if (i)
|
|
1772
|
-
parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
|
|
1773
|
-
return parts.join("");
|
|
1774
|
-
}
|
|
1775
|
-
return String.fromCharCode.apply(String, chunk.slice(0, i));
|
|
1776
|
-
};
|
|
1777
|
-
|
|
1778
|
-
var invalidEncoding = "invalid encoding";
|
|
1779
|
-
|
|
1780
|
-
/**
|
|
1781
|
-
* Decodes a base64 encoded string to a buffer.
|
|
1782
|
-
* @param {string} string Source string
|
|
1783
|
-
* @param {Uint8Array} buffer Destination buffer
|
|
1784
|
-
* @param {number} offset Destination offset
|
|
1785
|
-
* @returns {number} Number of bytes written
|
|
1786
|
-
* @throws {Error} If encoding is invalid
|
|
1787
|
-
*/
|
|
1788
|
-
base64.decode = function decode(string, buffer, offset) {
|
|
1789
|
-
var start = offset;
|
|
1790
|
-
var j = 0, // goto index
|
|
1791
|
-
t; // temporary
|
|
1792
|
-
for (var i = 0; i < string.length;) {
|
|
1793
|
-
var c = string.charCodeAt(i++);
|
|
1794
|
-
if (c === 61 && j > 1)
|
|
1795
|
-
break;
|
|
1796
|
-
if ((c = s64[c]) === undefined)
|
|
1797
|
-
throw Error(invalidEncoding);
|
|
1798
|
-
switch (j) {
|
|
1799
|
-
case 0:
|
|
1800
|
-
t = c;
|
|
1801
|
-
j = 1;
|
|
1802
|
-
break;
|
|
1803
|
-
case 1:
|
|
1804
|
-
buffer[offset++] = t << 2 | (c & 48) >> 4;
|
|
1805
|
-
t = c;
|
|
1806
|
-
j = 2;
|
|
1807
|
-
break;
|
|
1808
|
-
case 2:
|
|
1809
|
-
buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;
|
|
1810
|
-
t = c;
|
|
1811
|
-
j = 3;
|
|
1812
|
-
break;
|
|
1813
|
-
case 3:
|
|
1814
|
-
buffer[offset++] = (t & 3) << 6 | c;
|
|
1815
|
-
j = 0;
|
|
1816
|
-
break;
|
|
1817
|
-
}
|
|
1818
|
-
}
|
|
1819
|
-
if (j === 1)
|
|
1820
|
-
throw Error(invalidEncoding);
|
|
1821
|
-
return offset - start;
|
|
1822
|
-
};
|
|
1823
|
-
|
|
1824
|
-
/**
|
|
1825
|
-
* Tests if the specified string appears to be base64 encoded.
|
|
1826
|
-
* @param {string} string String to test
|
|
1827
|
-
* @returns {boolean} `true` if probably base64 encoded, otherwise false
|
|
1828
|
-
*/
|
|
1829
|
-
base64.test = function test(string) {
|
|
1830
|
-
return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string);
|
|
1831
|
-
};
|
|
1693
|
+
|
|
1694
|
+
|
|
1695
|
+
/**
|
|
1696
|
+
* A minimal base64 implementation for number arrays.
|
|
1697
|
+
* @memberof util
|
|
1698
|
+
* @namespace
|
|
1699
|
+
*/
|
|
1700
|
+
var base64 = exports;
|
|
1701
|
+
|
|
1702
|
+
/**
|
|
1703
|
+
* Calculates the byte length of a base64 encoded string.
|
|
1704
|
+
* @param {string} string Base64 encoded string
|
|
1705
|
+
* @returns {number} Byte length
|
|
1706
|
+
*/
|
|
1707
|
+
base64.length = function length(string) {
|
|
1708
|
+
var p = string.length;
|
|
1709
|
+
if (!p)
|
|
1710
|
+
return 0;
|
|
1711
|
+
var n = 0;
|
|
1712
|
+
while (--p % 4 > 1 && string.charAt(p) === "=")
|
|
1713
|
+
++n;
|
|
1714
|
+
return Math.ceil(string.length * 3) / 4 - n;
|
|
1715
|
+
};
|
|
1716
|
+
|
|
1717
|
+
// Base64 encoding table
|
|
1718
|
+
var b64 = new Array(64);
|
|
1719
|
+
|
|
1720
|
+
// Base64 decoding table
|
|
1721
|
+
var s64 = new Array(123);
|
|
1722
|
+
|
|
1723
|
+
// 65..90, 97..122, 48..57, 43, 47
|
|
1724
|
+
for (var i = 0; i < 64;)
|
|
1725
|
+
s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
|
|
1726
|
+
|
|
1727
|
+
/**
|
|
1728
|
+
* Encodes a buffer to a base64 encoded string.
|
|
1729
|
+
* @param {Uint8Array} buffer Source buffer
|
|
1730
|
+
* @param {number} start Source start
|
|
1731
|
+
* @param {number} end Source end
|
|
1732
|
+
* @returns {string} Base64 encoded string
|
|
1733
|
+
*/
|
|
1734
|
+
base64.encode = function encode(buffer, start, end) {
|
|
1735
|
+
var parts = null,
|
|
1736
|
+
chunk = [];
|
|
1737
|
+
var i = 0, // output index
|
|
1738
|
+
j = 0, // goto index
|
|
1739
|
+
t; // temporary
|
|
1740
|
+
while (start < end) {
|
|
1741
|
+
var b = buffer[start++];
|
|
1742
|
+
switch (j) {
|
|
1743
|
+
case 0:
|
|
1744
|
+
chunk[i++] = b64[b >> 2];
|
|
1745
|
+
t = (b & 3) << 4;
|
|
1746
|
+
j = 1;
|
|
1747
|
+
break;
|
|
1748
|
+
case 1:
|
|
1749
|
+
chunk[i++] = b64[t | b >> 4];
|
|
1750
|
+
t = (b & 15) << 2;
|
|
1751
|
+
j = 2;
|
|
1752
|
+
break;
|
|
1753
|
+
case 2:
|
|
1754
|
+
chunk[i++] = b64[t | b >> 6];
|
|
1755
|
+
chunk[i++] = b64[b & 63];
|
|
1756
|
+
j = 0;
|
|
1757
|
+
break;
|
|
1758
|
+
}
|
|
1759
|
+
if (i > 8191) {
|
|
1760
|
+
(parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
|
|
1761
|
+
i = 0;
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
if (j) {
|
|
1765
|
+
chunk[i++] = b64[t];
|
|
1766
|
+
chunk[i++] = 61;
|
|
1767
|
+
if (j === 1)
|
|
1768
|
+
chunk[i++] = 61;
|
|
1769
|
+
}
|
|
1770
|
+
if (parts) {
|
|
1771
|
+
if (i)
|
|
1772
|
+
parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
|
|
1773
|
+
return parts.join("");
|
|
1774
|
+
}
|
|
1775
|
+
return String.fromCharCode.apply(String, chunk.slice(0, i));
|
|
1776
|
+
};
|
|
1777
|
+
|
|
1778
|
+
var invalidEncoding = "invalid encoding";
|
|
1779
|
+
|
|
1780
|
+
/**
|
|
1781
|
+
* Decodes a base64 encoded string to a buffer.
|
|
1782
|
+
* @param {string} string Source string
|
|
1783
|
+
* @param {Uint8Array} buffer Destination buffer
|
|
1784
|
+
* @param {number} offset Destination offset
|
|
1785
|
+
* @returns {number} Number of bytes written
|
|
1786
|
+
* @throws {Error} If encoding is invalid
|
|
1787
|
+
*/
|
|
1788
|
+
base64.decode = function decode(string, buffer, offset) {
|
|
1789
|
+
var start = offset;
|
|
1790
|
+
var j = 0, // goto index
|
|
1791
|
+
t; // temporary
|
|
1792
|
+
for (var i = 0; i < string.length;) {
|
|
1793
|
+
var c = string.charCodeAt(i++);
|
|
1794
|
+
if (c === 61 && j > 1)
|
|
1795
|
+
break;
|
|
1796
|
+
if ((c = s64[c]) === undefined)
|
|
1797
|
+
throw Error(invalidEncoding);
|
|
1798
|
+
switch (j) {
|
|
1799
|
+
case 0:
|
|
1800
|
+
t = c;
|
|
1801
|
+
j = 1;
|
|
1802
|
+
break;
|
|
1803
|
+
case 1:
|
|
1804
|
+
buffer[offset++] = t << 2 | (c & 48) >> 4;
|
|
1805
|
+
t = c;
|
|
1806
|
+
j = 2;
|
|
1807
|
+
break;
|
|
1808
|
+
case 2:
|
|
1809
|
+
buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;
|
|
1810
|
+
t = c;
|
|
1811
|
+
j = 3;
|
|
1812
|
+
break;
|
|
1813
|
+
case 3:
|
|
1814
|
+
buffer[offset++] = (t & 3) << 6 | c;
|
|
1815
|
+
j = 0;
|
|
1816
|
+
break;
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
if (j === 1)
|
|
1820
|
+
throw Error(invalidEncoding);
|
|
1821
|
+
return offset - start;
|
|
1822
|
+
};
|
|
1823
|
+
|
|
1824
|
+
/**
|
|
1825
|
+
* Tests if the specified string appears to be base64 encoded.
|
|
1826
|
+
* @param {string} string String to test
|
|
1827
|
+
* @returns {boolean} `true` if probably base64 encoded, otherwise false
|
|
1828
|
+
*/
|
|
1829
|
+
base64.test = function test(string) {
|
|
1830
|
+
return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string);
|
|
1831
|
+
};
|
|
1832
1832
|
|
|
1833
1833
|
|
|
1834
1834
|
/***/ }),
|
|
@@ -1837,105 +1837,105 @@ base64.test = function test(string) {
|
|
|
1837
1837
|
/***/ ((module) => {
|
|
1838
1838
|
|
|
1839
1839
|
"use strict";
|
|
1840
|
-
|
|
1841
|
-
module.exports = codegen;
|
|
1842
|
-
|
|
1843
|
-
/**
|
|
1844
|
-
* Begins generating a function.
|
|
1845
|
-
* @memberof util
|
|
1846
|
-
* @param {string[]} functionParams Function parameter names
|
|
1847
|
-
* @param {string} [functionName] Function name if not anonymous
|
|
1848
|
-
* @returns {Codegen} Appender that appends code to the function's body
|
|
1849
|
-
*/
|
|
1850
|
-
function codegen(functionParams, functionName) {
|
|
1851
|
-
|
|
1852
|
-
/* istanbul ignore if */
|
|
1853
|
-
if (typeof functionParams === "string") {
|
|
1854
|
-
functionName = functionParams;
|
|
1855
|
-
functionParams = undefined;
|
|
1856
|
-
}
|
|
1857
|
-
|
|
1858
|
-
var body = [];
|
|
1859
|
-
|
|
1860
|
-
/**
|
|
1861
|
-
* Appends code to the function's body or finishes generation.
|
|
1862
|
-
* @typedef Codegen
|
|
1863
|
-
* @type {function}
|
|
1864
|
-
* @param {string|Object.<string,*>} [formatStringOrScope] Format string or, to finish the function, an object of additional scope variables, if any
|
|
1865
|
-
* @param {...*} [formatParams] Format parameters
|
|
1866
|
-
* @returns {Codegen|Function} Itself or the generated function if finished
|
|
1867
|
-
* @throws {Error} If format parameter counts do not match
|
|
1868
|
-
*/
|
|
1869
|
-
|
|
1870
|
-
function Codegen(formatStringOrScope) {
|
|
1871
|
-
// note that explicit array handling below makes this ~50% faster
|
|
1872
|
-
|
|
1873
|
-
// finish the function
|
|
1874
|
-
if (typeof formatStringOrScope !== "string") {
|
|
1875
|
-
var source = toString();
|
|
1876
|
-
if (codegen.verbose)
|
|
1877
|
-
console.log("codegen: " + source); // eslint-disable-line no-console
|
|
1878
|
-
source = "return " + source;
|
|
1879
|
-
if (formatStringOrScope) {
|
|
1880
|
-
var scopeKeys = Object.keys(formatStringOrScope),
|
|
1881
|
-
scopeParams = new Array(scopeKeys.length + 1),
|
|
1882
|
-
scopeValues = new Array(scopeKeys.length),
|
|
1883
|
-
scopeOffset = 0;
|
|
1884
|
-
while (scopeOffset < scopeKeys.length) {
|
|
1885
|
-
scopeParams[scopeOffset] = scopeKeys[scopeOffset];
|
|
1886
|
-
scopeValues[scopeOffset] = formatStringOrScope[scopeKeys[scopeOffset++]];
|
|
1887
|
-
}
|
|
1888
|
-
scopeParams[scopeOffset] = source;
|
|
1889
|
-
return Function.apply(null, scopeParams).apply(null, scopeValues); // eslint-disable-line no-new-func
|
|
1890
|
-
}
|
|
1891
|
-
return Function(source)(); // eslint-disable-line no-new-func
|
|
1892
|
-
}
|
|
1893
|
-
|
|
1894
|
-
// otherwise append to body
|
|
1895
|
-
var formatParams = new Array(arguments.length - 1),
|
|
1896
|
-
formatOffset = 0;
|
|
1897
|
-
while (formatOffset < formatParams.length)
|
|
1898
|
-
formatParams[formatOffset] = arguments[++formatOffset];
|
|
1899
|
-
formatOffset = 0;
|
|
1900
|
-
formatStringOrScope = formatStringOrScope.replace(/%([%dfijs])/g, function replace($0, $1) {
|
|
1901
|
-
var value = formatParams[formatOffset++];
|
|
1902
|
-
switch ($1) {
|
|
1903
|
-
case "d": case "f": return String(Number(value));
|
|
1904
|
-
case "i": return String(Math.floor(value));
|
|
1905
|
-
case "j": return JSON.stringify(value);
|
|
1906
|
-
case "s": return String(value);
|
|
1907
|
-
}
|
|
1908
|
-
return "%";
|
|
1909
|
-
});
|
|
1910
|
-
if (formatOffset !== formatParams.length)
|
|
1911
|
-
throw Error("parameter count mismatch");
|
|
1912
|
-
body.push(formatStringOrScope);
|
|
1913
|
-
return Codegen;
|
|
1914
|
-
}
|
|
1915
|
-
|
|
1916
|
-
function toString(functionNameOverride) {
|
|
1917
|
-
return "function " + (functionNameOverride || functionName || "") + "(" + (functionParams && functionParams.join(",") || "") + "){\n " + body.join("\n ") + "\n}";
|
|
1918
|
-
}
|
|
1919
|
-
|
|
1920
|
-
Codegen.toString = toString;
|
|
1921
|
-
return Codegen;
|
|
1922
|
-
}
|
|
1923
|
-
|
|
1924
|
-
/**
|
|
1925
|
-
* Begins generating a function.
|
|
1926
|
-
* @memberof util
|
|
1927
|
-
* @function codegen
|
|
1928
|
-
* @param {string} [functionName] Function name if not anonymous
|
|
1929
|
-
* @returns {Codegen} Appender that appends code to the function's body
|
|
1930
|
-
* @variation 2
|
|
1931
|
-
*/
|
|
1932
|
-
|
|
1933
|
-
/**
|
|
1934
|
-
* When set to `true`, codegen will log generated code to console. Useful for debugging.
|
|
1935
|
-
* @name util.codegen.verbose
|
|
1936
|
-
* @type {boolean}
|
|
1937
|
-
*/
|
|
1938
|
-
codegen.verbose = false;
|
|
1840
|
+
|
|
1841
|
+
module.exports = codegen;
|
|
1842
|
+
|
|
1843
|
+
/**
|
|
1844
|
+
* Begins generating a function.
|
|
1845
|
+
* @memberof util
|
|
1846
|
+
* @param {string[]} functionParams Function parameter names
|
|
1847
|
+
* @param {string} [functionName] Function name if not anonymous
|
|
1848
|
+
* @returns {Codegen} Appender that appends code to the function's body
|
|
1849
|
+
*/
|
|
1850
|
+
function codegen(functionParams, functionName) {
|
|
1851
|
+
|
|
1852
|
+
/* istanbul ignore if */
|
|
1853
|
+
if (typeof functionParams === "string") {
|
|
1854
|
+
functionName = functionParams;
|
|
1855
|
+
functionParams = undefined;
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
var body = [];
|
|
1859
|
+
|
|
1860
|
+
/**
|
|
1861
|
+
* Appends code to the function's body or finishes generation.
|
|
1862
|
+
* @typedef Codegen
|
|
1863
|
+
* @type {function}
|
|
1864
|
+
* @param {string|Object.<string,*>} [formatStringOrScope] Format string or, to finish the function, an object of additional scope variables, if any
|
|
1865
|
+
* @param {...*} [formatParams] Format parameters
|
|
1866
|
+
* @returns {Codegen|Function} Itself or the generated function if finished
|
|
1867
|
+
* @throws {Error} If format parameter counts do not match
|
|
1868
|
+
*/
|
|
1869
|
+
|
|
1870
|
+
function Codegen(formatStringOrScope) {
|
|
1871
|
+
// note that explicit array handling below makes this ~50% faster
|
|
1872
|
+
|
|
1873
|
+
// finish the function
|
|
1874
|
+
if (typeof formatStringOrScope !== "string") {
|
|
1875
|
+
var source = toString();
|
|
1876
|
+
if (codegen.verbose)
|
|
1877
|
+
console.log("codegen: " + source); // eslint-disable-line no-console
|
|
1878
|
+
source = "return " + source;
|
|
1879
|
+
if (formatStringOrScope) {
|
|
1880
|
+
var scopeKeys = Object.keys(formatStringOrScope),
|
|
1881
|
+
scopeParams = new Array(scopeKeys.length + 1),
|
|
1882
|
+
scopeValues = new Array(scopeKeys.length),
|
|
1883
|
+
scopeOffset = 0;
|
|
1884
|
+
while (scopeOffset < scopeKeys.length) {
|
|
1885
|
+
scopeParams[scopeOffset] = scopeKeys[scopeOffset];
|
|
1886
|
+
scopeValues[scopeOffset] = formatStringOrScope[scopeKeys[scopeOffset++]];
|
|
1887
|
+
}
|
|
1888
|
+
scopeParams[scopeOffset] = source;
|
|
1889
|
+
return Function.apply(null, scopeParams).apply(null, scopeValues); // eslint-disable-line no-new-func
|
|
1890
|
+
}
|
|
1891
|
+
return Function(source)(); // eslint-disable-line no-new-func
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1894
|
+
// otherwise append to body
|
|
1895
|
+
var formatParams = new Array(arguments.length - 1),
|
|
1896
|
+
formatOffset = 0;
|
|
1897
|
+
while (formatOffset < formatParams.length)
|
|
1898
|
+
formatParams[formatOffset] = arguments[++formatOffset];
|
|
1899
|
+
formatOffset = 0;
|
|
1900
|
+
formatStringOrScope = formatStringOrScope.replace(/%([%dfijs])/g, function replace($0, $1) {
|
|
1901
|
+
var value = formatParams[formatOffset++];
|
|
1902
|
+
switch ($1) {
|
|
1903
|
+
case "d": case "f": return String(Number(value));
|
|
1904
|
+
case "i": return String(Math.floor(value));
|
|
1905
|
+
case "j": return JSON.stringify(value);
|
|
1906
|
+
case "s": return String(value);
|
|
1907
|
+
}
|
|
1908
|
+
return "%";
|
|
1909
|
+
});
|
|
1910
|
+
if (formatOffset !== formatParams.length)
|
|
1911
|
+
throw Error("parameter count mismatch");
|
|
1912
|
+
body.push(formatStringOrScope);
|
|
1913
|
+
return Codegen;
|
|
1914
|
+
}
|
|
1915
|
+
|
|
1916
|
+
function toString(functionNameOverride) {
|
|
1917
|
+
return "function " + (functionNameOverride || functionName || "") + "(" + (functionParams && functionParams.join(",") || "") + "){\n " + body.join("\n ") + "\n}";
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
Codegen.toString = toString;
|
|
1921
|
+
return Codegen;
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1924
|
+
/**
|
|
1925
|
+
* Begins generating a function.
|
|
1926
|
+
* @memberof util
|
|
1927
|
+
* @function codegen
|
|
1928
|
+
* @param {string} [functionName] Function name if not anonymous
|
|
1929
|
+
* @returns {Codegen} Appender that appends code to the function's body
|
|
1930
|
+
* @variation 2
|
|
1931
|
+
*/
|
|
1932
|
+
|
|
1933
|
+
/**
|
|
1934
|
+
* When set to `true`, codegen will log generated code to console. Useful for debugging.
|
|
1935
|
+
* @name util.codegen.verbose
|
|
1936
|
+
* @type {boolean}
|
|
1937
|
+
*/
|
|
1938
|
+
codegen.verbose = false;
|
|
1939
1939
|
|
|
1940
1940
|
|
|
1941
1941
|
/***/ }),
|
|
@@ -1944,82 +1944,82 @@ codegen.verbose = false;
|
|
|
1944
1944
|
/***/ ((module) => {
|
|
1945
1945
|
|
|
1946
1946
|
"use strict";
|
|
1947
|
-
|
|
1948
|
-
module.exports = EventEmitter;
|
|
1949
|
-
|
|
1950
|
-
/**
|
|
1951
|
-
* Constructs a new event emitter instance.
|
|
1952
|
-
* @classdesc A minimal event emitter.
|
|
1953
|
-
* @memberof util
|
|
1954
|
-
* @constructor
|
|
1955
|
-
*/
|
|
1956
|
-
function EventEmitter() {
|
|
1957
|
-
|
|
1958
|
-
/**
|
|
1959
|
-
* Registered listeners.
|
|
1960
|
-
* @type {Object.<string,*>}
|
|
1961
|
-
* @private
|
|
1962
|
-
*/
|
|
1963
|
-
this._listeners = {};
|
|
1964
|
-
}
|
|
1965
|
-
|
|
1966
|
-
/**
|
|
1967
|
-
* Registers an event listener.
|
|
1968
|
-
* @param {string} evt Event name
|
|
1969
|
-
* @param {function} fn Listener
|
|
1970
|
-
* @param {*} [ctx] Listener context
|
|
1971
|
-
* @returns {util.EventEmitter} `this`
|
|
1972
|
-
*/
|
|
1973
|
-
EventEmitter.prototype.on = function on(evt, fn, ctx) {
|
|
1974
|
-
(this._listeners[evt] || (this._listeners[evt] = [])).push({
|
|
1975
|
-
fn : fn,
|
|
1976
|
-
ctx : ctx || this
|
|
1977
|
-
});
|
|
1978
|
-
return this;
|
|
1979
|
-
};
|
|
1980
|
-
|
|
1981
|
-
/**
|
|
1982
|
-
* Removes an event listener or any matching listeners if arguments are omitted.
|
|
1983
|
-
* @param {string} [evt] Event name. Removes all listeners if omitted.
|
|
1984
|
-
* @param {function} [fn] Listener to remove. Removes all listeners of `evt` if omitted.
|
|
1985
|
-
* @returns {util.EventEmitter} `this`
|
|
1986
|
-
*/
|
|
1987
|
-
EventEmitter.prototype.off = function off(evt, fn) {
|
|
1988
|
-
if (evt === undefined)
|
|
1989
|
-
this._listeners = {};
|
|
1990
|
-
else {
|
|
1991
|
-
if (fn === undefined)
|
|
1992
|
-
this._listeners[evt] = [];
|
|
1993
|
-
else {
|
|
1994
|
-
var listeners = this._listeners[evt];
|
|
1995
|
-
for (var i = 0; i < listeners.length;)
|
|
1996
|
-
if (listeners[i].fn === fn)
|
|
1997
|
-
listeners.splice(i, 1);
|
|
1998
|
-
else
|
|
1999
|
-
++i;
|
|
2000
|
-
}
|
|
2001
|
-
}
|
|
2002
|
-
return this;
|
|
2003
|
-
};
|
|
2004
|
-
|
|
2005
|
-
/**
|
|
2006
|
-
* Emits an event by calling its listeners with the specified arguments.
|
|
2007
|
-
* @param {string} evt Event name
|
|
2008
|
-
* @param {...*} args Arguments
|
|
2009
|
-
* @returns {util.EventEmitter} `this`
|
|
2010
|
-
*/
|
|
2011
|
-
EventEmitter.prototype.emit = function emit(evt) {
|
|
2012
|
-
var listeners = this._listeners[evt];
|
|
2013
|
-
if (listeners) {
|
|
2014
|
-
var args = [],
|
|
2015
|
-
i = 1;
|
|
2016
|
-
for (; i < arguments.length;)
|
|
2017
|
-
args.push(arguments[i++]);
|
|
2018
|
-
for (i = 0; i < listeners.length;)
|
|
2019
|
-
listeners[i].fn.apply(listeners[i++].ctx, args);
|
|
2020
|
-
}
|
|
2021
|
-
return this;
|
|
2022
|
-
};
|
|
1947
|
+
|
|
1948
|
+
module.exports = EventEmitter;
|
|
1949
|
+
|
|
1950
|
+
/**
|
|
1951
|
+
* Constructs a new event emitter instance.
|
|
1952
|
+
* @classdesc A minimal event emitter.
|
|
1953
|
+
* @memberof util
|
|
1954
|
+
* @constructor
|
|
1955
|
+
*/
|
|
1956
|
+
function EventEmitter() {
|
|
1957
|
+
|
|
1958
|
+
/**
|
|
1959
|
+
* Registered listeners.
|
|
1960
|
+
* @type {Object.<string,*>}
|
|
1961
|
+
* @private
|
|
1962
|
+
*/
|
|
1963
|
+
this._listeners = {};
|
|
1964
|
+
}
|
|
1965
|
+
|
|
1966
|
+
/**
|
|
1967
|
+
* Registers an event listener.
|
|
1968
|
+
* @param {string} evt Event name
|
|
1969
|
+
* @param {function} fn Listener
|
|
1970
|
+
* @param {*} [ctx] Listener context
|
|
1971
|
+
* @returns {util.EventEmitter} `this`
|
|
1972
|
+
*/
|
|
1973
|
+
EventEmitter.prototype.on = function on(evt, fn, ctx) {
|
|
1974
|
+
(this._listeners[evt] || (this._listeners[evt] = [])).push({
|
|
1975
|
+
fn : fn,
|
|
1976
|
+
ctx : ctx || this
|
|
1977
|
+
});
|
|
1978
|
+
return this;
|
|
1979
|
+
};
|
|
1980
|
+
|
|
1981
|
+
/**
|
|
1982
|
+
* Removes an event listener or any matching listeners if arguments are omitted.
|
|
1983
|
+
* @param {string} [evt] Event name. Removes all listeners if omitted.
|
|
1984
|
+
* @param {function} [fn] Listener to remove. Removes all listeners of `evt` if omitted.
|
|
1985
|
+
* @returns {util.EventEmitter} `this`
|
|
1986
|
+
*/
|
|
1987
|
+
EventEmitter.prototype.off = function off(evt, fn) {
|
|
1988
|
+
if (evt === undefined)
|
|
1989
|
+
this._listeners = {};
|
|
1990
|
+
else {
|
|
1991
|
+
if (fn === undefined)
|
|
1992
|
+
this._listeners[evt] = [];
|
|
1993
|
+
else {
|
|
1994
|
+
var listeners = this._listeners[evt];
|
|
1995
|
+
for (var i = 0; i < listeners.length;)
|
|
1996
|
+
if (listeners[i].fn === fn)
|
|
1997
|
+
listeners.splice(i, 1);
|
|
1998
|
+
else
|
|
1999
|
+
++i;
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
return this;
|
|
2003
|
+
};
|
|
2004
|
+
|
|
2005
|
+
/**
|
|
2006
|
+
* Emits an event by calling its listeners with the specified arguments.
|
|
2007
|
+
* @param {string} evt Event name
|
|
2008
|
+
* @param {...*} args Arguments
|
|
2009
|
+
* @returns {util.EventEmitter} `this`
|
|
2010
|
+
*/
|
|
2011
|
+
EventEmitter.prototype.emit = function emit(evt) {
|
|
2012
|
+
var listeners = this._listeners[evt];
|
|
2013
|
+
if (listeners) {
|
|
2014
|
+
var args = [],
|
|
2015
|
+
i = 1;
|
|
2016
|
+
for (; i < arguments.length;)
|
|
2017
|
+
args.push(arguments[i++]);
|
|
2018
|
+
for (i = 0; i < listeners.length;)
|
|
2019
|
+
listeners[i].fn.apply(listeners[i++].ctx, args);
|
|
2020
|
+
}
|
|
2021
|
+
return this;
|
|
2022
|
+
};
|
|
2023
2023
|
|
|
2024
2024
|
|
|
2025
2025
|
/***/ }),
|
|
@@ -2028,780 +2028,780 @@ EventEmitter.prototype.emit = function emit(evt) {
|
|
|
2028
2028
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
2029
2029
|
|
|
2030
2030
|
"use strict";
|
|
2031
|
+
|
|
2032
|
+
module.exports = fetch;
|
|
2033
|
+
|
|
2034
|
+
var asPromise = __webpack_require__(4537),
|
|
2035
|
+
inquire = __webpack_require__(7199);
|
|
2036
|
+
|
|
2037
|
+
var fs = inquire("fs");
|
|
2038
|
+
|
|
2039
|
+
/**
|
|
2040
|
+
* Node-style callback as used by {@link util.fetch}.
|
|
2041
|
+
* @typedef FetchCallback
|
|
2042
|
+
* @type {function}
|
|
2043
|
+
* @param {?Error} error Error, if any, otherwise `null`
|
|
2044
|
+
* @param {string} [contents] File contents, if there hasn't been an error
|
|
2045
|
+
* @returns {undefined}
|
|
2046
|
+
*/
|
|
2047
|
+
|
|
2048
|
+
/**
|
|
2049
|
+
* Options as used by {@link util.fetch}.
|
|
2050
|
+
* @typedef FetchOptions
|
|
2051
|
+
* @type {Object}
|
|
2052
|
+
* @property {boolean} [binary=false] Whether expecting a binary response
|
|
2053
|
+
* @property {boolean} [xhr=false] If `true`, forces the use of XMLHttpRequest
|
|
2054
|
+
*/
|
|
2055
|
+
|
|
2056
|
+
/**
|
|
2057
|
+
* Fetches the contents of a file.
|
|
2058
|
+
* @memberof util
|
|
2059
|
+
* @param {string} filename File path or url
|
|
2060
|
+
* @param {FetchOptions} options Fetch options
|
|
2061
|
+
* @param {FetchCallback} callback Callback function
|
|
2062
|
+
* @returns {undefined}
|
|
2063
|
+
*/
|
|
2064
|
+
function fetch(filename, options, callback) {
|
|
2065
|
+
if (typeof options === "function") {
|
|
2066
|
+
callback = options;
|
|
2067
|
+
options = {};
|
|
2068
|
+
} else if (!options)
|
|
2069
|
+
options = {};
|
|
2070
|
+
|
|
2071
|
+
if (!callback)
|
|
2072
|
+
return asPromise(fetch, this, filename, options); // eslint-disable-line no-invalid-this
|
|
2073
|
+
|
|
2074
|
+
// if a node-like filesystem is present, try it first but fall back to XHR if nothing is found.
|
|
2075
|
+
if (!options.xhr && fs && fs.readFile)
|
|
2076
|
+
return fs.readFile(filename, function fetchReadFileCallback(err, contents) {
|
|
2077
|
+
return err && typeof XMLHttpRequest !== "undefined"
|
|
2078
|
+
? fetch.xhr(filename, options, callback)
|
|
2079
|
+
: err
|
|
2080
|
+
? callback(err)
|
|
2081
|
+
: callback(null, options.binary ? contents : contents.toString("utf8"));
|
|
2082
|
+
});
|
|
2083
|
+
|
|
2084
|
+
// use the XHR version otherwise.
|
|
2085
|
+
return fetch.xhr(filename, options, callback);
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
/**
|
|
2089
|
+
* Fetches the contents of a file.
|
|
2090
|
+
* @name util.fetch
|
|
2091
|
+
* @function
|
|
2092
|
+
* @param {string} path File path or url
|
|
2093
|
+
* @param {FetchCallback} callback Callback function
|
|
2094
|
+
* @returns {undefined}
|
|
2095
|
+
* @variation 2
|
|
2096
|
+
*/
|
|
2097
|
+
|
|
2098
|
+
/**
|
|
2099
|
+
* Fetches the contents of a file.
|
|
2100
|
+
* @name util.fetch
|
|
2101
|
+
* @function
|
|
2102
|
+
* @param {string} path File path or url
|
|
2103
|
+
* @param {FetchOptions} [options] Fetch options
|
|
2104
|
+
* @returns {Promise<string|Uint8Array>} Promise
|
|
2105
|
+
* @variation 3
|
|
2106
|
+
*/
|
|
2107
|
+
|
|
2108
|
+
/**/
|
|
2109
|
+
fetch.xhr = function fetch_xhr(filename, options, callback) {
|
|
2110
|
+
var xhr = new XMLHttpRequest();
|
|
2111
|
+
xhr.onreadystatechange /* works everywhere */ = function fetchOnReadyStateChange() {
|
|
2112
|
+
|
|
2113
|
+
if (xhr.readyState !== 4)
|
|
2114
|
+
return undefined;
|
|
2115
|
+
|
|
2116
|
+
// local cors security errors return status 0 / empty string, too. afaik this cannot be
|
|
2117
|
+
// reliably distinguished from an actually empty file for security reasons. feel free
|
|
2118
|
+
// to send a pull request if you are aware of a solution.
|
|
2119
|
+
if (xhr.status !== 0 && xhr.status !== 200)
|
|
2120
|
+
return callback(Error("status " + xhr.status));
|
|
2121
|
+
|
|
2122
|
+
// if binary data is expected, make sure that some sort of array is returned, even if
|
|
2123
|
+
// ArrayBuffers are not supported. the binary string fallback, however, is unsafe.
|
|
2124
|
+
if (options.binary) {
|
|
2125
|
+
var buffer = xhr.response;
|
|
2126
|
+
if (!buffer) {
|
|
2127
|
+
buffer = [];
|
|
2128
|
+
for (var i = 0; i < xhr.responseText.length; ++i)
|
|
2129
|
+
buffer.push(xhr.responseText.charCodeAt(i) & 255);
|
|
2130
|
+
}
|
|
2131
|
+
return callback(null, typeof Uint8Array !== "undefined" ? new Uint8Array(buffer) : buffer);
|
|
2132
|
+
}
|
|
2133
|
+
return callback(null, xhr.responseText);
|
|
2134
|
+
};
|
|
2135
|
+
|
|
2136
|
+
if (options.binary) {
|
|
2137
|
+
// ref: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data#Receiving_binary_data_in_older_browsers
|
|
2138
|
+
if ("overrideMimeType" in xhr)
|
|
2139
|
+
xhr.overrideMimeType("text/plain; charset=x-user-defined");
|
|
2140
|
+
xhr.responseType = "arraybuffer";
|
|
2141
|
+
}
|
|
2142
|
+
|
|
2143
|
+
xhr.open("GET", filename);
|
|
2144
|
+
xhr.send();
|
|
2145
|
+
};
|
|
2031
2146
|
|
|
2032
|
-
module.exports = fetch;
|
|
2033
2147
|
|
|
2034
|
-
|
|
2035
|
-
inquire = __webpack_require__(7199);
|
|
2036
|
-
|
|
2037
|
-
var fs = inquire("fs");
|
|
2148
|
+
/***/ }),
|
|
2038
2149
|
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
* @typedef FetchCallback
|
|
2042
|
-
* @type {function}
|
|
2043
|
-
* @param {?Error} error Error, if any, otherwise `null`
|
|
2044
|
-
* @param {string} [contents] File contents, if there hasn't been an error
|
|
2045
|
-
* @returns {undefined}
|
|
2046
|
-
*/
|
|
2150
|
+
/***/ 945:
|
|
2151
|
+
/***/ ((module) => {
|
|
2047
2152
|
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2153
|
+
"use strict";
|
|
2154
|
+
|
|
2155
|
+
|
|
2156
|
+
module.exports = factory(factory);
|
|
2157
|
+
|
|
2158
|
+
/**
|
|
2159
|
+
* Reads / writes floats / doubles from / to buffers.
|
|
2160
|
+
* @name util.float
|
|
2161
|
+
* @namespace
|
|
2162
|
+
*/
|
|
2163
|
+
|
|
2164
|
+
/**
|
|
2165
|
+
* Writes a 32 bit float to a buffer using little endian byte order.
|
|
2166
|
+
* @name util.float.writeFloatLE
|
|
2167
|
+
* @function
|
|
2168
|
+
* @param {number} val Value to write
|
|
2169
|
+
* @param {Uint8Array} buf Target buffer
|
|
2170
|
+
* @param {number} pos Target buffer offset
|
|
2171
|
+
* @returns {undefined}
|
|
2172
|
+
*/
|
|
2173
|
+
|
|
2174
|
+
/**
|
|
2175
|
+
* Writes a 32 bit float to a buffer using big endian byte order.
|
|
2176
|
+
* @name util.float.writeFloatBE
|
|
2177
|
+
* @function
|
|
2178
|
+
* @param {number} val Value to write
|
|
2179
|
+
* @param {Uint8Array} buf Target buffer
|
|
2180
|
+
* @param {number} pos Target buffer offset
|
|
2181
|
+
* @returns {undefined}
|
|
2182
|
+
*/
|
|
2183
|
+
|
|
2184
|
+
/**
|
|
2185
|
+
* Reads a 32 bit float from a buffer using little endian byte order.
|
|
2186
|
+
* @name util.float.readFloatLE
|
|
2187
|
+
* @function
|
|
2188
|
+
* @param {Uint8Array} buf Source buffer
|
|
2189
|
+
* @param {number} pos Source buffer offset
|
|
2190
|
+
* @returns {number} Value read
|
|
2191
|
+
*/
|
|
2192
|
+
|
|
2193
|
+
/**
|
|
2194
|
+
* Reads a 32 bit float from a buffer using big endian byte order.
|
|
2195
|
+
* @name util.float.readFloatBE
|
|
2196
|
+
* @function
|
|
2197
|
+
* @param {Uint8Array} buf Source buffer
|
|
2198
|
+
* @param {number} pos Source buffer offset
|
|
2199
|
+
* @returns {number} Value read
|
|
2200
|
+
*/
|
|
2201
|
+
|
|
2202
|
+
/**
|
|
2203
|
+
* Writes a 64 bit double to a buffer using little endian byte order.
|
|
2204
|
+
* @name util.float.writeDoubleLE
|
|
2205
|
+
* @function
|
|
2206
|
+
* @param {number} val Value to write
|
|
2207
|
+
* @param {Uint8Array} buf Target buffer
|
|
2208
|
+
* @param {number} pos Target buffer offset
|
|
2209
|
+
* @returns {undefined}
|
|
2210
|
+
*/
|
|
2211
|
+
|
|
2212
|
+
/**
|
|
2213
|
+
* Writes a 64 bit double to a buffer using big endian byte order.
|
|
2214
|
+
* @name util.float.writeDoubleBE
|
|
2215
|
+
* @function
|
|
2216
|
+
* @param {number} val Value to write
|
|
2217
|
+
* @param {Uint8Array} buf Target buffer
|
|
2218
|
+
* @param {number} pos Target buffer offset
|
|
2219
|
+
* @returns {undefined}
|
|
2220
|
+
*/
|
|
2221
|
+
|
|
2222
|
+
/**
|
|
2223
|
+
* Reads a 64 bit double from a buffer using little endian byte order.
|
|
2224
|
+
* @name util.float.readDoubleLE
|
|
2225
|
+
* @function
|
|
2226
|
+
* @param {Uint8Array} buf Source buffer
|
|
2227
|
+
* @param {number} pos Source buffer offset
|
|
2228
|
+
* @returns {number} Value read
|
|
2229
|
+
*/
|
|
2230
|
+
|
|
2231
|
+
/**
|
|
2232
|
+
* Reads a 64 bit double from a buffer using big endian byte order.
|
|
2233
|
+
* @name util.float.readDoubleBE
|
|
2234
|
+
* @function
|
|
2235
|
+
* @param {Uint8Array} buf Source buffer
|
|
2236
|
+
* @param {number} pos Source buffer offset
|
|
2237
|
+
* @returns {number} Value read
|
|
2238
|
+
*/
|
|
2239
|
+
|
|
2240
|
+
// Factory function for the purpose of node-based testing in modified global environments
|
|
2241
|
+
function factory(exports) {
|
|
2242
|
+
|
|
2243
|
+
// float: typed array
|
|
2244
|
+
if (typeof Float32Array !== "undefined") (function() {
|
|
2245
|
+
|
|
2246
|
+
var f32 = new Float32Array([ -0 ]),
|
|
2247
|
+
f8b = new Uint8Array(f32.buffer),
|
|
2248
|
+
le = f8b[3] === 128;
|
|
2249
|
+
|
|
2250
|
+
function writeFloat_f32_cpy(val, buf, pos) {
|
|
2251
|
+
f32[0] = val;
|
|
2252
|
+
buf[pos ] = f8b[0];
|
|
2253
|
+
buf[pos + 1] = f8b[1];
|
|
2254
|
+
buf[pos + 2] = f8b[2];
|
|
2255
|
+
buf[pos + 3] = f8b[3];
|
|
2256
|
+
}
|
|
2257
|
+
|
|
2258
|
+
function writeFloat_f32_rev(val, buf, pos) {
|
|
2259
|
+
f32[0] = val;
|
|
2260
|
+
buf[pos ] = f8b[3];
|
|
2261
|
+
buf[pos + 1] = f8b[2];
|
|
2262
|
+
buf[pos + 2] = f8b[1];
|
|
2263
|
+
buf[pos + 3] = f8b[0];
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2266
|
+
/* istanbul ignore next */
|
|
2267
|
+
exports.writeFloatLE = le ? writeFloat_f32_cpy : writeFloat_f32_rev;
|
|
2268
|
+
/* istanbul ignore next */
|
|
2269
|
+
exports.writeFloatBE = le ? writeFloat_f32_rev : writeFloat_f32_cpy;
|
|
2270
|
+
|
|
2271
|
+
function readFloat_f32_cpy(buf, pos) {
|
|
2272
|
+
f8b[0] = buf[pos ];
|
|
2273
|
+
f8b[1] = buf[pos + 1];
|
|
2274
|
+
f8b[2] = buf[pos + 2];
|
|
2275
|
+
f8b[3] = buf[pos + 3];
|
|
2276
|
+
return f32[0];
|
|
2277
|
+
}
|
|
2278
|
+
|
|
2279
|
+
function readFloat_f32_rev(buf, pos) {
|
|
2280
|
+
f8b[3] = buf[pos ];
|
|
2281
|
+
f8b[2] = buf[pos + 1];
|
|
2282
|
+
f8b[1] = buf[pos + 2];
|
|
2283
|
+
f8b[0] = buf[pos + 3];
|
|
2284
|
+
return f32[0];
|
|
2285
|
+
}
|
|
2286
|
+
|
|
2287
|
+
/* istanbul ignore next */
|
|
2288
|
+
exports.readFloatLE = le ? readFloat_f32_cpy : readFloat_f32_rev;
|
|
2289
|
+
/* istanbul ignore next */
|
|
2290
|
+
exports.readFloatBE = le ? readFloat_f32_rev : readFloat_f32_cpy;
|
|
2291
|
+
|
|
2292
|
+
// float: ieee754
|
|
2293
|
+
})(); else (function() {
|
|
2294
|
+
|
|
2295
|
+
function writeFloat_ieee754(writeUint, val, buf, pos) {
|
|
2296
|
+
var sign = val < 0 ? 1 : 0;
|
|
2297
|
+
if (sign)
|
|
2298
|
+
val = -val;
|
|
2299
|
+
if (val === 0)
|
|
2300
|
+
writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos);
|
|
2301
|
+
else if (isNaN(val))
|
|
2302
|
+
writeUint(2143289344, buf, pos);
|
|
2303
|
+
else if (val > 3.4028234663852886e+38) // +-Infinity
|
|
2304
|
+
writeUint((sign << 31 | 2139095040) >>> 0, buf, pos);
|
|
2305
|
+
else if (val < 1.1754943508222875e-38) // denormal
|
|
2306
|
+
writeUint((sign << 31 | Math.round(val / 1.401298464324817e-45)) >>> 0, buf, pos);
|
|
2307
|
+
else {
|
|
2308
|
+
var exponent = Math.floor(Math.log(val) / Math.LN2),
|
|
2309
|
+
mantissa = Math.round(val * Math.pow(2, -exponent) * 8388608) & 8388607;
|
|
2310
|
+
writeUint((sign << 31 | exponent + 127 << 23 | mantissa) >>> 0, buf, pos);
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
exports.writeFloatLE = writeFloat_ieee754.bind(null, writeUintLE);
|
|
2315
|
+
exports.writeFloatBE = writeFloat_ieee754.bind(null, writeUintBE);
|
|
2316
|
+
|
|
2317
|
+
function readFloat_ieee754(readUint, buf, pos) {
|
|
2318
|
+
var uint = readUint(buf, pos),
|
|
2319
|
+
sign = (uint >> 31) * 2 + 1,
|
|
2320
|
+
exponent = uint >>> 23 & 255,
|
|
2321
|
+
mantissa = uint & 8388607;
|
|
2322
|
+
return exponent === 255
|
|
2323
|
+
? mantissa
|
|
2324
|
+
? NaN
|
|
2325
|
+
: sign * Infinity
|
|
2326
|
+
: exponent === 0 // denormal
|
|
2327
|
+
? sign * 1.401298464324817e-45 * mantissa
|
|
2328
|
+
: sign * Math.pow(2, exponent - 150) * (mantissa + 8388608);
|
|
2329
|
+
}
|
|
2330
|
+
|
|
2331
|
+
exports.readFloatLE = readFloat_ieee754.bind(null, readUintLE);
|
|
2332
|
+
exports.readFloatBE = readFloat_ieee754.bind(null, readUintBE);
|
|
2333
|
+
|
|
2334
|
+
})();
|
|
2335
|
+
|
|
2336
|
+
// double: typed array
|
|
2337
|
+
if (typeof Float64Array !== "undefined") (function() {
|
|
2338
|
+
|
|
2339
|
+
var f64 = new Float64Array([-0]),
|
|
2340
|
+
f8b = new Uint8Array(f64.buffer),
|
|
2341
|
+
le = f8b[7] === 128;
|
|
2342
|
+
|
|
2343
|
+
function writeDouble_f64_cpy(val, buf, pos) {
|
|
2344
|
+
f64[0] = val;
|
|
2345
|
+
buf[pos ] = f8b[0];
|
|
2346
|
+
buf[pos + 1] = f8b[1];
|
|
2347
|
+
buf[pos + 2] = f8b[2];
|
|
2348
|
+
buf[pos + 3] = f8b[3];
|
|
2349
|
+
buf[pos + 4] = f8b[4];
|
|
2350
|
+
buf[pos + 5] = f8b[5];
|
|
2351
|
+
buf[pos + 6] = f8b[6];
|
|
2352
|
+
buf[pos + 7] = f8b[7];
|
|
2353
|
+
}
|
|
2354
|
+
|
|
2355
|
+
function writeDouble_f64_rev(val, buf, pos) {
|
|
2356
|
+
f64[0] = val;
|
|
2357
|
+
buf[pos ] = f8b[7];
|
|
2358
|
+
buf[pos + 1] = f8b[6];
|
|
2359
|
+
buf[pos + 2] = f8b[5];
|
|
2360
|
+
buf[pos + 3] = f8b[4];
|
|
2361
|
+
buf[pos + 4] = f8b[3];
|
|
2362
|
+
buf[pos + 5] = f8b[2];
|
|
2363
|
+
buf[pos + 6] = f8b[1];
|
|
2364
|
+
buf[pos + 7] = f8b[0];
|
|
2365
|
+
}
|
|
2366
|
+
|
|
2367
|
+
/* istanbul ignore next */
|
|
2368
|
+
exports.writeDoubleLE = le ? writeDouble_f64_cpy : writeDouble_f64_rev;
|
|
2369
|
+
/* istanbul ignore next */
|
|
2370
|
+
exports.writeDoubleBE = le ? writeDouble_f64_rev : writeDouble_f64_cpy;
|
|
2371
|
+
|
|
2372
|
+
function readDouble_f64_cpy(buf, pos) {
|
|
2373
|
+
f8b[0] = buf[pos ];
|
|
2374
|
+
f8b[1] = buf[pos + 1];
|
|
2375
|
+
f8b[2] = buf[pos + 2];
|
|
2376
|
+
f8b[3] = buf[pos + 3];
|
|
2377
|
+
f8b[4] = buf[pos + 4];
|
|
2378
|
+
f8b[5] = buf[pos + 5];
|
|
2379
|
+
f8b[6] = buf[pos + 6];
|
|
2380
|
+
f8b[7] = buf[pos + 7];
|
|
2381
|
+
return f64[0];
|
|
2382
|
+
}
|
|
2383
|
+
|
|
2384
|
+
function readDouble_f64_rev(buf, pos) {
|
|
2385
|
+
f8b[7] = buf[pos ];
|
|
2386
|
+
f8b[6] = buf[pos + 1];
|
|
2387
|
+
f8b[5] = buf[pos + 2];
|
|
2388
|
+
f8b[4] = buf[pos + 3];
|
|
2389
|
+
f8b[3] = buf[pos + 4];
|
|
2390
|
+
f8b[2] = buf[pos + 5];
|
|
2391
|
+
f8b[1] = buf[pos + 6];
|
|
2392
|
+
f8b[0] = buf[pos + 7];
|
|
2393
|
+
return f64[0];
|
|
2394
|
+
}
|
|
2395
|
+
|
|
2396
|
+
/* istanbul ignore next */
|
|
2397
|
+
exports.readDoubleLE = le ? readDouble_f64_cpy : readDouble_f64_rev;
|
|
2398
|
+
/* istanbul ignore next */
|
|
2399
|
+
exports.readDoubleBE = le ? readDouble_f64_rev : readDouble_f64_cpy;
|
|
2400
|
+
|
|
2401
|
+
// double: ieee754
|
|
2402
|
+
})(); else (function() {
|
|
2403
|
+
|
|
2404
|
+
function writeDouble_ieee754(writeUint, off0, off1, val, buf, pos) {
|
|
2405
|
+
var sign = val < 0 ? 1 : 0;
|
|
2406
|
+
if (sign)
|
|
2407
|
+
val = -val;
|
|
2408
|
+
if (val === 0) {
|
|
2409
|
+
writeUint(0, buf, pos + off0);
|
|
2410
|
+
writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos + off1);
|
|
2411
|
+
} else if (isNaN(val)) {
|
|
2412
|
+
writeUint(0, buf, pos + off0);
|
|
2413
|
+
writeUint(2146959360, buf, pos + off1);
|
|
2414
|
+
} else if (val > 1.7976931348623157e+308) { // +-Infinity
|
|
2415
|
+
writeUint(0, buf, pos + off0);
|
|
2416
|
+
writeUint((sign << 31 | 2146435072) >>> 0, buf, pos + off1);
|
|
2417
|
+
} else {
|
|
2418
|
+
var mantissa;
|
|
2419
|
+
if (val < 2.2250738585072014e-308) { // denormal
|
|
2420
|
+
mantissa = val / 5e-324;
|
|
2421
|
+
writeUint(mantissa >>> 0, buf, pos + off0);
|
|
2422
|
+
writeUint((sign << 31 | mantissa / 4294967296) >>> 0, buf, pos + off1);
|
|
2423
|
+
} else {
|
|
2424
|
+
var exponent = Math.floor(Math.log(val) / Math.LN2);
|
|
2425
|
+
if (exponent === 1024)
|
|
2426
|
+
exponent = 1023;
|
|
2427
|
+
mantissa = val * Math.pow(2, -exponent);
|
|
2428
|
+
writeUint(mantissa * 4503599627370496 >>> 0, buf, pos + off0);
|
|
2429
|
+
writeUint((sign << 31 | exponent + 1023 << 20 | mantissa * 1048576 & 1048575) >>> 0, buf, pos + off1);
|
|
2430
|
+
}
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
|
|
2434
|
+
exports.writeDoubleLE = writeDouble_ieee754.bind(null, writeUintLE, 0, 4);
|
|
2435
|
+
exports.writeDoubleBE = writeDouble_ieee754.bind(null, writeUintBE, 4, 0);
|
|
2436
|
+
|
|
2437
|
+
function readDouble_ieee754(readUint, off0, off1, buf, pos) {
|
|
2438
|
+
var lo = readUint(buf, pos + off0),
|
|
2439
|
+
hi = readUint(buf, pos + off1);
|
|
2440
|
+
var sign = (hi >> 31) * 2 + 1,
|
|
2441
|
+
exponent = hi >>> 20 & 2047,
|
|
2442
|
+
mantissa = 4294967296 * (hi & 1048575) + lo;
|
|
2443
|
+
return exponent === 2047
|
|
2444
|
+
? mantissa
|
|
2445
|
+
? NaN
|
|
2446
|
+
: sign * Infinity
|
|
2447
|
+
: exponent === 0 // denormal
|
|
2448
|
+
? sign * 5e-324 * mantissa
|
|
2449
|
+
: sign * Math.pow(2, exponent - 1075) * (mantissa + 4503599627370496);
|
|
2450
|
+
}
|
|
2451
|
+
|
|
2452
|
+
exports.readDoubleLE = readDouble_ieee754.bind(null, readUintLE, 0, 4);
|
|
2453
|
+
exports.readDoubleBE = readDouble_ieee754.bind(null, readUintBE, 4, 0);
|
|
2454
|
+
|
|
2455
|
+
})();
|
|
2456
|
+
|
|
2457
|
+
return exports;
|
|
2458
|
+
}
|
|
2459
|
+
|
|
2460
|
+
// uint helpers
|
|
2461
|
+
|
|
2462
|
+
function writeUintLE(val, buf, pos) {
|
|
2463
|
+
buf[pos ] = val & 255;
|
|
2464
|
+
buf[pos + 1] = val >>> 8 & 255;
|
|
2465
|
+
buf[pos + 2] = val >>> 16 & 255;
|
|
2466
|
+
buf[pos + 3] = val >>> 24;
|
|
2467
|
+
}
|
|
2468
|
+
|
|
2469
|
+
function writeUintBE(val, buf, pos) {
|
|
2470
|
+
buf[pos ] = val >>> 24;
|
|
2471
|
+
buf[pos + 1] = val >>> 16 & 255;
|
|
2472
|
+
buf[pos + 2] = val >>> 8 & 255;
|
|
2473
|
+
buf[pos + 3] = val & 255;
|
|
2474
|
+
}
|
|
2475
|
+
|
|
2476
|
+
function readUintLE(buf, pos) {
|
|
2477
|
+
return (buf[pos ]
|
|
2478
|
+
| buf[pos + 1] << 8
|
|
2479
|
+
| buf[pos + 2] << 16
|
|
2480
|
+
| buf[pos + 3] << 24) >>> 0;
|
|
2481
|
+
}
|
|
2482
|
+
|
|
2483
|
+
function readUintBE(buf, pos) {
|
|
2484
|
+
return (buf[pos ] << 24
|
|
2485
|
+
| buf[pos + 1] << 16
|
|
2486
|
+
| buf[pos + 2] << 8
|
|
2487
|
+
| buf[pos + 3]) >>> 0;
|
|
2488
|
+
}
|
|
2055
2489
|
|
|
2056
|
-
/**
|
|
2057
|
-
* Fetches the contents of a file.
|
|
2058
|
-
* @memberof util
|
|
2059
|
-
* @param {string} filename File path or url
|
|
2060
|
-
* @param {FetchOptions} options Fetch options
|
|
2061
|
-
* @param {FetchCallback} callback Callback function
|
|
2062
|
-
* @returns {undefined}
|
|
2063
|
-
*/
|
|
2064
|
-
function fetch(filename, options, callback) {
|
|
2065
|
-
if (typeof options === "function") {
|
|
2066
|
-
callback = options;
|
|
2067
|
-
options = {};
|
|
2068
|
-
} else if (!options)
|
|
2069
|
-
options = {};
|
|
2070
2490
|
|
|
2071
|
-
|
|
2072
|
-
return asPromise(fetch, this, filename, options); // eslint-disable-line no-invalid-this
|
|
2073
|
-
|
|
2074
|
-
// if a node-like filesystem is present, try it first but fall back to XHR if nothing is found.
|
|
2075
|
-
if (!options.xhr && fs && fs.readFile)
|
|
2076
|
-
return fs.readFile(filename, function fetchReadFileCallback(err, contents) {
|
|
2077
|
-
return err && typeof XMLHttpRequest !== "undefined"
|
|
2078
|
-
? fetch.xhr(filename, options, callback)
|
|
2079
|
-
: err
|
|
2080
|
-
? callback(err)
|
|
2081
|
-
: callback(null, options.binary ? contents : contents.toString("utf8"));
|
|
2082
|
-
});
|
|
2491
|
+
/***/ }),
|
|
2083
2492
|
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
}
|
|
2493
|
+
/***/ 7199:
|
|
2494
|
+
/***/ ((module) => {
|
|
2087
2495
|
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
*
|
|
2094
|
-
* @
|
|
2095
|
-
* @
|
|
2096
|
-
|
|
2496
|
+
"use strict";
|
|
2497
|
+
|
|
2498
|
+
module.exports = inquire;
|
|
2499
|
+
|
|
2500
|
+
/**
|
|
2501
|
+
* Requires a module only if available.
|
|
2502
|
+
* @memberof util
|
|
2503
|
+
* @param {string} moduleName Module to require
|
|
2504
|
+
* @returns {?Object} Required module if available and not empty, otherwise `null`
|
|
2505
|
+
*/
|
|
2506
|
+
function inquire(moduleName) {
|
|
2507
|
+
try {
|
|
2508
|
+
var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
|
|
2509
|
+
if (mod && (mod.length || Object.keys(mod).length))
|
|
2510
|
+
return mod;
|
|
2511
|
+
} catch (e) {} // eslint-disable-line no-empty
|
|
2512
|
+
return null;
|
|
2513
|
+
}
|
|
2097
2514
|
|
|
2098
|
-
/**
|
|
2099
|
-
* Fetches the contents of a file.
|
|
2100
|
-
* @name util.fetch
|
|
2101
|
-
* @function
|
|
2102
|
-
* @param {string} path File path or url
|
|
2103
|
-
* @param {FetchOptions} [options] Fetch options
|
|
2104
|
-
* @returns {Promise<string|Uint8Array>} Promise
|
|
2105
|
-
* @variation 3
|
|
2106
|
-
*/
|
|
2107
2515
|
|
|
2108
|
-
|
|
2109
|
-
fetch.xhr = function fetch_xhr(filename, options, callback) {
|
|
2110
|
-
var xhr = new XMLHttpRequest();
|
|
2111
|
-
xhr.onreadystatechange /* works everywhere */ = function fetchOnReadyStateChange() {
|
|
2112
|
-
|
|
2113
|
-
if (xhr.readyState !== 4)
|
|
2114
|
-
return undefined;
|
|
2115
|
-
|
|
2116
|
-
// local cors security errors return status 0 / empty string, too. afaik this cannot be
|
|
2117
|
-
// reliably distinguished from an actually empty file for security reasons. feel free
|
|
2118
|
-
// to send a pull request if you are aware of a solution.
|
|
2119
|
-
if (xhr.status !== 0 && xhr.status !== 200)
|
|
2120
|
-
return callback(Error("status " + xhr.status));
|
|
2121
|
-
|
|
2122
|
-
// if binary data is expected, make sure that some sort of array is returned, even if
|
|
2123
|
-
// ArrayBuffers are not supported. the binary string fallback, however, is unsafe.
|
|
2124
|
-
if (options.binary) {
|
|
2125
|
-
var buffer = xhr.response;
|
|
2126
|
-
if (!buffer) {
|
|
2127
|
-
buffer = [];
|
|
2128
|
-
for (var i = 0; i < xhr.responseText.length; ++i)
|
|
2129
|
-
buffer.push(xhr.responseText.charCodeAt(i) & 255);
|
|
2130
|
-
}
|
|
2131
|
-
return callback(null, typeof Uint8Array !== "undefined" ? new Uint8Array(buffer) : buffer);
|
|
2132
|
-
}
|
|
2133
|
-
return callback(null, xhr.responseText);
|
|
2134
|
-
};
|
|
2516
|
+
/***/ }),
|
|
2135
2517
|
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
if ("overrideMimeType" in xhr)
|
|
2139
|
-
xhr.overrideMimeType("text/plain; charset=x-user-defined");
|
|
2140
|
-
xhr.responseType = "arraybuffer";
|
|
2141
|
-
}
|
|
2518
|
+
/***/ 8626:
|
|
2519
|
+
/***/ ((__unused_webpack_module, exports) => {
|
|
2142
2520
|
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2521
|
+
"use strict";
|
|
2522
|
+
|
|
2523
|
+
|
|
2524
|
+
/**
|
|
2525
|
+
* A minimal path module to resolve Unix, Windows and URL paths alike.
|
|
2526
|
+
* @memberof util
|
|
2527
|
+
* @namespace
|
|
2528
|
+
*/
|
|
2529
|
+
var path = exports;
|
|
2530
|
+
|
|
2531
|
+
var isAbsolute =
|
|
2532
|
+
/**
|
|
2533
|
+
* Tests if the specified path is absolute.
|
|
2534
|
+
* @param {string} path Path to test
|
|
2535
|
+
* @returns {boolean} `true` if path is absolute
|
|
2536
|
+
*/
|
|
2537
|
+
path.isAbsolute = function isAbsolute(path) {
|
|
2538
|
+
return /^(?:\/|\w+:)/.test(path);
|
|
2539
|
+
};
|
|
2540
|
+
|
|
2541
|
+
var normalize =
|
|
2542
|
+
/**
|
|
2543
|
+
* Normalizes the specified path.
|
|
2544
|
+
* @param {string} path Path to normalize
|
|
2545
|
+
* @returns {string} Normalized path
|
|
2546
|
+
*/
|
|
2547
|
+
path.normalize = function normalize(path) {
|
|
2548
|
+
path = path.replace(/\\/g, "/")
|
|
2549
|
+
.replace(/\/{2,}/g, "/");
|
|
2550
|
+
var parts = path.split("/"),
|
|
2551
|
+
absolute = isAbsolute(path),
|
|
2552
|
+
prefix = "";
|
|
2553
|
+
if (absolute)
|
|
2554
|
+
prefix = parts.shift() + "/";
|
|
2555
|
+
for (var i = 0; i < parts.length;) {
|
|
2556
|
+
if (parts[i] === "..") {
|
|
2557
|
+
if (i > 0 && parts[i - 1] !== "..")
|
|
2558
|
+
parts.splice(--i, 2);
|
|
2559
|
+
else if (absolute)
|
|
2560
|
+
parts.splice(i, 1);
|
|
2561
|
+
else
|
|
2562
|
+
++i;
|
|
2563
|
+
} else if (parts[i] === ".")
|
|
2564
|
+
parts.splice(i, 1);
|
|
2565
|
+
else
|
|
2566
|
+
++i;
|
|
2567
|
+
}
|
|
2568
|
+
return prefix + parts.join("/");
|
|
2569
|
+
};
|
|
2570
|
+
|
|
2571
|
+
/**
|
|
2572
|
+
* Resolves the specified include path against the specified origin path.
|
|
2573
|
+
* @param {string} originPath Path to the origin file
|
|
2574
|
+
* @param {string} includePath Include path relative to origin path
|
|
2575
|
+
* @param {boolean} [alreadyNormalized=false] `true` if both paths are already known to be normalized
|
|
2576
|
+
* @returns {string} Path to the include file
|
|
2577
|
+
*/
|
|
2578
|
+
path.resolve = function resolve(originPath, includePath, alreadyNormalized) {
|
|
2579
|
+
if (!alreadyNormalized)
|
|
2580
|
+
includePath = normalize(includePath);
|
|
2581
|
+
if (isAbsolute(includePath))
|
|
2582
|
+
return includePath;
|
|
2583
|
+
if (!alreadyNormalized)
|
|
2584
|
+
originPath = normalize(originPath);
|
|
2585
|
+
return (originPath = originPath.replace(/(?:\/|^)[^/]+$/, "")).length ? normalize(originPath + "/" + includePath) : includePath;
|
|
2586
|
+
};
|
|
2146
2587
|
|
|
2147
2588
|
|
|
2148
2589
|
/***/ }),
|
|
2149
2590
|
|
|
2150
|
-
/***/
|
|
2591
|
+
/***/ 6662:
|
|
2151
2592
|
/***/ ((module) => {
|
|
2152
2593
|
|
|
2153
2594
|
"use strict";
|
|
2595
|
+
|
|
2596
|
+
module.exports = pool;
|
|
2597
|
+
|
|
2598
|
+
/**
|
|
2599
|
+
* An allocator as used by {@link util.pool}.
|
|
2600
|
+
* @typedef PoolAllocator
|
|
2601
|
+
* @type {function}
|
|
2602
|
+
* @param {number} size Buffer size
|
|
2603
|
+
* @returns {Uint8Array} Buffer
|
|
2604
|
+
*/
|
|
2605
|
+
|
|
2606
|
+
/**
|
|
2607
|
+
* A slicer as used by {@link util.pool}.
|
|
2608
|
+
* @typedef PoolSlicer
|
|
2609
|
+
* @type {function}
|
|
2610
|
+
* @param {number} start Start offset
|
|
2611
|
+
* @param {number} end End offset
|
|
2612
|
+
* @returns {Uint8Array} Buffer slice
|
|
2613
|
+
* @this {Uint8Array}
|
|
2614
|
+
*/
|
|
2615
|
+
|
|
2616
|
+
/**
|
|
2617
|
+
* A general purpose buffer pool.
|
|
2618
|
+
* @memberof util
|
|
2619
|
+
* @function
|
|
2620
|
+
* @param {PoolAllocator} alloc Allocator
|
|
2621
|
+
* @param {PoolSlicer} slice Slicer
|
|
2622
|
+
* @param {number} [size=8192] Slab size
|
|
2623
|
+
* @returns {PoolAllocator} Pooled allocator
|
|
2624
|
+
*/
|
|
2625
|
+
function pool(alloc, slice, size) {
|
|
2626
|
+
var SIZE = size || 8192;
|
|
2627
|
+
var MAX = SIZE >>> 1;
|
|
2628
|
+
var slab = null;
|
|
2629
|
+
var offset = SIZE;
|
|
2630
|
+
return function pool_alloc(size) {
|
|
2631
|
+
if (size < 1 || size > MAX)
|
|
2632
|
+
return alloc(size);
|
|
2633
|
+
if (offset + size > SIZE) {
|
|
2634
|
+
slab = alloc(SIZE);
|
|
2635
|
+
offset = 0;
|
|
2636
|
+
}
|
|
2637
|
+
var buf = slice.call(slab, offset, offset += size);
|
|
2638
|
+
if (offset & 7) // align to 32 bit
|
|
2639
|
+
offset = (offset | 7) + 1;
|
|
2640
|
+
return buf;
|
|
2641
|
+
};
|
|
2642
|
+
}
|
|
2154
2643
|
|
|
2155
2644
|
|
|
2156
|
-
|
|
2645
|
+
/***/ }),
|
|
2157
2646
|
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
* @name util.float
|
|
2161
|
-
* @namespace
|
|
2162
|
-
*/
|
|
2647
|
+
/***/ 4997:
|
|
2648
|
+
/***/ ((__unused_webpack_module, exports) => {
|
|
2163
2649
|
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
*
|
|
2169
|
-
* @
|
|
2170
|
-
* @
|
|
2171
|
-
|
|
2172
|
-
|
|
2650
|
+
"use strict";
|
|
2651
|
+
|
|
2652
|
+
|
|
2653
|
+
/**
|
|
2654
|
+
* A minimal UTF8 implementation for number arrays.
|
|
2655
|
+
* @memberof util
|
|
2656
|
+
* @namespace
|
|
2657
|
+
*/
|
|
2658
|
+
var utf8 = exports;
|
|
2659
|
+
|
|
2660
|
+
/**
|
|
2661
|
+
* Calculates the UTF8 byte length of a string.
|
|
2662
|
+
* @param {string} string String
|
|
2663
|
+
* @returns {number} Byte length
|
|
2664
|
+
*/
|
|
2665
|
+
utf8.length = function utf8_length(string) {
|
|
2666
|
+
var len = 0,
|
|
2667
|
+
c = 0;
|
|
2668
|
+
for (var i = 0; i < string.length; ++i) {
|
|
2669
|
+
c = string.charCodeAt(i);
|
|
2670
|
+
if (c < 128)
|
|
2671
|
+
len += 1;
|
|
2672
|
+
else if (c < 2048)
|
|
2673
|
+
len += 2;
|
|
2674
|
+
else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
|
|
2675
|
+
++i;
|
|
2676
|
+
len += 4;
|
|
2677
|
+
} else
|
|
2678
|
+
len += 3;
|
|
2679
|
+
}
|
|
2680
|
+
return len;
|
|
2681
|
+
};
|
|
2682
|
+
|
|
2683
|
+
/**
|
|
2684
|
+
* Reads UTF8 bytes as a string.
|
|
2685
|
+
* @param {Uint8Array} buffer Source buffer
|
|
2686
|
+
* @param {number} start Source start
|
|
2687
|
+
* @param {number} end Source end
|
|
2688
|
+
* @returns {string} String read
|
|
2689
|
+
*/
|
|
2690
|
+
utf8.read = function utf8_read(buffer, start, end) {
|
|
2691
|
+
var len = end - start;
|
|
2692
|
+
if (len < 1)
|
|
2693
|
+
return "";
|
|
2694
|
+
var parts = null,
|
|
2695
|
+
chunk = [],
|
|
2696
|
+
i = 0, // char offset
|
|
2697
|
+
t; // temporary
|
|
2698
|
+
while (start < end) {
|
|
2699
|
+
t = buffer[start++];
|
|
2700
|
+
if (t < 128)
|
|
2701
|
+
chunk[i++] = t;
|
|
2702
|
+
else if (t > 191 && t < 224)
|
|
2703
|
+
chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
|
|
2704
|
+
else if (t > 239 && t < 365) {
|
|
2705
|
+
t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;
|
|
2706
|
+
chunk[i++] = 0xD800 + (t >> 10);
|
|
2707
|
+
chunk[i++] = 0xDC00 + (t & 1023);
|
|
2708
|
+
} else
|
|
2709
|
+
chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
|
|
2710
|
+
if (i > 8191) {
|
|
2711
|
+
(parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
|
|
2712
|
+
i = 0;
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2715
|
+
if (parts) {
|
|
2716
|
+
if (i)
|
|
2717
|
+
parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
|
|
2718
|
+
return parts.join("");
|
|
2719
|
+
}
|
|
2720
|
+
return String.fromCharCode.apply(String, chunk.slice(0, i));
|
|
2721
|
+
};
|
|
2722
|
+
|
|
2723
|
+
/**
|
|
2724
|
+
* Writes a string as UTF8 bytes.
|
|
2725
|
+
* @param {string} string Source string
|
|
2726
|
+
* @param {Uint8Array} buffer Destination buffer
|
|
2727
|
+
* @param {number} offset Destination offset
|
|
2728
|
+
* @returns {number} Bytes written
|
|
2729
|
+
*/
|
|
2730
|
+
utf8.write = function utf8_write(string, buffer, offset) {
|
|
2731
|
+
var start = offset,
|
|
2732
|
+
c1, // character 1
|
|
2733
|
+
c2; // character 2
|
|
2734
|
+
for (var i = 0; i < string.length; ++i) {
|
|
2735
|
+
c1 = string.charCodeAt(i);
|
|
2736
|
+
if (c1 < 128) {
|
|
2737
|
+
buffer[offset++] = c1;
|
|
2738
|
+
} else if (c1 < 2048) {
|
|
2739
|
+
buffer[offset++] = c1 >> 6 | 192;
|
|
2740
|
+
buffer[offset++] = c1 & 63 | 128;
|
|
2741
|
+
} else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
|
|
2742
|
+
c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
|
|
2743
|
+
++i;
|
|
2744
|
+
buffer[offset++] = c1 >> 18 | 240;
|
|
2745
|
+
buffer[offset++] = c1 >> 12 & 63 | 128;
|
|
2746
|
+
buffer[offset++] = c1 >> 6 & 63 | 128;
|
|
2747
|
+
buffer[offset++] = c1 & 63 | 128;
|
|
2748
|
+
} else {
|
|
2749
|
+
buffer[offset++] = c1 >> 12 | 224;
|
|
2750
|
+
buffer[offset++] = c1 >> 6 & 63 | 128;
|
|
2751
|
+
buffer[offset++] = c1 & 63 | 128;
|
|
2752
|
+
}
|
|
2753
|
+
}
|
|
2754
|
+
return offset - start;
|
|
2755
|
+
};
|
|
2173
2756
|
|
|
2174
|
-
/**
|
|
2175
|
-
* Writes a 32 bit float to a buffer using big endian byte order.
|
|
2176
|
-
* @name util.float.writeFloatBE
|
|
2177
|
-
* @function
|
|
2178
|
-
* @param {number} val Value to write
|
|
2179
|
-
* @param {Uint8Array} buf Target buffer
|
|
2180
|
-
* @param {number} pos Target buffer offset
|
|
2181
|
-
* @returns {undefined}
|
|
2182
|
-
*/
|
|
2183
2757
|
|
|
2184
|
-
|
|
2185
|
-
* Reads a 32 bit float from a buffer using little endian byte order.
|
|
2186
|
-
* @name util.float.readFloatLE
|
|
2187
|
-
* @function
|
|
2188
|
-
* @param {Uint8Array} buf Source buffer
|
|
2189
|
-
* @param {number} pos Source buffer offset
|
|
2190
|
-
* @returns {number} Value read
|
|
2191
|
-
*/
|
|
2758
|
+
/***/ }),
|
|
2192
2759
|
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
* @name util.float.readFloatBE
|
|
2196
|
-
* @function
|
|
2197
|
-
* @param {Uint8Array} buf Source buffer
|
|
2198
|
-
* @param {number} pos Source buffer offset
|
|
2199
|
-
* @returns {number} Value read
|
|
2200
|
-
*/
|
|
2760
|
+
/***/ 9669:
|
|
2761
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
2201
2762
|
|
|
2202
|
-
|
|
2203
|
-
* Writes a 64 bit double to a buffer using little endian byte order.
|
|
2204
|
-
* @name util.float.writeDoubleLE
|
|
2205
|
-
* @function
|
|
2206
|
-
* @param {number} val Value to write
|
|
2207
|
-
* @param {Uint8Array} buf Target buffer
|
|
2208
|
-
* @param {number} pos Target buffer offset
|
|
2209
|
-
* @returns {undefined}
|
|
2210
|
-
*/
|
|
2763
|
+
module.exports = __webpack_require__(1609);
|
|
2211
2764
|
|
|
2212
|
-
|
|
2213
|
-
* Writes a 64 bit double to a buffer using big endian byte order.
|
|
2214
|
-
* @name util.float.writeDoubleBE
|
|
2215
|
-
* @function
|
|
2216
|
-
* @param {number} val Value to write
|
|
2217
|
-
* @param {Uint8Array} buf Target buffer
|
|
2218
|
-
* @param {number} pos Target buffer offset
|
|
2219
|
-
* @returns {undefined}
|
|
2220
|
-
*/
|
|
2765
|
+
/***/ }),
|
|
2221
2766
|
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
* @name util.float.readDoubleLE
|
|
2225
|
-
* @function
|
|
2226
|
-
* @param {Uint8Array} buf Source buffer
|
|
2227
|
-
* @param {number} pos Source buffer offset
|
|
2228
|
-
* @returns {number} Value read
|
|
2229
|
-
*/
|
|
2767
|
+
/***/ 5448:
|
|
2768
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
2230
2769
|
|
|
2231
|
-
|
|
2232
|
-
* Reads a 64 bit double from a buffer using big endian byte order.
|
|
2233
|
-
* @name util.float.readDoubleBE
|
|
2234
|
-
* @function
|
|
2235
|
-
* @param {Uint8Array} buf Source buffer
|
|
2236
|
-
* @param {number} pos Source buffer offset
|
|
2237
|
-
* @returns {number} Value read
|
|
2238
|
-
*/
|
|
2770
|
+
"use strict";
|
|
2239
2771
|
|
|
2240
|
-
// Factory function for the purpose of node-based testing in modified global environments
|
|
2241
|
-
function factory(exports) {
|
|
2242
2772
|
|
|
2243
|
-
|
|
2244
|
-
|
|
2773
|
+
var utils = __webpack_require__(4867);
|
|
2774
|
+
var settle = __webpack_require__(6026);
|
|
2775
|
+
var cookies = __webpack_require__(4372);
|
|
2776
|
+
var buildURL = __webpack_require__(5327);
|
|
2777
|
+
var buildFullPath = __webpack_require__(4097);
|
|
2778
|
+
var parseHeaders = __webpack_require__(4109);
|
|
2779
|
+
var isURLSameOrigin = __webpack_require__(7985);
|
|
2780
|
+
var createError = __webpack_require__(5061);
|
|
2245
2781
|
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2782
|
+
module.exports = function xhrAdapter(config) {
|
|
2783
|
+
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
|
2784
|
+
var requestData = config.data;
|
|
2785
|
+
var requestHeaders = config.headers;
|
|
2249
2786
|
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
buf[pos + 1] = f8b[1];
|
|
2254
|
-
buf[pos + 2] = f8b[2];
|
|
2255
|
-
buf[pos + 3] = f8b[3];
|
|
2256
|
-
}
|
|
2787
|
+
if (utils.isFormData(requestData)) {
|
|
2788
|
+
delete requestHeaders['Content-Type']; // Let the browser set it
|
|
2789
|
+
}
|
|
2257
2790
|
|
|
2258
|
-
|
|
2259
|
-
f32[0] = val;
|
|
2260
|
-
buf[pos ] = f8b[3];
|
|
2261
|
-
buf[pos + 1] = f8b[2];
|
|
2262
|
-
buf[pos + 2] = f8b[1];
|
|
2263
|
-
buf[pos + 3] = f8b[0];
|
|
2264
|
-
}
|
|
2791
|
+
var request = new XMLHttpRequest();
|
|
2265
2792
|
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
f8b[0] = buf[pos ];
|
|
2273
|
-
f8b[1] = buf[pos + 1];
|
|
2274
|
-
f8b[2] = buf[pos + 2];
|
|
2275
|
-
f8b[3] = buf[pos + 3];
|
|
2276
|
-
return f32[0];
|
|
2277
|
-
}
|
|
2793
|
+
// HTTP basic authentication
|
|
2794
|
+
if (config.auth) {
|
|
2795
|
+
var username = config.auth.username || '';
|
|
2796
|
+
var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
|
|
2797
|
+
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
|
|
2798
|
+
}
|
|
2278
2799
|
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
f8b[2] = buf[pos + 1];
|
|
2282
|
-
f8b[1] = buf[pos + 2];
|
|
2283
|
-
f8b[0] = buf[pos + 3];
|
|
2284
|
-
return f32[0];
|
|
2285
|
-
}
|
|
2800
|
+
var fullPath = buildFullPath(config.baseURL, config.url);
|
|
2801
|
+
request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
|
|
2286
2802
|
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
/* istanbul ignore next */
|
|
2290
|
-
exports.readFloatBE = le ? readFloat_f32_rev : readFloat_f32_cpy;
|
|
2291
|
-
|
|
2292
|
-
// float: ieee754
|
|
2293
|
-
})(); else (function() {
|
|
2294
|
-
|
|
2295
|
-
function writeFloat_ieee754(writeUint, val, buf, pos) {
|
|
2296
|
-
var sign = val < 0 ? 1 : 0;
|
|
2297
|
-
if (sign)
|
|
2298
|
-
val = -val;
|
|
2299
|
-
if (val === 0)
|
|
2300
|
-
writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos);
|
|
2301
|
-
else if (isNaN(val))
|
|
2302
|
-
writeUint(2143289344, buf, pos);
|
|
2303
|
-
else if (val > 3.4028234663852886e+38) // +-Infinity
|
|
2304
|
-
writeUint((sign << 31 | 2139095040) >>> 0, buf, pos);
|
|
2305
|
-
else if (val < 1.1754943508222875e-38) // denormal
|
|
2306
|
-
writeUint((sign << 31 | Math.round(val / 1.401298464324817e-45)) >>> 0, buf, pos);
|
|
2307
|
-
else {
|
|
2308
|
-
var exponent = Math.floor(Math.log(val) / Math.LN2),
|
|
2309
|
-
mantissa = Math.round(val * Math.pow(2, -exponent) * 8388608) & 8388607;
|
|
2310
|
-
writeUint((sign << 31 | exponent + 127 << 23 | mantissa) >>> 0, buf, pos);
|
|
2311
|
-
}
|
|
2312
|
-
}
|
|
2313
|
-
|
|
2314
|
-
exports.writeFloatLE = writeFloat_ieee754.bind(null, writeUintLE);
|
|
2315
|
-
exports.writeFloatBE = writeFloat_ieee754.bind(null, writeUintBE);
|
|
2316
|
-
|
|
2317
|
-
function readFloat_ieee754(readUint, buf, pos) {
|
|
2318
|
-
var uint = readUint(buf, pos),
|
|
2319
|
-
sign = (uint >> 31) * 2 + 1,
|
|
2320
|
-
exponent = uint >>> 23 & 255,
|
|
2321
|
-
mantissa = uint & 8388607;
|
|
2322
|
-
return exponent === 255
|
|
2323
|
-
? mantissa
|
|
2324
|
-
? NaN
|
|
2325
|
-
: sign * Infinity
|
|
2326
|
-
: exponent === 0 // denormal
|
|
2327
|
-
? sign * 1.401298464324817e-45 * mantissa
|
|
2328
|
-
: sign * Math.pow(2, exponent - 150) * (mantissa + 8388608);
|
|
2329
|
-
}
|
|
2330
|
-
|
|
2331
|
-
exports.readFloatLE = readFloat_ieee754.bind(null, readUintLE);
|
|
2332
|
-
exports.readFloatBE = readFloat_ieee754.bind(null, readUintBE);
|
|
2333
|
-
|
|
2334
|
-
})();
|
|
2335
|
-
|
|
2336
|
-
// double: typed array
|
|
2337
|
-
if (typeof Float64Array !== "undefined") (function() {
|
|
2338
|
-
|
|
2339
|
-
var f64 = new Float64Array([-0]),
|
|
2340
|
-
f8b = new Uint8Array(f64.buffer),
|
|
2341
|
-
le = f8b[7] === 128;
|
|
2342
|
-
|
|
2343
|
-
function writeDouble_f64_cpy(val, buf, pos) {
|
|
2344
|
-
f64[0] = val;
|
|
2345
|
-
buf[pos ] = f8b[0];
|
|
2346
|
-
buf[pos + 1] = f8b[1];
|
|
2347
|
-
buf[pos + 2] = f8b[2];
|
|
2348
|
-
buf[pos + 3] = f8b[3];
|
|
2349
|
-
buf[pos + 4] = f8b[4];
|
|
2350
|
-
buf[pos + 5] = f8b[5];
|
|
2351
|
-
buf[pos + 6] = f8b[6];
|
|
2352
|
-
buf[pos + 7] = f8b[7];
|
|
2353
|
-
}
|
|
2354
|
-
|
|
2355
|
-
function writeDouble_f64_rev(val, buf, pos) {
|
|
2356
|
-
f64[0] = val;
|
|
2357
|
-
buf[pos ] = f8b[7];
|
|
2358
|
-
buf[pos + 1] = f8b[6];
|
|
2359
|
-
buf[pos + 2] = f8b[5];
|
|
2360
|
-
buf[pos + 3] = f8b[4];
|
|
2361
|
-
buf[pos + 4] = f8b[3];
|
|
2362
|
-
buf[pos + 5] = f8b[2];
|
|
2363
|
-
buf[pos + 6] = f8b[1];
|
|
2364
|
-
buf[pos + 7] = f8b[0];
|
|
2365
|
-
}
|
|
2366
|
-
|
|
2367
|
-
/* istanbul ignore next */
|
|
2368
|
-
exports.writeDoubleLE = le ? writeDouble_f64_cpy : writeDouble_f64_rev;
|
|
2369
|
-
/* istanbul ignore next */
|
|
2370
|
-
exports.writeDoubleBE = le ? writeDouble_f64_rev : writeDouble_f64_cpy;
|
|
2371
|
-
|
|
2372
|
-
function readDouble_f64_cpy(buf, pos) {
|
|
2373
|
-
f8b[0] = buf[pos ];
|
|
2374
|
-
f8b[1] = buf[pos + 1];
|
|
2375
|
-
f8b[2] = buf[pos + 2];
|
|
2376
|
-
f8b[3] = buf[pos + 3];
|
|
2377
|
-
f8b[4] = buf[pos + 4];
|
|
2378
|
-
f8b[5] = buf[pos + 5];
|
|
2379
|
-
f8b[6] = buf[pos + 6];
|
|
2380
|
-
f8b[7] = buf[pos + 7];
|
|
2381
|
-
return f64[0];
|
|
2382
|
-
}
|
|
2383
|
-
|
|
2384
|
-
function readDouble_f64_rev(buf, pos) {
|
|
2385
|
-
f8b[7] = buf[pos ];
|
|
2386
|
-
f8b[6] = buf[pos + 1];
|
|
2387
|
-
f8b[5] = buf[pos + 2];
|
|
2388
|
-
f8b[4] = buf[pos + 3];
|
|
2389
|
-
f8b[3] = buf[pos + 4];
|
|
2390
|
-
f8b[2] = buf[pos + 5];
|
|
2391
|
-
f8b[1] = buf[pos + 6];
|
|
2392
|
-
f8b[0] = buf[pos + 7];
|
|
2393
|
-
return f64[0];
|
|
2394
|
-
}
|
|
2395
|
-
|
|
2396
|
-
/* istanbul ignore next */
|
|
2397
|
-
exports.readDoubleLE = le ? readDouble_f64_cpy : readDouble_f64_rev;
|
|
2398
|
-
/* istanbul ignore next */
|
|
2399
|
-
exports.readDoubleBE = le ? readDouble_f64_rev : readDouble_f64_cpy;
|
|
2400
|
-
|
|
2401
|
-
// double: ieee754
|
|
2402
|
-
})(); else (function() {
|
|
2403
|
-
|
|
2404
|
-
function writeDouble_ieee754(writeUint, off0, off1, val, buf, pos) {
|
|
2405
|
-
var sign = val < 0 ? 1 : 0;
|
|
2406
|
-
if (sign)
|
|
2407
|
-
val = -val;
|
|
2408
|
-
if (val === 0) {
|
|
2409
|
-
writeUint(0, buf, pos + off0);
|
|
2410
|
-
writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos + off1);
|
|
2411
|
-
} else if (isNaN(val)) {
|
|
2412
|
-
writeUint(0, buf, pos + off0);
|
|
2413
|
-
writeUint(2146959360, buf, pos + off1);
|
|
2414
|
-
} else if (val > 1.7976931348623157e+308) { // +-Infinity
|
|
2415
|
-
writeUint(0, buf, pos + off0);
|
|
2416
|
-
writeUint((sign << 31 | 2146435072) >>> 0, buf, pos + off1);
|
|
2417
|
-
} else {
|
|
2418
|
-
var mantissa;
|
|
2419
|
-
if (val < 2.2250738585072014e-308) { // denormal
|
|
2420
|
-
mantissa = val / 5e-324;
|
|
2421
|
-
writeUint(mantissa >>> 0, buf, pos + off0);
|
|
2422
|
-
writeUint((sign << 31 | mantissa / 4294967296) >>> 0, buf, pos + off1);
|
|
2423
|
-
} else {
|
|
2424
|
-
var exponent = Math.floor(Math.log(val) / Math.LN2);
|
|
2425
|
-
if (exponent === 1024)
|
|
2426
|
-
exponent = 1023;
|
|
2427
|
-
mantissa = val * Math.pow(2, -exponent);
|
|
2428
|
-
writeUint(mantissa * 4503599627370496 >>> 0, buf, pos + off0);
|
|
2429
|
-
writeUint((sign << 31 | exponent + 1023 << 20 | mantissa * 1048576 & 1048575) >>> 0, buf, pos + off1);
|
|
2430
|
-
}
|
|
2431
|
-
}
|
|
2432
|
-
}
|
|
2433
|
-
|
|
2434
|
-
exports.writeDoubleLE = writeDouble_ieee754.bind(null, writeUintLE, 0, 4);
|
|
2435
|
-
exports.writeDoubleBE = writeDouble_ieee754.bind(null, writeUintBE, 4, 0);
|
|
2436
|
-
|
|
2437
|
-
function readDouble_ieee754(readUint, off0, off1, buf, pos) {
|
|
2438
|
-
var lo = readUint(buf, pos + off0),
|
|
2439
|
-
hi = readUint(buf, pos + off1);
|
|
2440
|
-
var sign = (hi >> 31) * 2 + 1,
|
|
2441
|
-
exponent = hi >>> 20 & 2047,
|
|
2442
|
-
mantissa = 4294967296 * (hi & 1048575) + lo;
|
|
2443
|
-
return exponent === 2047
|
|
2444
|
-
? mantissa
|
|
2445
|
-
? NaN
|
|
2446
|
-
: sign * Infinity
|
|
2447
|
-
: exponent === 0 // denormal
|
|
2448
|
-
? sign * 5e-324 * mantissa
|
|
2449
|
-
: sign * Math.pow(2, exponent - 1075) * (mantissa + 4503599627370496);
|
|
2450
|
-
}
|
|
2451
|
-
|
|
2452
|
-
exports.readDoubleLE = readDouble_ieee754.bind(null, readUintLE, 0, 4);
|
|
2453
|
-
exports.readDoubleBE = readDouble_ieee754.bind(null, readUintBE, 4, 0);
|
|
2454
|
-
|
|
2455
|
-
})();
|
|
2456
|
-
|
|
2457
|
-
return exports;
|
|
2458
|
-
}
|
|
2459
|
-
|
|
2460
|
-
// uint helpers
|
|
2461
|
-
|
|
2462
|
-
function writeUintLE(val, buf, pos) {
|
|
2463
|
-
buf[pos ] = val & 255;
|
|
2464
|
-
buf[pos + 1] = val >>> 8 & 255;
|
|
2465
|
-
buf[pos + 2] = val >>> 16 & 255;
|
|
2466
|
-
buf[pos + 3] = val >>> 24;
|
|
2467
|
-
}
|
|
2468
|
-
|
|
2469
|
-
function writeUintBE(val, buf, pos) {
|
|
2470
|
-
buf[pos ] = val >>> 24;
|
|
2471
|
-
buf[pos + 1] = val >>> 16 & 255;
|
|
2472
|
-
buf[pos + 2] = val >>> 8 & 255;
|
|
2473
|
-
buf[pos + 3] = val & 255;
|
|
2474
|
-
}
|
|
2475
|
-
|
|
2476
|
-
function readUintLE(buf, pos) {
|
|
2477
|
-
return (buf[pos ]
|
|
2478
|
-
| buf[pos + 1] << 8
|
|
2479
|
-
| buf[pos + 2] << 16
|
|
2480
|
-
| buf[pos + 3] << 24) >>> 0;
|
|
2481
|
-
}
|
|
2482
|
-
|
|
2483
|
-
function readUintBE(buf, pos) {
|
|
2484
|
-
return (buf[pos ] << 24
|
|
2485
|
-
| buf[pos + 1] << 16
|
|
2486
|
-
| buf[pos + 2] << 8
|
|
2487
|
-
| buf[pos + 3]) >>> 0;
|
|
2488
|
-
}
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
/***/ }),
|
|
2492
|
-
|
|
2493
|
-
/***/ 7199:
|
|
2494
|
-
/***/ ((module) => {
|
|
2495
|
-
|
|
2496
|
-
"use strict";
|
|
2497
|
-
|
|
2498
|
-
module.exports = inquire;
|
|
2499
|
-
|
|
2500
|
-
/**
|
|
2501
|
-
* Requires a module only if available.
|
|
2502
|
-
* @memberof util
|
|
2503
|
-
* @param {string} moduleName Module to require
|
|
2504
|
-
* @returns {?Object} Required module if available and not empty, otherwise `null`
|
|
2505
|
-
*/
|
|
2506
|
-
function inquire(moduleName) {
|
|
2507
|
-
try {
|
|
2508
|
-
var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
|
|
2509
|
-
if (mod && (mod.length || Object.keys(mod).length))
|
|
2510
|
-
return mod;
|
|
2511
|
-
} catch (e) {} // eslint-disable-line no-empty
|
|
2512
|
-
return null;
|
|
2513
|
-
}
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
/***/ }),
|
|
2517
|
-
|
|
2518
|
-
/***/ 8626:
|
|
2519
|
-
/***/ ((__unused_webpack_module, exports) => {
|
|
2520
|
-
|
|
2521
|
-
"use strict";
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
/**
|
|
2525
|
-
* A minimal path module to resolve Unix, Windows and URL paths alike.
|
|
2526
|
-
* @memberof util
|
|
2527
|
-
* @namespace
|
|
2528
|
-
*/
|
|
2529
|
-
var path = exports;
|
|
2530
|
-
|
|
2531
|
-
var isAbsolute =
|
|
2532
|
-
/**
|
|
2533
|
-
* Tests if the specified path is absolute.
|
|
2534
|
-
* @param {string} path Path to test
|
|
2535
|
-
* @returns {boolean} `true` if path is absolute
|
|
2536
|
-
*/
|
|
2537
|
-
path.isAbsolute = function isAbsolute(path) {
|
|
2538
|
-
return /^(?:\/|\w+:)/.test(path);
|
|
2539
|
-
};
|
|
2540
|
-
|
|
2541
|
-
var normalize =
|
|
2542
|
-
/**
|
|
2543
|
-
* Normalizes the specified path.
|
|
2544
|
-
* @param {string} path Path to normalize
|
|
2545
|
-
* @returns {string} Normalized path
|
|
2546
|
-
*/
|
|
2547
|
-
path.normalize = function normalize(path) {
|
|
2548
|
-
path = path.replace(/\\/g, "/")
|
|
2549
|
-
.replace(/\/{2,}/g, "/");
|
|
2550
|
-
var parts = path.split("/"),
|
|
2551
|
-
absolute = isAbsolute(path),
|
|
2552
|
-
prefix = "";
|
|
2553
|
-
if (absolute)
|
|
2554
|
-
prefix = parts.shift() + "/";
|
|
2555
|
-
for (var i = 0; i < parts.length;) {
|
|
2556
|
-
if (parts[i] === "..") {
|
|
2557
|
-
if (i > 0 && parts[i - 1] !== "..")
|
|
2558
|
-
parts.splice(--i, 2);
|
|
2559
|
-
else if (absolute)
|
|
2560
|
-
parts.splice(i, 1);
|
|
2561
|
-
else
|
|
2562
|
-
++i;
|
|
2563
|
-
} else if (parts[i] === ".")
|
|
2564
|
-
parts.splice(i, 1);
|
|
2565
|
-
else
|
|
2566
|
-
++i;
|
|
2567
|
-
}
|
|
2568
|
-
return prefix + parts.join("/");
|
|
2569
|
-
};
|
|
2570
|
-
|
|
2571
|
-
/**
|
|
2572
|
-
* Resolves the specified include path against the specified origin path.
|
|
2573
|
-
* @param {string} originPath Path to the origin file
|
|
2574
|
-
* @param {string} includePath Include path relative to origin path
|
|
2575
|
-
* @param {boolean} [alreadyNormalized=false] `true` if both paths are already known to be normalized
|
|
2576
|
-
* @returns {string} Path to the include file
|
|
2577
|
-
*/
|
|
2578
|
-
path.resolve = function resolve(originPath, includePath, alreadyNormalized) {
|
|
2579
|
-
if (!alreadyNormalized)
|
|
2580
|
-
includePath = normalize(includePath);
|
|
2581
|
-
if (isAbsolute(includePath))
|
|
2582
|
-
return includePath;
|
|
2583
|
-
if (!alreadyNormalized)
|
|
2584
|
-
originPath = normalize(originPath);
|
|
2585
|
-
return (originPath = originPath.replace(/(?:\/|^)[^/]+$/, "")).length ? normalize(originPath + "/" + includePath) : includePath;
|
|
2586
|
-
};
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
/***/ }),
|
|
2590
|
-
|
|
2591
|
-
/***/ 6662:
|
|
2592
|
-
/***/ ((module) => {
|
|
2593
|
-
|
|
2594
|
-
"use strict";
|
|
2595
|
-
|
|
2596
|
-
module.exports = pool;
|
|
2597
|
-
|
|
2598
|
-
/**
|
|
2599
|
-
* An allocator as used by {@link util.pool}.
|
|
2600
|
-
* @typedef PoolAllocator
|
|
2601
|
-
* @type {function}
|
|
2602
|
-
* @param {number} size Buffer size
|
|
2603
|
-
* @returns {Uint8Array} Buffer
|
|
2604
|
-
*/
|
|
2605
|
-
|
|
2606
|
-
/**
|
|
2607
|
-
* A slicer as used by {@link util.pool}.
|
|
2608
|
-
* @typedef PoolSlicer
|
|
2609
|
-
* @type {function}
|
|
2610
|
-
* @param {number} start Start offset
|
|
2611
|
-
* @param {number} end End offset
|
|
2612
|
-
* @returns {Uint8Array} Buffer slice
|
|
2613
|
-
* @this {Uint8Array}
|
|
2614
|
-
*/
|
|
2615
|
-
|
|
2616
|
-
/**
|
|
2617
|
-
* A general purpose buffer pool.
|
|
2618
|
-
* @memberof util
|
|
2619
|
-
* @function
|
|
2620
|
-
* @param {PoolAllocator} alloc Allocator
|
|
2621
|
-
* @param {PoolSlicer} slice Slicer
|
|
2622
|
-
* @param {number} [size=8192] Slab size
|
|
2623
|
-
* @returns {PoolAllocator} Pooled allocator
|
|
2624
|
-
*/
|
|
2625
|
-
function pool(alloc, slice, size) {
|
|
2626
|
-
var SIZE = size || 8192;
|
|
2627
|
-
var MAX = SIZE >>> 1;
|
|
2628
|
-
var slab = null;
|
|
2629
|
-
var offset = SIZE;
|
|
2630
|
-
return function pool_alloc(size) {
|
|
2631
|
-
if (size < 1 || size > MAX)
|
|
2632
|
-
return alloc(size);
|
|
2633
|
-
if (offset + size > SIZE) {
|
|
2634
|
-
slab = alloc(SIZE);
|
|
2635
|
-
offset = 0;
|
|
2636
|
-
}
|
|
2637
|
-
var buf = slice.call(slab, offset, offset += size);
|
|
2638
|
-
if (offset & 7) // align to 32 bit
|
|
2639
|
-
offset = (offset | 7) + 1;
|
|
2640
|
-
return buf;
|
|
2641
|
-
};
|
|
2642
|
-
}
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
/***/ }),
|
|
2646
|
-
|
|
2647
|
-
/***/ 4997:
|
|
2648
|
-
/***/ ((__unused_webpack_module, exports) => {
|
|
2649
|
-
|
|
2650
|
-
"use strict";
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
/**
|
|
2654
|
-
* A minimal UTF8 implementation for number arrays.
|
|
2655
|
-
* @memberof util
|
|
2656
|
-
* @namespace
|
|
2657
|
-
*/
|
|
2658
|
-
var utf8 = exports;
|
|
2659
|
-
|
|
2660
|
-
/**
|
|
2661
|
-
* Calculates the UTF8 byte length of a string.
|
|
2662
|
-
* @param {string} string String
|
|
2663
|
-
* @returns {number} Byte length
|
|
2664
|
-
*/
|
|
2665
|
-
utf8.length = function utf8_length(string) {
|
|
2666
|
-
var len = 0,
|
|
2667
|
-
c = 0;
|
|
2668
|
-
for (var i = 0; i < string.length; ++i) {
|
|
2669
|
-
c = string.charCodeAt(i);
|
|
2670
|
-
if (c < 128)
|
|
2671
|
-
len += 1;
|
|
2672
|
-
else if (c < 2048)
|
|
2673
|
-
len += 2;
|
|
2674
|
-
else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
|
|
2675
|
-
++i;
|
|
2676
|
-
len += 4;
|
|
2677
|
-
} else
|
|
2678
|
-
len += 3;
|
|
2679
|
-
}
|
|
2680
|
-
return len;
|
|
2681
|
-
};
|
|
2682
|
-
|
|
2683
|
-
/**
|
|
2684
|
-
* Reads UTF8 bytes as a string.
|
|
2685
|
-
* @param {Uint8Array} buffer Source buffer
|
|
2686
|
-
* @param {number} start Source start
|
|
2687
|
-
* @param {number} end Source end
|
|
2688
|
-
* @returns {string} String read
|
|
2689
|
-
*/
|
|
2690
|
-
utf8.read = function utf8_read(buffer, start, end) {
|
|
2691
|
-
var len = end - start;
|
|
2692
|
-
if (len < 1)
|
|
2693
|
-
return "";
|
|
2694
|
-
var parts = null,
|
|
2695
|
-
chunk = [],
|
|
2696
|
-
i = 0, // char offset
|
|
2697
|
-
t; // temporary
|
|
2698
|
-
while (start < end) {
|
|
2699
|
-
t = buffer[start++];
|
|
2700
|
-
if (t < 128)
|
|
2701
|
-
chunk[i++] = t;
|
|
2702
|
-
else if (t > 191 && t < 224)
|
|
2703
|
-
chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
|
|
2704
|
-
else if (t > 239 && t < 365) {
|
|
2705
|
-
t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;
|
|
2706
|
-
chunk[i++] = 0xD800 + (t >> 10);
|
|
2707
|
-
chunk[i++] = 0xDC00 + (t & 1023);
|
|
2708
|
-
} else
|
|
2709
|
-
chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
|
|
2710
|
-
if (i > 8191) {
|
|
2711
|
-
(parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
|
|
2712
|
-
i = 0;
|
|
2713
|
-
}
|
|
2714
|
-
}
|
|
2715
|
-
if (parts) {
|
|
2716
|
-
if (i)
|
|
2717
|
-
parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
|
|
2718
|
-
return parts.join("");
|
|
2719
|
-
}
|
|
2720
|
-
return String.fromCharCode.apply(String, chunk.slice(0, i));
|
|
2721
|
-
};
|
|
2722
|
-
|
|
2723
|
-
/**
|
|
2724
|
-
* Writes a string as UTF8 bytes.
|
|
2725
|
-
* @param {string} string Source string
|
|
2726
|
-
* @param {Uint8Array} buffer Destination buffer
|
|
2727
|
-
* @param {number} offset Destination offset
|
|
2728
|
-
* @returns {number} Bytes written
|
|
2729
|
-
*/
|
|
2730
|
-
utf8.write = function utf8_write(string, buffer, offset) {
|
|
2731
|
-
var start = offset,
|
|
2732
|
-
c1, // character 1
|
|
2733
|
-
c2; // character 2
|
|
2734
|
-
for (var i = 0; i < string.length; ++i) {
|
|
2735
|
-
c1 = string.charCodeAt(i);
|
|
2736
|
-
if (c1 < 128) {
|
|
2737
|
-
buffer[offset++] = c1;
|
|
2738
|
-
} else if (c1 < 2048) {
|
|
2739
|
-
buffer[offset++] = c1 >> 6 | 192;
|
|
2740
|
-
buffer[offset++] = c1 & 63 | 128;
|
|
2741
|
-
} else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
|
|
2742
|
-
c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
|
|
2743
|
-
++i;
|
|
2744
|
-
buffer[offset++] = c1 >> 18 | 240;
|
|
2745
|
-
buffer[offset++] = c1 >> 12 & 63 | 128;
|
|
2746
|
-
buffer[offset++] = c1 >> 6 & 63 | 128;
|
|
2747
|
-
buffer[offset++] = c1 & 63 | 128;
|
|
2748
|
-
} else {
|
|
2749
|
-
buffer[offset++] = c1 >> 12 | 224;
|
|
2750
|
-
buffer[offset++] = c1 >> 6 & 63 | 128;
|
|
2751
|
-
buffer[offset++] = c1 & 63 | 128;
|
|
2752
|
-
}
|
|
2753
|
-
}
|
|
2754
|
-
return offset - start;
|
|
2755
|
-
};
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
/***/ }),
|
|
2759
|
-
|
|
2760
|
-
/***/ 9669:
|
|
2761
|
-
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
2762
|
-
|
|
2763
|
-
module.exports = __webpack_require__(1609);
|
|
2764
|
-
|
|
2765
|
-
/***/ }),
|
|
2766
|
-
|
|
2767
|
-
/***/ 5448:
|
|
2768
|
-
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
2769
|
-
|
|
2770
|
-
"use strict";
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
var utils = __webpack_require__(4867);
|
|
2774
|
-
var settle = __webpack_require__(6026);
|
|
2775
|
-
var cookies = __webpack_require__(4372);
|
|
2776
|
-
var buildURL = __webpack_require__(5327);
|
|
2777
|
-
var buildFullPath = __webpack_require__(4097);
|
|
2778
|
-
var parseHeaders = __webpack_require__(4109);
|
|
2779
|
-
var isURLSameOrigin = __webpack_require__(7985);
|
|
2780
|
-
var createError = __webpack_require__(5061);
|
|
2781
|
-
|
|
2782
|
-
module.exports = function xhrAdapter(config) {
|
|
2783
|
-
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
|
2784
|
-
var requestData = config.data;
|
|
2785
|
-
var requestHeaders = config.headers;
|
|
2786
|
-
|
|
2787
|
-
if (utils.isFormData(requestData)) {
|
|
2788
|
-
delete requestHeaders['Content-Type']; // Let the browser set it
|
|
2789
|
-
}
|
|
2790
|
-
|
|
2791
|
-
var request = new XMLHttpRequest();
|
|
2792
|
-
|
|
2793
|
-
// HTTP basic authentication
|
|
2794
|
-
if (config.auth) {
|
|
2795
|
-
var username = config.auth.username || '';
|
|
2796
|
-
var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
|
|
2797
|
-
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
|
|
2798
|
-
}
|
|
2799
|
-
|
|
2800
|
-
var fullPath = buildFullPath(config.baseURL, config.url);
|
|
2801
|
-
request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
|
|
2802
|
-
|
|
2803
|
-
// Set the request timeout in MS
|
|
2804
|
-
request.timeout = config.timeout;
|
|
2803
|
+
// Set the request timeout in MS
|
|
2804
|
+
request.timeout = config.timeout;
|
|
2805
2805
|
|
|
2806
2806
|
// Listen for ready state
|
|
2807
2807
|
request.onreadystatechange = function handleLoad() {
|
|
@@ -11372,303 +11372,303 @@ BufferWriter._configure();
|
|
|
11372
11372
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
11373
11373
|
|
|
11374
11374
|
"use strict";
|
|
11375
|
-
|
|
11376
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
11377
|
-
exports.Contract = void 0;
|
|
11378
|
-
const Serializer_1 = __webpack_require__(7187);
|
|
11379
|
-
const utils_1 = __webpack_require__(8593);
|
|
11380
|
-
/**
|
|
11381
|
-
* The contract class contains the contract ID and contract entries
|
|
11382
|
-
* definition needed to encode/decode operations during the
|
|
11383
|
-
* interaction with the user and the communication with the RPC node.
|
|
11384
|
-
*
|
|
11385
|
-
* @example
|
|
11386
|
-
*
|
|
11387
|
-
* ```ts
|
|
11388
|
-
* const { Contract, Provider, Signer, utils } = require("koilib");
|
|
11389
|
-
* const rpcNodes = ["http://api.koinos.io:8080"];
|
|
11390
|
-
* const privateKey = "f186a5de49797bfd52dc42505c33d75a46822ed5b60046e09d7c336242e20200";
|
|
11391
|
-
* const provider = new Provider(rpcNodes);
|
|
11392
|
-
* const signer = new Signer({ privateKey, provider });
|
|
11393
|
-
* const koinContract = new Contract({
|
|
11394
|
-
* id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
|
|
11395
|
-
* abi: utils.Krc20Abi,
|
|
11396
|
-
* provider,
|
|
11397
|
-
* signer,
|
|
11398
|
-
* });
|
|
11399
|
-
* const koin = koinContract.functions;
|
|
11400
|
-
*
|
|
11401
|
-
* // optional: preformat input/output
|
|
11402
|
-
* koinContract.abi.methods.balanceOf.preformatInput = (owner) =>
|
|
11403
|
-
* ({ owner });
|
|
11404
|
-
* koinContract.abi.methods.balanceOf.preformatOutput = (res) =>
|
|
11405
|
-
* utils.formatUnits(res.value, 8);
|
|
11406
|
-
* koinContract.abi.methods.transfer.preformatInput = (input) => ({
|
|
11407
|
-
* from: signer.getAddress(),
|
|
11408
|
-
* to: input.to,
|
|
11409
|
-
* value: utils.parseUnits(input.value, 8),
|
|
11410
|
-
* });
|
|
11411
|
-
*
|
|
11412
|
-
* async funtion main() {
|
|
11413
|
-
* // Get balance
|
|
11414
|
-
* const { result } = await koin.balanceOf("12fN2CQnuJM8cMnWZ1hPtM4knjLME8E4PD");
|
|
11415
|
-
* console.log(result)
|
|
11416
|
-
*
|
|
11417
|
-
* // Transfer
|
|
11418
|
-
* const { transaction, transactionResponse } = await koin.transfer({
|
|
11419
|
-
* to: "172AB1FgCsYrRAW5cwQ8KjadgxofvgPFd6",
|
|
11420
|
-
* value: "10.0001",
|
|
11421
|
-
* });
|
|
11422
|
-
* console.log(`Transaction id ${transaction.id} submitted`);
|
|
11423
|
-
*
|
|
11424
|
-
* // wait to be mined
|
|
11425
|
-
* const blockId = await transactionResponse.wait();
|
|
11426
|
-
* console.log(`Transaction mined. Block id: ${blockId}`);
|
|
11427
|
-
* }
|
|
11428
|
-
*
|
|
11429
|
-
* main();
|
|
11430
|
-
* ```
|
|
11431
|
-
*/
|
|
11432
|
-
class Contract {
|
|
11433
|
-
constructor(c) {
|
|
11434
|
-
var _a;
|
|
11435
|
-
if (c.id)
|
|
11436
|
-
this.id = utils_1.decodeBase58(c.id);
|
|
11437
|
-
this.signer = c.signer;
|
|
11438
|
-
this.provider = c.provider || ((_a = c.signer) === null || _a === void 0 ? void 0 : _a.provider);
|
|
11439
|
-
this.abi = c.abi;
|
|
11440
|
-
this.bytecode = c.bytecode;
|
|
11441
|
-
if (c.serializer) {
|
|
11442
|
-
this.serializer = c.serializer;
|
|
11443
|
-
}
|
|
11444
|
-
else if (c.abi && c.abi.types) {
|
|
11445
|
-
this.serializer = new Serializer_1.Serializer(c.abi.types);
|
|
11446
|
-
}
|
|
11447
|
-
this.options = {
|
|
11448
|
-
rc_limit: 1e8,
|
|
11449
|
-
sendTransaction: true,
|
|
11450
|
-
sendAbis: true,
|
|
11451
|
-
...c.options,
|
|
11452
|
-
};
|
|
11453
|
-
this.functions = {};
|
|
11454
|
-
if (this.signer &&
|
|
11455
|
-
this.provider &&
|
|
11456
|
-
this.abi &&
|
|
11457
|
-
this.abi.methods &&
|
|
11458
|
-
this.serializer) {
|
|
11459
|
-
Object.keys(this.abi.methods).forEach((name) => {
|
|
11460
|
-
this.functions[name] = async (argu = {}, options) => {
|
|
11461
|
-
if (!this.provider)
|
|
11462
|
-
throw new Error("provider not found");
|
|
11463
|
-
if (!this.abi || !this.abi.methods)
|
|
11464
|
-
throw new Error("Methods are not defined");
|
|
11465
|
-
if (!this.abi.methods[name])
|
|
11466
|
-
throw new Error(`Method ${name} not defined in the ABI`);
|
|
11467
|
-
const opts = {
|
|
11468
|
-
...this.options,
|
|
11469
|
-
...options,
|
|
11470
|
-
};
|
|
11471
|
-
const { readOnly, output, defaultOutput, preformatInput, preformatOutput, } = this.abi.methods[name];
|
|
11472
|
-
let args;
|
|
11473
|
-
if (typeof preformatInput === "function") {
|
|
11474
|
-
args = preformatInput(argu);
|
|
11475
|
-
}
|
|
11476
|
-
else {
|
|
11477
|
-
args = argu;
|
|
11478
|
-
}
|
|
11479
|
-
const operation = await this.encodeOperation({ name, args });
|
|
11480
|
-
if (readOnly) {
|
|
11481
|
-
if (!output)
|
|
11482
|
-
throw new Error(`No output defined for ${name}`);
|
|
11483
|
-
// read contract
|
|
11484
|
-
const { result: resultEncoded } = await this.provider.readContract({
|
|
11485
|
-
contract_id: utils_1.encodeBase58(operation.call_contract.contract_id),
|
|
11486
|
-
entry_point: operation.call_contract.entry_point,
|
|
11487
|
-
args: utils_1.encodeBase64(operation.call_contract.args),
|
|
11488
|
-
});
|
|
11489
|
-
let result = defaultOutput;
|
|
11490
|
-
if (resultEncoded) {
|
|
11491
|
-
result = await this.serializer.deserialize(resultEncoded, output);
|
|
11492
|
-
}
|
|
11493
|
-
if (typeof preformatOutput === "function") {
|
|
11494
|
-
result = preformatOutput(result);
|
|
11495
|
-
}
|
|
11496
|
-
return { operation, result };
|
|
11497
|
-
}
|
|
11498
|
-
// return operation if send is false
|
|
11499
|
-
if (!(opts === null || opts === void 0 ? void 0 : opts.sendTransaction))
|
|
11500
|
-
return { operation };
|
|
11501
|
-
// write contract (sign and send)
|
|
11502
|
-
if (!this.signer)
|
|
11503
|
-
throw new Error("signer not found");
|
|
11504
|
-
const transaction = await this.signer.encodeTransaction({
|
|
11505
|
-
...opts,
|
|
11506
|
-
operations: [operation],
|
|
11507
|
-
});
|
|
11508
|
-
const abis = {};
|
|
11509
|
-
if (opts === null || opts === void 0 ? void 0 : opts.sendAbis) {
|
|
11510
|
-
const contractId = utils_1.encodeBase58(this.id);
|
|
11511
|
-
abis[contractId] = this.abi;
|
|
11512
|
-
}
|
|
11513
|
-
const transactionResponse = await this.signer.sendTransaction(transaction, abis);
|
|
11514
|
-
return { operation, transaction, transactionResponse };
|
|
11515
|
-
};
|
|
11516
|
-
});
|
|
11517
|
-
}
|
|
11518
|
-
}
|
|
11519
|
-
/**
|
|
11520
|
-
* Compute contract Id
|
|
11521
|
-
*/
|
|
11522
|
-
static computeContractId(address) {
|
|
11523
|
-
return utils_1.decodeBase58(address);
|
|
11524
|
-
}
|
|
11525
|
-
/**
|
|
11526
|
-
* Get contract Id
|
|
11527
|
-
*/
|
|
11528
|
-
getId() {
|
|
11529
|
-
if (!this.id)
|
|
11530
|
-
throw new Error("id is not defined");
|
|
11531
|
-
return utils_1.encodeBase58(this.id);
|
|
11532
|
-
}
|
|
11533
|
-
/**
|
|
11534
|
-
* Function to deploy a new smart contract.
|
|
11535
|
-
* The Bytecode must be defined in the constructor of the class
|
|
11536
|
-
* @example
|
|
11537
|
-
* ```ts
|
|
11538
|
-
* const privateKey = "f186a5de49797bfd52dc42505c33d75a46822ed5b60046e09d7c336242e20200";
|
|
11539
|
-
* const provider = new Provider(["http://api.koinos.io:8080"]);
|
|
11540
|
-
* const signer = new Signer({ privateKey, provider });
|
|
11541
|
-
* const bytecode = new Uint8Array([1, 2, 3, 4]);
|
|
11542
|
-
* const contract = new Contract({ signer, provider, bytecode });
|
|
11543
|
-
* const { transactionResponse } = await contract.deploy();
|
|
11544
|
-
* // wait to be mined
|
|
11545
|
-
* const blockId = await transactionResponse.wait();
|
|
11546
|
-
* console.log(`Contract uploaded in block id ${blockId}`);
|
|
11547
|
-
* ```
|
|
11548
|
-
*/
|
|
11549
|
-
async deploy(options) {
|
|
11550
|
-
if (!this.signer)
|
|
11551
|
-
throw new Error("signer not found");
|
|
11552
|
-
if (!this.bytecode)
|
|
11553
|
-
throw new Error("bytecode not found");
|
|
11554
|
-
const opts = {
|
|
11555
|
-
...this.options,
|
|
11556
|
-
...options,
|
|
11557
|
-
};
|
|
11558
|
-
const operation = {
|
|
11559
|
-
upload_contract: {
|
|
11560
|
-
contract_id: Contract.computeContractId(this.signer.getAddress()),
|
|
11561
|
-
bytecode: this.bytecode,
|
|
11562
|
-
},
|
|
11563
|
-
};
|
|
11564
|
-
// return operation if send is false
|
|
11565
|
-
if (!(opts === null || opts === void 0 ? void 0 : opts.sendTransaction))
|
|
11566
|
-
return { operation };
|
|
11567
|
-
const transaction = await this.signer.encodeTransaction({
|
|
11568
|
-
...opts,
|
|
11569
|
-
operations: [operation],
|
|
11570
|
-
});
|
|
11571
|
-
const transactionResponse = await this.signer.sendTransaction(transaction);
|
|
11572
|
-
return { operation, transaction, transactionResponse };
|
|
11573
|
-
}
|
|
11574
|
-
/**
|
|
11575
|
-
* Encondes a contract operation using Koinos serialization
|
|
11576
|
-
* and taking the contract entries as reference to build it
|
|
11577
|
-
* @param op - Operation to encode
|
|
11578
|
-
* @returns Operation encoded
|
|
11579
|
-
* @example
|
|
11580
|
-
* ```ts
|
|
11581
|
-
* const opEncoded = contract.encodeOperation({
|
|
11582
|
-
* name: "transfer",
|
|
11583
|
-
* args: {
|
|
11584
|
-
* from: "12fN2CQnuJM8cMnWZ1hPtM4knjLME8E4PD",
|
|
11585
|
-
* to: "172AB1FgCsYrRAW5cwQ8KjadgxofvgPFd6",
|
|
11586
|
-
* value: "1000",
|
|
11587
|
-
* }
|
|
11588
|
-
* });
|
|
11589
|
-
*
|
|
11590
|
-
* console.log(opEncoded);
|
|
11591
|
-
* // {
|
|
11592
|
-
* // call_contract: {
|
|
11593
|
-
* // contract_id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
|
|
11594
|
-
* // entry_point: 0x62efa292,
|
|
11595
|
-
* // args: "MBWFsaWNlA2JvYgAAAAAAAAPo",
|
|
11596
|
-
* // }
|
|
11597
|
-
* // }
|
|
11598
|
-
* ```
|
|
11599
|
-
*/
|
|
11600
|
-
async encodeOperation(op) {
|
|
11601
|
-
if (!this.abi || !this.abi.methods || !this.abi.methods[op.name])
|
|
11602
|
-
throw new Error(`Operation ${op.name} unknown`);
|
|
11603
|
-
if (!this.serializer)
|
|
11604
|
-
throw new Error("Serializer is not defined");
|
|
11605
|
-
if (!this.id)
|
|
11606
|
-
throw new Error("Contract id is not defined");
|
|
11607
|
-
const method = this.abi.methods[op.name];
|
|
11608
|
-
let bufferInputs = new Uint8Array(0);
|
|
11609
|
-
if (method.input) {
|
|
11610
|
-
if (!op.args)
|
|
11611
|
-
throw new Error(`No arguments defined for type '${method.input}'`);
|
|
11612
|
-
bufferInputs = await this.serializer.serialize(op.args, method.input);
|
|
11613
|
-
}
|
|
11614
|
-
return {
|
|
11615
|
-
call_contract: {
|
|
11616
|
-
contract_id: this.id,
|
|
11617
|
-
entry_point: method.entryPoint,
|
|
11618
|
-
args: bufferInputs,
|
|
11619
|
-
},
|
|
11620
|
-
};
|
|
11621
|
-
}
|
|
11622
|
-
/**
|
|
11623
|
-
* Decodes a contract operation to be human readable
|
|
11624
|
-
* @example
|
|
11625
|
-
* ```ts
|
|
11626
|
-
* const opDecoded = contract.decodeOperation({
|
|
11627
|
-
* call_contract: {
|
|
11628
|
-
* contract_id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
|
|
11629
|
-
* entry_point: 0x62efa292,
|
|
11630
|
-
* args: "MBWFsaWNlA2JvYgAAAAAAAAPo",
|
|
11631
|
-
* }
|
|
11632
|
-
* });
|
|
11633
|
-
* console.log(opDecoded);
|
|
11634
|
-
* // {
|
|
11635
|
-
* // name: "transfer",
|
|
11636
|
-
* // args: {
|
|
11637
|
-
* // from: "12fN2CQnuJM8cMnWZ1hPtM4knjLME8E4PD",
|
|
11638
|
-
* // to: "172AB1FgCsYrRAW5cwQ8KjadgxofvgPFd6",
|
|
11639
|
-
* // value: "1000",
|
|
11640
|
-
* // },
|
|
11641
|
-
* // }
|
|
11642
|
-
* ```
|
|
11643
|
-
*/
|
|
11644
|
-
async decodeOperation(op) {
|
|
11645
|
-
if (!this.id)
|
|
11646
|
-
throw new Error("Contract id is not defined");
|
|
11647
|
-
if (!this.abi || !this.abi.methods)
|
|
11648
|
-
throw new Error("Methods are not defined");
|
|
11649
|
-
if (!this.serializer)
|
|
11650
|
-
throw new Error("Serializer is not defined");
|
|
11651
|
-
if (!op.call_contract)
|
|
11652
|
-
throw new Error("Operation is not CallContractOperation");
|
|
11653
|
-
if (op.call_contract.contract_id !== this.id)
|
|
11654
|
-
throw new Error(`Invalid contract id. Expected: ${utils_1.encodeBase58(this.id)}. Received: ${utils_1.encodeBase58(op.call_contract.contract_id)}`);
|
|
11655
|
-
for (let i = 0; i < Object.keys(this.abi.methods).length; i += 1) {
|
|
11656
|
-
const opName = Object.keys(this.abi.methods)[i];
|
|
11657
|
-
const method = this.abi.methods[opName];
|
|
11658
|
-
if (op.call_contract.entry_point === method.entryPoint) {
|
|
11659
|
-
if (!method.input)
|
|
11660
|
-
return { name: opName };
|
|
11661
|
-
return {
|
|
11662
|
-
name: opName,
|
|
11663
|
-
args: await this.serializer.deserialize(op.call_contract.args, method.input),
|
|
11664
|
-
};
|
|
11665
|
-
}
|
|
11666
|
-
}
|
|
11667
|
-
throw new Error(`Unknown method id ${op.call_contract.entry_point}`);
|
|
11668
|
-
}
|
|
11669
|
-
}
|
|
11670
|
-
exports.Contract = Contract;
|
|
11671
|
-
exports.default = Contract;
|
|
11375
|
+
|
|
11376
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
11377
|
+
exports.Contract = void 0;
|
|
11378
|
+
const Serializer_1 = __webpack_require__(7187);
|
|
11379
|
+
const utils_1 = __webpack_require__(8593);
|
|
11380
|
+
/**
|
|
11381
|
+
* The contract class contains the contract ID and contract entries
|
|
11382
|
+
* definition needed to encode/decode operations during the
|
|
11383
|
+
* interaction with the user and the communication with the RPC node.
|
|
11384
|
+
*
|
|
11385
|
+
* @example
|
|
11386
|
+
*
|
|
11387
|
+
* ```ts
|
|
11388
|
+
* const { Contract, Provider, Signer, utils } = require("koilib");
|
|
11389
|
+
* const rpcNodes = ["http://api.koinos.io:8080"];
|
|
11390
|
+
* const privateKey = "f186a5de49797bfd52dc42505c33d75a46822ed5b60046e09d7c336242e20200";
|
|
11391
|
+
* const provider = new Provider(rpcNodes);
|
|
11392
|
+
* const signer = new Signer({ privateKey, provider });
|
|
11393
|
+
* const koinContract = new Contract({
|
|
11394
|
+
* id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
|
|
11395
|
+
* abi: utils.Krc20Abi,
|
|
11396
|
+
* provider,
|
|
11397
|
+
* signer,
|
|
11398
|
+
* });
|
|
11399
|
+
* const koin = koinContract.functions;
|
|
11400
|
+
*
|
|
11401
|
+
* // optional: preformat input/output
|
|
11402
|
+
* koinContract.abi.methods.balanceOf.preformatInput = (owner) =>
|
|
11403
|
+
* ({ owner });
|
|
11404
|
+
* koinContract.abi.methods.balanceOf.preformatOutput = (res) =>
|
|
11405
|
+
* utils.formatUnits(res.value, 8);
|
|
11406
|
+
* koinContract.abi.methods.transfer.preformatInput = (input) => ({
|
|
11407
|
+
* from: signer.getAddress(),
|
|
11408
|
+
* to: input.to,
|
|
11409
|
+
* value: utils.parseUnits(input.value, 8),
|
|
11410
|
+
* });
|
|
11411
|
+
*
|
|
11412
|
+
* async funtion main() {
|
|
11413
|
+
* // Get balance
|
|
11414
|
+
* const { result } = await koin.balanceOf("12fN2CQnuJM8cMnWZ1hPtM4knjLME8E4PD");
|
|
11415
|
+
* console.log(result)
|
|
11416
|
+
*
|
|
11417
|
+
* // Transfer
|
|
11418
|
+
* const { transaction, transactionResponse } = await koin.transfer({
|
|
11419
|
+
* to: "172AB1FgCsYrRAW5cwQ8KjadgxofvgPFd6",
|
|
11420
|
+
* value: "10.0001",
|
|
11421
|
+
* });
|
|
11422
|
+
* console.log(`Transaction id ${transaction.id} submitted`);
|
|
11423
|
+
*
|
|
11424
|
+
* // wait to be mined
|
|
11425
|
+
* const blockId = await transactionResponse.wait();
|
|
11426
|
+
* console.log(`Transaction mined. Block id: ${blockId}`);
|
|
11427
|
+
* }
|
|
11428
|
+
*
|
|
11429
|
+
* main();
|
|
11430
|
+
* ```
|
|
11431
|
+
*/
|
|
11432
|
+
class Contract {
|
|
11433
|
+
constructor(c) {
|
|
11434
|
+
var _a;
|
|
11435
|
+
if (c.id)
|
|
11436
|
+
this.id = utils_1.decodeBase58(c.id);
|
|
11437
|
+
this.signer = c.signer;
|
|
11438
|
+
this.provider = c.provider || ((_a = c.signer) === null || _a === void 0 ? void 0 : _a.provider);
|
|
11439
|
+
this.abi = c.abi;
|
|
11440
|
+
this.bytecode = c.bytecode;
|
|
11441
|
+
if (c.serializer) {
|
|
11442
|
+
this.serializer = c.serializer;
|
|
11443
|
+
}
|
|
11444
|
+
else if (c.abi && c.abi.types) {
|
|
11445
|
+
this.serializer = new Serializer_1.Serializer(c.abi.types);
|
|
11446
|
+
}
|
|
11447
|
+
this.options = {
|
|
11448
|
+
rc_limit: 1e8,
|
|
11449
|
+
sendTransaction: true,
|
|
11450
|
+
sendAbis: true,
|
|
11451
|
+
...c.options,
|
|
11452
|
+
};
|
|
11453
|
+
this.functions = {};
|
|
11454
|
+
if (this.signer &&
|
|
11455
|
+
this.provider &&
|
|
11456
|
+
this.abi &&
|
|
11457
|
+
this.abi.methods &&
|
|
11458
|
+
this.serializer) {
|
|
11459
|
+
Object.keys(this.abi.methods).forEach((name) => {
|
|
11460
|
+
this.functions[name] = async (argu = {}, options) => {
|
|
11461
|
+
if (!this.provider)
|
|
11462
|
+
throw new Error("provider not found");
|
|
11463
|
+
if (!this.abi || !this.abi.methods)
|
|
11464
|
+
throw new Error("Methods are not defined");
|
|
11465
|
+
if (!this.abi.methods[name])
|
|
11466
|
+
throw new Error(`Method ${name} not defined in the ABI`);
|
|
11467
|
+
const opts = {
|
|
11468
|
+
...this.options,
|
|
11469
|
+
...options,
|
|
11470
|
+
};
|
|
11471
|
+
const { readOnly, output, defaultOutput, preformatInput, preformatOutput, } = this.abi.methods[name];
|
|
11472
|
+
let args;
|
|
11473
|
+
if (typeof preformatInput === "function") {
|
|
11474
|
+
args = preformatInput(argu);
|
|
11475
|
+
}
|
|
11476
|
+
else {
|
|
11477
|
+
args = argu;
|
|
11478
|
+
}
|
|
11479
|
+
const operation = await this.encodeOperation({ name, args });
|
|
11480
|
+
if (readOnly) {
|
|
11481
|
+
if (!output)
|
|
11482
|
+
throw new Error(`No output defined for ${name}`);
|
|
11483
|
+
// read contract
|
|
11484
|
+
const { result: resultEncoded } = await this.provider.readContract({
|
|
11485
|
+
contract_id: utils_1.encodeBase58(operation.call_contract.contract_id),
|
|
11486
|
+
entry_point: operation.call_contract.entry_point,
|
|
11487
|
+
args: utils_1.encodeBase64(operation.call_contract.args),
|
|
11488
|
+
});
|
|
11489
|
+
let result = defaultOutput;
|
|
11490
|
+
if (resultEncoded) {
|
|
11491
|
+
result = await this.serializer.deserialize(resultEncoded, output);
|
|
11492
|
+
}
|
|
11493
|
+
if (typeof preformatOutput === "function") {
|
|
11494
|
+
result = preformatOutput(result);
|
|
11495
|
+
}
|
|
11496
|
+
return { operation, result };
|
|
11497
|
+
}
|
|
11498
|
+
// return operation if send is false
|
|
11499
|
+
if (!(opts === null || opts === void 0 ? void 0 : opts.sendTransaction))
|
|
11500
|
+
return { operation };
|
|
11501
|
+
// write contract (sign and send)
|
|
11502
|
+
if (!this.signer)
|
|
11503
|
+
throw new Error("signer not found");
|
|
11504
|
+
const transaction = await this.signer.encodeTransaction({
|
|
11505
|
+
...opts,
|
|
11506
|
+
operations: [operation],
|
|
11507
|
+
});
|
|
11508
|
+
const abis = {};
|
|
11509
|
+
if (opts === null || opts === void 0 ? void 0 : opts.sendAbis) {
|
|
11510
|
+
const contractId = utils_1.encodeBase58(this.id);
|
|
11511
|
+
abis[contractId] = this.abi;
|
|
11512
|
+
}
|
|
11513
|
+
const transactionResponse = await this.signer.sendTransaction(transaction, abis);
|
|
11514
|
+
return { operation, transaction, transactionResponse };
|
|
11515
|
+
};
|
|
11516
|
+
});
|
|
11517
|
+
}
|
|
11518
|
+
}
|
|
11519
|
+
/**
|
|
11520
|
+
* Compute contract Id
|
|
11521
|
+
*/
|
|
11522
|
+
static computeContractId(address) {
|
|
11523
|
+
return utils_1.decodeBase58(address);
|
|
11524
|
+
}
|
|
11525
|
+
/**
|
|
11526
|
+
* Get contract Id
|
|
11527
|
+
*/
|
|
11528
|
+
getId() {
|
|
11529
|
+
if (!this.id)
|
|
11530
|
+
throw new Error("id is not defined");
|
|
11531
|
+
return utils_1.encodeBase58(this.id);
|
|
11532
|
+
}
|
|
11533
|
+
/**
|
|
11534
|
+
* Function to deploy a new smart contract.
|
|
11535
|
+
* The Bytecode must be defined in the constructor of the class
|
|
11536
|
+
* @example
|
|
11537
|
+
* ```ts
|
|
11538
|
+
* const privateKey = "f186a5de49797bfd52dc42505c33d75a46822ed5b60046e09d7c336242e20200";
|
|
11539
|
+
* const provider = new Provider(["http://api.koinos.io:8080"]);
|
|
11540
|
+
* const signer = new Signer({ privateKey, provider });
|
|
11541
|
+
* const bytecode = new Uint8Array([1, 2, 3, 4]);
|
|
11542
|
+
* const contract = new Contract({ signer, provider, bytecode });
|
|
11543
|
+
* const { transactionResponse } = await contract.deploy();
|
|
11544
|
+
* // wait to be mined
|
|
11545
|
+
* const blockId = await transactionResponse.wait();
|
|
11546
|
+
* console.log(`Contract uploaded in block id ${blockId}`);
|
|
11547
|
+
* ```
|
|
11548
|
+
*/
|
|
11549
|
+
async deploy(options) {
|
|
11550
|
+
if (!this.signer)
|
|
11551
|
+
throw new Error("signer not found");
|
|
11552
|
+
if (!this.bytecode)
|
|
11553
|
+
throw new Error("bytecode not found");
|
|
11554
|
+
const opts = {
|
|
11555
|
+
...this.options,
|
|
11556
|
+
...options,
|
|
11557
|
+
};
|
|
11558
|
+
const operation = {
|
|
11559
|
+
upload_contract: {
|
|
11560
|
+
contract_id: Contract.computeContractId(this.signer.getAddress()),
|
|
11561
|
+
bytecode: this.bytecode,
|
|
11562
|
+
},
|
|
11563
|
+
};
|
|
11564
|
+
// return operation if send is false
|
|
11565
|
+
if (!(opts === null || opts === void 0 ? void 0 : opts.sendTransaction))
|
|
11566
|
+
return { operation };
|
|
11567
|
+
const transaction = await this.signer.encodeTransaction({
|
|
11568
|
+
...opts,
|
|
11569
|
+
operations: [operation],
|
|
11570
|
+
});
|
|
11571
|
+
const transactionResponse = await this.signer.sendTransaction(transaction);
|
|
11572
|
+
return { operation, transaction, transactionResponse };
|
|
11573
|
+
}
|
|
11574
|
+
/**
|
|
11575
|
+
* Encondes a contract operation using Koinos serialization
|
|
11576
|
+
* and taking the contract entries as reference to build it
|
|
11577
|
+
* @param op - Operation to encode
|
|
11578
|
+
* @returns Operation encoded
|
|
11579
|
+
* @example
|
|
11580
|
+
* ```ts
|
|
11581
|
+
* const opEncoded = contract.encodeOperation({
|
|
11582
|
+
* name: "transfer",
|
|
11583
|
+
* args: {
|
|
11584
|
+
* from: "12fN2CQnuJM8cMnWZ1hPtM4knjLME8E4PD",
|
|
11585
|
+
* to: "172AB1FgCsYrRAW5cwQ8KjadgxofvgPFd6",
|
|
11586
|
+
* value: "1000",
|
|
11587
|
+
* }
|
|
11588
|
+
* });
|
|
11589
|
+
*
|
|
11590
|
+
* console.log(opEncoded);
|
|
11591
|
+
* // {
|
|
11592
|
+
* // call_contract: {
|
|
11593
|
+
* // contract_id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
|
|
11594
|
+
* // entry_point: 0x62efa292,
|
|
11595
|
+
* // args: "MBWFsaWNlA2JvYgAAAAAAAAPo",
|
|
11596
|
+
* // }
|
|
11597
|
+
* // }
|
|
11598
|
+
* ```
|
|
11599
|
+
*/
|
|
11600
|
+
async encodeOperation(op) {
|
|
11601
|
+
if (!this.abi || !this.abi.methods || !this.abi.methods[op.name])
|
|
11602
|
+
throw new Error(`Operation ${op.name} unknown`);
|
|
11603
|
+
if (!this.serializer)
|
|
11604
|
+
throw new Error("Serializer is not defined");
|
|
11605
|
+
if (!this.id)
|
|
11606
|
+
throw new Error("Contract id is not defined");
|
|
11607
|
+
const method = this.abi.methods[op.name];
|
|
11608
|
+
let bufferInputs = new Uint8Array(0);
|
|
11609
|
+
if (method.input) {
|
|
11610
|
+
if (!op.args)
|
|
11611
|
+
throw new Error(`No arguments defined for type '${method.input}'`);
|
|
11612
|
+
bufferInputs = await this.serializer.serialize(op.args, method.input);
|
|
11613
|
+
}
|
|
11614
|
+
return {
|
|
11615
|
+
call_contract: {
|
|
11616
|
+
contract_id: this.id,
|
|
11617
|
+
entry_point: method.entryPoint,
|
|
11618
|
+
args: bufferInputs,
|
|
11619
|
+
},
|
|
11620
|
+
};
|
|
11621
|
+
}
|
|
11622
|
+
/**
|
|
11623
|
+
* Decodes a contract operation to be human readable
|
|
11624
|
+
* @example
|
|
11625
|
+
* ```ts
|
|
11626
|
+
* const opDecoded = contract.decodeOperation({
|
|
11627
|
+
* call_contract: {
|
|
11628
|
+
* contract_id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
|
|
11629
|
+
* entry_point: 0x62efa292,
|
|
11630
|
+
* args: "MBWFsaWNlA2JvYgAAAAAAAAPo",
|
|
11631
|
+
* }
|
|
11632
|
+
* });
|
|
11633
|
+
* console.log(opDecoded);
|
|
11634
|
+
* // {
|
|
11635
|
+
* // name: "transfer",
|
|
11636
|
+
* // args: {
|
|
11637
|
+
* // from: "12fN2CQnuJM8cMnWZ1hPtM4knjLME8E4PD",
|
|
11638
|
+
* // to: "172AB1FgCsYrRAW5cwQ8KjadgxofvgPFd6",
|
|
11639
|
+
* // value: "1000",
|
|
11640
|
+
* // },
|
|
11641
|
+
* // }
|
|
11642
|
+
* ```
|
|
11643
|
+
*/
|
|
11644
|
+
async decodeOperation(op) {
|
|
11645
|
+
if (!this.id)
|
|
11646
|
+
throw new Error("Contract id is not defined");
|
|
11647
|
+
if (!this.abi || !this.abi.methods)
|
|
11648
|
+
throw new Error("Methods are not defined");
|
|
11649
|
+
if (!this.serializer)
|
|
11650
|
+
throw new Error("Serializer is not defined");
|
|
11651
|
+
if (!op.call_contract)
|
|
11652
|
+
throw new Error("Operation is not CallContractOperation");
|
|
11653
|
+
if (utils_1.encodeBase58(op.call_contract.contract_id) !== utils_1.encodeBase58(this.id))
|
|
11654
|
+
throw new Error(`Invalid contract id. Expected: ${utils_1.encodeBase58(this.id)}. Received: ${utils_1.encodeBase58(op.call_contract.contract_id)}`);
|
|
11655
|
+
for (let i = 0; i < Object.keys(this.abi.methods).length; i += 1) {
|
|
11656
|
+
const opName = Object.keys(this.abi.methods)[i];
|
|
11657
|
+
const method = this.abi.methods[opName];
|
|
11658
|
+
if (op.call_contract.entry_point === method.entryPoint) {
|
|
11659
|
+
if (!method.input)
|
|
11660
|
+
return { name: opName };
|
|
11661
|
+
return {
|
|
11662
|
+
name: opName,
|
|
11663
|
+
args: await this.serializer.deserialize(op.call_contract.args, method.input),
|
|
11664
|
+
};
|
|
11665
|
+
}
|
|
11666
|
+
}
|
|
11667
|
+
throw new Error(`Unknown method id ${op.call_contract.entry_point}`);
|
|
11668
|
+
}
|
|
11669
|
+
}
|
|
11670
|
+
exports.Contract = Contract;
|
|
11671
|
+
exports.default = Contract;
|
|
11672
11672
|
|
|
11673
11673
|
|
|
11674
11674
|
/***/ }),
|
|
@@ -11677,261 +11677,261 @@ exports.default = Contract;
|
|
|
11677
11677
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
11678
11678
|
|
|
11679
11679
|
"use strict";
|
|
11680
|
-
|
|
11681
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11682
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11683
|
-
};
|
|
11684
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
11685
|
-
exports.Provider = void 0;
|
|
11686
|
-
const axios_1 = __importDefault(__webpack_require__(9669));
|
|
11687
|
-
async function sleep(ms) {
|
|
11688
|
-
return new Promise((r) => setTimeout(r, ms));
|
|
11689
|
-
}
|
|
11690
|
-
/**
|
|
11691
|
-
* Class to connect with the RPC node
|
|
11692
|
-
*/
|
|
11693
|
-
class Provider {
|
|
11694
|
-
/**
|
|
11695
|
-
*
|
|
11696
|
-
* @param rpcNodes - URL of the rpc node, or array of urls
|
|
11697
|
-
* to switch between them when someone is down
|
|
11698
|
-
* @example
|
|
11699
|
-
* ```ts
|
|
11700
|
-
* const provider = new Provider([
|
|
11701
|
-
* "http://45.56.104.152:8080",
|
|
11702
|
-
* "http://159.203.119.0:8080"
|
|
11703
|
-
* ]);
|
|
11704
|
-
* ```
|
|
11705
|
-
*/
|
|
11706
|
-
constructor(rpcNodes) {
|
|
11707
|
-
if (Array.isArray(rpcNodes))
|
|
11708
|
-
this.rpcNodes = rpcNodes;
|
|
11709
|
-
else
|
|
11710
|
-
this.rpcNodes = [rpcNodes];
|
|
11711
|
-
this.currentNodeId = 0;
|
|
11712
|
-
this.onError = () => false;
|
|
11713
|
-
}
|
|
11714
|
-
/**
|
|
11715
|
-
* Function to make jsonrpc requests to the RPC node
|
|
11716
|
-
* @param method - jsonrpc method
|
|
11717
|
-
* @param params - jsonrpc params
|
|
11718
|
-
* @returns Result of jsonrpc response
|
|
11719
|
-
*/
|
|
11720
|
-
async call(method, params) {
|
|
11721
|
-
let response = {
|
|
11722
|
-
data: {},
|
|
11723
|
-
status: 0,
|
|
11724
|
-
statusText: "",
|
|
11725
|
-
headers: {},
|
|
11726
|
-
config: {},
|
|
11727
|
-
};
|
|
11728
|
-
let success = false;
|
|
11729
|
-
/* eslint-disable no-await-in-loop */
|
|
11730
|
-
while (!success) {
|
|
11731
|
-
try {
|
|
11732
|
-
const data = {
|
|
11733
|
-
id: Math.round(Math.random() * 1000),
|
|
11734
|
-
jsonrpc: "2.0",
|
|
11735
|
-
method,
|
|
11736
|
-
params,
|
|
11737
|
-
};
|
|
11738
|
-
const url = this.rpcNodes[this.currentNodeId];
|
|
11739
|
-
// TODO: search conditional to enable fetch for Browser
|
|
11740
|
-
/* const response = await fetch(url, {
|
|
11741
|
-
method: "POST",
|
|
11742
|
-
body: JSON.stringify(data),
|
|
11743
|
-
});
|
|
11744
|
-
const json = await response.json();
|
|
11745
|
-
if (json.error && json.error.message) throw new Error(json.error.message);
|
|
11746
|
-
return json.result; */
|
|
11747
|
-
response = await axios_1.default.post(url, data, { validateStatus: (s) => s < 400 });
|
|
11748
|
-
success = true;
|
|
11749
|
-
}
|
|
11750
|
-
catch (e) {
|
|
11751
|
-
const currentNode = this.rpcNodes[this.currentNodeId];
|
|
11752
|
-
this.currentNodeId = (this.currentNodeId + 1) % this.rpcNodes.length;
|
|
11753
|
-
const newNode = this.rpcNodes[this.currentNodeId];
|
|
11754
|
-
const abort = this.onError(e, currentNode, newNode);
|
|
11755
|
-
if (abort)
|
|
11756
|
-
throw e;
|
|
11757
|
-
}
|
|
11758
|
-
}
|
|
11759
|
-
if (response.data.error)
|
|
11760
|
-
throw new Error(JSON.stringify({
|
|
11761
|
-
error: response.data.error,
|
|
11762
|
-
request: { method, params },
|
|
11763
|
-
}));
|
|
11764
|
-
return response.data.result;
|
|
11765
|
-
}
|
|
11766
|
-
/**
|
|
11767
|
-
* Function to call "chain.get_account_nonce" to return the number of
|
|
11768
|
-
* transactions for a particular account. This call is used
|
|
11769
|
-
* when creating new transactions.
|
|
11770
|
-
* @param account - account address
|
|
11771
|
-
* @returns Nonce
|
|
11772
|
-
*/
|
|
11773
|
-
async getNonce(account) {
|
|
11774
|
-
const { nonce } = await this.call("chain.get_account_nonce", { account });
|
|
11775
|
-
if (!nonce)
|
|
11776
|
-
return 0;
|
|
11777
|
-
return Number(nonce);
|
|
11778
|
-
}
|
|
11779
|
-
async getAccountRc(account) {
|
|
11780
|
-
const { rc } = await this.call("chain.get_account_rc", {
|
|
11781
|
-
account,
|
|
11782
|
-
});
|
|
11783
|
-
if (!rc)
|
|
11784
|
-
return "0";
|
|
11785
|
-
return rc;
|
|
11786
|
-
}
|
|
11787
|
-
/**
|
|
11788
|
-
* Get transactions by id and their corresponding block ids
|
|
11789
|
-
*/
|
|
11790
|
-
async getTransactionsById(transactionIds) {
|
|
11791
|
-
return this.call("transaction_store.get_transactions_by_id", {
|
|
11792
|
-
transaction_ids: transactionIds,
|
|
11793
|
-
});
|
|
11794
|
-
}
|
|
11795
|
-
async getBlocksById(blockIds) {
|
|
11796
|
-
return this.call("block_store.get_blocks_by_id", {
|
|
11797
|
-
block_id: blockIds,
|
|
11798
|
-
return_block: true,
|
|
11799
|
-
return_receipt: false,
|
|
11800
|
-
});
|
|
11801
|
-
}
|
|
11802
|
-
/**
|
|
11803
|
-
* Function to get info from the head block in the blockchain
|
|
11804
|
-
*/
|
|
11805
|
-
async getHeadInfo() {
|
|
11806
|
-
return this.call("chain.get_head_info", {});
|
|
11807
|
-
}
|
|
11808
|
-
/**
|
|
11809
|
-
* Function to get consecutive blocks in descending order
|
|
11810
|
-
* @param height - Starting block height
|
|
11811
|
-
* @param numBlocks - Number of blocks to fetch
|
|
11812
|
-
* @param idRef - Block ID reference to speed up searching blocks.
|
|
11813
|
-
* This ID must be from a greater block height. By default it
|
|
11814
|
-
* gets the ID from the block head.
|
|
11815
|
-
*/
|
|
11816
|
-
async getBlocks(height, numBlocks = 1, idRef) {
|
|
11817
|
-
let blockIdRef = idRef;
|
|
11818
|
-
if (!blockIdRef) {
|
|
11819
|
-
const head = await this.getHeadInfo();
|
|
11820
|
-
blockIdRef = head.head_topology.id;
|
|
11821
|
-
}
|
|
11822
|
-
return (await this.call("block_store.get_blocks_by_height", {
|
|
11823
|
-
head_block_id: blockIdRef,
|
|
11824
|
-
ancestor_start_height: height,
|
|
11825
|
-
num_blocks: numBlocks,
|
|
11826
|
-
return_block: true,
|
|
11827
|
-
return_receipt: false,
|
|
11828
|
-
})).block_items;
|
|
11829
|
-
}
|
|
11830
|
-
/**
|
|
11831
|
-
* Function to get a block by its height
|
|
11832
|
-
*/
|
|
11833
|
-
async getBlock(height) {
|
|
11834
|
-
return (await this.getBlocks(height, 1))[0];
|
|
11835
|
-
}
|
|
11836
|
-
/**
|
|
11837
|
-
* Function to call "chain.submit_transaction" to send a signed
|
|
11838
|
-
* transaction to the blockchain. It returns an object with the async
|
|
11839
|
-
* function "wait", which can be called to wait for the
|
|
11840
|
-
* transaction to be mined (see [[SendTransactionResponse]]).
|
|
11841
|
-
* @param transaction - Signed transaction
|
|
11842
|
-
* @example
|
|
11843
|
-
* ```ts
|
|
11844
|
-
* const { transactionResponse } = await provider.sendTransaction({
|
|
11845
|
-
* id: "1220...",
|
|
11846
|
-
* active: "...",
|
|
11847
|
-
* signatureData: "...",
|
|
11848
|
-
* });
|
|
11849
|
-
* console.log("Transaction submitted to the mempool");
|
|
11850
|
-
* // wait to be mined
|
|
11851
|
-
* const blockNumber = await transactionResponse.wait();
|
|
11852
|
-
* // const blockNumber = await transactionResponse.wait("byBlock", 30000);
|
|
11853
|
-
* // const blockId = await transactionResponse.wait("byTransactionId", 30000);
|
|
11854
|
-
* console.log("Transaction mined")
|
|
11855
|
-
* ```
|
|
11856
|
-
*/
|
|
11857
|
-
async sendTransaction(transaction) {
|
|
11858
|
-
await this.call("chain.submit_transaction", { transaction });
|
|
11859
|
-
return {
|
|
11860
|
-
wait: async (type = "byBlock", timeout = 30000) => {
|
|
11861
|
-
const iniTime = Date.now();
|
|
11862
|
-
if (type === "byTransactionId") {
|
|
11863
|
-
while (Date.now() < iniTime + timeout) {
|
|
11864
|
-
await sleep(1000);
|
|
11865
|
-
const { transactions } = await this.getTransactionsById([
|
|
11866
|
-
transaction.id,
|
|
11867
|
-
]);
|
|
11868
|
-
if (transactions &&
|
|
11869
|
-
transactions[0] &&
|
|
11870
|
-
transactions[0].containing_blocks)
|
|
11871
|
-
return transactions[0].containing_blocks[0];
|
|
11872
|
-
}
|
|
11873
|
-
throw new Error(`Transaction not mined after ${timeout} ms`);
|
|
11874
|
-
}
|
|
11875
|
-
// byBlock
|
|
11876
|
-
const findTxInBlocks = async (ini, numBlocks, idRef) => {
|
|
11877
|
-
const blocks = await this.getBlocks(ini, numBlocks, idRef);
|
|
11878
|
-
let bNum = 0;
|
|
11879
|
-
blocks.forEach((block) => {
|
|
11880
|
-
if (!block ||
|
|
11881
|
-
!block.block ||
|
|
11882
|
-
!block.block_id ||
|
|
11883
|
-
!block.block.transactions)
|
|
11884
|
-
return;
|
|
11885
|
-
const tx = block.block.transactions.find((t) => t.id === transaction.id);
|
|
11886
|
-
if (tx)
|
|
11887
|
-
bNum = Number(block.block_height);
|
|
11888
|
-
});
|
|
11889
|
-
let lastId = blocks[blocks.length - 1].block_id;
|
|
11890
|
-
return [bNum, lastId];
|
|
11891
|
-
};
|
|
11892
|
-
let blockNumber = 0;
|
|
11893
|
-
let iniBlock = 0;
|
|
11894
|
-
let previousId = "";
|
|
11895
|
-
while (Date.now() < iniTime + timeout) {
|
|
11896
|
-
await sleep(1000);
|
|
11897
|
-
const { head_topology: headTopology } = await this.getHeadInfo();
|
|
11898
|
-
if (blockNumber === 0) {
|
|
11899
|
-
blockNumber = Number(headTopology.height);
|
|
11900
|
-
iniBlock = blockNumber;
|
|
11901
|
-
}
|
|
11902
|
-
if (Number(headTopology.height) === blockNumber - 1 &&
|
|
11903
|
-
previousId &&
|
|
11904
|
-
previousId !== headTopology.id) {
|
|
11905
|
-
const [bNum, lastId] = await findTxInBlocks(iniBlock, Number(headTopology.height) - iniBlock + 1, headTopology.id);
|
|
11906
|
-
if (bNum)
|
|
11907
|
-
return bNum;
|
|
11908
|
-
previousId = lastId;
|
|
11909
|
-
blockNumber = Number(headTopology.height) + 1;
|
|
11910
|
-
}
|
|
11911
|
-
if (blockNumber > Number(headTopology.height))
|
|
11912
|
-
continue;
|
|
11913
|
-
const [bNum, lastId] = await findTxInBlocks(blockNumber, 1, headTopology.id);
|
|
11914
|
-
if (bNum)
|
|
11915
|
-
return bNum;
|
|
11916
|
-
if (!previousId)
|
|
11917
|
-
previousId = lastId;
|
|
11918
|
-
blockNumber += 1;
|
|
11919
|
-
}
|
|
11920
|
-
throw new Error(`Transaction not mined after ${timeout} ms. Blocks checked from ${iniBlock} to ${blockNumber}`);
|
|
11921
|
-
},
|
|
11922
|
-
};
|
|
11923
|
-
}
|
|
11924
|
-
/**
|
|
11925
|
-
* Function to call "chain.read_contract" to read a contract.
|
|
11926
|
-
* This function is used by [[Contract]] class when read methods
|
|
11927
|
-
* are invoked.
|
|
11928
|
-
*/
|
|
11929
|
-
async readContract(operation) {
|
|
11930
|
-
return this.call("chain.read_contract", operation);
|
|
11931
|
-
}
|
|
11932
|
-
}
|
|
11933
|
-
exports.Provider = Provider;
|
|
11934
|
-
exports.default = Provider;
|
|
11680
|
+
|
|
11681
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11682
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11683
|
+
};
|
|
11684
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
11685
|
+
exports.Provider = void 0;
|
|
11686
|
+
const axios_1 = __importDefault(__webpack_require__(9669));
|
|
11687
|
+
async function sleep(ms) {
|
|
11688
|
+
return new Promise((r) => setTimeout(r, ms));
|
|
11689
|
+
}
|
|
11690
|
+
/**
|
|
11691
|
+
* Class to connect with the RPC node
|
|
11692
|
+
*/
|
|
11693
|
+
class Provider {
|
|
11694
|
+
/**
|
|
11695
|
+
*
|
|
11696
|
+
* @param rpcNodes - URL of the rpc node, or array of urls
|
|
11697
|
+
* to switch between them when someone is down
|
|
11698
|
+
* @example
|
|
11699
|
+
* ```ts
|
|
11700
|
+
* const provider = new Provider([
|
|
11701
|
+
* "http://45.56.104.152:8080",
|
|
11702
|
+
* "http://159.203.119.0:8080"
|
|
11703
|
+
* ]);
|
|
11704
|
+
* ```
|
|
11705
|
+
*/
|
|
11706
|
+
constructor(rpcNodes) {
|
|
11707
|
+
if (Array.isArray(rpcNodes))
|
|
11708
|
+
this.rpcNodes = rpcNodes;
|
|
11709
|
+
else
|
|
11710
|
+
this.rpcNodes = [rpcNodes];
|
|
11711
|
+
this.currentNodeId = 0;
|
|
11712
|
+
this.onError = () => false;
|
|
11713
|
+
}
|
|
11714
|
+
/**
|
|
11715
|
+
* Function to make jsonrpc requests to the RPC node
|
|
11716
|
+
* @param method - jsonrpc method
|
|
11717
|
+
* @param params - jsonrpc params
|
|
11718
|
+
* @returns Result of jsonrpc response
|
|
11719
|
+
*/
|
|
11720
|
+
async call(method, params) {
|
|
11721
|
+
let response = {
|
|
11722
|
+
data: {},
|
|
11723
|
+
status: 0,
|
|
11724
|
+
statusText: "",
|
|
11725
|
+
headers: {},
|
|
11726
|
+
config: {},
|
|
11727
|
+
};
|
|
11728
|
+
let success = false;
|
|
11729
|
+
/* eslint-disable no-await-in-loop */
|
|
11730
|
+
while (!success) {
|
|
11731
|
+
try {
|
|
11732
|
+
const data = {
|
|
11733
|
+
id: Math.round(Math.random() * 1000),
|
|
11734
|
+
jsonrpc: "2.0",
|
|
11735
|
+
method,
|
|
11736
|
+
params,
|
|
11737
|
+
};
|
|
11738
|
+
const url = this.rpcNodes[this.currentNodeId];
|
|
11739
|
+
// TODO: search conditional to enable fetch for Browser
|
|
11740
|
+
/* const response = await fetch(url, {
|
|
11741
|
+
method: "POST",
|
|
11742
|
+
body: JSON.stringify(data),
|
|
11743
|
+
});
|
|
11744
|
+
const json = await response.json();
|
|
11745
|
+
if (json.error && json.error.message) throw new Error(json.error.message);
|
|
11746
|
+
return json.result; */
|
|
11747
|
+
response = await axios_1.default.post(url, data, { validateStatus: (s) => s < 400 });
|
|
11748
|
+
success = true;
|
|
11749
|
+
}
|
|
11750
|
+
catch (e) {
|
|
11751
|
+
const currentNode = this.rpcNodes[this.currentNodeId];
|
|
11752
|
+
this.currentNodeId = (this.currentNodeId + 1) % this.rpcNodes.length;
|
|
11753
|
+
const newNode = this.rpcNodes[this.currentNodeId];
|
|
11754
|
+
const abort = this.onError(e, currentNode, newNode);
|
|
11755
|
+
if (abort)
|
|
11756
|
+
throw e;
|
|
11757
|
+
}
|
|
11758
|
+
}
|
|
11759
|
+
if (response.data.error)
|
|
11760
|
+
throw new Error(JSON.stringify({
|
|
11761
|
+
error: response.data.error,
|
|
11762
|
+
request: { method, params },
|
|
11763
|
+
}));
|
|
11764
|
+
return response.data.result;
|
|
11765
|
+
}
|
|
11766
|
+
/**
|
|
11767
|
+
* Function to call "chain.get_account_nonce" to return the number of
|
|
11768
|
+
* transactions for a particular account. This call is used
|
|
11769
|
+
* when creating new transactions.
|
|
11770
|
+
* @param account - account address
|
|
11771
|
+
* @returns Nonce
|
|
11772
|
+
*/
|
|
11773
|
+
async getNonce(account) {
|
|
11774
|
+
const { nonce } = await this.call("chain.get_account_nonce", { account });
|
|
11775
|
+
if (!nonce)
|
|
11776
|
+
return 0;
|
|
11777
|
+
return Number(nonce);
|
|
11778
|
+
}
|
|
11779
|
+
async getAccountRc(account) {
|
|
11780
|
+
const { rc } = await this.call("chain.get_account_rc", {
|
|
11781
|
+
account,
|
|
11782
|
+
});
|
|
11783
|
+
if (!rc)
|
|
11784
|
+
return "0";
|
|
11785
|
+
return rc;
|
|
11786
|
+
}
|
|
11787
|
+
/**
|
|
11788
|
+
* Get transactions by id and their corresponding block ids
|
|
11789
|
+
*/
|
|
11790
|
+
async getTransactionsById(transactionIds) {
|
|
11791
|
+
return this.call("transaction_store.get_transactions_by_id", {
|
|
11792
|
+
transaction_ids: transactionIds,
|
|
11793
|
+
});
|
|
11794
|
+
}
|
|
11795
|
+
async getBlocksById(blockIds) {
|
|
11796
|
+
return this.call("block_store.get_blocks_by_id", {
|
|
11797
|
+
block_id: blockIds,
|
|
11798
|
+
return_block: true,
|
|
11799
|
+
return_receipt: false,
|
|
11800
|
+
});
|
|
11801
|
+
}
|
|
11802
|
+
/**
|
|
11803
|
+
* Function to get info from the head block in the blockchain
|
|
11804
|
+
*/
|
|
11805
|
+
async getHeadInfo() {
|
|
11806
|
+
return this.call("chain.get_head_info", {});
|
|
11807
|
+
}
|
|
11808
|
+
/**
|
|
11809
|
+
* Function to get consecutive blocks in descending order
|
|
11810
|
+
* @param height - Starting block height
|
|
11811
|
+
* @param numBlocks - Number of blocks to fetch
|
|
11812
|
+
* @param idRef - Block ID reference to speed up searching blocks.
|
|
11813
|
+
* This ID must be from a greater block height. By default it
|
|
11814
|
+
* gets the ID from the block head.
|
|
11815
|
+
*/
|
|
11816
|
+
async getBlocks(height, numBlocks = 1, idRef) {
|
|
11817
|
+
let blockIdRef = idRef;
|
|
11818
|
+
if (!blockIdRef) {
|
|
11819
|
+
const head = await this.getHeadInfo();
|
|
11820
|
+
blockIdRef = head.head_topology.id;
|
|
11821
|
+
}
|
|
11822
|
+
return (await this.call("block_store.get_blocks_by_height", {
|
|
11823
|
+
head_block_id: blockIdRef,
|
|
11824
|
+
ancestor_start_height: height,
|
|
11825
|
+
num_blocks: numBlocks,
|
|
11826
|
+
return_block: true,
|
|
11827
|
+
return_receipt: false,
|
|
11828
|
+
})).block_items;
|
|
11829
|
+
}
|
|
11830
|
+
/**
|
|
11831
|
+
* Function to get a block by its height
|
|
11832
|
+
*/
|
|
11833
|
+
async getBlock(height) {
|
|
11834
|
+
return (await this.getBlocks(height, 1))[0];
|
|
11835
|
+
}
|
|
11836
|
+
/**
|
|
11837
|
+
* Function to call "chain.submit_transaction" to send a signed
|
|
11838
|
+
* transaction to the blockchain. It returns an object with the async
|
|
11839
|
+
* function "wait", which can be called to wait for the
|
|
11840
|
+
* transaction to be mined (see [[SendTransactionResponse]]).
|
|
11841
|
+
* @param transaction - Signed transaction
|
|
11842
|
+
* @example
|
|
11843
|
+
* ```ts
|
|
11844
|
+
* const { transactionResponse } = await provider.sendTransaction({
|
|
11845
|
+
* id: "1220...",
|
|
11846
|
+
* active: "...",
|
|
11847
|
+
* signatureData: "...",
|
|
11848
|
+
* });
|
|
11849
|
+
* console.log("Transaction submitted to the mempool");
|
|
11850
|
+
* // wait to be mined
|
|
11851
|
+
* const blockNumber = await transactionResponse.wait();
|
|
11852
|
+
* // const blockNumber = await transactionResponse.wait("byBlock", 30000);
|
|
11853
|
+
* // const blockId = await transactionResponse.wait("byTransactionId", 30000);
|
|
11854
|
+
* console.log("Transaction mined")
|
|
11855
|
+
* ```
|
|
11856
|
+
*/
|
|
11857
|
+
async sendTransaction(transaction) {
|
|
11858
|
+
await this.call("chain.submit_transaction", { transaction });
|
|
11859
|
+
return {
|
|
11860
|
+
wait: async (type = "byBlock", timeout = 30000) => {
|
|
11861
|
+
const iniTime = Date.now();
|
|
11862
|
+
if (type === "byTransactionId") {
|
|
11863
|
+
while (Date.now() < iniTime + timeout) {
|
|
11864
|
+
await sleep(1000);
|
|
11865
|
+
const { transactions } = await this.getTransactionsById([
|
|
11866
|
+
transaction.id,
|
|
11867
|
+
]);
|
|
11868
|
+
if (transactions &&
|
|
11869
|
+
transactions[0] &&
|
|
11870
|
+
transactions[0].containing_blocks)
|
|
11871
|
+
return transactions[0].containing_blocks[0];
|
|
11872
|
+
}
|
|
11873
|
+
throw new Error(`Transaction not mined after ${timeout} ms`);
|
|
11874
|
+
}
|
|
11875
|
+
// byBlock
|
|
11876
|
+
const findTxInBlocks = async (ini, numBlocks, idRef) => {
|
|
11877
|
+
const blocks = await this.getBlocks(ini, numBlocks, idRef);
|
|
11878
|
+
let bNum = 0;
|
|
11879
|
+
blocks.forEach((block) => {
|
|
11880
|
+
if (!block ||
|
|
11881
|
+
!block.block ||
|
|
11882
|
+
!block.block_id ||
|
|
11883
|
+
!block.block.transactions)
|
|
11884
|
+
return;
|
|
11885
|
+
const tx = block.block.transactions.find((t) => t.id === transaction.id);
|
|
11886
|
+
if (tx)
|
|
11887
|
+
bNum = Number(block.block_height);
|
|
11888
|
+
});
|
|
11889
|
+
let lastId = blocks[blocks.length - 1].block_id;
|
|
11890
|
+
return [bNum, lastId];
|
|
11891
|
+
};
|
|
11892
|
+
let blockNumber = 0;
|
|
11893
|
+
let iniBlock = 0;
|
|
11894
|
+
let previousId = "";
|
|
11895
|
+
while (Date.now() < iniTime + timeout) {
|
|
11896
|
+
await sleep(1000);
|
|
11897
|
+
const { head_topology: headTopology } = await this.getHeadInfo();
|
|
11898
|
+
if (blockNumber === 0) {
|
|
11899
|
+
blockNumber = Number(headTopology.height);
|
|
11900
|
+
iniBlock = blockNumber;
|
|
11901
|
+
}
|
|
11902
|
+
if (Number(headTopology.height) === blockNumber - 1 &&
|
|
11903
|
+
previousId &&
|
|
11904
|
+
previousId !== headTopology.id) {
|
|
11905
|
+
const [bNum, lastId] = await findTxInBlocks(iniBlock, Number(headTopology.height) - iniBlock + 1, headTopology.id);
|
|
11906
|
+
if (bNum)
|
|
11907
|
+
return bNum;
|
|
11908
|
+
previousId = lastId;
|
|
11909
|
+
blockNumber = Number(headTopology.height) + 1;
|
|
11910
|
+
}
|
|
11911
|
+
if (blockNumber > Number(headTopology.height))
|
|
11912
|
+
continue;
|
|
11913
|
+
const [bNum, lastId] = await findTxInBlocks(blockNumber, 1, headTopology.id);
|
|
11914
|
+
if (bNum)
|
|
11915
|
+
return bNum;
|
|
11916
|
+
if (!previousId)
|
|
11917
|
+
previousId = lastId;
|
|
11918
|
+
blockNumber += 1;
|
|
11919
|
+
}
|
|
11920
|
+
throw new Error(`Transaction not mined after ${timeout} ms. Blocks checked from ${iniBlock} to ${blockNumber}`);
|
|
11921
|
+
},
|
|
11922
|
+
};
|
|
11923
|
+
}
|
|
11924
|
+
/**
|
|
11925
|
+
* Function to call "chain.read_contract" to read a contract.
|
|
11926
|
+
* This function is used by [[Contract]] class when read methods
|
|
11927
|
+
* are invoked.
|
|
11928
|
+
*/
|
|
11929
|
+
async readContract(operation) {
|
|
11930
|
+
return this.call("chain.read_contract", operation);
|
|
11931
|
+
}
|
|
11932
|
+
}
|
|
11933
|
+
exports.Provider = Provider;
|
|
11934
|
+
exports.default = Provider;
|
|
11935
11935
|
|
|
11936
11936
|
|
|
11937
11937
|
/***/ }),
|
|
@@ -11940,174 +11940,174 @@ exports.default = Provider;
|
|
|
11940
11940
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
11941
11941
|
|
|
11942
11942
|
"use strict";
|
|
11943
|
-
|
|
11944
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
11945
|
-
exports.Serializer = void 0;
|
|
11946
|
-
/* eslint-disable @typescript-eslint/require-await */
|
|
11947
|
-
const light_1 = __webpack_require__(4492);
|
|
11948
|
-
const utils_1 = __webpack_require__(8593);
|
|
11949
|
-
const OP_BYTES = "(koinos_bytes_type)";
|
|
11950
|
-
/**
|
|
11951
|
-
* Makes a copy of a value. The returned value can be modified
|
|
11952
|
-
* without altering the original one. Although this is not needed
|
|
11953
|
-
* for strings or numbers and only needed for objects and arrays,
|
|
11954
|
-
* all these options are covered in a single function
|
|
11955
|
-
*
|
|
11956
|
-
* It is assumed that the argument is number, string, or contructions
|
|
11957
|
-
* of these types inside objects or arrays.
|
|
11958
|
-
*/
|
|
11959
|
-
function copyValue(value) {
|
|
11960
|
-
if (typeof value === "string" || typeof value === "number") {
|
|
11961
|
-
return value;
|
|
11962
|
-
}
|
|
11963
|
-
return JSON.parse(JSON.stringify(value));
|
|
11964
|
-
}
|
|
11965
|
-
/**
|
|
11966
|
-
* The serializer class serialize and deserialize data using
|
|
11967
|
-
* protocol buffers.
|
|
11968
|
-
*
|
|
11969
|
-
* NOTE: This class uses the [protobufjs/light](https://www.npmjs.com/package/protobufjs)
|
|
11970
|
-
* library internally, which uses reflection (use of _eval_
|
|
11971
|
-
* and _new Function_) for the construction of the types.
|
|
11972
|
-
* This could cause issues in environments where _eval_ is not
|
|
11973
|
-
* allowed, like in browser extensions. In such cases, this class
|
|
11974
|
-
* must be confined in a [sandbox environment](https://developer.chrome.com/docs/apps/app_external/#sandboxing)
|
|
11975
|
-
* where _eval_ is allowed. This is the principal reason of
|
|
11976
|
-
* having the serializer in a separate class.
|
|
11977
|
-
*
|
|
11978
|
-
* @example
|
|
11979
|
-
*
|
|
11980
|
-
* ```ts
|
|
11981
|
-
* const descriptorJson = {
|
|
11982
|
-
* nested: {
|
|
11983
|
-
* awesomepackage: {
|
|
11984
|
-
* nested: {
|
|
11985
|
-
* AwesomeMessage: {
|
|
11986
|
-
* fields: {
|
|
11987
|
-
* awesomeField: {
|
|
11988
|
-
* type: "string",
|
|
11989
|
-
* id: 1
|
|
11990
|
-
* }
|
|
11991
|
-
* }
|
|
11992
|
-
* }
|
|
11993
|
-
* }
|
|
11994
|
-
* }
|
|
11995
|
-
* }
|
|
11996
|
-
* }
|
|
11997
|
-
* const serializer = new Serializer(descriptorJson)
|
|
11998
|
-
* ```
|
|
11999
|
-
*/
|
|
12000
|
-
class Serializer {
|
|
12001
|
-
constructor(types, opts) {
|
|
12002
|
-
/**
|
|
12003
|
-
* Preformat bytes for base64, base58 or hex string
|
|
12004
|
-
*/
|
|
12005
|
-
this.bytesConversion = true;
|
|
12006
|
-
this.types = types;
|
|
12007
|
-
this.root = light_1.Root.fromJSON(this.types);
|
|
12008
|
-
if (opts === null || opts === void 0 ? void 0 : opts.defaultTypeName)
|
|
12009
|
-
this.defaultType = this.root.lookupType(opts.defaultTypeName);
|
|
12010
|
-
if (opts && typeof opts.bytesConversion !== "undefined")
|
|
12011
|
-
this.bytesConversion = opts.bytesConversion;
|
|
12012
|
-
}
|
|
12013
|
-
/**
|
|
12014
|
-
* Function to encode a type using the protobuffer definitions
|
|
12015
|
-
* It also prepares the bytes for special cases (base58, hex string)
|
|
12016
|
-
* when bytesConversion param is true.
|
|
12017
|
-
*/
|
|
12018
|
-
async serialize(valueDecoded, typeName) {
|
|
12019
|
-
const protobufType = this.defaultType || this.root.lookupType(typeName);
|
|
12020
|
-
let object = {};
|
|
12021
|
-
if (this.bytesConversion) {
|
|
12022
|
-
// TODO: format from Buffer to base58/base64 for nested fields
|
|
12023
|
-
Object.keys(protobufType.fields).forEach((fieldName) => {
|
|
12024
|
-
const { options, name, type } = protobufType.fields[fieldName];
|
|
12025
|
-
// No byte conversion
|
|
12026
|
-
if (type !== "bytes") {
|
|
12027
|
-
object[name] = copyValue(valueDecoded[name]);
|
|
12028
|
-
return;
|
|
12029
|
-
}
|
|
12030
|
-
// Default byte conversion
|
|
12031
|
-
if (!options || !options[OP_BYTES]) {
|
|
12032
|
-
object[name] = utils_1.decodeBase64(valueDecoded[name]);
|
|
12033
|
-
return;
|
|
12034
|
-
}
|
|
12035
|
-
// Specific byte conversion
|
|
12036
|
-
switch (options[OP_BYTES]) {
|
|
12037
|
-
case "BASE58":
|
|
12038
|
-
case "CONTRACT_ID":
|
|
12039
|
-
case "ADDRESS":
|
|
12040
|
-
object[name] = utils_1.decodeBase58(valueDecoded[name]);
|
|
12041
|
-
break;
|
|
12042
|
-
case "BASE64":
|
|
12043
|
-
object[name] = utils_1.decodeBase64(valueDecoded[name]);
|
|
12044
|
-
break;
|
|
12045
|
-
case "HEX":
|
|
12046
|
-
case "BLOCK_ID":
|
|
12047
|
-
case "TRANSACTION_ID":
|
|
12048
|
-
object[name] = utils_1.toUint8Array(valueDecoded[name].replace("0x", ""));
|
|
12049
|
-
break;
|
|
12050
|
-
default:
|
|
12051
|
-
throw new Error(`unknown koinos_byte_type ${options[OP_BYTES]}`);
|
|
12052
|
-
}
|
|
12053
|
-
});
|
|
12054
|
-
}
|
|
12055
|
-
else {
|
|
12056
|
-
object = valueDecoded;
|
|
12057
|
-
}
|
|
12058
|
-
const message = protobufType.create(object);
|
|
12059
|
-
const buffer = protobufType.encode(message).finish();
|
|
12060
|
-
return buffer;
|
|
12061
|
-
}
|
|
12062
|
-
/**
|
|
12063
|
-
* Function to decode bytes using the protobuffer definitions
|
|
12064
|
-
* It also encodes the bytes for special cases (base58, hex string)
|
|
12065
|
-
* when bytesConversion param is true.
|
|
12066
|
-
*/
|
|
12067
|
-
async deserialize(valueEncoded, typeName) {
|
|
12068
|
-
const valueBuffer = typeof valueEncoded === "string"
|
|
12069
|
-
? utils_1.decodeBase64(valueEncoded)
|
|
12070
|
-
: valueEncoded;
|
|
12071
|
-
const protobufType = this.defaultType || this.root.lookupType(typeName);
|
|
12072
|
-
const message = protobufType.decode(valueBuffer);
|
|
12073
|
-
const object = protobufType.toObject(message, { longs: String });
|
|
12074
|
-
if (!this.bytesConversion)
|
|
12075
|
-
return object;
|
|
12076
|
-
// TODO: format from Buffer to base58/base64 for nested fields
|
|
12077
|
-
Object.keys(protobufType.fields).forEach((fieldName) => {
|
|
12078
|
-
const { options, name, type } = protobufType.fields[fieldName];
|
|
12079
|
-
// No byte conversion
|
|
12080
|
-
if (type !== "bytes")
|
|
12081
|
-
return;
|
|
12082
|
-
// Default byte conversion
|
|
12083
|
-
if (!options || !options[OP_BYTES]) {
|
|
12084
|
-
object[name] = utils_1.encodeBase64(object[name]);
|
|
12085
|
-
return;
|
|
12086
|
-
}
|
|
12087
|
-
// Specific byte conversion
|
|
12088
|
-
switch (options[OP_BYTES]) {
|
|
12089
|
-
case "BASE58":
|
|
12090
|
-
case "CONTRACT_ID":
|
|
12091
|
-
case "ADDRESS":
|
|
12092
|
-
object[name] = utils_1.encodeBase58(object[name]);
|
|
12093
|
-
break;
|
|
12094
|
-
case "BASE64":
|
|
12095
|
-
object[name] = utils_1.encodeBase64(object[name]);
|
|
12096
|
-
break;
|
|
12097
|
-
case "HEX":
|
|
12098
|
-
case "BLOCK_ID":
|
|
12099
|
-
case "TRANSACTION_ID":
|
|
12100
|
-
object[name] = `0x${utils_1.toHexString(object[name])}`;
|
|
12101
|
-
break;
|
|
12102
|
-
default:
|
|
12103
|
-
throw new Error(`unknown koinos_byte_type ${options[OP_BYTES]}`);
|
|
12104
|
-
}
|
|
12105
|
-
});
|
|
12106
|
-
return object;
|
|
12107
|
-
}
|
|
12108
|
-
}
|
|
12109
|
-
exports.Serializer = Serializer;
|
|
12110
|
-
exports.default = Serializer;
|
|
11943
|
+
|
|
11944
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
11945
|
+
exports.Serializer = void 0;
|
|
11946
|
+
/* eslint-disable @typescript-eslint/require-await */
|
|
11947
|
+
const light_1 = __webpack_require__(4492);
|
|
11948
|
+
const utils_1 = __webpack_require__(8593);
|
|
11949
|
+
const OP_BYTES = "(koinos_bytes_type)";
|
|
11950
|
+
/**
|
|
11951
|
+
* Makes a copy of a value. The returned value can be modified
|
|
11952
|
+
* without altering the original one. Although this is not needed
|
|
11953
|
+
* for strings or numbers and only needed for objects and arrays,
|
|
11954
|
+
* all these options are covered in a single function
|
|
11955
|
+
*
|
|
11956
|
+
* It is assumed that the argument is number, string, or contructions
|
|
11957
|
+
* of these types inside objects or arrays.
|
|
11958
|
+
*/
|
|
11959
|
+
function copyValue(value) {
|
|
11960
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
11961
|
+
return value;
|
|
11962
|
+
}
|
|
11963
|
+
return JSON.parse(JSON.stringify(value));
|
|
11964
|
+
}
|
|
11965
|
+
/**
|
|
11966
|
+
* The serializer class serialize and deserialize data using
|
|
11967
|
+
* protocol buffers.
|
|
11968
|
+
*
|
|
11969
|
+
* NOTE: This class uses the [protobufjs/light](https://www.npmjs.com/package/protobufjs)
|
|
11970
|
+
* library internally, which uses reflection (use of _eval_
|
|
11971
|
+
* and _new Function_) for the construction of the types.
|
|
11972
|
+
* This could cause issues in environments where _eval_ is not
|
|
11973
|
+
* allowed, like in browser extensions. In such cases, this class
|
|
11974
|
+
* must be confined in a [sandbox environment](https://developer.chrome.com/docs/apps/app_external/#sandboxing)
|
|
11975
|
+
* where _eval_ is allowed. This is the principal reason of
|
|
11976
|
+
* having the serializer in a separate class.
|
|
11977
|
+
*
|
|
11978
|
+
* @example
|
|
11979
|
+
*
|
|
11980
|
+
* ```ts
|
|
11981
|
+
* const descriptorJson = {
|
|
11982
|
+
* nested: {
|
|
11983
|
+
* awesomepackage: {
|
|
11984
|
+
* nested: {
|
|
11985
|
+
* AwesomeMessage: {
|
|
11986
|
+
* fields: {
|
|
11987
|
+
* awesomeField: {
|
|
11988
|
+
* type: "string",
|
|
11989
|
+
* id: 1
|
|
11990
|
+
* }
|
|
11991
|
+
* }
|
|
11992
|
+
* }
|
|
11993
|
+
* }
|
|
11994
|
+
* }
|
|
11995
|
+
* }
|
|
11996
|
+
* }
|
|
11997
|
+
* const serializer = new Serializer(descriptorJson)
|
|
11998
|
+
* ```
|
|
11999
|
+
*/
|
|
12000
|
+
class Serializer {
|
|
12001
|
+
constructor(types, opts) {
|
|
12002
|
+
/**
|
|
12003
|
+
* Preformat bytes for base64, base58 or hex string
|
|
12004
|
+
*/
|
|
12005
|
+
this.bytesConversion = true;
|
|
12006
|
+
this.types = types;
|
|
12007
|
+
this.root = light_1.Root.fromJSON(this.types);
|
|
12008
|
+
if (opts === null || opts === void 0 ? void 0 : opts.defaultTypeName)
|
|
12009
|
+
this.defaultType = this.root.lookupType(opts.defaultTypeName);
|
|
12010
|
+
if (opts && typeof opts.bytesConversion !== "undefined")
|
|
12011
|
+
this.bytesConversion = opts.bytesConversion;
|
|
12012
|
+
}
|
|
12013
|
+
/**
|
|
12014
|
+
* Function to encode a type using the protobuffer definitions
|
|
12015
|
+
* It also prepares the bytes for special cases (base58, hex string)
|
|
12016
|
+
* when bytesConversion param is true.
|
|
12017
|
+
*/
|
|
12018
|
+
async serialize(valueDecoded, typeName) {
|
|
12019
|
+
const protobufType = this.defaultType || this.root.lookupType(typeName);
|
|
12020
|
+
let object = {};
|
|
12021
|
+
if (this.bytesConversion) {
|
|
12022
|
+
// TODO: format from Buffer to base58/base64 for nested fields
|
|
12023
|
+
Object.keys(protobufType.fields).forEach((fieldName) => {
|
|
12024
|
+
const { options, name, type } = protobufType.fields[fieldName];
|
|
12025
|
+
// No byte conversion
|
|
12026
|
+
if (type !== "bytes") {
|
|
12027
|
+
object[name] = copyValue(valueDecoded[name]);
|
|
12028
|
+
return;
|
|
12029
|
+
}
|
|
12030
|
+
// Default byte conversion
|
|
12031
|
+
if (!options || !options[OP_BYTES]) {
|
|
12032
|
+
object[name] = utils_1.decodeBase64(valueDecoded[name]);
|
|
12033
|
+
return;
|
|
12034
|
+
}
|
|
12035
|
+
// Specific byte conversion
|
|
12036
|
+
switch (options[OP_BYTES]) {
|
|
12037
|
+
case "BASE58":
|
|
12038
|
+
case "CONTRACT_ID":
|
|
12039
|
+
case "ADDRESS":
|
|
12040
|
+
object[name] = utils_1.decodeBase58(valueDecoded[name]);
|
|
12041
|
+
break;
|
|
12042
|
+
case "BASE64":
|
|
12043
|
+
object[name] = utils_1.decodeBase64(valueDecoded[name]);
|
|
12044
|
+
break;
|
|
12045
|
+
case "HEX":
|
|
12046
|
+
case "BLOCK_ID":
|
|
12047
|
+
case "TRANSACTION_ID":
|
|
12048
|
+
object[name] = utils_1.toUint8Array(valueDecoded[name].replace("0x", ""));
|
|
12049
|
+
break;
|
|
12050
|
+
default:
|
|
12051
|
+
throw new Error(`unknown koinos_byte_type ${options[OP_BYTES]}`);
|
|
12052
|
+
}
|
|
12053
|
+
});
|
|
12054
|
+
}
|
|
12055
|
+
else {
|
|
12056
|
+
object = valueDecoded;
|
|
12057
|
+
}
|
|
12058
|
+
const message = protobufType.create(object);
|
|
12059
|
+
const buffer = protobufType.encode(message).finish();
|
|
12060
|
+
return buffer;
|
|
12061
|
+
}
|
|
12062
|
+
/**
|
|
12063
|
+
* Function to decode bytes using the protobuffer definitions
|
|
12064
|
+
* It also encodes the bytes for special cases (base58, hex string)
|
|
12065
|
+
* when bytesConversion param is true.
|
|
12066
|
+
*/
|
|
12067
|
+
async deserialize(valueEncoded, typeName) {
|
|
12068
|
+
const valueBuffer = typeof valueEncoded === "string"
|
|
12069
|
+
? utils_1.decodeBase64(valueEncoded)
|
|
12070
|
+
: valueEncoded;
|
|
12071
|
+
const protobufType = this.defaultType || this.root.lookupType(typeName);
|
|
12072
|
+
const message = protobufType.decode(valueBuffer);
|
|
12073
|
+
const object = protobufType.toObject(message, { longs: String });
|
|
12074
|
+
if (!this.bytesConversion)
|
|
12075
|
+
return object;
|
|
12076
|
+
// TODO: format from Buffer to base58/base64 for nested fields
|
|
12077
|
+
Object.keys(protobufType.fields).forEach((fieldName) => {
|
|
12078
|
+
const { options, name, type } = protobufType.fields[fieldName];
|
|
12079
|
+
// No byte conversion
|
|
12080
|
+
if (type !== "bytes")
|
|
12081
|
+
return;
|
|
12082
|
+
// Default byte conversion
|
|
12083
|
+
if (!options || !options[OP_BYTES]) {
|
|
12084
|
+
object[name] = utils_1.encodeBase64(object[name]);
|
|
12085
|
+
return;
|
|
12086
|
+
}
|
|
12087
|
+
// Specific byte conversion
|
|
12088
|
+
switch (options[OP_BYTES]) {
|
|
12089
|
+
case "BASE58":
|
|
12090
|
+
case "CONTRACT_ID":
|
|
12091
|
+
case "ADDRESS":
|
|
12092
|
+
object[name] = utils_1.encodeBase58(object[name]);
|
|
12093
|
+
break;
|
|
12094
|
+
case "BASE64":
|
|
12095
|
+
object[name] = utils_1.encodeBase64(object[name]);
|
|
12096
|
+
break;
|
|
12097
|
+
case "HEX":
|
|
12098
|
+
case "BLOCK_ID":
|
|
12099
|
+
case "TRANSACTION_ID":
|
|
12100
|
+
object[name] = `0x${utils_1.toHexString(object[name])}`;
|
|
12101
|
+
break;
|
|
12102
|
+
default:
|
|
12103
|
+
throw new Error(`unknown koinos_byte_type ${options[OP_BYTES]}`);
|
|
12104
|
+
}
|
|
12105
|
+
});
|
|
12106
|
+
return object;
|
|
12107
|
+
}
|
|
12108
|
+
}
|
|
12109
|
+
exports.Serializer = Serializer;
|
|
12110
|
+
exports.default = Serializer;
|
|
12111
12111
|
|
|
12112
12112
|
|
|
12113
12113
|
/***/ }),
|
|
@@ -12116,426 +12116,426 @@ exports.default = Serializer;
|
|
|
12116
12116
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
12117
12117
|
|
|
12118
12118
|
"use strict";
|
|
12119
|
-
|
|
12120
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12121
|
-
if (k2 === undefined) k2 = k;
|
|
12122
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12123
|
-
}) : (function(o, m, k, k2) {
|
|
12124
|
-
if (k2 === undefined) k2 = k;
|
|
12125
|
-
o[k2] = m[k];
|
|
12126
|
-
}));
|
|
12127
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
12128
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
12129
|
-
}) : function(o, v) {
|
|
12130
|
-
o["default"] = v;
|
|
12131
|
-
});
|
|
12132
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
12133
|
-
if (mod && mod.__esModule) return mod;
|
|
12134
|
-
var result = {};
|
|
12135
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
12136
|
-
__setModuleDefault(result, mod);
|
|
12137
|
-
return result;
|
|
12138
|
-
};
|
|
12139
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12140
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12141
|
-
};
|
|
12142
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
12143
|
-
exports.Signer = void 0;
|
|
12144
|
-
/* eslint-disable no-param-reassign */
|
|
12145
|
-
const sha256_1 = __webpack_require__(5374);
|
|
12146
|
-
const secp = __importStar(__webpack_require__(1337));
|
|
12147
|
-
const protocol_proto_json_1 = __importDefault(__webpack_require__(6139));
|
|
12148
|
-
const utils_1 = __webpack_require__(8593);
|
|
12149
|
-
const Serializer_1 = __webpack_require__(7187);
|
|
12150
|
-
/**
|
|
12151
|
-
* The Signer Class contains the private key needed to sign transactions.
|
|
12152
|
-
* It can be created using the seed, wif, or private key
|
|
12153
|
-
*
|
|
12154
|
-
* @example
|
|
12155
|
-
* using private key as hex string
|
|
12156
|
-
* ```ts
|
|
12157
|
-
* var privateKey = "ec8601a24f81decd57f4b611b5ac6eb801cb3780bb02c0f9cdfe9d09daaddf9c";
|
|
12158
|
-
* var signer = new Signer({ privateKey });
|
|
12159
|
-
* ```
|
|
12160
|
-
* <br>
|
|
12161
|
-
*
|
|
12162
|
-
* using private key as Uint8Array
|
|
12163
|
-
* ```ts
|
|
12164
|
-
* var buffer = new Uint8Array([
|
|
12165
|
-
* 236, 134, 1, 162, 79, 129, 222, 205,
|
|
12166
|
-
* 87, 244, 182, 17, 181, 172, 110, 184,
|
|
12167
|
-
* 1, 203, 55, 128, 187, 2, 192, 249,
|
|
12168
|
-
* 205, 254, 157, 9, 218, 173, 223, 156
|
|
12169
|
-
* ]);
|
|
12170
|
-
* var signer = new Signer({ privateKey: buffer });
|
|
12171
|
-
* ```
|
|
12172
|
-
*
|
|
12173
|
-
* <br>
|
|
12174
|
-
*
|
|
12175
|
-
* using private key as bigint
|
|
12176
|
-
* ```ts
|
|
12177
|
-
* var privateKey = 106982601049961974618234078204952280507266494766432547312316920283818886029212n;
|
|
12178
|
-
* var signer = new Signer({ privateKey });
|
|
12179
|
-
* ```
|
|
12180
|
-
*
|
|
12181
|
-
* <br>
|
|
12182
|
-
*
|
|
12183
|
-
* using the seed
|
|
12184
|
-
* ```ts
|
|
12185
|
-
* var signer = Signer.fromSeed("my seed");
|
|
12186
|
-
* ```
|
|
12187
|
-
*
|
|
12188
|
-
* <br>
|
|
12189
|
-
*
|
|
12190
|
-
* using private key in WIF format
|
|
12191
|
-
* ```ts
|
|
12192
|
-
* var signer = Signer.fromWif("L59UtJcTdNBnrH2QSBA5beSUhRufRu3g6tScDTite6Msuj7U93tM");
|
|
12193
|
-
* ```
|
|
12194
|
-
*
|
|
12195
|
-
* <br>
|
|
12196
|
-
*
|
|
12197
|
-
* defining a provider
|
|
12198
|
-
* ```ts
|
|
12199
|
-
* var provider = new Provider(["https://example.com/jsonrpc"]);
|
|
12200
|
-
* var privateKey = "ec8601a24f81decd57f4b611b5ac6eb801cb3780bb02c0f9cdfe9d09daaddf9c";
|
|
12201
|
-
* var signer = new Signer({ privateKey, provider });
|
|
12202
|
-
* ```
|
|
12203
|
-
*/
|
|
12204
|
-
class Signer {
|
|
12205
|
-
/**
|
|
12206
|
-
* The constructor receives de private key as hexstring, bigint or Uint8Array.
|
|
12207
|
-
* See also the functions [[Signer.fromWif]] and [[Signer.fromSeed]]
|
|
12208
|
-
* to create the signer from the WIF or Seed respectively.
|
|
12209
|
-
*
|
|
12210
|
-
* @param privateKey - Private key as hexstring, bigint or Uint8Array
|
|
12211
|
-
* @param compressed - compressed format is true by default
|
|
12212
|
-
* @param provider - provider to connect with the blockchain
|
|
12213
|
-
* @example
|
|
12214
|
-
* ```ts
|
|
12215
|
-
* const privateKey = "ec8601a24f81decd57f4b611b5ac6eb801cb3780bb02c0f9cdfe9d09daaddf9c";
|
|
12216
|
-
* cons signer = new Signer({ privateKey });
|
|
12217
|
-
* console.log(signer.getAddress());
|
|
12218
|
-
* // 1MbL6mG8ASAvSYdoMnGUfG3ZXkmQ2dpL5b
|
|
12219
|
-
* ```
|
|
12220
|
-
*/
|
|
12221
|
-
constructor(c) {
|
|
12222
|
-
this.compressed = typeof c.compressed === "undefined" ? true : c.compressed;
|
|
12223
|
-
this.privateKey = c.privateKey;
|
|
12224
|
-
this.provider = c.provider;
|
|
12225
|
-
if (c.serializer) {
|
|
12226
|
-
this.serializer = c.serializer;
|
|
12227
|
-
}
|
|
12228
|
-
else {
|
|
12229
|
-
this.serializer = new Serializer_1.Serializer(protocol_proto_json_1.default, {
|
|
12230
|
-
defaultTypeName: "active_transaction_data",
|
|
12231
|
-
bytesConversion: false,
|
|
12232
|
-
});
|
|
12233
|
-
}
|
|
12234
|
-
if (typeof c.privateKey === "string") {
|
|
12235
|
-
this.publicKey = secp.getPublicKey(c.privateKey, this.compressed);
|
|
12236
|
-
this.address = utils_1.bitcoinAddress(utils_1.toUint8Array(this.publicKey));
|
|
12237
|
-
}
|
|
12238
|
-
else {
|
|
12239
|
-
this.publicKey = secp.getPublicKey(c.privateKey, this.compressed);
|
|
12240
|
-
this.address = utils_1.bitcoinAddress(this.publicKey);
|
|
12241
|
-
}
|
|
12242
|
-
}
|
|
12243
|
-
/**
|
|
12244
|
-
* Function to import a private key from the WIF
|
|
12245
|
-
* @param wif - Private key in WIF format
|
|
12246
|
-
* @example
|
|
12247
|
-
* ```ts
|
|
12248
|
-
* const signer = Signer.fromWif("L59UtJcTdNBnrH2QSBA5beSUhRufRu3g6tScDTite6Msuj7U93tM")
|
|
12249
|
-
* console.log(signer.getAddress());
|
|
12250
|
-
* // 1MbL6mG8ASAvSYdoMnGUfG3ZXkmQ2dpL5b
|
|
12251
|
-
* ```
|
|
12252
|
-
* @returns Signer object
|
|
12253
|
-
*/
|
|
12254
|
-
static fromWif(wif) {
|
|
12255
|
-
const compressed = wif[0] !== "5";
|
|
12256
|
-
const privateKey = utils_1.bitcoinDecode(wif);
|
|
12257
|
-
return new Signer({
|
|
12258
|
-
privateKey: utils_1.toHexString(privateKey),
|
|
12259
|
-
compressed,
|
|
12260
|
-
});
|
|
12261
|
-
}
|
|
12262
|
-
/**
|
|
12263
|
-
* Function to import a private key from the seed
|
|
12264
|
-
* @param seed - Seed words
|
|
12265
|
-
* @param compressed -
|
|
12266
|
-
* @example
|
|
12267
|
-
* ```ts
|
|
12268
|
-
* const signer = Signer.fromSeed("my seed");
|
|
12269
|
-
* console.log(signer.getAddress());
|
|
12270
|
-
* // 1BqtgWBcqm9cSZ97avLGZGJdgso7wx6pCA
|
|
12271
|
-
* ```
|
|
12272
|
-
* @returns Signer object
|
|
12273
|
-
*/
|
|
12274
|
-
static fromSeed(seed, compressed) {
|
|
12275
|
-
const privateKey = sha256_1.sha256(seed);
|
|
12276
|
-
return new Signer({ privateKey, compressed });
|
|
12277
|
-
}
|
|
12278
|
-
/**
|
|
12279
|
-
* @param compressed - determines if the address should be
|
|
12280
|
-
* derived from the compressed public key (default) or the public key
|
|
12281
|
-
* @returns Signer address
|
|
12282
|
-
*/
|
|
12283
|
-
getAddress(compressed = true) {
|
|
12284
|
-
if (typeof this.privateKey === "string") {
|
|
12285
|
-
const publicKey = secp.getPublicKey(this.privateKey, compressed);
|
|
12286
|
-
return utils_1.bitcoinAddress(utils_1.toUint8Array(publicKey));
|
|
12287
|
-
}
|
|
12288
|
-
const publicKey = secp.getPublicKey(this.privateKey, compressed);
|
|
12289
|
-
return utils_1.bitcoinAddress(publicKey);
|
|
12290
|
-
}
|
|
12291
|
-
/**
|
|
12292
|
-
* Function to get the private key in hex format or wif format
|
|
12293
|
-
* @param format - The format must be "hex" (default) or "wif"
|
|
12294
|
-
* @param compressed - Optional arg when using WIF format. By default it
|
|
12295
|
-
* uses the compressed value defined in the signer
|
|
12296
|
-
* @example
|
|
12297
|
-
* ```ts
|
|
12298
|
-
* const signer = Signer.fromSeed("one two three four five six");
|
|
12299
|
-
* console.log(signer.getPrivateKey());
|
|
12300
|
-
* // bab7fd6e5bd624f4ea0c33f7e7219262a6fa93a945a8964d9f110148286b7b37
|
|
12301
|
-
*
|
|
12302
|
-
* console.log(signer.getPrivateKey("wif"));
|
|
12303
|
-
* // L3UfgFJWmbVziGB1uZBjkG1UjKkF7hhpXWY7mbTUdmycmvXCVtiL
|
|
12304
|
-
*
|
|
12305
|
-
* console.log(signer.getPrivateKey("wif", false));
|
|
12306
|
-
* // 5KEX4TMHG66fT7cM9HMZLmdp4hVq4LC4X2Fkg6zeypM5UteWmtd
|
|
12307
|
-
* ```
|
|
12308
|
-
*/
|
|
12309
|
-
getPrivateKey(format = "hex", compressed) {
|
|
12310
|
-
let stringPrivateKey;
|
|
12311
|
-
if (this.privateKey instanceof Uint8Array) {
|
|
12312
|
-
stringPrivateKey = utils_1.toHexString(this.privateKey);
|
|
12313
|
-
}
|
|
12314
|
-
else if (typeof this.privateKey === "string") {
|
|
12315
|
-
stringPrivateKey = this.privateKey;
|
|
12316
|
-
}
|
|
12317
|
-
else {
|
|
12318
|
-
stringPrivateKey = BigInt(this.privateKey).toString(16).padStart(64, "0");
|
|
12319
|
-
}
|
|
12320
|
-
const comp = compressed === undefined ? this.compressed : compressed;
|
|
12321
|
-
switch (format) {
|
|
12322
|
-
case "hex":
|
|
12323
|
-
return stringPrivateKey;
|
|
12324
|
-
case "wif":
|
|
12325
|
-
return utils_1.bitcoinEncode(utils_1.toUint8Array(stringPrivateKey), "private", comp);
|
|
12326
|
-
default:
|
|
12327
|
-
/* eslint-disable-next-line @typescript-eslint/restrict-template-expressions */
|
|
12328
|
-
throw new Error(`Invalid format ${format}`);
|
|
12329
|
-
}
|
|
12330
|
-
}
|
|
12331
|
-
/**
|
|
12332
|
-
* Function to sign a transaction. It's important to remark that
|
|
12333
|
-
* the transaction parameter is modified inside this function.
|
|
12334
|
-
* @param tx - Unsigned transaction
|
|
12335
|
-
* @returns
|
|
12336
|
-
*/
|
|
12337
|
-
async signTransaction(tx) {
|
|
12338
|
-
if (!tx.active)
|
|
12339
|
-
throw new Error("Active data is not defined");
|
|
12340
|
-
const hash = sha256_1.sha256(utils_1.decodeBase64(tx.active));
|
|
12341
|
-
const [compSignature, recovery] = await secp.sign(hash, this.privateKey, {
|
|
12342
|
-
recovered: true,
|
|
12343
|
-
canonical: true,
|
|
12344
|
-
der: false, // compact signature
|
|
12345
|
-
});
|
|
12346
|
-
const compactSignature = new Uint8Array(65);
|
|
12347
|
-
compactSignature.set([recovery + 31], 0);
|
|
12348
|
-
compactSignature.set(compSignature, 1);
|
|
12349
|
-
tx.signature_data = utils_1.encodeBase64(compactSignature);
|
|
12350
|
-
const multihash = `0x1220${utils_1.toHexString(hash)}`; // 12: code sha2-256. 20: length (32 bytes)
|
|
12351
|
-
tx.id = multihash;
|
|
12352
|
-
return tx;
|
|
12353
|
-
}
|
|
12354
|
-
/**
|
|
12355
|
-
* Function to sign and send a transaction. It internally uses
|
|
12356
|
-
* [[Provider.sendTransaction]]
|
|
12357
|
-
* @param tx - Transaction to send. It will be signed inside this function
|
|
12358
|
-
* if it is not signed yet
|
|
12359
|
-
* @param _abis - Collection of Abis to parse the operations in the
|
|
12360
|
-
* transaction. This parameter is optional.
|
|
12361
|
-
* @returns
|
|
12362
|
-
*/
|
|
12363
|
-
async sendTransaction(tx, _abis) {
|
|
12364
|
-
if (!tx.signature_data || !tx.id)
|
|
12365
|
-
await this.signTransaction(tx);
|
|
12366
|
-
if (!this.provider)
|
|
12367
|
-
throw new Error("provider is undefined");
|
|
12368
|
-
return this.provider.sendTransaction(tx);
|
|
12369
|
-
}
|
|
12370
|
-
/**
|
|
12371
|
-
* Function to recover the public key from a signed
|
|
12372
|
-
* transaction or block.
|
|
12373
|
-
* The output format can be compressed (default) or uncompressed.
|
|
12374
|
-
*
|
|
12375
|
-
* @example
|
|
12376
|
-
* ```ts
|
|
12377
|
-
* const publicKey = await Signer.recoverPublicKey(tx);
|
|
12378
|
-
* ```
|
|
12379
|
-
*
|
|
12380
|
-
* If the signature data contains more data, like in the
|
|
12381
|
-
* blocks for PoW consensus, use the "transformSignature"
|
|
12382
|
-
* function to extract the signature.
|
|
12383
|
-
*
|
|
12384
|
-
* @example
|
|
12385
|
-
* ```ts
|
|
12386
|
-
* const powDescriptorJson = {
|
|
12387
|
-
* nested: {
|
|
12388
|
-
* mypackage: {
|
|
12389
|
-
* nested: {
|
|
12390
|
-
* pow_signature_data: {
|
|
12391
|
-
* fields: {
|
|
12392
|
-
* nonce: {
|
|
12393
|
-
* type: "bytes",
|
|
12394
|
-
* id: 1,
|
|
12395
|
-
* },
|
|
12396
|
-
* recoverable_signature: {
|
|
12397
|
-
* type: "bytes",
|
|
12398
|
-
* id: 2,
|
|
12399
|
-
* },
|
|
12400
|
-
* },
|
|
12401
|
-
* },
|
|
12402
|
-
* },
|
|
12403
|
-
* },
|
|
12404
|
-
* },
|
|
12405
|
-
* };
|
|
12406
|
-
*
|
|
12407
|
-
* const serializer = new Serializer(powDescriptorJson, {
|
|
12408
|
-
* defaultTypeName: "pow_signature_data",
|
|
12409
|
-
* });
|
|
12410
|
-
*
|
|
12411
|
-
* const signer = await Signer.recoverPublicKey(block, {
|
|
12412
|
-
* transformSignature: async (signatureData) => {
|
|
12413
|
-
* const powSignatureData = await serializer.deserialize(signatureData);
|
|
12414
|
-
* return powSignatureData.recoverable_signature;
|
|
12415
|
-
* },
|
|
12416
|
-
* });
|
|
12417
|
-
* ```
|
|
12418
|
-
*/
|
|
12419
|
-
static async recoverPublicKey(txOrBlock, opts) {
|
|
12420
|
-
if (!txOrBlock.active)
|
|
12421
|
-
throw new Error("active is not defined");
|
|
12422
|
-
if (!txOrBlock.signature_data)
|
|
12423
|
-
throw new Error("signature_data is not defined");
|
|
12424
|
-
let signatureData = txOrBlock.signature_data;
|
|
12425
|
-
if (opts && typeof opts.transformSignature === "function") {
|
|
12426
|
-
signatureData = await opts.transformSignature(txOrBlock.signature_data);
|
|
12427
|
-
}
|
|
12428
|
-
let compressed = true;
|
|
12429
|
-
if (opts && typeof opts.compressed !== "undefined") {
|
|
12430
|
-
compressed = opts.compressed;
|
|
12431
|
-
}
|
|
12432
|
-
const hash = sha256_1.sha256(utils_1.decodeBase64(txOrBlock.active));
|
|
12433
|
-
const compactSignatureHex = utils_1.toHexString(utils_1.decodeBase64(signatureData));
|
|
12434
|
-
const recovery = Number(`0x${compactSignatureHex.slice(0, 2)}`) - 31;
|
|
12435
|
-
const rHex = compactSignatureHex.slice(2, 66);
|
|
12436
|
-
const sHex = compactSignatureHex.slice(66);
|
|
12437
|
-
const r = BigInt(`0x${rHex}`);
|
|
12438
|
-
const s = BigInt(`0x${sHex}`);
|
|
12439
|
-
const sig = new secp.Signature(r, s);
|
|
12440
|
-
const publicKey = secp.recoverPublicKey(utils_1.toHexString(hash), sig.toHex(), recovery);
|
|
12441
|
-
if (!publicKey)
|
|
12442
|
-
throw new Error("Public key cannot be recovered");
|
|
12443
|
-
if (!compressed)
|
|
12444
|
-
return publicKey;
|
|
12445
|
-
return secp.Point.fromHex(publicKey).toHex(true);
|
|
12446
|
-
}
|
|
12447
|
-
/**
|
|
12448
|
-
* Function to recover the signer address from a signed
|
|
12449
|
-
* transaction or block.
|
|
12450
|
-
* The output format can be compressed (default) or uncompressed.
|
|
12451
|
-
* @example
|
|
12452
|
-
* ```ts
|
|
12453
|
-
* const publicKey = await Signer.recoverAddress(tx);
|
|
12454
|
-
* ```
|
|
12455
|
-
*
|
|
12456
|
-
* If the signature data contains more data, like in the
|
|
12457
|
-
* blocks for PoW consensus, use the "transformSignature"
|
|
12458
|
-
* function to extract the signature.
|
|
12459
|
-
*
|
|
12460
|
-
* @example
|
|
12461
|
-
* ```ts
|
|
12462
|
-
* const powDescriptorJson = {
|
|
12463
|
-
* nested: {
|
|
12464
|
-
* mypackage: {
|
|
12465
|
-
* nested: {
|
|
12466
|
-
* pow_signature_data: {
|
|
12467
|
-
* fields: {
|
|
12468
|
-
* nonce: {
|
|
12469
|
-
* type: "bytes",
|
|
12470
|
-
* id: 1,
|
|
12471
|
-
* },
|
|
12472
|
-
* recoverable_signature: {
|
|
12473
|
-
* type: "bytes",
|
|
12474
|
-
* id: 2,
|
|
12475
|
-
* },
|
|
12476
|
-
* },
|
|
12477
|
-
* },
|
|
12478
|
-
* },
|
|
12479
|
-
* },
|
|
12480
|
-
* },
|
|
12481
|
-
* };
|
|
12482
|
-
*
|
|
12483
|
-
* const serializer = new Serializer(powDescriptorJson, {
|
|
12484
|
-
* defaultTypeName: "pow_signature_data",
|
|
12485
|
-
* });
|
|
12486
|
-
*
|
|
12487
|
-
* const signer = await Signer.recoverAddress(block, {
|
|
12488
|
-
* transformSignature: async (signatureData) => {
|
|
12489
|
-
* const powSignatureData = await serializer.deserialize(signatureData);
|
|
12490
|
-
* return powSignatureData.recoverable_signature;
|
|
12491
|
-
* },
|
|
12492
|
-
* });
|
|
12493
|
-
* ```
|
|
12494
|
-
*/
|
|
12495
|
-
static async recoverAddress(txOrBlock, opts) {
|
|
12496
|
-
const publicKey = await Signer.recoverPublicKey(txOrBlock, opts);
|
|
12497
|
-
return utils_1.bitcoinAddress(utils_1.toUint8Array(publicKey));
|
|
12498
|
-
}
|
|
12499
|
-
/**
|
|
12500
|
-
* Function to encode a transaction
|
|
12501
|
-
* @param activeData - Active data consists of nonce, rc_limit, and
|
|
12502
|
-
* operations. Do not set the nonce to get it from the blockchain
|
|
12503
|
-
* using the provider. The rc_limit is 1000000 by default.
|
|
12504
|
-
* @returns A transaction encoded. The active field is encoded in
|
|
12505
|
-
* base64url
|
|
12506
|
-
*/
|
|
12507
|
-
async encodeTransaction(activeData) {
|
|
12508
|
-
let { nonce } = activeData;
|
|
12509
|
-
if (activeData.nonce === undefined) {
|
|
12510
|
-
if (!this.provider)
|
|
12511
|
-
throw new Error("Cannot get the nonce because provider is undefined. To skip this call set a nonce in the parameters");
|
|
12512
|
-
// TODO: Option to resolve names
|
|
12513
|
-
// this depends on the final architecture for names on Koinos
|
|
12514
|
-
nonce = await this.provider.getNonce(this.getAddress());
|
|
12515
|
-
}
|
|
12516
|
-
const rcLimit = activeData.rc_limit === undefined ? 1000000 : activeData.rc_limit;
|
|
12517
|
-
const operations = activeData.operations ? activeData.operations : [];
|
|
12518
|
-
const activeData2 = {
|
|
12519
|
-
rc_limit: rcLimit,
|
|
12520
|
-
nonce,
|
|
12521
|
-
operations,
|
|
12522
|
-
};
|
|
12523
|
-
const buffer = await this.serializer.serialize(activeData2);
|
|
12524
|
-
return {
|
|
12525
|
-
active: utils_1.encodeBase64(buffer),
|
|
12526
|
-
};
|
|
12527
|
-
}
|
|
12528
|
-
/**
|
|
12529
|
-
* Function to decode a transaction
|
|
12530
|
-
*/
|
|
12531
|
-
async decodeTransaction(tx) {
|
|
12532
|
-
if (!tx.active)
|
|
12533
|
-
throw new Error("Active data is not defined");
|
|
12534
|
-
return this.serializer.deserialize(tx.active);
|
|
12535
|
-
}
|
|
12536
|
-
}
|
|
12537
|
-
exports.Signer = Signer;
|
|
12538
|
-
exports.default = Signer;
|
|
12119
|
+
|
|
12120
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12121
|
+
if (k2 === undefined) k2 = k;
|
|
12122
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12123
|
+
}) : (function(o, m, k, k2) {
|
|
12124
|
+
if (k2 === undefined) k2 = k;
|
|
12125
|
+
o[k2] = m[k];
|
|
12126
|
+
}));
|
|
12127
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
12128
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
12129
|
+
}) : function(o, v) {
|
|
12130
|
+
o["default"] = v;
|
|
12131
|
+
});
|
|
12132
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
12133
|
+
if (mod && mod.__esModule) return mod;
|
|
12134
|
+
var result = {};
|
|
12135
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
12136
|
+
__setModuleDefault(result, mod);
|
|
12137
|
+
return result;
|
|
12138
|
+
};
|
|
12139
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12140
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12141
|
+
};
|
|
12142
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
12143
|
+
exports.Signer = void 0;
|
|
12144
|
+
/* eslint-disable no-param-reassign */
|
|
12145
|
+
const sha256_1 = __webpack_require__(5374);
|
|
12146
|
+
const secp = __importStar(__webpack_require__(1337));
|
|
12147
|
+
const protocol_proto_json_1 = __importDefault(__webpack_require__(6139));
|
|
12148
|
+
const utils_1 = __webpack_require__(8593);
|
|
12149
|
+
const Serializer_1 = __webpack_require__(7187);
|
|
12150
|
+
/**
|
|
12151
|
+
* The Signer Class contains the private key needed to sign transactions.
|
|
12152
|
+
* It can be created using the seed, wif, or private key
|
|
12153
|
+
*
|
|
12154
|
+
* @example
|
|
12155
|
+
* using private key as hex string
|
|
12156
|
+
* ```ts
|
|
12157
|
+
* var privateKey = "ec8601a24f81decd57f4b611b5ac6eb801cb3780bb02c0f9cdfe9d09daaddf9c";
|
|
12158
|
+
* var signer = new Signer({ privateKey });
|
|
12159
|
+
* ```
|
|
12160
|
+
* <br>
|
|
12161
|
+
*
|
|
12162
|
+
* using private key as Uint8Array
|
|
12163
|
+
* ```ts
|
|
12164
|
+
* var buffer = new Uint8Array([
|
|
12165
|
+
* 236, 134, 1, 162, 79, 129, 222, 205,
|
|
12166
|
+
* 87, 244, 182, 17, 181, 172, 110, 184,
|
|
12167
|
+
* 1, 203, 55, 128, 187, 2, 192, 249,
|
|
12168
|
+
* 205, 254, 157, 9, 218, 173, 223, 156
|
|
12169
|
+
* ]);
|
|
12170
|
+
* var signer = new Signer({ privateKey: buffer });
|
|
12171
|
+
* ```
|
|
12172
|
+
*
|
|
12173
|
+
* <br>
|
|
12174
|
+
*
|
|
12175
|
+
* using private key as bigint
|
|
12176
|
+
* ```ts
|
|
12177
|
+
* var privateKey = 106982601049961974618234078204952280507266494766432547312316920283818886029212n;
|
|
12178
|
+
* var signer = new Signer({ privateKey });
|
|
12179
|
+
* ```
|
|
12180
|
+
*
|
|
12181
|
+
* <br>
|
|
12182
|
+
*
|
|
12183
|
+
* using the seed
|
|
12184
|
+
* ```ts
|
|
12185
|
+
* var signer = Signer.fromSeed("my seed");
|
|
12186
|
+
* ```
|
|
12187
|
+
*
|
|
12188
|
+
* <br>
|
|
12189
|
+
*
|
|
12190
|
+
* using private key in WIF format
|
|
12191
|
+
* ```ts
|
|
12192
|
+
* var signer = Signer.fromWif("L59UtJcTdNBnrH2QSBA5beSUhRufRu3g6tScDTite6Msuj7U93tM");
|
|
12193
|
+
* ```
|
|
12194
|
+
*
|
|
12195
|
+
* <br>
|
|
12196
|
+
*
|
|
12197
|
+
* defining a provider
|
|
12198
|
+
* ```ts
|
|
12199
|
+
* var provider = new Provider(["https://example.com/jsonrpc"]);
|
|
12200
|
+
* var privateKey = "ec8601a24f81decd57f4b611b5ac6eb801cb3780bb02c0f9cdfe9d09daaddf9c";
|
|
12201
|
+
* var signer = new Signer({ privateKey, provider });
|
|
12202
|
+
* ```
|
|
12203
|
+
*/
|
|
12204
|
+
class Signer {
|
|
12205
|
+
/**
|
|
12206
|
+
* The constructor receives de private key as hexstring, bigint or Uint8Array.
|
|
12207
|
+
* See also the functions [[Signer.fromWif]] and [[Signer.fromSeed]]
|
|
12208
|
+
* to create the signer from the WIF or Seed respectively.
|
|
12209
|
+
*
|
|
12210
|
+
* @param privateKey - Private key as hexstring, bigint or Uint8Array
|
|
12211
|
+
* @param compressed - compressed format is true by default
|
|
12212
|
+
* @param provider - provider to connect with the blockchain
|
|
12213
|
+
* @example
|
|
12214
|
+
* ```ts
|
|
12215
|
+
* const privateKey = "ec8601a24f81decd57f4b611b5ac6eb801cb3780bb02c0f9cdfe9d09daaddf9c";
|
|
12216
|
+
* cons signer = new Signer({ privateKey });
|
|
12217
|
+
* console.log(signer.getAddress());
|
|
12218
|
+
* // 1MbL6mG8ASAvSYdoMnGUfG3ZXkmQ2dpL5b
|
|
12219
|
+
* ```
|
|
12220
|
+
*/
|
|
12221
|
+
constructor(c) {
|
|
12222
|
+
this.compressed = typeof c.compressed === "undefined" ? true : c.compressed;
|
|
12223
|
+
this.privateKey = c.privateKey;
|
|
12224
|
+
this.provider = c.provider;
|
|
12225
|
+
if (c.serializer) {
|
|
12226
|
+
this.serializer = c.serializer;
|
|
12227
|
+
}
|
|
12228
|
+
else {
|
|
12229
|
+
this.serializer = new Serializer_1.Serializer(protocol_proto_json_1.default, {
|
|
12230
|
+
defaultTypeName: "active_transaction_data",
|
|
12231
|
+
bytesConversion: false,
|
|
12232
|
+
});
|
|
12233
|
+
}
|
|
12234
|
+
if (typeof c.privateKey === "string") {
|
|
12235
|
+
this.publicKey = secp.getPublicKey(c.privateKey, this.compressed);
|
|
12236
|
+
this.address = utils_1.bitcoinAddress(utils_1.toUint8Array(this.publicKey));
|
|
12237
|
+
}
|
|
12238
|
+
else {
|
|
12239
|
+
this.publicKey = secp.getPublicKey(c.privateKey, this.compressed);
|
|
12240
|
+
this.address = utils_1.bitcoinAddress(this.publicKey);
|
|
12241
|
+
}
|
|
12242
|
+
}
|
|
12243
|
+
/**
|
|
12244
|
+
* Function to import a private key from the WIF
|
|
12245
|
+
* @param wif - Private key in WIF format
|
|
12246
|
+
* @example
|
|
12247
|
+
* ```ts
|
|
12248
|
+
* const signer = Signer.fromWif("L59UtJcTdNBnrH2QSBA5beSUhRufRu3g6tScDTite6Msuj7U93tM")
|
|
12249
|
+
* console.log(signer.getAddress());
|
|
12250
|
+
* // 1MbL6mG8ASAvSYdoMnGUfG3ZXkmQ2dpL5b
|
|
12251
|
+
* ```
|
|
12252
|
+
* @returns Signer object
|
|
12253
|
+
*/
|
|
12254
|
+
static fromWif(wif) {
|
|
12255
|
+
const compressed = wif[0] !== "5";
|
|
12256
|
+
const privateKey = utils_1.bitcoinDecode(wif);
|
|
12257
|
+
return new Signer({
|
|
12258
|
+
privateKey: utils_1.toHexString(privateKey),
|
|
12259
|
+
compressed,
|
|
12260
|
+
});
|
|
12261
|
+
}
|
|
12262
|
+
/**
|
|
12263
|
+
* Function to import a private key from the seed
|
|
12264
|
+
* @param seed - Seed words
|
|
12265
|
+
* @param compressed -
|
|
12266
|
+
* @example
|
|
12267
|
+
* ```ts
|
|
12268
|
+
* const signer = Signer.fromSeed("my seed");
|
|
12269
|
+
* console.log(signer.getAddress());
|
|
12270
|
+
* // 1BqtgWBcqm9cSZ97avLGZGJdgso7wx6pCA
|
|
12271
|
+
* ```
|
|
12272
|
+
* @returns Signer object
|
|
12273
|
+
*/
|
|
12274
|
+
static fromSeed(seed, compressed) {
|
|
12275
|
+
const privateKey = sha256_1.sha256(seed);
|
|
12276
|
+
return new Signer({ privateKey, compressed });
|
|
12277
|
+
}
|
|
12278
|
+
/**
|
|
12279
|
+
* @param compressed - determines if the address should be
|
|
12280
|
+
* derived from the compressed public key (default) or the public key
|
|
12281
|
+
* @returns Signer address
|
|
12282
|
+
*/
|
|
12283
|
+
getAddress(compressed = true) {
|
|
12284
|
+
if (typeof this.privateKey === "string") {
|
|
12285
|
+
const publicKey = secp.getPublicKey(this.privateKey, compressed);
|
|
12286
|
+
return utils_1.bitcoinAddress(utils_1.toUint8Array(publicKey));
|
|
12287
|
+
}
|
|
12288
|
+
const publicKey = secp.getPublicKey(this.privateKey, compressed);
|
|
12289
|
+
return utils_1.bitcoinAddress(publicKey);
|
|
12290
|
+
}
|
|
12291
|
+
/**
|
|
12292
|
+
* Function to get the private key in hex format or wif format
|
|
12293
|
+
* @param format - The format must be "hex" (default) or "wif"
|
|
12294
|
+
* @param compressed - Optional arg when using WIF format. By default it
|
|
12295
|
+
* uses the compressed value defined in the signer
|
|
12296
|
+
* @example
|
|
12297
|
+
* ```ts
|
|
12298
|
+
* const signer = Signer.fromSeed("one two three four five six");
|
|
12299
|
+
* console.log(signer.getPrivateKey());
|
|
12300
|
+
* // bab7fd6e5bd624f4ea0c33f7e7219262a6fa93a945a8964d9f110148286b7b37
|
|
12301
|
+
*
|
|
12302
|
+
* console.log(signer.getPrivateKey("wif"));
|
|
12303
|
+
* // L3UfgFJWmbVziGB1uZBjkG1UjKkF7hhpXWY7mbTUdmycmvXCVtiL
|
|
12304
|
+
*
|
|
12305
|
+
* console.log(signer.getPrivateKey("wif", false));
|
|
12306
|
+
* // 5KEX4TMHG66fT7cM9HMZLmdp4hVq4LC4X2Fkg6zeypM5UteWmtd
|
|
12307
|
+
* ```
|
|
12308
|
+
*/
|
|
12309
|
+
getPrivateKey(format = "hex", compressed) {
|
|
12310
|
+
let stringPrivateKey;
|
|
12311
|
+
if (this.privateKey instanceof Uint8Array) {
|
|
12312
|
+
stringPrivateKey = utils_1.toHexString(this.privateKey);
|
|
12313
|
+
}
|
|
12314
|
+
else if (typeof this.privateKey === "string") {
|
|
12315
|
+
stringPrivateKey = this.privateKey;
|
|
12316
|
+
}
|
|
12317
|
+
else {
|
|
12318
|
+
stringPrivateKey = BigInt(this.privateKey).toString(16).padStart(64, "0");
|
|
12319
|
+
}
|
|
12320
|
+
const comp = compressed === undefined ? this.compressed : compressed;
|
|
12321
|
+
switch (format) {
|
|
12322
|
+
case "hex":
|
|
12323
|
+
return stringPrivateKey;
|
|
12324
|
+
case "wif":
|
|
12325
|
+
return utils_1.bitcoinEncode(utils_1.toUint8Array(stringPrivateKey), "private", comp);
|
|
12326
|
+
default:
|
|
12327
|
+
/* eslint-disable-next-line @typescript-eslint/restrict-template-expressions */
|
|
12328
|
+
throw new Error(`Invalid format ${format}`);
|
|
12329
|
+
}
|
|
12330
|
+
}
|
|
12331
|
+
/**
|
|
12332
|
+
* Function to sign a transaction. It's important to remark that
|
|
12333
|
+
* the transaction parameter is modified inside this function.
|
|
12334
|
+
* @param tx - Unsigned transaction
|
|
12335
|
+
* @returns
|
|
12336
|
+
*/
|
|
12337
|
+
async signTransaction(tx) {
|
|
12338
|
+
if (!tx.active)
|
|
12339
|
+
throw new Error("Active data is not defined");
|
|
12340
|
+
const hash = sha256_1.sha256(utils_1.decodeBase64(tx.active));
|
|
12341
|
+
const [compSignature, recovery] = await secp.sign(hash, this.privateKey, {
|
|
12342
|
+
recovered: true,
|
|
12343
|
+
canonical: true,
|
|
12344
|
+
der: false, // compact signature
|
|
12345
|
+
});
|
|
12346
|
+
const compactSignature = new Uint8Array(65);
|
|
12347
|
+
compactSignature.set([recovery + 31], 0);
|
|
12348
|
+
compactSignature.set(compSignature, 1);
|
|
12349
|
+
tx.signature_data = utils_1.encodeBase64(compactSignature);
|
|
12350
|
+
const multihash = `0x1220${utils_1.toHexString(hash)}`; // 12: code sha2-256. 20: length (32 bytes)
|
|
12351
|
+
tx.id = multihash;
|
|
12352
|
+
return tx;
|
|
12353
|
+
}
|
|
12354
|
+
/**
|
|
12355
|
+
* Function to sign and send a transaction. It internally uses
|
|
12356
|
+
* [[Provider.sendTransaction]]
|
|
12357
|
+
* @param tx - Transaction to send. It will be signed inside this function
|
|
12358
|
+
* if it is not signed yet
|
|
12359
|
+
* @param _abis - Collection of Abis to parse the operations in the
|
|
12360
|
+
* transaction. This parameter is optional.
|
|
12361
|
+
* @returns
|
|
12362
|
+
*/
|
|
12363
|
+
async sendTransaction(tx, _abis) {
|
|
12364
|
+
if (!tx.signature_data || !tx.id)
|
|
12365
|
+
await this.signTransaction(tx);
|
|
12366
|
+
if (!this.provider)
|
|
12367
|
+
throw new Error("provider is undefined");
|
|
12368
|
+
return this.provider.sendTransaction(tx);
|
|
12369
|
+
}
|
|
12370
|
+
/**
|
|
12371
|
+
* Function to recover the public key from a signed
|
|
12372
|
+
* transaction or block.
|
|
12373
|
+
* The output format can be compressed (default) or uncompressed.
|
|
12374
|
+
*
|
|
12375
|
+
* @example
|
|
12376
|
+
* ```ts
|
|
12377
|
+
* const publicKey = await Signer.recoverPublicKey(tx);
|
|
12378
|
+
* ```
|
|
12379
|
+
*
|
|
12380
|
+
* If the signature data contains more data, like in the
|
|
12381
|
+
* blocks for PoW consensus, use the "transformSignature"
|
|
12382
|
+
* function to extract the signature.
|
|
12383
|
+
*
|
|
12384
|
+
* @example
|
|
12385
|
+
* ```ts
|
|
12386
|
+
* const powDescriptorJson = {
|
|
12387
|
+
* nested: {
|
|
12388
|
+
* mypackage: {
|
|
12389
|
+
* nested: {
|
|
12390
|
+
* pow_signature_data: {
|
|
12391
|
+
* fields: {
|
|
12392
|
+
* nonce: {
|
|
12393
|
+
* type: "bytes",
|
|
12394
|
+
* id: 1,
|
|
12395
|
+
* },
|
|
12396
|
+
* recoverable_signature: {
|
|
12397
|
+
* type: "bytes",
|
|
12398
|
+
* id: 2,
|
|
12399
|
+
* },
|
|
12400
|
+
* },
|
|
12401
|
+
* },
|
|
12402
|
+
* },
|
|
12403
|
+
* },
|
|
12404
|
+
* },
|
|
12405
|
+
* };
|
|
12406
|
+
*
|
|
12407
|
+
* const serializer = new Serializer(powDescriptorJson, {
|
|
12408
|
+
* defaultTypeName: "pow_signature_data",
|
|
12409
|
+
* });
|
|
12410
|
+
*
|
|
12411
|
+
* const signer = await Signer.recoverPublicKey(block, {
|
|
12412
|
+
* transformSignature: async (signatureData) => {
|
|
12413
|
+
* const powSignatureData = await serializer.deserialize(signatureData);
|
|
12414
|
+
* return powSignatureData.recoverable_signature;
|
|
12415
|
+
* },
|
|
12416
|
+
* });
|
|
12417
|
+
* ```
|
|
12418
|
+
*/
|
|
12419
|
+
static async recoverPublicKey(txOrBlock, opts) {
|
|
12420
|
+
if (!txOrBlock.active)
|
|
12421
|
+
throw new Error("active is not defined");
|
|
12422
|
+
if (!txOrBlock.signature_data)
|
|
12423
|
+
throw new Error("signature_data is not defined");
|
|
12424
|
+
let signatureData = txOrBlock.signature_data;
|
|
12425
|
+
if (opts && typeof opts.transformSignature === "function") {
|
|
12426
|
+
signatureData = await opts.transformSignature(txOrBlock.signature_data);
|
|
12427
|
+
}
|
|
12428
|
+
let compressed = true;
|
|
12429
|
+
if (opts && typeof opts.compressed !== "undefined") {
|
|
12430
|
+
compressed = opts.compressed;
|
|
12431
|
+
}
|
|
12432
|
+
const hash = sha256_1.sha256(utils_1.decodeBase64(txOrBlock.active));
|
|
12433
|
+
const compactSignatureHex = utils_1.toHexString(utils_1.decodeBase64(signatureData));
|
|
12434
|
+
const recovery = Number(`0x${compactSignatureHex.slice(0, 2)}`) - 31;
|
|
12435
|
+
const rHex = compactSignatureHex.slice(2, 66);
|
|
12436
|
+
const sHex = compactSignatureHex.slice(66);
|
|
12437
|
+
const r = BigInt(`0x${rHex}`);
|
|
12438
|
+
const s = BigInt(`0x${sHex}`);
|
|
12439
|
+
const sig = new secp.Signature(r, s);
|
|
12440
|
+
const publicKey = secp.recoverPublicKey(utils_1.toHexString(hash), sig.toHex(), recovery);
|
|
12441
|
+
if (!publicKey)
|
|
12442
|
+
throw new Error("Public key cannot be recovered");
|
|
12443
|
+
if (!compressed)
|
|
12444
|
+
return publicKey;
|
|
12445
|
+
return secp.Point.fromHex(publicKey).toHex(true);
|
|
12446
|
+
}
|
|
12447
|
+
/**
|
|
12448
|
+
* Function to recover the signer address from a signed
|
|
12449
|
+
* transaction or block.
|
|
12450
|
+
* The output format can be compressed (default) or uncompressed.
|
|
12451
|
+
* @example
|
|
12452
|
+
* ```ts
|
|
12453
|
+
* const publicKey = await Signer.recoverAddress(tx);
|
|
12454
|
+
* ```
|
|
12455
|
+
*
|
|
12456
|
+
* If the signature data contains more data, like in the
|
|
12457
|
+
* blocks for PoW consensus, use the "transformSignature"
|
|
12458
|
+
* function to extract the signature.
|
|
12459
|
+
*
|
|
12460
|
+
* @example
|
|
12461
|
+
* ```ts
|
|
12462
|
+
* const powDescriptorJson = {
|
|
12463
|
+
* nested: {
|
|
12464
|
+
* mypackage: {
|
|
12465
|
+
* nested: {
|
|
12466
|
+
* pow_signature_data: {
|
|
12467
|
+
* fields: {
|
|
12468
|
+
* nonce: {
|
|
12469
|
+
* type: "bytes",
|
|
12470
|
+
* id: 1,
|
|
12471
|
+
* },
|
|
12472
|
+
* recoverable_signature: {
|
|
12473
|
+
* type: "bytes",
|
|
12474
|
+
* id: 2,
|
|
12475
|
+
* },
|
|
12476
|
+
* },
|
|
12477
|
+
* },
|
|
12478
|
+
* },
|
|
12479
|
+
* },
|
|
12480
|
+
* },
|
|
12481
|
+
* };
|
|
12482
|
+
*
|
|
12483
|
+
* const serializer = new Serializer(powDescriptorJson, {
|
|
12484
|
+
* defaultTypeName: "pow_signature_data",
|
|
12485
|
+
* });
|
|
12486
|
+
*
|
|
12487
|
+
* const signer = await Signer.recoverAddress(block, {
|
|
12488
|
+
* transformSignature: async (signatureData) => {
|
|
12489
|
+
* const powSignatureData = await serializer.deserialize(signatureData);
|
|
12490
|
+
* return powSignatureData.recoverable_signature;
|
|
12491
|
+
* },
|
|
12492
|
+
* });
|
|
12493
|
+
* ```
|
|
12494
|
+
*/
|
|
12495
|
+
static async recoverAddress(txOrBlock, opts) {
|
|
12496
|
+
const publicKey = await Signer.recoverPublicKey(txOrBlock, opts);
|
|
12497
|
+
return utils_1.bitcoinAddress(utils_1.toUint8Array(publicKey));
|
|
12498
|
+
}
|
|
12499
|
+
/**
|
|
12500
|
+
* Function to encode a transaction
|
|
12501
|
+
* @param activeData - Active data consists of nonce, rc_limit, and
|
|
12502
|
+
* operations. Do not set the nonce to get it from the blockchain
|
|
12503
|
+
* using the provider. The rc_limit is 1000000 by default.
|
|
12504
|
+
* @returns A transaction encoded. The active field is encoded in
|
|
12505
|
+
* base64url
|
|
12506
|
+
*/
|
|
12507
|
+
async encodeTransaction(activeData) {
|
|
12508
|
+
let { nonce } = activeData;
|
|
12509
|
+
if (activeData.nonce === undefined) {
|
|
12510
|
+
if (!this.provider)
|
|
12511
|
+
throw new Error("Cannot get the nonce because provider is undefined. To skip this call set a nonce in the parameters");
|
|
12512
|
+
// TODO: Option to resolve names
|
|
12513
|
+
// this depends on the final architecture for names on Koinos
|
|
12514
|
+
nonce = await this.provider.getNonce(this.getAddress());
|
|
12515
|
+
}
|
|
12516
|
+
const rcLimit = activeData.rc_limit === undefined ? 1000000 : activeData.rc_limit;
|
|
12517
|
+
const operations = activeData.operations ? activeData.operations : [];
|
|
12518
|
+
const activeData2 = {
|
|
12519
|
+
rc_limit: rcLimit,
|
|
12520
|
+
nonce,
|
|
12521
|
+
operations,
|
|
12522
|
+
};
|
|
12523
|
+
const buffer = await this.serializer.serialize(activeData2);
|
|
12524
|
+
return {
|
|
12525
|
+
active: utils_1.encodeBase64(buffer),
|
|
12526
|
+
};
|
|
12527
|
+
}
|
|
12528
|
+
/**
|
|
12529
|
+
* Function to decode a transaction
|
|
12530
|
+
*/
|
|
12531
|
+
async decodeTransaction(tx) {
|
|
12532
|
+
if (!tx.active)
|
|
12533
|
+
throw new Error("Active data is not defined");
|
|
12534
|
+
return this.serializer.deserialize(tx.active);
|
|
12535
|
+
}
|
|
12536
|
+
}
|
|
12537
|
+
exports.Signer = Signer;
|
|
12538
|
+
exports.default = Signer;
|
|
12539
12539
|
|
|
12540
12540
|
|
|
12541
12541
|
/***/ }),
|
|
@@ -12544,38 +12544,38 @@ exports.default = Signer;
|
|
|
12544
12544
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
12545
12545
|
|
|
12546
12546
|
"use strict";
|
|
12547
|
-
|
|
12548
|
-
/*! koilib - MIT License (c) Julian Gonzalez (joticajulian@gmail.com) */
|
|
12549
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12550
|
-
if (k2 === undefined) k2 = k;
|
|
12551
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12552
|
-
}) : (function(o, m, k, k2) {
|
|
12553
|
-
if (k2 === undefined) k2 = k;
|
|
12554
|
-
o[k2] = m[k];
|
|
12555
|
-
}));
|
|
12556
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
12557
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
12558
|
-
}) : function(o, v) {
|
|
12559
|
-
o["default"] = v;
|
|
12560
|
-
});
|
|
12561
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
12562
|
-
if (mod && mod.__esModule) return mod;
|
|
12563
|
-
var result = {};
|
|
12564
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
12565
|
-
__setModuleDefault(result, mod);
|
|
12566
|
-
return result;
|
|
12567
|
-
};
|
|
12568
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
12569
|
-
const utils = __importStar(__webpack_require__(8593));
|
|
12570
|
-
const Contract_1 = __webpack_require__(9822);
|
|
12571
|
-
const Signer_1 = __webpack_require__(6991);
|
|
12572
|
-
const Provider_1 = __webpack_require__(5635);
|
|
12573
|
-
const Serializer_1 = __webpack_require__(7187);
|
|
12574
|
-
window.utils = utils;
|
|
12575
|
-
window.Contract = Contract_1.Contract;
|
|
12576
|
-
window.Signer = Signer_1.Signer;
|
|
12577
|
-
window.Provider = Provider_1.Provider;
|
|
12578
|
-
window.Serializer = Serializer_1.Serializer;
|
|
12547
|
+
|
|
12548
|
+
/*! koilib - MIT License (c) Julian Gonzalez (joticajulian@gmail.com) */
|
|
12549
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12550
|
+
if (k2 === undefined) k2 = k;
|
|
12551
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12552
|
+
}) : (function(o, m, k, k2) {
|
|
12553
|
+
if (k2 === undefined) k2 = k;
|
|
12554
|
+
o[k2] = m[k];
|
|
12555
|
+
}));
|
|
12556
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
12557
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
12558
|
+
}) : function(o, v) {
|
|
12559
|
+
o["default"] = v;
|
|
12560
|
+
});
|
|
12561
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
12562
|
+
if (mod && mod.__esModule) return mod;
|
|
12563
|
+
var result = {};
|
|
12564
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
12565
|
+
__setModuleDefault(result, mod);
|
|
12566
|
+
return result;
|
|
12567
|
+
};
|
|
12568
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
12569
|
+
const utils = __importStar(__webpack_require__(8593));
|
|
12570
|
+
const Contract_1 = __webpack_require__(9822);
|
|
12571
|
+
const Signer_1 = __webpack_require__(6991);
|
|
12572
|
+
const Provider_1 = __webpack_require__(5635);
|
|
12573
|
+
const Serializer_1 = __webpack_require__(7187);
|
|
12574
|
+
window.utils = utils;
|
|
12575
|
+
window.Contract = Contract_1.Contract;
|
|
12576
|
+
window.Signer = Signer_1.Signer;
|
|
12577
|
+
window.Provider = Provider_1.Provider;
|
|
12578
|
+
window.Serializer = Serializer_1.Serializer;
|
|
12579
12579
|
|
|
12580
12580
|
|
|
12581
12581
|
/***/ }),
|
|
@@ -12584,257 +12584,257 @@ window.Serializer = Serializer_1.Serializer;
|
|
|
12584
12584
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
12585
12585
|
|
|
12586
12586
|
"use strict";
|
|
12587
|
-
|
|
12588
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12589
|
-
if (k2 === undefined) k2 = k;
|
|
12590
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12591
|
-
}) : (function(o, m, k, k2) {
|
|
12592
|
-
if (k2 === undefined) k2 = k;
|
|
12593
|
-
o[k2] = m[k];
|
|
12594
|
-
}));
|
|
12595
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
12596
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
12597
|
-
}) : function(o, v) {
|
|
12598
|
-
o["default"] = v;
|
|
12599
|
-
});
|
|
12600
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
12601
|
-
if (mod && mod.__esModule) return mod;
|
|
12602
|
-
var result = {};
|
|
12603
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
12604
|
-
__setModuleDefault(result, mod);
|
|
12605
|
-
return result;
|
|
12606
|
-
};
|
|
12607
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12608
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12609
|
-
};
|
|
12610
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
12611
|
-
exports.ProtocolTypes = exports.Krc20Abi = exports.parseUnits = exports.formatUnits = exports.bitcoinAddress = exports.bitcoinDecode = exports.bitcoinEncode = exports.decodeBase64 = exports.encodeBase64 = exports.decodeBase58 = exports.encodeBase58 = exports.toHexString = exports.toUint8Array = void 0;
|
|
12612
|
-
const multibase = __importStar(__webpack_require__(6957));
|
|
12613
|
-
const sha256_1 = __webpack_require__(5374);
|
|
12614
|
-
const ripemd160_1 = __webpack_require__(7050);
|
|
12615
|
-
const krc20_proto_json_1 = __importDefault(__webpack_require__(7177));
|
|
12616
|
-
const protocol_proto_json_1 = __importDefault(__webpack_require__(6139));
|
|
12617
|
-
/**
|
|
12618
|
-
* Converts an hex string to Uint8Array
|
|
12619
|
-
*/
|
|
12620
|
-
function toUint8Array(hex) {
|
|
12621
|
-
const pairs = hex.match(/[\dA-F]{2}/gi);
|
|
12622
|
-
if (!pairs)
|
|
12623
|
-
throw new Error("Invalid hex");
|
|
12624
|
-
return new Uint8Array(pairs.map((s) => parseInt(s, 16)) // convert to integers
|
|
12625
|
-
);
|
|
12626
|
-
}
|
|
12627
|
-
exports.toUint8Array = toUint8Array;
|
|
12628
|
-
/**
|
|
12629
|
-
* Converts Uint8Array to hex string
|
|
12630
|
-
*/
|
|
12631
|
-
function toHexString(buffer) {
|
|
12632
|
-
return Array.from(buffer)
|
|
12633
|
-
.map((n) => `0${Number(n).toString(16)}`.slice(-2))
|
|
12634
|
-
.join("");
|
|
12635
|
-
}
|
|
12636
|
-
exports.toHexString = toHexString;
|
|
12637
|
-
/**
|
|
12638
|
-
* Encodes an Uint8Array in base58
|
|
12639
|
-
*/
|
|
12640
|
-
function encodeBase58(buffer) {
|
|
12641
|
-
return new TextDecoder().decode(multibase.encode("z", buffer)).slice(1);
|
|
12642
|
-
}
|
|
12643
|
-
exports.encodeBase58 = encodeBase58;
|
|
12644
|
-
/**
|
|
12645
|
-
* Decodes a buffer formatted in base58
|
|
12646
|
-
*/
|
|
12647
|
-
function decodeBase58(bs58) {
|
|
12648
|
-
return multibase.decode(`z${bs58}`);
|
|
12649
|
-
}
|
|
12650
|
-
exports.decodeBase58 = decodeBase58;
|
|
12651
|
-
/**
|
|
12652
|
-
* Encodes an Uint8Array in base64
|
|
12653
|
-
*/
|
|
12654
|
-
function encodeBase64(buffer) {
|
|
12655
|
-
return new TextDecoder().decode(multibase.encode("U", buffer)).slice(1);
|
|
12656
|
-
}
|
|
12657
|
-
exports.encodeBase64 = encodeBase64;
|
|
12658
|
-
/**
|
|
12659
|
-
* Decodes a buffer formatted in base64
|
|
12660
|
-
*/
|
|
12661
|
-
function decodeBase64(bs64) {
|
|
12662
|
-
return multibase.decode(`U${bs64}`);
|
|
12663
|
-
}
|
|
12664
|
-
exports.decodeBase64 = decodeBase64;
|
|
12665
|
-
/**
|
|
12666
|
-
* Encodes a public or private key in base58 using
|
|
12667
|
-
* the bitcoin format (see [Bitcoin Base58Check encoding](https://en.bitcoin.it/wiki/Base58Check_encoding)
|
|
12668
|
-
* and [Bitcoin WIF](https://en.bitcoin.it/wiki/Wallet_import_format)).
|
|
12669
|
-
*
|
|
12670
|
-
* For private keys this encode is also known as
|
|
12671
|
-
* wallet import format (WIF).
|
|
12672
|
-
*/
|
|
12673
|
-
function bitcoinEncode(buffer, type, compressed = false) {
|
|
12674
|
-
let bufferCheck;
|
|
12675
|
-
let prefixBuffer;
|
|
12676
|
-
let offsetChecksum;
|
|
12677
|
-
if (type === "public") {
|
|
12678
|
-
bufferCheck = new Uint8Array(25);
|
|
12679
|
-
prefixBuffer = new Uint8Array(21);
|
|
12680
|
-
bufferCheck[0] = 0;
|
|
12681
|
-
prefixBuffer[0] = 0;
|
|
12682
|
-
offsetChecksum = 21;
|
|
12683
|
-
}
|
|
12684
|
-
else {
|
|
12685
|
-
if (compressed) {
|
|
12686
|
-
bufferCheck = new Uint8Array(38);
|
|
12687
|
-
prefixBuffer = new Uint8Array(34);
|
|
12688
|
-
offsetChecksum = 34;
|
|
12689
|
-
bufferCheck[33] = 1;
|
|
12690
|
-
prefixBuffer[33] = 1;
|
|
12691
|
-
}
|
|
12692
|
-
else {
|
|
12693
|
-
bufferCheck = new Uint8Array(37);
|
|
12694
|
-
prefixBuffer = new Uint8Array(33);
|
|
12695
|
-
offsetChecksum = 33;
|
|
12696
|
-
}
|
|
12697
|
-
bufferCheck[0] = 128;
|
|
12698
|
-
prefixBuffer[0] = 128;
|
|
12699
|
-
}
|
|
12700
|
-
prefixBuffer.set(buffer, 1);
|
|
12701
|
-
const firstHash = sha256_1.sha256(prefixBuffer);
|
|
12702
|
-
const doubleHash = sha256_1.sha256(firstHash);
|
|
12703
|
-
const checksum = new Uint8Array(4);
|
|
12704
|
-
checksum.set(doubleHash.slice(0, 4));
|
|
12705
|
-
bufferCheck.set(buffer, 1);
|
|
12706
|
-
bufferCheck.set(checksum, offsetChecksum);
|
|
12707
|
-
return encodeBase58(bufferCheck);
|
|
12708
|
-
}
|
|
12709
|
-
exports.bitcoinEncode = bitcoinEncode;
|
|
12710
|
-
/**
|
|
12711
|
-
* Decodes a public or private key formatted in base58 using
|
|
12712
|
-
* the bitcoin format (see [Bitcoin Base58Check encoding](https://en.bitcoin.it/wiki/Base58Check_encoding)
|
|
12713
|
-
* and [Bitcoin WIF](https://en.bitcoin.it/wiki/Wallet_import_format)).
|
|
12714
|
-
*
|
|
12715
|
-
* For private keys this encode is also known as
|
|
12716
|
-
* wallet import format (WIF).
|
|
12717
|
-
*/
|
|
12718
|
-
function bitcoinDecode(value) {
|
|
12719
|
-
const buffer = decodeBase58(value);
|
|
12720
|
-
const privateKey = new Uint8Array(32);
|
|
12721
|
-
const checksum = new Uint8Array(4);
|
|
12722
|
-
// const prefix = buffer[0];
|
|
12723
|
-
privateKey.set(buffer.slice(1, 33));
|
|
12724
|
-
if (value[0] !== "5") {
|
|
12725
|
-
// compressed
|
|
12726
|
-
checksum.set(buffer.slice(34, 38));
|
|
12727
|
-
}
|
|
12728
|
-
else {
|
|
12729
|
-
checksum.set(buffer.slice(33, 37));
|
|
12730
|
-
}
|
|
12731
|
-
// TODO: verify prefix and checksum
|
|
12732
|
-
return privateKey;
|
|
12733
|
-
}
|
|
12734
|
-
exports.bitcoinDecode = bitcoinDecode;
|
|
12735
|
-
/**
|
|
12736
|
-
* Computes a bitcoin address, which is the format used in Koinos
|
|
12737
|
-
*
|
|
12738
|
-
* address = bitcoinEncode( ripemd160 ( sha256 ( publicKey ) ) )
|
|
12739
|
-
*/
|
|
12740
|
-
function bitcoinAddress(publicKey) {
|
|
12741
|
-
const hash = sha256_1.sha256(publicKey);
|
|
12742
|
-
const hash160 = ripemd160_1.ripemd160(hash);
|
|
12743
|
-
return bitcoinEncode(hash160, "public");
|
|
12744
|
-
}
|
|
12745
|
-
exports.bitcoinAddress = bitcoinAddress;
|
|
12746
|
-
/**
|
|
12747
|
-
* Function to format a number in a decimal point number
|
|
12748
|
-
* @example
|
|
12749
|
-
* ```js
|
|
12750
|
-
* const amount = formatUnits("123456", 8);
|
|
12751
|
-
* console.log(amount);
|
|
12752
|
-
* // '0.00123456'
|
|
12753
|
-
* ```
|
|
12754
|
-
*/
|
|
12755
|
-
function formatUnits(value, decimals) {
|
|
12756
|
-
let v = typeof value === "string" ? value : BigInt(value).toString();
|
|
12757
|
-
const sign = v[0] === "-" ? "-" : "";
|
|
12758
|
-
v = v.replace("-", "").padStart(decimals + 1, "0");
|
|
12759
|
-
const integerPart = v
|
|
12760
|
-
.substring(0, v.length - decimals)
|
|
12761
|
-
.replace(/^0+(?=\d)/, "");
|
|
12762
|
-
const decimalPart = v.substring(v.length - decimals);
|
|
12763
|
-
return `${sign}${integerPart}.${decimalPart}`.replace(/(\.0+)?(0+)$/, "");
|
|
12764
|
-
}
|
|
12765
|
-
exports.formatUnits = formatUnits;
|
|
12766
|
-
/**
|
|
12767
|
-
* Function to format a decimal point number in an integer
|
|
12768
|
-
* @example
|
|
12769
|
-
* ```js
|
|
12770
|
-
* const amount = parseUnits("0.00123456", 8);
|
|
12771
|
-
* console.log(amount);
|
|
12772
|
-
* // '123456'
|
|
12773
|
-
* ```
|
|
12774
|
-
*/
|
|
12775
|
-
function parseUnits(value, decimals) {
|
|
12776
|
-
const sign = value[0] === "-" ? "-" : "";
|
|
12777
|
-
// eslint-disable-next-line prefer-const
|
|
12778
|
-
let [integerPart, decimalPart] = value
|
|
12779
|
-
.replace("-", "")
|
|
12780
|
-
.replace(",", ".")
|
|
12781
|
-
.split(".");
|
|
12782
|
-
if (!decimalPart)
|
|
12783
|
-
decimalPart = "";
|
|
12784
|
-
decimalPart = decimalPart.padEnd(decimals, "0");
|
|
12785
|
-
return `${sign}${`${integerPart}${decimalPart}`.replace(/^0+(?=\d)/, "")}`;
|
|
12786
|
-
}
|
|
12787
|
-
exports.parseUnits = parseUnits;
|
|
12788
|
-
/**
|
|
12789
|
-
* ABI for tokens
|
|
12790
|
-
*/
|
|
12791
|
-
exports.Krc20Abi = {
|
|
12792
|
-
methods: {
|
|
12793
|
-
name: {
|
|
12794
|
-
entryPoint: 0x76ea4297,
|
|
12795
|
-
input: "name_arguments",
|
|
12796
|
-
output: "name_result",
|
|
12797
|
-
readOnly: true,
|
|
12798
|
-
},
|
|
12799
|
-
symbol: {
|
|
12800
|
-
entryPoint: 0x7e794b24,
|
|
12801
|
-
input: "symbol_arguments",
|
|
12802
|
-
output: "symbol_result",
|
|
12803
|
-
readOnly: true,
|
|
12804
|
-
},
|
|
12805
|
-
decimals: {
|
|
12806
|
-
entryPoint: 0x59dc15ce,
|
|
12807
|
-
input: "decimals_arguments",
|
|
12808
|
-
output: "decimals_result",
|
|
12809
|
-
readOnly: true,
|
|
12810
|
-
},
|
|
12811
|
-
totalSupply: {
|
|
12812
|
-
entryPoint: 0xcf2e8212,
|
|
12813
|
-
input: "total_supply_arguments",
|
|
12814
|
-
output: "total_supply_result",
|
|
12815
|
-
readOnly: true,
|
|
12816
|
-
},
|
|
12817
|
-
balanceOf: {
|
|
12818
|
-
entryPoint: 0x15619248,
|
|
12819
|
-
input: "balance_of_arguments",
|
|
12820
|
-
output: "balance_of_result",
|
|
12821
|
-
readOnly: true,
|
|
12822
|
-
defaultOutput: { value: "0" },
|
|
12823
|
-
},
|
|
12824
|
-
transfer: {
|
|
12825
|
-
entryPoint: 0x62efa292,
|
|
12826
|
-
input: "transfer_arguments",
|
|
12827
|
-
output: "transfer_result",
|
|
12828
|
-
},
|
|
12829
|
-
mint: {
|
|
12830
|
-
entryPoint: 0xc2f82bdc,
|
|
12831
|
-
input: "
|
|
12832
|
-
output: "mint_result",
|
|
12833
|
-
},
|
|
12834
|
-
},
|
|
12835
|
-
types: krc20_proto_json_1.default,
|
|
12836
|
-
};
|
|
12837
|
-
exports.ProtocolTypes = protocol_proto_json_1.default;
|
|
12587
|
+
|
|
12588
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12589
|
+
if (k2 === undefined) k2 = k;
|
|
12590
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12591
|
+
}) : (function(o, m, k, k2) {
|
|
12592
|
+
if (k2 === undefined) k2 = k;
|
|
12593
|
+
o[k2] = m[k];
|
|
12594
|
+
}));
|
|
12595
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
12596
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
12597
|
+
}) : function(o, v) {
|
|
12598
|
+
o["default"] = v;
|
|
12599
|
+
});
|
|
12600
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
12601
|
+
if (mod && mod.__esModule) return mod;
|
|
12602
|
+
var result = {};
|
|
12603
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
12604
|
+
__setModuleDefault(result, mod);
|
|
12605
|
+
return result;
|
|
12606
|
+
};
|
|
12607
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12608
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12609
|
+
};
|
|
12610
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
12611
|
+
exports.ProtocolTypes = exports.Krc20Abi = exports.parseUnits = exports.formatUnits = exports.bitcoinAddress = exports.bitcoinDecode = exports.bitcoinEncode = exports.decodeBase64 = exports.encodeBase64 = exports.decodeBase58 = exports.encodeBase58 = exports.toHexString = exports.toUint8Array = void 0;
|
|
12612
|
+
const multibase = __importStar(__webpack_require__(6957));
|
|
12613
|
+
const sha256_1 = __webpack_require__(5374);
|
|
12614
|
+
const ripemd160_1 = __webpack_require__(7050);
|
|
12615
|
+
const krc20_proto_json_1 = __importDefault(__webpack_require__(7177));
|
|
12616
|
+
const protocol_proto_json_1 = __importDefault(__webpack_require__(6139));
|
|
12617
|
+
/**
|
|
12618
|
+
* Converts an hex string to Uint8Array
|
|
12619
|
+
*/
|
|
12620
|
+
function toUint8Array(hex) {
|
|
12621
|
+
const pairs = hex.match(/[\dA-F]{2}/gi);
|
|
12622
|
+
if (!pairs)
|
|
12623
|
+
throw new Error("Invalid hex");
|
|
12624
|
+
return new Uint8Array(pairs.map((s) => parseInt(s, 16)) // convert to integers
|
|
12625
|
+
);
|
|
12626
|
+
}
|
|
12627
|
+
exports.toUint8Array = toUint8Array;
|
|
12628
|
+
/**
|
|
12629
|
+
* Converts Uint8Array to hex string
|
|
12630
|
+
*/
|
|
12631
|
+
function toHexString(buffer) {
|
|
12632
|
+
return Array.from(buffer)
|
|
12633
|
+
.map((n) => `0${Number(n).toString(16)}`.slice(-2))
|
|
12634
|
+
.join("");
|
|
12635
|
+
}
|
|
12636
|
+
exports.toHexString = toHexString;
|
|
12637
|
+
/**
|
|
12638
|
+
* Encodes an Uint8Array in base58
|
|
12639
|
+
*/
|
|
12640
|
+
function encodeBase58(buffer) {
|
|
12641
|
+
return new TextDecoder().decode(multibase.encode("z", buffer)).slice(1);
|
|
12642
|
+
}
|
|
12643
|
+
exports.encodeBase58 = encodeBase58;
|
|
12644
|
+
/**
|
|
12645
|
+
* Decodes a buffer formatted in base58
|
|
12646
|
+
*/
|
|
12647
|
+
function decodeBase58(bs58) {
|
|
12648
|
+
return multibase.decode(`z${bs58}`);
|
|
12649
|
+
}
|
|
12650
|
+
exports.decodeBase58 = decodeBase58;
|
|
12651
|
+
/**
|
|
12652
|
+
* Encodes an Uint8Array in base64
|
|
12653
|
+
*/
|
|
12654
|
+
function encodeBase64(buffer) {
|
|
12655
|
+
return new TextDecoder().decode(multibase.encode("U", buffer)).slice(1);
|
|
12656
|
+
}
|
|
12657
|
+
exports.encodeBase64 = encodeBase64;
|
|
12658
|
+
/**
|
|
12659
|
+
* Decodes a buffer formatted in base64
|
|
12660
|
+
*/
|
|
12661
|
+
function decodeBase64(bs64) {
|
|
12662
|
+
return multibase.decode(`U${bs64}`);
|
|
12663
|
+
}
|
|
12664
|
+
exports.decodeBase64 = decodeBase64;
|
|
12665
|
+
/**
|
|
12666
|
+
* Encodes a public or private key in base58 using
|
|
12667
|
+
* the bitcoin format (see [Bitcoin Base58Check encoding](https://en.bitcoin.it/wiki/Base58Check_encoding)
|
|
12668
|
+
* and [Bitcoin WIF](https://en.bitcoin.it/wiki/Wallet_import_format)).
|
|
12669
|
+
*
|
|
12670
|
+
* For private keys this encode is also known as
|
|
12671
|
+
* wallet import format (WIF).
|
|
12672
|
+
*/
|
|
12673
|
+
function bitcoinEncode(buffer, type, compressed = false) {
|
|
12674
|
+
let bufferCheck;
|
|
12675
|
+
let prefixBuffer;
|
|
12676
|
+
let offsetChecksum;
|
|
12677
|
+
if (type === "public") {
|
|
12678
|
+
bufferCheck = new Uint8Array(25);
|
|
12679
|
+
prefixBuffer = new Uint8Array(21);
|
|
12680
|
+
bufferCheck[0] = 0;
|
|
12681
|
+
prefixBuffer[0] = 0;
|
|
12682
|
+
offsetChecksum = 21;
|
|
12683
|
+
}
|
|
12684
|
+
else {
|
|
12685
|
+
if (compressed) {
|
|
12686
|
+
bufferCheck = new Uint8Array(38);
|
|
12687
|
+
prefixBuffer = new Uint8Array(34);
|
|
12688
|
+
offsetChecksum = 34;
|
|
12689
|
+
bufferCheck[33] = 1;
|
|
12690
|
+
prefixBuffer[33] = 1;
|
|
12691
|
+
}
|
|
12692
|
+
else {
|
|
12693
|
+
bufferCheck = new Uint8Array(37);
|
|
12694
|
+
prefixBuffer = new Uint8Array(33);
|
|
12695
|
+
offsetChecksum = 33;
|
|
12696
|
+
}
|
|
12697
|
+
bufferCheck[0] = 128;
|
|
12698
|
+
prefixBuffer[0] = 128;
|
|
12699
|
+
}
|
|
12700
|
+
prefixBuffer.set(buffer, 1);
|
|
12701
|
+
const firstHash = sha256_1.sha256(prefixBuffer);
|
|
12702
|
+
const doubleHash = sha256_1.sha256(firstHash);
|
|
12703
|
+
const checksum = new Uint8Array(4);
|
|
12704
|
+
checksum.set(doubleHash.slice(0, 4));
|
|
12705
|
+
bufferCheck.set(buffer, 1);
|
|
12706
|
+
bufferCheck.set(checksum, offsetChecksum);
|
|
12707
|
+
return encodeBase58(bufferCheck);
|
|
12708
|
+
}
|
|
12709
|
+
exports.bitcoinEncode = bitcoinEncode;
|
|
12710
|
+
/**
|
|
12711
|
+
* Decodes a public or private key formatted in base58 using
|
|
12712
|
+
* the bitcoin format (see [Bitcoin Base58Check encoding](https://en.bitcoin.it/wiki/Base58Check_encoding)
|
|
12713
|
+
* and [Bitcoin WIF](https://en.bitcoin.it/wiki/Wallet_import_format)).
|
|
12714
|
+
*
|
|
12715
|
+
* For private keys this encode is also known as
|
|
12716
|
+
* wallet import format (WIF).
|
|
12717
|
+
*/
|
|
12718
|
+
function bitcoinDecode(value) {
|
|
12719
|
+
const buffer = decodeBase58(value);
|
|
12720
|
+
const privateKey = new Uint8Array(32);
|
|
12721
|
+
const checksum = new Uint8Array(4);
|
|
12722
|
+
// const prefix = buffer[0];
|
|
12723
|
+
privateKey.set(buffer.slice(1, 33));
|
|
12724
|
+
if (value[0] !== "5") {
|
|
12725
|
+
// compressed
|
|
12726
|
+
checksum.set(buffer.slice(34, 38));
|
|
12727
|
+
}
|
|
12728
|
+
else {
|
|
12729
|
+
checksum.set(buffer.slice(33, 37));
|
|
12730
|
+
}
|
|
12731
|
+
// TODO: verify prefix and checksum
|
|
12732
|
+
return privateKey;
|
|
12733
|
+
}
|
|
12734
|
+
exports.bitcoinDecode = bitcoinDecode;
|
|
12735
|
+
/**
|
|
12736
|
+
* Computes a bitcoin address, which is the format used in Koinos
|
|
12737
|
+
*
|
|
12738
|
+
* address = bitcoinEncode( ripemd160 ( sha256 ( publicKey ) ) )
|
|
12739
|
+
*/
|
|
12740
|
+
function bitcoinAddress(publicKey) {
|
|
12741
|
+
const hash = sha256_1.sha256(publicKey);
|
|
12742
|
+
const hash160 = ripemd160_1.ripemd160(hash);
|
|
12743
|
+
return bitcoinEncode(hash160, "public");
|
|
12744
|
+
}
|
|
12745
|
+
exports.bitcoinAddress = bitcoinAddress;
|
|
12746
|
+
/**
|
|
12747
|
+
* Function to format a number in a decimal point number
|
|
12748
|
+
* @example
|
|
12749
|
+
* ```js
|
|
12750
|
+
* const amount = formatUnits("123456", 8);
|
|
12751
|
+
* console.log(amount);
|
|
12752
|
+
* // '0.00123456'
|
|
12753
|
+
* ```
|
|
12754
|
+
*/
|
|
12755
|
+
function formatUnits(value, decimals) {
|
|
12756
|
+
let v = typeof value === "string" ? value : BigInt(value).toString();
|
|
12757
|
+
const sign = v[0] === "-" ? "-" : "";
|
|
12758
|
+
v = v.replace("-", "").padStart(decimals + 1, "0");
|
|
12759
|
+
const integerPart = v
|
|
12760
|
+
.substring(0, v.length - decimals)
|
|
12761
|
+
.replace(/^0+(?=\d)/, "");
|
|
12762
|
+
const decimalPart = v.substring(v.length - decimals);
|
|
12763
|
+
return `${sign}${integerPart}.${decimalPart}`.replace(/(\.0+)?(0+)$/, "");
|
|
12764
|
+
}
|
|
12765
|
+
exports.formatUnits = formatUnits;
|
|
12766
|
+
/**
|
|
12767
|
+
* Function to format a decimal point number in an integer
|
|
12768
|
+
* @example
|
|
12769
|
+
* ```js
|
|
12770
|
+
* const amount = parseUnits("0.00123456", 8);
|
|
12771
|
+
* console.log(amount);
|
|
12772
|
+
* // '123456'
|
|
12773
|
+
* ```
|
|
12774
|
+
*/
|
|
12775
|
+
function parseUnits(value, decimals) {
|
|
12776
|
+
const sign = value[0] === "-" ? "-" : "";
|
|
12777
|
+
// eslint-disable-next-line prefer-const
|
|
12778
|
+
let [integerPart, decimalPart] = value
|
|
12779
|
+
.replace("-", "")
|
|
12780
|
+
.replace(",", ".")
|
|
12781
|
+
.split(".");
|
|
12782
|
+
if (!decimalPart)
|
|
12783
|
+
decimalPart = "";
|
|
12784
|
+
decimalPart = decimalPart.padEnd(decimals, "0");
|
|
12785
|
+
return `${sign}${`${integerPart}${decimalPart}`.replace(/^0+(?=\d)/, "")}`;
|
|
12786
|
+
}
|
|
12787
|
+
exports.parseUnits = parseUnits;
|
|
12788
|
+
/**
|
|
12789
|
+
* ABI for tokens
|
|
12790
|
+
*/
|
|
12791
|
+
exports.Krc20Abi = {
|
|
12792
|
+
methods: {
|
|
12793
|
+
name: {
|
|
12794
|
+
entryPoint: 0x76ea4297,
|
|
12795
|
+
input: "name_arguments",
|
|
12796
|
+
output: "name_result",
|
|
12797
|
+
readOnly: true,
|
|
12798
|
+
},
|
|
12799
|
+
symbol: {
|
|
12800
|
+
entryPoint: 0x7e794b24,
|
|
12801
|
+
input: "symbol_arguments",
|
|
12802
|
+
output: "symbol_result",
|
|
12803
|
+
readOnly: true,
|
|
12804
|
+
},
|
|
12805
|
+
decimals: {
|
|
12806
|
+
entryPoint: 0x59dc15ce,
|
|
12807
|
+
input: "decimals_arguments",
|
|
12808
|
+
output: "decimals_result",
|
|
12809
|
+
readOnly: true,
|
|
12810
|
+
},
|
|
12811
|
+
totalSupply: {
|
|
12812
|
+
entryPoint: 0xcf2e8212,
|
|
12813
|
+
input: "total_supply_arguments",
|
|
12814
|
+
output: "total_supply_result",
|
|
12815
|
+
readOnly: true,
|
|
12816
|
+
},
|
|
12817
|
+
balanceOf: {
|
|
12818
|
+
entryPoint: 0x15619248,
|
|
12819
|
+
input: "balance_of_arguments",
|
|
12820
|
+
output: "balance_of_result",
|
|
12821
|
+
readOnly: true,
|
|
12822
|
+
defaultOutput: { value: "0" },
|
|
12823
|
+
},
|
|
12824
|
+
transfer: {
|
|
12825
|
+
entryPoint: 0x62efa292,
|
|
12826
|
+
input: "transfer_arguments",
|
|
12827
|
+
output: "transfer_result",
|
|
12828
|
+
},
|
|
12829
|
+
mint: {
|
|
12830
|
+
entryPoint: 0xc2f82bdc,
|
|
12831
|
+
input: "mint_arguments",
|
|
12832
|
+
output: "mint_result",
|
|
12833
|
+
},
|
|
12834
|
+
},
|
|
12835
|
+
types: krc20_proto_json_1.default,
|
|
12836
|
+
};
|
|
12837
|
+
exports.ProtocolTypes = protocol_proto_json_1.default;
|
|
12838
12838
|
|
|
12839
12839
|
|
|
12840
12840
|
/***/ }),
|