@aioha/tx-digest 1.0.1 → 1.0.2

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.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license bytebuffer.js (c) 2015 Daniel Wirtz <dcode@dcode.io>
3
- * Backing buffer: ArrayBuffer, Accessor: DataView
3
+ * Backing buffer: ArrayBuffer
4
4
  * Released under the Apache License, Version 2.0
5
5
  * see: https://github.com/dcodeIO/bytebuffer.js for details
6
6
  * modified by @xmcl/bytebuffer
@@ -158,29 +158,6 @@ export class ByteBuffer {
158
158
  this.noAssert = noAssert
159
159
  }
160
160
 
161
- /**
162
- * Gets the accessor type.
163
- * @returns {Function} `Buffer` under node.js, `Uint8Array` respectively `DataView` in the browser (classes)
164
- * @expose
165
- */
166
- static accessor = function () {
167
- return DataView
168
- }
169
-
170
- /**
171
- * Allocates a new ByteBuffer backed by a buffer of the specified capacity.
172
- * @param {number=} capacity Initial capacity. Defaults to {@link ByteBuffer.DEFAULT_CAPACITY}.
173
- * @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to
174
- * {@link ByteBuffer.DEFAULT_ENDIAN}.
175
- * @param {boolean=} noAssert Whether to skip assertions of offsets and values. Defaults to
176
- * {@link ByteBuffer.DEFAULT_NOASSERT}.
177
- * @returns {!ByteBuffer}
178
- * @expose
179
- */
180
- static allocate = function (capacity, littleEndian, noAssert) {
181
- return new ByteBuffer(capacity, littleEndian, noAssert)
182
- }
183
-
184
161
  /**
185
162
  * Gets the backing buffer type.
186
163
  * @returns {Function} `Buffer` under node.js, `ArrayBuffer` in the browser (classes)
@@ -513,64 +490,6 @@ export class ByteBuffer {
513
490
 
514
491
  // types/ints/int32
515
492
 
516
- /**
517
- * Writes a 32bit signed integer.
518
- * @param {number} value Value to write
519
- * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.
520
- * @expose
521
- */
522
- writeInt32(value, offset) {
523
- const relative = typeof offset === 'undefined'
524
-
525
- if (relative) {
526
- offset = this.offset
527
- }
528
-
529
- if (!this.noAssert) {
530
- if (typeof value !== 'number' || value % 1 !== 0) {
531
- throw TypeError('Illegal value: ' + value + ' (not an integer)')
532
- }
533
-
534
- value |= 0
535
-
536
- if (typeof offset !== 'number' || offset % 1 !== 0) {
537
- throw TypeError('Illegal offset: ' + offset + ' (not an integer)')
538
- }
539
-
540
- offset >>>= 0
541
-
542
- if (offset < 0 || offset + 0 > this.buffer.byteLength) {
543
- throw RangeError('Illegal offset: 0 <= ' + offset + ' (+0) <= ' + this.buffer.byteLength)
544
- }
545
- }
546
-
547
- offset += 4
548
-
549
- let capacity4 = this.buffer.byteLength
550
-
551
- if (offset > capacity4) {
552
- this.resize((capacity4 *= 2) > offset ? capacity4 : offset)
553
- }
554
-
555
- offset -= 4
556
-
557
- this.view.setInt32(offset, value, this.littleEndian)
558
-
559
- if (relative) {
560
- this.offset += 4
561
- }
562
-
563
- return this
564
- }
565
-
566
- /**
567
- * Writes a 32bit signed integer. This is an alias of {@link ByteBuffer#writeInt32}.
568
- * @param {number} value Value to write
569
- * @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.
570
- * @expose
571
- */
572
- writeInt = this.writeInt32
573
-
574
493
  /**
575
494
  * Writes a 32bit unsigned integer.
576
495
  * @param {number} value Value to write
@@ -739,22 +658,6 @@ export class ByteBuffer {
739
658
  return bb
740
659
  }
741
660
 
742
- /**
743
- * Makes sure that this ByteBuffer is backed by a {@link ByteBuffer#buffer} of at least the specified capacity. If the
744
- * current capacity is exceeded, it will be doubled. If double the current capacity is less than the required capacity,
745
- * the required capacity will be used instead.
746
- * @param {number} capacity Required capacity
747
- * @returns {!ByteBuffer} this
748
- * @expose
749
- */
750
- ensureCapacity(capacity) {
751
- let current = this.buffer.byteLength
752
- if (current < capacity) {
753
- return this.resize((current *= 2) > capacity ? current : capacity)
754
- }
755
- return this
756
- }
757
-
758
661
  /**
759
662
  * Makes this ByteBuffer ready for a new sequence of write or relative read operations. Sets `limit = offset` and
760
663
  * `offset = 0`. Make sure always to flip a ByteBuffer when all relative read or write operations are complete.
@@ -767,30 +670,6 @@ export class ByteBuffer {
767
670
  return this
768
671
  }
769
672
 
770
- /**
771
- * Switches (to) little endian byte order.
772
- * @param {boolean=} littleEndian Defaults to `true`, otherwise uses big endian
773
- * @returns {!ByteBuffer} this
774
- * @expose
775
- */
776
- LE(littleEndian) {
777
- this.littleEndian = typeof littleEndian !== 'undefined' ? !!littleEndian : true
778
-
779
- return this
780
- }
781
-
782
- /**
783
- * Switches (to) big endian byte order.
784
- * @param {boolean=} bigEndian Defaults to `true`, otherwise uses little endian
785
- * @returns {!ByteBuffer} this
786
- * @expose
787
- */
788
- BE(bigEndian) {
789
- this.littleEndian = typeof bigEndian !== 'undefined' ? !bigEndian : false
790
-
791
- return this
792
- }
793
-
794
673
  /**
795
674
  * Resizes this ByteBuffer to be backed by a buffer of at least the given capacity. Will do nothing if already that
796
675
  * large or larger.
@@ -1143,105 +1022,7 @@ export class ByteBuffer {
1143
1022
  }
1144
1023
  return offset - start
1145
1024
  }
1146
-
1147
- readUTF8String(length, metrics, offset) {
1148
- if (typeof metrics === 'number') {
1149
- offset = metrics
1150
- metrics = undefined
1151
- }
1152
- const relative = typeof offset === 'undefined'
1153
- if (relative) offset = this.offset
1154
- if (typeof metrics === 'undefined') metrics = ByteBuffer.METRICS_CHARS
1155
- if (!this.noAssert) {
1156
- if (typeof length !== 'number' || length % 1 !== 0) {
1157
- throw TypeError('Illegal length: ' + length + ' (not an integer)')
1158
- }
1159
- length |= 0
1160
- if (typeof offset !== 'number' || offset % 1 !== 0) {
1161
- throw TypeError('Illegal offset: ' + offset + ' (not an integer)')
1162
- }
1163
- offset >>>= 0
1164
- if (offset < 0 || offset + 0 > this.buffer.byteLength) {
1165
- throw RangeError('Illegal offset: 0 <= ' + offset + ' (+' + 0 + ') <= ' + this.buffer.byteLength)
1166
- }
1167
- }
1168
- let i = 0
1169
- const start = offset
1170
- let sd
1171
- if (metrics === ByteBuffer.METRICS_CHARS) {
1172
- // The same for node and the browser
1173
- sd = stringDestination()
1174
- utfx.decodeUTF8(
1175
- function () {
1176
- return i < length && offset < this.limit ? this.view.getUint8(offset++) : null
1177
- }.bind(this),
1178
- function (cp) {
1179
- ++i
1180
- utfx.UTF8toUTF16(cp, sd)
1181
- }
1182
- )
1183
- if (i !== length) {
1184
- throw RangeError('Illegal range: Truncated data, ' + i + ' == ' + length)
1185
- }
1186
- if (relative) {
1187
- this.offset = offset
1188
- return sd()
1189
- } else {
1190
- return {
1191
- string: sd(),
1192
- length: offset - start
1193
- }
1194
- }
1195
- } else if (metrics === ByteBuffer.METRICS_BYTES) {
1196
- if (!this.noAssert) {
1197
- if (typeof offset !== 'number' || offset % 1 !== 0) {
1198
- throw TypeError('Illegal offset: ' + offset + ' (not an integer)')
1199
- }
1200
- offset >>>= 0
1201
- if (offset < 0 || offset + length > this.buffer.byteLength) {
1202
- throw RangeError('Illegal offset: 0 <= ' + offset + ' (+' + length + ') <= ' + this.buffer.byteLength)
1203
- }
1204
- }
1205
- const k = offset + length
1206
- utfx.decodeUTF8toUTF16(
1207
- function () {
1208
- return offset < k ? this.view.getUint8(offset++) : null
1209
- }.bind(this),
1210
- (sd = stringDestination()),
1211
- this.noAssert
1212
- )
1213
- if (offset !== k) {
1214
- throw RangeError('Illegal range: Truncated data, ' + offset + ' == ' + k)
1215
- }
1216
- if (relative) {
1217
- this.offset = offset
1218
- return sd()
1219
- } else {
1220
- return {
1221
- string: sd(),
1222
- length: offset - start
1223
- }
1224
- }
1225
- } else {
1226
- throw TypeError('Unsupported metrics: ' + metrics)
1227
- }
1228
- }
1229
- }
1230
- function stringDestination() {
1231
- const cs = []
1232
- const ps = []
1233
- return function () {
1234
- if (arguments.length === 0) {
1235
- return ps.join('') + stringFromCharCode.apply(String, cs)
1236
- }
1237
- if (cs.length + arguments.length > 1024) {
1238
- ps.push(stringFromCharCode.apply(String, cs))
1239
- cs.length = 0
1240
- }
1241
- Array.prototype.push.apply(cs, arguments)
1242
- }
1243
1025
  }
1244
- const stringFromCharCode = String.fromCharCode
1245
1026
 
1246
1027
  function stringSource(s) {
1247
1028
  let i = 0
@@ -9,17 +9,17 @@ const StringSerializer = (buffer, data) => {
9
9
  buffer.writeVString(data)
10
10
  }
11
11
 
12
- const Int8Serializer = (buffer, data) => {
13
- buffer.writeInt8(data)
14
- }
12
+ // const Int8Serializer = (buffer, data) => {
13
+ // buffer.writeInt8(data)
14
+ // }
15
15
 
16
16
  const Int16Serializer = (buffer, data) => {
17
17
  buffer.writeInt16(data)
18
18
  }
19
19
 
20
- const Int32Serializer = (buffer, data) => {
21
- buffer.writeInt32(data)
22
- }
20
+ // const Int32Serializer = (buffer, data) => {
21
+ // buffer.writeInt32(data)
22
+ // }
23
23
 
24
24
  const Int64Serializer = (buffer, data) => {
25
25
  buffer.writeInt64(data)
@@ -614,9 +614,9 @@ export const Serializer = {
614
614
  Date: DateSerializer,
615
615
  FlatMap: FlatMapSerializer,
616
616
  Int16: Int16Serializer,
617
- Int32: Int32Serializer,
617
+ // Int32: Int32Serializer,
618
618
  Int64: Int64Serializer,
619
- Int8: Int8Serializer,
619
+ // Int8: Int8Serializer,
620
620
  Memo: EncryptedMemoSerializer,
621
621
  Object: ObjectSerializer,
622
622
  Operation: OperationSerializer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aioha/tx-digest",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Hive transaction serializer and digest",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",