ccxt 4.2.60 → 4.2.62

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 (160) hide show
  1. package/README.md +6 -5
  2. package/build.sh +1 -1
  3. package/dist/ccxt.browser.js +11280 -3407
  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/base/Exchange.js +22 -1
  8. package/dist/cjs/src/base/functions/encode.js +5 -0
  9. package/dist/cjs/src/base/functions.js +1 -0
  10. package/dist/cjs/src/bitfinex2.js +1 -1
  11. package/dist/cjs/src/bitget.js +74 -23
  12. package/dist/cjs/src/coinbase.js +108 -103
  13. package/dist/cjs/src/coinex.js +61 -1
  14. package/dist/cjs/src/hyperliquid.js +2035 -0
  15. package/dist/cjs/src/kraken.js +8 -2
  16. package/dist/cjs/src/krakenfutures.js +28 -0
  17. package/dist/cjs/src/kucoinfutures.js +2 -2
  18. package/dist/cjs/src/okx.js +1 -1
  19. package/dist/cjs/src/phemex.js +2 -2
  20. package/dist/cjs/src/pro/bingx.js +1 -0
  21. package/dist/cjs/src/static_dependencies/ethers/abi-coder.js +158 -0
  22. package/dist/cjs/src/static_dependencies/ethers/address/address.js +144 -0
  23. package/dist/cjs/src/static_dependencies/ethers/coders/abstract-coder.js +407 -0
  24. package/dist/cjs/src/static_dependencies/ethers/coders/address.js +45 -0
  25. package/dist/cjs/src/static_dependencies/ethers/coders/anonymous.js +28 -0
  26. package/dist/cjs/src/static_dependencies/ethers/coders/array.js +176 -0
  27. package/dist/cjs/src/static_dependencies/ethers/coders/boolean.js +27 -0
  28. package/dist/cjs/src/static_dependencies/ethers/coders/bytes.js +52 -0
  29. package/dist/cjs/src/static_dependencies/ethers/coders/fixed-bytes.js +45 -0
  30. package/dist/cjs/src/static_dependencies/ethers/coders/null.js +30 -0
  31. package/dist/cjs/src/static_dependencies/ethers/coders/number.js +60 -0
  32. package/dist/cjs/src/static_dependencies/ethers/coders/string.js +27 -0
  33. package/dist/cjs/src/static_dependencies/ethers/coders/tuple.js +68 -0
  34. package/dist/cjs/src/static_dependencies/ethers/fragments.js +614 -0
  35. package/dist/cjs/src/static_dependencies/ethers/hash/typed-data.js +492 -0
  36. package/dist/cjs/src/static_dependencies/ethers/index.js +35 -0
  37. package/dist/cjs/src/static_dependencies/ethers/interface.js +44 -0
  38. package/dist/cjs/src/static_dependencies/ethers/typed.js +618 -0
  39. package/dist/cjs/src/static_dependencies/ethers/utils/base58.js +20 -0
  40. package/dist/cjs/src/static_dependencies/ethers/utils/data.js +134 -0
  41. package/dist/cjs/src/static_dependencies/ethers/utils/errors.js +228 -0
  42. package/dist/cjs/src/static_dependencies/ethers/utils/events.js +13 -0
  43. package/dist/cjs/src/static_dependencies/ethers/utils/fixednumber.js +29 -0
  44. package/dist/cjs/src/static_dependencies/ethers/utils/index.js +53 -0
  45. package/dist/cjs/src/static_dependencies/ethers/utils/maths.js +231 -0
  46. package/dist/cjs/src/static_dependencies/ethers/utils/properties.js +47 -0
  47. package/dist/cjs/src/static_dependencies/ethers/utils/utf8.js +218 -0
  48. package/dist/cjs/src/static_dependencies/messagepack/msgpack.js +292 -0
  49. package/dist/cjs/src/tokocrypto.js +22 -2
  50. package/dist/cjs/src/wazirx.js +308 -3
  51. package/js/ccxt.d.ts +5 -2
  52. package/js/ccxt.js +4 -2
  53. package/js/src/abstract/coinbase.d.ts +3 -3
  54. package/js/src/abstract/hyperliquid.d.ts +9 -0
  55. package/js/src/abstract/hyperliquid.js +11 -0
  56. package/js/src/base/Exchange.d.ts +4 -0
  57. package/js/src/base/Exchange.js +13 -1
  58. package/js/src/base/functions/encode.d.ts +2 -1
  59. package/js/src/base/functions/encode.js +5 -1
  60. package/js/src/bitfinex2.js +1 -1
  61. package/js/src/bitget.js +74 -23
  62. package/js/src/coinbase.js +108 -103
  63. package/js/src/coinex.d.ts +3 -1
  64. package/js/src/coinex.js +61 -1
  65. package/js/src/hyperliquid.d.ts +83 -0
  66. package/js/src/hyperliquid.js +2036 -0
  67. package/js/src/kraken.js +8 -2
  68. package/js/src/krakenfutures.d.ts +2 -1
  69. package/js/src/krakenfutures.js +28 -0
  70. package/js/src/kucoinfutures.js +2 -2
  71. package/js/src/okx.js +1 -1
  72. package/js/src/phemex.js +2 -2
  73. package/js/src/pro/bingx.js +1 -0
  74. package/js/src/static_dependencies/ethers/abi-coder.d.ts +50 -0
  75. package/js/src/static_dependencies/ethers/abi-coder.js +148 -0
  76. package/js/src/static_dependencies/ethers/address/address.d.ts +55 -0
  77. package/js/src/static_dependencies/ethers/address/address.js +162 -0
  78. package/js/src/static_dependencies/ethers/address/checks.d.ts +80 -0
  79. package/js/src/static_dependencies/ethers/address/checks.js +119 -0
  80. package/js/src/static_dependencies/ethers/address/contract-address.d.ts +47 -0
  81. package/js/src/static_dependencies/ethers/address/contract-address.js +73 -0
  82. package/js/src/static_dependencies/ethers/address/index.d.ts +48 -0
  83. package/js/src/static_dependencies/ethers/address/index.js +24 -0
  84. package/js/src/static_dependencies/ethers/bytes32.d.ts +14 -0
  85. package/js/src/static_dependencies/ethers/bytes32.js +45 -0
  86. package/js/src/static_dependencies/ethers/coders/abstract-coder.d.ts +120 -0
  87. package/js/src/static_dependencies/ethers/coders/abstract-coder.js +424 -0
  88. package/js/src/static_dependencies/ethers/coders/address.d.ts +12 -0
  89. package/js/src/static_dependencies/ethers/coders/address.js +34 -0
  90. package/js/src/static_dependencies/ethers/coders/anonymous.d.ts +14 -0
  91. package/js/src/static_dependencies/ethers/coders/anonymous.js +27 -0
  92. package/js/src/static_dependencies/ethers/coders/array.d.ts +24 -0
  93. package/js/src/static_dependencies/ethers/coders/array.js +162 -0
  94. package/js/src/static_dependencies/ethers/coders/boolean.d.ts +12 -0
  95. package/js/src/static_dependencies/ethers/coders/boolean.js +26 -0
  96. package/js/src/static_dependencies/ethers/coders/bytes.d.ts +18 -0
  97. package/js/src/static_dependencies/ethers/coders/bytes.js +39 -0
  98. package/js/src/static_dependencies/ethers/coders/fixed-bytes.d.ts +14 -0
  99. package/js/src/static_dependencies/ethers/coders/fixed-bytes.js +32 -0
  100. package/js/src/static_dependencies/ethers/coders/null.d.ts +11 -0
  101. package/js/src/static_dependencies/ethers/coders/null.js +29 -0
  102. package/js/src/static_dependencies/ethers/coders/number.d.ts +15 -0
  103. package/js/src/static_dependencies/ethers/coders/number.js +48 -0
  104. package/js/src/static_dependencies/ethers/coders/string.d.ts +12 -0
  105. package/js/src/static_dependencies/ethers/coders/string.js +26 -0
  106. package/js/src/static_dependencies/ethers/coders/tuple.d.ts +15 -0
  107. package/js/src/static_dependencies/ethers/coders/tuple.js +67 -0
  108. package/js/src/static_dependencies/ethers/fragments.d.ts +458 -0
  109. package/js/src/static_dependencies/ethers/fragments.js +1252 -0
  110. package/js/src/static_dependencies/ethers/hash/index.d.ts +10 -0
  111. package/js/src/static_dependencies/ethers/hash/index.js +15 -0
  112. package/js/src/static_dependencies/ethers/hash/solidity.d.ts +30 -0
  113. package/js/src/static_dependencies/ethers/hash/solidity.js +107 -0
  114. package/js/src/static_dependencies/ethers/hash/typed-data.d.ts +144 -0
  115. package/js/src/static_dependencies/ethers/hash/typed-data.js +490 -0
  116. package/js/src/static_dependencies/ethers/index.d.ts +19 -0
  117. package/js/src/static_dependencies/ethers/index.js +22 -0
  118. package/js/src/static_dependencies/ethers/interface.d.ts +380 -0
  119. package/js/src/static_dependencies/ethers/interface.js +990 -0
  120. package/js/src/static_dependencies/ethers/typed.d.ts +569 -0
  121. package/js/src/static_dependencies/ethers/typed.js +608 -0
  122. package/js/src/static_dependencies/ethers/utils/base58.d.ts +22 -0
  123. package/js/src/static_dependencies/ethers/utils/base58.js +68 -0
  124. package/js/src/static_dependencies/ethers/utils/base64-browser.d.ts +3 -0
  125. package/js/src/static_dependencies/ethers/utils/base64-browser.js +24 -0
  126. package/js/src/static_dependencies/ethers/utils/base64.d.ts +39 -0
  127. package/js/src/static_dependencies/ethers/utils/base64.js +58 -0
  128. package/js/src/static_dependencies/ethers/utils/data.d.ts +92 -0
  129. package/js/src/static_dependencies/ethers/utils/data.js +175 -0
  130. package/js/src/static_dependencies/ethers/utils/errors.d.ts +509 -0
  131. package/js/src/static_dependencies/ethers/utils/errors.js +227 -0
  132. package/js/src/static_dependencies/ethers/utils/events.d.ts +76 -0
  133. package/js/src/static_dependencies/ethers/utils/events.js +52 -0
  134. package/js/src/static_dependencies/ethers/utils/fixednumber.d.ts +251 -0
  135. package/js/src/static_dependencies/ethers/utils/fixednumber.js +529 -0
  136. package/js/src/static_dependencies/ethers/utils/index.d.ts +30 -0
  137. package/js/src/static_dependencies/ethers/utils/index.js +38 -0
  138. package/js/src/static_dependencies/ethers/utils/maths.d.ts +65 -0
  139. package/js/src/static_dependencies/ethers/utils/maths.js +220 -0
  140. package/js/src/static_dependencies/ethers/utils/properties.d.ts +22 -0
  141. package/js/src/static_dependencies/ethers/utils/properties.js +59 -0
  142. package/js/src/static_dependencies/ethers/utils/rlp-decode.d.ts +5 -0
  143. package/js/src/static_dependencies/ethers/utils/rlp-decode.js +84 -0
  144. package/js/src/static_dependencies/ethers/utils/rlp-encode.d.ts +5 -0
  145. package/js/src/static_dependencies/ethers/utils/rlp-encode.js +54 -0
  146. package/js/src/static_dependencies/ethers/utils/rlp.d.ts +16 -0
  147. package/js/src/static_dependencies/ethers/utils/rlp.js +14 -0
  148. package/js/src/static_dependencies/ethers/utils/units.d.ts +23 -0
  149. package/js/src/static_dependencies/ethers/utils/units.js +88 -0
  150. package/js/src/static_dependencies/ethers/utils/utf8.d.ts +95 -0
  151. package/js/src/static_dependencies/ethers/utils/utf8.js +225 -0
  152. package/js/src/static_dependencies/ethers/utils/uuid.d.ts +7 -0
  153. package/js/src/static_dependencies/ethers/utils/uuid.js +35 -0
  154. package/js/src/static_dependencies/messagepack/msgpack.d.ts +2 -0
  155. package/js/src/static_dependencies/messagepack/msgpack.js +572 -0
  156. package/js/src/tokocrypto.js +22 -2
  157. package/js/src/wazirx.d.ts +12 -1
  158. package/js/src/wazirx.js +308 -3
  159. package/package.json +1 -1
  160. package/skip-tests.json +18 -0
@@ -0,0 +1,492 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var address = require('../address/address.js');
6
+ var index = require('../utils/index.js');
7
+ var functions = require('../../../base/functions.js');
8
+ var maths = require('../utils/maths.js');
9
+ var errors = require('../utils/errors.js');
10
+ var properties = require('../utils/properties.js');
11
+ var data = require('../utils/data.js');
12
+
13
+ var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
14
+ if (kind === "m") throw new TypeError("Private method is not writable");
15
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
16
+ 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");
17
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
18
+ };
19
+ var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
20
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
21
+ 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");
22
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
23
+ };
24
+ var _TypedDataEncoder_instances, _TypedDataEncoder_types, _TypedDataEncoder_fullTypes, _TypedDataEncoder_encoderCache, _TypedDataEncoder_getEncoder;
25
+ const { base16ToBinary } = functions;
26
+ const padding = new Uint8Array(32);
27
+ padding.fill(0);
28
+ const BN__1 = BigInt(-1);
29
+ const BN_0 = BigInt(0);
30
+ const BN_1 = BigInt(1);
31
+ const BN_MAX_UINT256 = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
32
+ function hexPadRight(value) {
33
+ const bytes = data.getBytes(value);
34
+ const padOffset = bytes.length % 32;
35
+ if (padOffset) {
36
+ return data.concat([bytes, padding.slice(padOffset)]);
37
+ }
38
+ return data.hexlify(bytes);
39
+ }
40
+ const hexTrue = maths.toBeHex(BN_1, 32);
41
+ const hexFalse = maths.toBeHex(BN_0, 32);
42
+ const domainFieldTypes = {
43
+ name: "string",
44
+ version: "string",
45
+ chainId: "uint256",
46
+ verifyingContract: "address",
47
+ salt: "bytes32"
48
+ };
49
+ const domainFieldNames = [
50
+ "name", "version", "chainId", "verifyingContract", "salt"
51
+ ];
52
+ function checkString(key) {
53
+ return function (value) {
54
+ errors.assertArgument(typeof (value) === "string", `invalid domain value for ${JSON.stringify(key)}`, `domain.${key}`, value);
55
+ return value;
56
+ };
57
+ }
58
+ const domainChecks = {
59
+ name: checkString("name"),
60
+ version: checkString("version"),
61
+ chainId: function (_value) {
62
+ const value = maths.getBigInt(_value, "domain.chainId");
63
+ errors.assertArgument(value >= 0, "invalid chain ID", "domain.chainId", _value);
64
+ if (Number.isSafeInteger(value)) {
65
+ return Number(value);
66
+ }
67
+ return maths.toQuantity(value);
68
+ },
69
+ verifyingContract: function (value) {
70
+ try {
71
+ return address.getAddress(value).toLowerCase();
72
+ }
73
+ catch (error) { }
74
+ errors.assertArgument(false, `invalid domain value "verifyingContract"`, "domain.verifyingContract", value);
75
+ },
76
+ salt: function (value) {
77
+ const bytes = data.getBytes(value, "domain.salt");
78
+ errors.assertArgument(bytes.length === 32, `invalid domain value "salt"`, "domain.salt", value);
79
+ return data.hexlify(bytes);
80
+ }
81
+ };
82
+ function getBaseEncoder(type) {
83
+ // intXX and uintXX
84
+ {
85
+ const match = type.match(/^(u?)int(\d*)$/);
86
+ if (match) {
87
+ const signed = (match[1] === "");
88
+ const width = parseInt(match[2] || "256");
89
+ errors.assertArgument(width % 8 === 0 && width !== 0 && width <= 256 && (match[2] == null || match[2] === String(width)), "invalid numeric width", "type", type);
90
+ const boundsUpper = maths.mask(BN_MAX_UINT256, signed ? (width - 1) : width);
91
+ const boundsLower = signed ? ((boundsUpper + BN_1) * BN__1) : BN_0;
92
+ return function (_value) {
93
+ const value = maths.getBigInt(_value, "value");
94
+ errors.assertArgument(value >= boundsLower && value <= boundsUpper, `value out-of-bounds for ${type}`, "value", value);
95
+ return maths.toBeHex(signed ? maths.toTwos(value, 256) : value, 32);
96
+ };
97
+ }
98
+ }
99
+ // bytesXX
100
+ {
101
+ const match = type.match(/^bytes(\d+)$/);
102
+ if (match) {
103
+ const width = parseInt(match[1]);
104
+ errors.assertArgument(width !== 0 && width <= 32 && match[1] === String(width), "invalid bytes width", "type", type);
105
+ return function (value) {
106
+ const bytes = data.getBytes(value);
107
+ errors.assertArgument(bytes.length === width, `invalid length for ${type}`, "value", value);
108
+ return hexPadRight(value);
109
+ };
110
+ }
111
+ }
112
+ switch (type) {
113
+ case "address": return function (value) {
114
+ return data.zeroPadValue(address.getAddress(value), 32);
115
+ };
116
+ case "bool": return function (value) {
117
+ return ((!value) ? hexFalse : hexTrue);
118
+ };
119
+ case "bytes": return function (value) {
120
+ return index.keccak256(value);
121
+ };
122
+ case "string": return function (value) {
123
+ return index.id(value);
124
+ };
125
+ }
126
+ return null;
127
+ }
128
+ function encodeType(name, fields) {
129
+ return `${name}(${fields.map(({ name, type }) => (type + " " + name)).join(",")})`;
130
+ }
131
+ /**
132
+ * A **TypedDataEncode** prepares and encodes [[link-eip-712]] payloads
133
+ * for signed typed data.
134
+ *
135
+ * This is useful for those that wish to compute various components of a
136
+ * typed data hash, primary types, or sub-components, but generally the
137
+ * higher level [[Signer-signTypedData]] is more useful.
138
+ */
139
+ class TypedDataEncoder {
140
+ /**
141
+ * Create a new **TypedDataEncoder** for %%types%%.
142
+ *
143
+ * This performs all necessary checking that types are valid and
144
+ * do not violate the [[link-eip-712]] structural constraints as
145
+ * well as computes the [[primaryType]].
146
+ */
147
+ constructor(types) {
148
+ _TypedDataEncoder_instances.add(this);
149
+ _TypedDataEncoder_types.set(this, void 0);
150
+ _TypedDataEncoder_fullTypes.set(this, void 0);
151
+ _TypedDataEncoder_encoderCache.set(this, void 0);
152
+ __classPrivateFieldSet(this, _TypedDataEncoder_types, JSON.stringify(types), "f");
153
+ __classPrivateFieldSet(this, _TypedDataEncoder_fullTypes, new Map(), "f");
154
+ __classPrivateFieldSet(this, _TypedDataEncoder_encoderCache, new Map(), "f");
155
+ // Link struct types to their direct child structs
156
+ const links = new Map();
157
+ // Link structs to structs which contain them as a child
158
+ const parents = new Map();
159
+ // Link all subtypes within a given struct
160
+ const subtypes = new Map();
161
+ Object.keys(types).forEach((type) => {
162
+ links.set(type, new Set());
163
+ parents.set(type, []);
164
+ subtypes.set(type, new Set());
165
+ });
166
+ for (const name in types) {
167
+ const uniqueNames = new Set();
168
+ for (const field of types[name]) {
169
+ // Check each field has a unique name
170
+ errors.assertArgument(!uniqueNames.has(field.name), `duplicate variable name ${JSON.stringify(field.name)} in ${JSON.stringify(name)}`, "types", types);
171
+ uniqueNames.add(field.name);
172
+ // Get the base type (drop any array specifiers)
173
+ const baseType = (field.type.match(/^([^\x5b]*)(\x5b|$)/))[1] || null;
174
+ errors.assertArgument(baseType !== name, `circular type reference to ${JSON.stringify(baseType)}`, "types", types);
175
+ // Is this a base encoding type?
176
+ const encoder = getBaseEncoder(baseType);
177
+ if (encoder) {
178
+ continue;
179
+ }
180
+ errors.assertArgument(parents.has(baseType), `unknown type ${JSON.stringify(baseType)}`, "types", types);
181
+ // Add linkage
182
+ parents.get(baseType).push(name);
183
+ links.get(name).add(baseType);
184
+ }
185
+ }
186
+ // Deduce the primary type
187
+ const primaryTypes = Array.from(parents.keys()).filter((n) => (parents.get(n).length === 0));
188
+ errors.assertArgument(primaryTypes.length !== 0, "missing primary type", "types", types);
189
+ errors.assertArgument(primaryTypes.length === 1, `ambiguous primary types or unused types: ${primaryTypes.map((t) => (JSON.stringify(t))).join(", ")}`, "types", types);
190
+ properties.defineProperties(this, { primaryType: primaryTypes[0] });
191
+ // Check for circular type references
192
+ function checkCircular(type, found) {
193
+ errors.assertArgument(!found.has(type), `circular type reference to ${JSON.stringify(type)}`, "types", types);
194
+ found.add(type);
195
+ for (const child of links.get(type)) {
196
+ if (!parents.has(child)) {
197
+ continue;
198
+ }
199
+ // Recursively check children
200
+ checkCircular(child, found);
201
+ // Mark all ancestors as having this decendant
202
+ for (const subtype of found) {
203
+ subtypes.get(subtype).add(child);
204
+ }
205
+ }
206
+ found.delete(type);
207
+ }
208
+ checkCircular(this.primaryType, new Set());
209
+ // Compute each fully describe type
210
+ for (const [name, set] of subtypes) {
211
+ const st = Array.from(set);
212
+ st.sort();
213
+ __classPrivateFieldGet(this, _TypedDataEncoder_fullTypes, "f").set(name, encodeType(name, types[name]) + st.map((t) => encodeType(t, types[t])).join(""));
214
+ }
215
+ }
216
+ /**
217
+ * The types.
218
+ */
219
+ get types() {
220
+ return JSON.parse(__classPrivateFieldGet(this, _TypedDataEncoder_types, "f"));
221
+ }
222
+ /**
223
+ * Returnthe encoder for the specific %%type%%.
224
+ */
225
+ getEncoder(type) {
226
+ let encoder = __classPrivateFieldGet(this, _TypedDataEncoder_encoderCache, "f").get(type);
227
+ if (!encoder) {
228
+ encoder = __classPrivateFieldGet(this, _TypedDataEncoder_instances, "m", _TypedDataEncoder_getEncoder).call(this, type);
229
+ __classPrivateFieldGet(this, _TypedDataEncoder_encoderCache, "f").set(type, encoder);
230
+ }
231
+ return encoder;
232
+ }
233
+ /**
234
+ * Return the full type for %%name%%.
235
+ */
236
+ encodeType(name) {
237
+ const result = __classPrivateFieldGet(this, _TypedDataEncoder_fullTypes, "f").get(name);
238
+ errors.assertArgument(result, `unknown type: ${JSON.stringify(name)}`, "name", name);
239
+ return result;
240
+ }
241
+ /**
242
+ * Return the encoded %%value%% for the %%type%%.
243
+ */
244
+ encodeData(type, value) {
245
+ return this.getEncoder(type)(value);
246
+ }
247
+ /**
248
+ * Returns the hash of %%value%% for the type of %%name%%.
249
+ */
250
+ hashStruct(name, value) {
251
+ return index.keccak256(base16ToBinary(this.encodeData(name, value).slice(2)));
252
+ }
253
+ /**
254
+ * Return the fulled encoded %%value%% for the [[types]].
255
+ */
256
+ encode(value) {
257
+ return this.encodeData(this.primaryType, value);
258
+ }
259
+ /**
260
+ * Return the hash of the fully encoded %%value%% for the [[types]].
261
+ */
262
+ hash(value) {
263
+ return this.hashStruct(this.primaryType, value);
264
+ }
265
+ /**
266
+ * @_ignore:
267
+ */
268
+ _visit(type, value, callback) {
269
+ // Basic encoder type (address, bool, uint256, etc)
270
+ {
271
+ const encoder = getBaseEncoder(type);
272
+ if (encoder) {
273
+ return callback(type, value);
274
+ }
275
+ }
276
+ // Array
277
+ const match = type.match(/^(.*)(\x5b(\d*)\x5d)$/);
278
+ if (match) {
279
+ errors.assertArgument(!match[3] || parseInt(match[3]) === value.length, `array length mismatch; expected length ${parseInt(match[3])}`, "value", value);
280
+ return value.map((v) => this._visit(match[1], v, callback));
281
+ }
282
+ // Struct
283
+ const fields = this.types[type];
284
+ if (fields) {
285
+ return fields.reduce((accum, { name, type }) => {
286
+ accum[name] = this._visit(type, value[name], callback);
287
+ return accum;
288
+ }, {});
289
+ }
290
+ errors.assertArgument(false, `unknown type: ${type}`, "type", type);
291
+ }
292
+ /**
293
+ * Call %%calback%% for each value in %%value%%, passing the type and
294
+ * component within %%value%%.
295
+ *
296
+ * This is useful for replacing addresses or other transformation that
297
+ * may be desired on each component, based on its type.
298
+ */
299
+ visit(value, callback) {
300
+ return this._visit(this.primaryType, value, callback);
301
+ }
302
+ /**
303
+ * Create a new **TypedDataEncoder** for %%types%%.
304
+ */
305
+ static from(types) {
306
+ return new TypedDataEncoder(types);
307
+ }
308
+ /**
309
+ * Return the primary type for %%types%%.
310
+ */
311
+ static getPrimaryType(types) {
312
+ return TypedDataEncoder.from(types).primaryType;
313
+ }
314
+ /**
315
+ * Return the hashed struct for %%value%% using %%types%% and %%name%%.
316
+ */
317
+ static hashStruct(name, types, value) {
318
+ return TypedDataEncoder.from(types).hashStruct(name, value);
319
+ }
320
+ /**
321
+ * Return the domain hash for %%domain%%.
322
+ */
323
+ static hashDomain(domain) {
324
+ const domainFields = [];
325
+ for (const name in domain) {
326
+ if (domain[name] == null) {
327
+ continue;
328
+ }
329
+ const type = domainFieldTypes[name];
330
+ errors.assertArgument(type, `invalid typed-data domain key: ${JSON.stringify(name)}`, "domain", domain);
331
+ domainFields.push({ name, type });
332
+ }
333
+ domainFields.sort((a, b) => {
334
+ return domainFieldNames.indexOf(a.name) - domainFieldNames.indexOf(b.name);
335
+ });
336
+ return TypedDataEncoder.hashStruct("EIP712Domain", { EIP712Domain: domainFields }, domain);
337
+ }
338
+ /**
339
+ * Return the fully encoded [[link-eip-712]] %%value%% for %%types%% with %%domain%%.
340
+ */
341
+ static encode(domain, types, value) {
342
+ return data.concat([
343
+ "0x1901",
344
+ TypedDataEncoder.hashDomain(domain),
345
+ TypedDataEncoder.from(types).hash(value)
346
+ ]);
347
+ }
348
+ /**
349
+ * Return the hash of the fully encoded [[link-eip-712]] %%value%% for %%types%% with %%domain%%.
350
+ */
351
+ static hash(domain, types, value) {
352
+ return index.keccak256(TypedDataEncoder.encode(domain, types, value));
353
+ }
354
+ // Replaces all address types with ENS names with their looked up address
355
+ /**
356
+ * Resolves to the value from resolving all addresses in %%value%% for
357
+ * %%types%% and the %%domain%%.
358
+ */
359
+ static async resolveNames(domain, types, value, resolveName) {
360
+ // Make a copy to isolate it from the object passed in
361
+ domain = Object.assign({}, domain);
362
+ // Allow passing null to ignore value
363
+ for (const key in domain) {
364
+ if (domain[key] == null) {
365
+ delete domain[key];
366
+ }
367
+ }
368
+ // Look up all ENS names
369
+ const ensCache = {};
370
+ // Do we need to look up the domain's verifyingContract?
371
+ if (domain.verifyingContract && !data.isHexString(domain.verifyingContract, 20)) {
372
+ ensCache[domain.verifyingContract] = "0x";
373
+ }
374
+ // We are going to use the encoder to visit all the base values
375
+ const encoder = TypedDataEncoder.from(types);
376
+ // Get a list of all the addresses
377
+ encoder.visit(value, (type, value) => {
378
+ if (type === "address" && !data.isHexString(value, 20)) {
379
+ ensCache[value] = "0x";
380
+ }
381
+ return value;
382
+ });
383
+ // Lookup each name
384
+ for (const name in ensCache) {
385
+ ensCache[name] = await resolveName(name);
386
+ }
387
+ // Replace the domain verifyingContract if needed
388
+ if (domain.verifyingContract && ensCache[domain.verifyingContract]) {
389
+ domain.verifyingContract = ensCache[domain.verifyingContract];
390
+ }
391
+ // Replace all ENS names with their address
392
+ value = encoder.visit(value, (type, value) => {
393
+ if (type === "address" && ensCache[value]) {
394
+ return ensCache[value];
395
+ }
396
+ return value;
397
+ });
398
+ return { domain, value };
399
+ }
400
+ /**
401
+ * Returns the JSON-encoded payload expected by nodes which implement
402
+ * the JSON-RPC [[link-eip-712]] method.
403
+ */
404
+ static getPayload(domain, types, value) {
405
+ // Validate the domain fields
406
+ TypedDataEncoder.hashDomain(domain);
407
+ // Derive the EIP712Domain Struct reference type
408
+ const domainValues = {};
409
+ const domainTypes = [];
410
+ domainFieldNames.forEach((name) => {
411
+ const value = domain[name];
412
+ if (value == null) {
413
+ return;
414
+ }
415
+ domainValues[name] = domainChecks[name](value);
416
+ domainTypes.push({ name, type: domainFieldTypes[name] });
417
+ });
418
+ const encoder = TypedDataEncoder.from(types);
419
+ const typesWithDomain = Object.assign({}, types);
420
+ errors.assertArgument(typesWithDomain.EIP712Domain == null, "types must not contain EIP712Domain type", "types.EIP712Domain", types);
421
+ typesWithDomain.EIP712Domain = domainTypes;
422
+ // Validate the data structures and types
423
+ encoder.encode(value);
424
+ return {
425
+ types: typesWithDomain,
426
+ domain: domainValues,
427
+ primaryType: encoder.primaryType,
428
+ message: encoder.visit(value, (type, value) => {
429
+ // bytes
430
+ if (type.match(/^bytes(\d*)/)) {
431
+ return data.hexlify(data.getBytes(value));
432
+ }
433
+ // uint or int
434
+ if (type.match(/^u?int/)) {
435
+ return maths.getBigInt(value).toString();
436
+ }
437
+ switch (type) {
438
+ case "address":
439
+ return value.toLowerCase();
440
+ case "bool":
441
+ return !!value;
442
+ case "string":
443
+ errors.assertArgument(typeof (value) === "string", "invalid string", "value", value);
444
+ return value;
445
+ }
446
+ errors.assertArgument(false, "unsupported type", "type", type);
447
+ })
448
+ };
449
+ }
450
+ }
451
+ _TypedDataEncoder_types = new WeakMap(), _TypedDataEncoder_fullTypes = new WeakMap(), _TypedDataEncoder_encoderCache = new WeakMap(), _TypedDataEncoder_instances = new WeakSet(), _TypedDataEncoder_getEncoder = function _TypedDataEncoder_getEncoder(type) {
452
+ // Basic encoder type (address, bool, uint256, etc)
453
+ {
454
+ const encoder = getBaseEncoder(type);
455
+ if (encoder) {
456
+ return encoder;
457
+ }
458
+ }
459
+ // Array
460
+ const match = type.match(/^(.*)(\x5b(\d*)\x5d)$/);
461
+ if (match) {
462
+ const subtype = match[1];
463
+ const subEncoder = this.getEncoder(subtype);
464
+ return (value) => {
465
+ errors.assertArgument(!match[3] || parseInt(match[3]) === value.length, `array length mismatch; expected length ${parseInt(match[3])}`, "value", value);
466
+ let result = value.map(subEncoder);
467
+ if (__classPrivateFieldGet(this, _TypedDataEncoder_fullTypes, "f").has(subtype)) {
468
+ result = result.map(index.keccak256);
469
+ }
470
+ return index.keccak256(data.concat(result));
471
+ };
472
+ }
473
+ // Struct
474
+ const fields = this.types[type];
475
+ if (fields) {
476
+ const encodedType = index.id(__classPrivateFieldGet(this, _TypedDataEncoder_fullTypes, "f").get(type));
477
+ return (value) => {
478
+ const values = fields.map(({ name, type }) => {
479
+ const result = this.getEncoder(type)(value[name]);
480
+ if (__classPrivateFieldGet(this, _TypedDataEncoder_fullTypes, "f").has(type)) {
481
+ return index.keccak256(result);
482
+ }
483
+ return result;
484
+ });
485
+ values.unshift(encodedType);
486
+ return data.concat(values);
487
+ };
488
+ }
489
+ errors.assertArgument(false, `unknown type: ${type}`, "type", type);
490
+ };
491
+
492
+ exports.TypedDataEncoder = TypedDataEncoder;
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var abiCoder = require('./abi-coder.js');
6
+ require('./utils/base58.js');
7
+ require('./utils/errors.js');
8
+ require('./utils/events.js');
9
+ require('./utils/fixednumber.js');
10
+ require('./utils/maths.js');
11
+ require('./utils/utf8.js');
12
+ require('../../base/functions/platform.js');
13
+ require('../../base/functions/encode.js');
14
+ require('../../base/functions/crypto.js');
15
+ require('../noble-hashes/sha3.js');
16
+ require('../noble-hashes/sha256.js');
17
+ var fragments = require('./fragments.js');
18
+ require('./interface.js');
19
+ var typed = require('./typed.js');
20
+
21
+ /**
22
+ * The Application Binary Interface (ABI) describes how method input
23
+ * parameters should be encoded, their results decoded, and how to
24
+ * decode events and errors.
25
+ *
26
+ * See [About ABIs](docs-abi) for more details how they are used.
27
+ *
28
+ * @_section api/abi:Application Binary Interface [about-abi]
29
+ * @_navTitle: ABI
30
+ */
31
+ var ethers = abiCoder.AbiCoder.defaultAbiCoder();
32
+
33
+ exports.ParamType = fragments.ParamType;
34
+ exports.Typed = typed.Typed;
35
+ exports["default"] = ethers;
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('./utils/base58.js');
6
+ require('./utils/errors.js');
7
+ require('./utils/events.js');
8
+ require('./utils/fixednumber.js');
9
+ require('./utils/maths.js');
10
+ require('./utils/utf8.js');
11
+ require('../../base/functions/platform.js');
12
+ require('../../base/functions/encode.js');
13
+ require('../../base/functions/crypto.js');
14
+ require('../noble-hashes/sha3.js');
15
+ require('../noble-hashes/sha256.js');
16
+ require('./abi-coder.js');
17
+ var abstractCoder = require('./coders/abstract-coder.js');
18
+ require('./fragments.js');
19
+ require('./typed.js');
20
+
21
+ /**
22
+ * The Interface class is a low-level class that accepts an
23
+ * ABI and provides all the necessary functionality to encode
24
+ * and decode paramaters to and results from methods, events
25
+ * and errors.
26
+ *
27
+ * It also provides several convenience methods to automatically
28
+ * search and find matching transactions and events to parse them.
29
+ *
30
+ * @_subsection api/abi:Interfaces [interfaces]
31
+ */
32
+ (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
33
+ if (kind === "m") throw new TypeError("Private method is not writable");
34
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
35
+ 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");
36
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
37
+ };
38
+ (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
39
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
40
+ 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");
41
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
42
+ };
43
+
44
+ exports.Result = abstractCoder.Result;