@steemit/steem-js 0.7.10 → 0.8.0
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 +22 -3
- package/circle.yml +1 -1
- package/config.json +1 -1
- package/dist/steem-tests.min.js +4097 -23
- package/dist/steem.min.js +2089 -18
- package/docker-webpack.config.js +44 -0
- package/lib/api/index.js +305 -412
- package/lib/api/methods.js +16 -1
- package/lib/api/rpc-auth.js +135 -0
- package/lib/api/transports/base.js +25 -66
- package/lib/api/transports/http.js +114 -129
- package/lib/api/transports/index.js +8 -15
- package/lib/api/transports/ws.js +107 -207
- package/lib/auth/ecc/index.js +9 -9
- package/lib/auth/ecc/src/address.js +48 -78
- package/lib/auth/ecc/src/aes.js +93 -129
- package/lib/auth/ecc/src/brain_key.js +7 -7
- package/lib/auth/ecc/src/ecdsa.js +7 -33
- package/lib/auth/ecc/src/ecsignature.js +4 -30
- package/lib/auth/ecc/src/enforce_types.js +1 -8
- package/lib/auth/ecc/src/hash.js +16 -25
- package/lib/auth/ecc/src/key_private.js +146 -199
- package/lib/auth/ecc/src/key_public.js +130 -202
- package/lib/auth/ecc/src/key_utils.js +64 -106
- package/lib/auth/ecc/src/signature.js +125 -177
- package/lib/auth/index.js +84 -97
- package/lib/auth/memo.js +90 -118
- package/lib/auth/serializer/index.js +12 -18
- package/lib/auth/serializer/src/ChainTypes.js +0 -3
- package/lib/auth/serializer/src/convert.js +29 -32
- package/lib/auth/serializer/src/error_with_cause.js +22 -37
- package/lib/auth/serializer/src/fast_parser.js +54 -74
- package/lib/auth/serializer/src/number_utils.js +30 -54
- package/lib/auth/serializer/src/object_id.js +37 -62
- package/lib/auth/serializer/src/operations.js +597 -689
- package/lib/auth/serializer/src/precision.js +55 -73
- package/lib/auth/serializer/src/serializer.js +158 -204
- package/lib/auth/serializer/src/template.js +13 -8
- package/lib/auth/serializer/src/types.js +949 -1110
- package/lib/auth/serializer/src/validation.js +268 -328
- package/lib/broadcast/helpers.js +61 -98
- package/lib/broadcast/index.js +61 -82
- package/lib/browser.js +15 -19
- package/lib/config.js +16 -38
- package/lib/formatter.js +89 -115
- package/lib/index.js +19 -17
- package/lib/utils.js +4 -9
- package/node-18.dockerfile +28 -0
- package/package.json +62 -38
- package/test/Crypto.js +16 -16
- package/test/KeyFormats.js +1 -1
- package/test/api.test.js +37 -0
- package/test/broadcast.test.js +14 -8
- package/test/comment.test.js +17 -3
- package/test/operations_test.js +1 -1
- package/test/promise-broadcast.test.js +86 -0
- package/test/reputation.test.js +68 -0
- package/test/smt.test.js +11 -11
- package/test-github-workflow.bat +19 -0
- package/test-github-workflow.sh +15 -0
- package/webpack/makeConfig.js +25 -17
- package/.circleci/config.yml +0 -23
- package/dist/statistics.html +0 -208
- package/dist/steem-tests.min.js.gz +0 -0
- package/dist/steem-tests.min.js.map +0 -1
- package/dist/steem.min.js.gz +0 -0
- package/dist/steem.min.js.map +0 -1
- package/lib/auth/ecc/README.md +0 -20
- package/lib/auth/ecc/package.json +0 -36
- package/lib/auth/serializer/README.md +0 -13
- package/lib/auth/serializer/package.json +0 -32
- package/node-4.dockerfile +0 -6
- package/node-6.dockerfile +0 -6
- package/yarn.lock +0 -3336
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
|
1
|
+
"use strict";
|
|
4
2
|
|
|
5
3
|
var _my;
|
|
6
4
|
var is_empty;
|
|
@@ -21,340 +19,282 @@ var Long = require('bytebuffer').Long;
|
|
|
21
19
|
// var BigInteger = require('bigi');
|
|
22
20
|
|
|
23
21
|
var chain_types = require('./ChainTypes');
|
|
24
|
-
|
|
25
22
|
var MAX_SAFE_INT = 9007199254740991;
|
|
26
23
|
var MIN_SAFE_INT = -9007199254740991;
|
|
27
24
|
|
|
28
25
|
/**
|
|
29
|
-
Most validations are skipped and the value returned unchanged when an empty string, null, or undefined is encountered (except "required").
|
|
26
|
+
Most validations are skipped and the value returned unchanged when an empty string, null, or undefined is encountered (except "required").
|
|
30
27
|
|
|
31
28
|
Validations support a string format for dealing with large numbers.
|
|
32
29
|
*/
|
|
33
30
|
module.exports = _my = {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (typeof value === "numeric") {
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
return (/^[0-9]+$/.test(value)
|
|
102
|
-
);
|
|
103
|
-
},
|
|
104
|
-
|
|
105
|
-
to_number: to_number = function to_number(value) {
|
|
106
|
-
var field_name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
|
|
107
|
-
|
|
108
|
-
if (is_empty(value)) {
|
|
109
|
-
return value;
|
|
110
|
-
}
|
|
111
|
-
_my.no_overflow53(value, field_name);
|
|
112
|
-
var int_value = function () {
|
|
113
|
-
if (typeof value === "number") {
|
|
114
|
-
return value;
|
|
115
|
-
} else {
|
|
116
|
-
return parseInt(value);
|
|
117
|
-
}
|
|
118
|
-
}();
|
|
119
|
-
return int_value;
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
to_long: function to_long(value) {
|
|
123
|
-
var field_name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
|
|
124
|
-
|
|
125
|
-
if (is_empty(value)) {
|
|
126
|
-
return value;
|
|
127
|
-
}
|
|
128
|
-
if (Long.isLong(value)) {
|
|
129
|
-
return value;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
_my.no_overflow64(value, field_name);
|
|
133
|
-
if (typeof value === "number") {
|
|
134
|
-
value = "" + value;
|
|
135
|
-
}
|
|
136
|
-
return Long.fromString(value);
|
|
137
|
-
},
|
|
138
|
-
to_string: function to_string(value) {
|
|
139
|
-
var field_name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
|
|
140
|
-
|
|
141
|
-
if (is_empty(value)) {
|
|
142
|
-
return value;
|
|
143
|
-
}
|
|
144
|
-
if (typeof value === "string") {
|
|
145
|
-
return value;
|
|
146
|
-
}
|
|
147
|
-
if (typeof value === "number") {
|
|
148
|
-
_my.no_overflow53(value, field_name);
|
|
149
|
-
return "" + value;
|
|
150
|
-
}
|
|
151
|
-
if (Long.isLong(value)) {
|
|
152
|
-
return value.toString();
|
|
153
|
-
}
|
|
154
|
-
throw 'unsupported type ' + field_name + ': (' + (typeof value === 'undefined' ? 'undefined' : _typeof(value)) + ') ' + value;
|
|
155
|
-
},
|
|
156
|
-
require_test: function require_test(regex, value) {
|
|
157
|
-
var field_name = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
|
|
158
|
-
|
|
159
|
-
if (is_empty(value)) {
|
|
160
|
-
return value;
|
|
161
|
-
}
|
|
162
|
-
if (!regex.test(value)) {
|
|
163
|
-
throw new Error('unmatched ' + regex + ' ' + field_name + ' ' + value);
|
|
164
|
-
}
|
|
165
|
-
return value;
|
|
166
|
-
},
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
require_match: require_match = function require_match(regex, value) {
|
|
170
|
-
var field_name = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
|
|
171
|
-
|
|
172
|
-
if (is_empty(value)) {
|
|
173
|
-
return value;
|
|
174
|
-
}
|
|
175
|
-
var match = value.match(regex);
|
|
176
|
-
if (match === null) {
|
|
177
|
-
throw new Error('unmatched ' + regex + ' ' + field_name + ' ' + value);
|
|
178
|
-
}
|
|
179
|
-
return match;
|
|
180
|
-
},
|
|
181
|
-
|
|
182
|
-
// require_object_id: require_object_id=function(value, field_name){
|
|
183
|
-
// return require_match(
|
|
184
|
-
// /^([0-9]+)\.([0-9]+)\.([0-9]+)$/,
|
|
185
|
-
// value,
|
|
186
|
-
// field_name
|
|
187
|
-
// );
|
|
188
|
-
// },
|
|
189
|
-
|
|
190
|
-
// Does not support over 53 bits
|
|
191
|
-
require_range: function require_range(min, max, value) {
|
|
192
|
-
var field_name = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "";
|
|
193
|
-
|
|
194
|
-
if (is_empty(value)) {
|
|
195
|
-
return value;
|
|
196
|
-
}
|
|
197
|
-
var number = to_number(value);
|
|
198
|
-
if (value < min || value > max) {
|
|
199
|
-
throw new Error('out of range ' + value + ' ' + field_name + ' ' + value);
|
|
200
|
-
}
|
|
201
|
-
return value;
|
|
202
|
-
},
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
require_object_type: require_object_type = function require_object_type() {
|
|
206
|
-
var reserved_spaces = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
207
|
-
var type = arguments[1];
|
|
208
|
-
var value = arguments[2];
|
|
209
|
-
var field_name = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "";
|
|
210
|
-
|
|
211
|
-
if (is_empty(value)) {
|
|
212
|
-
return value;
|
|
213
|
-
}
|
|
214
|
-
var object_type = chain_types.object_type[type];
|
|
215
|
-
if (!object_type) {
|
|
216
|
-
throw new Error('Unknown object type: ' + type + ', ' + field_name + ', ' + value);
|
|
217
|
-
}
|
|
218
|
-
var re = new RegExp(reserved_spaces + '.' + object_type + '.[0-9]+$');
|
|
219
|
-
if (!re.test(value)) {
|
|
220
|
-
throw new Error('Expecting ' + type + ' in format ' + (reserved_spaces + '.' + object_type + '.[0-9]+ ') + ('instead of ' + value + ' ' + field_name + ' ' + value));
|
|
221
|
-
}
|
|
222
|
-
return value;
|
|
223
|
-
},
|
|
224
|
-
|
|
225
|
-
get_instance: get_instance = function get_instance(reserve_spaces, type, value, field_name) {
|
|
226
|
-
if (is_empty(value)) {
|
|
227
|
-
return value;
|
|
228
|
-
}
|
|
229
|
-
require_object_type(reserve_spaces, type, value, field_name);
|
|
230
|
-
return to_number(value.split('.')[2]);
|
|
231
|
-
},
|
|
232
|
-
|
|
233
|
-
require_relative_type: require_relative_type = function require_relative_type(type, value, field_name) {
|
|
234
|
-
require_object_type(0, type, value, field_name);
|
|
235
|
-
return value;
|
|
236
|
-
},
|
|
237
|
-
|
|
238
|
-
get_relative_instance: get_relative_instance = function get_relative_instance(type, value, field_name) {
|
|
239
|
-
if (is_empty(value)) {
|
|
240
|
-
return value;
|
|
241
|
-
}
|
|
242
|
-
require_object_type(0, type, value, field_name);
|
|
243
|
-
return to_number(value.split('.')[2]);
|
|
244
|
-
},
|
|
245
|
-
|
|
246
|
-
require_protocol_type: require_protocol_type = function require_protocol_type(type, value, field_name) {
|
|
247
|
-
require_object_type(1, type, value, field_name);
|
|
248
|
-
return value;
|
|
249
|
-
},
|
|
250
|
-
|
|
251
|
-
get_protocol_instance: get_protocol_instance = function get_protocol_instance(type, value, field_name) {
|
|
252
|
-
if (is_empty(value)) {
|
|
253
|
-
return value;
|
|
254
|
-
}
|
|
255
|
-
require_object_type(1, type, value, field_name);
|
|
256
|
-
return to_number(value.split('.')[2]);
|
|
257
|
-
},
|
|
258
|
-
|
|
259
|
-
get_protocol_type: get_protocol_type = function get_protocol_type(value, field_name) {
|
|
260
|
-
if (is_empty(value)) {
|
|
261
|
-
return value;
|
|
262
|
-
}
|
|
263
|
-
require_object_id(value, field_name);
|
|
264
|
-
var values = value.split('.');
|
|
265
|
-
return to_number(values[1]);
|
|
266
|
-
},
|
|
267
|
-
|
|
268
|
-
get_protocol_type_name: function get_protocol_type_name(value, field_name) {
|
|
269
|
-
if (is_empty(value)) {
|
|
270
|
-
return value;
|
|
271
|
-
}
|
|
272
|
-
var type_id = get_protocol_type(value, field_name);
|
|
273
|
-
return Object.keys(chain_types.object_type)[type_id];
|
|
274
|
-
},
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
require_implementation_type: require_implementation_type = function require_implementation_type(type, value, field_name) {
|
|
278
|
-
require_object_type(2, type, value, field_name);
|
|
31
|
+
is_empty: is_empty = function (value) {
|
|
32
|
+
return value === null || value === undefined;
|
|
33
|
+
},
|
|
34
|
+
required(value, field_name = "") {
|
|
35
|
+
if (is_empty(value)) {
|
|
36
|
+
throw new Error(`value required ${field_name} ${value}`);
|
|
37
|
+
}
|
|
38
|
+
return value;
|
|
39
|
+
},
|
|
40
|
+
require_long(value, field_name = "") {
|
|
41
|
+
if (!Long.isLong(value)) {
|
|
42
|
+
throw new Error(`Long value required ${field_name} ${value}`);
|
|
43
|
+
}
|
|
44
|
+
return value;
|
|
45
|
+
},
|
|
46
|
+
string(value) {
|
|
47
|
+
if (is_empty(value)) {
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
if (typeof value !== "string") {
|
|
51
|
+
throw new Error(`string required: ${value}`);
|
|
52
|
+
}
|
|
53
|
+
return value;
|
|
54
|
+
},
|
|
55
|
+
number(value) {
|
|
56
|
+
if (is_empty(value)) {
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
if (typeof value !== "number") {
|
|
60
|
+
throw new Error(`number required: ${value}`);
|
|
61
|
+
}
|
|
62
|
+
return value;
|
|
63
|
+
},
|
|
64
|
+
whole_number(value, field_name = "") {
|
|
65
|
+
if (is_empty(value)) {
|
|
66
|
+
return value;
|
|
67
|
+
}
|
|
68
|
+
if (/\./.test(value)) {
|
|
69
|
+
throw new Error(`whole number required ${field_name} ${value}`);
|
|
70
|
+
}
|
|
71
|
+
return value;
|
|
72
|
+
},
|
|
73
|
+
unsigned(value, field_name = "") {
|
|
74
|
+
if (is_empty(value)) {
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
77
|
+
if (/-/.test(value)) {
|
|
78
|
+
throw new Error(`unsigned required ${field_name} ${value}`);
|
|
79
|
+
}
|
|
80
|
+
return value;
|
|
81
|
+
},
|
|
82
|
+
is_digits: is_digits = function (value) {
|
|
83
|
+
if (typeof value === "numeric") {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
return /^[0-9]+$/.test(value);
|
|
87
|
+
},
|
|
88
|
+
to_number: to_number = function (value, field_name = "") {
|
|
89
|
+
if (is_empty(value)) {
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
_my.no_overflow53(value, field_name);
|
|
93
|
+
var int_value = (() => {
|
|
94
|
+
if (typeof value === "number") {
|
|
279
95
|
return value;
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
96
|
+
} else {
|
|
97
|
+
return parseInt(value);
|
|
98
|
+
}
|
|
99
|
+
})();
|
|
100
|
+
return int_value;
|
|
101
|
+
},
|
|
102
|
+
to_long(value, field_name = "") {
|
|
103
|
+
if (is_empty(value)) {
|
|
104
|
+
return value;
|
|
105
|
+
}
|
|
106
|
+
if (Long.isLong(value)) {
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
_my.no_overflow64(value, field_name);
|
|
110
|
+
if (typeof value === "number") {
|
|
111
|
+
value = "" + value;
|
|
112
|
+
}
|
|
113
|
+
return Long.fromString(value);
|
|
114
|
+
},
|
|
115
|
+
to_string(value, field_name = "") {
|
|
116
|
+
if (is_empty(value)) {
|
|
117
|
+
return value;
|
|
118
|
+
}
|
|
119
|
+
if (typeof value === "string") {
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
if (typeof value === "number") {
|
|
123
|
+
_my.no_overflow53(value, field_name);
|
|
124
|
+
return "" + value;
|
|
125
|
+
}
|
|
126
|
+
if (Long.isLong(value)) {
|
|
127
|
+
return value.toString();
|
|
128
|
+
}
|
|
129
|
+
throw `unsupported type ${field_name}: (${typeof value}) ${value}`;
|
|
130
|
+
},
|
|
131
|
+
require_test(regex, value, field_name = "") {
|
|
132
|
+
if (is_empty(value)) {
|
|
133
|
+
return value;
|
|
134
|
+
}
|
|
135
|
+
if (!regex.test(value)) {
|
|
136
|
+
throw new Error(`unmatched ${regex} ${field_name} ${value}`);
|
|
137
|
+
}
|
|
138
|
+
return value;
|
|
139
|
+
},
|
|
140
|
+
require_match: require_match = function (regex, value, field_name = "") {
|
|
141
|
+
if (is_empty(value)) {
|
|
142
|
+
return value;
|
|
143
|
+
}
|
|
144
|
+
var match = value.match(regex);
|
|
145
|
+
if (match === null) {
|
|
146
|
+
throw new Error(`unmatched ${regex} ${field_name} ${value}`);
|
|
147
|
+
}
|
|
148
|
+
return match;
|
|
149
|
+
},
|
|
150
|
+
// require_object_id: require_object_id=function(value, field_name){
|
|
151
|
+
// return require_match(
|
|
152
|
+
// /^([0-9]+)\.([0-9]+)\.([0-9]+)$/,
|
|
153
|
+
// value,
|
|
154
|
+
// field_name
|
|
155
|
+
// );
|
|
156
|
+
// },
|
|
157
|
+
|
|
158
|
+
// Does not support over 53 bits
|
|
159
|
+
require_range(min, max, value, field_name = "") {
|
|
160
|
+
if (is_empty(value)) {
|
|
161
|
+
return value;
|
|
162
|
+
}
|
|
163
|
+
var number = to_number(value);
|
|
164
|
+
if (value < min || value > max) {
|
|
165
|
+
throw new Error(`out of range ${value} ${field_name} ${value}`);
|
|
166
|
+
}
|
|
167
|
+
return value;
|
|
168
|
+
},
|
|
169
|
+
require_object_type: require_object_type = function (reserved_spaces = 1, type, value, field_name = "") {
|
|
170
|
+
if (is_empty(value)) {
|
|
171
|
+
return value;
|
|
172
|
+
}
|
|
173
|
+
var object_type = chain_types.object_type[type];
|
|
174
|
+
if (!object_type) {
|
|
175
|
+
throw new Error(`Unknown object type: ${type}, ${field_name}, ${value}`);
|
|
176
|
+
}
|
|
177
|
+
var re = new RegExp(`${reserved_spaces}\.${object_type}\.[0-9]+$`);
|
|
178
|
+
if (!re.test(value)) {
|
|
179
|
+
throw new Error(`Expecting ${type} in format ` + `${reserved_spaces}.${object_type}.[0-9]+ ` + `instead of ${value} ${field_name} ${value}`);
|
|
180
|
+
}
|
|
181
|
+
return value;
|
|
182
|
+
},
|
|
183
|
+
get_instance: get_instance = function (reserve_spaces, type, value, field_name) {
|
|
184
|
+
if (is_empty(value)) {
|
|
185
|
+
return value;
|
|
186
|
+
}
|
|
187
|
+
require_object_type(reserve_spaces, type, value, field_name);
|
|
188
|
+
return to_number(value.split('.')[2]);
|
|
189
|
+
},
|
|
190
|
+
require_relative_type: require_relative_type = function (type, value, field_name) {
|
|
191
|
+
require_object_type(0, type, value, field_name);
|
|
192
|
+
return value;
|
|
193
|
+
},
|
|
194
|
+
get_relative_instance: get_relative_instance = function (type, value, field_name) {
|
|
195
|
+
if (is_empty(value)) {
|
|
196
|
+
return value;
|
|
197
|
+
}
|
|
198
|
+
require_object_type(0, type, value, field_name);
|
|
199
|
+
return to_number(value.split('.')[2]);
|
|
200
|
+
},
|
|
201
|
+
require_protocol_type: require_protocol_type = function (type, value, field_name) {
|
|
202
|
+
require_object_type(1, type, value, field_name);
|
|
203
|
+
return value;
|
|
204
|
+
},
|
|
205
|
+
get_protocol_instance: get_protocol_instance = function (type, value, field_name) {
|
|
206
|
+
if (is_empty(value)) {
|
|
207
|
+
return value;
|
|
208
|
+
}
|
|
209
|
+
require_object_type(1, type, value, field_name);
|
|
210
|
+
return to_number(value.split('.')[2]);
|
|
211
|
+
},
|
|
212
|
+
get_protocol_type: get_protocol_type = function (value, field_name) {
|
|
213
|
+
if (is_empty(value)) {
|
|
214
|
+
return value;
|
|
215
|
+
}
|
|
216
|
+
require_object_id(value, field_name);
|
|
217
|
+
var values = value.split('.');
|
|
218
|
+
return to_number(values[1]);
|
|
219
|
+
},
|
|
220
|
+
get_protocol_type_name(value, field_name) {
|
|
221
|
+
if (is_empty(value)) {
|
|
222
|
+
return value;
|
|
223
|
+
}
|
|
224
|
+
var type_id = get_protocol_type(value, field_name);
|
|
225
|
+
return Object.keys(chain_types.object_type)[type_id];
|
|
226
|
+
},
|
|
227
|
+
require_implementation_type: require_implementation_type = function (type, value, field_name) {
|
|
228
|
+
require_object_type(2, type, value, field_name);
|
|
229
|
+
return value;
|
|
230
|
+
},
|
|
231
|
+
get_implementation_instance: get_implementation_instance = function (type, value, field_name) {
|
|
232
|
+
if (is_empty(value)) {
|
|
233
|
+
return value;
|
|
234
|
+
}
|
|
235
|
+
require_object_type(2, type, value, field_name);
|
|
236
|
+
return to_number(value.split('.')[2]);
|
|
237
|
+
},
|
|
238
|
+
// signed / unsigned decimal
|
|
239
|
+
no_overflow53(value, field_name = "") {
|
|
240
|
+
if (typeof value === "number") {
|
|
241
|
+
if (value > MAX_SAFE_INT || value < MIN_SAFE_INT) {
|
|
242
|
+
throw new Error(`overflow ${field_name} ${value}`);
|
|
243
|
+
}
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (typeof value === "string") {
|
|
247
|
+
var int = parseInt(value);
|
|
248
|
+
if (value > MAX_SAFE_INT || value < MIN_SAFE_INT) {
|
|
249
|
+
throw new Error(`overflow ${field_name} ${value}`);
|
|
250
|
+
}
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (Long.isLong(value)) {
|
|
254
|
+
// typeof value.toInt() is 'number'
|
|
255
|
+
_my.no_overflow53(value.toInt(), field_name);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
throw `unsupported type ${field_name}: (${typeof value}) ${value}`;
|
|
259
|
+
},
|
|
260
|
+
// signed / unsigned whole numbers only
|
|
261
|
+
no_overflow64(value, field_name = "") {
|
|
262
|
+
// https://github.com/dcodeIO/Long.js/issues/20
|
|
263
|
+
if (Long.isLong(value)) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
357
266
|
|
|
358
|
-
|
|
267
|
+
// BigInteger#isBigInteger https://github.com/cryptocoinjs/bigi/issues/20
|
|
268
|
+
if (value.t !== undefined && value.s !== undefined) {
|
|
269
|
+
_my.no_overflow64(value.toString(), field_name);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (typeof value === "string") {
|
|
273
|
+
// remove leading zeros, will cause a false positive
|
|
274
|
+
value = value.replace(/^0+/, '');
|
|
275
|
+
// remove trailing zeros
|
|
276
|
+
while (/0$/.test(value)) {
|
|
277
|
+
value = value.substring(0, value.length - 1);
|
|
278
|
+
}
|
|
279
|
+
if (/\.$/.test(value)) {
|
|
280
|
+
// remove trailing dot
|
|
281
|
+
value = value.substring(0, value.length - 1);
|
|
282
|
+
}
|
|
283
|
+
if (value === "") {
|
|
284
|
+
value = "0";
|
|
285
|
+
}
|
|
286
|
+
var long_string = Long.fromString(value).toString();
|
|
287
|
+
if (long_string !== value.trim()) {
|
|
288
|
+
throw new Error(`overflow ${field_name} ${value}`);
|
|
289
|
+
}
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
if (typeof value === "number") {
|
|
293
|
+
if (value > MAX_SAFE_INT || value < MIN_SAFE_INT) {
|
|
294
|
+
throw new Error(`overflow ${field_name} ${value}`);
|
|
295
|
+
}
|
|
296
|
+
return;
|
|
359
297
|
}
|
|
298
|
+
throw `unsupported type ${field_name}: (${typeof value}) ${value}`;
|
|
299
|
+
}
|
|
360
300
|
};
|