ccxt 4.2.60 → 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.
- package/README.md +103 -102
- package/build.sh +1 -1
- package/dist/ccxt.browser.js +107943 -100121
- package/dist/ccxt.browser.min.js +7 -7
- package/dist/cjs/ccxt.js +4 -1
- package/dist/cjs/src/abstract/hyperliquid.js +9 -0
- package/dist/cjs/src/base/Exchange.js +22 -1
- package/dist/cjs/src/base/functions/encode.js +5 -0
- package/dist/cjs/src/base/functions.js +1 -0
- package/dist/cjs/src/bitfinex2.js +1 -1
- package/dist/cjs/src/coinbase.js +108 -103
- package/dist/cjs/src/coinex.js +61 -1
- package/dist/cjs/src/hyperliquid.js +2035 -0
- package/dist/cjs/src/kraken.js +8 -2
- package/dist/cjs/src/krakenfutures.js +28 -0
- package/dist/cjs/src/kucoinfutures.js +2 -2
- package/dist/cjs/src/okx.js +1 -1
- package/dist/cjs/src/phemex.js +2 -2
- package/dist/cjs/src/pro/bingx.js +1 -0
- package/dist/cjs/src/static_dependencies/ethers/abi-coder.js +158 -0
- package/dist/cjs/src/static_dependencies/ethers/address/address.js +144 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/abstract-coder.js +407 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/address.js +45 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/anonymous.js +28 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/array.js +176 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/boolean.js +27 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/bytes.js +52 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/fixed-bytes.js +45 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/null.js +30 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/number.js +60 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/string.js +27 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/tuple.js +68 -0
- package/dist/cjs/src/static_dependencies/ethers/fragments.js +614 -0
- package/dist/cjs/src/static_dependencies/ethers/hash/typed-data.js +492 -0
- package/dist/cjs/src/static_dependencies/ethers/index.js +35 -0
- package/dist/cjs/src/static_dependencies/ethers/interface.js +44 -0
- package/dist/cjs/src/static_dependencies/ethers/typed.js +618 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/base58.js +20 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/data.js +134 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/errors.js +228 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/events.js +13 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/fixednumber.js +29 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/index.js +53 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/maths.js +231 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/properties.js +47 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/utf8.js +218 -0
- package/dist/cjs/src/static_dependencies/messagepack/msgpack.js +292 -0
- package/dist/cjs/src/tokocrypto.js +22 -2
- package/dist/cjs/src/wazirx.js +308 -3
- package/js/ccxt.d.ts +5 -2
- package/js/ccxt.js +4 -2
- package/js/src/abstract/coinbase.d.ts +3 -3
- package/js/src/abstract/hyperliquid.d.ts +9 -0
- package/js/src/abstract/hyperliquid.js +11 -0
- package/js/src/base/Exchange.d.ts +4 -0
- package/js/src/base/Exchange.js +13 -1
- package/js/src/base/functions/encode.d.ts +2 -1
- package/js/src/base/functions/encode.js +5 -1
- package/js/src/bitfinex2.js +1 -1
- package/js/src/coinbase.js +108 -103
- package/js/src/coinex.d.ts +3 -1
- package/js/src/coinex.js +61 -1
- package/js/src/hyperliquid.d.ts +83 -0
- package/js/src/hyperliquid.js +2036 -0
- package/js/src/kraken.js +8 -2
- package/js/src/krakenfutures.d.ts +2 -1
- package/js/src/krakenfutures.js +28 -0
- package/js/src/kucoinfutures.js +2 -2
- package/js/src/okx.js +1 -1
- package/js/src/phemex.js +2 -2
- package/js/src/pro/bingx.js +1 -0
- package/js/src/static_dependencies/ethers/abi-coder.d.ts +50 -0
- package/js/src/static_dependencies/ethers/abi-coder.js +148 -0
- package/js/src/static_dependencies/ethers/address/address.d.ts +55 -0
- package/js/src/static_dependencies/ethers/address/address.js +162 -0
- package/js/src/static_dependencies/ethers/address/checks.d.ts +80 -0
- package/js/src/static_dependencies/ethers/address/checks.js +119 -0
- package/js/src/static_dependencies/ethers/address/contract-address.d.ts +47 -0
- package/js/src/static_dependencies/ethers/address/contract-address.js +73 -0
- package/js/src/static_dependencies/ethers/address/index.d.ts +48 -0
- package/js/src/static_dependencies/ethers/address/index.js +24 -0
- package/js/src/static_dependencies/ethers/bytes32.d.ts +14 -0
- package/js/src/static_dependencies/ethers/bytes32.js +45 -0
- package/js/src/static_dependencies/ethers/coders/abstract-coder.d.ts +120 -0
- package/js/src/static_dependencies/ethers/coders/abstract-coder.js +424 -0
- package/js/src/static_dependencies/ethers/coders/address.d.ts +12 -0
- package/js/src/static_dependencies/ethers/coders/address.js +34 -0
- package/js/src/static_dependencies/ethers/coders/anonymous.d.ts +14 -0
- package/js/src/static_dependencies/ethers/coders/anonymous.js +27 -0
- package/js/src/static_dependencies/ethers/coders/array.d.ts +24 -0
- package/js/src/static_dependencies/ethers/coders/array.js +162 -0
- package/js/src/static_dependencies/ethers/coders/boolean.d.ts +12 -0
- package/js/src/static_dependencies/ethers/coders/boolean.js +26 -0
- package/js/src/static_dependencies/ethers/coders/bytes.d.ts +18 -0
- package/js/src/static_dependencies/ethers/coders/bytes.js +39 -0
- package/js/src/static_dependencies/ethers/coders/fixed-bytes.d.ts +14 -0
- package/js/src/static_dependencies/ethers/coders/fixed-bytes.js +32 -0
- package/js/src/static_dependencies/ethers/coders/null.d.ts +11 -0
- package/js/src/static_dependencies/ethers/coders/null.js +29 -0
- package/js/src/static_dependencies/ethers/coders/number.d.ts +15 -0
- package/js/src/static_dependencies/ethers/coders/number.js +48 -0
- package/js/src/static_dependencies/ethers/coders/string.d.ts +12 -0
- package/js/src/static_dependencies/ethers/coders/string.js +26 -0
- package/js/src/static_dependencies/ethers/coders/tuple.d.ts +15 -0
- package/js/src/static_dependencies/ethers/coders/tuple.js +67 -0
- package/js/src/static_dependencies/ethers/fragments.d.ts +458 -0
- package/js/src/static_dependencies/ethers/fragments.js +1252 -0
- package/js/src/static_dependencies/ethers/hash/index.d.ts +10 -0
- package/js/src/static_dependencies/ethers/hash/index.js +15 -0
- package/js/src/static_dependencies/ethers/hash/solidity.d.ts +30 -0
- package/js/src/static_dependencies/ethers/hash/solidity.js +107 -0
- package/js/src/static_dependencies/ethers/hash/typed-data.d.ts +144 -0
- package/js/src/static_dependencies/ethers/hash/typed-data.js +490 -0
- package/js/src/static_dependencies/ethers/index.d.ts +19 -0
- package/js/src/static_dependencies/ethers/index.js +22 -0
- package/js/src/static_dependencies/ethers/interface.d.ts +380 -0
- package/js/src/static_dependencies/ethers/interface.js +990 -0
- package/js/src/static_dependencies/ethers/typed.d.ts +569 -0
- package/js/src/static_dependencies/ethers/typed.js +608 -0
- package/js/src/static_dependencies/ethers/utils/base58.d.ts +22 -0
- package/js/src/static_dependencies/ethers/utils/base58.js +68 -0
- package/js/src/static_dependencies/ethers/utils/base64-browser.d.ts +3 -0
- package/js/src/static_dependencies/ethers/utils/base64-browser.js +24 -0
- package/js/src/static_dependencies/ethers/utils/base64.d.ts +39 -0
- package/js/src/static_dependencies/ethers/utils/base64.js +58 -0
- package/js/src/static_dependencies/ethers/utils/data.d.ts +92 -0
- package/js/src/static_dependencies/ethers/utils/data.js +175 -0
- package/js/src/static_dependencies/ethers/utils/errors.d.ts +509 -0
- package/js/src/static_dependencies/ethers/utils/errors.js +227 -0
- package/js/src/static_dependencies/ethers/utils/events.d.ts +76 -0
- package/js/src/static_dependencies/ethers/utils/events.js +52 -0
- package/js/src/static_dependencies/ethers/utils/fixednumber.d.ts +251 -0
- package/js/src/static_dependencies/ethers/utils/fixednumber.js +529 -0
- package/js/src/static_dependencies/ethers/utils/index.d.ts +30 -0
- package/js/src/static_dependencies/ethers/utils/index.js +38 -0
- package/js/src/static_dependencies/ethers/utils/maths.d.ts +65 -0
- package/js/src/static_dependencies/ethers/utils/maths.js +220 -0
- package/js/src/static_dependencies/ethers/utils/properties.d.ts +22 -0
- package/js/src/static_dependencies/ethers/utils/properties.js +59 -0
- package/js/src/static_dependencies/ethers/utils/rlp-decode.d.ts +5 -0
- package/js/src/static_dependencies/ethers/utils/rlp-decode.js +84 -0
- package/js/src/static_dependencies/ethers/utils/rlp-encode.d.ts +5 -0
- package/js/src/static_dependencies/ethers/utils/rlp-encode.js +54 -0
- package/js/src/static_dependencies/ethers/utils/rlp.d.ts +16 -0
- package/js/src/static_dependencies/ethers/utils/rlp.js +14 -0
- package/js/src/static_dependencies/ethers/utils/units.d.ts +23 -0
- package/js/src/static_dependencies/ethers/utils/units.js +88 -0
- package/js/src/static_dependencies/ethers/utils/utf8.d.ts +95 -0
- package/js/src/static_dependencies/ethers/utils/utf8.js +225 -0
- package/js/src/static_dependencies/ethers/utils/uuid.d.ts +7 -0
- package/js/src/static_dependencies/ethers/utils/uuid.js +35 -0
- package/js/src/static_dependencies/messagepack/msgpack.d.ts +2 -0
- package/js/src/static_dependencies/messagepack/msgpack.js +572 -0
- package/js/src/tokocrypto.js +22 -2
- package/js/src/wazirx.d.ts +12 -1
- package/js/src/wazirx.js +308 -3
- package/package.json +1 -1
- package/skip-tests.json +18 -0
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('../utils/base58.js');
|
|
6
|
+
var data = require('../utils/data.js');
|
|
7
|
+
var errors = require('../utils/errors.js');
|
|
8
|
+
require('../utils/events.js');
|
|
9
|
+
require('../utils/fixednumber.js');
|
|
10
|
+
var maths = require('../utils/maths.js');
|
|
11
|
+
var properties = require('../utils/properties.js');
|
|
12
|
+
require('../utils/utf8.js');
|
|
13
|
+
require('../../../base/functions/platform.js');
|
|
14
|
+
require('../../../base/functions/encode.js');
|
|
15
|
+
require('../../../base/functions/crypto.js');
|
|
16
|
+
require('../../noble-hashes/sha3.js');
|
|
17
|
+
require('../../noble-hashes/sha256.js');
|
|
18
|
+
|
|
19
|
+
var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
20
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
21
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
22
|
+
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");
|
|
23
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
24
|
+
};
|
|
25
|
+
var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
26
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
27
|
+
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");
|
|
28
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
29
|
+
};
|
|
30
|
+
var _Result_names, _Writer_instances, _Writer_data, _Writer_dataLength, _Writer_writeData, _Reader_instances, _Reader_data, _Reader_offset, _Reader_bytesRead, _Reader_parent, _Reader_maxInflation, _Reader_incrementBytesRead, _Reader_peekBytes;
|
|
31
|
+
/**
|
|
32
|
+
* @_ignore:
|
|
33
|
+
*/
|
|
34
|
+
const WordSize = 32;
|
|
35
|
+
const Padding = new Uint8Array(WordSize);
|
|
36
|
+
// Properties used to immediate pass through to the underlying object
|
|
37
|
+
// - `then` is used to detect if an object is a Promise for await
|
|
38
|
+
const passProperties = ["then"];
|
|
39
|
+
const _guard = {};
|
|
40
|
+
function throwError(name, error) {
|
|
41
|
+
const wrapped = new Error(`deferred error during ABI decoding triggered accessing ${name}`);
|
|
42
|
+
wrapped.error = error;
|
|
43
|
+
throw wrapped;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A [[Result]] is a sub-class of Array, which allows accessing any
|
|
47
|
+
* of its values either positionally by its index or, if keys are
|
|
48
|
+
* provided by its name.
|
|
49
|
+
*
|
|
50
|
+
* @_docloc: api/abi
|
|
51
|
+
*/
|
|
52
|
+
class Result extends Array {
|
|
53
|
+
/**
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
56
|
+
constructor(...args) {
|
|
57
|
+
// To properly sub-class Array so the other built-in
|
|
58
|
+
// functions work, the constructor has to behave fairly
|
|
59
|
+
// well. So, in the event we are created via fromItems()
|
|
60
|
+
// we build the read-only Result object we want, but on
|
|
61
|
+
// any other input, we use the default constructor
|
|
62
|
+
// constructor(guard: any, items: Array<any>, keys?: Array<null | string>);
|
|
63
|
+
const guard = args[0];
|
|
64
|
+
let items = args[1];
|
|
65
|
+
let names = (args[2] || []).slice();
|
|
66
|
+
let wrap = true;
|
|
67
|
+
if (guard !== _guard) {
|
|
68
|
+
items = args;
|
|
69
|
+
names = [];
|
|
70
|
+
wrap = false;
|
|
71
|
+
}
|
|
72
|
+
// Can't just pass in ...items since an array of length 1
|
|
73
|
+
// is a special case in the super.
|
|
74
|
+
super(items.length);
|
|
75
|
+
_Result_names.set(this, void 0);
|
|
76
|
+
items.forEach((item, index) => { this[index] = item; });
|
|
77
|
+
// Find all unique keys
|
|
78
|
+
const nameCounts = names.reduce((accum, name) => {
|
|
79
|
+
if (typeof (name) === "string") {
|
|
80
|
+
accum.set(name, (accum.get(name) || 0) + 1);
|
|
81
|
+
}
|
|
82
|
+
return accum;
|
|
83
|
+
}, (new Map()));
|
|
84
|
+
// Remove any key thats not unique
|
|
85
|
+
__classPrivateFieldSet(this, _Result_names, Object.freeze(items.map((item, index) => {
|
|
86
|
+
const name = names[index];
|
|
87
|
+
if (name != null && nameCounts.get(name) === 1) {
|
|
88
|
+
return name;
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
})), "f");
|
|
92
|
+
if (!wrap) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
// A wrapped Result is immutable
|
|
96
|
+
Object.freeze(this);
|
|
97
|
+
// Proxy indices and names so we can trap deferred errors
|
|
98
|
+
return new Proxy(this, {
|
|
99
|
+
get: (target, prop, receiver) => {
|
|
100
|
+
if (typeof (prop) === "string") {
|
|
101
|
+
// Index accessor
|
|
102
|
+
if (prop.match(/^[0-9]+$/)) {
|
|
103
|
+
const index = maths.getNumber(prop, "%index");
|
|
104
|
+
if (index < 0 || index >= this.length) {
|
|
105
|
+
throw new RangeError("out of result range");
|
|
106
|
+
}
|
|
107
|
+
const item = target[index];
|
|
108
|
+
if (item instanceof Error) {
|
|
109
|
+
throwError(`index ${index}`, item);
|
|
110
|
+
}
|
|
111
|
+
return item;
|
|
112
|
+
}
|
|
113
|
+
// Pass important checks (like `then` for Promise) through
|
|
114
|
+
if (passProperties.indexOf(prop) >= 0) {
|
|
115
|
+
return Reflect.get(target, prop, receiver);
|
|
116
|
+
}
|
|
117
|
+
const value = target[prop];
|
|
118
|
+
if (value instanceof Function) {
|
|
119
|
+
// Make sure functions work with private variables
|
|
120
|
+
// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy#no_private_property_forwarding
|
|
121
|
+
return function (...args) {
|
|
122
|
+
return value.apply((this === receiver) ? target : this, args);
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
else if (!(prop in target)) {
|
|
126
|
+
// Possible name accessor
|
|
127
|
+
return target.getValue.apply((this === receiver) ? target : this, [prop]);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return Reflect.get(target, prop, receiver);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Returns the Result as a normal Array.
|
|
136
|
+
*
|
|
137
|
+
* This will throw if there are any outstanding deferred
|
|
138
|
+
* errors.
|
|
139
|
+
*/
|
|
140
|
+
toArray() {
|
|
141
|
+
const result = [];
|
|
142
|
+
this.forEach((item, index) => {
|
|
143
|
+
if (item instanceof Error) {
|
|
144
|
+
throwError(`index ${index}`, item);
|
|
145
|
+
}
|
|
146
|
+
result.push(item);
|
|
147
|
+
});
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Returns the Result as an Object with each name-value pair.
|
|
152
|
+
*
|
|
153
|
+
* This will throw if any value is unnamed, or if there are
|
|
154
|
+
* any outstanding deferred errors.
|
|
155
|
+
*/
|
|
156
|
+
toObject() {
|
|
157
|
+
return __classPrivateFieldGet(this, _Result_names, "f").reduce((accum, name, index) => {
|
|
158
|
+
errors.assert(name != null, "value at index ${ index } unnamed", "UNSUPPORTED_OPERATION", {
|
|
159
|
+
operation: "toObject()"
|
|
160
|
+
});
|
|
161
|
+
// Add values for names that don't conflict
|
|
162
|
+
if (!(name in accum)) {
|
|
163
|
+
accum[name] = this.getValue(name);
|
|
164
|
+
}
|
|
165
|
+
return accum;
|
|
166
|
+
}, {});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* @_ignore
|
|
170
|
+
*/
|
|
171
|
+
slice(start, end) {
|
|
172
|
+
if (start == null) {
|
|
173
|
+
start = 0;
|
|
174
|
+
}
|
|
175
|
+
if (start < 0) {
|
|
176
|
+
start += this.length;
|
|
177
|
+
if (start < 0) {
|
|
178
|
+
start = 0;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (end == null) {
|
|
182
|
+
end = this.length;
|
|
183
|
+
}
|
|
184
|
+
if (end < 0) {
|
|
185
|
+
end += this.length;
|
|
186
|
+
if (end < 0) {
|
|
187
|
+
end = 0;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (end > this.length) {
|
|
191
|
+
end = this.length;
|
|
192
|
+
}
|
|
193
|
+
const result = [], names = [];
|
|
194
|
+
for (let i = start; i < end; i++) {
|
|
195
|
+
result.push(this[i]);
|
|
196
|
+
names.push(__classPrivateFieldGet(this, _Result_names, "f")[i]);
|
|
197
|
+
}
|
|
198
|
+
return new Result(_guard, result, names);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* @_ignore
|
|
202
|
+
*/
|
|
203
|
+
filter(callback, thisArg) {
|
|
204
|
+
const result = [], names = [];
|
|
205
|
+
for (let i = 0; i < this.length; i++) {
|
|
206
|
+
const item = this[i];
|
|
207
|
+
if (item instanceof Error) {
|
|
208
|
+
throwError(`index ${i}`, item);
|
|
209
|
+
}
|
|
210
|
+
if (callback.call(thisArg, item, i, this)) {
|
|
211
|
+
result.push(item);
|
|
212
|
+
names.push(__classPrivateFieldGet(this, _Result_names, "f")[i]);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return new Result(_guard, result, names);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* @_ignore
|
|
219
|
+
*/
|
|
220
|
+
map(callback, thisArg) {
|
|
221
|
+
const result = [];
|
|
222
|
+
for (let i = 0; i < this.length; i++) {
|
|
223
|
+
const item = this[i];
|
|
224
|
+
if (item instanceof Error) {
|
|
225
|
+
throwError(`index ${i}`, item);
|
|
226
|
+
}
|
|
227
|
+
result.push(callback.call(thisArg, item, i, this));
|
|
228
|
+
}
|
|
229
|
+
return result;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Returns the value for %%name%%.
|
|
233
|
+
*
|
|
234
|
+
* Since it is possible to have a key whose name conflicts with
|
|
235
|
+
* a method on a [[Result]] or its superclass Array, or any
|
|
236
|
+
* JavaScript keyword, this ensures all named values are still
|
|
237
|
+
* accessible by name.
|
|
238
|
+
*/
|
|
239
|
+
getValue(name) {
|
|
240
|
+
const index = __classPrivateFieldGet(this, _Result_names, "f").indexOf(name);
|
|
241
|
+
if (index === -1) {
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
const value = this[index];
|
|
245
|
+
if (value instanceof Error) {
|
|
246
|
+
throwError(`property ${JSON.stringify(name)}`, value.error);
|
|
247
|
+
}
|
|
248
|
+
return value;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Creates a new [[Result]] for %%items%% with each entry
|
|
252
|
+
* also accessible by its corresponding name in %%keys%%.
|
|
253
|
+
*/
|
|
254
|
+
static fromItems(items, keys) {
|
|
255
|
+
return new Result(_guard, items, keys);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
_Result_names = new WeakMap();
|
|
259
|
+
function getValue(value) {
|
|
260
|
+
let bytes = maths.toBeArray(value);
|
|
261
|
+
errors.assert(bytes.length <= WordSize, "value out-of-bounds", "BUFFER_OVERRUN", { buffer: bytes, length: WordSize, offset: bytes.length });
|
|
262
|
+
if (bytes.length !== WordSize) {
|
|
263
|
+
bytes = data.getBytesCopy(data.concat([Padding.slice(bytes.length % WordSize), bytes]));
|
|
264
|
+
}
|
|
265
|
+
return bytes;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* @_ignore
|
|
269
|
+
*/
|
|
270
|
+
class Coder {
|
|
271
|
+
constructor(name, type, localName, dynamic) {
|
|
272
|
+
properties.defineProperties(this, { name, type, localName, dynamic }, {
|
|
273
|
+
name: "string", type: "string", localName: "string", dynamic: "boolean"
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
_throwError(message, value) {
|
|
277
|
+
errors.assertArgument(false, message, this.localName, value);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* @_ignore
|
|
282
|
+
*/
|
|
283
|
+
class Writer {
|
|
284
|
+
constructor() {
|
|
285
|
+
_Writer_instances.add(this);
|
|
286
|
+
// An array of WordSize lengthed objects to concatenation
|
|
287
|
+
_Writer_data.set(this, void 0);
|
|
288
|
+
_Writer_dataLength.set(this, void 0);
|
|
289
|
+
__classPrivateFieldSet(this, _Writer_data, [], "f");
|
|
290
|
+
__classPrivateFieldSet(this, _Writer_dataLength, 0, "f");
|
|
291
|
+
}
|
|
292
|
+
get data() {
|
|
293
|
+
return data.concat(__classPrivateFieldGet(this, _Writer_data, "f"));
|
|
294
|
+
}
|
|
295
|
+
get length() { return __classPrivateFieldGet(this, _Writer_dataLength, "f"); }
|
|
296
|
+
appendWriter(writer) {
|
|
297
|
+
return __classPrivateFieldGet(this, _Writer_instances, "m", _Writer_writeData).call(this, data.getBytesCopy(writer.data));
|
|
298
|
+
}
|
|
299
|
+
// Arrayish item; pad on the right to *nearest* WordSize
|
|
300
|
+
writeBytes(value) {
|
|
301
|
+
let bytes = data.getBytesCopy(value);
|
|
302
|
+
const paddingOffset = bytes.length % WordSize;
|
|
303
|
+
if (paddingOffset) {
|
|
304
|
+
bytes = data.getBytesCopy(data.concat([bytes, Padding.slice(paddingOffset)]));
|
|
305
|
+
}
|
|
306
|
+
return __classPrivateFieldGet(this, _Writer_instances, "m", _Writer_writeData).call(this, bytes);
|
|
307
|
+
}
|
|
308
|
+
// Numeric item; pad on the left *to* WordSize
|
|
309
|
+
writeValue(value) {
|
|
310
|
+
return __classPrivateFieldGet(this, _Writer_instances, "m", _Writer_writeData).call(this, getValue(value));
|
|
311
|
+
}
|
|
312
|
+
// Inserts a numeric place-holder, returning a callback that can
|
|
313
|
+
// be used to asjust the value later
|
|
314
|
+
writeUpdatableValue() {
|
|
315
|
+
const offset = __classPrivateFieldGet(this, _Writer_data, "f").length;
|
|
316
|
+
__classPrivateFieldGet(this, _Writer_data, "f").push(Padding);
|
|
317
|
+
__classPrivateFieldSet(this, _Writer_dataLength, __classPrivateFieldGet(this, _Writer_dataLength, "f") + WordSize, "f");
|
|
318
|
+
return (value) => {
|
|
319
|
+
__classPrivateFieldGet(this, _Writer_data, "f")[offset] = getValue(value);
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
_Writer_data = new WeakMap(), _Writer_dataLength = new WeakMap(), _Writer_instances = new WeakSet(), _Writer_writeData = function _Writer_writeData(data) {
|
|
324
|
+
__classPrivateFieldGet(this, _Writer_data, "f").push(data);
|
|
325
|
+
__classPrivateFieldSet(this, _Writer_dataLength, __classPrivateFieldGet(this, _Writer_dataLength, "f") + data.length, "f");
|
|
326
|
+
return data.length;
|
|
327
|
+
};
|
|
328
|
+
/**
|
|
329
|
+
* @_ignore
|
|
330
|
+
*/
|
|
331
|
+
class Reader {
|
|
332
|
+
constructor(data$1, allowLoose, maxInflation) {
|
|
333
|
+
_Reader_instances.add(this);
|
|
334
|
+
_Reader_data.set(this, void 0);
|
|
335
|
+
_Reader_offset.set(this, void 0);
|
|
336
|
+
_Reader_bytesRead.set(this, void 0);
|
|
337
|
+
_Reader_parent.set(this, void 0);
|
|
338
|
+
_Reader_maxInflation.set(this, void 0);
|
|
339
|
+
properties.defineProperties(this, { allowLoose: !!allowLoose });
|
|
340
|
+
__classPrivateFieldSet(this, _Reader_data, data.getBytesCopy(data$1), "f");
|
|
341
|
+
__classPrivateFieldSet(this, _Reader_bytesRead, 0, "f");
|
|
342
|
+
__classPrivateFieldSet(this, _Reader_parent, null, "f");
|
|
343
|
+
__classPrivateFieldSet(this, _Reader_maxInflation, (maxInflation != null) ? maxInflation : 1024, "f");
|
|
344
|
+
__classPrivateFieldSet(this, _Reader_offset, 0, "f");
|
|
345
|
+
}
|
|
346
|
+
get data() { return data.hexlify(__classPrivateFieldGet(this, _Reader_data, "f")); }
|
|
347
|
+
get dataLength() { return __classPrivateFieldGet(this, _Reader_data, "f").length; }
|
|
348
|
+
get consumed() { return __classPrivateFieldGet(this, _Reader_offset, "f"); }
|
|
349
|
+
get bytes() { return new Uint8Array(__classPrivateFieldGet(this, _Reader_data, "f")); }
|
|
350
|
+
// Create a sub-reader with the same underlying data, but offset
|
|
351
|
+
subReader(offset) {
|
|
352
|
+
const reader = new Reader(__classPrivateFieldGet(this, _Reader_data, "f").slice(__classPrivateFieldGet(this, _Reader_offset, "f") + offset), this.allowLoose, __classPrivateFieldGet(this, _Reader_maxInflation, "f"));
|
|
353
|
+
__classPrivateFieldSet(reader, _Reader_parent, this, "f");
|
|
354
|
+
return reader;
|
|
355
|
+
}
|
|
356
|
+
// Read bytes
|
|
357
|
+
readBytes(length, loose) {
|
|
358
|
+
let bytes = __classPrivateFieldGet(this, _Reader_instances, "m", _Reader_peekBytes).call(this, 0, length, !!loose);
|
|
359
|
+
__classPrivateFieldGet(this, _Reader_instances, "m", _Reader_incrementBytesRead).call(this, length);
|
|
360
|
+
__classPrivateFieldSet(this, _Reader_offset, __classPrivateFieldGet(this, _Reader_offset, "f") + bytes.length, "f");
|
|
361
|
+
// @TODO: Make sure the length..end bytes are all 0?
|
|
362
|
+
return bytes.slice(0, length);
|
|
363
|
+
}
|
|
364
|
+
// Read a numeric values
|
|
365
|
+
readValue() {
|
|
366
|
+
return maths.toBigInt(this.readBytes(WordSize));
|
|
367
|
+
}
|
|
368
|
+
readIndex() {
|
|
369
|
+
return maths.toNumber(this.readBytes(WordSize));
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
_Reader_data = new WeakMap(), _Reader_offset = new WeakMap(), _Reader_bytesRead = new WeakMap(), _Reader_parent = new WeakMap(), _Reader_maxInflation = new WeakMap(), _Reader_instances = new WeakSet(), _Reader_incrementBytesRead = function _Reader_incrementBytesRead(count) {
|
|
373
|
+
var _a;
|
|
374
|
+
if (__classPrivateFieldGet(this, _Reader_parent, "f")) {
|
|
375
|
+
return __classPrivateFieldGet((_a = __classPrivateFieldGet(this, _Reader_parent, "f")), _Reader_instances, "m", _Reader_incrementBytesRead).call(_a, count);
|
|
376
|
+
}
|
|
377
|
+
__classPrivateFieldSet(this, _Reader_bytesRead, __classPrivateFieldGet(this, _Reader_bytesRead, "f") + count, "f");
|
|
378
|
+
// Check for excessive inflation (see: #4537)
|
|
379
|
+
errors.assert(__classPrivateFieldGet(this, _Reader_maxInflation, "f") < 1 || __classPrivateFieldGet(this, _Reader_bytesRead, "f") <= __classPrivateFieldGet(this, _Reader_maxInflation, "f") * this.dataLength, `compressed ABI data exceeds inflation ratio of ${__classPrivateFieldGet(this, _Reader_maxInflation, "f")} ( see: https:/\/github.com/ethers-io/ethers.js/issues/4537 )`, "BUFFER_OVERRUN", {
|
|
380
|
+
buffer: data.getBytesCopy(__classPrivateFieldGet(this, _Reader_data, "f")), offset: __classPrivateFieldGet(this, _Reader_offset, "f"),
|
|
381
|
+
length: count, info: {
|
|
382
|
+
bytesRead: __classPrivateFieldGet(this, _Reader_bytesRead, "f"),
|
|
383
|
+
dataLength: this.dataLength
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
}, _Reader_peekBytes = function _Reader_peekBytes(offset, length, loose) {
|
|
387
|
+
let alignedLength = Math.ceil(length / WordSize) * WordSize;
|
|
388
|
+
if (__classPrivateFieldGet(this, _Reader_offset, "f") + alignedLength > __classPrivateFieldGet(this, _Reader_data, "f").length) {
|
|
389
|
+
if (this.allowLoose && loose && __classPrivateFieldGet(this, _Reader_offset, "f") + length <= __classPrivateFieldGet(this, _Reader_data, "f").length) {
|
|
390
|
+
alignedLength = length;
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
errors.assert(false, "data out-of-bounds", "BUFFER_OVERRUN", {
|
|
394
|
+
buffer: data.getBytesCopy(__classPrivateFieldGet(this, _Reader_data, "f")),
|
|
395
|
+
length: __classPrivateFieldGet(this, _Reader_data, "f").length,
|
|
396
|
+
offset: __classPrivateFieldGet(this, _Reader_offset, "f") + alignedLength
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return __classPrivateFieldGet(this, _Reader_data, "f").slice(__classPrivateFieldGet(this, _Reader_offset, "f"), __classPrivateFieldGet(this, _Reader_offset, "f") + alignedLength);
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
exports.Coder = Coder;
|
|
404
|
+
exports.Reader = Reader;
|
|
405
|
+
exports.Result = Result;
|
|
406
|
+
exports.WordSize = WordSize;
|
|
407
|
+
exports.Writer = Writer;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var address = require('../address/address.js');
|
|
6
|
+
require('../utils/base58.js');
|
|
7
|
+
require('../utils/errors.js');
|
|
8
|
+
require('../utils/events.js');
|
|
9
|
+
require('../utils/fixednumber.js');
|
|
10
|
+
var maths = 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 typed = require('../typed.js');
|
|
18
|
+
var abstractCoder = require('./abstract-coder.js');
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @_ignore
|
|
22
|
+
*/
|
|
23
|
+
class AddressCoder extends abstractCoder.Coder {
|
|
24
|
+
constructor(localName) {
|
|
25
|
+
super("address", "address", localName, false);
|
|
26
|
+
}
|
|
27
|
+
defaultValue() {
|
|
28
|
+
return "0x0000000000000000000000000000000000000000";
|
|
29
|
+
}
|
|
30
|
+
encode(writer, _value) {
|
|
31
|
+
let value = typed.Typed.dereference(_value, "string");
|
|
32
|
+
try {
|
|
33
|
+
value = address.getAddress(value);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
return this._throwError(error.message, _value);
|
|
37
|
+
}
|
|
38
|
+
return writer.writeValue(value);
|
|
39
|
+
}
|
|
40
|
+
decode(reader) {
|
|
41
|
+
return address.getAddress(maths.toBeHex(reader.readValue(), 20));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
exports.AddressCoder = AddressCoder;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var abstractCoder = require('./abstract-coder.js');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Clones the functionality of an existing Coder, but without a localName
|
|
9
|
+
*
|
|
10
|
+
* @_ignore
|
|
11
|
+
*/
|
|
12
|
+
class AnonymousCoder extends abstractCoder.Coder {
|
|
13
|
+
constructor(coder) {
|
|
14
|
+
super(coder.name, coder.type, "_", coder.dynamic);
|
|
15
|
+
this.coder = coder;
|
|
16
|
+
}
|
|
17
|
+
defaultValue() {
|
|
18
|
+
return this.coder.defaultValue();
|
|
19
|
+
}
|
|
20
|
+
encode(writer, value) {
|
|
21
|
+
return this.coder.encode(writer, value);
|
|
22
|
+
}
|
|
23
|
+
decode(reader) {
|
|
24
|
+
return this.coder.decode(reader);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
exports.AnonymousCoder = AnonymousCoder;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('../utils/base58.js');
|
|
6
|
+
var errors = require('../utils/errors.js');
|
|
7
|
+
require('../utils/events.js');
|
|
8
|
+
require('../utils/fixednumber.js');
|
|
9
|
+
require('../utils/maths.js');
|
|
10
|
+
var properties = require('../utils/properties.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 typed = require('../typed.js');
|
|
18
|
+
var abstractCoder = require('./abstract-coder.js');
|
|
19
|
+
var anonymous = require('./anonymous.js');
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @_ignore
|
|
23
|
+
*/
|
|
24
|
+
function pack(writer, coders, values) {
|
|
25
|
+
let arrayValues = [];
|
|
26
|
+
if (Array.isArray(values)) {
|
|
27
|
+
arrayValues = values;
|
|
28
|
+
}
|
|
29
|
+
else if (values && typeof (values) === "object") {
|
|
30
|
+
let unique = {};
|
|
31
|
+
arrayValues = coders.map((coder) => {
|
|
32
|
+
const name = coder.localName;
|
|
33
|
+
errors.assert(name, "cannot encode object for signature with missing names", "INVALID_ARGUMENT", { argument: "values", info: { coder }, value: values });
|
|
34
|
+
errors.assert(!unique[name], "cannot encode object for signature with duplicate names", "INVALID_ARGUMENT", { argument: "values", info: { coder }, value: values });
|
|
35
|
+
unique[name] = true;
|
|
36
|
+
return values[name];
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
errors.assertArgument(false, "invalid tuple value", "tuple", values);
|
|
41
|
+
}
|
|
42
|
+
errors.assertArgument(coders.length === arrayValues.length, "types/value length mismatch", "tuple", values);
|
|
43
|
+
let staticWriter = new abstractCoder.Writer();
|
|
44
|
+
let dynamicWriter = new abstractCoder.Writer();
|
|
45
|
+
let updateFuncs = [];
|
|
46
|
+
coders.forEach((coder, index) => {
|
|
47
|
+
let value = arrayValues[index];
|
|
48
|
+
if (coder.dynamic) {
|
|
49
|
+
// Get current dynamic offset (for the future pointer)
|
|
50
|
+
let dynamicOffset = dynamicWriter.length;
|
|
51
|
+
// Encode the dynamic value into the dynamicWriter
|
|
52
|
+
coder.encode(dynamicWriter, value);
|
|
53
|
+
// Prepare to populate the correct offset once we are done
|
|
54
|
+
let updateFunc = staticWriter.writeUpdatableValue();
|
|
55
|
+
updateFuncs.push((baseOffset) => {
|
|
56
|
+
updateFunc(baseOffset + dynamicOffset);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
coder.encode(staticWriter, value);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
// Backfill all the dynamic offsets, now that we know the static length
|
|
64
|
+
updateFuncs.forEach((func) => { func(staticWriter.length); });
|
|
65
|
+
let length = writer.appendWriter(staticWriter);
|
|
66
|
+
length += writer.appendWriter(dynamicWriter);
|
|
67
|
+
return length;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @_ignore
|
|
71
|
+
*/
|
|
72
|
+
function unpack(reader, coders) {
|
|
73
|
+
let values = [];
|
|
74
|
+
let keys = [];
|
|
75
|
+
// A reader anchored to this base
|
|
76
|
+
let baseReader = reader.subReader(0);
|
|
77
|
+
coders.forEach((coder) => {
|
|
78
|
+
let value = null;
|
|
79
|
+
if (coder.dynamic) {
|
|
80
|
+
let offset = reader.readIndex();
|
|
81
|
+
let offsetReader = baseReader.subReader(offset);
|
|
82
|
+
try {
|
|
83
|
+
value = coder.decode(offsetReader);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
// Cannot recover from this
|
|
87
|
+
if (errors.isError(error, "BUFFER_OVERRUN")) {
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
value = error;
|
|
91
|
+
value.baseType = coder.name;
|
|
92
|
+
value.name = coder.localName;
|
|
93
|
+
value.type = coder.type;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
try {
|
|
98
|
+
value = coder.decode(reader);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
// Cannot recover from this
|
|
102
|
+
if (errors.isError(error, "BUFFER_OVERRUN")) {
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
value = error;
|
|
106
|
+
value.baseType = coder.name;
|
|
107
|
+
value.name = coder.localName;
|
|
108
|
+
value.type = coder.type;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (value == undefined) {
|
|
112
|
+
throw new Error("investigate");
|
|
113
|
+
}
|
|
114
|
+
values.push(value);
|
|
115
|
+
keys.push(coder.localName || null);
|
|
116
|
+
});
|
|
117
|
+
return abstractCoder.Result.fromItems(values, keys);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* @_ignore
|
|
121
|
+
*/
|
|
122
|
+
class ArrayCoder extends abstractCoder.Coder {
|
|
123
|
+
constructor(coder, length, localName) {
|
|
124
|
+
const type = (coder.type + "[" + (length >= 0 ? length : "") + "]");
|
|
125
|
+
const dynamic = (length === -1 || coder.dynamic);
|
|
126
|
+
super("array", type, localName, dynamic);
|
|
127
|
+
properties.defineProperties(this, { coder, length });
|
|
128
|
+
}
|
|
129
|
+
defaultValue() {
|
|
130
|
+
// Verifies the child coder is valid (even if the array is dynamic or 0-length)
|
|
131
|
+
const defaultChild = this.coder.defaultValue();
|
|
132
|
+
const result = [];
|
|
133
|
+
for (let i = 0; i < this.length; i++) {
|
|
134
|
+
result.push(defaultChild);
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
encode(writer, _value) {
|
|
139
|
+
const value = typed.Typed.dereference(_value, "array");
|
|
140
|
+
if (!Array.isArray(value)) {
|
|
141
|
+
this._throwError("expected array value", value);
|
|
142
|
+
}
|
|
143
|
+
let count = this.length;
|
|
144
|
+
if (count === -1) {
|
|
145
|
+
count = value.length;
|
|
146
|
+
writer.writeValue(value.length);
|
|
147
|
+
}
|
|
148
|
+
errors.assertArgumentCount(value.length, count, "coder array" + (this.localName ? (" " + this.localName) : ""));
|
|
149
|
+
let coders = [];
|
|
150
|
+
for (let i = 0; i < value.length; i++) {
|
|
151
|
+
coders.push(this.coder);
|
|
152
|
+
}
|
|
153
|
+
return pack(writer, coders, value);
|
|
154
|
+
}
|
|
155
|
+
decode(reader) {
|
|
156
|
+
let count = this.length;
|
|
157
|
+
if (count === -1) {
|
|
158
|
+
count = reader.readIndex();
|
|
159
|
+
// Check that there is *roughly* enough data to ensure
|
|
160
|
+
// stray random data is not being read as a length. Each
|
|
161
|
+
// slot requires at least 32 bytes for their value (or 32
|
|
162
|
+
// bytes as a link to the data). This could use a much
|
|
163
|
+
// tighter bound, but we are erroring on the side of safety.
|
|
164
|
+
errors.assert(count * abstractCoder.WordSize <= reader.dataLength, "insufficient data length", "BUFFER_OVERRUN", { buffer: reader.bytes, offset: count * abstractCoder.WordSize, length: reader.dataLength });
|
|
165
|
+
}
|
|
166
|
+
let coders = [];
|
|
167
|
+
for (let i = 0; i < count; i++) {
|
|
168
|
+
coders.push(new anonymous.AnonymousCoder(this.coder));
|
|
169
|
+
}
|
|
170
|
+
return unpack(reader, coders);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
exports.ArrayCoder = ArrayCoder;
|
|
175
|
+
exports.pack = pack;
|
|
176
|
+
exports.unpack = unpack;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var typed = require('../typed.js');
|
|
6
|
+
var abstractCoder = require('./abstract-coder.js');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @_ignore
|
|
10
|
+
*/
|
|
11
|
+
class BooleanCoder extends abstractCoder.Coder {
|
|
12
|
+
constructor(localName) {
|
|
13
|
+
super("bool", "bool", localName, false);
|
|
14
|
+
}
|
|
15
|
+
defaultValue() {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
encode(writer, _value) {
|
|
19
|
+
const value = typed.Typed.dereference(_value, "bool");
|
|
20
|
+
return writer.writeValue(value ? 1 : 0);
|
|
21
|
+
}
|
|
22
|
+
decode(reader) {
|
|
23
|
+
return !!reader.readValue();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.BooleanCoder = BooleanCoder;
|