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