ccxt 4.2.59 → 4.2.61

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.
Files changed (184) hide show
  1. package/README.md +103 -102
  2. package/build.sh +2 -2
  3. package/dist/ccxt.browser.js +11853 -3790
  4. package/dist/ccxt.browser.min.js +7 -7
  5. package/dist/cjs/ccxt.js +4 -1
  6. package/dist/cjs/src/abstract/hyperliquid.js +9 -0
  7. package/dist/cjs/src/ascendex.js +10 -12
  8. package/dist/cjs/src/base/Exchange.js +22 -1
  9. package/dist/cjs/src/base/functions/encode.js +5 -0
  10. package/dist/cjs/src/base/functions.js +1 -0
  11. package/dist/cjs/src/bingx.js +38 -0
  12. package/dist/cjs/src/bitfinex2.js +20 -3
  13. package/dist/cjs/src/bitget.js +9 -2
  14. package/dist/cjs/src/bitmart.js +41 -23
  15. package/dist/cjs/src/blofin.js +59 -1
  16. package/dist/cjs/src/coinbase.js +108 -103
  17. package/dist/cjs/src/coinex.js +61 -1
  18. package/dist/cjs/src/hitbtc.js +1 -1
  19. package/dist/cjs/src/htx.js +4 -1
  20. package/dist/cjs/src/hyperliquid.js +2035 -0
  21. package/dist/cjs/src/kraken.js +50 -41
  22. package/dist/cjs/src/krakenfutures.js +28 -0
  23. package/dist/cjs/src/kucoinfutures.js +3 -2
  24. package/dist/cjs/src/okx.js +1 -1
  25. package/dist/cjs/src/phemex.js +2 -2
  26. package/dist/cjs/src/pro/binance.js +16 -3
  27. package/dist/cjs/src/pro/bingx.js +1 -0
  28. package/dist/cjs/src/static_dependencies/ethers/abi-coder.js +158 -0
  29. package/dist/cjs/src/static_dependencies/ethers/address/address.js +144 -0
  30. package/dist/cjs/src/static_dependencies/ethers/coders/abstract-coder.js +407 -0
  31. package/dist/cjs/src/static_dependencies/ethers/coders/address.js +45 -0
  32. package/dist/cjs/src/static_dependencies/ethers/coders/anonymous.js +28 -0
  33. package/dist/cjs/src/static_dependencies/ethers/coders/array.js +176 -0
  34. package/dist/cjs/src/static_dependencies/ethers/coders/boolean.js +27 -0
  35. package/dist/cjs/src/static_dependencies/ethers/coders/bytes.js +52 -0
  36. package/dist/cjs/src/static_dependencies/ethers/coders/fixed-bytes.js +45 -0
  37. package/dist/cjs/src/static_dependencies/ethers/coders/null.js +30 -0
  38. package/dist/cjs/src/static_dependencies/ethers/coders/number.js +60 -0
  39. package/dist/cjs/src/static_dependencies/ethers/coders/string.js +27 -0
  40. package/dist/cjs/src/static_dependencies/ethers/coders/tuple.js +68 -0
  41. package/dist/cjs/src/static_dependencies/ethers/fragments.js +614 -0
  42. package/dist/cjs/src/static_dependencies/ethers/hash/typed-data.js +492 -0
  43. package/dist/cjs/src/static_dependencies/ethers/index.js +35 -0
  44. package/dist/cjs/src/static_dependencies/ethers/interface.js +44 -0
  45. package/dist/cjs/src/static_dependencies/ethers/typed.js +618 -0
  46. package/dist/cjs/src/static_dependencies/ethers/utils/base58.js +20 -0
  47. package/dist/cjs/src/static_dependencies/ethers/utils/data.js +134 -0
  48. package/dist/cjs/src/static_dependencies/ethers/utils/errors.js +228 -0
  49. package/dist/cjs/src/static_dependencies/ethers/utils/events.js +13 -0
  50. package/dist/cjs/src/static_dependencies/ethers/utils/fixednumber.js +29 -0
  51. package/dist/cjs/src/static_dependencies/ethers/utils/index.js +53 -0
  52. package/dist/cjs/src/static_dependencies/ethers/utils/maths.js +231 -0
  53. package/dist/cjs/src/static_dependencies/ethers/utils/properties.js +47 -0
  54. package/dist/cjs/src/static_dependencies/ethers/utils/utf8.js +218 -0
  55. package/dist/cjs/src/static_dependencies/messagepack/msgpack.js +292 -0
  56. package/dist/cjs/src/tokocrypto.js +22 -2
  57. package/dist/cjs/src/wazirx.js +314 -4
  58. package/dist/cjs/src/woo.js +157 -77
  59. package/js/ccxt.d.ts +5 -2
  60. package/js/ccxt.js +4 -2
  61. package/js/src/abstract/blofin.d.ts +1 -0
  62. package/js/src/abstract/coinbase.d.ts +3 -3
  63. package/js/src/abstract/hyperliquid.d.ts +9 -0
  64. package/js/src/abstract/hyperliquid.js +11 -0
  65. package/js/src/abstract/wazirx.d.ts +5 -0
  66. package/js/src/ascendex.d.ts +2 -2
  67. package/js/src/ascendex.js +10 -12
  68. package/js/src/base/Exchange.d.ts +4 -0
  69. package/js/src/base/Exchange.js +13 -1
  70. package/js/src/base/functions/encode.d.ts +2 -1
  71. package/js/src/base/functions/encode.js +5 -1
  72. package/js/src/bingx.d.ts +3 -1
  73. package/js/src/bingx.js +38 -0
  74. package/js/src/bitfinex2.js +20 -3
  75. package/js/src/bitget.js +9 -2
  76. package/js/src/bitmart.d.ts +9 -2
  77. package/js/src/bitmart.js +41 -23
  78. package/js/src/blofin.d.ts +2 -1
  79. package/js/src/blofin.js +59 -1
  80. package/js/src/coinbase.js +108 -103
  81. package/js/src/coinex.d.ts +3 -1
  82. package/js/src/coinex.js +61 -1
  83. package/js/src/hitbtc.js +1 -1
  84. package/js/src/htx.js +4 -1
  85. package/js/src/hyperliquid.d.ts +83 -0
  86. package/js/src/hyperliquid.js +2036 -0
  87. package/js/src/kraken.js +50 -41
  88. package/js/src/krakenfutures.d.ts +2 -1
  89. package/js/src/krakenfutures.js +28 -0
  90. package/js/src/kucoinfutures.js +3 -2
  91. package/js/src/okx.js +1 -1
  92. package/js/src/phemex.js +2 -2
  93. package/js/src/pro/binance.js +16 -3
  94. package/js/src/pro/bingx.js +1 -0
  95. package/js/src/pro/deribit.d.ts +1 -1
  96. package/js/src/static_dependencies/ethers/abi-coder.d.ts +50 -0
  97. package/js/src/static_dependencies/ethers/abi-coder.js +148 -0
  98. package/js/src/static_dependencies/ethers/address/address.d.ts +55 -0
  99. package/js/src/static_dependencies/ethers/address/address.js +162 -0
  100. package/js/src/static_dependencies/ethers/address/checks.d.ts +80 -0
  101. package/js/src/static_dependencies/ethers/address/checks.js +119 -0
  102. package/js/src/static_dependencies/ethers/address/contract-address.d.ts +47 -0
  103. package/js/src/static_dependencies/ethers/address/contract-address.js +73 -0
  104. package/js/src/static_dependencies/ethers/address/index.d.ts +48 -0
  105. package/js/src/static_dependencies/ethers/address/index.js +24 -0
  106. package/js/src/static_dependencies/ethers/bytes32.d.ts +14 -0
  107. package/js/src/static_dependencies/ethers/bytes32.js +45 -0
  108. package/js/src/static_dependencies/ethers/coders/abstract-coder.d.ts +120 -0
  109. package/js/src/static_dependencies/ethers/coders/abstract-coder.js +424 -0
  110. package/js/src/static_dependencies/ethers/coders/address.d.ts +12 -0
  111. package/js/src/static_dependencies/ethers/coders/address.js +34 -0
  112. package/js/src/static_dependencies/ethers/coders/anonymous.d.ts +14 -0
  113. package/js/src/static_dependencies/ethers/coders/anonymous.js +27 -0
  114. package/js/src/static_dependencies/ethers/coders/array.d.ts +24 -0
  115. package/js/src/static_dependencies/ethers/coders/array.js +162 -0
  116. package/js/src/static_dependencies/ethers/coders/boolean.d.ts +12 -0
  117. package/js/src/static_dependencies/ethers/coders/boolean.js +26 -0
  118. package/js/src/static_dependencies/ethers/coders/bytes.d.ts +18 -0
  119. package/js/src/static_dependencies/ethers/coders/bytes.js +39 -0
  120. package/js/src/static_dependencies/ethers/coders/fixed-bytes.d.ts +14 -0
  121. package/js/src/static_dependencies/ethers/coders/fixed-bytes.js +32 -0
  122. package/js/src/static_dependencies/ethers/coders/null.d.ts +11 -0
  123. package/js/src/static_dependencies/ethers/coders/null.js +29 -0
  124. package/js/src/static_dependencies/ethers/coders/number.d.ts +15 -0
  125. package/js/src/static_dependencies/ethers/coders/number.js +48 -0
  126. package/js/src/static_dependencies/ethers/coders/string.d.ts +12 -0
  127. package/js/src/static_dependencies/ethers/coders/string.js +26 -0
  128. package/js/src/static_dependencies/ethers/coders/tuple.d.ts +15 -0
  129. package/js/src/static_dependencies/ethers/coders/tuple.js +67 -0
  130. package/js/src/static_dependencies/ethers/fragments.d.ts +458 -0
  131. package/js/src/static_dependencies/ethers/fragments.js +1252 -0
  132. package/js/src/static_dependencies/ethers/hash/index.d.ts +10 -0
  133. package/js/src/static_dependencies/ethers/hash/index.js +15 -0
  134. package/js/src/static_dependencies/ethers/hash/solidity.d.ts +30 -0
  135. package/js/src/static_dependencies/ethers/hash/solidity.js +107 -0
  136. package/js/src/static_dependencies/ethers/hash/typed-data.d.ts +144 -0
  137. package/js/src/static_dependencies/ethers/hash/typed-data.js +490 -0
  138. package/js/src/static_dependencies/ethers/index.d.ts +19 -0
  139. package/js/src/static_dependencies/ethers/index.js +22 -0
  140. package/js/src/static_dependencies/ethers/interface.d.ts +380 -0
  141. package/js/src/static_dependencies/ethers/interface.js +990 -0
  142. package/js/src/static_dependencies/ethers/typed.d.ts +569 -0
  143. package/js/src/static_dependencies/ethers/typed.js +608 -0
  144. package/js/src/static_dependencies/ethers/utils/base58.d.ts +22 -0
  145. package/js/src/static_dependencies/ethers/utils/base58.js +68 -0
  146. package/js/src/static_dependencies/ethers/utils/base64-browser.d.ts +3 -0
  147. package/js/src/static_dependencies/ethers/utils/base64-browser.js +24 -0
  148. package/js/src/static_dependencies/ethers/utils/base64.d.ts +39 -0
  149. package/js/src/static_dependencies/ethers/utils/base64.js +58 -0
  150. package/js/src/static_dependencies/ethers/utils/data.d.ts +92 -0
  151. package/js/src/static_dependencies/ethers/utils/data.js +175 -0
  152. package/js/src/static_dependencies/ethers/utils/errors.d.ts +509 -0
  153. package/js/src/static_dependencies/ethers/utils/errors.js +227 -0
  154. package/js/src/static_dependencies/ethers/utils/events.d.ts +76 -0
  155. package/js/src/static_dependencies/ethers/utils/events.js +52 -0
  156. package/js/src/static_dependencies/ethers/utils/fixednumber.d.ts +251 -0
  157. package/js/src/static_dependencies/ethers/utils/fixednumber.js +529 -0
  158. package/js/src/static_dependencies/ethers/utils/index.d.ts +30 -0
  159. package/js/src/static_dependencies/ethers/utils/index.js +38 -0
  160. package/js/src/static_dependencies/ethers/utils/maths.d.ts +65 -0
  161. package/js/src/static_dependencies/ethers/utils/maths.js +220 -0
  162. package/js/src/static_dependencies/ethers/utils/properties.d.ts +22 -0
  163. package/js/src/static_dependencies/ethers/utils/properties.js +59 -0
  164. package/js/src/static_dependencies/ethers/utils/rlp-decode.d.ts +5 -0
  165. package/js/src/static_dependencies/ethers/utils/rlp-decode.js +84 -0
  166. package/js/src/static_dependencies/ethers/utils/rlp-encode.d.ts +5 -0
  167. package/js/src/static_dependencies/ethers/utils/rlp-encode.js +54 -0
  168. package/js/src/static_dependencies/ethers/utils/rlp.d.ts +16 -0
  169. package/js/src/static_dependencies/ethers/utils/rlp.js +14 -0
  170. package/js/src/static_dependencies/ethers/utils/units.d.ts +23 -0
  171. package/js/src/static_dependencies/ethers/utils/units.js +88 -0
  172. package/js/src/static_dependencies/ethers/utils/utf8.d.ts +95 -0
  173. package/js/src/static_dependencies/ethers/utils/utf8.js +225 -0
  174. package/js/src/static_dependencies/ethers/utils/uuid.d.ts +7 -0
  175. package/js/src/static_dependencies/ethers/utils/uuid.js +35 -0
  176. package/js/src/static_dependencies/messagepack/msgpack.d.ts +2 -0
  177. package/js/src/static_dependencies/messagepack/msgpack.js +572 -0
  178. package/js/src/tokocrypto.js +22 -2
  179. package/js/src/wazirx.d.ts +12 -1
  180. package/js/src/wazirx.js +314 -4
  181. package/js/src/woo.d.ts +8 -0
  182. package/js/src/woo.js +157 -77
  183. package/package.json +1 -1
  184. package/skip-tests.json +60 -16
@@ -0,0 +1,134 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var errors = require('./errors.js');
6
+
7
+ /**
8
+ * Some data helpers.
9
+ *
10
+ *
11
+ * @_subsection api/utils:Data Helpers [about-data]
12
+ */
13
+ function _getBytes(value, name, copy) {
14
+ if (value instanceof Uint8Array) {
15
+ if (copy) {
16
+ return new Uint8Array(value);
17
+ }
18
+ return value;
19
+ }
20
+ if (typeof (value) === "string" && value.match(/^0x([0-9a-f][0-9a-f])*$/i)) {
21
+ const result = new Uint8Array((value.length - 2) / 2);
22
+ let offset = 2;
23
+ for (let i = 0; i < result.length; i++) {
24
+ result[i] = parseInt(value.substring(offset, offset + 2), 16);
25
+ offset += 2;
26
+ }
27
+ return result;
28
+ }
29
+ errors.assertArgument(false, "invalid BytesLike value", name || "value", value);
30
+ }
31
+ /**
32
+ * Get a typed Uint8Array for %%value%%. If already a Uint8Array
33
+ * the original %%value%% is returned; if a copy is required use
34
+ * [[getBytesCopy]].
35
+ *
36
+ * @see: getBytesCopy
37
+ */
38
+ function getBytes(value, name) {
39
+ return _getBytes(value, name, false);
40
+ }
41
+ /**
42
+ * Get a typed Uint8Array for %%value%%, creating a copy if necessary
43
+ * to prevent any modifications of the returned value from being
44
+ * reflected elsewhere.
45
+ *
46
+ * @see: getBytes
47
+ */
48
+ function getBytesCopy(value, name) {
49
+ return _getBytes(value, name, true);
50
+ }
51
+ /**
52
+ * Returns true if %%value%% is a valid [[HexString]].
53
+ *
54
+ * If %%length%% is ``true`` or a //number//, it also checks that
55
+ * %%value%% is a valid [[DataHexString]] of %%length%% (if a //number//)
56
+ * bytes of data (e.g. ``0x1234`` is 2 bytes).
57
+ */
58
+ function isHexString(value, length) {
59
+ if (typeof (value) !== "string" || !value.match(/^0x[0-9A-Fa-f]*$/)) {
60
+ return false;
61
+ }
62
+ if (typeof (length) === "number" && value.length !== 2 + 2 * length) {
63
+ return false;
64
+ }
65
+ if (length === true && (value.length % 2) !== 0) {
66
+ return false;
67
+ }
68
+ return true;
69
+ }
70
+ /**
71
+ * Returns true if %%value%% is a valid representation of arbitrary
72
+ * data (i.e. a valid [[DataHexString]] or a Uint8Array).
73
+ */
74
+ function isBytesLike(value) {
75
+ return (isHexString(value, true) || (value instanceof Uint8Array));
76
+ }
77
+ const HexCharacters = "0123456789abcdef";
78
+ /**
79
+ * Returns a [[DataHexString]] representation of %%data%%.
80
+ */
81
+ function hexlify(data) {
82
+ const bytes = getBytes(data);
83
+ let result = "0x";
84
+ for (let i = 0; i < bytes.length; i++) {
85
+ const v = bytes[i];
86
+ result += HexCharacters[(v & 0xf0) >> 4] + HexCharacters[v & 0x0f];
87
+ }
88
+ return result;
89
+ }
90
+ /**
91
+ * Returns a [[DataHexString]] by concatenating all values
92
+ * within %%data%%.
93
+ */
94
+ function concat(datas) {
95
+ return "0x" + datas.map((d) => hexlify(d).substring(2)).join("");
96
+ }
97
+ function zeroPad(data, length, left) {
98
+ const bytes = getBytes(data);
99
+ errors.assert(length >= bytes.length, "padding exceeds data length", "BUFFER_OVERRUN", {
100
+ buffer: new Uint8Array(bytes),
101
+ length: length,
102
+ offset: length + 1
103
+ });
104
+ const result = new Uint8Array(length);
105
+ result.fill(0);
106
+ if (left) {
107
+ result.set(bytes, length - bytes.length);
108
+ }
109
+ else {
110
+ result.set(bytes, 0);
111
+ }
112
+ return hexlify(result);
113
+ }
114
+ /**
115
+ * Return the [[DataHexString]] of %%data%% padded on the **left**
116
+ * to %%length%% bytes.
117
+ *
118
+ * If %%data%% already exceeds %%length%%, a [[BufferOverrunError]] is
119
+ * thrown.
120
+ *
121
+ * This pads data the same as **values** are in Solidity
122
+ * (e.g. ``uint128``).
123
+ */
124
+ function zeroPadValue(data, length) {
125
+ return zeroPad(data, length, true);
126
+ }
127
+
128
+ exports.concat = concat;
129
+ exports.getBytes = getBytes;
130
+ exports.getBytesCopy = getBytesCopy;
131
+ exports.hexlify = hexlify;
132
+ exports.isBytesLike = isBytesLike;
133
+ exports.isHexString = isHexString;
134
+ exports.zeroPadValue = zeroPadValue;
@@ -0,0 +1,228 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var properties = require('./properties.js');
6
+
7
+ /**
8
+ * All errors in ethers include properties to ensure they are both
9
+ * human-readable (i.e. ``.message``) and machine-readable (i.e. ``.code``).
10
+ *
11
+ * The [[isError]] function can be used to check the error ``code`` and
12
+ * provide a type guard for the properties present on that error interface.
13
+ *
14
+ * @_section: api/utils/errors:Errors [about-errors]
15
+ */
16
+ function stringify(value) {
17
+ if (value == null) {
18
+ return "null";
19
+ }
20
+ if (Array.isArray(value)) {
21
+ return "[ " + (value.map(stringify)).join(", ") + " ]";
22
+ }
23
+ if (value instanceof Uint8Array) {
24
+ const HEX = "0123456789abcdef";
25
+ let result = "0x";
26
+ for (let i = 0; i < value.length; i++) {
27
+ result += HEX[value[i] >> 4];
28
+ result += HEX[value[i] & 0xf];
29
+ }
30
+ return result;
31
+ }
32
+ if (typeof (value) === "object" && typeof (value.toJSON) === "function") {
33
+ return stringify(value.toJSON());
34
+ }
35
+ switch (typeof (value)) {
36
+ case "boolean":
37
+ case "symbol":
38
+ return value.toString();
39
+ case "bigint":
40
+ return BigInt(value).toString();
41
+ case "number":
42
+ return (value).toString();
43
+ case "string":
44
+ return JSON.stringify(value);
45
+ case "object": {
46
+ const keys = Object.keys(value);
47
+ keys.sort();
48
+ return "{ " + keys.map((k) => `${stringify(k)}: ${stringify(value[k])}`).join(", ") + " }";
49
+ }
50
+ }
51
+ return `[ COULD NOT SERIALIZE ]`;
52
+ }
53
+ /**
54
+ * Returns true if the %%error%% matches an error thrown by ethers
55
+ * that matches the error %%code%%.
56
+ *
57
+ * In TypeScript environments, this can be used to check that %%error%%
58
+ * matches an EthersError type, which means the expected properties will
59
+ * be set.
60
+ *
61
+ * @See [ErrorCodes](api:ErrorCode)
62
+ * @example
63
+ * try {
64
+ * // code....
65
+ * } catch (e) {
66
+ * if (isError(e, "CALL_EXCEPTION")) {
67
+ * // The Type Guard has validated this object
68
+ * console.log(e.data);
69
+ * }
70
+ * }
71
+ */
72
+ function isError(error, code) {
73
+ return (error && error.code === code);
74
+ }
75
+ /**
76
+ * Returns a new Error configured to the format ethers emits errors, with
77
+ * the %%message%%, [[api:ErrorCode]] %%code%% and additional properties
78
+ * for the corresponding EthersError.
79
+ *
80
+ * Each error in ethers includes the version of ethers, a
81
+ * machine-readable [[ErrorCode]], and depending on %%code%%, additional
82
+ * required properties. The error message will also include the %%message%%,
83
+ * ethers version, %%code%% and all additional properties, serialized.
84
+ */
85
+ function makeError(message, code, info) {
86
+ let shortMessage = message;
87
+ {
88
+ const details = [];
89
+ if (info) {
90
+ if ("message" in info || "code" in info || "name" in info) {
91
+ throw new Error(`value will overwrite populated values: ${stringify(info)}`);
92
+ }
93
+ for (const key in info) {
94
+ if (key === "shortMessage") {
95
+ continue;
96
+ }
97
+ const value = (info[key]);
98
+ // try {
99
+ details.push(key + "=" + stringify(value));
100
+ // } catch (error: any) {
101
+ // console.log("MMM", error.message);
102
+ // details.push(key + "=[could not serialize object]");
103
+ // }
104
+ }
105
+ }
106
+ details.push(`code=${code}`);
107
+ if (details.length) {
108
+ message += " (" + details.join(", ") + ")";
109
+ }
110
+ }
111
+ let error;
112
+ switch (code) {
113
+ case "INVALID_ARGUMENT":
114
+ error = new TypeError(message);
115
+ break;
116
+ case "NUMERIC_FAULT":
117
+ case "BUFFER_OVERRUN":
118
+ error = new RangeError(message);
119
+ break;
120
+ default:
121
+ error = new Error(message);
122
+ }
123
+ properties.defineProperties(error, { code });
124
+ if (info) {
125
+ Object.assign(error, info);
126
+ }
127
+ if (error.shortMessage == null) {
128
+ properties.defineProperties(error, { shortMessage });
129
+ }
130
+ return error;
131
+ }
132
+ /**
133
+ * Throws an EthersError with %%message%%, %%code%% and additional error
134
+ * %%info%% when %%check%% is falsish..
135
+ *
136
+ * @see [[api:makeError]]
137
+ */
138
+ function assert(check, message, code, info) {
139
+ if (!check) {
140
+ throw makeError(message, code, info);
141
+ }
142
+ }
143
+ /**
144
+ * A simple helper to simply ensuring provided arguments match expected
145
+ * constraints, throwing if not.
146
+ *
147
+ * In TypeScript environments, the %%check%% has been asserted true, so
148
+ * any further code does not need additional compile-time checks.
149
+ */
150
+ function assertArgument(check, message, name, value) {
151
+ assert(check, message, "INVALID_ARGUMENT", { argument: name, value: value });
152
+ }
153
+ function assertArgumentCount(count, expectedCount, message) {
154
+ if (message == null) {
155
+ message = "";
156
+ }
157
+ if (message) {
158
+ message = ": " + message;
159
+ }
160
+ assert(count >= expectedCount, "missing arguemnt" + message, "MISSING_ARGUMENT", {
161
+ count: count,
162
+ expectedCount: expectedCount
163
+ });
164
+ assert(count <= expectedCount, "too many arguemnts" + message, "UNEXPECTED_ARGUMENT", {
165
+ count: count,
166
+ expectedCount: expectedCount
167
+ });
168
+ }
169
+ const _normalizeForms = ["NFD", "NFC", "NFKD", "NFKC"].reduce((accum, form) => {
170
+ try {
171
+ // General test for normalize
172
+ /* c8 ignore start */
173
+ if ("test".normalize(form) !== "test") {
174
+ throw new Error("bad");
175
+ }
176
+ ;
177
+ /* c8 ignore stop */
178
+ if (form === "NFD") {
179
+ const check = String.fromCharCode(0xe9).normalize("NFD");
180
+ const expected = String.fromCharCode(0x65, 0x0301);
181
+ /* c8 ignore start */
182
+ if (check !== expected) {
183
+ throw new Error("broken");
184
+ }
185
+ /* c8 ignore stop */
186
+ }
187
+ accum.push(form);
188
+ }
189
+ catch (error) { }
190
+ return accum;
191
+ }, []);
192
+ /**
193
+ * Throws if the normalization %%form%% is not supported.
194
+ */
195
+ function assertNormalize(form) {
196
+ assert(_normalizeForms.indexOf(form) >= 0, "platform missing String.prototype.normalize", "UNSUPPORTED_OPERATION", {
197
+ operation: "String.prototype.normalize", info: { form }
198
+ });
199
+ }
200
+ /**
201
+ * Many classes use file-scoped values to guard the constructor,
202
+ * making it effectively private. This facilitates that pattern
203
+ * by ensuring the %%givenGaurd%% matches the file-scoped %%guard%%,
204
+ * throwing if not, indicating the %%className%% if provided.
205
+ */
206
+ function assertPrivate(givenGuard, guard, className) {
207
+ if (className == null) {
208
+ className = "";
209
+ }
210
+ if (givenGuard !== guard) {
211
+ let method = className, operation = "new";
212
+ if (className) {
213
+ method += ".";
214
+ operation += " " + className;
215
+ }
216
+ assert(false, `private constructor; use ${method}from* methods`, "UNSUPPORTED_OPERATION", {
217
+ operation
218
+ });
219
+ }
220
+ }
221
+
222
+ exports.assert = assert;
223
+ exports.assertArgument = assertArgument;
224
+ exports.assertArgumentCount = assertArgumentCount;
225
+ exports.assertNormalize = assertNormalize;
226
+ exports.assertPrivate = assertPrivate;
227
+ exports.isError = isError;
228
+ exports.makeError = makeError;
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
4
+ if (kind === "m") throw new TypeError("Private method is not writable");
5
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
6
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
7
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
8
+ };
9
+ (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
10
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
11
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
12
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
13
+ };
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ require('./errors.js');
4
+ require('./maths.js');
5
+
6
+ (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
+ if (kind === "m") throw new TypeError("Private method is not writable");
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
+ };
12
+ (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
14
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
15
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
16
+ };
17
+ BigInt(-1);
18
+ BigInt(0);
19
+ BigInt(1);
20
+ BigInt(5);
21
+ // Constant to pull zeros from for multipliers
22
+ let Zeros = "0000";
23
+ while (Zeros.length < 80) {
24
+ Zeros += Zeros;
25
+ }
26
+ //const f1 = FixedNumber.fromString("12.56", "fixed16x2");
27
+ //const f2 = FixedNumber.fromString("0.3", "fixed16x2");
28
+ //console.log(f1.divSignal(f2));
29
+ //const BUMP = FixedNumber.from("0.5");
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('./base58.js');
6
+ var errors = require('./errors.js');
7
+ require('./events.js');
8
+ require('./fixednumber.js');
9
+ var maths = require('./maths.js');
10
+ var utf8 = require('./utf8.js');
11
+ require('../../../base/functions/platform.js');
12
+ require('../../../base/functions/encode.js');
13
+ var crypto = require('../../../base/functions/crypto.js');
14
+ var sha3 = require('../../noble-hashes/sha3.js');
15
+ require('../../noble-hashes/sha256.js');
16
+
17
+ /**
18
+ * There are many simple utilities required to interact with
19
+ * Ethereum and to simplify the library, without increasing
20
+ * the library dependencies for simple functions.
21
+ *
22
+ * @_section api/utils:Utilities [about-utils]
23
+ */
24
+ function id(value) {
25
+ return '0x' + crypto.hash(value, sha3.keccak_256, 'hex');
26
+ }
27
+ function keccak256(value) {
28
+ return '0x' + crypto.hash(value, sha3.keccak_256, 'hex');
29
+ }
30
+
31
+ exports.assert = errors.assert;
32
+ exports.assertArgument = errors.assertArgument;
33
+ exports.assertArgumentCount = errors.assertArgumentCount;
34
+ exports.assertNormalize = errors.assertNormalize;
35
+ exports.assertPrivate = errors.assertPrivate;
36
+ exports.isError = errors.isError;
37
+ exports.makeError = errors.makeError;
38
+ exports.fromTwos = maths.fromTwos;
39
+ exports.getBigInt = maths.getBigInt;
40
+ exports.getNumber = maths.getNumber;
41
+ exports.getUint = maths.getUint;
42
+ exports.mask = maths.mask;
43
+ exports.toBeArray = maths.toBeArray;
44
+ exports.toBeHex = maths.toBeHex;
45
+ exports.toBigInt = maths.toBigInt;
46
+ exports.toNumber = maths.toNumber;
47
+ exports.toQuantity = maths.toQuantity;
48
+ exports.toTwos = maths.toTwos;
49
+ exports.Utf8ErrorFuncs = utf8.Utf8ErrorFuncs;
50
+ exports.toUtf8Bytes = utf8.toUtf8Bytes;
51
+ exports.toUtf8String = utf8.toUtf8String;
52
+ exports.id = id;
53
+ exports.keccak256 = keccak256;
@@ -0,0 +1,231 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var data = require('./data.js');
6
+ var errors = require('./errors.js');
7
+
8
+ /**
9
+ * Some mathematic operations.
10
+ *
11
+ * @_subsection: api/utils:Math Helpers [about-maths]
12
+ */
13
+ const BN_0 = BigInt(0);
14
+ const BN_1 = BigInt(1);
15
+ //const BN_Max256 = (BN_1 << BigInt(256)) - BN_1;
16
+ // IEEE 754 support 53-bits of mantissa
17
+ const maxValue = 0x1fffffffffffff;
18
+ /**
19
+ * Convert %%value%% from a twos-compliment representation of %%width%%
20
+ * bits to its value.
21
+ *
22
+ * If the highest bit is ``1``, the result will be negative.
23
+ */
24
+ function fromTwos(_value, _width) {
25
+ const value = getUint(_value, "value");
26
+ const width = BigInt(getNumber(_width, "width"));
27
+ errors.assert((value >> width) === BN_0, "overflow", "NUMERIC_FAULT", {
28
+ operation: "fromTwos", fault: "overflow", value: _value
29
+ });
30
+ // Top bit set; treat as a negative value
31
+ if (value >> (width - BN_1)) {
32
+ const mask = (BN_1 << width) - BN_1;
33
+ return -(((~value) & mask) + BN_1);
34
+ }
35
+ return value;
36
+ }
37
+ /**
38
+ * Convert %%value%% to a twos-compliment representation of
39
+ * %%width%% bits.
40
+ *
41
+ * The result will always be positive.
42
+ */
43
+ function toTwos(_value, _width) {
44
+ let value = getBigInt(_value, "value");
45
+ const width = BigInt(getNumber(_width, "width"));
46
+ const limit = (BN_1 << (width - BN_1));
47
+ if (value < BN_0) {
48
+ value = -value;
49
+ errors.assert(value <= limit, "too low", "NUMERIC_FAULT", {
50
+ operation: "toTwos", fault: "overflow", value: _value
51
+ });
52
+ const mask = (BN_1 << width) - BN_1;
53
+ return ((~value) & mask) + BN_1;
54
+ }
55
+ else {
56
+ errors.assert(value < limit, "too high", "NUMERIC_FAULT", {
57
+ operation: "toTwos", fault: "overflow", value: _value
58
+ });
59
+ }
60
+ return value;
61
+ }
62
+ /**
63
+ * Mask %%value%% with a bitmask of %%bits%% ones.
64
+ */
65
+ function mask(_value, _bits) {
66
+ const value = getUint(_value, "value");
67
+ const bits = BigInt(getNumber(_bits, "bits"));
68
+ return value & ((BN_1 << bits) - BN_1);
69
+ }
70
+ /**
71
+ * Gets a BigInt from %%value%%. If it is an invalid value for
72
+ * a BigInt, then an ArgumentError will be thrown for %%name%%.
73
+ */
74
+ function getBigInt(value, name) {
75
+ switch (typeof (value)) {
76
+ case "bigint": return value;
77
+ case "number":
78
+ errors.assertArgument(Number.isInteger(value), "underflow", name || "value", value);
79
+ errors.assertArgument(value >= -maxValue && value <= maxValue, "overflow", name || "value", value);
80
+ return BigInt(value);
81
+ case "string":
82
+ try {
83
+ if (value === "") {
84
+ throw new Error("empty string");
85
+ }
86
+ if (value[0] === "-" && value[1] !== "-") {
87
+ return -BigInt(value.substring(1));
88
+ }
89
+ return BigInt(value);
90
+ }
91
+ catch (e) {
92
+ errors.assertArgument(false, `invalid BigNumberish string: ${e.message}`, name || "value", value);
93
+ }
94
+ }
95
+ errors.assertArgument(false, "invalid BigNumberish value", name || "value", value);
96
+ }
97
+ /**
98
+ * Returns %%value%% as a bigint, validating it is valid as a bigint
99
+ * value and that it is positive.
100
+ */
101
+ function getUint(value, name) {
102
+ const result = getBigInt(value, name);
103
+ errors.assert(result >= BN_0, "unsigned value cannot be negative", "NUMERIC_FAULT", {
104
+ fault: "overflow", operation: "getUint", value
105
+ });
106
+ return result;
107
+ }
108
+ const Nibbles = "0123456789abcdef";
109
+ /*
110
+ * Converts %%value%% to a BigInt. If %%value%% is a Uint8Array, it
111
+ * is treated as Big Endian data.
112
+ */
113
+ function toBigInt(value) {
114
+ if (value instanceof Uint8Array) {
115
+ let result = "0x0";
116
+ for (const v of value) {
117
+ result += Nibbles[v >> 4];
118
+ result += Nibbles[v & 0x0f];
119
+ }
120
+ return BigInt(result);
121
+ }
122
+ return getBigInt(value);
123
+ }
124
+ /**
125
+ * Gets a //number// from %%value%%. If it is an invalid value for
126
+ * a //number//, then an ArgumentError will be thrown for %%name%%.
127
+ */
128
+ function getNumber(value, name) {
129
+ switch (typeof (value)) {
130
+ case "bigint":
131
+ errors.assertArgument(value >= -maxValue && value <= maxValue, "overflow", name || "value", value);
132
+ return Number(value);
133
+ case "number":
134
+ errors.assertArgument(Number.isInteger(value), "underflow", name || "value", value);
135
+ errors.assertArgument(value >= -maxValue && value <= maxValue, "overflow", name || "value", value);
136
+ return value;
137
+ case "string":
138
+ try {
139
+ if (value === "") {
140
+ throw new Error("empty string");
141
+ }
142
+ return getNumber(BigInt(value), name);
143
+ }
144
+ catch (e) {
145
+ errors.assertArgument(false, `invalid numeric string: ${e.message}`, name || "value", value);
146
+ }
147
+ }
148
+ errors.assertArgument(false, "invalid numeric value", name || "value", value);
149
+ }
150
+ /**
151
+ * Converts %%value%% to a number. If %%value%% is a Uint8Array, it
152
+ * is treated as Big Endian data. Throws if the value is not safe.
153
+ */
154
+ function toNumber(value) {
155
+ return getNumber(toBigInt(value));
156
+ }
157
+ /**
158
+ * Converts %%value%% to a Big Endian hexstring, optionally padded to
159
+ * %%width%% bytes.
160
+ */
161
+ function toBeHex(_value, _width) {
162
+ const value = getUint(_value, "value");
163
+ let result = value.toString(16);
164
+ if (_width == null) {
165
+ // Ensure the value is of even length
166
+ if (result.length % 2) {
167
+ result = "0" + result;
168
+ }
169
+ }
170
+ else {
171
+ const width = getNumber(_width, "width");
172
+ errors.assert(width * 2 >= result.length, `value exceeds width (${width} bytes)`, "NUMERIC_FAULT", {
173
+ operation: "toBeHex",
174
+ fault: "overflow",
175
+ value: _value
176
+ });
177
+ // Pad the value to the required width
178
+ while (result.length < (width * 2)) {
179
+ result = "0" + result;
180
+ }
181
+ }
182
+ return "0x" + result;
183
+ }
184
+ /**
185
+ * Converts %%value%% to a Big Endian Uint8Array.
186
+ */
187
+ function toBeArray(_value) {
188
+ const value = getUint(_value, "value");
189
+ if (value === BN_0) {
190
+ return new Uint8Array([]);
191
+ }
192
+ let hex = value.toString(16);
193
+ if (hex.length % 2) {
194
+ hex = "0" + hex;
195
+ }
196
+ const result = new Uint8Array(hex.length / 2);
197
+ for (let i = 0; i < result.length; i++) {
198
+ const offset = i * 2;
199
+ result[i] = parseInt(hex.substring(offset, offset + 2), 16);
200
+ }
201
+ return result;
202
+ }
203
+ /**
204
+ * Returns a [[HexString]] for %%value%% safe to use as a //Quantity//.
205
+ *
206
+ * A //Quantity// does not have and leading 0 values unless the value is
207
+ * the literal value `0x0`. This is most commonly used for JSSON-RPC
208
+ * numeric values.
209
+ */
210
+ function toQuantity(value) {
211
+ let result = data.hexlify(data.isBytesLike(value) ? value : toBeArray(value)).substring(2);
212
+ while (result.startsWith("0")) {
213
+ result = result.substring(1);
214
+ }
215
+ if (result === "") {
216
+ result = "0";
217
+ }
218
+ return "0x" + result;
219
+ }
220
+
221
+ exports.fromTwos = fromTwos;
222
+ exports.getBigInt = getBigInt;
223
+ exports.getNumber = getNumber;
224
+ exports.getUint = getUint;
225
+ exports.mask = mask;
226
+ exports.toBeArray = toBeArray;
227
+ exports.toBeHex = toBeHex;
228
+ exports.toBigInt = toBigInt;
229
+ exports.toNumber = toNumber;
230
+ exports.toQuantity = toQuantity;
231
+ exports.toTwos = toTwos;