@transia/ripple-binary-codec 1.4.6-alpha.9 → 2.5.1-quantum.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 (340) hide show
  1. package/dist/binary.d.ts +30 -16
  2. package/dist/binary.js +36 -16
  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/constants.d.ts +1 -0
  8. package/dist/enums/constants.js +6 -5
  9. package/dist/enums/constants.js.map +1 -1
  10. package/dist/enums/definitions.json +1535 -919
  11. package/dist/enums/field.d.ts +1 -2
  12. package/dist/enums/field.js +1 -2
  13. package/dist/enums/field.js.map +1 -1
  14. package/dist/enums/index.d.ts +1 -2
  15. package/dist/enums/index.js +5 -27
  16. package/dist/enums/index.js.map +1 -1
  17. package/dist/enums/src/enums/definitions.json +1537 -921
  18. package/dist/enums/xrpl-definitions-base.d.ts +5 -3
  19. package/dist/enums/xrpl-definitions-base.js +26 -6
  20. package/dist/enums/xrpl-definitions-base.js.map +1 -1
  21. package/dist/enums/xrpl-definitions.d.ts +2 -1
  22. package/dist/enums/xrpl-definitions.js +2 -1
  23. package/dist/enums/xrpl-definitions.js.map +1 -1
  24. package/dist/hash-prefixes.d.ts +1 -2
  25. package/dist/hash-prefixes.js +8 -6
  26. package/dist/hash-prefixes.js.map +1 -1
  27. package/dist/hashes.d.ts +6 -7
  28. package/dist/hashes.js +6 -7
  29. package/dist/hashes.js.map +1 -1
  30. package/dist/index.d.ts +16 -11
  31. package/dist/index.js +53 -58
  32. package/dist/index.js.map +1 -1
  33. package/dist/ledger-hashes.d.ts +1 -2
  34. package/dist/ledger-hashes.js +11 -30
  35. package/dist/ledger-hashes.js.map +1 -1
  36. package/dist/quality.d.ts +3 -4
  37. package/dist/quality.js +10 -8
  38. package/dist/quality.js.map +1 -1
  39. package/dist/serdes/binary-parser.d.ts +2 -3
  40. package/dist/serdes/binary-parser.js +16 -32
  41. package/dist/serdes/binary-parser.js.map +1 -1
  42. package/dist/serdes/binary-serializer.d.ts +6 -7
  43. package/dist/serdes/binary-serializer.js +12 -35
  44. package/dist/serdes/binary-serializer.js.map +1 -1
  45. package/dist/shamap.d.ts +4 -5
  46. package/dist/shamap.js +5 -5
  47. package/dist/shamap.js.map +1 -1
  48. package/dist/src/binary.d.ts +106 -0
  49. package/dist/src/binary.js +154 -0
  50. package/dist/src/binary.js.map +1 -0
  51. package/dist/src/coretypes.d.ts +9 -0
  52. package/dist/src/coretypes.js +48 -0
  53. package/dist/src/coretypes.js.map +1 -0
  54. package/dist/src/enums/bytes.d.ts +25 -0
  55. package/dist/src/enums/bytes.js +63 -0
  56. package/dist/src/enums/bytes.js.map +1 -0
  57. package/dist/src/enums/constants.d.ts +5 -0
  58. package/dist/src/enums/constants.js +9 -0
  59. package/dist/src/enums/constants.js.map +1 -0
  60. package/dist/src/enums/definitions.json +3385 -0
  61. package/dist/src/enums/field.d.ts +28 -0
  62. package/dist/src/enums/field.js +58 -0
  63. package/dist/src/enums/field.js.map +1 -0
  64. package/dist/src/enums/index.d.ts +12 -0
  65. package/dist/src/enums/index.js +31 -0
  66. package/dist/src/enums/index.js.map +1 -0
  67. package/dist/src/enums/utils-renumber.d.ts +101 -0
  68. package/dist/src/enums/utils-renumber.js +127 -0
  69. package/dist/src/enums/utils-renumber.js.map +1 -0
  70. package/dist/src/enums/xrpl-definitions-base.d.ts +47 -0
  71. package/dist/src/enums/xrpl-definitions-base.js +83 -0
  72. package/dist/src/enums/xrpl-definitions-base.js.map +1 -0
  73. package/dist/src/enums/xrpl-definitions.d.ts +22 -0
  74. package/dist/src/enums/xrpl-definitions.js +30 -0
  75. package/dist/src/enums/xrpl-definitions.js.map +1 -0
  76. package/dist/src/hash-prefixes.d.ts +5 -0
  77. package/dist/src/hash-prefixes.js +43 -0
  78. package/dist/src/hash-prefixes.js.map +1 -0
  79. package/dist/src/hashes.d.ts +50 -0
  80. package/dist/src/hashes.js +76 -0
  81. package/dist/src/hashes.js.map +1 -0
  82. package/dist/src/index.d.ts +69 -0
  83. package/dist/src/index.js +134 -0
  84. package/dist/src/index.js.map +1 -0
  85. package/dist/src/ledger-hashes.d.ts +48 -0
  86. package/dist/src/ledger-hashes.js +141 -0
  87. package/dist/src/ledger-hashes.js.map +1 -0
  88. package/dist/src/quality.d.ts +21 -0
  89. package/dist/src/quality.js +42 -0
  90. package/dist/src/quality.js.map +1 -0
  91. package/dist/src/serdes/binary-parser.d.ts +100 -0
  92. package/dist/src/serdes/binary-parser.js +194 -0
  93. package/dist/src/serdes/binary-parser.js.map +1 -0
  94. package/dist/src/serdes/binary-serializer.d.ts +81 -0
  95. package/dist/src/serdes/binary-serializer.js +149 -0
  96. package/dist/src/serdes/binary-serializer.js.map +1 -0
  97. package/dist/src/shamap.d.ts +102 -0
  98. package/dist/src/shamap.js +172 -0
  99. package/dist/src/shamap.js.map +1 -0
  100. package/dist/src/types/account-id.d.ts +35 -0
  101. package/dist/src/types/account-id.js +69 -0
  102. package/dist/src/types/account-id.js.map +1 -0
  103. package/dist/src/types/amount.d.ts +91 -0
  104. package/dist/src/types/amount.js +289 -0
  105. package/dist/src/types/amount.js.map +1 -0
  106. package/dist/src/types/blob.d.ts +24 -0
  107. package/dist/src/types/blob.js +43 -0
  108. package/dist/src/types/blob.js.map +1 -0
  109. package/dist/src/types/currency.d.ts +28 -0
  110. package/dist/src/types/currency.js +127 -0
  111. package/dist/src/types/currency.js.map +1 -0
  112. package/dist/src/types/hash-128.d.ts +16 -0
  113. package/dist/src/types/hash-128.js +32 -0
  114. package/dist/src/types/hash-128.js.map +1 -0
  115. package/dist/src/types/hash-160.d.ts +10 -0
  116. package/dist/src/types/hash-160.js +19 -0
  117. package/dist/src/types/hash-160.js.map +1 -0
  118. package/dist/src/types/hash-192.d.ts +10 -0
  119. package/dist/src/types/hash-192.js +19 -0
  120. package/dist/src/types/hash-192.js.map +1 -0
  121. package/dist/src/types/hash-256.d.ts +10 -0
  122. package/dist/src/types/hash-256.js +16 -0
  123. package/dist/src/types/hash-256.js.map +1 -0
  124. package/dist/src/types/hash.d.ts +40 -0
  125. package/dist/src/types/hash.js +76 -0
  126. package/dist/src/types/hash.js.map +1 -0
  127. package/dist/src/types/index.d.ts +19 -0
  128. package/dist/src/types/index.js +66 -0
  129. package/dist/src/types/index.js.map +1 -0
  130. package/dist/src/types/issue.d.ts +48 -0
  131. package/dist/src/types/issue.js +104 -0
  132. package/dist/src/types/issue.js.map +1 -0
  133. package/dist/src/types/path-set.d.ts +36 -0
  134. package/dist/src/types/path-set.js +233 -0
  135. package/dist/src/types/path-set.js.map +1 -0
  136. package/dist/src/types/serialized-type.d.ts +70 -0
  137. package/dist/src/types/serialized-type.js +105 -0
  138. package/dist/src/types/serialized-type.js.map +1 -0
  139. package/dist/src/types/st-array.d.ts +31 -0
  140. package/dist/src/types/st-array.js +86 -0
  141. package/dist/src/types/st-array.js.map +1 -0
  142. package/dist/src/types/st-number.d.ts +54 -0
  143. package/dist/src/types/st-number.js +208 -0
  144. package/dist/src/types/st-number.js.map +1 -0
  145. package/dist/src/types/st-object.d.ts +32 -0
  146. package/dist/src/types/st-object.js +173 -0
  147. package/dist/src/types/st-object.js.map +1 -0
  148. package/dist/src/types/uint-16.d.ts +24 -0
  149. package/dist/src/types/uint-16.js +45 -0
  150. package/dist/src/types/uint-16.js.map +1 -0
  151. package/dist/src/types/uint-32.d.ts +24 -0
  152. package/dist/src/types/uint-32.js +50 -0
  153. package/dist/src/types/uint-32.js.map +1 -0
  154. package/dist/src/types/uint-64.d.ts +38 -0
  155. package/dist/src/types/uint-64.js +107 -0
  156. package/dist/src/types/uint-64.js.map +1 -0
  157. package/dist/src/types/uint-8.d.ts +24 -0
  158. package/dist/src/types/uint-8.js +46 -0
  159. package/dist/src/types/uint-8.js.map +1 -0
  160. package/dist/src/types/uint.d.ts +29 -0
  161. package/dist/src/types/uint.js +47 -0
  162. package/dist/src/types/uint.js.map +1 -0
  163. package/dist/src/types/vector-256.d.ts +30 -0
  164. package/dist/src/types/vector-256.js +73 -0
  165. package/dist/src/types/vector-256.js.map +1 -0
  166. package/dist/src/types/xchain-bridge.d.ts +44 -0
  167. package/dist/src/types/xchain-bridge.js +102 -0
  168. package/dist/src/types/xchain-bridge.js.map +1 -0
  169. package/dist/src/utils.d.ts +79 -0
  170. package/dist/src/utils.js +181 -0
  171. package/dist/src/utils.js.map +1 -0
  172. package/dist/tsconfig.tsbuildinfo +1 -0
  173. package/dist/types/account-id.d.ts +1 -2
  174. package/dist/types/account-id.js +4 -6
  175. package/dist/types/account-id.js.map +1 -1
  176. package/dist/types/amount.d.ts +31 -8
  177. package/dist/types/amount.js +125 -43
  178. package/dist/types/amount.js.map +1 -1
  179. package/dist/types/blob.d.ts +1 -2
  180. package/dist/types/blob.js +5 -2
  181. package/dist/types/blob.js.map +1 -1
  182. package/dist/types/currency.d.ts +1 -2
  183. package/dist/types/currency.js +13 -13
  184. package/dist/types/currency.js.map +1 -1
  185. package/dist/types/hash-128.d.ts +1 -2
  186. package/dist/types/hash-128.js +3 -3
  187. package/dist/types/hash-128.js.map +1 -1
  188. package/dist/types/hash-160.d.ts +1 -2
  189. package/dist/types/hash-160.js +1 -2
  190. package/dist/types/hash-160.js.map +1 -1
  191. package/dist/types/hash-192.d.ts +10 -0
  192. package/dist/types/hash-192.js +19 -0
  193. package/dist/types/hash-192.js.map +1 -0
  194. package/dist/types/hash-256.d.ts +1 -2
  195. package/dist/types/hash-256.js +1 -2
  196. package/dist/types/hash-256.js.map +1 -1
  197. package/dist/types/hash.d.ts +2 -3
  198. package/dist/types/hash.js +8 -4
  199. package/dist/types/hash.js.map +1 -1
  200. package/dist/types/index.d.ts +2 -1
  201. package/dist/types/index.js +11 -2
  202. package/dist/types/index.js.map +1 -1
  203. package/dist/types/issue.d.ts +48 -0
  204. package/dist/types/issue.js +104 -0
  205. package/dist/types/issue.js.map +1 -0
  206. package/dist/types/path-set.js +12 -12
  207. package/dist/types/path-set.js.map +1 -1
  208. package/dist/types/serialized-type.d.ts +23 -16
  209. package/dist/types/serialized-type.js +15 -7
  210. package/dist/types/serialized-type.js.map +1 -1
  211. package/dist/types/st-array.d.ts +5 -2
  212. package/dist/types/st-array.js +17 -11
  213. package/dist/types/st-array.js.map +1 -1
  214. package/dist/types/st-number.d.ts +54 -0
  215. package/dist/types/st-number.js +208 -0
  216. package/dist/types/st-number.js.map +1 -0
  217. package/dist/types/st-object.js +32 -8
  218. package/dist/types/st-object.js.map +1 -1
  219. package/dist/types/uint-16.d.ts +1 -2
  220. package/dist/types/uint-16.js +6 -5
  221. package/dist/types/uint-16.js.map +1 -1
  222. package/dist/types/uint-32.d.ts +1 -2
  223. package/dist/types/uint-32.js +7 -6
  224. package/dist/types/uint-32.js.map +1 -1
  225. package/dist/types/uint-64.d.ts +6 -7
  226. package/dist/types/uint-64.js +44 -24
  227. package/dist/types/uint-64.js.map +1 -1
  228. package/dist/types/uint-8.d.ts +1 -2
  229. package/dist/types/uint-8.js +7 -5
  230. package/dist/types/uint-8.js.map +1 -1
  231. package/dist/types/uint.d.ts +5 -6
  232. package/dist/types/uint.js +5 -0
  233. package/dist/types/uint.js.map +1 -1
  234. package/dist/types/vector-256.d.ts +1 -2
  235. package/dist/types/vector-256.js +2 -4
  236. package/dist/types/vector-256.js.map +1 -1
  237. package/dist/types/xchain-bridge.d.ts +44 -0
  238. package/dist/types/xchain-bridge.js +102 -0
  239. package/dist/types/xchain-bridge.js.map +1 -0
  240. package/dist/utils.d.ts +79 -0
  241. package/dist/utils.js +181 -0
  242. package/dist/utils.js.map +1 -0
  243. package/package.json +21 -17
  244. package/src/README.md +5 -0
  245. package/src/binary.ts +235 -0
  246. package/src/coretypes.ts +31 -0
  247. package/src/enums/README.md +144 -0
  248. package/src/enums/bytes.ts +74 -0
  249. package/src/enums/constants.ts +5 -0
  250. package/src/enums/definitions.json +3390 -0
  251. package/src/enums/field.ts +84 -0
  252. package/src/enums/index.ts +34 -0
  253. package/src/enums/utils-renumber.ts +134 -0
  254. package/src/enums/xrpl-definitions-base.ts +150 -0
  255. package/src/enums/xrpl-definitions.ts +33 -0
  256. package/src/hash-prefixes.ts +42 -0
  257. package/src/hashes.ts +75 -0
  258. package/src/index.ts +166 -0
  259. package/src/ledger-hashes.ts +191 -0
  260. package/src/quality.ts +38 -0
  261. package/src/serdes/binary-parser.ts +228 -0
  262. package/src/serdes/binary-serializer.ts +166 -0
  263. package/src/shamap.ts +186 -0
  264. package/src/types/account-id.ts +86 -0
  265. package/src/types/amount.ts +362 -0
  266. package/src/types/blob.ts +46 -0
  267. package/src/types/currency.ts +140 -0
  268. package/src/types/hash-128.ts +33 -0
  269. package/src/types/hash-160.ts +19 -0
  270. package/src/types/hash-192.ts +19 -0
  271. package/src/types/hash-256.ts +15 -0
  272. package/src/types/hash.ts +86 -0
  273. package/src/types/index.ts +68 -0
  274. package/src/types/issue.ts +136 -0
  275. package/src/types/path-set.ts +290 -0
  276. package/src/types/serialized-type.ts +122 -0
  277. package/src/types/st-array.ts +113 -0
  278. package/src/types/st-number.ts +233 -0
  279. package/src/types/st-object.ts +215 -0
  280. package/src/types/uint-16.ts +53 -0
  281. package/src/types/uint-32.ts +59 -0
  282. package/src/types/uint-64.ts +135 -0
  283. package/src/types/uint-8.ts +52 -0
  284. package/src/types/uint.ts +60 -0
  285. package/src/types/vector-256.ts +79 -0
  286. package/src/types/xchain-bridge.ts +128 -0
  287. package/src/utils.ts +220 -0
  288. package/test/amount.test.js +0 -43
  289. package/test/binary-json.test.js +0 -45
  290. package/test/binary-parser.test.js +0 -396
  291. package/test/binary-serializer.test.js +0 -319
  292. package/test/definitions.test.js +0 -100
  293. package/test/fixtures/account-tx-transactions.db +0 -0
  294. package/test/fixtures/codec-fixtures.json +0 -4466
  295. package/test/fixtures/data-driven-tests.json +0 -2919
  296. package/test/fixtures/delivermin-tx-binary.json +0 -1
  297. package/test/fixtures/delivermin-tx.json +0 -98
  298. package/test/fixtures/deposit-preauth-tx-binary.json +0 -1
  299. package/test/fixtures/deposit-preauth-tx-meta-binary.json +0 -1
  300. package/test/fixtures/deposit-preauth-tx.json +0 -58
  301. package/test/fixtures/escrow-cancel-binary.json +0 -1
  302. package/test/fixtures/escrow-cancel-tx.json +0 -6
  303. package/test/fixtures/escrow-create-binary.json +0 -1
  304. package/test/fixtures/escrow-create-tx.json +0 -10
  305. package/test/fixtures/escrow-finish-binary.json +0 -1
  306. package/test/fixtures/escrow-finish-meta-binary.json +0 -1
  307. package/test/fixtures/escrow-finish-tx.json +0 -95
  308. package/test/fixtures/ledger-full-38129.json +0 -1
  309. package/test/fixtures/ledger-full-40000.json +0 -1
  310. package/test/fixtures/negative-unl.json +0 -12
  311. package/test/fixtures/nf-token.json +0 -547
  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/remit-binary.json +0 -1
  319. package/test/fixtures/remit-tx.json +0 -39
  320. package/test/fixtures/signerlistset-tx-binary.json +0 -1
  321. package/test/fixtures/signerlistset-tx-meta-binary.json +0 -1
  322. package/test/fixtures/signerlistset-tx.json +0 -94
  323. package/test/fixtures/ticket-create-binary.json +0 -1
  324. package/test/fixtures/ticket-create-tx.json +0 -7
  325. package/test/fixtures/unl-report-binary.json +0 -1
  326. package/test/fixtures/unl-report-meta-binary.json +0 -1
  327. package/test/fixtures/unl-report.json +0 -89
  328. package/test/fixtures/x-codec-fixtures.json +0 -188
  329. package/test/hash.test.js +0 -135
  330. package/test/ledger.test.js +0 -29
  331. package/test/lower-case-hex.test.js +0 -46
  332. package/test/pseudo-transaction.test.js +0 -38
  333. package/test/quality.test.js +0 -15
  334. package/test/shamap.test.js +0 -89
  335. package/test/signing-data-encoding.test.js +0 -213
  336. package/test/tx-encode-decode.test.js +0 -119
  337. package/test/types.test.js +0 -34
  338. package/test/uint.test.js +0 -148
  339. package/test/utils.js +0 -30
  340. package/test/x-address.test.js +0 -181
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Issue = void 0;
4
+ const utils_1 = require("@transia/isomorphic/utils");
5
+ const binary_parser_1 = require("../serdes/binary-parser");
6
+ const account_id_1 = require("./account-id");
7
+ const currency_1 = require("./currency");
8
+ const serialized_type_1 = require("./serialized-type");
9
+ const hash_192_1 = require("./hash-192");
10
+ /**
11
+ * Type guard for Issue Object
12
+ */
13
+ function isIssueObject(arg) {
14
+ const keys = Object.keys(arg).sort();
15
+ const isXRP = keys.length === 1 && keys[0] === 'currency';
16
+ const isIOU = keys.length === 2 && keys[0] === 'currency' && keys[1] === 'issuer';
17
+ const isMPT = keys.length === 1 && keys[0] === 'mpt_issuance_id';
18
+ return isXRP || isIOU || isMPT;
19
+ }
20
+ /**
21
+ * Class for serializing/Deserializing Amounts
22
+ */
23
+ class Issue extends serialized_type_1.SerializedType {
24
+ constructor(bytes) {
25
+ super(bytes !== null && bytes !== void 0 ? bytes : Issue.ZERO_ISSUED_CURRENCY.bytes);
26
+ }
27
+ /**
28
+ * Construct an amount from an IOU or string amount
29
+ *
30
+ * @param value An Amount, object representing an IOU, MPTAmount, or a string
31
+ * representing an integer amount
32
+ * @returns An Issue object
33
+ */
34
+ static from(value) {
35
+ if (value instanceof Issue) {
36
+ return value;
37
+ }
38
+ if (isIssueObject(value)) {
39
+ if (value.currency) {
40
+ const currency = currency_1.Currency.from(value.currency.toString()).toBytes();
41
+ //IOU case
42
+ if (value.issuer) {
43
+ const issuer = account_id_1.AccountID.from(value.issuer.toString()).toBytes();
44
+ return new Issue((0, utils_1.concat)([currency, issuer]));
45
+ }
46
+ //XRP case
47
+ return new Issue(currency);
48
+ }
49
+ // MPT case
50
+ if (value.mpt_issuance_id) {
51
+ const mptIssuanceIdBytes = hash_192_1.Hash192.from(value.mpt_issuance_id.toString()).toBytes();
52
+ return new Issue(mptIssuanceIdBytes);
53
+ }
54
+ }
55
+ throw new Error('Invalid type to construct an Amount');
56
+ }
57
+ /**
58
+ * Read an amount from a BinaryParser
59
+ *
60
+ * @param parser BinaryParser to read the Amount from
61
+ * @param hint The number of bytes to consume from the parser.
62
+ * For an MPT amount, pass 24 (the fixed length for Hash192).
63
+ *
64
+ * @returns An Issue object
65
+ */
66
+ static fromParser(parser, hint) {
67
+ if (hint === hash_192_1.Hash192.width) {
68
+ const mptBytes = parser.read(hash_192_1.Hash192.width);
69
+ return new Issue(mptBytes);
70
+ }
71
+ const currency = parser.read(20);
72
+ if (new currency_1.Currency(currency).toJSON() === 'XRP') {
73
+ return new Issue(currency);
74
+ }
75
+ const currencyAndIssuer = [currency, parser.read(20)];
76
+ return new Issue((0, utils_1.concat)(currencyAndIssuer));
77
+ }
78
+ /**
79
+ * Get the JSON representation of this Amount
80
+ *
81
+ * @returns the JSON interpretation of this.bytes
82
+ */
83
+ toJSON() {
84
+ // If the buffer is exactly 24 bytes, treat it as an MPT amount.
85
+ if (this.toBytes().length === hash_192_1.Hash192.width) {
86
+ return {
87
+ mpt_issuance_id: this.toHex().toUpperCase(),
88
+ };
89
+ }
90
+ const parser = new binary_parser_1.BinaryParser(this.toString());
91
+ const currency = currency_1.Currency.fromParser(parser);
92
+ if (currency.toJSON() === 'XRP') {
93
+ return { currency: currency.toJSON() };
94
+ }
95
+ const issuer = account_id_1.AccountID.fromParser(parser);
96
+ return {
97
+ currency: currency.toJSON(),
98
+ issuer: issuer.toJSON(),
99
+ };
100
+ }
101
+ }
102
+ exports.Issue = Issue;
103
+ Issue.ZERO_ISSUED_CURRENCY = new Issue(new Uint8Array(20));
104
+ //# sourceMappingURL=issue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"issue.js","sourceRoot":"","sources":["../../../src/types/issue.ts"],"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AI,IAAI,CAAC,OAAO,EAAE,CAAC,MAAM,KAAK,kBAAO,CAAC,KAAK,EAAE;YAC3C,OAAO;gBACL,eAAe,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,WAAW,EAAE;aAC5C,CAAA;SACF;QAED,MAAM,MAAM,GAAG,IAAI,4BAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;QAEhD,MAAM,QAAQ,GAAG,mBAAQ,CAAC,UAAU,CAAC,MAAM,CAAa,CAAA;QACxD,IAAI,QAAQ,CAAC,MAAM,EAAE,KAAK,KAAK,EAAE;YAC/B,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAA;SACvC;QACD,MAAM,MAAM,GAAG,sBAAS,CAAC,UAAU,CAAC,MAAM,CAAc,CAAA;QAExD,OAAO;YACL,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE;YAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;SACxB,CAAA;IACH,CAAC;;AAGM,sBAAK;AA9FI,0BAAoB,GAAU,IAAI,KAAK,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAA"}
@@ -0,0 +1,36 @@
1
+ import { BinaryParser } from '../serdes/binary-parser';
2
+ import { SerializedType, JsonObject } from './serialized-type';
3
+ /**
4
+ * The object representation of a Hop, an issuer AccountID, an account AccountID, and a Currency
5
+ */
6
+ interface HopObject extends JsonObject {
7
+ issuer?: string;
8
+ account?: string;
9
+ currency?: string;
10
+ }
11
+ /**
12
+ * Deserialize and Serialize the PathSet type
13
+ */
14
+ declare class PathSet extends SerializedType {
15
+ /**
16
+ * Construct a PathSet from an Array of Arrays representing paths
17
+ *
18
+ * @param value A PathSet or Array of Array of HopObjects
19
+ * @returns the PathSet constructed from value
20
+ */
21
+ static from<T extends PathSet | Array<Array<HopObject>>>(value: T): PathSet;
22
+ /**
23
+ * Construct a PathSet from a BinaryParser
24
+ *
25
+ * @param parser A BinaryParser to read PathSet from
26
+ * @returns the PathSet read from parser
27
+ */
28
+ static fromParser(parser: BinaryParser): PathSet;
29
+ /**
30
+ * Get the JSON representation of this PathSet
31
+ *
32
+ * @returns an Array of Array of HopObjects, representing this PathSet
33
+ */
34
+ toJSON(): Array<Array<HopObject>>;
35
+ }
36
+ export { PathSet };
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PathSet = void 0;
4
+ const account_id_1 = require("./account-id");
5
+ const currency_1 = require("./currency");
6
+ const binary_parser_1 = require("../serdes/binary-parser");
7
+ const serialized_type_1 = require("./serialized-type");
8
+ const utils_1 = require("@transia/isomorphic/utils");
9
+ /**
10
+ * Constants for separating Paths in a PathSet
11
+ */
12
+ const PATHSET_END_BYTE = 0x00;
13
+ const PATH_SEPARATOR_BYTE = 0xff;
14
+ /**
15
+ * Constant for masking types of a Hop
16
+ */
17
+ const TYPE_ACCOUNT = 0x01;
18
+ const TYPE_CURRENCY = 0x10;
19
+ const TYPE_ISSUER = 0x20;
20
+ /**
21
+ * TypeGuard for HopObject
22
+ */
23
+ function isHopObject(arg) {
24
+ return (arg.issuer !== undefined ||
25
+ arg.account !== undefined ||
26
+ arg.currency !== undefined);
27
+ }
28
+ /**
29
+ * TypeGuard for PathSet
30
+ */
31
+ function isPathSet(arg) {
32
+ return ((Array.isArray(arg) && arg.length === 0) ||
33
+ (Array.isArray(arg) && Array.isArray(arg[0]) && arg[0].length === 0) ||
34
+ (Array.isArray(arg) && Array.isArray(arg[0]) && isHopObject(arg[0][0])));
35
+ }
36
+ /**
37
+ * Serialize and Deserialize a Hop
38
+ */
39
+ class Hop extends serialized_type_1.SerializedType {
40
+ /**
41
+ * Create a Hop from a HopObject
42
+ *
43
+ * @param value Either a hop or HopObject to create a hop with
44
+ * @returns a Hop
45
+ */
46
+ static from(value) {
47
+ if (value instanceof Hop) {
48
+ return value;
49
+ }
50
+ const bytes = [Uint8Array.from([0])];
51
+ if (value.account) {
52
+ bytes.push(account_id_1.AccountID.from(value.account).toBytes());
53
+ bytes[0][0] |= TYPE_ACCOUNT;
54
+ }
55
+ if (value.currency) {
56
+ bytes.push(currency_1.Currency.from(value.currency).toBytes());
57
+ bytes[0][0] |= TYPE_CURRENCY;
58
+ }
59
+ if (value.issuer) {
60
+ bytes.push(account_id_1.AccountID.from(value.issuer).toBytes());
61
+ bytes[0][0] |= TYPE_ISSUER;
62
+ }
63
+ return new Hop((0, utils_1.concat)(bytes));
64
+ }
65
+ /**
66
+ * Construct a Hop from a BinaryParser
67
+ *
68
+ * @param parser BinaryParser to read the Hop from
69
+ * @returns a Hop
70
+ */
71
+ static fromParser(parser) {
72
+ const type = parser.readUInt8();
73
+ const bytes = [Uint8Array.from([type])];
74
+ if (type & TYPE_ACCOUNT) {
75
+ bytes.push(parser.read(account_id_1.AccountID.width));
76
+ }
77
+ if (type & TYPE_CURRENCY) {
78
+ bytes.push(parser.read(currency_1.Currency.width));
79
+ }
80
+ if (type & TYPE_ISSUER) {
81
+ bytes.push(parser.read(account_id_1.AccountID.width));
82
+ }
83
+ return new Hop((0, utils_1.concat)(bytes));
84
+ }
85
+ /**
86
+ * Get the JSON interpretation of this hop
87
+ *
88
+ * @returns a HopObject, an JS object with optional account, issuer, and currency
89
+ */
90
+ toJSON() {
91
+ const hopParser = new binary_parser_1.BinaryParser((0, utils_1.bytesToHex)(this.bytes));
92
+ const type = hopParser.readUInt8();
93
+ let account, currency, issuer;
94
+ if (type & TYPE_ACCOUNT) {
95
+ account = account_id_1.AccountID.fromParser(hopParser).toJSON();
96
+ }
97
+ if (type & TYPE_CURRENCY) {
98
+ currency = currency_1.Currency.fromParser(hopParser).toJSON();
99
+ }
100
+ if (type & TYPE_ISSUER) {
101
+ issuer = account_id_1.AccountID.fromParser(hopParser).toJSON();
102
+ }
103
+ const result = {};
104
+ if (account) {
105
+ result.account = account;
106
+ }
107
+ if (issuer) {
108
+ result.issuer = issuer;
109
+ }
110
+ if (currency) {
111
+ result.currency = currency;
112
+ }
113
+ return result;
114
+ }
115
+ /**
116
+ * get a number representing the type of this hop
117
+ *
118
+ * @returns a number to be bitwise and-ed with TYPE_ constants to describe the types in the hop
119
+ */
120
+ type() {
121
+ return this.bytes[0];
122
+ }
123
+ }
124
+ /**
125
+ * Class for serializing/deserializing Paths
126
+ */
127
+ class Path extends serialized_type_1.SerializedType {
128
+ /**
129
+ * construct a Path from an array of Hops
130
+ *
131
+ * @param value Path or array of HopObjects to construct a Path
132
+ * @returns the Path
133
+ */
134
+ static from(value) {
135
+ if (value instanceof Path) {
136
+ return value;
137
+ }
138
+ const bytes = [];
139
+ value.forEach((hop) => {
140
+ bytes.push(Hop.from(hop).toBytes());
141
+ });
142
+ return new Path((0, utils_1.concat)(bytes));
143
+ }
144
+ /**
145
+ * Read a Path from a BinaryParser
146
+ *
147
+ * @param parser BinaryParser to read Path from
148
+ * @returns the Path represented by the bytes read from the BinaryParser
149
+ */
150
+ static fromParser(parser) {
151
+ const bytes = [];
152
+ while (!parser.end()) {
153
+ bytes.push(Hop.fromParser(parser).toBytes());
154
+ if (parser.peek() === PATHSET_END_BYTE ||
155
+ parser.peek() === PATH_SEPARATOR_BYTE) {
156
+ break;
157
+ }
158
+ }
159
+ return new Path((0, utils_1.concat)(bytes));
160
+ }
161
+ /**
162
+ * Get the JSON representation of this Path
163
+ *
164
+ * @returns an Array of HopObject constructed from this.bytes
165
+ */
166
+ toJSON() {
167
+ const json = [];
168
+ const pathParser = new binary_parser_1.BinaryParser(this.toString());
169
+ while (!pathParser.end()) {
170
+ json.push(Hop.fromParser(pathParser).toJSON());
171
+ }
172
+ return json;
173
+ }
174
+ }
175
+ /**
176
+ * Deserialize and Serialize the PathSet type
177
+ */
178
+ class PathSet extends serialized_type_1.SerializedType {
179
+ /**
180
+ * Construct a PathSet from an Array of Arrays representing paths
181
+ *
182
+ * @param value A PathSet or Array of Array of HopObjects
183
+ * @returns the PathSet constructed from value
184
+ */
185
+ static from(value) {
186
+ if (value instanceof PathSet) {
187
+ return value;
188
+ }
189
+ if (isPathSet(value)) {
190
+ const bytes = [];
191
+ value.forEach((path) => {
192
+ bytes.push(Path.from(path).toBytes());
193
+ bytes.push(Uint8Array.from([PATH_SEPARATOR_BYTE]));
194
+ });
195
+ bytes[bytes.length - 1] = Uint8Array.from([PATHSET_END_BYTE]);
196
+ return new PathSet((0, utils_1.concat)(bytes));
197
+ }
198
+ throw new Error('Cannot construct PathSet from given value');
199
+ }
200
+ /**
201
+ * Construct a PathSet from a BinaryParser
202
+ *
203
+ * @param parser A BinaryParser to read PathSet from
204
+ * @returns the PathSet read from parser
205
+ */
206
+ static fromParser(parser) {
207
+ const bytes = [];
208
+ while (!parser.end()) {
209
+ bytes.push(Path.fromParser(parser).toBytes());
210
+ bytes.push(parser.read(1));
211
+ if (bytes[bytes.length - 1][0] == PATHSET_END_BYTE) {
212
+ break;
213
+ }
214
+ }
215
+ return new PathSet((0, utils_1.concat)(bytes));
216
+ }
217
+ /**
218
+ * Get the JSON representation of this PathSet
219
+ *
220
+ * @returns an Array of Array of HopObjects, representing this PathSet
221
+ */
222
+ toJSON() {
223
+ const json = [];
224
+ const pathParser = new binary_parser_1.BinaryParser(this.toString());
225
+ while (!pathParser.end()) {
226
+ json.push(Path.fromParser(pathParser).toJSON());
227
+ pathParser.skip(1);
228
+ }
229
+ return json;
230
+ }
231
+ }
232
+ exports.PathSet = PathSet;
233
+ //# sourceMappingURL=path-set.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path-set.js","sourceRoot":"","sources":["../../../src/types/path-set.ts"],"names":[],"mappings":";;;AAAA,6CAAwC;AACxC,yCAAqC;AACrC,2DAAsD;AACtD,uDAA8D;AAC9D,qDAA8D;AAE9D;;GAEG;AACH,MAAM,gBAAgB,GAAG,IAAI,CAAA;AAC7B,MAAM,mBAAmB,GAAG,IAAI,CAAA;AAEhC;;GAEG;AACH,MAAM,YAAY,GAAG,IAAI,CAAA;AACzB,MAAM,aAAa,GAAG,IAAI,CAAA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AU,CAAC,UAAU,CAAC,CAAC,MAAM,EAAE,CAAC,CAAA;YAC/C,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SACnB;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAEQ,0BAAO"}
@@ -0,0 +1,70 @@
1
+ import { BytesList } from '../serdes/binary-serializer';
2
+ import { BinaryParser } from '../serdes/binary-parser';
3
+ import { XrplDefinitionsBase } from '../enums';
4
+ type JSON = string | number | boolean | null | undefined | JSON[] | JsonObject;
5
+ type JsonObject = {
6
+ [key: string]: JSON;
7
+ };
8
+ /**
9
+ * The base class for all binary-codec types
10
+ */
11
+ declare class SerializedType {
12
+ protected readonly bytes: Uint8Array;
13
+ constructor(bytes?: Uint8Array);
14
+ static fromParser(parser: BinaryParser, hint?: number): SerializedType;
15
+ static from(value: SerializedType | JSON | bigint): SerializedType;
16
+ /**
17
+ * Write the bytes representation of a SerializedType to a BytesList
18
+ *
19
+ * @param list The BytesList to write SerializedType bytes to
20
+ */
21
+ toBytesSink(list: BytesList): void;
22
+ /**
23
+ * Get the hex representation of a SerializedType's bytes
24
+ *
25
+ * @returns hex String of this.bytes
26
+ */
27
+ toHex(): string;
28
+ /**
29
+ * Get the bytes representation of a SerializedType
30
+ *
31
+ * @returns A Uint8Array of the bytes
32
+ */
33
+ toBytes(): Uint8Array;
34
+ /**
35
+ * Return the JSON representation of a SerializedType
36
+ *
37
+ * @param _definitions rippled definitions used to parse the values of transaction types and such.
38
+ * Unused in default, but used in STObject, STArray
39
+ * Can be customized for sidechains and amendments.
40
+ * @returns any type, if not overloaded returns hexString representation of bytes
41
+ */
42
+ toJSON(_definitions?: XrplDefinitionsBase, _fieldName?: string): JSON;
43
+ /**
44
+ * @returns hexString representation of this.bytes
45
+ */
46
+ toString(): string;
47
+ }
48
+ /**
49
+ * Base class for SerializedTypes that are comparable.
50
+ *
51
+ * @template T - What types you want to allow comparisons between. You must specify all types. Primarily used to allow
52
+ * comparisons between built-in types (like `string`) and SerializedType subclasses (like `Hash`).
53
+ *
54
+ * Ex. `class Hash extends Comparable<Hash | string>`
55
+ */
56
+ declare class Comparable<T extends Object> extends SerializedType {
57
+ lt(other: T): boolean;
58
+ eq(other: T): boolean;
59
+ gt(other: T): boolean;
60
+ gte(other: T): boolean;
61
+ lte(other: T): boolean;
62
+ /**
63
+ * Overload this method to define how two Comparable SerializedTypes are compared
64
+ *
65
+ * @param other The comparable object to compare this to
66
+ * @returns A number denoting the relationship of this and other
67
+ */
68
+ compareTo(other: T): number;
69
+ }
70
+ export { SerializedType, Comparable, JSON, JsonObject };
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Comparable = exports.SerializedType = void 0;
4
+ const binary_serializer_1 = require("../serdes/binary-serializer");
5
+ const utils_1 = require("@transia/isomorphic/utils");
6
+ /**
7
+ * The base class for all binary-codec types
8
+ */
9
+ class SerializedType {
10
+ constructor(bytes) {
11
+ this.bytes = new Uint8Array(0);
12
+ this.bytes = bytes !== null && bytes !== void 0 ? bytes : new Uint8Array(0);
13
+ }
14
+ static fromParser(parser, hint) {
15
+ throw new Error('fromParser not implemented');
16
+ return this.fromParser(parser, hint);
17
+ }
18
+ static from(value) {
19
+ throw new Error('from not implemented');
20
+ return this.from(value);
21
+ }
22
+ /**
23
+ * Write the bytes representation of a SerializedType to a BytesList
24
+ *
25
+ * @param list The BytesList to write SerializedType bytes to
26
+ */
27
+ toBytesSink(list) {
28
+ list.put(this.bytes);
29
+ }
30
+ /**
31
+ * Get the hex representation of a SerializedType's bytes
32
+ *
33
+ * @returns hex String of this.bytes
34
+ */
35
+ toHex() {
36
+ return (0, utils_1.bytesToHex)(this.toBytes());
37
+ }
38
+ /**
39
+ * Get the bytes representation of a SerializedType
40
+ *
41
+ * @returns A Uint8Array of the bytes
42
+ */
43
+ toBytes() {
44
+ if (this.bytes) {
45
+ return this.bytes;
46
+ }
47
+ const bytes = new binary_serializer_1.BytesList();
48
+ this.toBytesSink(bytes);
49
+ return bytes.toBytes();
50
+ }
51
+ /**
52
+ * Return the JSON representation of a SerializedType
53
+ *
54
+ * @param _definitions rippled definitions used to parse the values of transaction types and such.
55
+ * Unused in default, but used in STObject, STArray
56
+ * Can be customized for sidechains and amendments.
57
+ * @returns any type, if not overloaded returns hexString representation of bytes
58
+ */
59
+ toJSON(_definitions, _fieldName) {
60
+ return this.toHex();
61
+ }
62
+ /**
63
+ * @returns hexString representation of this.bytes
64
+ */
65
+ toString() {
66
+ return this.toHex();
67
+ }
68
+ }
69
+ exports.SerializedType = SerializedType;
70
+ /**
71
+ * Base class for SerializedTypes that are comparable.
72
+ *
73
+ * @template T - What types you want to allow comparisons between. You must specify all types. Primarily used to allow
74
+ * comparisons between built-in types (like `string`) and SerializedType subclasses (like `Hash`).
75
+ *
76
+ * Ex. `class Hash extends Comparable<Hash | string>`
77
+ */
78
+ class Comparable extends SerializedType {
79
+ lt(other) {
80
+ return this.compareTo(other) < 0;
81
+ }
82
+ eq(other) {
83
+ return this.compareTo(other) === 0;
84
+ }
85
+ gt(other) {
86
+ return this.compareTo(other) > 0;
87
+ }
88
+ gte(other) {
89
+ return this.compareTo(other) > -1;
90
+ }
91
+ lte(other) {
92
+ return this.compareTo(other) < 1;
93
+ }
94
+ /**
95
+ * Overload this method to define how two Comparable SerializedTypes are compared
96
+ *
97
+ * @param other The comparable object to compare this to
98
+ * @returns A number denoting the relationship of this and other
99
+ */
100
+ compareTo(other) {
101
+ throw new Error(`cannot compare ${this.toString()} and ${other.toString()}`);
102
+ }
103
+ }
104
+ exports.Comparable = Comparable;
105
+ //# sourceMappingURL=serialized-type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialized-type.js","sourceRoot":"","sources":["../../../src/types/serialized-type.ts"],"names":[],"mappings":";;;AAAA,mEAAuD;AAGvD,qDAAsD;AAMtD;;GAEG;AACH,MAAM,cAAc;IAGlB,YAAY,KAAkB;QAFX,UAAK,GAAe,IAAI,UAAU,CAAC,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I,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAClC,CAAC;IAED,EAAE,CAAC,KAAQ;QACT,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IACpC,CAAC;IAED,EAAE,CAAC,KAAQ;QACT,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAClC,CAAC;IAED,GAAG,CAAC,KAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;IACnC,CAAC;IAED,GAAG,CAAC,KAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAClC,CAAC;IAED;;;;;OAKG;IACH,SAAS,CAAC,KAAQ;QAChB,MAAM,IAAI,KAAK,CAAC,kBAAkB,IAAI,CAAC,QAAQ,EAAE,QAAQ,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IAC9E,CAAC;CACF;AAEwB,gCAAU"}
@@ -0,0 +1,31 @@
1
+ import { XrplDefinitionsBase } from '../enums';
2
+ import { SerializedType, JsonObject } from './serialized-type';
3
+ import { BinaryParser } from '../serdes/binary-parser';
4
+ /**
5
+ * Class for serializing and deserializing Arrays of Objects
6
+ */
7
+ declare class STArray extends SerializedType {
8
+ /**
9
+ * Construct an STArray from a BinaryParser
10
+ *
11
+ * @param parser BinaryParser to parse an STArray from
12
+ * @returns An STArray Object
13
+ */
14
+ static fromParser(parser: BinaryParser): STArray;
15
+ /**
16
+ * Construct an STArray from an Array of JSON Objects
17
+ *
18
+ * @param value STArray or Array of Objects to parse into an STArray
19
+ * @param definitions optional, types and values to use to encode/decode a transaction
20
+ * @returns An STArray object
21
+ */
22
+ static from<T extends STArray | Array<JsonObject>>(value: T, definitions?: XrplDefinitionsBase): STArray;
23
+ /**
24
+ * Return the JSON representation of this.bytes
25
+ *
26
+ * @param definitions optional, types and values to use to encode/decode a transaction
27
+ * @returns An Array of JSON objects
28
+ */
29
+ toJSON(definitions?: XrplDefinitionsBase): Array<JsonObject>;
30
+ }
31
+ export { STArray };