ripple-binary-codec 1.0.2 → 1.0.3-mpt-beta

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 (333) hide show
  1. package/README.md +3 -3
  2. package/dist/binary.d.ts +34 -20
  3. package/dist/binary.js +51 -34
  4. package/dist/binary.js.map +1 -1
  5. package/dist/coretypes.d.ts +9 -9
  6. package/dist/coretypes.js +33 -9
  7. package/dist/coretypes.js.map +1 -1
  8. package/dist/enums/bytes.d.ts +25 -0
  9. package/dist/enums/bytes.js +63 -0
  10. package/dist/enums/bytes.js.map +1 -0
  11. package/dist/enums/constants.d.ts +4 -0
  12. package/dist/enums/constants.js +8 -0
  13. package/dist/enums/constants.js.map +1 -0
  14. package/dist/enums/definitions.json +3066 -1760
  15. package/dist/enums/field.d.ts +28 -0
  16. package/dist/enums/field.js +58 -0
  17. package/dist/enums/field.js.map +1 -0
  18. package/dist/enums/index.d.ts +12 -46
  19. package/dist/enums/index.js +22 -110
  20. package/dist/enums/index.js.map +1 -1
  21. package/dist/enums/src/enums/definitions.json +3073 -0
  22. package/dist/enums/utils-renumber.js +20 -20
  23. package/dist/enums/utils-renumber.js.map +1 -1
  24. package/dist/enums/xrpl-definitions-base.d.ts +44 -0
  25. package/dist/enums/xrpl-definitions-base.js +59 -0
  26. package/dist/enums/xrpl-definitions-base.js.map +1 -0
  27. package/dist/enums/xrpl-definitions.d.ts +21 -0
  28. package/dist/enums/xrpl-definitions.js +29 -0
  29. package/dist/enums/xrpl-definitions.js.map +1 -0
  30. package/dist/hash-prefixes.d.ts +1 -2
  31. package/dist/hash-prefixes.js +7 -6
  32. package/dist/hash-prefixes.js.map +1 -1
  33. package/dist/hashes.d.ts +7 -8
  34. package/dist/hashes.js +23 -44
  35. package/dist/hashes.js.map +1 -1
  36. package/dist/index.d.ts +16 -17
  37. package/dist/index.js +65 -40
  38. package/dist/index.js.map +1 -1
  39. package/dist/ledger-hashes.d.ts +6 -3
  40. package/dist/ledger-hashes.js +40 -33
  41. package/dist/ledger-hashes.js.map +1 -1
  42. package/dist/quality.d.ts +3 -4
  43. package/dist/quality.js +20 -19
  44. package/dist/quality.js.map +1 -1
  45. package/dist/serdes/binary-parser.d.ts +8 -6
  46. package/dist/serdes/binary-parser.js +74 -64
  47. package/dist/serdes/binary-parser.js.map +1 -1
  48. package/dist/serdes/binary-serializer.d.ts +10 -11
  49. package/dist/serdes/binary-serializer.js +50 -48
  50. package/dist/serdes/binary-serializer.js.map +1 -1
  51. package/dist/shamap.d.ts +6 -7
  52. package/dist/shamap.js +74 -97
  53. package/dist/shamap.js.map +1 -1
  54. package/dist/src/binary.d.ts +90 -0
  55. package/dist/src/binary.js +128 -0
  56. package/dist/src/binary.js.map +1 -0
  57. package/dist/src/coretypes.d.ts +9 -0
  58. package/dist/src/coretypes.js +48 -0
  59. package/dist/src/coretypes.js.map +1 -0
  60. package/dist/src/enums/bytes.d.ts +25 -0
  61. package/dist/src/enums/bytes.js +63 -0
  62. package/dist/src/enums/bytes.js.map +1 -0
  63. package/dist/src/enums/constants.d.ts +4 -0
  64. package/dist/src/enums/constants.js +8 -0
  65. package/dist/src/enums/constants.js.map +1 -0
  66. package/dist/src/enums/definitions.json +3068 -0
  67. package/dist/src/enums/field.d.ts +28 -0
  68. package/dist/src/enums/field.js +58 -0
  69. package/dist/src/enums/field.js.map +1 -0
  70. package/dist/src/enums/index.d.ts +12 -0
  71. package/dist/src/enums/index.js +31 -0
  72. package/dist/src/enums/index.js.map +1 -0
  73. package/dist/src/enums/utils-renumber.d.ts +101 -0
  74. package/dist/src/enums/utils-renumber.js +127 -0
  75. package/dist/src/enums/utils-renumber.js.map +1 -0
  76. package/dist/src/enums/xrpl-definitions-base.d.ts +44 -0
  77. package/dist/src/enums/xrpl-definitions-base.js +59 -0
  78. package/dist/src/enums/xrpl-definitions-base.js.map +1 -0
  79. package/dist/src/enums/xrpl-definitions.d.ts +21 -0
  80. package/dist/src/enums/xrpl-definitions.js +29 -0
  81. package/dist/src/enums/xrpl-definitions.js.map +1 -0
  82. package/dist/src/hash-prefixes.d.ts +5 -0
  83. package/dist/src/hash-prefixes.js +41 -0
  84. package/dist/src/hash-prefixes.js.map +1 -0
  85. package/dist/src/hashes.d.ts +50 -0
  86. package/dist/src/hashes.js +76 -0
  87. package/dist/src/hashes.js.map +1 -0
  88. package/dist/src/index.d.ts +64 -0
  89. package/dist/src/index.js +123 -0
  90. package/dist/src/index.js.map +1 -0
  91. package/dist/src/ledger-hashes.d.ts +48 -0
  92. package/dist/src/ledger-hashes.js +141 -0
  93. package/dist/src/ledger-hashes.js.map +1 -0
  94. package/dist/src/quality.d.ts +21 -0
  95. package/dist/src/quality.js +42 -0
  96. package/dist/src/quality.js.map +1 -0
  97. package/dist/src/serdes/binary-parser.d.ts +100 -0
  98. package/dist/src/serdes/binary-parser.js +194 -0
  99. package/dist/src/serdes/binary-parser.js.map +1 -0
  100. package/dist/src/serdes/binary-serializer.d.ts +81 -0
  101. package/dist/src/serdes/binary-serializer.js +149 -0
  102. package/dist/src/serdes/binary-serializer.js.map +1 -0
  103. package/dist/src/shamap.d.ts +102 -0
  104. package/dist/src/shamap.js +172 -0
  105. package/dist/src/shamap.js.map +1 -0
  106. package/dist/src/types/account-id.d.ts +35 -0
  107. package/dist/src/types/account-id.js +69 -0
  108. package/dist/src/types/account-id.js.map +1 -0
  109. package/dist/src/types/amount.d.ts +91 -0
  110. package/dist/src/types/amount.js +289 -0
  111. package/dist/src/types/amount.js.map +1 -0
  112. package/dist/src/types/blob.d.ts +24 -0
  113. package/dist/src/types/blob.js +43 -0
  114. package/dist/src/types/blob.js.map +1 -0
  115. package/dist/src/types/currency.d.ts +28 -0
  116. package/dist/src/types/currency.js +127 -0
  117. package/dist/src/types/currency.js.map +1 -0
  118. package/dist/src/types/hash-128.d.ts +16 -0
  119. package/dist/src/types/hash-128.js +32 -0
  120. package/dist/src/types/hash-128.js.map +1 -0
  121. package/dist/src/types/hash-160.d.ts +10 -0
  122. package/dist/src/types/hash-160.js +19 -0
  123. package/dist/src/types/hash-160.js.map +1 -0
  124. package/dist/src/types/hash-192.d.ts +10 -0
  125. package/dist/src/types/hash-192.js +19 -0
  126. package/dist/src/types/hash-192.js.map +1 -0
  127. package/dist/src/types/hash-256.d.ts +10 -0
  128. package/dist/src/types/hash-256.js +16 -0
  129. package/dist/src/types/hash-256.js.map +1 -0
  130. package/dist/src/types/hash.d.ts +40 -0
  131. package/dist/src/types/hash.js +73 -0
  132. package/dist/src/types/hash.js.map +1 -0
  133. package/dist/src/types/index.d.ts +19 -0
  134. package/dist/src/types/index.js +64 -0
  135. package/dist/src/types/index.js.map +1 -0
  136. package/dist/src/types/issue.d.ts +38 -0
  137. package/dist/src/types/issue.js +81 -0
  138. package/dist/src/types/issue.js.map +1 -0
  139. package/dist/src/types/path-set.d.ts +36 -0
  140. package/dist/src/types/path-set.js +233 -0
  141. package/dist/src/types/path-set.js.map +1 -0
  142. package/dist/src/types/serialized-type.d.ts +70 -0
  143. package/dist/src/types/serialized-type.js +105 -0
  144. package/dist/src/types/serialized-type.js.map +1 -0
  145. package/dist/src/types/st-array.d.ts +31 -0
  146. package/dist/src/types/st-array.js +86 -0
  147. package/dist/src/types/st-array.js.map +1 -0
  148. package/dist/src/types/st-object.d.ts +32 -0
  149. package/dist/src/types/st-object.js +155 -0
  150. package/dist/src/types/st-object.js.map +1 -0
  151. package/dist/src/types/uint-16.d.ts +24 -0
  152. package/dist/src/types/uint-16.js +45 -0
  153. package/dist/src/types/uint-16.js.map +1 -0
  154. package/dist/src/types/uint-32.d.ts +24 -0
  155. package/dist/src/types/uint-32.js +50 -0
  156. package/dist/src/types/uint-32.js.map +1 -0
  157. package/dist/src/types/uint-64.d.ts +37 -0
  158. package/dist/src/types/uint-64.js +86 -0
  159. package/dist/src/types/uint-64.js.map +1 -0
  160. package/dist/src/types/uint-8.d.ts +24 -0
  161. package/dist/src/types/uint-8.js +46 -0
  162. package/dist/src/types/uint-8.js.map +1 -0
  163. package/dist/src/types/uint.d.ts +29 -0
  164. package/dist/src/types/uint.js +47 -0
  165. package/dist/src/types/uint.js.map +1 -0
  166. package/dist/src/types/vector-256.d.ts +30 -0
  167. package/dist/src/types/vector-256.js +73 -0
  168. package/dist/src/types/vector-256.js.map +1 -0
  169. package/dist/src/types/xchain-bridge.d.ts +44 -0
  170. package/dist/src/types/xchain-bridge.js +102 -0
  171. package/dist/src/types/xchain-bridge.js.map +1 -0
  172. package/dist/src/utils.d.ts +47 -0
  173. package/dist/src/utils.js +137 -0
  174. package/dist/src/utils.js.map +1 -0
  175. package/dist/tsconfig.tsbuildinfo +1 -0
  176. package/dist/types/account-id.d.ts +2 -3
  177. package/dist/types/account-id.js +29 -37
  178. package/dist/types/account-id.js.map +1 -1
  179. package/dist/types/amount.d.ts +33 -10
  180. package/dist/types/amount.js +181 -101
  181. package/dist/types/amount.js.map +1 -1
  182. package/dist/types/blob.d.ts +3 -4
  183. package/dist/types/blob.js +16 -27
  184. package/dist/types/blob.js.map +1 -1
  185. package/dist/types/currency.d.ts +5 -13
  186. package/dist/types/currency.js +53 -66
  187. package/dist/types/currency.js.map +1 -1
  188. package/dist/types/hash-128.d.ts +8 -3
  189. package/dist/types/hash-128.js +23 -22
  190. package/dist/types/hash-128.js.map +1 -1
  191. package/dist/types/hash-160.d.ts +2 -3
  192. package/dist/types/hash-160.js +7 -24
  193. package/dist/types/hash-160.js.map +1 -1
  194. package/dist/types/hash-192.d.ts +10 -0
  195. package/dist/types/hash-192.js +19 -0
  196. package/dist/types/hash-192.js.map +1 -0
  197. package/dist/types/hash-256.d.ts +2 -3
  198. package/dist/types/hash-256.js +7 -22
  199. package/dist/types/hash-256.js.map +1 -1
  200. package/dist/types/hash.d.ts +4 -5
  201. package/dist/types/hash.js +25 -39
  202. package/dist/types/hash.js.map +1 -1
  203. package/dist/types/index.d.ts +19 -33
  204. package/dist/types/index.js +44 -24
  205. package/dist/types/index.js.map +1 -1
  206. package/dist/types/issue.d.ts +38 -0
  207. package/dist/types/issue.js +81 -0
  208. package/dist/types/issue.js.map +1 -0
  209. package/dist/types/path-set.d.ts +2 -2
  210. package/dist/types/path-set.js +73 -94
  211. package/dist/types/path-set.js.map +1 -1
  212. package/dist/types/serialized-type.d.ts +26 -18
  213. package/dist/types/serialized-type.js +50 -60
  214. package/dist/types/serialized-type.js.map +1 -1
  215. package/dist/types/st-array.d.ts +7 -4
  216. package/dist/types/st-array.js +36 -47
  217. package/dist/types/st-array.js.map +1 -1
  218. package/dist/types/st-object.d.ts +8 -5
  219. package/dist/types/st-object.js +73 -74
  220. package/dist/types/st-object.js.map +1 -1
  221. package/dist/types/uint-16.d.ts +3 -4
  222. package/dist/types/uint-16.js +20 -33
  223. package/dist/types/uint-16.js.map +1 -1
  224. package/dist/types/uint-32.d.ts +3 -4
  225. package/dist/types/uint-32.js +23 -36
  226. package/dist/types/uint-32.js.map +1 -1
  227. package/dist/types/uint-64.d.ts +5 -6
  228. package/dist/types/uint-64.js +44 -48
  229. package/dist/types/uint-64.js.map +1 -1
  230. package/dist/types/uint-8.d.ts +3 -4
  231. package/dist/types/uint-8.js +21 -33
  232. package/dist/types/uint-8.js.map +1 -1
  233. package/dist/types/uint.d.ts +5 -5
  234. package/dist/types/uint.js +17 -27
  235. package/dist/types/uint.js.map +1 -1
  236. package/dist/types/vector-256.d.ts +3 -4
  237. package/dist/types/vector-256.js +28 -45
  238. package/dist/types/vector-256.js.map +1 -1
  239. package/dist/types/xchain-bridge.d.ts +44 -0
  240. package/dist/types/xchain-bridge.js +102 -0
  241. package/dist/types/xchain-bridge.js.map +1 -0
  242. package/dist/utils.d.ts +47 -0
  243. package/dist/utils.js +137 -0
  244. package/dist/utils.js.map +1 -0
  245. package/package.json +23 -33
  246. package/src/README.md +5 -0
  247. package/src/binary.ts +194 -0
  248. package/src/coretypes.ts +31 -0
  249. package/src/enums/README.md +144 -0
  250. package/src/enums/bytes.ts +74 -0
  251. package/src/enums/constants.ts +4 -0
  252. package/src/enums/definitions.json +3073 -0
  253. package/src/enums/field.ts +84 -0
  254. package/src/enums/index.ts +34 -0
  255. package/src/enums/utils-renumber.ts +134 -0
  256. package/src/enums/xrpl-definitions-base.ts +111 -0
  257. package/src/enums/xrpl-definitions.ts +32 -0
  258. package/src/hash-prefixes.ts +40 -0
  259. package/src/hashes.ts +75 -0
  260. package/src/index.ts +153 -0
  261. package/src/ledger-hashes.ts +191 -0
  262. package/src/quality.ts +38 -0
  263. package/src/serdes/binary-parser.ts +228 -0
  264. package/src/serdes/binary-serializer.ts +166 -0
  265. package/src/shamap.ts +186 -0
  266. package/src/types/account-id.ts +86 -0
  267. package/src/types/amount.ts +362 -0
  268. package/src/types/blob.ts +46 -0
  269. package/src/types/currency.ts +140 -0
  270. package/src/types/hash-128.ts +33 -0
  271. package/src/types/hash-160.ts +19 -0
  272. package/src/types/hash-192.ts +19 -0
  273. package/src/types/hash-256.ts +15 -0
  274. package/src/types/hash.ts +83 -0
  275. package/src/types/index.ts +66 -0
  276. package/src/types/issue.ts +96 -0
  277. package/src/types/path-set.ts +290 -0
  278. package/src/types/serialized-type.ts +122 -0
  279. package/src/types/st-array.ts +113 -0
  280. package/src/types/st-object.ts +192 -0
  281. package/src/types/uint-16.ts +53 -0
  282. package/src/types/uint-32.ts +59 -0
  283. package/src/types/uint-64.ts +104 -0
  284. package/src/types/uint-8.ts +52 -0
  285. package/src/types/uint.ts +60 -0
  286. package/src/types/vector-256.ts +79 -0
  287. package/src/types/xchain-bridge.ts +128 -0
  288. package/src/utils.ts +152 -0
  289. package/HISTORY.md +0 -74
  290. package/test/amount.test.js +0 -43
  291. package/test/binary-json.test.js +0 -47
  292. package/test/binary-parser.test.js +0 -397
  293. package/test/binary-serializer.test.js +0 -248
  294. package/test/fixtures/account-tx-transactions.db +0 -0
  295. package/test/fixtures/codec-fixtures.json +0 -4466
  296. package/test/fixtures/data-driven-tests.json +0 -3721
  297. package/test/fixtures/delivermin-tx-binary.json +0 -1
  298. package/test/fixtures/delivermin-tx.json +0 -98
  299. package/test/fixtures/deposit-preauth-tx-binary.json +0 -1
  300. package/test/fixtures/deposit-preauth-tx-meta-binary.json +0 -1
  301. package/test/fixtures/deposit-preauth-tx.json +0 -58
  302. package/test/fixtures/escrow-cancel-binary.json +0 -1
  303. package/test/fixtures/escrow-cancel-tx.json +0 -6
  304. package/test/fixtures/escrow-create-binary.json +0 -1
  305. package/test/fixtures/escrow-create-tx.json +0 -10
  306. package/test/fixtures/escrow-finish-binary.json +0 -1
  307. package/test/fixtures/escrow-finish-meta-binary.json +0 -1
  308. package/test/fixtures/escrow-finish-tx.json +0 -95
  309. package/test/fixtures/ledger-full-38129.json +0 -1
  310. package/test/fixtures/ledger-full-40000.json +0 -1
  311. package/test/fixtures/negative-unl.json +0 -12
  312. package/test/fixtures/payment-channel-claim-binary.json +0 -1
  313. package/test/fixtures/payment-channel-claim-tx.json +0 -8
  314. package/test/fixtures/payment-channel-create-binary.json +0 -1
  315. package/test/fixtures/payment-channel-create-tx.json +0 -11
  316. package/test/fixtures/payment-channel-fund-binary.json +0 -1
  317. package/test/fixtures/payment-channel-fund-tx.json +0 -7
  318. package/test/fixtures/signerlistset-tx-binary.json +0 -1
  319. package/test/fixtures/signerlistset-tx-meta-binary.json +0 -1
  320. package/test/fixtures/signerlistset-tx.json +0 -94
  321. package/test/fixtures/x-codec-fixtures.json +0 -188
  322. package/test/hash.test.js +0 -82
  323. package/test/ledger.test.js +0 -29
  324. package/test/lower-case-hex.test.js +0 -45
  325. package/test/pseudo-transaction.test.js +0 -38
  326. package/test/quality.test.js +0 -15
  327. package/test/shamap.test.js +0 -88
  328. package/test/signing-data-encoding.test.js +0 -129
  329. package/test/tx-encode-decode.test.js +0 -80
  330. package/test/types.test.js +0 -34
  331. package/test/uint.test.js +0 -40
  332. package/test/utils.js +0 -29
  333. package/test/x-address.test.js +0 -147
@@ -1,63 +1,50 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
2
  Object.defineProperty(exports, "__esModule", { value: true });
16
3
  exports.UInt32 = void 0;
17
- var uint_1 = require("./uint");
4
+ const uint_1 = require("./uint");
5
+ const utils_1 = require("../utils");
18
6
  /**
19
7
  * Derived UInt class for serializing/deserializing 32 bit UInt
20
8
  */
21
- var UInt32 = /** @class */ (function (_super) {
22
- __extends(UInt32, _super);
23
- function UInt32(bytes) {
24
- return _super.call(this, bytes !== null && bytes !== void 0 ? bytes : UInt32.defaultUInt32.bytes) || this;
9
+ class UInt32 extends uint_1.UInt {
10
+ constructor(bytes) {
11
+ super(bytes !== null && bytes !== void 0 ? bytes : UInt32.defaultUInt32.bytes);
25
12
  }
26
- UInt32.fromParser = function (parser) {
13
+ static fromParser(parser) {
27
14
  return new UInt32(parser.read(UInt32.width));
28
- };
15
+ }
29
16
  /**
30
17
  * Construct a UInt32 object from a number
31
18
  *
32
19
  * @param val UInt32 object or number
33
20
  */
34
- UInt32.from = function (val) {
21
+ static from(val) {
35
22
  if (val instanceof UInt32) {
36
23
  return val;
37
24
  }
38
- var buf = Buffer.alloc(UInt32.width);
39
- if (typeof val === "string") {
40
- var num = Number.parseInt(val);
41
- buf.writeUInt32BE(num);
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);
42
29
  return new UInt32(buf);
43
30
  }
44
- if (typeof val === "number") {
45
- buf.writeUInt32BE(val);
31
+ if (typeof val === 'number') {
32
+ UInt32.checkUintRange(val, 0, 0xffffffff);
33
+ (0, utils_1.writeUInt32BE)(buf, val, 0);
46
34
  return new UInt32(buf);
47
35
  }
48
- throw new Error("Cannot construct UInt32 from given value");
49
- };
36
+ throw new Error('Cannot construct UInt32 from given value');
37
+ }
50
38
  /**
51
39
  * get the value of a UInt32 object
52
40
  *
53
41
  * @returns the number represented by this.bytes
54
42
  */
55
- UInt32.prototype.valueOf = function () {
56
- return this.bytes.readUInt32BE();
57
- };
58
- UInt32.width = 32 / 8; // 4
59
- UInt32.defaultUInt32 = new UInt32(Buffer.alloc(UInt32.width));
60
- return UInt32;
61
- }(uint_1.UInt));
43
+ valueOf() {
44
+ return parseInt((0, utils_1.readUInt32BE)(this.bytes, 0), 10);
45
+ }
46
+ }
62
47
  exports.UInt32 = UInt32;
48
+ UInt32.width = 32 / 8; // 4
49
+ UInt32.defaultUInt32 = new UInt32(new Uint8Array(UInt32.width));
63
50
  //# sourceMappingURL=uint-32.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"uint-32.js","sourceRoot":"","sources":["../../src/types/uint-32.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+BAA8B;AAG9B;;GAEG;AACH;IAAqB,0BAAI;IAMvB,gBAAY,KAAa;eACvB,kBAAM,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC;IAC5C,CAAC;IAEM,iBAAU,GAAjB,UAAkB,MAAoB;QACpC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/C,CAAC;IAED;;;;OAIG;IACI,WAAI,GAAX,UAAgD,GAAM;QACpD,IAAI,GAAG,YAAY,MAAM,EAAE;YACzB,OAAO,GAAG,CAAC;SACZ;QAED,IAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAEvC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAC3B,IAAM,GAAG,GAAG,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AAI,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"}
@@ -1,18 +1,17 @@
1
- /// <reference types="node" />
2
- import { UInt } from "./uint";
3
- import { BinaryParser } from "../serdes/binary-parser";
1
+ import { UInt } from './uint';
2
+ import { BinaryParser } from '../serdes/binary-parser';
4
3
  /**
5
4
  * Derived UInt class for serializing/deserializing 64 bit UInt
6
5
  */
7
6
  declare class UInt64 extends UInt {
8
7
  protected static readonly width: number;
9
8
  static readonly defaultUInt64: UInt64;
10
- constructor(bytes: Buffer);
9
+ constructor(bytes: Uint8Array);
11
10
  static fromParser(parser: BinaryParser): UInt;
12
11
  /**
13
12
  * Construct a UInt64 object
14
13
  *
15
- * @param val A UInt64, hex-string, bigint, or number
14
+ * @param val A UInt64, hex-string, bigInt, or number
16
15
  * @returns A UInt64 object
17
16
  */
18
17
  static from<T extends UInt64 | string | bigint | number>(val: T): UInt64;
@@ -33,6 +32,6 @@ declare class UInt64 extends UInt {
33
32
  *
34
33
  * @returns 8 bytes representing the UInt64
35
34
  */
36
- toBytes(): Buffer;
35
+ toBytes(): Uint8Array;
37
36
  }
38
37
  export { UInt64 };
@@ -1,90 +1,86 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
2
  Object.defineProperty(exports, "__esModule", { value: true });
16
3
  exports.UInt64 = void 0;
17
- var uint_1 = require("./uint");
18
- var HEX_REGEX = /^[A-F0-9]{16}$/;
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);
19
9
  /**
20
10
  * Derived UInt class for serializing/deserializing 64 bit UInt
21
11
  */
22
- var UInt64 = /** @class */ (function (_super) {
23
- __extends(UInt64, _super);
24
- function UInt64(bytes) {
25
- return _super.call(this, bytes !== null && bytes !== void 0 ? bytes : UInt64.defaultUInt64.bytes) || this;
12
+ class UInt64 extends uint_1.UInt {
13
+ constructor(bytes) {
14
+ super(bytes !== null && bytes !== void 0 ? bytes : UInt64.defaultUInt64.bytes);
26
15
  }
27
- UInt64.fromParser = function (parser) {
16
+ static fromParser(parser) {
28
17
  return new UInt64(parser.read(UInt64.width));
29
- };
18
+ }
30
19
  /**
31
20
  * Construct a UInt64 object
32
21
  *
33
- * @param val A UInt64, hex-string, bigint, or number
22
+ * @param val A UInt64, hex-string, bigInt, or number
34
23
  * @returns A UInt64 object
35
24
  */
36
- UInt64.from = function (val) {
25
+ static from(val) {
37
26
  if (val instanceof UInt64) {
38
27
  return val;
39
28
  }
40
- var buf = Buffer.alloc(UInt64.width);
41
- if (typeof val === "number") {
29
+ let buf = new Uint8Array(UInt64.width);
30
+ if (typeof val === 'number') {
42
31
  if (val < 0) {
43
- throw new Error("value must be an unsigned integer");
32
+ throw new Error('value must be an unsigned integer');
44
33
  }
45
- buf.writeBigUInt64BE(BigInt(val));
46
- return new UInt64(buf);
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));
47
39
  }
48
- if (typeof val === "string") {
40
+ if (typeof val === 'string') {
49
41
  if (!HEX_REGEX.test(val)) {
50
- throw new Error(val + " is not a valid hex-string");
42
+ throw new Error(`${val} is not a valid hex-string`);
51
43
  }
52
- buf = Buffer.from(val, "hex");
44
+ const strBuf = val.padStart(16, '0');
45
+ buf = (0, utils_1.hexToBytes)(strBuf);
53
46
  return new UInt64(buf);
54
47
  }
55
- if (typeof val === "bigint") {
56
- buf.writeBigUInt64BE(val);
57
- return new UInt64(buf);
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));
58
53
  }
59
- throw new Error("Cannot construct UInt64 from given value");
60
- };
54
+ throw new Error('Cannot construct UInt64 from given value');
55
+ }
61
56
  /**
62
57
  * The JSON representation of a UInt64 object
63
58
  *
64
59
  * @returns a hex-string
65
60
  */
66
- UInt64.prototype.toJSON = function () {
67
- return this.bytes.toString("hex").toUpperCase();
68
- };
61
+ toJSON() {
62
+ return (0, utils_1.bytesToHex)(this.bytes);
63
+ }
69
64
  /**
70
65
  * Get the value of the UInt64
71
66
  *
72
67
  * @returns the number represented buy this.bytes
73
68
  */
74
- UInt64.prototype.valueOf = function () {
75
- return this.bytes.readBigUInt64BE();
76
- };
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
+ }
77
74
  /**
78
75
  * Get the bytes representation of the UInt64 object
79
76
  *
80
77
  * @returns 8 bytes representing the UInt64
81
78
  */
82
- UInt64.prototype.toBytes = function () {
79
+ toBytes() {
83
80
  return this.bytes;
84
- };
85
- UInt64.width = 64 / 8; // 8
86
- UInt64.defaultUInt64 = new UInt64(Buffer.alloc(UInt64.width));
87
- return UInt64;
88
- }(uint_1.UInt));
81
+ }
82
+ }
89
83
  exports.UInt64 = UInt64;
84
+ UInt64.width = 64 / 8; // 8
85
+ UInt64.defaultUInt64 = new UInt64(new Uint8Array(UInt64.width));
90
86
  //# sourceMappingURL=uint-64.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"uint-64.js","sourceRoot":"","sources":["../../src/types/uint-64.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+BAA8B;AAG9B,IAAM,SAAS,GAAG,gBAAgB,CAAC;AAEnC;;GAEG;AACH;IAAqB,0BAAI;IAMvB,gBAAY,KAAa;eACvB,kBAAM,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,MAAM,CAAC,aAAa,C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AAa,EAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;YAEvD,OAAO,IAAI,MAAM,CAAC,IAAA,cAAM,EAAC,MAAM,CAAC,CAAC,CAAA;SAClC;QAED,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAA;IAC7D,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,OAAO,IAAA,kBAAU,EAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC/B,CAAC;IAED;;;;OAIG;IACH,OAAO;QACL,MAAM,GAAG,GAAG,MAAM,CAAC,IAAA,oBAAY,EAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAC3D,MAAM,GAAG,GAAG,MAAM,CAAC,IAAA,oBAAY,EAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QACxD,OAAO,CAAC,GAAG,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAA;IAClC,CAAC;IAED;;;;OAIG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;;AAGM,wBAAM;AA3Fa,YAAK,GAAW,EAAE,GAAG,CAAC,CAAA,CAAC,IAAI;AACrC,oBAAa,GAAW,IAAI,MAAM,CAChD,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAC7B,CAAA"}
@@ -1,13 +1,12 @@
1
- /// <reference types="node" />
2
- import { UInt } from "./uint";
3
- import { BinaryParser } from "../serdes/binary-parser";
1
+ import { UInt } from './uint';
2
+ import { BinaryParser } from '../serdes/binary-parser';
4
3
  /**
5
4
  * Derived UInt class for serializing/deserializing 8 bit UInt
6
5
  */
7
6
  declare class UInt8 extends UInt {
8
7
  protected static readonly width: number;
9
8
  static readonly defaultUInt8: UInt8;
10
- constructor(bytes: Buffer);
9
+ constructor(bytes: Uint8Array);
11
10
  static fromParser(parser: BinaryParser): UInt;
12
11
  /**
13
12
  * Construct a UInt8 object from a number
@@ -1,58 +1,46 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
2
  Object.defineProperty(exports, "__esModule", { value: true });
16
3
  exports.UInt8 = void 0;
17
- var uint_1 = require("./uint");
4
+ const uint_1 = require("./uint");
5
+ const utils_1 = require("@xrplf/isomorphic/utils");
6
+ const utils_2 = require("../utils");
18
7
  /**
19
8
  * Derived UInt class for serializing/deserializing 8 bit UInt
20
9
  */
21
- var UInt8 = /** @class */ (function (_super) {
22
- __extends(UInt8, _super);
23
- function UInt8(bytes) {
24
- return _super.call(this, bytes !== null && bytes !== void 0 ? bytes : UInt8.defaultUInt8.bytes) || this;
10
+ class UInt8 extends uint_1.UInt {
11
+ constructor(bytes) {
12
+ super(bytes !== null && bytes !== void 0 ? bytes : UInt8.defaultUInt8.bytes);
25
13
  }
26
- UInt8.fromParser = function (parser) {
14
+ static fromParser(parser) {
27
15
  return new UInt8(parser.read(UInt8.width));
28
- };
16
+ }
29
17
  /**
30
18
  * Construct a UInt8 object from a number
31
19
  *
32
20
  * @param val UInt8 object or number
33
21
  */
34
- UInt8.from = function (val) {
22
+ static from(val) {
35
23
  if (val instanceof UInt8) {
36
24
  return val;
37
25
  }
38
- if (typeof val === "number") {
39
- var buf = Buffer.alloc(UInt8.width);
40
- buf.writeUInt8(val);
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);
41
30
  return new UInt8(buf);
42
31
  }
43
- throw new Error("Cannot construct UInt8 from given value");
44
- };
32
+ throw new Error('Cannot construct UInt8 from given value');
33
+ }
45
34
  /**
46
35
  * get the value of a UInt8 object
47
36
  *
48
37
  * @returns the number represented by this.bytes
49
38
  */
50
- UInt8.prototype.valueOf = function () {
51
- return this.bytes.readUInt8();
52
- };
53
- UInt8.width = 8 / 8; // 1
54
- UInt8.defaultUInt8 = new UInt8(Buffer.alloc(UInt8.width));
55
- return UInt8;
56
- }(uint_1.UInt));
39
+ valueOf() {
40
+ return parseInt((0, utils_1.bytesToHex)(this.bytes), 16);
41
+ }
42
+ }
57
43
  exports.UInt8 = UInt8;
44
+ UInt8.width = 8 / 8; // 1
45
+ UInt8.defaultUInt8 = new UInt8(new Uint8Array(UInt8.width));
58
46
  //# sourceMappingURL=uint-8.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"uint-8.js","sourceRoot":"","sources":["../../src/types/uint-8.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+BAA8B;AAG9B;;GAEG;AACH;IAAoB,yBAAI;IAItB,eAAY,KAAa;eACvB,kBAAM,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC;IAC1C,CAAC;IAEM,gBAAU,GAAjB,UAAkB,MAAoB;QACpC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7C,CAAC;IAED;;;;OAIG;IACI,UAAI,GAAX,UAAsC,GAAM;QAC1C,IAAI,GAAG,YAAY,KAAK,EAAE;YACxB,OAAO,GAAG,CAAC;SACZ;QAED,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAC3B,IAAM,GAAG,GAA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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"}
@@ -1,18 +1,17 @@
1
- /// <reference types="node" />
2
- import { Comparable } from "./serialized-type";
1
+ import { Comparable } from './serialized-type';
3
2
  /**
4
3
  * Base class for serializing and deserializing unsigned integers.
5
4
  */
6
- declare abstract class UInt extends Comparable {
5
+ declare abstract class UInt extends Comparable<UInt | number> {
7
6
  protected static width: number;
8
- constructor(bytes: Buffer);
7
+ constructor(bytes: Uint8Array);
9
8
  /**
10
9
  * Overload of compareTo for Comparable
11
10
  *
12
11
  * @param other other UInt to compare this to
13
12
  * @returns -1, 0, or 1 depending on how the objects relate to each other
14
13
  */
15
- compareTo(other: UInt): number;
14
+ compareTo(other: UInt | number): number;
16
15
  /**
17
16
  * Convert a UInt object to JSON
18
17
  *
@@ -25,5 +24,6 @@ declare abstract class UInt extends Comparable {
25
24
  * @returns the value
26
25
  */
27
26
  abstract valueOf(): number | bigint;
27
+ static checkUintRange(val: number, min: number, max: number): void;
28
28
  }
29
29
  export { UInt };
@@ -1,22 +1,9 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
2
  Object.defineProperty(exports, "__esModule", { value: true });
16
3
  exports.UInt = void 0;
17
- var serialized_type_1 = require("./serialized-type");
4
+ const serialized_type_1 = require("./serialized-type");
18
5
  /**
19
- * Compare numbers and bigints n1 and n2
6
+ * Compare numbers and bigInts n1 and n2
20
7
  *
21
8
  * @param n1 First object to compare
22
9
  * @param n2 Second object to compare
@@ -28,10 +15,9 @@ function compare(n1, n2) {
28
15
  /**
29
16
  * Base class for serializing and deserializing unsigned integers.
30
17
  */
31
- var UInt = /** @class */ (function (_super) {
32
- __extends(UInt, _super);
33
- function UInt(bytes) {
34
- return _super.call(this, bytes) || this;
18
+ class UInt extends serialized_type_1.Comparable {
19
+ constructor(bytes) {
20
+ super(bytes);
35
21
  }
36
22
  /**
37
23
  * Overload of compareTo for Comparable
@@ -39,19 +25,23 @@ var UInt = /** @class */ (function (_super) {
39
25
  * @param other other UInt to compare this to
40
26
  * @returns -1, 0, or 1 depending on how the objects relate to each other
41
27
  */
42
- UInt.prototype.compareTo = function (other) {
28
+ compareTo(other) {
43
29
  return compare(this.valueOf(), other.valueOf());
44
- };
30
+ }
45
31
  /**
46
32
  * Convert a UInt object to JSON
47
33
  *
48
34
  * @returns number or string represented by this.bytes
49
35
  */
50
- UInt.prototype.toJSON = function () {
51
- var val = this.valueOf();
52
- return typeof val === "number" ? val : val.toString();
53
- };
54
- return UInt;
55
- }(serialized_type_1.Comparable));
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
+ }
56
46
  exports.UInt = UInt;
57
47
  //# sourceMappingURL=uint.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"uint.js","sourceRoot":"","sources":["../../src/types/uint.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAA+C;AAE/C;;;;;;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,CAAC;AACzC,CAAC;AAED;;GAEG;AACH;IAA4B,wBAAU;IAGpC,cAAY,KAAa;eACvB,kBAAM,KAAK,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,wBAAS,GAAT,UAAU,KAAW;QACnB,OAAO,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAClD,CAAC;IAED;;;;OAIG;IACH,qBAAM,GAAN;QACE,IAAM,GAAG,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAC3B,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;IACxD,CAAC;IAQH,WAAC;AAAD,CAAC,AAjCD,CAA4B,4BAAU,GAiCrC;AAEQ,oBAAI"}
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"}
@@ -1,11 +1,10 @@
1
- /// <reference types="node" />
2
- import { SerializedType } from "./serialized-type";
3
- import { BinaryParser } from "../serdes/binary-parser";
1
+ import { SerializedType } from './serialized-type';
2
+ import { BinaryParser } from '../serdes/binary-parser';
4
3
  /**
5
4
  * Class for serializing and deserializing vectors of Hash256
6
5
  */
7
6
  declare class Vector256 extends SerializedType {
8
- constructor(bytes: Buffer);
7
+ constructor(bytes: Uint8Array);
9
8
  /**
10
9
  * Construct a Vector256 from a BinaryParser
11
10
  *
@@ -1,35 +1,22 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
2
  Object.defineProperty(exports, "__esModule", { value: true });
16
3
  exports.Vector256 = void 0;
17
- var serialized_type_1 = require("./serialized-type");
18
- var hash_256_1 = require("./hash-256");
19
- var binary_serializer_1 = require("../serdes/binary-serializer");
4
+ const serialized_type_1 = require("./serialized-type");
5
+ const hash_256_1 = require("./hash-256");
6
+ const binary_serializer_1 = require("../serdes/binary-serializer");
7
+ const utils_1 = require("@xrplf/isomorphic/utils");
20
8
  /**
21
9
  * TypeGuard for Array<string>
22
10
  */
23
11
  function isStrings(arg) {
24
- return Array.isArray(arg) && (arg.length === 0 || typeof arg[0] === "string");
12
+ return Array.isArray(arg) && (arg.length === 0 || typeof arg[0] === 'string');
25
13
  }
26
14
  /**
27
15
  * Class for serializing and deserializing vectors of Hash256
28
16
  */
29
- var Vector256 = /** @class */ (function (_super) {
30
- __extends(Vector256, _super);
31
- function Vector256(bytes) {
32
- return _super.call(this, bytes) || this;
17
+ class Vector256 extends serialized_type_1.SerializedType {
18
+ constructor(bytes) {
19
+ super(bytes);
33
20
  }
34
21
  /**
35
22
  * Construct a Vector256 from a BinaryParser
@@ -38,53 +25,49 @@ var Vector256 = /** @class */ (function (_super) {
38
25
  * @param hint length of the vector, in bytes, optional
39
26
  * @returns a Vector256 object
40
27
  */
41
- Vector256.fromParser = function (parser, hint) {
42
- var bytesList = new binary_serializer_1.BytesList();
43
- var bytes = hint !== null && hint !== void 0 ? hint : parser.size();
44
- var hashes = bytes / 32;
45
- for (var i = 0; i < hashes; i++) {
28
+ static fromParser(parser, hint) {
29
+ const bytesList = new binary_serializer_1.BytesList();
30
+ const bytes = hint !== null && hint !== void 0 ? hint : parser.size();
31
+ const hashes = bytes / 32;
32
+ for (let i = 0; i < hashes; i++) {
46
33
  hash_256_1.Hash256.fromParser(parser).toBytesSink(bytesList);
47
34
  }
48
35
  return new Vector256(bytesList.toBytes());
49
- };
36
+ }
50
37
  /**
51
38
  * Construct a Vector256 object from an array of hashes
52
39
  *
53
40
  * @param value A Vector256 object or array of hex-strings representing Hash256's
54
41
  * @returns a Vector256 object
55
42
  */
56
- Vector256.from = function (value) {
43
+ static from(value) {
57
44
  if (value instanceof Vector256) {
58
45
  return value;
59
46
  }
60
47
  if (isStrings(value)) {
61
- var bytesList_1 = new binary_serializer_1.BytesList();
62
- value.forEach(function (hash) {
63
- hash_256_1.Hash256.from(hash).toBytesSink(bytesList_1);
48
+ const bytesList = new binary_serializer_1.BytesList();
49
+ value.forEach((hash) => {
50
+ hash_256_1.Hash256.from(hash).toBytesSink(bytesList);
64
51
  });
65
- return new Vector256(bytesList_1.toBytes());
52
+ return new Vector256(bytesList.toBytes());
66
53
  }
67
- throw new Error("Cannot construct Vector256 from given value");
68
- };
54
+ throw new Error('Cannot construct Vector256 from given value');
55
+ }
69
56
  /**
70
57
  * Return an Array of hex-strings represented by this.bytes
71
58
  *
72
59
  * @returns An Array of strings representing the Hash256 objects
73
60
  */
74
- Vector256.prototype.toJSON = function () {
61
+ toJSON() {
75
62
  if (this.bytes.byteLength % 32 !== 0) {
76
- throw new Error("Invalid bytes for Vector256");
63
+ throw new Error('Invalid bytes for Vector256');
77
64
  }
78
- var result = [];
79
- for (var i = 0; i < this.bytes.byteLength; i += 32) {
80
- result.push(this.bytes
81
- .slice(i, i + 32)
82
- .toString("hex")
83
- .toUpperCase());
65
+ const result = [];
66
+ for (let i = 0; i < this.bytes.byteLength; i += 32) {
67
+ result.push((0, utils_1.bytesToHex)(this.bytes.slice(i, i + 32)));
84
68
  }
85
69
  return result;
86
- };
87
- return Vector256;
88
- }(serialized_type_1.SerializedType));
70
+ }
71
+ }
89
72
  exports.Vector256 = Vector256;
90
73
  //# sourceMappingURL=vector-256.js.map