@steemit/steem-js 0.7.11 → 1.0.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.
Files changed (132) hide show
  1. package/README.md +203 -87
  2. package/dist/api/index.d.ts +128 -0
  3. package/dist/api/methods.d.ts +9 -0
  4. package/dist/api/rpc-auth.d.ts +43 -0
  5. package/dist/api/transports/base.d.ts +13 -0
  6. package/dist/api/transports/http.d.ts +9 -0
  7. package/dist/api/transports/index.d.ts +9 -0
  8. package/dist/api/transports/types.d.ts +35 -0
  9. package/dist/api/transports/ws.d.ts +18 -0
  10. package/dist/auth/ecc/index.d.ts +9 -0
  11. package/dist/auth/ecc/src/address.d.ts +13 -0
  12. package/dist/auth/ecc/src/aes.d.ts +16 -0
  13. package/dist/auth/ecc/src/brain_key.d.ts +1 -0
  14. package/dist/auth/ecc/src/ecdsa.d.ts +28 -0
  15. package/dist/auth/ecc/src/ecsignature.d.ts +19 -0
  16. package/dist/auth/ecc/src/enforce_types.d.ts +5 -0
  17. package/dist/auth/ecc/src/hash.d.ts +25 -0
  18. package/dist/auth/ecc/src/index.d.ts +9 -0
  19. package/dist/auth/ecc/src/key_private.d.ts +38 -0
  20. package/dist/auth/ecc/src/key_public.d.ts +41 -0
  21. package/dist/auth/ecc/src/key_utils.d.ts +9 -0
  22. package/dist/auth/ecc/src/signature.d.ts +18 -0
  23. package/dist/auth/ecc.d.ts +3 -0
  24. package/dist/auth/index.d.ts +48 -0
  25. package/dist/auth/key_classes.d.ts +3 -0
  26. package/dist/auth/serializer.d.ts +19 -0
  27. package/dist/broadcast/helpers.d.ts +11 -0
  28. package/dist/broadcast/index.d.ts +43 -0
  29. package/dist/broadcast/operations.d.ts +6 -0
  30. package/dist/config.d.ts +25 -0
  31. package/dist/crypto/index.d.ts +25 -0
  32. package/dist/formatter/index.d.ts +92 -0
  33. package/dist/index.cjs +25848 -0
  34. package/dist/index.cjs.map +1 -0
  35. package/dist/index.d.ts +30 -0
  36. package/dist/index.js +25812 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/index.umd.js +57513 -0
  39. package/dist/index.umd.js.map +1 -0
  40. package/dist/memo/index.d.ts +11 -0
  41. package/dist/operations/index.d.ts +44 -0
  42. package/dist/serializer/convert.d.ts +12 -0
  43. package/dist/serializer/index.d.ts +11 -0
  44. package/dist/serializer/number_utils.d.ts +8 -0
  45. package/dist/serializer/precision.d.ts +5 -0
  46. package/dist/serializer/types.d.ts +36 -0
  47. package/dist/types/index.d.ts +131 -0
  48. package/dist/types.d.ts +34 -0
  49. package/dist/utils/index.d.ts +8 -0
  50. package/dist/utils.d.ts +2 -0
  51. package/package.json +72 -67
  52. package/.circleci/config.yml +0 -23
  53. package/.dockerignore +0 -12
  54. package/.editorconfig +0 -20
  55. package/.eslintrc +0 -27
  56. package/LICENSE +0 -21
  57. package/circle.yml +0 -3
  58. package/config.json +0 -10
  59. package/dist/statistics.html +0 -208
  60. package/dist/steem-tests.min.js +0 -23
  61. package/dist/steem-tests.min.js.gz +0 -0
  62. package/dist/steem-tests.min.js.map +0 -1
  63. package/dist/steem.min.js +0 -18
  64. package/dist/steem.min.js.gz +0 -0
  65. package/dist/steem.min.js.map +0 -1
  66. package/lib/api/index.js +0 -422
  67. package/lib/api/methods.js +0 -413
  68. package/lib/api/transports/base.js +0 -72
  69. package/lib/api/transports/http.js +0 -172
  70. package/lib/api/transports/index.js +0 -20
  71. package/lib/api/transports/ws.js +0 -228
  72. package/lib/auth/ecc/README.md +0 -20
  73. package/lib/auth/ecc/index.js +0 -13
  74. package/lib/auth/ecc/package.json +0 -36
  75. package/lib/auth/ecc/src/address.js +0 -84
  76. package/lib/auth/ecc/src/aes.js +0 -184
  77. package/lib/auth/ecc/src/brain_key.js +0 -13
  78. package/lib/auth/ecc/src/ecdsa.js +0 -219
  79. package/lib/auth/ecc/src/ecsignature.js +0 -128
  80. package/lib/auth/ecc/src/enforce_types.js +0 -49
  81. package/lib/auth/ecc/src/hash.js +0 -67
  82. package/lib/auth/ecc/src/key_private.js +0 -212
  83. package/lib/auth/ecc/src/key_public.js +0 -215
  84. package/lib/auth/ecc/src/key_utils.js +0 -112
  85. package/lib/auth/ecc/src/signature.js +0 -187
  86. package/lib/auth/index.js +0 -126
  87. package/lib/auth/memo.js +0 -147
  88. package/lib/auth/serializer/README.md +0 -13
  89. package/lib/auth/serializer/index.js +0 -21
  90. package/lib/auth/serializer/package.json +0 -32
  91. package/lib/auth/serializer/src/ChainTypes.js +0 -90
  92. package/lib/auth/serializer/src/convert.js +0 -37
  93. package/lib/auth/serializer/src/error_with_cause.js +0 -42
  94. package/lib/auth/serializer/src/fast_parser.js +0 -77
  95. package/lib/auth/serializer/src/number_utils.js +0 -67
  96. package/lib/auth/serializer/src/object_id.js +0 -68
  97. package/lib/auth/serializer/src/operations.js +0 -787
  98. package/lib/auth/serializer/src/precision.js +0 -95
  99. package/lib/auth/serializer/src/serializer.js +0 -211
  100. package/lib/auth/serializer/src/template.js +0 -17
  101. package/lib/auth/serializer/src/types.js +0 -1238
  102. package/lib/auth/serializer/src/validation.js +0 -360
  103. package/lib/broadcast/helpers.js +0 -177
  104. package/lib/broadcast/index.js +0 -127
  105. package/lib/broadcast/operations.js +0 -255
  106. package/lib/browser.js +0 -29
  107. package/lib/config.js +0 -45
  108. package/lib/formatter.js +0 -189
  109. package/lib/index.js +0 -19
  110. package/lib/utils.js +0 -55
  111. package/node-4.dockerfile +0 -6
  112. package/node-6.dockerfile +0 -6
  113. package/test/Crypto.js +0 -100
  114. package/test/KeyFormats.js +0 -105
  115. package/test/all_types.js +0 -115
  116. package/test/api.test.js +0 -326
  117. package/test/broadcast.test.js +0 -225
  118. package/test/browser/BrowserTests.js +0 -55
  119. package/test/comment.test.js +0 -69
  120. package/test/hf20-accounts.test.js +0 -76
  121. package/test/hf21-sps.test.js +0 -78
  122. package/test/memo.test.js +0 -37
  123. package/test/number_utils.js +0 -28
  124. package/test/operations_test.js +0 -39
  125. package/test/smt.test.js +0 -347
  126. package/test/test-post.json +0 -13
  127. package/test/test.html +0 -13
  128. package/test/test_helper.js +0 -19
  129. package/test/types_test.js +0 -139
  130. package/webpack/makeConfig.js +0 -105
  131. package/webpack.config.js +0 -2
  132. package/yarn.lock +0 -3336
@@ -1,1238 +0,0 @@
1
- 'use strict';
2
-
3
- var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
4
-
5
- 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; };
6
-
7
- var _ecc = require('../../ecc');
8
-
9
- var _number_utils = require('./number_utils');
10
-
11
- var _config = require('../../../config.js');
12
-
13
- var _config2 = _interopRequireDefault(_config);
14
-
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
-
17
- // Low-level types that make up operations
18
-
19
- var v = require('./validation');
20
- var ObjectId = require('./object_id');
21
- var fp = require('./fast_parser');
22
- var chain_types = require('./ChainTypes');
23
- //const BigInt = require('BigInt')
24
-
25
- var Types = {};
26
- module.exports = Types;
27
-
28
- var HEX_DUMP = process.env.npm_config__graphene_serializer_hex_dump;
29
-
30
- // Highly optimized implementation of Damm algorithm
31
- // https://en.wikipedia.org/wiki/Damm_algorithm
32
- function damm_checksum_8digit(value) {
33
- if (value >= 100000000) throw new Error("Expected value less than 100000000, instead got " + value);
34
-
35
- var t = [0, 30, 10, 70, 50, 90, 80, 60, 40, 20, 70, 0, 90, 20, 10, 50, 40, 80, 60, 30, 40, 20, 0, 60, 80, 70, 10, 30, 50, 90, 10, 70, 50, 0, 90, 80, 30, 40, 20, 60, 60, 10, 20, 30, 0, 40, 50, 90, 70, 80, 30, 60, 70, 40, 20, 0, 90, 50, 80, 10, 50, 80, 60, 90, 70, 20, 0, 10, 30, 40, 80, 90, 40, 50, 30, 60, 20, 0, 10, 70, 90, 40, 30, 80, 60, 10, 70, 20, 0, 50, 20, 50, 80, 10, 40, 30, 60, 70, 90, 0];
36
-
37
- var q0 = value / 10;
38
- var d0 = value % 10;
39
- var q1 = q0 / 10;
40
- var d1 = q0 % 10;
41
- var q2 = q1 / 10;
42
- var d2 = q1 % 10;
43
- var q3 = q2 / 10;
44
- var d3 = q2 % 10;
45
- var q4 = q3 / 10;
46
- var d4 = q3 % 10;
47
- var q5 = q4 / 10;
48
- var d5 = q4 % 10;
49
- var d6 = q5 % 10;
50
- var d7 = q5 / 10;
51
-
52
- var x = t[d7];
53
- x = t[x + d6];
54
- x = t[x + d5];
55
- x = t[x + d4];
56
- x = t[x + d3];
57
- x = t[x + d2];
58
- x = t[x + d1];
59
- x = t[x + d0];
60
-
61
- return x / 10;
62
- }
63
-
64
- /**
65
- * Asset symbols contain the following information
66
- *
67
- * 4 bit PRECISION
68
- * 4 bit RESERVED
69
- * CHAR[6] up to 6 upper case alpha numeric ascii characters,
70
- * char = \0 null terminated
71
- *
72
- * It is treated as a uint64_t for all internal operations, but
73
- * is easily converted to something that can be displayed.
74
- *
75
- * Legacy serialization of assets
76
- * 0000pppp aaaaaaaa bbbbbbbb cccccccc dddddddd eeeeeeee ffffffff 00000000
77
- * Symbol = abcdef
78
- *
79
- * NAI serialization of assets
80
- * aaa1pppp bbbbbbbb cccccccc dddddddd
81
- * NAI = (MSB to LSB) dddddddd cccccccc bbbbbbbb aaa
82
- *
83
- * NAI internal storage of legacy assets
84
- */
85
- Types.asset = {
86
- fromByteBuffer: function fromByteBuffer(b) {
87
- var amount = b.readInt64();
88
- var precision = b.readUint8();
89
- var amount_string = "";
90
- var symbol = "";
91
-
92
- if (precision >= 16) {
93
- // NAI Case
94
- var b_copy = b.copy(b.offset - 1, b.offset + 3);
95
- var nai = new Buffer(b_copy.toBinary(), "binary").readInt32();
96
- nai = nai / 32;
97
- symbol = "@@" + nai.toString().padStart(8, '0') + damm_checksum_8digit(nai).to_String();
98
- precision = precision % 16;
99
- b.skip(3);
100
- amount_string = (0, _number_utils.fromImpliedDecimal)(amount, precision);
101
- } else {
102
- // Legacy Case
103
- var _b_copy = b.copy(b.offset, b.offset + 7);
104
- symbol = new Buffer(_b_copy.toBinary(), "binary").toString().replace(/\x00/g, "");
105
- b.skip(7);
106
- // "1.000 STEEM" always written with full precision
107
- amount_string = (0, _number_utils.fromImpliedDecimal)(amount, precision);
108
- }
109
-
110
- return amount_string + " " + symbol;
111
- },
112
- appendByteBuffer: function appendByteBuffer(b, object) {
113
- var amount = "";
114
- var symbol = "";
115
- var nai = 0;
116
- var precision = 0;
117
-
118
- if (object["nai"]) {
119
- symbol = object["nai"];
120
- nai = parseInt(symbol.slice(2));
121
- var checksum = nai % 10;
122
- nai = Math.floor(nai / 10);
123
- var expected_checksum = damm_checksum_8digit(nai);
124
-
125
- switch (object["nai"]) {
126
- case "@@000000021":
127
- precision = 3;
128
- symbol = _config2.default.get("address_prefix") == "STM" ? "STEEM" : "TESTS";
129
- break;
130
- case "@@000000013":
131
- precision = 3;
132
- symbol = _config2.default.get("address_prefix") == "STM" ? "SBD" : "TBD";
133
- break;
134
- case "@@000000037":
135
- precision = 6;
136
- symbol = "VESTS";
137
- break;
138
- }
139
-
140
- precision = parseInt(object["precision"]);
141
- b.writeInt64(v.to_long(parseInt(object["amount"])));
142
- } else {
143
- object = object.trim();
144
- if (!/^[0-9]+\.?[0-9]* [A-Za-z0-9@]+$/.test(object)) throw new Error("Expecting amount like '99.000 SYMBOL', instead got '" + object + "'");
145
-
146
- var res = object.split(" ");
147
- amount = res[0];
148
- symbol = res[1];
149
-
150
- if (symbol.startsWith("@@")) {
151
- // NAI Case
152
- nai = parseInt(symbol.slice(2));
153
- var _checksum = nai % 10;
154
- nai = Math.floor(nai / 10);
155
- var _expected_checksum = damm_checksum_8digit(nai);
156
- } else if (symbol.length > 6) throw new Error("Symbols are not longer than 6 characters " + symbol + "-" + symbol.length);
157
-
158
- b.writeInt64(v.to_long(amount.replace(".", "")));
159
- var dot = amount.indexOf("."); // 0.000
160
- precision = dot === -1 ? 0 : amount.length - dot - 1;
161
- }
162
-
163
- if (symbol.startsWith("@@")) {
164
- nai = (nai << 5) + 16 + precision;
165
- b.writeUint32(nai);
166
- } else {
167
- b.writeUint8(precision);
168
- b.append(symbol.toUpperCase(), 'binary');
169
- for (var i = 0; i < 7 - symbol.length; i++) {
170
- b.writeUint8(0);
171
- }
172
- }
173
-
174
- return;
175
- },
176
- fromObject: function fromObject(object) {
177
- return object;
178
- },
179
- toObject: function toObject(object) {
180
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
181
-
182
- if (debug.use_default && object === undefined) {
183
- return "0.000 STEEM";
184
- }
185
- return object;
186
- }
187
- };
188
-
189
- Types.asset_symbol = {
190
- fromByteBuffer: function fromByteBuffer(b) {
191
- var precision = b.readUint8();
192
- var amount_string = "";
193
- var nai_string = "";
194
-
195
- if (precision >= 16) {
196
- // NAI Case
197
- var b_copy = b.copy(b.offset - 1, b.offset + 3);
198
- var nai = new Buffer(b_copy.toBinary(), "binary").readInt32();
199
- nai = nai / 32;
200
- nai_string = "@@" + nai.toString().padStart(8, '0') + damm_checksum_8digit(nai).to_String();
201
- precision = precision % 16;
202
- b.skip(3);
203
- } else {
204
- // Legacy Case
205
- var _b_copy2 = b.copy(b.offset, b.offset + 7);
206
- var symbol = new Buffer(_b_copy2.toBinary(), "binary").toString().replace(/\x00/g, "");
207
- if (symbol == "STEEM" || symbol == "TESTS") nai_string = "@@000000021";else if (symbol == "SBD" || symbol == "TBD") nai_string = "@@000000013";else if (symbol == "VESTS") nai_string = "@@000000037";else throw new Error("Expecting non-smt core asset symbol, instead got '" + symbol + "'");
208
- b.skip(7);
209
- }
210
-
211
- return { "nai": nai_string, "precision": precision };
212
- },
213
- appendByteBuffer: function appendByteBuffer(b, object) {
214
-
215
- var nai = 0;
216
- if (!object["nai"].startsWith("@@")) throw new Error("Asset Symbols NAIs must be prefixed with '@@'. Was " + object["nai"]);
217
-
218
- nai = parseInt(object["nai"].slice(2));
219
- var checksum = nai % 10;
220
- nai = Math.floor(nai / 10);
221
- var expected_checksum = damm_checksum_8digit(nai);
222
-
223
- var precision = 0;
224
- var symbol = "";
225
- switch (object["nai"]) {
226
- case "@@000000021":
227
- precision = 3;
228
- symbol = _config2.default.get("address_prefix") == "STM" ? "STEEM" : "TESTS";
229
- break;
230
- case "@@000000013":
231
- precision = 3;
232
- symbol = _config2.default.get("address_prefix") == "STM" ? "SBD" : "TBD";
233
- break;
234
- case "@@000000037":
235
- precision = 6;
236
- symbol = "VESTS";
237
- break;
238
- }
239
-
240
- if (precision > 0) {
241
- //Core Symbol Case
242
- b.writeUint8(precision);
243
- b.append(symbol, 'binary');
244
- for (var i = 0; i < 7 - symbol.length; i++) {
245
- b.writeUint8(0);
246
- }
247
- } else {
248
- nai = (nai << 5) + 16 + object["precision"];
249
- b.writeUint32(nai);
250
- }
251
-
252
- return;
253
- },
254
- fromObject: function fromObject(object) {
255
- return object;
256
- },
257
- toObject: function toObject(object) {
258
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
259
-
260
- if (debug.use_default && object === undefined) {
261
- return "STEEM";
262
- }
263
- return object;
264
- }
265
- };
266
-
267
- Types.uint8 = {
268
- fromByteBuffer: function fromByteBuffer(b) {
269
- return b.readUint8();
270
- },
271
- appendByteBuffer: function appendByteBuffer(b, object) {
272
- v.require_range(0, 0xFF, object, 'uint8 ' + object);
273
- b.writeUint8(object);
274
- return;
275
- },
276
- fromObject: function fromObject(object) {
277
- v.require_range(0, 0xFF, object, 'uint8 ' + object);
278
- return object;
279
- },
280
- toObject: function toObject(object) {
281
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
282
-
283
- if (debug.use_default && object === undefined) {
284
- return 0;
285
- }
286
- v.require_range(0, 0xFF, object, 'uint8 ' + object);
287
- return parseInt(object);
288
- }
289
- };
290
-
291
- Types.uint16 = {
292
- fromByteBuffer: function fromByteBuffer(b) {
293
- return b.readUint16();
294
- },
295
- appendByteBuffer: function appendByteBuffer(b, object) {
296
- v.require_range(0, 0xFFFF, object, 'uint16 ' + object);
297
- b.writeUint16(object);
298
- return;
299
- },
300
- fromObject: function fromObject(object) {
301
- v.require_range(0, 0xFFFF, object, 'uint16 ' + object);
302
- return object;
303
- },
304
- toObject: function toObject(object) {
305
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
306
-
307
- if (debug.use_default && object === undefined) {
308
- return 0;
309
- }
310
- v.require_range(0, 0xFFFF, object, 'uint16 ' + object);
311
- return parseInt(object);
312
- }
313
- };
314
-
315
- Types.uint32 = {
316
- fromByteBuffer: function fromByteBuffer(b) {
317
- return b.readUint32();
318
- },
319
- appendByteBuffer: function appendByteBuffer(b, object) {
320
- v.require_range(0, 0xFFFFFFFF, object, 'uint32 ' + object);
321
- b.writeUint32(object);
322
- return;
323
- },
324
- fromObject: function fromObject(object) {
325
- v.require_range(0, 0xFFFFFFFF, object, 'uint32 ' + object);
326
- return object;
327
- },
328
- toObject: function toObject(object) {
329
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
330
-
331
- if (debug.use_default && object === undefined) {
332
- return 0;
333
- }
334
- v.require_range(0, 0xFFFFFFFF, object, 'uint32 ' + object);
335
- return parseInt(object);
336
- }
337
- };
338
-
339
- var MIN_SIGNED_32 = -1 * Math.pow(2, 31);
340
- var MAX_SIGNED_32 = Math.pow(2, 31) - 1;
341
-
342
- Types.varint32 = {
343
- fromByteBuffer: function fromByteBuffer(b) {
344
- return b.readVarint32();
345
- },
346
- appendByteBuffer: function appendByteBuffer(b, object) {
347
- v.require_range(MIN_SIGNED_32, MAX_SIGNED_32, object, 'uint32 ' + object);
348
- b.writeVarint32(object);
349
- return;
350
- },
351
- fromObject: function fromObject(object) {
352
- v.require_range(MIN_SIGNED_32, MAX_SIGNED_32, object, 'uint32 ' + object);
353
- return object;
354
- },
355
- toObject: function toObject(object) {
356
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
357
-
358
- if (debug.use_default && object === undefined) {
359
- return 0;
360
- }
361
- v.require_range(MIN_SIGNED_32, MAX_SIGNED_32, object, 'uint32 ' + object);
362
- return parseInt(object);
363
- }
364
- };
365
-
366
- Types.int16 = {
367
- fromByteBuffer: function fromByteBuffer(b) {
368
- return b.readInt16();
369
- },
370
- appendByteBuffer: function appendByteBuffer(b, object) {
371
- b.writeInt16(object);
372
- return;
373
- },
374
- fromObject: function fromObject(object) {
375
- return object;
376
- },
377
- toObject: function toObject(object) {
378
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
379
-
380
- if (debug.use_default && object === undefined) {
381
- return 0;
382
- }
383
- return parseInt(object);
384
- }
385
- };
386
-
387
- Types.int64 = {
388
- fromByteBuffer: function fromByteBuffer(b) {
389
- return b.readInt64();
390
- },
391
- appendByteBuffer: function appendByteBuffer(b, object) {
392
- v.required(object);
393
- b.writeInt64(v.to_long(object));
394
- return;
395
- },
396
- fromObject: function fromObject(object) {
397
- v.required(object);
398
- return v.to_long(object);
399
- },
400
- toObject: function toObject(object) {
401
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
402
-
403
- if (debug.use_default && object === undefined) {
404
- return "0";
405
- }
406
- v.required(object);
407
- return v.to_long(object).toString();
408
- }
409
- };
410
-
411
- Types.uint64 = {
412
- fromByteBuffer: function fromByteBuffer(b) {
413
- return b.readUint64();
414
- },
415
- appendByteBuffer: function appendByteBuffer(b, object) {
416
- b.writeUint64(v.to_long(v.unsigned(object)));
417
- return;
418
- },
419
- fromObject: function fromObject(object) {
420
- return v.to_long(v.unsigned(object));
421
- },
422
- toObject: function toObject(object) {
423
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
424
-
425
- if (debug.use_default && object === undefined) {
426
- return "0";
427
- }
428
- return v.to_long(object).toString();
429
- }
430
- };
431
-
432
- Types.uint128 = {
433
- fromByteBuffer: function fromByteBuffer(b) {
434
- b.readBigInt64();
435
- return b.readBigInt64();
436
- },
437
- appendByteBuffer: function appendByteBuffer(b, object) {
438
- b.writeUint64(v.to_long(v.unsigned(0)));
439
- b.writeUint64(v.to_long(v.unsigned(object)));
440
- return;
441
- },
442
- fromObject: function fromObject(object) {
443
- return v.to_long(v.unsigned(object));
444
- },
445
- toObject: function toObject(object) {
446
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
447
-
448
- if (debug.use_default && object === undefined) {
449
- return "0";
450
- }
451
- return v.to_long(object).toString();
452
- }
453
- };
454
-
455
- Types.string = {
456
- fromByteBuffer: function fromByteBuffer(b) {
457
- return new Buffer(b.readVString(), 'utf8');
458
- },
459
- appendByteBuffer: function appendByteBuffer(b, object) {
460
- v.required(object);
461
- b.writeVString(object.toString());
462
- return;
463
- },
464
- fromObject: function fromObject(object) {
465
- v.required(object);
466
- return new Buffer(object, 'utf8');
467
- },
468
- toObject: function toObject(object) {
469
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
470
-
471
- if (debug.use_default && object === undefined) {
472
- return "";
473
- }
474
- return object.toString('utf8');
475
- }
476
- };
477
-
478
- Types.string_binary = {
479
- fromByteBuffer: function fromByteBuffer(b) {
480
- var b_copy;
481
- var len = b.readVarint32();
482
- b_copy = b.copy(b.offset, b.offset + len), b.skip(len);
483
- return new Buffer(b_copy.toBinary(), 'binary');
484
- },
485
- appendByteBuffer: function appendByteBuffer(b, object) {
486
- b.writeVarint32(object.length);
487
- b.append(object.toString('binary'), 'binary');
488
- return;
489
- },
490
- fromObject: function fromObject(object) {
491
- v.required(object);
492
- return new Buffer(object);
493
- },
494
- toObject: function toObject(object) {
495
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
496
-
497
- if (debug.use_default && object === undefined) {
498
- return "";
499
- }
500
- return object.toString();
501
- }
502
- };
503
-
504
- Types.bytes = function (size) {
505
- return {
506
- fromByteBuffer: function fromByteBuffer(b) {
507
- if (size === undefined) {
508
- var b_copy;
509
- var len = b.readVarint32();
510
- b_copy = b.copy(b.offset, b.offset + len), b.skip(len);
511
- return new Buffer(b_copy.toBinary(), 'binary');
512
- } else {
513
- b_copy = b.copy(b.offset, b.offset + size), b.skip(size);
514
- return new Buffer(b_copy.toBinary(), 'binary');
515
- }
516
- },
517
- appendByteBuffer: function appendByteBuffer(b, object) {
518
- v.required(object);
519
- if (typeof object === "string") object = new Buffer(object, "hex");
520
-
521
- if (size === undefined) {
522
- b.writeVarint32(object.length);
523
- }
524
- b.append(object.toString('binary'), 'binary');
525
- return;
526
- },
527
- fromObject: function fromObject(object) {
528
- v.required(object);
529
- if (Buffer.isBuffer(object)) return object;
530
-
531
- return new Buffer(object, 'hex');
532
- },
533
- toObject: function toObject(object) {
534
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
535
-
536
- if (debug.use_default && object === undefined) {
537
- var zeros = function zeros(num) {
538
- return new Array(num).join("00");
539
- };
540
- return zeros(size);
541
- }
542
- v.required(object);
543
- return object.toString('hex');
544
- }
545
- };
546
- };
547
-
548
- Types.bool = {
549
- fromByteBuffer: function fromByteBuffer(b) {
550
- return b.readUint8() === 1;
551
- },
552
- appendByteBuffer: function appendByteBuffer(b, object) {
553
- // supports boolean or integer
554
- b.writeUint8(JSON.parse(object) ? 1 : 0);
555
- return;
556
- },
557
- fromObject: function fromObject(object) {
558
- return JSON.parse(object) ? true : false;
559
- },
560
- toObject: function toObject(object) {
561
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
562
-
563
- if (debug.use_default && object === undefined) {
564
- return false;
565
- }
566
- return JSON.parse(object) ? true : false;
567
- }
568
- };
569
-
570
- Types.void = {
571
- fromByteBuffer: function fromByteBuffer(b) {
572
- throw new Error("(void) undefined type");
573
- },
574
- appendByteBuffer: function appendByteBuffer(b, object) {
575
- throw new Error("(void) undefined type");
576
- },
577
- fromObject: function fromObject(object) {
578
- throw new Error("(void) undefined type");
579
- },
580
- toObject: function toObject(object) {
581
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
582
-
583
- if (debug.use_default && object === undefined) {
584
- return undefined;
585
- }
586
- throw new Error("(void) undefined type");
587
- }
588
- };
589
-
590
- Types.array = function (st_operation) {
591
- return {
592
- fromByteBuffer: function fromByteBuffer(b) {
593
- var size = b.readVarint32();
594
- if (HEX_DUMP) {
595
- console.log("varint32 size = " + size.toString(16));
596
- }
597
- var result = [];
598
- for (var i = 0; 0 < size ? i < size : i > size; 0 < size ? i++ : i++) {
599
- result.push(st_operation.fromByteBuffer(b));
600
- }
601
- return sortOperation(result, st_operation);
602
- },
603
- appendByteBuffer: function appendByteBuffer(b, object) {
604
- v.required(object);
605
- object = sortOperation(object, st_operation);
606
- b.writeVarint32(object.length);
607
- for (var i = 0, o; i < object.length; i++) {
608
- o = object[i];
609
- st_operation.appendByteBuffer(b, o);
610
- }
611
- },
612
- fromObject: function fromObject(object) {
613
- v.required(object);
614
- object = sortOperation(object, st_operation);
615
- var result = [];
616
- for (var i = 0, o; i < object.length; i++) {
617
- o = object[i];
618
- result.push(st_operation.fromObject(o));
619
- }
620
- return result;
621
- },
622
- toObject: function toObject(object) {
623
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
624
-
625
- if (debug.use_default && object === undefined) {
626
- return [st_operation.toObject(object, debug)];
627
- }
628
- v.required(object);
629
- object = sortOperation(object, st_operation);
630
-
631
- var result = [];
632
- for (var i = 0, o; i < object.length; i++) {
633
- o = object[i];
634
- result.push(st_operation.toObject(o, debug));
635
- }
636
- return result;
637
- }
638
- };
639
- };
640
-
641
- Types.time_point_sec = {
642
- fromByteBuffer: function fromByteBuffer(b) {
643
- return b.readUint32();
644
- },
645
- appendByteBuffer: function appendByteBuffer(b, object) {
646
- if (typeof object !== "number") object = Types.time_point_sec.fromObject(object);
647
-
648
- b.writeUint32(object);
649
- return;
650
- },
651
- fromObject: function fromObject(object) {
652
- v.required(object);
653
-
654
- if (typeof object === "number") return object;
655
-
656
- if (object.getTime) return Math.floor(object.getTime() / 1000);
657
-
658
- if (typeof object !== "string") throw new Error("Unknown date type: " + object);
659
-
660
- if (typeof object === "string" && !/Z$/.test(object)) object = object + "Z";
661
-
662
- return Math.floor(new Date(object).getTime() / 1000);
663
- },
664
- toObject: function toObject(object) {
665
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
666
-
667
- if (debug.use_default && object === undefined) return new Date(0).toISOString().split('.')[0];
668
-
669
- v.required(object);
670
-
671
- if (typeof object === "string") return object;
672
-
673
- if (object.getTime) return object.toISOString().split('.')[0];
674
-
675
- var int = parseInt(object);
676
- v.require_range(0, 0xFFFFFFFF, int, 'uint32 ' + object);
677
- return new Date(int * 1000).toISOString().split('.')[0];
678
- }
679
- };
680
-
681
- Types.set = function (st_operation) {
682
- return {
683
- validate: function validate(array) {
684
- var dup_map = {};
685
- for (var i = 0, o; i < array.length; i++) {
686
- o = array[i];
687
- var ref;
688
- if (ref = typeof o === 'undefined' ? 'undefined' : _typeof(o), ['string', 'number'].indexOf(ref) >= 0) {
689
- if (dup_map[o] !== undefined) {
690
- throw new Error("duplicate (set)");
691
- }
692
- dup_map[o] = true;
693
- }
694
- }
695
- return sortOperation(array, st_operation);
696
- },
697
- fromByteBuffer: function fromByteBuffer(b) {
698
- var size = b.readVarint32();
699
- if (HEX_DUMP) {
700
- console.log("varint32 size = " + size.toString(16));
701
- }
702
- return this.validate(function () {
703
- var result = [];
704
- for (var i = 0; 0 < size ? i < size : i > size; 0 < size ? i++ : i++) {
705
- result.push(st_operation.fromByteBuffer(b));
706
- }
707
- return result;
708
- }());
709
- },
710
- appendByteBuffer: function appendByteBuffer(b, object) {
711
- if (!object) {
712
- object = [];
713
- }
714
- b.writeVarint32(object.length);
715
- var iterable = this.validate(object);
716
- for (var i = 0, o; i < iterable.length; i++) {
717
- o = iterable[i];
718
- st_operation.appendByteBuffer(b, o);
719
- }
720
- return;
721
- },
722
- fromObject: function fromObject(object) {
723
- if (!object) {
724
- object = [];
725
- }
726
- return this.validate(function () {
727
- var result = [];
728
- for (var i = 0, o; i < object.length; i++) {
729
- o = object[i];
730
- result.push(st_operation.fromObject(o));
731
- }
732
- return result;
733
- }());
734
- },
735
- toObject: function toObject(object) {
736
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
737
-
738
- if (debug.use_default && object === undefined) {
739
- return [st_operation.toObject(object, debug)];
740
- }
741
- if (!object) {
742
- object = [];
743
- }
744
- return this.validate(function () {
745
- var result = [];
746
- for (var i = 0, o; i < object.length; i++) {
747
- o = object[i];
748
- result.push(st_operation.toObject(o, debug));
749
- }
750
- return result;
751
- }());
752
- }
753
- };
754
- };
755
-
756
- // global_parameters_update_operation current_fees
757
- Types.fixed_array = function (count, st_operation) {
758
- return {
759
- fromByteBuffer: function fromByteBuffer(b) {
760
- var i, j, ref, results;
761
- results = [];
762
- for (i = j = 0, ref = count; j < ref; i = j += 1) {
763
- results.push(st_operation.fromByteBuffer(b));
764
- }
765
- return sortOperation(results, st_operation);
766
- },
767
- appendByteBuffer: function appendByteBuffer(b, object) {
768
- var i, j, ref;
769
- if (count !== 0) {
770
- v.required(object);
771
- object = sortOperation(object, st_operation);
772
- }
773
- for (i = j = 0, ref = count; j < ref; i = j += 1) {
774
- st_operation.appendByteBuffer(b, object[i]);
775
- }
776
- },
777
- fromObject: function fromObject(object) {
778
- var i, j, ref, results;
779
- if (count !== 0) {
780
- v.required(object);
781
- }
782
- results = [];
783
- for (i = j = 0, ref = count; j < ref; i = j += 1) {
784
- results.push(st_operation.fromObject(object[i]));
785
- }
786
- return results;
787
- },
788
- toObject: function toObject(object, debug) {
789
- var i, j, k, ref, ref1, results, results1;
790
- if (debug == null) {
791
- debug = {};
792
- }
793
- if (debug.use_default && object === void 0) {
794
- results = [];
795
- for (i = j = 0, ref = count; j < ref; i = j += 1) {
796
- results.push(st_operation.toObject(void 0, debug));
797
- }
798
- return results;
799
- }
800
- if (count !== 0) {
801
- v.required(object);
802
- }
803
- results1 = [];
804
- for (i = k = 0, ref1 = count; k < ref1; i = k += 1) {
805
- results1.push(st_operation.toObject(object[i], debug));
806
- }
807
- return results1;
808
- }
809
- };
810
- };
811
-
812
- /* Supports instance numbers (11) or object types (1.2.11). Object type
813
- validation is enforced when an object type is used. */
814
- var id_type = function id_type(reserved_spaces, object_type) {
815
- v.required(reserved_spaces, "reserved_spaces");
816
- v.required(object_type, "object_type");
817
- return {
818
- fromByteBuffer: function fromByteBuffer(b) {
819
- return b.readVarint32();
820
- },
821
- appendByteBuffer: function appendByteBuffer(b, object) {
822
- v.required(object);
823
- if (object.resolve !== undefined) {
824
- object = object.resolve;
825
- }
826
- // convert 1.2.n into just n
827
- if (/^[0-9]+\.[0-9]+\.[0-9]+$/.test(object)) {
828
- object = v.get_instance(reserved_spaces, object_type, object);
829
- }
830
- b.writeVarint32(v.to_number(object));
831
- return;
832
- },
833
- fromObject: function fromObject(object) {
834
- v.required(object);
835
- if (object.resolve !== undefined) {
836
- object = object.resolve;
837
- }
838
- if (v.is_digits(object)) {
839
- return v.to_number(object);
840
- }
841
- return v.get_instance(reserved_spaces, object_type, object);
842
- },
843
- toObject: function toObject(object) {
844
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
845
-
846
- var object_type_id = chain_types.object_type[object_type];
847
- if (debug.use_default && object === undefined) {
848
- return reserved_spaces + '.' + object_type_id + '.0';
849
- }
850
- v.required(object);
851
- if (object.resolve !== undefined) {
852
- object = object.resolve;
853
- }
854
- if (/^[0-9]+\.[0-9]+\.[0-9]+$/.test(object)) {
855
- object = v.get_instance(reserved_spaces, object_type, object);
856
- }
857
-
858
- return reserved_spaces + '.' + object_type_id + '.' + object;
859
- }
860
- };
861
- };
862
-
863
- Types.protocol_id_type = function (name) {
864
- v.required(name, "name");
865
- return id_type(chain_types.reserved_spaces.protocol_ids, name);
866
- };
867
-
868
- Types.object_id_type = {
869
- fromByteBuffer: function fromByteBuffer(b) {
870
- return ObjectId.fromByteBuffer(b);
871
- },
872
- appendByteBuffer: function appendByteBuffer(b, object) {
873
- v.required(object);
874
- if (object.resolve !== undefined) {
875
- object = object.resolve;
876
- }
877
- object = ObjectId.fromString(object);
878
- object.appendByteBuffer(b);
879
- return;
880
- },
881
- fromObject: function fromObject(object) {
882
- v.required(object);
883
- if (object.resolve !== undefined) {
884
- object = object.resolve;
885
- }
886
- return ObjectId.fromString(object);
887
- },
888
- toObject: function toObject(object) {
889
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
890
-
891
- if (debug.use_default && object === undefined) {
892
- return "0.0.0";
893
- }
894
- v.required(object);
895
- if (object.resolve !== undefined) {
896
- object = object.resolve;
897
- }
898
- object = ObjectId.fromString(object);
899
- return object.toString();
900
- }
901
- };
902
-
903
- Types.vote_id = { TYPE: 0x000000FF,
904
- ID: 0xFFFFFF00,
905
- fromByteBuffer: function fromByteBuffer(b) {
906
- var value = b.readUint32();
907
- return {
908
- type: value & this.TYPE,
909
- id: value & this.ID
910
- };
911
- },
912
- appendByteBuffer: function appendByteBuffer(b, object) {
913
- v.required(object);
914
- if (object === "string") object = Types.vote_id.fromObject(object);
915
-
916
- var value = object.id << 8 | object.type;
917
- b.writeUint32(value);
918
- return;
919
- },
920
- fromObject: function fromObject(object) {
921
- v.required(object, "(type vote_id)");
922
- if ((typeof object === 'undefined' ? 'undefined' : _typeof(object)) === "object") {
923
- v.required(object.type, "type");
924
- v.required(object.id, "id");
925
- return object;
926
- }
927
- v.require_test(/^[0-9]+:[0-9]+$/, object, 'vote_id format ' + object);
928
-
929
- var _object$split = object.split(':'),
930
- _object$split2 = _slicedToArray(_object$split, 2),
931
- type = _object$split2[0],
932
- id = _object$split2[1];
933
-
934
- v.require_range(0, 0xff, type, 'vote type ' + object);
935
- v.require_range(0, 0xffffff, id, 'vote id ' + object);
936
- return { type: type, id: id };
937
- },
938
- toObject: function toObject(object) {
939
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
940
-
941
- if (debug.use_default && object === undefined) {
942
- return "0:0";
943
- }
944
- v.required(object);
945
- if (typeof object === "string") object = Types.vote_id.fromObject(object);
946
-
947
- return object.type + ":" + object.id;
948
- },
949
- compare: function compare(a, b) {
950
- if ((typeof a === 'undefined' ? 'undefined' : _typeof(a)) !== "object") a = Types.vote_id.fromObject(a);
951
- if ((typeof b === 'undefined' ? 'undefined' : _typeof(b)) !== "object") b = Types.vote_id.fromObject(b);
952
- return parseInt(a.id) - parseInt(b.id);
953
- }
954
- };
955
-
956
- Types.optional = function (st_operation) {
957
- v.required(st_operation, "st_operation");
958
- return {
959
- fromByteBuffer: function fromByteBuffer(b) {
960
- if (!(b.readUint8() === 1)) {
961
- return undefined;
962
- }
963
- return st_operation.fromByteBuffer(b);
964
- },
965
- appendByteBuffer: function appendByteBuffer(b, object) {
966
- if (object !== null && object !== undefined) {
967
- b.writeUint8(1);
968
- st_operation.appendByteBuffer(b, object);
969
- } else {
970
- b.writeUint8(0);
971
- }
972
- return;
973
- },
974
- fromObject: function fromObject(object) {
975
- if (object === undefined) {
976
- return undefined;
977
- }
978
- return st_operation.fromObject(object);
979
- },
980
- toObject: function toObject(object) {
981
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
982
-
983
- // toObject is only null save if use_default is true
984
- var result_object = function () {
985
- if (!debug.use_default && object === undefined) {
986
- return undefined;
987
- } else {
988
- return st_operation.toObject(object, debug);
989
- }
990
- }();
991
-
992
- if (debug.annotate) {
993
- if ((typeof result_object === 'undefined' ? 'undefined' : _typeof(result_object)) === "object") {
994
- result_object.__optional = "parent is optional";
995
- } else {
996
- result_object = { __optional: result_object };
997
- }
998
- }
999
- return result_object;
1000
- }
1001
- };
1002
- };
1003
-
1004
- Types.static_variant = function (_st_operations) {
1005
- return {
1006
- nosort: true,
1007
- st_operations: _st_operations,
1008
- opTypeId: function opTypeId(value) {
1009
- var pos = 0,
1010
- type_id = void 0;
1011
- if (typeof value === "number") type_id = value;else {
1012
- var _iteratorNormalCompletion = true;
1013
- var _didIteratorError = false;
1014
- var _iteratorError = undefined;
1015
-
1016
- try {
1017
- for (var _iterator = this.st_operations[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
1018
- var op = _step.value;
1019
-
1020
- if (op.operation_name === value) {
1021
- type_id = pos;
1022
- break;
1023
- }
1024
- pos++;
1025
- }
1026
- } catch (err) {
1027
- _didIteratorError = true;
1028
- _iteratorError = err;
1029
- } finally {
1030
- try {
1031
- if (!_iteratorNormalCompletion && _iterator.return) {
1032
- _iterator.return();
1033
- }
1034
- } finally {
1035
- if (_didIteratorError) {
1036
- throw _iteratorError;
1037
- }
1038
- }
1039
- }
1040
- }
1041
- return type_id;
1042
- },
1043
- fromByteBuffer: function fromByteBuffer(b) {
1044
- var type_id = b.readVarint32();
1045
- var st_operation = this.st_operations[type_id];
1046
- if (HEX_DUMP) {
1047
- console.error('static_variant id 0x' + type_id.toString(16) + ' (' + type_id + ')');
1048
- }
1049
- v.required(st_operation, 'operation ' + type_id);
1050
- return [type_id, st_operation.fromByteBuffer(b)];
1051
- },
1052
- appendByteBuffer: function appendByteBuffer(b, object) {
1053
- v.required(object);
1054
- var type_id = this.opTypeId(object[0]);
1055
- var st_operation = this.st_operations[type_id];
1056
- v.required(st_operation, 'operation ' + type_id);
1057
- b.writeVarint32(type_id);
1058
- st_operation.appendByteBuffer(b, object[1]);
1059
- return;
1060
- },
1061
- fromObject: function fromObject(object) {
1062
- v.required(object);
1063
- var type_id = this.opTypeId(object[0]);
1064
- var st_operation = this.st_operations[type_id];
1065
- v.required(st_operation, 'operation ' + type_id);
1066
- return [type_id, st_operation.fromObject(object[1])];
1067
- },
1068
- toObject: function toObject(object) {
1069
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1070
-
1071
- if (debug.use_default && object === undefined) {
1072
- return [this.st_operations[0].operation_name, this.st_operations[0].toObject(undefined, debug)];
1073
- }
1074
- v.required(object);
1075
- var type_id = this.opTypeId(object[0]);
1076
- var st_operation = this.st_operations[type_id];
1077
- v.required(st_operation, 'operation ' + type_id);
1078
- return [st_operation.operation_name, st_operation.toObject(object[1], debug)];
1079
- },
1080
- compare: function compare(a, b) {
1081
- return strCmp(this.opTypeId(a[0]), this.opTypeId(b[0]));
1082
- }
1083
- };
1084
- };
1085
-
1086
- Types.map = function (key_st_operation, value_st_operation) {
1087
- return {
1088
- validate: function validate(array) {
1089
- if (!Array.isArray(array)) {
1090
- throw new Error("expecting array");
1091
- }
1092
- var dup_map = {};
1093
- for (var i = 0, o; i < array.length; i++) {
1094
- o = array[i];
1095
- var ref;
1096
- if (!(o.length === 2)) {
1097
- throw new Error("expecting two elements");
1098
- }
1099
- if (ref = _typeof(o[0]), ['number', 'string'].indexOf(ref) >= 0) {
1100
- if (dup_map[o[0]] !== undefined) {
1101
- throw new Error("duplicate (map)");
1102
- }
1103
- dup_map[o[0]] = true;
1104
- }
1105
- }
1106
- return sortOperation(array, key_st_operation);
1107
- },
1108
- fromByteBuffer: function fromByteBuffer(b) {
1109
- var result = [];
1110
- var end = b.readVarint32();
1111
- for (var i = 0; 0 < end ? i < end : i > end; 0 < end ? i++ : i++) {
1112
- result.push([key_st_operation.fromByteBuffer(b), value_st_operation.fromByteBuffer(b)]);
1113
- }
1114
- return this.validate(result);
1115
- },
1116
- appendByteBuffer: function appendByteBuffer(b, object) {
1117
- this.validate(object);
1118
- b.writeVarint32(object.length);
1119
- for (var i = 0, o; i < object.length; i++) {
1120
- o = object[i];
1121
- key_st_operation.appendByteBuffer(b, o[0]);
1122
- value_st_operation.appendByteBuffer(b, o[1]);
1123
- }
1124
- return;
1125
- },
1126
- fromObject: function fromObject(object) {
1127
- v.required(object);
1128
- var result = [];
1129
- for (var i = 0, o; i < object.length; i++) {
1130
- o = object[i];
1131
- result.push([key_st_operation.fromObject(o[0]), value_st_operation.fromObject(o[1])]);
1132
- }
1133
- return this.validate(result);
1134
- },
1135
- toObject: function toObject(object) {
1136
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1137
-
1138
- if (debug.use_default && object === undefined) {
1139
- return [[key_st_operation.toObject(undefined, debug), value_st_operation.toObject(undefined, debug)]];
1140
- }
1141
- v.required(object);
1142
- object = this.validate(object);
1143
- var result = [];
1144
- for (var i = 0, o; i < object.length; i++) {
1145
- o = object[i];
1146
- result.push([key_st_operation.toObject(o[0], debug), value_st_operation.toObject(o[1], debug)]);
1147
- }
1148
- return result;
1149
- }
1150
- };
1151
- };
1152
-
1153
- Types.public_key = {
1154
- toPublic: function toPublic(object) {
1155
- if (object.resolve !== undefined) {
1156
- object = object.resolve;
1157
- }
1158
- return object == null ? object : object.Q ? object : _ecc.PublicKey.fromStringOrThrow(object);
1159
- },
1160
- fromByteBuffer: function fromByteBuffer(b) {
1161
- return fp.public_key(b);
1162
- },
1163
- appendByteBuffer: function appendByteBuffer(b, object) {
1164
- v.required(object);
1165
- fp.public_key(b, Types.public_key.toPublic(object));
1166
- return;
1167
- },
1168
- fromObject: function fromObject(object) {
1169
- v.required(object);
1170
- if (object.Q) {
1171
- return object;
1172
- }
1173
- return Types.public_key.toPublic(object);
1174
- },
1175
- toObject: function toObject(object) {
1176
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1177
-
1178
- if (debug.use_default && object === undefined) {
1179
- return _ecc.ecc_config.get('address_prefix') + "859gxfnXyUriMgUeThh1fWv3oqcpLFyHa3TfFYC4PK2HqhToVM";
1180
- }
1181
- v.required(object);
1182
- return object.toString();
1183
- },
1184
- compare: function compare(a, b) {
1185
- // sort ascending
1186
- return 1 * strCmp(a.toString(), b.toString());
1187
- }
1188
- };
1189
-
1190
- Types.address = {
1191
- _to_address: function _to_address(object) {
1192
- v.required(object);
1193
- if (object.addy) {
1194
- return object;
1195
- }
1196
- return _ecc.Address.fromString(object);
1197
- },
1198
- fromByteBuffer: function fromByteBuffer(b) {
1199
- return new _ecc.Address(fp.ripemd160(b));
1200
- },
1201
- appendByteBuffer: function appendByteBuffer(b, object) {
1202
- fp.ripemd160(b, Types.address._to_address(object).toBuffer());
1203
- return;
1204
- },
1205
- fromObject: function fromObject(object) {
1206
- return Types.address._to_address(object);
1207
- },
1208
- toObject: function toObject(object) {
1209
- var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1210
-
1211
- if (debug.use_default && object === undefined) {
1212
- return _ecc.ecc_config.get('address_prefix') + "664KmHxSuQyDsfwo4WEJvWpzg1QKdg67S";
1213
- }
1214
- return Types.address._to_address(object).toString();
1215
- },
1216
- compare: function compare(a, b) {
1217
- // sort decending
1218
- return -1 * strCmp(a.toString(), b.toString());
1219
- }
1220
- };
1221
-
1222
- var strCmp = function strCmp(a, b) {
1223
- return a > b ? 1 : a < b ? -1 : 0;
1224
- };
1225
- var firstEl = function firstEl(el) {
1226
- return Array.isArray(el) ? el[0] : el;
1227
- };
1228
- var sortOperation = function sortOperation(array, st_operation) {
1229
- // console.log('operation.nosort', st_operation.nosort)
1230
- return st_operation.nosort ? array : st_operation.compare ? array.sort(function (a, b) {
1231
- return st_operation.compare(firstEl(a), firstEl(b));
1232
- }) : // custom compare operation
1233
- array.sort(function (a, b) {
1234
- return typeof firstEl(a) === "number" && typeof firstEl(b) === "number" ? firstEl(a) - firstEl(b) :
1235
- // A binary string compare does not work. Performanance is very good so HEX is used.. localeCompare is another option.
1236
- Buffer.isBuffer(firstEl(a)) && Buffer.isBuffer(firstEl(b)) ? strCmp(firstEl(a).toString("hex"), firstEl(b).toString("hex")) : strCmp(firstEl(a).toString(), firstEl(b).toString());
1237
- });
1238
- };