ripple-binary-codec 2.0.0-beta.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/dist/binary.d.ts +12 -13
  2. package/dist/binary.js +6 -5
  3. package/dist/binary.js.map +1 -1
  4. package/dist/enums/bytes.d.ts +1 -2
  5. package/dist/enums/bytes.js +1 -2
  6. package/dist/enums/bytes.js.map +1 -1
  7. package/dist/enums/definitions.json +36 -11
  8. package/dist/enums/field.d.ts +1 -2
  9. package/dist/enums/field.js +1 -2
  10. package/dist/enums/field.js.map +1 -1
  11. package/dist/enums/index.js +4 -24
  12. package/dist/enums/index.js.map +1 -1
  13. package/dist/enums/src/enums/definitions.json +36 -11
  14. package/dist/hash-prefixes.d.ts +1 -2
  15. package/dist/hash-prefixes.js +6 -6
  16. package/dist/hash-prefixes.js.map +1 -1
  17. package/dist/hashes.d.ts +5 -6
  18. package/dist/hashes.js +1 -2
  19. package/dist/hashes.js.map +1 -1
  20. package/dist/index.js +7 -14
  21. package/dist/index.js.map +1 -1
  22. package/dist/quality.d.ts +1 -2
  23. package/dist/quality.js +3 -3
  24. package/dist/quality.js.map +1 -1
  25. package/dist/serdes/binary-parser.d.ts +2 -3
  26. package/dist/serdes/binary-parser.js +2 -2
  27. package/dist/serdes/binary-parser.js.map +1 -1
  28. package/dist/serdes/binary-serializer.d.ts +6 -7
  29. package/dist/serdes/binary-serializer.js +9 -9
  30. package/dist/serdes/binary-serializer.js.map +1 -1
  31. package/dist/shamap.d.ts +4 -5
  32. package/dist/shamap.js +2 -3
  33. package/dist/shamap.js.map +1 -1
  34. package/dist/src/binary.d.ts +90 -0
  35. package/dist/src/binary.js +128 -0
  36. package/dist/src/binary.js.map +1 -0
  37. package/dist/src/coretypes.d.ts +9 -0
  38. package/dist/src/coretypes.js +48 -0
  39. package/dist/src/coretypes.js.map +1 -0
  40. package/dist/src/enums/bytes.d.ts +25 -0
  41. package/dist/src/enums/bytes.js +63 -0
  42. package/dist/src/enums/bytes.js.map +1 -0
  43. package/dist/src/enums/constants.d.ts +4 -0
  44. package/dist/src/enums/constants.js +8 -0
  45. package/dist/src/enums/constants.js.map +1 -0
  46. package/dist/src/enums/definitions.json +2866 -0
  47. package/dist/src/enums/field.d.ts +28 -0
  48. package/dist/src/enums/field.js +58 -0
  49. package/dist/src/enums/field.js.map +1 -0
  50. package/dist/src/enums/index.d.ts +12 -0
  51. package/dist/src/enums/index.js +31 -0
  52. package/dist/src/enums/index.js.map +1 -0
  53. package/dist/src/enums/utils-renumber.d.ts +101 -0
  54. package/dist/src/enums/utils-renumber.js +127 -0
  55. package/dist/src/enums/utils-renumber.js.map +1 -0
  56. package/dist/src/enums/xrpl-definitions-base.d.ts +44 -0
  57. package/dist/src/enums/xrpl-definitions-base.js +59 -0
  58. package/dist/src/enums/xrpl-definitions-base.js.map +1 -0
  59. package/dist/src/enums/xrpl-definitions.d.ts +21 -0
  60. package/dist/src/enums/xrpl-definitions.js +29 -0
  61. package/dist/src/enums/xrpl-definitions.js.map +1 -0
  62. package/dist/src/hash-prefixes.d.ts +5 -0
  63. package/dist/src/hash-prefixes.js +41 -0
  64. package/dist/src/hash-prefixes.js.map +1 -0
  65. package/dist/src/hashes.d.ts +50 -0
  66. package/dist/src/hashes.js +76 -0
  67. package/dist/src/hashes.js.map +1 -0
  68. package/dist/src/index.d.ts +64 -0
  69. package/dist/src/index.js +123 -0
  70. package/dist/src/index.js.map +1 -0
  71. package/dist/src/ledger-hashes.d.ts +48 -0
  72. package/dist/src/ledger-hashes.js +141 -0
  73. package/dist/src/ledger-hashes.js.map +1 -0
  74. package/dist/src/quality.d.ts +21 -0
  75. package/dist/src/quality.js +42 -0
  76. package/dist/src/quality.js.map +1 -0
  77. package/dist/src/serdes/binary-parser.d.ts +100 -0
  78. package/dist/src/serdes/binary-parser.js +194 -0
  79. package/dist/src/serdes/binary-parser.js.map +1 -0
  80. package/dist/src/serdes/binary-serializer.d.ts +81 -0
  81. package/dist/src/serdes/binary-serializer.js +149 -0
  82. package/dist/src/serdes/binary-serializer.js.map +1 -0
  83. package/dist/src/shamap.d.ts +102 -0
  84. package/dist/src/shamap.js +172 -0
  85. package/dist/src/shamap.js.map +1 -0
  86. package/dist/src/types/account-id.d.ts +35 -0
  87. package/dist/src/types/account-id.js +69 -0
  88. package/dist/src/types/account-id.js.map +1 -0
  89. package/dist/src/types/amount.d.ts +67 -0
  90. package/dist/src/types/amount.js +212 -0
  91. package/dist/src/types/amount.js.map +1 -0
  92. package/dist/src/types/blob.d.ts +24 -0
  93. package/dist/src/types/blob.js +40 -0
  94. package/dist/src/types/blob.js.map +1 -0
  95. package/dist/src/types/currency.d.ts +28 -0
  96. package/dist/src/types/currency.js +127 -0
  97. package/dist/src/types/currency.js.map +1 -0
  98. package/dist/src/types/hash-128.d.ts +16 -0
  99. package/dist/src/types/hash-128.js +32 -0
  100. package/dist/src/types/hash-128.js.map +1 -0
  101. package/dist/src/types/hash-160.d.ts +10 -0
  102. package/dist/src/types/hash-160.js +19 -0
  103. package/dist/src/types/hash-160.js.map +1 -0
  104. package/dist/src/types/hash-256.d.ts +10 -0
  105. package/dist/src/types/hash-256.js +16 -0
  106. package/dist/src/types/hash-256.js.map +1 -0
  107. package/dist/src/types/hash.d.ts +40 -0
  108. package/dist/src/types/hash.js +73 -0
  109. package/dist/src/types/hash.js.map +1 -0
  110. package/dist/src/types/index.d.ts +18 -0
  111. package/dist/src/types/index.js +61 -0
  112. package/dist/src/types/index.js.map +1 -0
  113. package/dist/src/types/issue.d.ts +38 -0
  114. package/dist/src/types/issue.js +81 -0
  115. package/dist/src/types/issue.js.map +1 -0
  116. package/dist/src/types/path-set.d.ts +36 -0
  117. package/dist/src/types/path-set.js +233 -0
  118. package/dist/src/types/path-set.js.map +1 -0
  119. package/dist/src/types/serialized-type.d.ts +70 -0
  120. package/dist/src/types/serialized-type.js +105 -0
  121. package/dist/src/types/serialized-type.js.map +1 -0
  122. package/dist/src/types/st-array.d.ts +31 -0
  123. package/dist/src/types/st-array.js +83 -0
  124. package/dist/src/types/st-array.js.map +1 -0
  125. package/dist/src/types/st-object.d.ts +32 -0
  126. package/dist/src/types/st-object.js +155 -0
  127. package/dist/src/types/st-object.js.map +1 -0
  128. package/dist/src/types/uint-16.d.ts +24 -0
  129. package/dist/src/types/uint-16.js +45 -0
  130. package/dist/src/types/uint-16.js.map +1 -0
  131. package/dist/src/types/uint-32.d.ts +24 -0
  132. package/dist/src/types/uint-32.js +50 -0
  133. package/dist/src/types/uint-32.js.map +1 -0
  134. package/dist/src/types/uint-64.d.ts +37 -0
  135. package/dist/src/types/uint-64.js +86 -0
  136. package/dist/src/types/uint-64.js.map +1 -0
  137. package/dist/src/types/uint-8.d.ts +24 -0
  138. package/dist/src/types/uint-8.js +46 -0
  139. package/dist/src/types/uint-8.js.map +1 -0
  140. package/dist/src/types/uint.d.ts +29 -0
  141. package/dist/src/types/uint.js +47 -0
  142. package/dist/src/types/uint.js.map +1 -0
  143. package/dist/src/types/vector-256.d.ts +30 -0
  144. package/dist/src/types/vector-256.js +73 -0
  145. package/dist/src/types/vector-256.js.map +1 -0
  146. package/dist/src/types/xchain-bridge.d.ts +44 -0
  147. package/dist/src/types/xchain-bridge.js +102 -0
  148. package/dist/src/types/xchain-bridge.js.map +1 -0
  149. package/dist/src/utils.d.ts +47 -0
  150. package/dist/src/utils.js +137 -0
  151. package/dist/src/utils.js.map +1 -0
  152. package/dist/tsconfig.tsbuildinfo +1 -0
  153. package/dist/types/account-id.d.ts +1 -2
  154. package/dist/types/account-id.js +4 -6
  155. package/dist/types/account-id.js.map +1 -1
  156. package/dist/types/amount.d.ts +1 -2
  157. package/dist/types/amount.js +16 -15
  158. package/dist/types/amount.js.map +1 -1
  159. package/dist/types/blob.d.ts +1 -2
  160. package/dist/types/blob.js +2 -2
  161. package/dist/types/blob.js.map +1 -1
  162. package/dist/types/currency.d.ts +1 -2
  163. package/dist/types/currency.js +10 -10
  164. package/dist/types/currency.js.map +1 -1
  165. package/dist/types/hash-128.d.ts +1 -2
  166. package/dist/types/hash-128.js +3 -3
  167. package/dist/types/hash-128.js.map +1 -1
  168. package/dist/types/hash-160.d.ts +1 -2
  169. package/dist/types/hash-160.js +1 -2
  170. package/dist/types/hash-160.js.map +1 -1
  171. package/dist/types/hash-256.d.ts +1 -2
  172. package/dist/types/hash-256.js +1 -2
  173. package/dist/types/hash-256.js.map +1 -1
  174. package/dist/types/hash.d.ts +2 -3
  175. package/dist/types/hash.js +5 -4
  176. package/dist/types/hash.js.map +1 -1
  177. package/dist/types/issue.d.ts +1 -2
  178. package/dist/types/issue.js +4 -4
  179. package/dist/types/issue.js.map +1 -1
  180. package/dist/types/path-set.js +12 -12
  181. package/dist/types/path-set.js.map +1 -1
  182. package/dist/types/serialized-type.d.ts +17 -13
  183. package/dist/types/serialized-type.js +11 -6
  184. package/dist/types/serialized-type.js.map +1 -1
  185. package/dist/types/st-array.js +5 -5
  186. package/dist/types/st-array.js.map +1 -1
  187. package/dist/types/st-object.js +1 -2
  188. package/dist/types/st-object.js.map +1 -1
  189. package/dist/types/uint-16.d.ts +1 -2
  190. package/dist/types/uint-16.js +6 -5
  191. package/dist/types/uint-16.js.map +1 -1
  192. package/dist/types/uint-32.d.ts +1 -2
  193. package/dist/types/uint-32.js +7 -6
  194. package/dist/types/uint-32.js.map +1 -1
  195. package/dist/types/uint-64.d.ts +2 -3
  196. package/dist/types/uint-64.js +16 -15
  197. package/dist/types/uint-64.js.map +1 -1
  198. package/dist/types/uint-8.d.ts +1 -2
  199. package/dist/types/uint-8.js +7 -5
  200. package/dist/types/uint-8.js.map +1 -1
  201. package/dist/types/uint.d.ts +4 -4
  202. package/dist/types/uint.js +5 -0
  203. package/dist/types/uint.js.map +1 -1
  204. package/dist/types/vector-256.d.ts +1 -2
  205. package/dist/types/vector-256.js +2 -4
  206. package/dist/types/vector-256.js.map +1 -1
  207. package/dist/types/xchain-bridge.d.ts +1 -2
  208. package/dist/types/xchain-bridge.js +20 -20
  209. package/dist/types/xchain-bridge.js.map +1 -1
  210. package/dist/utils.d.ts +47 -0
  211. package/dist/utils.js +137 -0
  212. package/dist/utils.js.map +1 -0
  213. package/package.json +8 -11
  214. package/src/README.md +3 -1
  215. package/src/binary.ts +21 -14
  216. package/src/enums/bytes.ts +2 -3
  217. package/src/enums/definitions.json +36 -11
  218. package/src/enums/field.ts +3 -4
  219. package/src/enums/index.ts +1 -1
  220. package/src/hash-prefixes.ts +8 -8
  221. package/src/hashes.ts +6 -7
  222. package/src/index.ts +12 -15
  223. package/src/quality.ts +4 -4
  224. package/src/serdes/binary-parser.ts +5 -5
  225. package/src/serdes/binary-serializer.ts +14 -14
  226. package/src/shamap.ts +5 -6
  227. package/src/types/account-id.ts +8 -8
  228. package/src/types/amount.ts +17 -18
  229. package/src/types/blob.ts +3 -3
  230. package/src/types/currency.ts +16 -16
  231. package/src/types/hash-128.ts +4 -4
  232. package/src/types/hash-160.ts +2 -3
  233. package/src/types/hash-256.ts +2 -3
  234. package/src/types/hash.ts +8 -6
  235. package/src/types/issue.ts +5 -5
  236. package/src/types/path-set.ts +16 -16
  237. package/src/types/serialized-type.ts +20 -15
  238. package/src/types/st-array.ts +7 -7
  239. package/src/types/st-object.ts +2 -2
  240. package/src/types/uint-16.ts +10 -6
  241. package/src/types/uint-32.ts +10 -7
  242. package/src/types/uint-64.ts +20 -17
  243. package/src/types/uint-8.ts +9 -6
  244. package/src/types/uint.ts +11 -4
  245. package/src/types/vector-256.ts +3 -8
  246. package/src/types/xchain-bridge.ts +22 -22
  247. package/src/utils.ts +152 -0
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.STObject = void 0;
4
+ const enums_1 = require("../enums");
5
+ const serialized_type_1 = require("./serialized-type");
6
+ const ripple_address_codec_1 = require("ripple-address-codec");
7
+ const binary_parser_1 = require("../serdes/binary-parser");
8
+ const binary_serializer_1 = require("../serdes/binary-serializer");
9
+ const st_array_1 = require("./st-array");
10
+ const OBJECT_END_MARKER_BYTE = Uint8Array.from([0xe1]);
11
+ const OBJECT_END_MARKER = 'ObjectEndMarker';
12
+ const ST_OBJECT = 'STObject';
13
+ const DESTINATION = 'Destination';
14
+ const ACCOUNT = 'Account';
15
+ const SOURCE_TAG = 'SourceTag';
16
+ const DEST_TAG = 'DestinationTag';
17
+ /**
18
+ * Break down an X-Address into an account and a tag
19
+ *
20
+ * @param field Name of field
21
+ * @param xAddress X-Address corresponding to the field
22
+ */
23
+ function handleXAddress(field, xAddress) {
24
+ const decoded = (0, ripple_address_codec_1.xAddressToClassicAddress)(xAddress);
25
+ let tagName;
26
+ if (field === DESTINATION)
27
+ tagName = DEST_TAG;
28
+ else if (field === ACCOUNT)
29
+ tagName = SOURCE_TAG;
30
+ else if (decoded.tag !== false)
31
+ throw new Error(`${field} cannot have an associated tag`);
32
+ return decoded.tag !== false
33
+ ? { [field]: decoded.classicAddress, [tagName]: decoded.tag }
34
+ : { [field]: decoded.classicAddress };
35
+ }
36
+ /**
37
+ * Validate that two objects don't both have the same tag fields
38
+ *
39
+ * @param obj1 First object to check for tags
40
+ * @param obj2 Second object to check for tags
41
+ * @throws When both objects have SourceTag or DestinationTag
42
+ */
43
+ function checkForDuplicateTags(obj1, obj2) {
44
+ if (!(obj1[SOURCE_TAG] === undefined || obj2[SOURCE_TAG] === undefined))
45
+ throw new Error('Cannot have Account X-Address and SourceTag');
46
+ if (!(obj1[DEST_TAG] === undefined || obj2[DEST_TAG] === undefined))
47
+ throw new Error('Cannot have Destination X-Address and DestinationTag');
48
+ }
49
+ /**
50
+ * Class for Serializing/Deserializing objects
51
+ */
52
+ class STObject extends serialized_type_1.SerializedType {
53
+ /**
54
+ * Construct a STObject from a BinaryParser
55
+ *
56
+ * @param parser BinaryParser to read STObject from
57
+ * @returns A STObject object
58
+ */
59
+ static fromParser(parser) {
60
+ const list = new binary_serializer_1.BytesList();
61
+ const bytes = new binary_serializer_1.BinarySerializer(list);
62
+ while (!parser.end()) {
63
+ const field = parser.readField();
64
+ if (field.name === OBJECT_END_MARKER) {
65
+ break;
66
+ }
67
+ const associatedValue = parser.readFieldValue(field);
68
+ bytes.writeFieldAndValue(field, associatedValue);
69
+ if (field.type.name === ST_OBJECT) {
70
+ bytes.put(OBJECT_END_MARKER_BYTE);
71
+ }
72
+ }
73
+ return new STObject(list.toBytes());
74
+ }
75
+ /**
76
+ * Construct a STObject from a JSON object
77
+ *
78
+ * @param value An object to include
79
+ * @param filter optional, denote which field to include in serialized object
80
+ * @param definitions optional, types and values to use to encode/decode a transaction
81
+ * @returns a STObject object
82
+ */
83
+ static from(value, filter, definitions = enums_1.DEFAULT_DEFINITIONS) {
84
+ if (value instanceof STObject) {
85
+ return value;
86
+ }
87
+ const list = new binary_serializer_1.BytesList();
88
+ const bytes = new binary_serializer_1.BinarySerializer(list);
89
+ let isUnlModify = false;
90
+ const xAddressDecoded = Object.entries(value).reduce((acc, [key, val]) => {
91
+ let handled = undefined;
92
+ if (val && (0, ripple_address_codec_1.isValidXAddress)(val.toString())) {
93
+ handled = handleXAddress(key, val.toString());
94
+ checkForDuplicateTags(handled, value);
95
+ }
96
+ return Object.assign(acc, handled !== null && handled !== void 0 ? handled : { [key]: val });
97
+ }, {});
98
+ let sorted = Object.keys(xAddressDecoded)
99
+ .map((f) => definitions.field[f])
100
+ .filter((f) => f !== undefined &&
101
+ xAddressDecoded[f.name] !== undefined &&
102
+ f.isSerialized)
103
+ .sort((a, b) => {
104
+ return a.ordinal - b.ordinal;
105
+ });
106
+ if (filter !== undefined) {
107
+ sorted = sorted.filter(filter);
108
+ }
109
+ sorted.forEach((field) => {
110
+ const associatedValue = field.type.name === ST_OBJECT
111
+ ? this.from(xAddressDecoded[field.name], undefined, definitions)
112
+ : field.type.name === 'STArray'
113
+ ? st_array_1.STArray.from(xAddressDecoded[field.name], definitions)
114
+ : field.associatedType.from(xAddressDecoded[field.name]);
115
+ if (associatedValue == undefined) {
116
+ throw new TypeError(`Unable to interpret "${field.name}: ${xAddressDecoded[field.name]}".`);
117
+ }
118
+ if (associatedValue.name === 'UNLModify') {
119
+ // triggered when the TransactionType field has a value of 'UNLModify'
120
+ isUnlModify = true;
121
+ }
122
+ // true when in the UNLModify pseudotransaction (after the transaction type has been processed) and working with the
123
+ // Account field
124
+ // The Account field must not be a part of the UNLModify pseudotransaction encoding, due to a bug in rippled
125
+ const isUnlModifyWorkaround = field.name == 'Account' && isUnlModify;
126
+ bytes.writeFieldAndValue(field, associatedValue, isUnlModifyWorkaround);
127
+ if (field.type.name === ST_OBJECT) {
128
+ bytes.put(OBJECT_END_MARKER_BYTE);
129
+ }
130
+ });
131
+ return new STObject(list.toBytes());
132
+ }
133
+ /**
134
+ * Get the JSON interpretation of this.bytes
135
+ * @param definitions rippled definitions used to parse the values of transaction types and such.
136
+ * Can be customized for sidechains and amendments.
137
+ * @returns a JSON object
138
+ */
139
+ toJSON(definitions) {
140
+ const objectParser = new binary_parser_1.BinaryParser(this.toString(), definitions);
141
+ const accumulator = {};
142
+ while (!objectParser.end()) {
143
+ const field = objectParser.readField();
144
+ if (field.name === OBJECT_END_MARKER) {
145
+ break;
146
+ }
147
+ accumulator[field.name] = objectParser
148
+ .readFieldValue(field)
149
+ .toJSON(definitions);
150
+ }
151
+ return accumulator;
152
+ }
153
+ }
154
+ exports.STObject = STObject;
155
+ //# sourceMappingURL=st-object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"st-object.js","sourceRoot":"","sources":["../../../src/types/st-object.ts"],"names":[],"mappings":";;;AAAA,oCAKiB;AACjB,uDAA8D;AAC9D,+DAAgF;AAChF,2DAAsD;AACtD,mEAAyE;AAEzE,yCAAoC;AAEpC,MAAM,sBAAsB,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;AACtD,MAAM,iBAAiB,GAAG,iBAAiB,CAAA;AAC3C,MAAM,SAAS,GAAG,UAAU,CAAA;AAC5B,MAAM,WAAW,GAAG,aAA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ED,OAAO,WAAW,CAAA;IACpB,CAAC;CACF;AAEQ,4BAAQ"}
@@ -0,0 +1,24 @@
1
+ import { UInt } from './uint';
2
+ import { BinaryParser } from '../serdes/binary-parser';
3
+ /**
4
+ * Derived UInt class for serializing/deserializing 16 bit UInt
5
+ */
6
+ declare class UInt16 extends UInt {
7
+ protected static readonly width: number;
8
+ static readonly defaultUInt16: UInt16;
9
+ constructor(bytes: Uint8Array);
10
+ static fromParser(parser: BinaryParser): UInt;
11
+ /**
12
+ * Construct a UInt16 object from a number
13
+ *
14
+ * @param val UInt16 object or number
15
+ */
16
+ static from<T extends UInt16 | number>(val: T): UInt16;
17
+ /**
18
+ * get the value of a UInt16 object
19
+ *
20
+ * @returns the number represented by this.bytes
21
+ */
22
+ valueOf(): number;
23
+ }
24
+ export { UInt16 };
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UInt16 = void 0;
4
+ const uint_1 = require("./uint");
5
+ const utils_1 = require("../utils");
6
+ /**
7
+ * Derived UInt class for serializing/deserializing 16 bit UInt
8
+ */
9
+ class UInt16 extends uint_1.UInt {
10
+ constructor(bytes) {
11
+ super(bytes !== null && bytes !== void 0 ? bytes : UInt16.defaultUInt16.bytes);
12
+ }
13
+ static fromParser(parser) {
14
+ return new UInt16(parser.read(UInt16.width));
15
+ }
16
+ /**
17
+ * Construct a UInt16 object from a number
18
+ *
19
+ * @param val UInt16 object or number
20
+ */
21
+ static from(val) {
22
+ if (val instanceof UInt16) {
23
+ return val;
24
+ }
25
+ if (typeof val === 'number') {
26
+ UInt16.checkUintRange(val, 0, 0xffff);
27
+ const buf = new Uint8Array(UInt16.width);
28
+ (0, utils_1.writeUInt16BE)(buf, val, 0);
29
+ return new UInt16(buf);
30
+ }
31
+ throw new Error('Can not construct UInt16 with given value');
32
+ }
33
+ /**
34
+ * get the value of a UInt16 object
35
+ *
36
+ * @returns the number represented by this.bytes
37
+ */
38
+ valueOf() {
39
+ return parseInt((0, utils_1.readUInt16BE)(this.bytes, 0));
40
+ }
41
+ }
42
+ exports.UInt16 = UInt16;
43
+ UInt16.width = 16 / 8; // 2
44
+ UInt16.defaultUInt16 = new UInt16(new Uint8Array(UInt16.width));
45
+ //# sourceMappingURL=uint-16.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uint-16.js","sourceRoot":"","sources":["../../../src/types/uint-16.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAE7B,oCAAsD;AAEtD;;GAEG;AACH,MAAM,MAAO,SAAQ,WAAI;IAMvB,YAAY,KAAiB;QAC3B,KAAK,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;IAC5C,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,MAAoB;QACpC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IAC9C,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAA4B,GAAM;QAC3C,IAAI,GAAG,YAAY,MAAM,EAAE;YACzB,OAAO,GAAG,CAAA;SACX;QAED,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAC3B,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC,EAAE,MAAM,CAAC,CAAA;YAErC,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YACxC,IAAA,qBAAa,EAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAA;YAC1B,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,CAAA;SACvB;QAED,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAA;IAC9D,CAAC;IAED;;;;OAIG;IACH,OAAO;QACL,OAAO,QAAQ,CAAC,IAAA,oBAAY,EAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAA;IAC9C,CAAC;;AAGM,wBAAM;AA5Ca,YAAK,GAAW,EAAE,GAAG,CAAC,CAAA,CAAC,IAAI;AACrC,oBAAa,GAAW,IAAI,MAAM,CAChD,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAC7B,CAAA"}
@@ -0,0 +1,24 @@
1
+ import { UInt } from './uint';
2
+ import { BinaryParser } from '../serdes/binary-parser';
3
+ /**
4
+ * Derived UInt class for serializing/deserializing 32 bit UInt
5
+ */
6
+ declare class UInt32 extends UInt {
7
+ protected static readonly width: number;
8
+ static readonly defaultUInt32: UInt32;
9
+ constructor(bytes: Uint8Array);
10
+ static fromParser(parser: BinaryParser): UInt;
11
+ /**
12
+ * Construct a UInt32 object from a number
13
+ *
14
+ * @param val UInt32 object or number
15
+ */
16
+ static from<T extends UInt32 | number | string>(val: T): UInt32;
17
+ /**
18
+ * get the value of a UInt32 object
19
+ *
20
+ * @returns the number represented by this.bytes
21
+ */
22
+ valueOf(): number;
23
+ }
24
+ export { UInt32 };
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UInt32 = void 0;
4
+ const uint_1 = require("./uint");
5
+ const utils_1 = require("../utils");
6
+ /**
7
+ * Derived UInt class for serializing/deserializing 32 bit UInt
8
+ */
9
+ class UInt32 extends uint_1.UInt {
10
+ constructor(bytes) {
11
+ super(bytes !== null && bytes !== void 0 ? bytes : UInt32.defaultUInt32.bytes);
12
+ }
13
+ static fromParser(parser) {
14
+ return new UInt32(parser.read(UInt32.width));
15
+ }
16
+ /**
17
+ * Construct a UInt32 object from a number
18
+ *
19
+ * @param val UInt32 object or number
20
+ */
21
+ static from(val) {
22
+ if (val instanceof UInt32) {
23
+ return val;
24
+ }
25
+ const buf = new Uint8Array(UInt32.width);
26
+ if (typeof val === 'string') {
27
+ const num = Number.parseInt(val);
28
+ (0, utils_1.writeUInt32BE)(buf, num, 0);
29
+ return new UInt32(buf);
30
+ }
31
+ if (typeof val === 'number') {
32
+ UInt32.checkUintRange(val, 0, 0xffffffff);
33
+ (0, utils_1.writeUInt32BE)(buf, val, 0);
34
+ return new UInt32(buf);
35
+ }
36
+ throw new Error('Cannot construct UInt32 from given value');
37
+ }
38
+ /**
39
+ * get the value of a UInt32 object
40
+ *
41
+ * @returns the number represented by this.bytes
42
+ */
43
+ valueOf() {
44
+ return parseInt((0, utils_1.readUInt32BE)(this.bytes, 0), 10);
45
+ }
46
+ }
47
+ exports.UInt32 = UInt32;
48
+ UInt32.width = 32 / 8; // 4
49
+ UInt32.defaultUInt32 = new UInt32(new Uint8Array(UInt32.width));
50
+ //# sourceMappingURL=uint-32.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uint-32.js","sourceRoot":"","sources":["../../../src/types/uint-32.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAE7B,oCAAsD;AAEtD;;GAEG;AACH,MAAM,MAAO,SAAQ,WAAI;IAMvB,YAAY,KAAiB;QAC3B,KAAK,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;IAC5C,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,MAAoB;QACpC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IAC9C,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAqC,GAAM;QACpD,IAAI,GAAG,YAAY,MAAM,EAAE;YACzB,OAAO,GAAG,CAAA;SACX;QAED,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAExC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAC3B,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;YAChC,IAAA,qBAAa,EAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAA;YAC1B,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,CAAA;SACvB;QAED,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAC3B,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC,EAAE,UAAU,CAAC,CAAA;YACzC,IAAA,qBAAa,EAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAA;YAC1B,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,CAAA;SACvB;QAED,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAA;IAC7D,CAAC;IAED;;;;OAIG;IACH,OAAO;QACL,OAAO,QAAQ,CAAC,IAAA,oBAAY,EAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;IAClD,CAAC;;AAGM,wBAAM;AAlDa,YAAK,GAAW,EAAE,GAAG,CAAC,CAAA,CAAC,IAAI;AACrC,oBAAa,GAAW,IAAI,MAAM,CAChD,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAC7B,CAAA"}
@@ -0,0 +1,37 @@
1
+ import { UInt } from './uint';
2
+ import { BinaryParser } from '../serdes/binary-parser';
3
+ /**
4
+ * Derived UInt class for serializing/deserializing 64 bit UInt
5
+ */
6
+ declare class UInt64 extends UInt {
7
+ protected static readonly width: number;
8
+ static readonly defaultUInt64: UInt64;
9
+ constructor(bytes: Uint8Array);
10
+ static fromParser(parser: BinaryParser): UInt;
11
+ /**
12
+ * Construct a UInt64 object
13
+ *
14
+ * @param val A UInt64, hex-string, bigInt, or number
15
+ * @returns A UInt64 object
16
+ */
17
+ static from<T extends UInt64 | string | bigint | number>(val: T): UInt64;
18
+ /**
19
+ * The JSON representation of a UInt64 object
20
+ *
21
+ * @returns a hex-string
22
+ */
23
+ toJSON(): string;
24
+ /**
25
+ * Get the value of the UInt64
26
+ *
27
+ * @returns the number represented buy this.bytes
28
+ */
29
+ valueOf(): bigint;
30
+ /**
31
+ * Get the bytes representation of the UInt64 object
32
+ *
33
+ * @returns 8 bytes representing the UInt64
34
+ */
35
+ toBytes(): Uint8Array;
36
+ }
37
+ export { UInt64 };
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UInt64 = void 0;
4
+ const uint_1 = require("./uint");
5
+ const utils_1 = require("@xrplf/isomorphic/utils");
6
+ const utils_2 = require("../utils");
7
+ const HEX_REGEX = /^[a-fA-F0-9]{1,16}$/;
8
+ const mask = BigInt(0x00000000ffffffff);
9
+ /**
10
+ * Derived UInt class for serializing/deserializing 64 bit UInt
11
+ */
12
+ class UInt64 extends uint_1.UInt {
13
+ constructor(bytes) {
14
+ super(bytes !== null && bytes !== void 0 ? bytes : UInt64.defaultUInt64.bytes);
15
+ }
16
+ static fromParser(parser) {
17
+ return new UInt64(parser.read(UInt64.width));
18
+ }
19
+ /**
20
+ * Construct a UInt64 object
21
+ *
22
+ * @param val A UInt64, hex-string, bigInt, or number
23
+ * @returns A UInt64 object
24
+ */
25
+ static from(val) {
26
+ if (val instanceof UInt64) {
27
+ return val;
28
+ }
29
+ let buf = new Uint8Array(UInt64.width);
30
+ if (typeof val === 'number') {
31
+ if (val < 0) {
32
+ throw new Error('value must be an unsigned integer');
33
+ }
34
+ const number = BigInt(val);
35
+ const intBuf = [new Uint8Array(4), new Uint8Array(4)];
36
+ (0, utils_2.writeUInt32BE)(intBuf[0], Number(number >> BigInt(32)), 0);
37
+ (0, utils_2.writeUInt32BE)(intBuf[1], Number(number & BigInt(mask)), 0);
38
+ return new UInt64((0, utils_1.concat)(intBuf));
39
+ }
40
+ if (typeof val === 'string') {
41
+ if (!HEX_REGEX.test(val)) {
42
+ throw new Error(`${val} is not a valid hex-string`);
43
+ }
44
+ const strBuf = val.padStart(16, '0');
45
+ buf = (0, utils_1.hexToBytes)(strBuf);
46
+ return new UInt64(buf);
47
+ }
48
+ if (typeof val === 'bigint') {
49
+ const intBuf = [new Uint8Array(4), new Uint8Array(4)];
50
+ (0, utils_2.writeUInt32BE)(intBuf[0], Number(Number(val >> BigInt(32))), 0);
51
+ (0, utils_2.writeUInt32BE)(intBuf[1], Number(val & BigInt(mask)), 0);
52
+ return new UInt64((0, utils_1.concat)(intBuf));
53
+ }
54
+ throw new Error('Cannot construct UInt64 from given value');
55
+ }
56
+ /**
57
+ * The JSON representation of a UInt64 object
58
+ *
59
+ * @returns a hex-string
60
+ */
61
+ toJSON() {
62
+ return (0, utils_1.bytesToHex)(this.bytes);
63
+ }
64
+ /**
65
+ * Get the value of the UInt64
66
+ *
67
+ * @returns the number represented buy this.bytes
68
+ */
69
+ valueOf() {
70
+ const msb = BigInt((0, utils_2.readUInt32BE)(this.bytes.slice(0, 4), 0));
71
+ const lsb = BigInt((0, utils_2.readUInt32BE)(this.bytes.slice(4), 0));
72
+ return (msb << BigInt(32)) | lsb;
73
+ }
74
+ /**
75
+ * Get the bytes representation of the UInt64 object
76
+ *
77
+ * @returns 8 bytes representing the UInt64
78
+ */
79
+ toBytes() {
80
+ return this.bytes;
81
+ }
82
+ }
83
+ exports.UInt64 = UInt64;
84
+ UInt64.width = 64 / 8; // 8
85
+ UInt64.defaultUInt64 = new UInt64(new Uint8Array(UInt64.width));
86
+ //# sourceMappingURL=uint-64.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uint-64.js","sourceRoot":"","sources":["../../../src/types/uint-64.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAE7B,mDAAwE;AACxE,oCAAsD;AAEtD,MAAM,SAAS,GAAG,qBAAqB,CAAA;AACvC,MAAM,IAAI,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAA;AAEvC;;GAEG;AACH,MAAM,MAAO,SAAQ,WAAI;IAMvB,YAAY,KAAiB;QAC3B,KAAK,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;IAC5C,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,MAAoB;QACpC,OAAO,IAAI,M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AAE,GAAG,CAAC,CAAA,CAAC,IAAI;AACrC,oBAAa,GAAW,IAAI,MAAM,CAChD,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAC7B,CAAA"}
@@ -0,0 +1,24 @@
1
+ import { UInt } from './uint';
2
+ import { BinaryParser } from '../serdes/binary-parser';
3
+ /**
4
+ * Derived UInt class for serializing/deserializing 8 bit UInt
5
+ */
6
+ declare class UInt8 extends UInt {
7
+ protected static readonly width: number;
8
+ static readonly defaultUInt8: UInt8;
9
+ constructor(bytes: Uint8Array);
10
+ static fromParser(parser: BinaryParser): UInt;
11
+ /**
12
+ * Construct a UInt8 object from a number
13
+ *
14
+ * @param val UInt8 object or number
15
+ */
16
+ static from<T extends UInt8 | number>(val: T): UInt8;
17
+ /**
18
+ * get the value of a UInt8 object
19
+ *
20
+ * @returns the number represented by this.bytes
21
+ */
22
+ valueOf(): number;
23
+ }
24
+ export { UInt8 };
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UInt8 = void 0;
4
+ const uint_1 = require("./uint");
5
+ const utils_1 = require("@xrplf/isomorphic/utils");
6
+ const utils_2 = require("../utils");
7
+ /**
8
+ * Derived UInt class for serializing/deserializing 8 bit UInt
9
+ */
10
+ class UInt8 extends uint_1.UInt {
11
+ constructor(bytes) {
12
+ super(bytes !== null && bytes !== void 0 ? bytes : UInt8.defaultUInt8.bytes);
13
+ }
14
+ static fromParser(parser) {
15
+ return new UInt8(parser.read(UInt8.width));
16
+ }
17
+ /**
18
+ * Construct a UInt8 object from a number
19
+ *
20
+ * @param val UInt8 object or number
21
+ */
22
+ static from(val) {
23
+ if (val instanceof UInt8) {
24
+ return val;
25
+ }
26
+ if (typeof val === 'number') {
27
+ UInt8.checkUintRange(val, 0, 0xff);
28
+ const buf = new Uint8Array(UInt8.width);
29
+ (0, utils_2.writeUInt8)(buf, val, 0);
30
+ return new UInt8(buf);
31
+ }
32
+ throw new Error('Cannot construct UInt8 from given value');
33
+ }
34
+ /**
35
+ * get the value of a UInt8 object
36
+ *
37
+ * @returns the number represented by this.bytes
38
+ */
39
+ valueOf() {
40
+ return parseInt((0, utils_1.bytesToHex)(this.bytes), 16);
41
+ }
42
+ }
43
+ exports.UInt8 = UInt8;
44
+ UInt8.width = 8 / 8; // 1
45
+ UInt8.defaultUInt8 = new UInt8(new Uint8Array(UInt8.width));
46
+ //# sourceMappingURL=uint-8.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uint-8.js","sourceRoot":"","sources":["../../../src/types/uint-8.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAE7B,mDAAoD;AACpD,oCAAqC;AAErC;;GAEG;AACH,MAAM,KAAM,SAAQ,WAAI;IAItB,YAAY,KAAiB;QAC3B,KAAK,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;IAC1C,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,MAAoB;QACpC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;IAC5C,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAA2B,GAAM;QAC1C,IAAI,GAAG,YAAY,KAAK,EAAE;YACxB,OAAO,GAAG,CAAA;SACX;QAED,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAC3B,KAAK,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,CAAA;YAElC,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YACvC,IAAA,kBAAU,EAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAA;YACvB,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,CAAA;SACtB;QAED,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAA;IAC5D,CAAC;IAED;;;;OAIG;IACH,OAAO;QACL,OAAO,QAAQ,CAAC,IAAA,kBAAU,EAAC,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAA;IAC7C,CAAC;;AAGM,sBAAK;AA1Cc,WAAK,GAAW,CAAC,GAAG,CAAC,CAAA,CAAC,IAAI;AACpC,kBAAY,GAAU,IAAI,KAAK,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA"}
@@ -0,0 +1,29 @@
1
+ import { Comparable } from './serialized-type';
2
+ /**
3
+ * Base class for serializing and deserializing unsigned integers.
4
+ */
5
+ declare abstract class UInt extends Comparable<UInt | number> {
6
+ protected static width: number;
7
+ constructor(bytes: Uint8Array);
8
+ /**
9
+ * Overload of compareTo for Comparable
10
+ *
11
+ * @param other other UInt to compare this to
12
+ * @returns -1, 0, or 1 depending on how the objects relate to each other
13
+ */
14
+ compareTo(other: UInt | number): number;
15
+ /**
16
+ * Convert a UInt object to JSON
17
+ *
18
+ * @returns number or string represented by this.bytes
19
+ */
20
+ toJSON(): number | string;
21
+ /**
22
+ * Get the value of the UInt represented by this.bytes
23
+ *
24
+ * @returns the value
25
+ */
26
+ abstract valueOf(): number | bigint;
27
+ static checkUintRange(val: number, min: number, max: number): void;
28
+ }
29
+ export { UInt };
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UInt = void 0;
4
+ const serialized_type_1 = require("./serialized-type");
5
+ /**
6
+ * Compare numbers and bigInts n1 and n2
7
+ *
8
+ * @param n1 First object to compare
9
+ * @param n2 Second object to compare
10
+ * @returns -1, 0, or 1, depending on how the two objects compare
11
+ */
12
+ function compare(n1, n2) {
13
+ return n1 < n2 ? -1 : n1 == n2 ? 0 : 1;
14
+ }
15
+ /**
16
+ * Base class for serializing and deserializing unsigned integers.
17
+ */
18
+ class UInt extends serialized_type_1.Comparable {
19
+ constructor(bytes) {
20
+ super(bytes);
21
+ }
22
+ /**
23
+ * Overload of compareTo for Comparable
24
+ *
25
+ * @param other other UInt to compare this to
26
+ * @returns -1, 0, or 1 depending on how the objects relate to each other
27
+ */
28
+ compareTo(other) {
29
+ return compare(this.valueOf(), other.valueOf());
30
+ }
31
+ /**
32
+ * Convert a UInt object to JSON
33
+ *
34
+ * @returns number or string represented by this.bytes
35
+ */
36
+ toJSON() {
37
+ const val = this.valueOf();
38
+ return typeof val === 'number' ? val : val.toString();
39
+ }
40
+ static checkUintRange(val, min, max) {
41
+ if (val < min || val > max) {
42
+ throw new Error(`Invalid ${this.constructor.name}: ${val} must be >= ${min} and <= ${max}`);
43
+ }
44
+ }
45
+ }
46
+ exports.UInt = UInt;
47
+ //# sourceMappingURL=uint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uint.js","sourceRoot":"","sources":["../../../src/types/uint.ts"],"names":[],"mappings":";;;AAAA,uDAA8C;AAE9C;;;;;;GAMG;AACH,SAAS,OAAO,CAAC,EAAmB,EAAE,EAAmB;IACvD,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AACxC,CAAC;AAED;;GAEG;AACH,MAAe,IAAK,SAAQ,4BAAyB;IAGnD,YAAY,KAAiB;QAC3B,KAAK,CAAC,KAAK,CAAC,CAAA;IACd,CAAC;IAED;;;;;OAKG;IACH,SAAS,CAAC,KAAoB;QAC5B,OAAO,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;IACjD,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,EAAE,CAAA;QAC1B,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAA;IACvD,CAAC;IASD,MAAM,CAAC,cAAc,CAAC,GAAW,EAAE,GAAW,EAAE,GAAW;QACzD,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,EAAE;YAC1B,MAAM,IAAI,KAAK,CACb,WAAW,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,GAAG,eAAe,GAAG,WAAW,GAAG,EAAE,CAC3E,CAAA;SACF;IACH,CAAC;CACF;AAEQ,oBAAI"}
@@ -0,0 +1,30 @@
1
+ import { SerializedType } from './serialized-type';
2
+ import { BinaryParser } from '../serdes/binary-parser';
3
+ /**
4
+ * Class for serializing and deserializing vectors of Hash256
5
+ */
6
+ declare class Vector256 extends SerializedType {
7
+ constructor(bytes: Uint8Array);
8
+ /**
9
+ * Construct a Vector256 from a BinaryParser
10
+ *
11
+ * @param parser BinaryParser to
12
+ * @param hint length of the vector, in bytes, optional
13
+ * @returns a Vector256 object
14
+ */
15
+ static fromParser(parser: BinaryParser, hint?: number): Vector256;
16
+ /**
17
+ * Construct a Vector256 object from an array of hashes
18
+ *
19
+ * @param value A Vector256 object or array of hex-strings representing Hash256's
20
+ * @returns a Vector256 object
21
+ */
22
+ static from<T extends Vector256 | Array<string>>(value: T): Vector256;
23
+ /**
24
+ * Return an Array of hex-strings represented by this.bytes
25
+ *
26
+ * @returns An Array of strings representing the Hash256 objects
27
+ */
28
+ toJSON(): Array<string>;
29
+ }
30
+ export { Vector256 };