@burnt-labs/xion-types 21.0.0-alpha.2 → 21.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/binary.js ADDED
@@ -0,0 +1,562 @@
1
+ /* eslint-disable */ /**
2
+ * This file and any referenced files were automatically generated by @hyperweb/telescope@2.0.1
3
+ * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain
4
+ * and run the transpile command or npm scripts command that is used to regenerate this bundle.
5
+ */ // Copyright (c) 2016, Daniel Wirtz All rights reserved.
6
+ // Redistribution and use in source and binary forms, with or without
7
+ // modification, are permitted provided that the following conditions are
8
+ // met:
9
+ // * Redistributions of source code must retain the above copyright
10
+ // notice, this list of conditions and the following disclaimer.
11
+ // * Redistributions in binary form must reproduce the above copyright
12
+ // notice, this list of conditions and the following disclaimer in the
13
+ // documentation and/or other materials provided with the distribution.
14
+ // * Neither the name of its author, nor the names of its contributors
15
+ // may be used to endorse or promote products derived from this software
16
+ // without specific prior written permission.
17
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ // ---
29
+ // Code generated by the command line utilities is owned by the owner
30
+ // of the input file used when generating it. This code is not
31
+ // standalone and requires a support library to be linked with it. This
32
+ // support library is itself covered by the above license.
33
+ function _array_like_to_array(arr, len) {
34
+ if (len == null || len > arr.length) len = arr.length;
35
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
36
+ return arr2;
37
+ }
38
+ function _array_with_holes(arr) {
39
+ if (Array.isArray(arr)) return arr;
40
+ }
41
+ function _class_call_check(instance, Constructor) {
42
+ if (!(instance instanceof Constructor)) {
43
+ throw new TypeError("Cannot call a class as a function");
44
+ }
45
+ }
46
+ function _defineProperties(target, props) {
47
+ for(var i = 0; i < props.length; i++){
48
+ var descriptor = props[i];
49
+ descriptor.enumerable = descriptor.enumerable || false;
50
+ descriptor.configurable = true;
51
+ if ("value" in descriptor) descriptor.writable = true;
52
+ Object.defineProperty(target, descriptor.key, descriptor);
53
+ }
54
+ }
55
+ function _create_class(Constructor, protoProps, staticProps) {
56
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
57
+ if (staticProps) _defineProperties(Constructor, staticProps);
58
+ return Constructor;
59
+ }
60
+ function _define_property(obj, key, value) {
61
+ if (key in obj) {
62
+ Object.defineProperty(obj, key, {
63
+ value: value,
64
+ enumerable: true,
65
+ configurable: true,
66
+ writable: true
67
+ });
68
+ } else {
69
+ obj[key] = value;
70
+ }
71
+ return obj;
72
+ }
73
+ function _iterable_to_array_limit(arr, i) {
74
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
75
+ if (_i == null) return;
76
+ var _arr = [];
77
+ var _n = true;
78
+ var _d = false;
79
+ var _s, _e;
80
+ try {
81
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
82
+ _arr.push(_s.value);
83
+ if (i && _arr.length === i) break;
84
+ }
85
+ } catch (err) {
86
+ _d = true;
87
+ _e = err;
88
+ } finally{
89
+ try {
90
+ if (!_n && _i["return"] != null) _i["return"]();
91
+ } finally{
92
+ if (_d) throw _e;
93
+ }
94
+ }
95
+ return _arr;
96
+ }
97
+ function _non_iterable_rest() {
98
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
99
+ }
100
+ function _sliced_to_array(arr, i) {
101
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
102
+ }
103
+ function _unsupported_iterable_to_array(o, minLen) {
104
+ if (!o) return;
105
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
106
+ var n = Object.prototype.toString.call(o).slice(8, -1);
107
+ if (n === "Object" && o.constructor) n = o.constructor.name;
108
+ if (n === "Map" || n === "Set") return Array.from(n);
109
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
110
+ }
111
+ import { utf8Length, utf8Read, utf8Write } from "./utf8";
112
+ import { int64ToString, readInt32, readUInt32, uInt64ToString, varint32read, varint64read, writeVarint32, writeVarint64, int64FromString, int64Length, writeFixed32, writeByte, zzDecode, zzEncode } from "./varint";
113
+ export var WireType = /*#__PURE__*/ function(WireType) {
114
+ WireType[WireType["Varint"] = 0] = "Varint";
115
+ WireType[WireType["Fixed64"] = 1] = "Fixed64";
116
+ WireType[WireType["Bytes"] = 2] = "Bytes";
117
+ WireType[WireType["Fixed32"] = 5] = "Fixed32";
118
+ return WireType;
119
+ }({});
120
+ export var BinaryReader = /*#__PURE__*/ function() {
121
+ "use strict";
122
+ function BinaryReader(buf) {
123
+ _class_call_check(this, BinaryReader);
124
+ _define_property(this, "buf", void 0);
125
+ _define_property(this, "pos", void 0);
126
+ _define_property(this, "type", void 0);
127
+ _define_property(this, "len", void 0);
128
+ this.buf = buf ? new Uint8Array(buf) : new Uint8Array(0);
129
+ this.pos = 0;
130
+ this.type = 0;
131
+ this.len = this.buf.length;
132
+ }
133
+ _create_class(BinaryReader, [
134
+ {
135
+ key: "assertBounds",
136
+ value: function assertBounds() {
137
+ if (this.pos > this.len) throw new RangeError("premature EOF");
138
+ }
139
+ },
140
+ {
141
+ key: "tag",
142
+ value: function tag() {
143
+ var tag = this.uint32(), fieldNo = tag >>> 3, wireType = tag & 7;
144
+ if (fieldNo <= 0 || wireType < 0 || wireType > 5) throw new Error("illegal tag: field no " + fieldNo + " wire type " + wireType);
145
+ return [
146
+ fieldNo,
147
+ wireType,
148
+ tag
149
+ ];
150
+ }
151
+ },
152
+ {
153
+ key: "skip",
154
+ value: function skip(length) {
155
+ if (typeof length === "number") {
156
+ if (this.pos + length > this.len) throw indexOutOfRange(this, length);
157
+ this.pos += length;
158
+ } else {
159
+ do {
160
+ if (this.pos >= this.len) throw indexOutOfRange(this);
161
+ }while (this.buf[this.pos++] & 128);
162
+ }
163
+ return this;
164
+ }
165
+ },
166
+ {
167
+ key: "skipType",
168
+ value: function skipType(wireType) {
169
+ switch(wireType){
170
+ case 0:
171
+ this.skip();
172
+ break;
173
+ case 1:
174
+ this.skip(8);
175
+ break;
176
+ case 2:
177
+ this.skip(this.uint32());
178
+ break;
179
+ case 3:
180
+ while((wireType = this.uint32() & 7) !== 4){
181
+ this.skipType(wireType);
182
+ }
183
+ break;
184
+ case 5:
185
+ this.skip(4);
186
+ break;
187
+ /* istanbul ignore next */ default:
188
+ throw Error("invalid wire type " + wireType + " at offset " + this.pos);
189
+ }
190
+ return this;
191
+ }
192
+ },
193
+ {
194
+ key: "uint32",
195
+ value: function uint32() {
196
+ return varint32read.bind(this)();
197
+ }
198
+ },
199
+ {
200
+ key: "int32",
201
+ value: function int32() {
202
+ return this.uint32() | 0;
203
+ }
204
+ },
205
+ {
206
+ key: "sint32",
207
+ value: function sint32() {
208
+ var num = this.uint32();
209
+ return num % 2 === 1 ? (num + 1) / -2 : num / 2; // zigzag encoding
210
+ }
211
+ },
212
+ {
213
+ key: "fixed32",
214
+ value: function fixed32() {
215
+ var val = readUInt32(this.buf, this.pos);
216
+ this.pos += 4;
217
+ return val;
218
+ }
219
+ },
220
+ {
221
+ key: "sfixed32",
222
+ value: function sfixed32() {
223
+ var val = readInt32(this.buf, this.pos);
224
+ this.pos += 4;
225
+ return val;
226
+ }
227
+ },
228
+ {
229
+ key: "int64",
230
+ value: function int64() {
231
+ var _varint64read_bind = _sliced_to_array(varint64read.bind(this)(), 2), lo = _varint64read_bind[0], hi = _varint64read_bind[1];
232
+ return BigInt(int64ToString(lo, hi));
233
+ }
234
+ },
235
+ {
236
+ key: "uint64",
237
+ value: function uint64() {
238
+ var _varint64read_bind = _sliced_to_array(varint64read.bind(this)(), 2), lo = _varint64read_bind[0], hi = _varint64read_bind[1];
239
+ return BigInt(uInt64ToString(lo, hi));
240
+ }
241
+ },
242
+ {
243
+ key: "sint64",
244
+ value: function sint64() {
245
+ var _varint64read_bind = _sliced_to_array(varint64read.bind(this)(), 2), lo = _varint64read_bind[0], hi = _varint64read_bind[1];
246
+ var ref;
247
+ // zig zag
248
+ ref = _sliced_to_array(zzDecode(lo, hi), 2), lo = ref[0], hi = ref[1], ref;
249
+ return BigInt(int64ToString(lo, hi));
250
+ }
251
+ },
252
+ {
253
+ key: "fixed64",
254
+ value: function fixed64() {
255
+ var lo = this.sfixed32();
256
+ var hi = this.sfixed32();
257
+ return BigInt(uInt64ToString(lo, hi));
258
+ }
259
+ },
260
+ {
261
+ key: "sfixed64",
262
+ value: function sfixed64() {
263
+ var lo = this.sfixed32();
264
+ var hi = this.sfixed32();
265
+ return BigInt(int64ToString(lo, hi));
266
+ }
267
+ },
268
+ {
269
+ key: "float",
270
+ value: function float() {
271
+ throw new Error("float not supported");
272
+ }
273
+ },
274
+ {
275
+ key: "double",
276
+ value: function double() {
277
+ throw new Error("double not supported");
278
+ }
279
+ },
280
+ {
281
+ key: "bool",
282
+ value: function bool() {
283
+ var _varint64read_bind = _sliced_to_array(varint64read.bind(this)(), 2), lo = _varint64read_bind[0], hi = _varint64read_bind[1];
284
+ return lo !== 0 || hi !== 0;
285
+ }
286
+ },
287
+ {
288
+ key: "bytes",
289
+ value: function bytes() {
290
+ var len = this.uint32(), start = this.pos;
291
+ this.pos += len;
292
+ this.assertBounds();
293
+ return this.buf.subarray(start, start + len);
294
+ }
295
+ },
296
+ {
297
+ key: "string",
298
+ value: function string() {
299
+ var bytes = this.bytes();
300
+ return utf8Read(bytes, 0, bytes.length);
301
+ }
302
+ }
303
+ ]);
304
+ return BinaryReader;
305
+ }();
306
+ var Op = /*#__PURE__*/ function() {
307
+ "use strict";
308
+ function Op(fn, len, val) {
309
+ _class_call_check(this, Op);
310
+ _define_property(this, "fn", void 0);
311
+ _define_property(this, "len", void 0);
312
+ _define_property(this, "val", void 0);
313
+ _define_property(this, "next", void 0);
314
+ this.fn = fn;
315
+ this.len = len;
316
+ this.val = val;
317
+ }
318
+ _create_class(Op, [
319
+ {
320
+ key: "proceed",
321
+ value: function proceed(buf, pos) {
322
+ if (this.fn) {
323
+ this.fn(this.val, buf, pos);
324
+ }
325
+ }
326
+ }
327
+ ]);
328
+ return Op;
329
+ }();
330
+ var State = function State(writer) {
331
+ "use strict";
332
+ _class_call_check(this, State);
333
+ _define_property(this, "head", void 0);
334
+ _define_property(this, "tail", void 0);
335
+ _define_property(this, "len", void 0);
336
+ _define_property(this, "next", void 0);
337
+ this.head = writer.head;
338
+ this.tail = writer.tail;
339
+ this.len = writer.len;
340
+ this.next = writer.states;
341
+ };
342
+ export var BinaryWriter = /*#__PURE__*/ function() {
343
+ "use strict";
344
+ function BinaryWriter() {
345
+ _class_call_check(this, BinaryWriter);
346
+ _define_property(this, "len", 0);
347
+ _define_property(this, "head", void 0);
348
+ _define_property(this, "tail", void 0);
349
+ _define_property(this, "states", void 0);
350
+ // uint64 is the same with int64
351
+ _define_property(this, "uint64", BinaryWriter.prototype.int64);
352
+ // sfixed64 is the same with fixed64
353
+ _define_property(this, "sfixed64", BinaryWriter.prototype.fixed64);
354
+ // sfixed32 is the same with fixed32
355
+ _define_property(this, "sfixed32", BinaryWriter.prototype.fixed32);
356
+ this.head = new Op(null, 0, 0);
357
+ this.tail = this.head;
358
+ this.states = null;
359
+ }
360
+ _create_class(BinaryWriter, [
361
+ {
362
+ key: "_push",
363
+ value: function _push(fn, len, val) {
364
+ this.tail = this.tail.next = new Op(fn, len, val);
365
+ this.len += len;
366
+ return this;
367
+ }
368
+ },
369
+ {
370
+ key: "finish",
371
+ value: function finish() {
372
+ var head = this.head.next, pos = 0;
373
+ var buf = BinaryWriter.alloc(this.len);
374
+ while(head){
375
+ head.proceed(buf, pos);
376
+ pos += head.len;
377
+ head = head.next;
378
+ }
379
+ return buf;
380
+ }
381
+ },
382
+ {
383
+ key: "fork",
384
+ value: function fork() {
385
+ this.states = new State(this);
386
+ this.head = this.tail = new Op(null, 0, 0);
387
+ this.len = 0;
388
+ return this;
389
+ }
390
+ },
391
+ {
392
+ key: "reset",
393
+ value: function reset() {
394
+ if (this.states) {
395
+ this.head = this.states.head;
396
+ this.tail = this.states.tail;
397
+ this.len = this.states.len;
398
+ this.states = this.states.next;
399
+ } else {
400
+ this.head = this.tail = new Op(null, 0, 0);
401
+ this.len = 0;
402
+ }
403
+ return this;
404
+ }
405
+ },
406
+ {
407
+ key: "ldelim",
408
+ value: function ldelim() {
409
+ var head = this.head, tail = this.tail, len = this.len;
410
+ this.reset().uint32(len);
411
+ if (len) {
412
+ this.tail.next = head.next; // skip noop
413
+ this.tail = tail;
414
+ this.len += len;
415
+ }
416
+ return this;
417
+ }
418
+ },
419
+ {
420
+ key: "tag",
421
+ value: function tag(fieldNo, type) {
422
+ return this.uint32((fieldNo << 3 | type) >>> 0);
423
+ }
424
+ },
425
+ {
426
+ key: "uint32",
427
+ value: function uint32(value) {
428
+ this.len += (this.tail = this.tail.next = new Op(writeVarint32, (value = value >>> 0) < 128 ? 1 : value < 16384 ? 2 : value < 2097152 ? 3 : value < 268435456 ? 4 : 5, value)).len;
429
+ return this;
430
+ }
431
+ },
432
+ {
433
+ key: "int32",
434
+ value: function int32(value) {
435
+ return value < 0 ? this._push(writeVarint64, 10, int64FromString(value.toString())) // 10 bytes per spec
436
+ : this.uint32(value);
437
+ }
438
+ },
439
+ {
440
+ key: "sint32",
441
+ value: function sint32(value) {
442
+ return this.uint32((value << 1 ^ value >> 31) >>> 0);
443
+ }
444
+ },
445
+ {
446
+ key: "int64",
447
+ value: function int64(value) {
448
+ var _int64FromString = int64FromString(value.toString()), lo = _int64FromString.lo, hi = _int64FromString.hi;
449
+ return this._push(writeVarint64, int64Length(lo, hi), {
450
+ lo: lo,
451
+ hi: hi
452
+ });
453
+ }
454
+ },
455
+ {
456
+ key: "sint64",
457
+ value: function sint64(value) {
458
+ var _int64FromString = int64FromString(value.toString()), lo = _int64FromString.lo, hi = _int64FromString.hi;
459
+ var ref;
460
+ // zig zag
461
+ ref = _sliced_to_array(zzEncode(lo, hi), 2), lo = ref[0], hi = ref[1], ref;
462
+ return this._push(writeVarint64, int64Length(lo, hi), {
463
+ lo: lo,
464
+ hi: hi
465
+ });
466
+ }
467
+ },
468
+ {
469
+ key: "fixed64",
470
+ value: function fixed64(value) {
471
+ var _int64FromString = int64FromString(value.toString()), lo = _int64FromString.lo, hi = _int64FromString.hi;
472
+ return this._push(writeFixed32, 4, lo)._push(writeFixed32, 4, hi);
473
+ }
474
+ },
475
+ {
476
+ key: "bool",
477
+ value: function bool(value) {
478
+ return this._push(writeByte, 1, value ? 1 : 0);
479
+ }
480
+ },
481
+ {
482
+ key: "fixed32",
483
+ value: function fixed32(value) {
484
+ return this._push(writeFixed32, 4, value >>> 0);
485
+ }
486
+ },
487
+ {
488
+ key: "float",
489
+ value: function float(value) {
490
+ throw new Error("float not supported" + value);
491
+ }
492
+ },
493
+ {
494
+ key: "double",
495
+ value: function double(value) {
496
+ throw new Error("double not supported" + value);
497
+ }
498
+ },
499
+ {
500
+ key: "bytes",
501
+ value: function bytes(value) {
502
+ var len = value.length >>> 0;
503
+ if (!len) return this._push(writeByte, 1, 0);
504
+ return this.uint32(len)._push(writeBytes, len, value);
505
+ }
506
+ },
507
+ {
508
+ key: "string",
509
+ value: function string(value) {
510
+ var len = utf8Length(value);
511
+ return len ? this.uint32(len)._push(utf8Write, len, value) : this._push(writeByte, 1, 0);
512
+ }
513
+ }
514
+ ], [
515
+ {
516
+ key: "create",
517
+ value: function create() {
518
+ return new BinaryWriter();
519
+ }
520
+ },
521
+ {
522
+ key: "alloc",
523
+ value: function alloc(size) {
524
+ if (typeof Uint8Array !== "undefined") {
525
+ return pool(function(size) {
526
+ return new Uint8Array(size);
527
+ }, Uint8Array.prototype.subarray)(size);
528
+ } else {
529
+ return new Array(size);
530
+ }
531
+ }
532
+ }
533
+ ]);
534
+ return BinaryWriter;
535
+ }();
536
+ function writeBytes(val, buf, pos) {
537
+ if (typeof Uint8Array !== "undefined") {
538
+ buf.set(val, pos);
539
+ } else {
540
+ for(var i = 0; i < val.length; ++i)buf[pos + i] = val[i];
541
+ }
542
+ }
543
+ function pool(alloc, slice, size) {
544
+ var SIZE = size || 8192;
545
+ var MAX = SIZE >>> 1;
546
+ var slab = null;
547
+ var offset = SIZE;
548
+ return function pool_alloc(size) {
549
+ if (size < 1 || size > MAX) return alloc(size);
550
+ if (offset + size > SIZE) {
551
+ slab = alloc(SIZE);
552
+ offset = 0;
553
+ }
554
+ var buf = slice.call(slab, offset, offset += size);
555
+ if (offset & 7) // align to 32 bit
556
+ offset = (offset | 7) + 1;
557
+ return buf;
558
+ };
559
+ }
560
+ function indexOutOfRange(reader, writeLength) {
561
+ return RangeError("index out of range: " + reader.pos + " + " + (writeLength || 1) + " > " + reader.len);
562
+ }